xstate 6.0.0-alpha.8 → 6.0.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/declarations/src/StateMachine.d.ts +10 -3
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/setup.d.ts +28 -6
- package/dist/declarations/src/types.v6.d.ts +15 -6
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +2 -1
- package/dist/xstate.development.cjs.js +2 -1
- package/dist/xstate.development.esm.js +2 -1
- package/dist/xstate.esm.js +2 -1
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { MachineSnapshot } from "./State.js";
|
|
2
2
|
import { StateNode } from "./StateNode.js";
|
|
3
3
|
import { AnyActorSystem } from "./system.js";
|
|
4
|
-
import type { ActorLogic, ActorLogicTransitionResult, ActorScope, AnyActor, AnyActorRef, AnyActorScope, AnyTransitionDefinition, Equals, EventDescriptor, EventObject, ExecutableActionObjectFromLogic, HistoryValue, MachineContext, MetaObject, Snapshot, StateValue, StateSchema, SnapshotStatus } from "./types.js";
|
|
4
|
+
import type { ActorLogic, ActorLogicTransitionResult, ActorScope, AnyActor, AnyActorLogic, AnyActorRef, AnyActorScope, AnyTransitionDefinition, Equals, EventDescriptor, EmittedFrom, EventObject, EventFromLogic, ExecutableActionObjectFromLogic, HistoryValue, InputFrom, IsAny, MachineContext, MetaObject, OutputFrom, Snapshot, SnapshotFrom, StateValue, StateSchema, SnapshotStatus } from "./types.js";
|
|
5
5
|
import { AnyMachineSchemas, Implementations, Next_MachineConfig, MachineOptions } from "./types.v6.js";
|
|
6
|
+
type CompatibleProvidedActorSource<TExpected extends AnyActorLogic, TActual extends AnyActorLogic> = IsAny<TActual> extends true ? TActual : [OutputFrom<TActual>] extends [OutputFrom<TExpected>] ? [Omit<SnapshotFrom<TActual>, 'input'>] extends [
|
|
7
|
+
Omit<SnapshotFrom<TExpected>, 'input'>
|
|
8
|
+
] ? [InputFrom<TExpected>] extends [InputFrom<TActual>] ? [EventFromLogic<TExpected>] extends [EventFromLogic<TActual>] ? [EmittedFrom<TActual>] extends [EmittedFrom<TExpected>] ? TActual : never : never : never : never : never;
|
|
9
|
+
type ProvidedActorSources<TExpectedActorMap extends Implementations['actorSources'], TProvidedActorMap extends Partial<Record<keyof TExpectedActorMap & string, AnyActorLogic>>> = {
|
|
10
|
+
[K in keyof TProvidedActorMap]: K extends keyof TExpectedActorMap ? TProvidedActorMap[K] extends AnyActorLogic ? CompatibleProvidedActorSource<TExpectedActorMap[K], TProvidedActorMap[K]> : never : never;
|
|
11
|
+
};
|
|
6
12
|
export declare class StateMachine<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TInput, TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TConfig extends StateSchema, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> implements ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, TEvent, TInput, AnyActorSystem, TEmitted> {
|
|
7
13
|
/** The raw config used to create the machine. */
|
|
8
14
|
config: Next_MachineConfig<any, any, any, any, any, any, any, any, any, any, any> & {
|
|
@@ -33,9 +39,9 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
33
39
|
* `delays`) to recursively merge with the existing options.
|
|
34
40
|
* @returns A new `StateMachine` instance with the provided implementations.
|
|
35
41
|
*/
|
|
36
|
-
provide(implementations: {
|
|
42
|
+
provide<const TProvidedActorMap extends Partial<Record<keyof TActorMap & string, AnyActorLogic>> = {}>(implementations: {
|
|
37
43
|
actions?: Partial<TActionMap>;
|
|
38
|
-
actorSources?:
|
|
44
|
+
actorSources?: TProvidedActorMap & ProvidedActorSources<TActorMap, TProvidedActorMap>;
|
|
39
45
|
guards?: Partial<TGuardMap>;
|
|
40
46
|
delays?: Partial<TDelayMap>;
|
|
41
47
|
}): StateMachine<TContext, TEvent, TChildren, TStateValue, TTag, TInput, TOutput, TEmitted, TMeta, TConfig, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
@@ -78,3 +84,4 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
78
84
|
getPersistedSnapshot(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, options?: unknown): Snapshot<unknown>;
|
|
79
85
|
restoreSnapshot(snapshot: Snapshot<unknown>, _actorScope: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, TEvent, AnyActorSystem, TEmitted>): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>;
|
|
80
86
|
}
|
|
87
|
+
export {};
|
|
@@ -8,6 +8,7 @@ export { machineConfigToJSON, serializeMachine, type CodeExpression, type Unseri
|
|
|
8
8
|
export { mapState } from "./mapState.js";
|
|
9
9
|
export { types, isTypeSchema, type StandardSchemaV1, type TypeSchema } from "./schema.types.js";
|
|
10
10
|
export { createSystem, setup } from "./setup.js";
|
|
11
|
+
export type { AnySetupConfig, SetupConfig, SetupReturn, SetupReturnFromConfig, SetupSchemas, SetupStateSchema, SetupStateSchemas } from "./setup.js";
|
|
11
12
|
export { getInitialSnapshot, getNextSnapshot } from "./getNextSnapshot.js";
|
|
12
13
|
export type { InspectionEvent, ActorInspectionEvent, TransitionInspectionEvent, ActionRecord, SentRecord } from "./inspection.js";
|
|
13
14
|
export { SimulatedClock } from "./SimulatedClock.js";
|
|
@@ -5,7 +5,7 @@ import { AnyActorRef, AnyActorLogic, ActorRefFromLogic, AnyStateNode, EventObjec
|
|
|
5
5
|
import { AnyActorSystem } from "./system.js";
|
|
6
6
|
import { InspectionEvent } from "./inspection.js";
|
|
7
7
|
import { DelayMapFromNames, InferChildren, Implementations, InferOutput, InferEvents, Next_MachineConfig, Next_StateNodeConfig, WithDefault } from "./types.v6.js";
|
|
8
|
-
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']> = {
|
|
8
|
+
export type SetupConfig<TSchemas extends SetupSchemas, TStates extends Record<string, SetupStateSchema>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
9
9
|
schemas?: TSchemas;
|
|
10
10
|
states?: TStates;
|
|
11
11
|
actions?: TActionMap;
|
|
@@ -13,6 +13,7 @@ type SetupConfig<TSchemas extends SetupSchemas, TStates extends Record<string, S
|
|
|
13
13
|
guards?: TGuardMap;
|
|
14
14
|
delays?: TDelayMap;
|
|
15
15
|
};
|
|
16
|
+
export type AnySetupConfig = SetupConfig<SetupSchemas, Record<string, SetupStateSchema>, Implementations['actions'], Implementations['actorSources'], Implementations['guards'], Implementations['delays']>;
|
|
16
17
|
type SystemConfig<TSystemRegistry extends SystemRegistry> = {
|
|
17
18
|
registry?: TSystemRegistry;
|
|
18
19
|
};
|
|
@@ -49,11 +50,11 @@ type ValidateRegistryKeys<TConfig, TSystemRegistry extends SystemRegistry, TActo
|
|
|
49
50
|
[K in keyof TStates]: TStates[K] & ValidateRegistryKeys<TStates[K], TSystemRegistry, TActorMap>;
|
|
50
51
|
};
|
|
51
52
|
} : unknown);
|
|
52
|
-
type SetupStateSchemas = {
|
|
53
|
+
export type SetupStateSchemas = {
|
|
53
54
|
context?: StandardSchemaV1;
|
|
54
55
|
input?: StandardSchemaV1;
|
|
55
56
|
};
|
|
56
|
-
type SetupSchemas = {
|
|
57
|
+
export type SetupSchemas = {
|
|
57
58
|
context?: StandardSchemaV1;
|
|
58
59
|
events?: Record<string, StandardSchemaV1>;
|
|
59
60
|
emitted?: Record<string, StandardSchemaV1>;
|
|
@@ -64,7 +65,7 @@ type SetupSchemas = {
|
|
|
64
65
|
children?: Record<string, StandardSchemaV1>;
|
|
65
66
|
};
|
|
66
67
|
/** State schema with optional schemas.input and nested states */
|
|
67
|
-
interface SetupStateSchema {
|
|
68
|
+
export interface SetupStateSchema {
|
|
68
69
|
schemas?: SetupStateSchemas;
|
|
69
70
|
states?: Record<string, SetupStateSchema>;
|
|
70
71
|
}
|
|
@@ -300,7 +301,7 @@ type InitialTransitionWithInput<TStateSchemas extends Record<string, SetupStateS
|
|
|
300
301
|
};
|
|
301
302
|
}[keyof TStateSchemas & string];
|
|
302
303
|
/** Return type of setup() */
|
|
303
|
-
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> {
|
|
304
|
+
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> {
|
|
304
305
|
/** Extends the setup configuration */
|
|
305
306
|
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>;
|
|
306
307
|
/** Creates a state machine with the setup configuration */
|
|
@@ -330,6 +331,25 @@ interface SetupReturn<TStates extends Record<string, SetupStateSchema> = Record<
|
|
|
330
331
|
/** State input schemas from setup config */
|
|
331
332
|
states: TStates;
|
|
332
333
|
}
|
|
334
|
+
type SetupConfigSchemas<TConfig> = TConfig extends {
|
|
335
|
+
schemas?: infer TSchemas;
|
|
336
|
+
} ? TSchemas extends SetupSchemas ? TSchemas : {} : {};
|
|
337
|
+
type SetupConfigStates<TConfig> = TConfig extends {
|
|
338
|
+
states?: infer TStates;
|
|
339
|
+
} ? TStates extends Record<string, SetupStateSchema> ? TStates : Record<string, SetupStateSchema> : Record<string, SetupStateSchema>;
|
|
340
|
+
type SetupConfigActions<TConfig> = TConfig extends {
|
|
341
|
+
actions?: infer TActions;
|
|
342
|
+
} ? TActions extends Implementations['actions'] ? TActions : {} : {};
|
|
343
|
+
type SetupConfigActorSources<TConfig> = TConfig extends {
|
|
344
|
+
actorSources?: infer TActorSources;
|
|
345
|
+
} ? TActorSources extends Implementations['actorSources'] ? TActorSources : {} : {};
|
|
346
|
+
type SetupConfigGuards<TConfig> = TConfig extends {
|
|
347
|
+
guards?: infer TGuards;
|
|
348
|
+
} ? TGuards extends Implementations['guards'] ? TGuards : {} : {};
|
|
349
|
+
type SetupConfigDelays<TConfig> = TConfig extends {
|
|
350
|
+
delays?: infer TDelays;
|
|
351
|
+
} ? TDelays extends Implementations['delays'] ? TDelays : {} : {};
|
|
352
|
+
export type SetupReturnFromConfig<TConfig extends AnySetupConfig> = SetupReturn<SetupConfigStates<TConfig>, SetupConfigSchemas<TConfig>, SetupConfigActions<TConfig>, SetupConfigActorSources<TConfig>, SetupConfigGuards<TConfig>, SetupConfigDelays<TConfig>>;
|
|
333
353
|
/**
|
|
334
354
|
* Sets up a state machine with state input schemas and other configuration.
|
|
335
355
|
*
|
|
@@ -366,7 +386,9 @@ interface SetupReturn<TStates extends Record<string, SetupStateSchema> = Record<
|
|
|
366
386
|
* });
|
|
367
387
|
* ```
|
|
368
388
|
*/
|
|
369
|
-
export declare function setup
|
|
389
|
+
export declare function setup(): SetupReturn;
|
|
390
|
+
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>;
|
|
391
|
+
export declare function setup<const TConfig extends AnySetupConfig>(config: TConfig): SetupReturnFromConfig<TConfig>;
|
|
370
392
|
type SystemBuilder<TSystemRegistry extends SystemRegistry> = {
|
|
371
393
|
createActor<TLogic extends AnyActorLogic>(logic: TLogic, options?: Omit<ActorOptions<TLogic>, 'registryKey'> & {
|
|
372
394
|
registryKey?: RegistryKeyForLogic<TLogic, TSystemRegistry>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "./schema.types.js";
|
|
2
2
|
import { MachineSnapshot } from "./State.js";
|
|
3
|
-
import { Action, ActorLogic, ActorRef, ActorRefFromLogic, ActorSelf, AnyActorLogic, AnyActorRef, Compute, DoneActorEvent, DoNotInfer, EventDescriptor, EventObject, ExtractEvent, InitialContext, InputFrom, IsNever, MetaObject, NonReducibleUnknown, SingleOrArray, SnapshotEvent, StateValue, TODO, TransitionConfigFunction, Values, AnyStateNode, SystemRegistry } from "./types.js";
|
|
3
|
+
import { Action, ActorLogic, ActorRef, ActorRefFromLogic, ActorSelf, AnyActorLogic, AnyActorRef, Compute, DoneActorEvent, DoNotInfer, EventDescriptor, EventObject, ExtractEvent, InitialContext, InputFrom, IsNever, MetaObject, NonReducibleUnknown, OutputFrom, SingleOrArray, SnapshotEvent, StateValue, TODO, TransitionConfigFunction, Values, AnyStateNode, SystemRegistry } from "./types.js";
|
|
4
4
|
import { MachineContext, Mapper } from "./types.js";
|
|
5
5
|
import { LowInfer } from "./types.js";
|
|
6
6
|
import { DoneStateEvent } from "./types.js";
|
|
@@ -13,6 +13,10 @@ export type InferOutput<T extends StandardSchemaV1, U> = Compute<StandardSchemaV
|
|
|
13
13
|
export type InferEvents<TEventSchemaMap extends Record<string, StandardSchemaV1>> = Values<{
|
|
14
14
|
[K in keyof TEventSchemaMap & string]: StandardSchemaV1.InferOutput<TEventSchemaMap[K]> extends infer O ? unknown extends O ? O & {
|
|
15
15
|
type: K;
|
|
16
|
+
} : string extends keyof O ? [O[string]] extends [never] ? {
|
|
17
|
+
type: K;
|
|
18
|
+
} : Required<O> & {
|
|
19
|
+
type: K;
|
|
16
20
|
} : Required<O> & {
|
|
17
21
|
type: K;
|
|
18
22
|
} : never;
|
|
@@ -142,16 +146,21 @@ export type Next_InvokeConfig<TContext extends MachineContext, TEvent extends Ev
|
|
|
142
146
|
src: string | AnyActorLogic | ((args: InvokeSrcArgs<TContext, TEvent, TActorMap>) => string | AnyActorLogic);
|
|
143
147
|
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted, TChildren>) => unknown) | NonReducibleUnknown;
|
|
144
148
|
} : {
|
|
145
|
-
[K in keyof TActorMap & string]: Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry
|
|
146
|
-
src: K | TActorMap[K] | ((args: InvokeSrcArgs<TContext, TEvent, TActorMap>) => K | TActorMap[K]);
|
|
149
|
+
[K in keyof TActorMap & string]: Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry, DoneActorEvent<OutputFrom<TActorMap[K]>>> & {
|
|
147
150
|
id?: ChildIdForLogic<TActorMap[K], TChildren>;
|
|
148
151
|
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted, TChildren>) => InputFrom<TActorMap[K]>) | InputFrom<TActorMap[K]>;
|
|
149
|
-
}
|
|
152
|
+
} & ({
|
|
153
|
+
src: K;
|
|
154
|
+
} | {
|
|
155
|
+
src: TActorMap[K];
|
|
156
|
+
} | {
|
|
157
|
+
src: (args: InvokeSrcArgs<TContext, TEvent, TActorMap>) => K | TActorMap[K];
|
|
158
|
+
});
|
|
150
159
|
}[keyof TActorMap & string] | InlineInvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry>;
|
|
151
|
-
interface Next_InvokeConfigBase<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, _TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, TSystemRegistry extends SystemRegistry> {
|
|
160
|
+
interface Next_InvokeConfigBase<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, _TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, TSystemRegistry extends SystemRegistry, TDoneEvent extends EventObject = [keyof TActorMap & string] extends [never] ? DoneActorEvent<any> : DoneActorEvent<OutputFrom<TActorMap[keyof TActorMap & string]>>> {
|
|
152
161
|
id?: string;
|
|
153
162
|
registryKey?: keyof TSystemRegistry & string;
|
|
154
|
-
onDone?: Next_TransitionConfigOrTarget<TContext,
|
|
163
|
+
onDone?: Next_TransitionConfigOrTarget<TContext, TDoneEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
155
164
|
onError?: Next_TransitionConfigOrTarget<TContext, ErrorEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
156
165
|
onSnapshot?: Next_TransitionConfigOrTarget<TContext, SnapshotEvent<any>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
157
166
|
/**
|