@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.
Files changed (84) hide show
  1. package/README.md +90 -91
  2. package/dist/define-player.d.ts +3 -3
  3. package/dist/define-player.js +3 -3
  4. package/dist/errors.d.ts +46 -70
  5. package/dist/errors.d.ts.map +1 -1
  6. package/dist/errors.js +69 -77
  7. package/dist/errors.js.map +1 -1
  8. package/dist/guards/compose.d.ts +49 -59
  9. package/dist/guards/compose.d.ts.map +1 -1
  10. package/dist/guards/compose.js +68 -95
  11. package/dist/guards/compose.js.map +1 -1
  12. package/dist/guards/helpers.d.ts +6 -2
  13. package/dist/guards/helpers.d.ts.map +1 -1
  14. package/dist/guards/helpers.js +6 -2
  15. package/dist/guards/helpers.js.map +1 -1
  16. package/dist/guards/index.d.ts +7 -0
  17. package/dist/guards/index.d.ts.map +1 -1
  18. package/dist/guards/index.js +7 -0
  19. package/dist/guards/index.js.map +1 -1
  20. package/dist/guards/types.d.ts +4 -5
  21. package/dist/guards/types.d.ts.map +1 -1
  22. package/dist/index.d.ts +3 -4
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +2 -4
  25. package/dist/index.js.map +1 -1
  26. package/dist/player-actor.d.ts +112 -44
  27. package/dist/player-actor.d.ts.map +1 -1
  28. package/dist/player-actor.js +311 -327
  29. package/dist/player-actor.js.map +1 -1
  30. package/dist/routing/build-url.d.ts +2 -7
  31. package/dist/routing/build-url.d.ts.map +1 -1
  32. package/dist/routing/build-url.js +21 -25
  33. package/dist/routing/build-url.js.map +1 -1
  34. package/dist/routing/derive-current-route.d.ts +32 -0
  35. package/dist/routing/derive-current-route.d.ts.map +1 -1
  36. package/dist/routing/derive-current-route.js +20 -19
  37. package/dist/routing/derive-current-route.js.map +1 -1
  38. package/dist/routing/derive-initial-route.d.ts +1 -4
  39. package/dist/routing/derive-initial-route.d.ts.map +1 -1
  40. package/dist/routing/derive-initial-route.js +1 -4
  41. package/dist/routing/derive-initial-route.js.map +1 -1
  42. package/dist/routing/format-play-route-transitions.d.ts +11 -54
  43. package/dist/routing/format-play-route-transitions.d.ts.map +1 -1
  44. package/dist/routing/format-play-route-transitions.js +65 -125
  45. package/dist/routing/format-play-route-transitions.js.map +1 -1
  46. package/dist/routing/index.d.ts +1 -5
  47. package/dist/routing/index.d.ts.map +1 -1
  48. package/dist/routing/index.js +1 -3
  49. package/dist/routing/index.js.map +1 -1
  50. package/dist/types.d.ts +87 -14
  51. package/dist/types.d.ts.map +1 -1
  52. package/dist/view/derive-current-view.d.ts +49 -0
  53. package/dist/view/derive-current-view.d.ts.map +1 -0
  54. package/dist/view/derive-current-view.js +115 -0
  55. package/dist/view/derive-current-view.js.map +1 -0
  56. package/package.json +22 -22
  57. package/dist/define-player.typecheck.d.ts +0 -2
  58. package/dist/define-player.typecheck.d.ts.map +0 -1
  59. package/dist/define-player.typecheck.js +0 -48
  60. package/dist/define-player.typecheck.js.map +0 -1
  61. package/dist/guards/compose.typecheck.d.ts +0 -2
  62. package/dist/guards/compose.typecheck.d.ts.map +0 -1
  63. package/dist/guards/compose.typecheck.js +0 -22
  64. package/dist/guards/compose.typecheck.js.map +0 -1
  65. package/dist/player-actor.typecheck.d.ts +0 -2
  66. package/dist/player-actor.typecheck.d.ts.map +0 -1
  67. package/dist/player-actor.typecheck.js +0 -30
  68. package/dist/player-actor.typecheck.js.map +0 -1
  69. package/dist/routing/create-routed-machine.d.ts +0 -71
  70. package/dist/routing/create-routed-machine.d.ts.map +0 -1
  71. package/dist/routing/create-routed-machine.js +0 -71
  72. package/dist/routing/create-routed-machine.js.map +0 -1
  73. package/dist/routing/play-route-event.typecheck.d.ts +0 -2
  74. package/dist/routing/play-route-event.typecheck.d.ts.map +0 -1
  75. package/dist/routing/play-route-event.typecheck.js +0 -43
  76. package/dist/routing/play-route-event.typecheck.js.map +0 -1
  77. package/dist/routing/schemas.d.ts +0 -99
  78. package/dist/routing/schemas.d.ts.map +0 -1
  79. package/dist/routing/schemas.js +0 -30
  80. package/dist/routing/schemas.js.map +0 -1
  81. package/dist/schemas.d.ts +0 -28
  82. package/dist/schemas.d.ts.map +0 -1
  83. package/dist/schemas.js +0 -29
  84. package/dist/schemas.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmachines/play-xstate",
3
- "version": "2.0.0-alpha.1",
3
+ "version": "2.0.0",
4
4
  "description": "XState v5 adapter for Play Architecture",
5
5
  "keywords": [
6
6
  "actor-model",
@@ -13,7 +13,7 @@
13
13
  "author": "",
14
14
  "repository": {
15
15
  "type": "git",
16
- "url": "git+ssh://git@gitlab.com/xmachin-es/xmachines-js.git",
16
+ "url": "git+https://gitlab.com/xmachin-es/xmachines-js.git",
17
17
  "directory": "packages/play-xstate"
18
18
  },
19
19
  "files": [
@@ -22,53 +22,53 @@
22
22
  "LICENSE"
23
23
  ],
24
24
  "type": "module",
25
+ "sideEffects": false,
25
26
  "main": "./dist/index.js",
26
27
  "types": "./dist/index.d.ts",
27
28
  "exports": {
28
29
  ".": {
29
- "source": "./src/index.ts",
30
30
  "types": "./dist/index.d.ts",
31
- "import": "./dist/index.js"
31
+ "default": "./dist/index.js"
32
32
  },
33
33
  "./errors": {
34
- "source": "./src/errors.ts",
35
34
  "types": "./dist/errors.d.ts",
36
- "import": "./dist/errors.js"
37
- }
35
+ "default": "./dist/errors.js"
36
+ },
37
+ "./package.json": "./package.json"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
42
  "scripts": {
43
- "build": "tsc --build",
43
+ "build": "vite build && tsc --build",
44
44
  "clean": "rm -rf dist *.tsbuildinfo coverage node_modules/.svelte2tsx-* node_modules/.vite*",
45
45
  "lint": "oxlint .",
46
46
  "format": "oxfmt .",
47
- "test": "vitest",
48
- "prepublishOnly": "npm run build"
47
+ "test": "vitest"
49
48
  },
50
49
  "dependencies": {
51
- "@xmachines/play": "2.0.0-alpha.1",
52
- "@xmachines/play-actor": "2.0.0-alpha.1",
53
- "@xmachines/play-signals": "2.0.0-alpha.1",
50
+ "@xmachines/play": "2.0.0",
51
+ "@xmachines/play-actor": "2.0.0",
52
+ "@xmachines/play-signals": "2.0.0",
54
53
  "dequal": "^2.0.3"
55
54
  },
56
55
  "devDependencies": {
57
56
  "@testing-library/jest-dom": "^6.9.1",
58
- "@types/node": "^26.1.1",
59
- "@xmachines/play-router": "2.0.0-alpha.1",
60
- "@xmachines/shared": "2.0.0-alpha.1",
61
- "oxfmt": "^0.58.0",
62
- "oxlint": "^1.73.0",
57
+ "@types/node": "^26.2.0",
58
+ "@xmachines/json-render-core": "^0.20.0-xm.2",
59
+ "@xmachines/play-router": "2.0.0",
60
+ "oxfmt": "^0.64.0",
61
+ "oxlint": "^1.79.0",
63
62
  "typescript": "^5.9.3 || ^6.0.3",
64
- "vitest": "^4.1.10",
65
- "xstate": "^6.0.0-alpha.20"
63
+ "vite": "^8.0.10",
64
+ "vitest": "^4.1.11",
65
+ "xstate": "^5.31.0"
66
66
  },
67
67
  "peerDependencies": {
68
- "xstate": "^6.0.0-alpha.20"
68
+ "xstate": "^5.31.0"
69
69
  },
70
70
  "engines": {
71
71
  "node": ">=22.0.0"
72
72
  },
73
- "_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 ^6.0.0-alpha.20 to prevent drift."
73
+ "_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."
74
74
  }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=define-player.typecheck.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"define-player.typecheck.d.ts","sourceRoot":"","sources":["../src/define-player.typecheck.ts"],"names":[],"mappings":""}
@@ -1,48 +0,0 @@
1
- import { setup, types } from "xstate";
2
- import { emptyEventSchema } from "./schemas.js";
3
- import { definePlayer } from "./define-player.js";
4
- const machine = setup({
5
- schemas: {
6
- context: types(),
7
- input: types(),
8
- events: {
9
- inc: emptyEventSchema,
10
- },
11
- },
12
- }).createMachine({
13
- context: ({ input }) => ({ count: input.count }),
14
- initial: "active",
15
- states: {
16
- active: {
17
- on: {
18
- // XState v6: transitions are functions returning a context patch.
19
- inc: ({ context }) => ({ context: { count: context.count + 1 } }),
20
- },
21
- },
22
- },
23
- });
24
- const createPlayer = definePlayer({
25
- machine,
26
- options: {
27
- onTransition: (actor, prevState, nextState) => {
28
- const actorNotAny = false;
29
- const prevNotAny = false;
30
- const nextNotAny = false;
31
- void actorNotAny;
32
- void prevNotAny;
33
- void nextNotAny;
34
- },
35
- },
36
- });
37
- const actor = createPlayer({ count: 1 });
38
- const snapshot = actor.getSnapshot();
39
- const restoredActor = createPlayer({ count: 1 }, { snapshot });
40
- const returnNotAny = false;
41
- const restoredReturnNotAny = false;
42
- void returnNotAny;
43
- void restoredReturnNotAny;
44
- // @ts-expect-error factory input must match machine input shape
45
- createPlayer("invalid");
46
- // @ts-expect-error snapshot must be nested under the `snapshot` key
47
- createPlayer({ count: 1 }, { persisted: snapshot });
48
- //# sourceMappingURL=define-player.typecheck.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"define-player.typecheck.js","sourceRoot":"","sources":["../src/define-player.typecheck.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAKlD,MAAM,OAAO,GAAG,KAAK,CAAC;IACrB,OAAO,EAAE;QACR,OAAO,EAAE,KAAK,EAAqB;QACnC,KAAK,EAAE,KAAK,EAAqB;QACjC,MAAM,EAAE;YACP,GAAG,EAAE,gBAAgB;SACrB;KACD;CACD,CAAC,CAAC,aAAa,CAAC;IAChB,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;IAChD,OAAO,EAAE,QAAQ;IACjB,MAAM,EAAE;QACP,MAAM,EAAE;YACP,EAAE,EAAE;gBACH,kEAAkE;gBAClE,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,GAAG,CAAC,EAAE,EAAE,CAAC;aACjE;SACD;KACD;CACD,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,YAAY,CAAC;IACjC,OAAO;IACP,OAAO,EAAE;QACR,YAAY,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE;YAK7C,MAAM,WAAW,GAA4B,KAAK,CAAC;YACnD,MAAM,UAAU,GAA2B,KAAK,CAAC;YACjD,MAAM,UAAU,GAA2B,KAAK,CAAC;YAEjD,KAAK,WAAW,CAAC;YACjB,KAAK,UAAU,CAAC;YAChB,KAAK,UAAU,CAAC;QACjB,CAAC;KACD;CACD,CAAC,CAAC;AAEH,MAAM,KAAK,GAAG,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;AACzC,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;AACrC,MAAM,aAAa,GAAG,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;AAI/D,MAAM,YAAY,GAA6B,KAAK,CAAC;AACrD,MAAM,oBAAoB,GAAqC,KAAK,CAAC;AACrE,KAAK,YAAY,CAAC;AAClB,KAAK,oBAAoB,CAAC;AAE1B,gEAAgE;AAChE,YAAY,CAAC,SAAS,CAAC,CAAC;AAExB,oEAAoE;AACpE,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=compose.typecheck.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compose.typecheck.d.ts","sourceRoot":"","sources":["../../src/guards/compose.typecheck.ts"],"names":[],"mappings":""}
@@ -1,22 +0,0 @@
1
- /**
2
- * Type-level contract for guard composition: declared Guard<TContext> values
3
- * and inline predicates must compose without casts, exactly as the JSDoc
4
- * examples show.
5
- */
6
- import { composeGuards, composeGuardsOr, negateGuard } from "./compose.js";
7
- const isAdult = ({ context }) => context.age >= 18;
8
- // Declared typed guards compose without casts.
9
- const both = composeGuards([isAdult, ({ context }) => context.verified]);
10
- // The documented inline-predicate example compiles as written (no annotations).
11
- const isEligible = composeGuards([
12
- ({ context }) => context.age >= 18,
13
- ({ context }) => context.verified,
14
- ]);
15
- // OR and NOT accept typed guards too.
16
- const either = composeGuardsOr([isAdult, "isVerified"]);
17
- const notAdult = negateGuard(isAdult);
18
- void both;
19
- void isEligible;
20
- void either;
21
- void notAdult;
22
- //# sourceMappingURL=compose.typecheck.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compose.typecheck.js","sourceRoot":"","sources":["../../src/guards/compose.typecheck.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAK3E,MAAM,OAAO,GAAe,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC;AAE/D,+CAA+C;AAC/C,MAAM,IAAI,GAAG,aAAa,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,EAAoB,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;AAE3F,gFAAgF;AAChF,MAAM,UAAU,GAAG,aAAa,CAAC;IAChC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,IAAI,EAAE;IAClC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ;CACjC,CAAC,CAAC;AAEH,sCAAsC;AACtC,MAAM,MAAM,GAAG,eAAe,CAAC,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC;AACxD,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;AAEtC,KAAK,IAAI,CAAC;AACV,KAAK,UAAU,CAAC;AAChB,KAAK,MAAM,CAAC;AACZ,KAAK,QAAQ,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=player-actor.typecheck.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"player-actor.typecheck.d.ts","sourceRoot":"","sources":["../src/player-actor.typecheck.ts"],"names":[],"mappings":""}
@@ -1,30 +0,0 @@
1
- import { setup, types } from "xstate";
2
- import { emptyEventSchema } from "./schemas.js";
3
- import { definePlayer } from "./define-player.js";
4
- const machine = setup({
5
- schemas: {
6
- context: types(),
7
- input: types(),
8
- events: {
9
- noop: emptyEventSchema,
10
- },
11
- },
12
- }).createMachine({
13
- context: ({ input }) => ({ value: input.value }),
14
- initial: "idle",
15
- states: {
16
- idle: {},
17
- },
18
- });
19
- const createPlayer = definePlayer({ machine });
20
- const actor = createPlayer({ value: 1 });
21
- const restoredActor = createPlayer({ value: 1 }, { snapshot: actor.getSnapshot() });
22
- // Verify actor instances are created successfully
23
- void actor;
24
- void restoredActor;
25
- // CONS-16: [key: string]: unknown index signature removed.
26
- // Accessing unknown properties on PlayerActor is now a type error (correct behavior).
27
- // @ts-expect-error — unknown fields no longer accessible via index signature
28
- const unknownField = actor["custom-extension-field"];
29
- void unknownField;
30
- //# sourceMappingURL=player-actor.typecheck.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"player-actor.typecheck.js","sourceRoot":"","sources":["../src/player-actor.typecheck.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,OAAO,GAAG,KAAK,CAAC;IACrB,OAAO,EAAE;QACR,OAAO,EAAE,KAAK,EAAqB;QACnC,KAAK,EAAE,KAAK,EAAqB;QACjC,MAAM,EAAE;YACP,IAAI,EAAE,gBAAgB;SACtB;KACD;CACD,CAAC,CAAC,aAAa,CAAC;IAChB,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;IAChD,OAAO,EAAE,MAAM;IACf,MAAM,EAAE;QACP,IAAI,EAAE,EAAE;KACR;CACD,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,YAAY,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;AAC/C,MAAM,KAAK,GAAG,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;AACzC,MAAM,aAAa,GAAG,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AAEpF,kDAAkD;AAClD,KAAK,KAAK,CAAC;AACX,KAAK,aAAa,CAAC;AAEnB,2DAA2D;AAC3D,sFAAsF;AACtF,6EAA6E;AAC7E,MAAM,YAAY,GAAG,KAAK,CAAC,wBAAwB,CAAC,CAAC;AACrD,KAAK,YAAY,CAAC"}
@@ -1,71 +0,0 @@
1
- /**
2
- * Structural constraint for `setup(...)` return values: anything exposing a
3
- * `createMachine` function. Kept structural (rather than importing XState's
4
- * `SetupReturn`) so the wrapper stays agnostic to that type's many generics.
5
- */
6
- export type SetupLike = {
7
- createMachine: (...args: never[]) => unknown;
8
- };
9
- /**
10
- * Returns a `createMachine` that routes: identical signature to the setup's
11
- * own `createMachine`, with {@link formatPlayRouteTransitions} applied to the
12
- * config at runtime.
13
- *
14
- * ### Why this exists
15
- *
16
- * `formatPlayRouteTransitions(config)` accepts a loosely-typed config. A config
17
- * authored as a standalone value loses inline transition-function parameter
18
- * inference entirely (implicit-any under strict mode), and even the inline
19
- * `setup().createMachine(formatPlayRouteTransitions({ ... }))` form depends on
20
- * TypeScript threading contextual typing through two generic calls.
21
- *
22
- * This wrapper removes the question: it is typed as the setup's own
23
- * `createMachine`, so the config is contextually typed exactly as if passed to
24
- * `setup().createMachine(...)` directly — transition-function args infer from
25
- * the setup's schemas, sibling targets are validated, and the returned machine
26
- * keeps its full literal state-value typing.
27
- *
28
- * Typing is *identical to native* — including its current gaps: as of xstate
29
- * 6.0.0-alpha.20, `event` and `context` reads in transition args are fully
30
- * typed, while returned context patches are property-typed but still carry a
31
- * loose index signature in the alpha itself. Expect that to tighten upstream
32
- * without changes here.
33
- *
34
- * @example
35
- * ```typescript
36
- * import { setup, types } from "xstate";
37
- * import { createRoutedMachine, playMetaSchema, playRouteEventSchema } from "@xmachines/play-xstate";
38
- *
39
- * const authSetup = setup({
40
- * schemas: {
41
- * context: types<{ isAuthenticated: boolean }>(),
42
- * events: { "play.route": playRouteEventSchema },
43
- * meta: playMetaSchema,
44
- * },
45
- * });
46
- *
47
- * const machine = createRoutedMachine(authSetup)({
48
- * initial: "home",
49
- * context: { isAuthenticated: false },
50
- * states: {
51
- * home: { id: "home", meta: { route: "/" } },
52
- * login: { id: "login", meta: { route: "/login" } },
53
- * },
54
- * });
55
- * // ({ context }) params in transitions infer from the setup schemas —
56
- * // no explicit annotations needed.
57
- * ```
58
- *
59
- * Note: routes are injected at runtime, so the machine's static type does not
60
- * gain an `xstate.route` event for them — `play.route` (declared in the
61
- * setup's event schemas) remains the typed public API; native `xstate.route`
62
- * interop is runtime-only.
63
- *
64
- * @param s - A `setup(...)` return value (anything with `createMachine`).
65
- * @returns A function with the same signature as `s.createMachine` that
66
- * applies {@link formatPlayRouteTransitions} before creating the machine.
67
- *
68
- * @see {@link formatPlayRouteTransitions} for the routing transform itself
69
- */
70
- export declare const createRoutedMachine: <TSetup extends SetupLike>(s: TSetup) => TSetup["createMachine"];
71
- //# sourceMappingURL=create-routed-machine.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-routed-machine.d.ts","sourceRoot":"","sources":["../../src/routing/create-routed-machine.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG;IAGvB,aAAa,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC;CAC7C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,eAAO,MAAM,mBAAmB,GAAI,MAAM,SAAS,SAAS,EAAE,GAAG,MAAM,KAAG,MAAM,CAAC,eAAe,CASjE,CAAC"}
@@ -1,71 +0,0 @@
1
- import { formatPlayRouteTransitions, } from "./format-play-route-transitions.js";
2
- /**
3
- * Returns a `createMachine` that routes: identical signature to the setup's
4
- * own `createMachine`, with {@link formatPlayRouteTransitions} applied to the
5
- * config at runtime.
6
- *
7
- * ### Why this exists
8
- *
9
- * `formatPlayRouteTransitions(config)` accepts a loosely-typed config. A config
10
- * authored as a standalone value loses inline transition-function parameter
11
- * inference entirely (implicit-any under strict mode), and even the inline
12
- * `setup().createMachine(formatPlayRouteTransitions({ ... }))` form depends on
13
- * TypeScript threading contextual typing through two generic calls.
14
- *
15
- * This wrapper removes the question: it is typed as the setup's own
16
- * `createMachine`, so the config is contextually typed exactly as if passed to
17
- * `setup().createMachine(...)` directly — transition-function args infer from
18
- * the setup's schemas, sibling targets are validated, and the returned machine
19
- * keeps its full literal state-value typing.
20
- *
21
- * Typing is *identical to native* — including its current gaps: as of xstate
22
- * 6.0.0-alpha.20, `event` and `context` reads in transition args are fully
23
- * typed, while returned context patches are property-typed but still carry a
24
- * loose index signature in the alpha itself. Expect that to tighten upstream
25
- * without changes here.
26
- *
27
- * @example
28
- * ```typescript
29
- * import { setup, types } from "xstate";
30
- * import { createRoutedMachine, playMetaSchema, playRouteEventSchema } from "@xmachines/play-xstate";
31
- *
32
- * const authSetup = setup({
33
- * schemas: {
34
- * context: types<{ isAuthenticated: boolean }>(),
35
- * events: { "play.route": playRouteEventSchema },
36
- * meta: playMetaSchema,
37
- * },
38
- * });
39
- *
40
- * const machine = createRoutedMachine(authSetup)({
41
- * initial: "home",
42
- * context: { isAuthenticated: false },
43
- * states: {
44
- * home: { id: "home", meta: { route: "/" } },
45
- * login: { id: "login", meta: { route: "/login" } },
46
- * },
47
- * });
48
- * // ({ context }) params in transitions infer from the setup schemas —
49
- * // no explicit annotations needed.
50
- * ```
51
- *
52
- * Note: routes are injected at runtime, so the machine's static type does not
53
- * gain an `xstate.route` event for them — `play.route` (declared in the
54
- * setup's event schemas) remains the typed public API; native `xstate.route`
55
- * interop is runtime-only.
56
- *
57
- * @param s - A `setup(...)` return value (anything with `createMachine`).
58
- * @returns A function with the same signature as `s.createMachine` that
59
- * applies {@link formatPlayRouteTransitions} before creating the machine.
60
- *
61
- * @see {@link formatPlayRouteTransitions} for the routing transform itself
62
- */
63
- export const createRoutedMachine = (s) =>
64
- // The runtime transform only ADDS behavior (native route configs + the
65
- // play.route forwarder) and preserves the config's own shape, so exposing
66
- // the setup's exact createMachine signature keeps native config typing.
67
- ((config) =>
68
- // One internal widening cast: the `never[]` constraint that keeps
69
- // SetupLike any-free also makes the parameter uncallable directly.
70
- s.createMachine(formatPlayRouteTransitions(config)));
71
- //# sourceMappingURL=create-routed-machine.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-routed-machine.js","sourceRoot":"","sources":["../../src/routing/create-routed-machine.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,0BAA0B,GAE1B,MAAM,oCAAoC,CAAC;AAa5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAA2B,CAAS,EAA2B,EAAE;AACnG,uEAAuE;AACvE,0EAA0E;AAC1E,wEAAwE;AACxE,CAAC,CAAC,MAA0B,EAAE,EAAE;AAC/B,kEAAkE;AAClE,mEAAmE;AAClE,CAAC,CAAC,aAA8C,CAChD,0BAA0B,CAAC,MAAM,CAAC,CAClC,CAA4B,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=play-route-event.typecheck.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"play-route-event.typecheck.d.ts","sourceRoot":"","sources":["../../src/routing/play-route-event.typecheck.ts"],"names":[],"mappings":""}
@@ -1,43 +0,0 @@
1
- /**
2
- * Type-level contract for the play.route event payload as machines receive it
3
- * through playRouteEventSchema. Pins the requirements the hand-written v5
4
- * union enforced: `to` is required and string-typed; params/query/match are
5
- * omittable; values constructed as PlayRouteEvent (router bridges) remain
6
- * assignable.
7
- */
8
- import { setup } from "xstate";
9
- import { playRouteEventSchema } from "./schemas.js";
10
- const s = setup({
11
- schemas: {
12
- events: { "play.route": playRouteEventSchema },
13
- },
14
- });
15
- const m = s.createMachine({ initial: "a", states: { a: {} } });
16
- // Minimal send: optional payload fields are omittable.
17
- const minimal = { type: "play.route", to: "#home" };
18
- // Full send: every documented field accepted.
19
- const full = {
20
- type: "play.route",
21
- to: "#profile",
22
- params: { username: "alice" },
23
- query: { tab: "posts" },
24
- match: {},
25
- };
26
- // @ts-expect-error `to` is required — a routeless play.route must not compile
27
- const missingTo = { type: "play.route" };
28
- // @ts-expect-error `to` must be a string
29
- const badTo = { type: "play.route", to: 123 };
30
- const badParams = {
31
- type: "play.route",
32
- to: "#p",
33
- // @ts-expect-error `params` values must be strings
34
- params: { n: 42 },
35
- };
36
- const fromBridge = bridgeEvent;
37
- void fromBridge;
38
- void minimal;
39
- void full;
40
- void missingTo;
41
- void badTo;
42
- void badParams;
43
- //# sourceMappingURL=play-route-event.typecheck.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"play-route-event.typecheck.js","sourceRoot":"","sources":["../../src/routing/play-route-event.typecheck.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,KAAK,EAAuB,MAAM,QAAQ,CAAC;AAEpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,CAAC,GAAG,KAAK,CAAC;IACf,OAAO,EAAE;QACR,MAAM,EAAE,EAAE,YAAY,EAAE,oBAAoB,EAAE;KAC9C;CACD,CAAC,CAAC;AACH,MAAM,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AAG/D,uDAAuD;AACvD,MAAM,OAAO,GAAyB,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC;AAE1E,8CAA8C;AAC9C,MAAM,IAAI,GAAyB;IAClC,IAAI,EAAE,YAAY;IAClB,EAAE,EAAE,UAAU;IACd,MAAM,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE;IAC7B,KAAK,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE;IACvB,KAAK,EAAE,EAAE;CACT,CAAC;AAEF,8EAA8E;AAC9E,MAAM,SAAS,GAAyB,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;AAE/D,yCAAyC;AACzC,MAAM,KAAK,GAAyB,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC;AAEpE,MAAM,SAAS,GAAyB;IACvC,IAAI,EAAE,YAAY;IAClB,EAAE,EAAE,IAAI;IACR,mDAAmD;IACnD,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE;CACjB,CAAC;AAKF,MAAM,UAAU,GAAyB,WAAW,CAAC;AAErD,KAAK,UAAU,CAAC;AAChB,KAAK,OAAO,CAAC;AACb,KAAK,IAAI,CAAC;AACV,KAAK,SAAS,CAAC;AACf,KAAK,KAAK,CAAC;AACX,KAAK,SAAS,CAAC"}
@@ -1,99 +0,0 @@
1
- import type { PlayRouteEvent } from "@xmachines/play-router";
2
- import type { PlaySpec } from "@xmachines/play-actor";
3
- import type { RouteMetadata } from "./types.js";
4
- /**
5
- * Event schema for the `play.route` navigation event, for use in an XState v6
6
- * `schemas.events` map.
7
- *
8
- * XState v6 declares machine events as a map of event type to payload schema
9
- * (payloads exclude the `type` field). Every Play machine handles `play.route`,
10
- * so this constant is the single source of truth for its payload shape —
11
- * declare it instead of re-deriving the payload shape per machine. The payload
12
- * is authored explicitly (not `Omit<PlayRouteEvent, "type">`): `Omit` over
13
- * PlayRouteEvent's index signature collapses the named props and would erase
14
- * all payload checking.
15
- *
16
- * @example
17
- * ```typescript
18
- * import { setup } from "xstate";
19
- * import {
20
- * emptyEventSchema,
21
- * playMetaSchema,
22
- * playRouteEventSchema,
23
- * } from "@xmachines/play-xstate";
24
- *
25
- * const authSetup = setup({
26
- * schemas: {
27
- * events: {
28
- * "play.route": playRouteEventSchema,
29
- * "auth.logout": emptyEventSchema,
30
- * },
31
- * meta: playMetaSchema,
32
- * },
33
- * });
34
- * ```
35
- *
36
- * @see {@link playMetaSchema} for the companion state-meta schema
37
- */
38
- /**
39
- * Adds `TExtra` as an optional-by-union extension of `TBase`.
40
- *
41
- * XState v6's `InferEvents` wraps every event payload in `Required<>` (to
42
- * undo Zod-style optional inference), which would make `?`-marked fields
43
- * mandatory on every send. Encoding optionality as a union sidesteps that:
44
- * `Required<>` distributes over the members, each of which is already fully
45
- * required. Use it for your own event payload schemas with optional fields.
46
- *
47
- * @example
48
- * ```typescript
49
- * type SavePayload = WithOptional<{ id: string }, { draft: boolean }>;
50
- * // accepts { id } and { id, draft } — and survives InferEvents' Required<>
51
- * ```
52
- */
53
- export type WithOptional<TBase, TExtra> = TBase | (TBase & TExtra);
54
- /**
55
- * The `play.route` event payload as machines receive it: `to` required;
56
- * `params`/`query`/`match` encoded as optional-by-union so they stay omittable
57
- * through XState v6's `Required<>` event inference.
58
- */
59
- export type PlayRoutePayload = WithOptional<WithOptional<WithOptional<{
60
- to: PlayRouteEvent["to"];
61
- }, {
62
- params: Record<string, string>;
63
- }>, {
64
- query: Record<string, string>;
65
- }>, {
66
- match: unknown;
67
- }>;
68
- export declare const playRouteEventSchema: import("xstate").TypeSchema<PlayRoutePayload>;
69
- /**
70
- * State meta schema for Play's routing/view metadata, for use as an XState v6
71
- * `schemas.meta` declaration.
72
- *
73
- * XState v6 types state `meta` as `never` unless a meta schema is declared, so
74
- * every machine that carries `meta.route` templates or `meta.view` specs needs
75
- * this schema. `route` accepts both the string template form
76
- * (`"/profile/:username"`) and the object form (`{ path, title }` — see
77
- * {@link RouteMetadata}); `view` is a Play view {@link PlaySpec}.
78
- *
79
- * @example
80
- * ```typescript
81
- * import { createMachine } from "xstate";
82
- * import { playMetaSchema } from "@xmachines/play-xstate";
83
- *
84
- * const machine = createMachine({
85
- * schemas: { meta: playMetaSchema },
86
- * initial: "home",
87
- * states: {
88
- * home: { id: "home", meta: { route: "/" } },
89
- * },
90
- * });
91
- * ```
92
- *
93
- * @see {@link playRouteEventSchema} for the companion `play.route` event schema
94
- */
95
- export declare const playMetaSchema: import("xstate").TypeSchema<{
96
- route?: RouteMetadata;
97
- view?: PlaySpec;
98
- }>;
99
- //# sourceMappingURL=schemas.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/routing/schemas.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,YAAY,CAAC,KAAK,EAAE,MAAM,IAAI,KAAK,GAAG,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC;AAEnE;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,YAAY,CAC1C,YAAY,CACX,YAAY,CAAC;IAAE,EAAE,EAAE,cAAc,CAAC,IAAI,CAAC,CAAA;CAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAAC,EAC9E;IAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CACjC,EACD;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,CAClB,CAAC;AAEF,eAAO,MAAM,oBAAoB,+CAA4B,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,cAAc;YAAmB,aAAa;WAAS,QAAQ;EAAK,CAAC"}
@@ -1,30 +0,0 @@
1
- import { types } from "xstate";
2
- export const playRouteEventSchema = types();
3
- /**
4
- * State meta schema for Play's routing/view metadata, for use as an XState v6
5
- * `schemas.meta` declaration.
6
- *
7
- * XState v6 types state `meta` as `never` unless a meta schema is declared, so
8
- * every machine that carries `meta.route` templates or `meta.view` specs needs
9
- * this schema. `route` accepts both the string template form
10
- * (`"/profile/:username"`) and the object form (`{ path, title }` — see
11
- * {@link RouteMetadata}); `view` is a Play view {@link PlaySpec}.
12
- *
13
- * @example
14
- * ```typescript
15
- * import { createMachine } from "xstate";
16
- * import { playMetaSchema } from "@xmachines/play-xstate";
17
- *
18
- * const machine = createMachine({
19
- * schemas: { meta: playMetaSchema },
20
- * initial: "home",
21
- * states: {
22
- * home: { id: "home", meta: { route: "/" } },
23
- * },
24
- * });
25
- * ```
26
- *
27
- * @see {@link playRouteEventSchema} for the companion `play.route` event schema
28
- */
29
- export const playMetaSchema = types();
30
- //# sourceMappingURL=schemas.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/routing/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAqE/B,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAoB,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAA8C,CAAC"}
package/dist/schemas.d.ts DELETED
@@ -1,28 +0,0 @@
1
- /**
2
- * Event schema for a payload-less event, for use in an XState v6
3
- * `schemas.events` map.
4
- *
5
- * Most Play machines carry events with no payload (`auth.logout`, `timer`,
6
- * …) — declare them with this constant instead of re-spelling
7
- * `types<Record<string, never>>()` per event.
8
- *
9
- * @example
10
- * ```typescript
11
- * import { setup } from "xstate";
12
- * import { emptyEventSchema, playRouteEventSchema } from "@xmachines/play-xstate";
13
- *
14
- * setup({
15
- * schemas: {
16
- * events: {
17
- * "play.route": playRouteEventSchema,
18
- * "auth.logout": emptyEventSchema,
19
- * },
20
- * },
21
- * });
22
- * ```
23
- *
24
- * @see {@link playRouteEventSchema} and {@link playMetaSchema} for the routing
25
- * schema constants
26
- */
27
- export declare const emptyEventSchema: import("xstate").TypeSchema<Record<string, never>>;
28
- //# sourceMappingURL=schemas.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,gBAAgB,oDAAiC,CAAC"}
package/dist/schemas.js DELETED
@@ -1,29 +0,0 @@
1
- import { types } from "xstate";
2
- /**
3
- * Event schema for a payload-less event, for use in an XState v6
4
- * `schemas.events` map.
5
- *
6
- * Most Play machines carry events with no payload (`auth.logout`, `timer`,
7
- * …) — declare them with this constant instead of re-spelling
8
- * `types<Record<string, never>>()` per event.
9
- *
10
- * @example
11
- * ```typescript
12
- * import { setup } from "xstate";
13
- * import { emptyEventSchema, playRouteEventSchema } from "@xmachines/play-xstate";
14
- *
15
- * setup({
16
- * schemas: {
17
- * events: {
18
- * "play.route": playRouteEventSchema,
19
- * "auth.logout": emptyEventSchema,
20
- * },
21
- * },
22
- * });
23
- * ```
24
- *
25
- * @see {@link playRouteEventSchema} and {@link playMetaSchema} for the routing
26
- * schema constants
27
- */
28
- export const emptyEventSchema = types();
29
- //# sourceMappingURL=schemas.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE/B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAyB,CAAC"}