Runtime
Everything here is exported from @ts-atlas/core/runtime (types included: RuntimeOptions, WorkerOptions, RetryPolicy, DeliveryBatch, DispatchOptions, DispatchResult, QueryOptions, QueryResult, TraceEvent, Runtime).
createRuntime(options)
Section titled “createRuntime(options)”| Option | Default | Meaning |
|---|---|---|
capabilities |
required | The capabilities, e.g. system.capabilities.map((c) => c.capability). |
store |
createMemoryStore() |
Where records, the outbox and consumer cursors live. |
workerStore |
store |
The store the background workers use (deliveries, timers, leases). Same database, second pool. |
clock |
the system clock | () => string (ISO instant). Tests inject it. |
observe |
none | (event: TraceEvent) => void, called for every trace event. |
traceLimit |
1000 |
Events kept in memory for trace(). |
instance |
a random UUID | This runtime’s identity as a lease owner (runtime.instance). Unique per process. |
retry |
{ attempts: 5, baseMs: 10, maxMs: 200 } |
Optimistic-concurrency retries: up to attempts runs, each retry after a random wait below baseMs * 2^(retry - 1), capped at maxMs. |
delivery |
{ projections: 100, reactions: 20, subscribers: 10 } |
Outbox entries per delivery transaction, per consumer. 1 everywhere delivers one entry per transaction. |
maxDepth |
1000 |
The deepest cause chain a delivery accepts; past it, failed with cascade-exceeded. |
maxSteps |
1000 |
Handler runs allowed per drain() call (a cascade guard for tests and CLIs). |
beforeCommit |
none | Test seam between decide and commit: ({ capability, handler, attempt }) => void | Promise<void>. |
runtime.start(options)
Section titled “runtime.start(options)”Starts background delivery and returns { stop(): Promise<void> }.
| Option | Default | Meaning |
|---|---|---|
pollMs |
250 |
How often the instance checks the outbox for entries committed elsewhere. One check per instance; local commits wake it at once. |
idleMs |
1000 |
While the outbox stays still, the check backs off up to this (never below pollMs). |
batch |
100 |
Outbox entries a consumer reads per round. |
workers |
true |
false: an API-only instance. No consumer loop and no scheduler; dispatch, queries and await keep working. |
leaseMs |
30000 |
How long a consumer’s lease lasts without renewal. |
renewMs |
10000 |
How often held leases are renewed and standby instances try to acquire free ones. Must be shorter than leaseMs (start throws otherwise). |
runtime.dispatch(command, options)
Section titled “runtime.dispatch(command, options)”command is { type, ...input }. Options (DispatchOptions):
| Option | Meaning |
|---|---|
actor |
Actor | null (default null, anonymous). Never read from the payload. |
await |
'views', 'all' or a list of view names: wait after the commit until they applied this dispatch’s facts. |
timeoutMs |
Bound of the wait (default 2000). |
Returns DispatchResult: { outcome: 'accepted', facts, awaited? } or { outcome: 'rejected', code, params, reason, facts: [] }. awaited is present only when the dispatch asked to await; false means the wait timed out (the command still committed).
runtime.query(name, input, options)
Section titled “runtime.query(name, input, options)”Options (QueryOptions): actor, and for view queries after (the previous page’s next) and limit (1..page.max, default page.size). Returns QueryResult: { outcome: 'ok', result } (a view query’s result is { items, next }) or a rejection.
Other methods
Section titled “Other methods”| Method | Meaning |
|---|---|
drain() |
Deliver until every consumer is caught up. Tests and CLIs only: it ignores leases. |
subscribe(id, types, handler) |
An edge subscriber with its own durable cursor, at least once. Register before start(). |
rebuild(view) |
Replay a view from the outbox into a shadow table, swapped in when caught up. |
cursors() |
Every consumer cursor { consumer, position, capability }; capability is null for orphans. |
copyCursor(from, to, { force? }) |
Start to where from is (compare-and-set). |
store.get(collection, key) / store.list(collection) |
Free reads without versions, lifted to the latest shape. Prefer declared queries. |
facts() |
Every stored fact (sent commands excluded). |
trace() |
The newest trace events (traceLimit). |
instance |
The lease owner id. |
Helpers
Section titled “Helpers”| Export | Meaning |
|---|---|
capability({...}) |
Declares a capability (see Capabilities). |
t |
Shapes (see Shapes). |
q |
The view filter DSL: q.eq / in / notIn / gte / lte / between / contains / prefix. |
time |
Pure instant and calendar helpers: add, diff, localDate, localTime, fromLocal, weekday, addDays, minutes, hhmm, isDate, isTime. |
SYSTEM |
The actor reactions and sent commands run as. |
rejection(code, params?) |
Builds a rejection body (the shop example uses it for its own error boundary). |
retryDelay(attempt, policy, random?) |
The wait before run attempt after a conflict. |
createMemoryStore() |
The in-memory Store. |