Skip to content

WriteWorkspaceItem

Presents the Workspace Item inside a read-write execution.

readonly createdAt: Date

When the Item was created, taken from the execution time of the execution that created it.

BaseWriteItem.createdAt


readonly definition: TemplateDefinition

The Template definition the Item was created from, with any extension Properties of its parent merged in.

BaseWriteItem.definition


readonly events: Record<string, WriteEventPublishInstance>

Publishers for the Events declared on the Item’s Template and on Unions it belongs to, keyed by Event key. A Template’s created is not included, as only the Runtime publishes it.

BaseWriteItem.events


readonly id: string

The Item identifier, a UUID.

BaseWriteItem.id


readonly metadata: AlpyneWorkspaceMetadataMap

Platform metadata stored on the Workspace, such as feature flags and identifiers of linked systems.


readonly properties: PropertyMap

Plain Property values keyed by Property key, ready for application logic.

Select values are reduced to option keys: a single-select reads as its option key or null, a multi-select as an array of option keys. instant and datetime values are Luxon DateTime objects. A Property that is unset, invalid or not granted to the principal reads as undefined.

PropertyMap

BaseWriteItem.properties


readonly propertyValues: PropertyValueMap

Property values keyed by Property key, each tagged with its data type.

Use this form when the data type is significant, for example to tell an unset value from a stored value that has become invalid. Properties the principal is not granted are absent.

PropertyValue

BaseWriteItem.propertyValues


readonly relations: Record<string, WriteRelationInstance>

Relations declared on the Item’s Template, keyed by Relation key, with write operations for this side.

BaseWriteItem.relations


readonly state: WriteStateInstance<WriteItem<ItemInstanceTypes>, string | null, {[transition: string]: any; }> | null

The Item’s current state with its available transitions, or null when the Template declares no states.

BaseWriteItem.state


readonly templatePrn: string

The PRN of the Template the Item was created from.

BaseWriteItem.templatePrn


readonly workspaceId: string

The identifier of the Workspace holding the Item.

BaseWriteItem.workspaceId

assertRole(role): Promise<true>

Confirms that the active principal holds a Template Role on this Item.

TemplateRoleInstance

A Role from the Template’s roles.

Promise<true>

true when the Role is held.

AssertRoleFailedError when the active principal does not hold the Role on this Item.

BaseWriteItem.assertRole


assignParent(parent): Promise<WriteItem<ItemInstanceTypes>>

Moves this Item under a new parent.

ReadItem

The Item to become the parent; it must not be this Item or one of its descendants.

Promise<WriteItem<ItemInstanceTypes>>

The moved Item.

(error-009-parent-child-circular-reference) when the new parent is this Item or descends from it.

BaseWriteItem.assignParent


checkRole(role): Promise<boolean>

Reports whether the active principal holds a Template Role on this Item.

TemplateRoleInstance

A Role from the Template’s roles.

Promise<boolean>

BaseWriteItem.checkRole


clearKey(): Promise<WriteWorkspaceItem>

Removes this Item’s key so that it can no longer be found by key.

Promise<WriteWorkspaceItem>

The updated Item.

BaseWriteItem.clearKey


createChild<TReadTemplate>(template, options): Promise<WriteItem<ItemInstanceTypes>>

Creates a new Item of a Template as a child of this Item.

TReadTemplate extends BaseReadTemplate

The Template, whose PRN selects the returned Item type.

TReadTemplate

The Template to create the Item from, normally taken from an App’s templates.

CreateChildOptions

Key, Property values and initial state for the new Item.

Promise<WriteItem<ItemInstanceTypes>>

The created Item, writable in the current execution.

Property values are converted against the Template and the parent’s extension of it; a value that does not fit its Property definition, or whose key is not defined, is not stored and reads back as unset. When key is supplied, a sibling carrying that key loses it, so a key names at most one child of a parent. When the Template declares a created Event, it is published against the new Item with a {} payload.

when options.state is supplied and is not an initial state of the Template.

Create a child with Properties

const directory = await ctx.getItemByKeyPath('directory');
if (!directory) throw new Error('Missing directory');
const employee = await directory.createChild(ctx.apps.employeeProfile.templates.employee, {
properties: { displayName: 'Ada Lovelace' },
});

CreateChildOptions

BaseWriteItem.createChild


currentRoles(): Promise<BaseRoleInstance[]>

Lists the Template Roles the active principal holds on this Item.

Promise<BaseRoleInstance[]>

Sudo and system contexts hold every Role the Template declares.

Grant access

BaseWriteItem.currentRoles


getAncestors(): Promise<WriteItem<ItemInstanceTypes>[]>

Loads the ancestors of this Item as writable Items, nearest parent first, up to and including the Workspace Item.

Promise<WriteItem<ItemInstanceTypes>[]>

The ancestors the active principal can read, stopping at the first unreadable one; the Workspace Item has none.

BaseWriteItem.getAncestors


getChildByKey(key): Promise<WriteItem<ItemInstanceTypes> | undefined>

Finds the child of this Item that carries a key and returns it writable.

string

The child’s key, relative to this Item.

Promise<WriteItem<ItemInstanceTypes> | undefined>

The child, or undefined when no child the active principal can read carries the key.

BaseWriteItem.getChildByKey


getParent(): Promise<WriteItem<ItemInstanceTypes> | undefined>

Loads the parent of this Item as a writable Item.

Promise<WriteItem<ItemInstanceTypes> | undefined>

The parent, or undefined for the Workspace Item, which has no parent.

BaseWriteItem.getParent


selectChildren(): ItemCursorSelector<WriteItem<ItemInstanceTypes>>

Starts a selection over the top-level Items of the Workspace, returning writable Items.

ItemCursorSelector<WriteItem<ItemInstanceTypes>>


updateKey(key): Promise<WriteWorkspaceItem>

Gives this Item a new key relative to its parent.

string

The new key; it must be a valid key.

Promise<WriteWorkspaceItem>

The updated Item.

when key is not a valid key.

BaseWriteItem.updateKey


updateProperties(input): Promise<WriteWorkspaceItem>

Stores new values for some of this Item’s Properties.

Record<string, unknown>

Property values keyed by Property key; Properties not named keep their stored values.

Promise<WriteWorkspaceItem>

The updated Item; the instance the method was called on is unchanged.

Only Properties that the Template or its extension defines and that the active principal is granted are written. Values are converted against the Property definitions before being stored, so a value that does not fit its definition reads back as unset.

Patch one Property

const updated = await item.updateProperties({ installation: 'requested' });

Handle incomplete data

BaseWriteItem.updateProperties


upsertChildByKey<TReadTemplate>(template, options): Promise<WriteItem<ItemInstanceTypes>>

Creates the child of this Item that carries a key, or updates the existing child when there already is one.

TReadTemplate extends BaseReadTemplate

The Template, whose PRN selects the returned Item type.

TReadTemplate

The Template for a newly created child.

UpsertChildByKeyOptions

The key, Property values, initial state for a new child and the conflict policy.

Promise<WriteItem<ItemInstanceTypes>>

The child carrying the key after the operation.

The existing child is found by key among this Item’s children. With onConflict: 'merge' the supplied Properties are written to it and its state is left unchanged; with 'ignore' it is returned untouched. A newly created child takes initialState, or the Template’s default state, and its created Event is published as for BaseWriteItem.createChild.

when key is missing or not a valid key.

Ensure a keyed child exists without overwriting it

const integration = await settings.upsertChildByKey(ctx.apps.email.templates.integration, {
key: 'email',
properties: { category: 'communication', title: 'Email' },
initialState: 'active',
onConflict: 'ignore',
});

UpsertChildByKeyOptions

BaseWriteItem.upsertChildByKey


upsertChildrenByKey<TReadTemplate>(template, options): Promise<Record<string, WriteItem<ItemInstanceTypes>>>

Creates or updates several keyed children of this Item in one call.

TReadTemplate extends BaseReadTemplate

The Template, whose PRN selects the returned Item type.

TReadTemplate

The Template for newly created children.

UpsertChildrenByKeyOptions

The children to upsert, keyed by child key, and the conflict policy applied to all of them.

Promise<Record<string, WriteItem<ItemInstanceTypes>>>

The resulting children keyed by child key.

Each child follows the rules of BaseWriteItem.upsertChildByKey. An empty children map returns an empty result.

UpsertChildrenByKeyOptions

BaseWriteItem.upsertChildrenByKey