@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
package/dist/errors.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { PlayError } from "@xmachines/play";
2
2
  /**
3
- * Stringify a thrown value without trusting it: `String()` itself throws for
4
- * a null-prototype object or a value whose `toString`/`Symbol.toPrimitive`
5
- * throw, and this runs inside the error path a second throw here would
6
- * replace the machine's real failure with a `TypeError` and bypass `onError`.
3
+ * Converts a value from a throw into a string, and it trusts that value not:
4
+ * `String()` itself throws for an object with a null prototype, and also for a value
5
+ * whose `toString` or `Symbol.toPrimitive` throws. This function runs inside the
6
+ * error path. A second throw here therefore replaces the real failure of the machine
7
+ * with a `TypeError`, and it passes around `onError`.
7
8
  */
8
9
  const safeString = (value) => {
9
10
  try {
@@ -14,23 +15,23 @@ const safeString = (value) => {
14
15
  return Object.prototype.toString.call(value);
15
16
  }
16
17
  catch {
17
- // A revoked Proxy throws even on brand inspection.
18
+ // A revoked Proxy throws also on an inspection of the brand.
18
19
  return "[unrepresentable value]";
19
20
  }
20
21
  }
21
22
  };
22
23
  /**
23
- * Thrown by `buildRouteUrl()` when a required route parameter is absent from the
24
- * actor's context.
24
+ * `buildRouteUrl()` throws this error when the context of the actor does not hold a
25
+ * necessary route parameter.
25
26
  *
26
- * Use the `param` and `template` fields to identify the missing parameter without
27
- * parsing the `.message` string.
27
+ * Read the `param` field and the `template` field to identify the parameter that is
28
+ * absent. Your code therefore parses no `.message` string.
28
29
  *
29
30
  * **Error code:** `PLAY_XSTATE_ROUTE_PARAM_MISSING`
30
31
  *
31
- * Note: `actor.currentRoute.get()` never surfaces this error route
32
- * derivation catches it and returns `null` for the transient mid-transition
33
- * case. It only escapes direct `buildRouteUrl()` calls.
32
+ * Note: `actor.currentRoute.get()` shows this error never. The route derivation
33
+ * catches it, and it returns `null` for the temporary case during a transition. The
34
+ * error leaves a direct `buildRouteUrl()` call only.
34
35
  *
35
36
  * @example
36
37
  * ```typescript
@@ -49,9 +50,9 @@ const safeString = (value) => {
49
50
  * ```
50
51
  */
51
52
  export class MissingRouteParamError extends PlayError {
52
- /** The name of the route parameter that was missing (e.g. `"userId"`). */
53
+ /** The name of the route parameter that was absent, for example `"userId"`. */
53
54
  param;
54
- /** The route template that required the missing parameter (e.g. `"/profile/:userId"`). */
55
+ /** The route template that needs the absent parameter, for example `"/profile/:userId"`. */
55
56
  template;
56
57
  constructor(param, template) {
57
58
  super("buildRouteUrl", "PLAY_XSTATE_ROUTE_PARAM_MISSING", `Route parameter '${param}' is required by template '${template}' but was not found in context.`);
@@ -61,16 +62,16 @@ export class MissingRouteParamError extends PlayError {
61
62
  }
62
63
  }
63
64
  /**
64
- * @deprecated Never thrown any more. `buildRouteUrl` treats a missing `query`
65
- * field as `query: {}` the generated `play.route` transitions assign
66
- * `query` on every navigation, so the loss this error guarded against cannot
67
- * occur through route derivation. Machines that handle `play.route` by hand
68
- * and want query forwarding must assign `event.query` to context themselves.
69
- * Kept exported so existing `instanceof` handlers keep compiling; remove them
70
- * at leisure.
65
+ * @deprecated Nothing throws this error now. `buildRouteUrl` reads an absent `query`
66
+ * field as `query: {}`. The generated `play.route` transitions assign `query` on
67
+ * every navigation, and the loss that this error guarded against therefore cannot
68
+ * happen through the route derivation. A machine that handles `play.route` itself
69
+ * and wants the query must assign `event.query` to its context itself. This class
70
+ * stays in the exports, so that an `instanceof` handler that exists now still
71
+ * compiles. Remove such a handler when you have the time.
71
72
  *
72
- * Formerly thrown by `buildRouteUrl()` when the context had a `params` field
73
- * (a routing-aware machine context) but no `query` field.
73
+ * `buildRouteUrl()` threw this error before, when the context had a `params` field,
74
+ * which means a context that knows the routing, but no `query` field.
74
75
  *
75
76
  * **Error code:** `PLAY_XSTATE_MISSING_QUERY_CONTEXT`
76
77
  */
@@ -83,23 +84,24 @@ export class MissingQueryContextError extends PlayError {
83
84
  }
84
85
  }
85
86
  /**
86
- * Thrown by `formatPlayRouteTransitions()` when a state node declares `meta.route`
87
- * but omits an explicit `id`.
87
+ * `formatPlayRouteTransitions()` throws this error when a state node declares a
88
+ * `meta.route` field but no explicit `id` field.
88
89
  *
89
- * Without `id`, the function cannot generate a `play.route` guard that targets the
90
- * state the guard compares `event.to` against `#<id>`, so a missing `id` means
91
- * the state is silently unreachable via routing. This error surfaces the
92
- * misconfiguration at machine-definition time rather than silently skipping the state.
90
+ * Without an `id`, the function can generate no `play.route` guard that targets the
91
+ * state: the guard compares `event.to` with `#<id>`. An absent `id` therefore makes
92
+ * the state unreachable through the routing, and nothing says so. This error shows
93
+ * the fault of the configuration at the moment of the machine definition, and the
94
+ * function skips no state in silence.
93
95
  *
94
96
  * **Error code:** `PLAY_XSTATE_MISSING_STATE_ID`
95
97
  *
96
98
  * @example
97
99
  * ```typescript
98
- * // Bad — meta.route without id:
100
+ * // Bad — a meta.route field without an id field:
99
101
  * states: {
100
102
  * profile: {
101
103
  * meta: { route: "/profile/:username" },
102
- * // ← missing id: "profile"
104
+ * // ← the id: "profile" field is absent
103
105
  * }
104
106
  * }
105
107
  *
@@ -113,9 +115,9 @@ export class MissingQueryContextError extends PlayError {
113
115
  * ```
114
116
  */
115
117
  export class MissingStateIdError extends PlayError {
116
- /** The state key (position in the states tree) that is missing an explicit `id`. */
118
+ /** The state key, which is the position in the tree of the states, without an explicit `id` field. */
117
119
  stateKey;
118
- /** The route template declared on the state (e.g. `"/profile/:username"`). */
120
+ /** The route template of the state, for example `"/profile/:username"`. */
119
121
  route;
120
122
  constructor(stateKey, route) {
121
123
  super("formatPlayRouteTransitions", "PLAY_XSTATE_MISSING_STATE_ID", `State "${stateKey}" declares meta.route "${route}" but has no explicit id. ` +
@@ -126,8 +128,9 @@ export class MissingStateIdError extends PlayError {
126
128
  }
127
129
  }
128
130
  /**
129
- * Thrown by the `PlayerActor` constructor when the `machine` argument is not a
130
- * valid XState machine object (null, undefined, or a non-object).
131
+ * The `PlayerActor` constructor throws this error when the `machine` argument is not
132
+ * a valid XState machine object, which means that it is null, undefined, or not an
133
+ * object.
131
134
  *
132
135
  * **Error code:** `PLAY_XSTATE_INVALID_MACHINE`
133
136
  */
@@ -138,13 +141,13 @@ export class InvalidMachineError extends PlayError {
138
141
  }
139
142
  }
140
143
  /**
141
- * Thrown by `normalizeRoute()` when a state's `meta.route` value is neither a
142
- * string nor an object with a `path` property.
144
+ * `normalizeRoute()` throws this error when the `meta.route` value of a state is not
145
+ * a string and not an object with a `path` property.
143
146
  *
144
147
  * **Error code:** `PLAY_XSTATE_INVALID_ROUTE_METADATA`
145
148
  */
146
149
  export class InvalidRouteMetadataError extends PlayError {
147
- /** The serialised form of the invalid route value for debugging. */
150
+ /** The invalid route value, as a string, for the debug work. */
148
151
  detail;
149
152
  constructor(route, source = "deriveRoute") {
150
153
  const detail = JSON.stringify(route);
@@ -154,13 +157,13 @@ export class InvalidRouteMetadataError extends PlayError {
154
157
  }
155
158
  }
156
159
  /**
157
- * Thrown by `composeGuards()` or `composeGuardsOr()` when called with an empty
158
- * guards array. A composition of zero guards has no meaningful semantics.
160
+ * `composeGuards()` and `composeGuardsOr()` throw this error for an empty array of
161
+ * guards. A composition of zero guards has no meaning.
159
162
  *
160
163
  * **Error code:** `PLAY_XSTATE_EMPTY_GUARD_ARRAY`
161
164
  */
162
165
  export class EmptyGuardArrayError extends PlayError {
163
- /** The combinator that was called with an empty array (`"and"` or `"or"`). */
166
+ /** The combinator of the call with the empty array: `"and"` or `"or"`. */
164
167
  combinator;
165
168
  constructor(combinator) {
166
169
  super(combinator === "and" ? "composeGuards" : "composeGuardsOr", "PLAY_XSTATE_EMPTY_GUARD_ARRAY", `${combinator === "and" ? "composeGuards" : "composeGuardsOr"} requires at least one guard`);
@@ -169,13 +172,16 @@ export class EmptyGuardArrayError extends PlayError {
169
172
  }
170
173
  }
171
174
  /**
172
- * Thrown by `PlayerActor.send()` when the event argument is not a plain object.
175
+ * `PlayerActor.send()` throws this error when the event argument is not a plain
176
+ * object.
173
177
  *
174
- * `PlayEvent` requires `{ type: string, ...fields }`. Passing `null`, `undefined`,
175
- * a string, or any other non-object value is a programmer error.
178
+ * A `PlayEvent` needs the shape `{ type: string, ...fields }`. A `null` value, an
179
+ * `undefined` value, a string, and every other value that is not an object are an
180
+ * error of the programmer.
176
181
  *
177
- * The offending value is attached as the `detail` readonly class field for debugging.
178
- * TypeScript consumers can access `err.detail` directly without any unsafe cast.
182
+ * The error holds the value in question in its readonly class field `detail`, for
183
+ * the debug work. A TypeScript consumer reads `err.detail` directly, with no unsafe
184
+ * cast.
179
185
  *
180
186
  * **Error code:** `PLAY_XSTATE_INVALID_EVENT`
181
187
  *
@@ -187,14 +193,14 @@ export class EmptyGuardArrayError extends PlayError {
187
193
  * actor.send(null as any);
188
194
  * } catch (err) {
189
195
  * if (err instanceof InvalidEventError) {
190
- * // err.detail is typed as `unknown` no cast needed
196
+ * // err.detail has the type `unknown`, and it needs no cast
191
197
  * console.error("Invalid event passed to actor.send():", err.detail);
192
198
  * }
193
199
  * }
194
200
  * ```
195
201
  */
196
202
  export class InvalidEventError extends PlayError {
197
- /** The offending value passed to `send()`. */
203
+ /** The value in question, from the `send()` call. */
198
204
  detail;
199
205
  constructor(detail) {
200
206
  super("PlayerActor", "PLAY_XSTATE_INVALID_EVENT", "PlayerActor.send() received a non-object event.");
@@ -203,13 +209,15 @@ export class InvalidEventError extends PlayError {
203
209
  }
204
210
  }
205
211
  /**
206
- * Passed to `PlayerOptions.onError` when the actor failed with a value that is
207
- * not an `Error` e.g. a machine action ran `throw { code: 42 }`.
212
+ * The actor gives this error to `PlayerOptions.onError` when it failed with a value
213
+ * that is not an `Error`, for example after a machine action ran
214
+ * `throw { code: 42 }`.
208
215
  *
209
- * An actor error that *is* an `Error` reaches `onError` untouched, keeping the
210
- * identity the machine gave it. Only this case constructs a new error, so it
211
- * carries a matchable code instead of a `String(value)` message such as
212
- * `"[object Object]"`. The thrown value is preserved on `cause`.
216
+ * An actor error that *is* an `Error` reaches `onError` without a change, and it
217
+ * keeps the identity of the machine. This case alone builds a new error. The new
218
+ * error therefore carries a code that your code can match, and not a
219
+ * `String(value)` message such as `"[object Object]"`. The `cause` field holds the
220
+ * value from the throw.
213
221
  *
214
222
  * **Error code:** `PLAY_XSTATE_NON_ERROR_THROWN`
215
223
  *
@@ -222,7 +230,7 @@ export class InvalidEventError extends PlayError {
222
230
  * options: {
223
231
  * onError: (actor, err) => {
224
232
  * if (err instanceof ActorThrewNonErrorError) {
225
- * // err.cause is the value the machine actually threw
233
+ * // err.cause is the value that the machine threw
226
234
  * console.error("Machine threw a non-Error:", err.cause);
227
235
  * }
228
236
  * },
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,UAAU,GAAG,CAAC,KAAc,EAAU,EAAE;IAC7C,IAAI,CAAC;QACJ,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;IAAC,MAAM,CAAC;QACR,IAAI,CAAC;YACJ,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9C,CAAC;QAAC,MAAM,CAAC;YACR,mDAAmD;YACnD,OAAO,yBAA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AAQ,SAAS;IAClD,0EAA0E;IACjE,UAAU,CAAe;IAElC,YAAY,UAAwB;QACnC,KAAK,CACJ,UAAU,KAAK,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,iBAAiB,EAC1D,+BAA+B,EAC/B,GAAG,UAAU,KAAK,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,iBAAiB,8BAA8B,CAC3F,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC9B,CAAC;CACD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IAC/C,qDAAqD;IAC5C,MAAM,CAAU;IAEzB,YAAY,MAAe;QAC1B,KAAK,CACJ,aAAa,EACb,2BAA2B,EAC3B,iDAAiD,CACjD,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;CACD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,OAAO,uBAAwB,SAAQ,SAAS;IACrD,YAAY,KAAc;QACzB,KAAK,CACJ,aAAa,EACb,8BAA8B,EAC9B,8CAA8C,UAAU,CAAC,KAAK,CAAC,GAAG,EAClE,EAAE,KAAK,EAAE,KAAK,EAAE,CAChB,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACvC,CAAC;CACD"}
@@ -2,37 +2,39 @@ import type { GuardPredicate } from "xstate";
2
2
  import type { Guard, GuardArray } from "./types.js";
3
3
  import type { MachineContext, EventObject, ParameterizedObject } from "xstate";
4
4
  /**
5
- * Narrowest public return type for guard composition helpers.
5
+ * The narrowest public return type of the guard composition helpers.
6
6
  *
7
7
  * `GuardPredicate<MachineContext, EventObject, unknown, ParameterizedObject>` is the
8
- * widest-compatible concrete XState guard type that does not use `any`.
8
+ * concrete XState guard type with the widest compatibility that uses no `any`.
9
9
  *
10
10
  * @public
11
- * @deprecated The guard utilities will be removed in the next major use
12
- * XState's own combinator types directly.
11
+ * @deprecated The next major version removes the guard utilities. Use the
12
+ * combinator types of XState directly.
13
13
  */
14
14
  export type ComposedGuard = GuardPredicate<MachineContext, EventObject, unknown, ParameterizedObject>;
15
15
  /**
16
- * Compose guards with AND logic using XState's and() helper
16
+ * Composes the guards with the AND logic, through the and() helper of XState
17
17
  *
18
- * Combines multiple guard predicates using AND semantics—all guards must pass for
19
- * the composition to succeed. Uses XState's built-in `and()` helper to ensure proper
20
- * type inference and machine serialization.
18
+ * The function joins more than one guard predicate with the AND semantics: every
19
+ * guard must pass, and the composition then succeeds. It uses the built-in `and()`
20
+ * helper of XState. The type inference and the serialization of the machine are
21
+ * therefore correct.
21
22
  *
22
- * **Architectural Context:** Supports **Actor Authority (INV-01)** by enabling
23
- * declarative guard composition in state machine transitions. Guards enforce business
24
- * logic rules that determine whether navigation or actions are valid.
23
+ * **Architectural context:** the function supports **Actor Authority (INV-01)**,
24
+ * because it composes the guards of a state machine transition declaratively. A
25
+ * guard enforces a rule of the business logic, and that rule decides if a
26
+ * navigation or an action is valid.
25
27
  *
26
- * @typeParam TContext - State machine context type
27
- * @typeParam TEvent - Event type
28
+ * @typeParam TContext - The context type of the state machine
29
+ * @typeParam TEvent - The event type
28
30
  *
29
- * @param guards - Array of guard predicates or guard names (string references)
30
- * @returns XState and() guard composition
31
+ * @param guards - The array of the guard predicates, or of the guard names as strings
32
+ * @returns The and() guard composition of XState
31
33
  *
32
- * @throws {Error} If guards array is empty
34
+ * @throws {Error} When the array of the guards is empty
33
35
  *
34
36
  * @example
35
- * AND composition with named guards
37
+ * An AND composition with named guards
36
38
  * ```typescript
37
39
  * import { setup } from "xstate";
38
40
  * import { composeGuards } from "@xmachines/play-xstate";
@@ -54,7 +56,7 @@ export type ComposedGuard = GuardPredicate<MachineContext, EventObject, unknown,
54
56
  * ```
55
57
  *
56
58
  * @example
57
- * AND composition with inline predicates
59
+ * An AND composition with inline predicates
58
60
  * ```typescript
59
61
  * import { composeGuards } from "@xmachines/play-xstate";
60
62
  *
@@ -64,29 +66,29 @@ export type ComposedGuard = GuardPredicate<MachineContext, EventObject, unknown,
64
66
  * ])
65
67
  * ```
66
68
  *
67
- * @see {@link composeGuardsOr} for OR composition
68
- * @see {@link negateGuard} for NOT logic
69
- * @deprecated Use XState's own `and()`/`or()`/`not()` directly this helper does not
70
- * compose with `setup()`-typed guard slots and will be removed in the next major.
69
+ * @see {@link composeGuardsOr} for the OR composition
70
+ * @see {@link negateGuard} for the NOT logic
71
+ * @deprecated Use the `and()`, `or()`, and `not()` combinators of XState directly. This helper
72
+ * does not compose with a guard slot that `setup()` types, and the next major version removes it.
71
73
  */
72
74
  export declare const composeGuards: <TContext = any, TEvent = any>(guards: GuardArray<TContext, TEvent>) => ComposedGuard;
73
75
  /**
74
- * Compose guards with OR logic using XState's or() helper
76
+ * Composes the guards with the OR logic, through the or() helper of XState
75
77
  *
76
- * Combines multiple guard predicates using OR semantics—at least one guard must pass
77
- * for the composition to succeed. Uses XState's built-in `or()` helper for proper
78
- * type inference.
78
+ * The function joins more than one guard predicate with the OR semantics: one guard
79
+ * must pass at least, and the composition then succeeds. It uses the built-in `or()`
80
+ * helper of XState, and the type inference is therefore correct.
79
81
  *
80
- * @typeParam TContext - State machine context type
81
- * @typeParam TEvent - Event type
82
+ * @typeParam TContext - The context type of the state machine
83
+ * @typeParam TEvent - The event type
82
84
  *
83
- * @param guards - Array of guard predicates or guard names
84
- * @returns XState or() guard composition
85
+ * @param guards - The array of the guard predicates, or of the guard names
86
+ * @returns The or() guard composition of XState
85
87
  *
86
- * @throws {Error} If guards array is empty
88
+ * @throws {Error} When the array of the guards is empty
87
89
  *
88
90
  * @example
89
- * OR composition with named guards
91
+ * An OR composition with named guards
90
92
  * ```typescript
91
93
  * import { setup } from "xstate";
92
94
  * import { composeGuardsOr } from "@xmachines/play-xstate";
@@ -99,7 +101,7 @@ export declare const composeGuards: <TContext = any, TEvent = any>(guards: Guard
99
101
  * }).createMachine({
100
102
  * on: {
101
103
  * deleteResource: {
102
- * // Either guard can pass
104
+ * // One guard is sufficient
103
105
  * guard: composeGuardsOr(['isOwner', 'isAdmin']),
104
106
  * actions: 'delete'
105
107
  * }
@@ -107,26 +109,27 @@ export declare const composeGuards: <TContext = any, TEvent = any>(guards: Guard
107
109
  * });
108
110
  * ```
109
111
  *
110
- * @see {@link composeGuards} for AND composition
111
- * @see {@link negateGuard} for NOT logic
112
- * @deprecated Use XState's own `and()`/`or()`/`not()` directly this helper does not
113
- * compose with `setup()`-typed guard slots and will be removed in the next major.
112
+ * @see {@link composeGuards} for the AND composition
113
+ * @see {@link negateGuard} for the NOT logic
114
+ * @deprecated Use the `and()`, `or()`, and `not()` combinators of XState directly. This helper
115
+ * does not compose with a guard slot that `setup()` types, and the next major version removes it.
114
116
  */
115
117
  export declare const composeGuardsOr: <TContext = any, TEvent = any>(guards: GuardArray<TContext, TEvent>) => ComposedGuard;
116
118
  /**
117
- * Negate a guard using XState's not() helper
119
+ * Negates a guard, through the not() helper of XState
118
120
  *
119
- * Inverts a guard's result—if the guard passes, NOT fails; if guard fails, NOT passes.
120
- * Uses XState's built-in `not()` helper for proper serialization.
121
+ * The function inverts the result of a guard: the guard passes, and NOT then fails;
122
+ * the guard fails, and NOT then passes. It uses the built-in `not()` helper of
123
+ * XState, and the serialization is therefore correct.
121
124
  *
122
- * @typeParam TContext - State machine context type
123
- * @typeParam TEvent - Event type
125
+ * @typeParam TContext - The context type of the state machine
126
+ * @typeParam TEvent - The event type
124
127
  *
125
- * @param guard - Guard predicate or guard name to negate
126
- * @returns XState not() guard negation
128
+ * @param guard - The guard predicate to negate, or its name
129
+ * @returns The not() guard negation of XState
127
130
  *
128
131
  * @example
129
- * NOT composition with named guard
132
+ * A NOT composition with a named guard
130
133
  * ```typescript
131
134
  * import { setup } from "xstate";
132
135
  * import { negateGuard } from "@xmachines/play-xstate";
@@ -138,7 +141,7 @@ export declare const composeGuardsOr: <TContext = any, TEvent = any>(guards: Gua
138
141
  * }).createMachine({
139
142
  * on: {
140
143
  * accessDashboard: {
141
- * // Allow if NOT a guest (i.e., authenticated)
144
+ * // Permit the transition when the user is NOT a guest, which means an authenticated user
142
145
  * guard: negateGuard('isGuest'),
143
146
  * target: 'dashboard'
144
147
  * }
@@ -146,10 +149,10 @@ export declare const composeGuardsOr: <TContext = any, TEvent = any>(guards: Gua
146
149
  * });
147
150
  * ```
148
151
  *
149
- * @see {@link composeGuards} for AND composition
150
- * @see {@link composeGuardsOr} for OR composition
151
- * @deprecated Use XState's own `and()`/`or()`/`not()` directly this helper does not
152
- * compose with `setup()`-typed guard slots and will be removed in the next major.
152
+ * @see {@link composeGuards} for the AND composition
153
+ * @see {@link composeGuardsOr} for the OR composition
154
+ * @deprecated Use the `and()`, `or()`, and `not()` combinators of XState directly. This helper
155
+ * does not compose with a guard slot that `setup()` types, and the next major version removes it.
153
156
  */
154
157
  export declare const negateGuard: <TContext = any, TEvent = any>(guard: Guard<TContext, TEvent> | string) => ComposedGuard;
155
158
  //# sourceMappingURL=compose.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/guards/compose.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAkB/E;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG,cAAc,CACzC,cAAc,EACd,WAAW,EACX,OAAO,EACP,mBAAmB,CACnB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AA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