import type { Action2, ActionConfig, ActionResult } from '../actions/index.js'; import type { DefinedValue } from '../guards/index.js'; import type { NodeConfig, StateExtended, StatePextended, StateValue } from '../states/index.js'; import type { Decompose } from '@bemedev/decompose'; import type { Fn, PrimitiveObject, Ru, SubTypeLow } from '../libs/bemedev/globals/types'; import type { ActorsConfigMap, EventArg, EventArgAll, EventObject, EventsMap } from '../events/index.js'; import type { FnMap, FnR, ValuesOf } from '../types/index.js'; import type { Config, EventsMapFrom, SimpleMachineOptions2 } from './types'; /** * Options for async action helpers. * - `error`: called with the thrown error and current context snapshot when * the async function rejects. Its return value is merged as the ActionResult. * When omitted, the rejection propagates to the interpreter's `_addError` channel. * - `max`: maximum milliseconds before the async action is forcibly aborted via * `TimeoutPromise`. When omitted, no timeout is applied. */ export type AsyncOptions = { error: (state: StatePextended) => R; max?: number; }; /** * Types for all meaningful elements of the machine. * * @template : {@linkcode Config} [C] - type of the machine configuration * @template : {@linkcode EventsMap} [E] - type of the events map * @template : {@linkcode ActorsConfigMap} [A] - type of the actors configuration map * @template : any [Pc] - type of the private context * @template : {@linkcode types} [Tc] - type of the context * @template : {@linkcode SimpleMachineOptions2} [Mo] - type of the machine options */ export type Elements = { config: C; pContext: Pc; events: E; actorsMap: A; context: Tc; actions?: Mo['actions']; predicates?: Mo['predicates']; delays?: Mo['delays']; actors?: Mo['actors']; }; export type GetIO_F = (key: 'exit' | 'entry', node?: NodeConfig) => ActionConfig[]; /** * Simple representation of a machine with meaningful properties. * * @template : {@linkcode EventsMap} [E] - type of the events map * @template : {@linkcode ActorsConfigMap} [A] - type of the actors configuration map * @template : any [Pc] - type of the private context * @template : {@linkcode PrimitiveObject} [Tc] - type of the context * * @see {@linkcode NodeConfigWithInitials} for the structure of node configurations with initials. * @see {@linkcode StateValue} for the type of state values. * @see {@linkcode Fn} for creating functions * */ export interface AnyMachine { options: any; config: Config; flat: Record; context: Tc; pContext: Pc; eventsMap: E; actorsMap: A; __events: any; __state: any; __decomposedState: any; addOptions: any; actions: any; predicates: any; delays: any; children: any; renew: any; initialConfig: NodeConfig; initialValue: StateValue; isInitial: Fn<[string], boolean>; retrieveParentFromInitial: Fn<[string], NodeConfig>; toNode: Fn<[StateValue], NodeConfig>; } export type AssignAction_F = , K extends keyof D = keyof D, F extends D[K] | Promise = D[K] | Promise, Err extends PrimitiveObject = PrimitiveObject>(key: K, fn: FnMap, ...args: F extends Promise ? [AsyncOptions] : []) => Action2; export type ResendAction_F = (event: EventArgAll) => Action2; export type TimeAction_F = (id: string) => Action2; export type VoidAction_F = = void | Promise, Err extends PrimitiveObject = PrimitiveObject>(fn: FnMap, ...args: F extends Promise ? [AsyncOptions] : []) => Action2; export type ByKey_F = , D = Decompose, K extends keyof D & string = keyof D & string>(key: K) => D[K]; export type FilterAction_F = , K extends keyof D & string = keyof D & string>(key: K, fn: K extends string ? D[K] extends Array ? (item: Item, index: number, array: Item[]) => boolean : D[K] extends Ru ? (value: ValuesOf, all: D[K]) => boolean : never : never) => Action2; export type EraseAction_F = , object>, DD = SubTypeLow, K extends keyof DD & string = keyof DD & string>(key: K) => Action2; export type DirectMerge_F = Fn<[result?: ActionResult], void>; export type SendAction_F = (_?: M) => >; } | Promise<{ to: string; event: EventArg>; }> = { to: string; event: EventArg>; } | Promise<{ to: string; event: EventArg>; }>, Err extends PrimitiveObject = PrimitiveObject>(fn: FnMap, ...args: F extends Promise<{ to: string; event: EventArg>; }> ? [AsyncOptions] : []) => Action2; export type ValueCheckerGuard_F = (path: DefinedValue, ...values: any[]) => FnR; export type DefineGuard_F = (path: DefinedValue) => FnR; export type AllActions_F = AssignAction_F | VoidAction_F; export type DebounceAction_F = >(fn: A, options: { ms?: number; id: string; }) => Action2; export type BatchAction_F = | undefined)[]>(...fns: A) => Action2; /** * Type for the _legacy parameter containing previously defined options. */ export type LegacyOptions = Readonly<{ actions?: Mo['actions']; predicates?: Mo['predicates']; delays?: Mo['delays']; actors?: Mo['actors']; }>; export type AddOption = { isDefined: DefineGuard_F; isNotDefined: DefineGuard_F; isValue: ValueCheckerGuard_F; isNotValue: ValueCheckerGuard_F; assign: AssignAction_F; batch: BatchAction_F; filter: FilterAction_F; erase: EraseAction_F; voidAction: VoidAction_F; sendTo: SendAction_F; debounce: DebounceAction_F; resend: ResendAction_F; /** * Force send action, performs the action regardless of the current state. */ forceSend: ResendAction_F; pauseActivity: TimeAction_F; resumeActivity: TimeAction_F; stopActivity: TimeAction_F; pauseTimer: TimeAction_F; resumeTimer: TimeAction_F; stopTimer: TimeAction_F; }; export type AddOptionsParam_F = (option: AddOption, /** * Access to previously defined options from previous addOptions or provideOptions calls. * Provides actions, predicates, emitters, machines, promises, and delays. */ legacyOptions: { _legacy: LegacyOptions; }) => Mo | undefined; export type AddOptions_F = (option: AddOptionsParam_F) => Mo | undefined; /** * Represents a scheduled action with its data and execution time. * * @template : any [Pc] - type of the private context * @template : {@linkcode PrimitiveObject} [Tc] - type of the context * * @see {@linkcode ActionResult} for the result of the action. */ export type ScheduledData = { data: ActionResult; ms: number; id: string; }; export type SendToEvent = { to: string; event: T; }; export type ExtendedActionsParams = Partial<{ scheduled: ScheduledData; resend: EventArg; forceSend: EventArg; pauseActivity: string; resumeActivity: string; stopActivity: string; pauseTimer: string; resumeTimer: string; stopTimer: string; sentEvent: SendToEvent; }>; export type TimeActionsTypes = 'pauseActivity' | 'resumeActivity' | 'stopActivity' | 'pauseTimer' | 'resumeTimer' | 'stopTimer'; export type _ActionTypes = 'assign' | 'void' | 'sendTo' | 'resend' | 'forceSend' | 'debounce' | TimeActionsTypes; export type ActionTypes = `actions.${_ActionTypes}`; export type AppTypes = ActionTypes | 'guards' | 'pContext' | 'context'; //# sourceMappingURL=machine.types.d.ts.map