xstate 6.0.0-alpha.7 → 6.0.0-alpha.8
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.
- package/dist/{StateMachine-2b259bff.development.esm.js → StateMachine-0aa98f54.development.esm.js} +10 -10
- package/dist/{StateMachine-6673bf76.cjs.js → StateMachine-aef700df.cjs.js} +9 -9
- package/dist/{StateMachine-1ff90553.esm.js → StateMachine-d4931336.esm.js} +9 -9
- package/dist/{StateMachine-68fe6077.development.cjs.js → StateMachine-da872dde.development.cjs.js} +10 -10
- package/dist/declarations/src/StateMachine.d.ts +4 -4
- package/dist/declarations/src/createMachine.d.ts +4 -4
- package/dist/declarations/src/createMachineFromConfig.d.ts +2 -2
- package/dist/declarations/src/serialize.d.ts +2 -1
- package/dist/declarations/src/setup.d.ts +31 -25
- package/dist/declarations/src/types.d.ts +54 -42
- package/dist/declarations/src/types.v6.d.ts +21 -21
- package/dist/declarations/src/utils.d.ts +2 -1
- package/dist/{index-b063a967.development.cjs.js → index-219cb621.development.cjs.js} +35 -13
- package/dist/{index-9594f050.development.esm.js → index-2f2fbd9b.development.esm.js} +35 -13
- package/dist/{index-87499be0.cjs.js → index-559ceab3.cjs.js} +35 -13
- package/dist/{index-aaf74d09.esm.js → index-8828376f.esm.js} +35 -13
- package/dist/xstate-actors.cjs.js +1 -1
- package/dist/xstate-actors.development.cjs.js +1 -1
- package/dist/xstate-actors.development.esm.js +1 -1
- package/dist/xstate-actors.esm.js +1 -1
- package/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/xstate-graph.cjs.js +2 -2
- package/dist/xstate-graph.development.cjs.js +2 -2
- package/dist/xstate-graph.development.esm.js +2 -2
- package/dist/xstate-graph.esm.js +2 -2
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +17 -16
- package/dist/xstate.development.cjs.js +17 -16
- package/dist/xstate.development.esm.js +19 -18
- package/dist/xstate.esm.js +19 -18
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -79,18 +79,27 @@ export interface ParameterizedObject {
|
|
|
79
79
|
type: string;
|
|
80
80
|
params?: NonReducibleUnknown;
|
|
81
81
|
}
|
|
82
|
-
export
|
|
82
|
+
export type UnifiedArg<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> = {
|
|
83
83
|
context: TContext;
|
|
84
84
|
event: TExpressionEvent;
|
|
85
85
|
self: ActorSelf<MachineSnapshot<TContext, TEvent, Record<string, AnyActorRef | undefined>, // TODO: this should be replaced with `TChildren`
|
|
86
86
|
StateValue, string, unknown, TODO, // TMeta
|
|
87
87
|
TODO>, TEvent, AnyEventObject>;
|
|
88
88
|
system: AnyActorSystem;
|
|
89
|
-
}
|
|
89
|
+
} & OutputArg<TExpressionEvent>;
|
|
90
90
|
export type MachineContext = Record<string, any>;
|
|
91
|
-
|
|
91
|
+
type DoneEventType = `xstate.done.actor.${string}` | `xstate.done.state.${string}`;
|
|
92
|
+
export type OutputArg<TEvent extends EventObject> = TEvent extends {
|
|
93
|
+
type: DoneEventType;
|
|
94
|
+
output: infer TOutput;
|
|
95
|
+
} ? {
|
|
96
|
+
output: TOutput;
|
|
97
|
+
} : {
|
|
98
|
+
output: undefined;
|
|
99
|
+
};
|
|
100
|
+
export type ActionArgs<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> = UnifiedArg<TContext, TExpressionEvent, TEvent> & {
|
|
92
101
|
children: Record<string, AnyActor>;
|
|
93
|
-
}
|
|
102
|
+
};
|
|
94
103
|
export type InputFrom<T> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TStateSchema, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap> ? TInput : T extends ActorLogic<infer _TSnapshot, infer _TEvent, infer TInput, infer _TSystem, infer _TEmitted> ? TInput : never;
|
|
95
104
|
export type OutputFrom<T> = T extends ActorLogic<infer TSnapshot, infer _TEvent, infer _TInput, infer _TSystem, infer _TEmitted> ? (TSnapshot & {
|
|
96
105
|
status: 'done';
|
|
@@ -101,10 +110,10 @@ export type NoRequiredParams<T extends ParameterizedObject> = T extends any ? un
|
|
|
101
110
|
export type ConditionalRequired<T, Condition extends boolean> = Condition extends true ? Required<T> : T;
|
|
102
111
|
export type WithDynamicParams<TContext extends MachineContext, TExpressionEvent extends EventObject, T extends ParameterizedObject> = T extends any ? ConditionalRequired<{
|
|
103
112
|
type: T['type'];
|
|
104
|
-
params?: T['params'] | (({ context, event }: {
|
|
113
|
+
params?: T['params'] | (({ context, event, output }: {
|
|
105
114
|
context: TContext;
|
|
106
115
|
event: TExpressionEvent;
|
|
107
|
-
}) => T['params']);
|
|
116
|
+
} & OutputArg<TExpressionEvent>) => T['params']);
|
|
108
117
|
}, undefined extends T['params'] ? false : true> : never;
|
|
109
118
|
export type StateKey = string | AnyMachineSnapshot;
|
|
110
119
|
export interface StateValueMap {
|
|
@@ -121,7 +130,7 @@ export interface StateValueMap {
|
|
|
121
130
|
*/
|
|
122
131
|
export type StateValue = string | StateValueMap;
|
|
123
132
|
export type TransitionTarget = SingleOrArray<string>;
|
|
124
|
-
export interface TransitionConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
133
|
+
export interface TransitionConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> {
|
|
125
134
|
actions?: never;
|
|
126
135
|
guard?: unknown;
|
|
127
136
|
reenter?: boolean;
|
|
@@ -131,7 +140,7 @@ export interface TransitionConfig<TContext extends MachineContext, TExpressionEv
|
|
|
131
140
|
meta?: TMeta;
|
|
132
141
|
description?: string;
|
|
133
142
|
}
|
|
134
|
-
export interface InitialTransitionConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
143
|
+
export interface InitialTransitionConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> extends TransitionConfig<TContext, TEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap> {
|
|
135
144
|
target: string;
|
|
136
145
|
}
|
|
137
146
|
export type AnyTransitionConfig = TransitionConfig<any, // TContext
|
|
@@ -143,11 +152,11 @@ any, // TActionMap
|
|
|
143
152
|
any, // TActorMap
|
|
144
153
|
any, // TGuardMap
|
|
145
154
|
any>;
|
|
146
|
-
export interface InvokeDefinition<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
155
|
+
export interface InvokeDefinition<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> {
|
|
147
156
|
id: string;
|
|
148
157
|
registryKey: string | undefined;
|
|
149
|
-
logic: string | AnyActorLogic | (({
|
|
150
|
-
|
|
158
|
+
logic: string | AnyActorLogic | (({ actorSources, context, event, self }: {
|
|
159
|
+
actorSources: TActorMap;
|
|
151
160
|
context: TContext;
|
|
152
161
|
event: TEvent;
|
|
153
162
|
self: AnyActorRef;
|
|
@@ -177,9 +186,9 @@ export interface InvokeDefinition<TContext extends MachineContext, TEvent extend
|
|
|
177
186
|
/** The transition to take when the invoke-level `timeout` expires. */
|
|
178
187
|
onTimeout?: string | SingleOrArray<TransitionConfig<TContext, TEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>>;
|
|
179
188
|
}
|
|
180
|
-
export type AnyInvokeDefinition = InvokeDefinition<MachineContext, EventObject, EventObject, MetaObject, Implementations['actions'], Implementations['
|
|
189
|
+
export type AnyInvokeDefinition = InvokeDefinition<MachineContext, EventObject, EventObject, MetaObject, Implementations['actions'], Implementations['actorSources'], Implementations['guards'], Implementations['delays']>;
|
|
181
190
|
type Delay<TDelay extends string> = TDelay | number;
|
|
182
|
-
export type DelayedTransitions<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
191
|
+
export type DelayedTransitions<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
183
192
|
[K in Delay<keyof TDelayMap & string>]?: string | SingleOrArray<TransitionConfig<TContext, TEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>> | TransitionConfigFunction<TContext, TEvent, TEvent, TODO, any, any, any, any, any>;
|
|
184
193
|
};
|
|
185
194
|
export type StateTypes = 'atomic' | 'compound' | 'parallel' | 'final' | 'choice' | 'history' | ({} & string);
|
|
@@ -188,26 +197,28 @@ export type StateNodesConfig<TContext extends MachineContext, TEvent extends Eve
|
|
|
188
197
|
[K in string]: StateNode<TContext, TEvent>;
|
|
189
198
|
};
|
|
190
199
|
export type TransitionConfigTarget = string | undefined;
|
|
191
|
-
export type TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
192
|
-
export type TransitionConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
193
|
-
|
|
200
|
+
export type TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = SingleOrArray<TransitionConfigTarget | TransitionConfig<TContext, TExpressionEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap> | TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>>;
|
|
201
|
+
export type TransitionConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, _TCtx = [TContext] extends [never] ? any : TContext> = (args: TransitionFunctionArgs<_TCtx, TCurrentEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap>, enq: EnqueueObject<TEvent, TEmitted>) => {
|
|
202
|
+
target?: string | string[];
|
|
203
|
+
context?: Partial<_TCtx>;
|
|
204
|
+
reenter?: boolean;
|
|
205
|
+
meta?: TMeta;
|
|
206
|
+
} | void;
|
|
207
|
+
type TransitionFunctionArgs<TContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
208
|
+
context: TContext;
|
|
194
209
|
event: TCurrentEvent;
|
|
195
|
-
self: ActorSelf<MachineSnapshot<
|
|
210
|
+
self: ActorSelf<MachineSnapshot<TContext & MachineContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO>, TEvent>;
|
|
196
211
|
parent: UnknownActorRef | undefined;
|
|
197
212
|
value: StateValue;
|
|
198
213
|
children: Record<string, AnyActor>;
|
|
214
|
+
system: AnyActorSystem;
|
|
199
215
|
actions: TActionMap;
|
|
200
|
-
|
|
216
|
+
actorSources: TActorMap;
|
|
201
217
|
guards: TGuardMap;
|
|
202
218
|
delays: TDelayMap;
|
|
203
|
-
}
|
|
204
|
-
target?: string | string[];
|
|
205
|
-
context?: Partial<_TCtx>;
|
|
206
|
-
reenter?: boolean;
|
|
207
|
-
meta?: TMeta;
|
|
208
|
-
} | void;
|
|
219
|
+
} & OutputArg<TCurrentEvent>;
|
|
209
220
|
export type AnyTransitionConfigFunction = TransitionConfigFunction<any, any, any, any, any, any, any, any, any, any>;
|
|
210
|
-
export type TransitionsConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
221
|
+
export type TransitionsConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
211
222
|
[K in EventDescriptor<TEvent>]?: TransitionConfigOrTarget<TContext, ExtractEvent<TEvent, K>, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
212
223
|
};
|
|
213
224
|
type PartialEventDescriptor<TEventType extends string> = TEventType extends `${infer TLeading}.${infer TTail}` ? `${TLeading}.*` | `${TLeading}.${PartialEventDescriptor<TTail>}` : never;
|
|
@@ -225,8 +236,8 @@ type DistributeActors<TContext extends MachineContext, TEvent extends EventObjec
|
|
|
225
236
|
} ? Compute<{
|
|
226
237
|
registryKey?: string;
|
|
227
238
|
/** The source of the machine to be invoked, or the machine itself. */
|
|
228
|
-
src: TSrc | (({
|
|
229
|
-
|
|
239
|
+
src: TSrc | (({ actorSources, context, event, self }: {
|
|
240
|
+
actorSources: ActorImplementationsBySrc<TActor>;
|
|
230
241
|
context: TContext;
|
|
231
242
|
event: TEvent;
|
|
232
243
|
self: AnyActorRef;
|
|
@@ -258,8 +269,8 @@ type DistributeActors<TContext extends MachineContext, TEvent extends EventObjec
|
|
|
258
269
|
}> | {
|
|
259
270
|
id?: never;
|
|
260
271
|
registryKey?: string;
|
|
261
|
-
src: string | AnyActorLogic | (({
|
|
262
|
-
|
|
272
|
+
src: string | AnyActorLogic | (({ actorSources, context, event, self }: {
|
|
273
|
+
actorSources: ActorImplementationsBySrc<TActor>;
|
|
263
274
|
context: TContext;
|
|
264
275
|
event: TEvent;
|
|
265
276
|
self: AnyActorRef;
|
|
@@ -282,8 +293,8 @@ export type InvokeConfig<TContext extends MachineContext, TEvent extends EventOb
|
|
|
282
293
|
id?: string;
|
|
283
294
|
registryKey?: string;
|
|
284
295
|
/** The source of the machine to be invoked, or the machine itself. */
|
|
285
|
-
src: string | AnyActorLogic | (({
|
|
286
|
-
|
|
296
|
+
src: string | AnyActorLogic | (({ actorSources, context, event, self }: {
|
|
297
|
+
actorSources: ActorImplementationsBySrc<TActor>;
|
|
287
298
|
context: TContext;
|
|
288
299
|
event: TEvent;
|
|
289
300
|
self: AnyActorRef;
|
|
@@ -326,10 +337,10 @@ any, // TGuardMap
|
|
|
326
337
|
any>;
|
|
327
338
|
export type AnyStateConfig = StateConfig<any, AnyEventObject>;
|
|
328
339
|
export type DelayConfig<TContext extends MachineContext, TExpressionEvent extends EventObject> = number | DelayExpr<TContext, TExpressionEvent>;
|
|
329
|
-
export type InitialContext<TContext extends MachineContext, TActorMap extends Implementations['
|
|
330
|
-
export type ContextFactory<TContext extends MachineContext, TActorMap extends Implementations['
|
|
340
|
+
export type InitialContext<TContext extends MachineContext, TActorMap extends Implementations['actorSources'], TInput, TEvent extends EventObject> = TContext | ContextFactory<TContext, TActorMap, TInput, TEvent>;
|
|
341
|
+
export type ContextFactory<TContext extends MachineContext, TActorMap extends Implementations['actorSources'], TInput, TEvent extends EventObject = EventObject> = ({ spawn, actorSources, input, self }: {
|
|
331
342
|
spawn: Spawner;
|
|
332
|
-
|
|
343
|
+
actorSources: TActorMap;
|
|
333
344
|
input: TInput;
|
|
334
345
|
self: ActorSelf<MachineSnapshot<[
|
|
335
346
|
TContext
|
|
@@ -353,7 +364,7 @@ export interface SetupTypes<TContext extends MachineContext, TEvent extends Even
|
|
|
353
364
|
meta?: TMeta;
|
|
354
365
|
}
|
|
355
366
|
export interface MachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput, TEmitted extends EventObject, TMeta extends MetaObject> extends SetupTypes<TContext, TEvent, never, TTag, TInput, TOutput, TEmitted, TMeta> {
|
|
356
|
-
|
|
367
|
+
actorSources?: TActor;
|
|
357
368
|
actions?: TAction;
|
|
358
369
|
guards?: TGuard;
|
|
359
370
|
delays?: TDelay;
|
|
@@ -396,7 +407,7 @@ export type Mapper<TContext extends MachineContext, TExpressionEvent extends Eve
|
|
|
396
407
|
self: ActorSelf<MachineSnapshot<_TCtx & MachineContext, TEvent, Record<string, AnyActorRef>, // TODO: this should be replaced with `TChildren`
|
|
397
408
|
StateValue, string, unknown, TODO, // TMeta
|
|
398
409
|
TODO>, TEvent, AnyEventObject>;
|
|
399
|
-
}) => TResult;
|
|
410
|
+
} & OutputArg<TExpressionEvent>) => TResult;
|
|
400
411
|
export interface TransitionDefinition<TContext extends MachineContext, TEvent extends EventObject> extends Omit<TransitionConfig<TContext, TEvent, TEvent, TODO, TODO, TODO, TODO, TODO, // TEmitted
|
|
401
412
|
TODO>, 'target' | 'to'> {
|
|
402
413
|
target: ReadonlyArray<AnyStateNode> | undefined;
|
|
@@ -407,6 +418,7 @@ TODO>, 'target' | 'to'> {
|
|
|
407
418
|
input?: Record<string, unknown> | ((args: {
|
|
408
419
|
context: any;
|
|
409
420
|
event: any;
|
|
421
|
+
output: any;
|
|
410
422
|
}) => Record<string, unknown>);
|
|
411
423
|
}
|
|
412
424
|
export type AnyTransitionDefinition = TransitionDefinition<any, any>;
|
|
@@ -731,7 +743,7 @@ export type UnknownActorRef = ActorRef<Snapshot<unknown>, EventObject>;
|
|
|
731
743
|
export type DevToolsAdapter = (service: AnyActor) => void;
|
|
732
744
|
export type MachineImplementationsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TConfig, infer TActionMap, infer TActorMap, infer TGuardMap, infer TDelayMap> ? {
|
|
733
745
|
actions: TActionMap;
|
|
734
|
-
|
|
746
|
+
actorSources: TActorMap;
|
|
735
747
|
guards: TGuardMap;
|
|
736
748
|
delays: TDelayMap;
|
|
737
749
|
} : never;
|
|
@@ -928,7 +940,7 @@ export type RoutableStateId<TSchema extends StateSchema> = (TSchema extends {
|
|
|
928
940
|
export interface StateMachineTypes {
|
|
929
941
|
context: MachineContext;
|
|
930
942
|
events: EventObject;
|
|
931
|
-
|
|
943
|
+
actorSources: ProvidedActor;
|
|
932
944
|
actions: ParameterizedObject;
|
|
933
945
|
guards: ParameterizedObject;
|
|
934
946
|
delays: string;
|
|
@@ -939,7 +951,7 @@ export interface StateMachineTypes {
|
|
|
939
951
|
export interface ResolvedStateMachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TEmitted extends EventObject = EventObject> {
|
|
940
952
|
context: TContext;
|
|
941
953
|
events: TEvent;
|
|
942
|
-
|
|
954
|
+
actorSources: TActor;
|
|
943
955
|
actions: TAction;
|
|
944
956
|
guards: TGuard;
|
|
945
957
|
delays: TDelay;
|
|
@@ -1077,14 +1089,14 @@ export type EnqueueObject<TEvent extends EventObject, TEmittedEvent extends Even
|
|
|
1077
1089
|
<TSnapshot extends Snapshot<unknown>, TOutput, TMappedEvent extends TEvent>(actor: AnyActor, mappers: SubscribeToMappers<TSnapshot, TOutput, TMappedEvent> | ((snapshot: TSnapshot) => TMappedEvent)): AnyActor;
|
|
1078
1090
|
};
|
|
1079
1091
|
};
|
|
1080
|
-
export type Action<TContext extends MachineContext, TEvent extends EventObject, TEmittedEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
1092
|
+
export type Action<TContext extends MachineContext, TEvent extends EventObject, TEmittedEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TParams = Record<string, unknown> | undefined, _TCtx = [TContext] extends [never] ? any : TContext> = (_: {
|
|
1081
1093
|
context: _TCtx;
|
|
1082
1094
|
event: TEvent;
|
|
1083
1095
|
parent: AnyActorRef | undefined;
|
|
1084
1096
|
self: ActorSelf<MachineSnapshot<_TCtx & MachineContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO>, TEvent>;
|
|
1085
1097
|
children: Record<string, AnyActor | undefined>;
|
|
1086
1098
|
actions: TActionMap;
|
|
1087
|
-
|
|
1099
|
+
actorSources: TActorMap;
|
|
1088
1100
|
guards: TGuardMap;
|
|
1089
1101
|
delays: TDelayMap;
|
|
1090
1102
|
system?: AnyActorSystem;
|
|
@@ -1093,7 +1105,7 @@ export type Action<TContext extends MachineContext, TEvent extends EventObject,
|
|
|
1093
1105
|
context?: Partial<_TCtx>;
|
|
1094
1106
|
children?: Record<string, AnyActor | undefined>;
|
|
1095
1107
|
} | void;
|
|
1096
|
-
export type AnyAction = Action<MachineContext, EventObject, EventObject, Implementations['actions'], Implementations['
|
|
1108
|
+
export type AnyAction = Action<MachineContext, EventObject, EventObject, Implementations['actions'], Implementations['actorSources'], Implementations['guards'], Implementations['delays']> | {
|
|
1097
1109
|
action: (...args: any[]) => any;
|
|
1098
1110
|
args: any[];
|
|
1099
1111
|
} | AnyEventObject;
|
|
@@ -61,12 +61,12 @@ type MachineSchemas<TContextSchema extends StandardSchemaV1, TEventSchemaMap ext
|
|
|
61
61
|
children?: TChildrenSchemaMap;
|
|
62
62
|
};
|
|
63
63
|
export type AnyMachineSchemas = MachineSchemas<StandardSchemaV1, Record<string, StandardSchemaV1>, Record<string, StandardSchemaV1>, StandardSchemaV1, StandardSchemaV1, StandardSchemaV1, StandardSchemaV1, Record<string, StandardSchemaV1>>;
|
|
64
|
-
export type Next_MachineConfig<TContextSchema extends StandardSchemaV1, TEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, TChildrenSchemaMap extends Record<string, StandardSchemaV1>, TContext extends MachineContext = InferOutput<TContextSchema, MachineContext>, TEvent extends EventObject = InferEvents<TEventSchemaMap>, TChildren extends Record<string, AnyActorRef | undefined> = InferChildren<TChildrenSchemaMap>, TDelays extends string = string, _TTag extends string = string, TActionMap extends Implementations['actions'] = Implementations['actions'], TActorMap extends Implementations['
|
|
64
|
+
export type Next_MachineConfig<TContextSchema extends StandardSchemaV1, TEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, TChildrenSchemaMap extends Record<string, StandardSchemaV1>, TContext extends MachineContext = InferOutput<TContextSchema, MachineContext>, TEvent extends EventObject = InferEvents<TEventSchemaMap>, TChildren extends Record<string, AnyActorRef | undefined> = InferChildren<TChildrenSchemaMap>, TDelays extends string = string, _TTag extends string = string, TActionMap extends Implementations['actions'] = Implementations['actions'], TActorMap extends Implementations['actorSources'] = Implementations['actorSources'], TGuardMap extends Implementations['guards'] = Implementations['guards'], TDelayMap extends Implementations['delays'] = Implementations['delays'], TContextRequired extends boolean = IsNever<TContext> extends true ? false : true, TSystemRegistry extends SystemRegistry = SystemRegistry> = (DistributiveOmit<Next_StateNodeConfig<TContext, DoNotInfer<InferEvents<TEventSchemaMap>>, DoNotInfer<TDelays>, DoNotInfer<StandardSchemaV1.InferOutput<TTagSchema> & string>, DoNotInfer<StandardSchemaV1.InferOutput<TOutputSchema>>, DoNotInfer<InferEvents<TEmittedSchemaMap>>, DoNotInfer<InferOutput<TMetaSchema, MetaObject>>, DoNotInfer<TChildren>, DoNotInfer<TActionMap>, DoNotInfer<TActorMap>, DoNotInfer<TGuardMap>, DoNotInfer<TDelayMap>, Record<string, unknown> | undefined, Record<string, unknown>, DoNotInfer<TSystemRegistry>>, 'output'> & {
|
|
65
65
|
internalEvents?: readonly InternalEventDescriptorFor<InferEvents<TEventSchemaMap>>[];
|
|
66
66
|
schemas?: MachineSchemas<TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap>;
|
|
67
67
|
actions?: TActionMap;
|
|
68
68
|
guards?: TGuardMap;
|
|
69
|
-
|
|
69
|
+
actorSources?: TActorMap;
|
|
70
70
|
/** The machine's own version. */
|
|
71
71
|
version?: string;
|
|
72
72
|
/**
|
|
@@ -101,8 +101,8 @@ export type Next_MachineConfig<TContextSchema extends StandardSchemaV1, TEventSc
|
|
|
101
101
|
export type WidenLiterals<T> = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T extends bigint ? bigint : T extends (...args: any[]) => any ? T : T extends readonly (infer U)[] ? WidenLiterals<U>[] : T extends object ? {
|
|
102
102
|
-readonly [K in keyof T]: WidenLiterals<T[K]>;
|
|
103
103
|
} : T;
|
|
104
|
-
type InvokeSrcArgs<TContext extends MachineContext, TEvent extends EventObject, TActorMap extends Implementations['
|
|
105
|
-
|
|
104
|
+
type InvokeSrcArgs<TContext extends MachineContext, TEvent extends EventObject, TActorMap extends Implementations['actorSources']> = {
|
|
105
|
+
actorSources: TActorMap;
|
|
106
106
|
context: TContext;
|
|
107
107
|
event: TEvent;
|
|
108
108
|
self: AnyActorRef;
|
|
@@ -117,28 +117,28 @@ type ChildIdForLogic<TLogic extends AnyActorLogic, TChildren extends Record<stri
|
|
|
117
117
|
[K in keyof TChildren & string]: ActorRefFromLogic<TLogic> extends NonNullable<TChildren[K]> ? K : never;
|
|
118
118
|
}> : string;
|
|
119
119
|
type LogicForChildRef<TActorRef> = NonNullable<TActorRef> extends ActorRef<infer TSnapshot, infer TEvent, infer TEmitted, any> ? ActorLogic<TSnapshot, TEvent, any, any, TEmitted> : never;
|
|
120
|
-
type InlineChildInvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
120
|
+
type InlineChildInvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, TSystemRegistry extends SystemRegistry> = Values<{
|
|
121
121
|
[K in keyof TChildren & string]: Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry> & {
|
|
122
122
|
id: K;
|
|
123
123
|
src: LogicForChildRef<TChildren[K]>;
|
|
124
124
|
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted, TChildren>) => unknown) | NonReducibleUnknown;
|
|
125
125
|
};
|
|
126
126
|
}>;
|
|
127
|
-
type InlineInvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
127
|
+
type InlineInvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, TSystemRegistry extends SystemRegistry> = HasExplicitChildren<TChildren> extends true ? InlineChildInvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry> : Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry> & {
|
|
128
128
|
src: AnyActorLogic;
|
|
129
129
|
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted, TChildren>) => unknown) | NonReducibleUnknown;
|
|
130
130
|
};
|
|
131
131
|
/**
|
|
132
132
|
* Invoke config. A union of:
|
|
133
133
|
*
|
|
134
|
-
* - One branch per registered actor (distributed over the `
|
|
135
|
-
* `src` — a key, the logic itself, or a resolver function
|
|
136
|
-
* is correlated with `input`, so static and mapped inputs
|
|
137
|
-
* that logic's input type.
|
|
134
|
+
* - One branch per registered actor source (distributed over the `actorSources`
|
|
135
|
+
* map), where `src` — a key, the logic itself, or a resolver function
|
|
136
|
+
* returning either — is correlated with `input`, so static and mapped inputs
|
|
137
|
+
* typecheck against that logic's input type.
|
|
138
138
|
* - A branch for inline (unregistered) actor logic values, whose `input` cannot
|
|
139
139
|
* be correlated (the config is not generic over inline logic).
|
|
140
140
|
*/
|
|
141
|
-
export type Next_InvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
141
|
+
export type Next_InvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, TSystemRegistry extends SystemRegistry = SystemRegistry> = string extends keyof TActorMap ? HasExplicitChildren<TChildren> extends true ? InlineInvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry> : Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry> & {
|
|
142
142
|
src: string | AnyActorLogic | ((args: InvokeSrcArgs<TContext, TEvent, TActorMap>) => string | AnyActorLogic);
|
|
143
143
|
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted, TChildren>) => unknown) | NonReducibleUnknown;
|
|
144
144
|
} : {
|
|
@@ -148,7 +148,7 @@ export type Next_InvokeConfig<TContext extends MachineContext, TEvent extends Ev
|
|
|
148
148
|
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted, TChildren>) => InputFrom<TActorMap[K]>) | InputFrom<TActorMap[K]>;
|
|
149
149
|
};
|
|
150
150
|
}[keyof TActorMap & string] | InlineInvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry>;
|
|
151
|
-
interface Next_InvokeConfigBase<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, _TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
151
|
+
interface Next_InvokeConfigBase<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, _TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, TSystemRegistry extends SystemRegistry> {
|
|
152
152
|
id?: string;
|
|
153
153
|
registryKey?: keyof TSystemRegistry & string;
|
|
154
154
|
onDone?: Next_TransitionConfigOrTarget<TContext, DoneActorEvent<any>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
@@ -173,7 +173,7 @@ interface Next_InvokeConfigBase<TContext extends MachineContext, TEvent extends
|
|
|
173
173
|
}
|
|
174
174
|
/** Lookup state input type from an input map, with fallback to undefined */
|
|
175
175
|
type LookupInput<TInputMap extends Record<string, unknown>, K extends string> = K extends keyof TInputMap ? TInputMap[K] : undefined;
|
|
176
|
-
type StateAction<TContext extends MachineContext, TEvent extends EventObject, TEmittedEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
176
|
+
type StateAction<TContext extends MachineContext, TEvent extends EventObject, TEmittedEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TInput = Record<string, unknown> | undefined> = (_: Omit<Parameters<Action<TContext, TEvent, TEmittedEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, never>>[0], 'params'> & {
|
|
177
177
|
input: TInput;
|
|
178
178
|
}, enqueue: Parameters<Action<TContext, TEvent, TEmittedEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, never>>[1]) => ReturnType<Action<TContext, TEvent, TEmittedEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, never>>;
|
|
179
179
|
type Next_ChoiceTarget<TMeta extends MetaObject> = {
|
|
@@ -186,7 +186,7 @@ type Next_ChoiceTarget<TMeta extends MetaObject> = {
|
|
|
186
186
|
event: any;
|
|
187
187
|
}) => Record<string, unknown>);
|
|
188
188
|
};
|
|
189
|
-
type Next_ChoiceArgs<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
189
|
+
type Next_ChoiceArgs<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], _TCtx = [TContext] extends [never] ? any : TContext> = Parameters<TransitionConfigFunction<TContext, TCurrentEvent, TEvent, EventObject, TActionMap, TActorMap, TGuardMap, TDelayMap, MetaObject, _TCtx>>[0];
|
|
190
190
|
/**
|
|
191
191
|
* Route config: either a static config object, or a transition-style function
|
|
192
192
|
* that acts as the route's guard and resolver — returning `undefined`/`false`
|
|
@@ -196,7 +196,7 @@ type Next_ChoiceArgs<TContext extends MachineContext, TCurrentEvent extends Even
|
|
|
196
196
|
* Guard objects/strings on routes are only produced by the JSON layer
|
|
197
197
|
* (`createMachineFromConfig`) — authoring uses the function form.
|
|
198
198
|
*/
|
|
199
|
-
type Next_RouteConfig<TContext extends MachineContext, TEvent extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
199
|
+
type Next_RouteConfig<TContext extends MachineContext, TEvent extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
200
200
|
description?: string;
|
|
201
201
|
reenter?: boolean;
|
|
202
202
|
meta?: TMeta;
|
|
@@ -213,9 +213,9 @@ type Next_RouteConfig<TContext extends MachineContext, TEvent extends EventObjec
|
|
|
213
213
|
event: any;
|
|
214
214
|
}) => Record<string, unknown>);
|
|
215
215
|
});
|
|
216
|
-
type Next_ChoiceConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
217
|
-
export type Next_StateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, _TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
218
|
-
interface Next_ChoiceStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TTag extends string, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
216
|
+
type Next_ChoiceConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, _TCtx = [TContext] extends [never] ? any : TContext> = (args: Next_ChoiceArgs<TContext, TCurrentEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, _TCtx>) => Next_ChoiceTarget<TMeta>;
|
|
217
|
+
export type Next_StateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, _TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TInput = Record<string, unknown> | undefined, TInputMap extends Record<string, unknown> = Record<string, unknown>, TSystemRegistry extends SystemRegistry = SystemRegistry> = Next_RegularStateNodeConfig<TContext, TEvent, TDelays, TTag, _TOutput, TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TInput, TInputMap, TSystemRegistry> | Next_ChoiceStateNodeConfig<TContext, TEvent, TTag, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
218
|
+
interface Next_ChoiceStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TTag extends string, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> {
|
|
219
219
|
contextSchema?: StandardSchemaV1;
|
|
220
220
|
type: 'choice';
|
|
221
221
|
/** Function that resolves this choice state to a target. */
|
|
@@ -241,7 +241,7 @@ interface Next_ChoiceStateNodeConfig<TContext extends MachineContext, TEvent ext
|
|
|
241
241
|
output?: never;
|
|
242
242
|
target?: never;
|
|
243
243
|
}
|
|
244
|
-
interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, _TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
244
|
+
interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, _TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TInput = Record<string, unknown> | undefined, TInputMap extends Record<string, unknown> = Record<string, unknown>, TSystemRegistry extends SystemRegistry = SystemRegistry> {
|
|
245
245
|
contextSchema?: StandardSchemaV1;
|
|
246
246
|
/** The initial state transition. */
|
|
247
247
|
initial?: string | {
|
|
@@ -364,7 +364,7 @@ interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent ex
|
|
|
364
364
|
/** A default target for a history state */
|
|
365
365
|
target?: string | undefined;
|
|
366
366
|
}
|
|
367
|
-
export type Next_TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
367
|
+
export type Next_TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject> = undefined | {
|
|
368
368
|
target?: string | string[];
|
|
369
369
|
context?: Partial<TContext>;
|
|
370
370
|
description?: string;
|
|
@@ -393,7 +393,7 @@ export interface Implementations {
|
|
|
393
393
|
}>;
|
|
394
394
|
guards: Record<string, (...args: any[]) => boolean>;
|
|
395
395
|
delays: Record<string, number | ((...args: any[]) => number)>;
|
|
396
|
-
|
|
396
|
+
actorSources: Record<string, AnyActorLogic>;
|
|
397
397
|
}
|
|
398
398
|
export type DelayMapFromNames<TDelays extends string, _TDelayMap extends Implementations['delays']> = string extends TDelays ? Implementations['delays'] : {
|
|
399
399
|
[K in TDelays]: Implementations['delays'][string];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StateNode } from "./StateNode.js";
|
|
2
|
-
import type { AnyActor, AnyEventObject, AnyMachineSnapshot, AnyStateMachine, AnyTransitionConfig, AnyTransitionConfigFunction, ErrorActorEvent, EventObject, MachineContext, Mapper, NonReducibleUnknown, Observer, SingleOrArray, StateValue, TransitionConfigTarget } from "./types.js";
|
|
2
|
+
import type { AnyActor, AnyEventObject, AnyMachineSnapshot, AnyStateMachine, AnyTransitionConfig, AnyTransitionConfigFunction, ErrorActorEvent, EventObject, MachineContext, Mapper, NonReducibleUnknown, Observer, OutputArg, SingleOrArray, StateValue, TransitionConfigTarget } from "./types.js";
|
|
3
3
|
export declare function matchesState(parentStateId: StateValue, childStateId: StateValue): boolean;
|
|
4
4
|
export declare function checkStateIn(snapshot: AnyMachineSnapshot, stateValue: StateValue): boolean;
|
|
5
5
|
export declare function toStatePath(stateId: string | string[]): string[];
|
|
@@ -9,6 +9,7 @@ export declare function mapValues<P, O extends Record<string, unknown>>(collecti
|
|
|
9
9
|
};
|
|
10
10
|
export declare function toArray<T>(value: readonly T[] | T | undefined): readonly T[];
|
|
11
11
|
export declare function resolveOutput<TContext extends MachineContext, TExpressionEvent extends EventObject>(mapper: Mapper<TContext, TExpressionEvent, unknown, EventObject> | NonReducibleUnknown, context: TContext, event: TExpressionEvent, self: AnyActor): unknown;
|
|
12
|
+
export declare function getEventOutput<TEvent extends EventObject>(event: TEvent): OutputArg<TEvent>['output'];
|
|
12
13
|
export declare function isErrorActorEvent(event: AnyEventObject): event is ErrorActorEvent;
|
|
13
14
|
export declare function toTransitionConfigArray(configLike: SingleOrArray<AnyTransitionConfig | TransitionConfigTarget | AnyTransitionConfigFunction>): Array<AnyTransitionConfig>;
|
|
14
15
|
export declare function normalizeTarget<TContext extends MachineContext, TEvent extends EventObject>(target: SingleOrArray<string | StateNode<TContext, TEvent>> | undefined): ReadonlyArray<string | StateNode<TContext, TEvent>> | undefined;
|
|
@@ -524,12 +524,13 @@ function resolveActionsWithContext(currentSnapshot, event, actorScope, actions)
|
|
|
524
524
|
const actionArgs = {
|
|
525
525
|
context: intermediateSnapshot.context,
|
|
526
526
|
event,
|
|
527
|
+
output: getEventOutput(event),
|
|
527
528
|
self: actorScope.self,
|
|
528
529
|
system: actorScope.system,
|
|
529
530
|
children: intermediateSnapshot.children,
|
|
530
531
|
parent: actorScope.self._parent,
|
|
531
532
|
actions: currentSnapshot.machine.implementations.actions,
|
|
532
|
-
|
|
533
|
+
actorSources: currentSnapshot.machine.implementations.actorSources
|
|
533
534
|
};
|
|
534
535
|
let actionParams = undefined;
|
|
535
536
|
if (typeof action === 'object' && action !== null) {
|
|
@@ -1301,7 +1302,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
1301
1302
|
children,
|
|
1302
1303
|
system: actorScope.system,
|
|
1303
1304
|
actions: currentSnapshot.machine.implementations.actions,
|
|
1304
|
-
|
|
1305
|
+
actorSources: currentSnapshot.machine.implementations.actorSources,
|
|
1305
1306
|
guards: currentSnapshot.machine.implementations.guards,
|
|
1306
1307
|
delays: currentSnapshot.machine.implementations.delays,
|
|
1307
1308
|
input
|
|
@@ -1530,7 +1531,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
1530
1531
|
let src = invokeDef.logic;
|
|
1531
1532
|
if (typeof src === 'function') {
|
|
1532
1533
|
src = src({
|
|
1533
|
-
|
|
1534
|
+
actorSources: currentSnapshot.machine.implementations.actorSources,
|
|
1534
1535
|
context: nextState.context,
|
|
1535
1536
|
event,
|
|
1536
1537
|
self: actorScope.self
|
|
@@ -1543,7 +1544,8 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
1543
1544
|
const input = typeof invokeDef.input === 'function' ? invokeDef.input({
|
|
1544
1545
|
self: actorScope.self,
|
|
1545
1546
|
context: nextState.context,
|
|
1546
|
-
event
|
|
1547
|
+
event,
|
|
1548
|
+
output: getEventOutput(event)
|
|
1547
1549
|
}) : invokeDef.input;
|
|
1548
1550
|
const actor = createActor(logic, {
|
|
1549
1551
|
...invokeDef,
|
|
@@ -1702,12 +1704,14 @@ function getTransitionResult(transition, snapshot, event, actorScope) {
|
|
|
1702
1704
|
const res = transition.to({
|
|
1703
1705
|
context: snapshot.context,
|
|
1704
1706
|
event,
|
|
1707
|
+
output: getEventOutput(event),
|
|
1705
1708
|
value: snapshot.value,
|
|
1706
1709
|
children: snapshot.children,
|
|
1710
|
+
system: actorScope.system,
|
|
1707
1711
|
parent: actorScope.self._parent,
|
|
1708
1712
|
self: actorScope.self,
|
|
1709
1713
|
actions: snapshot.machine.implementations.actions,
|
|
1710
|
-
|
|
1714
|
+
actorSources: snapshot.machine.implementations.actorSources,
|
|
1711
1715
|
guards: snapshot.machine.implementations.guards,
|
|
1712
1716
|
delays: snapshot.machine.implementations.delays
|
|
1713
1717
|
}, enqueue);
|
|
@@ -1715,7 +1719,8 @@ function getTransitionResult(transition, snapshot, event, actorScope) {
|
|
|
1715
1719
|
// Resolve input for .to transitions
|
|
1716
1720
|
const resolvedInput = typeof transition.input === 'function' ? transition.input({
|
|
1717
1721
|
context: snapshot.context,
|
|
1718
|
-
event
|
|
1722
|
+
event,
|
|
1723
|
+
output: getEventOutput(event)
|
|
1719
1724
|
}) : transition.input;
|
|
1720
1725
|
return {
|
|
1721
1726
|
targets: targets,
|
|
@@ -1730,7 +1735,8 @@ function getTransitionResult(transition, snapshot, event, actorScope) {
|
|
|
1730
1735
|
// Resolve input for regular transitions
|
|
1731
1736
|
const resolvedInput = typeof transition.input === 'function' ? transition.input({
|
|
1732
1737
|
context: snapshot.context,
|
|
1733
|
-
event
|
|
1738
|
+
event,
|
|
1739
|
+
output: getEventOutput(event)
|
|
1734
1740
|
}) : transition.input;
|
|
1735
1741
|
return {
|
|
1736
1742
|
targets: transition.target,
|
|
@@ -1876,14 +1882,16 @@ function transitionToHasEffect(transitionTo, context, event, snapshot, self, imp
|
|
|
1876
1882
|
res = transitionTo({
|
|
1877
1883
|
context,
|
|
1878
1884
|
event,
|
|
1885
|
+
output: getEventOutput(event),
|
|
1879
1886
|
self,
|
|
1887
|
+
system: self.system,
|
|
1880
1888
|
value: snapshot.value,
|
|
1881
1889
|
children: snapshot.children,
|
|
1882
1890
|
parent: {
|
|
1883
1891
|
send: triggerEffect
|
|
1884
1892
|
},
|
|
1885
1893
|
actions: implementations.actions,
|
|
1886
|
-
|
|
1894
|
+
actorSources: implementations.actorSources,
|
|
1887
1895
|
guards: implementations.guards,
|
|
1888
1896
|
delays: implementations.delays
|
|
1889
1897
|
}, createEnqueueObject({
|
|
@@ -1938,11 +1946,12 @@ function evaluateCandidate(candidate, event, snapshot, stateNode, self) {
|
|
|
1938
1946
|
const guardArgs = {
|
|
1939
1947
|
context: snapshot.context,
|
|
1940
1948
|
event,
|
|
1949
|
+
output: getEventOutput(event),
|
|
1941
1950
|
self,
|
|
1942
1951
|
parent: self._parent,
|
|
1943
1952
|
children: snapshot.children,
|
|
1944
1953
|
actions: stateNode.machine.implementations.actions,
|
|
1945
|
-
|
|
1954
|
+
actorSources: stateNode.machine.implementations.actorSources,
|
|
1946
1955
|
guards: stateNode.machine.implementations.guards,
|
|
1947
1956
|
delays: stateNode.machine.implementations.delays,
|
|
1948
1957
|
_snapshot: snapshot
|
|
@@ -2288,17 +2297,30 @@ function toArray(value) {
|
|
|
2288
2297
|
}
|
|
2289
2298
|
function resolveOutput(mapper, context, event, self) {
|
|
2290
2299
|
if (typeof mapper === 'function') {
|
|
2291
|
-
|
|
2300
|
+
const outputMapper = mapper;
|
|
2301
|
+
const args = {
|
|
2292
2302
|
context,
|
|
2293
2303
|
event,
|
|
2304
|
+
output: getEventOutput(event),
|
|
2294
2305
|
self
|
|
2295
|
-
}
|
|
2306
|
+
};
|
|
2307
|
+
return outputMapper(args);
|
|
2296
2308
|
}
|
|
2297
2309
|
if (!!mapper && typeof mapper === 'object' && Object.values(mapper).some(val => typeof val === 'function')) {
|
|
2298
2310
|
console.warn(`Dynamically mapping values to individual properties is deprecated. Use a single function that returns the mapped object instead.\nFound object containing properties whose values are possibly mapping functions: ${Object.entries(mapper).filter(([, value]) => typeof value === 'function').map(([key, value]) => `\n - ${key}: ${value.toString().replace(/\n\s*/g, '')}`).join('')}`);
|
|
2299
2311
|
}
|
|
2300
2312
|
return mapper;
|
|
2301
2313
|
}
|
|
2314
|
+
function getEventOutput(event) {
|
|
2315
|
+
if (isDoneEvent(event)) {
|
|
2316
|
+
const doneEvent = event;
|
|
2317
|
+
return doneEvent.output;
|
|
2318
|
+
}
|
|
2319
|
+
return undefined;
|
|
2320
|
+
}
|
|
2321
|
+
function isDoneEvent(event) {
|
|
2322
|
+
return event.type.startsWith('xstate.done.actor.') || event.type.startsWith('xstate.done.state.');
|
|
2323
|
+
}
|
|
2302
2324
|
function isArray(value) {
|
|
2303
2325
|
return Array.isArray(value);
|
|
2304
2326
|
}
|
|
@@ -2341,14 +2363,14 @@ function createInvokeId(stateNodeId, index) {
|
|
|
2341
2363
|
function resolveReferencedActor(machine, src) {
|
|
2342
2364
|
const match = src.match(/^xstate\.invoke\.(\d+)\.(.*)/);
|
|
2343
2365
|
if (!match) {
|
|
2344
|
-
return machine.implementations.
|
|
2366
|
+
return machine.implementations.actorSources[src];
|
|
2345
2367
|
}
|
|
2346
2368
|
const [, indexStr, nodeId] = match;
|
|
2347
2369
|
const node = machine.getStateNodeById(nodeId);
|
|
2348
2370
|
const invokeConfig = node.config.invoke;
|
|
2349
2371
|
const configSrc = (Array.isArray(invokeConfig) ? invokeConfig[indexStr] : invokeConfig).src;
|
|
2350
2372
|
// A referenced actor may itself be registered by name.
|
|
2351
|
-
return typeof configSrc === 'string' ? machine.implementations.
|
|
2373
|
+
return typeof configSrc === 'string' ? machine.implementations.actorSources[configSrc] : configSrc;
|
|
2352
2374
|
}
|
|
2353
2375
|
function getAllOwnEventDescriptors(snapshot) {
|
|
2354
2376
|
return [...new Set([...snapshot._nodes.flatMap(sn => sn.ownEvents)])];
|