@xmachines/play-xstate 3.0.0 → 5.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 +190 -68
- package/dist/capabilities.d.ts +93 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +4 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/define-player.d.ts +7 -1
- package/dist/define-player.d.ts.map +1 -1
- package/dist/define-player.js +9 -60
- package/dist/define-player.js.map +1 -1
- package/dist/errors.d.ts +64 -23
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +93 -31
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +4 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -6
- package/dist/index.js.map +1 -1
- package/dist/player-actor.d.ts +73 -137
- package/dist/player-actor.d.ts.map +1 -1
- package/dist/player-actor.js +108 -254
- package/dist/player-actor.js.map +1 -1
- package/dist/routing/build-url.d.ts +8 -1
- package/dist/routing/build-url.d.ts.map +1 -1
- package/dist/routing/build-url.js +34 -54
- package/dist/routing/build-url.js.map +1 -1
- package/dist/routing/derive-current-route.d.ts +12 -38
- package/dist/routing/derive-current-route.d.ts.map +1 -1
- package/dist/routing/derive-current-route.js +24 -82
- package/dist/routing/derive-current-route.js.map +1 -1
- package/dist/routing/derive-initial-route.d.ts +2 -1
- package/dist/routing/derive-initial-route.d.ts.map +1 -1
- package/dist/routing/derive-initial-route.js +13 -2
- package/dist/routing/derive-initial-route.js.map +1 -1
- package/dist/routing/derive-route.d.ts +81 -2
- package/dist/routing/derive-route.d.ts.map +1 -1
- package/dist/routing/derive-route.js +97 -3
- package/dist/routing/derive-route.js.map +1 -1
- package/dist/routing/format-play-route-transitions.d.ts +8 -2
- package/dist/routing/format-play-route-transitions.d.ts.map +1 -1
- package/dist/routing/format-play-route-transitions.js +175 -43
- package/dist/routing/format-play-route-transitions.js.map +1 -1
- package/dist/routing/index.d.ts +1 -1
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/types.d.ts +9 -5
- package/dist/routing/types.d.ts.map +1 -1
- package/dist/state-meta.d.ts +52 -0
- package/dist/state-meta.d.ts.map +1 -0
- package/dist/state-meta.js +77 -0
- package/dist/state-meta.js.map +1 -0
- package/dist/types.d.ts +20 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/view/derive-current-view.d.ts +7 -6
- package/dist/view/derive-current-view.d.ts.map +1 -1
- package/dist/view/derive-current-view.js +7 -6
- package/dist/view/derive-current-view.js.map +1 -1
- package/dist/with-routing.d.ts +45 -0
- package/dist/with-routing.d.ts.map +1 -0
- package/dist/with-routing.js +140 -0
- package/dist/with-routing.js.map +1 -0
- package/dist/with-view.d.ts +57 -0
- package/dist/with-view.d.ts.map +1 -0
- package/dist/with-view.js +158 -0
- package/dist/with-view.js.map +1 -0
- package/package.json +40 -18
- package/dist/guards/compose.d.ts +0 -158
- package/dist/guards/compose.d.ts.map +0 -1
- package/dist/guards/compose.js +0 -188
- package/dist/guards/compose.js.map +0 -1
- package/dist/guards/helpers.d.ts +0 -62
- package/dist/guards/helpers.d.ts.map +0 -1
- package/dist/guards/helpers.js +0 -85
- package/dist/guards/helpers.js.map +0 -1
- package/dist/guards/index.d.ts +0 -20
- package/dist/guards/index.d.ts.map +0 -1
- package/dist/guards/index.js +0 -18
- package/dist/guards/index.js.map +0 -1
- package/dist/guards/types.d.ts +0 -22
- package/dist/guards/types.d.ts.map +0 -1
- package/dist/guards/types.js +0 -2
- package/dist/guards/types.js.map +0 -1
package/dist/guards/helpers.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { Guard } from "./types.js";
|
|
2
|
-
import type { PlayEvent } from "@xmachines/play";
|
|
3
|
-
/**
|
|
4
|
-
* Tells you if the context holds a value at the path, and that the value is truthy
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* const machine = setup({
|
|
9
|
-
* guards: {
|
|
10
|
-
* hasUserId: hasContext('userId'),
|
|
11
|
-
* hasEmail: hasContext('user.email')
|
|
12
|
-
* }
|
|
13
|
-
* });
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
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
|
-
*/
|
|
21
|
-
export declare const hasContext: <TContext = Record<string, unknown>>(path: string) => Guard<TContext, PlayEvent>;
|
|
22
|
-
/**
|
|
23
|
-
* Tells you if the type of the event is the expected type
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```typescript
|
|
27
|
-
* const machine = setup({
|
|
28
|
-
* guards: {
|
|
29
|
-
* isSubmitEvent: eventMatches('submit'),
|
|
30
|
-
* isBackOrForward: composeGuardsOr([
|
|
31
|
-
* eventMatches('back'),
|
|
32
|
-
* eventMatches('forward')
|
|
33
|
-
* ])
|
|
34
|
-
* }
|
|
35
|
-
* });
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
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
|
-
*/
|
|
43
|
-
export declare const eventMatches: <TEvent extends PlayEvent = PlayEvent>(eventType: string) => Guard<unknown, TEvent>;
|
|
44
|
-
/**
|
|
45
|
-
* Tells you if a context field holds the expected value.
|
|
46
|
-
*
|
|
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
|
-
*
|
|
53
|
-
* For a match of an XState state node, use the built-in `in:` guard syntax instead.
|
|
54
|
-
*
|
|
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
|
-
*/
|
|
61
|
-
export declare const contextFieldMatches: <TContext = Record<string, unknown>>(fieldPath: string, expectedValue: unknown) => Guard<TContext, PlayEvent>;
|
|
62
|
-
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { dequal } from "dequal/lite";
|
|
2
|
-
/**
|
|
3
|
-
* Tells you if the context holds a value at the path, and that the value is truthy
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```typescript
|
|
7
|
-
* const machine = setup({
|
|
8
|
-
* guards: {
|
|
9
|
-
* hasUserId: hasContext('userId'),
|
|
10
|
-
* hasEmail: hasContext('user.email')
|
|
11
|
-
* }
|
|
12
|
-
* });
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
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
|
-
*/
|
|
20
|
-
export const hasContext = (path) => ({ context }) => {
|
|
21
|
-
const value = getNestedValue(context, path);
|
|
22
|
-
return value !== undefined && value !== null && value !== "";
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Tells you if the type of the event is the expected type
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```typescript
|
|
29
|
-
* const machine = setup({
|
|
30
|
-
* guards: {
|
|
31
|
-
* isSubmitEvent: eventMatches('submit'),
|
|
32
|
-
* isBackOrForward: composeGuardsOr([
|
|
33
|
-
* eventMatches('back'),
|
|
34
|
-
* eventMatches('forward')
|
|
35
|
-
* ])
|
|
36
|
-
* }
|
|
37
|
-
* });
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
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
|
-
*/
|
|
45
|
-
export const eventMatches = (eventType) => ({ event }) => {
|
|
46
|
-
return event.type === eventType;
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Tells you if a context field holds the expected value.
|
|
50
|
-
*
|
|
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
|
-
*
|
|
57
|
-
* For a match of an XState state node, use the built-in `in:` guard syntax instead.
|
|
58
|
-
*
|
|
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
|
-
*/
|
|
65
|
-
export const contextFieldMatches = (fieldPath, expectedValue) => ({ context }) => {
|
|
66
|
-
const actual = getNestedValue(context, fieldPath);
|
|
67
|
-
return dequal(actual, expectedValue);
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Returns a nested value of an object, from a path with a dot between two segments
|
|
71
|
-
*
|
|
72
|
-
* @internal
|
|
73
|
-
*/
|
|
74
|
-
const getNestedValue = (obj, path) => {
|
|
75
|
-
const keys = path.split(".");
|
|
76
|
-
let value = obj;
|
|
77
|
-
for (const key of keys) {
|
|
78
|
-
if (value === null || value === undefined || typeof value !== "object") {
|
|
79
|
-
return undefined;
|
|
80
|
-
}
|
|
81
|
-
value = value[key]; // nosemgrep: gitlab.eslint.detect-object-injection
|
|
82
|
-
}
|
|
83
|
-
return value;
|
|
84
|
-
};
|
|
85
|
-
//# sourceMappingURL=helpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceR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,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
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The guard composition utilities and the guard helpers of an XState machine
|
|
3
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
14
|
-
* @packageDocumentation
|
|
15
|
-
*/
|
|
16
|
-
export { composeGuards, composeGuardsOr, negateGuard } from "./compose.js";
|
|
17
|
-
export type { ComposedGuard } from "./compose.js";
|
|
18
|
-
export { hasContext, eventMatches, contextFieldMatches } from "./helpers.js";
|
|
19
|
-
export type { Guard, GuardArray } from "./types.js";
|
|
20
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The guard composition utilities and the guard helpers of an XState machine
|
|
3
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
14
|
-
* @packageDocumentation
|
|
15
|
-
*/
|
|
16
|
-
export { composeGuards, composeGuardsOr, negateGuard } from "./compose.js";
|
|
17
|
-
export { hasContext, eventMatches, contextFieldMatches } from "./helpers.js";
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
package/dist/guards/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { PlayEvent } from "@xmachines/play";
|
|
2
|
-
/**
|
|
3
|
-
* The standard signature of an XState guard function. A guard receives `{ context, event }`.
|
|
4
|
-
*
|
|
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
|
-
*/
|
|
11
|
-
export type Guard<TContext = Record<string, unknown>, TEvent = PlayEvent> = (args: {
|
|
12
|
-
context: TContext;
|
|
13
|
-
event: TEvent;
|
|
14
|
-
}) => boolean;
|
|
15
|
-
/**
|
|
16
|
-
* The array of the guard predicates, or of the guard names. An array means AND:
|
|
17
|
-
* every guard must pass.
|
|
18
|
-
*
|
|
19
|
-
* @deprecated The next major version removes the guard utilities.
|
|
20
|
-
*/
|
|
21
|
-
export type GuardArray<TContext = Record<string, unknown>, TEvent = PlayEvent> = Array<Guard<TContext, TEvent> | string>;
|
|
22
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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/guards/types.js
DELETED
package/dist/guards/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/guards/types.ts"],"names":[],"mappings":""}
|