xstate 5.5.1 → 5.6.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/actions/dist/xstate-actions.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.esm.js +2 -2
- package/actions/dist/xstate-actions.esm.js +2 -2
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.esm.js +1 -1
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/StateMachine.d.ts +7 -2
- package/dist/declarations/src/createActor.d.ts +8 -2
- package/dist/declarations/src/createMachine.d.ts +5 -2
- package/dist/declarations/src/setup.d.ts +2 -1
- package/dist/declarations/src/types.d.ts +3 -4
- package/dist/declarations/src/waitFor.d.ts +3 -3
- package/dist/{log-da322832.development.cjs.js → log-3552abe4.development.cjs.js} +1 -1
- package/dist/{log-742895c6.cjs.js → log-8a4f6e5c.cjs.js} +1 -1
- package/dist/{log-22b3587f.esm.js → log-a8de0b28.esm.js} +1 -1
- package/dist/{log-285f62db.development.esm.js → log-fedd0292.development.esm.js} +1 -1
- package/dist/{raise-8da27ebb.development.esm.js → raise-2fdbadc6.development.esm.js} +31 -11
- package/dist/{raise-0e64ee6e.esm.js → raise-309d511a.esm.js} +28 -8
- package/dist/{raise-ad8bb7c2.cjs.js → raise-540fdaf2.cjs.js} +28 -7
- package/dist/{raise-7af39710.development.cjs.js → raise-d7d9caaa.development.cjs.js} +31 -10
- package/dist/xstate.cjs.js +14 -8
- package/dist/xstate.development.cjs.js +14 -8
- package/dist/xstate.development.esm.js +16 -10
- package/dist/xstate.esm.js +16 -10
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StateMachine } from "./StateMachine.js";
|
|
2
2
|
import { ResolveTypegenMeta, TypegenConstraint, TypegenDisabled } from "./typegenTypes.js";
|
|
3
|
-
import { AnyActorRef, AnyEventObject, Cast, InternalMachineImplementations, IsNever, MachineConfig, MachineContext, NonReducibleUnknown, ParameterizedObject, Prop, ProvidedActor, StateValue, ToChildren } from "./types.js";
|
|
3
|
+
import { AnyActorRef, AnyEventObject, Cast, InternalMachineImplementations, IsNever, MachineConfig, MachineContext, MachineTypes, NonReducibleUnknown, ParameterizedObject, Prop, ProvidedActor, StateValue, ToChildren } from "./types.js";
|
|
4
4
|
type TestValue = string | {
|
|
5
5
|
[k: string]: TestValue | undefined;
|
|
6
6
|
};
|
|
@@ -56,5 +56,8 @@ type ToStateValue<TTestValue extends string | TestValue> = FilterLeafValues<Grou
|
|
|
56
56
|
```
|
|
57
57
|
*/
|
|
58
58
|
export declare function createMachine<TContext extends MachineContext, TEvent extends AnyEventObject, // TODO: consider using a stricter `EventObject` here
|
|
59
|
-
TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config:
|
|
59
|
+
TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: {
|
|
60
|
+
types?: MachineTypes<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TTypesMeta>;
|
|
61
|
+
schemas?: unknown;
|
|
62
|
+
} & MachineConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TTypesMeta>, implementations?: InternalMachineImplementations<TContext, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>>): StateMachine<TContext, TEvent, Cast<ToChildren<TActor>, Record<string, AnyActorRef | undefined>>, TActor, TAction, TGuard, TDelay, 'matchesStates' extends keyof TTypesMeta ? ToStateValue<Cast<TTypesMeta['matchesStates'], TestValue>> : StateValue, Prop<ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>['resolved'], 'tags'> & string, TInput, TOutput, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>>;
|
|
60
63
|
export {};
|
|
@@ -33,7 +33,8 @@ type ToStateValue<T extends StateSchema> = T extends {
|
|
|
33
33
|
type: 'parallel';
|
|
34
34
|
} ? true : false> : never) : {};
|
|
35
35
|
export declare function setup<TContext extends MachineContext, TEvent extends AnyEventObject, // TODO: consider using a stricter `EventObject` here
|
|
36
|
-
TActors extends Record<Values<TChildrenMap>, UnknownActorLogic>, TActions extends Record<string, ParameterizedObject['params'] | undefined>, TGuards extends Record<string, ParameterizedObject['params'] | undefined>, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TChildrenMap extends Record<string, string> = never>({ actors, actions, guards, delays }: {
|
|
36
|
+
TActors extends Record<Values<TChildrenMap>, UnknownActorLogic>, TActions extends Record<string, ParameterizedObject['params'] | undefined>, TGuards extends Record<string, ParameterizedObject['params'] | undefined>, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TChildrenMap extends Record<string, string> = never>({ schemas, actors, actions, guards, delays }: {
|
|
37
|
+
schemas?: unknown;
|
|
37
38
|
types?: SetupTypes<TContext, TEvent, TChildrenMap, TTag, TInput, TOutput>;
|
|
38
39
|
actors?: {
|
|
39
40
|
[K in keyof TActors]: TActors[K];
|
|
@@ -119,7 +119,7 @@ export type UnknownAction = Action<MachineContext, EventObject, EventObject, Par
|
|
|
119
119
|
export type Actions<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> = SingleOrArray<Action<TContext, TExpressionEvent, TEvent, TParams, TActor, TAction, TGuard, TDelay>>;
|
|
120
120
|
export type StateKey = string | AnyMachineSnapshot;
|
|
121
121
|
export interface StateValueMap {
|
|
122
|
-
[key: string]: StateValue;
|
|
122
|
+
[key: string]: StateValue | undefined;
|
|
123
123
|
}
|
|
124
124
|
/**
|
|
125
125
|
* The string or object representing the state value relative to the parent state node.
|
|
@@ -433,7 +433,6 @@ export type MachineConfig<TContext extends MachineContext, TEvent extends EventO
|
|
|
433
433
|
* The machine's own version.
|
|
434
434
|
*/
|
|
435
435
|
version?: string;
|
|
436
|
-
types?: MachineTypes<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TTypesMeta>;
|
|
437
436
|
output?: Mapper<TContext, DoneStateEvent, TOutput, TEvent> | TOutput;
|
|
438
437
|
}) & (MachineContext extends TContext ? {
|
|
439
438
|
context?: InitialContext<LowInfer<TContext>, TActor, TInput, TEvent>;
|
|
@@ -860,12 +859,12 @@ type ExtractLiteralString<T extends string | undefined> = T extends string ? str
|
|
|
860
859
|
type ToConcreteChildren<TActor extends ProvidedActor> = {
|
|
861
860
|
[A in TActor as ExtractLiteralString<A['id']>]?: ActorRefFrom<A['logic']>;
|
|
862
861
|
};
|
|
863
|
-
export type ToChildren<TActor extends ProvidedActor> = string extends TActor['src'] ? Record<string, AnyActorRef> :
|
|
862
|
+
export type ToChildren<TActor extends ProvidedActor> = string extends TActor['src'] ? Record<string, AnyActorRef> : ToConcreteChildren<TActor> & {
|
|
864
863
|
include: {
|
|
865
864
|
[id: string]: TActor extends any ? ActorRefFrom<TActor['logic']> | undefined : never;
|
|
866
865
|
};
|
|
867
866
|
exclude: {};
|
|
868
|
-
}[undefined extends TActor['id'] ? 'include' : string extends TActor['id'] ? 'include' : 'exclude']
|
|
867
|
+
}[undefined extends TActor['id'] ? 'include' : string extends TActor['id'] ? 'include' : 'exclude'];
|
|
869
868
|
export type StateSchema = {
|
|
870
869
|
states?: Record<string, StateSchema>;
|
|
871
870
|
};
|
|
@@ -4,15 +4,15 @@ interface WaitForOptions {
|
|
|
4
4
|
* How long to wait before rejecting, if no emitted
|
|
5
5
|
* state satisfies the predicate.
|
|
6
6
|
*
|
|
7
|
-
* @defaultValue
|
|
7
|
+
* @defaultValue Infinity
|
|
8
8
|
*/
|
|
9
9
|
timeout: number;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Subscribes to an actor ref and waits for its emitted value to satisfy
|
|
13
13
|
* a predicate, and then resolves with that value.
|
|
14
|
-
* Will throw if the desired state is not reached after
|
|
15
|
-
* (defaults to
|
|
14
|
+
* Will throw if the desired state is not reached after an optional timeout.
|
|
15
|
+
* (defaults to Infinity).
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```js
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-d7d9caaa.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
// it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
|
|
6
6
|
// but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-540fdaf2.cjs.js');
|
|
4
4
|
|
|
5
5
|
// it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
|
|
6
6
|
// but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as XSTATE_ERROR, W as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-309d511a.esm.js';
|
|
2
2
|
|
|
3
3
|
// it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
|
|
4
4
|
// but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as XSTATE_ERROR, W as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-2fdbadc6.development.esm.js';
|
|
2
2
|
|
|
3
3
|
// it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
|
|
4
4
|
// but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
|
|
@@ -270,7 +270,28 @@ function toStatePath(stateId) {
|
|
|
270
270
|
if (isArray(stateId)) {
|
|
271
271
|
return stateId;
|
|
272
272
|
}
|
|
273
|
-
|
|
273
|
+
let result = [];
|
|
274
|
+
let segment = '';
|
|
275
|
+
for (let i = 0; i < stateId.length; i++) {
|
|
276
|
+
const char = stateId.charCodeAt(i);
|
|
277
|
+
switch (char) {
|
|
278
|
+
// \
|
|
279
|
+
case 92:
|
|
280
|
+
// consume the next character
|
|
281
|
+
segment += stateId[i + 1];
|
|
282
|
+
// and skip over it
|
|
283
|
+
i++;
|
|
284
|
+
continue;
|
|
285
|
+
// .
|
|
286
|
+
case 46:
|
|
287
|
+
result.push(segment);
|
|
288
|
+
segment = '';
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
segment += stateId[i];
|
|
292
|
+
}
|
|
293
|
+
result.push(segment);
|
|
294
|
+
return result;
|
|
274
295
|
}
|
|
275
296
|
function toStateValue(stateValue) {
|
|
276
297
|
if (isMachineSnapshot(stateValue)) {
|
|
@@ -954,7 +975,6 @@ class Actor {
|
|
|
954
975
|
return this._snapshot;
|
|
955
976
|
}
|
|
956
977
|
}
|
|
957
|
-
|
|
958
978
|
/**
|
|
959
979
|
* Creates a new actor instance for the given actor logic with the provided options, if any.
|
|
960
980
|
*
|
|
@@ -987,7 +1007,7 @@ class Actor {
|
|
|
987
1007
|
* @param logic - The actor logic to create an actor from. For a state machine actor logic creator, see {@link createMachine}. Other actor logic creators include {@link fromCallback}, {@link fromEventObservable}, {@link fromObservable}, {@link fromPromise}, and {@link fromTransition}.
|
|
988
1008
|
* @param options - Actor options
|
|
989
1009
|
*/
|
|
990
|
-
function createActor(logic, options) {
|
|
1010
|
+
function createActor(logic, ...[options]) {
|
|
991
1011
|
return new Actor(logic, options);
|
|
992
1012
|
}
|
|
993
1013
|
|
|
@@ -1491,19 +1511,19 @@ function isInFinalState(stateNodeSet, stateNode) {
|
|
|
1491
1511
|
}
|
|
1492
1512
|
const isStateId = str => str[0] === STATE_IDENTIFIER;
|
|
1493
1513
|
function getCandidates(stateNode, receivedEventType) {
|
|
1494
|
-
const candidates = stateNode.transitions.get(receivedEventType) || [...stateNode.transitions.keys()].filter(
|
|
1514
|
+
const candidates = stateNode.transitions.get(receivedEventType) || [...stateNode.transitions.keys()].filter(eventDescriptor => {
|
|
1495
1515
|
// check if transition is a wildcard transition,
|
|
1496
1516
|
// which matches any non-transient events
|
|
1497
|
-
if (
|
|
1517
|
+
if (eventDescriptor === WILDCARD) {
|
|
1498
1518
|
return true;
|
|
1499
1519
|
}
|
|
1500
|
-
if (!
|
|
1520
|
+
if (!eventDescriptor.endsWith('.*')) {
|
|
1501
1521
|
return false;
|
|
1502
1522
|
}
|
|
1503
|
-
if (/.*\*.+/.test(
|
|
1504
|
-
console.warn(`Wildcards can only be the last token of an event descriptor (e.g., "event.*") or the entire event descriptor ("*"). Check the "${
|
|
1523
|
+
if (/.*\*.+/.test(eventDescriptor)) {
|
|
1524
|
+
console.warn(`Wildcards can only be the last token of an event descriptor (e.g., "event.*") or the entire event descriptor ("*"). Check the "${eventDescriptor}" event.`);
|
|
1505
1525
|
}
|
|
1506
|
-
const partialEventTokens =
|
|
1526
|
+
const partialEventTokens = eventDescriptor.split('.');
|
|
1507
1527
|
const eventTokens = receivedEventType.split('.');
|
|
1508
1528
|
for (let tokenIndex = 0; tokenIndex < partialEventTokens.length; tokenIndex++) {
|
|
1509
1529
|
const partialEventToken = partialEventTokens[tokenIndex];
|
|
@@ -1511,7 +1531,7 @@ function getCandidates(stateNode, receivedEventType) {
|
|
|
1511
1531
|
if (partialEventToken === '*') {
|
|
1512
1532
|
const isLastToken = tokenIndex === partialEventTokens.length - 1;
|
|
1513
1533
|
if (!isLastToken) {
|
|
1514
|
-
console.warn(`Infix wildcards in transition events are not allowed. Check the "${
|
|
1534
|
+
console.warn(`Infix wildcards in transition events are not allowed. Check the "${eventDescriptor}" transition.`);
|
|
1515
1535
|
}
|
|
1516
1536
|
return isLastToken;
|
|
1517
1537
|
}
|
|
@@ -2546,4 +2566,4 @@ function raise(eventOrExpr, options) {
|
|
|
2546
2566
|
return raise;
|
|
2547
2567
|
}
|
|
2548
2568
|
|
|
2549
|
-
export { $$ACTOR_TYPE as $,
|
|
2569
|
+
export { $$ACTOR_TYPE as $, createActor as A, Actor as B, interpret as C, isMachineSnapshot as D, and as E, not as F, or as G, stateIn as H, getAllOwnEventDescriptors as I, matchesState as J, pathToStateValue as K, toObserver as L, cancel as M, NULL_EVENT as N, raise as O, spawnChild as P, stop as Q, stopChild as R, STATE_DELIMITER as S, ProcessingStatus as T, cloneMachineSnapshot as U, XSTATE_ERROR as V, createErrorActorEvent as W, XSTATE_STOP as X, toTransitionConfigArray as a, formatTransition as b, createInvokeId as c, formatInitialTransition as d, evaluateGuard as e, formatTransitions as f, getDelayedTransitions as g, getCandidates as h, getAllStateNodes as i, getStateNodes as j, createMachineSnapshot as k, isInFinalState as l, mapValues as m, macrostep as n, transitionNode as o, resolveActionsAndContext as p, createInitEvent as q, resolveStateValue as r, microstep as s, toArray as t, getInitialStateNodes as u, toStatePath as v, isStateId as w, getStateNodeByPath as x, getPersistedSnapshot as y, resolveReferencedActor as z };
|
|
@@ -270,7 +270,28 @@ function toStatePath(stateId) {
|
|
|
270
270
|
if (isArray(stateId)) {
|
|
271
271
|
return stateId;
|
|
272
272
|
}
|
|
273
|
-
|
|
273
|
+
let result = [];
|
|
274
|
+
let segment = '';
|
|
275
|
+
for (let i = 0; i < stateId.length; i++) {
|
|
276
|
+
const char = stateId.charCodeAt(i);
|
|
277
|
+
switch (char) {
|
|
278
|
+
// \
|
|
279
|
+
case 92:
|
|
280
|
+
// consume the next character
|
|
281
|
+
segment += stateId[i + 1];
|
|
282
|
+
// and skip over it
|
|
283
|
+
i++;
|
|
284
|
+
continue;
|
|
285
|
+
// .
|
|
286
|
+
case 46:
|
|
287
|
+
result.push(segment);
|
|
288
|
+
segment = '';
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
segment += stateId[i];
|
|
292
|
+
}
|
|
293
|
+
result.push(segment);
|
|
294
|
+
return result;
|
|
274
295
|
}
|
|
275
296
|
function toStateValue(stateValue) {
|
|
276
297
|
if (isMachineSnapshot(stateValue)) {
|
|
@@ -940,7 +961,6 @@ class Actor {
|
|
|
940
961
|
return this._snapshot;
|
|
941
962
|
}
|
|
942
963
|
}
|
|
943
|
-
|
|
944
964
|
/**
|
|
945
965
|
* Creates a new actor instance for the given actor logic with the provided options, if any.
|
|
946
966
|
*
|
|
@@ -973,7 +993,7 @@ class Actor {
|
|
|
973
993
|
* @param logic - The actor logic to create an actor from. For a state machine actor logic creator, see {@link createMachine}. Other actor logic creators include {@link fromCallback}, {@link fromEventObservable}, {@link fromObservable}, {@link fromPromise}, and {@link fromTransition}.
|
|
974
994
|
* @param options - Actor options
|
|
975
995
|
*/
|
|
976
|
-
function createActor(logic, options) {
|
|
996
|
+
function createActor(logic, ...[options]) {
|
|
977
997
|
return new Actor(logic, options);
|
|
978
998
|
}
|
|
979
999
|
|
|
@@ -1457,16 +1477,16 @@ function isInFinalState(stateNodeSet, stateNode) {
|
|
|
1457
1477
|
}
|
|
1458
1478
|
const isStateId = str => str[0] === STATE_IDENTIFIER;
|
|
1459
1479
|
function getCandidates(stateNode, receivedEventType) {
|
|
1460
|
-
const candidates = stateNode.transitions.get(receivedEventType) || [...stateNode.transitions.keys()].filter(
|
|
1480
|
+
const candidates = stateNode.transitions.get(receivedEventType) || [...stateNode.transitions.keys()].filter(eventDescriptor => {
|
|
1461
1481
|
// check if transition is a wildcard transition,
|
|
1462
1482
|
// which matches any non-transient events
|
|
1463
|
-
if (
|
|
1483
|
+
if (eventDescriptor === WILDCARD) {
|
|
1464
1484
|
return true;
|
|
1465
1485
|
}
|
|
1466
|
-
if (!
|
|
1486
|
+
if (!eventDescriptor.endsWith('.*')) {
|
|
1467
1487
|
return false;
|
|
1468
1488
|
}
|
|
1469
|
-
const partialEventTokens =
|
|
1489
|
+
const partialEventTokens = eventDescriptor.split('.');
|
|
1470
1490
|
const eventTokens = receivedEventType.split('.');
|
|
1471
1491
|
for (let tokenIndex = 0; tokenIndex < partialEventTokens.length; tokenIndex++) {
|
|
1472
1492
|
const partialEventToken = partialEventTokens[tokenIndex];
|
|
@@ -2489,4 +2509,4 @@ function raise(eventOrExpr, options) {
|
|
|
2489
2509
|
return raise;
|
|
2490
2510
|
}
|
|
2491
2511
|
|
|
2492
|
-
export { $$ACTOR_TYPE as $,
|
|
2512
|
+
export { $$ACTOR_TYPE as $, createActor as A, Actor as B, interpret as C, isMachineSnapshot as D, and as E, not as F, or as G, stateIn as H, getAllOwnEventDescriptors as I, matchesState as J, pathToStateValue as K, toObserver as L, cancel as M, NULL_EVENT as N, raise as O, spawnChild as P, stop as Q, stopChild as R, STATE_DELIMITER as S, ProcessingStatus as T, cloneMachineSnapshot as U, XSTATE_ERROR as V, createErrorActorEvent as W, XSTATE_STOP as X, toTransitionConfigArray as a, formatTransition as b, createInvokeId as c, formatInitialTransition as d, evaluateGuard as e, formatTransitions as f, getDelayedTransitions as g, getCandidates as h, getAllStateNodes as i, getStateNodes as j, createMachineSnapshot as k, isInFinalState as l, mapValues as m, macrostep as n, transitionNode as o, resolveActionsAndContext as p, createInitEvent as q, resolveStateValue as r, microstep as s, toArray as t, getInitialStateNodes as u, toStatePath as v, isStateId as w, getStateNodeByPath as x, getPersistedSnapshot as y, resolveReferencedActor as z };
|
|
@@ -272,7 +272,28 @@ function toStatePath(stateId) {
|
|
|
272
272
|
if (isArray(stateId)) {
|
|
273
273
|
return stateId;
|
|
274
274
|
}
|
|
275
|
-
|
|
275
|
+
let result = [];
|
|
276
|
+
let segment = '';
|
|
277
|
+
for (let i = 0; i < stateId.length; i++) {
|
|
278
|
+
const char = stateId.charCodeAt(i);
|
|
279
|
+
switch (char) {
|
|
280
|
+
// \
|
|
281
|
+
case 92:
|
|
282
|
+
// consume the next character
|
|
283
|
+
segment += stateId[i + 1];
|
|
284
|
+
// and skip over it
|
|
285
|
+
i++;
|
|
286
|
+
continue;
|
|
287
|
+
// .
|
|
288
|
+
case 46:
|
|
289
|
+
result.push(segment);
|
|
290
|
+
segment = '';
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
segment += stateId[i];
|
|
294
|
+
}
|
|
295
|
+
result.push(segment);
|
|
296
|
+
return result;
|
|
276
297
|
}
|
|
277
298
|
function toStateValue(stateValue) {
|
|
278
299
|
if (isMachineSnapshot(stateValue)) {
|
|
@@ -942,7 +963,6 @@ class Actor {
|
|
|
942
963
|
return this._snapshot;
|
|
943
964
|
}
|
|
944
965
|
}
|
|
945
|
-
|
|
946
966
|
/**
|
|
947
967
|
* Creates a new actor instance for the given actor logic with the provided options, if any.
|
|
948
968
|
*
|
|
@@ -975,7 +995,7 @@ class Actor {
|
|
|
975
995
|
* @param logic - The actor logic to create an actor from. For a state machine actor logic creator, see {@link createMachine}. Other actor logic creators include {@link fromCallback}, {@link fromEventObservable}, {@link fromObservable}, {@link fromPromise}, and {@link fromTransition}.
|
|
976
996
|
* @param options - Actor options
|
|
977
997
|
*/
|
|
978
|
-
function createActor(logic, options) {
|
|
998
|
+
function createActor(logic, ...[options]) {
|
|
979
999
|
return new Actor(logic, options);
|
|
980
1000
|
}
|
|
981
1001
|
|
|
@@ -1459,16 +1479,16 @@ function isInFinalState(stateNodeSet, stateNode) {
|
|
|
1459
1479
|
}
|
|
1460
1480
|
const isStateId = str => str[0] === STATE_IDENTIFIER;
|
|
1461
1481
|
function getCandidates(stateNode, receivedEventType) {
|
|
1462
|
-
const candidates = stateNode.transitions.get(receivedEventType) || [...stateNode.transitions.keys()].filter(
|
|
1482
|
+
const candidates = stateNode.transitions.get(receivedEventType) || [...stateNode.transitions.keys()].filter(eventDescriptor => {
|
|
1463
1483
|
// check if transition is a wildcard transition,
|
|
1464
1484
|
// which matches any non-transient events
|
|
1465
|
-
if (
|
|
1485
|
+
if (eventDescriptor === WILDCARD) {
|
|
1466
1486
|
return true;
|
|
1467
1487
|
}
|
|
1468
|
-
if (!
|
|
1488
|
+
if (!eventDescriptor.endsWith('.*')) {
|
|
1469
1489
|
return false;
|
|
1470
1490
|
}
|
|
1471
|
-
const partialEventTokens =
|
|
1491
|
+
const partialEventTokens = eventDescriptor.split('.');
|
|
1472
1492
|
const eventTokens = receivedEventType.split('.');
|
|
1473
1493
|
for (let tokenIndex = 0; tokenIndex < partialEventTokens.length; tokenIndex++) {
|
|
1474
1494
|
const partialEventToken = partialEventTokens[tokenIndex];
|
|
@@ -2539,5 +2559,6 @@ exports.stop = stop;
|
|
|
2539
2559
|
exports.stopChild = stopChild;
|
|
2540
2560
|
exports.toArray = toArray;
|
|
2541
2561
|
exports.toObserver = toObserver;
|
|
2562
|
+
exports.toStatePath = toStatePath;
|
|
2542
2563
|
exports.toTransitionConfigArray = toTransitionConfigArray;
|
|
2543
2564
|
exports.transitionNode = transitionNode;
|
|
@@ -272,7 +272,28 @@ function toStatePath(stateId) {
|
|
|
272
272
|
if (isArray(stateId)) {
|
|
273
273
|
return stateId;
|
|
274
274
|
}
|
|
275
|
-
|
|
275
|
+
let result = [];
|
|
276
|
+
let segment = '';
|
|
277
|
+
for (let i = 0; i < stateId.length; i++) {
|
|
278
|
+
const char = stateId.charCodeAt(i);
|
|
279
|
+
switch (char) {
|
|
280
|
+
// \
|
|
281
|
+
case 92:
|
|
282
|
+
// consume the next character
|
|
283
|
+
segment += stateId[i + 1];
|
|
284
|
+
// and skip over it
|
|
285
|
+
i++;
|
|
286
|
+
continue;
|
|
287
|
+
// .
|
|
288
|
+
case 46:
|
|
289
|
+
result.push(segment);
|
|
290
|
+
segment = '';
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
segment += stateId[i];
|
|
294
|
+
}
|
|
295
|
+
result.push(segment);
|
|
296
|
+
return result;
|
|
276
297
|
}
|
|
277
298
|
function toStateValue(stateValue) {
|
|
278
299
|
if (isMachineSnapshot(stateValue)) {
|
|
@@ -956,7 +977,6 @@ class Actor {
|
|
|
956
977
|
return this._snapshot;
|
|
957
978
|
}
|
|
958
979
|
}
|
|
959
|
-
|
|
960
980
|
/**
|
|
961
981
|
* Creates a new actor instance for the given actor logic with the provided options, if any.
|
|
962
982
|
*
|
|
@@ -989,7 +1009,7 @@ class Actor {
|
|
|
989
1009
|
* @param logic - The actor logic to create an actor from. For a state machine actor logic creator, see {@link createMachine}. Other actor logic creators include {@link fromCallback}, {@link fromEventObservable}, {@link fromObservable}, {@link fromPromise}, and {@link fromTransition}.
|
|
990
1010
|
* @param options - Actor options
|
|
991
1011
|
*/
|
|
992
|
-
function createActor(logic, options) {
|
|
1012
|
+
function createActor(logic, ...[options]) {
|
|
993
1013
|
return new Actor(logic, options);
|
|
994
1014
|
}
|
|
995
1015
|
|
|
@@ -1493,19 +1513,19 @@ function isInFinalState(stateNodeSet, stateNode) {
|
|
|
1493
1513
|
}
|
|
1494
1514
|
const isStateId = str => str[0] === STATE_IDENTIFIER;
|
|
1495
1515
|
function getCandidates(stateNode, receivedEventType) {
|
|
1496
|
-
const candidates = stateNode.transitions.get(receivedEventType) || [...stateNode.transitions.keys()].filter(
|
|
1516
|
+
const candidates = stateNode.transitions.get(receivedEventType) || [...stateNode.transitions.keys()].filter(eventDescriptor => {
|
|
1497
1517
|
// check if transition is a wildcard transition,
|
|
1498
1518
|
// which matches any non-transient events
|
|
1499
|
-
if (
|
|
1519
|
+
if (eventDescriptor === WILDCARD) {
|
|
1500
1520
|
return true;
|
|
1501
1521
|
}
|
|
1502
|
-
if (!
|
|
1522
|
+
if (!eventDescriptor.endsWith('.*')) {
|
|
1503
1523
|
return false;
|
|
1504
1524
|
}
|
|
1505
|
-
if (/.*\*.+/.test(
|
|
1506
|
-
console.warn(`Wildcards can only be the last token of an event descriptor (e.g., "event.*") or the entire event descriptor ("*"). Check the "${
|
|
1525
|
+
if (/.*\*.+/.test(eventDescriptor)) {
|
|
1526
|
+
console.warn(`Wildcards can only be the last token of an event descriptor (e.g., "event.*") or the entire event descriptor ("*"). Check the "${eventDescriptor}" event.`);
|
|
1507
1527
|
}
|
|
1508
|
-
const partialEventTokens =
|
|
1528
|
+
const partialEventTokens = eventDescriptor.split('.');
|
|
1509
1529
|
const eventTokens = receivedEventType.split('.');
|
|
1510
1530
|
for (let tokenIndex = 0; tokenIndex < partialEventTokens.length; tokenIndex++) {
|
|
1511
1531
|
const partialEventToken = partialEventTokens[tokenIndex];
|
|
@@ -1513,7 +1533,7 @@ function getCandidates(stateNode, receivedEventType) {
|
|
|
1513
1533
|
if (partialEventToken === '*') {
|
|
1514
1534
|
const isLastToken = tokenIndex === partialEventTokens.length - 1;
|
|
1515
1535
|
if (!isLastToken) {
|
|
1516
|
-
console.warn(`Infix wildcards in transition events are not allowed. Check the "${
|
|
1536
|
+
console.warn(`Infix wildcards in transition events are not allowed. Check the "${eventDescriptor}" transition.`);
|
|
1517
1537
|
}
|
|
1518
1538
|
return isLastToken;
|
|
1519
1539
|
}
|
|
@@ -2596,5 +2616,6 @@ exports.stop = stop;
|
|
|
2596
2616
|
exports.stopChild = stopChild;
|
|
2597
2617
|
exports.toArray = toArray;
|
|
2598
2618
|
exports.toObserver = toObserver;
|
|
2619
|
+
exports.toStatePath = toStatePath;
|
|
2599
2620
|
exports.toTransitionConfigArray = toTransitionConfigArray;
|
|
2600
2621
|
exports.transitionNode = transitionNode;
|
package/dist/xstate.cjs.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var actors_dist_xstateActors = require('../actors/dist/xstate-actors.cjs.js');
|
|
6
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
7
|
-
var log = require('./log-
|
|
6
|
+
var guards_dist_xstateGuards = require('./raise-540fdaf2.cjs.js');
|
|
7
|
+
var log = require('./log-8a4f6e5c.cjs.js');
|
|
8
8
|
require('../dev/dist/xstate-dev.cjs.js');
|
|
9
9
|
|
|
10
10
|
class SimulatedClock {
|
|
@@ -394,6 +394,7 @@ class StateMachine {
|
|
|
394
394
|
* The machine's own version.
|
|
395
395
|
*/
|
|
396
396
|
this.version = void 0;
|
|
397
|
+
this.schemas = void 0;
|
|
397
398
|
this.implementations = void 0;
|
|
398
399
|
/** @internal */
|
|
399
400
|
this.__xstatenode = true;
|
|
@@ -415,6 +416,7 @@ class StateMachine {
|
|
|
415
416
|
guards: implementations?.guards ?? {}
|
|
416
417
|
};
|
|
417
418
|
this.version = this.config.version;
|
|
419
|
+
this.schemas = this.config.schemas;
|
|
418
420
|
this.transition = this.transition.bind(this);
|
|
419
421
|
this.getInitialSnapshot = this.getInitialSnapshot.bind(this);
|
|
420
422
|
this.getPersistedSnapshot = this.getPersistedSnapshot.bind(this);
|
|
@@ -560,7 +562,7 @@ class StateMachine {
|
|
|
560
562
|
});
|
|
561
563
|
}
|
|
562
564
|
getStateNodeById(stateId) {
|
|
563
|
-
const fullPath =
|
|
565
|
+
const fullPath = guards_dist_xstateGuards.toStatePath(stateId);
|
|
564
566
|
const relativePath = fullPath.slice(1);
|
|
565
567
|
const resolvedStateId = guards_dist_xstateGuards.isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
|
|
566
568
|
const stateNode = this.idMap.get(resolvedStateId);
|
|
@@ -633,8 +635,8 @@ const defaultWaitForOptions = {
|
|
|
633
635
|
/**
|
|
634
636
|
* Subscribes to an actor ref and waits for its emitted value to satisfy
|
|
635
637
|
* a predicate, and then resolves with that value.
|
|
636
|
-
* Will throw if the desired state is not reached after
|
|
637
|
-
* (defaults to
|
|
638
|
+
* Will throw if the desired state is not reached after an optional timeout.
|
|
639
|
+
* (defaults to Infinity).
|
|
638
640
|
*
|
|
639
641
|
* @example
|
|
640
642
|
* ```js
|
|
@@ -704,10 +706,10 @@ function waitFor(actorRef, predicate, options) {
|
|
|
704
706
|
* Creates a state machine (statechart) with the given configuration.
|
|
705
707
|
*
|
|
706
708
|
* The state machine represents the pure logic of a state machine actor.
|
|
707
|
-
*
|
|
709
|
+
*
|
|
708
710
|
* @param config The state machine configuration.
|
|
709
711
|
* @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })` to provide machine implementations instead.
|
|
710
|
-
*
|
|
712
|
+
*
|
|
711
713
|
* @example
|
|
712
714
|
```ts
|
|
713
715
|
import { createMachine } from 'xstate';
|
|
@@ -797,13 +799,17 @@ function getNextSnapshot(actorLogic, snapshot, event) {
|
|
|
797
799
|
// at the moment we allow extra actors - ones that are not specified by `children`
|
|
798
800
|
// this could be reconsidered in the future
|
|
799
801
|
function setup({
|
|
802
|
+
schemas,
|
|
800
803
|
actors,
|
|
801
804
|
actions,
|
|
802
805
|
guards,
|
|
803
806
|
delays
|
|
804
807
|
}) {
|
|
805
808
|
return {
|
|
806
|
-
createMachine: config => createMachine(
|
|
809
|
+
createMachine: config => createMachine({
|
|
810
|
+
...config,
|
|
811
|
+
schemas
|
|
812
|
+
}, {
|
|
807
813
|
actors,
|
|
808
814
|
actions,
|
|
809
815
|
guards,
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var actors_dist_xstateActors = require('../actors/dist/xstate-actors.development.cjs.js');
|
|
6
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
7
|
-
var log = require('./log-
|
|
6
|
+
var guards_dist_xstateGuards = require('./raise-d7d9caaa.development.cjs.js');
|
|
7
|
+
var log = require('./log-3552abe4.development.cjs.js');
|
|
8
8
|
require('../dev/dist/xstate-dev.development.cjs.js');
|
|
9
9
|
|
|
10
10
|
class SimulatedClock {
|
|
@@ -394,6 +394,7 @@ class StateMachine {
|
|
|
394
394
|
* The machine's own version.
|
|
395
395
|
*/
|
|
396
396
|
this.version = void 0;
|
|
397
|
+
this.schemas = void 0;
|
|
397
398
|
this.implementations = void 0;
|
|
398
399
|
/** @internal */
|
|
399
400
|
this.__xstatenode = true;
|
|
@@ -415,6 +416,7 @@ class StateMachine {
|
|
|
415
416
|
guards: implementations?.guards ?? {}
|
|
416
417
|
};
|
|
417
418
|
this.version = this.config.version;
|
|
419
|
+
this.schemas = this.config.schemas;
|
|
418
420
|
this.transition = this.transition.bind(this);
|
|
419
421
|
this.getInitialSnapshot = this.getInitialSnapshot.bind(this);
|
|
420
422
|
this.getPersistedSnapshot = this.getPersistedSnapshot.bind(this);
|
|
@@ -563,7 +565,7 @@ class StateMachine {
|
|
|
563
565
|
});
|
|
564
566
|
}
|
|
565
567
|
getStateNodeById(stateId) {
|
|
566
|
-
const fullPath =
|
|
568
|
+
const fullPath = guards_dist_xstateGuards.toStatePath(stateId);
|
|
567
569
|
const relativePath = fullPath.slice(1);
|
|
568
570
|
const resolvedStateId = guards_dist_xstateGuards.isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
|
|
569
571
|
const stateNode = this.idMap.get(resolvedStateId);
|
|
@@ -636,8 +638,8 @@ const defaultWaitForOptions = {
|
|
|
636
638
|
/**
|
|
637
639
|
* Subscribes to an actor ref and waits for its emitted value to satisfy
|
|
638
640
|
* a predicate, and then resolves with that value.
|
|
639
|
-
* Will throw if the desired state is not reached after
|
|
640
|
-
* (defaults to
|
|
641
|
+
* Will throw if the desired state is not reached after an optional timeout.
|
|
642
|
+
* (defaults to Infinity).
|
|
641
643
|
*
|
|
642
644
|
* @example
|
|
643
645
|
* ```js
|
|
@@ -710,10 +712,10 @@ function waitFor(actorRef, predicate, options) {
|
|
|
710
712
|
* Creates a state machine (statechart) with the given configuration.
|
|
711
713
|
*
|
|
712
714
|
* The state machine represents the pure logic of a state machine actor.
|
|
713
|
-
*
|
|
715
|
+
*
|
|
714
716
|
* @param config The state machine configuration.
|
|
715
717
|
* @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })` to provide machine implementations instead.
|
|
716
|
-
*
|
|
718
|
+
*
|
|
717
719
|
* @example
|
|
718
720
|
```ts
|
|
719
721
|
import { createMachine } from 'xstate';
|
|
@@ -803,13 +805,17 @@ function getNextSnapshot(actorLogic, snapshot, event) {
|
|
|
803
805
|
// at the moment we allow extra actors - ones that are not specified by `children`
|
|
804
806
|
// this could be reconsidered in the future
|
|
805
807
|
function setup({
|
|
808
|
+
schemas,
|
|
806
809
|
actors,
|
|
807
810
|
actions,
|
|
808
811
|
guards,
|
|
809
812
|
delays
|
|
810
813
|
}) {
|
|
811
814
|
return {
|
|
812
|
-
createMachine: config => createMachine(
|
|
815
|
+
createMachine: config => createMachine({
|
|
816
|
+
...config,
|
|
817
|
+
schemas
|
|
818
|
+
}, {
|
|
813
819
|
actors,
|
|
814
820
|
actions,
|
|
815
821
|
guards,
|