xstate 6.0.0-alpha.11 → 6.0.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{StateMachine-aef700df.cjs.js → StateMachine-7af634f9.cjs.js} +2 -2
- package/dist/{StateMachine-0aa98f54.development.esm.js → StateMachine-8a9e6cb4.development.esm.js} +2 -2
- package/dist/{StateMachine-d4931336.esm.js → StateMachine-97ef0e5e.esm.js} +2 -2
- package/dist/{StateMachine-da872dde.development.cjs.js → StateMachine-c7e1996c.development.cjs.js} +2 -2
- package/dist/declarations/src/actors/promise.d.ts +4 -2
- package/dist/declarations/src/createActor.d.ts +2 -8
- package/dist/declarations/src/createMachineFromConfig.d.ts +56 -25
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/declarations/src/serialize.d.ts +8 -22
- package/dist/declarations/src/setup.d.ts +25 -13
- package/dist/declarations/src/stateUtils.d.ts +3 -1
- package/dist/declarations/src/transitionActions.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +8 -4
- package/dist/declarations/src/types.v6.d.ts +20 -1
- package/dist/{index-219cb621.development.cjs.js → index-3d018b1e.development.cjs.js} +27 -12
- package/dist/{index-8828376f.esm.js → index-45856a94.esm.js} +27 -12
- package/dist/{index-559ceab3.cjs.js → index-698a3320.cjs.js} +27 -12
- package/dist/{index-2f2fbd9b.development.esm.js → index-be3d4c2d.development.esm.js} +27 -12
- package/dist/xstate-actors.cjs.js +1 -1
- package/dist/xstate-actors.development.cjs.js +1 -1
- package/dist/xstate-actors.development.esm.js +1 -1
- package/dist/xstate-actors.esm.js +1 -1
- package/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/xstate-graph.cjs.js +2 -2
- package/dist/xstate-graph.development.cjs.js +2 -2
- package/dist/xstate-graph.development.esm.js +2 -2
- package/dist/xstate-graph.esm.js +2 -2
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +501 -144
- package/dist/xstate.development.cjs.js +501 -144
- package/dist/xstate.development.esm.js +503 -146
- package/dist/xstate.esm.js +503 -146
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var dist_xstateActors = require('./index-
|
|
3
|
+
var dist_xstateActors = require('./index-698a3320.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, {
|
|
6
6
|
machine,
|
|
@@ -266,7 +266,7 @@ function formatChoiceTransitions(stateNode) {
|
|
|
266
266
|
if (!result || result.target === undefined) {
|
|
267
267
|
throw new Error(`Choice state "${stateNode.id}" must resolve to a target.`);
|
|
268
268
|
}
|
|
269
|
-
for (const key of ['actions', 'to'
|
|
269
|
+
for (const key of ['actions', 'to']) {
|
|
270
270
|
if (result[key] !== undefined) {
|
|
271
271
|
throw new Error(`Choice state "${stateNode.id}" cannot declare \`${key}\` on a choice.`);
|
|
272
272
|
}
|
package/dist/{StateMachine-0aa98f54.development.esm.js → StateMachine-8a9e6cb4.development.esm.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ProcessingStatus, C as resolveReferencedActor, c as createActor, S as STATE_DELIMITER, D as mapValues, t as toArray, E as createInvokeId, F as getDelayedTransitions, G as evaluateCandidate, H as formatTransition, N as NULL_EVENT, I as toTransitionConfigArray, J as createInvokeTimeoutEvent, K as getCandidates, L as formatRouteTransitions, M as resolveStateValue, O as getAllStateNodes, f as getStateNodes, Q as createMachineSnapshot, R as isInFinalState, a as macrostep, U as transitionNode, m as matchesEventDescriptor, V as resolveActionsWithContext, b as createInitEvent, d as initialMicrostep, W as toStatePath, X as isStateId, Y as getStateNodeByPath, Z as getPersistedSnapshot, $ as $$ACTOR_TYPE } from './index-
|
|
1
|
+
import { P as ProcessingStatus, C as resolveReferencedActor, c as createActor, S as STATE_DELIMITER, D as mapValues, t as toArray, E as createInvokeId, F as getDelayedTransitions, G as evaluateCandidate, H as formatTransition, N as NULL_EVENT, I as toTransitionConfigArray, J as createInvokeTimeoutEvent, K as getCandidates, L as formatRouteTransitions, M as resolveStateValue, O as getAllStateNodes, f as getStateNodes, Q as createMachineSnapshot, R as isInFinalState, a as macrostep, U as transitionNode, m as matchesEventDescriptor, V as resolveActionsWithContext, b as createInitEvent, d as initialMicrostep, W as toStatePath, X as isStateId, Y as getStateNodeByPath, Z as getPersistedSnapshot, $ as $$ACTOR_TYPE } from './index-be3d4c2d.development.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -264,7 +264,7 @@ function formatChoiceTransitions(stateNode) {
|
|
|
264
264
|
if (!result || result.target === undefined) {
|
|
265
265
|
throw new Error(`Choice state "${stateNode.id}" must resolve to a target.`);
|
|
266
266
|
}
|
|
267
|
-
for (const key of ['actions', 'to'
|
|
267
|
+
for (const key of ['actions', 'to']) {
|
|
268
268
|
if (result[key] !== undefined) {
|
|
269
269
|
throw new Error(`Choice state "${stateNode.id}" cannot declare \`${key}\` on a choice.`);
|
|
270
270
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ProcessingStatus, C as resolveReferencedActor, c as createActor, S as STATE_DELIMITER, D as mapValues, t as toArray, E as createInvokeId, F as getDelayedTransitions, G as evaluateCandidate, H as formatTransition, N as NULL_EVENT, I as toTransitionConfigArray, J as createInvokeTimeoutEvent, K as getCandidates, L as formatRouteTransitions, M as resolveStateValue, O as getAllStateNodes, f as getStateNodes, Q as createMachineSnapshot, R as isInFinalState, a as macrostep, U as transitionNode, m as matchesEventDescriptor, V as resolveActionsWithContext, b as createInitEvent, d as initialMicrostep, W as toStatePath, X as isStateId, Y as getStateNodeByPath, Z as getPersistedSnapshot, $ as $$ACTOR_TYPE } from './index-
|
|
1
|
+
import { P as ProcessingStatus, C as resolveReferencedActor, c as createActor, S as STATE_DELIMITER, D as mapValues, t as toArray, E as createInvokeId, F as getDelayedTransitions, G as evaluateCandidate, H as formatTransition, N as NULL_EVENT, I as toTransitionConfigArray, J as createInvokeTimeoutEvent, K as getCandidates, L as formatRouteTransitions, M as resolveStateValue, O as getAllStateNodes, f as getStateNodes, Q as createMachineSnapshot, R as isInFinalState, a as macrostep, U as transitionNode, m as matchesEventDescriptor, V as resolveActionsWithContext, b as createInitEvent, d as initialMicrostep, W as toStatePath, X as isStateId, Y as getStateNodeByPath, Z as getPersistedSnapshot, $ as $$ACTOR_TYPE } from './index-45856a94.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -264,7 +264,7 @@ function formatChoiceTransitions(stateNode) {
|
|
|
264
264
|
if (!result || result.target === undefined) {
|
|
265
265
|
throw new Error(`Choice state "${stateNode.id}" must resolve to a target.`);
|
|
266
266
|
}
|
|
267
|
-
for (const key of ['actions', 'to'
|
|
267
|
+
for (const key of ['actions', 'to']) {
|
|
268
268
|
if (result[key] !== undefined) {
|
|
269
269
|
throw new Error(`Choice state "${stateNode.id}" cannot declare \`${key}\` on a choice.`);
|
|
270
270
|
}
|
package/dist/{StateMachine-da872dde.development.cjs.js → StateMachine-c7e1996c.development.cjs.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var dist_xstateActors = require('./index-
|
|
3
|
+
var dist_xstateActors = require('./index-3d018b1e.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, {
|
|
6
6
|
machine,
|
|
@@ -266,7 +266,7 @@ function formatChoiceTransitions(stateNode) {
|
|
|
266
266
|
if (!result || result.target === undefined) {
|
|
267
267
|
throw new Error(`Choice state "${stateNode.id}" must resolve to a target.`);
|
|
268
268
|
}
|
|
269
|
-
for (const key of ['actions', 'to'
|
|
269
|
+
for (const key of ['actions', 'to']) {
|
|
270
270
|
if (result[key] !== undefined) {
|
|
271
271
|
throw new Error(`Choice state "${stateNode.id}" cannot declare \`${key}\` on a choice.`);
|
|
272
272
|
}
|
|
@@ -41,6 +41,7 @@ export interface LogicEnqueue<TEmitted extends EventObject> {
|
|
|
41
41
|
step: <TStepOutput>(key: string, exec: () => TStepOutput | PromiseLike<TStepOutput>) => Promise<TStepOutput>;
|
|
42
42
|
}
|
|
43
43
|
export type LogicFunction<TOutput, TInput = NonReducibleUnknown, TEmitted extends EventObject = EventObject> = (args: LogicArgs<TOutput, TInput>, enq: LogicEnqueue<TEmitted>) => PromiseLike<TOutput>;
|
|
44
|
+
type AsyncLogicFunctionOutput<TLogicFunction extends (...args: any[]) => PromiseLike<any>> = Awaited<ReturnType<TLogicFunction>>;
|
|
44
45
|
export interface LogicConfig<TOutput, TInput = NonReducibleUnknown, TEmitted extends EventObject = EventObject, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1> {
|
|
45
46
|
/**
|
|
46
47
|
* Stable identifier for this async logic. This identifies the logic, not a
|
|
@@ -165,12 +166,13 @@ export declare function createAsyncLogic<const TInputSchema extends StandardSche
|
|
|
165
166
|
}): AsyncActorLogic<StandardSchemaV1.InferOutput<TOutputSchema>, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted> & {
|
|
166
167
|
id?: string;
|
|
167
168
|
};
|
|
168
|
-
export declare function createAsyncLogic<
|
|
169
|
+
export declare function createAsyncLogic<const TInputSchema extends StandardSchemaV1, TEmitted extends EventObject = EventObject, TLogicFunction extends LogicFunction<any, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted> = LogicFunction<any, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted>>(asyncLogic: Omit<LogicConfig<never, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted, TInputSchema>, 'run' | 'schemas'> & {
|
|
169
170
|
schemas: {
|
|
170
171
|
input: TInputSchema;
|
|
171
172
|
output?: never;
|
|
172
173
|
};
|
|
173
|
-
|
|
174
|
+
run: TLogicFunction;
|
|
175
|
+
}): AsyncActorLogic<AsyncLogicFunctionOutput<TLogicFunction>, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted> & {
|
|
174
176
|
id?: string;
|
|
175
177
|
};
|
|
176
178
|
export declare function createAsyncLogic<const TOutputSchema extends StandardSchemaV1, TInput = NonReducibleUnknown, TEmitted extends EventObject = EventObject>(asyncLogic: LogicConfig<StandardSchemaV1.InferOutput<TOutputSchema>, TInput, TEmitted, StandardSchemaV1, TOutputSchema> & {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { symbolObservable } from "./symbolObservable.js";
|
|
2
2
|
import { AnyActorSystem, Clock } from "./system.js";
|
|
3
|
-
import type { AnyActor, AnyActorLogic, EmittedFrom, EventFromLogic, SendableEventFromLogic, InputFrom, Snapshot, SnapshotFrom, Readable } from "./types.js";
|
|
3
|
+
import type { ActorTrigger, AnyActor, AnyActorLogic, EmittedFrom, EventFromLogic, SendableEventFromLogic, InputFrom, Snapshot, SnapshotFrom, Readable } from "./types.js";
|
|
4
4
|
import { ActorOptions, ActorInstance, ActorRef, InteropSubscribable, Observer, Subscription } from "./types.js";
|
|
5
5
|
export declare const $$ACTOR_TYPE = 1;
|
|
6
6
|
export declare enum ProcessingStatus {
|
|
@@ -45,13 +45,7 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorInstanc
|
|
|
45
45
|
sessionId: string;
|
|
46
46
|
/** The system to which this actor belongs. */
|
|
47
47
|
system: AnyActorSystem;
|
|
48
|
-
trigger:
|
|
49
|
-
[K in SendableEventFromLogic<TLogic>['type']]: {} extends Omit<Extract<SendableEventFromLogic<TLogic>, {
|
|
50
|
-
type: K;
|
|
51
|
-
}>, 'type'> ? () => void : (payload: Omit<Extract<SendableEventFromLogic<TLogic>, {
|
|
52
|
-
type: K;
|
|
53
|
-
}>, 'type'>) => void;
|
|
54
|
-
};
|
|
48
|
+
trigger: ActorTrigger<SendableEventFromLogic<TLogic>>;
|
|
55
49
|
src: string | AnyActorLogic;
|
|
56
50
|
/**
|
|
57
51
|
* Creates a new actor instance for the given logic with the provided options,
|
|
@@ -90,44 +90,64 @@ interface ScxmlIfJSON {
|
|
|
90
90
|
}
|
|
91
91
|
interface CustomActionJSON {
|
|
92
92
|
type: string;
|
|
93
|
-
params?:
|
|
93
|
+
params?: unknown;
|
|
94
94
|
}
|
|
95
|
-
export type ActionJSON = CustomActionJSON | RaiseJSON | CancelJSON | LogJSON | EmitJSON | AssignJSON | ScxmlAssignJSON | ScxmlRaiseJSON | ScxmlScriptJSON | ScxmlIfJSON | ScxmlForeachJSON | ScxmlCancelJSON | ScxmlBlockJSON;
|
|
95
|
+
export type ActionJSON = CustomActionJSON | RaiseJSON | CancelJSON | LogJSON | EmitJSON | AssignJSON | ScxmlAssignJSON | ScxmlRaiseJSON | ScxmlScriptJSON | ScxmlIfJSON | ScxmlForeachJSON | ScxmlCancelJSON | ScxmlBlockJSON | ExpressionJSON | CodeJSON;
|
|
96
96
|
export interface GuardJSON {
|
|
97
97
|
type: string;
|
|
98
|
-
params?:
|
|
98
|
+
params?: unknown;
|
|
99
|
+
}
|
|
100
|
+
interface ExpressionJSON {
|
|
101
|
+
'@expr': string;
|
|
102
|
+
'@lang'?: string;
|
|
103
|
+
}
|
|
104
|
+
interface CodeJSON {
|
|
105
|
+
'@code': string;
|
|
106
|
+
'@lang'?: string;
|
|
107
|
+
}
|
|
108
|
+
type ResolvableJSON = ExpressionJSON | CodeJSON;
|
|
109
|
+
type ConditionJSON = GuardJSON | ResolvableJSON;
|
|
110
|
+
interface ChoiceBranchJSON {
|
|
111
|
+
when?: ConditionJSON;
|
|
112
|
+
target: string | string[];
|
|
113
|
+
context?: MachineContext;
|
|
114
|
+
input?: unknown;
|
|
115
|
+
description?: string;
|
|
116
|
+
reenter?: boolean;
|
|
117
|
+
meta?: MetaObject;
|
|
99
118
|
}
|
|
100
119
|
export interface InvokeJSON {
|
|
101
120
|
id?: string;
|
|
102
121
|
registryKey?: string;
|
|
103
|
-
src: string
|
|
122
|
+
src: string;
|
|
104
123
|
input?: unknown;
|
|
105
|
-
onDone?:
|
|
106
|
-
onError?:
|
|
107
|
-
onSnapshot?:
|
|
108
|
-
timeout?: number | string;
|
|
109
|
-
onTimeout?:
|
|
124
|
+
onDone?: TransitionConfigJSON | TransitionConfigJSON[];
|
|
125
|
+
onError?: TransitionConfigJSON | TransitionConfigJSON[];
|
|
126
|
+
onSnapshot?: TransitionConfigJSON | TransitionConfigJSON[];
|
|
127
|
+
timeout?: number | string | ResolvableJSON;
|
|
128
|
+
onTimeout?: TransitionConfigJSON | TransitionConfigJSON[];
|
|
110
129
|
}
|
|
111
130
|
export interface TransitionJSON {
|
|
112
131
|
target?: string | string[];
|
|
113
132
|
context?: MachineContext;
|
|
114
133
|
actions?: ActionJSON[];
|
|
115
|
-
guard?:
|
|
134
|
+
guard?: ConditionJSON;
|
|
116
135
|
description?: string;
|
|
117
136
|
reenter?: boolean;
|
|
118
137
|
meta?: MetaObject;
|
|
119
138
|
input?: unknown;
|
|
120
139
|
}
|
|
140
|
+
type TransitionConfigJSON = TransitionJSON | ResolvableJSON;
|
|
121
141
|
export interface StateNodeJSON {
|
|
122
142
|
id?: string;
|
|
123
143
|
key?: string;
|
|
124
144
|
type?: 'atomic' | 'compound' | 'parallel' | 'final' | 'history' | 'choice';
|
|
125
145
|
initial?: string;
|
|
126
146
|
states?: Record<string, StateNodeJSON>;
|
|
127
|
-
on?: Record<string,
|
|
128
|
-
after?: Record<string,
|
|
129
|
-
always?:
|
|
130
|
-
choice?:
|
|
147
|
+
on?: Record<string, TransitionConfigJSON | TransitionConfigJSON[]>;
|
|
148
|
+
after?: Record<string, TransitionConfigJSON | TransitionConfigJSON[]>;
|
|
149
|
+
always?: TransitionConfigJSON | TransitionConfigJSON[];
|
|
150
|
+
choice?: ChoiceBranchJSON[] | ResolvableJSON;
|
|
131
151
|
/**
|
|
132
152
|
* JSON route config. Unlike the authoring API (a function), the JSON layer
|
|
133
153
|
* allows an object form whose `guard` may be a named guard reference (string)
|
|
@@ -139,16 +159,16 @@ export interface StateNodeJSON {
|
|
|
139
159
|
meta?: MetaObject;
|
|
140
160
|
guard?: string;
|
|
141
161
|
input?: Record<string, unknown>;
|
|
142
|
-
};
|
|
162
|
+
} | ResolvableJSON;
|
|
143
163
|
invoke?: InvokeJSON | InvokeJSON[];
|
|
144
|
-
entry?: ActionJSON[];
|
|
145
|
-
exit?: ActionJSON[];
|
|
164
|
+
entry?: ActionJSON | ActionJSON[];
|
|
165
|
+
exit?: ActionJSON | ActionJSON[];
|
|
146
166
|
meta?: MetaObject;
|
|
147
167
|
description?: string;
|
|
148
168
|
tags?: string[];
|
|
149
169
|
input?: unknown;
|
|
150
|
-
timeout?: number | string;
|
|
151
|
-
onTimeout?:
|
|
170
|
+
timeout?: number | string | ResolvableJSON;
|
|
171
|
+
onTimeout?: TransitionConfigJSON | TransitionConfigJSON[];
|
|
152
172
|
history?: 'shallow' | 'deep';
|
|
153
173
|
target?: string;
|
|
154
174
|
output?: unknown;
|
|
@@ -156,22 +176,33 @@ export interface StateNodeJSON {
|
|
|
156
176
|
_scxmlDonedata?: ScxmlDonedataJSON;
|
|
157
177
|
}
|
|
158
178
|
export interface MachineJSON extends StateNodeJSON {
|
|
179
|
+
'@exprLang'?: string;
|
|
159
180
|
version?: string;
|
|
160
|
-
actions?: Record<string,
|
|
161
|
-
guards?: Record<string,
|
|
181
|
+
actions?: Record<string, ActionJSON | ActionJSON[]>;
|
|
182
|
+
guards?: Record<string, {
|
|
183
|
+
when: ConditionJSON;
|
|
184
|
+
}>;
|
|
162
185
|
actorSources?: Record<string, unknown>;
|
|
163
|
-
delays?: Record<string,
|
|
186
|
+
delays?: Record<string, number | string | {
|
|
187
|
+
duration: number | string | ResolvableJSON;
|
|
188
|
+
}>;
|
|
164
189
|
schemas?: Record<string, unknown>;
|
|
165
190
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
191
|
+
type EvaluatorSlot = 'context' | 'guard' | 'choice' | 'action' | 'actionParams' | 'transition' | 'input' | 'output' | 'delay' | 'transitionContext' | 'unknown';
|
|
192
|
+
type EvaluatorKind = 'expr' | 'code';
|
|
193
|
+
interface EvaluatorArgs {
|
|
194
|
+
source: string;
|
|
195
|
+
kind: EvaluatorKind;
|
|
196
|
+
slot: EvaluatorSlot;
|
|
197
|
+
scope: Record<string, unknown>;
|
|
198
|
+
path: string;
|
|
169
199
|
}
|
|
170
200
|
interface MachineImplementations {
|
|
171
201
|
actions?: Record<string, (...args: any[]) => unknown>;
|
|
172
202
|
guards?: Record<string, (...args: any[]) => boolean>;
|
|
173
203
|
actorSources?: Record<string, AnyActorLogic>;
|
|
174
204
|
delays?: Record<string, number | ((...args: any[]) => number)>;
|
|
205
|
+
evaluators?: Record<string, (args: EvaluatorArgs) => unknown>;
|
|
175
206
|
}
|
|
176
207
|
export declare function createMachineFromConfig(json: MachineJSON, implementations?: MachineImplementations): AnyStateMachine;
|
|
177
208
|
export {};
|
|
@@ -4,7 +4,7 @@ export { Actor, createActor, type RequiredActorOptionsKeys as RequiredActorOptio
|
|
|
4
4
|
export { createMachine, createStateConfig } from "./createMachine.js";
|
|
5
5
|
export { createMachineFromConfig } from "./createMachineFromConfig.js";
|
|
6
6
|
export type { ActionJSON, GuardJSON, InvokeJSON, MachineJSON, StateNodeJSON, TransitionJSON } from "./createMachineFromConfig.js";
|
|
7
|
-
export { machineConfigToJSON, serializeMachine, type CodeExpression
|
|
7
|
+
export { machineConfigToJSON, serializeMachine, type CodeExpression } from "./serialize.js";
|
|
8
8
|
export { mapState } from "./mapState.js";
|
|
9
9
|
export { types, isTypeSchema, type StandardSchemaV1, type TypeSchema } from "./schema.types.js";
|
|
10
10
|
export { createSystem, setup } from "./setup.js";
|
|
@@ -4,34 +4,20 @@
|
|
|
4
4
|
* `machineConfigToJSON` converts a machine config into a JSON-safe structure
|
|
5
5
|
* (the `MachineJSON` shape accepted by `createMachineFromConfig`). The boundary
|
|
6
6
|
* between serializable structure and runtime implementations is explicit:
|
|
7
|
-
* functions are represented as code
|
|
8
|
-
* schemas, and other non-
|
|
9
|
-
* "$unserializable": <kind> }` marker rather than silently dropped.
|
|
10
|
-
*
|
|
11
|
-
* A machine definition is fully portable iff its JSON contains no
|
|
12
|
-
* `$unserializable` markers; reviving a definition that has markers requires
|
|
13
|
-
* re-providing those implementations (e.g. via `machine.provide(...)` or the
|
|
14
|
-
* `actions`/`guards`/`actorSources` maps on `createMachineFromConfig`
|
|
15
|
-
* revival).
|
|
7
|
+
* functions are represented as `@code` source objects, while actor logic,
|
|
8
|
+
* runtime schemas, and other non-data runtime values are omitted.
|
|
16
9
|
*/
|
|
17
10
|
import type { AnyStateMachine } from "./types.js";
|
|
18
|
-
export interface UnserializableMarker {
|
|
19
|
-
$unserializable: 'function' | 'actor' | 'schema' | 'value';
|
|
20
|
-
/** Best-effort identifier (function name, actor logic id) for diagnostics. */
|
|
21
|
-
id?: string;
|
|
22
|
-
}
|
|
23
11
|
export interface CodeExpression {
|
|
24
|
-
'@
|
|
25
|
-
lang: 'ts';
|
|
26
|
-
expr: string;
|
|
12
|
+
'@code': string;
|
|
13
|
+
'@lang': 'ts';
|
|
27
14
|
}
|
|
28
15
|
/**
|
|
29
16
|
* Returns the JSON-serializable definition of a machine.
|
|
30
17
|
*
|
|
31
|
-
* Inline functions are represented as `{ "@
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* JSON config (lossless round-trip):
|
|
18
|
+
* Inline functions are represented as `{ "@code": string, "@lang": "ts" }`. A
|
|
19
|
+
* machine created via `createMachineFromConfig` returns its original JSON
|
|
20
|
+
* config (lossless round-trip):
|
|
35
21
|
*
|
|
36
22
|
* ```ts
|
|
37
23
|
* import { serializeMachine, createMachineFromConfig } from 'xstate';
|
|
@@ -45,6 +31,6 @@ export interface CodeExpression {
|
|
|
45
31
|
export declare function serializeMachine(machine: AnyStateMachine): Record<string, unknown>;
|
|
46
32
|
/**
|
|
47
33
|
* Converts a machine config (as passed to `createMachine`) to its JSON-safe
|
|
48
|
-
* definition.
|
|
34
|
+
* definition.
|
|
49
35
|
*/
|
|
50
36
|
export declare function machineConfigToJSON(config: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -4,7 +4,7 @@ import { type Actor, type RequiredActorOptionsKeys } from "./createActor.js";
|
|
|
4
4
|
import { AnyActorRef, AnyActorLogic, ActorRefFromLogic, AnyStateNode, EventObject, AnyEventObject, EventDescriptor, ExtractEvent, MachineContext, ProvidedActor, RoutableStateId, StateSchema, StateValue, ToChildren, MetaObject, Cast, Compute, EnqueueObject, SystemRegistry, RegistryKeyForLogic, ActorOptions, Observer, Subscription, OutputArg } from "./types.js";
|
|
5
5
|
import { AnyActorSystem } from "./system.js";
|
|
6
6
|
import { InspectionEvent } from "./inspection.js";
|
|
7
|
-
import { DelayMapFromNames, InferChildren, Implementations, InferOutput, InferEvents, Next_MachineConfig, Next_StateNodeConfig, WithDefault } from "./types.v6.js";
|
|
7
|
+
import { ActionSchemas, DelayMapFromNames, GuardSchemas, InferChildren, InferActions, InferGuards, Implementations, InferOutput, InferEvents, Next_MachineConfig, Next_StateNodeConfig, WithDefault } from "./types.v6.js";
|
|
8
8
|
export type SetupConfig<TSchemas extends SetupSchemas, TStates extends Record<string, SetupStateSchema>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
9
9
|
schemas?: TSchemas & SetupSchemas;
|
|
10
10
|
states?: TStates;
|
|
@@ -57,6 +57,8 @@ export type SetupStateSchemas = {
|
|
|
57
57
|
export type SetupSchemas = {
|
|
58
58
|
context?: StandardSchemaV1;
|
|
59
59
|
events?: Record<string, StandardSchemaV1>;
|
|
60
|
+
actions?: ActionSchemas;
|
|
61
|
+
guards?: GuardSchemas;
|
|
60
62
|
emitted?: Record<string, StandardSchemaV1>;
|
|
61
63
|
input?: StandardSchemaV1;
|
|
62
64
|
output?: StandardSchemaV1;
|
|
@@ -71,7 +73,9 @@ export interface SetupStateSchema {
|
|
|
71
73
|
}
|
|
72
74
|
type SetupSchema<TSchemas, TKey extends keyof SetupSchemas> = TKey extends keyof TSchemas ? TSchemas[TKey] extends StandardSchemaV1 ? TSchemas[TKey] : never : never;
|
|
73
75
|
type SetupSchemaMap<TSchemas, TKey extends 'events' | 'emitted' | 'children'> = TKey extends keyof TSchemas ? TSchemas[TKey] extends Record<string, StandardSchemaV1> ? TSchemas[TKey] : never : never;
|
|
74
|
-
type
|
|
76
|
+
type SetupActionSchemaMap<TSchemas> = 'actions' extends keyof TSchemas ? TSchemas['actions'] extends ActionSchemas ? TSchemas['actions'] : never : never;
|
|
77
|
+
type SetupGuardSchemaMap<TSchemas> = 'guards' extends keyof TSchemas ? TSchemas['guards'] extends GuardSchemas ? TSchemas['guards'] : never : never;
|
|
78
|
+
type SetupOrConfigSchema<TSchemas, TKey extends Exclude<keyof SetupSchemas, 'events' | 'actions' | 'guards' | 'emitted' | 'children'>, TConfigSchema extends StandardSchemaV1> = [SetupSchema<TSchemas, TKey>] extends [never] ? TConfigSchema : SetupSchema<TSchemas, TKey>;
|
|
75
79
|
type SetupOrConfigSchemaMap<TSchemas, TKey extends 'events' | 'emitted' | 'children', TConfigSchemaMap extends Record<string, StandardSchemaV1>> = [SetupSchemaMap<TSchemas, TKey>] extends [never] ? TConfigSchemaMap : SetupSchemaMap<TSchemas, TKey>;
|
|
76
80
|
type SetupStateKeys<TStateSchemas extends Record<string, SetupStateSchema>> = keyof TStateSchemas & string;
|
|
77
81
|
type SetupStateKey<TStateSchemas extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStateSchemas> ? string : [SetupStateKeys<TStateSchemas>] extends [never] ? string : SetupStateKeys<TStateSchemas>;
|
|
@@ -115,6 +119,12 @@ type SetupMeta<TSchemas, TMetaSchema extends StandardSchemaV1> = [
|
|
|
115
119
|
SetupSchema<TSchemas, 'meta'>
|
|
116
120
|
] extends [never] ? InferOutput<TMetaSchema, MetaObject> : InferOutput<SetupSchema<TSchemas, 'meta'>, MetaObject>;
|
|
117
121
|
type SetupChildren<TSchemas, TChildrenSchemaMap extends Record<string, StandardSchemaV1>> = [SetupSchemaMap<TSchemas, 'children'>] extends [never] ? InferChildren<TChildrenSchemaMap> : InferChildren<SetupSchemaMap<TSchemas, 'children'>>;
|
|
122
|
+
type SetupActions<TSchemas, TActionMap extends Implementations['actions']> = [
|
|
123
|
+
SetupActionSchemaMap<TSchemas>
|
|
124
|
+
] extends [never] ? TActionMap : MergeImplementationMaps<InferActions<SetupActionSchemaMap<TSchemas>>, TActionMap>;
|
|
125
|
+
type SetupGuards<TSchemas, TGuardMap extends Implementations['guards']> = [
|
|
126
|
+
SetupGuardSchemaMap<TSchemas>
|
|
127
|
+
] extends [never] ? TGuardMap : MergeImplementationMaps<InferGuards<SetupGuardSchemaMap<TSchemas>>, TGuardMap>;
|
|
118
128
|
type MergeChildren<TChildren extends Record<string, AnyActorRef | undefined>, TActor extends ProvidedActor> = [keyof TChildren] extends [never] ? Compute<ToChildren<TActor>> : Compute<TChildren>;
|
|
119
129
|
type MergeImplementationMaps<TBase extends Record<string, unknown>, TExtension extends Record<string, unknown>> = Compute<TBase & TExtension>;
|
|
120
130
|
type DelayNamesFromConfigOrString<TConfig> = TConfig extends {
|
|
@@ -212,22 +222,22 @@ type SetupMachineConfig<TStateSchemas extends Record<string, SetupStateSchema>,
|
|
|
212
222
|
initial?: SetupStateKey<TStateSchemas> | InitialTransitionWithInput<TStateSchemas, TContext, TEvent> | undefined;
|
|
213
223
|
on?: StateTransitions<TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
214
224
|
always?: StateTransitionConfigOrTarget<TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
215
|
-
states?: StatesWithInput<TStateSchemas, TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TChildren, TDelays, TTag, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
225
|
+
states?: StatesWithInput<TStateSchemas, TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TChildren, TDelays, TTag, SetupOutput<TSchemas, TOutputSchema>, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
216
226
|
};
|
|
217
227
|
/** States config type that provides typed input for known states */
|
|
218
|
-
type StatesWithInput<TRootStateSchemas extends Record<string, SetupStateSchema>, TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = {
|
|
219
|
-
[K in keyof TStateSchemas & string]?: StateNodeConfigWithNestedInput<TRootStateSchemas, TStateSchemas[K], TContext, TContextShape, TEvent, TChildren, TDelays, TTag, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
228
|
+
type StatesWithInput<TRootStateSchemas extends Record<string, SetupStateSchema>, TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = {
|
|
229
|
+
[K in keyof TStateSchemas & string]?: StateNodeConfigWithNestedInput<TRootStateSchemas, TStateSchemas[K], TContext, TContextShape, TEvent, TChildren, TDelays, TTag, TOutput, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
220
230
|
};
|
|
221
231
|
/** State node config that recursively applies typed input for nested states */
|
|
222
|
-
type StateNodeConfigWithNestedInput<TSiblingStateSchemas extends Record<string, SetupStateSchema>, TStateSchema extends SetupStateSchema, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = WithNestedStates<Omit<Next_StateNodeConfig<StateContext<TStateSchema, TContext>, TEvent, TDelays, TTag,
|
|
232
|
+
type StateNodeConfigWithNestedInput<TSiblingStateSchemas extends Record<string, SetupStateSchema>, TStateSchema extends SetupStateSchema, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = WithNestedStates<Omit<Next_StateNodeConfig<StateContext<TStateSchema, TContext>, TEvent, TDelays, TTag, TOutput, TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, StateInput<TStateSchema>, Record<string, unknown>, TSystemRegistry>, 'on' | 'always' | 'initial'> & {
|
|
223
233
|
initial?: TStateSchema['states'] extends Record<string, SetupStateSchema> ? SetupStateKey<TStateSchema['states']> | InitialTransitionWithInput<TStateSchema['states'], StateContext<TStateSchema, TContext>, TEvent> : string | {
|
|
224
234
|
target: string;
|
|
225
235
|
input?: Record<string, unknown>;
|
|
226
236
|
} | undefined;
|
|
227
237
|
on?: StateTransitions<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, StateContextShape<TStateSchema, TContextShape>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
228
238
|
always?: StateTransitionConfigOrTarget<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, StateContextShape<TStateSchema, TContextShape>, TEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
229
|
-
}, TStateSchema['states'] extends Record<string, SetupStateSchema> ? StatesWithInput<TStateSchema['states'], TStateSchema['states'], TContext, StateContextShape<TStateSchema, TContextShape>, TEvent, TChildren, TDelays, TTag, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry> : {
|
|
230
|
-
[K in string]?: Next_StateNodeConfig<TContext, TEvent, TDelays, TTag,
|
|
239
|
+
}, TStateSchema['states'] extends Record<string, SetupStateSchema> ? StatesWithInput<TStateSchema['states'], TStateSchema['states'], TContext, StateContextShape<TStateSchema, TContextShape>, TEvent, TChildren, TDelays, TTag, TOutput, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry> : {
|
|
240
|
+
[K in string]?: Next_StateNodeConfig<TContext, TEvent, TDelays, TTag, TOutput, TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, undefined, Record<string, unknown>, TSystemRegistry>;
|
|
231
241
|
}>;
|
|
232
242
|
type StateTransitions<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = {
|
|
233
243
|
[K in EventDescriptor<TEvent>]?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, ExtractEvent<TEvent, K>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
@@ -305,11 +315,13 @@ export interface SetupReturn<TStates extends Record<string, SetupStateSchema> =
|
|
|
305
315
|
/** Extends the setup configuration */
|
|
306
316
|
extend<const TExtendSchemas extends SetupSchemas = {}, const TExtendStates extends Record<string, SetupStateSchema> = {}, TExtendActionMap extends Implementations['actions'] = {}, TExtendActorMap extends Implementations['actorSources'] = {}, TExtendGuardMap extends Implementations['guards'] = {}, TExtendDelayMap extends Implementations['delays'] = {}>(config: SetupConfig<TExtendSchemas, TExtendStates, TExtendActionMap, TExtendActorMap, TExtendGuardMap, TExtendDelayMap>): SetupReturn<MergeImplementationMaps<TStates, TExtendStates>, MergeImplementationMaps<TSchemas, TExtendSchemas>, MergeImplementationMaps<TSetupActionMap, TExtendActionMap>, MergeImplementationMaps<TSetupActorMap, TExtendActorMap>, MergeImplementationMaps<TSetupGuardMap, TExtendGuardMap>, MergeImplementationMaps<TSetupDelayMap, TExtendDelayMap>, TSetupDelays | Extract<keyof TExtendDelayMap, string>, TSystemRegistry>;
|
|
307
317
|
/** Creates a state machine with the setup configuration */
|
|
308
|
-
createMachine<TContextSchema extends StandardSchemaV1 = StandardSchemaV1, const TEventSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1, TTagSchema extends StandardSchemaV1 = StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, _TEvent extends EventObject = EventObject, TActor extends ProvidedActor = ProvidedActor, TActionMap extends Implementations['actions'] = {}, TActorMap extends Implementations['actorSources'] = {}, TGuardMap extends Implementations['guards'] = {}, TDelayMap extends Implementations['delays'] = {}, TDelays extends string = Extract<keyof TDelayMap, string>, TTag extends SetupTags<TSchemas, TTagSchema> = SetupTags<TSchemas, TTagSchema>, TInput = unknown, TConfig extends SetupMachineConfig<TStates, TSchemas, TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap, SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap>, Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TSetupDelays | TDelays, TTag, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, MergeImplementationMaps<
|
|
318
|
+
createMachine<TContextSchema extends StandardSchemaV1 = StandardSchemaV1, const TEventSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1, TTagSchema extends StandardSchemaV1 = StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, const TActionSchemaMap extends ActionSchemas = {}, const TGuardSchemaMap extends GuardSchemas = {}, _TEvent extends EventObject = EventObject, TActor extends ProvidedActor = ProvidedActor, TActionMap extends Implementations['actions'] = {}, TActorMap extends Implementations['actorSources'] = {}, TGuardMap extends Implementations['guards'] = {}, TDelayMap extends Implementations['delays'] = {}, TDelays extends string = Extract<keyof TDelayMap, string>, TTag extends SetupTags<TSchemas, TTagSchema> = SetupTags<TSchemas, TTagSchema>, TInput = unknown, TConfig extends SetupMachineConfig<TStates, TSchemas, TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap, SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap>, Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TSetupDelays | TDelays, TTag, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, MergeImplementationMaps<SetupActions<TSchemas, TSetupActionMap>, MergeImplementationMaps<InferActions<TActionSchemaMap>, TActionMap>>, MergeImplementationMaps<TSetupActorMap, TActorMap>, MergeImplementationMaps<SetupGuards<TSchemas, TSetupGuardMap>, MergeImplementationMaps<InferGuards<TGuardSchemaMap>, TGuardMap>>, MergeImplementationMaps<TSetupDelayMap, TDelayMap>, TSystemRegistry, SetupContextRequired<TSchemas, TContextSchema>, TDelays, TActionMap, TActorMap, TGuardMap> = SetupMachineConfig<TStates, TSchemas, TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap, SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap>, Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TSetupDelays | TDelays, TTag, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, MergeImplementationMaps<SetupActions<TSchemas, TSetupActionMap>, MergeImplementationMaps<InferActions<TActionSchemaMap>, TActionMap>>, MergeImplementationMaps<TSetupActorMap, TActorMap>, MergeImplementationMaps<SetupGuards<TSchemas, TSetupGuardMap>, MergeImplementationMaps<InferGuards<TGuardSchemaMap>, TGuardMap>>, MergeImplementationMaps<TSetupDelayMap, TDelayMap>, TSystemRegistry, SetupContextRequired<TSchemas, TContextSchema>, TDelays, TActionMap, TActorMap, TGuardMap>>(config: {
|
|
309
319
|
schemas?: {
|
|
310
320
|
events?: TEventSchemaMap;
|
|
311
321
|
context?: TContextSchema;
|
|
312
322
|
emitted?: TEmittedSchemaMap;
|
|
323
|
+
actions?: TActionSchemaMap;
|
|
324
|
+
guards?: TGuardSchemaMap;
|
|
313
325
|
input?: TInputSchema;
|
|
314
326
|
output?: TOutputSchema;
|
|
315
327
|
meta?: TMetaSchema;
|
|
@@ -325,9 +337,9 @@ export interface SetupReturn<TStates extends Record<string, SetupStateSchema> =
|
|
|
325
337
|
to: RoutableStateId<Cast<TConfig, StateSchema>>;
|
|
326
338
|
}), Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, StateValue, TTag & string, [
|
|
327
339
|
SetupSchema<TSchemas, 'input'>
|
|
328
|
-
] extends [never] ? TInput : SetupInput<TSchemas, TInputSchema>, SetupOutput<TSchemas, TOutputSchema>, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, MergeStateSchema<Cast<TConfig, StateSchema>, SetupStatesToStateSchema<TStates>>, MergeImplementationMaps<
|
|
340
|
+
] extends [never] ? TInput : SetupInput<TSchemas, TInputSchema>, SetupOutput<TSchemas, TOutputSchema>, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, MergeStateSchema<Cast<TConfig, StateSchema>, SetupStatesToStateSchema<TStates>>, MergeImplementationMaps<SetupActions<TSchemas, TSetupActionMap>, MergeImplementationMaps<InferActions<TActionSchemaMap>, TActionMap>>, MergeImplementationMaps<TSetupActorMap, TActorMap>, MergeImplementationMaps<SetupGuards<TSchemas, TSetupGuardMap>, MergeImplementationMaps<InferGuards<TGuardSchemaMap>, TGuardMap>>, DelayMapFromNames<TSetupDelays | TDelays, MergeImplementationMaps<TSetupDelayMap, TDelayMap>>>;
|
|
329
341
|
/** Creates a state node config with the setup configuration */
|
|
330
|
-
createStateConfig<const TConfig extends StateNodeConfigWithNestedInput<TStates, SetupStateSchema, SetupContext<TSchemas, StandardSchemaV1>, SetupContextShape<TSchemas, StandardSchemaV1, SetupContext<TSchemas, StandardSchemaV1>>, SetupEvents<TSchemas, Record<string, StandardSchemaV1>>, Cast<SetupChildren<TSchemas, Record<string, StandardSchemaV1>>, Record<string, AnyActorRef | undefined>>, string, SetupTags<TSchemas, StandardSchemaV1>, SetupEmitted<TSchemas, Record<string, StandardSchemaV1>>, SetupMeta<TSchemas, StandardSchemaV1>,
|
|
342
|
+
createStateConfig<const TConfig extends StateNodeConfigWithNestedInput<TStates, SetupStateSchema, SetupContext<TSchemas, StandardSchemaV1>, SetupContextShape<TSchemas, StandardSchemaV1, SetupContext<TSchemas, StandardSchemaV1>>, SetupEvents<TSchemas, Record<string, StandardSchemaV1>>, Cast<SetupChildren<TSchemas, Record<string, StandardSchemaV1>>, Record<string, AnyActorRef | undefined>>, string, SetupTags<TSchemas, StandardSchemaV1>, SetupOutput<TSchemas, StandardSchemaV1>, SetupEmitted<TSchemas, Record<string, StandardSchemaV1>>, SetupMeta<TSchemas, StandardSchemaV1>, SetupActions<TSchemas, TSetupActionMap>, TSetupActorMap, SetupGuards<TSchemas, TSetupGuardMap>, TSetupDelayMap, TSystemRegistry>>(config: TConfig): TConfig;
|
|
331
343
|
/** State input schemas from setup config */
|
|
332
344
|
states: TStates;
|
|
333
345
|
}
|
|
@@ -339,13 +351,13 @@ type SetupConfigStates<TConfig> = TConfig extends {
|
|
|
339
351
|
} ? TStates extends Record<string, SetupStateSchema> ? TStates : Record<string, SetupStateSchema> : Record<string, SetupStateSchema>;
|
|
340
352
|
type SetupConfigActions<TConfig> = TConfig extends {
|
|
341
353
|
actions?: infer TActions;
|
|
342
|
-
} ? TActions extends Implementations['actions'] ? TActions : {} : {}
|
|
354
|
+
} ? TActions extends Implementations['actions'] ? MergeImplementationMaps<SetupActions<SetupConfigSchemas<TConfig>, {}>, TActions> : SetupActions<SetupConfigSchemas<TConfig>, {}> : SetupActions<SetupConfigSchemas<TConfig>, {}>;
|
|
343
355
|
type SetupConfigActorSources<TConfig> = TConfig extends {
|
|
344
356
|
actorSources?: infer TActorSources;
|
|
345
357
|
} ? TActorSources extends Implementations['actorSources'] ? TActorSources : {} : {};
|
|
346
358
|
type SetupConfigGuards<TConfig> = TConfig extends {
|
|
347
359
|
guards?: infer TGuards;
|
|
348
|
-
} ? TGuards extends Implementations['guards'] ? TGuards : {} : {}
|
|
360
|
+
} ? TGuards extends Implementations['guards'] ? MergeImplementationMaps<SetupGuards<SetupConfigSchemas<TConfig>, {}>, TGuards> : SetupGuards<SetupConfigSchemas<TConfig>, {}> : SetupGuards<SetupConfigSchemas<TConfig>, {}>;
|
|
349
361
|
type SetupConfigDelays<TConfig> = TConfig extends {
|
|
350
362
|
delays?: infer TDelays;
|
|
351
363
|
} ? TDelays extends Implementations['delays'] ? TDelays : {} : {};
|
|
@@ -40,7 +40,9 @@ export declare function getTransitionResult(transition: Pick<AnyTransitionDefini
|
|
|
40
40
|
reenter?: AnyTransitionDefinition['reenter'];
|
|
41
41
|
input?: AnyTransitionDefinition['input'];
|
|
42
42
|
context?: AnyTransitionDefinition['context'];
|
|
43
|
-
}, snapshot: AnyMachineSnapshot, event: AnyEventObject, actorScope: AnyActorScope
|
|
43
|
+
}, snapshot: AnyMachineSnapshot, event: AnyEventObject, actorScope: AnyActorScope, options?: {
|
|
44
|
+
resolveActions?: boolean;
|
|
45
|
+
}): {
|
|
44
46
|
targets: Readonly<AnyStateNode[]> | undefined;
|
|
45
47
|
context: MachineContext | undefined;
|
|
46
48
|
actions: AnyAction[] | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { AnyAction, AnyActorScope, AnyEventObject, AnyMachineSnapshot, EnqueueObject, EventObject, ExecutableActionObject, SpecialExecutableAction } from "./types.js";
|
|
2
|
-
export declare function createTransitionEnqueue(actorScope: AnyActorScope, actions: any[], internalEvents: EventObject[], actorSubscriptions?: boolean): EnqueueObject<any, any>;
|
|
2
|
+
export declare function createTransitionEnqueue(actorScope: AnyActorScope, actions: any[], internalEvents: EventObject[], actorSubscriptions?: boolean, createActors?: boolean): EnqueueObject<any, any>;
|
|
3
3
|
export declare function isBuiltInExecutableAction(action: ExecutableActionObject): action is SpecialExecutableAction;
|
|
4
4
|
export declare function resolveActionsWithContext(currentSnapshot: AnyMachineSnapshot, event: AnyEventObject, actorScope: AnyActorScope, actions: AnyAction[]): [AnyMachineSnapshot, ExecutableActionObject[]];
|
|
@@ -679,6 +679,10 @@ export interface ActorRef<TSnapshot extends Snapshot<unknown>, TEvent extends Ev
|
|
|
679
679
|
type: TType;
|
|
680
680
|
})) => void) => Subscription;
|
|
681
681
|
}
|
|
682
|
+
type EventPayload<TEvent extends EventObject, TType extends TEvent['type']> = HomomorphicOmit<ExtractEvent<TEvent, TType>, 'type'>;
|
|
683
|
+
export type ActorTrigger<TEvent extends EventObject> = {
|
|
684
|
+
[K in TEvent['type']]: {} extends EventPayload<TEvent, K> ? () => void : (payload: EventPayload<TEvent, K>) => void;
|
|
685
|
+
};
|
|
682
686
|
/**
|
|
683
687
|
* Runtime-only actor capabilities.
|
|
684
688
|
*
|
|
@@ -687,7 +691,7 @@ export interface ActorRef<TSnapshot extends Snapshot<unknown>, TEvent extends Ev
|
|
|
687
691
|
* genuinely need lifecycle control such as starting, stopping, or accessing
|
|
688
692
|
* system-owned runtime state.
|
|
689
693
|
*/
|
|
690
|
-
export interface ActorRuntime<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, _TEmitted extends EventObject = EventObject> {
|
|
694
|
+
export interface ActorRuntime<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, _TEmitted extends EventObject = EventObject, TSendEvent extends EventObject = TEvent> {
|
|
691
695
|
/** The unique identifier for this actor relative to its parent. */
|
|
692
696
|
id: string;
|
|
693
697
|
/**
|
|
@@ -704,7 +708,7 @@ export interface ActorRuntime<TSnapshot extends Snapshot<unknown>, TEvent extend
|
|
|
704
708
|
_parent?: any;
|
|
705
709
|
system: any;
|
|
706
710
|
src: string | AnyActorLogic;
|
|
707
|
-
trigger:
|
|
711
|
+
trigger: ActorTrigger<TSendEvent>;
|
|
708
712
|
select<TSelected>(selector: (snapshot: TSnapshot) => TSelected, equalityFn?: (a: TSelected, b: TSelected) => boolean): Readable<TSelected>;
|
|
709
713
|
}
|
|
710
714
|
/**
|
|
@@ -714,7 +718,7 @@ export interface ActorRuntime<TSnapshot extends Snapshot<unknown>, TEvent extend
|
|
|
714
718
|
* lifecycle capabilities. Values returned by `createActor(...)` and
|
|
715
719
|
* `spawn(...)` naturally satisfy narrower `ActorRef` contracts.
|
|
716
720
|
*/
|
|
717
|
-
export interface ActorInstance<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TEmitted extends EventObject = EventObject, TSendEvent extends EventObject = TEvent> extends ActorRuntime<TSnapshot, TEvent, TEmitted>, ActorRef<TSnapshot, TEvent, TEmitted, TSendEvent> {
|
|
721
|
+
export interface ActorInstance<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TEmitted extends EventObject = EventObject, TSendEvent extends EventObject = TEvent> extends ActorRuntime<TSnapshot, TEvent, TEmitted, TSendEvent>, ActorRef<TSnapshot, TEvent, TEmitted, TSendEvent> {
|
|
718
722
|
}
|
|
719
723
|
/**
|
|
720
724
|
* The actor's own full self handle.
|
|
@@ -723,7 +727,7 @@ export interface ActorInstance<TSnapshot extends Snapshot<unknown>, TEvent exten
|
|
|
723
727
|
* can participate in runtime-owned behavior while still being usable wherever
|
|
724
728
|
* an `ActorRef` is expected.
|
|
725
729
|
*/
|
|
726
|
-
export type ActorSelf<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TEmitted extends EventObject = EventObject, TSendEvent extends EventObject = TEvent> = ActorRuntime<TSnapshot, TEvent, TEmitted> & ActorRef<TSnapshot, TEvent, TEmitted, TSendEvent>;
|
|
730
|
+
export type ActorSelf<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TEmitted extends EventObject = EventObject, TSendEvent extends EventObject = TEvent> = ActorRuntime<TSnapshot, TEvent, TEmitted, TSendEvent> & ActorRef<TSnapshot, TEvent, TEmitted, TSendEvent>;
|
|
727
731
|
export type ActorRefFrom<T> = T extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer TStateValue, infer TTag, infer _TInput, infer TOutput, infer TEmitted, infer TMeta, infer TConfig, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap> ? TConfig extends {
|
|
728
732
|
internalEvents?: readonly EventDescriptor<TEvent>[];
|
|
729
733
|
} ? ActorRef<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, any>, TEvent, TEmitted, ExcludeInternalEvents<TEvent, TConfig['internalEvents'] extends readonly EventDescriptor<TEvent>[] ? TConfig['internalEvents'] extends readonly (infer TDesc)[] ? Extract<TDesc, string> : never : never>> : ActorRef<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, any>, TEvent, TEmitted> : T extends Promise<infer U> ? ActorRefFrom<AsyncActorLogic<U>> : T extends ActorLogic<infer TSnapshot, infer TEvent, infer _TInput, infer _TSystem, infer TEmitted> ? ActorRef<TSnapshot, TEvent, TEmitted> : never;
|
|
@@ -11,7 +11,9 @@ export type InferOutput<T extends StandardSchemaV1, U> = Compute<StandardSchemaV
|
|
|
11
11
|
* are required on the event.
|
|
12
12
|
*/
|
|
13
13
|
export type InferEvents<TEventSchemaMap extends Record<string, StandardSchemaV1>> = Values<{
|
|
14
|
-
[K in keyof TEventSchemaMap & string]: StandardSchemaV1.InferOutput<TEventSchemaMap[K]> extends infer O ? unknown extends O ? O & {
|
|
14
|
+
[K in keyof TEventSchemaMap & string]: StandardSchemaV1.InferOutput<TEventSchemaMap[K]> extends infer O ? [O] extends [never] ? never : unknown extends O ? O & {
|
|
15
|
+
type: K;
|
|
16
|
+
} : [O] extends [void] ? {
|
|
15
17
|
type: K;
|
|
16
18
|
} : string extends keyof O ? [O[string]] extends [never] ? {
|
|
17
19
|
type: K;
|
|
@@ -24,6 +26,21 @@ export type InferEvents<TEventSchemaMap extends Record<string, StandardSchemaV1>
|
|
|
24
26
|
export type InferChildren<TChildrenSchemaMap extends Record<string, StandardSchemaV1>> = string extends keyof TChildrenSchemaMap ? {} : {
|
|
25
27
|
[K in keyof TChildrenSchemaMap & string]?: StandardSchemaV1.InferOutput<TChildrenSchemaMap[K]> extends AnyActorRef ? NormalizeActorRef<StandardSchemaV1.InferOutput<TChildrenSchemaMap[K]>> : never;
|
|
26
28
|
};
|
|
29
|
+
export type ActionSchemas = Record<string, {
|
|
30
|
+
params: StandardSchemaV1;
|
|
31
|
+
}>;
|
|
32
|
+
export type GuardSchemas = Record<string, {
|
|
33
|
+
params: StandardSchemaV1;
|
|
34
|
+
}>;
|
|
35
|
+
export type InferActions<TActionSchemaMap extends ActionSchemas> = string extends keyof TActionSchemaMap ? {} : {
|
|
36
|
+
[K in keyof TActionSchemaMap & string]: (params: StandardSchemaV1.InferOutput<TActionSchemaMap[K]['params']>) => void | {
|
|
37
|
+
context?: any;
|
|
38
|
+
children?: any;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export type InferGuards<TGuardSchemaMap extends GuardSchemas> = string extends keyof TGuardSchemaMap ? {} : {
|
|
42
|
+
[K in keyof TGuardSchemaMap & string]: (params: StandardSchemaV1.InferOutput<TGuardSchemaMap[K]['params']>) => boolean;
|
|
43
|
+
};
|
|
27
44
|
type OutputConfig<TContext extends MachineContext, TEvent extends EventObject, TOutput> = unknown extends TOutput ? Mapper<TContext, TEvent, NonReducibleUnknown, TEvent> | NonReducibleUnknown : Mapper<TContext, TEvent, TOutput, TEvent> | TOutput;
|
|
28
45
|
export type ValidateTopLevelFinalOutputs<TConfig, TContext extends MachineContext, TEvent extends EventObject> = TConfig extends {
|
|
29
46
|
schemas: {
|
|
@@ -71,6 +88,8 @@ export interface MachineOptions {
|
|
|
71
88
|
}
|
|
72
89
|
type MachineSchemas<TContextSchema extends StandardSchemaV1, TEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, TChildrenSchemaMap extends Record<string, StandardSchemaV1>> = {
|
|
73
90
|
events?: TEventSchemaMap;
|
|
91
|
+
actions?: ActionSchemas;
|
|
92
|
+
guards?: GuardSchemas;
|
|
74
93
|
context?: TContextSchema;
|
|
75
94
|
emitted?: TEmittedSchemaMap;
|
|
76
95
|
input?: TInputSchema;
|