xstate 4.7.5 → 4.8.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/CHANGELOG.md +34 -0
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/Machine.d.ts +1 -1
- package/es/State.d.ts +3 -3
- package/es/State.js +3 -1
- package/es/StateNode.d.ts +4 -4
- package/es/StateNode.js +17 -3
- package/es/actions.d.ts +5 -4
- package/es/actions.js +7 -4
- package/es/interpreter.d.ts +10 -10
- package/es/interpreter.js +4 -2
- package/es/json.d.ts +31 -0
- package/es/registry.d.ts +3 -2
- package/es/registry.js +6 -8
- package/es/types.d.ts +7 -6
- package/lib/Machine.d.ts +1 -1
- package/lib/State.d.ts +3 -3
- package/lib/State.js +2 -1
- package/lib/StateNode.d.ts +4 -4
- package/lib/StateNode.js +10 -3
- package/lib/actions.d.ts +5 -4
- package/lib/actions.js +9 -4
- package/lib/interpreter.d.ts +10 -10
- package/lib/interpreter.js +4 -3
- package/lib/json.d.ts +31 -0
- package/lib/json.js +84 -0
- package/lib/registry.d.ts +3 -2
- package/lib/registry.js +6 -6
- package/lib/types.d.ts +7 -6
- package/package.json +2 -2
package/es/Machine.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StateMachine, MachineOptions, DefaultContext, MachineConfig, StateSchema, EventObject, AnyEventObject, Typestate } from './types';
|
|
2
2
|
export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, any, TEvent>;
|
|
3
3
|
export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, TStateSchema, TEvent>;
|
|
4
|
-
export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject,
|
|
4
|
+
export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject, TTypestate extends Typestate<TContext> = any>(config: MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
|
|
5
5
|
//# sourceMappingURL=Machine.d.ts.map
|
package/es/State.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Actor } from './Actor';
|
|
|
4
4
|
export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
|
|
5
5
|
export declare function isState<TContext, TEvent extends EventObject>(state: object | string): state is State<TContext, TEvent>;
|
|
6
6
|
export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE>): ActionObject<TC, TE>;
|
|
7
|
-
export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any,
|
|
7
|
+
export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = any> {
|
|
8
8
|
value: StateValue;
|
|
9
9
|
context: TContext;
|
|
10
10
|
historyValue?: HistoryValue | undefined;
|
|
@@ -86,8 +86,8 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
86
86
|
* Whether the current state value is a subset of the given parent state value.
|
|
87
87
|
* @param parentStateValue
|
|
88
88
|
*/
|
|
89
|
-
matches<TSV extends
|
|
89
|
+
matches<TSV extends TTypestate['value']>(parentStateValue: TSV): this is TTypestate extends {
|
|
90
90
|
value: TSV;
|
|
91
|
-
} ? State<
|
|
91
|
+
} ? State<TTypestate['context'], TEvent, TStateSchema, TTypestate> : never;
|
|
92
92
|
}
|
|
93
93
|
//# sourceMappingURL=State.d.ts.map
|
package/es/State.js
CHANGED
|
@@ -66,6 +66,8 @@ function () {
|
|
|
66
66
|
* @param configuration
|
|
67
67
|
*/
|
|
68
68
|
function State(config) {
|
|
69
|
+
var _this = this;
|
|
70
|
+
|
|
69
71
|
this.actions = [];
|
|
70
72
|
this.activities = EMPTY_ACTIVITY_MAP;
|
|
71
73
|
this.meta = {};
|
|
@@ -89,7 +91,7 @@ function () {
|
|
|
89
91
|
this.done = !!config.done;
|
|
90
92
|
Object.defineProperty(this, 'nextEvents', {
|
|
91
93
|
get: function () {
|
|
92
|
-
return nextEvents(
|
|
94
|
+
return nextEvents(_this.configuration);
|
|
93
95
|
}
|
|
94
96
|
});
|
|
95
97
|
}
|
package/es/StateNode.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Event, StateValue, StateValueMap, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap } from './types';
|
|
2
2
|
import { State } from './State';
|
|
3
|
-
declare class StateNode<TContext = any, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject,
|
|
3
|
+
declare class StateNode<TContext = any, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = any> {
|
|
4
4
|
/**
|
|
5
5
|
* The raw config used to create the machine.
|
|
6
6
|
*/
|
|
@@ -191,7 +191,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
191
191
|
* @param event The event that was sent at the current state
|
|
192
192
|
* @param context The current context (extended state) of the current state
|
|
193
193
|
*/
|
|
194
|
-
transition(state: string | StateValueMap | State<TContext, TEvent, any, any> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext): State<TContext, TEvent, TStateSchema,
|
|
194
|
+
transition(state: string | StateValueMap | State<TContext, TEvent, any, any> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
195
195
|
private resolveRaisedTransition;
|
|
196
196
|
private resolveTransition;
|
|
197
197
|
/**
|
|
@@ -218,12 +218,12 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
218
218
|
resolve(stateValue: StateValue): StateValue;
|
|
219
219
|
private getResolvedPath;
|
|
220
220
|
private get initialStateValue();
|
|
221
|
-
getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema,
|
|
221
|
+
getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
222
222
|
/**
|
|
223
223
|
* The initial State instance, which includes all actions to be executed from
|
|
224
224
|
* entering the initial state.
|
|
225
225
|
*/
|
|
226
|
-
get initialState(): State<TContext, TEvent, TStateSchema,
|
|
226
|
+
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
227
227
|
/**
|
|
228
228
|
* The target state value of the history state node, if it exists. This represents the
|
|
229
229
|
* default state value to transition to if no history value exists yet.
|
package/es/StateNode.js
CHANGED
|
@@ -229,6 +229,7 @@ function () {
|
|
|
229
229
|
id: this.id,
|
|
230
230
|
key: this.key,
|
|
231
231
|
version: this.version,
|
|
232
|
+
context: this.context,
|
|
232
233
|
type: this.type,
|
|
233
234
|
initial: this.initial,
|
|
234
235
|
history: this.history,
|
|
@@ -237,8 +238,8 @@ function () {
|
|
|
237
238
|
}),
|
|
238
239
|
on: this.on,
|
|
239
240
|
transitions: this.transitions,
|
|
240
|
-
|
|
241
|
-
|
|
241
|
+
entry: this.onEntry,
|
|
242
|
+
exit: this.onExit,
|
|
242
243
|
activities: this.activities || [],
|
|
243
244
|
meta: this.meta,
|
|
244
245
|
order: this.order || -1,
|
|
@@ -1475,7 +1476,8 @@ function () {
|
|
|
1475
1476
|
}) : true;
|
|
1476
1477
|
var guards = this.machine.options.guards;
|
|
1477
1478
|
var target = this.resolveTarget(normalizedTarget);
|
|
1478
|
-
|
|
1479
|
+
|
|
1480
|
+
var transition = __assign(__assign({}, transitionConfig), {
|
|
1479
1481
|
actions: toActionObjects(toArray(transitionConfig.actions)),
|
|
1480
1482
|
cond: toGuard(transitionConfig.cond, guards),
|
|
1481
1483
|
target: target,
|
|
@@ -1483,6 +1485,18 @@ function () {
|
|
|
1483
1485
|
internal: internal,
|
|
1484
1486
|
eventType: transitionConfig.event
|
|
1485
1487
|
});
|
|
1488
|
+
|
|
1489
|
+
Object.defineProperty(transition, 'toJSON', {
|
|
1490
|
+
value: function () {
|
|
1491
|
+
return __assign(__assign({}, transition), {
|
|
1492
|
+
target: transition.target ? transition.target.map(function (t) {
|
|
1493
|
+
return "#" + t.id;
|
|
1494
|
+
}) : undefined,
|
|
1495
|
+
source: "#{this.id}"
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1498
|
+
});
|
|
1499
|
+
return transition;
|
|
1486
1500
|
};
|
|
1487
1501
|
|
|
1488
1502
|
StateNode.prototype.formatTransitions = function () {
|
package/es/actions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML } from './types';
|
|
1
|
+
import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta } from './types';
|
|
2
2
|
import * as actionTypes from './actionTypes';
|
|
3
3
|
export { actionTypes };
|
|
4
4
|
export declare const initEvent: SCXML.Event<{
|
|
@@ -6,7 +6,7 @@ export declare const initEvent: SCXML.Event<{
|
|
|
6
6
|
}>;
|
|
7
7
|
export declare function getActionFunction<TContext, TEvent extends EventObject>(actionType: ActionType, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | undefined;
|
|
8
8
|
export declare function toActionObject<TContext, TEvent extends EventObject>(action: Action<TContext, TEvent>, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent>;
|
|
9
|
-
export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: string | ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | AssignAction<Required<TContext>, TEvent> | SendAction<TContext, TEvent> |
|
|
9
|
+
export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: string | RaiseAction<import("./types").AnyEventObject> | ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | AssignAction<Required<TContext>, TEvent> | SendAction<TContext, TEvent> | Action<TContext, TEvent>[] | undefined, actionFunctionMap?: Record<string, ActionFunction<TContext, TEvent> | ActionObject<TContext, TEvent>> | undefined) => ActionObject<TContext, TEvent>[];
|
|
10
10
|
export declare function toActivityDefinition<TContext, TEvent extends EventObject>(action: string | ActivityDefinition<TContext, TEvent>): ActivityDefinition<TContext, TEvent>;
|
|
11
11
|
/**
|
|
12
12
|
* Raises an event. This places the event in the internal event queue, so that
|
|
@@ -121,8 +121,9 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
|
|
|
121
121
|
/**
|
|
122
122
|
* Escalates an error by sending it as an event to this machine's parent.
|
|
123
123
|
*
|
|
124
|
-
* @param errorData The error data to send
|
|
124
|
+
* @param errorData The error data to send, or the expression function that
|
|
125
|
+
* takes in the `context`, `event`, and `meta`, and returns the error data to send.
|
|
125
126
|
* @param options Options to pass into the send action creator.
|
|
126
127
|
*/
|
|
127
|
-
export declare function escalate<TContext, TEvent extends EventObject>(errorData:
|
|
128
|
+
export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent>;
|
|
128
129
|
//# sourceMappingURL=actions.d.ts.map
|
package/es/actions.js
CHANGED
|
@@ -379,15 +379,18 @@ function forwardTo(target, options) {
|
|
|
379
379
|
/**
|
|
380
380
|
* Escalates an error by sending it as an event to this machine's parent.
|
|
381
381
|
*
|
|
382
|
-
* @param errorData The error data to send
|
|
382
|
+
* @param errorData The error data to send, or the expression function that
|
|
383
|
+
* takes in the `context`, `event`, and `meta`, and returns the error data to send.
|
|
383
384
|
* @param options Options to pass into the send action creator.
|
|
384
385
|
*/
|
|
385
386
|
|
|
386
387
|
|
|
387
388
|
function escalate(errorData, options) {
|
|
388
|
-
return sendParent({
|
|
389
|
-
|
|
390
|
-
|
|
389
|
+
return sendParent(function (context, event, meta) {
|
|
390
|
+
return {
|
|
391
|
+
type: error$1,
|
|
392
|
+
data: isFunction(errorData) ? errorData(context, event, meta) : errorData
|
|
393
|
+
};
|
|
391
394
|
}, __assign(__assign({}, options), {
|
|
392
395
|
to: SpecialTargets.Parent
|
|
393
396
|
}));
|
package/es/interpreter.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, DoneEvent, Unsubscribable, MachineOptions, SCXML, EventData, Observer, Spawnable } from './types';
|
|
1
|
+
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, DoneEvent, Unsubscribable, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate } from './types';
|
|
2
2
|
import { State } from './State';
|
|
3
3
|
import { Actor } from './Actor';
|
|
4
|
-
export declare type StateListener<TContext, TEvent extends EventObject> = (state: State<TContext, TEvent>, event: TEvent) => void;
|
|
4
|
+
export declare type StateListener<TContext, TEvent extends EventObject, TTypestate extends Typestate<TContext> = any> = (state: State<TContext, TEvent, any, TTypestate>, event: TEvent) => void;
|
|
5
5
|
export declare type ContextListener<TContext = DefaultContext> = (context: TContext, prevContext: TContext | undefined) => void;
|
|
6
6
|
export declare type EventListener<TEvent extends EventObject = EventObject> = (event: TEvent) => void;
|
|
7
7
|
export declare type Listener = () => void;
|
|
@@ -14,8 +14,8 @@ interface SpawnOptions {
|
|
|
14
14
|
autoForward?: boolean;
|
|
15
15
|
sync?: boolean;
|
|
16
16
|
}
|
|
17
|
-
export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject> implements Actor<State<TContext, TEvent>, TEvent> {
|
|
18
|
-
machine: StateMachine<TContext, TStateSchema, TEvent>;
|
|
17
|
+
export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = any> implements Actor<State<TContext, TEvent>, TEvent> {
|
|
18
|
+
machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
|
|
19
19
|
/**
|
|
20
20
|
* The default interpreter options:
|
|
21
21
|
*
|
|
@@ -62,7 +62,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
62
62
|
* @param machine The machine to be interpreted
|
|
63
63
|
* @param options Interpreter options
|
|
64
64
|
*/
|
|
65
|
-
constructor(machine: StateMachine<TContext, TStateSchema, TEvent>, options?: Partial<InterpreterOptions
|
|
65
|
+
constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>, options?: Partial<InterpreterOptions>);
|
|
66
66
|
get initialState(): State<TContext, TEvent>;
|
|
67
67
|
get state(): State<TContext, TEvent>;
|
|
68
68
|
static interpret: typeof interpret;
|
|
@@ -74,9 +74,9 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
74
74
|
*/
|
|
75
75
|
execute(state: State<TContext, TEvent>, actionsConfig?: MachineOptions<TContext, TEvent>['actions']): void;
|
|
76
76
|
private update;
|
|
77
|
-
onTransition(listener: StateListener<TContext, TEvent>):
|
|
78
|
-
subscribe(observer: Observer<State<TContext, TEvent>>): Unsubscribable;
|
|
79
|
-
subscribe(nextListener?: (state: State<TContext, TEvent>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Unsubscribable;
|
|
77
|
+
onTransition(listener: StateListener<TContext, TEvent, TTypestate>): this;
|
|
78
|
+
subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate>>): Unsubscribable;
|
|
79
|
+
subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Unsubscribable;
|
|
80
80
|
/**
|
|
81
81
|
* Adds an event listener that is notified whenever an event is sent to the running interpreter.
|
|
82
82
|
* @param listener The event listener
|
|
@@ -110,7 +110,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
110
110
|
/**
|
|
111
111
|
* Alias for Interpreter.prototype.start
|
|
112
112
|
*/
|
|
113
|
-
init: (initialState?: string | State<TContext, TEvent, any, any> | import("./types").StateValueMap | undefined) => Interpreter<TContext, TStateSchema, TEvent>;
|
|
113
|
+
init: (initialState?: string | State<TContext, TEvent, any, any> | import("./types").StateValueMap | undefined) => Interpreter<TContext, TStateSchema, TEvent, any>;
|
|
114
114
|
/**
|
|
115
115
|
* Starts the interpreter from the given state, or the initial state.
|
|
116
116
|
* @param initialState The state to start the statechart from
|
|
@@ -178,6 +178,6 @@ export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnO
|
|
|
178
178
|
* @param machine The machine to interpret
|
|
179
179
|
* @param options Interpreter options
|
|
180
180
|
*/
|
|
181
|
-
export declare function interpret<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject>(machine: StateMachine<TContext, TStateSchema, TEvent>, options?: Partial<InterpreterOptions>): Interpreter<TContext, TStateSchema, TEvent>;
|
|
181
|
+
export declare function interpret<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = any>(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>, options?: Partial<InterpreterOptions>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
182
182
|
export {};
|
|
183
183
|
//# sourceMappingURL=interpreter.d.ts.map
|
package/es/interpreter.js
CHANGED
|
@@ -52,7 +52,7 @@ function () {
|
|
|
52
52
|
* @param machine The machine to be interpreted
|
|
53
53
|
* @param options Interpreter options
|
|
54
54
|
*/
|
|
55
|
-
function Interpreter(machine, options
|
|
55
|
+
function Interpreter(machine, options) {
|
|
56
56
|
var _this = this;
|
|
57
57
|
|
|
58
58
|
if (options === void 0) {
|
|
@@ -175,7 +175,7 @@ function () {
|
|
|
175
175
|
this.scheduler = new Scheduler({
|
|
176
176
|
deferEvents: this.options.deferEvents
|
|
177
177
|
});
|
|
178
|
-
this.sessionId =
|
|
178
|
+
this.sessionId = registry.bookId();
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
Object.defineProperty(Interpreter.prototype, "initialState", {
|
|
@@ -471,6 +471,7 @@ function () {
|
|
|
471
471
|
return this;
|
|
472
472
|
}
|
|
473
473
|
|
|
474
|
+
registry.register(this.sessionId, this);
|
|
474
475
|
this.initialized = true;
|
|
475
476
|
this._status = InterpreterStatus.Running;
|
|
476
477
|
var resolvedState = initialState === undefined ? this.initialState : withServiceScope(this, function () {
|
|
@@ -594,6 +595,7 @@ function () {
|
|
|
594
595
|
this.scheduler.clear();
|
|
595
596
|
this.initialized = false;
|
|
596
597
|
this._status = InterpreterStatus.Stopped;
|
|
598
|
+
registry.free(this.sessionId);
|
|
597
599
|
return this;
|
|
598
600
|
};
|
|
599
601
|
|
package/es/json.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { StateNode, ActionObject, Guard, InvokeDefinition } from './';
|
|
2
|
+
interface JSONFunction {
|
|
3
|
+
$function: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function stringifyFunction(fn: Function): JSONFunction;
|
|
6
|
+
interface TransitionConfig {
|
|
7
|
+
target: string[];
|
|
8
|
+
source: string;
|
|
9
|
+
actions: Array<ActionObject<any, any>>;
|
|
10
|
+
cond: Guard<any, any> | undefined;
|
|
11
|
+
eventType: string;
|
|
12
|
+
}
|
|
13
|
+
interface StateNodeConfig {
|
|
14
|
+
type: StateNode['type'];
|
|
15
|
+
id: string;
|
|
16
|
+
key: string;
|
|
17
|
+
initial?: string;
|
|
18
|
+
entry: Array<ActionObject<any, any>>;
|
|
19
|
+
exit: Array<ActionObject<any, any>>;
|
|
20
|
+
on: {
|
|
21
|
+
[key: string]: TransitionConfig[];
|
|
22
|
+
};
|
|
23
|
+
invoke: Array<InvokeDefinition<any, any>>;
|
|
24
|
+
states: Record<string, StateNodeConfig>;
|
|
25
|
+
}
|
|
26
|
+
export declare function machineToJSON(stateNode: StateNode): StateNodeConfig;
|
|
27
|
+
export declare function stringify(machine: StateNode): string;
|
|
28
|
+
export declare function parse(machineString: string): StateNodeConfig;
|
|
29
|
+
export declare function jsonify<T extends Record<string, any>>(value: T): T;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=json.d.ts.map
|
package/es/registry.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Actor } from './Actor';
|
|
2
2
|
export interface Registry {
|
|
3
|
-
|
|
3
|
+
bookId(): string;
|
|
4
|
+
register(id: string, actor: Actor): string;
|
|
4
5
|
get(id: string): Actor | undefined;
|
|
5
|
-
|
|
6
|
+
free(id: string): void;
|
|
6
7
|
}
|
|
7
8
|
export declare const registry: Registry;
|
|
8
9
|
//# sourceMappingURL=registry.d.ts.map
|
package/es/registry.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
var children =
|
|
2
2
|
/*#__PURE__*/
|
|
3
3
|
new Map();
|
|
4
|
-
var idMap =
|
|
5
|
-
/*#__PURE__*/
|
|
6
|
-
new Map();
|
|
7
4
|
var sessionIdIndex = 0;
|
|
8
5
|
var registry = {
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
bookId: function () {
|
|
7
|
+
return "x:" + sessionIdIndex++;
|
|
8
|
+
},
|
|
9
|
+
register: function (id, actor) {
|
|
11
10
|
children.set(id, actor);
|
|
12
|
-
idMap.set(actor, id);
|
|
13
11
|
return id;
|
|
14
12
|
},
|
|
15
13
|
get: function (id) {
|
|
16
14
|
return children.get(id);
|
|
17
15
|
},
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
free: function (id) {
|
|
17
|
+
children.delete(id);
|
|
20
18
|
}
|
|
21
19
|
};
|
|
22
20
|
export { registry };
|
package/es/types.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export interface AssignMeta<TContext, TEvent extends EventObject> {
|
|
|
50
50
|
_event: SCXML.Event<TEvent>;
|
|
51
51
|
}
|
|
52
52
|
export declare type ActionFunction<TContext, TEvent extends EventObject> = (context: TContext, event: TEvent, meta: ActionMeta<TContext, TEvent>) => any | void;
|
|
53
|
-
export declare type Action<TContext, TEvent extends EventObject> = ActionType | ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | AssignAction<Required<TContext>, TEvent> | SendAction<TContext, TEvent> | RaiseAction<
|
|
53
|
+
export declare type Action<TContext, TEvent extends EventObject> = ActionType | ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | AssignAction<Required<TContext>, TEvent> | SendAction<TContext, TEvent> | RaiseAction<AnyEventObject>;
|
|
54
54
|
export declare type Actions<TContext, TEvent extends EventObject> = SingleOrArray<Action<TContext, TEvent>>;
|
|
55
55
|
export declare type StateKey = string | State<any>;
|
|
56
56
|
export interface StateValueMap {
|
|
@@ -124,7 +124,7 @@ export declare type InvokeCallback = (callback: Sender<any>, onReceive: Receiver
|
|
|
124
124
|
* @param context The current machine `context`
|
|
125
125
|
* @param event The event that invoked the service
|
|
126
126
|
*/
|
|
127
|
-
export declare type InvokeCreator<TContext, TFinalContext = any> = (context: TContext, event:
|
|
127
|
+
export declare type InvokeCreator<TContext, TEvent = AnyEventObject, TFinalContext = any> = (context: TContext, event: TEvent) => PromiseLike<TFinalContext> | StateMachine<TFinalContext, any, any> | Subscribable<any> | InvokeCallback;
|
|
128
128
|
export interface InvokeDefinition<TContext, TEvent extends EventObject> extends ActivityDefinition<TContext, TEvent> {
|
|
129
129
|
/**
|
|
130
130
|
* The source of the machine to be invoked, or the machine itself.
|
|
@@ -196,7 +196,7 @@ export declare type InvokeConfig<TContext, TEvent extends EventObject> = {
|
|
|
196
196
|
/**
|
|
197
197
|
* The source of the machine to be invoked, or the machine itself.
|
|
198
198
|
*/
|
|
199
|
-
src: string | StateMachine<any, any, any> | InvokeCreator<
|
|
199
|
+
src: string | StateMachine<any, any, any> | InvokeCreator<TContext, TEvent, any>;
|
|
200
200
|
/**
|
|
201
201
|
* If `true`, events sent to the parent service will be forwarded to the invoked service.
|
|
202
202
|
*
|
|
@@ -345,14 +345,15 @@ export interface StateNodeDefinition<TContext, TStateSchema extends StateSchema,
|
|
|
345
345
|
id: string;
|
|
346
346
|
version: string | undefined;
|
|
347
347
|
key: string;
|
|
348
|
+
context: TContext;
|
|
348
349
|
type: 'atomic' | 'compound' | 'parallel' | 'final' | 'history';
|
|
349
350
|
initial: StateNodeConfig<TContext, TStateSchema, TEvent>['initial'];
|
|
350
351
|
history: boolean | 'shallow' | 'deep' | undefined;
|
|
351
352
|
states: StatesDefinition<TContext, TStateSchema, TEvent>;
|
|
352
353
|
on: TransitionDefinitionMap<TContext, TEvent>;
|
|
353
354
|
transitions: Array<TransitionDefinition<TContext, TEvent>>;
|
|
354
|
-
|
|
355
|
-
|
|
355
|
+
entry: Array<ActionObject<TContext, TEvent>>;
|
|
356
|
+
exit: Array<ActionObject<TContext, TEvent>>;
|
|
356
357
|
activities: Array<ActivityDefinition<TContext, TEvent>>;
|
|
357
358
|
meta: any;
|
|
358
359
|
order: number;
|
|
@@ -422,7 +423,7 @@ export interface HistoryStateNode<TContext> extends StateNode<TContext> {
|
|
|
422
423
|
history: 'shallow' | 'deep';
|
|
423
424
|
target: StateValue | undefined;
|
|
424
425
|
}
|
|
425
|
-
export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent extends EventObject,
|
|
426
|
+
export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TTypestate extends Typestate<TContext> = any> extends StateNode<TContext, TStateSchema, TEvent, TTypestate> {
|
|
426
427
|
id: string;
|
|
427
428
|
states: StateNode<TContext, TStateSchema, TEvent>['states'];
|
|
428
429
|
}
|
package/lib/Machine.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StateMachine, MachineOptions, DefaultContext, MachineConfig, StateSchema, EventObject, AnyEventObject, Typestate } from './types';
|
|
2
2
|
export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, any, TEvent>;
|
|
3
3
|
export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, TStateSchema, TEvent>;
|
|
4
|
-
export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject,
|
|
4
|
+
export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject, TTypestate extends Typestate<TContext> = any>(config: MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
|
|
5
5
|
//# sourceMappingURL=Machine.d.ts.map
|
package/lib/State.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Actor } from './Actor';
|
|
|
4
4
|
export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
|
|
5
5
|
export declare function isState<TContext, TEvent extends EventObject>(state: object | string): state is State<TContext, TEvent>;
|
|
6
6
|
export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE>): ActionObject<TC, TE>;
|
|
7
|
-
export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any,
|
|
7
|
+
export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = any> {
|
|
8
8
|
value: StateValue;
|
|
9
9
|
context: TContext;
|
|
10
10
|
historyValue?: HistoryValue | undefined;
|
|
@@ -86,8 +86,8 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
86
86
|
* Whether the current state value is a subset of the given parent state value.
|
|
87
87
|
* @param parentStateValue
|
|
88
88
|
*/
|
|
89
|
-
matches<TSV extends
|
|
89
|
+
matches<TSV extends TTypestate['value']>(parentStateValue: TSV): this is TTypestate extends {
|
|
90
90
|
value: TSV;
|
|
91
|
-
} ? State<
|
|
91
|
+
} ? State<TTypestate['context'], TEvent, TStateSchema, TTypestate> : never;
|
|
92
92
|
}
|
|
93
93
|
//# sourceMappingURL=State.d.ts.map
|
package/lib/State.js
CHANGED
|
@@ -97,6 +97,7 @@ var State = /** @class */ (function () {
|
|
|
97
97
|
* @param configuration
|
|
98
98
|
*/
|
|
99
99
|
function State(config) {
|
|
100
|
+
var _this = this;
|
|
100
101
|
this.actions = [];
|
|
101
102
|
this.activities = constants_1.EMPTY_ACTIVITY_MAP;
|
|
102
103
|
this.meta = {};
|
|
@@ -120,7 +121,7 @@ var State = /** @class */ (function () {
|
|
|
120
121
|
this.done = !!config.done;
|
|
121
122
|
Object.defineProperty(this, 'nextEvents', {
|
|
122
123
|
get: function () {
|
|
123
|
-
return stateUtils_1.nextEvents(
|
|
124
|
+
return stateUtils_1.nextEvents(_this.configuration);
|
|
124
125
|
}
|
|
125
126
|
});
|
|
126
127
|
}
|
package/lib/StateNode.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Event, StateValue, StateValueMap, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap } from './types';
|
|
2
2
|
import { State } from './State';
|
|
3
|
-
declare class StateNode<TContext = any, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject,
|
|
3
|
+
declare class StateNode<TContext = any, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = any> {
|
|
4
4
|
/**
|
|
5
5
|
* The raw config used to create the machine.
|
|
6
6
|
*/
|
|
@@ -191,7 +191,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
191
191
|
* @param event The event that was sent at the current state
|
|
192
192
|
* @param context The current context (extended state) of the current state
|
|
193
193
|
*/
|
|
194
|
-
transition(state: string | StateValueMap | State<TContext, TEvent, any, any> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext): State<TContext, TEvent, TStateSchema,
|
|
194
|
+
transition(state: string | StateValueMap | State<TContext, TEvent, any, any> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
195
195
|
private resolveRaisedTransition;
|
|
196
196
|
private resolveTransition;
|
|
197
197
|
/**
|
|
@@ -218,12 +218,12 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
218
218
|
resolve(stateValue: StateValue): StateValue;
|
|
219
219
|
private getResolvedPath;
|
|
220
220
|
private get initialStateValue();
|
|
221
|
-
getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema,
|
|
221
|
+
getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
222
222
|
/**
|
|
223
223
|
* The initial State instance, which includes all actions to be executed from
|
|
224
224
|
* entering the initial state.
|
|
225
225
|
*/
|
|
226
|
-
get initialState(): State<TContext, TEvent, TStateSchema,
|
|
226
|
+
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
227
227
|
/**
|
|
228
228
|
* The target state value of the history state node, if it exists. This represents the
|
|
229
229
|
* default state value to transition to if no history value exists yet.
|
package/lib/StateNode.js
CHANGED
|
@@ -263,14 +263,15 @@ var StateNode = /** @class */ (function () {
|
|
|
263
263
|
id: this.id,
|
|
264
264
|
key: this.key,
|
|
265
265
|
version: this.version,
|
|
266
|
+
context: this.context,
|
|
266
267
|
type: this.type,
|
|
267
268
|
initial: this.initial,
|
|
268
269
|
history: this.history,
|
|
269
270
|
states: utils_1.mapValues(this.states, function (state) { return state.definition; }),
|
|
270
271
|
on: this.on,
|
|
271
272
|
transitions: this.transitions,
|
|
272
|
-
|
|
273
|
-
|
|
273
|
+
entry: this.onEntry,
|
|
274
|
+
exit: this.onExit,
|
|
274
275
|
activities: this.activities || [],
|
|
275
276
|
meta: this.meta,
|
|
276
277
|
order: this.order || -1,
|
|
@@ -1326,7 +1327,13 @@ var StateNode = /** @class */ (function () {
|
|
|
1326
1327
|
: true;
|
|
1327
1328
|
var guards = this.machine.options.guards;
|
|
1328
1329
|
var target = this.resolveTarget(normalizedTarget);
|
|
1329
|
-
|
|
1330
|
+
var transition = __assign(__assign({}, transitionConfig), { actions: actions_1.toActionObjects(utils_1.toArray(transitionConfig.actions)), cond: utils_1.toGuard(transitionConfig.cond, guards), target: target, source: this, internal: internal, eventType: transitionConfig.event });
|
|
1331
|
+
Object.defineProperty(transition, 'toJSON', {
|
|
1332
|
+
value: function () { return (__assign(__assign({}, transition), { target: transition.target
|
|
1333
|
+
? transition.target.map(function (t) { return "#" + t.id; })
|
|
1334
|
+
: undefined, source: "#{this.id}" })); }
|
|
1335
|
+
});
|
|
1336
|
+
return transition;
|
|
1330
1337
|
};
|
|
1331
1338
|
StateNode.prototype.formatTransitions = function () {
|
|
1332
1339
|
var e_9, _a;
|
package/lib/actions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML } from './types';
|
|
1
|
+
import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta } from './types';
|
|
2
2
|
import * as actionTypes from './actionTypes';
|
|
3
3
|
export { actionTypes };
|
|
4
4
|
export declare const initEvent: SCXML.Event<{
|
|
@@ -6,7 +6,7 @@ export declare const initEvent: SCXML.Event<{
|
|
|
6
6
|
}>;
|
|
7
7
|
export declare function getActionFunction<TContext, TEvent extends EventObject>(actionType: ActionType, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | undefined;
|
|
8
8
|
export declare function toActionObject<TContext, TEvent extends EventObject>(action: Action<TContext, TEvent>, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent>;
|
|
9
|
-
export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: string | ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | AssignAction<Required<TContext>, TEvent> | SendAction<TContext, TEvent> |
|
|
9
|
+
export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: string | RaiseAction<import("./types").AnyEventObject> | ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | AssignAction<Required<TContext>, TEvent> | SendAction<TContext, TEvent> | Action<TContext, TEvent>[] | undefined, actionFunctionMap?: Record<string, ActionFunction<TContext, TEvent> | ActionObject<TContext, TEvent>> | undefined) => ActionObject<TContext, TEvent>[];
|
|
10
10
|
export declare function toActivityDefinition<TContext, TEvent extends EventObject>(action: string | ActivityDefinition<TContext, TEvent>): ActivityDefinition<TContext, TEvent>;
|
|
11
11
|
/**
|
|
12
12
|
* Raises an event. This places the event in the internal event queue, so that
|
|
@@ -121,8 +121,9 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
|
|
|
121
121
|
/**
|
|
122
122
|
* Escalates an error by sending it as an event to this machine's parent.
|
|
123
123
|
*
|
|
124
|
-
* @param errorData The error data to send
|
|
124
|
+
* @param errorData The error data to send, or the expression function that
|
|
125
|
+
* takes in the `context`, `event`, and `meta`, and returns the error data to send.
|
|
125
126
|
* @param options Options to pass into the send action creator.
|
|
126
127
|
*/
|
|
127
|
-
export declare function escalate<TContext, TEvent extends EventObject>(errorData:
|
|
128
|
+
export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent>;
|
|
128
129
|
//# sourceMappingURL=actions.d.ts.map
|
package/lib/actions.js
CHANGED
|
@@ -351,13 +351,18 @@ exports.forwardTo = forwardTo;
|
|
|
351
351
|
/**
|
|
352
352
|
* Escalates an error by sending it as an event to this machine's parent.
|
|
353
353
|
*
|
|
354
|
-
* @param errorData The error data to send
|
|
354
|
+
* @param errorData The error data to send, or the expression function that
|
|
355
|
+
* takes in the `context`, `event`, and `meta`, and returns the error data to send.
|
|
355
356
|
* @param options Options to pass into the send action creator.
|
|
356
357
|
*/
|
|
357
358
|
function escalate(errorData, options) {
|
|
358
|
-
return sendParent({
|
|
359
|
-
|
|
360
|
-
|
|
359
|
+
return sendParent(function (context, event, meta) {
|
|
360
|
+
return {
|
|
361
|
+
type: actionTypes.error,
|
|
362
|
+
data: utils_1.isFunction(errorData)
|
|
363
|
+
? errorData(context, event, meta)
|
|
364
|
+
: errorData
|
|
365
|
+
};
|
|
361
366
|
}, __assign(__assign({}, options), { to: types_1.SpecialTargets.Parent }));
|
|
362
367
|
}
|
|
363
368
|
exports.escalate = escalate;
|