@xmachines/play-xstate 1.0.0 → 1.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.
- package/README.md +32 -14
- package/dist/errors.d.ts +46 -32
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +69 -32
- package/dist/errors.js.map +1 -1
- package/dist/guards/compose.d.ts +8 -0
- package/dist/guards/compose.d.ts.map +1 -1
- package/dist/guards/compose.js +7 -2
- package/dist/guards/compose.js.map +1 -1
- package/dist/guards/helpers.d.ts +6 -2
- package/dist/guards/helpers.d.ts.map +1 -1
- package/dist/guards/helpers.js +6 -2
- package/dist/guards/helpers.js.map +1 -1
- package/dist/guards/index.d.ts +7 -0
- package/dist/guards/index.d.ts.map +1 -1
- package/dist/guards/index.js +7 -0
- package/dist/guards/index.js.map +1 -1
- package/dist/guards/types.d.ts +4 -5
- package/dist/guards/types.d.ts.map +1 -1
- package/dist/player-actor.d.ts +105 -39
- package/dist/player-actor.d.ts.map +1 -1
- package/dist/player-actor.js +312 -318
- package/dist/player-actor.js.map +1 -1
- package/dist/routing/build-url.d.ts +2 -7
- package/dist/routing/build-url.d.ts.map +1 -1
- package/dist/routing/build-url.js +21 -25
- package/dist/routing/build-url.js.map +1 -1
- package/dist/routing/derive-current-route.d.ts +32 -0
- package/dist/routing/derive-current-route.d.ts.map +1 -1
- package/dist/routing/derive-current-route.js +20 -19
- package/dist/routing/derive-current-route.js.map +1 -1
- package/dist/routing/derive-initial-route.d.ts +0 -3
- package/dist/routing/derive-initial-route.d.ts.map +1 -1
- package/dist/routing/derive-initial-route.js +0 -3
- package/dist/routing/derive-initial-route.js.map +1 -1
- package/dist/routing/index.d.ts +1 -1
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/index.js +1 -1
- package/dist/routing/index.js.map +1 -1
- package/dist/types.d.ts +86 -13
- package/dist/types.d.ts.map +1 -1
- package/dist/view/derive-current-view.d.ts +54 -0
- package/dist/view/derive-current-view.d.ts.map +1 -0
- package/dist/view/derive-current-view.js +167 -0
- package/dist/view/derive-current-view.js.map +1 -0
- package/package.json +11 -14
- package/dist/define-player.typecheck.d.ts +0 -2
- package/dist/define-player.typecheck.d.ts.map +0 -1
- package/dist/define-player.typecheck.js +0 -48
- package/dist/define-player.typecheck.js.map +0 -1
- package/dist/player-actor.typecheck.d.ts +0 -2
- package/dist/player-actor.typecheck.d.ts.map +0 -1
- package/dist/player-actor.typecheck.js +0 -27
- package/dist/player-actor.typecheck.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
<!-- generated-by: gsd-doc-writer -->
|
|
2
|
-
|
|
3
1
|
# @xmachines/play-xstate
|
|
4
2
|
|
|
5
3
|
> XState v5 adapter for the XMachines Play Architecture — bind state machines to the actor base with signal-driven reactivity and router integration.
|
|
6
4
|
|
|
7
5
|
[](https://opensource.org/licenses/MIT)
|
|
8
|
-
[](https://www.npmjs.com/package/@xmachines/play-xstate)
|
|
9
7
|
|
|
10
8
|
Part of the [XMachines Play](../../README.md) monorepo.
|
|
11
9
|
|
|
@@ -84,6 +82,7 @@ const createPlayer = definePlayer({
|
|
|
84
82
|
onTransition: (actor, prev, next) => console.log("transitioned"),
|
|
85
83
|
onStateChange: (actor, state) => console.log("state changed"),
|
|
86
84
|
onError: (actor, err) => console.error(err),
|
|
85
|
+
inspect: (event) => console.log(event.type), // handed to XState's actor constructor — enables @statelyai/inspect
|
|
87
86
|
},
|
|
88
87
|
});
|
|
89
88
|
|
|
@@ -94,17 +93,27 @@ const bob = createPlayer({ userId: "bob" });
|
|
|
94
93
|
|
|
95
94
|
#### `PlayerFactory` signature
|
|
96
95
|
|
|
96
|
+
`input` requiredness mirrors XState's `createActor`: a machine whose input type
|
|
97
|
+
cannot be `undefined` makes the factory's first argument required, so forgetting
|
|
98
|
+
it is a compile error instead of an actor stuck in an error status.
|
|
99
|
+
|
|
97
100
|
```typescript
|
|
98
|
-
type PlayerFactory<TMachine> =
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
type PlayerFactory<TMachine> =
|
|
102
|
+
undefined extends InputFrom<TMachine>
|
|
103
|
+
? (
|
|
104
|
+
input?: InputFrom<TMachine>,
|
|
105
|
+
options?: PlayerFactoryResumeOptions<TMachine>,
|
|
106
|
+
) => PlayerActor<TMachine>
|
|
107
|
+
: (
|
|
108
|
+
input: InputFrom<TMachine>,
|
|
109
|
+
options?: PlayerFactoryResumeOptions<TMachine>,
|
|
110
|
+
) => PlayerActor<TMachine>;
|
|
102
111
|
```
|
|
103
112
|
|
|
104
113
|
#### Restoring from a snapshot
|
|
105
114
|
|
|
106
115
|
```typescript
|
|
107
|
-
const snapshot = actor.
|
|
116
|
+
const snapshot = actor.getPersistedSnapshot();
|
|
108
117
|
actor.stop();
|
|
109
118
|
|
|
110
119
|
// Restore to the exact saved state
|
|
@@ -113,11 +122,15 @@ restored.start();
|
|
|
113
122
|
console.log(restored.currentRoute.get()); // same route as when saved
|
|
114
123
|
```
|
|
115
124
|
|
|
125
|
+
> **Note:** Persist with `getPersistedSnapshot()`, not `getSnapshot()` — it is
|
|
126
|
+
> the form `createActor` accepts, and the only one that round-trips machines
|
|
127
|
+
> with invoked or spawned children.
|
|
128
|
+
|
|
116
129
|
---
|
|
117
130
|
|
|
118
131
|
### `PlayerActor<TMachine>`
|
|
119
132
|
|
|
120
|
-
Concrete actor class
|
|
133
|
+
Concrete actor class: an XState v5 actor that also exposes TC39 Signal-based reactive signals. Implements both `Routable` and `Viewable` interfaces from `@xmachines/play-actor`.
|
|
121
134
|
|
|
122
135
|
#### Signals
|
|
123
136
|
|
|
@@ -158,6 +171,10 @@ actor.start();
|
|
|
158
171
|
|
|
159
172
|
### Guard utilities
|
|
160
173
|
|
|
174
|
+
> **Deprecated:** the guard helpers wrap XState's own `and()` / `or()` / `not()`
|
|
175
|
+
> combinators without composing with `setup()`-typed guard slots. Use XState's
|
|
176
|
+
> combinators directly; this module will be removed in the next major.
|
|
177
|
+
|
|
161
178
|
Composable guard helpers that wrap XState's built-in `and()`, `or()`, and `not()` for use in machine `setup({ guards })` definitions.
|
|
162
179
|
|
|
163
180
|
```typescript
|
|
@@ -241,12 +258,12 @@ const machine = setup({}).createMachine(config);
|
|
|
241
258
|
```typescript
|
|
242
259
|
import type {
|
|
243
260
|
PlayerConfig, // definePlayer() config argument shape
|
|
244
|
-
PlayerOptions, // Lifecycle hooks (onStart, onStop, onTransition, onStateChange, onError)
|
|
261
|
+
PlayerOptions, // Lifecycle hooks (onStart, onStop, onTransition, onStateChange, onError) + inspect
|
|
245
262
|
PlayerFactory, // Factory function returned by definePlayer()
|
|
246
263
|
PlayerFactoryResumeOptions, // { snapshot? } for restoring actor state
|
|
247
|
-
Guard, //
|
|
248
|
-
GuardArray, //
|
|
249
|
-
ComposedGuard, //
|
|
264
|
+
Guard, // deprecated with the guard utilities — removed in the next major
|
|
265
|
+
GuardArray, // deprecated with the guard utilities — removed in the next major
|
|
266
|
+
ComposedGuard, // deprecated with the guard utilities — removed in the next major
|
|
250
267
|
RouteMachineConfig, // Minimal machine config accepted by formatPlayRouteTransitions
|
|
251
268
|
RouteStateNode, // Single state node shape used during route crawling
|
|
252
269
|
RouteContext, // Context shape expected by buildRouteUrl ({ params?, query?, basePath?, hash? })
|
|
@@ -264,10 +281,11 @@ Error classes are exported from the `@xmachines/play-xstate/errors` sub-path to
|
|
|
264
281
|
```typescript
|
|
265
282
|
import {
|
|
266
283
|
MissingRouteParamError, // Required :param absent from context when resolving currentRoute
|
|
267
|
-
MissingQueryContextError, //
|
|
284
|
+
MissingQueryContextError, // deprecated: no longer thrown
|
|
268
285
|
MissingStateIdError, // meta.route declared without a state id field
|
|
269
286
|
InvalidMachineError, // PlayerActor constructed with a non-object machine
|
|
270
287
|
InvalidEventError, // actor.send() called with null/undefined/non-object
|
|
288
|
+
ActorThrewNonErrorError, // actor failed with a thrown value that is not an Error
|
|
271
289
|
InvalidRouteMetadataError, // meta.route is neither a string nor { path: string }
|
|
272
290
|
EmptyGuardArrayError, // composeGuards/composeGuardsOr called with empty array
|
|
273
291
|
} from "@xmachines/play-xstate/errors";
|
package/dist/errors.d.ts
CHANGED
|
@@ -8,16 +8,17 @@ import { PlayError } from "@xmachines/play";
|
|
|
8
8
|
*
|
|
9
9
|
* **Error code:** `PLAY_XSTATE_ROUTE_PARAM_MISSING`
|
|
10
10
|
*
|
|
11
|
+
* Note: `actor.currentRoute.get()` never surfaces this error — route
|
|
12
|
+
* derivation catches it and returns `null` for the transient mid-transition
|
|
13
|
+
* case. It only escapes direct `buildRouteUrl()` calls.
|
|
14
|
+
*
|
|
11
15
|
* @example
|
|
12
16
|
* ```typescript
|
|
17
|
+
* import { buildRouteUrl } from "@xmachines/play-xstate";
|
|
13
18
|
* import { MissingRouteParamError } from "@xmachines/play-xstate/errors";
|
|
14
19
|
*
|
|
15
|
-
* // The route template "/profile/:userId" requires "userId" in context.
|
|
16
|
-
* // If userId is absent, MissingRouteParamError is thrown when the
|
|
17
|
-
* // actor.currentRoute signal is read.
|
|
18
|
-
*
|
|
19
20
|
* try {
|
|
20
|
-
*
|
|
21
|
+
* buildRouteUrl("/profile/:userId", { params: {}, query: {} });
|
|
21
22
|
* } catch (err) {
|
|
22
23
|
* if (err instanceof MissingRouteParamError) {
|
|
23
24
|
* console.error(
|
|
@@ -35,36 +36,18 @@ export declare class MissingRouteParamError extends PlayError {
|
|
|
35
36
|
constructor(param: string, template: string);
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
39
|
+
* @deprecated Never thrown any more. `buildRouteUrl` treats a missing `query`
|
|
40
|
+
* field as `query: {}` — the generated `play.route` transitions assign
|
|
41
|
+
* `query` on every navigation, so the loss this error guarded against cannot
|
|
42
|
+
* occur through route derivation. Machines that handle `play.route` by hand
|
|
43
|
+
* and want query forwarding must assign `event.query` to context themselves.
|
|
44
|
+
* Kept exported so existing `instanceof` handlers keep compiling; remove them
|
|
45
|
+
* at leisure.
|
|
44
46
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* If using `formatPlayRouteTransitions`, the field is assigned automatically on each
|
|
48
|
-
* `play.route` event — but the machine's initial context must still declare it.
|
|
47
|
+
* Formerly thrown by `buildRouteUrl()` when the context had a `params` field
|
|
48
|
+
* (a routing-aware machine context) but no `query` field.
|
|
49
49
|
*
|
|
50
50
|
* **Error code:** `PLAY_XSTATE_MISSING_QUERY_CONTEXT`
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```typescript
|
|
54
|
-
* import { MissingQueryContextError } from "@xmachines/play-xstate/errors";
|
|
55
|
-
*
|
|
56
|
-
* try {
|
|
57
|
-
* // params present but no query field — throws
|
|
58
|
-
* buildRouteUrl("/profile/:userId", { params: { userId: "42" } });
|
|
59
|
-
* } catch (err) {
|
|
60
|
-
* if (err instanceof MissingQueryContextError) {
|
|
61
|
-
* console.error("Machine context missing query field");
|
|
62
|
-
* }
|
|
63
|
-
* }
|
|
64
|
-
*
|
|
65
|
-
* // Correct — both params and query declared
|
|
66
|
-
* buildRouteUrl("/profile/:userId", { params: { userId: "42" }, query: {} });
|
|
67
|
-
* ```
|
|
68
51
|
*/
|
|
69
52
|
export declare class MissingQueryContextError extends PlayError {
|
|
70
53
|
constructor();
|
|
@@ -167,4 +150,35 @@ export declare class InvalidEventError extends PlayError {
|
|
|
167
150
|
readonly detail: unknown;
|
|
168
151
|
constructor(detail: unknown);
|
|
169
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Passed to `PlayerOptions.onError` when the actor failed with a value that is
|
|
155
|
+
* not an `Error` — e.g. a machine action ran `throw { code: 42 }`.
|
|
156
|
+
*
|
|
157
|
+
* An actor error that *is* an `Error` reaches `onError` untouched, keeping the
|
|
158
|
+
* identity the machine gave it. Only this case constructs a new error, so it
|
|
159
|
+
* carries a matchable code instead of a `String(value)` message such as
|
|
160
|
+
* `"[object Object]"`. The thrown value is preserved on `cause`.
|
|
161
|
+
*
|
|
162
|
+
* **Error code:** `PLAY_XSTATE_NON_ERROR_THROWN`
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* import { ActorThrewNonErrorError } from "@xmachines/play-xstate/errors";
|
|
167
|
+
*
|
|
168
|
+
* definePlayer({
|
|
169
|
+
* machine,
|
|
170
|
+
* options: {
|
|
171
|
+
* onError: (actor, err) => {
|
|
172
|
+
* if (err instanceof ActorThrewNonErrorError) {
|
|
173
|
+
* // err.cause is the value the machine actually threw
|
|
174
|
+
* console.error("Machine threw a non-Error:", err.cause);
|
|
175
|
+
* }
|
|
176
|
+
* },
|
|
177
|
+
* },
|
|
178
|
+
* });
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
export declare class ActorThrewNonErrorError extends PlayError {
|
|
182
|
+
constructor(value: unknown);
|
|
183
|
+
}
|
|
170
184
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAqB5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,sBAAuB,SAAQ,SAAS;IACpD,0EAA0E;IAC1E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,0FAA0F;IAC1F,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAU3C;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,wBAAyB,SAAQ,SAAS;;CAWtD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;IACjD,oFAAoF;IACpF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,8EAA8E;IAC9E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;gBAEX,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;CAW3C;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;;CASjD;AAED;;;;;GAKG;AACH,qBAAa,yBAA0B,SAAQ,SAAS;IACvD,oEAAoE;IACpE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,KAAK,EAAE,OAAO,EAAE,MAAM,SAAgB;CAUlD;AAED;;;;;GAKG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;IAClD,8EAA8E;IAC9E,QAAQ,CAAC,UAAU,EAAE,KAAK,GAAG,IAAI,CAAC;gBAEtB,UAAU,EAAE,KAAK,GAAG,IAAI;CASpC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,iBAAkB,SAAQ,SAAS;IAC/C,8CAA8C;IAC9C,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;gBAEb,MAAM,EAAE,OAAO;CAS3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,uBAAwB,SAAQ,SAAS;gBACzC,KAAK,EAAE,OAAO;CAS1B"}
|
package/dist/errors.js
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
import { PlayError } from "@xmachines/play";
|
|
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`.
|
|
7
|
+
*/
|
|
8
|
+
const safeString = (value) => {
|
|
9
|
+
try {
|
|
10
|
+
return String(value);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
try {
|
|
14
|
+
return Object.prototype.toString.call(value);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
// A revoked Proxy throws even on brand inspection.
|
|
18
|
+
return "[unrepresentable value]";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
2
22
|
/**
|
|
3
23
|
* Thrown by `buildRouteUrl()` when a required route parameter is absent from the
|
|
4
24
|
* actor's context.
|
|
@@ -8,16 +28,17 @@ import { PlayError } from "@xmachines/play";
|
|
|
8
28
|
*
|
|
9
29
|
* **Error code:** `PLAY_XSTATE_ROUTE_PARAM_MISSING`
|
|
10
30
|
*
|
|
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.
|
|
34
|
+
*
|
|
11
35
|
* @example
|
|
12
36
|
* ```typescript
|
|
37
|
+
* import { buildRouteUrl } from "@xmachines/play-xstate";
|
|
13
38
|
* import { MissingRouteParamError } from "@xmachines/play-xstate/errors";
|
|
14
39
|
*
|
|
15
|
-
* // The route template "/profile/:userId" requires "userId" in context.
|
|
16
|
-
* // If userId is absent, MissingRouteParamError is thrown when the
|
|
17
|
-
* // actor.currentRoute signal is read.
|
|
18
|
-
*
|
|
19
40
|
* try {
|
|
20
|
-
*
|
|
41
|
+
* buildRouteUrl("/profile/:userId", { params: {}, query: {} });
|
|
21
42
|
* } catch (err) {
|
|
22
43
|
* if (err instanceof MissingRouteParamError) {
|
|
23
44
|
* console.error(
|
|
@@ -40,36 +61,18 @@ export class MissingRouteParamError extends PlayError {
|
|
|
40
61
|
}
|
|
41
62
|
}
|
|
42
63
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
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.
|
|
49
71
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* If using `formatPlayRouteTransitions`, the field is assigned automatically on each
|
|
53
|
-
* `play.route` event — but the machine's initial context must still declare it.
|
|
72
|
+
* Formerly thrown by `buildRouteUrl()` when the context had a `params` field
|
|
73
|
+
* (a routing-aware machine context) but no `query` field.
|
|
54
74
|
*
|
|
55
75
|
* **Error code:** `PLAY_XSTATE_MISSING_QUERY_CONTEXT`
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```typescript
|
|
59
|
-
* import { MissingQueryContextError } from "@xmachines/play-xstate/errors";
|
|
60
|
-
*
|
|
61
|
-
* try {
|
|
62
|
-
* // params present but no query field — throws
|
|
63
|
-
* buildRouteUrl("/profile/:userId", { params: { userId: "42" } });
|
|
64
|
-
* } catch (err) {
|
|
65
|
-
* if (err instanceof MissingQueryContextError) {
|
|
66
|
-
* console.error("Machine context missing query field");
|
|
67
|
-
* }
|
|
68
|
-
* }
|
|
69
|
-
*
|
|
70
|
-
* // Correct — both params and query declared
|
|
71
|
-
* buildRouteUrl("/profile/:userId", { params: { userId: "42" }, query: {} });
|
|
72
|
-
* ```
|
|
73
76
|
*/
|
|
74
77
|
export class MissingQueryContextError extends PlayError {
|
|
75
78
|
constructor() {
|
|
@@ -199,4 +202,38 @@ export class InvalidEventError extends PlayError {
|
|
|
199
202
|
this.detail = detail;
|
|
200
203
|
}
|
|
201
204
|
}
|
|
205
|
+
/**
|
|
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 }`.
|
|
208
|
+
*
|
|
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`.
|
|
213
|
+
*
|
|
214
|
+
* **Error code:** `PLAY_XSTATE_NON_ERROR_THROWN`
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* import { ActorThrewNonErrorError } from "@xmachines/play-xstate/errors";
|
|
219
|
+
*
|
|
220
|
+
* definePlayer({
|
|
221
|
+
* machine,
|
|
222
|
+
* options: {
|
|
223
|
+
* onError: (actor, err) => {
|
|
224
|
+
* if (err instanceof ActorThrewNonErrorError) {
|
|
225
|
+
* // err.cause is the value the machine actually threw
|
|
226
|
+
* console.error("Machine threw a non-Error:", err.cause);
|
|
227
|
+
* }
|
|
228
|
+
* },
|
|
229
|
+
* },
|
|
230
|
+
* });
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
export class ActorThrewNonErrorError extends PlayError {
|
|
234
|
+
constructor(value) {
|
|
235
|
+
super("PlayerActor", "PLAY_XSTATE_NON_ERROR_THROWN", `PlayerActor failed with a non-Error value: ${safeString(value)}.`, { cause: value });
|
|
236
|
+
this.name = "ActorThrewNonErrorError";
|
|
237
|
+
}
|
|
238
|
+
}
|
|
202
239
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"m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,UAAU,GAAG,UAAU,CAAC;IAC9B,CAAC;CACD;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IAC/C,8CAA8C;IACrC,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;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;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"}
|
package/dist/guards/compose.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ import type { MachineContext, EventObject, ParameterizedObject } from "xstate";
|
|
|
8
8
|
* widest-compatible concrete XState guard type that does not use `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
13
|
*/
|
|
12
14
|
export type ComposedGuard = GuardPredicate<MachineContext, EventObject, unknown, ParameterizedObject>;
|
|
13
15
|
/**
|
|
@@ -64,6 +66,8 @@ export type ComposedGuard = GuardPredicate<MachineContext, EventObject, unknown,
|
|
|
64
66
|
*
|
|
65
67
|
* @see {@link composeGuardsOr} for OR composition
|
|
66
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.
|
|
67
71
|
*/
|
|
68
72
|
export declare const composeGuards: <TContext = any, TEvent = any>(guards: GuardArray<TContext, TEvent>) => ComposedGuard;
|
|
69
73
|
/**
|
|
@@ -105,6 +109,8 @@ export declare const composeGuards: <TContext = any, TEvent = any>(guards: Guard
|
|
|
105
109
|
*
|
|
106
110
|
* @see {@link composeGuards} for AND composition
|
|
107
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.
|
|
108
114
|
*/
|
|
109
115
|
export declare const composeGuardsOr: <TContext = any, TEvent = any>(guards: GuardArray<TContext, TEvent>) => ComposedGuard;
|
|
110
116
|
/**
|
|
@@ -142,6 +148,8 @@ export declare const composeGuardsOr: <TContext = any, TEvent = any>(guards: Gua
|
|
|
142
148
|
*
|
|
143
149
|
* @see {@link composeGuards} for AND composition
|
|
144
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.
|
|
145
153
|
*/
|
|
146
154
|
export declare const negateGuard: <TContext = any, TEvent = any>(guard: Guard<TContext, TEvent> | string) => ComposedGuard;
|
|
147
155
|
//# 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;AAG/E
|
|
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;AAG/E;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG,cAAc,CACzC,cAAc,EACd,WAAW,EACX,OAAO,EACP,mBAAmB,CACnB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,eAAO,MAAM,aAAa,GAAI,QAAQ,GAAG,GAAG,EAAE,MAAM,GAAG,GAAG,EACzD,QAAQ,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,KAClC,aAoBF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,eAAO,MAAM,eAAe,GAAI,QAAQ,GAAG,GAAG,EAAE,MAAM,GAAG,GAAG,EAC3D,QAAQ,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,KAClC,aAmBF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,eAAO,MAAM,WAAW,GAAI,QAAQ,GAAG,GAAG,EAAE,MAAM,GAAG,GAAG,EACvD,OAAO,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,MAAM,KACrC,aAOF,CAAC"}
|
package/dist/guards/compose.js
CHANGED
|
@@ -54,6 +54,8 @@ import { EmptyGuardArrayError } from "../errors.js";
|
|
|
54
54
|
*
|
|
55
55
|
* @see {@link composeGuardsOr} for OR composition
|
|
56
56
|
* @see {@link negateGuard} for NOT logic
|
|
57
|
+
* @deprecated Use XState's own `and()`/`or()`/`not()` directly — this helper does not
|
|
58
|
+
* compose with `setup()`-typed guard slots and will be removed in the next major.
|
|
57
59
|
*/
|
|
58
60
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
61
|
export const composeGuards = (guards) => {
|
|
@@ -67,8 +69,7 @@ export const composeGuards = (guards) => {
|
|
|
67
69
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
70
|
return guards[0];
|
|
69
71
|
}
|
|
70
|
-
// Use XState's built-in and() for type inference and serialization
|
|
71
|
-
// Per RESEARCH.md: Don't hand-roll guard composition
|
|
72
|
+
// Use XState's built-in and() for type inference and serialization.
|
|
72
73
|
// XState 5.28.0: and() requires `readonly [...tuple]` but our GuardArray is a mutable array.
|
|
73
74
|
// We cast through unknown to express the narrowest possible type boundary rather than
|
|
74
75
|
// escaping to `any`. The runtime value is identical.
|
|
@@ -115,6 +116,8 @@ export const composeGuards = (guards) => {
|
|
|
115
116
|
*
|
|
116
117
|
* @see {@link composeGuards} for AND composition
|
|
117
118
|
* @see {@link negateGuard} for NOT logic
|
|
119
|
+
* @deprecated Use XState's own `and()`/`or()`/`not()` directly — this helper does not
|
|
120
|
+
* compose with `setup()`-typed guard slots and will be removed in the next major.
|
|
118
121
|
*/
|
|
119
122
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
120
123
|
export const composeGuardsOr = (guards) => {
|
|
@@ -170,6 +173,8 @@ export const composeGuardsOr = (guards) => {
|
|
|
170
173
|
*
|
|
171
174
|
* @see {@link composeGuards} for AND composition
|
|
172
175
|
* @see {@link composeGuardsOr} for OR composition
|
|
176
|
+
* @deprecated Use XState's own `and()`/`or()`/`not()` directly — this helper does not
|
|
177
|
+
* compose with `setup()`-typed guard slots and will be removed in the next major.
|
|
173
178
|
*/
|
|
174
179
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
175
180
|
export const negateGuard = (guard) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.js","sourceRoot":"","sources":["../../src/guards/compose.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE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ACnE,8DAA8D;QAC9D,OAAO,MAAM,CAAC,CAAC,CAA6B,CAAC;IAC9C,CAAC;IAED,4FAA4F;IAC5F,sFAAsF;IACtF,qDAAqD;IACrD,+EAA+E;IAC/E,8DAA8D;IAC9D,OAAO,EAAE,CAAC,MAA6C,CAAC,CAAC;AAC1D,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,WAAW,GAAG,CAC1B,KAAuC,EACvB,EAAE;IAClB,qFAAqF;IACrF,sFAAsF;IACtF,qDAAqD;IACrD,+EAA+E;IAC/E,8DAA8D;IAC9D,OAAO,GAAG,CAAC,KAA6C,CAAC,CAAC;AAC3D,CAAC,CAAC"}
|
package/dist/guards/helpers.d.ts
CHANGED
|
@@ -3,8 +3,6 @@ import type { PlayEvent } from "@xmachines/play";
|
|
|
3
3
|
/**
|
|
4
4
|
* Check if context has a truthy value at path
|
|
5
5
|
*
|
|
6
|
-
* Per CONTEXT.md: Convenience helper for common guard pattern
|
|
7
|
-
*
|
|
8
6
|
* @example
|
|
9
7
|
* ```typescript
|
|
10
8
|
* const machine = setup({
|
|
@@ -17,6 +15,8 @@ import type { PlayEvent } from "@xmachines/play";
|
|
|
17
15
|
*
|
|
18
16
|
* @param path - Dot-separated path to context property
|
|
19
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.
|
|
20
20
|
*/
|
|
21
21
|
export declare const hasContext: <TContext = Record<string, unknown>>(path: string) => Guard<TContext, PlayEvent>;
|
|
22
22
|
/**
|
|
@@ -37,6 +37,8 @@ export declare const hasContext: <TContext = Record<string, unknown>>(path: stri
|
|
|
37
37
|
*
|
|
38
38
|
* @param eventType - Expected event type
|
|
39
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.
|
|
40
42
|
*/
|
|
41
43
|
export declare const eventMatches: <TEvent extends PlayEvent = PlayEvent>(eventType: string) => Guard<unknown, TEvent>;
|
|
42
44
|
/**
|
|
@@ -53,6 +55,8 @@ export declare const eventMatches: <TEvent extends PlayEvent = PlayEvent>(eventT
|
|
|
53
55
|
* @param fieldPath - Dot-separated path to context property (e.g., "status", "user.role")
|
|
54
56
|
* @param expectedValue - Value to compare against (string, object, Date, etc.)
|
|
55
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.
|
|
56
60
|
*/
|
|
57
61
|
export declare const contextFieldMatches: <TContext = Record<string, unknown>>(fieldPath: string, expectedValue: unknown) => Guard<TContext, PlayEvent>;
|
|
58
62
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/guards/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,UAAU,GACrB,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,MAAM,KAAG,KAAK,CAAC,QAAQ,EAAE,SAAS,CAI5E,CAAC;AAEH
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/guards/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,UAAU,GACrB,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,MAAM,KAAG,KAAK,CAAC,QAAQ,EAAE,SAAS,CAI5E,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,YAAY,GACvB,MAAM,SAAS,SAAS,GAAG,SAAS,EAAE,WAAW,MAAM,KAAG,KAAK,CAAC,OAAO,EAAE,MAAM,CAG/E,CAAC;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,mBAAmB,GAC9B,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,WAAW,MAAM,EACjB,eAAe,OAAO,KACpB,KAAK,CAAC,QAAQ,EAAE,SAAS,CAI3B,CAAC"}
|
package/dist/guards/helpers.js
CHANGED
|
@@ -2,8 +2,6 @@ import { dequal } from "dequal/lite";
|
|
|
2
2
|
/**
|
|
3
3
|
* Check if context has a truthy value at path
|
|
4
4
|
*
|
|
5
|
-
* Per CONTEXT.md: Convenience helper for common guard pattern
|
|
6
|
-
*
|
|
7
5
|
* @example
|
|
8
6
|
* ```typescript
|
|
9
7
|
* const machine = setup({
|
|
@@ -16,6 +14,8 @@ import { dequal } from "dequal/lite";
|
|
|
16
14
|
*
|
|
17
15
|
* @param path - Dot-separated path to context property
|
|
18
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.
|
|
19
19
|
*/
|
|
20
20
|
export const hasContext = (path) => ({ context }) => {
|
|
21
21
|
const value = getNestedValue(context, path);
|
|
@@ -39,6 +39,8 @@ export const hasContext = (path) => ({ context }) => {
|
|
|
39
39
|
*
|
|
40
40
|
* @param eventType - Expected event type
|
|
41
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.
|
|
42
44
|
*/
|
|
43
45
|
export const eventMatches = (eventType) => ({ event }) => {
|
|
44
46
|
return event.type === eventType;
|
|
@@ -57,6 +59,8 @@ export const eventMatches = (eventType) => ({ event }) => {
|
|
|
57
59
|
* @param fieldPath - Dot-separated path to context property (e.g., "status", "user.role")
|
|
58
60
|
* @param expectedValue - Value to compare against (string, object, Date, etc.)
|
|
59
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.
|
|
60
64
|
*/
|
|
61
65
|
export const contextFieldMatches = (fieldPath, expectedValue) => ({ context }) => {
|
|
62
66
|
const actual = getNestedValue(context, fieldPath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/guards/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,UAAU,GACtB,CAAqC,IAAY,EAA8B,EAAE,CACjF,CAAC,EAAE,OAAO,EAAyB,EAAE,EAAE;IACtC,MAAM,KAAK,GAAG,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC5C,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;AAC9D,CAAC,CAAC;AAEH
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/guards/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,UAAU,GACtB,CAAqC,IAAY,EAA8B,EAAE,CACjF,CAAC,EAAE,OAAO,EAAyB,EAAE,EAAE;IACtC,MAAM,KAAK,GAAG,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC5C,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;AAC9D,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,YAAY,GACxB,CAAuC,SAAiB,EAA0B,EAAE,CACpF,CAAC,EAAE,KAAK,EAAqB,EAAE,EAAE;IAChC,OAAO,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC;AACjC,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAC/B,CACC,SAAiB,EACjB,aAAsB,EACO,EAAE,CAChC,CAAC,EAAE,OAAO,EAAyB,EAAE,EAAE;IACtC,MAAM,MAAM,GAAG,cAAc,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAClD,OAAO,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AACtC,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,cAAc,GAAG,CAAC,GAAY,EAAE,IAAY,EAAW,EAAE;IAC9D,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,KAAK,GAAG,GAAG,CAAC;IAEhB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACxB,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACxE,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,KAAK,GAAI,KAAiC,CAAC,GAAG,CAAC,CAAC,CAAC,mDAAmD;IACrG,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC,CAAC"}
|
package/dist/guards/index.d.ts
CHANGED
|
@@ -4,6 +4,13 @@
|
|
|
4
4
|
* Provides array-means-AND composition and convenience helpers
|
|
5
5
|
* for common guard patterns in 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.
|
|
13
|
+
*
|
|
7
14
|
* @packageDocumentation
|
|
8
15
|
*/
|
|
9
16
|
export { composeGuards, composeGuardsOr, negateGuard } from "./compose.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/guards/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/guards/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3E,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAC7E,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/guards/index.js
CHANGED
|
@@ -4,6 +4,13 @@
|
|
|
4
4
|
* Provides array-means-AND composition and convenience helpers
|
|
5
5
|
* for common guard patterns in 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.
|
|
13
|
+
*
|
|
7
14
|
* @packageDocumentation
|
|
8
15
|
*/
|
|
9
16
|
export { composeGuards, composeGuardsOr, negateGuard } from "./compose.js";
|
package/dist/guards/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/guards/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/guards/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/guards/types.d.ts
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import type { PlayEvent } from "@xmachines/play";
|
|
2
2
|
/**
|
|
3
|
-
* Standard XState guard function signature
|
|
4
|
-
*
|
|
5
|
-
* Per CONTEXT.md: Guards receive { context, event } per XState standard
|
|
3
|
+
* Standard XState guard function signature — guards receive `{ context, event }`.
|
|
6
4
|
*
|
|
7
5
|
* @param args - Guard arguments with context and event
|
|
8
6
|
* @param args.context - Current machine context
|
|
9
7
|
* @param args.event - Event that triggered the guard evaluation
|
|
10
8
|
* @returns boolean indicating if guard passes
|
|
9
|
+
* @deprecated The guard utilities will be removed in the next major.
|
|
11
10
|
*/
|
|
12
11
|
export type Guard<TContext = Record<string, unknown>, TEvent = PlayEvent> = (args: {
|
|
13
12
|
context: TContext;
|
|
14
13
|
event: TEvent;
|
|
15
14
|
}) => boolean;
|
|
16
15
|
/**
|
|
17
|
-
* Array of guard predicates or guard names
|
|
16
|
+
* Array of guard predicates or guard names — an array means AND: all must pass.
|
|
18
17
|
*
|
|
19
|
-
*
|
|
18
|
+
* @deprecated The guard utilities will be removed in the next major.
|
|
20
19
|
*/
|
|
21
20
|
export type GuardArray<TContext = Record<string, unknown>, TEvent = PlayEvent> = Array<Guard<TContext, TEvent> | string>;
|
|
22
21
|
//# 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
|
|
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"}
|