@xmachines/play-xstate 2.0.0-alpha.1 → 2.0.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 +90 -91
- package/dist/define-player.d.ts +3 -3
- package/dist/define-player.js +3 -3
- package/dist/errors.d.ts +46 -70
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +69 -77
- package/dist/errors.js.map +1 -1
- package/dist/guards/compose.d.ts +49 -59
- package/dist/guards/compose.d.ts.map +1 -1
- package/dist/guards/compose.js +68 -95
- 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/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/player-actor.d.ts +112 -44
- package/dist/player-actor.d.ts.map +1 -1
- package/dist/player-actor.js +311 -327
- 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 +1 -4
- package/dist/routing/derive-initial-route.d.ts.map +1 -1
- package/dist/routing/derive-initial-route.js +1 -4
- package/dist/routing/derive-initial-route.js.map +1 -1
- package/dist/routing/format-play-route-transitions.d.ts +11 -54
- package/dist/routing/format-play-route-transitions.d.ts.map +1 -1
- package/dist/routing/format-play-route-transitions.js +65 -125
- package/dist/routing/format-play-route-transitions.js.map +1 -1
- package/dist/routing/index.d.ts +1 -5
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/index.js +1 -3
- package/dist/routing/index.js.map +1 -1
- package/dist/types.d.ts +87 -14
- package/dist/types.d.ts.map +1 -1
- package/dist/view/derive-current-view.d.ts +49 -0
- package/dist/view/derive-current-view.d.ts.map +1 -0
- package/dist/view/derive-current-view.js +115 -0
- package/dist/view/derive-current-view.js.map +1 -0
- package/package.json +22 -22
- 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/guards/compose.typecheck.d.ts +0 -2
- package/dist/guards/compose.typecheck.d.ts.map +0 -1
- package/dist/guards/compose.typecheck.js +0 -22
- package/dist/guards/compose.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 -30
- package/dist/player-actor.typecheck.js.map +0 -1
- package/dist/routing/create-routed-machine.d.ts +0 -71
- package/dist/routing/create-routed-machine.d.ts.map +0 -1
- package/dist/routing/create-routed-machine.js +0 -71
- package/dist/routing/create-routed-machine.js.map +0 -1
- package/dist/routing/play-route-event.typecheck.d.ts +0 -2
- package/dist/routing/play-route-event.typecheck.d.ts.map +0 -1
- package/dist/routing/play-route-event.typecheck.js +0 -43
- package/dist/routing/play-route-event.typecheck.js.map +0 -1
- package/dist/routing/schemas.d.ts +0 -99
- package/dist/routing/schemas.d.ts.map +0 -1
- package/dist/routing/schemas.js +0 -30
- package/dist/routing/schemas.js.map +0 -1
- package/dist/schemas.d.ts +0 -28
- package/dist/schemas.d.ts.map +0 -1
- package/dist/schemas.js +0 -29
- package/dist/schemas.js.map +0 -1
package/dist/guards/compose.js
CHANGED
|
@@ -1,60 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { and, or, not } from "xstate";
|
|
2
|
+
import { EmptyGuardArrayError } from "../errors.js";
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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
|
|
11
15
|
*/
|
|
12
|
-
const
|
|
13
|
-
if (typeof guard === "function") {
|
|
14
|
-
return (args) => Boolean(guard(args));
|
|
15
|
-
}
|
|
16
|
-
if (typeof guard === "string") {
|
|
17
|
-
return (args) => {
|
|
18
|
-
const named = args?.guards?.[guard];
|
|
19
|
-
if (typeof named !== "function") {
|
|
20
|
-
throw new UnresolvableGuardNameError(guard, origin);
|
|
21
|
-
}
|
|
22
|
-
return Boolean(named(args));
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
// XState v5 failed loudly when EVALUATING a nullish guard entry — silently
|
|
26
|
-
// treating it as never-passing would turn negateGuard(undefined) into an
|
|
27
|
-
// always-allow. Composition stays lazy; evaluation throws.
|
|
28
|
-
return () => {
|
|
29
|
-
throw new InvalidGuardEntryError(typeof guard, origin);
|
|
30
|
-
};
|
|
31
|
-
};
|
|
16
|
+
const asXStateGuard = (value) => value;
|
|
32
17
|
/**
|
|
33
|
-
* Compose guards with AND logic
|
|
18
|
+
* Compose guards with AND logic using XState's and() helper
|
|
34
19
|
*
|
|
35
20
|
* Combines multiple guard predicates using AND semantics—all guards must pass for
|
|
36
|
-
* the composition to succeed.
|
|
21
|
+
* the composition to succeed. Uses XState's built-in `and()` helper to ensure proper
|
|
22
|
+
* type inference and machine serialization.
|
|
37
23
|
*
|
|
38
24
|
* **Architectural Context:** Supports **Actor Authority (INV-01)** by enabling
|
|
39
25
|
* declarative guard composition in state machine transitions. Guards enforce business
|
|
40
26
|
* logic rules that determine whether navigation or actions are valid.
|
|
41
27
|
*
|
|
42
|
-
*
|
|
43
|
-
* transition function and return early to block the transition:
|
|
44
|
-
*
|
|
45
|
-
* @typeParam TContext - State machine context type (defaults to `any` so the
|
|
46
|
-
* documented inline-predicate examples compile without annotations)
|
|
28
|
+
* @typeParam TContext - State machine context type
|
|
47
29
|
* @typeParam TEvent - Event type
|
|
48
30
|
*
|
|
49
|
-
* @
|
|
50
|
-
*
|
|
51
|
-
* @typeParam TEvent - Event type
|
|
31
|
+
* @param guards - Array of guard predicates or guard names (string references)
|
|
32
|
+
* @returns XState and() guard composition
|
|
52
33
|
*
|
|
53
|
-
* @
|
|
54
|
-
* resolved against `args.guards` from `setup({ guards })`)
|
|
55
|
-
* @returns Predicate returning `true` only when every guard passes
|
|
56
|
-
*
|
|
57
|
-
* @throws {EmptyGuardArrayError} If guards array is empty
|
|
34
|
+
* @throws {Error} If guards array is empty
|
|
58
35
|
*
|
|
59
36
|
* @example
|
|
60
37
|
* AND composition with named guards
|
|
@@ -62,8 +39,6 @@ const toEvaluator = (guard, origin) => {
|
|
|
62
39
|
* import { setup } from "xstate";
|
|
63
40
|
* import { composeGuards } from "@xmachines/play-xstate";
|
|
64
41
|
*
|
|
65
|
-
* const canAccessAdmin = composeGuards(['isLoggedIn', 'hasPermission']);
|
|
66
|
-
*
|
|
67
42
|
* const machine = setup({
|
|
68
43
|
* guards: {
|
|
69
44
|
* isLoggedIn: ({ context }) => !!context.userId,
|
|
@@ -71,9 +46,10 @@ const toEvaluator = (guard, origin) => {
|
|
|
71
46
|
* }
|
|
72
47
|
* }).createMachine({
|
|
73
48
|
* on: {
|
|
74
|
-
* accessAdmin:
|
|
75
|
-
*
|
|
76
|
-
*
|
|
49
|
+
* accessAdmin: {
|
|
50
|
+
* // Both guards must pass
|
|
51
|
+
* guard: composeGuards(['isLoggedIn', 'hasPermission']),
|
|
52
|
+
* target: 'adminPanel'
|
|
77
53
|
* }
|
|
78
54
|
* }
|
|
79
55
|
* });
|
|
@@ -84,43 +60,43 @@ const toEvaluator = (guard, origin) => {
|
|
|
84
60
|
* ```typescript
|
|
85
61
|
* import { composeGuards } from "@xmachines/play-xstate";
|
|
86
62
|
*
|
|
87
|
-
*
|
|
63
|
+
* guard: composeGuards([
|
|
88
64
|
* ({ context }) => context.age >= 18,
|
|
89
65
|
* ({ context }) => context.verified
|
|
90
|
-
* ])
|
|
66
|
+
* ])
|
|
91
67
|
* ```
|
|
92
68
|
*
|
|
93
69
|
* @see {@link composeGuardsOr} for OR composition
|
|
94
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.
|
|
95
73
|
*/
|
|
96
74
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
97
75
|
export const composeGuards = (guards) => {
|
|
98
76
|
if (guards.length === 0) {
|
|
99
77
|
throw new EmptyGuardArrayError("and");
|
|
100
78
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return
|
|
79
|
+
if (guards.length === 1) {
|
|
80
|
+
// Single guard passthrough — see asXStateGuard for why the boundary exists.
|
|
81
|
+
return asXStateGuard(guards[0]);
|
|
104
82
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (!evaluate(args))
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
return true;
|
|
111
|
-
};
|
|
83
|
+
// Use XState's built-in and() for type inference and serialization.
|
|
84
|
+
return and(asXStateGuard(guards));
|
|
112
85
|
};
|
|
113
86
|
/**
|
|
114
|
-
* Compose guards with OR logic
|
|
87
|
+
* Compose guards with OR logic using XState's or() helper
|
|
115
88
|
*
|
|
116
89
|
* Combines multiple guard predicates using OR semantics—at least one guard must pass
|
|
117
|
-
* for the composition to succeed.
|
|
90
|
+
* for the composition to succeed. Uses XState's built-in `or()` helper for proper
|
|
91
|
+
* type inference.
|
|
92
|
+
*
|
|
93
|
+
* @typeParam TContext - State machine context type
|
|
94
|
+
* @typeParam TEvent - Event type
|
|
118
95
|
*
|
|
119
|
-
* @param guards - Array of guard predicates or guard names
|
|
120
|
-
*
|
|
121
|
-
* @returns Predicate returning `true` when any guard passes
|
|
96
|
+
* @param guards - Array of guard predicates or guard names
|
|
97
|
+
* @returns XState or() guard composition
|
|
122
98
|
*
|
|
123
|
-
* @throws {
|
|
99
|
+
* @throws {Error} If guards array is empty
|
|
124
100
|
*
|
|
125
101
|
* @example
|
|
126
102
|
* OR composition with named guards
|
|
@@ -128,8 +104,6 @@ export const composeGuards = (guards) => {
|
|
|
128
104
|
* import { setup } from "xstate";
|
|
129
105
|
* import { composeGuardsOr } from "@xmachines/play-xstate";
|
|
130
106
|
*
|
|
131
|
-
* const canDelete = composeGuardsOr(['isOwner', 'isAdmin']);
|
|
132
|
-
*
|
|
133
107
|
* const machine = setup({
|
|
134
108
|
* guards: {
|
|
135
109
|
* isOwner: ({ context }) => context.role === 'owner',
|
|
@@ -137,9 +111,10 @@ export const composeGuards = (guards) => {
|
|
|
137
111
|
* }
|
|
138
112
|
* }).createMachine({
|
|
139
113
|
* on: {
|
|
140
|
-
* deleteResource:
|
|
141
|
-
*
|
|
142
|
-
*
|
|
114
|
+
* deleteResource: {
|
|
115
|
+
* // Either guard can pass
|
|
116
|
+
* guard: composeGuardsOr(['isOwner', 'isAdmin']),
|
|
117
|
+
* actions: 'delete'
|
|
143
118
|
* }
|
|
144
119
|
* }
|
|
145
120
|
* });
|
|
@@ -147,36 +122,32 @@ export const composeGuards = (guards) => {
|
|
|
147
122
|
*
|
|
148
123
|
* @see {@link composeGuards} for AND composition
|
|
149
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.
|
|
150
127
|
*/
|
|
151
128
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
152
129
|
export const composeGuardsOr = (guards) => {
|
|
153
130
|
if (guards.length === 0) {
|
|
154
131
|
throw new EmptyGuardArrayError("or");
|
|
155
132
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return
|
|
133
|
+
if (guards.length === 1) {
|
|
134
|
+
// Single guard passthrough — see asXStateGuard for why the boundary exists.
|
|
135
|
+
return asXStateGuard(guards[0]);
|
|
159
136
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (evaluate(args))
|
|
163
|
-
return true;
|
|
164
|
-
}
|
|
165
|
-
return false;
|
|
166
|
-
};
|
|
137
|
+
// Use XState's built-in or() for type inference and serialization.
|
|
138
|
+
return or(asXStateGuard(guards));
|
|
167
139
|
};
|
|
168
140
|
/**
|
|
169
|
-
* Negate a guard
|
|
141
|
+
* Negate a guard using XState's not() helper
|
|
170
142
|
*
|
|
171
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.
|
|
172
145
|
*
|
|
173
|
-
* @typeParam TContext - State machine context type
|
|
174
|
-
* inline predicates compile without annotations)
|
|
146
|
+
* @typeParam TContext - State machine context type
|
|
175
147
|
* @typeParam TEvent - Event type
|
|
176
148
|
*
|
|
177
|
-
* @param guard - Guard predicate or guard name
|
|
178
|
-
*
|
|
179
|
-
* @returns Predicate returning the inverted guard result
|
|
149
|
+
* @param guard - Guard predicate or guard name to negate
|
|
150
|
+
* @returns XState not() guard negation
|
|
180
151
|
*
|
|
181
152
|
* @example
|
|
182
153
|
* NOT composition with named guard
|
|
@@ -184,17 +155,16 @@ export const composeGuardsOr = (guards) => {
|
|
|
184
155
|
* import { setup } from "xstate";
|
|
185
156
|
* import { negateGuard } from "@xmachines/play-xstate";
|
|
186
157
|
*
|
|
187
|
-
* const isAuthenticated = negateGuard('isGuest');
|
|
188
|
-
*
|
|
189
158
|
* const machine = setup({
|
|
190
159
|
* guards: {
|
|
191
160
|
* isGuest: ({ context }) => !context.userId
|
|
192
161
|
* }
|
|
193
162
|
* }).createMachine({
|
|
194
163
|
* on: {
|
|
195
|
-
* accessDashboard:
|
|
196
|
-
* if (
|
|
197
|
-
*
|
|
164
|
+
* accessDashboard: {
|
|
165
|
+
* // Allow if NOT a guest (i.e., authenticated)
|
|
166
|
+
* guard: negateGuard('isGuest'),
|
|
167
|
+
* target: 'dashboard'
|
|
198
168
|
* }
|
|
199
169
|
* }
|
|
200
170
|
* });
|
|
@@ -202,10 +172,13 @@ export const composeGuardsOr = (guards) => {
|
|
|
202
172
|
*
|
|
203
173
|
* @see {@link composeGuards} for AND composition
|
|
204
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.
|
|
205
177
|
*/
|
|
206
178
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
207
179
|
export const negateGuard = (guard) => {
|
|
208
|
-
|
|
209
|
-
|
|
180
|
+
// XState 5.28.0: not() requires a specific SingleGuardArg shape, not our
|
|
181
|
+
// Guard type — see asXStateGuard.
|
|
182
|
+
return not(asXStateGuard(guard));
|
|
210
183
|
};
|
|
211
184
|
//# sourceMappingURL=compose.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.js","sourceRoot":"","sources":["../../src/guards/compose.ts"],"names":[],"mappings":"
|
|
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,aAAa,CAAgB,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,mEAAmE;IACnE,OAAO,EAAE,CAAC,aAAa,CAA2B,MAAM,CAAC,CAAC,CAAC;AAC5D,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,WAAW,GAAG,CAC1B,KAAuC,EACvB,EAAE;IAClB,yEAAyE;IACzE,kCAAkC;IAClC,OAAO,GAAG,CAAC,aAAa,CAA4B,KAAK,CAAC,CAAC,CAAC;AAC7D,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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @xmachines/play-xstate - XState
|
|
2
|
+
* @xmachines/play-xstate - XState v5 adapter for Play Architecture
|
|
3
3
|
*
|
|
4
4
|
* Provides definePlayer() API for binding XState state machines to the
|
|
5
5
|
* actor base with signal lifecycle and DevTools integration.
|
|
@@ -15,7 +15,6 @@ export { PlayerActor } from "./player-actor.js";
|
|
|
15
15
|
export type { PlayerConfig, PlayerOptions, PlayerFactory, PlayerFactoryResumeOptions, } from "./types.js";
|
|
16
16
|
export { composeGuards, composeGuardsOr, negateGuard, hasContext, eventMatches, contextFieldMatches, } from "./guards/index.js";
|
|
17
17
|
export type { Guard, GuardArray, ComposedGuard } from "./guards/index.js";
|
|
18
|
-
export { deriveRoute, isAbsoluteRoute, buildRouteUrl, formatPlayRouteTransitions,
|
|
19
|
-
export {
|
|
20
|
-
export type { PlayRoutePayload, SetupLike, WithOptional, RouteMachineConfig, RouteStateNode, RouteContext, RouteObject, RouteMetadata, } from "./routing/index.js";
|
|
18
|
+
export { deriveRoute, isAbsoluteRoute, buildRouteUrl, formatPlayRouteTransitions, } from "./routing/index.js";
|
|
19
|
+
export type { RouteMachineConfig, RouteStateNode, RouteContext, RouteObject, RouteMetadata, } from "./routing/index.js";
|
|
21
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","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;AAChD,YAAY,EACX,YAAY,EACZ,aAAa,EACb,aAAa,EACb,0BAA0B,GAC1B,MAAM,YAAY,CAAC;AAGpB,OAAO,EACN,aAAa,EACb,eAAe,EACf,WAAW,EACX,UAAU,EACV,YAAY,EACZ,mBAAmB,GACnB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAG1E,OAAO,EACN,WAAW,EACX,eAAe,EACf,aAAa,EACb,0BAA0B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","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;AAChD,YAAY,EACX,YAAY,EACZ,aAAa,EACb,aAAa,EACb,0BAA0B,GAC1B,MAAM,YAAY,CAAC;AAGpB,OAAO,EACN,aAAa,EACb,eAAe,EACf,WAAW,EACX,UAAU,EACV,YAAY,EACZ,mBAAmB,GACnB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAG1E,OAAO,EACN,WAAW,EACX,eAAe,EACf,aAAa,EACb,0BAA0B,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACX,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,WAAW,EACX,aAAa,GACb,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @xmachines/play-xstate - XState
|
|
2
|
+
* @xmachines/play-xstate - XState v5 adapter for Play Architecture
|
|
3
3
|
*
|
|
4
4
|
* Provides definePlayer() API for binding XState state machines to the
|
|
5
5
|
* actor base with signal lifecycle and DevTools integration.
|
|
@@ -15,7 +15,5 @@ export { PlayerActor } from "./player-actor.js";
|
|
|
15
15
|
// Guard utilities
|
|
16
16
|
export { composeGuards, composeGuardsOr, negateGuard, hasContext, eventMatches, contextFieldMatches, } from "./guards/index.js";
|
|
17
17
|
// Routing utilities
|
|
18
|
-
export { deriveRoute, isAbsoluteRoute, buildRouteUrl, formatPlayRouteTransitions,
|
|
19
|
-
// XState v6 schema constants (not routing-specific)
|
|
20
|
-
export { emptyEventSchema } from "./schemas.js";
|
|
18
|
+
export { deriveRoute, isAbsoluteRoute, buildRouteUrl, formatPlayRouteTransitions, } from "./routing/index.js";
|
|
21
19
|
//# 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,
|
|
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"}
|