SystemWriteRuntimeInstance
Extends the write context with operations reserved for system access, as passed to the onCreate and onSeed
App Hooks.
Remarks
Section titled “Remarks”These operations are rejected for a regular principal; they require a sudo or system context.
Extends
Section titled “Extends”Properties
Section titled “Properties”
readonlyapps:Record<string,WriteAppInstance>
The Apps of the Definition, keyed by canonical App key, with Mutations and Event publishers.
Inherited from
Section titled “Inherited from”
readonlynow:DateTime
The execution time in UTC, fixed for the whole attempt so that every read and write within it observes the same moment; a retried attempt receives a fresh time.
Inherited from
Section titled “Inherited from”principalId
Section titled “principalId”
readonlyprincipalId:string
The identifier of the principal the execution runs as; inside sudo, the principal that invoked it.
Throws
Section titled “Throws”when read in a system context, which has no principal.
Inherited from
Section titled “Inherited from”WriteRuntimeInstance.principalId
readonlyroot:WriteAppInstance
The root App of the Definition, with Mutations and Event publishers.
Inherited from
Section titled “Inherited from”workspaceId
Section titled “workspaceId”
readonlyworkspaceId:string
The identifier of the Workspace.
Inherited from
Section titled “Inherited from”WriteRuntimeInstance.workspaceId
Methods
Section titled “Methods”getItem()
Section titled “getItem()”getItem(
id):Promise<WriteItem<ItemInstanceTypes> |undefined>
Loads an Item by identifier, writable in the current execution.
Parameters
Section titled “Parameters”string
The Item identifier.
Returns
Section titled “Returns”Promise<WriteItem<ItemInstanceTypes> | undefined>
The Item, or undefined when the active principal cannot read it.
Inherited from
Section titled “Inherited from”getItemByKeyPath()
Section titled “getItemByKeyPath()”getItemByKeyPath(…
parts):Promise<WriteItem<ItemInstanceTypes> |undefined>
Loads an Item by following keys down the hierarchy from the Workspace Item, writable in the current execution.
Parameters
Section titled “Parameters”…[string, ...string[]]
The keys to follow, starting with a top-level Item’s key.
Returns
Section titled “Returns”Promise<WriteItem<ItemInstanceTypes> | undefined>
The Item at the end of the path, or undefined when any key along it does not match a readable child.
Inherited from
Section titled “Inherited from”WriteRuntimeInstance.getItemByKeyPath
getWorkspaceItem()
Section titled “getWorkspaceItem()”getWorkspaceItem():
Promise<WriteWorkspaceItem>
Loads the Item at the root of the Workspace hierarchy, writable in the current execution.
Returns
Section titled “Returns”Promise<WriteWorkspaceItem>
Inherited from
Section titled “Inherited from”WriteRuntimeInstance.getWorkspaceItem
getWorkspaceTemplate()
Section titled “getWorkspaceTemplate()”getWorkspaceTemplate():
ReadTemplate
Returns the Template of the Workspace Item.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”WriteRuntimeInstance.getWorkspaceTemplate
hashKey()
Section titled “hashKey()”hashKey(
source):Promise<string>
Hashes a string into a key of the form sha256:<hex>, for deriving stable keys from external identifiers.
Parameters
Section titled “Parameters”source
Section titled “source”string
The string to hash, at most 1,024 characters.
Returns
Section titled “Returns”Promise<string>
Throws
Section titled “Throws”when source is not a string of at most 1,024 characters.
Inherited from
Section titled “Inherited from”log(
message, …optional):void
Writes a message to the Runtime log, with the same argument handling as console.log.
Parameters
Section titled “Parameters”message
Section titled “message”any
The message or value to log.
optional
Section titled “optional”…any[]
Further values to log alongside it.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”seed()
Section titled “seed()”seed(
options):Promise<void>
Creates the Items described in seed data, leaving Items that already exist unchanged.
Parameters
Section titled “Parameters”options
Section titled “options”The Items to seed.
Returns
Section titled “Returns”Promise<void>
Remarks
Section titled “Remarks”Each Item is stored under the Workspace-scoped identifier derived from its id, with id kept as its
origin identifier; an Item whose stored identifier already exists is skipped rather than updated.
Throws
Section titled “Throws”when the context is neither sudo nor system, or when an Item names a Template that is not in the Definition.
seedId()
Section titled “seedId()”seedId(
key):string
Derives a stable origin identifier from a key, for use as id, parentId and Relation targets in seed data.
Parameters
Section titled “Parameters”string
A non-empty key naming the seeded Item, such as 'navigation/library'.
Returns
Section titled “Returns”string
The same UUID for every call with that key in this Workspace.
Throws
Section titled “Throws”when the context is neither sudo nor system, or when key is empty.
Example
Section titled “Example”Seed a parent and child
await ctx.seed({ items: [ { id: ctx.seedId('navigation/library'), templatePrn: navigation.prn, properties: { title: 'Library' } }, { id: ctx.seedId('library/content'), parentId: ctx.seedId('navigation/library'), templatePrn: flexViewGroup.prn, properties: {} }, ],});SystemWriteRuntimeInstance.seed
selectEvents()
Section titled “selectEvents()”selectEvents():
EventCursorSelector<EventInstance>
Starts a selection over the Events appended in the Workspace.
Returns
Section titled “Returns”EventCursorSelector<EventInstance>
Throws
Section titled “Throws”when the context is neither sudo nor system.
selectItems()
Section titled “selectItems()”selectItems():
ItemCursorSelector<WriteItem<ItemInstanceTypes>>
Starts a selection over every Item in the Workspace, returning writable Items.
Returns
Section titled “Returns”ItemCursorSelector<WriteItem<ItemInstanceTypes>>
Inherited from
Section titled “Inherited from”WriteRuntimeInstance.selectItems
sudo()
Section titled “sudo()”sudo<
TResult>(fn):Promise<TResult>
Runs a callback with a context that bypasses Grants for reads and writes while staying attributed to the active principal.
Type Parameters
Section titled “Type Parameters”TResult
Section titled “TResult”TResult
Parameters
Section titled “Parameters”(ctx) => Promise<TResult>
Receives the elevated context and returns the result of the call.
Returns
Section titled “Returns”Promise<TResult>
Whatever fn returns.
Remarks
Section titled “Remarks”Writes made through the elevated context are part of the same execution attempt.
Inherited from
Section titled “Inherited from”template()
Section titled “template()”template(
prn):Promise<WriteTemplate<WriteItem<ItemInstanceTypes>> |undefined>
Looks up a Template by PRN, returning it with Item creation.
Parameters
Section titled “Parameters”string
The Template PRN.
Returns
Section titled “Returns”Promise<WriteTemplate<WriteItem<ItemInstanceTypes>> | undefined>
The Template, or undefined when no Template in the Definition has that PRN.
Inherited from
Section titled “Inherited from”workspaceSeedId()
Section titled “workspaceSeedId()”workspaceSeedId(
key):string
Returns the identifier a seeded Item is stored under, derived from the same key as seedId.
Parameters
Section titled “Parameters”string
The key passed to seedId for the Item.
Returns
Section titled “Returns”string
Remarks
Section titled “Remarks”Use it where the stored identifier must appear outside id, parentId and Relation targets, for
example inside Property values or content.

