Skip to content

ReadRuntimeInstance

Gives read access to one Workspace under the active principal, as passed to queries and to the read side of every execution.

Item lookups return undefined for Items the principal cannot read, and Property values are filtered by the principal’s Grants.

Workspaces and access

readonly apps: Record<string, ReadAppInstance>

The Apps of the Definition, keyed by canonical App key.


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.


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.


readonly root: ReadAppInstance

The root App of the Definition.


readonly workspaceId: string

The identifier of the Workspace.

BaseInstance.workspaceId

getItem(id): Promise<ReadItem | undefined>

Loads an Item by identifier.

string

The Item identifier.

Promise<ReadItem | undefined>

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


getItemByKeyPath(…parts): Promise<ReadItem | undefined>

Loads an Item by following keys down the hierarchy from the Workspace Item, one key per part.

…[string, ...string[]]

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

Promise<ReadItem | undefined>

The Item at the end of the path, or undefined when any key along it does not match a readable child.

Load a well-known Item

const settings = await ctx.getItemByKeyPath('settings');

getWorkspaceItem(): Promise<ReadWorkspaceItem | undefined>

Loads the Item at the root of the Workspace hierarchy.

Promise<ReadWorkspaceItem | undefined>


getWorkspaceTemplate(): ReadTemplate

Returns the Template of the Workspace Item.

ReadTemplate


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.


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


selectItems(): ItemCursorSelector<ReadItem>

Starts a selection over every Item in the Workspace.

ItemCursorSelector<ReadItem>

Narrow the selection with template, union, prn or only before filtering or sorting by Property.

ItemCursorSelector


sudo<TResult>(fn): Promise<TResult>

Runs a callback with a context that bypasses Grants 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.

From a principal or masquerade context the callback receives a sudo context whose reads ignore Grants and whose principalId is still the invoking principal. From a sudo or system context it receives the same level of access it already had.

Workspaces and access


template(prn): Promise<ReadTemplate<ReadItem> | undefined>

Looks up a Template by PRN.

string

The Template PRN.

Promise<ReadTemplate<ReadItem> | undefined>

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