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