xstate 6.0.0-beta.0 → 6.0.0-beta.2
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/bin/xstate.js +10 -4
- package/dist/{createActor-551369be.development.esm.js → createActor-0250284a.development.esm.js} +244 -41
- package/dist/{createActor-cbe3abac.esm.js → createActor-20a97166.esm.js} +243 -40
- package/dist/{createActor-a49ae0ce.development.cjs.js → createActor-c029d29f.development.cjs.js} +245 -40
- package/dist/{createActor-25900f76.cjs.js → createActor-c91c9ffe.cjs.js} +244 -39
- package/dist/declarations/src/createActor.d.ts +3 -1
- package/dist/declarations/src/createMachine.d.ts +6 -3
- package/dist/declarations/src/durable/index.d.ts +43 -8
- package/dist/declarations/src/effectDescriptor.d.ts +2 -2
- package/dist/declarations/src/machineVersion.types.d.ts +2 -2
- package/dist/declarations/src/setup.d.ts +5 -5
- package/dist/declarations/src/systemTransition.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +11 -3
- package/dist/declarations/src/types.v6.d.ts +37 -2
- package/dist/{effectDescriptor-f73da4ec.development.cjs.js → effectDescriptor-3fff5c51.development.cjs.js} +5 -5
- package/dist/{effectDescriptor-2fa27c54.cjs.js → effectDescriptor-47f73e7e.cjs.js} +5 -5
- package/dist/{effectDescriptor-321a8ce9.development.esm.js → effectDescriptor-5ac7dccb.development.esm.js} +5 -5
- package/dist/{effectDescriptor-d8b0f749.esm.js → effectDescriptor-e93df910.esm.js} +5 -5
- package/dist/{machineSchemas-88d01821.cjs.js → legacySnapshot-8d595687.cjs.js} +117 -1
- package/dist/{machineSchemas-45c21bc2.esm.js → legacySnapshot-9e06feb4.esm.js} +116 -2
- package/dist/{machineSchemas-b5736804.development.esm.js → legacySnapshot-ae6594a7.development.esm.js} +117 -3
- package/dist/{machineSchemas-6d96bef4.development.cjs.js → legacySnapshot-ebf0b2b8.development.cjs.js} +118 -2
- package/dist/xstate-actors.cjs.js +1 -1
- package/dist/xstate-actors.development.cjs.js +1 -1
- package/dist/xstate-actors.development.esm.js +2 -2
- package/dist/xstate-actors.esm.js +2 -2
- package/dist/xstate-actors.umd.min.js +1 -1
- package/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/xstate-durable.cjs.js +120 -10
- package/dist/xstate-durable.development.cjs.js +120 -10
- package/dist/xstate-durable.development.esm.js +120 -10
- package/dist/xstate-durable.esm.js +120 -10
- package/dist/xstate-durable.umd.min.js +1 -1
- package/dist/xstate-durable.umd.min.js.map +1 -1
- package/dist/xstate-fsm.cjs.js +4 -4
- package/dist/xstate-fsm.development.cjs.js +4 -4
- package/dist/xstate-fsm.development.esm.js +4 -4
- package/dist/xstate-fsm.esm.js +4 -4
- package/dist/xstate-fsm.umd.min.js +1 -1
- package/dist/xstate-fsm.umd.min.js.map +1 -1
- package/dist/xstate-graph.cjs.js +1 -1
- package/dist/xstate-graph.development.cjs.js +1 -1
- 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-persist.cjs.js +23 -12
- package/dist/xstate-persist.development.cjs.js +23 -12
- package/dist/xstate-persist.development.esm.js +17 -6
- package/dist/xstate-persist.esm.js +17 -6
- package/dist/xstate-persist.umd.min.js +1 -1
- package/dist/xstate-persist.umd.min.js.map +1 -1
- package/dist/xstate-validation.cjs.js +1 -1
- package/dist/xstate-validation.development.cjs.js +1 -1
- package/dist/xstate-validation.development.esm.js +1 -1
- package/dist/xstate-validation.esm.js +1 -1
- package/dist/xstate.cjs.js +63 -51
- package/dist/xstate.development.cjs.js +63 -51
- package/dist/xstate.development.esm.js +53 -41
- package/dist/xstate.esm.js +53 -41
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/docs/agents.md +9 -0
- package/docs/api-stability.json +273 -249
- package/docs/backend-workflows.md +3 -3
- package/docs/durable-execution.md +72 -48
- package/docs/errors.md +2 -2
- package/docs/examples.md +34 -34
- package/docs/fsm.md +2 -1
- package/docs/guards.md +1 -1
- package/docs/index.md +1 -1
- package/docs/invoke.md +34 -2
- package/docs/persistence.md +16 -10
- package/docs/serialization.md +1 -1
- package/docs/setup-and-provide.md +3 -3
- package/docs/spawn.md +1 -1
- package/docs/system-transitions.md +6 -6
- package/docs/tutorial.md +5 -5
- package/docs/typescript.md +9 -0
- package/docs/xstate-v5-to-v6.md +176 -19
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { EventObject, ExecutableEffect, SerializedActorRef } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* A serializable view of an executable effect. Actor references are replaced
|
|
4
|
-
* by `{
|
|
4
|
+
* by `{ "@actor": address, incarnation? }` and actor sources by their registered
|
|
5
5
|
* source keys, so a durable host can journal, deduplicate, and route effects without
|
|
6
6
|
* holding live actor references. Payload fields (`event`, `input`, `params`,
|
|
7
7
|
* `output`, `error`) pass through by reference and are only as serializable
|
|
@@ -87,7 +87,7 @@ export type ExecutableEffectDescriptor = {
|
|
|
87
87
|
/**
|
|
88
88
|
* Returns the serializable descriptor for an executable effect: the same
|
|
89
89
|
* discriminants (`kind`, `type`) with actor references replaced by
|
|
90
|
-
* `{
|
|
90
|
+
* `{ "@actor": address, incarnation? }` and actor sources by source keys. Payload fields pass through by
|
|
91
91
|
* reference.
|
|
92
92
|
*
|
|
93
93
|
* @experimental
|
|
@@ -15,8 +15,8 @@ export type PersistedMachineSnapshot = {
|
|
|
15
15
|
historyValue: Record<string, unknown>;
|
|
16
16
|
timers: readonly unknown[];
|
|
17
17
|
_nextActorId?: number;
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
nextActorIds?: Record<string, number>;
|
|
19
|
+
nextTimerId?: number;
|
|
20
20
|
stateInputs?: Record<string, Record<string, unknown>>;
|
|
21
21
|
machine?: {
|
|
22
22
|
id: string;
|
|
@@ -3,13 +3,13 @@ import type { SetupSchemas, SetupStateSchema, SetupStateType } from "./base.type
|
|
|
3
3
|
import type { ActorLogicValidator } from "./validation.types.js";
|
|
4
4
|
import { StateMachine, type CompatibleProvidedActorSource, type ProvidedActionContracts } from "./StateMachine.js";
|
|
5
5
|
import { type Actor, type RequiredActorOptionsFor, type RequiredActorOptionsKeys } from "./createActor.js";
|
|
6
|
-
import { AnyActorRef, AnyStateMachine, AnyActorLogic, ActorRefFrom, ActorSelf, AnyStateNode, EventObject, AnyEventObject, EventDescriptor, ReservedMachineEvent, ReservedEventFromDescriptor, ExtractEvent, MachineContext, ProvidedActor, RoutableStateId, StateSchema, StateValue, StateValueFromStateSchema, ToChildren, MetaObject, EnqueueObject, DoneActorEvent, DoneStateEvent, ErrorFrom, ErrorActorEvent, SystemRegistry, RegistryKeyForLogic, ActorOptions, Observer, Subscription, OutputArg, SnapshotEvent, AfterEvent, TimeoutEvent, ErrorEvent, CallbackActors, InputFrom, OutputFrom, SnapshotFrom, ActorTimeoutEvent } from "./types.js";
|
|
6
|
+
import { AnyActorRef, AnyStateMachine, AnyActorLogic, ActorRefFrom, ActorSelf, AnyStateNode, EventObject, AnyEventObject, EventDescriptor, ReservedMachineEvent, ReservedEventFromDescriptor, ExtractEvent, MachineContext, ProvidedActor, RoutableStateId, StateSchema, StateValue, StateValueFromStateSchema, ToChildren, MetaObject, EnqueueObject, DoneActorEvent, DoneStateEvent, ErrorFrom, ErrorActorEvent, SystemRegistry, RegistryKeyForLogic, ActorOptions, Observer, Subscription, OutputArg, SnapshotEvent, AfterEvent, TimeoutEvent, ErrorEvent, CallbackActors, InputFrom, OutputFrom, SnapshotFrom, ActorTimeoutEvent, TransitionTargetString } from "./types.js";
|
|
7
7
|
import type { Cast, Compute, SingleOrArray, NonReducibleUnknown } from "./typeUtils.js";
|
|
8
8
|
import { AnyActorSystem } from "./system.js";
|
|
9
9
|
import { InspectionEvent } from "./inspection.js";
|
|
10
10
|
import type { MachineSnapshot } from "./State.js";
|
|
11
11
|
import { type AsyncActorLogic, type AsyncSnapshot, type AsyncLogicFunction } from "./actors/promise.js";
|
|
12
|
-
import { ActionSchemas, DelayMapFromNames, DelaySourceMap, GuardSourceMap, GuardSchemas, InferChildren, InferActions, InferGuards, Sources, InferMachineInput, InferOutput, InferEvents, InferInternalEvents, Next_MachineConfig, Next_InvokeConfig, Next_InvokeConfigBase, InvokeInputArgs, Next_StateNodeConfig, Next_TransitionConfigOrTarget, type createdInvokeConfig, FinalStateConfigOutput, OutputFromConfig, ChildCompletionEvents, DelayDurationKey, ValidateDelayNames, ValidateEventDescriptors, ValidateHistoryDefaults, ValidateInvokeInputs, ValidateVersionedMachineId, ValidateStateTargets, WithDefault } from "./types.v6.js";
|
|
12
|
+
import { ActionSchemas, DelayMapFromNames, DelaySourceMap, GuardSourceMap, GuardSchemas, InferChildren, InferredInvokeChildren, InferActions, InferGuards, Sources, InferMachineInput, InferOutput, InferEvents, InferInternalEvents, Next_MachineConfig, Next_InvokeConfig, Next_InvokeConfigBase, InvokeInputArgs, Next_StateNodeConfig, Next_TransitionConfigOrTarget, type createdInvokeConfig, FinalStateConfigOutput, OutputFromConfig, ChildCompletionEvents, DelayDurationKey, ValidateDelayNames, ValidateEventDescriptors, ValidateHistoryDefaults, ValidateInvokeInputs, ValidateVersionedMachineId, ValidateStateTargets, WithDefault } from "./types.v6.js";
|
|
13
13
|
/** @public */
|
|
14
14
|
export type SetupConfig<TSchemas extends SetupSchemas, TStates extends Record<string, SetupStateSchema>, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TValidator extends ActorLogicValidator | undefined = ActorLogicValidator | undefined> = {
|
|
15
15
|
validator?: TValidator;
|
|
@@ -211,7 +211,7 @@ type UncheckedSetupStateSchemas = Record<string, UncheckedSetupStateSchema>;
|
|
|
211
211
|
type SetupStateKey<TStateSchemas extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStateSchemas> ? string : [SetupStateKeys<TStateSchemas>] extends [never] ? string : SetupStateKeys<TStateSchemas>;
|
|
212
212
|
type StrictSetupStatePaths<TStateSchemas extends Record<string, SetupStateSchema>> = [SetupStateKeys<TStateSchemas>] extends [never] ? never : StatePaths<TStateSchemas>;
|
|
213
213
|
type SetupRelativeStateTarget<TStateSchemas extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStateSchemas> ? `.${string}` : [SetupStateKeys<TStateSchemas>] extends [never] ? '.' : '.' | `.${StatePaths<TStateSchemas> & string}`;
|
|
214
|
-
type SetupStateTarget<TStateSchemas extends Record<string, SetupStateSchema>> = TStateSchemas extends StrictSetupStateTargetsMarker ? StrictSetupStatePaths<TStateSchemas> | SetupRelativeStateTarget<RelativeSetupStateSchemas<TStateSchemas>> | `#${string}` : string extends SetupStateKeys<TStateSchemas> ?
|
|
214
|
+
type SetupStateTarget<TStateSchemas extends Record<string, SetupStateSchema>> = TStateSchemas extends StrictSetupStateTargetsMarker ? StrictSetupStatePaths<TStateSchemas> | SetupRelativeStateTarget<RelativeSetupStateSchemas<TStateSchemas>> | `#${string}` : string extends SetupStateKeys<TStateSchemas> ? TransitionTargetString : [SetupStateKeys<TStateSchemas>] extends [never] ? TransitionTargetString : StatePaths<TStateSchemas> | `.${string}` | `#${string}`;
|
|
215
215
|
type KnownSetupStateTarget<TStateSchemas extends Record<string, SetupStateSchema>> = string extends StatePaths<TStateSchemas> ? string extends StatePaths<RelativeSetupStateSchemas<TStateSchemas>> ? never : SetupRelativeStateTarget<RelativeSetupStateSchemas<TStateSchemas>> | RootSetupStateIdTarget<RootSetupStateSchemas<TStateSchemas>> : (StrictSetupStatePaths<TStateSchemas> & string) | SetupRelativeStateTarget<RelativeSetupStateSchemas<TStateSchemas>> | RootSetupStateIdTarget<RootSetupStateSchemas<TStateSchemas>>;
|
|
216
216
|
declare const strictSetupStateTargets: unique symbol;
|
|
217
217
|
declare const relativeSetupStateSchemas: unique symbol;
|
|
@@ -625,7 +625,7 @@ type SetupStateNodeTargetArrayInputConstraint<TConfig, TSiblingStateSchemas exte
|
|
|
625
625
|
};
|
|
626
626
|
} : unknown);
|
|
627
627
|
type ValidateSetupTargetArrayInputs<TConfig, TRootStateSchemas extends Record<string, SetupStateSchema>> = SetupStateNodeTargetArrayInputConstraint<TConfig, TRootStateSchemas, SetupStateSchema, TRootStateSchemas>;
|
|
628
|
-
type ValidateSetupStateContracts<TConfig, TStateSchemas extends Record<string, SetupStateSchema>> = HasExplicitSetupStateContracts<TStateSchemas> extends true ? ValidateSetupHistoryInputs<TConfig, TStateSchemas> & ValidateHistoryDefaults<MergeSetupConfig<TConfig, TStateSchemas>> &
|
|
628
|
+
type ValidateSetupStateContracts<TConfig, TStateSchemas extends Record<string, SetupStateSchema>> = ValidateStateTargets<MergeSetupConfig<TConfig, TStateSchemas>> & (HasExplicitSetupStateContracts<TStateSchemas> extends true ? ValidateSetupHistoryInputs<TConfig, TStateSchemas> & ValidateHistoryDefaults<MergeSetupConfig<TConfig, TStateSchemas>> & NoInfer<ValidateSetupTargetArrayInputs<TConfig, TStateSchemas>> : unknown);
|
|
629
629
|
type SetupInitialTransitionConfig<TStateSchema extends SetupStateSchema, TTarget extends string, TConfig, TContext extends MachineContext, TEvent extends EventObject> = Extract<SetupConfigInitial<TConfig>, {
|
|
630
630
|
target: TTarget;
|
|
631
631
|
}> extends infer TInitial ? [TInitial] extends [never] ? {
|
|
@@ -1220,7 +1220,7 @@ export interface SetupReturn<TStates extends Record<string, SetupStateSchema> =
|
|
|
1220
1220
|
] extends [never] ? never : {
|
|
1221
1221
|
type: 'xstate.route';
|
|
1222
1222
|
to: RoutableStateId<SetupMachineStateSchema<TConfig, TStates>>;
|
|
1223
|
-
}), Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor
|
|
1223
|
+
}), Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor> & InferredInvokeChildren<TConfig, MergeSourceMaps<TSetupActorMap, TActorMap>>, Record<string, AnyActorRef | undefined>>, StateValueFromStateSchema<SetupMachineStateSchema<TConfig, TStates>>, TTag & string, SetupInput<TSchemas, TInputSchema>, SetupOrConfigOutput<TSchemas, TOutputSchema, TConfig, TStates>, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, PublicStateSchema<SetupMachineStateSchema<TConfig, TStates>> & {
|
|
1224
1224
|
schemas: MergedSetupSchemas<SetupConfigSchemas<TConfig>, TSchemas>;
|
|
1225
1225
|
}, MergeSourceMaps<SetupActions<TSchemas, TSetupActionMap>, MergeSourceMaps<InferActions<TActionSchemaMap>, TActionMap>>, MergeSourceMaps<TSetupActorMap, TActorMap>, MergeSourceMaps<SetupGuards<TSchemas, TSetupGuardMap>, MergeSourceMaps<InferGuards<TGuardSchemaMap>, TGuardMap>>, DelayMapFromNames<TSetupDelays | TDelays, MergeSourceMaps<TSetupDelayMap, TDelayMap>>, SetupInternalEvents<TSchemas, TInternalEventSchemaMap>, SetupTransitionMeta<TSchemas, TMetaSchema, TTransitionMetaSchema>> & MachineIdentity<TConfig>;
|
|
1226
1226
|
/**
|
|
@@ -11,7 +11,7 @@ export interface SystemLogic<TLogic extends AnyActorLogic = AnyActorLogic> {
|
|
|
11
11
|
}
|
|
12
12
|
/** An actor identity, without a live actor or runtime. @experimental */
|
|
13
13
|
export interface SystemActorReference {
|
|
14
|
-
readonly
|
|
14
|
+
readonly '@actor': string;
|
|
15
15
|
readonly incarnation: string;
|
|
16
16
|
}
|
|
17
17
|
/** Actor state and topology in a system snapshot. @experimental */
|
|
@@ -40,7 +40,9 @@ export type UnifiedArg<TContext extends MachineContext, TExpressionEvent extends
|
|
|
40
40
|
} & OutputArg<TExpressionEvent>;
|
|
41
41
|
type DoneEventType = 'xstate.done.actor' | 'xstate.done.state';
|
|
42
42
|
/** @public */
|
|
43
|
-
export type OutputArg<TEvent extends EventObject> = TEvent extends {
|
|
43
|
+
export type OutputArg<TEvent extends EventObject> = [TEvent] extends [never] ? {
|
|
44
|
+
output: undefined;
|
|
45
|
+
} : TEvent extends {
|
|
44
46
|
type: DoneEventType;
|
|
45
47
|
output: infer TOutput;
|
|
46
48
|
} ? {
|
|
@@ -178,11 +180,17 @@ export type StateNodesConfig<TContext extends MachineContext, TEvent extends Eve
|
|
|
178
180
|
/** @public */
|
|
179
181
|
export type TransitionConfigTarget = string | undefined;
|
|
180
182
|
export type TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays']> = SingleOrArray<TransitionConfigTarget | TransitionConfig<TContext, TExpressionEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap> | TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>>;
|
|
183
|
+
/**
|
|
184
|
+
* @public A contextual type containing a literal ('.') keeps a returned
|
|
185
|
+
* literal target from widening to `string`, so `ValidateStateTargets` can
|
|
186
|
+
* check it; `string & {}` still accepts dynamic targets.
|
|
187
|
+
*/
|
|
188
|
+
export type TransitionTargetString = '.' | (string & {});
|
|
181
189
|
/** @public */
|
|
182
190
|
export type TransitionConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TMeta extends MetaObject, TInput = undefined, _TCtx extends MachineContext = [TContext] extends [never] ? any : TContext, TChildren extends Record<string, AnyActorRef | undefined> = {}> = (args: TransitionFunctionArgs<_TCtx, TCurrentEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, TChildren> & {
|
|
183
191
|
input: TInput;
|
|
184
192
|
}, enq: EnqueueObject<TEvent, TEmitted, SystemRegistry, Compute<CallbackActors<TActorMap>>, TChildren>) => {
|
|
185
|
-
target?:
|
|
193
|
+
target?: TransitionTargetString | TransitionTargetString[];
|
|
186
194
|
context?: TransitionContextPatch<_TCtx>;
|
|
187
195
|
reenter?: boolean;
|
|
188
196
|
meta?: TMeta;
|
|
@@ -935,7 +943,7 @@ export interface ActorLike<TCurrent, TEvent extends EventObject> extends Subscri
|
|
|
935
943
|
*/
|
|
936
944
|
export interface SerializedActorRef {
|
|
937
945
|
/** The actor's logical address. */
|
|
938
|
-
|
|
946
|
+
'@actor': string;
|
|
939
947
|
/** The incarnation token, when the serializer knows it. */
|
|
940
948
|
incarnation?: string;
|
|
941
949
|
}
|
|
@@ -4,7 +4,7 @@ import { SetupStateSchemas, StandardSchemaV1 } from "./schema.types.js";
|
|
|
4
4
|
import type { ActionSchemas, GuardSchemas, InferEvents, InferInternalEvents } from "./base.types.js";
|
|
5
5
|
export type { ActionSchemas, GuardSchemas, InferEvents, InferInternalEvents };
|
|
6
6
|
import { MachineSnapshot } from "./State.js";
|
|
7
|
-
import { Action, ActorTimeoutEvent, AfterEvent, ActorLogic, ActorRef, ActorRefFrom, ActorSelf, AnyActorLogic, AnyActorRef, DoneActorEvent, ErrorFrom, ErrorActorEvent, EnqueueObject, EventDescriptor, ReservedEventDescriptor, ReservedMachineEvent, ReservedEventFromDescriptor, ErrorEvent, EventObject, EventPayloadPattern, ExtractEvent, InitialContext, InputFrom, MetaObject, OutputFrom, SnapshotEvent, StateValue, TransitionContextMapper, TransitionContextPatch, TransitionConfigFunction, Values, AnyStateNode, SystemRegistry, TimeoutEvent, RequiredLogicInput } from "./types.js";
|
|
7
|
+
import { Action, ActorTimeoutEvent, AfterEvent, ActorLogic, ActorRef, ActorRefFrom, ActorFromLogic, ActorSelf, AnyActorLogic, AnyActorRef, DoneActorEvent, ErrorFrom, ErrorActorEvent, EnqueueObject, EventDescriptor, ReservedEventDescriptor, ReservedMachineEvent, ReservedEventFromDescriptor, ErrorEvent, EventObject, EventPayloadPattern, ExtractEvent, InitialContext, InputFrom, MetaObject, OutputFrom, SnapshotEvent, StateValue, TransitionContextMapper, TransitionContextPatch, TransitionConfigFunction, Values, AnyStateNode, SystemRegistry, TimeoutEvent, RequiredLogicInput } from "./types.js";
|
|
8
8
|
import type { Compute, DoNotInfer, IsNever, NonReducibleUnknown, SingleOrArray } from "./typeUtils.js";
|
|
9
9
|
import { MachineContext, Mapper } from "./types.js";
|
|
10
10
|
import type { LowInfer } from "./typeUtils.js";
|
|
@@ -58,6 +58,41 @@ export type SchemaOrConfigOutput<TOutputSchema extends StandardSchemaV1, TConfig
|
|
|
58
58
|
export type InferChildren<TChildrenSchemaMap extends Record<string, StandardSchemaV1>> = string extends keyof TChildrenSchemaMap ? {} : {
|
|
59
59
|
[K in keyof TChildrenSchemaMap & string]?: StandardSchemaV1.InferOutput<TChildrenSchemaMap[K]> extends AnyActorRef ? NormalizeActorRef<StandardSchemaV1.InferOutput<TChildrenSchemaMap[K]>> : never;
|
|
60
60
|
};
|
|
61
|
+
type InvokeSourceLogic<TSrc, TActors extends Sources['actors']> = [0] extends [
|
|
62
|
+
1 & TSrc
|
|
63
|
+
] ? never : TSrc extends keyof TActors ? TActors[TSrc] : TSrc extends AnyActorLogic ? TSrc : TSrc extends (...args: any[]) => infer TResult ? InvokeSourceLogic<TResult, TActors> : never;
|
|
64
|
+
type InvokedChild<TInvoke, TActors extends Sources['actors']> = TInvoke extends readonly (infer TItem)[] ? InvokedChild<TItem, TActors> : TInvoke extends {
|
|
65
|
+
readonly [createdInvokeConfig]: infer TConfig;
|
|
66
|
+
src: infer TLogic;
|
|
67
|
+
} ? TConfig extends {
|
|
68
|
+
id: infer TId extends string;
|
|
69
|
+
} ? string extends TId ? never : TLogic extends AnyActorLogic ? {
|
|
70
|
+
id: TId;
|
|
71
|
+
ref: ActorFromLogic<TLogic>;
|
|
72
|
+
} : never : never : TInvoke extends {
|
|
73
|
+
id: infer TId extends string;
|
|
74
|
+
src: infer TSrc;
|
|
75
|
+
} ? string extends TId ? never : InvokeSourceLogic<TSrc, TActors> extends infer TLogic extends AnyActorLogic ? {
|
|
76
|
+
id: TId;
|
|
77
|
+
ref: ActorFromLogic<TLogic>;
|
|
78
|
+
} : never : never;
|
|
79
|
+
type InvokedChildren<TConfig, TActors extends Sources['actors']> = (TConfig extends {
|
|
80
|
+
invoke: infer TInvoke;
|
|
81
|
+
} ? InvokedChild<TInvoke, TActors> : never) | (TConfig extends {
|
|
82
|
+
states: infer TStates;
|
|
83
|
+
} ? {
|
|
84
|
+
[K in keyof TStates]: InvokedChildren<TStates[K], TActors>;
|
|
85
|
+
}[keyof TStates] : never);
|
|
86
|
+
/** Type-level plumbing for children inferred from literal invoke IDs. */
|
|
87
|
+
export type InferredInvokeChildren<TConfig, TActors extends Sources['actors'], TChild extends {
|
|
88
|
+
id: string;
|
|
89
|
+
ref: AnyActorRef;
|
|
90
|
+
} = InvokedChildren<TConfig, TActors>> = [TChild] extends [never] ? {} : {
|
|
91
|
+
[K in TChild['id']]?: TChild extends {
|
|
92
|
+
id: string;
|
|
93
|
+
ref: AnyActorRef;
|
|
94
|
+
} ? K extends TChild['id'] ? TChild['ref'] : never : never;
|
|
95
|
+
};
|
|
61
96
|
export type InferActions<TActionSchemaMap extends ActionSchemas> = string extends keyof TActionSchemaMap ? {} : {
|
|
62
97
|
[K in keyof TActionSchemaMap & string]: (params: StandardSchemaV1.InferOutput<TActionSchemaMap[K]['params']>) => void | {
|
|
63
98
|
context?: any;
|
|
@@ -224,7 +259,7 @@ type LogicForChildRef<TActorRef> = NonNullable<TActorRef> extends ActorRef<infer
|
|
|
224
259
|
* With no registered sources (empty or permissive maps) there is no competing
|
|
225
260
|
* branch, so the full transition config is allowed.
|
|
226
261
|
*/
|
|
227
|
-
type InlineInvokeOnDone<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TMeta extends MetaObject, TChildren extends Record<string, AnyActorRef | undefined>> = [keyof TActorMap & string] extends [never] ? Next_TransitionConfigOrTarget<TContext, DoneActorEvent<
|
|
262
|
+
type InlineInvokeOnDone<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TMeta extends MetaObject, TChildren extends Record<string, AnyActorRef | undefined>> = [keyof TActorMap & string] extends [never] ? Next_TransitionConfigOrTarget<TContext, DoneActorEvent<unknown>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, undefined, TChildren> : string extends keyof TActorMap ? Next_TransitionConfigOrTarget<TContext, DoneActorEvent<OutputFrom<TActorMap[keyof TActorMap & string]>>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, undefined, TChildren> : undefined | {
|
|
228
263
|
matches?: EventPayloadPattern<DoneActorEvent>;
|
|
229
264
|
target?: string | string[];
|
|
230
265
|
context?: TransitionContextPatch<TContext>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var createActor = require('./createActor-
|
|
3
|
+
var createActor = require('./createActor-c029d29f.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
function attachMicrostepActorRefs(microsteps, actorScope, inputSnapshot) {
|
|
6
6
|
const result = microsteps.map(([snapshot, actions, transitions]) => [snapshot, actions, transitions ?? []]);
|
|
@@ -202,7 +202,7 @@ function getNextTransitions(state) {
|
|
|
202
202
|
|
|
203
203
|
/**
|
|
204
204
|
* A serializable view of an executable effect. Actor references are replaced
|
|
205
|
-
* by `{
|
|
205
|
+
* by `{ "@actor": address, incarnation? }` and actor sources by their registered
|
|
206
206
|
* source keys, so a durable host can journal, deduplicate, and route effects without
|
|
207
207
|
* holding live actor references. Payload fields (`event`, `input`, `params`,
|
|
208
208
|
* `output`, `error`) pass through by reference and are only as serializable
|
|
@@ -224,9 +224,9 @@ function toRef(actor) {
|
|
|
224
224
|
}
|
|
225
225
|
const incarnation = createActor.isRemoteActorRef(actor) ? actor.sessionId : undefined;
|
|
226
226
|
return incarnation === undefined ? {
|
|
227
|
-
|
|
227
|
+
'@actor': actor.address
|
|
228
228
|
} : {
|
|
229
|
-
|
|
229
|
+
'@actor': actor.address,
|
|
230
230
|
incarnation
|
|
231
231
|
};
|
|
232
232
|
}
|
|
@@ -234,7 +234,7 @@ function toRef(actor) {
|
|
|
234
234
|
/**
|
|
235
235
|
* Returns the serializable descriptor for an executable effect: the same
|
|
236
236
|
* discriminants (`kind`, `type`) with actor references replaced by
|
|
237
|
-
* `{
|
|
237
|
+
* `{ "@actor": address, incarnation? }` and actor sources by source keys. Payload fields pass through by
|
|
238
238
|
* reference.
|
|
239
239
|
*
|
|
240
240
|
* @experimental
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var createActor = require('./createActor-
|
|
3
|
+
var createActor = require('./createActor-c91c9ffe.cjs.js');
|
|
4
4
|
|
|
5
5
|
function attachMicrostepActorRefs(microsteps, actorScope, inputSnapshot) {
|
|
6
6
|
const result = microsteps.map(([snapshot, actions, transitions]) => [snapshot, actions, transitions ?? []]);
|
|
@@ -202,7 +202,7 @@ function getNextTransitions(state) {
|
|
|
202
202
|
|
|
203
203
|
/**
|
|
204
204
|
* A serializable view of an executable effect. Actor references are replaced
|
|
205
|
-
* by `{
|
|
205
|
+
* by `{ "@actor": address, incarnation? }` and actor sources by their registered
|
|
206
206
|
* source keys, so a durable host can journal, deduplicate, and route effects without
|
|
207
207
|
* holding live actor references. Payload fields (`event`, `input`, `params`,
|
|
208
208
|
* `output`, `error`) pass through by reference and are only as serializable
|
|
@@ -224,9 +224,9 @@ function toRef(actor) {
|
|
|
224
224
|
}
|
|
225
225
|
const incarnation = createActor.isRemoteActorRef(actor) ? actor.sessionId : undefined;
|
|
226
226
|
return incarnation === undefined ? {
|
|
227
|
-
|
|
227
|
+
'@actor': actor.address
|
|
228
228
|
} : {
|
|
229
|
-
|
|
229
|
+
'@actor': actor.address,
|
|
230
230
|
incarnation
|
|
231
231
|
};
|
|
232
232
|
}
|
|
@@ -234,7 +234,7 @@ function toRef(actor) {
|
|
|
234
234
|
/**
|
|
235
235
|
* Returns the serializable descriptor for an executable effect: the same
|
|
236
236
|
* discriminants (`kind`, `type`) with actor references replaced by
|
|
237
|
-
* `{
|
|
237
|
+
* `{ "@actor": address, incarnation? }` and actor sources by source keys. Payload fields pass through by
|
|
238
238
|
* reference.
|
|
239
239
|
*
|
|
240
240
|
* @experimental
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ah as createInertActorScope, ai as setInertActorScopeSnapshot, l as finalizeTransitionResult, ak as attachSnapshotActorRef, O as createInitEvent, aG as hasAmbientInspector, aj as beginSpawnAllocation, al as macrostep, az as createSpawnEffect, aA as initialMicrostep, i as isAtomicStateNode, aH as getProperAncestors, q as readTimerKey, k as getActorIdPrefix, o as isSerializedActorRef, aI as isRemoteActorRef } from './createActor-
|
|
1
|
+
import { ah as createInertActorScope, ai as setInertActorScopeSnapshot, l as finalizeTransitionResult, ak as attachSnapshotActorRef, O as createInitEvent, aG as hasAmbientInspector, aj as beginSpawnAllocation, al as macrostep, az as createSpawnEffect, aA as initialMicrostep, i as isAtomicStateNode, aH as getProperAncestors, q as readTimerKey, k as getActorIdPrefix, o as isSerializedActorRef, aI as isRemoteActorRef } from './createActor-0250284a.development.esm.js';
|
|
2
2
|
|
|
3
3
|
function attachMicrostepActorRefs(microsteps, actorScope, inputSnapshot) {
|
|
4
4
|
const result = microsteps.map(([snapshot, actions, transitions]) => [snapshot, actions, transitions ?? []]);
|
|
@@ -200,7 +200,7 @@ function getNextTransitions(state) {
|
|
|
200
200
|
|
|
201
201
|
/**
|
|
202
202
|
* A serializable view of an executable effect. Actor references are replaced
|
|
203
|
-
* by `{
|
|
203
|
+
* by `{ "@actor": address, incarnation? }` and actor sources by their registered
|
|
204
204
|
* source keys, so a durable host can journal, deduplicate, and route effects without
|
|
205
205
|
* holding live actor references. Payload fields (`event`, `input`, `params`,
|
|
206
206
|
* `output`, `error`) pass through by reference and are only as serializable
|
|
@@ -222,9 +222,9 @@ function toRef(actor) {
|
|
|
222
222
|
}
|
|
223
223
|
const incarnation = isRemoteActorRef(actor) ? actor.sessionId : undefined;
|
|
224
224
|
return incarnation === undefined ? {
|
|
225
|
-
|
|
225
|
+
'@actor': actor.address
|
|
226
226
|
} : {
|
|
227
|
-
|
|
227
|
+
'@actor': actor.address,
|
|
228
228
|
incarnation
|
|
229
229
|
};
|
|
230
230
|
}
|
|
@@ -232,7 +232,7 @@ function toRef(actor) {
|
|
|
232
232
|
/**
|
|
233
233
|
* Returns the serializable descriptor for an executable effect: the same
|
|
234
234
|
* discriminants (`kind`, `type`) with actor references replaced by
|
|
235
|
-
* `{
|
|
235
|
+
* `{ "@actor": address, incarnation? }` and actor sources by source keys. Payload fields pass through by
|
|
236
236
|
* reference.
|
|
237
237
|
*
|
|
238
238
|
* @experimental
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ai as createInertActorScope, aj as setInertActorScopeSnapshot, l as finalizeTransitionResult, al as attachSnapshotActorRef, Q as createInitEvent, aF as hasAmbientInspector, ak as beginSpawnAllocation, am as macrostep, az as createSpawnEffect, aA as initialMicrostep, i as isAtomicStateNode, aG as getProperAncestors, q as readTimerKey, k as getActorIdPrefix, o as isSerializedActorRef, aH as isRemoteActorRef } from './createActor-
|
|
1
|
+
import { ai as createInertActorScope, aj as setInertActorScopeSnapshot, l as finalizeTransitionResult, al as attachSnapshotActorRef, Q as createInitEvent, aF as hasAmbientInspector, ak as beginSpawnAllocation, am as macrostep, az as createSpawnEffect, aA as initialMicrostep, i as isAtomicStateNode, aG as getProperAncestors, q as readTimerKey, k as getActorIdPrefix, o as isSerializedActorRef, aH as isRemoteActorRef } from './createActor-20a97166.esm.js';
|
|
2
2
|
|
|
3
3
|
function attachMicrostepActorRefs(microsteps, actorScope, inputSnapshot) {
|
|
4
4
|
const result = microsteps.map(([snapshot, actions, transitions]) => [snapshot, actions, transitions ?? []]);
|
|
@@ -200,7 +200,7 @@ function getNextTransitions(state) {
|
|
|
200
200
|
|
|
201
201
|
/**
|
|
202
202
|
* A serializable view of an executable effect. Actor references are replaced
|
|
203
|
-
* by `{
|
|
203
|
+
* by `{ "@actor": address, incarnation? }` and actor sources by their registered
|
|
204
204
|
* source keys, so a durable host can journal, deduplicate, and route effects without
|
|
205
205
|
* holding live actor references. Payload fields (`event`, `input`, `params`,
|
|
206
206
|
* `output`, `error`) pass through by reference and are only as serializable
|
|
@@ -222,9 +222,9 @@ function toRef(actor) {
|
|
|
222
222
|
}
|
|
223
223
|
const incarnation = isRemoteActorRef(actor) ? actor.sessionId : undefined;
|
|
224
224
|
return incarnation === undefined ? {
|
|
225
|
-
|
|
225
|
+
'@actor': actor.address
|
|
226
226
|
} : {
|
|
227
|
-
|
|
227
|
+
'@actor': actor.address,
|
|
228
228
|
incarnation
|
|
229
229
|
};
|
|
230
230
|
}
|
|
@@ -232,7 +232,7 @@ function toRef(actor) {
|
|
|
232
232
|
/**
|
|
233
233
|
* Returns the serializable descriptor for an executable effect: the same
|
|
234
234
|
* discriminants (`kind`, `type`) with actor references replaced by
|
|
235
|
-
* `{
|
|
235
|
+
* `{ "@actor": address, incarnation? }` and actor sources by source keys. Payload fields pass through by
|
|
236
236
|
* reference.
|
|
237
237
|
*
|
|
238
238
|
* @experimental
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var createActor = require('./createActor-
|
|
3
|
+
var createActor = require('./createActor-c91c9ffe.cjs.js');
|
|
4
4
|
var validation = require('./validation-4561b43c.cjs.js');
|
|
5
5
|
|
|
6
6
|
var isDevelopment = false;
|
|
@@ -605,6 +605,15 @@ class StateMachine {
|
|
|
605
605
|
/** @internal */
|
|
606
606
|
this.idMap = new Map();
|
|
607
607
|
this.root = void 0;
|
|
608
|
+
/**
|
|
609
|
+
* Returns the machine itself, never a Proxy wrapped around it (a function
|
|
610
|
+
* member is not wrapped by reactive proxies, so it still closes over the raw
|
|
611
|
+
* instance). Persistence resolves state nodes through it, matching the
|
|
612
|
+
* bound `transition` / `getInitialSnapshot`.
|
|
613
|
+
*
|
|
614
|
+
* @internal
|
|
615
|
+
*/
|
|
616
|
+
this._raw = () => this;
|
|
608
617
|
/**
|
|
609
618
|
* The machine's `id`, or the empty string when the config declares none.
|
|
610
619
|
* The root state node has this id; a machine without one has no `#id` root.
|
|
@@ -1291,10 +1300,117 @@ function eventSchema(machine) {
|
|
|
1291
1300
|
}));
|
|
1292
1301
|
}
|
|
1293
1302
|
|
|
1303
|
+
// TODO(v7): remove this module and its callers. It reads snapshots written by
|
|
1304
|
+
// 6.0.0-beta.1, which used `$`- and `_`-prefixed field names that stores such
|
|
1305
|
+
// as Convex reject. Snapshots are written with the new names only.
|
|
1306
|
+
|
|
1307
|
+
// Legacy marker key -> [new key, other keys the marker object may have].
|
|
1308
|
+
const markers = {
|
|
1309
|
+
$actor: ['@actor', ['incarnation']],
|
|
1310
|
+
$error: ['@error', ['message']],
|
|
1311
|
+
$stateNode: ['@stateNode', []],
|
|
1312
|
+
$systemMapper: ['@systemMapper', []]
|
|
1313
|
+
};
|
|
1314
|
+
const fields = {
|
|
1315
|
+
_stateInputs: 'stateInputs',
|
|
1316
|
+
_nextTimerId: 'nextTimerId',
|
|
1317
|
+
_nextActorIds: 'nextActorIds'
|
|
1318
|
+
};
|
|
1319
|
+
|
|
1320
|
+
// Persisted snapshots are JSON; live objects (actors, state nodes, errors)
|
|
1321
|
+
// are left alone.
|
|
1322
|
+
function isPlain(value) {
|
|
1323
|
+
if (!value || typeof value !== 'object') return false;
|
|
1324
|
+
const proto = Object.getPrototypeOf(value);
|
|
1325
|
+
return proto === Object.prototype || proto === null || Array.isArray(value);
|
|
1326
|
+
}
|
|
1327
|
+
function renameMarkers(value, allowed) {
|
|
1328
|
+
if (!isPlain(value)) return value;
|
|
1329
|
+
if (Array.isArray(value)) {
|
|
1330
|
+
const items = value.map(item => renameMarkers(item, allowed));
|
|
1331
|
+
return items.some((item, i) => item !== value[i]) ? items : value;
|
|
1332
|
+
}
|
|
1333
|
+
const keys = Object.keys(value);
|
|
1334
|
+
const legacy = keys.find(key => allowed.includes(key));
|
|
1335
|
+
if (legacy && typeof value[legacy] === 'string' && keys.every(key => key === legacy || markers[legacy][1].includes(key))) {
|
|
1336
|
+
const {
|
|
1337
|
+
[legacy]: name,
|
|
1338
|
+
...rest
|
|
1339
|
+
} = value;
|
|
1340
|
+
return {
|
|
1341
|
+
[markers[legacy][0]]: name,
|
|
1342
|
+
...rest
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1345
|
+
let copy;
|
|
1346
|
+
for (const key of keys) {
|
|
1347
|
+
const item = renameMarkers(value[key], allowed);
|
|
1348
|
+
if (item !== value[key]) (copy ??= {
|
|
1349
|
+
...value
|
|
1350
|
+
})[key] = item;
|
|
1351
|
+
}
|
|
1352
|
+
return copy ?? value;
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
// beta.1 always wrote `_nextTimerId` on machine snapshots. Current snapshots
|
|
1356
|
+
// write `nextTimerId`, so marker-shaped data in them is left alone.
|
|
1357
|
+
function isLegacyEnvelope(envelope) {
|
|
1358
|
+
return isPlain(envelope) && '_nextTimerId' in envelope && !('nextTimerId' in envelope);
|
|
1359
|
+
}
|
|
1360
|
+
function renameFields(envelope) {
|
|
1361
|
+
// A live machine snapshot keeps its `_`-prefixed in-memory fields.
|
|
1362
|
+
if (!isPlain(envelope) || typeof envelope.matches === 'function') return envelope;
|
|
1363
|
+
let copy;
|
|
1364
|
+
for (const [legacy, name] of Object.entries(fields)) {
|
|
1365
|
+
if (legacy in envelope && !(name in envelope)) {
|
|
1366
|
+
const {
|
|
1367
|
+
[legacy]: value,
|
|
1368
|
+
...rest
|
|
1369
|
+
} = copy ?? envelope;
|
|
1370
|
+
copy = {
|
|
1371
|
+
...rest,
|
|
1372
|
+
[name]: value
|
|
1373
|
+
};
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
return copy ?? envelope;
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
/** Upgrades a persisted machine snapshot written by 6.0.0-beta.1. */
|
|
1380
|
+
function upgradeLegacyPersistedSnapshot(snapshot) {
|
|
1381
|
+
if (snapshot?.machine && typeof snapshot.matches === 'function') return snapshot;
|
|
1382
|
+
if (!isLegacyEnvelope(snapshot)) return snapshot;
|
|
1383
|
+
return renameMarkers(renameFields(snapshot), ['$actor']);
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
/** Upgrades a `systemTransition` snapshot written by 6.0.0-beta.1. */
|
|
1387
|
+
function upgradeLegacySystemSnapshot(snapshot) {
|
|
1388
|
+
const actors = Object.values(snapshot?.actors ?? {});
|
|
1389
|
+
if (!actors.some(actor => isLegacyEnvelope(actor?.snapshot))) return snapshot;
|
|
1390
|
+
const upgraded = renameMarkers(snapshot, Object.keys(markers));
|
|
1391
|
+
if (!upgraded?.actors) return upgraded;
|
|
1392
|
+
let renamed;
|
|
1393
|
+
for (const [address, actor] of Object.entries(upgraded.actors)) {
|
|
1394
|
+
const data = renameFields(actor?.snapshot);
|
|
1395
|
+
if (data !== actor?.snapshot) (renamed ??= {
|
|
1396
|
+
...upgraded.actors
|
|
1397
|
+
})[address] = {
|
|
1398
|
+
...actor,
|
|
1399
|
+
snapshot: data
|
|
1400
|
+
};
|
|
1401
|
+
}
|
|
1402
|
+
return renamed ? {
|
|
1403
|
+
...upgraded,
|
|
1404
|
+
actors: renamed
|
|
1405
|
+
} : upgraded;
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1294
1408
|
exports.InvalidSnapshotError = InvalidSnapshotError;
|
|
1295
1409
|
exports.StateMachine = StateMachine;
|
|
1296
1410
|
exports.StateNode = StateNode;
|
|
1297
1411
|
exports.eventSchema = eventSchema;
|
|
1298
1412
|
exports.historicalEventSchema = historicalEventSchema;
|
|
1299
1413
|
exports.snapshotSchema = snapshotSchema;
|
|
1414
|
+
exports.upgradeLegacyPersistedSnapshot = upgradeLegacyPersistedSnapshot;
|
|
1415
|
+
exports.upgradeLegacySystemSnapshot = upgradeLegacySystemSnapshot;
|
|
1300
1416
|
exports.validatePersistedSnapshot = validatePersistedSnapshot;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as resolveRegisteredActorSource, a0 as allocateChildId, a1 as assertChildIdFree, a2 as reserveChildId, a3 as hasUnescapedDot, x as xstateError, a4 as STATE_DELIMITER, a5 as mapValues, t as toArray, a6 as createInvokeId, a7 as getDelayedTransitions, a8 as getCandidates, a9 as evaluateCandidate, aa as formatTransition, ab as NULL_EVENT, ac as toTransitionConfigArray, ad as matchesActorSession, g as getAllStateNodes, b as getStateNodes, r as resolveInvokedActorLogic, ae as describeMachine, o as isSerializedActorRef, af as formatRouteTransitions, ag as resolveStateValue, e as createMachineSnapshot, ah as isInFinalState, ai as createInertActorScope, aj as setInertActorScopeSnapshot, R as createDeadLetterEffect, ak as beginSpawnAllocation, al as attachSnapshotActorRef, am as macrostep, an as isInertActorScope, ao as setSnapshotActorRef, ap as cloneMachineSnapshot, aq as transitionNode, ar as XSTATE_TIMER, m as matchesEventDescriptor, as as getTransitionResult, at as hasEffect, au as createErrorPlatformEvent, av as withActorSelf, aw as resolveActionsWithContext, ax as takeSpawnAllocationCounters, ay as mergeActorIdCounters, Q as createInitEvent, az as createSpawnEffect, aA as initialMicrostep, aB as createStartEffect, aC as isStateId, aD as getPersistedSnapshot, aE as detachedScopes, h as createActor } from './createActor-
|
|
1
|
+
import { $ as resolveRegisteredActorSource, a0 as allocateChildId, a1 as assertChildIdFree, a2 as reserveChildId, a3 as hasUnescapedDot, x as xstateError, a4 as STATE_DELIMITER, a5 as mapValues, t as toArray, a6 as createInvokeId, a7 as getDelayedTransitions, a8 as getCandidates, a9 as evaluateCandidate, aa as formatTransition, ab as NULL_EVENT, ac as toTransitionConfigArray, ad as matchesActorSession, g as getAllStateNodes, b as getStateNodes, r as resolveInvokedActorLogic, ae as describeMachine, o as isSerializedActorRef, af as formatRouteTransitions, ag as resolveStateValue, e as createMachineSnapshot, ah as isInFinalState, ai as createInertActorScope, aj as setInertActorScopeSnapshot, R as createDeadLetterEffect, ak as beginSpawnAllocation, al as attachSnapshotActorRef, am as macrostep, an as isInertActorScope, ao as setSnapshotActorRef, ap as cloneMachineSnapshot, aq as transitionNode, ar as XSTATE_TIMER, m as matchesEventDescriptor, as as getTransitionResult, at as hasEffect, au as createErrorPlatformEvent, av as withActorSelf, aw as resolveActionsWithContext, ax as takeSpawnAllocationCounters, ay as mergeActorIdCounters, Q as createInitEvent, az as createSpawnEffect, aA as initialMicrostep, aB as createStartEffect, aC as isStateId, aD as getPersistedSnapshot, aE as detachedScopes, h as createActor } from './createActor-20a97166.esm.js';
|
|
2
2
|
import { a as assertValid } from './validation-05f1d517.esm.js';
|
|
3
3
|
|
|
4
4
|
var isDevelopment = false;
|
|
@@ -603,6 +603,15 @@ class StateMachine {
|
|
|
603
603
|
/** @internal */
|
|
604
604
|
this.idMap = new Map();
|
|
605
605
|
this.root = void 0;
|
|
606
|
+
/**
|
|
607
|
+
* Returns the machine itself, never a Proxy wrapped around it (a function
|
|
608
|
+
* member is not wrapped by reactive proxies, so it still closes over the raw
|
|
609
|
+
* instance). Persistence resolves state nodes through it, matching the
|
|
610
|
+
* bound `transition` / `getInitialSnapshot`.
|
|
611
|
+
*
|
|
612
|
+
* @internal
|
|
613
|
+
*/
|
|
614
|
+
this._raw = () => this;
|
|
606
615
|
/**
|
|
607
616
|
* The machine's `id`, or the empty string when the config declares none.
|
|
608
617
|
* The root state node has this id; a machine without one has no `#id` root.
|
|
@@ -1289,4 +1298,109 @@ function eventSchema(machine) {
|
|
|
1289
1298
|
}));
|
|
1290
1299
|
}
|
|
1291
1300
|
|
|
1292
|
-
|
|
1301
|
+
// TODO(v7): remove this module and its callers. It reads snapshots written by
|
|
1302
|
+
// 6.0.0-beta.1, which used `$`- and `_`-prefixed field names that stores such
|
|
1303
|
+
// as Convex reject. Snapshots are written with the new names only.
|
|
1304
|
+
|
|
1305
|
+
// Legacy marker key -> [new key, other keys the marker object may have].
|
|
1306
|
+
const markers = {
|
|
1307
|
+
$actor: ['@actor', ['incarnation']],
|
|
1308
|
+
$error: ['@error', ['message']],
|
|
1309
|
+
$stateNode: ['@stateNode', []],
|
|
1310
|
+
$systemMapper: ['@systemMapper', []]
|
|
1311
|
+
};
|
|
1312
|
+
const fields = {
|
|
1313
|
+
_stateInputs: 'stateInputs',
|
|
1314
|
+
_nextTimerId: 'nextTimerId',
|
|
1315
|
+
_nextActorIds: 'nextActorIds'
|
|
1316
|
+
};
|
|
1317
|
+
|
|
1318
|
+
// Persisted snapshots are JSON; live objects (actors, state nodes, errors)
|
|
1319
|
+
// are left alone.
|
|
1320
|
+
function isPlain(value) {
|
|
1321
|
+
if (!value || typeof value !== 'object') return false;
|
|
1322
|
+
const proto = Object.getPrototypeOf(value);
|
|
1323
|
+
return proto === Object.prototype || proto === null || Array.isArray(value);
|
|
1324
|
+
}
|
|
1325
|
+
function renameMarkers(value, allowed) {
|
|
1326
|
+
if (!isPlain(value)) return value;
|
|
1327
|
+
if (Array.isArray(value)) {
|
|
1328
|
+
const items = value.map(item => renameMarkers(item, allowed));
|
|
1329
|
+
return items.some((item, i) => item !== value[i]) ? items : value;
|
|
1330
|
+
}
|
|
1331
|
+
const keys = Object.keys(value);
|
|
1332
|
+
const legacy = keys.find(key => allowed.includes(key));
|
|
1333
|
+
if (legacy && typeof value[legacy] === 'string' && keys.every(key => key === legacy || markers[legacy][1].includes(key))) {
|
|
1334
|
+
const {
|
|
1335
|
+
[legacy]: name,
|
|
1336
|
+
...rest
|
|
1337
|
+
} = value;
|
|
1338
|
+
return {
|
|
1339
|
+
[markers[legacy][0]]: name,
|
|
1340
|
+
...rest
|
|
1341
|
+
};
|
|
1342
|
+
}
|
|
1343
|
+
let copy;
|
|
1344
|
+
for (const key of keys) {
|
|
1345
|
+
const item = renameMarkers(value[key], allowed);
|
|
1346
|
+
if (item !== value[key]) (copy ??= {
|
|
1347
|
+
...value
|
|
1348
|
+
})[key] = item;
|
|
1349
|
+
}
|
|
1350
|
+
return copy ?? value;
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
// beta.1 always wrote `_nextTimerId` on machine snapshots. Current snapshots
|
|
1354
|
+
// write `nextTimerId`, so marker-shaped data in them is left alone.
|
|
1355
|
+
function isLegacyEnvelope(envelope) {
|
|
1356
|
+
return isPlain(envelope) && '_nextTimerId' in envelope && !('nextTimerId' in envelope);
|
|
1357
|
+
}
|
|
1358
|
+
function renameFields(envelope) {
|
|
1359
|
+
// A live machine snapshot keeps its `_`-prefixed in-memory fields.
|
|
1360
|
+
if (!isPlain(envelope) || typeof envelope.matches === 'function') return envelope;
|
|
1361
|
+
let copy;
|
|
1362
|
+
for (const [legacy, name] of Object.entries(fields)) {
|
|
1363
|
+
if (legacy in envelope && !(name in envelope)) {
|
|
1364
|
+
const {
|
|
1365
|
+
[legacy]: value,
|
|
1366
|
+
...rest
|
|
1367
|
+
} = copy ?? envelope;
|
|
1368
|
+
copy = {
|
|
1369
|
+
...rest,
|
|
1370
|
+
[name]: value
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
return copy ?? envelope;
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
/** Upgrades a persisted machine snapshot written by 6.0.0-beta.1. */
|
|
1378
|
+
function upgradeLegacyPersistedSnapshot(snapshot) {
|
|
1379
|
+
if (snapshot?.machine && typeof snapshot.matches === 'function') return snapshot;
|
|
1380
|
+
if (!isLegacyEnvelope(snapshot)) return snapshot;
|
|
1381
|
+
return renameMarkers(renameFields(snapshot), ['$actor']);
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
/** Upgrades a `systemTransition` snapshot written by 6.0.0-beta.1. */
|
|
1385
|
+
function upgradeLegacySystemSnapshot(snapshot) {
|
|
1386
|
+
const actors = Object.values(snapshot?.actors ?? {});
|
|
1387
|
+
if (!actors.some(actor => isLegacyEnvelope(actor?.snapshot))) return snapshot;
|
|
1388
|
+
const upgraded = renameMarkers(snapshot, Object.keys(markers));
|
|
1389
|
+
if (!upgraded?.actors) return upgraded;
|
|
1390
|
+
let renamed;
|
|
1391
|
+
for (const [address, actor] of Object.entries(upgraded.actors)) {
|
|
1392
|
+
const data = renameFields(actor?.snapshot);
|
|
1393
|
+
if (data !== actor?.snapshot) (renamed ??= {
|
|
1394
|
+
...upgraded.actors
|
|
1395
|
+
})[address] = {
|
|
1396
|
+
...actor,
|
|
1397
|
+
snapshot: data
|
|
1398
|
+
};
|
|
1399
|
+
}
|
|
1400
|
+
return renamed ? {
|
|
1401
|
+
...upgraded,
|
|
1402
|
+
actors: renamed
|
|
1403
|
+
} : upgraded;
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
export { InvalidSnapshotError as I, StateMachine as S, StateNode as a, upgradeLegacyPersistedSnapshot as b, eventSchema as e, historicalEventSchema as h, snapshotSchema as s, upgradeLegacySystemSnapshot as u, validatePersistedSnapshot as v };
|