xstate 5.0.0-beta.20 → 5.0.0-beta.21
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/actions/dist/xstate-actions.cjs.js +1 -1
- package/actions/dist/xstate-actions.development.cjs.js +1 -1
- package/actions/dist/xstate-actions.development.esm.js +1 -1
- package/actions/dist/xstate-actions.esm.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.esm.js +1 -1
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/{actions-b299d008.development.esm.js → actions-49f0501e.development.esm.js} +136 -63
- package/dist/{actions-a8a9433c.esm.js → actions-5039c951.esm.js} +134 -64
- package/dist/{actions-d1c41ed3.development.cjs.js → actions-a95d2e66.development.cjs.js} +136 -62
- package/dist/{actions-069d9805.cjs.js → actions-c619a105.cjs.js} +134 -63
- package/dist/declarations/src/Machine.d.ts +2 -2
- package/dist/declarations/src/State.d.ts +4 -7
- package/dist/declarations/src/StateMachine.d.ts +7 -6
- package/dist/declarations/src/StateNode.d.ts +3 -3
- package/dist/declarations/src/actions/send.d.ts +1 -1
- package/dist/declarations/src/actions/stop.d.ts +1 -1
- package/dist/declarations/src/actions.d.ts +2 -2
- package/dist/declarations/src/actors/callback.d.ts +4 -4
- package/dist/declarations/src/actors/observable.d.ts +7 -4
- package/dist/declarations/src/actors/promise.d.ts +4 -4
- package/dist/declarations/src/types.d.ts +41 -29
- package/dist/declarations/src/utils.d.ts +2 -2
- package/dist/xstate.cjs.js +11 -10
- package/dist/xstate.development.cjs.js +11 -10
- package/dist/xstate.development.esm.js +12 -11
- package/dist/xstate.esm.js +12 -11
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -4,6 +4,18 @@ import type { ActorStatus, Clock, Interpreter } from "./interpreter.js";
|
|
|
4
4
|
import type { StateMachine } from "./StateMachine.js";
|
|
5
5
|
import { TypegenDisabled, ResolveTypegenMeta, TypegenConstraint, MarkAllImplementationsAsProvided, AreAllImplementationsAssumedToBeProvided } from "./typegenTypes.js";
|
|
6
6
|
import { PromiseActorLogic } from "./actors/promise.js";
|
|
7
|
+
/**
|
|
8
|
+
* `T | unknown` reduces to `unknown` and that can be problematic when it comes to contextual typing.
|
|
9
|
+
* It especially is a problem when the union has a function member, like here:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* declare function test(cbOrVal: ((arg: number) => unknown) | unknown): void;
|
|
13
|
+
* test((arg) => {}) // oops, implicit any
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* This type can be used to avoid this problem. This union represents the same value space as `unknown`.
|
|
17
|
+
*/
|
|
18
|
+
export type NonReducibleUnknown = {} | null | undefined;
|
|
7
19
|
export type AnyFunction = (...args: any[]) => any;
|
|
8
20
|
type ReturnTypeOrValue<T> = T extends AnyFunction ? ReturnType<T> : T;
|
|
9
21
|
export type IsNever<T> = [T] extends [never] ? true : false;
|
|
@@ -55,7 +67,7 @@ export type MachineContext = Record<string, any>;
|
|
|
55
67
|
export interface ActionArgs<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject = ParameterizedObject> extends UnifiedArg<TContext, TEvent> {
|
|
56
68
|
action: TAction;
|
|
57
69
|
}
|
|
58
|
-
export type InputFrom<T extends AnyActorLogic> = T extends ActorLogic<infer _TEvent, infer _TSnapshot, infer _TInternalState, infer _TPersisted, infer _TSystem, infer TInput> ? TInput : never;
|
|
70
|
+
export type InputFrom<T extends AnyActorLogic> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TActions, infer _TActors, infer TInput, infer _TResolvedTypesMeta> ? TInput : T extends ActorLogic<infer _TEvent, infer _TSnapshot, infer _TInternalState, infer _TPersisted, infer _TSystem, infer TInput> ? TInput : never;
|
|
59
71
|
export type OutputFrom<T extends AnyActorLogic> = T extends ActorLogic<infer _TEvent, infer _TSnapshot, infer _TInternalState, infer _TPersisted, infer _TSystem, infer _TInput, infer TOutput> ? TOutput : never;
|
|
60
72
|
export type Spawner = <T extends AnyActorLogic | string>(// TODO: read string from machine logic keys
|
|
61
73
|
logic: T, options?: Partial<{
|
|
@@ -157,7 +169,7 @@ export interface InvokeDefinition<TContext extends MachineContext, TEvent extend
|
|
|
157
169
|
* The source of the actor logic to be invoked
|
|
158
170
|
*/
|
|
159
171
|
src: string;
|
|
160
|
-
input?: Mapper<TContext, TEvent,
|
|
172
|
+
input?: Mapper<TContext, TEvent, NonReducibleUnknown> | NonReducibleUnknown;
|
|
161
173
|
/**
|
|
162
174
|
* The transition to take upon the invoked child machine reaching its final top-level state.
|
|
163
175
|
*/
|
|
@@ -243,7 +255,7 @@ export type InvokeConfig<TContext extends MachineContext, TEvent extends EventOb
|
|
|
243
255
|
* The source of the machine to be invoked, or the machine itself.
|
|
244
256
|
*/
|
|
245
257
|
src: AnyActorLogic | string;
|
|
246
|
-
input?: Mapper<TContext, TEvent,
|
|
258
|
+
input?: Mapper<TContext, TEvent, NonReducibleUnknown> | NonReducibleUnknown;
|
|
247
259
|
/**
|
|
248
260
|
* The transition to take upon the invoked child machine reaching its final top-level state.
|
|
249
261
|
*/
|
|
@@ -328,7 +340,7 @@ export interface StateNodeConfig<TContext extends MachineContext, TEvent extends
|
|
|
328
340
|
* The output data will be evaluated with the current `context` and placed on the `.data` property
|
|
329
341
|
* of the event.
|
|
330
342
|
*/
|
|
331
|
-
output?: Mapper<TContext, TEvent, any> |
|
|
343
|
+
output?: Mapper<TContext, TEvent, any> | NonReducibleUnknown;
|
|
332
344
|
/**
|
|
333
345
|
* The unique ID of the state node, which can be referenced as a transition target via the
|
|
334
346
|
* `#id` syntax.
|
|
@@ -375,7 +387,7 @@ export interface StateMachineDefinition<TContext extends MachineContext, TEvent
|
|
|
375
387
|
export type AnyStateNode = StateNode<any, any>;
|
|
376
388
|
export type AnyStateNodeDefinition = StateNodeDefinition<any, any>;
|
|
377
389
|
export type AnyState = State<any, any, any, any>;
|
|
378
|
-
export type AnyStateMachine = StateMachine<any, any, any, any, any>;
|
|
390
|
+
export type AnyStateMachine = StateMachine<any, any, any, any, any, any>;
|
|
379
391
|
export type AnyStateConfig = StateConfig<any, AnyEventObject>;
|
|
380
392
|
export interface AtomicStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject> extends StateNodeConfig<TContext, TEvent, TODO, TODO> {
|
|
381
393
|
initial?: undefined;
|
|
@@ -393,7 +405,7 @@ export interface FinalStateNodeConfig<TContext extends MachineContext, TEvent ex
|
|
|
393
405
|
* The data to be sent with the "done.state.<id>" event. The data can be
|
|
394
406
|
* static or dynamic (based on assigners).
|
|
395
407
|
*/
|
|
396
|
-
output?: Mapper<TContext, TEvent, any
|
|
408
|
+
output?: Mapper<TContext, TEvent, any>;
|
|
397
409
|
}
|
|
398
410
|
export type SimpleOrStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject> = AtomicStateNodeConfig<TContext, TEvent> | StateNodeConfig<TContext, TEvent, TODO, TODO>;
|
|
399
411
|
export type ActionFunctionMap<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject = ParameterizedObject> = {
|
|
@@ -447,12 +459,12 @@ type GenerateGuardsImplementationsPart<TContext extends MachineContext, TResolve
|
|
|
447
459
|
}>;
|
|
448
460
|
export type InternalMachineImplementations<TContext extends MachineContext, TEvent extends EventObject, _TAction extends ParameterizedObject, TActor extends ProvidedActor, TResolvedTypesMeta, TRequireMissingImplementations extends boolean = false, TMissingImplementations = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'missingImplementations'>> = Compute<GenerateActionsImplementationsPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateActorsImplementationsPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateDelaysImplementationsPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateGuardsImplementationsPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations>>;
|
|
449
461
|
export type MachineImplementations<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject = ParameterizedObject, TActor extends ProvidedActor = ProvidedActor, TTypesMeta extends TypegenConstraint = TypegenDisabled> = InternalMachineImplementations<TContext, TEvent, TAction, TActor, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TActor>>;
|
|
450
|
-
type InitialContext<TContext extends MachineContext> = TContext | ContextFactory<TContext>;
|
|
451
|
-
export type ContextFactory<TContext extends MachineContext> = ({ spawn, input }: {
|
|
462
|
+
type InitialContext<TContext extends MachineContext, TInput> = TContext | ContextFactory<TContext, TInput>;
|
|
463
|
+
export type ContextFactory<TContext extends MachineContext, TInput> = ({ spawn, input }: {
|
|
452
464
|
spawn: Spawner;
|
|
453
|
-
input:
|
|
465
|
+
input: TInput;
|
|
454
466
|
}) => TContext;
|
|
455
|
-
export type MachineConfig<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject = ParameterizedObject, TActor extends ProvidedActor = ProvidedActor, TTypesMeta = TypegenDisabled> = (StateNodeConfig<NoInfer<TContext>, NoInfer<TEvent>, NoInfer<TAction>, NoInfer<TActor>> & {
|
|
467
|
+
export type MachineConfig<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject = ParameterizedObject, TActor extends ProvidedActor = ProvidedActor, TInput = any, TTypesMeta = TypegenDisabled> = (StateNodeConfig<NoInfer<TContext>, NoInfer<TEvent>, NoInfer<TAction>, NoInfer<TActor>> & {
|
|
456
468
|
/**
|
|
457
469
|
* The initial context (extended state)
|
|
458
470
|
*/
|
|
@@ -460,18 +472,18 @@ export type MachineConfig<TContext extends MachineContext, TEvent extends EventO
|
|
|
460
472
|
* The machine's own version.
|
|
461
473
|
*/
|
|
462
474
|
version?: string;
|
|
463
|
-
types?: MachineTypes<TContext, TEvent, TActor, TTypesMeta>;
|
|
475
|
+
types?: MachineTypes<TContext, TEvent, TActor, TInput, TTypesMeta>;
|
|
464
476
|
}) & (Equals<TContext, MachineContext> extends true ? {
|
|
465
|
-
context?: InitialContext<LowInfer<TContext
|
|
477
|
+
context?: InitialContext<LowInfer<TContext>, TInput>;
|
|
466
478
|
} : {
|
|
467
|
-
context: InitialContext<LowInfer<TContext
|
|
479
|
+
context: InitialContext<LowInfer<TContext>, TInput>;
|
|
468
480
|
});
|
|
469
481
|
export interface ProvidedActor {
|
|
470
482
|
src: string;
|
|
471
483
|
logic: AnyActorLogic;
|
|
472
484
|
id?: string;
|
|
473
485
|
}
|
|
474
|
-
export interface MachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TTypesMeta = TypegenDisabled> {
|
|
486
|
+
export interface MachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TInput, TTypesMeta = TypegenDisabled> {
|
|
475
487
|
context?: TContext;
|
|
476
488
|
actions?: {
|
|
477
489
|
type: string;
|
|
@@ -484,6 +496,7 @@ export interface MachineTypes<TContext extends MachineContext, TEvent extends Ev
|
|
|
484
496
|
[key: string]: any;
|
|
485
497
|
};
|
|
486
498
|
typegen?: TTypesMeta;
|
|
499
|
+
input?: TInput;
|
|
487
500
|
}
|
|
488
501
|
export interface HistoryStateNode<TContext extends MachineContext> extends StateNode<TContext> {
|
|
489
502
|
history: 'shallow' | 'deep';
|
|
@@ -551,15 +564,13 @@ export type PartialAssigner<TContext extends MachineContext, TExpressionEvent ex
|
|
|
551
564
|
export type PropertyAssigner<TContext extends MachineContext, TExpressionEvent extends EventObject> = {
|
|
552
565
|
[K in keyof TContext]?: PartialAssigner<TContext, TExpressionEvent, K> | TContext[K];
|
|
553
566
|
};
|
|
554
|
-
export type Mapper<TContext extends MachineContext, TEvent extends EventObject, TParams
|
|
567
|
+
export type Mapper<TContext extends MachineContext, TEvent extends EventObject, TParams> = (args: {
|
|
555
568
|
context: TContext;
|
|
556
569
|
event: TEvent;
|
|
570
|
+
self: ActorRef<TEvent>;
|
|
557
571
|
}) => TParams;
|
|
558
572
|
export type PropertyMapper<TContext extends MachineContext, TEvent extends EventObject, TParams extends {}> = {
|
|
559
|
-
[K in keyof TParams]?:
|
|
560
|
-
context: TContext;
|
|
561
|
-
event: TEvent;
|
|
562
|
-
}) => TParams[K]) | TParams[K];
|
|
573
|
+
[K in keyof TParams]?: Mapper<TContext, TEvent, TParams[K]> | TParams[K];
|
|
563
574
|
};
|
|
564
575
|
export interface TransitionDefinition<TContext extends MachineContext, TEvent extends EventObject> extends Omit<TransitionConfig<TContext, TEvent>, 'target'> {
|
|
565
576
|
target: Array<StateNode<TContext, TEvent>> | undefined;
|
|
@@ -629,8 +640,9 @@ export interface StateConfig<TContext extends MachineContext, TEvent extends Eve
|
|
|
629
640
|
children: Record<string, ActorRef<any>>;
|
|
630
641
|
done?: boolean;
|
|
631
642
|
output?: any;
|
|
643
|
+
error?: unknown;
|
|
632
644
|
tags?: Set<string>;
|
|
633
|
-
machine?: StateMachine<TContext, TEvent, any, any, any>;
|
|
645
|
+
machine?: StateMachine<TContext, TEvent, any, any, any, any>;
|
|
634
646
|
_internalQueue?: Array<TEvent>;
|
|
635
647
|
}
|
|
636
648
|
export interface InterpreterOptions<TLogic extends AnyActorLogic> {
|
|
@@ -719,12 +731,12 @@ export interface ActorRef<TEvent extends EventObject, TSnapshot = any> extends S
|
|
|
719
731
|
}
|
|
720
732
|
export type AnyActorRef = ActorRef<any, any>;
|
|
721
733
|
export type ActorLogicFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<any, any, any, any, any> ? R : R extends Promise<infer U> ? PromiseActorLogic<U> : never : never;
|
|
722
|
-
export type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer TEvent, any, any, infer TResolvedTypesMeta> ? ActorRef<TEvent, State<TContext, TEvent, TODO, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>> : R extends Promise<infer U> ? ActorRefFrom<PromiseActorLogic<U>> : R extends ActorLogic<infer TEvent, infer TSnapshot, infer _, infer __, infer ___, infer ____, infer _____> ? ActorRef<TEvent, TSnapshot> : never : never;
|
|
734
|
+
export type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer TEvent, any, any, any, infer TResolvedTypesMeta> ? ActorRef<TEvent, State<TContext, TEvent, TODO, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>> : R extends Promise<infer U> ? ActorRefFrom<PromiseActorLogic<U>> : R extends ActorLogic<infer TEvent, infer TSnapshot, infer _, infer __, infer ___, infer ____, infer _____> ? ActorRef<TEvent, TSnapshot> : never : never;
|
|
723
735
|
export type DevToolsAdapter = (service: AnyInterpreter) => void;
|
|
724
|
-
export type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TEvent, infer
|
|
725
|
-
export type MachineImplementationsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine), TRequireMissingImplementations extends boolean = false> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TEvent, infer TAction, infer TActor, infer TResolvedTypesMeta> ? InternalMachineImplementations<TContext, TEvent, TAction, TActor, TResolvedTypesMeta, TRequireMissingImplementations> : never;
|
|
726
|
-
export type __ResolvedTypesMetaFrom<T> = T extends StateMachine<any, any, any, infer TResolvedTypesMeta> ? TResolvedTypesMeta : never;
|
|
727
|
-
export type EventOfMachine<TMachine extends AnyStateMachine> = TMachine extends StateMachine<any, infer E, any, any, any> ? E : never;
|
|
736
|
+
export type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TEvent, infer _TAction, infer TActor, infer TInput, infer TResolvedTypesMeta> ? Interpreter<ActorLogic<TEvent, State<TContext, TEvent, TActor, TResolvedTypesMeta>, State<TContext, TEvent, TActor, TResolvedTypesMeta>, PersistedMachineState<State<TContext, TEvent, TActor, TResolvedTypesMeta>>, ActorSystem<any>, TInput>> : never;
|
|
737
|
+
export type MachineImplementationsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine), TRequireMissingImplementations extends boolean = false> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TEvent, infer TAction, infer TActor, infer _TInput, infer TResolvedTypesMeta> ? InternalMachineImplementations<TContext, TEvent, TAction, TActor, TResolvedTypesMeta, TRequireMissingImplementations> : never;
|
|
738
|
+
export type __ResolvedTypesMetaFrom<T> = T extends StateMachine<any, any, any, any, any, infer TResolvedTypesMeta> ? TResolvedTypesMeta : never;
|
|
739
|
+
export type EventOfMachine<TMachine extends AnyStateMachine> = TMachine extends StateMachine<any, infer E, any, any, any, any> ? E : never;
|
|
728
740
|
export interface ActorContext<TEvent extends EventObject, TSnapshot, TSystem extends ActorSystem<any> = ActorSystem<any>> {
|
|
729
741
|
self: ActorRef<TEvent, TSnapshot>;
|
|
730
742
|
id: string;
|
|
@@ -763,13 +775,13 @@ any, // persisted state
|
|
|
763
775
|
any, // system
|
|
764
776
|
any, // input
|
|
765
777
|
any>;
|
|
766
|
-
export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TSnapshot> ? TSnapshot : R extends Interpreter<infer TLogic> ? SnapshotFrom<TLogic> : R extends StateMachine<infer _, infer __, infer ___, infer ____, infer _____> ? StateFrom<R> : R extends ActorLogic<infer _, infer TSnapshot, infer __, infer ___, infer ____> ? TSnapshot : R extends ActorContext<infer _, infer TSnapshot, infer __> ? TSnapshot : never : never;
|
|
778
|
+
export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TSnapshot> ? TSnapshot : R extends Interpreter<infer TLogic> ? SnapshotFrom<TLogic> : R extends StateMachine<infer _, infer __, infer ___, infer ____, infer _____, infer ______> ? StateFrom<R> : R extends ActorLogic<infer _, infer TSnapshot, infer __, infer ___, infer ____> ? TSnapshot : R extends ActorContext<infer _, infer TSnapshot, infer __> ? TSnapshot : never : never;
|
|
767
779
|
export type EventFromLogic<TLogic extends ActorLogic<any, any>> = TLogic extends ActorLogic<infer TEvent, infer _, infer __, infer ___, infer ____> ? TEvent : never;
|
|
768
780
|
export type PersistedStateFrom<TLogic extends ActorLogic<any, any>> = TLogic extends ActorLogic<infer _TEvent, infer _TSnapshot, infer _TInternalState, infer TPersisted> ? TPersisted : never;
|
|
769
781
|
export type InternalStateFrom<TLogic extends ActorLogic<any, any>> = TLogic extends ActorLogic<infer _TEvent, infer _TSnapshot, infer TInternalState, infer _TPersisted> ? TInternalState : never;
|
|
770
|
-
type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer TEvent, infer __, infer ___, infer ____> ? TEvent : R extends State<infer _TContext, infer TEvent, infer _TAction, infer _TActor> ? TEvent : R extends ActorRef<infer TEvent, infer _> ? TEvent : never : never;
|
|
782
|
+
type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer TEvent, infer __, infer ___, infer ____, infer _____> ? TEvent : R extends State<infer _TContext, infer TEvent, infer _TAction, infer _TActor> ? TEvent : R extends ActorRef<infer TEvent, infer _> ? TEvent : never : never;
|
|
771
783
|
export type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent extends EventObject = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : ExtractEvent<TEvent, K>;
|
|
772
|
-
export type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _, infer __, infer ___, infer ____> ? TContext : R extends State<infer TContext, infer _TEvent, infer _TAction, infer _TActor> ? TContext : R extends Interpreter<infer TActorLogic> ? TActorLogic extends StateMachine<infer TContext, infer
|
|
784
|
+
export type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _, infer __, infer ___, infer ____, infer _____> ? TContext : R extends State<infer TContext, infer _TEvent, infer _TAction, infer _TActor> ? TContext : R extends Interpreter<infer TActorLogic> ? TActorLogic extends StateMachine<infer TContext, infer _TEvent, infer _TActions, infer _TActors, infer _TInput, infer _TTypesMeta> ? TContext : never : never : never;
|
|
773
785
|
export type InferEvent<E extends EventObject> = {
|
|
774
786
|
[T in E['type']]: {
|
|
775
787
|
type: T;
|
|
@@ -791,7 +803,7 @@ export interface ActorSystem<T extends ActorSystemInfo> {
|
|
|
791
803
|
get: <K extends keyof T['actors']>(key: K) => T['actors'][K] | undefined;
|
|
792
804
|
}
|
|
793
805
|
export type AnyActorSystem = ActorSystem<any>;
|
|
794
|
-
export type PersistedMachineState<TState extends AnyState> = Pick<TState, 'value' | 'output' | 'context' | 'done' | 'historyValue'> & {
|
|
806
|
+
export type PersistedMachineState<TState extends AnyState> = Pick<TState, 'value' | 'output' | 'error' | 'context' | 'done' | 'historyValue'> & {
|
|
795
807
|
children: {
|
|
796
808
|
[K in keyof TState['children']]: {
|
|
797
809
|
state: any;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnyActorLogic, AnyState } from "./index.js";
|
|
2
2
|
import type { StateNode } from "./StateNode.js";
|
|
3
|
-
import type { ActorLogic, AnyEventObject, EventObject, EventType, InvokeConfig, MachineContext, Mapper, Observer,
|
|
3
|
+
import type { ActorLogic, AnyEventObject, EventObject, EventType, InvokeConfig, MachineContext, Mapper, Observer, ErrorEvent, SingleOrArray, StateLike, StateValue, Subscribable, TransitionConfig, TransitionConfigTarget, TODO, AnyActorRef } from "./types.js";
|
|
4
4
|
export declare function keys<T extends object>(value: T): Array<keyof T & string>;
|
|
5
5
|
export declare function matchesState(parentStateId: StateValue, childStateId: StateValue): boolean;
|
|
6
6
|
export declare function toStatePath(stateId: string | string[]): string[];
|
|
@@ -26,7 +26,7 @@ export declare function toStatePaths(stateValue: StateValue | undefined): string
|
|
|
26
26
|
export declare function flatten<T>(array: Array<T | T[]>): T[];
|
|
27
27
|
export declare function toArrayStrict<T>(value: T[] | T): T[];
|
|
28
28
|
export declare function toArray<T>(value: T[] | T | undefined): T[];
|
|
29
|
-
export declare function mapContext<TContext extends MachineContext, TEvent extends EventObject>(mapper: Mapper<TContext, TEvent, any
|
|
29
|
+
export declare function mapContext<TContext extends MachineContext, TEvent extends EventObject>(mapper: Mapper<TContext, TEvent, any>, context: TContext, event: TEvent, self: AnyActorRef): any;
|
|
30
30
|
export declare function isBuiltInEvent(eventType: EventType): boolean;
|
|
31
31
|
export declare function isPromiseLike(value: any): value is PromiseLike<any>;
|
|
32
32
|
export declare function isActorLogic(value: any): value is ActorLogic<any, any>;
|
package/dist/xstate.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var actors_dist_xstateActors = require('./actions-
|
|
5
|
+
var actors_dist_xstateActors = require('./actions-c619a105.cjs.js');
|
|
6
6
|
require('../dev/dist/xstate-dev.cjs.js');
|
|
7
7
|
|
|
8
8
|
const EMPTY_OBJECT = {};
|
|
@@ -365,6 +365,7 @@ class StateMachine {
|
|
|
365
365
|
this.__TAction = void 0;
|
|
366
366
|
this.__TActor = void 0;
|
|
367
367
|
this.__TResolvedTypesMeta = void 0;
|
|
368
|
+
this.__TInput = void 0;
|
|
368
369
|
this.id = config.id || '(machine)';
|
|
369
370
|
this.implementations = {
|
|
370
371
|
actors: implementations?.actors ?? {},
|
|
@@ -452,7 +453,9 @@ class StateMachine {
|
|
|
452
453
|
transition(state, event, actorCtx) {
|
|
453
454
|
// TODO: handle error events in a better way
|
|
454
455
|
if (actors_dist_xstateActors.isErrorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
|
|
455
|
-
|
|
456
|
+
return actors_dist_xstateActors.cloneState(state, {
|
|
457
|
+
error: event.data
|
|
458
|
+
});
|
|
456
459
|
}
|
|
457
460
|
const {
|
|
458
461
|
state: nextState
|
|
@@ -523,15 +526,10 @@ class StateMachine {
|
|
|
523
526
|
} = actors_dist_xstateActors.macrostep(nextState, initEvent, actorCtx);
|
|
524
527
|
return macroState;
|
|
525
528
|
}
|
|
526
|
-
start(state
|
|
529
|
+
start(state) {
|
|
527
530
|
Object.values(state.children).forEach(child => {
|
|
528
531
|
if (child.status === 0) {
|
|
529
|
-
|
|
530
|
-
child.start?.();
|
|
531
|
-
} catch (err) {
|
|
532
|
-
// TODO: unify error handling when child starts
|
|
533
|
-
actorCtx.self.send(actors_dist_xstateActors.error(child.id, err));
|
|
534
|
-
}
|
|
532
|
+
child.start?.();
|
|
535
533
|
}
|
|
536
534
|
});
|
|
537
535
|
}
|
|
@@ -558,7 +556,10 @@ class StateMachine {
|
|
|
558
556
|
return stateConfig instanceof actors_dist_xstateActors.State ? stateConfig : new actors_dist_xstateActors.State(stateConfig, this);
|
|
559
557
|
}
|
|
560
558
|
getStatus(state) {
|
|
561
|
-
return state.
|
|
559
|
+
return state.error ? {
|
|
560
|
+
status: 'error',
|
|
561
|
+
data: state.error
|
|
562
|
+
} : state.done ? {
|
|
562
563
|
status: 'done',
|
|
563
564
|
data: state.output
|
|
564
565
|
} : {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var actors_dist_xstateActors = require('./actions-
|
|
5
|
+
var actors_dist_xstateActors = require('./actions-a95d2e66.development.cjs.js');
|
|
6
6
|
require('../dev/dist/xstate-dev.development.cjs.js');
|
|
7
7
|
|
|
8
8
|
const EMPTY_OBJECT = {};
|
|
@@ -365,6 +365,7 @@ class StateMachine {
|
|
|
365
365
|
this.__TAction = void 0;
|
|
366
366
|
this.__TActor = void 0;
|
|
367
367
|
this.__TResolvedTypesMeta = void 0;
|
|
368
|
+
this.__TInput = void 0;
|
|
368
369
|
this.id = config.id || '(machine)';
|
|
369
370
|
this.implementations = {
|
|
370
371
|
actors: implementations?.actors ?? {},
|
|
@@ -452,7 +453,9 @@ class StateMachine {
|
|
|
452
453
|
transition(state, event, actorCtx) {
|
|
453
454
|
// TODO: handle error events in a better way
|
|
454
455
|
if (actors_dist_xstateActors.isErrorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
|
|
455
|
-
|
|
456
|
+
return actors_dist_xstateActors.cloneState(state, {
|
|
457
|
+
error: event.data
|
|
458
|
+
});
|
|
456
459
|
}
|
|
457
460
|
const {
|
|
458
461
|
state: nextState
|
|
@@ -523,15 +526,10 @@ class StateMachine {
|
|
|
523
526
|
} = actors_dist_xstateActors.macrostep(nextState, initEvent, actorCtx);
|
|
524
527
|
return macroState;
|
|
525
528
|
}
|
|
526
|
-
start(state
|
|
529
|
+
start(state) {
|
|
527
530
|
Object.values(state.children).forEach(child => {
|
|
528
531
|
if (child.status === 0) {
|
|
529
|
-
|
|
530
|
-
child.start?.();
|
|
531
|
-
} catch (err) {
|
|
532
|
-
// TODO: unify error handling when child starts
|
|
533
|
-
actorCtx.self.send(actors_dist_xstateActors.error(child.id, err));
|
|
534
|
-
}
|
|
532
|
+
child.start?.();
|
|
535
533
|
}
|
|
536
534
|
});
|
|
537
535
|
}
|
|
@@ -558,7 +556,10 @@ class StateMachine {
|
|
|
558
556
|
return stateConfig instanceof actors_dist_xstateActors.State ? stateConfig : new actors_dist_xstateActors.State(stateConfig, this);
|
|
559
557
|
}
|
|
560
558
|
getStatus(state) {
|
|
561
|
-
return state.
|
|
559
|
+
return state.error ? {
|
|
560
|
+
status: 'error',
|
|
561
|
+
data: state.error
|
|
562
|
+
} : state.done ? {
|
|
562
563
|
status: 'done',
|
|
563
564
|
data: state.output
|
|
564
565
|
} : {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, c as memo, e as evaluateGuard, d as flatten, g as createInvokeId, h as getDelayedTransitions, i as formatInitialTransition, j as getCandidates, k as toInvokeConfig, l as getConfiguration, n as getStateNodes, r as resolveStateValue, o as isInFinalState, p as State, q as isErrorEvent, s as
|
|
2
|
-
export { a5 as ConstantPrefix, L as Interpreter, M as InterpreterStatus, a6 as SpecialTargets, p as State, a3 as and,
|
|
1
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, c as memo, e as evaluateGuard, d as flatten, g as createInvokeId, h as getDelayedTransitions, i as formatInitialTransition, j as getCandidates, k as toInvokeConfig, l as getConfiguration, n as getStateNodes, r as resolveStateValue, o as isInFinalState, p as State, q as isErrorEvent, s as cloneState, u as macrostep, v as transitionNode, w as getInitialConfiguration, x as resolveActionsAndContext, y as assign, z as createInitEvent, A as microstep, B as isAtomicStateNode, C as isStateId, D as getStateNodeByPath, E as getPersistedState, F as resolveReferencedActor, G as interpret, H as matchesState } from './actions-49f0501e.development.esm.js';
|
|
2
|
+
export { a5 as ConstantPrefix, L as Interpreter, M as InterpreterStatus, a6 as SpecialTargets, p as State, a3 as and, y as assign, P as cancel, Q as choose, O as doneInvoke, K as forwardTo, _ as fromCallback, $ as fromEventObservable, Z as fromObservable, Y as fromPromise, a0 as fromTransition, n as getStateNodes, G as interpret, R as log, H as matchesState, a2 as not, a4 as or, W as pathToStateValue, T as pure, U as raise, J as sendParent, I as sendTo, a1 as stateIn, V as stop, X as toObserver } from './actions-49f0501e.development.esm.js';
|
|
3
3
|
import '../dev/dist/xstate-dev.development.esm.js';
|
|
4
4
|
|
|
5
5
|
const EMPTY_OBJECT = {};
|
|
@@ -362,6 +362,7 @@ class StateMachine {
|
|
|
362
362
|
this.__TAction = void 0;
|
|
363
363
|
this.__TActor = void 0;
|
|
364
364
|
this.__TResolvedTypesMeta = void 0;
|
|
365
|
+
this.__TInput = void 0;
|
|
365
366
|
this.id = config.id || '(machine)';
|
|
366
367
|
this.implementations = {
|
|
367
368
|
actors: implementations?.actors ?? {},
|
|
@@ -449,7 +450,9 @@ class StateMachine {
|
|
|
449
450
|
transition(state, event, actorCtx) {
|
|
450
451
|
// TODO: handle error events in a better way
|
|
451
452
|
if (isErrorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
|
|
452
|
-
|
|
453
|
+
return cloneState(state, {
|
|
454
|
+
error: event.data
|
|
455
|
+
});
|
|
453
456
|
}
|
|
454
457
|
const {
|
|
455
458
|
state: nextState
|
|
@@ -520,15 +523,10 @@ class StateMachine {
|
|
|
520
523
|
} = macrostep(nextState, initEvent, actorCtx);
|
|
521
524
|
return macroState;
|
|
522
525
|
}
|
|
523
|
-
start(state
|
|
526
|
+
start(state) {
|
|
524
527
|
Object.values(state.children).forEach(child => {
|
|
525
528
|
if (child.status === 0) {
|
|
526
|
-
|
|
527
|
-
child.start?.();
|
|
528
|
-
} catch (err) {
|
|
529
|
-
// TODO: unify error handling when child starts
|
|
530
|
-
actorCtx.self.send(error(child.id, err));
|
|
531
|
-
}
|
|
529
|
+
child.start?.();
|
|
532
530
|
}
|
|
533
531
|
});
|
|
534
532
|
}
|
|
@@ -555,7 +553,10 @@ class StateMachine {
|
|
|
555
553
|
return stateConfig instanceof State ? stateConfig : new State(stateConfig, this);
|
|
556
554
|
}
|
|
557
555
|
getStatus(state) {
|
|
558
|
-
return state.
|
|
556
|
+
return state.error ? {
|
|
557
|
+
status: 'error',
|
|
558
|
+
data: state.error
|
|
559
|
+
} : state.done ? {
|
|
559
560
|
status: 'done',
|
|
560
561
|
data: state.output
|
|
561
562
|
} : {
|
package/dist/xstate.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, c as memo, e as evaluateGuard, d as flatten, g as createInvokeId, h as getDelayedTransitions, i as formatInitialTransition, j as getCandidates, k as toInvokeConfig, l as getConfiguration, n as getStateNodes, r as resolveStateValue, o as isInFinalState, p as State, q as isErrorEvent, s as
|
|
2
|
-
export { a5 as ConstantPrefix, L as Interpreter, M as InterpreterStatus, a6 as SpecialTargets, p as State, a3 as and,
|
|
1
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, c as memo, e as evaluateGuard, d as flatten, g as createInvokeId, h as getDelayedTransitions, i as formatInitialTransition, j as getCandidates, k as toInvokeConfig, l as getConfiguration, n as getStateNodes, r as resolveStateValue, o as isInFinalState, p as State, q as isErrorEvent, s as cloneState, u as macrostep, v as transitionNode, w as getInitialConfiguration, x as resolveActionsAndContext, y as assign, z as createInitEvent, A as microstep, B as isAtomicStateNode, C as isStateId, D as getStateNodeByPath, E as getPersistedState, F as resolveReferencedActor, G as interpret, H as matchesState } from './actions-5039c951.esm.js';
|
|
2
|
+
export { a5 as ConstantPrefix, L as Interpreter, M as InterpreterStatus, a6 as SpecialTargets, p as State, a3 as and, y as assign, P as cancel, Q as choose, O as doneInvoke, K as forwardTo, _ as fromCallback, $ as fromEventObservable, Z as fromObservable, Y as fromPromise, a0 as fromTransition, n as getStateNodes, G as interpret, R as log, H as matchesState, a2 as not, a4 as or, W as pathToStateValue, T as pure, U as raise, J as sendParent, I as sendTo, a1 as stateIn, V as stop, X as toObserver } from './actions-5039c951.esm.js';
|
|
3
3
|
import '../dev/dist/xstate-dev.esm.js';
|
|
4
4
|
|
|
5
5
|
const EMPTY_OBJECT = {};
|
|
@@ -362,6 +362,7 @@ class StateMachine {
|
|
|
362
362
|
this.__TAction = void 0;
|
|
363
363
|
this.__TActor = void 0;
|
|
364
364
|
this.__TResolvedTypesMeta = void 0;
|
|
365
|
+
this.__TInput = void 0;
|
|
365
366
|
this.id = config.id || '(machine)';
|
|
366
367
|
this.implementations = {
|
|
367
368
|
actors: implementations?.actors ?? {},
|
|
@@ -449,7 +450,9 @@ class StateMachine {
|
|
|
449
450
|
transition(state, event, actorCtx) {
|
|
450
451
|
// TODO: handle error events in a better way
|
|
451
452
|
if (isErrorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
|
|
452
|
-
|
|
453
|
+
return cloneState(state, {
|
|
454
|
+
error: event.data
|
|
455
|
+
});
|
|
453
456
|
}
|
|
454
457
|
const {
|
|
455
458
|
state: nextState
|
|
@@ -520,15 +523,10 @@ class StateMachine {
|
|
|
520
523
|
} = macrostep(nextState, initEvent, actorCtx);
|
|
521
524
|
return macroState;
|
|
522
525
|
}
|
|
523
|
-
start(state
|
|
526
|
+
start(state) {
|
|
524
527
|
Object.values(state.children).forEach(child => {
|
|
525
528
|
if (child.status === 0) {
|
|
526
|
-
|
|
527
|
-
child.start?.();
|
|
528
|
-
} catch (err) {
|
|
529
|
-
// TODO: unify error handling when child starts
|
|
530
|
-
actorCtx.self.send(error(child.id, err));
|
|
531
|
-
}
|
|
529
|
+
child.start?.();
|
|
532
530
|
}
|
|
533
531
|
});
|
|
534
532
|
}
|
|
@@ -555,7 +553,10 @@ class StateMachine {
|
|
|
555
553
|
return stateConfig instanceof State ? stateConfig : new State(stateConfig, this);
|
|
556
554
|
}
|
|
557
555
|
getStatus(state) {
|
|
558
|
-
return state.
|
|
556
|
+
return state.error ? {
|
|
557
|
+
status: 'error',
|
|
558
|
+
data: state.error
|
|
559
|
+
} : state.done ? {
|
|
559
560
|
status: 'done',
|
|
560
561
|
data: state.output
|
|
561
562
|
} : {
|