Skip to content

SystemWriteRuntimeInstance

Extends the write context with operations reserved for system access, as passed to the onCreate and onSeed App Hooks.

These operations are rejected for a regular principal; they require a sudo or system context.

readonly apps: Record<string, WriteAppInstance>

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

WriteRuntimeInstance.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.

WriteRuntimeInstance.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.

WriteRuntimeInstance.principalId


readonly root: WriteAppInstance

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

WriteRuntimeInstance.root


readonly workspaceId: string

The identifier of the Workspace.

WriteRuntimeInstance.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.

WriteRuntimeInstance.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.

WriteRuntimeInstance.getItemByKeyPath


getWorkspaceItem(): Promise<WriteWorkspaceItem>

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

Promise<WriteWorkspaceItem>

WriteRuntimeInstance.getWorkspaceItem


getWorkspaceTemplate(): ReadTemplate

Returns the Template of the Workspace Item.

ReadTemplate

WriteRuntimeInstance.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.

WriteRuntimeInstance.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

WriteRuntimeInstance.log


seed(options): Promise<void>

Creates the Items described in seed data, leaving Items that already exist unchanged.

SeedOptions

The Items to seed.

Promise<void>

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.

when the context is neither sudo nor system, or when an Item names a Template that is not in the Definition.

SeedItem


seedId(key): string

Derives a stable origin identifier from a key, for use as id, parentId and Relation targets in seed data.

string

A non-empty key naming the seeded Item, such as 'navigation/library'.

string

The same UUID for every call with that key in this Workspace.

when the context is neither sudo nor system, or when key is empty.

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(): EventCursorSelector<EventInstance>

Starts a selection over the Events appended in the Workspace.

EventCursorSelector<EventInstance>

when the context is neither sudo nor system.

EventCursorSelector


selectItems(): ItemCursorSelector<WriteItem<ItemInstanceTypes>>

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

ItemCursorSelector<WriteItem<ItemInstanceTypes>>

WriteRuntimeInstance.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.

WriteRuntimeInstance.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.

WriteRuntimeInstance.template


workspaceSeedId(key): string

Returns the identifier a seeded Item is stored under, derived from the same key as seedId.

string

The key passed to seedId for the Item.

string

Use it where the stored identifier must appear outside id, parentId and Relation targets, for example inside Property values or content.

SystemWriteRuntimeInstance.seedId