Skip to main content
Version: Current

Precondition

@rotorsoft/act-root


@rotorsoft/act-root / act/src / Precondition

Type Alias: Precondition<TState, TPayload, TActor, TLoaded>

Precondition<TState, TPayload, TActor, TLoaded> = object

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

A precondition is a named rule an action requires before it runs: what the state, the actor and the payload must meet for the action to run now, such as "the ticket must be open". Declared with .requires([...]) and checked before the handler: a precondition whose holds returns false refuses the action with a PreconditionError carrying its description.

A precondition typed over a narrower payload ({ from: string }) fits every action whose payload has those fields, and one typed over unknown reads only the state and the actor and fits every action.

Not an invariant: what must hold after every action belongs in the state's schema, which every action checks before it commits.

Type Parameters​

TState​

TState extends Schema

State schema.

TPayload​

TPayload

The action payload, or the part of it the rule reads.

TActor​

TActor extends Actor = Actor

Actor type extending base Actor.

TLoaded​

TLoaded extends Record<string, Schema | undefined> = { }

The states the action loads, read in holds' fourth argument.

Properties​

description​

description: string

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


holds​

holds: (payload, state, actor, loaded) => boolean

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

Parameters​

payload​

Readonly<TPayload>

state​

Readonly<TState>

actor​

TActor | undefined

loaded​

Readonly<TLoaded>

Returns​

boolean