xstate 6.0.0-beta.0 → 6.0.0-beta.1

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/bin/xstate.js CHANGED
@@ -15,11 +15,14 @@ switch (command) {
15
15
  case 'diff':
16
16
  require('./agent.js')(command, rest);
17
17
  break;
18
- case 'migrate': {
19
- // Delegates to @xstate/codemod (ts-morph based v5 → v6 codemods).
18
+ case 'migrate':
19
+ case 'baseline':
20
+ case 'verify': {
21
+ // Delegates to @xstate/codemod (ts-morph based v5 → v6 codemods plus the
22
+ // baseline/verify trace-equivalence loop).
20
23
  const result = spawnSync(
21
24
  process.platform === 'win32' ? 'npx.cmd' : 'npx',
22
- ['-y', '@xstate/codemod', 'migrate', ...rest],
25
+ ['-y', '@xstate/codemod', command, ...rest],
23
26
  { stdio: 'inherit' }
24
27
  );
25
28
  process.exit(result.status ?? 1);
@@ -41,7 +44,10 @@ switch (command) {
41
44
  ' replay <machine> <fixture> Replay a matching counterexample (JSON)',
42
45
  ' diff <before> <after> Structural definition changes (JSON)',
43
46
  ' migrate [globs...] [--dry] Migrate source files to the current XState version',
44
- ' (delegates to @xstate/codemod)'
47
+ ' (delegates to @xstate/codemod)',
48
+ ' baseline <v5-file> Record a v5 behavior baseline before migrating',
49
+ ' verify --baseline <json> <v6-file>',
50
+ ' Replay the baseline against the migrated module'
45
51
  ].join('\n')
46
52
  );
47
53
  process.exit(command ? 0 : 1);
@@ -3,7 +3,7 @@ import type { SetupSchemas, SetupStateSchema, SetupStateType } from "./base.type
3
3
  import type { ActorLogicValidator } from "./validation.types.js";
4
4
  import { StateMachine, type CompatibleProvidedActorSource, type ProvidedActionContracts } from "./StateMachine.js";
5
5
  import { type Actor, type RequiredActorOptionsFor, type RequiredActorOptionsKeys } from "./createActor.js";
6
- import { AnyActorRef, AnyStateMachine, AnyActorLogic, ActorRefFrom, ActorSelf, AnyStateNode, EventObject, AnyEventObject, EventDescriptor, ReservedMachineEvent, ReservedEventFromDescriptor, ExtractEvent, MachineContext, ProvidedActor, RoutableStateId, StateSchema, StateValue, StateValueFromStateSchema, ToChildren, MetaObject, EnqueueObject, DoneActorEvent, DoneStateEvent, ErrorFrom, ErrorActorEvent, SystemRegistry, RegistryKeyForLogic, ActorOptions, Observer, Subscription, OutputArg, SnapshotEvent, AfterEvent, TimeoutEvent, ErrorEvent, CallbackActors, InputFrom, OutputFrom, SnapshotFrom, ActorTimeoutEvent } from "./types.js";
6
+ import { AnyActorRef, AnyStateMachine, AnyActorLogic, ActorRefFrom, ActorSelf, AnyStateNode, EventObject, AnyEventObject, EventDescriptor, ReservedMachineEvent, ReservedEventFromDescriptor, ExtractEvent, MachineContext, ProvidedActor, RoutableStateId, StateSchema, StateValue, StateValueFromStateSchema, ToChildren, MetaObject, EnqueueObject, DoneActorEvent, DoneStateEvent, ErrorFrom, ErrorActorEvent, SystemRegistry, RegistryKeyForLogic, ActorOptions, Observer, Subscription, OutputArg, SnapshotEvent, AfterEvent, TimeoutEvent, ErrorEvent, CallbackActors, InputFrom, OutputFrom, SnapshotFrom, ActorTimeoutEvent, TransitionTargetString } from "./types.js";
7
7
  import type { Cast, Compute, SingleOrArray, NonReducibleUnknown } from "./typeUtils.js";
8
8
  import { AnyActorSystem } from "./system.js";
9
9
  import { InspectionEvent } from "./inspection.js";
@@ -211,7 +211,7 @@ type UncheckedSetupStateSchemas = Record<string, UncheckedSetupStateSchema>;
211
211
  type SetupStateKey<TStateSchemas extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStateSchemas> ? string : [SetupStateKeys<TStateSchemas>] extends [never] ? string : SetupStateKeys<TStateSchemas>;
212
212
  type StrictSetupStatePaths<TStateSchemas extends Record<string, SetupStateSchema>> = [SetupStateKeys<TStateSchemas>] extends [never] ? never : StatePaths<TStateSchemas>;
213
213
  type SetupRelativeStateTarget<TStateSchemas extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStateSchemas> ? `.${string}` : [SetupStateKeys<TStateSchemas>] extends [never] ? '.' : '.' | `.${StatePaths<TStateSchemas> & string}`;
214
- type SetupStateTarget<TStateSchemas extends Record<string, SetupStateSchema>> = TStateSchemas extends StrictSetupStateTargetsMarker ? StrictSetupStatePaths<TStateSchemas> | SetupRelativeStateTarget<RelativeSetupStateSchemas<TStateSchemas>> | `#${string}` : string extends SetupStateKeys<TStateSchemas> ? string : [SetupStateKeys<TStateSchemas>] extends [never] ? string : StatePaths<TStateSchemas> | `.${string}` | `#${string}`;
214
+ type SetupStateTarget<TStateSchemas extends Record<string, SetupStateSchema>> = TStateSchemas extends StrictSetupStateTargetsMarker ? StrictSetupStatePaths<TStateSchemas> | SetupRelativeStateTarget<RelativeSetupStateSchemas<TStateSchemas>> | `#${string}` : string extends SetupStateKeys<TStateSchemas> ? TransitionTargetString : [SetupStateKeys<TStateSchemas>] extends [never] ? TransitionTargetString : StatePaths<TStateSchemas> | `.${string}` | `#${string}`;
215
215
  type KnownSetupStateTarget<TStateSchemas extends Record<string, SetupStateSchema>> = string extends StatePaths<TStateSchemas> ? string extends StatePaths<RelativeSetupStateSchemas<TStateSchemas>> ? never : SetupRelativeStateTarget<RelativeSetupStateSchemas<TStateSchemas>> | RootSetupStateIdTarget<RootSetupStateSchemas<TStateSchemas>> : (StrictSetupStatePaths<TStateSchemas> & string) | SetupRelativeStateTarget<RelativeSetupStateSchemas<TStateSchemas>> | RootSetupStateIdTarget<RootSetupStateSchemas<TStateSchemas>>;
216
216
  declare const strictSetupStateTargets: unique symbol;
217
217
  declare const relativeSetupStateSchemas: unique symbol;
@@ -625,7 +625,7 @@ type SetupStateNodeTargetArrayInputConstraint<TConfig, TSiblingStateSchemas exte
625
625
  };
626
626
  } : unknown);
627
627
  type ValidateSetupTargetArrayInputs<TConfig, TRootStateSchemas extends Record<string, SetupStateSchema>> = SetupStateNodeTargetArrayInputConstraint<TConfig, TRootStateSchemas, SetupStateSchema, TRootStateSchemas>;
628
- type ValidateSetupStateContracts<TConfig, TStateSchemas extends Record<string, SetupStateSchema>> = HasExplicitSetupStateContracts<TStateSchemas> extends true ? ValidateSetupHistoryInputs<TConfig, TStateSchemas> & ValidateHistoryDefaults<MergeSetupConfig<TConfig, TStateSchemas>> & ValidateStateTargets<MergeSetupConfig<TConfig, TStateSchemas>> & NoInfer<ValidateSetupTargetArrayInputs<TConfig, TStateSchemas>> : unknown;
628
+ type ValidateSetupStateContracts<TConfig, TStateSchemas extends Record<string, SetupStateSchema>> = ValidateStateTargets<MergeSetupConfig<TConfig, TStateSchemas>> & (HasExplicitSetupStateContracts<TStateSchemas> extends true ? ValidateSetupHistoryInputs<TConfig, TStateSchemas> & ValidateHistoryDefaults<MergeSetupConfig<TConfig, TStateSchemas>> & NoInfer<ValidateSetupTargetArrayInputs<TConfig, TStateSchemas>> : unknown);
629
629
  type SetupInitialTransitionConfig<TStateSchema extends SetupStateSchema, TTarget extends string, TConfig, TContext extends MachineContext, TEvent extends EventObject> = Extract<SetupConfigInitial<TConfig>, {
630
630
  target: TTarget;
631
631
  }> extends infer TInitial ? [TInitial] extends [never] ? {
@@ -178,11 +178,17 @@ export type StateNodesConfig<TContext extends MachineContext, TEvent extends Eve
178
178
  /** @public */
179
179
  export type TransitionConfigTarget = string | undefined;
180
180
  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>>;
181
+ /**
182
+ * @public A contextual type containing a literal ('.') keeps a returned
183
+ * literal target from widening to `string`, so `ValidateStateTargets` can
184
+ * check it; `string & {}` still accepts dynamic targets.
185
+ */
186
+ export type TransitionTargetString = '.' | (string & {});
181
187
  /** @public */
182
188
  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, TChildren extends Record<string, AnyActorRef | undefined> = {}> = (args: TransitionFunctionArgs<_TCtx, TCurrentEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, TChildren> & {
183
189
  input: TInput;
184
190
  }, enq: EnqueueObject<TEvent, TEmitted, SystemRegistry, Compute<CallbackActors<TActorMap>>, TChildren>) => {
185
- target?: string | string[];
191
+ target?: TransitionTargetString | TransitionTargetString[];
186
192
  context?: TransitionContextPatch<_TCtx>;
187
193
  reenter?: boolean;
188
194
  meta?: TMeta;