xstate 6.0.0-alpha.21 → 6.0.0-alpha.23
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-3c17fe3e.esm.js → StateMachine-022864fd.esm.js} +183 -64
- package/dist/{StateMachine-550ff7f2.development.cjs.js → StateMachine-53114dce.development.cjs.js} +187 -63
- package/dist/{StateMachine-1b155670.cjs.js → StateMachine-aad57180.cjs.js} +187 -63
- package/dist/{StateMachine-e25dd61f.development.esm.js → StateMachine-d2247245.development.esm.js} +183 -64
- package/dist/declarations/src/State.d.ts +4 -2
- package/dist/declarations/src/StateMachine.d.ts +5 -4
- package/dist/declarations/src/actions.d.ts +10 -8
- package/dist/declarations/src/actors/logic.d.ts +5 -21
- package/dist/declarations/src/createActor.d.ts +3 -1
- package/dist/declarations/src/fsm.d.ts +3 -1
- package/dist/declarations/src/index.d.ts +2 -2
- package/dist/declarations/src/spawn.d.ts +3 -3
- package/dist/declarations/src/stateUtils.d.ts +1 -1
- package/dist/declarations/src/system.d.ts +34 -9
- package/dist/declarations/src/transitionActions.d.ts +5 -1
- package/dist/declarations/src/types.d.ts +70 -51
- package/dist/{index-3f87408c.esm.js → index-3609e096.esm.js} +782 -389
- package/dist/{index-ec7c7a2d.development.cjs.js → index-41c0375c.development.cjs.js} +790 -390
- package/dist/{index-e694228c.cjs.js → index-434fac23.cjs.js} +789 -389
- package/dist/{index-d39fb138.development.esm.js → index-f5407323.development.esm.js} +783 -390
- 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 +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 +82 -103
- package/dist/xstate.cjs.mjs +1 -0
- package/dist/xstate.development.cjs.js +82 -103
- package/dist/xstate.development.cjs.mjs +1 -0
- package/dist/xstate.development.esm.js +80 -102
- package/dist/xstate.esm.js +80 -102
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import { AsyncActorLogic } from "./actors/promise.js";
|
|
|
5
5
|
import type { Actor } from "./createActor.js";
|
|
6
6
|
import { InspectionEvent } from "./inspection.js";
|
|
7
7
|
import { Spawner } from "./spawn.js";
|
|
8
|
-
import { AnyActorSystem, Clock } from "./system.js";
|
|
8
|
+
import type { ActorSystemRuntime, AnyActorSystem, Clock } from "./system.js";
|
|
9
9
|
import { Implementations, Next_StateNodeConfig } from "./types.v6.js";
|
|
10
10
|
import { StandardSchemaV1 } from "./schema.types.js";
|
|
11
11
|
import { builtInActions } from "./actions.js";
|
|
@@ -486,50 +486,27 @@ export interface StateConfig<TContext extends MachineContext, TEvent extends Eve
|
|
|
486
486
|
context: TContext;
|
|
487
487
|
historyValue?: HistoryValue;
|
|
488
488
|
children: Record<string, AnyActorRef | undefined>;
|
|
489
|
+
timers?: Record<string, LogicalTimer>;
|
|
489
490
|
status: SnapshotStatus;
|
|
490
491
|
output?: any;
|
|
491
492
|
error?: unknown;
|
|
492
493
|
machine?: StateMachine<TContext, TEvent, any, any, any, any, any, any, any, any, any, any, any, any>;
|
|
493
494
|
}
|
|
494
|
-
/**
|
|
495
|
-
|
|
496
|
-
* in a persisted snapshot — a serialized built-in action descriptor plus its
|
|
497
|
-
* runtime progress, with enough information to restore it under any strategy.
|
|
498
|
-
*/
|
|
499
|
-
export interface PendingEffect {
|
|
500
|
-
/** The serialized built-in action type for this effect. */
|
|
501
|
-
type: '@xstate.raise';
|
|
502
|
-
event: EventObject;
|
|
495
|
+
/** A deterministic delayed-delivery declaration owned by a logic snapshot. */
|
|
496
|
+
export interface LogicalTimer {
|
|
503
497
|
id: string;
|
|
504
|
-
/** The original delay (in ms) the effect was scheduled with. */
|
|
505
498
|
delay: number;
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
/**
|
|
509
|
-
|
|
499
|
+
type: '@xstate.raise' | '@xstate.sendTo';
|
|
500
|
+
event: EventObject;
|
|
501
|
+
/** `self` or the logical actor that will receive `event`. */
|
|
502
|
+
target: 'self' | AnyActor;
|
|
503
|
+
}
|
|
504
|
+
/** The logical input delivered to a timer's source when its runtime delay ends. */
|
|
505
|
+
export interface TimerEvent extends EventObject {
|
|
506
|
+
type: 'xstate.timer';
|
|
507
|
+
id: string;
|
|
510
508
|
}
|
|
511
|
-
/**
|
|
512
|
-
* How pending effects (timers) from a persisted snapshot are restored on
|
|
513
|
-
* `actor.start()`:
|
|
514
|
-
*
|
|
515
|
-
* - `'resume'` (default) — the clock was "frozen" while persisted: a 5-minute
|
|
516
|
-
* timer persisted with 1 minute elapsed fires after 4 more minutes.
|
|
517
|
-
* - `'restart'` — timers start over with their full delay.
|
|
518
|
-
* - `'absolute'` — timers honor the original wall-clock expiry (`startedAt +
|
|
519
|
-
* delay`); already-expired timers fire immediately.
|
|
520
|
-
* - A custom function receiving the pending effect and returning the remaining
|
|
521
|
-
* delay in ms.
|
|
522
|
-
*/
|
|
523
|
-
export type TimersRestoreStrategy = 'resume' | 'restart' | 'absolute' | ((pendingEffect: PendingEffect) => number);
|
|
524
509
|
export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
525
|
-
/**
|
|
526
|
-
* How pending timers (delayed events/transitions) from a persisted `snapshot`
|
|
527
|
-
* are restored when the actor starts. Applies to this actor and (when this is
|
|
528
|
-
* the root) all rehydrated child actors.
|
|
529
|
-
*
|
|
530
|
-
* @default 'resume'
|
|
531
|
-
*/
|
|
532
|
-
timers?: TimersRestoreStrategy;
|
|
533
510
|
/**
|
|
534
511
|
* The clock that is responsible for setting and clearing timeouts, such as
|
|
535
512
|
* delayed events and transitions.
|
|
@@ -795,7 +772,7 @@ export interface ActorScope<TSnapshot extends Snapshot<unknown>, TEvent extends
|
|
|
795
772
|
sessionId: string;
|
|
796
773
|
logger: (...args: any[]) => void;
|
|
797
774
|
defer: (fn: () => void) => void;
|
|
798
|
-
emit: (event: TEmitted) => void
|
|
775
|
+
emit: (event: TEmitted) => void | PromiseLike<void>;
|
|
799
776
|
system: TSystem;
|
|
800
777
|
stopChild: (child: AnyActor) => void;
|
|
801
778
|
actionExecutor: ActionExecutor;
|
|
@@ -822,7 +799,7 @@ export type Snapshot<TOutput> = {
|
|
|
822
799
|
output: undefined;
|
|
823
800
|
error: undefined;
|
|
824
801
|
};
|
|
825
|
-
export type ActorLogicTransitionResult<TSnapshot extends Snapshot<unknown>, TEffect =
|
|
802
|
+
export type ActorLogicTransitionResult<TSnapshot extends Snapshot<unknown>, TEffect = ExecutableActionObject> = [nextSnapshot: TSnapshot, effects: TEffect[]];
|
|
826
803
|
/**
|
|
827
804
|
* Represents logic which can be used by an actor.
|
|
828
805
|
*
|
|
@@ -877,8 +854,12 @@ in TInput = NonReducibleUnknown, TSystem extends AnyActorSystem = AnyActorSystem
|
|
|
877
854
|
*
|
|
878
855
|
* @param snapshot - The starting state.
|
|
879
856
|
* @param actorScope - The actor scope.
|
|
857
|
+
* @param options - Start metadata, including whether the snapshot was
|
|
858
|
+
* restored.
|
|
880
859
|
*/
|
|
881
|
-
start?: (snapshot: TSnapshot, actorScope: ActorScope<TSnapshot, TEvent, AnyActorSystem, TEmitted
|
|
860
|
+
start?: (snapshot: TSnapshot, actorScope: ActorScope<TSnapshot, TEvent, AnyActorSystem, TEmitted>, options?: {
|
|
861
|
+
restored: boolean;
|
|
862
|
+
}) => void;
|
|
882
863
|
/**
|
|
883
864
|
* Obtains the internal state of the actor in a representation which can be be
|
|
884
865
|
* persisted. The persisted state can be restored by `restoreSnapshot`.
|
|
@@ -887,12 +868,6 @@ in TInput = NonReducibleUnknown, TSystem extends AnyActorSystem = AnyActorSystem
|
|
|
887
868
|
* @returns The a representation of the internal state to be persisted.
|
|
888
869
|
*/
|
|
889
870
|
getPersistedSnapshot: (snapshot: TSnapshot, options?: unknown) => Snapshot<unknown>;
|
|
890
|
-
/**
|
|
891
|
-
* Executes the non-action effects returned from `transition` (e.g. the
|
|
892
|
-
* effects produced by `createLogic`-based actors). Actor logic that never
|
|
893
|
-
* returns such effects can omit this.
|
|
894
|
-
*/
|
|
895
|
-
executeEffects?: (effects: readonly unknown[], actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>) => void;
|
|
896
871
|
/**
|
|
897
872
|
* Returns an event that the actor should transition with to recover from an
|
|
898
873
|
* execution error, or `undefined` if the given snapshot cannot handle it.
|
|
@@ -906,9 +881,10 @@ export interface AnyActorLogic {
|
|
|
906
881
|
initialTransition(input: any, actorScope: any): ActorLogicTransitionResult<any>;
|
|
907
882
|
getInitialSnapshot(actorScope: any, input: any): any;
|
|
908
883
|
restoreSnapshot?(persistedState: Snapshot<unknown>, actorScope: any): any;
|
|
909
|
-
start?(snapshot: any, actorScope: any
|
|
884
|
+
start?(snapshot: any, actorScope: any, options?: {
|
|
885
|
+
restored: boolean;
|
|
886
|
+
}): void;
|
|
910
887
|
getPersistedSnapshot(snapshot: any, options?: unknown): Snapshot<unknown>;
|
|
911
|
-
executeEffects?(effects: readonly unknown[], actorScope: any): void;
|
|
912
888
|
getExecutionErrorEvent?(snapshot: any, error: unknown): any;
|
|
913
889
|
}
|
|
914
890
|
export type UnknownActorLogic = ActorLogic<any, // snapshot
|
|
@@ -1047,13 +1023,35 @@ export type ToStateValue<T extends StateSchema> = T extends {
|
|
|
1047
1023
|
export interface BaseExecutableActionObject {
|
|
1048
1024
|
params: NonReducibleUnknown;
|
|
1049
1025
|
args: unknown[];
|
|
1050
|
-
exec
|
|
1026
|
+
exec(runtime?: Partial<ActorSystemRuntime>): void | PromiseLike<void> | undefined;
|
|
1051
1027
|
}
|
|
1028
|
+
/** The terminal result published when an actor completes or errors. */
|
|
1029
|
+
export type ActorTermination = {
|
|
1030
|
+
status: 'done';
|
|
1031
|
+
output: unknown;
|
|
1032
|
+
error: undefined;
|
|
1033
|
+
} | {
|
|
1034
|
+
status: 'error';
|
|
1035
|
+
output: undefined;
|
|
1036
|
+
error: unknown;
|
|
1037
|
+
};
|
|
1052
1038
|
export interface CustomExecutableActionObject<TType extends string = string & {}> extends BaseExecutableActionObject {
|
|
1039
|
+
kind: 'action';
|
|
1053
1040
|
type: TType;
|
|
1041
|
+
action: ((...args: any[]) => void | PromiseLike<void>) | undefined;
|
|
1042
|
+
}
|
|
1043
|
+
export interface EmitExecutableActionObject<TType extends string = string & {}> extends BaseExecutableActionObject {
|
|
1044
|
+
kind: 'emit';
|
|
1045
|
+
type: TType;
|
|
1046
|
+
source: AnyActor;
|
|
1047
|
+
event: EventObject & {
|
|
1048
|
+
type: TType;
|
|
1049
|
+
};
|
|
1054
1050
|
}
|
|
1055
1051
|
export interface SpawnExecutableActionObject extends BaseExecutableActionObject {
|
|
1052
|
+
kind: 'builtin';
|
|
1056
1053
|
type: '@xstate.spawn';
|
|
1054
|
+
source: AnyActor | undefined;
|
|
1057
1055
|
actor: AnyActor;
|
|
1058
1056
|
id: string;
|
|
1059
1057
|
logic: AnyActorLogic;
|
|
@@ -1062,20 +1060,26 @@ export interface SpawnExecutableActionObject extends BaseExecutableActionObject
|
|
|
1062
1060
|
args: Parameters<(typeof builtInActions)['@xstate.spawn']>;
|
|
1063
1061
|
}
|
|
1064
1062
|
export interface StartExecutableActionObject extends BaseExecutableActionObject {
|
|
1063
|
+
kind: 'builtin';
|
|
1065
1064
|
type: '@xstate.start';
|
|
1065
|
+
source: AnyActor | undefined;
|
|
1066
1066
|
actor: AnyActor;
|
|
1067
1067
|
id: string;
|
|
1068
1068
|
args: Parameters<(typeof builtInActions)['@xstate.start']>;
|
|
1069
1069
|
}
|
|
1070
1070
|
export interface RaiseExecutableActionObject extends BaseExecutableActionObject {
|
|
1071
|
+
kind: 'builtin';
|
|
1071
1072
|
type: '@xstate.raise';
|
|
1073
|
+
source: AnyActor;
|
|
1072
1074
|
event: EventObject;
|
|
1073
1075
|
id: string | undefined;
|
|
1074
1076
|
delay: number | undefined;
|
|
1075
1077
|
args: Parameters<(typeof builtInActions)['@xstate.raise']>;
|
|
1076
1078
|
}
|
|
1077
1079
|
export interface SendToExecutableActionObject extends BaseExecutableActionObject {
|
|
1080
|
+
kind: 'builtin';
|
|
1078
1081
|
type: '@xstate.sendTo';
|
|
1082
|
+
source: AnyActor;
|
|
1079
1083
|
target: AnyActor;
|
|
1080
1084
|
event: EventObject;
|
|
1081
1085
|
id: string | undefined;
|
|
@@ -1083,15 +1087,29 @@ export interface SendToExecutableActionObject extends BaseExecutableActionObject
|
|
|
1083
1087
|
args: Parameters<(typeof builtInActions)['@xstate.sendTo']>;
|
|
1084
1088
|
}
|
|
1085
1089
|
export interface CancelExecutableActionObject extends BaseExecutableActionObject {
|
|
1090
|
+
kind: 'builtin';
|
|
1086
1091
|
type: '@xstate.cancel';
|
|
1092
|
+
source: AnyActor;
|
|
1087
1093
|
id: string;
|
|
1088
1094
|
args: Parameters<(typeof builtInActions)['@xstate.cancel']>;
|
|
1089
1095
|
}
|
|
1090
1096
|
export interface StopExecutableActionObject extends BaseExecutableActionObject {
|
|
1097
|
+
kind: 'builtin';
|
|
1091
1098
|
type: '@xstate.stop';
|
|
1099
|
+
source: AnyActor;
|
|
1092
1100
|
actor: AnyActor;
|
|
1101
|
+
id: string;
|
|
1093
1102
|
args: Parameters<(typeof builtInActions)['@xstate.stop']>;
|
|
1094
1103
|
}
|
|
1104
|
+
/** An executable effect that publishes an actor's terminal result. */
|
|
1105
|
+
export type TerminateExecutableActionObject = BaseExecutableActionObject & {
|
|
1106
|
+
kind: 'builtin';
|
|
1107
|
+
type: '@xstate.terminate';
|
|
1108
|
+
source: AnyActor;
|
|
1109
|
+
actor: AnyActor;
|
|
1110
|
+
id: string;
|
|
1111
|
+
args: Parameters<(typeof builtInActions)['@xstate.terminate']>;
|
|
1112
|
+
} & ActorTermination;
|
|
1095
1113
|
export type BuiltInExecutableActionObject = Values<{
|
|
1096
1114
|
'@xstate.spawn': SpawnExecutableActionObject;
|
|
1097
1115
|
'@xstate.start': StartExecutableActionObject;
|
|
@@ -1099,16 +1117,17 @@ export type BuiltInExecutableActionObject = Values<{
|
|
|
1099
1117
|
'@xstate.sendTo': SendToExecutableActionObject;
|
|
1100
1118
|
'@xstate.cancel': CancelExecutableActionObject;
|
|
1101
1119
|
'@xstate.stop': StopExecutableActionObject;
|
|
1120
|
+
'@xstate.terminate': TerminateExecutableActionObject;
|
|
1102
1121
|
}>;
|
|
1103
1122
|
export type SpecialExecutableAction = BuiltInExecutableActionObject;
|
|
1104
|
-
type TransitionExecutableActionObject<TType extends string = never> = BuiltInExecutableActionObject | CustomExecutableActionObject<TType | (string & {})>;
|
|
1123
|
+
type TransitionExecutableActionObject<TType extends string = never> = BuiltInExecutableActionObject | EmitExecutableActionObject | CustomExecutableActionObject<TType | (string & {})>;
|
|
1105
1124
|
type KnownImplementationKeys<TImplementationMap> = string extends keyof TImplementationMap ? never : Extract<keyof TImplementationMap, string>;
|
|
1106
1125
|
export type ExecutableActionObjectFromLogic<T extends AnyActorLogic> = T extends StateMachine<any, any, any, any, any, any, any, any, any, any, infer TActionMap, any, any, any> ? TransitionExecutableActionObject<KnownImplementationKeys<TActionMap>> : ExecutableActionObject;
|
|
1107
|
-
export type ExecutableActionObject<TType extends string = string & {}> = BuiltInExecutableActionObject | CustomExecutableActionObject<TType>;
|
|
1126
|
+
export type ExecutableActionObject<TType extends string = string & {}> = BuiltInExecutableActionObject | EmitExecutableActionObject | CustomExecutableActionObject<TType>;
|
|
1108
1127
|
export interface ToExecutableAction<T extends ParameterizedObject> extends CustomExecutableActionObject<T['type']> {
|
|
1109
1128
|
type: T['type'];
|
|
1110
1129
|
params: T['params'];
|
|
1111
|
-
|
|
1130
|
+
action: undefined;
|
|
1112
1131
|
}
|
|
1113
1132
|
export type ActionExecutor = (actionToExecute: ExecutableActionObject) => void;
|
|
1114
1133
|
/** Mappers for subscribeTo - maps lifecycle events to machine events */
|