xstate 6.0.0-alpha.2 → 6.0.0-alpha.3

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 (36) hide show
  1. package/dist/{StateMachine-8d22a79c.development.cjs.js → StateMachine-0770ac71.development.cjs.js} +1 -1
  2. package/dist/{StateMachine-2dcdb1f5.esm.js → StateMachine-8249d511.esm.js} +1 -1
  3. package/dist/{StateMachine-64813f46.cjs.js → StateMachine-e1048cd6.cjs.js} +1 -1
  4. package/dist/{StateMachine-2ea0a7fa.development.esm.js → StateMachine-e6ad61d0.development.esm.js} +1 -1
  5. package/dist/declarations/src/StateMachine.d.ts +4 -4
  6. package/dist/declarations/src/createActor.d.ts +0 -2
  7. package/dist/declarations/src/index.d.ts +1 -3
  8. package/dist/declarations/src/serialize.d.ts +13 -8
  9. package/dist/declarations/src/types.d.ts +0 -4
  10. package/dist/declarations/src/types.v6.d.ts +11 -9
  11. package/dist/{index-f6ef20d1.development.cjs.js → index-269d256d.development.cjs.js} +10 -689
  12. package/dist/{index-e61170ba.development.esm.js → index-66ff64a6.development.esm.js} +11 -685
  13. package/dist/{index-93edd3bd.esm.js → index-a7e3d8b3.esm.js} +11 -685
  14. package/dist/{index-9cb3b3a0.cjs.js → index-dda021d5.cjs.js} +10 -689
  15. package/dist/xstate-actors.cjs.js +1 -1
  16. package/dist/xstate-actors.development.cjs.js +1 -1
  17. package/dist/xstate-actors.development.esm.js +1 -1
  18. package/dist/xstate-actors.esm.js +1 -1
  19. package/dist/xstate-actors.umd.min.js +1 -1
  20. package/dist/xstate-actors.umd.min.js.map +1 -1
  21. package/dist/xstate-graph.cjs.js +2 -2
  22. package/dist/xstate-graph.development.cjs.js +2 -2
  23. package/dist/xstate-graph.development.esm.js +2 -2
  24. package/dist/xstate-graph.esm.js +2 -2
  25. package/dist/xstate-graph.umd.min.js +1 -1
  26. package/dist/xstate-graph.umd.min.js.map +1 -1
  27. package/dist/xstate.cjs.js +85 -32
  28. package/dist/xstate.cjs.mjs +0 -5
  29. package/dist/xstate.development.cjs.js +85 -32
  30. package/dist/xstate.development.cjs.mjs +0 -5
  31. package/dist/xstate.development.esm.js +87 -29
  32. package/dist/xstate.esm.js +87 -29
  33. package/dist/xstate.umd.min.js +1 -1
  34. package/dist/xstate.umd.min.js.map +1 -1
  35. package/package.json +1 -1
  36. package/dist/declarations/src/atom.d.ts +0 -81
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var dist_xstateActors = require('./index-f6ef20d1.development.cjs.js');
3
+ var dist_xstateActors = require('./index-269d256d.development.cjs.js');
4
4
 
5
5
  function createSpawner(actorScope, {
6
6
  machine,
@@ -1,4 +1,4 @@
1
- import { P as ProcessingStatus, G as resolveReferencedActor, c as createActor, S as STATE_DELIMITER, H as mapValues, t as toArray, I as createInvokeId, J as getDelayedTransitions, K as evaluateCandidate, L as formatTransition, N as NULL_EVENT, M as toTransitionConfigArray, O as createInvokeTimeoutEvent, Q as getCandidates, R as formatRouteTransitions, U as resolveStateValue, V as getAllStateNodes, n as getStateNodes, W as createMachineSnapshot, X as isInFinalState, a as macrostep, Y as transitionNode, m as matchesEventDescriptor, Z as resolveAndExecuteActionsWithContext, b as createInitEvent, d as initialMicrostep, _ as toStatePath, $ as isStateId, a0 as getStateNodeByPath, a1 as getPersistedSnapshot, a2 as $$ACTOR_TYPE } from './index-93edd3bd.esm.js';
1
+ import { P as ProcessingStatus, B as resolveReferencedActor, c as createActor, S as STATE_DELIMITER, C as mapValues, t as toArray, D as createInvokeId, E as getDelayedTransitions, F as evaluateCandidate, G as formatTransition, N as NULL_EVENT, H as toTransitionConfigArray, I as createInvokeTimeoutEvent, J as getCandidates, K as formatRouteTransitions, L as resolveStateValue, M as getAllStateNodes, f as getStateNodes, O as createMachineSnapshot, Q as isInFinalState, a as macrostep, R as transitionNode, m as matchesEventDescriptor, U as resolveAndExecuteActionsWithContext, b as createInitEvent, d as initialMicrostep, V as toStatePath, W as isStateId, X as getStateNodeByPath, Y as getPersistedSnapshot, $ as $$ACTOR_TYPE } from './index-a7e3d8b3.esm.js';
2
2
 
3
3
  function createSpawner(actorScope, {
4
4
  machine,
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var dist_xstateActors = require('./index-9cb3b3a0.cjs.js');
3
+ var dist_xstateActors = require('./index-dda021d5.cjs.js');
4
4
 
5
5
  function createSpawner(actorScope, {
6
6
  machine,
@@ -1,4 +1,4 @@
1
- import { P as ProcessingStatus, G as resolveReferencedActor, c as createActor, S as STATE_DELIMITER, H as mapValues, t as toArray, I as createInvokeId, J as getDelayedTransitions, K as evaluateCandidate, L as formatTransition, N as NULL_EVENT, M as toTransitionConfigArray, O as createInvokeTimeoutEvent, Q as getCandidates, R as formatRouteTransitions, U as resolveStateValue, V as getAllStateNodes, n as getStateNodes, W as createMachineSnapshot, X as isInFinalState, a as macrostep, Y as transitionNode, m as matchesEventDescriptor, Z as resolveAndExecuteActionsWithContext, b as createInitEvent, d as initialMicrostep, _ as toStatePath, $ as isStateId, a0 as getStateNodeByPath, a1 as getPersistedSnapshot, a2 as $$ACTOR_TYPE } from './index-e61170ba.development.esm.js';
1
+ import { P as ProcessingStatus, B as resolveReferencedActor, c as createActor, S as STATE_DELIMITER, C as mapValues, t as toArray, D as createInvokeId, E as getDelayedTransitions, F as evaluateCandidate, G as formatTransition, N as NULL_EVENT, H as toTransitionConfigArray, I as createInvokeTimeoutEvent, J as getCandidates, K as formatRouteTransitions, L as resolveStateValue, M as getAllStateNodes, f as getStateNodes, O as createMachineSnapshot, Q as isInFinalState, a as macrostep, R as transitionNode, m as matchesEventDescriptor, U as resolveAndExecuteActionsWithContext, b as createInitEvent, d as initialMicrostep, V as toStatePath, W as isStateId, X as getStateNodeByPath, Y as getPersistedSnapshot, $ as $$ACTOR_TYPE } from './index-66ff64a6.development.esm.js';
2
2
 
3
3
  function createSpawner(actorScope, {
4
4
  machine,
@@ -2,16 +2,16 @@ import { MachineSnapshot } from "./State.js";
2
2
  import { StateNode } from "./StateNode.js";
3
3
  import { AnyActorSystem } from "./system.js";
4
4
  import type { ActorLogic, ActorScope, AnyActor, AnyActorRef, AnyActorScope, AnyTransitionDefinition, Equals, EventDescriptor, EventObject, HistoryValue, MachineContext, MetaObject, Snapshot, StateValue, StateSchema, SnapshotStatus } from "./types.js";
5
- import { Implementations, Next_MachineConfig, MachineOptions } from "./types.v6.js";
5
+ import { AnyMachineSchemas, Implementations, Next_MachineConfig, MachineOptions } from "./types.v6.js";
6
6
  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['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> implements ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, TEvent, TInput, AnyActorSystem, TEmitted> {
7
7
  /** The raw config used to create the machine. */
8
8
  config: Next_MachineConfig<any, any, any, any, any, any, any, any, any, any> & {
9
- schemas?: unknown;
9
+ schemas?: AnyMachineSchemas;
10
10
  internalEvents?: readonly string[];
11
11
  };
12
12
  /** The machine's own version. */
13
13
  version?: string;
14
- schemas: unknown;
14
+ schemas: AnyMachineSchemas | undefined;
15
15
  implementations: Implementations;
16
16
  /** Runtime options for machine execution. */
17
17
  options: MachineOptions;
@@ -23,7 +23,7 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
23
23
  constructor(
24
24
  /** The raw config used to create the machine. */
25
25
  config: Next_MachineConfig<any, any, any, any, any, any, any, any, any, any> & {
26
- schemas?: unknown;
26
+ schemas?: AnyMachineSchemas;
27
27
  internalEvents?: readonly string[];
28
28
  }, implementations?: Implementations);
29
29
  /**
@@ -177,8 +177,6 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorInstanc
177
177
  * @see {@link Actor.getPersistedSnapshot} to persist the internal state of an actor (which is more than just a snapshot).
178
178
  */
179
179
  getSnapshot(): SnapshotFrom<TLogic>;
180
- /** Read the actor's current snapshot as an atom value. */
181
- get(): SnapshotFrom<TLogic>;
182
180
  }
183
181
  export type RequiredActorOptionsKeys<TLogic extends AnyActorLogic> = undefined extends InputFrom<TLogic> ? never : 'input';
184
182
  /**
@@ -1,12 +1,10 @@
1
1
  export * from "./actors/index.js";
2
- export { createAtom, createAtomConfig, createAsyncAtom, createReducerAtom, isAtom } from "./atom.js";
3
- export type { AnyAtom, AnyAtomConfig, AsyncAtomOptions, AsyncAtomState, Atom, AtomConfig, AtomOptions, BaseAtom, InputFromAtomConfig, ReadonlyAtom, ReducerAtom, ValueFromAtomConfig } from "./atom.js";
4
2
  export { assertEvent } from "./assert.js";
5
3
  export { Actor, createActor, type RequiredActorOptionsKeys as RequiredActorOptionsKeys } from "./createActor.js";
6
4
  export { createMachine, createStateConfig } from "./createMachine.js";
7
5
  export { createMachineFromConfig } from "./createMachineFromConfig.js";
8
6
  export type { ActionJSON, GuardJSON, InvokeJSON, MachineJSON, StateNodeJSON, TransitionJSON } from "./createMachineFromConfig.js";
9
- export { machineConfigToJSON, serializeMachine, type UnserializableMarker } from "./serialize.js";
7
+ export { machineConfigToJSON, serializeMachine, type CodeExpression, type UnserializableMarker } from "./serialize.js";
10
8
  export { mapState } from "./mapState.js";
11
9
  export { types, isTypeSchema, type StandardSchemaV1, type TypeSchema } from "./schema.types.js";
12
10
  export { setup } from "./setup.js";
@@ -3,10 +3,10 @@
3
3
  *
4
4
  * `machineConfigToJSON` converts a machine config into a JSON-safe structure
5
5
  * (the `MachineJSON` shape accepted by `createMachineFromConfig`). The boundary
6
- * between serializable structure and runtime implementations is explicit: any
7
- * value that cannot be represented as data (inline functions, actor logic,
8
- * runtime schemas) is replaced with an `{ "$unserializable": <kind> }` marker
9
- * rather than silently dropped.
6
+ * between serializable structure and runtime implementations is explicit:
7
+ * functions are represented as code expressions, while actor logic, runtime
8
+ * schemas, and other non-code runtime values are replaced with an `{
9
+ * "$unserializable": <kind> }` marker rather than silently dropped.
10
10
  *
11
11
  * A machine definition is fully portable iff its JSON contains no
12
12
  * `$unserializable` markers; reviving a definition that has markers requires
@@ -19,13 +19,18 @@ export interface UnserializableMarker {
19
19
  /** Best-effort identifier (function name, actor logic id) for diagnostics. */
20
20
  id?: string;
21
21
  }
22
+ export interface CodeExpression {
23
+ '@type': 'code';
24
+ lang: 'ts';
25
+ expr: string;
26
+ }
22
27
  /**
23
28
  * Returns the JSON-serializable definition of a machine.
24
29
  *
25
- * Inline functions, actor logic, and runtime schemas cannot be represented as
26
- * data; they appear as `{ "$unserializable": ... }` markers. A machine created
27
- * via `createMachineFromConfig` returns its original JSON config (lossless
28
- * round-trip):
30
+ * Inline functions are represented as `{ "@type": "code", lang: "ts", expr }`.
31
+ * Actor logic and runtime schemas appear as `{ "$unserializable": ... }`
32
+ * markers. A machine created via `createMachineFromConfig` returns its original
33
+ * JSON config (lossless round-trip):
29
34
  *
30
35
  * ```ts
31
36
  * import { serializeMachine, createMachineFromConfig } from 'xstate';
@@ -2,7 +2,6 @@ import type { MachineSnapshot } from "./State.js";
2
2
  import type { StateMachine } from "./StateMachine.js";
3
3
  import type { StateNode } from "./StateNode.js";
4
4
  import { AsyncActorLogic } from "./actors/promise.js";
5
- import type { BaseAtom } from "./atom.js";
6
5
  import type { Actor } from "./createActor.js";
7
6
  import { InspectionEvent } from "./inspection.js";
8
7
  import { Spawner } from "./spawn.js";
@@ -1019,9 +1018,6 @@ export type EnqueueObject<TEvent extends EventObject, TEmittedEvent extends Even
1019
1018
  */
1020
1019
  subscribeTo: {
1021
1020
  <TSnapshot extends Snapshot<unknown>, TOutput, TMappedEvent extends TEvent>(actor: AnyActor, mappers: SubscribeToMappers<TSnapshot, TOutput, TMappedEvent> | ((snapshot: TSnapshot) => TMappedEvent)): AnyActor;
1022
- <TValue, TMappedEvent extends TEvent>(atom: BaseAtom<TValue>, mappers: {
1023
- snapshot?: (value: TValue) => TMappedEvent;
1024
- } | ((value: TValue) => TMappedEvent)): AnyActor;
1025
1021
  };
1026
1022
  };
1027
1023
  export type Action<TContext extends MachineContext, TEvent extends EventObject, TEmittedEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TParams = Record<string, unknown> | undefined, _TCtx = [TContext] extends [never] ? any : TContext> = (_: {
@@ -46,17 +46,19 @@ export interface MachineOptions {
46
46
  */
47
47
  maxIterations?: number;
48
48
  }
49
+ type MachineSchemas<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> = {
50
+ events?: TEventSchemaMap;
51
+ context?: TContextSchema;
52
+ emitted?: TEmittedSchemaMap;
53
+ input?: TInputSchema;
54
+ output?: TOutputSchema;
55
+ meta?: TMetaSchema;
56
+ tags?: TTagSchema;
57
+ };
58
+ export type AnyMachineSchemas = MachineSchemas<StandardSchemaV1, Record<string, StandardSchemaV1>, Record<string, StandardSchemaV1>, StandardSchemaV1, StandardSchemaV1, StandardSchemaV1, StandardSchemaV1>;
49
59
  export type Next_MachineConfig<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 = InferOutput<TContextSchema, MachineContext>, TEvent extends EventObject = InferEvents<TEventSchemaMap>, TDelays extends string = string, _TTag extends string = string, TActionMap extends Implementations['actions'] = Implementations['actions'], TActorMap extends Implementations['actors'] = Implementations['actors'], TGuardMap extends Implementations['guards'] = Implementations['guards'], TDelayMap extends Implementations['delays'] = Implementations['delays'], TContextRequired extends boolean = IsNever<TContext> extends true ? false : true> = (DistributiveOmit<Next_StateNodeConfig<TContext, DoNotInfer<InferEvents<TEventSchemaMap>>, DoNotInfer<TDelays>, DoNotInfer<StandardSchemaV1.InferOutput<TTagSchema> & string>, DoNotInfer<StandardSchemaV1.InferOutput<TOutputSchema>>, DoNotInfer<InferEvents<TEmittedSchemaMap>>, DoNotInfer<InferOutput<TMetaSchema, MetaObject>>, DoNotInfer<TActionMap>, DoNotInfer<TActorMap>, DoNotInfer<TGuardMap>, DoNotInfer<TDelayMap>>, 'output'> & {
50
60
  internalEvents?: readonly InternalEventDescriptorFor<InferEvents<TEventSchemaMap>>[];
51
- schemas?: {
52
- events?: TEventSchemaMap;
53
- context?: TContextSchema;
54
- emitted?: TEmittedSchemaMap;
55
- input?: TInputSchema;
56
- output?: TOutputSchema;
57
- meta?: TMetaSchema;
58
- tags?: TTagSchema;
59
- };
61
+ schemas?: MachineSchemas<TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema>;
60
62
  actions?: TActionMap;
61
63
  guards?: TGuardMap;
62
64
  actors?: TActorMap;