xstate 6.0.0-alpha.2 → 6.0.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -17
- package/bin/xstate.js +36 -0
- package/dist/{StateMachine-64813f46.cjs.js → StateMachine-1b155670.cjs.js} +182 -40
- package/dist/{StateMachine-2dcdb1f5.esm.js → StateMachine-3c17fe3e.esm.js} +182 -40
- package/dist/{StateMachine-8d22a79c.development.cjs.js → StateMachine-550ff7f2.development.cjs.js} +193 -36
- package/dist/{StateMachine-2ea0a7fa.development.esm.js → StateMachine-e25dd61f.development.esm.js} +193 -36
- package/dist/declarations/src/State.d.ts +13 -2
- package/dist/declarations/src/StateMachine.d.ts +23 -13
- package/dist/declarations/src/actions.d.ts +2 -1
- package/dist/declarations/src/actors/promise.d.ts +4 -2
- package/dist/declarations/src/createActor.d.ts +9 -11
- package/dist/declarations/src/createMachine.d.ts +14 -11
- package/dist/declarations/src/createMachineFromConfig.d.ts +61 -28
- package/dist/declarations/src/fsm.d.ts +74 -0
- package/dist/declarations/src/graph/graph.d.ts +3 -3
- package/dist/declarations/src/graph/shortestPaths.d.ts +2 -2
- package/dist/declarations/src/graph/simplePaths.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +6 -5
- package/dist/declarations/src/serialize.d.ts +10 -18
- package/dist/declarations/src/setup.d.ts +277 -65
- package/dist/declarations/src/spawn.d.ts +3 -3
- package/dist/declarations/src/stateUtils.d.ts +4 -1
- package/dist/declarations/src/system.d.ts +1 -1
- package/dist/declarations/src/transition.d.ts +8 -5
- package/dist/declarations/src/transitionActions.d.ts +12 -0
- package/dist/declarations/src/types.d.ts +237 -102
- package/dist/declarations/src/types.v6.d.ts +132 -58
- package/dist/declarations/src/utils.d.ts +4 -3
- package/dist/{index-93edd3bd.esm.js → index-3f87408c.esm.js} +936 -1389
- package/dist/{index-e61170ba.development.esm.js → index-d39fb138.development.esm.js} +968 -1421
- package/dist/{index-9cb3b3a0.cjs.js → index-e694228c.cjs.js} +945 -1394
- package/dist/{index-f6ef20d1.development.cjs.js → index-ec7c7a2d.development.cjs.js} +977 -1426
- 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 +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 +1100 -182
- package/dist/xstate.cjs.mjs +3 -5
- package/dist/xstate.development.cjs.js +1100 -182
- package/dist/xstate.development.cjs.mjs +3 -5
- package/dist/xstate.development.esm.js +1101 -181
- package/dist/xstate.esm.js +1101 -181
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +6 -2
- package/dist/declarations/src/atom.d.ts +0 -81
|
@@ -1,52 +1,115 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "./schema.types.js";
|
|
2
2
|
import { StateMachine } from "./StateMachine.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
3
|
+
import { type Actor, type RequiredActorOptionsKeys } from "./createActor.js";
|
|
4
|
+
import { AnyActorRef, AnyActorLogic, ActorRefFromLogic, AnyStateNode, EventObject, AnyEventObject, EventDescriptor, ExtractEvent, MachineContext, ProvidedActor, RoutableStateId, StateSchema, StateValue, ToChildren, MetaObject, Cast, Compute, EnqueueObject, DoneActorEvent, DoneStateEvent, ErrorActorEvent, SystemRegistry, RegistryKeyForLogic, ActorOptions, Observer, Subscription, OutputArg, SnapshotEvent, SingleOrArray } from "./types.js";
|
|
5
|
+
import { AnyActorSystem } from "./system.js";
|
|
6
|
+
import { InspectionEvent } from "./inspection.js";
|
|
7
|
+
import { ActionSchemas, DelayMapFromNames, GuardSchemas, InferChildren, InferActions, InferGuards, Implementations, InferOutput, InferEvents, Next_MachineConfig, Next_InvokeConfig, Next_StateNodeConfig, Next_TransitionConfigOrTarget, WithDefault } from "./types.v6.js";
|
|
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
|
+
schemas?: TSchemas & SetupSchemas;
|
|
10
|
+
states?: TStates;
|
|
11
|
+
actions?: TActionMap;
|
|
12
|
+
actorSources?: TActorMap;
|
|
13
|
+
guards?: TGuardMap;
|
|
14
|
+
delays?: TDelayMap;
|
|
15
|
+
};
|
|
16
|
+
export type AnySetupConfig = SetupConfig<SetupSchemas, Record<string, SetupStateSchema>, Implementations['actions'], Implementations['actorSources'], Implementations['guards'], Implementations['delays']>;
|
|
17
|
+
export type SystemConfig<TSystemRegistry extends SystemRegistry> = {
|
|
18
|
+
registry?: TSystemRegistry;
|
|
19
|
+
};
|
|
20
|
+
export type SystemActorMap<TSystemRegistry extends SystemRegistry> = {
|
|
21
|
+
[K in keyof TSystemRegistry & string]: ActorRefFromLogic<TSystemRegistry[K]>;
|
|
22
|
+
};
|
|
23
|
+
export type SystemRuntime<TSystemRegistry extends SystemRegistry> = Omit<AnyActorSystem, 'get' | 'getAll'> & {
|
|
24
|
+
get<K extends keyof SystemActorMap<TSystemRegistry> & string>(key: K): SystemActorMap<TSystemRegistry>[K] | undefined;
|
|
25
|
+
getAll(): Partial<SystemActorMap<TSystemRegistry>>;
|
|
26
|
+
};
|
|
27
|
+
type LogicMatchesRegistryKey<TLogic, TSystemLogic> = TLogic extends AnyActorLogic ? TSystemLogic extends AnyActorLogic ? [TLogic] extends [TSystemLogic] ? true : [TSystemLogic] extends [TLogic] ? true : ActorRefFromLogic<TLogic> extends ActorRefFromLogic<TSystemLogic> ? true : false : false : false;
|
|
28
|
+
type RegistryKeyMatchesSrc<TKey extends string, TSrc, TSystemRegistry extends SystemRegistry, TActorMap extends Implementations['actorSources']> = TKey extends keyof TSystemRegistry & string ? TSrc extends keyof TActorMap & string ? LogicMatchesRegistryKey<TActorMap[TSrc], TSystemRegistry[TKey]> : TSrc extends AnyActorLogic ? LogicMatchesRegistryKey<TSrc, TSystemRegistry[TKey]> : true : false;
|
|
29
|
+
type ValidateSystemInvoke<TInvoke, TSystemRegistry extends SystemRegistry, TActorMap extends Implementations['actorSources']> = TInvoke extends readonly unknown[] ? {
|
|
30
|
+
[K in keyof TInvoke]: TInvoke[K] & ValidateSystemInvoke<TInvoke[K], TSystemRegistry, TActorMap>;
|
|
31
|
+
} : TInvoke extends {
|
|
32
|
+
registryKey: infer TKey;
|
|
33
|
+
} ? TKey extends string ? TInvoke extends {
|
|
34
|
+
src: infer TSrc;
|
|
35
|
+
} ? RegistryKeyMatchesSrc<TKey, TSrc, TSystemRegistry, TActorMap> extends true ? unknown : {
|
|
36
|
+
registryKey: never;
|
|
37
|
+
} : TKey extends keyof TSystemRegistry & string ? unknown : {
|
|
38
|
+
registryKey: never;
|
|
39
|
+
} : {
|
|
40
|
+
registryKey: never;
|
|
41
|
+
} : unknown;
|
|
42
|
+
type ValidateRegistryKeys<TConfig, TSystemRegistry extends SystemRegistry, TActorMap extends Implementations['actorSources']> = string extends keyof TSystemRegistry ? unknown : (TConfig extends {
|
|
43
|
+
invoke: infer TInvoke;
|
|
44
|
+
} ? {
|
|
45
|
+
invoke: TInvoke & ValidateSystemInvoke<TInvoke, TSystemRegistry, TActorMap>;
|
|
46
|
+
} : unknown) & (TConfig extends {
|
|
47
|
+
states: infer TStates;
|
|
48
|
+
} ? {
|
|
49
|
+
states: {
|
|
50
|
+
[K in keyof TStates]: TStates[K] & ValidateRegistryKeys<TStates[K], TSystemRegistry, TActorMap>;
|
|
51
|
+
};
|
|
52
|
+
} : unknown);
|
|
53
|
+
export type SetupStateSchemas = {
|
|
6
54
|
context?: StandardSchemaV1;
|
|
7
55
|
input?: StandardSchemaV1;
|
|
8
56
|
};
|
|
9
|
-
type SetupSchemas = {
|
|
57
|
+
export type SetupSchemas = {
|
|
10
58
|
context?: StandardSchemaV1;
|
|
11
59
|
events?: Record<string, StandardSchemaV1>;
|
|
60
|
+
actions?: ActionSchemas;
|
|
61
|
+
guards?: GuardSchemas;
|
|
12
62
|
emitted?: Record<string, StandardSchemaV1>;
|
|
13
63
|
input?: StandardSchemaV1;
|
|
14
64
|
output?: StandardSchemaV1;
|
|
15
65
|
meta?: StandardSchemaV1;
|
|
16
66
|
tags?: StandardSchemaV1;
|
|
67
|
+
children?: Record<string, StandardSchemaV1>;
|
|
17
68
|
};
|
|
18
69
|
/** State schema with optional schemas.input and nested states */
|
|
19
|
-
interface SetupStateSchema {
|
|
70
|
+
export interface SetupStateSchema {
|
|
20
71
|
schemas?: SetupStateSchemas;
|
|
21
72
|
states?: Record<string, SetupStateSchema>;
|
|
22
73
|
}
|
|
23
74
|
type SetupSchema<TSchemas, TKey extends keyof SetupSchemas> = TKey extends keyof TSchemas ? TSchemas[TKey] extends StandardSchemaV1 ? TSchemas[TKey] : never : never;
|
|
24
|
-
type SetupSchemaMap<TSchemas, TKey extends 'events' | 'emitted'> = TKey extends keyof TSchemas ? TSchemas[TKey] extends Record<string, StandardSchemaV1> ? TSchemas[TKey] : never : never;
|
|
25
|
-
type
|
|
26
|
-
type
|
|
75
|
+
type SetupSchemaMap<TSchemas, TKey extends 'events' | 'emitted' | 'children'> = TKey extends keyof TSchemas ? TSchemas[TKey] extends Record<string, StandardSchemaV1> ? TSchemas[TKey] : never : never;
|
|
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>;
|
|
79
|
+
type SetupOrConfigSchemaMap<TSchemas, TKey extends 'events' | 'emitted' | 'children', TConfigSchemaMap extends Record<string, StandardSchemaV1>> = [SetupSchemaMap<TSchemas, TKey>] extends [never] ? TConfigSchemaMap : SetupSchemaMap<TSchemas, TKey>;
|
|
27
80
|
type SetupStateKeys<TStateSchemas extends Record<string, SetupStateSchema>> = keyof TStateSchemas & string;
|
|
28
81
|
type SetupStateKey<TStateSchemas extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStateSchemas> ? string : [SetupStateKeys<TStateSchemas>] extends [never] ? string : SetupStateKeys<TStateSchemas>;
|
|
29
82
|
type SetupStateTarget<TStateSchemas extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStateSchemas> ? string : [SetupStateKeys<TStateSchemas>] extends [never] ? string : SetupStateKeys<TStateSchemas> | `.${string}` | `#${string}`;
|
|
30
|
-
type
|
|
31
|
-
|
|
32
|
-
} ? Exclude<keyof TStates & string, SetupStateKeys<TStateSchemas>> : never;
|
|
33
|
-
type ValidateSetupStateKeys<TConfig, TStateSchemas extends Record<string, SetupStateSchema>> = [InvalidSetupStateKeys<TConfig, TStateSchemas>] extends [never] ? unknown : {
|
|
34
|
-
states: {
|
|
35
|
-
[K in InvalidSetupStateKeys<TConfig, TStateSchemas>]: never;
|
|
36
|
-
};
|
|
83
|
+
type StateSchemasWithKeys<TStateSchemas extends Record<string, SetupStateSchema>, TStateKeys extends string> = TStateSchemas & {
|
|
84
|
+
[K in Exclude<TStateKeys, keyof TStateSchemas>]: {};
|
|
37
85
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
86
|
+
/**
|
|
87
|
+
* The sibling state schemas of a dotted path: the children of the path's
|
|
88
|
+
* parent. A bare transition target resolves relative to the parent, so the
|
|
89
|
+
* valid targets for a path's config are its siblings. For a dotless (top-level)
|
|
90
|
+
* path the siblings are the root states.
|
|
91
|
+
*/
|
|
92
|
+
type ResolveStateSiblings<TStates extends Record<string, SetupStateSchema>, TPath extends string> = TPath extends `${infer Head}.${infer Rest}` ? Head extends keyof TStates ? TStates[Head]['states'] extends Record<string, SetupStateSchema> ? ResolveStateSiblings<TStates[Head]['states'], Rest> : never : never : TStates;
|
|
93
|
+
/**
|
|
94
|
+
* Resolves a dotted state path (e.g. `'parent.child'`) into the leaf
|
|
95
|
+
* `SetupStateSchema` it addresses, or `never` if any segment is missing.
|
|
96
|
+
*/
|
|
97
|
+
type ResolveStatePath<TStates extends Record<string, SetupStateSchema>, TPath extends string> = TPath extends `${infer Head}.${infer Rest}` ? Head extends keyof TStates ? TStates[Head]['states'] extends Record<string, SetupStateSchema> ? ResolveStatePath<TStates[Head]['states'], Rest> : never : never : TPath extends keyof TStates ? TStates[TPath] : never;
|
|
98
|
+
/** Union of every addressable dotted path into a setup states tree */
|
|
99
|
+
type StatePathsInner<TStates extends Record<string, SetupStateSchema>> = {
|
|
100
|
+
[K in SetupStateKeys<TStates>]: K | (TStates[K]['states'] extends Record<string, SetupStateSchema> ? `${K}.${StatePathsInner<TStates[K]['states']>}` : never);
|
|
101
|
+
}[SetupStateKeys<TStates>];
|
|
102
|
+
type StatePaths<TStates extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStates> ? string : [SetupStateKeys<TStates>] extends [never] ? string : StatePathsInner<TStates>;
|
|
103
|
+
/**
|
|
104
|
+
* Shared body of both `createStateConfig` overloads: the
|
|
105
|
+
* `StateNodeConfigWithNestedInput` instantiation whose only varying parts are
|
|
106
|
+
* the leading sibling-schemas and state-schema arguments.
|
|
107
|
+
*/
|
|
108
|
+
type SetupStateNodeConfig<TStates extends Record<string, SetupStateSchema>, TStateSchema extends SetupStateSchema, TSchemas extends SetupSchemas, TSetupActionMap extends Implementations['actions'], TSetupActorMap extends Implementations['actorSources'], TSetupGuardMap extends Implementations['guards'], TSetupDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = StateNodeConfigWithNestedInput<TStates, TStateSchema, 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>;
|
|
47
109
|
type SetupContext<TSchemas, TContextSchema extends StandardSchemaV1> = [
|
|
48
110
|
SetupSchema<TSchemas, 'context'>
|
|
49
111
|
] extends [never] ? unknown extends StandardSchemaV1.InferOutput<TContextSchema> ? MachineContext : StandardSchemaV1.InferOutput<TContextSchema> & MachineContext : StandardSchemaV1.InferOutput<SetupSchema<TSchemas, 'context'>> & MachineContext;
|
|
112
|
+
type SetupContextShape<TSchemas, TContextSchema extends StandardSchemaV1, TFallbackContext> = [SetupSchema<TSchemas, 'context'>] extends [never] ? unknown extends StandardSchemaV1.InferOutput<TContextSchema> ? TFallbackContext : StandardSchemaV1.InferOutput<TContextSchema> : StandardSchemaV1.InferOutput<SetupSchema<TSchemas, 'context'>>;
|
|
50
113
|
type SetupContextRequired<TSchemas, TContextSchema extends StandardSchemaV1> = [
|
|
51
114
|
SetupSchema<TSchemas, 'context'>
|
|
52
115
|
] extends [never] ? unknown extends StandardSchemaV1.InferOutput<TContextSchema> ? false : true : true;
|
|
@@ -64,18 +127,56 @@ type SetupEmitted<TSchemas, TEmittedSchemaMap extends Record<string, StandardSch
|
|
|
64
127
|
type SetupMeta<TSchemas, TMetaSchema extends StandardSchemaV1> = [
|
|
65
128
|
SetupSchema<TSchemas, 'meta'>
|
|
66
129
|
] extends [never] ? InferOutput<TMetaSchema, MetaObject> : InferOutput<SetupSchema<TSchemas, 'meta'>, MetaObject>;
|
|
130
|
+
type SetupChildren<TSchemas, TChildrenSchemaMap extends Record<string, StandardSchemaV1>> = [SetupSchemaMap<TSchemas, 'children'>] extends [never] ? InferChildren<TChildrenSchemaMap> : InferChildren<SetupSchemaMap<TSchemas, 'children'>>;
|
|
131
|
+
type SetupActions<TSchemas, TActionMap extends Implementations['actions']> = [
|
|
132
|
+
SetupActionSchemaMap<TSchemas>
|
|
133
|
+
] extends [never] ? TActionMap : MergeImplementationMaps<InferActions<SetupActionSchemaMap<TSchemas>>, TActionMap>;
|
|
134
|
+
type SetupGuards<TSchemas, TGuardMap extends Implementations['guards']> = [
|
|
135
|
+
SetupGuardSchemaMap<TSchemas>
|
|
136
|
+
] extends [never] ? TGuardMap : MergeImplementationMaps<InferGuards<SetupGuardSchemaMap<TSchemas>>, TGuardMap>;
|
|
137
|
+
type MergeChildren<TChildren extends Record<string, AnyActorRef | undefined>, TActor extends ProvidedActor> = [keyof TChildren] extends [never] ? Compute<ToChildren<TActor>> : Compute<TChildren>;
|
|
138
|
+
type MergeImplementationMaps<TBase extends Record<string, unknown>, TExtension extends Record<string, unknown>> = Compute<TBase & TExtension>;
|
|
139
|
+
type DelayNamesFromConfigOrString<TConfig> = TConfig extends {
|
|
140
|
+
delays: infer TDelays;
|
|
141
|
+
} ? Extract<keyof TDelays, string> : string;
|
|
142
|
+
type DelayNamesFromConfig<TConfig> = TConfig extends {
|
|
143
|
+
delays: infer TDelays;
|
|
144
|
+
} ? Extract<keyof TDelays, string> : never;
|
|
145
|
+
type InvalidDelayReferences<TConfig, TDelays extends string> = (TConfig extends {
|
|
146
|
+
after: infer TAfter;
|
|
147
|
+
} ? Exclude<Extract<keyof TAfter, string>, TDelays> : never) | (TConfig extends {
|
|
148
|
+
timeout: infer TTimeout;
|
|
149
|
+
} ? TTimeout extends string ? TTimeout extends TDelays ? never : TTimeout : never : never) | (TConfig extends {
|
|
150
|
+
states: infer TStates;
|
|
151
|
+
} ? TStates extends Record<string, unknown> ? {
|
|
152
|
+
[K in keyof TStates]: InvalidDelayReferences<TStates[K], TDelays>;
|
|
153
|
+
}[keyof TStates] : never : never);
|
|
154
|
+
type ValidateSetupDelayReferences<TConfig, TSetupDelays extends string> = string extends ([
|
|
155
|
+
TSetupDelays
|
|
156
|
+
] extends [never] ? DelayNamesFromConfigOrString<TConfig> : TSetupDelays | DelayNamesFromConfig<TConfig>) ? unknown : InvalidDelayReferences<TConfig, [
|
|
157
|
+
TSetupDelays
|
|
158
|
+
] extends [never] ? DelayNamesFromConfigOrString<TConfig> : TSetupDelays | DelayNamesFromConfig<TConfig>> extends never ? unknown : never;
|
|
67
159
|
/** Extracts input type from a state schema */
|
|
68
160
|
type StateInput<TStateSchema extends SetupStateSchema> = TStateSchema['schemas'] extends {
|
|
69
161
|
input: infer TInputSchema;
|
|
70
162
|
} ? TInputSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TInputSchema> : undefined : undefined;
|
|
71
163
|
type StateContext<TStateSchema extends SetupStateSchema, TFallbackContext extends MachineContext> = TStateSchema['schemas'] extends {
|
|
72
164
|
context: infer TContextSchema;
|
|
73
|
-
} ? TContextSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TContextSchema> & MachineContext : TFallbackContext : TFallbackContext
|
|
165
|
+
} ? TContextSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TContextSchema> & MachineContext & RootContextMarker<TFallbackContext> : RootContext<TFallbackContext> : RootContext<TFallbackContext>;
|
|
166
|
+
declare const rootContext: unique symbol;
|
|
167
|
+
type RootContextMarker<TContext> = {
|
|
168
|
+
readonly [rootContext]?: RootContext<TContext>;
|
|
169
|
+
};
|
|
170
|
+
type RootContext<TContext> = typeof rootContext extends keyof TContext ? TContext[typeof rootContext] : TContext;
|
|
171
|
+
type StateContextShape<TStateSchema extends SetupStateSchema, TFallbackContext> = TStateSchema['schemas'] extends {
|
|
172
|
+
context: infer TContextSchema;
|
|
173
|
+
} ? TContextSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TContextSchema> & RootContextMarker<TFallbackContext> : RootContext<TFallbackContext> : RootContext<TFallbackContext>;
|
|
74
174
|
type WithNestedStates<TConfig, TNestedStates> = TConfig extends {
|
|
75
175
|
type: 'choice';
|
|
76
176
|
} ? TConfig : Omit<TConfig, 'states'> & {
|
|
77
177
|
states?: TNestedStates;
|
|
78
178
|
};
|
|
179
|
+
type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
|
|
79
180
|
/**
|
|
80
181
|
* Converts SetupStateSchema to StateSchema with input types included. This
|
|
81
182
|
* allows getInputs() to be strongly typed.
|
|
@@ -122,67 +223,130 @@ type MergeStateSchema<TConfig extends StateSchema, TSetup extends StateSchema> =
|
|
|
122
223
|
} : undefined : undefined;
|
|
123
224
|
};
|
|
124
225
|
/** Machine config with typed state input */
|
|
125
|
-
type SetupMachineConfig<TStateSchemas extends Record<string, SetupStateSchema>, TSchemas extends SetupSchemas, 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, TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
126
|
-
|
|
127
|
-
|
|
226
|
+
type SetupMachineConfig<TStateSchemas extends Record<string, SetupStateSchema>, TStateKeys extends string, TSchemas extends SetupSchemas, 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>, TContext extends MachineContext, 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, TContextRequired extends boolean, TRootDelays extends string = TDelays, TRootActionMap extends Implementations['actions'] = TActionMap, TRootActorMap extends Implementations['actorSources'] = TActorMap, TRootGuardMap extends Implementations['guards'] = TGuardMap> = Omit<Next_MachineConfig<SetupOrConfigSchema<TSchemas, 'context', TContextSchema>, SetupOrConfigSchemaMap<TSchemas, 'events', TEventSchemaMap>, SetupOrConfigSchemaMap<TSchemas, 'emitted', TEmittedSchemaMap>, SetupOrConfigSchema<TSchemas, 'input', TInputSchema>, SetupOrConfigSchema<TSchemas, 'output', TOutputSchema>, SetupOrConfigSchema<TSchemas, 'meta', TMetaSchema>, SetupOrConfigSchema<TSchemas, 'tags', TTagSchema>, SetupOrConfigSchemaMap<TSchemas, 'children', TChildrenSchemaMap>, TContext, TEvent, TChildren, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap, TContextRequired, TSystemRegistry>, 'states' | 'initial' | 'on' | 'always' | 'invoke' | 'actions' | 'actorSources' | 'guards' | 'delays'> & {
|
|
227
|
+
actions?: TRootActionMap;
|
|
228
|
+
actorSources?: TRootActorMap;
|
|
229
|
+
guards?: TRootGuardMap;
|
|
230
|
+
delays?: {
|
|
231
|
+
[K in TRootDelays | number]?: number | (({ context, event, stateNode }: {
|
|
232
|
+
context: TContext;
|
|
233
|
+
event: TEvent;
|
|
234
|
+
stateNode: AnyStateNode;
|
|
235
|
+
}) => number);
|
|
236
|
+
};
|
|
237
|
+
initial?: TStateKeys | InitialTransitionWithInput<TStateSchemas, TContext, TEvent> | undefined;
|
|
238
|
+
on?: StateTransitions<TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
239
|
+
always?: StateTransitionConfigOrTarget<TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
240
|
+
invoke?: SingleOrArray<SetupInvokeConfig<TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>>;
|
|
241
|
+
states?: StatesWithInput<TStateSchemas, TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TChildren, TDelays, TTag, SetupOutput<TSchemas, TOutputSchema>, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, TStateKeys>;
|
|
128
242
|
};
|
|
129
243
|
/** States config type that provides typed input for known states */
|
|
130
|
-
type StatesWithInput<TRootStateSchemas extends Record<string, SetupStateSchema>, TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
131
|
-
[K in
|
|
244
|
+
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, TStateKeys extends string = SetupStateKey<TStateSchemas>> = {
|
|
245
|
+
[K in TStateKeys]?: StateNodeConfigWithNestedInput<StateSchemasWithKeys<TRootStateSchemas, TStateKeys>, K extends keyof TStateSchemas ? TStateSchemas[K] : {}, TContext, TContextShape, TEvent, TChildren, TDelays, TTag, TOutput, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
132
246
|
};
|
|
133
247
|
/** State node config that recursively applies typed input for nested states */
|
|
134
|
-
type StateNodeConfigWithNestedInput<TSiblingStateSchemas extends Record<string, SetupStateSchema>, TStateSchema extends SetupStateSchema, TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
135
|
-
initial?: TStateSchema['states'] extends Record<string, SetupStateSchema> ? SetupStateKey<TStateSchema['states']> | InitialTransitionWithInput<TStateSchema['states'], StateContext<TStateSchema, TContext>, TEvent> : string | {
|
|
248
|
+
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' | 'invoke' | 'onDone'> & {
|
|
249
|
+
initial?: TStateSchema['states'] extends Record<string, SetupStateSchema> ? SetupStateKey<TStateSchema['states']> | (string & {}) | InitialTransitionWithInput<TStateSchema['states'], StateContext<TStateSchema, TContext>, TEvent> : string | {
|
|
136
250
|
target: string;
|
|
137
251
|
input?: Record<string, unknown>;
|
|
138
252
|
} | undefined;
|
|
139
|
-
on?: StateTransitions<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, TEvent, TEmitted, TMeta
|
|
140
|
-
always?: StateTransitionConfigOrTarget<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, TEvent, TEvent, TEmitted, TMeta
|
|
141
|
-
|
|
142
|
-
|
|
253
|
+
on?: StateTransitions<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, StateContextShape<TStateSchema, TContextShape>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, StateInput<TStateSchema>>;
|
|
254
|
+
always?: StateTransitionConfigOrTarget<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, StateContextShape<TStateSchema, TContextShape>, TEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, StateInput<TStateSchema>>;
|
|
255
|
+
invoke?: SingleOrArray<SetupInvokeConfig<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, StateContextShape<TStateSchema, TContextShape>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>>;
|
|
256
|
+
onDone?: StateTransitionConfigOrTarget<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, StateContextShape<TStateSchema, TContextShape>, DoneStateEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, StateInput<TStateSchema>>;
|
|
257
|
+
}, 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> : {
|
|
258
|
+
[K in string]?: Next_StateNodeConfig<TContext, TEvent, TDelays, TTag, TOutput, TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, undefined, Record<string, unknown>, TSystemRegistry>;
|
|
143
259
|
}>;
|
|
144
|
-
type StateTransitions<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject> = {
|
|
145
|
-
[K in EventDescriptor<TEvent>]?: StateTransitionConfigOrTarget<TStateSchemas, TContext, ExtractEvent<TEvent, K>, TEvent, TEmitted, TMeta>;
|
|
260
|
+
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, TInput = undefined> = {
|
|
261
|
+
[K in EventDescriptor<TEvent>]?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, ExtractEvent<TEvent, K>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, TInput>;
|
|
146
262
|
};
|
|
147
|
-
type
|
|
148
|
-
|
|
263
|
+
type InvokeDoneEvent<TInvoke> = TInvoke extends {
|
|
264
|
+
onDone?: Next_TransitionConfigOrTarget<infer _TContext, infer TDoneEvent, infer _TEvent, infer _TEmitted, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap, infer _TMeta>;
|
|
265
|
+
} ? Cast<TDoneEvent, EventObject> : DoneActorEvent;
|
|
266
|
+
type SetupInvokeConfig<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> = Next_InvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry> extends infer TInvoke ? TInvoke extends any ? DistributiveOmit<TInvoke, 'onDone' | 'onError' | 'onSnapshot' | 'onTimeout'> & {
|
|
267
|
+
onDone?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, InvokeDoneEvent<TInvoke>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
268
|
+
onError?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, ErrorActorEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
269
|
+
onSnapshot?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, SnapshotEvent<any>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
270
|
+
onTimeout?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, TEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
271
|
+
} : never : never;
|
|
272
|
+
type StateTransitionConfigOrTarget<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TExpressionEvent extends EventObject, 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, TInput = undefined> = undefined | StateTransitionObjectConfig<TStateSchemas, TContext, TContextShape, TExpressionEvent, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry> | StateTransitionFunction<TStateSchemas, TContext, TContextShape, TExpressionEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, TInput>;
|
|
273
|
+
type StateTransitionObjectConfig<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TExpressionEvent 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> = (StateTransitionResult<TStateSchemas, TContext, TContextShape, TMeta, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, true> & {
|
|
274
|
+
description?: string;
|
|
275
|
+
}) | {
|
|
276
|
+
target: SetupStateTarget<TStateSchemas>[];
|
|
277
|
+
context?: StateTransitionContext<true, TContext, TContextShape, TContextShape, TContext, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
149
278
|
description?: string;
|
|
150
279
|
reenter?: boolean;
|
|
151
280
|
meta?: TMeta;
|
|
152
281
|
input?: Record<string, unknown> | ((args: {
|
|
153
282
|
context: TContext;
|
|
154
283
|
event: TExpressionEvent;
|
|
155
|
-
}) => Record<string, unknown>);
|
|
156
|
-
}
|
|
157
|
-
type
|
|
284
|
+
} & OutputArg<TExpressionEvent>) => Record<string, unknown>);
|
|
285
|
+
};
|
|
286
|
+
type StateTransitionContextMapper<TContext extends MachineContext, TContextShape, TTargetContextShape, TResolvedTargetContext extends MachineContext, TExpressionEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = (args: {
|
|
287
|
+
context: TContext;
|
|
288
|
+
event: TExpressionEvent;
|
|
289
|
+
self: AnyActorRef;
|
|
290
|
+
parent: AnyActorRef | undefined;
|
|
291
|
+
value: StateValue;
|
|
292
|
+
children: TChildren;
|
|
293
|
+
system: SystemRuntime<TSystemRegistry>;
|
|
294
|
+
actions: TActionMap;
|
|
295
|
+
actorSources: TActorMap;
|
|
296
|
+
guards: TGuardMap;
|
|
297
|
+
delays: TDelayMap;
|
|
298
|
+
} & OutputArg<TExpressionEvent>) => ContextPatch<TContextShape, TTargetContextShape, TResolvedTargetContext>;
|
|
299
|
+
type StateTransitionContextOrMapper<TContext extends MachineContext, TContextShape, TTargetContextShape, TResolvedTargetContext extends MachineContext, TExpressionEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = ContextPatch<TContextShape, TTargetContextShape, TResolvedTargetContext> | StateTransitionContextMapper<TContext, TContextShape, TTargetContextShape, TResolvedTargetContext, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
300
|
+
type StateTransitionContext<TAllowMapper extends boolean, TContext extends MachineContext, TContextShape, TTargetContextShape, TResolvedTargetContext extends MachineContext, TExpressionEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = TAllowMapper extends true ? StateTransitionContextOrMapper<TContext, TContextShape, TTargetContextShape, TResolvedTargetContext, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry> : ContextPatch<TContextShape, TTargetContextShape, TResolvedTargetContext>;
|
|
301
|
+
type StateTransitionFunction<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TExpressionEvent extends EventObject, 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, TInput = undefined> = (args: {
|
|
158
302
|
context: TContext;
|
|
159
303
|
event: TExpressionEvent;
|
|
160
304
|
self: AnyActorRef;
|
|
161
305
|
parent: AnyActorRef | undefined;
|
|
162
306
|
value: StateValue;
|
|
163
|
-
children:
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
307
|
+
children: TChildren;
|
|
308
|
+
system: SystemRuntime<TSystemRegistry>;
|
|
309
|
+
actions: TActionMap;
|
|
310
|
+
actorSources: TActorMap;
|
|
311
|
+
guards: TGuardMap;
|
|
312
|
+
delays: TDelayMap;
|
|
313
|
+
input: TInput;
|
|
314
|
+
} & OutputArg<TExpressionEvent>, enq: EnqueueObject<TEvent, TEmitted, TSystemRegistry>) => StateTransitionResult<TStateSchemas, TContext, TContextShape, TMeta, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, false> | void;
|
|
315
|
+
type StateTransitionResult<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TMeta extends MetaObject, TExpressionEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry, TAllowContextMapper extends boolean> = {
|
|
170
316
|
target?: never;
|
|
171
|
-
context?: TContext
|
|
317
|
+
context?: StateTransitionContext<TAllowContextMapper, TContext, TContextShape, TContextShape, TContext, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
172
318
|
reenter?: boolean;
|
|
173
319
|
meta?: TMeta;
|
|
174
320
|
} | {
|
|
175
321
|
[K in keyof TStateSchemas & string]: {
|
|
176
322
|
target: K;
|
|
177
|
-
context: StateContext<TStateSchemas[K], TContext>;
|
|
178
323
|
reenter?: boolean;
|
|
179
324
|
meta?: TMeta;
|
|
180
325
|
input?: StateInput<TStateSchemas[K]> | ((args: {
|
|
181
326
|
context: TContext;
|
|
182
327
|
event: EventObject;
|
|
183
|
-
}) => StateInput<TStateSchemas[K]>);
|
|
184
|
-
}
|
|
185
|
-
|
|
328
|
+
} & OutputArg<EventObject>) => StateInput<TStateSchemas[K]>);
|
|
329
|
+
} & ([TContextShape] extends [
|
|
330
|
+
StateContextShape<TStateSchemas[K], TContextShape>
|
|
331
|
+
] ? {
|
|
332
|
+
context?: StateTransitionContext<TAllowContextMapper, TContext, TContextShape, StateContextShape<TStateSchemas[K], TContextShape>, StateContext<TStateSchemas[K], TContext>, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
333
|
+
} : {
|
|
334
|
+
context: StateTransitionContext<TAllowContextMapper, TContext, TContextShape, StateContextShape<TStateSchemas[K], TContextShape>, StateContext<TStateSchemas[K], TContext>, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
335
|
+
});
|
|
336
|
+
}[keyof TStateSchemas & string] | {
|
|
337
|
+
target: Exclude<SetupStateTarget<TStateSchemas>, keyof TStateSchemas & string>;
|
|
338
|
+
context?: StateTransitionContext<TAllowContextMapper, TContext, TContextShape, TContextShape, TContext, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
339
|
+
reenter?: boolean;
|
|
340
|
+
meta?: TMeta;
|
|
341
|
+
};
|
|
342
|
+
type ContextPatch<TCurrentContext, TTargetContext, TResolvedTargetContext extends MachineContext> = Compute<Partial<TResolvedTargetContext> & Pick<TResolvedTargetContext, Extract<RequiredContextKeys<TCurrentContext, TTargetContext>, string>> & {
|
|
343
|
+
call?: never;
|
|
344
|
+
apply?: never;
|
|
345
|
+
bind?: never;
|
|
346
|
+
}>;
|
|
347
|
+
type RequiredContextKeys<TCurrentContext, TTargetContext> = {
|
|
348
|
+
[K in keyof TTargetContext]-?: K extends keyof TCurrentContext ? [TCurrentContext[K]] extends [TTargetContext[K]] ? never : K : K;
|
|
349
|
+
}[keyof TTargetContext];
|
|
186
350
|
/** Initial transition with typed input based on target state */
|
|
187
351
|
type InitialTransitionWithInput<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TEvent extends EventObject> = {
|
|
188
352
|
[K in keyof TStateSchemas & string]: {
|
|
@@ -194,29 +358,66 @@ type InitialTransitionWithInput<TStateSchemas extends Record<string, SetupStateS
|
|
|
194
358
|
};
|
|
195
359
|
}[keyof TStateSchemas & string];
|
|
196
360
|
/** Return type of setup() */
|
|
197
|
-
interface SetupReturn<TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TSchemas extends SetupSchemas = {}> {
|
|
361
|
+
export interface SetupReturn<TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TSchemas extends SetupSchemas = {}, TSetupActionMap extends Implementations['actions'] = {}, TSetupActorMap extends Implementations['actorSources'] = {}, TSetupGuardMap extends Implementations['guards'] = {}, TSetupDelayMap extends Implementations['delays'] = {}, TSetupDelays extends string = Extract<keyof TSetupDelayMap, string>, TSystemRegistry extends SystemRegistry = SystemRegistry> {
|
|
362
|
+
/** Extends the setup configuration */
|
|
363
|
+
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>;
|
|
198
364
|
/** Creates a state machine with the setup configuration */
|
|
199
|
-
createMachine<TContextSchema extends StandardSchemaV1, const TEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, _TEvent extends EventObject, TActor extends ProvidedActor, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
365
|
+
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, const TStateKeys extends string = SetupStateKey<TStates>, TConfig extends SetupMachineConfig<TStates, TStateKeys, 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, TStateKeys, 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: {
|
|
200
366
|
schemas?: {
|
|
201
367
|
events?: TEventSchemaMap;
|
|
202
368
|
context?: TContextSchema;
|
|
203
369
|
emitted?: TEmittedSchemaMap;
|
|
370
|
+
actions?: TActionSchemaMap;
|
|
371
|
+
guards?: TGuardSchemaMap;
|
|
204
372
|
input?: TInputSchema;
|
|
205
373
|
output?: TOutputSchema;
|
|
206
374
|
meta?: TMetaSchema;
|
|
207
375
|
tags?: TTagSchema;
|
|
376
|
+
children?: TChildrenSchemaMap;
|
|
208
377
|
};
|
|
209
|
-
|
|
378
|
+
actions?: TActionMap;
|
|
379
|
+
actorSources?: TActorMap;
|
|
380
|
+
guards?: TGuardMap;
|
|
381
|
+
delays?: TDelayMap;
|
|
382
|
+
states?: Record<TStateKeys, unknown>;
|
|
383
|
+
} & TConfig & ValidateSetupDelayReferences<TConfig, TSetupDelays> & ValidateRegistryKeys<TConfig, TSystemRegistry, MergeImplementationMaps<TSetupActorMap, TActorMap>>): StateMachine<SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap> | ([RoutableStateId<Cast<TConfig, StateSchema>>] extends [never] ? never : {
|
|
210
384
|
type: 'xstate.route';
|
|
211
385
|
to: RoutableStateId<Cast<TConfig, StateSchema>>;
|
|
212
|
-
}), Cast<
|
|
386
|
+
}), Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, StateValue, TTag & string, [
|
|
213
387
|
SetupSchema<TSchemas, 'input'>
|
|
214
|
-
] extends [never] ? TInput : SetupInput<TSchemas, TInputSchema>, SetupOutput<TSchemas, TOutputSchema>, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, MergeStateSchema<Cast<TConfig, StateSchema>, SetupStatesToStateSchema<TStates>>, TActionMap, TActorMap, TGuardMap
|
|
388
|
+
] 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>>>;
|
|
389
|
+
/**
|
|
390
|
+
* Creates a state node config bound to a specific setup-declared state,
|
|
391
|
+
* addressed by a dotted path (e.g. `'loading'` or `'parent.child'`). The
|
|
392
|
+
* addressed state's own `input` schema is typed inside `entry`/`exit` args.
|
|
393
|
+
*/
|
|
394
|
+
createStateConfig<const TPath extends StatePaths<TStates>, const TConfig extends SetupStateNodeConfig<ResolveStateSiblings<TStates, TPath>, ResolveStatePath<TStates, TPath>, TSchemas, TSetupActionMap, TSetupActorMap, TSetupGuardMap, TSetupDelayMap, TSystemRegistry>>(path: TPath, config: TConfig): TConfig;
|
|
215
395
|
/** Creates a state node config with the setup configuration */
|
|
216
|
-
createStateConfig<const TConfig extends
|
|
396
|
+
createStateConfig<const TConfig extends SetupStateNodeConfig<TStates, SetupStateSchema, TSchemas, TSetupActionMap, TSetupActorMap, TSetupGuardMap, TSetupDelayMap, TSystemRegistry>>(config: TConfig): TConfig;
|
|
217
397
|
/** State input schemas from setup config */
|
|
218
398
|
states: TStates;
|
|
399
|
+
/** Schemas from setup config */
|
|
400
|
+
schemas: TSchemas;
|
|
219
401
|
}
|
|
402
|
+
type SetupConfigSchemas<TConfig> = TConfig extends {
|
|
403
|
+
schemas?: infer TSchemas;
|
|
404
|
+
} ? TSchemas extends SetupSchemas ? TSchemas : {} : {};
|
|
405
|
+
type SetupConfigStates<TConfig> = TConfig extends {
|
|
406
|
+
states?: infer TStates;
|
|
407
|
+
} ? TStates extends Record<string, SetupStateSchema> ? TStates : Record<string, SetupStateSchema> : Record<string, SetupStateSchema>;
|
|
408
|
+
type SetupConfigActions<TConfig> = TConfig extends {
|
|
409
|
+
actions?: infer TActions;
|
|
410
|
+
} ? TActions extends Implementations['actions'] ? MergeImplementationMaps<SetupActions<SetupConfigSchemas<TConfig>, {}>, TActions> : SetupActions<SetupConfigSchemas<TConfig>, {}> : SetupActions<SetupConfigSchemas<TConfig>, {}>;
|
|
411
|
+
type SetupConfigActorSources<TConfig> = TConfig extends {
|
|
412
|
+
actorSources?: infer TActorSources;
|
|
413
|
+
} ? TActorSources extends Implementations['actorSources'] ? TActorSources : {} : {};
|
|
414
|
+
type SetupConfigGuards<TConfig> = TConfig extends {
|
|
415
|
+
guards?: infer TGuards;
|
|
416
|
+
} ? TGuards extends Implementations['guards'] ? MergeImplementationMaps<SetupGuards<SetupConfigSchemas<TConfig>, {}>, TGuards> : SetupGuards<SetupConfigSchemas<TConfig>, {}> : SetupGuards<SetupConfigSchemas<TConfig>, {}>;
|
|
417
|
+
type SetupConfigDelays<TConfig> = TConfig extends {
|
|
418
|
+
delays?: infer TDelays;
|
|
419
|
+
} ? TDelays extends Implementations['delays'] ? TDelays : {} : {};
|
|
420
|
+
export type SetupReturnFromConfig<TConfig extends AnySetupConfig> = SetupReturn<SetupConfigStates<TConfig>, SetupConfigSchemas<TConfig>, SetupConfigActions<TConfig>, SetupConfigActorSources<TConfig>, SetupConfigGuards<TConfig>, SetupConfigDelays<TConfig>>;
|
|
220
421
|
/**
|
|
221
422
|
* Sets up a state machine with state input schemas and other configuration.
|
|
222
423
|
*
|
|
@@ -253,8 +454,19 @@ interface SetupReturn<TStates extends Record<string, SetupStateSchema> = Record<
|
|
|
253
454
|
* });
|
|
254
455
|
* ```
|
|
255
456
|
*/
|
|
256
|
-
export declare function setup
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
457
|
+
export declare function setup(): SetupReturn;
|
|
458
|
+
export declare function setup<const TSchemas extends SetupSchemas = {}, const TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TActionMap extends Implementations['actions'] = {}, TActorMap extends Implementations['actorSources'] = {}, TGuardMap extends Implementations['guards'] = {}, TDelayMap extends Implementations['delays'] = {}>(config: SetupConfig<TSchemas, TStates, TActionMap, TActorMap, TGuardMap, TDelayMap>): SetupReturn<TStates, TSchemas, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
459
|
+
export declare function setup<const TConfig extends AnySetupConfig>(config: TConfig): SetupReturnFromConfig<TConfig>;
|
|
460
|
+
type SystemBuilder<TSystemRegistry extends SystemRegistry> = {
|
|
461
|
+
createActor<TLogic extends AnyActorLogic>(logic: TLogic, options?: Omit<ActorOptions<TLogic>, 'registryKey'> & {
|
|
462
|
+
registryKey?: RegistryKeyForLogic<TLogic, TSystemRegistry>;
|
|
463
|
+
} & {
|
|
464
|
+
[K in RequiredActorOptionsKeys<TLogic>]: unknown;
|
|
465
|
+
}): Actor<TLogic>;
|
|
466
|
+
get: SystemRuntime<TSystemRegistry>['get'];
|
|
467
|
+
getAll: SystemRuntime<TSystemRegistry>['getAll'];
|
|
468
|
+
inspect(observer: Observer<InspectionEvent> | ((inspectionEvent: InspectionEvent) => void)): Subscription;
|
|
469
|
+
setup<const TSchemas extends SetupSchemas = {}, const TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TActionMap extends Implementations['actions'] = {}, TActorMap extends Implementations['actorSources'] = {}, TGuardMap extends Implementations['guards'] = {}, TDelayMap extends Implementations['delays'] = {}>(config?: SetupConfig<TSchemas, TStates, TActionMap, TActorMap, TGuardMap, TDelayMap>): SetupReturn<TStates, TSchemas, TActionMap, TActorMap, TGuardMap, TDelayMap, Extract<keyof TDelayMap, string>, TSystemRegistry>;
|
|
470
|
+
};
|
|
471
|
+
export declare function createSystem<const TSystemRegistry extends SystemRegistry = {}>(_config?: SystemConfig<TSystemRegistry>): SystemBuilder<TSystemRegistry>;
|
|
260
472
|
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ActorFromLogic, AnyActorLogic, AnyActorRef, AnyActorScope, AnyEventObject, AnyMachineSnapshot, ConditionalRequired, InputFrom, IsNotNever, type RequiredLogicInput } from "./types.js";
|
|
2
|
-
export type Spawner = <TLogic extends AnyActorLogic>(src: TLogic, ...[options]: ConditionalRequired<[
|
|
1
|
+
import { ActorFromLogic, AnyActorLogic, AnyActorRef, AnyActorScope, AnyEventObject, AnyMachineSnapshot, ConditionalRequired, InputFrom, IsNotNever, RegistryKeyForLogic, SystemRegistry, type RequiredLogicInput } from "./types.js";
|
|
2
|
+
export type Spawner<TSystemRegistry extends SystemRegistry = SystemRegistry> = <TLogic extends AnyActorLogic>(src: TLogic, ...[options]: ConditionalRequired<[
|
|
3
3
|
options?: {
|
|
4
4
|
id?: string;
|
|
5
|
-
|
|
5
|
+
registryKey?: RegistryKeyForLogic<TLogic, TSystemRegistry>;
|
|
6
6
|
input?: TLogic extends string ? unknown : InputFrom<TLogic>;
|
|
7
7
|
syncSnapshot?: boolean;
|
|
8
8
|
} & {
|
|
@@ -39,7 +39,10 @@ export declare function initialMicrostep(root: AnyStateNode, preInitialState: An
|
|
|
39
39
|
export declare function getTransitionResult(transition: Pick<AnyTransitionDefinition, 'target' | 'to' | 'source'> & {
|
|
40
40
|
reenter?: AnyTransitionDefinition['reenter'];
|
|
41
41
|
input?: AnyTransitionDefinition['input'];
|
|
42
|
-
|
|
42
|
+
context?: AnyTransitionDefinition['context'];
|
|
43
|
+
}, snapshot: AnyMachineSnapshot, event: AnyEventObject, actorScope: AnyActorScope, options?: {
|
|
44
|
+
resolveActions?: boolean;
|
|
45
|
+
}): {
|
|
43
46
|
targets: Readonly<AnyStateNode[]> | undefined;
|
|
44
47
|
context: MachineContext | undefined;
|
|
45
48
|
actions: AnyAction[] | undefined;
|
|
@@ -30,7 +30,7 @@ export interface ActorSystem<T extends ActorSystemInfo> {
|
|
|
30
30
|
_logger: (...args: any[]) => void;
|
|
31
31
|
}
|
|
32
32
|
export type AnyActorSystem = ActorSystem<any>;
|
|
33
|
-
export declare function
|
|
33
|
+
export declare function createRuntimeSystem<T extends ActorSystemInfo>(rootActor: AnyActor, options: {
|
|
34
34
|
clock: Clock;
|
|
35
35
|
logger: (...args: any[]) => void;
|
|
36
36
|
snapshot?: unknown;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { AnyActorLogic, AnyStateMachine, EventFromLogic, InputFrom, SnapshotFrom,
|
|
1
|
+
import { AnyActorLogic, AnyStateMachine, EventFromLogic, InputFrom, SnapshotFrom, ExecutableActionObjectFromLogic, AnyTransitionDefinition, AnyMachineSnapshot } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Given actor `logic`, a `snapshot`, and an `event`, returns a tuple of the
|
|
4
4
|
* `nextSnapshot` and `actions` to execute.
|
|
5
5
|
*
|
|
6
6
|
* This is a pure function that does not execute `actions`.
|
|
7
7
|
*/
|
|
8
|
-
export declare function transition<T extends AnyActorLogic>(logic: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): [
|
|
8
|
+
export declare function transition<T extends AnyActorLogic>(logic: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): [
|
|
9
|
+
nextSnapshot: SnapshotFrom<T>,
|
|
10
|
+
actions: ExecutableActionObjectFromLogic<T>[]
|
|
11
|
+
];
|
|
9
12
|
/**
|
|
10
13
|
* Given actor `logic` and optional `input`, returns a tuple of the
|
|
11
14
|
* `nextSnapshot` and `actions` to execute from the initial transition (no
|
|
@@ -13,14 +16,14 @@ export declare function transition<T extends AnyActorLogic>(logic: T, snapshot:
|
|
|
13
16
|
*
|
|
14
17
|
* This is a pure function that does not execute `actions`.
|
|
15
18
|
*/
|
|
16
|
-
export declare function initialTransition<T extends AnyActorLogic>(logic: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): [SnapshotFrom<T>,
|
|
19
|
+
export declare function initialTransition<T extends AnyActorLogic>(logic: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): [SnapshotFrom<T>, ExecutableActionObjectFromLogic<T>[]];
|
|
17
20
|
/**
|
|
18
21
|
* Given a state `machine`, a `snapshot`, and an `event`, returns an array of
|
|
19
22
|
* microsteps, where each microstep is a tuple of `[snapshot, actions]`.
|
|
20
23
|
*
|
|
21
24
|
* This is a pure function that does not execute `actions`.
|
|
22
25
|
*/
|
|
23
|
-
export declare function getMicrosteps<T extends AnyStateMachine>(machine: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): Array<[SnapshotFrom<T>,
|
|
26
|
+
export declare function getMicrosteps<T extends AnyStateMachine>(machine: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): Array<[SnapshotFrom<T>, ExecutableActionObjectFromLogic<T>[]]>;
|
|
24
27
|
/**
|
|
25
28
|
* Given a state `machine` and optional `input`, returns an array of microsteps
|
|
26
29
|
* from the initial transition, where each microstep is a tuple of `[snapshot,
|
|
@@ -28,7 +31,7 @@ export declare function getMicrosteps<T extends AnyStateMachine>(machine: T, sna
|
|
|
28
31
|
*
|
|
29
32
|
* This is a pure function that does not execute `actions`.
|
|
30
33
|
*/
|
|
31
|
-
export declare function getInitialMicrosteps<T extends AnyStateMachine>(machine: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): Array<[SnapshotFrom<T>,
|
|
34
|
+
export declare function getInitialMicrosteps<T extends AnyStateMachine>(machine: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): Array<[SnapshotFrom<T>, ExecutableActionObjectFromLogic<T>[]]>;
|
|
32
35
|
/**
|
|
33
36
|
* Gets all potential next transitions from the current state.
|
|
34
37
|
*
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AnyAction, AnyActorScope, AnyEventObject, AnyMachineSnapshot, EnqueueObject, EventObject, ExecutableActionObject, MachineContext, SpecialExecutableAction, StartExecutableActionObject } from "./types.js";
|
|
2
|
+
export declare function mergeContextPatch(context: MachineContext, patch: MachineContext): MachineContext;
|
|
3
|
+
export declare function createTransitionEnqueue(actorScope: AnyActorScope, actions: any[], internalEvents: EventObject[], actorSubscriptions?: boolean, createActors?: boolean): EnqueueObject<any, any>;
|
|
4
|
+
/**
|
|
5
|
+
* Attached (listener/subscription) starts are ordered before child starts so
|
|
6
|
+
* that a listener/subscription captures events emitted synchronously as its
|
|
7
|
+
* target actor starts.
|
|
8
|
+
*/
|
|
9
|
+
export declare function deriveDeferredStarts(effects: ReadonlyArray<ExecutableActionObject>): StartExecutableActionObject[];
|
|
10
|
+
export declare function isBuiltInExecutableAction(action: ExecutableActionObject): action is SpecialExecutableAction;
|
|
11
|
+
export declare function resolveActionsWithContext(currentSnapshot: AnyMachineSnapshot, event: AnyEventObject, actorScope: AnyActorScope, actions: AnyAction[]): [AnyMachineSnapshot, ExecutableActionObject[]];
|
|
12
|
+
export declare function createEnqueueObject(props: Partial<EnqueueObject<any, any>>, action: <T extends (...args: any[]) => any>(fn: T, ...args: Parameters<T>) => void): EnqueueObject<any, any>;
|