Skip to content

WriteRuntimeInstance

Gives read and write access to one Workspace for the current execution attempt, as passed to Mutations, Listeners and App Hooks.

Every write returns a fresh Item; use it, or a fresh lookup, rather than an Item loaded earlier. Writable references belong to the attempt that produced them and are not for use after the execute callback has finished.

Unit of Work

readonly apps: Record<string, WriteAppInstance>

The Apps of the Definition, keyed by canonical App key, with Mutations and Event publishers.

ReadRuntimeInstance.apps


readonly now: 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.

ReadRuntimeInstance.now


readonly principalId: string

The identifier of the principal the execution runs as; inside sudo, the principal that invoked it.

when read in a system context, which has no principal.

ReadRuntimeInstance.principalId


readonly root: WriteAppInstance

The root App of the Definition, with Mutations and Event publishers.

ReadRuntimeInstance.root


readonly workspaceId: string

The identifier of the Workspace.

ReadRuntimeInstance.workspaceId

getItem(id): Promise<WriteItem<ItemInstanceTypes> | undefined>

Loads an Item by identifier, writable in the current execution.

string

The Item identifier.

Promise<WriteItem<ItemInstanceTypes> | undefined>

The Item, or undefined when the active principal cannot read it.

ReadRuntimeInstance.getItem


getItemByKeyPath(…parts): Promise<WriteItem<ItemInstanceTypes> | undefined>

Loads an Item by following keys down the hierarchy from the Workspace Item, writable in the current execution.

…[string, ...string[]]

The keys to follow, starting with a top-level Item’s key.

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.

ReadRuntimeInstance.getItemByKeyPath


getWorkspaceItem(): Promise<WriteWorkspaceItem>

Loads the Item at the root of the Workspace hierarchy, writable in the current execution.

Promise<WriteWorkspaceItem>

ReadRuntimeInstance.getWorkspaceItem


getWorkspaceTemplate(): ReadTemplate

Returns the Template of the Workspace Item.

ReadTemplate

ReadRuntimeInstance.getWorkspaceTemplate


hashKey(source): Promise<string>

Hashes a string into a key of the form sha256:<hex>, for deriving stable keys from external identifiers.

string

The string to hash, at most 1,024 characters.

Promise<string>

when source is not a string of at most 1,024 characters.

ReadRuntimeInstance.hashKey


log(message, …optional): void

Writes a message to the Runtime log, with the same argument handling as console.log.

any

The message or value to log.

…any[]

Further values to log alongside it.

void

ReadRuntimeInstance.log


selectItems(): ItemCursorSelector<WriteItem<ItemInstanceTypes>>

Starts a selection over every Item in the Workspace, returning writable Items.

ItemCursorSelector<WriteItem<ItemInstanceTypes>>

ReadRuntimeInstance.selectItems


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.

TResult

(ctx) => Promise<TResult>

Receives the elevated context and returns the result of the call.

Promise<TResult>

Whatever fn returns.

Writes made through the elevated context are part of the same execution attempt.

ReadRuntimeInstance.sudo


template(prn): Promise<WriteTemplate<WriteItem<ItemInstanceTypes>> | undefined>

Looks up a Template by PRN, returning it with Item creation.

string

The Template PRN.

Promise<WriteTemplate<WriteItem<ItemInstanceTypes>> | undefined>

The Template, or undefined when no Template in the Definition has that PRN.

ReadRuntimeInstance.template