createItem method
- String parentPath,
- String itemName,
- String kind, {
- Map<
String, String> ? metadata, - bool existsError = false,
inherited
Creates a new item within a space.
parentPath is the space path where the item will be created.
itemName is the name of the item (e.g., 'hero').
kind is the type of item (e.g., 'model', 'texture', 'workflow').
metadata is optional key-value metadata. Because the create RPC does
not carry metadata, it is applied via a follow-up metadata update once
the item exists, mirroring the Python SDK.
existsError controls whether to throw an error if the item
already exists (default: false).
Implementation
Future<ItemResponse> createItem(
String parentPath,
String itemName,
String kind, {
Map<String, String>? metadata,
bool existsError = false,
}) async {
// The 'bundle' kind is reserved; mirror Python's create_item which raises
// ReservedKindError. Use createBundle() instead.
if (reservedKinds.contains(kind.toLowerCase())) {
throw ReservedKindError(
"Item kind '$kind' is reserved. Use createBundle() instead.",
);
}
final request =
CreateItemRequest()
..parentPath = parentPath
..itemName = itemName
..kind = kind
..existsError = existsError;
final response = await stub.createItem(request, options: callOptions);
if (metadata != null && metadata.isNotEmpty) {
// Apply metadata via a follow-up update (the create RPC carries none),
// but return the original create response like the Python SDK does.
await updateItemMetadata(response.kref.uri, metadata);
}
return response;
}