import type { ActionArgs, BuiltinCallable, DynamicParams } from "./actions.js"; import { BUILTIN } from "./brand.js"; import type { MachineContext, NonReducibleUnknown } from "./common.js"; import type { EventObject } from "./events.js"; import type { StateValue } from "./stateValue.js"; /** Guards receive the same `{ context, event }` object as actions. */ export type GuardArgs = ActionArgs; /** * A custom guard: inline in the config (`TParams` = `undefined`) or referenced * by name through `implementations.guards`. */ export type GuardPredicate = (args: GuardArgs, params: TParams) => boolean; /** `{ type: "name", params?: ... }` reference to a guard of the implementation table. */ export interface GuardObject { type: string; params?: DynamicParams; } export interface AndGuard extends BuiltinCallable { readonly [BUILTIN]: "and"; readonly type: "xstate.and"; readonly guards: readonly Guard[]; } export interface OrGuard extends BuiltinCallable { readonly [BUILTIN]: "or"; readonly type: "xstate.or"; readonly guards: readonly Guard[]; } export interface NotGuard extends BuiltinCallable { readonly [BUILTIN]: "not"; readonly type: "xstate.not"; readonly guard: Guard; } /** * `stateIn("#id")` / `stateIn({ a: "b" })`: true when the machine is in the * given state. An `#id` string checks node membership; anything else uses * `matches()` semantics against the current state value. */ export interface StateInGuard extends BuiltinCallable { readonly [BUILTIN]: "stateIn"; readonly type: "xstate.stateIn"; readonly stateValue: StateValue; } export type BuiltinGuard = AndGuard | OrGuard | NotGuard | StateInGuard; /** * Everything accepted as a transition `guard`: a name, a `{ type, params }` * reference, an inline predicate or a builtin combinator. */ export type Guard = string | GuardObject | GuardPredicate | BuiltinGuard;