Skip to main content
Version: Current

State

@rotorsoft/act-root


@rotorsoft/act-root / act/src / State

Type Alias: State<TState, TEvents, TActions, TName>

State<TState, TEvents, TActions, TName> = StateSchemas<TState, TEvents, TActions> & object

Defined in: libs/act/src/types/action.ts:742

The full state definition, including schemas, handlers, and optional preconditions and snapshot logic.

Type Parameters​

TState​

TState extends Schema

State schema.

TEvents​

TEvents extends Schemas

Event schemas.

TActions​

TActions extends Schemas

Action schemas.

TName​

TName extends string = string

State name literal.

Type Declaration​

autoclose_after_days?​

optional autoclose_after_days?: number

The smallest after window (in days) of the .autocloses({...}) policy, or undefined when the policy has no time component. Set alongside autoclose by the builder. Day-denominated — the close surface never speaks in ms/seconds/minutes.

autoclose_after_windows?​

optional autoclose_after_windows?: readonly number[]

Every after window (in days) of the .autocloses({...}) policy. The synthesized autoclose reaction defers its re-check to head.created plus the earliest one still ahead; a policy without one waits for the next event instead of parking on a due-time. Set alongside autoclose by the builder.

autoclose_keep_days?​

optional autoclose_keep_days?: number

The rolling-window width (in days) of the .autocloses({ keep }) policy, or undefined when the policy declares no rolling window. The synthesized autoclose reaction stages a windowed close (prune the prefix older than the window behind the closest safe snapshot) when the oldest surviving domain event ages out, and defers until the tail ages out otherwise. Set alongside autoclose by the builder; only reachable behind .snap(...).

init​

init: () => Readonly<TState>

Returns​

Readonly<TState>

loads?​

optional loads?: { [TKey in keyof TActions]?: readonly Load[] }

The other states each action loads, keyed by action name. Set by .loads(...); an action without an entry loads only its own stream.

name​

name: TName

on​

on: ActionHandlers<TState, TEvents, TActions>

options?​

optional options?: { [TKey in keyof TActions]?: ActionOptions }

Per-action retry policy keyed by action name. Set by state.on(entry, options); consumed by the orchestrator's command path. Actions without an entry behave as if { maxRetries: 0 } — ConcurrencyError surfaces on first conflict.

patch​

patch: PatchHandlers<TState, TEvents>

requires?​

optional requires?: RequiresHandlers<TState, TActions>

snap?​

optional snap?: (snapshot) => boolean

Parameters​

snapshot​

Snapshot<TState, TEvents>

Returns​

boolean

archive()?​

optional archive(stream, head, before?): Promise<void>

Archiver set by .archives(fn). The online close cycle threads this into CloseTarget.archive for every truncate it stages, so the existing close-cycle's archive-while-guarded invariant carries over to the autoclose path. Absent → the cycle truncates without an archive step. Bivariant method-shorthand for the same State<specific> → State<any, any, any> reason as disclose / autoclose.

Parameters​

stream​

string

Committed<TEvents, keyof TEvents>

before?​

Date

Returns​

Promise<void>

autoclose()?​

optional autoclose(stream, head, count): boolean

Online close predicate set by .autocloses(predicate). The orchestrator's autoclose cycle iterates this state's streams once per tick and calls the predicate per candidate; truthy results are scheduled for atomic truncate-and-seed via Store.truncate. Absent → the state opts out of online close entirely (zero per-cycle cost).

Bivariant method-shorthand for the same reason as disclose — keeps State<specific> assignable to State<any, any, any>. The .autocloses() builder method keeps the narrow signature.

Parameters​

stream​

string

head​

Committed<TEvents, keyof TEvents>

count​

number

Returns​

boolean

disclose()?​

optional disclose(event, actor): boolean

Disclosure predicate set by .discloses(predicate). Gates external reads of sensitive(...)-marked fields — returning true allows the actor to see plaintext, false redacts. When absent, the framework default-denies on every external read (sensitive fields are always substituted with "[REDACTED]").

Parameters​

event​

Committed<TEvents, keyof TEvents>

actor​

Actor

Returns​

boolean

message()​

message(validated): Message<TEvents, keyof TEvents>

Parameters​

validated​

Message<TEvents, keyof TEvents>

Returns​

Message<TEvents, keyof TEvents>

view()​

view(event, actor): Committed<TEvents, keyof TEvents>

Parameters​

event​

Committed<TEvents, keyof TEvents>

actor​

Readonly<{[key: string]: unknown; id: string; name: string; }> | undefined

Returns​

Committed<TEvents, keyof TEvents>