xstate 6.0.0-alpha.8 → 6.0.0-beta.0
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/README.md +223 -78
- package/bin/agent.js +347 -0
- package/bin/xstate.js +52 -0
- package/dist/createActor-25900f76.cjs.js +7015 -0
- package/dist/createActor-551369be.development.esm.js +7175 -0
- package/dist/createActor-a49ae0ce.development.cjs.js +7289 -0
- package/dist/createActor-cbe3abac.esm.js +6902 -0
- package/dist/declarations/src/SimulatedClock.d.ts +2 -1
- package/dist/declarations/src/State.d.ts +66 -5
- package/dist/declarations/src/StateMachine.d.ts +107 -32
- package/dist/declarations/src/StateNode.d.ts +21 -16
- package/dist/declarations/src/actions.d.ts +11 -6
- package/dist/declarations/src/actors/callback.d.ts +11 -2
- package/dist/declarations/src/actors/index.d.ts +6 -5
- package/dist/declarations/src/actors/listener.d.ts +8 -3
- package/dist/declarations/src/actors/logic.d.ts +42 -52
- package/dist/declarations/src/actors/observable.d.ts +15 -2
- package/dist/declarations/src/actors/promise.d.ts +90 -22
- package/dist/declarations/src/actors/subscription.d.ts +9 -3
- package/dist/declarations/src/assert.d.ts +1 -0
- package/dist/declarations/src/base.types.d.ts +102 -0
- package/dist/declarations/src/createActor.d.ts +101 -27
- package/dist/declarations/src/createMachine.d.ts +38 -17
- package/dist/declarations/src/delay.d.ts +8 -0
- package/dist/declarations/src/durable/index.d.ts +231 -0
- package/dist/declarations/src/effectDescriptor.d.ts +95 -0
- package/dist/declarations/src/eventTypes.d.ts +9 -0
- package/dist/declarations/src/fsm/index.d.ts +2 -0
- package/dist/declarations/src/fsm.d.ts +169 -0
- package/dist/declarations/src/graph/adjacency.d.ts +6 -3
- package/dist/declarations/src/graph/graph.d.ts +6 -3
- package/dist/declarations/src/graph/index.d.ts +2 -3
- package/dist/declarations/src/graph/pathFromEvents.d.ts +5 -2
- package/dist/declarations/src/graph/shortestPaths.d.ts +5 -3
- package/dist/declarations/src/graph/simplePaths.d.ts +5 -3
- package/dist/declarations/src/graph/types.d.ts +113 -59
- package/dist/declarations/src/hotSwap.d.ts +18 -0
- package/dist/declarations/src/index.d.ts +28 -19
- package/dist/declarations/src/inspection.d.ts +24 -1
- package/dist/declarations/src/machineFromJSON.d.ts +171 -0
- package/dist/declarations/src/machineSchemas.d.ts +27 -0
- package/dist/declarations/src/machineVersion.types.d.ts +53 -0
- package/dist/declarations/src/machineVersions.d.ts +103 -0
- package/dist/declarations/src/mapState.d.ts +2 -0
- package/dist/declarations/src/persist/index.d.ts +36 -0
- package/dist/declarations/src/persistedSnapshotValidation.d.ts +18 -0
- package/dist/declarations/src/runtimeHelpers.d.ts +43 -0
- package/dist/declarations/src/schema.types.d.ts +31 -4
- package/dist/declarations/src/serialize.d.ts +39 -28
- package/dist/declarations/src/setup.d.ts +1086 -147
- package/dist/declarations/src/spawn.d.ts +6 -4
- package/dist/declarations/src/stateUtils.d.ts +57 -14
- package/dist/declarations/src/system.d.ts +178 -17
- package/dist/declarations/src/systemTransition.d.ts +108 -0
- package/dist/declarations/src/toPromise.d.ts +1 -0
- package/dist/declarations/src/transition.d.ts +48 -10
- package/dist/declarations/src/transitionActions.d.ts +22 -4
- package/dist/declarations/src/typeUtils.d.ts +51 -0
- package/dist/declarations/src/types.d.ts +835 -318
- package/dist/declarations/src/types.v6.d.ts +547 -104
- package/dist/declarations/src/utils.d.ts +38 -8
- package/dist/declarations/src/validation/index.d.ts +49 -0
- package/dist/declarations/src/validation.types.d.ts +29 -0
- package/dist/declarations/src/waitFor.d.ts +1 -0
- package/dist/effectDescriptor-2fa27c54.cjs.js +351 -0
- package/dist/effectDescriptor-321a8ce9.development.esm.js +343 -0
- package/dist/effectDescriptor-d8b0f749.esm.js +343 -0
- package/dist/effectDescriptor-f73da4ec.development.cjs.js +351 -0
- package/dist/machineSchemas-45c21bc2.esm.js +1292 -0
- package/dist/machineSchemas-6d96bef4.development.cjs.js +1379 -0
- package/dist/machineSchemas-88d01821.cjs.js +1300 -0
- package/dist/machineSchemas-b5736804.development.esm.js +1371 -0
- package/dist/schema.types-0ecd17b8.esm.js +71 -0
- package/dist/schema.types-15a68ddc.cjs.js +74 -0
- package/dist/schema.types-1c16f035.development.cjs.js +74 -0
- package/dist/schema.types-1cd4652e.development.esm.js +71 -0
- package/dist/validation-05f1d517.esm.js +8 -0
- package/dist/validation-4561b43c.cjs.js +10 -0
- package/dist/validation-e69470ad.development.esm.js +8 -0
- package/dist/validation-f2714a35.development.cjs.js +10 -0
- package/dist/xstate-actors.cjs.js +1068 -12
- package/dist/xstate-actors.cjs.mjs +2 -4
- package/dist/xstate-actors.development.cjs.js +1068 -12
- package/dist/xstate-actors.development.cjs.mjs +2 -4
- package/dist/xstate-actors.development.esm.js +1064 -1
- package/dist/xstate-actors.esm.js +1064 -1
- package/dist/xstate-actors.umd.min.js +1 -1
- package/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/xstate-durable.cjs.d.mts +2 -0
- package/dist/xstate-durable.cjs.d.ts +2 -0
- package/dist/xstate-durable.cjs.js +513 -0
- package/dist/xstate-durable.cjs.mjs +5 -0
- package/dist/xstate-durable.development.cjs.js +513 -0
- package/dist/xstate-durable.development.cjs.mjs +5 -0
- package/dist/xstate-durable.development.esm.js +507 -0
- package/dist/xstate-durable.esm.js +507 -0
- package/dist/xstate-durable.umd.min.js +2 -0
- package/dist/xstate-durable.umd.min.js.map +1 -0
- package/dist/xstate-fsm.cjs.d.mts +2 -0
- package/dist/xstate-fsm.cjs.d.ts +2 -0
- package/dist/xstate-fsm.cjs.js +111 -0
- package/dist/xstate-fsm.cjs.mjs +5 -0
- package/dist/xstate-fsm.development.cjs.js +111 -0
- package/dist/xstate-fsm.development.cjs.mjs +5 -0
- package/dist/xstate-fsm.development.esm.js +105 -0
- package/dist/xstate-fsm.esm.js +105 -0
- package/dist/xstate-fsm.umd.min.js +2 -0
- package/dist/xstate-fsm.umd.min.js.map +1 -0
- package/dist/xstate-graph.cjs.js +173 -457
- package/dist/xstate-graph.cjs.mjs +2 -5
- package/dist/xstate-graph.development.cjs.js +173 -457
- package/dist/xstate-graph.development.cjs.mjs +2 -5
- package/dist/xstate-graph.development.esm.js +171 -451
- package/dist/xstate-graph.esm.js +171 -451
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate-persist.cjs.d.mts +2 -0
- package/dist/xstate-persist.cjs.d.ts +2 -0
- package/dist/xstate-persist.cjs.js +314 -0
- package/dist/xstate-persist.cjs.mjs +6 -0
- package/dist/xstate-persist.development.cjs.js +325 -0
- package/dist/xstate-persist.development.cjs.mjs +6 -0
- package/dist/xstate-persist.development.esm.js +319 -0
- package/dist/xstate-persist.esm.js +308 -0
- package/dist/xstate-persist.umd.min.js +2 -0
- package/dist/xstate-persist.umd.min.js.map +1 -0
- package/dist/xstate-validation.cjs.d.mts +2 -0
- package/dist/xstate-validation.cjs.d.ts +2 -0
- package/dist/xstate-validation.cjs.js +330 -0
- package/dist/xstate-validation.cjs.mjs +5 -0
- package/dist/xstate-validation.development.cjs.js +330 -0
- package/dist/xstate-validation.development.cjs.mjs +5 -0
- package/dist/xstate-validation.development.esm.js +324 -0
- package/dist/xstate-validation.esm.js +324 -0
- package/dist/xstate-validation.umd.min.js +2 -0
- package/dist/xstate-validation.umd.min.js.map +1 -0
- package/dist/xstate.cjs.js +2486 -1430
- package/dist/xstate.cjs.mjs +23 -13
- package/dist/xstate.development.cjs.js +2486 -1430
- package/dist/xstate.development.cjs.mjs +23 -13
- package/dist/xstate.development.esm.js +2445 -1398
- package/dist/xstate.esm.js +2445 -1398
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/docs/actions.md +75 -0
- package/docs/actor-logic.md +250 -0
- package/docs/actors.md +64 -0
- package/docs/agents.md +132 -0
- package/docs/api-stability.json +4287 -0
- package/docs/async-logic.md +75 -0
- package/docs/async-requests.md +157 -0
- package/docs/backend-workflows.md +124 -0
- package/docs/cancellation.md +42 -0
- package/docs/cheatsheet.md +563 -0
- package/docs/choice-states.md +109 -0
- package/docs/choose-xstate.md +47 -0
- package/docs/configuration.md +161 -0
- package/docs/context.md +67 -0
- package/docs/create-actor.md +159 -0
- package/docs/data-and-effects.md +48 -0
- package/docs/delays.md +81 -0
- package/docs/durable-execution.md +520 -0
- package/docs/emitted-events.md +146 -0
- package/docs/errors.md +812 -0
- package/docs/examples.md +75 -0
- package/docs/faq.md +60 -0
- package/docs/final-states.md +149 -0
- package/docs/forms-and-wizards.md +166 -0
- package/docs/frameworks.md +69 -0
- package/docs/fsm.md +164 -0
- package/docs/glossary.md +68 -0
- package/docs/guards.md +137 -0
- package/docs/history-states.md +161 -0
- package/docs/how-xstate-runs-machines.md +86 -0
- package/docs/index.md +74 -0
- package/docs/input-output.md +69 -0
- package/docs/inspect-actor-systems.md +118 -0
- package/docs/inspection.md +75 -0
- package/docs/internal-events.md +156 -0
- package/docs/invoke.md +371 -0
- package/docs/lifecycle-and-errors.md +48 -0
- package/docs/listen-and-subscribe.md +126 -0
- package/docs/model-based-testing.md +321 -0
- package/docs/modeling.md +40 -0
- package/docs/parallel-states.md +182 -0
- package/docs/persist-and-restore-actors.md +120 -0
- package/docs/persistence.md +312 -0
- package/docs/quick-start.md +55 -0
- package/docs/retries-and-timeouts.md +122 -0
- package/docs/route-states.md +104 -0
- package/docs/scxml.md +92 -0
- package/docs/selectors.md +99 -0
- package/docs/serialization.md +127 -0
- package/docs/setup-and-provide.md +273 -0
- package/docs/snapshots.md +134 -0
- package/docs/spawn.md +212 -0
- package/docs/state-input.md +162 -0
- package/docs/statecharts.md +54 -0
- package/docs/states-events-transitions.md +82 -0
- package/docs/states.md +168 -0
- package/docs/system-transitions.md +172 -0
- package/docs/systems.md +166 -0
- package/docs/testing.md +152 -0
- package/docs/timeouts.md +125 -0
- package/docs/transition-functions.md +89 -0
- package/docs/transitions.md +187 -0
- package/docs/troubleshooting.md +56 -0
- package/docs/tutorial.md +481 -0
- package/docs/typescript.md +213 -0
- package/docs/typestates.md +112 -0
- package/docs/utilities.md +39 -0
- package/docs/why-state-machines.md +59 -0
- package/docs/xstate-v5-to-v6.md +1923 -0
- package/docs/your-first-machine.md +79 -0
- package/durable/package.json +8 -0
- package/fsm/package.json +8 -0
- package/package.json +72 -10
- package/persist/package.json +8 -0
- package/validation/package.json +8 -0
- package/actions/package.json +0 -8
- package/dev/package.json +0 -8
- package/dist/StateMachine-0aa98f54.development.esm.js +0 -746
- package/dist/StateMachine-aef700df.cjs.js +0 -732
- package/dist/StateMachine-d4931336.esm.js +0 -729
- package/dist/StateMachine-da872dde.development.cjs.js +0 -749
- package/dist/declarations/src/createMachineFromConfig.d.ts +0 -177
- package/dist/declarations/src/getNextSnapshot.d.ts +0 -37
- package/dist/declarations/src/graph/TestModel.d.ts +0 -70
- package/dist/declarations/src/graph/pathGenerators.d.ts +0 -4
- package/dist/index-219cb621.development.cjs.js +0 -4476
- package/dist/index-2f2fbd9b.development.esm.js +0 -4421
- package/dist/index-559ceab3.cjs.js +0 -4437
- package/dist/index-8828376f.esm.js +0 -4382
- package/guards/package.json +0 -8
- package/invoke/package.json +0 -4
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "../schema.types.js";
|
|
2
|
-
import { AnyActorSystem } from "../system.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
2
|
+
import { ActorSystemRuntime, AnyActorSystem } from "../system.js";
|
|
3
|
+
import type { ActorLogicValidator } from "../validation.types.js";
|
|
4
|
+
import { ActorLogic, ActorRefFrom, ActorScope, EventObject, ExecutableEffect, Snapshot } from "../types.js";
|
|
5
|
+
import type { NonReducibleUnknown } from "../typeUtils.js";
|
|
6
|
+
/** @public */
|
|
7
|
+
export type StepSnapshot<TContext, TOutput, TInput> = Snapshot<TOutput> & {
|
|
5
8
|
context: TContext;
|
|
6
9
|
input: TInput | undefined;
|
|
7
|
-
effects?: Record<string,
|
|
10
|
+
effects?: Record<string, StepEffectState>;
|
|
8
11
|
};
|
|
9
|
-
|
|
12
|
+
/** @public */
|
|
13
|
+
export type StepEffectState = {
|
|
10
14
|
status: 'active';
|
|
11
15
|
} | {
|
|
12
16
|
status: 'done';
|
|
@@ -15,49 +19,39 @@ export type LogicEffectState = {
|
|
|
15
19
|
status: 'error';
|
|
16
20
|
error: unknown;
|
|
17
21
|
};
|
|
18
|
-
|
|
22
|
+
/** @public */
|
|
23
|
+
export interface StepLogicArgs<TContext, TEvent extends EventObject, TInput> {
|
|
19
24
|
context: TContext;
|
|
20
25
|
event: TEvent;
|
|
21
26
|
input: TInput;
|
|
22
27
|
system: AnyActorSystem;
|
|
23
|
-
self:
|
|
28
|
+
self: StepActorRef<TContext, unknown, TEvent, TInput>;
|
|
24
29
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
event: TEmitted;
|
|
28
|
-
} | {
|
|
29
|
-
type: 'sendBack';
|
|
30
|
-
event: EventObject;
|
|
31
|
-
} | {
|
|
32
|
-
type: 'raise';
|
|
33
|
-
event: TEvent;
|
|
34
|
-
} | {
|
|
35
|
-
type: 'effect';
|
|
36
|
-
key?: string;
|
|
37
|
-
exec: () => void | (() => void);
|
|
38
|
-
} | {
|
|
39
|
-
type: 'cleanupEffects';
|
|
40
|
-
};
|
|
41
|
-
export interface LogicEnqueue<TEvent extends EventObject, TEmitted extends EventObject> {
|
|
30
|
+
/** @public */
|
|
31
|
+
export interface StepLogicEnqueue<TEvent extends EventObject, TEmitted extends EventObject> {
|
|
42
32
|
emit: (emitted: TEmitted) => void;
|
|
43
33
|
sendBack: (event: EventObject) => void;
|
|
44
34
|
raise: (event: TEvent) => void;
|
|
45
35
|
effect: {
|
|
46
|
-
(exec: () => void | (() => void)): void;
|
|
47
|
-
(key: string, exec: () => void | (() => void)): void;
|
|
36
|
+
(exec: (runtime?: Partial<ActorSystemRuntime>) => void | (() => void)): void;
|
|
37
|
+
(key: string, exec: (runtime?: Partial<ActorSystemRuntime>) => void | (() => void)): void;
|
|
48
38
|
};
|
|
49
39
|
}
|
|
50
|
-
|
|
40
|
+
/** @public */
|
|
41
|
+
export type StepPatch<TContext, TOutput, TInput> = Partial<{
|
|
51
42
|
context: TContext;
|
|
52
43
|
input: TInput | undefined;
|
|
53
|
-
status:
|
|
44
|
+
status: StepSnapshot<TContext, TOutput, TInput>['status'];
|
|
54
45
|
output: TOutput;
|
|
55
46
|
error: unknown;
|
|
56
|
-
effects: Record<string,
|
|
47
|
+
effects: Record<string, StepEffectState>;
|
|
57
48
|
}>;
|
|
58
|
-
|
|
59
|
-
export
|
|
49
|
+
/** @public */
|
|
50
|
+
export type StepLogicFunction<TContext, TOutput, TEvent extends EventObject, TInput, TEmitted extends EventObject> = (args: StepLogicArgs<TContext, TEvent, TInput>, enq: StepLogicEnqueue<TEvent, TEmitted>) => void | StepPatch<TContext, TOutput, TInput>;
|
|
51
|
+
/** @public */
|
|
52
|
+
export interface StepLogicConfig<TContext, TOutput, TEvent extends EventObject, TInput, TEmitted extends EventObject, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1> {
|
|
60
53
|
id?: string;
|
|
54
|
+
validator?: ActorLogicValidator;
|
|
61
55
|
schemas?: {
|
|
62
56
|
input?: TInputSchema;
|
|
63
57
|
output?: TOutputSchema;
|
|
@@ -65,41 +59,37 @@ export interface LogicConfig<TContext, TOutput, TEvent extends EventObject, TInp
|
|
|
65
59
|
context: TContext | ((args: {
|
|
66
60
|
input: TInput;
|
|
67
61
|
}) => TContext);
|
|
68
|
-
run:
|
|
62
|
+
run: StepLogicFunction<TContext, TOutput, TEvent, TInput, TEmitted>;
|
|
69
63
|
}
|
|
70
|
-
interface
|
|
71
|
-
(snapshot:
|
|
72
|
-
|
|
73
|
-
LogicEffect<TEvent, TEmitted>[]
|
|
74
|
-
];
|
|
75
|
-
(snapshot: LogicSnapshot<TContext, TOutput, TInput>, event: TEvent, actorScope: ActorScope<LogicSnapshot<TContext, TOutput, TInput>, TEvent, AnyActorSystem, TEmitted>): LogicSnapshot<TContext, TOutput, TInput>;
|
|
64
|
+
interface StepTransition<TContext, TOutput, TEvent extends EventObject, TInput, TEmitted extends EventObject> {
|
|
65
|
+
(snapshot: StepSnapshot<TContext, TOutput, TInput>, event: TEvent, actorScope: ActorScope<StepSnapshot<TContext, TOutput, TInput>, TEvent, AnyActorSystem, TEmitted>): [StepSnapshot<TContext, TOutput, TInput>, ExecutableEffect[]];
|
|
66
|
+
(snapshot: StepSnapshot<TContext, TOutput, TInput>, event: TEvent, actorScope: ActorScope<StepSnapshot<TContext, TOutput, TInput>, TEvent, AnyActorSystem, TEmitted>): StepSnapshot<TContext, TOutput, TInput>;
|
|
76
67
|
}
|
|
77
|
-
|
|
68
|
+
/** @public */
|
|
69
|
+
export type StepActorLogic<TContext, TOutput, TEvent extends EventObject = EventObject, TInput = NonReducibleUnknown, TEmitted extends EventObject = EventObject> = Omit<ActorLogic<StepSnapshot<TContext, TOutput, TInput>, TEvent, TInput, AnyActorSystem, TEmitted>, 'transition'> & {
|
|
78
70
|
id?: string;
|
|
79
|
-
transition:
|
|
71
|
+
transition: StepTransition<TContext, TOutput, TEvent, TInput, TEmitted>;
|
|
80
72
|
};
|
|
81
|
-
|
|
82
|
-
export
|
|
83
|
-
|
|
84
|
-
export declare const
|
|
85
|
-
export declare function executeLogicEffects(effects: readonly unknown[] | undefined, actorScope: ActorScope<any, any, any, any>): void;
|
|
86
|
-
export declare function createLogic<TContext, const TInputSchema extends StandardSchemaV1, const TOutputSchema extends StandardSchemaV1, TEvent extends EventObject = EventObject, TEmitted extends EventObject = EventObject>(config: LogicConfig<TContext, StandardSchemaV1.InferOutput<TOutputSchema>, TEvent, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted, TInputSchema, TOutputSchema> & {
|
|
73
|
+
/** @public */
|
|
74
|
+
export type StepActorRef<TContext, TOutput, TEvent extends EventObject, TInput> = ActorRefFrom<StepActorLogic<TContext, TOutput, TEvent, TInput>>;
|
|
75
|
+
/** @public */
|
|
76
|
+
export declare function createStepLogic<TContext, const TInputSchema extends StandardSchemaV1, const TOutputSchema extends StandardSchemaV1, TEvent extends EventObject = EventObject, TEmitted extends EventObject = EventObject>(config: StepLogicConfig<TContext, StandardSchemaV1.InferOutput<TOutputSchema>, TEvent, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted, TInputSchema, TOutputSchema> & {
|
|
87
77
|
schemas: {
|
|
88
78
|
input: TInputSchema;
|
|
89
79
|
output: TOutputSchema;
|
|
90
80
|
};
|
|
91
|
-
}):
|
|
92
|
-
export declare function
|
|
81
|
+
}): StepActorLogic<TContext, StandardSchemaV1.InferOutput<TOutputSchema>, TEvent, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted>;
|
|
82
|
+
export declare function createStepLogic<TContext, TOutput, const TInputSchema extends StandardSchemaV1, TEvent extends EventObject = EventObject, TEmitted extends EventObject = EventObject>(config: StepLogicConfig<TContext, TOutput, TEvent, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted, TInputSchema> & {
|
|
93
83
|
schemas: {
|
|
94
84
|
input: TInputSchema;
|
|
95
85
|
output?: undefined;
|
|
96
86
|
};
|
|
97
|
-
}):
|
|
98
|
-
export declare function
|
|
87
|
+
}): StepActorLogic<TContext, TOutput, TEvent, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted>;
|
|
88
|
+
export declare function createStepLogic<TContext, const TOutputSchema extends StandardSchemaV1, TEvent extends EventObject = EventObject, TInput = NonReducibleUnknown, TEmitted extends EventObject = EventObject>(config: StepLogicConfig<TContext, StandardSchemaV1.InferOutput<TOutputSchema>, TEvent, TInput, TEmitted, StandardSchemaV1, TOutputSchema> & {
|
|
99
89
|
schemas: {
|
|
100
90
|
input?: undefined;
|
|
101
91
|
output: TOutputSchema;
|
|
102
92
|
};
|
|
103
|
-
}):
|
|
104
|
-
export declare function
|
|
93
|
+
}): StepActorLogic<TContext, StandardSchemaV1.InferOutput<TOutputSchema>, TEvent, TInput, TEmitted>;
|
|
94
|
+
export declare function createStepLogic<TContext, TOutput = unknown, TEvent extends EventObject = EventObject, TInput = NonReducibleUnknown, TEmitted extends EventObject = EventObject>(config: StepLogicConfig<TContext, TOutput, TEvent, TInput, TEmitted>): StepActorLogic<TContext, TOutput, TEvent, TInput, TEmitted>;
|
|
105
95
|
export {};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "../schema.types.js";
|
|
2
2
|
import { AnyActorSystem } from "../system.js";
|
|
3
|
-
import {
|
|
3
|
+
import type { ActorLogicValidator } from "../validation.types.js";
|
|
4
|
+
import { ActorLogic, ActorFromLogic, ActorRefFrom, EventObject, Snapshot, Subscribable, Subscription } from "../types.js";
|
|
5
|
+
import type { NonReducibleUnknown } from "../typeUtils.js";
|
|
6
|
+
/** @public */
|
|
4
7
|
export type ObservableSnapshot<TContext, TInput extends NonReducibleUnknown> = Snapshot<undefined> & {
|
|
5
8
|
context: TContext | undefined;
|
|
6
9
|
input: TInput | undefined;
|
|
@@ -15,6 +18,7 @@ export type ObservableSnapshot<TContext, TInput extends NonReducibleUnknown> = S
|
|
|
15
18
|
}>;
|
|
16
19
|
_subscription: Subscription | undefined;
|
|
17
20
|
};
|
|
21
|
+
/** @public */
|
|
18
22
|
export type ObservableActorLogic<TContext, TInput extends NonReducibleUnknown, TEmitted extends EventObject = EventObject> = ActorLogic<ObservableSnapshot<TContext, TInput>, {
|
|
19
23
|
type: string;
|
|
20
24
|
[k: string]: unknown;
|
|
@@ -53,28 +57,35 @@ export type ObservableActorLogic<TContext, TInput extends NonReducibleUnknown, T
|
|
|
53
57
|
*
|
|
54
58
|
* @see {@link createObservableLogic}
|
|
55
59
|
* @see {@link createEventObservableLogic}
|
|
60
|
+
* @public
|
|
56
61
|
*/
|
|
57
|
-
export type ObservableActorRef<TContext> =
|
|
62
|
+
export type ObservableActorRef<TContext> = ActorRefFrom<ObservableActorLogic<TContext, any>>;
|
|
58
63
|
type ObservableActor<TContext, TInput extends NonReducibleUnknown = any, TEmitted extends EventObject = EventObject> = ActorFromLogic<ObservableActorLogic<TContext, TInput, TEmitted>>;
|
|
64
|
+
/** @public */
|
|
59
65
|
export type ObservableLogicFunction<TContext, TInput extends NonReducibleUnknown, TEmitted extends EventObject = EventObject> = ({ input, system, self, emit }: {
|
|
60
66
|
input: TInput;
|
|
61
67
|
system: AnyActorSystem;
|
|
62
68
|
self: ObservableActor<TContext, TInput, TEmitted>;
|
|
63
69
|
emit: (emitted: TEmitted) => void;
|
|
64
70
|
}) => Subscribable<TContext>;
|
|
71
|
+
/** @public */
|
|
65
72
|
export interface ObservableLogicConfig<TContext, TInput extends NonReducibleUnknown, TEmitted extends EventObject = EventObject, TInputSchema extends StandardSchemaV1 = StandardSchemaV1> {
|
|
73
|
+
validator?: ActorLogicValidator;
|
|
66
74
|
schemas?: {
|
|
67
75
|
input?: TInputSchema;
|
|
68
76
|
};
|
|
69
77
|
run: ObservableLogicFunction<TContext, TInput, TEmitted>;
|
|
70
78
|
}
|
|
79
|
+
/** @public */
|
|
71
80
|
export type EventObservableLogicFunction<TEvent extends EventObject, TInput extends NonReducibleUnknown, TEmitted extends EventObject = EventObject> = ({ input, system, self, emit }: {
|
|
72
81
|
input: TInput;
|
|
73
82
|
system: AnyActorSystem;
|
|
74
83
|
self: ObservableActor<TEvent, TInput, TEmitted>;
|
|
75
84
|
emit: (emitted: TEmitted) => void;
|
|
76
85
|
}) => Subscribable<TEvent>;
|
|
86
|
+
/** @public */
|
|
77
87
|
export interface EventObservableLogicConfig<TEvent extends EventObject, TInput extends NonReducibleUnknown, TEmitted extends EventObject = EventObject, TInputSchema extends StandardSchemaV1 = StandardSchemaV1> {
|
|
88
|
+
validator?: ActorLogicValidator;
|
|
78
89
|
schemas?: {
|
|
79
90
|
input?: TInputSchema;
|
|
80
91
|
};
|
|
@@ -123,6 +134,7 @@ export interface EventObservableLogicConfig<TEvent extends EventObject, TInput e
|
|
|
123
134
|
* Observable, although RxJS is not required to create them.
|
|
124
135
|
* @see {@link https://rxjs.dev} for documentation on RxJS Observable and observable creators.
|
|
125
136
|
* @see {@link Subscribable} interface in XState, which is based on and compatible with RxJS Observable.
|
|
137
|
+
* @public
|
|
126
138
|
*/
|
|
127
139
|
export declare function createObservableLogic<TContext, const TInputSchema extends StandardSchemaV1, TEmitted extends EventObject = EventObject>(config: ObservableLogicConfig<TContext, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted, TInputSchema> & {
|
|
128
140
|
schemas: {
|
|
@@ -183,6 +195,7 @@ export declare function createObservableLogic<TContext, TInput extends NonReduci
|
|
|
183
195
|
*
|
|
184
196
|
* It should return a {@link Subscribable}, which is compatible with an RxJS
|
|
185
197
|
* Observable, although RxJS is not required to create them.
|
|
198
|
+
* @public
|
|
186
199
|
*/
|
|
187
200
|
export declare function createEventObservableLogic<TEvent extends EventObject, const TInputSchema extends StandardSchemaV1, TEmitted extends EventObject = EventObject>(config: EventObservableLogicConfig<TEvent, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted, TInputSchema> & {
|
|
188
201
|
schemas: {
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "../schema.types.js";
|
|
2
2
|
import { AnyActorSystem } from "../system.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import type { ActorLogicValidator } from "../validation.types.js";
|
|
4
|
+
import { ActorLogic, ActorFromLogic, ActorRefFrom, EventObject, Snapshot } from "../types.js";
|
|
5
|
+
import type { NonReducibleUnknown } from "../typeUtils.js";
|
|
6
|
+
/** @public */
|
|
7
|
+
export type AsyncSnapshot<TOutput, TInput, TError = unknown> = Snapshot<TOutput, TError> & {
|
|
5
8
|
input: TInput | undefined;
|
|
6
9
|
effects?: Record<string, {
|
|
7
10
|
status: 'active';
|
|
@@ -13,13 +16,16 @@ export type AsyncSnapshot<TOutput, TInput> = Snapshot<TOutput> & {
|
|
|
13
16
|
error: unknown;
|
|
14
17
|
}>;
|
|
15
18
|
};
|
|
16
|
-
|
|
19
|
+
/** @public */
|
|
20
|
+
export type AsyncActorLogic<TOutput, TInput = unknown, TEmitted extends EventObject = EventObject, TError = unknown> = ActorLogic<AsyncSnapshot<TOutput, TInput, TError>, {
|
|
17
21
|
type: string;
|
|
18
22
|
[k: string]: unknown;
|
|
19
23
|
}, TInput, AnyActorSystem, TEmitted>;
|
|
20
|
-
|
|
24
|
+
/** @public */
|
|
25
|
+
export type AsyncActorRef<TOutput> = ActorRefFrom<AsyncActorLogic<TOutput, unknown>>;
|
|
21
26
|
type AsyncActor<TOutput, TInput = unknown, TEmitted extends EventObject = EventObject> = ActorFromLogic<AsyncActorLogic<TOutput, TInput, TEmitted>>;
|
|
22
|
-
|
|
27
|
+
/** @public */
|
|
28
|
+
export interface AsyncLogicArgs<TOutput, TInput> {
|
|
23
29
|
/** Data that was provided to the async actor. */
|
|
24
30
|
input: TInput;
|
|
25
31
|
/** The actor system to which the async actor belongs. */
|
|
@@ -29,7 +35,8 @@ export interface LogicArgs<TOutput, TInput> {
|
|
|
29
35
|
/** Aborted when the async actor is stopped or times out. */
|
|
30
36
|
signal: AbortSignal;
|
|
31
37
|
}
|
|
32
|
-
|
|
38
|
+
/** @public */
|
|
39
|
+
export interface AsyncLogicEnqueue<TEmitted extends EventObject> {
|
|
33
40
|
/** Emits an event that can be observed with `actor.on(...)`. */
|
|
34
41
|
emit: (emitted: TEmitted) => void;
|
|
35
42
|
/**
|
|
@@ -40,26 +47,65 @@ export interface LogicEnqueue<TEmitted extends EventObject> {
|
|
|
40
47
|
*/
|
|
41
48
|
step: <TStepOutput>(key: string, exec: () => TStepOutput | PromiseLike<TStepOutput>) => Promise<TStepOutput>;
|
|
42
49
|
}
|
|
43
|
-
|
|
44
|
-
export
|
|
50
|
+
/** @public */
|
|
51
|
+
export type AsyncLogicFunction<TOutput, TInput = NonReducibleUnknown, TEmitted extends EventObject = EventObject> = (args: AsyncLogicArgs<TOutput, TInput>, enq: AsyncLogicEnqueue<TEmitted>) => PromiseLike<TOutput>;
|
|
52
|
+
type AsyncLogicFunctionOutput<TLogicFunction extends (...args: any[]) => PromiseLike<any>> = Awaited<ReturnType<TLogicFunction>>;
|
|
53
|
+
/** @public */
|
|
54
|
+
export interface AsyncLogicConfig<TOutput, TInput = NonReducibleUnknown, TEmitted extends EventObject = EventObject, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, TErrorSchema extends StandardSchemaV1 = StandardSchemaV1> {
|
|
45
55
|
/**
|
|
46
56
|
* Stable identifier for this async logic. This identifies the logic, not a
|
|
47
57
|
* particular actor instance.
|
|
48
58
|
*/
|
|
49
59
|
id?: string;
|
|
60
|
+
validator?: ActorLogicValidator;
|
|
50
61
|
/** Schemas for inferring async logic types. */
|
|
51
62
|
schemas?: {
|
|
52
63
|
input?: TInputSchema;
|
|
53
64
|
output?: TOutputSchema;
|
|
65
|
+
/**
|
|
66
|
+
* Types the error this logic fails with: the `error` snapshot field and
|
|
67
|
+
* `event.error` in the invoking machine's `onError`. Type-only.
|
|
68
|
+
*/
|
|
69
|
+
error?: TErrorSchema;
|
|
54
70
|
};
|
|
55
71
|
/** Maximum time this async logic may run before it is aborted and errors. */
|
|
56
72
|
timeout?: number | string;
|
|
57
73
|
/** The async work to execute when the actor starts. */
|
|
58
|
-
run:
|
|
74
|
+
run: AsyncLogicFunction<TOutput, TInput, TEmitted>;
|
|
59
75
|
}
|
|
76
|
+
/** @public */
|
|
60
77
|
export declare class TimeoutError extends Error {
|
|
61
78
|
constructor(timeout: number | string);
|
|
62
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* The error type of async logic: the `schemas.error` output, plus
|
|
82
|
+
* {@link TimeoutError} when a `timeout` is configured.
|
|
83
|
+
*
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
export type AsyncLogicError<TErrorSchema extends StandardSchemaV1, TTimeout> = [
|
|
87
|
+
TTimeout
|
|
88
|
+
] extends [undefined] ? StandardSchemaV1.InferOutput<TErrorSchema> : StandardSchemaV1.InferOutput<TErrorSchema> | TimeoutError;
|
|
89
|
+
type AsyncLogicLiteralOutput<T> = string | number | bigint | boolean | null | undefined | {
|
|
90
|
+
[key: string]: T;
|
|
91
|
+
} | readonly T[];
|
|
92
|
+
/**
|
|
93
|
+
* Contextual typing aid for the schema-free `createAsyncLogic` overload. It
|
|
94
|
+
* never matches a call (`schemas: never`).
|
|
95
|
+
*
|
|
96
|
+
* TypeScript fixes the return type of a parameterless `run` the first time an
|
|
97
|
+
* overload contextually types it, and the schema-free overload is checked
|
|
98
|
+
* first. Configs without `schemas` are discriminated to the schema-free member,
|
|
99
|
+
* so their output widens as usual. Configs with `schemas` see this member too:
|
|
100
|
+
* its `TLiteralOutput` return keeps literals such as `{ kind: 'a' }` from
|
|
101
|
+
* widening to `{ kind: string }` before the schema overloads check `run`
|
|
102
|
+
* against `schemas.output`. The member cannot tell which schemas are present,
|
|
103
|
+
* so input-only and error-only configs keep those literals as well.
|
|
104
|
+
*/
|
|
105
|
+
type AsyncLogicSchemaContext<TOutput, TInput, TEmitted extends EventObject, TLiteralOutput> = {
|
|
106
|
+
schemas: never;
|
|
107
|
+
run: (args: AsyncLogicArgs<TOutput, TInput>, enq: AsyncLogicEnqueue<TEmitted>) => PromiseLike<TLiteralOutput>;
|
|
108
|
+
};
|
|
63
109
|
/**
|
|
64
110
|
* Represents an actor created by `createAsyncLogic`.
|
|
65
111
|
*
|
|
@@ -156,34 +202,56 @@ export declare class TimeoutError extends Error {
|
|
|
156
202
|
* - `emit` - Emits an event that can be observed with `actor.on(...)`
|
|
157
203
|
*
|
|
158
204
|
* @see {@link https://stately.ai/docs/input | Input docs} for more information about how input is passed
|
|
205
|
+
* @public
|
|
159
206
|
*/
|
|
160
|
-
export declare function createAsyncLogic<
|
|
161
|
-
schemas
|
|
162
|
-
|
|
163
|
-
output: TOutputSchema;
|
|
164
|
-
};
|
|
165
|
-
}): AsyncActorLogic<StandardSchemaV1.InferOutput<TOutputSchema>, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted> & {
|
|
207
|
+
export declare function createAsyncLogic<TOutput, TInput = NonReducibleUnknown, TEmitted extends EventObject = EventObject, TLiteralOutput extends AsyncLogicLiteralOutput<TLiteralOutput> = never>(asyncLogic: (Omit<AsyncLogicConfig<TOutput, TInput, TEmitted>, 'schemas'> & {
|
|
208
|
+
schemas?: undefined;
|
|
209
|
+
}) | AsyncLogicSchemaContext<TOutput, TInput, TEmitted, TLiteralOutput>): AsyncActorLogic<TOutput, TInput, TEmitted> & {
|
|
166
210
|
id?: string;
|
|
167
211
|
};
|
|
168
|
-
export declare function createAsyncLogic<
|
|
212
|
+
export declare function createAsyncLogic<const TInputSchema extends StandardSchemaV1, TEmitted extends EventObject = EventObject, TLogicFunction extends AsyncLogicFunction<any, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted> = AsyncLogicFunction<any, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted>, const TErrorSchema extends StandardSchemaV1 = StandardSchemaV1, TTimeout extends number | string | undefined = undefined>(asyncLogic: Omit<AsyncLogicConfig<never, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted, TInputSchema>, 'run' | 'schemas'> & {
|
|
169
213
|
schemas: {
|
|
170
214
|
input: TInputSchema;
|
|
171
215
|
output?: never;
|
|
216
|
+
error?: TErrorSchema;
|
|
172
217
|
};
|
|
173
|
-
|
|
218
|
+
run: TLogicFunction;
|
|
219
|
+
} & {
|
|
220
|
+
timeout?: TTimeout;
|
|
221
|
+
}): AsyncActorLogic<AsyncLogicFunctionOutput<TLogicFunction>, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted, AsyncLogicError<TErrorSchema, TTimeout>> & {
|
|
174
222
|
id?: string;
|
|
175
223
|
};
|
|
176
|
-
export declare function createAsyncLogic<const TOutputSchema extends StandardSchemaV1, TInput = NonReducibleUnknown, TEmitted extends EventObject = EventObject>(asyncLogic:
|
|
224
|
+
export declare function createAsyncLogic<const TOutputSchema extends StandardSchemaV1, TInput = NonReducibleUnknown, TEmitted extends EventObject = EventObject, const TErrorSchema extends StandardSchemaV1 = StandardSchemaV1, TTimeout extends number | string | undefined = undefined>(asyncLogic: AsyncLogicConfig<StandardSchemaV1.InferOutput<TOutputSchema>, TInput, TEmitted, StandardSchemaV1, TOutputSchema, TErrorSchema> & {
|
|
177
225
|
schemas: {
|
|
178
226
|
input?: never;
|
|
179
227
|
output: TOutputSchema;
|
|
228
|
+
error?: TErrorSchema;
|
|
180
229
|
};
|
|
181
|
-
}
|
|
230
|
+
} & {
|
|
231
|
+
timeout?: TTimeout;
|
|
232
|
+
}): AsyncActorLogic<StandardSchemaV1.InferOutput<TOutputSchema>, TInput, TEmitted, AsyncLogicError<TErrorSchema, TTimeout>> & {
|
|
182
233
|
id?: string;
|
|
183
234
|
};
|
|
184
|
-
export declare function createAsyncLogic<TOutput, TInput = NonReducibleUnknown, TEmitted extends EventObject = EventObject>(asyncLogic: Omit<
|
|
185
|
-
schemas
|
|
186
|
-
|
|
235
|
+
export declare function createAsyncLogic<TOutput, TInput = NonReducibleUnknown, TEmitted extends EventObject = EventObject, const TErrorSchema extends StandardSchemaV1 = StandardSchemaV1, TTimeout extends number | string | undefined = undefined>(asyncLogic: Omit<AsyncLogicConfig<TOutput, TInput, TEmitted>, 'schemas'> & {
|
|
236
|
+
schemas: {
|
|
237
|
+
input?: never;
|
|
238
|
+
output?: never;
|
|
239
|
+
error: TErrorSchema;
|
|
240
|
+
};
|
|
241
|
+
} & {
|
|
242
|
+
timeout?: TTimeout;
|
|
243
|
+
}): AsyncActorLogic<TOutput, TInput, TEmitted, AsyncLogicError<TErrorSchema, TTimeout>> & {
|
|
244
|
+
id?: string;
|
|
245
|
+
};
|
|
246
|
+
export declare function createAsyncLogic<const TInputSchema extends StandardSchemaV1, const TOutputSchema extends StandardSchemaV1, TEmitted extends EventObject = EventObject, const TErrorSchema extends StandardSchemaV1 = StandardSchemaV1, TTimeout extends number | string | undefined = undefined>(asyncLogic: AsyncLogicConfig<StandardSchemaV1.InferOutput<TOutputSchema>, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted, TInputSchema, TOutputSchema, TErrorSchema> & {
|
|
247
|
+
schemas: {
|
|
248
|
+
input?: TInputSchema;
|
|
249
|
+
output: TOutputSchema;
|
|
250
|
+
error?: TErrorSchema;
|
|
251
|
+
};
|
|
252
|
+
} & {
|
|
253
|
+
timeout?: TTimeout;
|
|
254
|
+
}): AsyncActorLogic<StandardSchemaV1.InferOutput<TOutputSchema>, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted, AsyncLogicError<TErrorSchema, TTimeout>> & {
|
|
187
255
|
id?: string;
|
|
188
256
|
};
|
|
189
257
|
export {};
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import { AnyActorSystem } from "../system.js";
|
|
2
|
-
import { ActorLogic,
|
|
2
|
+
import { ActorLogic, ActorRefFrom, AnyActorRef, EventObject, Snapshot } from "../types.js";
|
|
3
|
+
/** @public */
|
|
3
4
|
export type SubscriptionSnapshot = Snapshot<undefined> & {
|
|
4
5
|
input: SubscriptionInput<any, any, any, any>;
|
|
5
6
|
};
|
|
7
|
+
/** @public */
|
|
6
8
|
export interface SubscriptionMappers<TSnapshot extends Snapshot<unknown>, TOutput, TMappedEvent extends EventObject> {
|
|
7
9
|
snapshot?: (snapshot: TSnapshot) => TMappedEvent;
|
|
8
10
|
done?: (output: TOutput) => TMappedEvent;
|
|
9
11
|
error?: (error: unknown) => TMappedEvent;
|
|
10
12
|
}
|
|
13
|
+
/** @public */
|
|
11
14
|
export interface SubscriptionInput<TSnapshot extends Snapshot<unknown>, TOutput, TMappedEvent extends EventObject, TMappers extends SubscriptionMappers<TSnapshot, TOutput, TMappedEvent>> {
|
|
12
15
|
actor: AnyActorRef;
|
|
13
16
|
mappers: TMappers;
|
|
14
17
|
}
|
|
18
|
+
/** @public */
|
|
15
19
|
export type SubscriptionActorLogic<TSnapshot extends Snapshot<unknown> = Snapshot<unknown>, TOutput = unknown, TMappedEvent extends EventObject = EventObject> = ActorLogic<SubscriptionSnapshot, EventObject, SubscriptionInput<TSnapshot, TOutput, TMappedEvent, SubscriptionMappers<TSnapshot, TOutput, TMappedEvent>>, AnyActorSystem, EventObject>;
|
|
16
|
-
|
|
20
|
+
/** @public */
|
|
21
|
+
export type SubscriptionActorRef<TSnapshot extends Snapshot<unknown> = Snapshot<unknown>, TOutput = unknown, TMappedEvent extends EventObject = EventObject> = ActorRefFrom<SubscriptionActorLogic<TSnapshot, TOutput, TMappedEvent>>;
|
|
17
22
|
/**
|
|
18
23
|
* Creates actor logic for subscribing to lifecycle events (done/error/snapshot)
|
|
19
24
|
* from another actor. Used internally by `enq.subscribeTo()`.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
20
27
|
*/
|
|
21
28
|
export declare function createSubscriptionLogic<TSnapshot extends Snapshot<unknown> = Snapshot<unknown>, TOutput = unknown, TMappedEvent extends EventObject = EventObject>(): SubscriptionActorLogic<TSnapshot, TOutput, TMappedEvent>;
|
|
22
|
-
export declare const subscriptionLogic: SubscriptionActorLogic<Snapshot<unknown>, unknown, EventObject>;
|
|
@@ -21,5 +21,6 @@ import { EventDescriptor, EventObject, ExtractEvent } from "./types.js";
|
|
|
21
21
|
* // or { type: 'notify'; message: string; level: 'info' | 'error' }
|
|
22
22
|
* },
|
|
23
23
|
* ```
|
|
24
|
+
* @public
|
|
24
25
|
*/
|
|
25
26
|
export declare function assertEvent<TEvent extends EventObject, TAssertedDescriptor extends EventDescriptor<TEvent>>(event: TEvent, type: TAssertedDescriptor | readonly TAssertedDescriptor[]): asserts event is ExtractEvent<TEvent, TAssertedDescriptor>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lean type primitives shared by the main `xstate` entry and the compact
|
|
3
|
+
* `xstate/fsm` entry. This module (plus `schema.types.ts`) must stay free of
|
|
4
|
+
* imports from the rest of the package so that `xstate/fsm` consumers do not
|
|
5
|
+
* pull the full type surface into their program.
|
|
6
|
+
*/
|
|
7
|
+
import type { SetupStateSchemas, StandardSchemaV1, TypeSchema } from "./schema.types.js";
|
|
8
|
+
declare global {
|
|
9
|
+
interface SymbolConstructor {
|
|
10
|
+
readonly observable: symbol;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The full definition of an event, with a string `type`.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export type EventObject = {
|
|
19
|
+
/** The type of event that is sent. */
|
|
20
|
+
type: string;
|
|
21
|
+
};
|
|
22
|
+
/** @public */
|
|
23
|
+
export type MachineContext = Record<string, any>;
|
|
24
|
+
/** @public */
|
|
25
|
+
export type Values<T> = T[keyof T];
|
|
26
|
+
export type ActionSchemas = Record<string, {
|
|
27
|
+
params: StandardSchemaV1;
|
|
28
|
+
}>;
|
|
29
|
+
export type GuardSchemas = Record<string, {
|
|
30
|
+
params: StandardSchemaV1;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* State node types that can be declared in a setup state contract.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export type SetupStateType = 'atomic' | 'compound' | 'parallel' | 'final' | 'history' | 'choice';
|
|
38
|
+
/** @public */
|
|
39
|
+
export type SetupSchemas = {
|
|
40
|
+
context?: StandardSchemaV1 | undefined;
|
|
41
|
+
events?: Record<string, StandardSchemaV1> | undefined;
|
|
42
|
+
internalEvents?: Record<string, StandardSchemaV1> | undefined;
|
|
43
|
+
actions?: ActionSchemas | undefined;
|
|
44
|
+
guards?: GuardSchemas | undefined;
|
|
45
|
+
emitted?: Record<string, StandardSchemaV1> | undefined;
|
|
46
|
+
input?: StandardSchemaV1 | undefined;
|
|
47
|
+
output?: StandardSchemaV1 | undefined;
|
|
48
|
+
meta?: StandardSchemaV1 | undefined;
|
|
49
|
+
transitionMeta?: StandardSchemaV1 | undefined;
|
|
50
|
+
tags?: StandardSchemaV1 | undefined;
|
|
51
|
+
children?: Record<string, StandardSchemaV1> | undefined;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* State schema with optional input/output schemas, structural metadata, and
|
|
55
|
+
* nested states.
|
|
56
|
+
*
|
|
57
|
+
* Structural fields are contracts/defaults for `createMachine(...)`; machine
|
|
58
|
+
* behavior remains authored in the machine config.
|
|
59
|
+
*
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
export interface SetupStateSchema {
|
|
63
|
+
type?: SetupStateType | undefined;
|
|
64
|
+
id?: string | undefined;
|
|
65
|
+
initial?: string | undefined;
|
|
66
|
+
history?: 'shallow' | 'deep' | true | undefined;
|
|
67
|
+
target?: string | readonly [string, ...string[]] | undefined;
|
|
68
|
+
route?: true | undefined;
|
|
69
|
+
schemas?: SetupStateSchemas | undefined;
|
|
70
|
+
states?: Record<string, SetupStateSchema> | undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Event payloads from schemas (e.g. Zod) are often inferred as optional in
|
|
74
|
+
* output types. Wrapping in Required<> ensures properties defined in the schema
|
|
75
|
+
* are required on the event. Type-only schemas created with the `types()`
|
|
76
|
+
* helper are exempt: their declared type is authoritative, so optional
|
|
77
|
+
* properties stay optional.
|
|
78
|
+
*
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
export type InferEvents<TEventSchemaMap extends Record<string, StandardSchemaV1>> = Values<{
|
|
82
|
+
[K in keyof TEventSchemaMap & string]: StandardSchemaV1.InferOutput<TEventSchemaMap[K]> extends infer O ? [O] extends [never] ? never : unknown extends O ? O & {
|
|
83
|
+
type: K;
|
|
84
|
+
} : [O] extends [void] ? {
|
|
85
|
+
type: K;
|
|
86
|
+
} : string extends keyof O ? [O[string]] extends [never] ? {
|
|
87
|
+
type: EventTypeFromSchemaKey<K>;
|
|
88
|
+
} : NormalizeEventPayload<TEventSchemaMap[K], O> & {
|
|
89
|
+
type: EventTypeFromSchemaKey<K>;
|
|
90
|
+
} : NormalizeEventPayload<TEventSchemaMap[K], O> & {
|
|
91
|
+
type: EventTypeFromSchemaKey<K>;
|
|
92
|
+
} : never;
|
|
93
|
+
}>;
|
|
94
|
+
/** Infers internal events only from explicitly declared schema keys. */
|
|
95
|
+
export type InferInternalEvents<TEventSchemaMap extends Record<string, StandardSchemaV1>> = string extends keyof TEventSchemaMap ? never : InferEvents<TEventSchemaMap>;
|
|
96
|
+
type EventTypeFromSchemaKey<TKey extends string> = TKey extends '*' ? string : TKey extends `${infer TLeading}.*` ? `${TLeading}.${string}` : TKey;
|
|
97
|
+
/**
|
|
98
|
+
* Keeps a type-only schema's payload verbatim; applies Required<> to payloads
|
|
99
|
+
* from validator libraries (see {@link InferEvents}).
|
|
100
|
+
*/
|
|
101
|
+
type NormalizeEventPayload<TSchema extends StandardSchemaV1, O> = TSchema extends TypeSchema<any> ? O : Required<O>;
|
|
102
|
+
export {};
|