@xstate/effect 1.0.0-alpha.8 → 1.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.
@@ -1,18 +1,19 @@
1
1
  import type { AnyMachineSnapshot, AnyStateMachine, MachineContext, MachineSnapshot, SnapshotFrom, StateContextFromStateValue, StateSchema, StateValueFromStateSchema } from 'xstate';
2
2
  type IsUnion<T, U = T> = T extends unknown ? [U] extends [T] ? false : true : never;
3
3
  type Join<TPrefix extends string, TKey extends string> = TPrefix extends '' ? TKey : `${TPrefix}.${TKey}`;
4
- /** The tag of the machine itself, used when the root state is parallel. */
5
- declare const MACHINE_TAG = "(machine)";
6
4
  /**
7
5
  * The dotted path of a state value: `'idle'`, `'form.editing'`. A parallel
8
- * state has no single path, so its tag stops at the parallel state, or is
9
- * `'(machine)'` when the machine itself is parallel.
6
+ * state has no single path, so its tag stops at the parallel state. When the
7
+ * machine itself is parallel, the tag is `TRootTag`: the machine id, or `''`
8
+ * for a machine without one.
10
9
  */
11
- export type StateTag<TValue, TPrefix extends string = ''> = string extends TValue ? string : TValue extends string ? Join<TPrefix, TValue> : TValue extends object ? string extends keyof TValue ? string : IsUnion<keyof TValue & string> extends true ? TPrefix extends '' ? typeof MACHINE_TAG : TPrefix : {
12
- [K in keyof TValue & string]: StateTag<TValue[K], Join<TPrefix, K>>;
10
+ export type StateTag<TValue, TPrefix extends string = '', TRootTag extends string = ''> = string extends TValue ? string : TValue extends string ? Join<TPrefix, TValue> : TValue extends object ? string extends keyof TValue ? string : IsUnion<keyof TValue & string> extends true ? TPrefix extends '' ? TRootTag : TPrefix : {
11
+ [K in keyof TValue & string]: StateTag<TValue[K], Join<TPrefix, K>, TRootTag>;
13
12
  }[keyof TValue & string] : never;
14
13
  type TaggedStateOf<TSnapshot, TValue, TContext extends MachineContext, TSchema extends StateSchema> = TValue extends unknown ? {
15
- readonly _tag: StateTag<TValue>;
14
+ readonly _tag: StateTag<TValue, '', TSchema extends {
15
+ id: infer TId extends string;
16
+ } ? TId : ''>;
16
17
  readonly value: TValue;
17
18
  readonly context: StateContextFromStateValue<TSchema, TContext, TValue>;
18
19
  readonly snapshot: TSnapshot;
@@ -715,13 +715,11 @@ class NotReadyError extends Data.TaggedError('NotReadyError') {
715
715
  }
716
716
  }
717
717
 
718
- /** The tag of the machine itself, used when the root state is parallel. */
719
- const MACHINE_TAG = '(machine)';
720
-
721
718
  /**
722
719
  * The dotted path of a state value: `'idle'`, `'form.editing'`. A parallel
723
- * state has no single path, so its tag stops at the parallel state, or is
724
- * `'(machine)'` when the machine itself is parallel.
720
+ * state has no single path, so its tag stops at the parallel state. When the
721
+ * machine itself is parallel, the tag is `TRootTag`: the machine id, or `''`
722
+ * for a machine without one.
725
723
  */
726
724
 
727
725
  /**
@@ -733,16 +731,16 @@ const MACHINE_TAG = '(machine)';
733
731
  /** The tagged state union of a machine. */
734
732
 
735
733
  /** Computes the dotted path tag of a state value. */
736
- function stateTag(value, prefix = '') {
734
+ function stateTag(value, rootTag, prefix = '') {
737
735
  if (typeof value === 'string') {
738
736
  return prefix ? `${prefix}.${value}` : value;
739
737
  }
740
738
  const keys = Object.keys(value);
741
739
  if (keys.length !== 1) {
742
- return prefix || MACHINE_TAG;
740
+ return prefix || rootTag;
743
741
  }
744
742
  const key = keys[0];
745
- return stateTag(value[key], prefix ? `${prefix}.${key}` : key);
743
+ return stateTag(value[key], rootTag, prefix ? `${prefix}.${key}` : key);
746
744
  }
747
745
 
748
746
  /**
@@ -762,7 +760,7 @@ function stateTag(value, prefix = '') {
762
760
  */
763
761
  function taggedState(snapshot) {
764
762
  return {
765
- _tag: stateTag(snapshot.value),
763
+ _tag: stateTag(snapshot.value, snapshot.machine.id),
766
764
  value: snapshot.value,
767
765
  context: snapshot.context,
768
766
  snapshot
@@ -1,7 +1,7 @@
1
1
  import { Cause } from 'effect';
2
2
  import { Atom, AsyncResult } from 'effect/reactivity';
3
- import { c as createEffectActor, N as NotReadyError, t as taggedState } from './state-ea62b88e.js';
4
- export { N as NotReadyError } from './state-ea62b88e.js';
3
+ import { c as createEffectActor, N as NotReadyError, t as taggedState } from './state-a2e5cb31.js';
4
+ export { N as NotReadyError } from './state-a2e5cb31.js';
5
5
  import 'xstate';
6
6
  import 'xstate/durable';
7
7
 
@@ -1,7 +1,7 @@
1
1
  import { Schema, Effect, Stream, Exit, Cause, Queue } from 'effect';
2
2
  import { createStepLogic, setup } from 'xstate';
3
- import { s as startHostedEffect, r as relayToParent, E as EffectInterruptedError, A as ActorStoppedError, a as runHostedEffect } from './state-ea62b88e.js';
4
- export { d as ActorScope, A as ActorStoppedError, b as EffectActor, E as EffectInterruptedError, c as createEffectActor, t as taggedState, w as withActorScope } from './state-ea62b88e.js';
3
+ import { s as startHostedEffect, r as relayToParent, E as EffectInterruptedError, A as ActorStoppedError, a as runHostedEffect } from './state-a2e5cb31.js';
4
+ export { d as ActorScope, A as ActorStoppedError, b as EffectActor, E as EffectInterruptedError, c as createEffectActor, t as taggedState, w as withActorScope } from './state-a2e5cb31.js';
5
5
  import { dual } from 'effect/Function';
6
6
  import 'xstate/durable';
7
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xstate/effect",
3
- "version": "1.0.0-alpha.8",
3
+ "version": "1.0.0-alpha.9",
4
4
  "type": "module",
5
5
  "description": "Effect integration for XState",
6
6
  "keywords": [
@@ -30,12 +30,12 @@
30
30
  },
31
31
  "peerDependencies": {
32
32
  "effect": "^4.0.0",
33
- "xstate": "^6.0.0-alpha.68"
33
+ "xstate": "^6.0.0-alpha.70"
34
34
  },
35
35
  "devDependencies": {
36
36
  "effect": "4.0.0",
37
37
  "fast-check": "4.10.2",
38
- "xstate": "^6.0.0-alpha.68"
38
+ "xstate": "^6.0.0-alpha.70"
39
39
  },
40
40
  "preconstruct": {
41
41
  "entrypoints": [