BaseWriteItem
Presents one Item with the operations that modify it inside the current read-write execution.
Remarks
Section titled “Remarks”Every write returns a fresh Item reflecting the stored result; the instance the method was called on is not updated in place. Use the returned Item, or a fresh lookup, for anything that follows.
Extends
Section titled “Extends”Extended by
Section titled “Extended by”Type Parameters
Section titled “Type Parameters”TItemInstanceTypes
Section titled “TItemInstanceTypes”TItemInstanceTypes extends ItemInstanceTypes = ItemInstanceTypes
The generated map from Template PRN to Item type, used to type the children
returned by createChild and the keyed upsert methods.
Properties
Section titled “Properties”createdAt
Section titled “createdAt”
readonlycreatedAt:Date
When the Item was created, taken from the execution time of the execution that created it.
Inherited from
Section titled “Inherited from”definition
Section titled “definition”
readonlydefinition:TemplateDefinition
The Template definition the Item was created from, with any extension Properties of its parent merged in.
Inherited from
Section titled “Inherited from”events
Section titled “events”
readonlyevents: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.
readonlyid:string
The Item identifier, a UUID.
Inherited from
Section titled “Inherited from”properties
Section titled “properties”
readonlyproperties:PropertyMap
Plain Property values keyed by Property key, ready for application logic.
Remarks
Section titled “Remarks”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.
Inherited from
Section titled “Inherited from”propertyValues
Section titled “propertyValues”
readonlypropertyValues:PropertyValueMap
Property values keyed by Property key, each tagged with its data type.
Remarks
Section titled “Remarks”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.
Inherited from
Section titled “Inherited from”relations
Section titled “relations”
readonlyrelations:Record<string,WriteRelationInstance>
Relations declared on the Item’s Template, keyed by Relation key, with write operations for this side.
Overrides
Section titled “Overrides”
readonlystate: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.
Overrides
Section titled “Overrides”templatePrn
Section titled “templatePrn”
readonlytemplatePrn:string
The PRN of the Template the Item was created from.
Inherited from
Section titled “Inherited from”workspaceId
Section titled “workspaceId”
readonlyworkspaceId:string
The identifier of the Workspace holding the Item.
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”assertRole()
Section titled “assertRole()”assertRole(
role):Promise<true>
Confirms that the active principal holds a Template Role on this Item.
Parameters
Section titled “Parameters”A Role from the Template’s roles.
Returns
Section titled “Returns”Promise<true>
true when the Role is held.
Throws
Section titled “Throws”AssertRoleFailedError when the active principal does not hold the Role on this Item.
Inherited from
Section titled “Inherited from”assignParent()
Section titled “assignParent()”assignParent(
parent):Promise<WriteItem<ItemInstanceTypes>>
Moves this Item under a new parent.
Parameters
Section titled “Parameters”parent
Section titled “parent”The Item to become the parent; it must not be this Item or one of its descendants.
Returns
Section titled “Returns”Promise<WriteItem<ItemInstanceTypes>>
The moved Item.
Throws
Section titled “Throws”(error-009-parent-child-circular-reference) when the new parent is this Item or descends from it.
checkRole()
Section titled “checkRole()”checkRole(
role):Promise<boolean>
Reports whether the active principal holds a Template Role on this Item.
Parameters
Section titled “Parameters”A Role from the Template’s roles.
Returns
Section titled “Returns”Promise<boolean>
Inherited from
Section titled “Inherited from”clearKey()
Section titled “clearKey()”clearKey():
Promise<BaseWriteItem<TItemInstanceTypes>>
Removes this Item’s key so that it can no longer be found by key.
Returns
Section titled “Returns”Promise<BaseWriteItem<TItemInstanceTypes>>
The updated Item.
createChild()
Section titled “createChild()”createChild<
TReadTemplate>(template,options):Promise<TItemInstanceTypes["WriteItemsByPrn"][TReadTemplate["prn"]]>
Creates a new Item of a Template as a child of this Item.
Type Parameters
Section titled “Type Parameters”TReadTemplate
Section titled “TReadTemplate”TReadTemplate extends BaseReadTemplate
The Template, whose PRN selects the returned Item type.
Parameters
Section titled “Parameters”template
Section titled “template”TReadTemplate
The Template to create the Item from, normally taken from an App’s templates.
options
Section titled “options”Key, Property values and initial state for the new Item.
Returns
Section titled “Returns”Promise<TItemInstanceTypes["WriteItemsByPrn"][TReadTemplate["prn"]]>
The created Item, writable in the current execution.
Remarks
Section titled “Remarks”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.
Throws
Section titled “Throws”when options.state is supplied and is not an initial state of the Template.
Example
Section titled “Example”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' },});currentRoles()
Section titled “currentRoles()”currentRoles():
Promise<BaseRoleInstance[]>
Lists the Template Roles the active principal holds on this Item.
Returns
Section titled “Returns”Promise<BaseRoleInstance[]>
Remarks
Section titled “Remarks”Sudo and system contexts hold every Role the Template declares.
Inherited from
Section titled “Inherited from”getAncestors()
Section titled “getAncestors()”getAncestors():
Promise<WriteItem<ItemInstanceTypes>[]>
Loads the ancestors of this Item as writable Items, nearest parent first, up to and including the Workspace Item.
Returns
Section titled “Returns”Promise<WriteItem<ItemInstanceTypes>[]>
The ancestors the active principal can read, stopping at the first unreadable one; the Workspace Item has none.
Overrides
Section titled “Overrides”getChildByKey()
Section titled “getChildByKey()”getChildByKey(
key):Promise<WriteItem<ItemInstanceTypes> |undefined>
Finds the child of this Item that carries a key and returns it writable.
Parameters
Section titled “Parameters”string
The child’s key, relative to this Item.
Returns
Section titled “Returns”Promise<WriteItem<ItemInstanceTypes> | undefined>
The child, or undefined when no child the active principal can read carries the key.
Overrides
Section titled “Overrides”getParent()
Section titled “getParent()”getParent():
Promise<WriteItem<ItemInstanceTypes> |undefined>
Loads the parent of this Item as a writable Item.
Returns
Section titled “Returns”Promise<WriteItem<ItemInstanceTypes> | undefined>
The parent, or undefined for the Workspace Item, which has no parent.
Overrides
Section titled “Overrides”updateKey()
Section titled “updateKey()”updateKey(
key):Promise<BaseWriteItem<TItemInstanceTypes>>
Gives this Item a new key relative to its parent.
Parameters
Section titled “Parameters”string
The new key; it must be a valid key.
Returns
Section titled “Returns”Promise<BaseWriteItem<TItemInstanceTypes>>
The updated Item.
Throws
Section titled “Throws”when key is not a valid key.
updateProperties()
Section titled “updateProperties()”updateProperties(
input):Promise<BaseWriteItem<TItemInstanceTypes>>
Stores new values for some of this Item’s Properties.
Parameters
Section titled “Parameters”Record<string, unknown>
Property values keyed by Property key; Properties not named keep their stored values.
Returns
Section titled “Returns”Promise<BaseWriteItem<TItemInstanceTypes>>
The updated Item; the instance the method was called on is unchanged.
Remarks
Section titled “Remarks”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.
Example
Section titled “Example”Patch one Property
const updated = await item.updateProperties({ installation: 'requested' });upsertChildByKey()
Section titled “upsertChildByKey()”upsertChildByKey<
TReadTemplate>(template,options):Promise<TItemInstanceTypes["WriteItemsByPrn"][TReadTemplate["prn"]]>
Creates the child of this Item that carries a key, or updates the existing child when there already is one.
Type Parameters
Section titled “Type Parameters”TReadTemplate
Section titled “TReadTemplate”TReadTemplate extends BaseReadTemplate
The Template, whose PRN selects the returned Item type.
Parameters
Section titled “Parameters”template
Section titled “template”TReadTemplate
The Template for a newly created child.
options
Section titled “options”The key, Property values, initial state for a new child and the conflict policy.
Returns
Section titled “Returns”Promise<TItemInstanceTypes["WriteItemsByPrn"][TReadTemplate["prn"]]>
The child carrying the key after the operation.
Remarks
Section titled “Remarks”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.
Throws
Section titled “Throws”when key is missing or not a valid key.
Example
Section titled “Example”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',});upsertChildrenByKey()
Section titled “upsertChildrenByKey()”upsertChildrenByKey<
TReadTemplate>(template,options):Promise<Record<string,TItemInstanceTypes["WriteItemsByPrn"][TReadTemplate["prn"]]>>
Creates or updates several keyed children of this Item in one call.
Type Parameters
Section titled “Type Parameters”TReadTemplate
Section titled “TReadTemplate”TReadTemplate extends BaseReadTemplate
The Template, whose PRN selects the returned Item type.
Parameters
Section titled “Parameters”template
Section titled “template”TReadTemplate
The Template for newly created children.
options
Section titled “options”The children to upsert, keyed by child key, and the conflict policy applied to all of them.
Returns
Section titled “Returns”Promise<Record<string, TItemInstanceTypes["WriteItemsByPrn"][TReadTemplate["prn"]]>>
The resulting children keyed by child key.
Remarks
Section titled “Remarks”Each child follows the rules of BaseWriteItem.upsertChildByKey. An empty children map
returns an empty result.

