@xmachines/play-xstate 2.0.0 → 2.1.0

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 (56) hide show
  1. package/README.md +66 -65
  2. package/dist/define-player.d.ts +16 -16
  3. package/dist/define-player.js +16 -16
  4. package/dist/errors.d.ts +57 -50
  5. package/dist/errors.d.ts.map +1 -1
  6. package/dist/errors.js +63 -55
  7. package/dist/errors.js.map +1 -1
  8. package/dist/guards/compose.d.ts +53 -50
  9. package/dist/guards/compose.d.ts.map +1 -1
  10. package/dist/guards/compose.js +67 -63
  11. package/dist/guards/compose.js.map +1 -1
  12. package/dist/guards/helpers.d.ts +22 -22
  13. package/dist/guards/helpers.js +23 -23
  14. package/dist/guards/index.d.ts +9 -9
  15. package/dist/guards/index.js +9 -9
  16. package/dist/guards/types.d.ts +9 -8
  17. package/dist/guards/types.d.ts.map +1 -1
  18. package/dist/index.d.ts +6 -5
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +8 -7
  21. package/dist/index.js.map +1 -1
  22. package/dist/player-actor.d.ts +162 -146
  23. package/dist/player-actor.d.ts.map +1 -1
  24. package/dist/player-actor.js +269 -241
  25. package/dist/player-actor.js.map +1 -1
  26. package/dist/routing/build-url.d.ts +19 -16
  27. package/dist/routing/build-url.d.ts.map +1 -1
  28. package/dist/routing/build-url.js +62 -59
  29. package/dist/routing/build-url.js.map +1 -1
  30. package/dist/routing/derive-current-route.d.ts +42 -36
  31. package/dist/routing/derive-current-route.d.ts.map +1 -1
  32. package/dist/routing/derive-current-route.js +57 -49
  33. package/dist/routing/derive-current-route.js.map +1 -1
  34. package/dist/routing/derive-initial-route.d.ts +23 -20
  35. package/dist/routing/derive-initial-route.d.ts.map +1 -1
  36. package/dist/routing/derive-initial-route.js +27 -24
  37. package/dist/routing/derive-initial-route.js.map +1 -1
  38. package/dist/routing/derive-route.d.ts +38 -37
  39. package/dist/routing/derive-route.d.ts.map +1 -1
  40. package/dist/routing/derive-route.js +45 -42
  41. package/dist/routing/derive-route.js.map +1 -1
  42. package/dist/routing/format-play-route-transitions.d.ts +34 -28
  43. package/dist/routing/format-play-route-transitions.d.ts.map +1 -1
  44. package/dist/routing/format-play-route-transitions.js +32 -28
  45. package/dist/routing/format-play-route-transitions.js.map +1 -1
  46. package/dist/routing/index.d.ts +3 -3
  47. package/dist/routing/index.js +3 -3
  48. package/dist/routing/types.d.ts +12 -11
  49. package/dist/routing/types.d.ts.map +1 -1
  50. package/dist/types.d.ts +64 -60
  51. package/dist/types.d.ts.map +1 -1
  52. package/dist/view/derive-current-view.d.ts +42 -40
  53. package/dist/view/derive-current-view.d.ts.map +1 -1
  54. package/dist/view/derive-current-view.js +51 -47
  55. package/dist/view/derive-current-view.js.map +1 -1
  56. package/package.json +7 -6
@@ -1,40 +1,43 @@
1
1
  import { and, or, not } from "xstate";
2
2
  import { EmptyGuardArrayError } from "../errors.js";
3
3
  /**
4
- * PRODUCTION code's single unsound boundary, scoped to XState's guard typings.
5
- * (Test code uses `unsafeCast` from `@xmachines/shared/test-support` instead —
6
- * the two are counterparts; a grep-based cast audit must cover both names.)
7
- *
8
- * These deprecated helpers bridge two known gaps in XState 5.28's types: our
9
- * `Guard<TContext, TEvent>` does not structurally match `ComposedGuard`
10
- * (generic event mismatch), and `and()`/`or()` require `readonly [...tuple]`
11
- * where `GuardArray` is a mutable array. The runtime values are identical in
12
- * every case. The parameter is `unknown`, so the one `as` lives here instead
13
- * of double-casts at each call site.
14
- * Track XState typing improvements: https://github.com/statelyai/xstate/issues
4
+ * The one unsound boundary of the PRODUCTION code, and it covers the guard types of
5
+ * XState only. (The test code uses `unsafeCast` from
6
+ * `@xmachines/shared/test-support` instead. The two functions are counterparts, and
7
+ * an audit of the casts with grep must cover both names.)
8
+ *
9
+ * These deprecated helpers close two known gaps in the types of XState 5.28. In the
10
+ * first gap, our `Guard<TContext, TEvent>` type does not match `ComposedGuard`
11
+ * structurally, because the event generic is different. In the second gap, `and()`
12
+ * and `or()` need a `readonly [...tuple]`, and `GuardArray` is a mutable array. The
13
+ * values at run time are identical in each case. The parameter has the type
14
+ * `unknown`. Therefore one `as` cast is here, and no call site needs a double cast.
15
+ * Follow the improvements of the XState types: https://github.com/statelyai/xstate/issues
15
16
  */
16
17
  const asXStateGuard = (value) => value;
17
18
  /**
18
- * Compose guards with AND logic using XState's and() helper
19
+ * Composes the guards with the AND logic, through the and() helper of XState
19
20
  *
20
- * Combines multiple guard predicates using AND semantics—all guards must pass for
21
- * the composition to succeed. Uses XState's built-in `and()` helper to ensure proper
22
- * type inference and machine serialization.
21
+ * The function joins more than one guard predicate with the AND semantics: every
22
+ * guard must pass, and the composition then succeeds. It uses the built-in `and()`
23
+ * helper of XState. The type inference and the serialization of the machine are
24
+ * therefore correct.
23
25
  *
24
- * **Architectural Context:** Supports **Actor Authority (INV-01)** by enabling
25
- * declarative guard composition in state machine transitions. Guards enforce business
26
- * logic rules that determine whether navigation or actions are valid.
26
+ * **Architectural context:** the function supports **Actor Authority (INV-01)**,
27
+ * because it composes the guards of a state machine transition declaratively. A
28
+ * guard enforces a rule of the business logic, and that rule decides if a
29
+ * navigation or an action is valid.
27
30
  *
28
- * @typeParam TContext - State machine context type
29
- * @typeParam TEvent - Event type
31
+ * @typeParam TContext - The context type of the state machine
32
+ * @typeParam TEvent - The event type
30
33
  *
31
- * @param guards - Array of guard predicates or guard names (string references)
32
- * @returns XState and() guard composition
34
+ * @param guards - The array of the guard predicates, or of the guard names as strings
35
+ * @returns The and() guard composition of XState
33
36
  *
34
- * @throws {Error} If guards array is empty
37
+ * @throws {Error} When the array of the guards is empty
35
38
  *
36
39
  * @example
37
- * AND composition with named guards
40
+ * An AND composition with named guards
38
41
  * ```typescript
39
42
  * import { setup } from "xstate";
40
43
  * import { composeGuards } from "@xmachines/play-xstate";
@@ -56,7 +59,7 @@ const asXStateGuard = (value) => value;
56
59
  * ```
57
60
  *
58
61
  * @example
59
- * AND composition with inline predicates
62
+ * An AND composition with inline predicates
60
63
  * ```typescript
61
64
  * import { composeGuards } from "@xmachines/play-xstate";
62
65
  *
@@ -66,10 +69,10 @@ const asXStateGuard = (value) => value;
66
69
  * ])
67
70
  * ```
68
71
  *
69
- * @see {@link composeGuardsOr} for OR composition
70
- * @see {@link negateGuard} for NOT logic
71
- * @deprecated Use XState's own `and()`/`or()`/`not()` directly this helper does not
72
- * compose with `setup()`-typed guard slots and will be removed in the next major.
72
+ * @see {@link composeGuardsOr} for the OR composition
73
+ * @see {@link negateGuard} for the NOT logic
74
+ * @deprecated Use the `and()`, `or()`, and `not()` combinators of XState directly. This helper
75
+ * does not compose with a guard slot that `setup()` types, and the next major version removes it.
73
76
  */
74
77
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
75
78
  export const composeGuards = (guards) => {
@@ -77,29 +80,29 @@ export const composeGuards = (guards) => {
77
80
  throw new EmptyGuardArrayError("and");
78
81
  }
79
82
  if (guards.length === 1) {
80
- // Single guard passthrough see asXStateGuard for why the boundary exists.
83
+ // One guard passes through. asXStateGuard gives the reason for the boundary.
81
84
  return asXStateGuard(guards[0]);
82
85
  }
83
- // Use XState's built-in and() for type inference and serialization.
86
+ // Use the built-in and() of XState, for the type inference and the serialization.
84
87
  return and(asXStateGuard(guards));
85
88
  };
86
89
  /**
87
- * Compose guards with OR logic using XState's or() helper
90
+ * Composes the guards with the OR logic, through the or() helper of XState
88
91
  *
89
- * Combines multiple guard predicates using OR semantics—at least one guard must pass
90
- * for the composition to succeed. Uses XState's built-in `or()` helper for proper
91
- * type inference.
92
+ * The function joins more than one guard predicate with the OR semantics: one guard
93
+ * must pass at least, and the composition then succeeds. It uses the built-in `or()`
94
+ * helper of XState, and the type inference is therefore correct.
92
95
  *
93
- * @typeParam TContext - State machine context type
94
- * @typeParam TEvent - Event type
96
+ * @typeParam TContext - The context type of the state machine
97
+ * @typeParam TEvent - The event type
95
98
  *
96
- * @param guards - Array of guard predicates or guard names
97
- * @returns XState or() guard composition
99
+ * @param guards - The array of the guard predicates, or of the guard names
100
+ * @returns The or() guard composition of XState
98
101
  *
99
- * @throws {Error} If guards array is empty
102
+ * @throws {Error} When the array of the guards is empty
100
103
  *
101
104
  * @example
102
- * OR composition with named guards
105
+ * An OR composition with named guards
103
106
  * ```typescript
104
107
  * import { setup } from "xstate";
105
108
  * import { composeGuardsOr } from "@xmachines/play-xstate";
@@ -112,7 +115,7 @@ export const composeGuards = (guards) => {
112
115
  * }).createMachine({
113
116
  * on: {
114
117
  * deleteResource: {
115
- * // Either guard can pass
118
+ * // One guard is sufficient
116
119
  * guard: composeGuardsOr(['isOwner', 'isAdmin']),
117
120
  * actions: 'delete'
118
121
  * }
@@ -120,10 +123,10 @@ export const composeGuards = (guards) => {
120
123
  * });
121
124
  * ```
122
125
  *
123
- * @see {@link composeGuards} for AND composition
124
- * @see {@link negateGuard} for NOT logic
125
- * @deprecated Use XState's own `and()`/`or()`/`not()` directly this helper does not
126
- * compose with `setup()`-typed guard slots and will be removed in the next major.
126
+ * @see {@link composeGuards} for the AND composition
127
+ * @see {@link negateGuard} for the NOT logic
128
+ * @deprecated Use the `and()`, `or()`, and `not()` combinators of XState directly. This helper
129
+ * does not compose with a guard slot that `setup()` types, and the next major version removes it.
127
130
  */
128
131
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
129
132
  export const composeGuardsOr = (guards) => {
@@ -131,26 +134,27 @@ export const composeGuardsOr = (guards) => {
131
134
  throw new EmptyGuardArrayError("or");
132
135
  }
133
136
  if (guards.length === 1) {
134
- // Single guard passthrough see asXStateGuard for why the boundary exists.
137
+ // One guard passes through. asXStateGuard gives the reason for the boundary.
135
138
  return asXStateGuard(guards[0]);
136
139
  }
137
- // Use XState's built-in or() for type inference and serialization.
140
+ // Use the built-in or() of XState, for the type inference and the serialization.
138
141
  return or(asXStateGuard(guards));
139
142
  };
140
143
  /**
141
- * Negate a guard using XState's not() helper
144
+ * Negates a guard, through the not() helper of XState
142
145
  *
143
- * Inverts a guard's result—if the guard passes, NOT fails; if guard fails, NOT passes.
144
- * Uses XState's built-in `not()` helper for proper serialization.
146
+ * The function inverts the result of a guard: the guard passes, and NOT then fails;
147
+ * the guard fails, and NOT then passes. It uses the built-in `not()` helper of
148
+ * XState, and the serialization is therefore correct.
145
149
  *
146
- * @typeParam TContext - State machine context type
147
- * @typeParam TEvent - Event type
150
+ * @typeParam TContext - The context type of the state machine
151
+ * @typeParam TEvent - The event type
148
152
  *
149
- * @param guard - Guard predicate or guard name to negate
150
- * @returns XState not() guard negation
153
+ * @param guard - The guard predicate to negate, or its name
154
+ * @returns The not() guard negation of XState
151
155
  *
152
156
  * @example
153
- * NOT composition with named guard
157
+ * A NOT composition with a named guard
154
158
  * ```typescript
155
159
  * import { setup } from "xstate";
156
160
  * import { negateGuard } from "@xmachines/play-xstate";
@@ -162,7 +166,7 @@ export const composeGuardsOr = (guards) => {
162
166
  * }).createMachine({
163
167
  * on: {
164
168
  * accessDashboard: {
165
- * // Allow if NOT a guest (i.e., authenticated)
169
+ * // Permit the transition when the user is NOT a guest, which means an authenticated user
166
170
  * guard: negateGuard('isGuest'),
167
171
  * target: 'dashboard'
168
172
  * }
@@ -170,15 +174,15 @@ export const composeGuardsOr = (guards) => {
170
174
  * });
171
175
  * ```
172
176
  *
173
- * @see {@link composeGuards} for AND composition
174
- * @see {@link composeGuardsOr} for OR composition
175
- * @deprecated Use XState's own `and()`/`or()`/`not()` directly this helper does not
176
- * compose with `setup()`-typed guard slots and will be removed in the next major.
177
+ * @see {@link composeGuards} for the AND composition
178
+ * @see {@link composeGuardsOr} for the OR composition
179
+ * @deprecated Use the `and()`, `or()`, and `not()` combinators of XState directly. This helper
180
+ * does not compose with a guard slot that `setup()` types, and the next major version removes it.
177
181
  */
178
182
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
179
183
  export const negateGuard = (guard) => {
180
- // XState 5.28.0: not() requires a specific SingleGuardArg shape, not our
181
- // Guard type see asXStateGuard.
184
+ // XState 5.28.0: not() requires one SingleGuardArg shape, and not the Guard
185
+ // type of this package. See asXStateGuard.
182
186
  return not(asXStateGuard(guard));
183
187
  };
184
188
  //# sourceMappingURL=compose.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"compose.js","sourceRoot":"","sources":["../../src/guards/compose.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAItC,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD;;;;;;;;;;;;GAYG;AACH,MAAM,aAAa,GAAG,CAAI,KAAc,EAAK,EAAE,CAAC,KAAU,CAAC;AAmB3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,aAAa,GAAG,CAC5B,MAAoC,EACpB,EAAE;IAClB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,oBAAoB,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,4EAA4E;QAC5E,OAAO,aAAa,CAAgB,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,oEAAoE;IACpE,OAAO,GAAG,CAAC,aAAa,CAA4B,MAAM,CAAC,CAAC,CAAC;AAC9D,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,eAAe,GAAG,CAC9B,MAAoC,EACpB,EAAE;IAClB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,oBAAoB,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,4EAA4E;QAC5E,OAAO,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;;;;;;;;;;;;;;;;;;GAyCG;AACH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,eAAe,GAAG,CAC9B,MAAoC,EACpB,EAAE;IAClB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,oBAAoB,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,6EAA6E;QAC7E,OAAO,aAAa,CAAgB,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,iFAAiF;IACjF,OAAO,EAAE,CAAC,aAAa,CAA2B,MAAM,CAAC,CAAC,CAAC;AAC5D,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,WAAW,GAAG,CAC1B,KAAuC,EACvB,EAAE;IAClB,4EAA4E;IAC5E,2CAA2C;IAC3C,OAAO,GAAG,CAAC,aAAa,CAA4B,KAAK,CAAC,CAAC,CAAC;AAC7D,CAAC,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import type { Guard } from "./types.js";
2
2
  import type { PlayEvent } from "@xmachines/play";
3
3
  /**
4
- * Check if context has a truthy value at path
4
+ * Tells you if the context holds a value at the path, and that the value is truthy
5
5
  *
6
6
  * @example
7
7
  * ```typescript
@@ -13,14 +13,14 @@ import type { PlayEvent } from "@xmachines/play";
13
13
  * });
14
14
  * ```
15
15
  *
16
- * @param path - Dot-separated path to context property
17
- * @returns Guard predicate checking if property is truthy
18
- * @deprecated Part of the guard utilities slated for removal in the next major
19
- * write a plain typed predicate instead.
16
+ * @param path - The path to the context property, with a dot between two segments
17
+ * @returns The guard predicate. It tests the property for a truthy value
18
+ * @deprecated This function is part of the guard utilities, and the next major version removes
19
+ * them. Write a plain typed predicate instead.
20
20
  */
21
21
  export declare const hasContext: <TContext = Record<string, unknown>>(path: string) => Guard<TContext, PlayEvent>;
22
22
  /**
23
- * Check if event type matches expected type
23
+ * Tells you if the type of the event is the expected type
24
24
  *
25
25
  * @example
26
26
  * ```typescript
@@ -35,28 +35,28 @@ export declare const hasContext: <TContext = Record<string, unknown>>(path: stri
35
35
  * });
36
36
  * ```
37
37
  *
38
- * @param eventType - Expected event type
39
- * @returns Guard predicate checking event type
40
- * @deprecated Part of the guard utilities slated for removal in the next major
41
- * write a plain typed predicate instead.
38
+ * @param eventType - The expected event type
39
+ * @returns The guard predicate. It tests the event type
40
+ * @deprecated This function is part of the guard utilities, and the next major version removes
41
+ * them. Write a plain typed predicate instead.
42
42
  */
43
43
  export declare const eventMatches: <TEvent extends PlayEvent = PlayEvent>(eventType: string) => Guard<unknown, TEvent>;
44
44
  /**
45
- * Check if a context field matches an expected value.
45
+ * Tells you if a context field holds the expected value.
46
46
  *
47
- * - Accepts an explicit dot-separated field path (e.g. `"user.role"`)
48
- * - Uses strict equality for primitives, deep structural equality for objects
49
- * - Object comparison is key-order-insensitive: `{a:1,b:2}` equals `{b:2,a:1}`
50
- * - Supports Date, RegExp, class instances, nested objects and arrays via `dequal/lite`
51
- * - Does NOT use substring matching — `"a"` will not match `"active"`
47
+ * - The function accepts an explicit field path, with a dot between two segments, for example `"user.role"`
48
+ * - It compares a primitive with a strict equality, and an object with a deep structural equality
49
+ * - The order of the keys has no effect on the comparison of an object: `{a:1,b:2}` equals `{b:2,a:1}`
50
+ * - It supports a Date, a RegExp, an instance of a class, a nested object, and an array, through `dequal/lite`
51
+ * - It does NOT match a substring: `"a"` does not match `"active"`
52
52
  *
53
- * For XState state-node matching, use the built-in `in:` guard syntax instead.
53
+ * For a match of an XState state node, use the built-in `in:` guard syntax instead.
54
54
  *
55
- * @param fieldPath - Dot-separated path to context property (e.g., "status", "user.role")
56
- * @param expectedValue - Value to compare against (string, object, Date, etc.)
57
- * @returns Guard predicate checking if context field matches
58
- * @deprecated Part of the guard utilities slated for removal in the next major
59
- * write a plain typed predicate instead.
55
+ * @param fieldPath - The path to the context property, with a dot between two segments, for example "status" or "user.role"
56
+ * @param expectedValue - The value for the comparison: a string, an object, a Date, and so on
57
+ * @returns The guard predicate. It tests the context field for the value
58
+ * @deprecated This function is part of the guard utilities, and the next major version removes
59
+ * them. Write a plain typed predicate instead.
60
60
  */
61
61
  export declare const contextFieldMatches: <TContext = Record<string, unknown>>(fieldPath: string, expectedValue: unknown) => Guard<TContext, PlayEvent>;
62
62
  //# sourceMappingURL=helpers.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { dequal } from "dequal/lite";
2
2
  /**
3
- * Check if context has a truthy value at path
3
+ * Tells you if the context holds a value at the path, and that the value is truthy
4
4
  *
5
5
  * @example
6
6
  * ```typescript
@@ -12,17 +12,17 @@ import { dequal } from "dequal/lite";
12
12
  * });
13
13
  * ```
14
14
  *
15
- * @param path - Dot-separated path to context property
16
- * @returns Guard predicate checking if property is truthy
17
- * @deprecated Part of the guard utilities slated for removal in the next major
18
- * write a plain typed predicate instead.
15
+ * @param path - The path to the context property, with a dot between two segments
16
+ * @returns The guard predicate. It tests the property for a truthy value
17
+ * @deprecated This function is part of the guard utilities, and the next major version removes
18
+ * them. Write a plain typed predicate instead.
19
19
  */
20
20
  export const hasContext = (path) => ({ context }) => {
21
21
  const value = getNestedValue(context, path);
22
22
  return value !== undefined && value !== null && value !== "";
23
23
  };
24
24
  /**
25
- * Check if event type matches expected type
25
+ * Tells you if the type of the event is the expected type
26
26
  *
27
27
  * @example
28
28
  * ```typescript
@@ -37,37 +37,37 @@ export const hasContext = (path) => ({ context }) => {
37
37
  * });
38
38
  * ```
39
39
  *
40
- * @param eventType - Expected event type
41
- * @returns Guard predicate checking event type
42
- * @deprecated Part of the guard utilities slated for removal in the next major
43
- * write a plain typed predicate instead.
40
+ * @param eventType - The expected event type
41
+ * @returns The guard predicate. It tests the event type
42
+ * @deprecated This function is part of the guard utilities, and the next major version removes
43
+ * them. Write a plain typed predicate instead.
44
44
  */
45
45
  export const eventMatches = (eventType) => ({ event }) => {
46
46
  return event.type === eventType;
47
47
  };
48
48
  /**
49
- * Check if a context field matches an expected value.
49
+ * Tells you if a context field holds the expected value.
50
50
  *
51
- * - Accepts an explicit dot-separated field path (e.g. `"user.role"`)
52
- * - Uses strict equality for primitives, deep structural equality for objects
53
- * - Object comparison is key-order-insensitive: `{a:1,b:2}` equals `{b:2,a:1}`
54
- * - Supports Date, RegExp, class instances, nested objects and arrays via `dequal/lite`
55
- * - Does NOT use substring matching — `"a"` will not match `"active"`
51
+ * - The function accepts an explicit field path, with a dot between two segments, for example `"user.role"`
52
+ * - It compares a primitive with a strict equality, and an object with a deep structural equality
53
+ * - The order of the keys has no effect on the comparison of an object: `{a:1,b:2}` equals `{b:2,a:1}`
54
+ * - It supports a Date, a RegExp, an instance of a class, a nested object, and an array, through `dequal/lite`
55
+ * - It does NOT match a substring: `"a"` does not match `"active"`
56
56
  *
57
- * For XState state-node matching, use the built-in `in:` guard syntax instead.
57
+ * For a match of an XState state node, use the built-in `in:` guard syntax instead.
58
58
  *
59
- * @param fieldPath - Dot-separated path to context property (e.g., "status", "user.role")
60
- * @param expectedValue - Value to compare against (string, object, Date, etc.)
61
- * @returns Guard predicate checking if context field matches
62
- * @deprecated Part of the guard utilities slated for removal in the next major
63
- * write a plain typed predicate instead.
59
+ * @param fieldPath - The path to the context property, with a dot between two segments, for example "status" or "user.role"
60
+ * @param expectedValue - The value for the comparison: a string, an object, a Date, and so on
61
+ * @returns The guard predicate. It tests the context field for the value
62
+ * @deprecated This function is part of the guard utilities, and the next major version removes
63
+ * them. Write a plain typed predicate instead.
64
64
  */
65
65
  export const contextFieldMatches = (fieldPath, expectedValue) => ({ context }) => {
66
66
  const actual = getNestedValue(context, fieldPath);
67
67
  return dequal(actual, expectedValue);
68
68
  };
69
69
  /**
70
- * Get nested value from object using dot-separated path
70
+ * Returns a nested value of an object, from a path with a dot between two segments
71
71
  *
72
72
  * @internal
73
73
  */
@@ -1,15 +1,15 @@
1
1
  /**
2
- * Guard composition and helper utilities for XState machines
2
+ * The guard composition utilities and the guard helpers of an XState machine
3
3
  *
4
- * Provides array-means-AND composition and convenience helpers
5
- * for common guard patterns in Play Architecture.
4
+ * The package gives you a composition where an array means AND. It also gives you
5
+ * the helpers of the common guard patterns of the Play Architecture.
6
6
  *
7
- * @deprecated The guard helpers wrap XState's own `and` / `or` / `not`
8
- * combinators without composing with `setup()`-typed guard slots (the
9
- * package's own example needs a cast to use them). Use XState's combinators
10
- * directly; this module will be removed in the next major. Every exported
11
- * symbol carries its own deprecation tag, since consumers import them through
12
- * the package root rather than this barrel.
7
+ * @deprecated These guard helpers wrap the `and`, `or`, and `not` combinators of
8
+ * XState, but they do not compose with a guard slot that `setup()` types. The
9
+ * example of the package itself needs a cast for them. Use the combinators of XState
10
+ * directly. The next major version removes this module. Each exported symbol carries
11
+ * its own deprecation tag, because a consumer imports it through the root of the
12
+ * package, and not through this barrel.
13
13
  *
14
14
  * @packageDocumentation
15
15
  */
@@ -1,15 +1,15 @@
1
1
  /**
2
- * Guard composition and helper utilities for XState machines
2
+ * The guard composition utilities and the guard helpers of an XState machine
3
3
  *
4
- * Provides array-means-AND composition and convenience helpers
5
- * for common guard patterns in Play Architecture.
4
+ * The package gives you a composition where an array means AND. It also gives you
5
+ * the helpers of the common guard patterns of the Play Architecture.
6
6
  *
7
- * @deprecated The guard helpers wrap XState's own `and` / `or` / `not`
8
- * combinators without composing with `setup()`-typed guard slots (the
9
- * package's own example needs a cast to use them). Use XState's combinators
10
- * directly; this module will be removed in the next major. Every exported
11
- * symbol carries its own deprecation tag, since consumers import them through
12
- * the package root rather than this barrel.
7
+ * @deprecated These guard helpers wrap the `and`, `or`, and `not` combinators of
8
+ * XState, but they do not compose with a guard slot that `setup()` types. The
9
+ * example of the package itself needs a cast for them. Use the combinators of XState
10
+ * directly. The next major version removes this module. Each exported symbol carries
11
+ * its own deprecation tag, because a consumer imports it through the root of the
12
+ * package, and not through this barrel.
13
13
  *
14
14
  * @packageDocumentation
15
15
  */
@@ -1,21 +1,22 @@
1
1
  import type { PlayEvent } from "@xmachines/play";
2
2
  /**
3
- * Standard XState guard function signature guards receive `{ context, event }`.
3
+ * The standard signature of an XState guard function. A guard receives `{ context, event }`.
4
4
  *
5
- * @param args - Guard arguments with context and event
6
- * @param args.context - Current machine context
7
- * @param args.event - Event that triggered the guard evaluation
8
- * @returns boolean indicating if guard passes
9
- * @deprecated The guard utilities will be removed in the next major.
5
+ * @param args - The arguments of the guard: the context and the event
6
+ * @param args.context - The current machine context
7
+ * @param args.event - The event that started the evaluation of the guard
8
+ * @returns The boolean value. It tells you if the guard passes
9
+ * @deprecated The next major version removes the guard utilities.
10
10
  */
11
11
  export type Guard<TContext = Record<string, unknown>, TEvent = PlayEvent> = (args: {
12
12
  context: TContext;
13
13
  event: TEvent;
14
14
  }) => boolean;
15
15
  /**
16
- * Array of guard predicates or guard names an array means AND: all must pass.
16
+ * The array of the guard predicates, or of the guard names. An array means AND:
17
+ * every guard must pass.
17
18
  *
18
- * @deprecated The guard utilities will be removed in the next major.
19
+ * @deprecated The next major version removes the guard utilities.
19
20
  */
20
21
  export type GuardArray<TContext = Record<string, unknown>, TEvent = PlayEvent> = Array<Guard<TContext, TEvent> | string>;
21
22
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/guards/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD;;;;;;;;GAQG;AACH,MAAM,MAAM,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,IAAI,CAAC,IAAI,EAAE;IAClF,OAAO,EAAE,QAAQ,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACd,KAAK,OAAO,CAAC;AAEd;;;;GAIG;AACH,MAAM,MAAM,UAAU,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,IAAI,KAAK,CACrF,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,MAAM,CAChC,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/guards/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD;;;;;;;;GAQG;AACH,MAAM,MAAM,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,IAAI,CAAC,IAAI,EAAE;IAClF,OAAO,EAAE,QAAQ,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACd,KAAK,OAAO,CAAC;AAEd;;;;;GAKG;AACH,MAAM,MAAM,UAAU,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,IAAI,KAAK,CACrF,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,MAAM,CAChC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  /**
2
- * @xmachines/play-xstate - XState v5 adapter for Play Architecture
2
+ * @xmachines/play-xstate - the XState v5 adapter of the Play Architecture
3
3
  *
4
- * Provides definePlayer() API for binding XState state machines to the
5
- * actor base with signal lifecycle and DevTools integration.
4
+ * This package gives you the definePlayer() API. That function binds an XState state
5
+ * machine to the actor base, with the signal lifecycle and the DevTools
6
+ * integration.
6
7
  *
7
- * Per the Play RFC, this package implements the Logic Layer adapter that
8
- * transforms declarative machine definitions into live actors with signal-driven
8
+ * The Play RFC gives this package as the adapter of the logic layer. It converts a
9
+ * declarative machine definition into a live actor with a signal-driven
9
10
  * reactivity.
10
11
  *
11
12
  * @packageDocumentation
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mapp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dist/index.js CHANGED
@@ -1,19 +1,20 @@
1
1
  /**
2
- * @xmachines/play-xstate - XState v5 adapter for Play Architecture
2
+ * @xmachines/play-xstate - the XState v5 adapter of the Play Architecture
3
3
  *
4
- * Provides definePlayer() API for binding XState state machines to the
5
- * actor base with signal lifecycle and DevTools integration.
4
+ * This package gives you the definePlayer() API. That function binds an XState state
5
+ * machine to the actor base, with the signal lifecycle and the DevTools
6
+ * integration.
6
7
  *
7
- * Per the Play RFC, this package implements the Logic Layer adapter that
8
- * transforms declarative machine definitions into live actors with signal-driven
8
+ * The Play RFC gives this package as the adapter of the logic layer. It converts a
9
+ * declarative machine definition into a live actor with a signal-driven
9
10
  * reactivity.
10
11
  *
11
12
  * @packageDocumentation
12
13
  */
13
14
  export { definePlayer } from "./define-player.js";
14
15
  export { PlayerActor } from "./player-actor.js";
15
- // Guard utilities
16
+ // The guard utilities
16
17
  export { composeGuards, composeGuardsOr, negateGuard, hasContext, eventMatches, contextFieldMatches, } from "./guards/index.js";
17
- // Routing utilities
18
+ // The routing utilities
18
19
  export { deriveRoute, isAbsoluteRoute, buildRouteUrl, formatPlayRouteTransitions, } from "./routing/index.js";
19
20
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQhD,kBAAkB;AAClB,OAAO,EACN,aAAa,EACb,eAAe,EACf,WAAW,EACX,UAAU,EACV,YAAY,EACZ,mBAAmB,GACnB,MAAM,mBAAmB,CAAC;AAG3B,oBAAoB;AACpB,OAAO,EACN,WAAW,EACX,eAAe,EACf,aAAa,EACb,0BAA0B,GAC1B,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQhD,sBAAsB;AACtB,OAAO,EACN,aAAa,EACb,eAAe,EACf,WAAW,EACX,UAAU,EACV,YAAY,EACZ,mBAAmB,GACnB,MAAM,mBAAmB,CAAC;AAG3B,wBAAwB;AACxB,OAAO,EACN,WAAW,EACX,eAAe,EACf,aAAa,EACb,0BAA0B,GAC1B,MAAM,oBAAoB,CAAC"}