@systemfsoftware/xstate 0.0.0-bootstrap.0 → 6.0.0-beta.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1832 @@
1
+ import "./index-DDWoKIF5.js";
2
+ import { $r as DelayMapFromNames, Ar as ActorSystemRuntime, Br as InspectionEvent, C as AnyActor, Ci as ValidateStateTargets, D as AnyEventObject, Di as createdInvokeConfig, Ei as WithDefault, Er as LogicFunction, F as AnyStateNode, Fn as StateValue, G as Cast, Hn as Subscription, Jr as MachineSnapshotSchema, Jt as OutputFrom, K as Compute, Kt as Observer, Ln as StateValueFromStateSchema, M as AnyMachineSnapshot, Mn as StateSchema, Mr as Clock, Oi as MachineSnapshot, Ot as InputFrom, P as AnyStateMachine, Qr as DelayDurationKey, Si as ValidateHistoryDefaults, Sr as AsyncSnapshot, T as AnyActorRef, Ti as WidenLiterals, U as CallbackActors, Un as SystemRegistry, Ur as ActorLogicValidator, Ut as MetaObject, Wt as NonReducibleUnknown, Y as ContextFrom, Yn as ToChildren, Yr as MachineVersionDescriptor, Zr as ChildCompletionEvents, _i as SchemaOrConfigOutput, _n as SnapshotFrom, _r as RequiredActorOptionsFor, ai as InferGuards, at as DoneStateEvent, bi as ValidateDelayReferences, bn as SpecialExecutableAction, br as AsyncActorLogic, bt as ExtractEvent, ci as InvokeInputArgs, ct as EnqueueObject, di as Next_InvokeConfigBase, dt as ErrorEvent, ei as DelaySourceMap, en as PersistedSnapshotFrom, f as ActorRefFromLogic, fi as Next_MachineConfig, ft as ErrorFrom, gi as OutputFromConfig, gn as SnapshotEvent, gr as Actor, gt as EventFromLogic, hi as Next_TransitionConfigOrTarget, hn as Snapshot, ht as EventFrom, ii as InferChildren, it as DoneActorEvent, jr as AnyActorSystem, l as ActorOptions, mi as Next_StateNodeConfig, mn as SingleOrArray, mt as EventDescriptor, ni as GuardSourceMap, oi as InferMachineInput, on as RegistryKeyForLogic, qn as TimeoutEvent, qr as MachineEventSchema, qt as OutputArg, ri as InferActions, rn as ProvidedActor, rt as DoNotInfer, si as InferOutput, ti as FinalStateConfigOutput, ui as Next_InvokeConfig, un as RoutableStateId, ur as StateMachine, ut as ErrorActorEvent, v as ActorTermination, vi as Sources, vr as RequiredActorOptionsKeys, vt as ExecutableActionObject, w as AnyActorLogic, wi as ValidateTopLevelFinalOutputs, x as AfterEvent, xi as ValidateEventDescriptors, y as ActorTimeoutEvent, yi as ValidateDelayNames, yt as ExecutableActionObjectFromLogic, z as AnyTransitionDefinition } from "./types-B2EAwOk-.js";
3
+ import { a as InferInternalEvents, c as SetupStateSchema, d as SetupStateSchemas, f as StandardSchemaV1, i as InferEvents, l as SetupStateType, n as EventObject, o as MachineContext, r as GuardSchemas, s as SetupSchemas, t as ActionSchemas } from "./base.types-DF8ZPiXj.js";
4
+ import "./effectDescriptor-EvNuy6U3.js";
5
+ /**
6
+ * Asserts that an event is of the given type or types, narrowing it, and
7
+ * throws when it is not. Given only the types, returns the assertion as a
8
+ * function.
9
+ * @public
10
+ */
11
+ declare function assertEvent<TEvent extends EventObject, TAssertedDescriptor extends EventDescriptor<TEvent>>(event: TEvent, type: TAssertedDescriptor | readonly TAssertedDescriptor[]): asserts event is ExtractEvent<TEvent, TAssertedDescriptor>;
12
+ declare function assertEvent<TEvent extends EventObject, TAssertedDescriptor extends EventDescriptor<TEvent>>(type: TAssertedDescriptor | readonly TAssertedDescriptor[]): (event: TEvent) => asserts event is ExtractEvent<TEvent, TAssertedDescriptor>;
13
+ type MergeChildren<TChildren extends Record<string, AnyActorRef | undefined>, TActor extends ProvidedActor> = [keyof TChildren] extends [never] ? Compute<ToChildren<TActor>> : Compute<TChildren>;
14
+ type MachineIdentity<TConfig> = {
15
+ readonly id: TConfig extends {
16
+ id: infer TId extends string;
17
+ } ? TId : '(machine)';
18
+ readonly version: TConfig extends {
19
+ version: infer TVersion extends string;
20
+ } ? TVersion : undefined;
21
+ };
22
+ type TransitionMetaFromSchemas<TMetaSchema extends StandardSchemaV1, TTransitionMetaSchema extends StandardSchemaV1> = StandardSchemaV1 extends TTransitionMetaSchema ? InferOutput<TMetaSchema, MetaObject> : InferOutput<TTransitionMetaSchema, MetaObject>;
23
+ /**
24
+ * Creates a state machine (statechart) with the given configuration.
25
+ *
26
+ * The state machine represents the pure logic of a state machine actor.
27
+ *
28
+ * @example
29
+ *
30
+ * ```ts
31
+ * import { createMachine } from '@systemfsoftware/xstate';
32
+ *
33
+ * const lightMachine = createMachine({
34
+ * id: 'light',
35
+ * initial: 'green',
36
+ * states: {
37
+ * green: {
38
+ * on: {
39
+ * TIMER: { target: 'yellow' }
40
+ * }
41
+ * },
42
+ * yellow: {
43
+ * on: {
44
+ * TIMER: { target: 'red' }
45
+ * }
46
+ * },
47
+ * red: {
48
+ * on: {
49
+ * TIMER: { target: 'green' }
50
+ * }
51
+ * }
52
+ * }
53
+ * });
54
+ *
55
+ * const lightActor = createActor(lightMachine);
56
+ * lightActor.start();
57
+ *
58
+ * lightActor.send({ type: 'TIMER' });
59
+ * ```
60
+ *
61
+ * @param config The state machine configuration.
62
+ * @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })`
63
+ * to provide machine sources instead.
64
+ * @public
65
+ */
66
+ declare function createMachine<TContextSchema extends StandardSchemaV1, const TEventSchemaMap extends Record<string, StandardSchemaV1>, const TInternalEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, const TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTransitionMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1>, _TEvent extends EventObject, TActor extends ProvidedActor, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TDelays extends string, TTag extends StandardSchemaV1.InferOutput<TTagSchema> & string, _TInput, const TSS extends StateSchema>(config: TSS & ValidateDelayReferences<TSS> & ValidateHistoryDefaults<TSS> & ValidateStateTargets<TSS> & ValidateEventDescriptors<TSS, NoInfer<InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>>> & Next_MachineConfig<TContextSchema, TEventSchemaMap, TInternalEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTransitionMetaSchema, TTagSchema, TChildrenSchemaMap, InferOutput<TContextSchema, MachineContext>, InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap> | ChildCompletionEvents<Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>>, Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap> & {
67
+ schemas: {
68
+ context: TContextSchema;
69
+ children?: TChildrenSchemaMap;
70
+ };
71
+ } & ValidateTopLevelFinalOutputs<TSS, InferOutput<TContextSchema, MachineContext>, InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>>): [TSS] extends [never] ? AnyStateMachine : StateMachine<InferOutput<TContextSchema, MachineContext>, (InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>) | ([RoutableStateId<TSS>] extends [never] ? never : {
72
+ type: 'xstate.route';
73
+ to: RoutableStateId<TSS>;
74
+ }), Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, StateValueFromStateSchema<TSS>, TTag & string, InferMachineInput<TInputSchema>, SchemaOrConfigOutput<TOutputSchema, TSS>, WithDefault<InferEvents<TEmittedSchemaMap>, AnyEventObject>, InferOutput<TMetaSchema, MetaObject>, // TMeta
75
+ TSS, // TStateSchema
76
+ TActionMap, TActorMap, TGuardMap, DelayMapFromNames<TDelays, TDelayMap>, InferInternalEvents<TInternalEventSchemaMap>, TransitionMetaFromSchemas<TMetaSchema, TTransitionMetaSchema>> & {
77
+ states: TSS;
78
+ } & MachineIdentity<TSS>;
79
+ declare function createMachine<TContext extends MachineContext = never, const TEventSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, const TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1, TTransitionMetaSchema extends StandardSchemaV1 = TMetaSchema, TTagSchema extends StandardSchemaV1 = StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, const TInternalEventSchemaMap extends Record<string, StandardSchemaV1> = {}, _TEvent extends EventObject = EventObject, TActor extends ProvidedActor = ProvidedActor, TActionMap extends Sources['actions'] = Sources['actions'], TActorMap extends Sources['actors'] = Sources['actors'], TGuardMap extends Sources['guards'] = Sources['guards'], TDelayMap extends Sources['delays'] = Sources['delays'], TDelays extends string = string, TTag extends StandardSchemaV1.InferOutput<TTagSchema> & string = StandardSchemaV1.InferOutput<TTagSchema> & string, _TInput = unknown, const TSS extends StateSchema = StateSchema>(config: TSS & ValidateDelayReferences<TSS> & ValidateHistoryDefaults<TSS> & ValidateStateTargets<TSS> & ValidateEventDescriptors<TSS, NoInfer<InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>>> & Next_MachineConfig<StandardSchemaV1, TEventSchemaMap, TInternalEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTransitionMetaSchema, TTagSchema, TChildrenSchemaMap, WidenLiterals<TContext>, InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap> | ChildCompletionEvents<Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>>, Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap, false> & {
80
+ schemas?: {
81
+ context?: never;
82
+ };
83
+ context?: TContext | ((_: {
84
+ spawn: any;
85
+ actors: TActorMap;
86
+ input: InferOutput<TInputSchema, unknown>;
87
+ self: any;
88
+ }) => TContext);
89
+ } & ValidateTopLevelFinalOutputs<TSS, WidenLiterals<TContext>, InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>>): [TSS] extends [never] ? AnyStateMachine : StateMachine<WidenLiterals<TContext>, (InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>) | ([RoutableStateId<TSS>] extends [never] ? never : {
90
+ type: 'xstate.route';
91
+ to: RoutableStateId<TSS>;
92
+ }), Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, StateValueFromStateSchema<TSS>, TTag & string, InferMachineInput<TInputSchema>, SchemaOrConfigOutput<TOutputSchema, TSS>, WithDefault<InferEvents<TEmittedSchemaMap>, AnyEventObject>, InferOutput<TMetaSchema, MetaObject>, // TMeta
93
+ TSS, // TStateSchema
94
+ TActionMap, TActorMap, TGuardMap, DelayMapFromNames<TDelays, TDelayMap>, InferInternalEvents<TInternalEventSchemaMap>, TransitionMetaFromSchemas<TMetaSchema, TTransitionMetaSchema>> & {
95
+ states: TSS;
96
+ } & MachineIdentity<TSS>;
97
+ /**
98
+ * Builds a machine from a config produced by a compiler (JSON, SCXML) without
99
+ * running the author-config v5 diagnostics.
100
+ *
101
+ * @experimental Used by `@xstate/scxml`; not part of the stable API.
102
+ */
103
+ declare function createMachineFromCompiledConfig(config: any): any;
104
+ /** @public */
105
+ declare function createStateConfig<TContextSchema extends StandardSchemaV1, TEventSchema extends StandardSchemaV1, TEmittedSchema extends StandardSchemaV1, _TInputSchema extends StandardSchemaV1, const TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTransitionMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, _TEvent extends StandardSchemaV1.InferOutput<TEventSchema> & EventObject, // TODO: consider using a stricter `EventObject` here
106
+ _TActor extends ProvidedActor, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TDelays extends string, _TTag extends StandardSchemaV1.InferOutput<TTagSchema> & string, _TInput, const TSS extends StateSchema>(config: TSS & Next_StateNodeConfig<InferOutput<TContextSchema, MachineContext>, DoNotInfer<StandardSchemaV1.InferOutput<TEventSchema> & EventObject>, DoNotInfer<TDelays>, DoNotInfer<StandardSchemaV1.InferOutput<TTagSchema> & string>, DoNotInfer<StandardSchemaV1.InferOutput<TOutputSchema>>, DoNotInfer<StandardSchemaV1.InferOutput<TEmittedSchema> & EventObject>, DoNotInfer<InferOutput<TMetaSchema, MetaObject>>, DoNotInfer<Record<string, AnyActorRef | undefined>>, DoNotInfer<TActionMap>, DoNotInfer<TActorMap>, DoNotInfer<TGuardMap>, DoNotInfer<TDelayMap>, any, any, any, any, DoNotInfer<TransitionMetaFromSchemas<TMetaSchema, TTransitionMetaSchema>>>): typeof config;
107
+ interface RaiseJSON {
108
+ type: '@xstate.raise';
109
+ event: EventObject;
110
+ id?: string;
111
+ delay?: number;
112
+ }
113
+ interface CancelJSON {
114
+ type: '@xstate.cancel';
115
+ id: string;
116
+ }
117
+ interface LogJSON {
118
+ type: '@xstate.log';
119
+ args: any[];
120
+ }
121
+ interface EmitJSON {
122
+ type: '@xstate.emit';
123
+ event: AnyEventObject;
124
+ }
125
+ interface AssignJSON {
126
+ type: '@xstate.assign';
127
+ context: MachineContext;
128
+ }
129
+ type BuiltInActionJSON = RaiseJSON | CancelJSON | LogJSON | EmitJSON | AssignJSON;
130
+ interface CustomActionJSON {
131
+ type: string;
132
+ params?: unknown;
133
+ }
134
+ /** @public */
135
+ type ActionJSON = CustomActionJSON | BuiltInActionJSON | ExpressionJSON | CodeJSON;
136
+ /** @public */
137
+ interface GuardJSON {
138
+ type: string;
139
+ params?: unknown;
140
+ }
141
+ interface ExpressionJSON {
142
+ '@expr': string;
143
+ '@lang'?: string;
144
+ }
145
+ interface CodeJSON {
146
+ '@code': string;
147
+ '@lang'?: string;
148
+ }
149
+ type ResolvableJSON = ExpressionJSON | CodeJSON;
150
+ type ConditionJSON = GuardJSON | ResolvableJSON;
151
+ interface ChoiceBranchJSON {
152
+ when?: ConditionJSON;
153
+ target: string | string[];
154
+ context?: MachineContext;
155
+ input?: unknown;
156
+ description?: string;
157
+ reenter?: boolean;
158
+ meta?: MetaObject;
159
+ }
160
+ /** @public */
161
+ interface InvokeJSON {
162
+ id?: string;
163
+ registryKey?: string;
164
+ src: string;
165
+ input?: unknown;
166
+ onDone?: TransitionConfigJSON | TransitionConfigJSON[];
167
+ onError?: TransitionConfigJSON | TransitionConfigJSON[];
168
+ onSnapshot?: TransitionConfigJSON | TransitionConfigJSON[];
169
+ timeout?: number | string | ResolvableJSON;
170
+ onTimeout?: TransitionConfigJSON | TransitionConfigJSON[];
171
+ }
172
+ /** @public */
173
+ interface TransitionJSON {
174
+ target?: string | string[];
175
+ matches?: Record<string, unknown>;
176
+ context?: MachineContext;
177
+ actions?: ActionJSON[];
178
+ guard?: ConditionJSON;
179
+ description?: string;
180
+ reenter?: boolean;
181
+ meta?: MetaObject;
182
+ input?: unknown;
183
+ }
184
+ type TransitionConfigJSON = TransitionJSON | ResolvableJSON;
185
+ /** @public */
186
+ interface StateNodeJSON {
187
+ id?: string;
188
+ key?: string;
189
+ type?: 'atomic' | 'compound' | 'parallel' | 'final' | 'history' | 'choice';
190
+ initial?: string;
191
+ states?: Record<string, StateNodeJSON>;
192
+ on?: Record<string, TransitionConfigJSON | TransitionConfigJSON[]>;
193
+ onError?: TransitionConfigJSON | TransitionConfigJSON[];
194
+ after?: Record<string, TransitionConfigJSON | TransitionConfigJSON[]>;
195
+ always?: TransitionConfigJSON | TransitionConfigJSON[];
196
+ choice?: ChoiceBranchJSON[] | ResolvableJSON;
197
+ route?: {
198
+ description?: string;
199
+ reenter?: boolean;
200
+ meta?: MetaObject;
201
+ guard?: string;
202
+ input?: Record<string, unknown>;
203
+ } | ResolvableJSON;
204
+ invoke?: InvokeJSON | InvokeJSON[];
205
+ entry?: ActionJSON | ActionJSON[];
206
+ exit?: ActionJSON | ActionJSON[];
207
+ meta?: MetaObject;
208
+ description?: string;
209
+ tags?: string[];
210
+ input?: unknown;
211
+ timeout?: number | string | ResolvableJSON;
212
+ onTimeout?: TransitionConfigJSON | TransitionConfigJSON[];
213
+ history?: 'shallow' | 'deep';
214
+ target?: string | [string, ...string[]];
215
+ output?: unknown;
216
+ context?: Record<string, unknown>;
217
+ }
218
+ /** @public */
219
+ interface MachineJSON extends StateNodeJSON {
220
+ '@exprLang'?: string;
221
+ version?: string;
222
+ actions?: Record<string, ActionJSON | ActionJSON[]>;
223
+ guards?: Record<string, {
224
+ when: ConditionJSON;
225
+ }>;
226
+ actors?: Record<string, unknown>;
227
+ delays?: Record<string, number | string | {
228
+ duration: number | string | ResolvableJSON;
229
+ }>;
230
+ schemas?: Record<string, unknown>;
231
+ /**
232
+ * Event types that only the machine itself (and its children) may send;
233
+ * external senders are rejected with reason `internalEvent`.
234
+ */
235
+ internalEvents?: string[];
236
+ }
237
+ type EvaluatorSlot = 'context' | 'guard' | 'choice' | 'action' | 'actionParams' | 'transition' | 'input' | 'output' | 'delay' | 'transitionContext' | 'unknown';
238
+ type EvaluatorKind = 'expr' | 'code';
239
+ interface EvaluatorArgs {
240
+ source: string;
241
+ kind: EvaluatorKind;
242
+ slot: EvaluatorSlot;
243
+ scope: Record<string, unknown>;
244
+ path: string;
245
+ }
246
+ interface MachineSources {
247
+ actions?: Record<string, (...args: any[]) => unknown>;
248
+ guards?: Record<string, (...args: any[]) => boolean>;
249
+ actors?: Record<string, AnyActorLogic>;
250
+ delays?: Record<string, number | ((...args: any[]) => number)>;
251
+ evaluators?: Record<string, (args: EvaluatorArgs) => unknown>;
252
+ }
253
+ /** @public */
254
+ declare function createMachineFromConfig(json: MachineJSON, sources?: MachineSources): AnyStateMachine;
255
+ type VersionedStateMachine = AnyStateMachine & {
256
+ version: string;
257
+ snapshotSchema: MachineSnapshotSchema;
258
+ eventSchema: MachineEventSchema;
259
+ };
260
+ type VersionEntry = MachineVersionDescriptor;
261
+ /** @public */
262
+ type PersistedSnapshotDataFrom<TMachine extends AnyStateMachine> = Snapshot<unknown> & {
263
+ context: ContextFrom<TMachine>;
264
+ [key: string]: unknown;
265
+ };
266
+ /** @public */
267
+ type ParsedPersistedSnapshot<TEntries extends readonly VersionEntry[]> = { [K in keyof TEntries]: TEntries[K] extends VersionEntry ? TEntries[K] extends VersionedStateMachine ? {
268
+ source: TEntries[K];
269
+ machine: TEntries[K];
270
+ snapshot: PersistedSnapshotFromEntry<TEntries[K]>;
271
+ } : {
272
+ source: TEntries[K];
273
+ snapshot: PersistedSnapshotFromEntry<TEntries[K]>;
274
+ } : never; }[number];
275
+ /** @public */
276
+ type MachineVersionsOptions<TEntries extends readonly VersionEntry[]> = {
277
+ unversioned?: SnapshotSourceVersion<TEntries>;
278
+ };
279
+ type MaybePromise<T> = T | PromiseLike<T>;
280
+ type MachineVersion<TEntries extends readonly VersionEntry[]> = Extract<TEntries[number], VersionedStateMachine>['version'];
281
+ type SnapshotSourceVersion<TEntries extends readonly VersionEntry[]> = { [K in keyof TEntries]: TEntries[K] extends VersionedStateMachine | {
282
+ snapshotSchema: MachineSnapshotSchema;
283
+ } ? TEntries[K]['version'] : never; }[number];
284
+ type EventSourceVersion<TEntries extends readonly VersionEntry[]> = { [K in keyof TEntries]: TEntries[K] extends VersionedStateMachine | {
285
+ eventSchema: MachineEventSchema;
286
+ } ? TEntries[K]['version'] : never; }[number];
287
+ type MachineForVersion<TEntries extends readonly VersionEntry[], TVersion extends string> = { [K in keyof TEntries]: TEntries[K] extends VersionedStateMachine ? TEntries[K]['version'] extends TVersion ? TEntries[K] : never : never; }[number];
288
+ type SnapshotEntryForVersion<TEntries extends readonly VersionEntry[], TVersion extends string> = { [K in keyof TEntries]: TEntries[K] extends VersionedStateMachine | {
289
+ snapshotSchema: MachineSnapshotSchema;
290
+ } ? TEntries[K]['version'] extends TVersion ? TEntries[K] : never : never; }[number];
291
+ type EventEntryForVersion<TEntries extends readonly VersionEntry[], TVersion extends string> = { [K in keyof TEntries]: TEntries[K] extends VersionedStateMachine | {
292
+ eventSchema: MachineEventSchema;
293
+ } ? TEntries[K]['version'] extends TVersion ? TEntries[K] : never : never; }[number];
294
+ type PersistedSnapshotFromEntry<TEntry extends VersionEntry> = TEntry extends {
295
+ snapshotSchema: infer TSchema extends MachineSnapshotSchema;
296
+ } ? StandardSchemaV1.InferOutput<TSchema> : TEntry extends VersionedStateMachine ? PersistedSnapshotFrom<TEntry> : never;
297
+ type EventFromEntry<TEntry extends VersionEntry> = TEntry extends {
298
+ eventSchema: infer TSchema extends MachineEventSchema;
299
+ } ? StandardSchemaV1.InferOutput<TSchema> : TEntry extends VersionedStateMachine ? EventFrom<TEntry> : never;
300
+ /** @public */
301
+ type PersistedSnapshotSource = {
302
+ id?: string | undefined;
303
+ version?: string | undefined;
304
+ };
305
+ /** @public */
306
+ type SnapshotMigrationHandlers<TEntries extends readonly VersionEntry[], TTarget extends VersionedStateMachine> = { [TVersion in Exclude<SnapshotSourceVersion<TEntries>, TTarget['version']>]?: (snapshot: PersistedSnapshotFromEntry<SnapshotEntryForVersion<TEntries, TVersion>>) => MaybePromise<PersistedSnapshotDataFrom<TTarget>>; } & {
307
+ '*'?: (snapshot: unknown, source: PersistedSnapshotSource) => MaybePromise<PersistedSnapshotDataFrom<TTarget>>;
308
+ };
309
+ /** @public */
310
+ type MigrateSnapshotOptions<TEntries extends readonly VersionEntry[], TTargetVersion extends MachineVersion<TEntries>> = {
311
+ to: TTargetVersion;
312
+ migrations: SnapshotMigrationHandlers<TEntries, MachineForVersion<TEntries, TTargetVersion>>;
313
+ };
314
+ /** @public */
315
+ type EventHistorySource = {
316
+ id?: string;
317
+ version?: string;
318
+ };
319
+ /** @public */
320
+ type EventAdapterHandlers<TEntries extends readonly VersionEntry[], TTarget extends VersionedStateMachine> = { [TVersion in Exclude<EventSourceVersion<TEntries>, TTarget['version']>]?: (events: readonly EventFromEntry<EventEntryForVersion<TEntries, TVersion>>[]) => MaybePromise<readonly EventFrom<TTarget>[]>; } & {
321
+ '*'?: (events: readonly unknown[], source: EventHistorySource) => MaybePromise<readonly EventFrom<TTarget>[]>;
322
+ };
323
+ /** @public */
324
+ type AdaptEventsOptions<TEntries extends readonly VersionEntry[], TTargetVersion extends MachineVersion<TEntries>> = {
325
+ from: EventHistorySource;
326
+ to: TTargetVersion;
327
+ adapters: EventAdapterHandlers<TEntries, MachineForVersion<TEntries, TTargetVersion>>;
328
+ };
329
+ /**
330
+ * Creates migration and adaptation utilities for versions of one machine.
331
+ *
332
+ * @public
333
+ */
334
+ declare function machineVersions<const TEntries extends readonly [VersionEntry, ...VersionEntry[]]>(entries: TEntries, options?: MachineVersionsOptions<TEntries>): {
335
+ parseSnapshot: (raw: unknown) => Promise<ParsedPersistedSnapshot<TEntries>>;
336
+ adaptEvents<TTargetVersion extends MachineVersion<TEntries>>(events: readonly unknown[], adaptationOptions: AdaptEventsOptions<TEntries, TTargetVersion>): Promise<EventFrom<MachineForVersion<TEntries, TTargetVersion>>[]>;
337
+ migrateSnapshot<TTargetVersion extends MachineVersion<TEntries>>(raw: unknown, migrationOptions: MigrateSnapshotOptions<TEntries, TTargetVersion>): Promise<PersistedSnapshotFrom<MachineForVersion<TEntries, TTargetVersion>>>;
338
+ };
339
+ type StateSchemaFromSnapshot<TSnapshot extends AnyMachineSnapshot> = TSnapshot extends MachineSnapshot<infer _TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TOutput, infer _TMeta, infer TStateSchema extends StateSchema> ? TStateSchema : StateSchema;
340
+ /**
341
+ * A mapper object that defines how to transform a snapshot based on its state.
342
+ * Can be nested to match the state hierarchy of the machine.
343
+ */
344
+ type StateSchemaMapper<TSnapshot extends AnyMachineSnapshot, T extends StateSchema, TResult> = {
345
+ /** Maps the snapshot to a value when this state is active. */
346
+ map?: (snapshot: TSnapshot) => TResult;
347
+ /** Nested mappers for child states. */
348
+ states?: { [K in keyof T['states']]?: T['states'][K] extends StateSchema ? StateSchemaMapper<TSnapshot, T['states'][K], TResult> : never; };
349
+ };
350
+ /**
351
+ * Maps a machine snapshot to an array of result objects based on active states.
352
+ *
353
+ * Collects results from the `map` functions in the mapper object for every
354
+ * active state node. Each state comes before its ancestors (most specific
355
+ * state first); otherwise results follow the order the states are declared in
356
+ * the machine. Called with the mapper alone, it returns a function that takes
357
+ * the snapshot.
358
+ *
359
+ * @public
360
+ */
361
+ declare function mapState<T extends AnyMachineSnapshot, TResult>(mapper: StateSchemaMapper<T, StateSchemaFromSnapshot<T>, TResult>): (snapshot: T) => {
362
+ stateNode: AnyStateNode;
363
+ result: TResult;
364
+ }[];
365
+ declare function mapState<T extends AnyMachineSnapshot, TResult>(snapshot: T, mapper: StateSchemaMapper<T, StateSchemaFromSnapshot<T>, TResult>): {
366
+ stateNode: AnyStateNode;
367
+ result: TResult;
368
+ }[];
369
+ /** @public */
370
+ interface CodeExpression {
371
+ '@code': string;
372
+ '@lang': 'ts';
373
+ }
374
+ /**
375
+ * Returns the JSON-serializable definition of a machine.
376
+ *
377
+ * Inline functions are represented as `{ "@code": string, "@lang": "ts" }`. A
378
+ * machine created via `createMachineFromConfig` returns its original JSON
379
+ * config (lossless round-trip):
380
+ *
381
+ * ```ts
382
+ * import { serializeMachine, createMachineFromConfig } from '@systemfsoftware/xstate';
383
+ *
384
+ * const json = serializeMachine(machine);
385
+ * const revived = createMachineFromConfig(
386
+ * JSON.parse(JSON.stringify(json))
387
+ * );
388
+ * ```
389
+ *
390
+ * @public
391
+ */
392
+ declare function serializeMachine(machine: AnyStateMachine): Record<string, unknown>;
393
+ /**
394
+ * Converts a machine config (as passed to `createMachine`) to its JSON-safe
395
+ * definition.
396
+ *
397
+ * @public
398
+ */
399
+ declare function machineConfigToJSON(config: Record<string, unknown>): Record<string, unknown>;
400
+ /**
401
+ * Switches a running machine actor to another version of its machine, for
402
+ * development hot reloading. The live snapshot is carried over in memory and
403
+ * never serialized, so context may hold values that `getPersistedSnapshot()`
404
+ * cannot represent (DOM nodes, cycles).
405
+ *
406
+ * Children whose logic is unchanged by identity keep running; other children
407
+ * are stopped and restarted from the new machine's logic. Returns `false`,
408
+ * leaving the actor unchanged, when the actor is not a running machine actor
409
+ * with the same machine id, a state or history id does not exist on the new
410
+ * machine, a child's logic cannot be resolved statically, context or a pending
411
+ * timer references a child that would restart, or the new machine's validator
412
+ * rejects the snapshot.
413
+ *
414
+ * @experimental Used by framework integrations; not part of the stable API.
415
+ */
416
+ declare function hotSwapActorLogic(actorRef: AnyActorRef, machine: AnyStateMachine): boolean;
417
+ /** @public */
418
+ type SetupConfig<TSchemas extends SetupSchemas, TStates extends Record<string, SetupStateSchema>, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TValidator extends ActorLogicValidator | undefined = ActorLogicValidator | undefined> = {
419
+ validator?: TValidator;
420
+ schemas?: TSchemas;
421
+ states?: TStates;
422
+ actions?: TActionMap;
423
+ actors?: TActorMap;
424
+ guards?: TGuardMap & SetupGuardSources<NoInfer<TSchemas>>;
425
+ delays?: TDelayMap & SetupDelaySources<NoInfer<TSchemas>>;
426
+ };
427
+ /**
428
+ * Contextual types for guard/delay source maps passed to `setup()`, derived
429
+ * from the same call's `schemas` (context/events). These intersect the
430
+ * inferred source-map type parameters so inline functions get typed args
431
+ * without hand-annotating.
432
+ */
433
+ type SetupGuardSources<TSchemas> = GuardSourceMap<SetupContext<TSchemas, StandardSchemaV1>, SetupEvents<TSchemas, Record<string, StandardSchemaV1>>>;
434
+ type SetupDelaySources<TSchemas> = DelaySourceMap<SetupContext<TSchemas, StandardSchemaV1>, SetupEvents<TSchemas, Record<string, StandardSchemaV1>>>;
435
+ /**
436
+ * Contextual companion for the whole-config `setup()` overload: gives inline
437
+ * `guards`/`delays` functions typed args from the config's own `schemas`.
438
+ */
439
+ type SetupSourceCompanions<TSchemas> = {
440
+ guards?: SetupGuardSources<TSchemas>;
441
+ delays?: SetupDelaySources<TSchemas>;
442
+ };
443
+ type MergeRecord<TBase, TExtend> = Omit<TBase, keyof TExtend> & TExtend;
444
+ /**
445
+ * Mirrors the runtime `mergeSchemas`: scalar schema keys (`context`, `input`,
446
+ * ...) are overridden whole, while map-valued keys (`events`, `emitted`,
447
+ * `children`, `actions`, `guards`) are merged entry-by-entry with extension
448
+ * entries winning, so base-declared entries stay visible to extension sources.
449
+ */
450
+ type MergedSetupSchemas<TBaseSchemas, TExtendSchemas> = { [K in keyof TBaseSchemas | keyof TExtendSchemas]: K extends 'events' | 'emitted' | 'children' | 'actions' | 'guards' ? MergeRecord<K extends keyof TBaseSchemas ? NonNullable<TBaseSchemas[K]> : {}, K extends keyof TExtendSchemas ? NonNullable<TExtendSchemas[K]> : {}> : K extends keyof TExtendSchemas ? TExtendSchemas[K] : K extends keyof TBaseSchemas ? TBaseSchemas[K] : never; };
451
+ /** @public */
452
+ type AnySetupConfig = SetupConfig<SetupSchemas, Record<string, SetupStateSchema>, Sources['actions'], Sources['actors'], Sources['guards'], Sources['delays'], ActorLogicValidator | undefined>;
453
+ interface RuntimeValidationDoesNotSupportTransformingSchemas {
454
+ readonly __xstate_error: 'Runtime validation does not support schemas with different input and output types';
455
+ }
456
+ type IsAny<T> = 0 extends 1 & T ? true : false;
457
+ type AssertNonTransformingSchema<TSchema extends StandardSchemaV1> = IsAny<StandardSchemaV1.InferInput<TSchema>> extends true ? TSchema : IsAny<StandardSchemaV1.InferOutput<TSchema>> extends true ? TSchema : [StandardSchemaV1.InferInput<TSchema>, StandardSchemaV1.InferOutput<TSchema>] extends [StandardSchemaV1.InferOutput<TSchema>, StandardSchemaV1.InferInput<TSchema>] ? TSchema : RuntimeValidationDoesNotSupportTransformingSchemas;
458
+ type ValidateSchemaMap<TMap> = TMap extends Record<string, StandardSchemaV1> ? { [K in keyof TMap]: TMap[K] extends StandardSchemaV1 ? AssertNonTransformingSchema<TMap[K]> : TMap[K]; } : TMap;
459
+ type ValidateSetupSchemas<TSchemas> = TSchemas extends SetupSchemas ? { [K in keyof TSchemas]: K extends 'events' | 'internalEvents' | 'emitted' | 'children' ? ValidateSchemaMap<TSchemas[K]> : K extends 'context' | 'input' | 'output' ? TSchemas[K] extends StandardSchemaV1 ? AssertNonTransformingSchema<TSchemas[K]> : TSchemas[K] : TSchemas[K]; } : TSchemas;
460
+ type ValidateSetupStates<TStates> = TStates extends Record<string, SetupStateSchema> ? { [K in keyof TStates]: TStates[K] extends SetupStateSchema ? Omit<TStates[K], 'schemas' | 'states'> & {
461
+ schemas?: TStates[K]['schemas'] extends SetupStateSchemas ? { [P in keyof TStates[K]['schemas']]: TStates[K]['schemas'][P] extends StandardSchemaV1 ? AssertNonTransformingSchema<TStates[K]['schemas'][P]> : TStates[K]['schemas'][P]; } : TStates[K]['schemas'];
462
+ states?: TStates[K]['states'] extends Record<string, SetupStateSchema> ? ValidateSetupStates<TStates[K]['states']> : TStates[K]['states'];
463
+ } : TStates[K]; } : TStates;
464
+ type RuntimeValidationConstraint<TSchemas, TStates, TValidator> = [TValidator] extends [ActorLogicValidator] ? {
465
+ schemas?: ValidateSetupSchemas<TSchemas>;
466
+ states?: ValidateSetupStates<TStates>;
467
+ } : unknown;
468
+ type RuntimeValidationCompatibility<TSchemas, TStates, TValidator> = [TValidator] extends [ActorLogicValidator] ? [TSchemas] extends [ValidateSetupSchemas<TSchemas>] ? [TStates] extends [ValidateSetupStates<TStates>] ? unknown : RuntimeValidationDoesNotSupportTransformingSchemas : RuntimeValidationDoesNotSupportTransformingSchemas : unknown;
469
+ declare const inheritedValidator: unique symbol;
470
+ type InheritedValidator = typeof inheritedValidator;
471
+ type ResolveExtendedValidator<TBase, TExtension> = [TExtension] extends [InheritedValidator] ? TBase : Exclude<TExtension, InheritedValidator>;
472
+ type ExtendValidatorConfig<TExtension> = [TExtension] extends [InheritedValidator] ? {
473
+ validator?: never;
474
+ } : {
475
+ validator: TExtension;
476
+ };
477
+ type SetupExtensionConfig<TBaseSchemas, TBaseStates, TBaseValidator, TExtendSchemas extends SetupSchemas, TExtendStates extends Record<string, SetupStateSchema>, TExtendActionMap extends Sources['actions'], TExtendActorMap extends Sources['actors'], TExtendGuardMap extends Sources['guards'], TExtendDelayMap extends Sources['delays'], TExtendValidator extends ActorLogicValidator | undefined | InheritedValidator> = Omit<SetupConfig<TExtendSchemas, TExtendStates, TExtendActionMap, TExtendActorMap, TExtendGuardMap, TExtendDelayMap>, 'validator' | 'guards' | 'delays'> & {
478
+ guards?: TExtendGuardMap & SetupGuardSources<NoInfer<MergedSetupSchemas<TBaseSchemas, TExtendSchemas>>>;
479
+ delays?: TExtendDelayMap & SetupDelaySources<NoInfer<MergedSetupSchemas<TBaseSchemas, TExtendSchemas>>>;
480
+ } & ExtendValidatorConfig<TExtendValidator> & RuntimeValidationCompatibility<NoInfer<TBaseSchemas>, NoInfer<TBaseStates>, ResolveExtendedValidator<TBaseValidator, TExtendValidator>> & RuntimeValidationConstraint<NoInfer<TExtendSchemas>, NoInfer<TExtendStates>, ResolveExtendedValidator<TBaseValidator, TExtendValidator>>;
481
+ type InlineMachineSchemas<TContextSchema, TEventSchemaMap, TInternalEventSchemaMap, TEmittedSchemaMap, TActionSchemaMap, TGuardSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTransitionMetaSchema, TTagSchema, TChildrenSchemaMap> = {
482
+ context?: TContextSchema;
483
+ events?: TEventSchemaMap;
484
+ internalEvents?: TInternalEventSchemaMap;
485
+ emitted?: TEmittedSchemaMap;
486
+ actions?: TActionSchemaMap;
487
+ guards?: TGuardSchemaMap;
488
+ input?: TInputSchema;
489
+ output?: TOutputSchema;
490
+ meta?: TMetaSchema;
491
+ transitionMeta?: TTransitionMetaSchema;
492
+ tags?: TTagSchema;
493
+ children?: TChildrenSchemaMap;
494
+ };
495
+ type MachineConfigStates<TConfig> = TConfig extends {
496
+ states?: infer TStates;
497
+ } ? TStates : {};
498
+ type MachineConfigSchemas<TConfig> = TConfig extends {
499
+ schemas?: infer TSchemas;
500
+ } ? TSchemas : {};
501
+ /** @public */
502
+ type SystemConfig<TSystemRegistry extends SystemRegistry> = {
503
+ registry?: TSystemRegistry;
504
+ };
505
+ /** @public */
506
+ type SystemActorMap<TSystemRegistry extends SystemRegistry> = { [K in keyof TSystemRegistry & string]: ActorRefFromLogic<TSystemRegistry[K]>; };
507
+ type SetupMachineIdentity<TConfig> = {
508
+ readonly id: TConfig extends {
509
+ id: infer TId extends string;
510
+ } ? TId : '(machine)';
511
+ readonly version: TConfig extends {
512
+ version: infer TVersion extends string;
513
+ } ? TVersion : undefined;
514
+ };
515
+ /** @public */
516
+ type SystemRuntime<TSystemRegistry extends SystemRegistry> = Omit<AnyActorSystem, 'get' | 'getAll'> & {
517
+ get<K extends keyof SystemActorMap<TSystemRegistry> & string>(key: K): SystemActorMap<TSystemRegistry>[K] | undefined;
518
+ getAll(): Partial<SystemActorMap<TSystemRegistry>>;
519
+ };
520
+ type LogicMatchesRegistryKey<TLogic, TSystemLogic> = TLogic extends AnyActorLogic ? TSystemLogic extends AnyActorLogic ? [TLogic] extends [TSystemLogic] ? true : [TSystemLogic] extends [TLogic] ? true : ActorRefFromLogic<TLogic> extends ActorRefFromLogic<TSystemLogic> ? true : false : false : false;
521
+ type RegistryKeyMatchesSrc<TKey extends string, TSrc, TSystemRegistry extends SystemRegistry, TActorMap extends Sources['actors']> = TKey extends keyof TSystemRegistry & string ? TSrc extends keyof TActorMap & string ? LogicMatchesRegistryKey<TActorMap[TSrc], TSystemRegistry[TKey]> : TSrc extends AnyActorLogic ? LogicMatchesRegistryKey<TSrc, TSystemRegistry[TKey]> : true : false;
522
+ type ValidateSystemInvoke<TInvoke, TSystemRegistry extends SystemRegistry, TActorMap extends Sources['actors']> = TInvoke extends readonly unknown[] ? { [K in keyof TInvoke]: TInvoke[K] & ValidateSystemInvoke<TInvoke[K], TSystemRegistry, TActorMap>; } : TInvoke extends {
523
+ registryKey: infer TKey;
524
+ } ? TKey extends string ? TInvoke extends {
525
+ src: infer TSrc;
526
+ } ? RegistryKeyMatchesSrc<TKey, TSrc, TSystemRegistry, TActorMap> extends true ? unknown : {
527
+ registryKey: never;
528
+ } : TKey extends keyof TSystemRegistry & string ? unknown : {
529
+ registryKey: never;
530
+ } : {
531
+ registryKey: never;
532
+ } : unknown;
533
+ type ValidateRegistryKeys<TConfig, TSystemRegistry extends SystemRegistry, TActorMap extends Sources['actors']> = string extends keyof TSystemRegistry ? unknown : (TConfig extends {
534
+ invoke: infer TInvoke;
535
+ } ? {
536
+ invoke: TInvoke & ValidateSystemInvoke<TInvoke, TSystemRegistry, TActorMap>;
537
+ } : unknown) & (TConfig extends {
538
+ states: infer TStates;
539
+ } ? {
540
+ states: { [K in keyof TStates]: TStates[K] & ValidateRegistryKeys<TStates[K], TSystemRegistry, TActorMap>; };
541
+ } : unknown);
542
+ type SetupSchema<TSchemas, TKey extends keyof SetupSchemas> = TKey extends keyof TSchemas ? TSchemas[TKey] extends StandardSchemaV1 ? TSchemas[TKey] : never : never;
543
+ type SetupSchemaMap<TSchemas, TKey extends 'events' | 'internalEvents' | 'emitted' | 'children'> = TKey extends keyof TSchemas ? TSchemas[TKey] extends Record<string, StandardSchemaV1> ? TSchemas[TKey] : never : never;
544
+ type SetupActionSchemaMap<TSchemas> = 'actions' extends keyof TSchemas ? TSchemas['actions'] extends ActionSchemas ? TSchemas['actions'] : never : never;
545
+ type SetupGuardSchemaMap<TSchemas> = 'guards' extends keyof TSchemas ? TSchemas['guards'] extends GuardSchemas ? TSchemas['guards'] : never : never;
546
+ type SetupOrConfigSchema<TSchemas, TKey extends Exclude<keyof SetupSchemas, 'events' | 'actions' | 'guards' | 'emitted' | 'children'>, TConfigSchema extends StandardSchemaV1> = [SetupSchema<TSchemas, TKey>] extends [never] ? TConfigSchema : SetupSchema<TSchemas, TKey>;
547
+ type SetupOrConfigSchemaMap<TSchemas, TKey extends 'events' | 'internalEvents' | 'emitted' | 'children', TConfigSchemaMap extends Record<string, StandardSchemaV1>> = [SetupSchemaMap<TSchemas, TKey>] extends [never] ? TConfigSchemaMap : SetupSchemaMap<TSchemas, TKey>;
548
+ type SetupStateKeys<TStateSchemas extends Record<string, SetupStateSchema>> = keyof TStateSchemas & string;
549
+ type HasExplicitSetupStateContracts<TStateSchemas extends Record<string, SetupStateSchema>> = string extends keyof TStateSchemas ? false : [keyof TStateSchemas] extends [never] ? false : true;
550
+ type UncheckedSetupStateSchema = {
551
+ schemas?: never;
552
+ states?: never;
553
+ };
554
+ type UncheckedSetupStateSchemas = Record<string, UncheckedSetupStateSchema>;
555
+ type SetupStateKey<TStateSchemas extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStateSchemas> ? string : [SetupStateKeys<TStateSchemas>] extends [never] ? string : SetupStateKeys<TStateSchemas>;
556
+ type StrictSetupStatePaths<TStateSchemas extends Record<string, SetupStateSchema>> = [SetupStateKeys<TStateSchemas>] extends [never] ? never : StatePaths<TStateSchemas>;
557
+ type SetupRelativeStateTarget<TStateSchemas extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStateSchemas> ? `.${string}` : [SetupStateKeys<TStateSchemas>] extends [never] ? '.' : '.' | `.${StatePaths<TStateSchemas> & string}`;
558
+ type SetupStateTarget<TStateSchemas extends Record<string, SetupStateSchema>> = TStateSchemas extends StrictSetupStateTargetsFlag ? StrictSetupStatePaths<TStateSchemas> | SetupRelativeStateTarget<RelativeSetupStateSchemas<TStateSchemas>> | `#${string}` : string extends SetupStateKeys<TStateSchemas> ? string : [SetupStateKeys<TStateSchemas>] extends [never] ? string : StatePaths<TStateSchemas> | `.${string}` | `#${string}`;
559
+ type KnownSetupStateTarget<TStateSchemas extends Record<string, SetupStateSchema>> = string extends StatePaths<TStateSchemas> ? string extends StatePaths<RelativeSetupStateSchemas<TStateSchemas>> ? never : SetupRelativeStateTarget<RelativeSetupStateSchemas<TStateSchemas>> | RootSetupStateIdTarget<RootSetupStateSchemas<TStateSchemas>> : (StrictSetupStatePaths<TStateSchemas> & string) | SetupRelativeStateTarget<RelativeSetupStateSchemas<TStateSchemas>> | RootSetupStateIdTarget<RootSetupStateSchemas<TStateSchemas>>;
560
+ declare const strictSetupStateTargets: unique symbol;
561
+ declare const relativeSetupStateSchemas: unique symbol;
562
+ declare const rootSetupStateSchemas: unique symbol;
563
+ declare const currentSetupStateSchema: unique symbol;
564
+ declare const parentSetupStateType: unique symbol;
565
+ /** @public Referenced by emitted declarations of strict transition targets. */
566
+ type StrictSetupStateTargetsFlag = {
567
+ readonly [strictSetupStateTargets]: true;
568
+ };
569
+ /** @public Referenced by emitted declarations of strict transition targets. */
570
+ type RelativeSetupStateSchemasMarker<TRelativeStateSchemas extends Record<string, SetupStateSchema>> = {
571
+ readonly [relativeSetupStateSchemas]: TRelativeStateSchemas;
572
+ };
573
+ /** @public Referenced by emitted declarations of strict transition targets. */
574
+ type CurrentSetupStateSchemaMarker<TCurrentStateSchema extends SetupStateSchema> = {
575
+ readonly [currentSetupStateSchema]: TCurrentStateSchema;
576
+ };
577
+ /** @public Referenced by emitted declarations of strict transition targets. */
578
+ type StrictSetupStateTargetsMarker<TRelativeStateSchemas extends Record<string, SetupStateSchema>, TRootStateSchemas extends Record<string, SetupStateSchema>, TCurrentStateSchema extends SetupStateSchema> = StrictSetupStateTargetsFlag & RelativeSetupStateSchemasMarker<TRelativeStateSchemas> & RootSetupStateSchemasMarker<TRootStateSchemas> & CurrentSetupStateSchemaMarker<TCurrentStateSchema>;
579
+ /** @public Referenced by emitted declarations of strict transition targets. */
580
+ type StrictSetupStateSchemas<TStateSchemas extends Record<string, SetupStateSchema>, TRelativeStateSchemas extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TRootStateSchemas extends Record<string, SetupStateSchema> = RootSetupStateSchemas<TStateSchemas>, TCurrentStateSchema extends SetupStateSchema = never> = TStateSchemas & StrictSetupStateTargetsMarker<TRelativeStateSchemas, TRootStateSchemas, TCurrentStateSchema>;
581
+ type RelativeSetupStateSchemas<TStateSchemas extends Record<string, SetupStateSchema>> = TStateSchemas extends RelativeSetupStateSchemasMarker<infer TRelativeStateSchemas> ? TRelativeStateSchemas : TStateSchemas;
582
+ type RootSetupStateSchemas<TStateSchemas extends Record<string, SetupStateSchema>> = TStateSchemas extends RootSetupStateSchemasMarker<infer TRootStateSchemas> ? TRootStateSchemas : TStateSchemas;
583
+ type CurrentSetupStateSchema<TStateSchemas extends Record<string, SetupStateSchema>> = TStateSchemas extends CurrentSetupStateSchemaMarker<infer TCurrentStateSchema> ? TCurrentStateSchema : never;
584
+ type SetupStateSelfSchema<TStateSchema extends SetupStateSchema> = TStateSchema extends {
585
+ schemas: infer TSchemas extends SetupStateSchemas;
586
+ } ? {
587
+ schemas: TSchemas;
588
+ } : {};
589
+ /** @public Referenced by emitted declarations of strict transition targets. */
590
+ type SetupStateParentTypeMarker<TParentStateType extends SetupStateType | never> = {
591
+ readonly [parentSetupStateType]: TParentStateType;
592
+ };
593
+ /** @public Referenced by emitted declarations of strict transition targets. */
594
+ type SetupStateSchemasWithParentType<TStateSchemas extends Record<string, SetupStateSchema>, TParentStateType extends SetupStateType | never> = TStateSchemas & SetupStateParentTypeMarker<TParentStateType>;
595
+ type SetupStateParentType<TStateSchemas extends Record<string, SetupStateSchema>> = TStateSchemas extends SetupStateParentTypeMarker<infer TParentStateType> ? TParentStateType : never;
596
+ type IsParallelSetupStateParent<TStateSchemas extends Record<string, SetupStateSchema>> = [SetupStateParentType<TStateSchemas>] extends [never] ? false : SetupStateParentType<TStateSchemas> extends 'parallel' ? true : false;
597
+ type ResolveStateSiblingsForPath<TStates extends Record<string, SetupStateSchema>, TPath extends string> = SetupStateParentAtPath<TStates, TPath> extends (infer TParent) ? [TParent] extends [SetupStateSchema] ? SetupStateSchemasWithParentType<ResolveStateSiblings<TStates, TPath>, TParent extends {
598
+ type: infer TType extends SetupStateType;
599
+ } ? TType : never> : ResolveStateSiblings<TStates, TPath> : never;
600
+ /** @public Referenced by emitted declarations of strict transition targets. */
601
+ type RootSetupStateSchemasMarker<TRootStateSchemas extends Record<string, SetupStateSchema>> = {
602
+ readonly [rootSetupStateSchemas]: TRootStateSchemas;
603
+ };
604
+ /** @public Referenced by emitted declarations of strict transition targets. */
605
+ type WithRootSetupStateSchemas<TStateSchemas extends Record<string, SetupStateSchema>, TRootStateSchemas extends Record<string, SetupStateSchema>> = TStateSchemas & RootSetupStateSchemasMarker<TRootStateSchemas>;
606
+ type RootSetupStateTransitionSchemas<TStateSchemas extends Record<string, SetupStateSchema>> = StrictSetupStateSchemas<{}, TStateSchemas, TStateSchemas>;
607
+ type RootSetupStateTarget<TStateSchemas extends Record<string, SetupStateSchema>> = SetupRelativeStateTarget<TStateSchemas> | RootSetupStateIdTarget<TStateSchemas>;
608
+ type SetupStateTransitionChildSchemas<TStateSchema extends SetupStateSchema> = TStateSchema extends {
609
+ states: infer TChildStateSchemas extends Record<string, SetupStateSchema>;
610
+ } ? TChildStateSchemas : {};
611
+ type SetupStateTransitionSchemas<TSiblingStateSchemas extends Record<string, SetupStateSchema>, TStateSchema extends SetupStateSchema> = IsParallelSetupStateParent<TSiblingStateSchemas> extends true ? StrictSetupStateSchemas<{}, SetupStateTransitionChildSchemas<TStateSchema>, RootSetupStateSchemas<TSiblingStateSchemas>, SetupStateSelfSchema<TStateSchema>> : string extends SetupStateKeys<TSiblingStateSchemas> ? TSiblingStateSchemas : keyof SetupStateSchema extends keyof TStateSchema ? TSiblingStateSchemas : TStateSchema extends {
612
+ states: Record<string, SetupStateSchema>;
613
+ } ? TStateSchema extends {
614
+ type: SetupStateType;
615
+ } ? StrictSetupStateSchemas<TSiblingStateSchemas, SetupStateTransitionChildSchemas<TStateSchema>, RootSetupStateSchemas<TSiblingStateSchemas>, SetupStateSelfSchema<TStateSchema>> : TSiblingStateSchemas : StrictSetupStateSchemas<TSiblingStateSchemas, {}, RootSetupStateSchemas<TSiblingStateSchemas>, SetupStateSelfSchema<TStateSchema>>;
616
+ type SetupStateChildSchemas<TStateSchema extends SetupStateSchema> = TStateSchema['states'] extends Record<string, SetupStateSchema> ? TStateSchema['states'] : Record<string, SetupStateSchema>;
617
+ type SetupStateIds<TStateSchemas extends Record<string, SetupStateSchema>> = { [K in keyof TStateSchemas & string]: TStateSchemas[K] extends {
618
+ id: infer TId extends string;
619
+ } ? TId : never; }[keyof TStateSchemas & string] | { [K in keyof TStateSchemas & string]: TStateSchemas[K]['states'] extends Record<string, SetupStateSchema> ? SetupStateIds<TStateSchemas[K]['states']> : never; }[keyof TStateSchemas & string];
620
+ type SetupStateIdTarget<TId extends string> = `#${EscapeSetupStatePathDots<TId>}`;
621
+ type SetupStateIdTargets<TStateSchemas extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStateSchemas> ? never : { [K in keyof TStateSchemas & string]: TStateSchemas[K] extends {
622
+ id: infer TId extends string;
623
+ } ? TStateSchemas[K]['states'] extends (infer TChildStateSchemas extends Record<string, SetupStateSchema>) ? string extends SetupStateKeys<TChildStateSchemas> ? never : `${SetupStateIdTarget<TId>}.${StatePaths<TChildStateSchemas> & string}` : never : never; }[keyof TStateSchemas & string] | { [K in keyof TStateSchemas & string]: TStateSchemas[K]['states'] extends (infer TChildStateSchemas extends Record<string, SetupStateSchema>) ? SetupStateIdTargets<TChildStateSchemas> : never; }[keyof TStateSchemas & string];
624
+ type RootSetupStateIdTarget<TStateSchemas extends Record<string, SetupStateSchema>> = SetupStateIds<TStateSchemas> extends (infer TIds extends string) ? [TIds] extends [never] ? never : SetupStateIdTarget<TIds> | SetupStateIdTargets<TStateSchemas> : never;
625
+ type SetupStateSchemaAtTarget<TStateSchemas extends Record<string, SetupStateSchema>, TTarget extends string> = (TTarget extends '.' ? CurrentSetupStateSchema<TStateSchemas> : TTarget extends `.${infer TPath}` ? ResolveStatePath<RelativeSetupStateSchemas<TStateSchemas>, TPath> : TTarget extends `#${string}` ? SetupStateSchemaAtIdTarget<RootSetupStateSchemas<TStateSchemas>, TTarget> : ResolveStatePath<TStateSchemas, TTarget>) extends (infer TStateSchema) ? TStateSchema extends SetupStateSchema ? TStateSchema : never : never;
626
+ type SetupStateSchemaAtId<TStateSchemas extends Record<string, SetupStateSchema>, TId extends string> = { [K in keyof TStateSchemas & string]: TStateSchemas[K] extends {
627
+ id: TId;
628
+ } ? TStateSchemas[K] : TStateSchemas[K]['states'] extends Record<string, SetupStateSchema> ? SetupStateSchemaAtId<TStateSchemas[K]['states'], TId> : never; }[keyof TStateSchemas & string];
629
+ type SetupStateSchemaAtIdTarget<TStateSchemas extends Record<string, SetupStateSchema>, TTarget extends string> = TTarget extends `#${infer TPath}` ? SplitSetupStatePath<TPath> extends [infer TId extends string, ...infer TDescendant extends string[]] ? SetupStateSchemaAtId<TStateSchemas, TId> extends (infer TStateSchema) ? TDescendant extends [] ? TStateSchema : TStateSchema extends {
630
+ states: infer TChildStateSchemas extends Record<string, SetupStateSchema>;
631
+ } ? ResolveStatePathSegments<TChildStateSchemas, TDescendant> : never : never : never : never;
632
+ type StateSchemasWithKeys<TStateSchemas extends Record<string, SetupStateSchema>, TStateKeys extends string> = TStateSchemas & { [K in Exclude<TStateKeys, keyof TStateSchemas>]: {}; };
633
+ type EscapeSetupStatePathDots<TValue extends string> = TValue extends `${infer THead}.${infer TTail}` ? `${THead}\\.${EscapeSetupStatePathDots<TTail>}` : TValue;
634
+ type ProtectSetupStatePathDots<TValue extends string> = TValue extends `${infer THead}\\.${infer TTail}` ? `${THead}__XSTATE_ESCAPED_DOT__${ProtectSetupStatePathDots<TTail>}` : TValue;
635
+ type RestoreSetupStatePathDots<TValue extends string> = TValue extends `${infer THead}__XSTATE_ESCAPED_DOT__${infer TTail}` ? `${THead}.${RestoreSetupStatePathDots<TTail>}` : TValue;
636
+ type SplitSetupStatePath<TPath extends string> = ProtectSetupStatePathDots<TPath> extends (infer TProtected extends string) ? TProtected extends '' ? [] : TProtected extends `${infer THead}.${infer TTail}` ? [RestoreSetupStatePathDots<THead>, ...SplitSetupStatePath<TTail>] : [RestoreSetupStatePathDots<TProtected>] : never;
637
+ type ResolveStatePathSegments<TStates extends Record<string, SetupStateSchema>, TSegments extends readonly string[]> = TSegments extends [infer THead extends string, ...infer TRest extends string[]] ? THead extends keyof TStates ? TRest extends [] ? TStates[THead] : TStates[THead]['states'] extends Record<string, SetupStateSchema> ? ResolveStatePathSegments<TStates[THead]['states'], TRest> : never : never : never;
638
+ type ResolveStatePath<TStates extends Record<string, SetupStateSchema>, TPath extends string> = ResolveStatePathSegments<TStates, SplitSetupStatePath<TPath>>;
639
+ type ResolveStateSiblingsSegments<TStates extends Record<string, SetupStateSchema>, TSegments extends readonly string[]> = TSegments extends [infer THead extends string, ...infer TRest extends string[]] ? TRest extends [] ? TStates : THead extends keyof TStates ? TStates[THead]['states'] extends Record<string, SetupStateSchema> ? ResolveStateSiblingsSegments<TStates[THead]['states'], TRest> : never : never : never;
640
+ /**
641
+ * The sibling state schemas of a dotted path: the children of the path's
642
+ * parent. A bare transition target resolves relative to the parent, so the
643
+ * valid targets for a path's config are its siblings. For a dotless (top-level)
644
+ * path the siblings are the root states.
645
+ */
646
+ type ResolveStateSiblings<TStates extends Record<string, SetupStateSchema>, TPath extends string> = ResolveStateSiblingsSegments<TStates, SplitSetupStatePath<TPath>>;
647
+ type SetupStateParentAtSegments<TStates extends Record<string, SetupStateSchema>, TSegments extends readonly string[]> = TSegments extends [infer THead extends string, ...infer TRest extends string[]] ? THead extends keyof TStates ? TRest extends [string] ? TStates[THead] : TStates[THead]['states'] extends Record<string, SetupStateSchema> ? SetupStateParentAtSegments<TStates[THead]['states'], TRest> : never : never : never;
648
+ type SetupStateParentAtPath<TStates extends Record<string, SetupStateSchema>, TPath extends string> = SetupStateParentAtSegments<TStates, SplitSetupStatePath<TPath>>;
649
+ /** Union of every addressable dotted path into a setup states tree */
650
+ type StatePathsInner<TStates extends Record<string, SetupStateSchema>> = { [K in SetupStateKeys<TStates>]: EscapeSetupStatePathDots<K> | (TStates[K]['states'] extends Record<string, SetupStateSchema> ? `${EscapeSetupStatePathDots<K>}.${StatePathsInner<TStates[K]['states']>}` : never); }[SetupStateKeys<TStates>];
651
+ type StatePaths<TStates extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStates> ? string : [SetupStateKeys<TStates>] extends [never] ? string : StatePathsInner<TStates>;
652
+ type SetupStatePath = readonly string[];
653
+ type SetupStatePathAtId<TStates extends Record<string, SetupStateSchema>, TId extends string, TPrefix extends SetupStatePath = []> = { [K in SetupStateKeys<TStates>]: TStates[K] extends {
654
+ id: TId;
655
+ } ? [...TPrefix, K] : TStates[K]['states'] extends Record<string, SetupStateSchema> ? SetupStatePathAtId<TStates[K]['states'], TId, [...TPrefix, K]> : never; }[SetupStateKeys<TStates>];
656
+ type SetupParentStatePath<TPath extends SetupStatePath> = TPath extends readonly [...infer TParent extends string[], string] ? TParent : [];
657
+ type SetupResolvedStatePath<TRootStateSchemas extends Record<string, SetupStateSchema>, TSourcePath extends string, TTarget extends string> = TTarget extends `#${infer TIdPath}` ? SplitSetupStatePath<TIdPath> extends [infer TId extends string, ...infer TDescendant extends string[]] ? SetupStatePathAtId<TRootStateSchemas, TId> extends (infer TIdStatePath) ? TIdStatePath extends SetupStatePath ? [...TIdStatePath, ...TDescendant] : never : never : never : TTarget extends '.' ? SplitSetupStatePath<TSourcePath> : TTarget extends `.${infer TDescendant}` ? [...SplitSetupStatePath<TSourcePath>, ...SplitSetupStatePath<TDescendant>] : [...SetupParentStatePath<SplitSetupStatePath<TSourcePath>>, ...SplitSetupStatePath<TTarget>];
658
+ type SetupCommonStatePath<TLeft extends SetupStatePath, TRight extends SetupStatePath, TCommon extends SetupStatePath = []> = TLeft extends readonly [infer TLeftHead extends string, ...infer TLeftTail extends string[]] ? TRight extends readonly [infer TRightHead extends string, ...infer TRightTail extends string[]] ? TLeftHead extends TRightHead ? SetupCommonStatePath<TLeftTail, TRightTail, [...TCommon, TLeftHead]> : TCommon : TCommon : TCommon;
659
+ type SetupIsParallelStatePath<TRootStateSchemas extends Record<string, SetupStateSchema>, TPath extends SetupStatePath> = TPath extends [] ? false : ResolveStatePathSegments<TRootStateSchemas, TPath> extends (infer TStateSchema) ? TStateSchema extends {
660
+ type: 'parallel';
661
+ } ? true : TStateSchema extends {
662
+ type: SetupStateType;
663
+ } ? false : 'unknown' : 'unknown';
664
+ type SetupInvalidTargetPair<TRootStateSchemas extends Record<string, SetupStateSchema>, TLeft extends SetupStatePath, TRight extends SetupStatePath> = [TLeft] extends [never] ? false : [TRight] extends [never] ? false : TLeft extends TRight ? true : TRight extends TLeft ? true : SetupIsParallelStatePath<TRootStateSchemas, SetupCommonStatePath<TLeft, TRight>> extends true ? false : SetupIsParallelStatePath<TRootStateSchemas, SetupCommonStatePath<TLeft, TRight>> extends false ? true : false;
665
+ type SetupInvalidTargetPairsWithHead<TRootStateSchemas extends Record<string, SetupStateSchema>, TSourcePath extends string, THead, TRest extends readonly unknown[]> = TRest extends readonly [infer TNext, ...infer TTail] ? SetupInvalidTargetPair<TRootStateSchemas, SetupResolvedStatePath<TRootStateSchemas, TSourcePath, Extract<THead, string>>, SetupResolvedStatePath<TRootStateSchemas, TSourcePath, Extract<TNext, string>>> extends true ? true : SetupInvalidTargetPairsWithHead<TRootStateSchemas, TSourcePath, THead, TTail> : false;
666
+ type SetupInvalidTargetSet<TRootStateSchemas extends Record<string, SetupStateSchema>, TSourcePath extends string, TTargets> = TTargets extends readonly [infer THead, ...infer TRest] ? SetupInvalidTargetPairsWithHead<TRootStateSchemas, TSourcePath, THead, TRest> extends true ? true : SetupInvalidTargetSet<TRootStateSchemas, TSourcePath, TRest> : false;
667
+ type SetupTargetSetLegality<TTransition, TRootStateSchemas extends Record<string, SetupStateSchema>, TSourcePath extends string> = TTransition extends ((...args: infer TArgs) => infer TResult) ? (...args: TArgs) => TResult & SetupTargetSetLegality<TResult, TRootStateSchemas, TSourcePath> : TTransition extends readonly unknown[] ? { [K in keyof TTransition]: TTransition[K] & SetupTargetSetLegality<TTransition[K], TRootStateSchemas, TSourcePath>; } : TTransition extends {
668
+ target: infer TTargets extends readonly string[];
669
+ } ? string extends TTargets[number] ? unknown : SetupInvalidTargetSet<TRootStateSchemas, TSourcePath, TTargets> extends true ? never : unknown : unknown;
670
+ type SetupTargetSetMapLegality<TMap, TRootStateSchemas extends Record<string, SetupStateSchema>, TSourcePath extends string> = TMap extends Record<string, unknown> ? { [K in keyof TMap]?: TMap[K] & SetupTargetSetLegality<TMap[K], TRootStateSchemas, TSourcePath>; } : unknown;
671
+ type SetupInvokeTargetSetLegality<TInvoke, TRootStateSchemas extends Record<string, SetupStateSchema>, TSourcePath extends string> = TInvoke extends {
672
+ readonly [createdInvokeConfig]: infer TConfig;
673
+ } ? {
674
+ readonly [createdInvokeConfig]: TConfig & SetupInvokeTargetSetLegality<TConfig, TRootStateSchemas, TSourcePath>;
675
+ } : TInvoke extends readonly unknown[] ? { [K in keyof TInvoke]: TInvoke[K] & SetupInvokeTargetSetLegality<TInvoke[K], TRootStateSchemas, TSourcePath>; } : TInvoke extends Record<string, unknown> ? (TInvoke extends {
676
+ onDone: infer TOnDone;
677
+ } ? {
678
+ onDone?: TInvoke['onDone'] & SetupTargetSetLegality<TOnDone, TRootStateSchemas, TSourcePath>;
679
+ } : unknown) & (TInvoke extends {
680
+ onError: infer TOnError;
681
+ } ? {
682
+ onError?: TInvoke['onError'] & SetupTargetSetLegality<TOnError, TRootStateSchemas, TSourcePath>;
683
+ } : unknown) & (TInvoke extends {
684
+ onSnapshot: infer TOnSnapshot;
685
+ } ? {
686
+ onSnapshot?: TInvoke['onSnapshot'] & SetupTargetSetLegality<TOnSnapshot, TRootStateSchemas, TSourcePath>;
687
+ } : unknown) & (TInvoke extends {
688
+ onTimeout: infer TOnTimeout;
689
+ } ? {
690
+ onTimeout?: TInvoke['onTimeout'] & SetupTargetSetLegality<TOnTimeout, TRootStateSchemas, TSourcePath>;
691
+ } : unknown) : unknown;
692
+ type SetupStateTargetSetLegality<TConfig, TRootStateSchemas extends Record<string, SetupStateSchema>, TSourcePath extends string> = (TConfig extends {
693
+ on: infer TOn;
694
+ } ? {
695
+ on?: TConfig['on'] & SetupTargetSetMapLegality<TOn, TRootStateSchemas, TSourcePath>;
696
+ } : unknown) & (TConfig extends {
697
+ always: infer TAlways;
698
+ } ? {
699
+ always?: TConfig['always'] & SetupTargetSetLegality<TAlways, TRootStateSchemas, TSourcePath>;
700
+ } : unknown) & (TConfig extends {
701
+ after: infer TAfter;
702
+ } ? {
703
+ after?: TConfig['after'] & SetupTargetSetMapLegality<TAfter, TRootStateSchemas, TSourcePath>;
704
+ } : unknown) & (TConfig extends {
705
+ onDone: infer TOnDone;
706
+ } ? {
707
+ onDone?: TConfig['onDone'] & SetupTargetSetLegality<TOnDone, TRootStateSchemas, TSourcePath>;
708
+ } : unknown) & (TConfig extends {
709
+ onError: infer TOnError;
710
+ } ? {
711
+ onError?: TConfig['onError'] & SetupTargetSetLegality<TOnError, TRootStateSchemas, TSourcePath>;
712
+ } : unknown) & (TConfig extends {
713
+ onTimeout: infer TOnTimeout;
714
+ } ? {
715
+ onTimeout?: TConfig['onTimeout'] & SetupTargetSetLegality<TOnTimeout, TRootStateSchemas, TSourcePath>;
716
+ } : unknown) & (TConfig extends {
717
+ choice: infer TChoice;
718
+ } ? {
719
+ choice?: TConfig['choice'] & SetupTargetSetLegality<TChoice, TRootStateSchemas, TSourcePath>;
720
+ } : unknown) & (TConfig extends {
721
+ invoke: infer TInvoke;
722
+ } ? {
723
+ invoke?: TConfig['invoke'] & SetupInvokeTargetSetLegality<TInvoke, TRootStateSchemas, TSourcePath>;
724
+ } : unknown);
725
+ /**
726
+ * Shared body of both `createStateConfig` overloads: the
727
+ * `StateNodeConfigWithNestedInput` instantiation whose only varying parts are
728
+ * the leading sibling-schemas and state-schema arguments.
729
+ */
730
+ type SetupStateNodeConfig<TStates extends Record<string, SetupStateSchema>, TStateSchema extends SetupStateSchema, TSchemas extends SetupSchemas, TSetupActionMap extends Sources['actions'], TSetupActorMap extends Sources['actors'], TSetupGuardMap extends Sources['guards'], TSetupDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry> = StateNodeConfigWithNestedInput<TStates, TStateSchema, SetupContext<TSchemas, StandardSchemaV1>, SetupContextShape<TSchemas, StandardSchemaV1, SetupContext<TSchemas, StandardSchemaV1>>, SetupEvents<TSchemas, Record<string, StandardSchemaV1>>, Cast<SetupChildren<TSchemas, Record<string, StandardSchemaV1>>, Record<string, AnyActorRef | undefined>>, string, SetupTags<TSchemas, StandardSchemaV1>, SetupOutput<TSchemas, StandardSchemaV1>, SetupEmitted<TSchemas, Record<string, StandardSchemaV1>>, SetupMeta<TSchemas, StandardSchemaV1>, SetupTransitionMeta<TSchemas, StandardSchemaV1, StandardSchemaV1>, SetupActions<TSchemas, TSetupActionMap>, TSetupActorMap, SetupGuards<TSchemas, TSetupGuardMap>, TSetupDelayMap, TSystemRegistry>;
731
+ type SetupContext<TSchemas, TContextSchema extends StandardSchemaV1> = [SetupSchema<TSchemas, 'context'>] extends [never] ? unknown extends StandardSchemaV1.InferOutput<TContextSchema> ? MachineContext : StandardSchemaV1.InferOutput<TContextSchema> & MachineContext : StandardSchemaV1.InferOutput<SetupSchema<TSchemas, 'context'>> & MachineContext;
732
+ type SetupContextShape<TSchemas, TContextSchema extends StandardSchemaV1, TFallbackContext> = [SetupSchema<TSchemas, 'context'>] extends [never] ? unknown extends StandardSchemaV1.InferOutput<TContextSchema> ? TFallbackContext : StandardSchemaV1.InferOutput<TContextSchema> : StandardSchemaV1.InferOutput<SetupSchema<TSchemas, 'context'>>;
733
+ type SetupContextRequired<TSchemas, TContextSchema extends StandardSchemaV1> = [SetupSchema<TSchemas, 'context'>] extends [never] ? unknown extends StandardSchemaV1.InferOutput<TContextSchema> ? false : true : true;
734
+ type SetupPublicEvents<TSchemas, TEventSchemaMap extends Record<string, StandardSchemaV1>> = [SetupSchemaMap<TSchemas, 'events'>] extends [never] ? InferEvents<TEventSchemaMap> : InferEvents<SetupSchemaMap<TSchemas, 'events'>>;
735
+ type SetupInternalEvents<TSchemas, TInternalEventSchemaMap extends Record<string, StandardSchemaV1>> = [SetupSchemaMap<TSchemas, 'internalEvents'>] extends [never] ? InferInternalEvents<TInternalEventSchemaMap> : InferInternalEvents<SetupSchemaMap<TSchemas, 'internalEvents'>>;
736
+ type SetupEvents<TSchemas, TEventSchemaMap extends Record<string, StandardSchemaV1>, TInternalEventSchemaMap extends Record<string, StandardSchemaV1> = {}> = SetupPublicEvents<TSchemas, TEventSchemaMap> | SetupInternalEvents<TSchemas, TInternalEventSchemaMap>;
737
+ type SetupTags<TSchemas, TTagSchema extends StandardSchemaV1> = [SetupSchema<TSchemas, 'tags'>] extends [never] ? StandardSchemaV1.InferOutput<TTagSchema> & string : StandardSchemaV1.InferOutput<SetupSchema<TSchemas, 'tags'>> & string;
738
+ type SetupInput<TSchemas, TInputSchema extends StandardSchemaV1> = [SetupSchema<TSchemas, 'input'>] extends [never] ? InferMachineInput<TInputSchema> : InferOutput<SetupSchema<TSchemas, 'input'>, unknown>;
739
+ type SetupOutput<TSchemas, TOutputSchema extends StandardSchemaV1> = [SetupSchema<TSchemas, 'output'>] extends [never] ? InferOutput<TOutputSchema, unknown> : InferOutput<SetupSchema<TSchemas, 'output'>, unknown>;
740
+ /**
741
+ * Whether an output schema was declared, either in `setup({ schemas })` or in
742
+ * the machine config's own `schemas.output`. A declared schema is always
743
+ * authoritative for the machine's output type.
744
+ */
745
+ type HasOutputSchema<TSchemas, TOutputSchema extends StandardSchemaV1> = [SetupSchema<TSchemas, 'output'>] extends [never] ? StandardSchemaV1 extends TOutputSchema ? false : true : true;
746
+ /**
747
+ * Whether a state is final, per the authored config or the setup-declared
748
+ * state contract.
749
+ */
750
+ type IsFinalState<TStateConfig, TStateSchema> = TStateConfig extends {
751
+ type: 'final';
752
+ } ? true : TStateSchema extends {
753
+ type: 'final';
754
+ } ? true : false;
755
+ /**
756
+ * The union of output types across the config's top-level final states, or
757
+ * `never` when it has none. A setup-declared per-state `schemas.output` wins
758
+ * over the state's inline `schemas.output`, which wins over the state's
759
+ * `output` mapper; a final state with none of these contributes `undefined`.
760
+ */
761
+ type SetupTopLevelFinalOutput<TConfig, TStates extends Record<string, SetupStateSchema>> = TConfig extends {
762
+ states: infer TConfigStates;
763
+ } ? { [K in keyof TConfigStates]: IsFinalState<TConfigStates[K], K extends keyof TStates ? TStates[K] : never> extends true ? K extends keyof TStates ? StateOutput<TStates[K], FinalStateConfigOutput<TConfigStates[K]>> : FinalStateConfigOutput<TConfigStates[K]> : never; }[keyof TConfigStates] : never;
764
+ /**
765
+ * The machine's output type. A declared output schema wins; otherwise the type
766
+ * is inferred from the config's `output` property (a mapper's return type, or
767
+ * the static value's type), falling back to the union of top-level
768
+ * final-state output types.
769
+ */
770
+ type SetupOrConfigOutput<TSchemas, TOutputSchema extends StandardSchemaV1, TConfig, TStates extends Record<string, SetupStateSchema>> = HasOutputSchema<TSchemas, TOutputSchema> extends true ? SetupOutput<TSchemas, TOutputSchema> : OutputFromConfig<TConfig, [SetupTopLevelFinalOutput<TConfig, TStates>] extends [never] ? SetupOutput<TSchemas, TOutputSchema> : SetupTopLevelFinalOutput<TConfig, TStates>>;
771
+ type SetupEmitted<TSchemas, TEmittedSchemaMap extends Record<string, StandardSchemaV1>> = [SetupSchemaMap<TSchemas, 'emitted'>] extends [never] ? WithDefault<InferEvents<TEmittedSchemaMap>, AnyEventObject> : WithDefault<InferEvents<SetupSchemaMap<TSchemas, 'emitted'>>, AnyEventObject>;
772
+ type SetupMeta<TSchemas, TMetaSchema extends StandardSchemaV1> = [SetupSchema<TSchemas, 'meta'>] extends [never] ? InferOutput<TMetaSchema, MetaObject> : InferOutput<SetupSchema<TSchemas, 'meta'>, MetaObject>;
773
+ type SetupTransitionMeta<TSchemas, TMetaSchema extends StandardSchemaV1, TTransitionMetaSchema extends StandardSchemaV1> = [SetupSchema<TSchemas, 'transitionMeta'>] extends [never] ? StandardSchemaV1 extends TTransitionMetaSchema ? SetupMeta<TSchemas, TMetaSchema> : InferOutput<TTransitionMetaSchema, MetaObject> : InferOutput<SetupSchema<TSchemas, 'transitionMeta'>, MetaObject>;
774
+ type SetupChildren<TSchemas, TChildrenSchemaMap extends Record<string, StandardSchemaV1>> = [SetupSchemaMap<TSchemas, 'children'>] extends [never] ? InferChildren<TChildrenSchemaMap> : InferChildren<SetupSchemaMap<TSchemas, 'children'>>;
775
+ type SetupActions<TSchemas, TActionMap extends Sources['actions']> = [SetupActionSchemaMap<TSchemas>] extends [never] ? TActionMap : MergeSourceMaps<InferActions<SetupActionSchemaMap<TSchemas>>, TActionMap>;
776
+ type SetupGuards<TSchemas, TGuardMap extends Sources['guards']> = [SetupGuardSchemaMap<TSchemas>] extends [never] ? TGuardMap : MergeSourceMaps<InferGuards<SetupGuardSchemaMap<TSchemas>>, TGuardMap>;
777
+ type SetupMergeChildren<TChildren extends Record<string, AnyActorRef | undefined>, TActor extends ProvidedActor> = [keyof TChildren] extends [never] ? Compute<ToChildren<TActor>> : Compute<TChildren>;
778
+ type MergeSourceMaps<TBase extends Record<string, unknown>, TExtension extends Record<string, unknown>> = Compute<TBase & TExtension>;
779
+ type MergeSetupStateSchemaField<TBase extends SetupStateSchema, TExtension extends SetupStateSchema, TKey extends 'schemas' | 'states'> = TKey extends keyof TExtension ? TKey extends keyof TBase ? TKey extends 'schemas' ? { [K in TKey]: MergeRecord<NonNullable<TBase[TKey]>, NonNullable<TExtension[TKey]>>; } : NonNullable<TBase[TKey]> extends Record<string, SetupStateSchema> ? NonNullable<TExtension[TKey]> extends Record<string, SetupStateSchema> ? { [K in TKey]: MergeSetupStateSchemas<NonNullable<TBase[TKey]>, NonNullable<TExtension[TKey]>>; } : Pick<TExtension, TKey> : Pick<TExtension, TKey> : Pick<TExtension, TKey> : TKey extends keyof TBase ? Pick<TBase, TKey> : {};
780
+ type MergeSetupStateSchema<TBase extends SetupStateSchema, TExtension extends SetupStateSchema> = Omit<TBase, keyof TExtension> & Omit<TExtension, 'schemas' | 'states'> & MergeSetupStateSchemaField<TBase, TExtension, 'schemas'> & MergeSetupStateSchemaField<TBase, TExtension, 'states'>;
781
+ type MergeSetupStateSchemas<TBase extends Record<string, SetupStateSchema>, TExtension extends Record<string, SetupStateSchema>> = { [K in keyof TBase | keyof TExtension]: K extends keyof TExtension ? K extends keyof TBase ? MergeSetupStateSchema<TBase[K], TExtension[K]> : TExtension[K] : K extends keyof TBase ? TBase[K] : never; };
782
+ type DelayNamesFromConfigOrString<TConfig> = TConfig extends {
783
+ delays: infer TDelays;
784
+ } ? Extract<keyof TDelays, string> : string;
785
+ type DelayNamesFromConfig<TConfig> = TConfig extends {
786
+ delays: infer TDelays;
787
+ } ? Extract<keyof TDelays, string> : never;
788
+ type ValidateSetupDelayReferences<TConfig, TSetupDelays extends string> = ValidateDelayNames<TConfig, [TSetupDelays] extends [never] ? DelayNamesFromConfigOrString<TConfig> : TSetupDelays | DelayNamesFromConfig<TConfig>>;
789
+ /** Extracts input type from a state schema */
790
+ type StateInput<TStateSchema extends SetupStateSchema> = TStateSchema['schemas'] extends {
791
+ input: infer TInputSchema;
792
+ } ? TInputSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TInputSchema> : undefined : undefined;
793
+ /** Extracts the completion output type from a state schema. */
794
+ type StateOutput<TStateSchema extends SetupStateSchema, TFallback> = TStateSchema['schemas'] extends {
795
+ output: infer TOutputSchema;
796
+ } ? TOutputSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TOutputSchema> : TFallback : TFallback;
797
+ type StateCompletionOutput<TStateSchema extends SetupStateSchema> = StateOutput<TStateSchema, unknown>;
798
+ type StateContext<TStateSchema extends SetupStateSchema, TFallbackContext extends MachineContext> = TStateSchema['schemas'] extends {
799
+ context: infer TContextSchema;
800
+ } ? TContextSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TContextSchema> & RootContext<TFallbackContext> & MachineContext & RootContextMarker<TFallbackContext> : RootContext<TFallbackContext> : RootContext<TFallbackContext>;
801
+ declare const rootContext: unique symbol;
802
+ /** @public Referenced by emitted declarations of narrowed state contexts. */
803
+ interface RootContextMarker<TContext> {
804
+ readonly [rootContext]?: RootContext<TContext>;
805
+ }
806
+ type RootContext<TContext> = typeof rootContext extends keyof TContext ? TContext[typeof rootContext] : TContext;
807
+ type StateContextShape<TStateSchema extends SetupStateSchema, TFallbackContext> = TStateSchema['schemas'] extends {
808
+ context: infer TContextSchema;
809
+ } ? TContextSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TContextSchema> & RootContext<TFallbackContext> & RootContextMarker<TFallbackContext> : RootContext<TFallbackContext> : RootContext<TFallbackContext>;
810
+ /** @public Referenced by emitted declarations of narrowed state contexts. */
811
+ type ActiveStateContext<TStateSchema extends SetupStateSchema, TRootContext extends MachineContext, TAncestorContext> = StateContext<TStateSchema, TRootContext> & TAncestorContext & MachineContext;
812
+ type ActiveStateContextShape<TStateSchema extends SetupStateSchema, TAncestorContext> = StateContextShape<TStateSchema, TAncestorContext> & TAncestorContext;
813
+ type WithNestedStates<TConfig, TNestedStates> = TConfig extends {
814
+ type: 'choice';
815
+ } ? TConfig : Omit<TConfig, 'states'> & {
816
+ states?: TNestedStates;
817
+ };
818
+ type HasStateInputSchema<TStateSchema extends SetupStateSchema> = TStateSchema['schemas'] extends {
819
+ input: infer TInputSchema;
820
+ } ? TInputSchema extends StandardSchemaV1 ? true : false : false;
821
+ type RequiresStateInput<TStateSchema extends SetupStateSchema> = HasStateInputSchema<TStateSchema> extends true ? undefined extends StateInput<TStateSchema> ? false : true : false;
822
+ type HasRequiredStateInput<TStates extends Record<string, SetupStateSchema>> = true extends { [K in keyof TStates]: RequiresStateInput<TStates[K]>; }[keyof TStates] ? true : false;
823
+ type SetupStateSchemaForChild<TStateSchema extends SetupStateSchema, TTarget extends string> = TStateSchema['states'] extends (infer TStates extends Record<string, SetupStateSchema>) ? TTarget extends keyof TStates & string ? TStates[TTarget] : {} : {};
824
+ type SetupStateInputConfig<TStateSchema extends SetupStateSchema, TContext extends MachineContext, TEvent extends EventObject, TInputArgs extends {
825
+ context: TContext;
826
+ event: TEvent;
827
+ } = {
828
+ context: TContext;
829
+ event: TEvent;
830
+ }> = HasStateInputSchema<TStateSchema> extends true ? undefined extends StateInput<TStateSchema> ? {
831
+ input?: StateInput<TStateSchema> | ((args: TInputArgs) => StateInput<TStateSchema>);
832
+ } : {
833
+ input: StateInput<TStateSchema> | ((args: TInputArgs) => StateInput<TStateSchema>);
834
+ } : {
835
+ input?: Record<string, unknown> | ((args: TInputArgs) => Record<string, unknown>);
836
+ };
837
+ type SetupChoiceTargetConfig<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TEvent extends EventObject> = { [K in KnownSetupStateTarget<TStateSchemas>]: {
838
+ target: K;
839
+ } & SetupStateInputConfig<SetupStateSchemaAtTarget<TStateSchemas, K>, TContext, TEvent>; }[KnownSetupStateTarget<TStateSchemas>] | (TStateSchemas extends StrictSetupStateTargetsFlag ? {
840
+ target: KnownSetupStateTarget<TStateSchemas>[];
841
+ input?: Record<string, unknown>;
842
+ } : {
843
+ target: SetupStateTarget<TStateSchemas>[];
844
+ input?: Record<string, unknown>;
845
+ });
846
+ type SetupChoiceFunction<TChoice, TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TEvent extends EventObject> = TChoice extends ((...args: infer TArgs) => infer TResult) ? (...args: TArgs) => (TResult extends {
847
+ target: unknown;
848
+ } ? Omit<TResult, 'target' | 'input'> & SetupChoiceTargetConfig<TStateSchemas, TContext, TEvent> : TResult) | void : never;
849
+ type SetupChoiceTargetArrayInputConstraint<TChoice, TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TEvent extends EventObject> = TChoice extends ((...args: infer TArgs) => infer TResult) ? (...args: TArgs) => TResult & SetupTargetArrayInputConstraint<TResult, TStateSchemas, TContext, TEvent> : never;
850
+ type SetupTargetInput<TStateSchema extends SetupStateSchema> = HasStateInputSchema<TStateSchema> extends true ? Exclude<StateInput<TStateSchema>, undefined> : Record<string, unknown>;
851
+ type SetupUnionToIntersection<T> = (T extends any ? (value: T) => void : never) extends ((value: infer I) => void) ? I : never;
852
+ type SetupTargetArrayInput<TStateSchemas extends Record<string, SetupStateSchema>, TTargets extends readonly string[]> = SetupUnionToIntersection<SetupTargetInputForTarget<TStateSchemas, TTargets[number]>>;
853
+ type SetupTargetInputForTarget<TStateSchemas extends Record<string, SetupStateSchema>, TTarget extends string> = SetupStateSchemaAtTarget<TStateSchemas, TTarget> extends (infer TStateSchema) ? TStateSchema extends SetupStateSchema ? SetupTargetInput<TStateSchema> : Record<string, unknown> : Record<string, unknown>;
854
+ type SetupTargetArrayRequiresInput<TStateSchemas extends Record<string, SetupStateSchema>, TTargets extends readonly string[]> = true extends { [K in TTargets[number]]: RequiresStateInput<SetupStateSchemaAtTarget<TStateSchemas, K>>; }[TTargets[number]] ? true : false;
855
+ type SetupTargetArrayInputConfig<TStateSchemas extends Record<string, SetupStateSchema>, TTargets extends readonly string[], TContext extends MachineContext = MachineContext, TEvent extends EventObject = EventObject> = SetupTargetArrayRequiresInput<TStateSchemas, TTargets> extends true ? {
856
+ input: SetupTargetArrayInput<TStateSchemas, TTargets> | ((args: {
857
+ context: TContext;
858
+ event: TEvent;
859
+ }) => SetupTargetArrayInput<TStateSchemas, TTargets>);
860
+ } : {
861
+ input?: SetupTargetArrayInput<TStateSchemas, TTargets> | ((args: {
862
+ context: TContext;
863
+ event: TEvent;
864
+ }) => SetupTargetArrayInput<TStateSchemas, TTargets>);
865
+ };
866
+ /**
867
+ * The runtime applies one transition input to every target in a target set.
868
+ * Keep the array's input correlated to its literal targets by requiring the
869
+ * intersection of their direct input types. Widened string arrays remain
870
+ * permissive for compatibility.
871
+ */
872
+ type SetupTargetArrayInputConstraint<TTransition, TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext = MachineContext, TEvent extends EventObject = EventObject> = TTransition extends ((...args: infer TArgs) => infer TResult) ? (...args: TArgs) => TResult & SetupTargetArrayInputConstraint<TResult, TStateSchemas, TContext, TEvent> : [TTransition] extends [{
873
+ target: infer TTargets extends readonly string[];
874
+ }] ? string extends TTargets[number] ? unknown : [TTargets[number]] extends [never] ? unknown : KnownSetupStateTarget<TStateSchemas> extends never ? unknown : Exclude<TTargets[number], KnownSetupStateTarget<TStateSchemas>> extends never ? SetupTargetArrayInputConfig<TStateSchemas, TTargets, TContext, TEvent> : never : unknown;
875
+ type SetupTransitionValueTargetArrayInputConstraint<TValue, TStateSchemas extends Record<string, SetupStateSchema>> = [TValue] extends [readonly unknown[]] ? { [K in keyof TValue]: TValue[K] & SetupTransitionValueTargetArrayInputConstraint<TValue[K], TStateSchemas>; } : SetupTargetArrayInputConstraint<TValue, TStateSchemas>;
876
+ type SetupTransitionMapTargetArrayInputConstraint<TValue, TStateSchemas extends Record<string, SetupStateSchema>> = [TValue] extends [Record<string, unknown>] ? { [K in keyof TValue]?: TValue[K] & SetupTransitionValueTargetArrayInputConstraint<TValue[K], TStateSchemas>; } : unknown;
877
+ type SetupTransitionPropertyTargetArrayInputConstraint<TConfig, TKey extends PropertyKey, TStateSchemas extends Record<string, SetupStateSchema>, TIsMap extends boolean = false> = TKey extends keyof TConfig ? { [K in TKey]?: TConfig[K] & (TIsMap extends true ? SetupTransitionMapTargetArrayInputConstraint<TConfig[K], TStateSchemas> : SetupTransitionValueTargetArrayInputConstraint<TConfig[K], TStateSchemas>); } : unknown;
878
+ type SetupInvokeTargetArrayInputConstraint<TInvoke, TStateSchemas extends Record<string, SetupStateSchema>> = TInvoke extends {
879
+ readonly [createdInvokeConfig]: infer TConfig;
880
+ } ? {
881
+ readonly [createdInvokeConfig]: TConfig & SetupInvokeTargetArrayInputConstraint<TConfig, TStateSchemas>;
882
+ } : [TInvoke] extends [readonly unknown[]] ? { [K in keyof TInvoke]: TInvoke[K] & SetupInvokeTargetArrayInputConstraint<TInvoke[K], TStateSchemas>; } : [TInvoke] extends [Record<string, unknown>] ? SetupTransitionPropertyTargetArrayInputConstraint<TInvoke, 'onDone', TStateSchemas> & SetupTransitionPropertyTargetArrayInputConstraint<TInvoke, 'onError', TStateSchemas> & SetupTransitionPropertyTargetArrayInputConstraint<TInvoke, 'onSnapshot', TStateSchemas> & SetupTransitionPropertyTargetArrayInputConstraint<TInvoke, 'onTimeout', TStateSchemas> : unknown;
883
+ type SetupStateNodeTargetArrayInputConstraint<TConfig, TSiblingStateSchemas extends Record<string, SetupStateSchema>, TStateSchema extends SetupStateSchema, TChildStateSchemas extends Record<string, SetupStateSchema>> = SetupTransitionPropertyTargetArrayInputConstraint<TConfig, 'on', SetupStateTransitionSchemas<TSiblingStateSchemas, TStateSchema>, true> & SetupTransitionPropertyTargetArrayInputConstraint<TConfig, 'always', SetupStateTransitionSchemas<TSiblingStateSchemas, TStateSchema>> & SetupTransitionPropertyTargetArrayInputConstraint<TConfig, 'after', SetupStateTransitionSchemas<TSiblingStateSchemas, TStateSchema>, true> & SetupTransitionPropertyTargetArrayInputConstraint<TConfig, 'onDone', SetupStateTransitionSchemas<TSiblingStateSchemas, TStateSchema>> & SetupTransitionPropertyTargetArrayInputConstraint<TConfig, 'onError', SetupStateTransitionSchemas<TSiblingStateSchemas, TStateSchema>> & SetupTransitionPropertyTargetArrayInputConstraint<TConfig, 'onTimeout', SetupStateTransitionSchemas<TSiblingStateSchemas, TStateSchema>> & SetupTransitionPropertyTargetArrayInputConstraint<TConfig, 'choice', SetupStateTransitionSchemas<TSiblingStateSchemas, TStateSchema>> & (TConfig extends {
884
+ invoke: infer TInvoke;
885
+ } ? {
886
+ invoke?: TConfig['invoke'] & SetupInvokeTargetArrayInputConstraint<TInvoke, SetupStateTransitionSchemas<TSiblingStateSchemas, TStateSchema>>;
887
+ } : unknown) & (TConfig extends {
888
+ states: infer TChildren extends Record<string, unknown>;
889
+ } ? {
890
+ states?: { [K in keyof TChildren]?: TChildren[K] & SetupStateNodeTargetArrayInputConstraint<TChildren[K], TChildStateSchemas, K extends keyof TChildStateSchemas ? TChildStateSchemas[K] : SetupStateSchema, SetupStateChildSchemas<K extends keyof TChildStateSchemas ? TChildStateSchemas[K] : SetupStateSchema>>; };
891
+ } : unknown);
892
+ type ValidateSetupTargetArrayInputs<TConfig, TRootStateSchemas extends Record<string, SetupStateSchema>> = SetupStateNodeTargetArrayInputConstraint<TConfig, TRootStateSchemas, SetupStateSchema, TRootStateSchemas>;
893
+ type ValidateSetupStateContracts<TConfig, TStateSchemas extends Record<string, SetupStateSchema>> = HasExplicitSetupStateContracts<TStateSchemas> extends true ? ValidateSetupHistoryInputs<TConfig, TStateSchemas> & ValidateHistoryDefaults<MergeSetupConfig<TConfig, TStateSchemas>> & ValidateStateTargets<MergeSetupConfig<TConfig, TStateSchemas>> & NoInfer<ValidateSetupTargetArrayInputs<TConfig, TStateSchemas>> : unknown;
894
+ type SetupInitialTransitionConfig<TStateSchema extends SetupStateSchema, TTarget extends string, TConfig, TContext extends MachineContext, TEvent extends EventObject> = Extract<SetupConfigInitial<TConfig>, {
895
+ target: TTarget;
896
+ }> extends (infer TInitial) ? [TInitial] extends [never] ? {
897
+ target: TTarget;
898
+ } & SetupStateInputConfig<SetupStateSchemaForChild<TStateSchema, TTarget>, TContext, TEvent> : Omit<TInitial, 'target' | 'input'> & {
899
+ target: TTarget;
900
+ } & SetupStateInputConfig<SetupStateSchemaForChild<TStateSchema, TTarget>, TContext, TEvent> : never;
901
+ type SetupConfigInitial<TConfig> = TConfig extends {
902
+ initial?: infer TInitial;
903
+ } ? NonNullable<TInitial> : never;
904
+ type SetupInitialTransition<TStateSchema extends SetupStateSchema, TTarget extends string = string, TConfig = unknown, TContext extends MachineContext = MachineContext, TEvent extends EventObject = EventObject> = (RequiresStateInput<SetupStateSchemaForChild<TStateSchema, TTarget>> extends true ? never : TTarget) | SetupInitialTransitionConfig<TStateSchema, TTarget, TConfig, TContext, TEvent>;
905
+ type SetupInitialTransitionForStates<TStateSchema extends SetupStateSchema, TConfig, TContext extends MachineContext, TEvent extends EventObject> = TStateSchema['states'] extends (infer TStates extends Record<string, SetupStateSchema>) ? { [K in keyof TStates & string]: SetupInitialTransition<TStateSchema, K, TConfig, TContext, TEvent>; }[keyof TStates & string] : never;
906
+ type SetupInitialTransitionForOtherStates<TStateSchema extends SetupStateSchema, TInitial extends string, TContext extends MachineContext, TEvent extends EventObject> = TStateSchema['states'] extends (infer TStates extends Record<string, SetupStateSchema>) ? { [K in Exclude<keyof TStates & string, TInitial>]: SetupInitialTransition<TStateSchema, K, unknown, TContext, TEvent>; }[Exclude<keyof TStates & string, TInitial>] : never;
907
+ type SetupStateInitial<TStateSchema extends SetupStateSchema, TContext extends MachineContext, TEvent extends EventObject> = TStateSchema extends {
908
+ initial: infer TInitial extends string;
909
+ } ? RequiresStateInput<SetupStateSchemaForChild<TStateSchema, TInitial>> extends true ? {
910
+ initial: SetupInitialTransition<TStateSchema, TInitial, unknown, TContext, TEvent> | SetupInitialTransitionForOtherStates<TStateSchema, TInitial, TContext, TEvent>;
911
+ } : {
912
+ initial?: SetupInitialTransition<TStateSchema, TInitial, unknown, TContext, TEvent> | SetupInitialTransitionForOtherStates<TStateSchema, TInitial, TContext, TEvent>;
913
+ } : TStateSchema['states'] extends Record<string, SetupStateSchema> ? HasRequiredStateInput<TStateSchema['states']> extends true ? {
914
+ initial: SetupInitialTransitionForStates<TStateSchema, unknown, TContext, TEvent>;
915
+ } : {
916
+ initial: string | {
917
+ target: string;
918
+ input?: Record<string, unknown>;
919
+ };
920
+ } : {
921
+ initial: string | {
922
+ target: string;
923
+ input?: Record<string, unknown>;
924
+ };
925
+ };
926
+ type SetupStateNodeContract<TStateSchema extends SetupStateSchema, TConfig, TContext extends MachineContext = MachineContext, TEvent extends EventObject = EventObject, TSiblingStateSchemas extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>> = TStateSchema extends {
927
+ type: infer TType;
928
+ } ? TType extends 'atomic' ? Omit<TConfig, 'type' | 'states' | 'initial' | 'history' | 'target'> & {
929
+ type?: 'atomic';
930
+ states?: never;
931
+ initial?: never;
932
+ history?: never;
933
+ target?: never;
934
+ } : TType extends 'compound' ? Omit<TConfig, 'type' | 'initial'> & ({
935
+ type?: 'compound';
936
+ } & SetupStateChildrenContract<TStateSchema, TConfig> & SetupStateInitial<TStateSchema, TContext, TEvent>) : TType extends 'parallel' ? Omit<TConfig, 'type' | 'initial'> & {
937
+ type?: 'parallel';
938
+ initial?: never;
939
+ states: NonNullable<TConfig extends {
940
+ states?: infer TStates;
941
+ } ? TStates : unknown>;
942
+ } : TType extends 'final' ? Omit<TConfig, 'type' | 'states' | 'initial' | 'history' | 'target' | 'invoke' | 'on' | 'always' | 'after' | 'timeout' | 'onTimeout' | 'onDone' | 'onError'> & {
943
+ type?: 'final';
944
+ states?: never;
945
+ initial?: never;
946
+ history?: never;
947
+ target?: never;
948
+ invoke?: never;
949
+ on?: never;
950
+ always?: never;
951
+ after?: never;
952
+ timeout?: never;
953
+ onTimeout?: never;
954
+ onDone?: never;
955
+ onError?: never;
956
+ } : TType extends 'history' ? SetupHistoryStateContract<TStateSchema, TConfig, TSiblingStateSchemas> : TType extends 'choice' ? Omit<TConfig, 'type' | 'states' | 'initial' | 'history' | 'target' | 'invoke' | 'on' | 'entry' | 'exit' | 'onDone' | 'onError' | 'after' | 'timeout' | 'onTimeout' | 'always'> & {
957
+ type?: 'choice';
958
+ choice: Extract<TConfig, {
959
+ choice: (...args: any[]) => any;
960
+ }> extends {
961
+ choice: infer TChoice;
962
+ } ? SetupChoiceFunction<TChoice, SetupStateTransitionSchemas<TSiblingStateSchemas, TStateSchema>, TContext, TEvent> & SetupChoiceTargetArrayInputConstraint<TChoice, SetupStateTransitionSchemas<TSiblingStateSchemas, TStateSchema>, TContext, TEvent> : (...args: any[]) => any;
963
+ states?: never;
964
+ initial?: never;
965
+ history?: never;
966
+ target?: never;
967
+ invoke?: never;
968
+ on?: never;
969
+ entry?: never;
970
+ exit?: never;
971
+ onDone?: never;
972
+ onError?: never;
973
+ after?: never;
974
+ timeout?: never;
975
+ onTimeout?: never;
976
+ always?: never;
977
+ } : TStateSchema extends {
978
+ history: unknown;
979
+ } ? SetupHistoryStateContract<TStateSchema, TConfig, TSiblingStateSchemas> : TConfig : TConfig;
980
+ type SetupHistoryStateContract<TStateSchema extends SetupStateSchema, TConfig, TSiblingStateSchemas extends Record<string, SetupStateSchema>> = Omit<TConfig, 'type' | 'states' | 'initial' | 'target'> & {
981
+ type?: 'history';
982
+ states?: never;
983
+ initial?: never;
984
+ } & (TStateSchema extends {
985
+ target: infer TTarget extends string | readonly [string, ...string[]];
986
+ } ? {
987
+ target?: TTarget | KnownSetupStateTarget<TSiblingStateSchemas> | readonly KnownSetupStateTarget<TSiblingStateSchemas>[];
988
+ } : {
989
+ target: KnownSetupStateTarget<TSiblingStateSchemas> | readonly KnownSetupStateTarget<TSiblingStateSchemas>[];
990
+ });
991
+ type SetupStateChildrenContract<TStateSchema extends SetupStateSchema, TConfig> = TStateSchema extends {
992
+ states: Record<string, SetupStateSchema>;
993
+ } ? {
994
+ states: NonNullable<TConfig extends {
995
+ states?: infer TStates;
996
+ } ? TStates : unknown>;
997
+ } : {};
998
+ type HistoryTargetRequiresInput<TSiblingStateSchemas extends Record<string, SetupStateSchema>, TTarget extends string | readonly string[]> = TTarget extends readonly (infer TTargets extends string)[] ? true extends { [K in TTargets]: RequiresStateInput<SetupStateSchemaAtTarget<TSiblingStateSchemas, K>>; }[TTargets] ? true : false : TTarget extends string ? RequiresStateInput<SetupStateSchemaAtTarget<TSiblingStateSchemas, TTarget>> : false;
999
+ type SetupHistoryTarget<TStateSchema extends SetupStateSchema, TConfig> = TConfig extends {
1000
+ target: infer TTarget extends string | readonly [string, ...string[]];
1001
+ } ? TTarget : TStateSchema extends {
1002
+ target: infer TTarget extends string | readonly [string, ...string[]];
1003
+ } ? TTarget : never;
1004
+ type ValidateSetupHistoryStateInput<TConfig, TStateSchema extends SetupStateSchema, TSiblingStateSchemas extends Record<string, SetupStateSchema>> = TStateSchema extends {
1005
+ type: 'history';
1006
+ } | {
1007
+ history: unknown;
1008
+ } ? SetupHistoryTarget<TStateSchema, TConfig> extends (infer TTarget) ? [TTarget] extends [never] ? unknown : TTarget extends string | readonly [string, ...string[]] ? HistoryTargetRequiresInput<TSiblingStateSchemas, TTarget> extends true ? never : unknown : unknown : unknown : unknown;
1009
+ type ValidateSetupHistoryInputs<TConfig, TStateSchemas extends Record<string, SetupStateSchema>, TRootStateSchemas extends Record<string, SetupStateSchema> = TStateSchemas> = TConfig extends {
1010
+ states: infer TStates extends Record<string, unknown>;
1011
+ } ? {
1012
+ states: { [K in keyof TStates & string]: K extends keyof TStateSchemas ? TStates[K] & ValidateSetupHistoryStateInput<TStates[K], TStateSchemas[K], WithRootSetupStateSchemas<TStateSchemas, TRootStateSchemas>> & (TStateSchemas[K]['states'] extends Record<string, SetupStateSchema> ? ValidateSetupHistoryInputs<TStates[K], TStateSchemas[K]['states'], TRootStateSchemas> : unknown) : TStates[K]; };
1013
+ } : unknown;
1014
+ type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
1015
+ type SetupStateSchemaMetadata<TSetupSchema extends SetupStateSchema> = (TSetupSchema extends {
1016
+ type: infer TType;
1017
+ } ? {
1018
+ type: TType;
1019
+ } : {}) & (TSetupSchema extends {
1020
+ id: infer TId;
1021
+ } ? {
1022
+ id: TId;
1023
+ } : {}) & (TSetupSchema extends {
1024
+ initial: infer TInitial;
1025
+ } ? {
1026
+ initial: TInitial;
1027
+ } : {}) & (TSetupSchema extends {
1028
+ history: infer THistory;
1029
+ } ? {
1030
+ history: THistory;
1031
+ } : {}) & (TSetupSchema extends {
1032
+ target: infer TTarget;
1033
+ } ? {
1034
+ target: TTarget;
1035
+ } : {}) & (TSetupSchema extends {
1036
+ route: infer TRoute;
1037
+ } ? {
1038
+ route: TRoute;
1039
+ } : {});
1040
+ /**
1041
+ * Converts SetupStateSchema to StateSchema with input types included. This
1042
+ * allows getInputs() to be strongly typed.
1043
+ */
1044
+ type SetupStateSchemaToStateSchema<TSetupSchema extends SetupStateSchema> = {
1045
+ input: StateInput<TSetupSchema>;
1046
+ contextSchema: TSetupSchema['schemas'] extends {
1047
+ context: infer TContextSchema;
1048
+ } ? TContextSchema extends StandardSchemaV1 ? TContextSchema : undefined : undefined;
1049
+ outputSchema: TSetupSchema['schemas'] extends {
1050
+ output: infer TOutputSchema;
1051
+ } ? TOutputSchema extends StandardSchemaV1 ? TOutputSchema : undefined : undefined;
1052
+ states: TSetupSchema['states'] extends Record<string, SetupStateSchema> ? { [K in keyof TSetupSchema['states'] & string]: SetupStateSchemaToStateSchema<TSetupSchema['states'][K]>; } : undefined;
1053
+ } & SetupStateSchemaMetadata<TSetupSchema>;
1054
+ /** Converts the root setup states config to a StateSchema. */
1055
+ type SetupStatesToStateSchema<TStates extends Record<string, SetupStateSchema>> = {
1056
+ states: { [K in keyof TStates & string]: SetupStateSchemaToStateSchema<TStates[K]>; };
1057
+ };
1058
+ type EmptyStateSchema = {
1059
+ input: undefined;
1060
+ states: undefined;
1061
+ };
1062
+ type StateSchemaInput<TConfig extends StateSchema, TSetup extends StateSchema> = TSetup extends {
1063
+ input: infer TInput;
1064
+ } ? TInput : TConfig extends {
1065
+ input: infer TInput;
1066
+ } ? TInput : undefined;
1067
+ type StateSchemaContextSchema<TConfig extends StateSchema, TSetup extends StateSchema> = TSetup extends {
1068
+ contextSchema: infer TContextSchema;
1069
+ } ? TContextSchema extends StandardSchemaV1 ? TContextSchema : undefined : TConfig extends {
1070
+ contextSchema: infer TContextSchema;
1071
+ } ? TContextSchema extends StandardSchemaV1 ? TContextSchema : undefined : undefined;
1072
+ type StateSchemaOutputSchema<TConfig extends StateSchema, TSetup extends StateSchema> = TSetup extends {
1073
+ outputSchema: infer TOutputSchema;
1074
+ } ? TOutputSchema extends StandardSchemaV1 ? TOutputSchema : undefined : TConfig extends {
1075
+ outputSchema: infer TOutputSchema;
1076
+ } ? TOutputSchema extends StandardSchemaV1 ? TOutputSchema : undefined : undefined;
1077
+ type StateSchemaChild<TSetup extends StateSchema, K extends string> = TSetup extends {
1078
+ states: infer TStates;
1079
+ } ? K extends keyof TStates ? Cast<TStates[K], StateSchema> : EmptyStateSchema : EmptyStateSchema;
1080
+ type StateMetadataField<TConfig, TSetup extends StateSchema, TKey extends keyof StateSchema> = TConfig extends Record<TKey, infer TValue> ? { [K in TKey]: TValue; } : TSetup extends Record<TKey, infer TValue> ? { [K in TKey]: TValue; } : {};
1081
+ type MergeStateSchemaMetadata<TConfig extends StateSchema, TSetup extends StateSchema> = StateMetadataField<TConfig, TSetup, 'id'> & StateMetadataField<TConfig, TSetup, 'route'> & StateMetadataField<TConfig, TSetup, 'type'> & StateMetadataField<TConfig, TSetup, 'initial'> & StateMetadataField<TConfig, TSetup, 'history'> & StateMetadataField<TConfig, TSetup, 'target'>;
1082
+ /** Adds setup-declared topology to authored config for structural validation. */
1083
+ type MergeSetupConfigState<TConfig, TSetup extends StateSchema> = Omit<TConfig, 'id' | 'route' | 'type' | 'initial' | 'history' | 'target' | 'states'> & StateMetadataField<TConfig, TSetup, 'id'> & StateMetadataField<TConfig, TSetup, 'route'> & StateMetadataField<TConfig, TSetup, 'type'> & StateMetadataField<TConfig, TSetup, 'initial'> & StateMetadataField<TConfig, TSetup, 'history'> & StateMetadataField<TConfig, TSetup, 'target'> & (TConfig extends {
1084
+ states: infer TStates;
1085
+ } ? TStates extends Record<string, unknown> ? {
1086
+ states: { [K in keyof TStates & string]: MergeSetupConfigState<TStates[K], StateSchemaChild<TSetup, K>>; };
1087
+ } : {
1088
+ states: TStates;
1089
+ } : {});
1090
+ type MergeSetupConfig<TConfig, TStates extends Record<string, SetupStateSchema>> = MergeSetupConfigState<TConfig, SetupStatesToStateSchema<TStates>>;
1091
+ type MergeStateSchema<TConfig extends StateSchema, TSetup extends StateSchema> = Omit<TConfig, 'contextSchema' | 'input' | 'states'> & {
1092
+ contextSchema: StateSchemaContextSchema<TConfig, TSetup>;
1093
+ outputSchema: StateSchemaOutputSchema<TConfig, TSetup>;
1094
+ input: StateSchemaInput<TConfig, TSetup>;
1095
+ states: TConfig extends {
1096
+ states: infer TStates;
1097
+ } ? TStates extends Record<string, StateSchema> ? { [K in keyof TStates & string]: MergeStateSchema<TStates[K], StateSchemaChild<TSetup, K>>; } : undefined : undefined;
1098
+ } & MergeStateSchemaMetadata<TConfig, TSetup>;
1099
+ type SetupMachineStateSchema<TConfig, TStateSchemas extends Record<string, SetupStateSchema>> = HasExplicitSetupStateContracts<TStateSchemas> extends true ? MergeStateSchema<Cast<TConfig, StateSchema>, SetupStatesToStateSchema<TStateSchemas>> : Cast<TConfig, StateSchema>;
1100
+ type PublicInvoke<T> = T extends readonly (infer TEntry)[] ? readonly PublicInvoke<TEntry>[] : T extends {
1101
+ src: infer TSrc;
1102
+ } ? {
1103
+ src: TSrc;
1104
+ } : never;
1105
+ type PublicStateField<T, K extends PropertyKey> = T extends Record<K, infer TValue> ? { [P in K]: TValue; } : {};
1106
+ type PublicStateSchema<T extends StateSchema> = {
1107
+ input: T extends {
1108
+ input: infer TInput;
1109
+ } ? TInput : undefined;
1110
+ } & PublicStateField<T, 'id'> & PublicStateField<T, 'version'> & PublicStateField<T, 'route'> & PublicStateField<T, 'type'> & PublicStateField<T, 'history'> & PublicStateField<T, 'target'> & PublicStateField<T, 'initial'> & PublicStateField<T, 'contextSchema'> & PublicStateField<T, 'outputSchema'> & PublicStateField<T, 'internalEvents'> & (T extends {
1111
+ invoke: infer TInvoke;
1112
+ } ? {
1113
+ invoke: PublicInvoke<TInvoke>;
1114
+ } : {}) & (T extends {
1115
+ states: infer TStates extends Record<string, StateSchema>;
1116
+ } ? {
1117
+ states: { [K in keyof TStates]: PublicStateSchema<TStates[K]>; };
1118
+ } : {});
1119
+ /** Machine config without setup-declared state contracts. */
1120
+ type SetupMachineConfigBase<_TStateSchemas extends Record<string, SetupStateSchema>, TStateKeys extends string, TSchemas extends SetupSchemas, TContextSchema extends StandardSchemaV1, TEventSchemaMap extends Record<string, StandardSchemaV1>, TInternalEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTransitionMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, TChildrenSchemaMap extends Record<string, StandardSchemaV1>, TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TEmitted extends EventObject, TStateMeta extends MetaObject, TTransitionMeta extends MetaObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry, TContextRequired extends boolean, TRootDelays extends string = TDelays, TRootActionMap extends Sources['actions'] = TActionMap, TRootActorMap extends Sources['actors'] = TActorMap, TRootGuardMap extends Sources['guards'] = TGuardMap> = Omit<Next_MachineConfig<SetupOrConfigSchema<TSchemas, 'context', TContextSchema>, SetupOrConfigSchemaMap<TSchemas, 'events', TEventSchemaMap>, SetupOrConfigSchemaMap<TSchemas, 'internalEvents', TInternalEventSchemaMap>, SetupOrConfigSchemaMap<TSchemas, 'emitted', TEmittedSchemaMap>, SetupOrConfigSchema<TSchemas, 'input', TInputSchema>, SetupOrConfigSchema<TSchemas, 'output', TOutputSchema>, SetupOrConfigSchema<TSchemas, 'meta', TMetaSchema>, SetupOrConfigSchema<TSchemas, 'transitionMeta', TTransitionMetaSchema>, SetupOrConfigSchema<TSchemas, 'tags', TTagSchema>, SetupOrConfigSchemaMap<TSchemas, 'children', TChildrenSchemaMap>, TContext, TEvent, TChildren, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap, TContextRequired, TSystemRegistry>, 'states' | 'initial' | 'on' | 'always' | 'invoke' | 'actions' | 'actors' | 'guards' | 'delays'> & {
1121
+ actions?: TRootActionMap;
1122
+ actors?: TRootActorMap;
1123
+ guards?: TRootGuardMap & GuardSourceMap<TContext, TEvent>;
1124
+ delays?: { [K in TRootDelays | number]?: number | (({ context, event, stateNode }: {
1125
+ context: TContext;
1126
+ event: TEvent;
1127
+ stateNode: AnyStateNode;
1128
+ }) => number); };
1129
+ initial?: string | {
1130
+ target: string;
1131
+ meta?: TTransitionMeta;
1132
+ description?: string;
1133
+ input?: unknown;
1134
+ } | undefined;
1135
+ on?: StateTransitions<UncheckedSetupStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TEmitted, TChildren, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
1136
+ always?: StateTransitionConfigOrTarget<UncheckedSetupStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TEvent, TEmitted, TChildren, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
1137
+ invoke?: SingleOrArray<SetupInvokeConfig<UncheckedSetupStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TEmitted, TChildren, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, SetupInput<TSchemas, TInputSchema>>>;
1138
+ states?: StatesWithInput<UncheckedSetupStateSchemas, UncheckedSetupStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TChildren, TDelays, TTag, SetupOutput<TSchemas, TOutputSchema>, TEmitted, TStateMeta, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, TStateKeys>;
1139
+ };
1140
+ /** Machine config with typed state input */
1141
+ type SetupMachineConfig<TStateSchemas extends Record<string, SetupStateSchema>, TStateKeys extends string, TSchemas extends SetupSchemas, TContextSchema extends StandardSchemaV1, TEventSchemaMap extends Record<string, StandardSchemaV1>, TInternalEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTransitionMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, TChildrenSchemaMap extends Record<string, StandardSchemaV1>, TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TEmitted extends EventObject, TStateMeta extends MetaObject, TTransitionMeta extends MetaObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry, TContextRequired extends boolean, TRootDelays extends string = TDelays, TRootActionMap extends Sources['actions'] = TActionMap, TRootActorMap extends Sources['actors'] = TActorMap, TRootGuardMap extends Sources['guards'] = TGuardMap> = HasExplicitSetupStateContracts<TStateSchemas> extends true ? Omit<SetupMachineConfigBase<TStateSchemas, TStateKeys, TSchemas, TContextSchema, TEventSchemaMap, TInternalEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTransitionMetaSchema, TTagSchema, TChildrenSchemaMap, TContext, TEvent, TChildren, TDelays, TTag, TEmitted, TStateMeta, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, TContextRequired, TRootDelays, TRootActionMap, TRootActorMap, TRootGuardMap>, 'states' | 'initial' | 'on' | 'always' | 'invoke'> & {
1142
+ initial?: SetupInitialStateKey<TStateSchemas, TStateKeys> | RootInitialTransitionWithInput<TStateSchemas, TContext, TEvent, TTransitionMeta> | undefined;
1143
+ on?: StateTransitions<TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TEmitted, TChildren, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, undefined, RootSetupStateTarget<TStateSchemas>, RootSetupStateTarget<TStateSchemas>>;
1144
+ always?: StateTransitionConfigOrTarget<TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TEvent, TEmitted, TChildren, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, undefined, RootSetupStateTarget<TStateSchemas>, RootSetupStateTarget<TStateSchemas>>;
1145
+ invoke?: SingleOrArray<SetupInvokeConfig<RootSetupStateTransitionSchemas<TStateSchemas>, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TEmitted, TChildren, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, SetupInput<TSchemas, TInputSchema>>>;
1146
+ states?: StatesWithInput<TStateSchemas, TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TChildren, TDelays, TTag, SetupOutput<TSchemas, TOutputSchema>, TEmitted, TStateMeta, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, TStateKeys>;
1147
+ } : SetupMachineConfigBase<TStateSchemas, TStateKeys, TSchemas, TContextSchema, TEventSchemaMap, TInternalEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTransitionMetaSchema, TTagSchema, TChildrenSchemaMap, TContext, TEvent, TChildren, TDelays, TTag, TEmitted, TStateMeta, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, TContextRequired, TRootDelays, TRootActionMap, TRootActorMap, TRootGuardMap>;
1148
+ /** States config type that provides typed input for known states */
1149
+ type StatesWithInput<TRootStateSchemas extends Record<string, SetupStateSchema>, TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TOutput, TEmitted extends EventObject, TStateMeta extends MetaObject, TTransitionMeta extends MetaObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry, TStateKeys extends string = SetupStateKey<TStateSchemas>> = { [K in TStateKeys]?: StateNodeConfigWithNestedInput<StateSchemasWithKeys<TRootStateSchemas, TStateKeys>, K extends keyof TStateSchemas ? TStateSchemas[K] : {}, TContext, TContextShape, TEvent, TChildren, TDelays, TTag, TOutput, TEmitted, TStateMeta, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>; };
1150
+ /** State node config that recursively applies typed input for nested states */
1151
+ type StateNodeConfigWithNestedInputBase<TSiblingStateSchemas extends Record<string, SetupStateSchema>, TStateSchema extends SetupStateSchema, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TOutput, TEmitted extends EventObject, TStateMeta extends MetaObject, TTransitionMeta extends MetaObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry> = WithNestedStates<DistributiveOmit<Next_StateNodeConfig<ActiveStateContext<TStateSchema, TContext, TContextShape>, TEvent, TDelays, TTag, StateOutput<TStateSchema, TOutput>, TEmitted, TStateMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, StateInput<TStateSchema>, Record<string, unknown>, TSystemRegistry, StateCompletionOutput<TStateSchema>, TTransitionMeta>, 'on' | 'always' | 'initial' | 'invoke' | 'onDone' | 'onError' | 'onTimeout' | 'after'> & {
1152
+ initial?: TStateSchema['states'] extends Record<string, SetupStateSchema> ? SetupStateKey<TStateSchema['states']> | (string & {}) | InitialTransitionWithInput<TStateSchema['states'], ActiveStateContext<TStateSchema, TContext, TContextShape>, TEvent, TTransitionMeta> : string | {
1153
+ target: string;
1154
+ meta?: TTransitionMeta;
1155
+ description?: string;
1156
+ input?: Record<string, unknown>;
1157
+ } | undefined;
1158
+ } & {
1159
+ on?: StateTransitions<SetupStateTransitionSchemas<TSiblingStateSchemas, TStateSchema>, ActiveStateContext<TStateSchema, TContext, TContextShape>, ActiveStateContextShape<TStateSchema, TContextShape>, TEvent, TEmitted, TChildren, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, StateInput<TStateSchema>>;
1160
+ always?: StateTransitionConfigOrTarget<SetupStateTransitionSchemas<TSiblingStateSchemas, TStateSchema>, ActiveStateContext<TStateSchema, TContext, TContextShape>, ActiveStateContextShape<TStateSchema, TContextShape>, TEvent, TEvent, TEmitted, TChildren, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, StateInput<TStateSchema>>;
1161
+ invoke?: SingleOrArray<SetupInvokeConfig<SetupStateTransitionSchemas<TSiblingStateSchemas, TStateSchema>, ActiveStateContext<TStateSchema, TContext, TContextShape>, ActiveStateContextShape<TStateSchema, TContextShape>, TEvent, TEmitted, TChildren, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, StateInput<TStateSchema>>>;
1162
+ onDone?: StateTransitionConfigOrTarget<SetupStateTransitionSchemas<TSiblingStateSchemas, TStateSchema>, ActiveStateContext<TStateSchema, TContext, TContextShape>, ActiveStateContextShape<TStateSchema, TContextShape>, DoneStateEvent<StateCompletionOutput<TStateSchema>>, TEvent, TEmitted, TChildren, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, StateInput<TStateSchema>>;
1163
+ onError?: StateTransitionConfigOrTarget<SetupStateTransitionSchemas<TSiblingStateSchemas, TStateSchema>, ActiveStateContext<TStateSchema, TContext, TContextShape>, ActiveStateContextShape<TStateSchema, TContextShape>, ErrorEvent, TEvent, TEmitted, TChildren, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, StateInput<TStateSchema>>;
1164
+ onTimeout?: StateTransitionConfigOrTarget<SetupStateTransitionSchemas<TSiblingStateSchemas, TStateSchema>, ActiveStateContext<TStateSchema, TContext, TContextShape>, ActiveStateContextShape<TStateSchema, TContextShape>, TimeoutEvent, TEvent, TEmitted, TChildren, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, StateInput<TStateSchema>>;
1165
+ after?: { [K in NoInfer<TDelays> | number | DelayDurationKey]?: StateTransitionConfigOrTarget<SetupStateTransitionSchemas<TSiblingStateSchemas, TStateSchema>, ActiveStateContext<TStateSchema, TContext, TContextShape>, ActiveStateContextShape<TStateSchema, TContextShape>, AfterEvent, TEvent, TEmitted, TChildren, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, StateInput<TStateSchema>>; };
1166
+ }, TStateSchema['states'] extends Record<string, SetupStateSchema> ? StatesWithInput<SetupStateSchemasWithParentType<WithRootSetupStateSchemas<TStateSchema['states'], RootSetupStateSchemas<TSiblingStateSchemas>>, TStateSchema extends {
1167
+ type: infer TType extends SetupStateType;
1168
+ } ? TType : never>, TStateSchema['states'], TContext, ActiveStateContextShape<TStateSchema, TContextShape>, TEvent, TChildren, TDelays, TTag, TOutput, TEmitted, TStateMeta, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry> : { [K in string]?: StateNodeConfigWithNestedInput<UncheckedSetupStateSchemas, SetupStateSchema, TContext, ActiveStateContextShape<TStateSchema, TContextShape>, TEvent, TChildren, TDelays, TTag, TOutput, TEmitted, TStateMeta, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>; }>;
1169
+ type StateNodeConfigWithNestedInput<TSiblingStateSchemas extends Record<string, SetupStateSchema>, TStateSchema extends SetupStateSchema, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TOutput, TEmitted extends EventObject, TStateMeta extends MetaObject, TTransitionMeta extends MetaObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry> = SetupStateNodeContract<TStateSchema, StateNodeConfigWithNestedInputBase<TSiblingStateSchemas, TStateSchema, TContext, TContextShape, TEvent, TChildren, TDelays, TTag, TOutput, TEmitted, TStateMeta, TTransitionMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>, TContext, TEvent, TSiblingStateSchemas>;
1170
+ type StateTransitions<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry, TInput = undefined, TTarget extends string = SetupStateTarget<TStateSchemas>, TKnownTarget extends string = KnownSetupStateTarget<TStateSchemas>> = { [K in EventDescriptor<TEvent>]?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, ExtractEvent<TEvent, K>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, TInput, TTarget, TKnownTarget>; } & (string extends TEvent['type'] ? unknown : { [K in `xstate.${string}`]?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, {
1171
+ type: K;
1172
+ }, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, TInput, TTarget, TKnownTarget>; });
1173
+ type InvokeDoneEvent<TInvoke> = TInvoke extends {
1174
+ onDone?: Next_TransitionConfigOrTarget<infer _TContext, infer TDoneEvent, infer _TEvent, infer _TEmitted, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap, infer _TMeta>;
1175
+ } ? Cast<TDoneEvent, EventObject> : DoneActorEvent;
1176
+ type PlainSetupInvokeConfig<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry, TStateInput = undefined> = Next_InvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry, TStateInput> extends (infer TInvoke) ? TInvoke extends any ? DistributiveOmit<TInvoke, 'onDone' | 'onError' | 'onSnapshot' | 'onTimeout'> & {
1177
+ onDone?: TInvoke extends {
1178
+ onDone?: infer TOnDone;
1179
+ } ? [Extract<NonNullable<TOnDone>, (...args: any[]) => unknown>] extends [never] ? undefined | StateTransitionObjectConfig<TStateSchemas, TContext, TContextShape, DoneActorEvent, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, false> : StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, InvokeDoneEvent<TInvoke>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry> : never;
1180
+ onError?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, InvokeErrorEvent<TInvoke, TActorMap>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
1181
+ onSnapshot?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, SnapshotEvent<any>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
1182
+ onTimeout?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, TEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
1183
+ } : never : never;
1184
+ declare const createdInvoke: unique symbol;
1185
+ /** @public Type-only scope carried by setup-created invoke configs. */
1186
+ interface CreatedInvoke<TLogic extends AnyActorLogic, TContext extends MachineContext, TContextShape, TStateSchemas extends Record<string, SetupStateSchema>, TStateInput, TConfig = unknown> {
1187
+ src: NoInfer<TLogic>;
1188
+ readonly [createdInvoke]: {
1189
+ context: TContext;
1190
+ contextShape: TContextShape;
1191
+ states: TStateSchemas;
1192
+ input: TStateInput;
1193
+ child: NoInfer<{
1194
+ id: TConfig extends {
1195
+ id: infer TId;
1196
+ } ? TId : undefined;
1197
+ ref: ActorRefFromLogic<TLogic>;
1198
+ }>;
1199
+ };
1200
+ readonly [createdInvokeConfig]: NoInfer<TConfig>;
1201
+ }
1202
+ type CreatedInvokeTransitionData<TTransition> = TTransition extends ((...args: any[]) => infer TResult) ? CreatedInvokeTransitionData<TResult> : TTransition extends {
1203
+ target: infer TTarget;
1204
+ } ? {
1205
+ target: TTarget;
1206
+ } & (TTransition extends {
1207
+ input: infer TInput;
1208
+ } ? {
1209
+ input: TInput extends ((...args: any[]) => infer TResult) ? TResult : TInput;
1210
+ } : unknown) : {};
1211
+ type CreatedInvokeValidationConfig<TConfig> = TConfig extends unknown ? { [K in keyof TConfig as K extends 'id' | 'onDone' | 'onError' | 'onSnapshot' | 'onTimeout' ? K : never]: K extends 'id' ? TConfig[K] : CreatedInvokeTransitionData<TConfig[K]>; } : never;
1212
+ type CreatedInvokeId<TLogic extends AnyActorLogic, TChildren> = string extends keyof TChildren ? {
1213
+ id?: string;
1214
+ } : [keyof TChildren] extends [never] ? {
1215
+ id?: string;
1216
+ } : {
1217
+ id: { [K in keyof TChildren & string]: ActorRefFromLogic<TLogic> extends NonNullable<TChildren[K]> ? K : never; }[keyof TChildren & string];
1218
+ };
1219
+ type CreatedInvokeChildContract<TChildren> = string extends keyof TChildren ? unknown : [keyof TChildren] extends [never] ? unknown : { [K in keyof TChildren & string]: {
1220
+ id: K;
1221
+ ref: NonNullable<TChildren[K]>;
1222
+ }; }[keyof TChildren & string];
1223
+ type ValidateCreatedInvokeChild<TInvoke, TChildren> = TInvoke extends {
1224
+ readonly [createdInvoke]: unknown;
1225
+ } ? {
1226
+ readonly [createdInvoke]: {
1227
+ child: CreatedInvokeChildContract<TChildren>;
1228
+ };
1229
+ } : TInvoke extends readonly unknown[] ? { [K in keyof TInvoke]: ValidateCreatedInvokeChild<TInvoke[K], TChildren>; } : unknown;
1230
+ type ValidateCreatedInvokeChildren<TConfig, TChildren> = (TConfig extends {
1231
+ invoke: infer TInvoke;
1232
+ } ? {
1233
+ invoke?: ValidateCreatedInvokeChild<TInvoke, TChildren>;
1234
+ } : unknown) & (TConfig extends {
1235
+ states: infer TStates;
1236
+ } ? {
1237
+ states?: { [K in keyof TStates]: ValidateCreatedInvokeChildren<TStates[K], TChildren>; };
1238
+ } : unknown);
1239
+ type CreatedInvokeInput<TLogic extends AnyActorLogic, TArgs, TInput = InputFrom<NoInfer<TLogic>>, TValue = TInput | ((args: TArgs) => TInput)> = undefined extends TInput ? {
1240
+ input?: TValue;
1241
+ } : {
1242
+ input: TValue;
1243
+ };
1244
+ /** @public An invoke config whose callbacks are checked against its source logic. */
1245
+ type CreateInvokeConfig<TLogic extends AnyActorLogic, TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry, TStateInput = undefined> = CreatedInvokeId<NoInfer<TLogic>, TChildren> & CreatedInvokeInput<TLogic, InvokeInputArgs<TContext, TEvent, TEmitted, TChildren, TStateInput>> & Omit<Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry, DoneActorEvent<OutputFrom<NoInfer<TLogic>>>, ErrorActorEvent<ErrorFrom<NoInfer<TLogic>>>>, 'id' | 'onDone' | 'onError' | 'onSnapshot' | 'onTimeout'> & {
1246
+ src: TLogic;
1247
+ schemas?: never;
1248
+ onDone?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, DoneActorEvent<OutputFrom<NoInfer<TLogic>>>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
1249
+ onError?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, ErrorActorEvent<ErrorFrom<NoInfer<TLogic>>>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
1250
+ onSnapshot?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, SnapshotEvent<SnapshotFrom<NoInfer<TLogic>>>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
1251
+ onTimeout?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, ActorTimeoutEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
1252
+ };
1253
+ type AsyncInvokeSchemaOutput<TSchema extends StandardSchemaV1, TFallback> = StandardSchemaV1 extends TSchema ? TFallback : StandardSchemaV1.InferOutput<TSchema>;
1254
+ /** @public An inline async invoke whose schemas and function determine its actor types. */
1255
+ type CreateAsyncInvokeConfig<TOutput, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TErrorSchema extends StandardSchemaV1, TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry, TStateInput = undefined> = CreatedInvokeId<AsyncActorLogic<NoInfer<TOutput>, AsyncInvokeSchemaOutput<NoInfer<TInputSchema>, NonReducibleUnknown>, EventObject, AsyncInvokeSchemaOutput<NoInfer<TErrorSchema>, unknown>>, TChildren> & CreatedInvokeInput<AsyncActorLogic<unknown, AsyncInvokeSchemaOutput<NoInfer<TInputSchema>, NonReducibleUnknown>>, InvokeInputArgs<TContext, TEvent, TEmitted, TChildren, TStateInput>> & Omit<Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry>, 'id' | 'onDone' | 'onError' | 'onSnapshot' | 'onTimeout'> & {
1256
+ schemas?: {
1257
+ input?: TInputSchema;
1258
+ output?: StandardSchemaV1 extends TOutputSchema ? never : TOutputSchema;
1259
+ error?: TErrorSchema;
1260
+ };
1261
+ src: (...args: Parameters<LogicFunction<AsyncInvokeSchemaOutput<NoInfer<TOutputSchema>, unknown>, AsyncInvokeSchemaOutput<NoInfer<TInputSchema>, NonReducibleUnknown>>>) => PromiseLike<TOutput>;
1262
+ onDone?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, DoneActorEvent<NoInfer<TOutput>>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, undefined, SetupStateTarget<TStateSchemas>, KnownSetupStateTarget<TStateSchemas>, NoInfer<TOutput>>;
1263
+ onError?: NoInfer<StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, ErrorActorEvent<NoInfer<AsyncInvokeSchemaOutput<TErrorSchema, unknown>>>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>>;
1264
+ onSnapshot?: NoInfer<StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, SnapshotEvent<AsyncSnapshot<TOutput, NoInfer<AsyncInvokeSchemaOutput<TInputSchema, NonReducibleUnknown>>, NoInfer<AsyncInvokeSchemaOutput<TErrorSchema, unknown>>>>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>>;
1265
+ onTimeout?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, ActorTimeoutEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
1266
+ };
1267
+ type SetupInvokeConfig<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry, TStateInput = undefined> = (PlainSetupInvokeConfig<TStateSchemas, TContext, TContextShape, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, TStateInput> & {
1268
+ readonly [createdInvoke]?: never;
1269
+ }) | {
1270
+ readonly [createdInvoke]: {
1271
+ context: TContext;
1272
+ contextShape: TContextShape;
1273
+ states: TStateSchemas extends UncheckedSetupStateSchemas ? Record<string, SetupStateSchema> : TStateSchemas;
1274
+ input: TStateInput;
1275
+ };
1276
+ };
1277
+ type InvokeErrorEvent<TInvoke, TActorMap extends Sources['actors']> = TInvoke extends {
1278
+ src: infer TSrc;
1279
+ } ? TSrc extends keyof TActorMap & string ? ErrorActorEvent<ErrorFrom<TActorMap[TSrc]>> : TSrc extends AnyActorLogic ? ErrorActorEvent<ErrorFrom<TSrc>> : ErrorActorEvent : ErrorActorEvent;
1280
+ type StateTransitionConfigOrTarget<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry, TInput = undefined, TTarget extends string = SetupStateTarget<TStateSchemas>, TKnownTarget extends string = KnownSetupStateTarget<TStateSchemas>, TOutput = OutputArg<TExpressionEvent>['output']> = undefined | StateTransitionObjectConfig<TStateSchemas, TContext, TContextShape, TExpressionEvent, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, true, TTarget, TKnownTarget> | StateTransitionFunction<TStateSchemas, TContext, TContextShape, TExpressionEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, TInput, TTarget, TKnownTarget, TOutput>;
1281
+ type StateTransitionObjectConfig<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TExpressionEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry, TAllowContextMapper extends boolean = true, TTarget extends string = SetupStateTarget<TStateSchemas>, TKnownTarget extends string = KnownSetupStateTarget<TStateSchemas>> = (StateTransitionResult<TStateSchemas, TContext, TContextShape, TMeta, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, TAllowContextMapper, TTarget, TKnownTarget> & {
1282
+ description?: string;
1283
+ }) | {
1284
+ target: TTarget[];
1285
+ context?: StateTransitionContext<TAllowContextMapper, TContext, TContextShape, TContextShape, TContext, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
1286
+ description?: string;
1287
+ reenter?: boolean;
1288
+ meta?: TMeta;
1289
+ input?: Record<string, unknown> | ((args: {
1290
+ context: TContext;
1291
+ event: TExpressionEvent;
1292
+ } & OutputArg<TExpressionEvent>) => Record<string, unknown>);
1293
+ };
1294
+ type StateTransitionContextMapper<TContext extends MachineContext, TContextShape, TTargetContextShape, TResolvedTargetContext extends MachineContext, TExpressionEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry> = (args: {
1295
+ context: TContext;
1296
+ event: TExpressionEvent;
1297
+ self: AnyActorRef;
1298
+ parent: AnyActorRef | undefined;
1299
+ value: StateValue;
1300
+ children: TChildren;
1301
+ system: SystemRuntime<TSystemRegistry>;
1302
+ actions: TActionMap;
1303
+ actors: Compute<CallbackActors<TActorMap>>;
1304
+ guards: TGuardMap;
1305
+ delays: TDelayMap;
1306
+ } & OutputArg<TExpressionEvent>) => ContextPatch<TContextShape, TTargetContextShape, TResolvedTargetContext>;
1307
+ type StateTransitionContextOrMapper<TContext extends MachineContext, TContextShape, TTargetContextShape, TResolvedTargetContext extends MachineContext, TExpressionEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry> = ContextPatch<TContextShape, TTargetContextShape, TResolvedTargetContext> | StateTransitionContextMapper<TContext, TContextShape, TTargetContextShape, TResolvedTargetContext, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
1308
+ type StateTransitionContext<TAllowMapper extends boolean, TContext extends MachineContext, TContextShape, TTargetContextShape, TResolvedTargetContext extends MachineContext, TExpressionEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry> = TAllowMapper extends true ? StateTransitionContextOrMapper<TContext, TContextShape, TTargetContextShape, TResolvedTargetContext, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry> : ContextPatch<TContextShape, TTargetContextShape, TResolvedTargetContext>;
1309
+ type StateTransitionFunction<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry, TInput = undefined, TTarget extends string = SetupStateTarget<TStateSchemas>, TKnownTarget extends string = KnownSetupStateTarget<TStateSchemas>, TOutput = OutputArg<TExpressionEvent>['output']> = (args: {
1310
+ context: TContext;
1311
+ event: TExpressionEvent;
1312
+ output: TOutput;
1313
+ self: AnyActorRef;
1314
+ parent: AnyActorRef | undefined;
1315
+ value: StateValue;
1316
+ children: TChildren;
1317
+ system: SystemRuntime<TSystemRegistry>;
1318
+ actions: TActionMap;
1319
+ actors: Compute<CallbackActors<TActorMap>>;
1320
+ guards: TGuardMap;
1321
+ delays: TDelayMap;
1322
+ input: TInput;
1323
+ }, enq: EnqueueObject<TEvent, TEmitted, TSystemRegistry, Compute<CallbackActors<TActorMap>>, TChildren>) => StateTransitionResult<TStateSchemas, TContext, TContextShape, TMeta, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, false, TTarget, TKnownTarget> | void;
1324
+ type StateTransitionResult<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TMeta extends MetaObject, TExpressionEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry, TAllowContextMapper extends boolean, TTarget extends string = SetupStateTarget<TStateSchemas>, TKnownTarget extends string = KnownSetupStateTarget<TStateSchemas>> = {
1325
+ target?: never;
1326
+ context?: StateTransitionContext<TAllowContextMapper, TContext, TContextShape, TContextShape, TContext, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
1327
+ reenter?: boolean;
1328
+ meta?: TMeta;
1329
+ } | { [K in TKnownTarget]: {
1330
+ target: K;
1331
+ reenter?: boolean;
1332
+ meta?: TMeta;
1333
+ } & SetupStateInputConfig<SetupStateSchemaAtTarget<TStateSchemas, K>, TContext, TExpressionEvent, {
1334
+ context: TContext;
1335
+ event: TExpressionEvent;
1336
+ } & OutputArg<TExpressionEvent>> & ([TContextShape] extends [StateContextShape<SetupStateSchemaAtTarget<TStateSchemas, K>, TContextShape>] ? {
1337
+ context?: StateTransitionContext<TAllowContextMapper, TContext, TContextShape, StateContextShape<SetupStateSchemaAtTarget<TStateSchemas, K>, TContextShape>, StateContext<SetupStateSchemaAtTarget<TStateSchemas, K>, TContext>, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
1338
+ } : {
1339
+ context: StateTransitionContext<TAllowContextMapper, TContext, TContextShape, StateContextShape<SetupStateSchemaAtTarget<TStateSchemas, K>, TContextShape>, StateContext<SetupStateSchemaAtTarget<TStateSchemas, K>, TContext>, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
1340
+ }); }[TKnownTarget] | {
1341
+ target: TStateSchemas extends StrictSetupStateTargetsFlag ? never : Exclude<TTarget, TKnownTarget>;
1342
+ context?: StateTransitionContext<TAllowContextMapper, TContext, TContextShape, TContextShape, TContext, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
1343
+ reenter?: boolean;
1344
+ meta?: TMeta;
1345
+ };
1346
+ type ContextPatch<TCurrentContext, TTargetContext, TResolvedTargetContext extends MachineContext> = Compute<Partial<TResolvedTargetContext> & Pick<TResolvedTargetContext, Extract<RequiredContextKeys<TCurrentContext, TTargetContext>, string>> & {
1347
+ call?: never;
1348
+ apply?: never;
1349
+ bind?: never;
1350
+ }>;
1351
+ type RequiredContextKeys<TCurrentContext, TTargetContext> = { [K in keyof TTargetContext]-?: K extends keyof TCurrentContext ? [TCurrentContext[K]] extends [TTargetContext[K]] ? never : K : K; }[keyof TTargetContext];
1352
+ /** Initial transition with typed input based on target state */
1353
+ type SetupInitialStateKey<TStateSchemas extends Record<string, SetupStateSchema>, TStateKeys extends string> = { [K in TStateKeys]: K extends keyof TStateSchemas ? TStateSchemas[K] extends {
1354
+ type: SetupStateType;
1355
+ } ? RequiresStateInput<TStateSchemas[K]> extends true ? never : K : K : K; }[TStateKeys];
1356
+ type InitialTransitionWithInput<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TEvent extends EventObject, TTransitionMeta extends MetaObject> = { [K in keyof TStateSchemas & string]: {
1357
+ target: K;
1358
+ meta?: TTransitionMeta;
1359
+ description?: string;
1360
+ } & SetupStateInputConfig<TStateSchemas[K], TContext, TEvent>; }[keyof TStateSchemas & string];
1361
+ type RootInitialTransitionWithInput<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TEvent extends EventObject, TTransitionMeta extends MetaObject> = InitialTransitionWithInput<TStateSchemas, TContext, TEvent, TTransitionMeta> | { [K in RootSetupStateIdTarget<TStateSchemas>]: {
1362
+ target: K;
1363
+ meta?: TTransitionMeta;
1364
+ description?: string;
1365
+ } & SetupStateInputConfig<SetupStateSchemaAtTarget<TStateSchemas, K>, TContext, TEvent>; }[RootSetupStateIdTarget<TStateSchemas>];
1366
+ /**
1367
+ * Return type of setup()
1368
+ *
1369
+ * @public
1370
+ */
1371
+ interface SetupReturn<TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TSchemas extends SetupSchemas = {}, TSetupActionMap extends Sources['actions'] = {}, TSetupActorMap extends Sources['actors'] = {}, TSetupGuardMap extends Sources['guards'] = {}, TSetupDelayMap extends Sources['delays'] = {}, TSetupDelays extends string = Extract<keyof TSetupDelayMap, string>, TSystemRegistry extends SystemRegistry = SystemRegistry, TValidator extends ActorLogicValidator | undefined = undefined> {
1372
+ /** Extends the setup configuration */
1373
+ extend<const TExtendSchemas extends SetupSchemas = {}, const TExtendStates extends Record<string, SetupStateSchema> = {}, TExtendActionMap extends Sources['actions'] = {}, TExtendActorMap extends Sources['actors'] = {}, TExtendGuardMap extends Sources['guards'] = {}, TExtendDelayMap extends Sources['delays'] = {}, const TExtendValidator extends ActorLogicValidator | undefined | InheritedValidator = InheritedValidator>(config: SetupExtensionConfig<TSchemas, TStates, TValidator, TExtendSchemas, TExtendStates, TExtendActionMap, TExtendActorMap, TExtendGuardMap, TExtendDelayMap, TExtendValidator>): SetupReturn<MergeSetupStateSchemas<TStates, TExtendStates>, MergeSourceMaps<TSchemas, TExtendSchemas>, MergeSourceMaps<TSetupActionMap, TExtendActionMap>, MergeSourceMaps<TSetupActorMap, TExtendActorMap>, MergeSourceMaps<TSetupGuardMap, TExtendGuardMap>, MergeSourceMaps<TSetupDelayMap, TExtendDelayMap>, TSetupDelays | Extract<keyof TExtendDelayMap, string>, TSystemRegistry, ResolveExtendedValidator<TValidator, TExtendValidator>>;
1374
+ /** Infers async output from src when no output schema is declared. */
1375
+ createInvoke<TOutput, TContext extends SetupContext<TSchemas, StandardSchemaV1>, const TInputSchema extends StandardSchemaV1 = StandardSchemaV1, const TErrorSchema extends StandardSchemaV1 = StandardSchemaV1, TContextShape = SetupContextShape<TSchemas, StandardSchemaV1, TContext>, TStateSchemas extends Record<string, SetupStateSchema> = TStates, TStateInput = undefined, const TConfig = unknown>(config: TConfig & CreateAsyncInvokeConfig<TOutput, TInputSchema, StandardSchemaV1, TErrorSchema, TStateSchemas, TContext, TContextShape, SetupEvents<TSchemas, Record<string, StandardSchemaV1>>, SetupEmitted<TSchemas, Record<string, StandardSchemaV1>>, SetupChildren<TSchemas, Record<string, StandardSchemaV1>>, SetupTransitionMeta<TSchemas, StandardSchemaV1, StandardSchemaV1>, SetupActions<TSchemas, TSetupActionMap>, TSetupActorMap, SetupGuards<TSchemas, TSetupGuardMap>, TSetupDelayMap, TSystemRegistry, TStateInput>, ...check: unknown extends TConfig ? [] : [TConfig] extends [NoInfer<CreateAsyncInvokeConfig<TOutput, TInputSchema, StandardSchemaV1, TErrorSchema, TStateSchemas, TContext, TContextShape, SetupEvents<TSchemas, Record<string, StandardSchemaV1>>, SetupEmitted<TSchemas, Record<string, StandardSchemaV1>>, SetupChildren<TSchemas, Record<string, StandardSchemaV1>>, SetupTransitionMeta<TSchemas, StandardSchemaV1, StandardSchemaV1>, SetupActions<TSchemas, TSetupActionMap>, TSetupActorMap, SetupGuards<TSchemas, TSetupGuardMap>, TSetupDelayMap, TSystemRegistry, TStateInput>> & ValidateSystemInvoke<Omit<TConfig, 'src'> & {
1376
+ src: AsyncActorLogic<AsyncInvokeSchemaOutput<StandardSchemaV1, TOutput>, AsyncInvokeSchemaOutput<TInputSchema, NonReducibleUnknown>, EventObject, AsyncInvokeSchemaOutput<TErrorSchema, unknown>>;
1377
+ }, TSystemRegistry, TSetupActorMap>] ? [] : [invalidConfig: never]): CreatedInvoke<AsyncActorLogic<AsyncInvokeSchemaOutput<StandardSchemaV1, TOutput>, AsyncInvokeSchemaOutput<TInputSchema, NonReducibleUnknown>, EventObject, AsyncInvokeSchemaOutput<TErrorSchema, unknown>>, TContext, TContextShape, TStateSchemas, TStateInput, CreatedInvokeValidationConfig<TConfig>>;
1378
+ /** Creates a typed inline invoke. Keep the call inline to infer its state scope. */
1379
+ createInvoke<TContext extends SetupContext<TSchemas, StandardSchemaV1>, const TInputSchema extends StandardSchemaV1 = StandardSchemaV1, const TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, const TErrorSchema extends StandardSchemaV1 = StandardSchemaV1, TContextShape = SetupContextShape<TSchemas, StandardSchemaV1, TContext>, TStateSchemas extends Record<string, SetupStateSchema> = TStates, TStateInput = undefined, const TConfig = unknown>(config: TConfig & CreateAsyncInvokeConfig<StandardSchemaV1.InferOutput<TOutputSchema>, TInputSchema, TOutputSchema, TErrorSchema, TStateSchemas, TContext, TContextShape, SetupEvents<TSchemas, Record<string, StandardSchemaV1>>, SetupEmitted<TSchemas, Record<string, StandardSchemaV1>>, SetupChildren<TSchemas, Record<string, StandardSchemaV1>>, SetupTransitionMeta<TSchemas, StandardSchemaV1, StandardSchemaV1>, SetupActions<TSchemas, TSetupActionMap>, TSetupActorMap, SetupGuards<TSchemas, TSetupGuardMap>, TSetupDelayMap, TSystemRegistry, TStateInput> & {
1380
+ schemas: {
1381
+ output: TOutputSchema;
1382
+ };
1383
+ }, ...check: unknown extends TConfig ? [] : [TConfig] extends [NoInfer<CreateAsyncInvokeConfig<StandardSchemaV1.InferOutput<TOutputSchema>, TInputSchema, TOutputSchema, TErrorSchema, TStateSchemas, TContext, TContextShape, SetupEvents<TSchemas, Record<string, StandardSchemaV1>>, SetupEmitted<TSchemas, Record<string, StandardSchemaV1>>, SetupChildren<TSchemas, Record<string, StandardSchemaV1>>, SetupTransitionMeta<TSchemas, StandardSchemaV1, StandardSchemaV1>, SetupActions<TSchemas, TSetupActionMap>, TSetupActorMap, SetupGuards<TSchemas, TSetupGuardMap>, TSetupDelayMap, TSystemRegistry, TStateInput>> & ValidateSystemInvoke<Omit<TConfig, 'src'> & {
1384
+ src: AsyncActorLogic<StandardSchemaV1.InferOutput<TOutputSchema>, AsyncInvokeSchemaOutput<TInputSchema, NonReducibleUnknown>, EventObject, AsyncInvokeSchemaOutput<TErrorSchema, unknown>>;
1385
+ }, TSystemRegistry, TSetupActorMap>] ? [] : [invalidConfig: never]): CreatedInvoke<AsyncActorLogic<StandardSchemaV1.InferOutput<TOutputSchema>, AsyncInvokeSchemaOutput<TInputSchema, NonReducibleUnknown>, EventObject, AsyncInvokeSchemaOutput<TErrorSchema, unknown>>, TContext, TContextShape, TStateSchemas, TStateInput, CreatedInvokeValidationConfig<TConfig>>;
1386
+ /** Creates an invoke from actor logic with its existing source types. */
1387
+ createInvoke<TLogic extends AnyActorLogic, TContext extends SetupContext<TSchemas, StandardSchemaV1>, TContextShape = SetupContextShape<TSchemas, StandardSchemaV1, TContext>, TStateSchemas extends Record<string, SetupStateSchema> = TStates, TStateInput = undefined, const TConfig = unknown>(config: TConfig & CreateInvokeConfig<TLogic, TStateSchemas, TContext, TContextShape, SetupEvents<TSchemas, Record<string, StandardSchemaV1>>, SetupEmitted<TSchemas, Record<string, StandardSchemaV1>>, SetupChildren<TSchemas, Record<string, StandardSchemaV1>>, SetupTransitionMeta<TSchemas, StandardSchemaV1, StandardSchemaV1>, SetupActions<TSchemas, TSetupActionMap>, TSetupActorMap, SetupGuards<TSchemas, TSetupGuardMap>, TSetupDelayMap, TSystemRegistry, TStateInput>, ...check: unknown extends TConfig ? [] : [TConfig] extends [NoInfer<CreateInvokeConfig<TLogic, TStateSchemas, TContext, TContextShape, SetupEvents<TSchemas, Record<string, StandardSchemaV1>>, SetupEmitted<TSchemas, Record<string, StandardSchemaV1>>, SetupChildren<TSchemas, Record<string, StandardSchemaV1>>, SetupTransitionMeta<TSchemas, StandardSchemaV1, StandardSchemaV1>, SetupActions<TSchemas, TSetupActionMap>, TSetupActorMap, SetupGuards<TSchemas, TSetupGuardMap>, TSetupDelayMap, TSystemRegistry, TStateInput>> & ValidateSystemInvoke<TConfig, TSystemRegistry, TSetupActorMap>] ? [] : [invalidConfig: never]): CreatedInvoke<TLogic, TContext, TContextShape, TStateSchemas, TStateInput, CreatedInvokeValidationConfig<TConfig>>;
1388
+ /** Creates a state machine with the setup configuration */
1389
+ createMachine<TContextSchema extends StandardSchemaV1 = StandardSchemaV1, const TEventSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, const TInternalEventSchemaMap extends Record<string, StandardSchemaV1> = {}, TEmittedSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1, TTransitionMetaSchema extends StandardSchemaV1 = TMetaSchema, TTagSchema extends StandardSchemaV1 = StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, const TActionSchemaMap extends ActionSchemas = {}, const TGuardSchemaMap extends GuardSchemas = {}, _TEvent extends EventObject = EventObject, TActor extends ProvidedActor = ProvidedActor, TActionMap extends Sources['actions'] = {}, TActorMap extends Sources['actors'] = {}, TGuardMap extends Sources['guards'] = {}, TDelayMap extends Sources['delays'] = {}, TDelays extends string = Extract<keyof TDelayMap, string>, TTag extends SetupTags<TSchemas, TTagSchema> = SetupTags<TSchemas, TTagSchema>, _TInput = unknown, const TStateKeys extends string = SetupStateKey<TStates>, const TConfig extends SetupMachineConfig<TStates, TStateKeys, TSchemas, TContextSchema, TEventSchemaMap, TInternalEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTransitionMetaSchema, TTagSchema, TChildrenSchemaMap, SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap, TInternalEventSchemaMap> | ChildCompletionEvents<Cast<SetupMergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>>, Cast<SetupMergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TSetupDelays | TDelays, TTag, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, SetupTransitionMeta<TSchemas, TMetaSchema, TTransitionMetaSchema>, MergeSourceMaps<SetupActions<TSchemas, TSetupActionMap>, MergeSourceMaps<InferActions<TActionSchemaMap>, TActionMap>>, MergeSourceMaps<TSetupActorMap, TActorMap>, MergeSourceMaps<SetupGuards<TSchemas, TSetupGuardMap>, MergeSourceMaps<InferGuards<TGuardSchemaMap>, TGuardMap>>, MergeSourceMaps<TSetupDelayMap, TDelayMap>, TSystemRegistry, SetupContextRequired<TSchemas, TContextSchema>, TDelays, TActionMap, TActorMap, TGuardMap> = SetupMachineConfig<TStates, TStateKeys, TSchemas, TContextSchema, TEventSchemaMap, TInternalEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTransitionMetaSchema, TTagSchema, TChildrenSchemaMap, SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap, TInternalEventSchemaMap> | ChildCompletionEvents<Cast<SetupMergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>>, Cast<SetupMergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TSetupDelays | TDelays, TTag, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, SetupTransitionMeta<TSchemas, TMetaSchema, TTransitionMetaSchema>, MergeSourceMaps<SetupActions<TSchemas, TSetupActionMap>, MergeSourceMaps<InferActions<TActionSchemaMap>, TActionMap>>, MergeSourceMaps<TSetupActorMap, TActorMap>, MergeSourceMaps<SetupGuards<TSchemas, TSetupGuardMap>, MergeSourceMaps<InferGuards<TGuardSchemaMap>, TGuardMap>>, MergeSourceMaps<TSetupDelayMap, TDelayMap>, TSystemRegistry, SetupContextRequired<TSchemas, TContextSchema>, TDelays, TActionMap, TActorMap, TGuardMap>>(config: {
1390
+ schemas?: {
1391
+ events?: TEventSchemaMap;
1392
+ internalEvents?: TInternalEventSchemaMap;
1393
+ context?: TContextSchema;
1394
+ emitted?: TEmittedSchemaMap;
1395
+ actions?: TActionSchemaMap;
1396
+ guards?: TGuardSchemaMap;
1397
+ input?: TInputSchema;
1398
+ output?: TOutputSchema;
1399
+ meta?: TMetaSchema;
1400
+ transitionMeta?: TTransitionMetaSchema;
1401
+ tags?: TTagSchema;
1402
+ children?: TChildrenSchemaMap;
1403
+ } & ([TValidator] extends [ActorLogicValidator] ? ValidateSetupSchemas<InlineMachineSchemas<TContextSchema, TEventSchemaMap, TInternalEventSchemaMap, TEmittedSchemaMap, TActionSchemaMap, TGuardSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTransitionMetaSchema, TTagSchema, TChildrenSchemaMap>> : unknown);
1404
+ actions?: TActionMap;
1405
+ actors?: TActorMap;
1406
+ guards?: TGuardMap;
1407
+ delays?: TDelayMap;
1408
+ states?: Record<TStateKeys, unknown>;
1409
+ } & TConfig & RuntimeValidationConstraint<NoInfer<MachineConfigSchemas<TConfig>>, NoInfer<MachineConfigStates<TConfig>>, TValidator> & ValidateSetupDelayReferences<TConfig, TSetupDelays> & ValidateSetupStateContracts<TConfig, TStates> & NoInfer<ValidateCreatedInvokeChildren<TConfig, SetupMergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>>> & ValidateEventDescriptors<TConfig, NoInfer<SetupEvents<TSchemas, TEventSchemaMap, TInternalEventSchemaMap>>> & ValidateRegistryKeys<TConfig, TSystemRegistry, MergeSourceMaps<TSetupActorMap, TActorMap>>): [TConfig] extends [never] ? AnyStateMachine : StateMachine<SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap, TInternalEventSchemaMap> | ([RoutableStateId<SetupMachineStateSchema<TConfig, TStates>>] extends [never] ? never : {
1410
+ type: 'xstate.route';
1411
+ to: RoutableStateId<SetupMachineStateSchema<TConfig, TStates>>;
1412
+ }), Cast<SetupMergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, StateValueFromStateSchema<SetupMachineStateSchema<TConfig, TStates>>, TTag & string, SetupInput<TSchemas, TInputSchema>, SetupOrConfigOutput<TSchemas, TOutputSchema, TConfig, TStates>, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, PublicStateSchema<SetupMachineStateSchema<TConfig, TStates>>, MergeSourceMaps<SetupActions<TSchemas, TSetupActionMap>, MergeSourceMaps<InferActions<TActionSchemaMap>, TActionMap>>, MergeSourceMaps<TSetupActorMap, TActorMap>, MergeSourceMaps<SetupGuards<TSchemas, TSetupGuardMap>, MergeSourceMaps<InferGuards<TGuardSchemaMap>, TGuardMap>>, DelayMapFromNames<TSetupDelays | TDelays, MergeSourceMaps<TSetupDelayMap, TDelayMap>>, SetupInternalEvents<TSchemas, TInternalEventSchemaMap>, SetupTransitionMeta<TSchemas, TMetaSchema, TTransitionMetaSchema>> & SetupMachineIdentity<TConfig>;
1413
+ /**
1414
+ * Creates a state node config bound to a specific setup-declared state,
1415
+ * addressed by a dotted path (e.g. `'loading'` or `'parent.child'`). The
1416
+ * addressed state's own `input` schema is typed inside `entry`/`exit` args.
1417
+ */
1418
+ createStateConfig<const TPath extends StatePaths<TStates>, const TConfig extends SetupStateNodeConfig<StrictSetupStateSchemas<ResolveStateSiblingsForPath<TStates, TPath>, SetupStateTransitionChildSchemas<ResolveStatePath<TStates, TPath>>, TStates, SetupStateSelfSchema<ResolveStatePath<TStates, TPath>>>, ResolveStatePath<TStates, TPath>, TSchemas, TSetupActionMap, TSetupActorMap, TSetupGuardMap, TSetupDelayMap, TSystemRegistry>>(path: TPath, config: TConfig & ValidateEventDescriptors<TConfig, NoInfer<SetupEvents<TSchemas, Record<string, StandardSchemaV1>>>> & NoInfer<SetupStateNodeTargetArrayInputConstraint<TConfig, StrictSetupStateSchemas<ResolveStateSiblingsForPath<TStates, TPath>, SetupStateTransitionChildSchemas<ResolveStatePath<TStates, TPath>>, TStates, SetupStateSelfSchema<ResolveStatePath<TStates, TPath>>>, ResolveStatePath<TStates, TPath>, SetupStateChildSchemas<ResolveStatePath<TStates, TPath>>>> & NoInfer<SetupStateTargetSetLegality<TConfig, TStates, TPath>> & ValidateSetupHistoryStateInput<TConfig, ResolveStatePath<TStates, TPath>, WithRootSetupStateSchemas<ResolveStateSiblingsForPath<TStates, TPath>, TStates>>): TConfig;
1419
+ /** Creates a state node config with the setup configuration */
1420
+ createStateConfig<const TConfig extends SetupStateNodeConfig<TStates, SetupStateSchema, TSchemas, TSetupActionMap, TSetupActorMap, TSetupGuardMap, TSetupDelayMap, TSystemRegistry>>(config: TConfig & ValidateEventDescriptors<TConfig, NoInfer<SetupEvents<TSchemas, Record<string, StandardSchemaV1>>>>): TConfig;
1421
+ /** State input schemas from setup config */
1422
+ states: TStates;
1423
+ /** Schemas from setup config */
1424
+ schemas: TSchemas;
1425
+ }
1426
+ type SetupConfigSchemas<TConfig> = TConfig extends {
1427
+ schemas?: infer TSchemas;
1428
+ } ? TSchemas extends SetupSchemas ? TSchemas : {} : {};
1429
+ type SetupConfigStates<TConfig> = TConfig extends {
1430
+ states?: infer TStates;
1431
+ } ? TStates extends Record<string, SetupStateSchema> ? TStates : Record<string, SetupStateSchema> : Record<string, SetupStateSchema>;
1432
+ type SetupConfigActions<TConfig> = TConfig extends {
1433
+ actions?: infer TActions;
1434
+ } ? TActions extends Sources['actions'] ? MergeSourceMaps<SetupActions<SetupConfigSchemas<TConfig>, {}>, TActions> : SetupActions<SetupConfigSchemas<TConfig>, {}> : SetupActions<SetupConfigSchemas<TConfig>, {}>;
1435
+ type SetupConfigActors<TConfig> = TConfig extends {
1436
+ actors?: infer TActors;
1437
+ } ? TActors extends Sources['actors'] ? TActors : {} : {};
1438
+ type SetupConfigGuards<TConfig> = TConfig extends {
1439
+ guards?: infer TGuards;
1440
+ } ? TGuards extends Sources['guards'] ? MergeSourceMaps<SetupGuards<SetupConfigSchemas<TConfig>, {}>, TGuards> : SetupGuards<SetupConfigSchemas<TConfig>, {}> : SetupGuards<SetupConfigSchemas<TConfig>, {}>;
1441
+ type SetupConfigDelays<TConfig> = TConfig extends {
1442
+ delays?: infer TDelays;
1443
+ } ? TDelays extends Sources['delays'] ? TDelays : {} : {};
1444
+ /** @public */
1445
+ type SetupReturnFromConfig<TConfig extends AnySetupConfig, TSystemRegistry extends SystemRegistry = SystemRegistry> = SetupReturn<SetupConfigStates<TConfig>, SetupConfigSchemas<TConfig>, SetupConfigActions<TConfig>, SetupConfigActors<TConfig>, SetupConfigGuards<TConfig>, SetupConfigDelays<TConfig>, Extract<keyof SetupConfigDelays<TConfig>, string>, TSystemRegistry, TConfig extends {
1446
+ validator: infer TValidator extends ActorLogicValidator;
1447
+ } ? TValidator : undefined>;
1448
+ type SetupFunction<TSystemRegistry extends SystemRegistry = SystemRegistry> = {
1449
+ (): SetupReturn<Record<string, SetupStateSchema>, {}, {}, {}, {}, {}, never, TSystemRegistry>;
1450
+ <const TSchemas extends SetupSchemas = {}, const TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TActionMap extends Sources['actions'] = {}, TActorMap extends Sources['actors'] = {}, TGuardMap extends Sources['guards'] = {}, TDelayMap extends Sources['delays'] = {}, const TValidator extends ActorLogicValidator | undefined = undefined>(config: SetupConfig<TSchemas, TStates, TActionMap, TActorMap, TGuardMap, TDelayMap, TValidator> & RuntimeValidationConstraint<NoInfer<TSchemas>, NoInfer<TStates>, TValidator>): SetupReturn<TStates, TSchemas, TActionMap, TActorMap, TGuardMap, TDelayMap, Extract<keyof TDelayMap, string>, TSystemRegistry, TValidator>;
1451
+ <const TConfig extends AnySetupConfig>(config: TConfig & SetupSourceCompanions<SetupConfigSchemas<TConfig>> & RuntimeValidationConstraint<NoInfer<SetupConfigSchemas<TConfig>>, NoInfer<SetupConfigStates<TConfig>>, TConfig extends {
1452
+ validator: infer TValidator;
1453
+ } ? TValidator : undefined>): SetupReturnFromConfig<TConfig, TSystemRegistry>;
1454
+ };
1455
+ /**
1456
+ * Sets up a state machine with state input schemas and other configuration.
1457
+ *
1458
+ * @example
1459
+ *
1460
+ * ```ts
1461
+ * import { setup } from '@systemfsoftware/xstate';
1462
+ * import z from 'zod';
1463
+ *
1464
+ * const s = setup({
1465
+ * states: {
1466
+ * loading: {
1467
+ * schemas: {
1468
+ * input: z.object({
1469
+ * userId: z.string()
1470
+ * })
1471
+ * }
1472
+ * }
1473
+ * }
1474
+ * });
1475
+ *
1476
+ * const machine = s.createMachine({
1477
+ * initial: {
1478
+ * target: 'loading',
1479
+ * input: { userId: '123' }
1480
+ * },
1481
+ * states: {
1482
+ * loading: {
1483
+ * entry: ({ input }) => {
1484
+ * console.log(input.userId);
1485
+ * }
1486
+ * }
1487
+ * }
1488
+ * });
1489
+ * ```
1490
+ * @public
1491
+ */
1492
+ declare const setup: SetupFunction;
1493
+ type SystemActorOptions<TLogic extends AnyActorLogic, TSystemRegistry extends SystemRegistry> = Omit<ActorOptions<TLogic>, 'registryKey'> & {
1494
+ registryKey?: RegistryKeyForLogic<TLogic, TSystemRegistry>;
1495
+ };
1496
+ type SystemBuilder<TSystemRegistry extends SystemRegistry> = {
1497
+ createActor<TLogic extends AnyActorLogic>(logic: TLogic, ...[options]: [RequiredActorOptionsKeys<TLogic>] extends [never] ? [options?: SystemActorOptions<TLogic, TSystemRegistry>] : [options: SystemActorOptions<TLogic, TSystemRegistry> & RequiredActorOptionsFor<TLogic>]): Actor<TLogic>;
1498
+ get: SystemRuntime<TSystemRegistry>['get'];
1499
+ getAll: SystemRuntime<TSystemRegistry>['getAll'];
1500
+ inspect(observer: Observer<InspectionEvent> | ((inspectionEvent: InspectionEvent) => void)): Subscription;
1501
+ onRejectedEvent: AnyActorSystem['onRejectedEvent'];
1502
+ setup: SetupFunction<TSystemRegistry>;
1503
+ };
1504
+ /** @public */
1505
+ declare function createSystem<const TSystemRegistry extends SystemRegistry = {}>(_config?: SystemConfig<TSystemRegistry>): SystemBuilder<TSystemRegistry>;
1506
+ /** @public */
1507
+ interface SimulatedClock extends Clock {
1508
+ start(speed: number): void;
1509
+ increment(ms: number): void;
1510
+ set(ms: number): void;
1511
+ }
1512
+ declare class SimulatedClock implements SimulatedClock {
1513
+ private timeouts;
1514
+ private readonly deadlines;
1515
+ private _now;
1516
+ private _id;
1517
+ private _flushing;
1518
+ now(): number;
1519
+ private getId;
1520
+ setTimeout(fn: (...args: any[]) => void, timeout: number): number;
1521
+ clearTimeout(id: number): void;
1522
+ private flushTimeouts;
1523
+ }
1524
+ /** Immutable definitions for a pure actor system. @experimental */
1525
+ interface SystemLogic<TLogic extends AnyActorLogic = AnyActorLogic> {
1526
+ readonly root: TLogic;
1527
+ /** Additional definitions used by dynamically spawned actors. */
1528
+ readonly actors?: Readonly<Record<string, AnyActorLogic>>;
1529
+ /** Stable names for callable external effects; implementations are never run here. */
1530
+ readonly effects?: Readonly<Record<string, (...args: any[]) => unknown>>;
1531
+ /** Pure, named event/snapshot mappers used by listen and subscribeTo. */
1532
+ readonly mappers?: Readonly<Record<string, (...args: any[]) => AnyEventObject>>;
1533
+ }
1534
+ /** An actor identity, without a live actor or runtime. @experimental */
1535
+ interface SystemActorReference {
1536
+ readonly $actor: string;
1537
+ readonly incarnation: number;
1538
+ }
1539
+ /** Actor state and topology in a system snapshot. @experimental */
1540
+ interface SystemActorState {
1541
+ readonly id: string;
1542
+ readonly address: string;
1543
+ readonly incarnation: number;
1544
+ readonly logic: string;
1545
+ readonly logicVersion?: string;
1546
+ readonly parent?: SystemActorReference;
1547
+ readonly registryKey?: string;
1548
+ readonly syncSnapshot?: boolean;
1549
+ readonly started: boolean;
1550
+ readonly input: unknown;
1551
+ readonly snapshot: Readonly<Record<string, any>>;
1552
+ }
1553
+ /** An accepted message waiting for a completed actor macrostep. @experimental */
1554
+ interface SystemMessage {
1555
+ readonly source?: SystemActorReference | undefined;
1556
+ readonly target: SystemActorReference;
1557
+ readonly event: AnyEventObject;
1558
+ readonly sequence: number;
1559
+ /** Set only by the system scheduler, never by an ordinary send. */
1560
+ readonly timerOccurrence?: number;
1561
+ }
1562
+ /** Absolute deadlines in the system's virtual time domain. @experimental */
1563
+ interface SystemTimer {
1564
+ readonly source: SystemActorReference;
1565
+ readonly id: string;
1566
+ readonly occurrence: number;
1567
+ readonly scheduledAt: number;
1568
+ readonly dueAt: number;
1569
+ readonly sequence: number;
1570
+ readonly event?: AnyEventObject;
1571
+ }
1572
+ /** External work as data. Interpret it outside the pure reducer. @experimental */
1573
+ interface SystemExternalEffect {
1574
+ readonly id: string;
1575
+ readonly source: SystemActorReference;
1576
+ readonly type: string;
1577
+ readonly kind: 'action' | 'emit' | 'deadLetter';
1578
+ readonly params?: unknown;
1579
+ readonly args?: readonly unknown[];
1580
+ readonly event?: AnyEventObject;
1581
+ readonly reason?: string;
1582
+ }
1583
+ /** Acknowledges external work, optionally delivering its result to its owner. @experimental */
1584
+ interface SystemEffectResult {
1585
+ type: 'xstate.system.effect.result';
1586
+ effectId: string;
1587
+ event?: AnyEventObject;
1588
+ }
1589
+ /** Complete immutable system state; no running actors are retained. @experimental */
1590
+ interface SystemSnapshot {
1591
+ readonly executionId: string;
1592
+ readonly root: string;
1593
+ readonly now: number;
1594
+ readonly actors: Readonly<Record<string, SystemActorState>>;
1595
+ readonly registry: Readonly<Record<string, SystemActorReference>>;
1596
+ readonly messages: readonly SystemMessage[];
1597
+ readonly timers: Readonly<Record<string, SystemTimer>>;
1598
+ readonly externalEffects: Readonly<Record<string, SystemExternalEffect>>;
1599
+ readonly counters: Readonly<{
1600
+ actor: number;
1601
+ timer: number;
1602
+ sequence: number;
1603
+ effect: number;
1604
+ }>;
1605
+ }
1606
+ /** Options for initializing an immutable system snapshot. @experimental */
1607
+ interface InitialSystemTransitionOptions<TLogic extends AnyActorLogic = AnyActorLogic> {
1608
+ input?: InputFrom<TLogic>;
1609
+ id?: string;
1610
+ registryKey?: string;
1611
+ /** Namespace external effect IDs when several executions share one host. */
1612
+ executionId?: string;
1613
+ time?: number;
1614
+ /** Bound immediate message chains. Exhaustion throws; the input is unchanged. */
1615
+ maxSteps?: number;
1616
+ }
1617
+ /** Initialize all actors and return external work without executing it. @experimental */
1618
+ declare function initialSystemTransition<TLogic extends AnyActorLogic>(systemLogic: SystemLogic<TLogic>, options?: InitialSystemTransitionOptions<TLogic>): [SystemSnapshot, SystemExternalEffect[]];
1619
+ /** Complete actor macrosteps and immediate communication in an immutable snapshot. @experimental */
1620
+ declare function systemTransition(systemLogic: SystemLogic, snapshot: SystemSnapshot, actorPath: string, event: AnyEventObject): [SystemSnapshot, SystemExternalEffect[]];
1621
+ /** Process every due timer chronologically across the entire system snapshot. @experimental */
1622
+ declare function advanceSystemTime(systemLogic: SystemLogic, snapshot: SystemSnapshot, options: {
1623
+ time: number;
1624
+ maxSteps?: number;
1625
+ }): [SystemSnapshot, SystemExternalEffect[]];
1626
+ /**
1627
+ * Converts a delay (milliseconds or an ISO 8601 duration string) to
1628
+ * milliseconds. Exported for `@xstate/scxml`; not part of the stable API.
1629
+ *
1630
+ * @experimental
1631
+ */
1632
+ declare function parseDelayToMilliseconds(delay: string | number | undefined): number | undefined;
1633
+ /**
1634
+ * Runs one keyed step of an async actor with the built-in journal: the
1635
+ * result is memoized in the actor's own snapshot (`effects[key]`), so a
1636
+ * restored actor skips completed steps when its logic function re-runs.
1637
+ * Custom runtimes that implement `runStep` use this for the default local
1638
+ * behavior, the same way `deliverEvent` exposes local delivery.
1639
+ *
1640
+ * @experimental
1641
+ */
1642
+ declare function runStep<TStepOutput>(actor: AnyActor, key: string, exec: () => TStepOutput | PromiseLike<TStepOutput>, sendSelf?: (event: AnyEventObject) => void): Promise<TStepOutput>;
1643
+ /**
1644
+ * Delivers an event directly to a target actor, bypassing any installed host
1645
+ * runtime. Custom runtimes use this for the default local delivery behavior
1646
+ * inside their own `sendEvent` implementations.
1647
+ *
1648
+ * @experimental
1649
+ */
1650
+ declare function deliverEvent(source: AnyActor | undefined, target: AnyActor, event: AnyEventObject): void;
1651
+ /**
1652
+ * Publishes an actor's terminal result, notifying its parent and observers.
1653
+ * Custom runtimes use this for the default local behavior inside their own
1654
+ * `terminateActor` implementations.
1655
+ *
1656
+ * @experimental
1657
+ */
1658
+ declare function terminateActor(actor: AnyActor, termination: ActorTermination): void;
1659
+ /**
1660
+ * Stops an actor without producing a completion result. Custom runtimes use
1661
+ * this for the default local behavior inside their own `stopActor`
1662
+ * implementations.
1663
+ *
1664
+ * @experimental
1665
+ */
1666
+ declare function stopActor(actor: AnyActor): void;
1667
+ /** @public */
1668
+ declare const pathToStateValue: (statePath: readonly string[]) => StateValue;
1669
+ /** @public */
1670
+ declare function matchesState(childStateValue: StateValue): (parentStateValue: StateValue) => boolean;
1671
+ declare function matchesState(parentStateValue: StateValue, childStateValue: StateValue): boolean;
1672
+ /**
1673
+ * Returns a promise that resolves to the `output` of the actor when it is done.
1674
+ *
1675
+ * @example
1676
+ *
1677
+ * ```ts
1678
+ * const machine = createMachine({
1679
+ * // ...
1680
+ * output: {
1681
+ * count: 42
1682
+ * }
1683
+ * });
1684
+ *
1685
+ * const actor = createActor(machine);
1686
+ *
1687
+ * actor.start();
1688
+ *
1689
+ * const output = await toPromise(actor);
1690
+ *
1691
+ * console.log(output);
1692
+ * // logs { count: 42 }
1693
+ * ```
1694
+ * @public
1695
+ */
1696
+ declare function toPromise<T extends AnyActorRef>(actor: T): Promise<OutputFrom<T>>;
1697
+ /**
1698
+ * Given actor `logic`, a `snapshot`, and an `event`, returns a tuple of the
1699
+ * `nextSnapshot` and `actions` to execute.
1700
+ *
1701
+ * This is a pure function that does not execute `actions`.
1702
+ *
1703
+ * @public
1704
+ */
1705
+ declare function transition<T extends AnyActorLogic>(logic: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): [nextSnapshot: SnapshotFrom<T>, actions: ExecutableActionObjectFromLogic<T>[]];
1706
+ /**
1707
+ * Returns `true` when `result` (from {@link transition}) means no transition
1708
+ * handled the event: the snapshot is the same object as `previousSnapshot`
1709
+ * and there are no effects. A handled event always yields a new snapshot
1710
+ * object, even when nothing in it changed.
1711
+ *
1712
+ * @example
1713
+ *
1714
+ * ```ts
1715
+ * const result = transition(machine, snapshot, event);
1716
+ * if (isUnhandled(snapshot, result)) {
1717
+ * console.warn(`Unhandled event: ${event.type}`);
1718
+ * }
1719
+ * ```
1720
+ *
1721
+ * @public
1722
+ */
1723
+ declare function isUnhandled(previousSnapshot: unknown, result: readonly [snapshot: unknown, effects: readonly unknown[]]): boolean;
1724
+ /**
1725
+ * Given actor `logic` and optional `input`, returns a tuple of the
1726
+ * `nextSnapshot` and `actions` to execute from the initial transition (no
1727
+ * previous state).
1728
+ *
1729
+ * This is a pure function that does not execute `actions`.
1730
+ *
1731
+ * @public
1732
+ */
1733
+ declare function initialTransition<T extends AnyActorLogic>(logic: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): [SnapshotFrom<T>, ExecutableActionObjectFromLogic<T>[]];
1734
+ /**
1735
+ * Given a state `machine`, a `snapshot`, and an `event`, returns an array of
1736
+ * microsteps, where each microstep is a tuple of
1737
+ * `[snapshot, actions, transitions]`. `transitions` are the transitions taken
1738
+ * in that microstep,
1739
+ * including eventless transitions and transitions for raised events; it is
1740
+ * empty for microsteps that take no transition (for example, a stop or timer
1741
+ * microstep).
1742
+ *
1743
+ * This is a pure function that does not execute `actions`.
1744
+ *
1745
+ * @public
1746
+ */
1747
+ declare function getMicrosteps<T extends AnyStateMachine>(machine: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): Array<[SnapshotFrom<T>, ExecutableActionObjectFromLogic<T>[], AnyTransitionDefinition[]]>;
1748
+ /**
1749
+ * Given a state `machine` and optional `input`, returns an array of microsteps
1750
+ * from the initial transition, where each microstep is a tuple of
1751
+ * `[snapshot, actions, transitions]`. `transitions` are the transitions taken
1752
+ * in that microstep (see {@link getMicrosteps}); it is empty for the first
1753
+ * microstep, which enters the initial states.
1754
+ *
1755
+ * This is a pure function that does not execute `actions`.
1756
+ *
1757
+ * @public
1758
+ */
1759
+ declare function getInitialMicrosteps<T extends AnyStateMachine>(machine: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): Array<[SnapshotFrom<T>, ExecutableActionObjectFromLogic<T>[], AnyTransitionDefinition[]]>;
1760
+ /**
1761
+ * Gets all potential next transitions from the current state.
1762
+ *
1763
+ * Returns all transitions that are available from the current state, including:
1764
+ *
1765
+ * - All transitions from atomic states (leaf states in the current state
1766
+ * configuration)
1767
+ * - All transitions from ancestor states (parent states that may handle events)
1768
+ * - All guarded transitions (regardless of whether their guards would pass)
1769
+ * - Always (eventless) transitions
1770
+ * - After (delayed) transitions
1771
+ *
1772
+ * The order of transitions is deterministic:
1773
+ *
1774
+ * 1. Atomic states are processed in document order
1775
+ * 2. For each atomic state, transitions are collected from the state itself first,
1776
+ * then its ancestors
1777
+ * 3. Within each state node, transitions are in the order they appear in the state
1778
+ * definition
1779
+ *
1780
+ * @param state - The current machine snapshot
1781
+ * @returns Array of transition definitions from the current state, in
1782
+ * deterministic order
1783
+ * @public
1784
+ */
1785
+ declare function getNextTransitions(state: AnyMachineSnapshot): AnyTransitionDefinition[];
1786
+ /** @public */
1787
+ declare function isBuiltInExecutableAction(action: ExecutableActionObject): action is SpecialExecutableAction;
1788
+ /**
1789
+ * Executes transition effects sequentially, awaiting each runtime operation.
1790
+ *
1791
+ * @public
1792
+ */
1793
+ declare function executeEffects(effects: readonly ExecutableActionObject[], runtime?: Partial<ActorSystemRuntime>): Promise<void>;
1794
+ /** @public */
1795
+ declare function toObserver<T>(nextHandler?: Observer<T> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
1796
+ /** @experimental */
1797
+ declare function getAllOwnEventDescriptors(snapshot: AnyMachineSnapshot): any[];
1798
+ interface WaitForOptions {
1799
+ /**
1800
+ * How long to wait before rejecting, if no emitted state satisfies the
1801
+ * predicate.
1802
+ *
1803
+ * @defaultValue Infinity
1804
+ */
1805
+ timeout: number;
1806
+ /** A signal which stops waiting when aborted. */
1807
+ signal?: AbortSignal;
1808
+ }
1809
+ /**
1810
+ * Subscribes to an actor ref and waits for its emitted value to satisfy a
1811
+ * predicate, and then resolves with that value. Will throw if the desired state
1812
+ * is not reached after an optional timeout. (defaults to Infinity).
1813
+ *
1814
+ * @example
1815
+ *
1816
+ * ```js
1817
+ * const state = await waitFor(someService, (state) => {
1818
+ * return state.hasTag('loaded');
1819
+ * });
1820
+ *
1821
+ * state.hasTag('loaded'); // true
1822
+ * ```
1823
+ *
1824
+ * @param actorRef The actor ref to subscribe to
1825
+ * @param predicate Determines if a value matches the condition to wait for
1826
+ * @param options
1827
+ * @returns A promise that eventually resolves to the emitted value that matches
1828
+ * the condition
1829
+ * @public
1830
+ */
1831
+ declare function waitFor<TActorRef extends AnyActorRef>(actorRef: TActorRef, predicate: (emitted: SnapshotFrom<TActorRef>) => boolean, options?: Partial<WaitForOptions>): Promise<SnapshotFrom<TActorRef>>;
1832
+ export { WithRootSetupStateSchemas as $, initialSystemTransition as A, RootContextMarker as B, SystemEffectResult as C, createMachineFromConfig as Ct, SystemSnapshot as D, assertEvent as Dt, SystemMessage as E, createStateConfig as Et, CreateAsyncInvokeConfig as F, SetupStateParentTypeMarker as G, SetupConfig as H, CreateInvokeConfig as I, StrictSetupStateTargetsFlag as J, SetupStateSchemasWithParentType as K, CreatedInvoke as L, SimulatedClock as M, ActiveStateContext as N, SystemTimer as O, AnySetupConfig as P, SystemRuntime as Q, CurrentSetupStateSchemaMarker as R, SystemActorState as S, TransitionJSON as St, SystemLogic as T, createMachineFromCompiledConfig as Tt, SetupReturn as U, RootSetupStateSchemasMarker as V, SetupReturnFromConfig as W, SystemActorMap as X, StrictSetupStateTargetsMarker as Y, SystemConfig as Z, stopActor as _, ActionJSON as _t, isBuiltInExecutableAction as a, serializeMachine as at, InitialSystemTransitionOptions as b, MachineJSON as bt, getNextTransitions as c, EventAdapterHandlers as ct, transition as d, MigrateSnapshotOptions as dt, createSystem as et, toPromise as f, ParsedPersistedSnapshot as ft, runStep as g, machineVersions as gt, deliverEvent as h, SnapshotMigrationHandlers as ht, executeEffects as i, machineConfigToJSON as it, systemTransition as j, advanceSystemTime as k, initialTransition as l, EventHistorySource as lt, pathToStateValue as m, PersistedSnapshotSource as mt, getAllOwnEventDescriptors as n, hotSwapActorLogic as nt, getInitialMicrosteps as o, mapState as ot, matchesState as p, PersistedSnapshotDataFrom as pt, StrictSetupStateSchemas as q, toObserver as r, CodeExpression as rt, getMicrosteps as s, AdaptEventsOptions as st, waitFor as t, setup as tt, isUnhandled as u, MachineVersionsOptions as ut, terminateActor as v, GuardJSON as vt, SystemExternalEffect as w, createMachine as wt, SystemActorReference as x, StateNodeJSON as xt, parseDelayToMilliseconds as y, InvokeJSON as yt, RelativeSetupStateSchemasMarker as z };