import { StateMachine } from "./StateMachine.js"; import { assign } from "./actions/assign.js"; import { cancel } from "./actions/cancel.js"; import { emit } from "./actions/emit.js"; import { enqueueActions } from "./actions/enqueueActions.js"; import { log } from "./actions/log.js"; import { raise } from "./actions/raise.js"; import { sendTo } from "./actions/send.js"; import { spawnChild } from "./actions/spawnChild.js"; import { stopChild } from "./actions/stopChild.js"; import { GuardPredicate } from "./guards.js"; import { ActionFunction, AnyActorRef, AnyEventObject, Cast, DelayConfig, EventObject, Invert, IsNever, MachineConfig, MachineContext, MetaObject, NonReducibleUnknown, ParameterizedObject, RoutableStateId, SetupTypes, StateNodeConfig, StateSchema, ToChildren, ToStateValue, UnknownActorLogic, Values } from "./types.js"; type ToParameterizedObject> = Values<{ [K in keyof TParameterizedMap as K & string]: { type: K & string; params: TParameterizedMap[K]; }; }>; type ToProvidedActor, TActors extends Record> = Values<{ [K in keyof TActors as K & string]: { src: K & string; logic: TActors[K]; id: IsNever extends true ? string | undefined : K extends keyof Invert ? Invert[K] & string : string | undefined; }; }>; type ToStateSchema = { -readonly [K in keyof TSchema as K & ('id' | 'states')]: K extends 'states' ? { [SK in keyof TSchema['states']]: ToStateSchema>; } : TSchema[K]; }; type RequiredSetupKeys = IsNever extends true ? never : 'actors'; export type SetupReturn, TChildrenMap extends Record, TActions extends Record, TGuards extends Record, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TEmitted extends EventObject, TMeta extends MetaObject> = { extend: = {}, TExtendGuards extends Record = {}, TExtendDelays extends string = never>({ actions, guards, delays }: { actions?: { [K in keyof TExtendActions]: ActionFunction, ToParameterizedObject, ToParameterizedObject, TDelay | TExtendDelays, TEmitted>; }; guards?: { [K in keyof TExtendGuards]: GuardPredicate>; }; delays?: { [K in TExtendDelays]: DelayConfig['params'], TEvent>; }; }) => SetupReturn; /** * Creates a state config that is strongly typed. This state config can be * used to create a machine. * * @example * * ```ts * const lightMachineSetup = setup({ * // ... * }); * * const green = lightMachineSetup.createStateConfig({ * on: { * timer: { * actions: 'doSomething' * } * } * }); * * const machine = lightMachineSetup.createMachine({ * initial: 'green', * states: { * green, * yellow, * red * } * }); * ``` */ createStateConfig: , ToParameterizedObject, ToParameterizedObject, TDelay, TTag, unknown, TEmitted, TMeta>>(config: TStateConfig) => TStateConfig; /** * Creates a type-safe action. * * @example * * ```ts * const machineSetup = setup({ * // ... * }); * * const action = machineSetup.createAction(({ context, event }) => { * console.log(context.count, event.value); * }); * * const incrementAction = machineSetup.createAction( * assign({ count: ({ context }) => context.count + 1 }) * ); * * const machine = machineSetup.createMachine({ * context: { count: 0 }, * entry: [action, incrementAction] * }); * ``` */ createAction: (action: ActionFunction, ToParameterizedObject, ToParameterizedObject, TDelay, TEmitted>) => typeof action; createMachine: , ToParameterizedObject, ToParameterizedObject, TDelay, TTag, TInput, TOutput, TEmitted, TMeta>>(config: TConfig) => StateMachine] extends [never] ? never : { type: 'xstate.route'; to: RoutableStateId; }), Cast>, Record>, ToProvidedActor, ToParameterizedObject, ToParameterizedObject, TDelay, ToStateValue, TTag, TInput, TOutput, TEmitted, TMeta, ToStateSchema>; assign: typeof assign>; sendTo: (...args: Parameters>) => ReturnType>; raise: typeof raise; log: typeof log; cancel: typeof cancel; stopChild: typeof stopChild; enqueueActions: typeof enqueueActions, ToParameterizedObject, ToParameterizedObject, TDelay, TEmitted>; emit: typeof emit; spawnChild: typeof spawnChild>; }; export declare function setup = {}, TChildrenMap extends Record = {}, TActions extends Record = {}, TGuards extends Record = {}, TDelay extends string = never, TTag extends string = string, TInput = NonReducibleUnknown, TOutput extends NonReducibleUnknown = NonReducibleUnknown, TEmitted extends EventObject = EventObject, TMeta extends MetaObject = MetaObject>({ schemas, actors, actions, guards, delays }: { schemas?: unknown; types?: SetupTypes; actors?: { [K in keyof TActors | Values]: K extends keyof TActors ? TActors[K] : never; }; actions?: { [K in keyof TActions]: ActionFunction, ToParameterizedObject, ToParameterizedObject, TDelay, TEmitted>; }; guards?: { [K in keyof TGuards]: GuardPredicate>; }; delays?: { [K in TDelay]: DelayConfig['params'], TEvent>; }; } & { [K in RequiredSetupKeys]: unknown; }): SetupReturn; export {};