State
@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:622
The full state definition, including schemas, handlers, and optional invariants and snapshot logic.
Type Declarationโ
autoclose_after_days?โ
optionalautoclose_after_days?:number
The smallest after window (in days) of the .autocloses({...})
policy, or undefined when the policy has no time component
(#1090). The synthesized autoclose reaction uses it to defer its
re-check to head.created plus this many days; a policy without an
after waits for the next event instead of parking on a due-time.
Set alongside autoclose by the builder. Day-denominated โ the
close surface never speaks in ms/seconds/minutes.
autoclose_keep_days?โ
optionalautoclose_keep_days?:number
The rolling-window width (in days) of the .autocloses({ keep })
policy, or undefined when the policy declares no rolling window
(#1011). 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(...).
given?โ
optionalgiven?:GivenHandlers<TState,TActions>
initโ
init: () =>
Readonly<TState>
Returnsโ
Readonly<TState>
nameโ
name:
TName
onโ
on:
ActionHandlers<TState,TEvents,TActions>
options?โ
optionaloptions?:{ [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>
snap?โ
optionalsnap?: (snapshot) =>boolean
Parametersโ
snapshotโ
Snapshot<TState, TEvents>
Returnsโ
boolean
archive()?โ
optionalarchive(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
headโ
Committed<TEvents, keyof TEvents>
before?โ
Date
Returnsโ
Promise<void>
autoclose()?โ
optionalautoclose(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()?โ
optionaldisclose(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]"). See #855 / epic #566.
Parametersโ
eventโ
Committed<TEvents, keyof TEvents>
actorโ
Returnsโ
boolean
message()โ
message(
validated):Message<TEvents, keyofTEvents>
Parametersโ
validatedโ
Message<TEvents, keyof TEvents>
Returnsโ
Message<TEvents, keyof TEvents>
view()โ
view(
event,actor):Committed<TEvents, keyofTEvents>
Parametersโ
eventโ
Committed<TEvents, keyof TEvents>
actorโ
Readonly<{[key: string]: unknown; id: string; name: string; }> | undefined
Returnsโ
Committed<TEvents, keyof TEvents>
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.