xstate 6.0.0-alpha.45 → 6.0.0-alpha.47

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.
Files changed (49) hide show
  1. package/dist/{StateMachine-2eecedfe.cjs.js → StateMachine-7046f677.cjs.js} +8 -4
  2. package/dist/{StateMachine-5b915fb1.development.cjs.js → StateMachine-70c06bdd.development.cjs.js} +8 -4
  3. package/dist/{StateMachine-d2fcf2e8.esm.js → StateMachine-74929087.esm.js} +8 -4
  4. package/dist/{StateMachine-4bf86161.development.esm.js → StateMachine-ee10f67e.development.esm.js} +8 -4
  5. package/dist/{createActor-5c9fa117.development.cjs.js → createActor-6736cbbe.development.cjs.js} +57 -22
  6. package/dist/{createActor-641ab5f7.esm.js → createActor-915ea40c.esm.js} +60 -23
  7. package/dist/{createActor-48401456.cjs.js → createActor-bfe8b6bd.cjs.js} +60 -22
  8. package/dist/{createActor-60ee6b5b.development.esm.js → createActor-ff132afa.development.esm.js} +57 -23
  9. package/dist/declarations/src/StateMachine.d.ts +7 -3
  10. package/dist/declarations/src/durable/index.d.ts +9 -2
  11. package/dist/declarations/src/setup.d.ts +37 -8
  12. package/dist/declarations/src/types.d.ts +27 -17
  13. package/dist/declarations/src/types.v6.d.ts +27 -5
  14. package/dist/{effectDescriptor-adb27412.cjs.js → effectDescriptor-3c699328.development.cjs.js} +4 -1
  15. package/dist/{effectDescriptor-dffb91a8.esm.js → effectDescriptor-8be60443.esm.js} +4 -1
  16. package/dist/{effectDescriptor-0cba79a1.development.cjs.js → effectDescriptor-a7e2d4d1.cjs.js} +4 -1
  17. package/dist/{effectDescriptor-fed26db6.development.esm.js → effectDescriptor-fbe67d5a.development.esm.js} +4 -1
  18. package/dist/{index-662114ff.development.cjs.js → index-0f498ef2.development.cjs.js} +1 -1
  19. package/dist/{index-158e7c37.development.esm.js → index-70d56425.development.esm.js} +1 -1
  20. package/dist/{index-8f19f242.esm.js → index-b051c924.esm.js} +1 -1
  21. package/dist/{index-fce4ea5c.cjs.js → index-b3fe59bc.cjs.js} +1 -1
  22. package/dist/xstate-actors.cjs.js +2 -2
  23. package/dist/xstate-actors.development.cjs.js +2 -2
  24. package/dist/xstate-actors.development.esm.js +2 -2
  25. package/dist/xstate-actors.esm.js +2 -2
  26. package/dist/xstate-actors.umd.min.js.map +1 -1
  27. package/dist/xstate-durable.cjs.js +9 -6
  28. package/dist/xstate-durable.development.cjs.js +9 -6
  29. package/dist/xstate-durable.development.esm.js +9 -6
  30. package/dist/xstate-durable.esm.js +9 -6
  31. package/dist/xstate-durable.umd.min.js +1 -1
  32. package/dist/xstate-durable.umd.min.js.map +1 -1
  33. package/dist/xstate-graph.cjs.js +3 -3
  34. package/dist/xstate-graph.development.cjs.js +3 -3
  35. package/dist/xstate-graph.development.esm.js +3 -3
  36. package/dist/xstate-graph.esm.js +3 -3
  37. package/dist/xstate-graph.umd.min.js +1 -1
  38. package/dist/xstate-graph.umd.min.js.map +1 -1
  39. package/dist/xstate-validation.cjs.js +1 -1
  40. package/dist/xstate-validation.development.cjs.js +1 -1
  41. package/dist/xstate-validation.development.esm.js +1 -1
  42. package/dist/xstate-validation.esm.js +1 -1
  43. package/dist/xstate.cjs.js +23 -4
  44. package/dist/xstate.development.cjs.js +23 -4
  45. package/dist/xstate.development.esm.js +25 -6
  46. package/dist/xstate.esm.js +25 -6
  47. package/dist/xstate.umd.min.js +1 -1
  48. package/dist/xstate.umd.min.js.map +1 -1
  49. package/package.json +1 -1
@@ -3,7 +3,7 @@ import { StateNode } from "./StateNode.js";
3
3
  import { type TransitionSelectionResults } from "./stateUtils.js";
4
4
  import { AnyActorSystem } from "./system.js";
5
5
  import type { ActorLogic, ActorLogicTransitionResult, ActorScope, AnyActorLogic, AnyActorRef, AnyActorScope, AnyTransitionDefinition, Equals, EventDescriptor, EmittedFrom, EventObject, EventFromLogic, ExecutableActionObjectFromLogic, HistoryValue, InputFrom, IsAny, MachineContext, MetaObject, OutputFrom, Snapshot, SnapshotFrom, StateValue, StateSchema, SnapshotStatus } from "./types.js";
6
- import { AnyMachineSchemas, Sources, Next_MachineConfig, MachineOptions } from "./types.v6.js";
6
+ import { AnyMachineSchemas, DelaySourceMap, GuardSourceMap, Sources, Next_MachineConfig, MachineOptions } from "./types.v6.js";
7
7
  import type { ActorLogicValidator } from "./validation.types.js";
8
8
  import type { StandardSchemaV1 } from "./schema.types.js";
9
9
  import type { PersistedMachineSnapshot } from "./machineVersion.types.js";
@@ -53,8 +53,12 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
53
53
  provide<const TProvidedActorMap extends Partial<Record<keyof TActorMap & string, AnyActorLogic>> = {}>(sources: {
54
54
  actions?: Partial<TActionMap>;
55
55
  actors?: TProvidedActorMap & ProvidedActors<TActorMap, TProvidedActorMap>;
56
- guards?: Partial<TGuardMap>;
57
- delays?: Partial<TDelayMap>;
56
+ guards?: Partial<TGuardMap> & {
57
+ [K in keyof TGuardMap]?: GuardSourceMap<TContext, TEvent>[string];
58
+ };
59
+ delays?: {
60
+ [K in keyof TDelayMap]?: DelaySourceMap<TContext, TEvent>[string];
61
+ };
58
62
  }): this;
59
63
  resolveState(config: {
60
64
  value: StateValue;
@@ -46,10 +46,17 @@ export interface DurableEffect<TEffect> extends DurableEffectMetadata {
46
46
  * during `executeEffects`: the execution captures and retains them, and the
47
47
  * execution's `waitForEvent()` hands them out before deferring to this
48
48
  * adapter. While the loop is parked, a root-addressed event reaches
49
- * `sendEvent` like any other target, so the host enqueues it in its own
50
- * mailbox.
49
+ * `enqueueRootEvent`, or the broader `sendEvent` override when implemented,
50
+ * so the host can place it in its own mailbox.
51
51
  */
52
52
  export interface DurableExecutionAdapter<TLogic extends AnyActorLogic> extends Partial<ActorSystemRuntime> {
53
+ /**
54
+ * Enqueues an event addressed to this execution's root while the durable
55
+ * loop is parked in `waitForEvent()`. Use this when the host only owns the
56
+ * root mailbox; implementing `sendEvent` instead takes ownership of delivery
57
+ * for every target and must use `deliverEvent` for co-located actors.
58
+ */
59
+ enqueueRootEvent?(source: AnyActor | undefined, event: AnyEventObject): void | PromiseLike<void>;
53
60
  /**
54
61
  * Executes a custom action as a durable host step or activity. The host
55
62
  * should identify the action by `type` and memoize or deduplicate it using
@@ -5,15 +5,41 @@ import { type Actor, type RequiredActorOptionsKeys } from "./createActor.js";
5
5
  import { AnyActorRef, AnyActorLogic, ActorRefFromLogic, AnyStateNode, EventObject, AnyEventObject, EventDescriptor, ExtractEvent, MachineContext, ProvidedActor, RoutableStateId, StateSchema, StateValue, StateValueFromStateSchema, ToChildren, MetaObject, Cast, Compute, EnqueueObject, DoneActorEvent, DoneStateEvent, ErrorActorEvent, SystemRegistry, RegistryKeyForLogic, ActorOptions, Observer, Subscription, OutputArg, SnapshotEvent, SingleOrArray, AfterEvent, TimeoutEvent, ErrorEvent } from "./types.js";
6
6
  import { AnyActorSystem } from "./system.js";
7
7
  import { InspectionEvent } from "./inspection.js";
8
- import { ActionSchemas, DelayMapFromNames, GuardSchemas, InferChildren, InferActions, InferGuards, Sources, InferOutput, InferEvents, InferInternalEvents, Next_MachineConfig, Next_InvokeConfig, Next_StateNodeConfig, Next_TransitionConfigOrTarget, OutputFromConfig, ValidateHistoryDefaults, ValidateStateTargets, WithDefault } from "./types.v6.js";
8
+ import { ActionSchemas, DelayMapFromNames, DelaySourceMap, GuardSourceMap, GuardSchemas, InferChildren, InferActions, InferGuards, Sources, InferOutput, InferEvents, InferInternalEvents, Next_MachineConfig, Next_InvokeConfig, Next_StateNodeConfig, Next_TransitionConfigOrTarget, OutputFromConfig, ValidateHistoryDefaults, ValidateStateTargets, WithDefault } from "./types.v6.js";
9
9
  export type SetupConfig<TSchemas extends SetupSchemas, TStates extends Record<string, SetupStateSchema>, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TValidator extends ActorLogicValidator | undefined = ActorLogicValidator | undefined> = {
10
10
  validator?: TValidator;
11
- schemas?: TSchemas & SetupSchemas;
11
+ schemas?: TSchemas;
12
12
  states?: TStates;
13
13
  actions?: TActionMap;
14
14
  actors?: TActorMap;
15
- guards?: TGuardMap;
16
- delays?: TDelayMap;
15
+ guards?: TGuardMap & SetupGuardSources<NoInfer<TSchemas>>;
16
+ delays?: TDelayMap & SetupDelaySources<NoInfer<TSchemas>>;
17
+ };
18
+ /**
19
+ * Contextual types for guard/delay source maps passed to `setup()`, derived
20
+ * from the same call's `schemas` (context/events). These intersect the
21
+ * inferred source-map type parameters so inline functions get typed args
22
+ * without hand-annotating.
23
+ */
24
+ type SetupGuardSources<TSchemas> = GuardSourceMap<SetupContext<TSchemas, StandardSchemaV1>, SetupEvents<TSchemas, Record<string, StandardSchemaV1>>>;
25
+ type SetupDelaySources<TSchemas> = DelaySourceMap<SetupContext<TSchemas, StandardSchemaV1>, SetupEvents<TSchemas, Record<string, StandardSchemaV1>>>;
26
+ /**
27
+ * Contextual companion for the whole-config `setup()` overload: gives inline
28
+ * `guards`/`delays` functions typed args from the config's own `schemas`.
29
+ */
30
+ type SetupSourceCompanions<TSchemas> = {
31
+ guards?: SetupGuardSources<TSchemas>;
32
+ delays?: SetupDelaySources<TSchemas>;
33
+ };
34
+ type MergeRecord<TBase, TExtend> = Omit<TBase, keyof TExtend> & TExtend;
35
+ /**
36
+ * Mirrors the runtime `mergeSchemas`: scalar schema keys (`context`, `input`,
37
+ * ...) are overridden whole, while map-valued keys (`events`, `emitted`,
38
+ * `children`, `actions`, `guards`) are merged entry-by-entry with extension
39
+ * entries winning, so base-declared entries stay visible to extension sources.
40
+ */
41
+ type MergedSetupSchemas<TBaseSchemas, TExtendSchemas> = {
42
+ [K in keyof TBaseSchemas | keyof TExtendSchemas]: K extends 'events' | 'emitted' | 'children' | 'actions' | 'guards' ? MergeRecord<K extends keyof TBaseSchemas ? NonNullable<TBaseSchemas[K]> : {}, K extends keyof TExtendSchemas ? NonNullable<TExtendSchemas[K]> : {}> : K extends keyof TExtendSchemas ? TExtendSchemas[K] : K extends keyof TBaseSchemas ? TBaseSchemas[K] : never;
17
43
  };
18
44
  export type AnySetupConfig = SetupConfig<SetupSchemas, Record<string, SetupStateSchema>, Sources['actions'], Sources['actors'], Sources['guards'], Sources['delays'], ActorLogicValidator | undefined>;
19
45
  interface RuntimeValidationDoesNotSupportTransformingSchemas {
@@ -62,7 +88,10 @@ type ExtendValidatorConfig<TExtension> = [TExtension] extends [
62
88
  } : {
63
89
  validator: TExtension;
64
90
  };
65
- type SetupExtensionConfig<TBaseSchemas, TBaseStates, TBaseValidator, TExtendSchemas extends SetupSchemas, TExtendStates extends Record<string, SetupStateSchema>, TExtendActionMap extends Sources['actions'], TExtendActorMap extends Sources['actors'], TExtendGuardMap extends Sources['guards'], TExtendDelayMap extends Sources['delays'], TExtendValidator extends ActorLogicValidator | undefined | InheritedValidator> = Omit<SetupConfig<TExtendSchemas, TExtendStates, TExtendActionMap, TExtendActorMap, TExtendGuardMap, TExtendDelayMap>, 'validator'> & ExtendValidatorConfig<TExtendValidator> & RuntimeValidationCompatibility<NoInfer<TBaseSchemas>, NoInfer<TBaseStates>, ResolveExtendedValidator<TBaseValidator, TExtendValidator>> & RuntimeValidationConstraint<NoInfer<TExtendSchemas>, NoInfer<TExtendStates>, ResolveExtendedValidator<TBaseValidator, TExtendValidator>>;
91
+ type SetupExtensionConfig<TBaseSchemas, TBaseStates, TBaseValidator, TExtendSchemas extends SetupSchemas, TExtendStates extends Record<string, SetupStateSchema>, TExtendActionMap extends Sources['actions'], TExtendActorMap extends Sources['actors'], TExtendGuardMap extends Sources['guards'], TExtendDelayMap extends Sources['delays'], TExtendValidator extends ActorLogicValidator | undefined | InheritedValidator> = Omit<SetupConfig<TExtendSchemas, TExtendStates, TExtendActionMap, TExtendActorMap, TExtendGuardMap, TExtendDelayMap>, 'validator' | 'guards' | 'delays'> & {
92
+ guards?: TExtendGuardMap & SetupGuardSources<NoInfer<MergedSetupSchemas<TBaseSchemas, TExtendSchemas>>>;
93
+ delays?: TExtendDelayMap & SetupDelaySources<NoInfer<MergedSetupSchemas<TBaseSchemas, TExtendSchemas>>>;
94
+ } & ExtendValidatorConfig<TExtendValidator> & RuntimeValidationCompatibility<NoInfer<TBaseSchemas>, NoInfer<TBaseStates>, ResolveExtendedValidator<TBaseValidator, TExtendValidator>> & RuntimeValidationConstraint<NoInfer<TExtendSchemas>, NoInfer<TExtendStates>, ResolveExtendedValidator<TBaseValidator, TExtendValidator>>;
66
95
  type InlineMachineSchemas<TContextSchema, TEventSchemaMap, TInternalEventSchemaMap, TEmittedSchemaMap, TActionSchemaMap, TGuardSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap> = {
67
96
  context?: TContextSchema;
68
97
  events?: TEventSchemaMap;
@@ -330,7 +359,7 @@ type MergeStateSchema<TConfig extends StateSchema, TSetup extends StateSchema> =
330
359
  type SetupMachineConfig<TStateSchemas extends Record<string, SetupStateSchema>, TStateKeys extends string, TSchemas extends SetupSchemas, TContextSchema extends StandardSchemaV1, TEventSchemaMap extends Record<string, StandardSchemaV1>, TInternalEventSchemaMap 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 Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry, TContextRequired extends boolean, TRootDelays extends string = TDelays, TRootActionMap extends Sources['actions'] = TActionMap, TRootActorMap extends Sources['actors'] = TActorMap, TRootGuardMap extends Sources['guards'] = TGuardMap> = Omit<Next_MachineConfig<SetupOrConfigSchema<TSchemas, 'context', TContextSchema>, SetupOrConfigSchemaMap<TSchemas, 'events', TEventSchemaMap>, SetupOrConfigSchemaMap<TSchemas, 'internalEvents', TInternalEventSchemaMap>, 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' | 'actors' | 'guards' | 'delays'> & {
331
360
  actions?: TRootActionMap;
332
361
  actors?: TRootActorMap;
333
- guards?: TRootGuardMap;
362
+ guards?: TRootGuardMap & GuardSourceMap<TContext, TEvent>;
334
363
  delays?: {
335
364
  [K in TRootDelays | number]?: number | (({ context, event, stateNode }: {
336
365
  context: TContext;
@@ -424,7 +453,7 @@ type StateTransitionFunction<TStateSchemas extends Record<string, SetupStateSche
424
453
  guards: TGuardMap;
425
454
  delays: TDelayMap;
426
455
  input: TInput;
427
- } & OutputArg<TExpressionEvent>, enq: EnqueueObject<TEvent, TEmitted, TSystemRegistry>) => StateTransitionResult<TStateSchemas, TContext, TContextShape, TMeta, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, false> | void;
456
+ } & OutputArg<TExpressionEvent>, enq: EnqueueObject<TEvent, TEmitted, TSystemRegistry, TActorMap>) => StateTransitionResult<TStateSchemas, TContext, TContextShape, TMeta, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, false> | void;
428
457
  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 Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry, TAllowContextMapper extends boolean> = {
429
458
  target?: never;
430
459
  context?: StateTransitionContext<TAllowContextMapper, TContext, TContextShape, TContextShape, TContext, TExpressionEvent, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
@@ -537,7 +566,7 @@ export type SetupReturnFromConfig<TConfig extends AnySetupConfig, TSystemRegistr
537
566
  type SetupFunction<TSystemRegistry extends SystemRegistry = SystemRegistry> = {
538
567
  (): SetupReturn<Record<string, SetupStateSchema>, {}, {}, {}, {}, {}, never, TSystemRegistry>;
539
568
  <const TSchemas extends SetupSchemas = {}, const TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TActionMap extends Sources['actions'] = {}, TActorMap extends Sources['actors'] = {}, TGuardMap extends Sources['guards'] = {}, TDelayMap extends Sources['delays'] = {}, const TValidator extends ActorLogicValidator | undefined = undefined>(config: SetupConfig<TSchemas, TStates, TActionMap, TActorMap, TGuardMap, TDelayMap, TValidator> & RuntimeValidationConstraint<NoInfer<TSchemas>, NoInfer<TStates>, TValidator>): SetupReturn<TStates, TSchemas, TActionMap, TActorMap, TGuardMap, TDelayMap, Extract<keyof TDelayMap, string>, TSystemRegistry, TValidator>;
540
- <const TConfig extends AnySetupConfig>(config: TConfig & RuntimeValidationConstraint<NoInfer<SetupConfigSchemas<TConfig>>, NoInfer<SetupConfigStates<TConfig>>, TConfig extends {
569
+ <const TConfig extends AnySetupConfig>(config: TConfig & SetupSourceCompanions<SetupConfigSchemas<TConfig>> & RuntimeValidationConstraint<NoInfer<SetupConfigSchemas<TConfig>>, NoInfer<SetupConfigStates<TConfig>>, TConfig extends {
541
570
  validator: infer TValidator;
542
571
  } ? TValidator : undefined>): SetupReturnFromConfig<TConfig, TSystemRegistry>;
543
572
  };
@@ -101,7 +101,7 @@ export type OutputArg<TEvent extends EventObject> = TEvent extends {
101
101
  export type ActionArgs<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> = UnifiedArg<TContext, TExpressionEvent, TEvent> & {
102
102
  children: Record<string, AnyActor>;
103
103
  };
104
- export type InputFrom<T> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TStateSchema, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap> ? TInput : T extends ActorLogic<infer _TSnapshot, infer _TEvent, infer TInput, infer _TSystem, infer _TEmitted> ? TInput : never;
104
+ export type InputFrom<T> = T extends ActorLogic<infer _TSnapshot, infer _TEvent, infer TInput, infer _TSystem, infer _TEmitted> ? TInput : T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TStateSchema, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap> ? TInput : never;
105
105
  export type OutputFrom<T> = T extends ActorLogic<infer TSnapshot, infer _TEvent, infer _TInput, infer _TSystem, infer _TEmitted> ? (TSnapshot & {
106
106
  status: 'done';
107
107
  })['output'] : T extends ActorRef<infer TSnapshot, infer _TEvent, infer _TEmitted> ? (TSnapshot & {
@@ -209,7 +209,7 @@ export type TransitionConfigTarget = string | undefined;
209
209
  export type TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays']> = SingleOrArray<TransitionConfigTarget | TransitionConfig<TContext, TExpressionEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap> | TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>>;
210
210
  export type TransitionConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TMeta extends MetaObject, TInput = undefined, _TCtx extends MachineContext = [TContext] extends [never] ? any : TContext> = (args: TransitionFunctionArgs<_TCtx, TCurrentEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap> & {
211
211
  input: TInput;
212
- }, enq: EnqueueObject<TEvent, TEmitted>) => {
212
+ }, enq: EnqueueObject<TEvent, TEmitted, SystemRegistry, TActorMap>) => {
213
213
  target?: string | string[];
214
214
  context?: TransitionContextPatch<_TCtx>;
215
215
  reenter?: boolean;
@@ -1210,24 +1210,34 @@ export interface SubscribeToMappers<TSnapshot extends Snapshot<unknown>, TOutput
1210
1210
  done?: (output: TOutput) => TMappedEvent;
1211
1211
  error?: (error: unknown) => TMappedEvent;
1212
1212
  }
1213
- export type EnqueueObject<TEvent extends EventObject, TEmittedEvent extends EventObject, TSystemRegistry extends SystemRegistry = SystemRegistry> = {
1213
+ type EnqueueSpawnOptions<TLogic extends AnyActorLogic, TSystemRegistry extends SystemRegistry> = {
1214
+ input?: InputFrom<TLogic>;
1215
+ id?: string;
1216
+ syncSnapshot?: boolean;
1217
+ registryKey?: RegistryKeyForLogic<TLogic, TSystemRegistry>;
1218
+ };
1219
+ type EnqueueSpawnArgs<TLogic extends AnyActorLogic, TSystemRegistry extends SystemRegistry> = ConditionalRequired<[
1220
+ options?: EnqueueSpawnOptions<TLogic, TSystemRegistry> & {
1221
+ [K in RequiredLogicInput<TLogic>]: unknown;
1222
+ }
1223
+ ], IsNotNever<RequiredLogicInput<TLogic>>>;
1224
+ type EnqueueSpawner<TActorMap extends Sources['actors'], TSystemRegistry extends SystemRegistry> = {
1225
+ <TSource extends keyof TActorMap & string>(src: TSource, ...[options]: EnqueueSpawnArgs<TActorMap[TSource], TSystemRegistry>): ActorFromLogic<TActorMap[TSource]>;
1226
+ <TLogic extends AnyActorLogic>(logic: TLogic, ...[options]: EnqueueSpawnArgs<TLogic, TSystemRegistry>): ActorFromLogic<TLogic>;
1227
+ };
1228
+ export type EnqueueObject<TEvent extends EventObject, TEmittedEvent extends EventObject, TSystemRegistry extends SystemRegistry = SystemRegistry, TActorMap extends Sources['actors'] = Sources['actors']> = {
1214
1229
  cancel: (id: string) => void;
1215
1230
  raise: (ev: TEvent, options?: {
1216
1231
  id?: string;
1217
1232
  delay?: number;
1218
1233
  }) => void;
1219
1234
  /**
1220
- * Spawns a child actor from the given logic. Without an explicit `id`, the
1221
- * child gets a deterministic src-keyed id (`worker:0`, `worker:1`, …)
1222
- * allocated from the parent snapshot's own counters, so ids replay
1223
- * identically and persist with the parent.
1235
+ * Spawns a child actor from a registered source key or logic. Without an
1236
+ * explicit `id`, the child gets a deterministic src-keyed id (`worker:0`,
1237
+ * `worker:1`, …) allocated from the parent snapshot's own counters, so ids
1238
+ * replay identically and persist with the parent.
1224
1239
  */
1225
- spawn: <T extends AnyActorLogic>(logic: T, options?: {
1226
- input?: InputFrom<T>;
1227
- id?: string;
1228
- syncSnapshot?: boolean;
1229
- registryKey?: RegistryKeyForLogic<T, TSystemRegistry>;
1230
- }) => ActorFromLogic<T>;
1240
+ spawn: EnqueueSpawner<TActorMap, TSystemRegistry>;
1231
1241
  emit: (emittedEvent: TEmittedEvent) => void;
1232
1242
  <T extends (...args: any[]) => any>(fn: T, ...args: Parameters<T>): void;
1233
1243
  log: (...args: any[]) => void;
@@ -1237,7 +1247,7 @@ export type EnqueueObject<TEvent extends EventObject, TEmittedEvent extends Even
1237
1247
  id?: string;
1238
1248
  delay?: number;
1239
1249
  }) => void;
1240
- stop: (actor?: AnyActor) => void;
1250
+ stop: (actor?: AnyActorRef) => void;
1241
1251
  /**
1242
1252
  * Listen to emitted events from an actor. Returns a listener actor that can
1243
1253
  * be stopped via `enq.stop()`.
@@ -1247,7 +1257,7 @@ export type EnqueueObject<TEvent extends EventObject, TEmittedEvent extends Even
1247
1257
  * wildcards: 'event._', '_')
1248
1258
  * @param mapper - Function to transform emitted events into machine events
1249
1259
  */
1250
- listen: <TEmitted extends EventObject, TMappedEvent extends TEvent>(actor: AnyActor, eventType: string, mapper: (event: TEmitted) => TMappedEvent) => AnyActor;
1260
+ listen: <TEmitted extends EventObject, TMappedEvent extends TEvent>(actor: AnyActorRef, eventType: string, mapper: (event: TEmitted) => TMappedEvent) => AnyActor;
1251
1261
  /**
1252
1262
  * Subscribe to lifecycle events (done/error/snapshot) from an actor. Returns
1253
1263
  * a subscription actor that can be stopped via `enq.stop()`.
@@ -1256,7 +1266,7 @@ export type EnqueueObject<TEvent extends EventObject, TEmittedEvent extends Even
1256
1266
  * @param mappers - Object with done/error/snapshot mappers, or a single
1257
1267
  * snapshot mapper function
1258
1268
  */
1259
- subscribeTo: <TActor extends AnyActor, TMappedEvent extends TEvent>(actor: TActor, mappers: SubscribeToMappers<SnapshotFrom<TActor>, OutputFrom<TActor>, TMappedEvent> | ((snapshot: SnapshotFrom<TActor>) => TMappedEvent)) => AnyActor;
1269
+ subscribeTo: <TActor extends AnyActorRef, TMappedEvent extends TEvent>(actor: TActor, mappers: SubscribeToMappers<SnapshotFrom<TActor>, OutputFrom<TActor>, TMappedEvent> | ((snapshot: SnapshotFrom<TActor>) => TMappedEvent)) => AnyActor;
1260
1270
  };
1261
1271
  export type Action<TContext extends MachineContext, TEvent extends EventObject, TEmittedEvent extends EventObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TParams = Record<string, unknown> | undefined, _TCtx = [TContext] extends [never] ? any : TContext> = (_: {
1262
1272
  context: _TCtx;
@@ -1270,7 +1280,7 @@ export type Action<TContext extends MachineContext, TEvent extends EventObject,
1270
1280
  delays: TDelayMap;
1271
1281
  system?: AnyActorSystem;
1272
1282
  params: TParams;
1273
- }, enqueue: EnqueueObject<TEvent, TEmittedEvent>) => {
1283
+ }, enqueue: EnqueueObject<TEvent, TEmittedEvent, SystemRegistry, TActorMap>) => {
1274
1284
  context?: Partial<_TCtx>;
1275
1285
  children?: Record<string, AnyActor | undefined>;
1276
1286
  } | void;
@@ -132,7 +132,7 @@ export type Next_MachineConfig<TContextSchema extends StandardSchemaV1, TEventSc
132
132
  internalEvents?: readonly InternalEventDescriptorFor<TEvent>[];
133
133
  schemas?: MachineSchemas<TContextSchema, TEventSchemaMap, TInternalEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap>;
134
134
  actions?: TActionMap;
135
- guards?: TGuardMap;
135
+ guards?: TGuardMap & GuardSourceMap<TContext, TEvent>;
136
136
  actors?: TActorMap;
137
137
  /** The machine's own version. */
138
138
  version?: string;
@@ -504,12 +504,34 @@ export interface Sources {
504
504
  context?: any;
505
505
  children?: any;
506
506
  }>;
507
- guards: Record<string, (...args: any[]) => boolean>;
508
- delays: Record<string, number | ((...args: any[]) => number)>;
507
+ guards: Record<string, Function>;
508
+ delays: Record<string, number | Function>;
509
509
  actors: Record<string, AnyActorLogic>;
510
510
  }
511
- export type DelayMapFromNames<TDelays extends string, _TDelayMap extends Sources['delays']> = string extends TDelays ? Sources['delays'] : {
512
- [K in TDelays]: Sources['delays'][string];
511
+ /**
512
+ * Contextually types the entries of a `guards: { ... }` source map. Guard
513
+ * sources receive the transition args object first and optional caller-supplied
514
+ * params after it.
515
+ */
516
+ export type GuardSourceMap<TContext extends MachineContext, TEvent extends EventObject, _TCtx = [TContext] extends [never] ? any : TContext> = Record<string, (args: {
517
+ context: _TCtx;
518
+ event: TEvent;
519
+ self: AnyActorRef;
520
+ parent: AnyActorRef | undefined;
521
+ value: StateValue;
522
+ children: Record<string, AnyActorRef | undefined>;
523
+ }, ...params: any[]) => boolean>;
524
+ /**
525
+ * Contextually types the entries of a `delays: { ... }` source map. Delay
526
+ * functions receive `{ context, event, stateNode }` at runtime.
527
+ */
528
+ export type DelaySourceMap<TContext extends MachineContext, TEvent extends EventObject, _TCtx = [TContext] extends [never] ? any : TContext> = Record<string, number | ((args: {
529
+ context: _TCtx;
530
+ event: TEvent;
531
+ stateNode: AnyStateNode;
532
+ }) => number)>;
533
+ export type DelayMapFromNames<TDelays extends string, TDelayMap extends Sources['delays']> = string extends TDelays ? Sources['delays'] : {
534
+ [K in TDelays]: K extends keyof TDelayMap ? TDelayMap[K] : number | ((...args: any[]) => number);
513
535
  };
514
536
  type DelayNamesFromConfig<TConfig> = TConfig extends {
515
537
  delays: infer TDelays;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var createActor = require('./createActor-48401456.cjs.js');
3
+ var createActor = require('./createActor-6736cbbe.development.cjs.js');
4
4
 
5
5
  function attachMicrostepActorRefs(microsteps, actorScope, inputSnapshot) {
6
6
  if (!microsteps.length) {
@@ -130,6 +130,9 @@ function getInitialMicrosteps(machine, ...[input]) {
130
130
  * deterministic order
131
131
  */
132
132
  function getNextTransitions(state) {
133
+ if (state.status !== 'active') {
134
+ return [];
135
+ }
133
136
  const potentialTransitions = [];
134
137
  const atomicStates = state.nodes.filter(createActor.isAtomicStateNode);
135
138
  const visited = new Set();
@@ -1,4 +1,4 @@
1
- import { a9 as createInertActorScope, aa as setInertActorScopeSnapshot, f as finalizeTransitionResult, ab as attachSnapshotActorRef, K as createInitEvent, ay as hasAmbientInspector, a as beginSpawnAllocation, ac as macrostep, an as createSpawnEffect, ao as initialMicrostep, j as isAtomicStateNode, az as getProperAncestors, aA as isRemoteActorRef, aB as getActorIdPrefix } from './createActor-641ab5f7.esm.js';
1
+ import { aa as createInertActorScope, ab as setInertActorScopeSnapshot, f as finalizeTransitionResult, ac as attachSnapshotActorRef, K as createInitEvent, az as hasAmbientInspector, a as beginSpawnAllocation, ad as macrostep, ao as createSpawnEffect, ap as initialMicrostep, j as isAtomicStateNode, aA as getProperAncestors, aB as isRemoteActorRef, aC as getActorIdPrefix } from './createActor-915ea40c.esm.js';
2
2
 
3
3
  function attachMicrostepActorRefs(microsteps, actorScope, inputSnapshot) {
4
4
  if (!microsteps.length) {
@@ -128,6 +128,9 @@ function getInitialMicrosteps(machine, ...[input]) {
128
128
  * deterministic order
129
129
  */
130
130
  function getNextTransitions(state) {
131
+ if (state.status !== 'active') {
132
+ return [];
133
+ }
131
134
  const potentialTransitions = [];
132
135
  const atomicStates = state.nodes.filter(isAtomicStateNode);
133
136
  const visited = new Set();
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var createActor = require('./createActor-5c9fa117.development.cjs.js');
3
+ var createActor = require('./createActor-bfe8b6bd.cjs.js');
4
4
 
5
5
  function attachMicrostepActorRefs(microsteps, actorScope, inputSnapshot) {
6
6
  if (!microsteps.length) {
@@ -130,6 +130,9 @@ function getInitialMicrosteps(machine, ...[input]) {
130
130
  * deterministic order
131
131
  */
132
132
  function getNextTransitions(state) {
133
+ if (state.status !== 'active') {
134
+ return [];
135
+ }
133
136
  const potentialTransitions = [];
134
137
  const atomicStates = state.nodes.filter(createActor.isAtomicStateNode);
135
138
  const visited = new Set();
@@ -1,4 +1,4 @@
1
- import { a9 as createInertActorScope, aa as setInertActorScopeSnapshot, f as finalizeTransitionResult, ab as attachSnapshotActorRef, K as createInitEvent, ay as hasAmbientInspector, a as beginSpawnAllocation, ac as macrostep, an as createSpawnEffect, ao as initialMicrostep, j as isAtomicStateNode, az as getProperAncestors, aA as isRemoteActorRef, aB as getActorIdPrefix } from './createActor-60ee6b5b.development.esm.js';
1
+ import { aa as createInertActorScope, ab as setInertActorScopeSnapshot, f as finalizeTransitionResult, ac as attachSnapshotActorRef, K as createInitEvent, az as hasAmbientInspector, a as beginSpawnAllocation, ad as macrostep, ao as createSpawnEffect, ap as initialMicrostep, j as isAtomicStateNode, aA as getProperAncestors, aB as isRemoteActorRef, aC as getActorIdPrefix } from './createActor-ff132afa.development.esm.js';
2
2
 
3
3
  function attachMicrostepActorRefs(microsteps, actorScope, inputSnapshot) {
4
4
  if (!microsteps.length) {
@@ -128,6 +128,9 @@ function getInitialMicrosteps(machine, ...[input]) {
128
128
  * deterministic order
129
129
  */
130
130
  function getNextTransitions(state) {
131
+ if (state.status !== 'active') {
132
+ return [];
133
+ }
131
134
  const potentialTransitions = [];
132
135
  const atomicStates = state.nodes.filter(isAtomicStateNode);
133
136
  const visited = new Set();
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var createActor = require('./createActor-5c9fa117.development.cjs.js');
3
+ var createActor = require('./createActor-6736cbbe.development.cjs.js');
4
4
 
5
5
  function assertValid(validator, request) {
6
6
  const error = validator.check(request);
@@ -1,4 +1,4 @@
1
- import { K as createInitEvent, e as XSTATE_STOP, L as createCustomEffect, M as XSTATE_LOGIC_EFFECT_START, N as XSTATE_LOGIC_EFFECT_RESOLVE, O as XSTATE_LOGIC_EFFECT_REJECT, f as finalizeTransitionResult, P as createEmitEffect, h as createSendToEffect, X as XSTATE_INIT, p as parseDelayToMilliseconds, H as runStep, k as createActor } from './createActor-60ee6b5b.development.esm.js';
1
+ import { K as createInitEvent, e as XSTATE_STOP, L as createCustomEffect, M as XSTATE_LOGIC_EFFECT_START, N as XSTATE_LOGIC_EFFECT_RESOLVE, O as XSTATE_LOGIC_EFFECT_REJECT, f as finalizeTransitionResult, P as createEmitEffect, h as createSendToEffect, X as XSTATE_INIT, p as parseDelayToMilliseconds, H as runStep, k as createActor } from './createActor-ff132afa.development.esm.js';
2
2
 
3
3
  function assertValid(validator, request) {
4
4
  const error = validator.check(request);
@@ -1,4 +1,4 @@
1
- import { K as createInitEvent, e as XSTATE_STOP, L as createCustomEffect, M as XSTATE_LOGIC_EFFECT_START, N as XSTATE_LOGIC_EFFECT_RESOLVE, O as XSTATE_LOGIC_EFFECT_REJECT, f as finalizeTransitionResult, P as createEmitEffect, h as createSendToEffect, X as XSTATE_INIT, p as parseDelayToMilliseconds, H as runStep, k as createActor } from './createActor-641ab5f7.esm.js';
1
+ import { K as createInitEvent, e as XSTATE_STOP, L as createCustomEffect, M as XSTATE_LOGIC_EFFECT_START, N as XSTATE_LOGIC_EFFECT_RESOLVE, O as XSTATE_LOGIC_EFFECT_REJECT, f as finalizeTransitionResult, P as createEmitEffect, h as createSendToEffect, X as XSTATE_INIT, p as parseDelayToMilliseconds, H as runStep, k as createActor } from './createActor-915ea40c.esm.js';
2
2
 
3
3
  function assertValid(validator, request) {
4
4
  const error = validator.check(request);
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var createActor = require('./createActor-48401456.cjs.js');
3
+ var createActor = require('./createActor-bfe8b6bd.cjs.js');
4
4
 
5
5
  function assertValid(validator, request) {
6
6
  const error = validator.check(request);
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var createActor = require('./createActor-48401456.cjs.js');
6
- var dist_xstateActors = require('./index-fce4ea5c.cjs.js');
5
+ var createActor = require('./createActor-bfe8b6bd.cjs.js');
6
+ var dist_xstateActors = require('./index-b3fe59bc.cjs.js');
7
7
 
8
8
 
9
9
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var createActor = require('./createActor-5c9fa117.development.cjs.js');
6
- var dist_xstateActors = require('./index-662114ff.development.cjs.js');
5
+ var createActor = require('./createActor-6736cbbe.development.cjs.js');
6
+ var dist_xstateActors = require('./index-0f498ef2.development.cjs.js');
7
7
 
8
8
 
9
9
 
@@ -1,2 +1,2 @@
1
- export { l as createListenerLogic, n as createSubscriptionLogic, o as listenerLogic, s as subscriptionLogic } from './createActor-60ee6b5b.development.esm.js';
2
- export { T as TimeoutError, c as createAsyncLogic, a as createCallbackLogic, b as createEmptyActor, d as createEventObservableLogic, e as createLogic, f as createObservableLogic } from './index-158e7c37.development.esm.js';
1
+ export { l as createListenerLogic, n as createSubscriptionLogic, o as listenerLogic, s as subscriptionLogic } from './createActor-ff132afa.development.esm.js';
2
+ export { T as TimeoutError, c as createAsyncLogic, a as createCallbackLogic, b as createEmptyActor, d as createEventObservableLogic, e as createLogic, f as createObservableLogic } from './index-70d56425.development.esm.js';
@@ -1,2 +1,2 @@
1
- export { l as createListenerLogic, n as createSubscriptionLogic, o as listenerLogic, s as subscriptionLogic } from './createActor-641ab5f7.esm.js';
2
- export { T as TimeoutError, c as createAsyncLogic, a as createCallbackLogic, b as createEmptyActor, d as createEventObservableLogic, e as createLogic, f as createObservableLogic } from './index-8f19f242.esm.js';
1
+ export { l as createListenerLogic, n as createSubscriptionLogic, o as listenerLogic, s as subscriptionLogic } from './createActor-915ea40c.esm.js';
2
+ export { T as TimeoutError, c as createAsyncLogic, a as createCallbackLogic, b as createEmptyActor, d as createEventObservableLogic, e as createLogic, f as createObservableLogic } from './index-b051c924.esm.js';