@xmachines/play-xstate 3.0.0 → 4.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.
Files changed (75) hide show
  1. package/README.md +148 -57
  2. package/dist/capabilities.d.ts +92 -0
  3. package/dist/capabilities.d.ts.map +1 -0
  4. package/dist/capabilities.js +4 -0
  5. package/dist/capabilities.js.map +1 -0
  6. package/dist/define-player.d.ts +7 -1
  7. package/dist/define-player.d.ts.map +1 -1
  8. package/dist/define-player.js +9 -60
  9. package/dist/define-player.js.map +1 -1
  10. package/dist/errors.d.ts +29 -26
  11. package/dist/errors.d.ts.map +1 -1
  12. package/dist/errors.js +53 -35
  13. package/dist/errors.js.map +1 -1
  14. package/dist/index.d.ts +2 -4
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +9 -4
  17. package/dist/index.js.map +1 -1
  18. package/dist/player-actor.d.ts +52 -117
  19. package/dist/player-actor.d.ts.map +1 -1
  20. package/dist/player-actor.js +72 -228
  21. package/dist/player-actor.js.map +1 -1
  22. package/dist/routing/derive-current-route.d.ts +1 -36
  23. package/dist/routing/derive-current-route.d.ts.map +1 -1
  24. package/dist/routing/derive-current-route.js +2 -76
  25. package/dist/routing/derive-current-route.js.map +1 -1
  26. package/dist/routing/derive-initial-route.d.ts.map +1 -1
  27. package/dist/routing/derive-initial-route.js +11 -0
  28. package/dist/routing/derive-initial-route.js.map +1 -1
  29. package/dist/routing/derive-route.d.ts +81 -2
  30. package/dist/routing/derive-route.d.ts.map +1 -1
  31. package/dist/routing/derive-route.js +97 -3
  32. package/dist/routing/derive-route.js.map +1 -1
  33. package/dist/routing/format-play-route-transitions.d.ts +8 -2
  34. package/dist/routing/format-play-route-transitions.d.ts.map +1 -1
  35. package/dist/routing/format-play-route-transitions.js +170 -43
  36. package/dist/routing/format-play-route-transitions.js.map +1 -1
  37. package/dist/routing/index.d.ts +1 -1
  38. package/dist/routing/index.d.ts.map +1 -1
  39. package/dist/routing/types.d.ts +9 -5
  40. package/dist/routing/types.d.ts.map +1 -1
  41. package/dist/state-meta.d.ts +52 -0
  42. package/dist/state-meta.d.ts.map +1 -0
  43. package/dist/state-meta.js +77 -0
  44. package/dist/state-meta.js.map +1 -0
  45. package/dist/types.d.ts +18 -3
  46. package/dist/types.d.ts.map +1 -1
  47. package/dist/view/derive-current-view.d.ts +1 -1
  48. package/dist/view/derive-current-view.d.ts.map +1 -1
  49. package/dist/view/derive-current-view.js +2 -2
  50. package/dist/view/derive-current-view.js.map +1 -1
  51. package/dist/with-routing.d.ts +45 -0
  52. package/dist/with-routing.d.ts.map +1 -0
  53. package/dist/with-routing.js +78 -0
  54. package/dist/with-routing.js.map +1 -0
  55. package/dist/with-view.d.ts +42 -0
  56. package/dist/with-view.d.ts.map +1 -0
  57. package/dist/with-view.js +150 -0
  58. package/dist/with-view.js.map +1 -0
  59. package/package.json +38 -17
  60. package/dist/guards/compose.d.ts +0 -158
  61. package/dist/guards/compose.d.ts.map +0 -1
  62. package/dist/guards/compose.js +0 -188
  63. package/dist/guards/compose.js.map +0 -1
  64. package/dist/guards/helpers.d.ts +0 -62
  65. package/dist/guards/helpers.d.ts.map +0 -1
  66. package/dist/guards/helpers.js +0 -85
  67. package/dist/guards/helpers.js.map +0 -1
  68. package/dist/guards/index.d.ts +0 -20
  69. package/dist/guards/index.d.ts.map +0 -1
  70. package/dist/guards/index.js +0 -18
  71. package/dist/guards/index.js.map +0 -1
  72. package/dist/guards/types.d.ts +0 -22
  73. package/dist/guards/types.d.ts.map +0 -1
  74. package/dist/guards/types.js +0 -2
  75. package/dist/guards/types.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmachines/play-xstate",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "description": "XState v5 adapter for Play Architecture",
5
5
  "keywords": [
6
6
  "actor-model",
@@ -10,7 +10,7 @@
10
10
  "xstate"
11
11
  ],
12
12
  "license": "MIT",
13
- "author": "",
13
+ "author": "XMachines Contributors",
14
14
  "repository": {
15
15
  "type": "git",
16
16
  "url": "git+https://gitlab.com/xmachin-es/xmachines-js.git",
@@ -30,6 +30,14 @@
30
30
  "types": "./dist/index.d.ts",
31
31
  "default": "./dist/index.js"
32
32
  },
33
+ "./routing": {
34
+ "types": "./dist/with-routing.d.ts",
35
+ "default": "./dist/with-routing.js"
36
+ },
37
+ "./view": {
38
+ "types": "./dist/with-view.d.ts",
39
+ "default": "./dist/with-view.js"
40
+ },
33
41
  "./errors": {
34
42
  "types": "./dist/errors.d.ts",
35
43
  "default": "./dist/errors.js"
@@ -43,33 +51,46 @@
43
51
  "build": "vite build && tsc --build",
44
52
  "clean": "rm -rf dist *.tsbuildinfo coverage node_modules/.svelte2tsx-* node_modules/.vite*",
45
53
  "lint": "oxlint .",
54
+ "lint:security": "node ../../scripts/semgrep-scan.mjs",
46
55
  "format": "oxfmt .",
47
56
  "test": "vitest",
48
57
  "test:coverage": "vitest run --coverage"
49
58
  },
50
59
  "dependencies": {
51
- "@xmachines/play": "3.0.0",
52
- "@xmachines/play-actor": "3.0.0",
53
- "@xmachines/play-signals": "3.0.0",
54
- "dequal": "^2.0.3"
60
+ "@xmachines/play-actor": "4.0.0"
55
61
  },
56
62
  "devDependencies": {
57
- "@testing-library/jest-dom": "^6.9.1",
58
- "@types/node": "^26.2.0",
63
+ "@testing-library/jest-dom": "^7.0.1",
64
+ "@types/node": "^26.6.2",
59
65
  "@xmachines/json-render-core": "^0.20.0-xm.4",
60
- "@xmachines/play-router": "3.0.0",
61
- "oxfmt": "^0.64.0",
62
- "oxlint": "^1.79.0",
66
+ "@xmachines/play": "4.0.0",
67
+ "@xmachines/play-router": "4.0.0",
68
+ "@xmachines/play-signals": "4.0.0",
69
+ "@xmachines/play-view": "4.0.0",
70
+ "oxfmt": "^0.68.0",
71
+ "oxlint": "^1.83.0",
63
72
  "typescript": "^5.9.3 || ^6.0.3",
64
- "vite": "^8.0.10",
65
- "vitest": "^4.1.11",
66
- "xstate": "^5.31.0"
73
+ "vite": "^8.3.0",
74
+ "vitest": "^5.0.1",
75
+ "xstate": "^5.33.0"
67
76
  },
68
77
  "peerDependencies": {
69
- "xstate": "^5.31.0"
78
+ "@xmachines/play": "4.0.0",
79
+ "@xmachines/play-router": "4.0.0",
80
+ "@xmachines/play-signals": "4.0.0",
81
+ "@xmachines/play-view": "4.0.0",
82
+ "xstate": "^5.33.0"
83
+ },
84
+ "peerDependenciesMeta": {
85
+ "@xmachines/play-view": {
86
+ "optional": true
87
+ },
88
+ "@xmachines/play-router": {
89
+ "optional": true
90
+ }
70
91
  },
71
92
  "engines": {
72
- "node": ">=22.0.0"
93
+ "node": ">=24.0.0"
73
94
  },
74
- "_devDependencies_note": "xstate appears in both peerDependencies and devDependencies intentionally. devDependencies provides workspace resolution for local builds, tests, and typechecking. peerDependencies declares the consumer version constraint. Both are pinned to ^5.30.0 to prevent drift."
95
+ "_devDependencies_note": "xstate appears in both peerDependencies and devDependencies intentionally. devDependencies provides workspace resolution for local builds, tests, and typechecking. peerDependencies declares the consumer version constraint. Both hold the same range, to prevent drift."
75
96
  }
@@ -1,158 +0,0 @@
1
- import type { GuardPredicate } from "xstate";
2
- import type { Guard, GuardArray } from "./types.js";
3
- import type { MachineContext, EventObject, ParameterizedObject } from "xstate";
4
- /**
5
- * The narrowest public return type of the guard composition helpers.
6
- *
7
- * `GuardPredicate<MachineContext, EventObject, unknown, ParameterizedObject>` is the
8
- * concrete XState guard type with the widest compatibility that uses no `any`.
9
- *
10
- * @public
11
- * @deprecated The next major version removes the guard utilities. Use the
12
- * combinator types of XState directly.
13
- */
14
- export type ComposedGuard = GuardPredicate<MachineContext, EventObject, unknown, ParameterizedObject>;
15
- /**
16
- * Composes the guards with the AND logic, through the and() helper of XState
17
- *
18
- * The function joins more than one guard predicate with the AND semantics: every
19
- * guard must pass, and the composition then succeeds. It uses the built-in `and()`
20
- * helper of XState. The type inference and the serialization of the machine are
21
- * therefore correct.
22
- *
23
- * **Architectural context:** the function supports **Actor Authority (INV-01)**,
24
- * because it composes the guards of a state machine transition declaratively. A
25
- * guard enforces a rule of the business logic, and that rule decides if a
26
- * navigation or an action is valid.
27
- *
28
- * @typeParam TContext - The context type of the state machine
29
- * @typeParam TEvent - The event type
30
- *
31
- * @param guards - The array of the guard predicates, or of the guard names as strings
32
- * @returns The and() guard composition of XState
33
- *
34
- * @throws {Error} When the array of the guards is empty
35
- *
36
- * @example
37
- * An AND composition with named guards
38
- * ```typescript
39
- * import { setup } from "xstate";
40
- * import { composeGuards } from "@xmachines/play-xstate";
41
- *
42
- * const machine = setup({
43
- * guards: {
44
- * isLoggedIn: ({ context }) => !!context.userId,
45
- * hasPermission: ({ context }) => context.permissions.includes('admin'),
46
- * }
47
- * }).createMachine({
48
- * on: {
49
- * accessAdmin: {
50
- * // Both guards must pass
51
- * guard: composeGuards(['isLoggedIn', 'hasPermission']),
52
- * target: 'adminPanel'
53
- * }
54
- * }
55
- * });
56
- * ```
57
- *
58
- * @example
59
- * An AND composition with inline predicates
60
- * ```typescript
61
- * import { composeGuards } from "@xmachines/play-xstate";
62
- *
63
- * guard: composeGuards([
64
- * ({ context }) => context.age >= 18,
65
- * ({ context }) => context.verified
66
- * ])
67
- * ```
68
- *
69
- * @see {@link composeGuardsOr} for the OR composition
70
- * @see {@link negateGuard} for the NOT logic
71
- * @deprecated Use the `and()`, `or()`, and `not()` combinators of XState directly. This helper
72
- * does not compose with a guard slot that `setup()` types, and the next major version removes it.
73
- */
74
- export declare const composeGuards: <TContext = any, TEvent = any>(guards: GuardArray<TContext, TEvent>) => ComposedGuard;
75
- /**
76
- * Composes the guards with the OR logic, through the or() helper of XState
77
- *
78
- * The function joins more than one guard predicate with the OR semantics: one guard
79
- * must pass at least, and the composition then succeeds. It uses the built-in `or()`
80
- * helper of XState, and the type inference is therefore correct.
81
- *
82
- * @typeParam TContext - The context type of the state machine
83
- * @typeParam TEvent - The event type
84
- *
85
- * @param guards - The array of the guard predicates, or of the guard names
86
- * @returns The or() guard composition of XState
87
- *
88
- * @throws {Error} When the array of the guards is empty
89
- *
90
- * @example
91
- * An OR composition with named guards
92
- * ```typescript
93
- * import { setup } from "xstate";
94
- * import { composeGuardsOr } from "@xmachines/play-xstate";
95
- *
96
- * const machine = setup({
97
- * guards: {
98
- * isOwner: ({ context }) => context.role === 'owner',
99
- * isAdmin: ({ context }) => context.role === 'admin'
100
- * }
101
- * }).createMachine({
102
- * on: {
103
- * deleteResource: {
104
- * // One guard is sufficient
105
- * guard: composeGuardsOr(['isOwner', 'isAdmin']),
106
- * actions: 'delete'
107
- * }
108
- * }
109
- * });
110
- * ```
111
- *
112
- * @see {@link composeGuards} for the AND composition
113
- * @see {@link negateGuard} for the NOT logic
114
- * @deprecated Use the `and()`, `or()`, and `not()` combinators of XState directly. This helper
115
- * does not compose with a guard slot that `setup()` types, and the next major version removes it.
116
- */
117
- export declare const composeGuardsOr: <TContext = any, TEvent = any>(guards: GuardArray<TContext, TEvent>) => ComposedGuard;
118
- /**
119
- * Negates a guard, through the not() helper of XState
120
- *
121
- * The function inverts the result of a guard: the guard passes, and NOT then fails;
122
- * the guard fails, and NOT then passes. It uses the built-in `not()` helper of
123
- * XState, and the serialization is therefore correct.
124
- *
125
- * @typeParam TContext - The context type of the state machine
126
- * @typeParam TEvent - The event type
127
- *
128
- * @param guard - The guard predicate to negate, or its name
129
- * @returns The not() guard negation of XState
130
- *
131
- * @example
132
- * A NOT composition with a named guard
133
- * ```typescript
134
- * import { setup } from "xstate";
135
- * import { negateGuard } from "@xmachines/play-xstate";
136
- *
137
- * const machine = setup({
138
- * guards: {
139
- * isGuest: ({ context }) => !context.userId
140
- * }
141
- * }).createMachine({
142
- * on: {
143
- * accessDashboard: {
144
- * // Permit the transition when the user is NOT a guest, which means an authenticated user
145
- * guard: negateGuard('isGuest'),
146
- * target: 'dashboard'
147
- * }
148
- * }
149
- * });
150
- * ```
151
- *
152
- * @see {@link composeGuards} for the AND composition
153
- * @see {@link composeGuardsOr} for the OR composition
154
- * @deprecated Use the `and()`, `or()`, and `not()` combinators of XState directly. This helper
155
- * does not compose with a guard slot that `setup()` types, and the next major version removes it.
156
- */
157
- export declare const negateGuard: <TContext = any, TEvent = any>(guard: Guard<TContext, TEvent> | string) => ComposedGuard;
158
- //# sourceMappingURL=compose.d.ts.map
@@ -1 +0,0 @@
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;AAmB/E;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG,cAAc,CACzC,cAAc,EACd,WAAW,EACX,OAAO,EACP,mBAAmB,CACnB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAEH,eAAO,MAAM,aAAa,GAAI,QAAQ,GAAG,GAAG,EAAE,MAAM,GAAG,GAAG,EACzD,QAAQ,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,KAClC,aAYF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,eAAO,MAAM,eAAe,GAAI,QAAQ,GAAG,GAAG,EAAE,MAAM,GAAG,GAAG,EAC3D,QAAQ,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,KAClC,aAYF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,eAAO,MAAM,WAAW,GAAI,QAAQ,GAAG,GAAG,EAAE,MAAM,GAAG,GAAG,EACvD,OAAO,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,MAAM,KACrC,aAIF,CAAC"}
@@ -1,188 +0,0 @@
1
- import { and, or, not } from "xstate";
2
- import { EmptyGuardArrayError } from "../errors.js";
3
- /**
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
16
- */
17
- const asXStateGuard = (value) => value;
18
- /**
19
- * Composes the guards with the AND logic, through the and() helper of XState
20
- *
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.
25
- *
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.
30
- *
31
- * @typeParam TContext - The context type of the state machine
32
- * @typeParam TEvent - The event type
33
- *
34
- * @param guards - The array of the guard predicates, or of the guard names as strings
35
- * @returns The and() guard composition of XState
36
- *
37
- * @throws {Error} When the array of the guards is empty
38
- *
39
- * @example
40
- * An AND composition with named guards
41
- * ```typescript
42
- * import { setup } from "xstate";
43
- * import { composeGuards } from "@xmachines/play-xstate";
44
- *
45
- * const machine = setup({
46
- * guards: {
47
- * isLoggedIn: ({ context }) => !!context.userId,
48
- * hasPermission: ({ context }) => context.permissions.includes('admin'),
49
- * }
50
- * }).createMachine({
51
- * on: {
52
- * accessAdmin: {
53
- * // Both guards must pass
54
- * guard: composeGuards(['isLoggedIn', 'hasPermission']),
55
- * target: 'adminPanel'
56
- * }
57
- * }
58
- * });
59
- * ```
60
- *
61
- * @example
62
- * An AND composition with inline predicates
63
- * ```typescript
64
- * import { composeGuards } from "@xmachines/play-xstate";
65
- *
66
- * guard: composeGuards([
67
- * ({ context }) => context.age >= 18,
68
- * ({ context }) => context.verified
69
- * ])
70
- * ```
71
- *
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.
76
- */
77
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
- export const composeGuards = (guards) => {
79
- if (guards.length === 0) {
80
- throw new EmptyGuardArrayError("and");
81
- }
82
- if (guards.length === 1) {
83
- // One guard passes through. asXStateGuard gives the reason for the boundary.
84
- return asXStateGuard(guards[0]);
85
- }
86
- // Use the built-in and() of XState, for the type inference and the serialization.
87
- return and(asXStateGuard(guards));
88
- };
89
- /**
90
- * Composes the guards with the OR logic, through the or() helper of XState
91
- *
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.
95
- *
96
- * @typeParam TContext - The context type of the state machine
97
- * @typeParam TEvent - The event type
98
- *
99
- * @param guards - The array of the guard predicates, or of the guard names
100
- * @returns The or() guard composition of XState
101
- *
102
- * @throws {Error} When the array of the guards is empty
103
- *
104
- * @example
105
- * An OR composition with named guards
106
- * ```typescript
107
- * import { setup } from "xstate";
108
- * import { composeGuardsOr } from "@xmachines/play-xstate";
109
- *
110
- * const machine = setup({
111
- * guards: {
112
- * isOwner: ({ context }) => context.role === 'owner',
113
- * isAdmin: ({ context }) => context.role === 'admin'
114
- * }
115
- * }).createMachine({
116
- * on: {
117
- * deleteResource: {
118
- * // One guard is sufficient
119
- * guard: composeGuardsOr(['isOwner', 'isAdmin']),
120
- * actions: 'delete'
121
- * }
122
- * }
123
- * });
124
- * ```
125
- *
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.
130
- */
131
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
132
- export const composeGuardsOr = (guards) => {
133
- if (guards.length === 0) {
134
- throw new EmptyGuardArrayError("or");
135
- }
136
- if (guards.length === 1) {
137
- // One guard passes through. asXStateGuard gives the reason for the boundary.
138
- return asXStateGuard(guards[0]);
139
- }
140
- // Use the built-in or() of XState, for the type inference and the serialization.
141
- return or(asXStateGuard(guards));
142
- };
143
- /**
144
- * Negates a guard, through the not() helper of XState
145
- *
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.
149
- *
150
- * @typeParam TContext - The context type of the state machine
151
- * @typeParam TEvent - The event type
152
- *
153
- * @param guard - The guard predicate to negate, or its name
154
- * @returns The not() guard negation of XState
155
- *
156
- * @example
157
- * A NOT composition with a named guard
158
- * ```typescript
159
- * import { setup } from "xstate";
160
- * import { negateGuard } from "@xmachines/play-xstate";
161
- *
162
- * const machine = setup({
163
- * guards: {
164
- * isGuest: ({ context }) => !context.userId
165
- * }
166
- * }).createMachine({
167
- * on: {
168
- * accessDashboard: {
169
- * // Permit the transition when the user is NOT a guest, which means an authenticated user
170
- * guard: negateGuard('isGuest'),
171
- * target: 'dashboard'
172
- * }
173
- * }
174
- * });
175
- * ```
176
- *
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.
181
- */
182
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
183
- export const negateGuard = (guard) => {
184
- // XState 5.28.0: not() requires one SingleGuardArg shape, and not the Guard
185
- // type of this package. See asXStateGuard.
186
- return not(asXStateGuard(guard));
187
- };
188
- //# sourceMappingURL=compose.js.map
@@ -1 +0,0 @@
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"}
@@ -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"}
@@ -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","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"}
@@ -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"}
@@ -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
@@ -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"}