PlatformInstance
Runs application code against one Workspace as one principal; the entry point to every Runtime.
Remarks
Section titled “Remarks”Obtain an instance from the Runtime for a Workspace and an auth context, then call execute to
run Queries in read mode and Mutations, Listeners and hooks in read-write mode.
Properties
Section titled “Properties”
readonlyauth:AlpyneAuthContext
The auth context every execution on this instance runs under; a copy, so changes to the original do not affect it.
workspaceId
Section titled “workspaceId”
readonlyworkspaceId:string
The identifier of the Workspace this instance operates in.
Methods
Section titled “Methods”execute()
Section titled “execute()”Call Signature
Section titled “Call Signature”execute<
TResult>(mode,fn):Promise<TResult>
Runs a callback in read mode, where Items cannot be modified and Events cannot be published.
Type Parameters
Section titled “Type Parameters”TResult
Section titled “TResult”TResult
The value the callback resolves to.
Parameters
Section titled “Parameters”"read"
'read'.
RuntimeReadFn<TResult>
Receives the root App and the read context.
Returns
Section titled “Returns”Promise<TResult>
Whatever fn resolves to.
Remarks
Section titled “Remarks”Use read mode for Queries. Items returned reflect committed data at the time they are read.
Example
Section titled “Example”Run a Query
const total = await instance.execute('read', async (_root, ctx) => { const page = await ctx.apps.library.templates.content.selectItems().execute(); return page.results.length;});Call Signature
Section titled “Call Signature”execute<
TWriteAppInstance,TResult>(mode,event,fn,options?):Promise<TResult>
Runs a callback in read-write mode inside one transaction, with full access to Items and data under the instance’s permissions.
Type Parameters
Section titled “Type Parameters”TWriteAppInstance
Section titled “TWriteAppInstance”TWriteAppInstance extends WriteRuntimeInstance = WriteRuntimeInstance
The write context type, narrowed to an App’s generated context where one exists.
TResult
Section titled “TResult”TResult = unknown
The value the callback resolves to.
Parameters
Section titled “Parameters”"readwrite"
'readwrite'.
RuntimeExternalEvent | RuntimeInternalEvent
The Event that caused this execution, such as an API call or a processed Event; it supplies the identity used for deduplication and lineage.
RuntimeReadWriteFn<TResult, TWriteAppInstance>
Receives the write context.
options?
Section titled “options?”Deduplication and retry settings.
Returns
Section titled “Returns”Promise<TResult>
Whatever fn resolves to, once the transaction has committed.
Remarks
Section titled “Remarks”Use read-write mode for Mutations, Listeners and App Hooks. Items marked external by their Template
stay read-only. Every write in the callback commits or rolls back together; an attempt that fails with a
transient error is retried within maximumTransientRetries. Awaiting the result awaits the commit, not the
asynchronous Listeners and Metric projections that follow it.
Throws
Section titled “Throws”(error-020-idempotent-execution-rejected) when idempotencyScope is set and the Event has
already been executed in that scope.
Call Signature
Section titled “Call Signature”execute<
TResult>(mode,eventOrFn,fn?,options?):Promise<TResult>
Runs a callback in the given mode; the 'read' and 'readwrite' overloads describe each mode.
Type Parameters
Section titled “Type Parameters”TResult
Section titled “TResult”TResult
The value the callback resolves to.
Parameters
Section titled “Parameters”'read' or 'readwrite'.
eventOrFn
Section titled “eventOrFn”RuntimeExternalEvent | RuntimeInternalEvent | RuntimeReadFn<TResult>
The read callback, or the causing Event of a read-write execution.
RuntimeReadWriteFn<TResult, WriteRuntimeInstance>
The write callback of a read-write execution.
options?
Section titled “options?”Deduplication and retry settings of a read-write execution.
Returns
Section titled “Returns”Promise<TResult>
publishExternalEvent()
Section titled “publishExternalEvent()”publishExternalEvent(
event):Promise<void>
Enqueues one or more external Events for the Workspace; the reactor processes them asynchronously.
Parameters
Section titled “Parameters”Omit<AlpyneExternalEvent, "workspaceId"> | Omit<AlpyneExternalEvent, "workspaceId">[]
The Event or Events to enqueue, without a Workspace identifier; this instance’s Workspace is applied.
Returns
Section titled “Returns”Promise<void>
Remarks
Section titled “Remarks”Awaiting the result awaits the enqueue, not the processing. An empty array enqueues nothing.
runCreate()
Section titled “runCreate()”runCreate(
event):Promise<void>
Runs the onCreate hooks of every App in the Definition inside one transaction, to initialize a new Workspace.
Parameters
Section titled “Parameters”The external Event that caused the creation.
Returns
Section titled “Returns”Promise<void>
runSeed()
Section titled “runSeed()”runSeed(
event):Promise<void>
Runs the onSeed hooks of every App in the Definition inside one transaction, to populate a Workspace with
seed Items.
Parameters
Section titled “Parameters”The external Event that caused the seeding; its payload may restrict which Templates are seeded.
Returns
Section titled “Returns”Promise<void>
setRefreshBy()
Section titled “setRefreshBy()”setRefreshBy(
itemId,duration):Promise<WriteItem<ItemInstanceTypes> |undefined>
Schedules the next refresh of an Item, in its own transaction.
Parameters
Section titled “Parameters”itemId
Section titled “itemId”string
The identifier of the Item to schedule.
duration
Section titled “duration”DurationLikeObject | { immediate: true; }
The refresh period as a Luxon duration object, or { immediate: true } to make the Item due now.
Returns
Section titled “Returns”Promise<WriteItem<ItemInstanceTypes> | undefined>
The updated Item, or undefined when the Item cannot be read.
Remarks
Section titled “Remarks”With a period, the due time is the next occurrence of a phase derived from the Item’s identifier within
that period, which spreads Items sharing a period evenly across it. With immediate, refreshBy is set to now.

