@xmachines/play-router 4.0.0 → 5.0.1
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 +25 -14
- package/dist/base-route-map.d.ts +17 -12
- package/dist/base-route-map.d.ts.map +1 -1
- package/dist/base-route-map.js +101 -25
- package/dist/base-route-map.js.map +1 -1
- package/dist/create-route-map-from-tree.d.ts +1 -1
- package/dist/create-route-map-from-tree.js +1 -1
- package/dist/errors.js +3 -3
- package/dist/errors.js.map +1 -1
- package/dist/find-route.d.ts +13 -1
- package/dist/find-route.d.ts.map +1 -1
- package/dist/find-route.js +22 -10
- package/dist/find-route.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/provider-lifecycle.d.ts +13 -5
- package/dist/provider-lifecycle.d.ts.map +1 -1
- package/dist/provider-lifecycle.js +9 -4
- package/dist/provider-lifecycle.js.map +1 -1
- package/dist/router-bridge-base.d.ts +36 -20
- package/dist/router-bridge-base.d.ts.map +1 -1
- package/dist/router-bridge-base.js +79 -72
- package/dist/router-bridge-base.js.map +1 -1
- package/dist/router-sync.d.ts +2 -26
- package/dist/router-sync.d.ts.map +1 -1
- package/dist/router-sync.js +8 -41
- package/dist/router-sync.js.map +1 -1
- package/dist/types.d.ts +31 -26
- package/dist/types.d.ts.map +1 -1
- package/dist/xstate/create-route-map.d.ts +2 -2
- package/dist/xstate/create-route-map.d.ts.map +1 -1
- package/dist/xstate/create-route-map.js +6 -3
- package/dist/xstate/create-route-map.js.map +1 -1
- package/dist/xstate/extract-routes.d.ts +2 -1
- package/dist/xstate/extract-routes.d.ts.map +1 -1
- package/dist/xstate/extract-routes.js +5 -5
- package/dist/xstate/extract-routes.js.map +1 -1
- package/package.json +15 -12
package/dist/router-sync.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-sync.js","sourceRoot":"","sources":["../src/router-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"router-sync.js","sourceRoot":"","sources":["../src/router-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,GAGhB,MAAM,qBAAqB,CAAC;AAmB7B;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAC5B,QAAgB,EAChB,QAA0B,EAC1B,aAA4E;IAE5E,MAAM,OAAO,GAAG,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACpD,IAAI,CAAC,OAAO,EAAE,CAAC;QACd,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IACjC,CAAC;IAED,OAAO;QACN,EAAE,EAAE,OAAO;QACX,MAAM,EAAE,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC;KACxC,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,UAAU,kBAAkB,CACjC,QAAgB,EAChB,OAAe,EACf,OAAwB;IAExB,oFAAoF;IACpF,mDAAmD;IACnD,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC9C,IAAI,CAAC,MAAM,CAAC,aAAa;QAAE,OAAO,EAAE,CAAC;IACrC,4EAA4E;IAC5E,oFAAoF;IACpF,6EAA6E;IAC7E,MAAM,UAAU,GAAmB,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACxE,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC5C,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IACvC,yFAAyF;IACzF,MAAM,OAAO,GAAG,MAAM,CAAC,aAAa,CAAC;IACrC,wFAAwF;IACxF,u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C;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAClC,OAAmC;IAEnC,MAAM,QAAQ,GAAG,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpD,IAAI,QAAQ,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAEnC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACtC,IAAI,CAAC,KAAK,CAAC,EAAE;QAAE,OAAO,IAAI,CAAC;IAE3B,iFAAiF;IACjF,6EAA6E;IAC7E,8EAA8E;IAC9E,8EAA8E;IAC9E,MAAM;IACN,MAAM,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC;IAChE,OAAO;QACN,QAAQ;QACR,KAAK,EAAE;YACN,IAAI,EAAE,YAAY;YAClB,EAAE;YACF,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,EAAE;YAC1B,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;SACzC;KACD,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { BasePathOptions } from "@xmachines/play-url";
|
|
2
|
-
import type {
|
|
1
|
+
import type { BasePathOptions, CompileOptions, PatternCache } from "@xmachines/play-url";
|
|
2
|
+
import type { ReadonlyAtom } from "@xmachines/play-atom";
|
|
3
3
|
/**
|
|
4
4
|
* The type definitions of the routing protocol of @xmachines/play-router
|
|
5
5
|
*
|
|
@@ -344,7 +344,7 @@ export interface PlayRouteEvent {
|
|
|
344
344
|
* An optional capability: the routing support
|
|
345
345
|
*/
|
|
346
346
|
export interface Routable {
|
|
347
|
-
readonly currentRoute:
|
|
347
|
+
readonly currentRoute: ReadonlyAtom<string | null>;
|
|
348
348
|
readonly initialRoute: string | null;
|
|
349
349
|
}
|
|
350
350
|
/**
|
|
@@ -390,36 +390,34 @@ export interface RoutableActor extends Routable {
|
|
|
390
390
|
*
|
|
391
391
|
* The interface defines the connection of the lifecycle between the infrastructure,
|
|
392
392
|
* for example a framework router, and the Actor. The infrastructure builds a "bridge"
|
|
393
|
-
* to the Actor: it observes the
|
|
393
|
+
* to the Actor: it observes the atoms of the Actor, and it manages its own
|
|
394
394
|
* lifecycle accordingly.
|
|
395
395
|
*
|
|
396
396
|
* **Architectural context:** the interface implements **Passive Infrastructure
|
|
397
397
|
* (INV-04)**, because it gives an observation in one direction. The infrastructure
|
|
398
|
-
* connects to observe the
|
|
398
|
+
* connects to observe the atoms of the Actor (currentRoute, currentView, and
|
|
399
399
|
* state), and it reflects each change. It makes no decision about the state.
|
|
400
400
|
*
|
|
401
401
|
* @example
|
|
402
402
|
* The implementation of a framework router bridge
|
|
403
403
|
* ```typescript
|
|
404
404
|
* import type { RouterBridge } from "@xmachines/play-router";
|
|
405
|
-
* import {
|
|
405
|
+
* import { watchAtom, type Cleanup } from "@xmachines/play-atom";
|
|
406
406
|
*
|
|
407
407
|
* class MyRouterBridge implements RouterBridge {
|
|
408
|
-
* private
|
|
408
|
+
* private stop: Cleanup | null = null;
|
|
409
409
|
*
|
|
410
410
|
* async connect(): Promise<void> {
|
|
411
|
-
* // Start the observation of the actor.currentRoute
|
|
412
|
-
* this.
|
|
413
|
-
* const route = actor.currentRoute.get();
|
|
411
|
+
* // Start the observation of the actor.currentRoute atom
|
|
412
|
+
* this.stop = watchAtom(actor.currentRoute, (route) => {
|
|
414
413
|
* if (route) router.navigate(route);
|
|
415
414
|
* });
|
|
416
|
-
* this.watcher.watch(actor.currentRoute);
|
|
417
415
|
* }
|
|
418
416
|
*
|
|
419
417
|
* async disconnect(): Promise<void> {
|
|
420
|
-
* // Stop the observation, and
|
|
421
|
-
* this.
|
|
422
|
-
* this.
|
|
418
|
+
* // Stop the observation, and release the subscription
|
|
419
|
+
* this.stop?.();
|
|
420
|
+
* this.stop = null;
|
|
423
421
|
* }
|
|
424
422
|
* }
|
|
425
423
|
* ```
|
|
@@ -431,7 +429,7 @@ export interface RouterBridge {
|
|
|
431
429
|
* Connects the router bridge to the Actor
|
|
432
430
|
*
|
|
433
431
|
* The infrastructure calls it when it must start the observation of the Actor
|
|
434
|
-
*
|
|
432
|
+
* atoms, and when it must bring its own state, for example the browser URL, in line
|
|
435
433
|
* with the Actor state.
|
|
436
434
|
*
|
|
437
435
|
* @returns The promise that resolves after the connection, or void for a synchronous connection
|
|
@@ -440,7 +438,7 @@ export interface RouterBridge {
|
|
|
440
438
|
* ```typescript
|
|
441
439
|
* const bridge: RouterBridge = createBridge(actor, router);
|
|
442
440
|
* await bridge.connect();
|
|
443
|
-
* // The bridge observes the actor.currentRoute
|
|
441
|
+
* // The bridge observes the actor.currentRoute atom now
|
|
444
442
|
* ```
|
|
445
443
|
*/
|
|
446
444
|
connect(): void | Promise<void>;
|
|
@@ -448,7 +446,7 @@ export interface RouterBridge {
|
|
|
448
446
|
* Disconnects the router bridge from the Actor
|
|
449
447
|
*
|
|
450
448
|
* The infrastructure calls it when it must stop the observation and free its
|
|
451
|
-
* resources, for example
|
|
449
|
+
* resources, for example an atom watcher and an event listener.
|
|
452
450
|
*
|
|
453
451
|
* @returns The promise that resolves after the disconnection, or void for a synchronous disconnection
|
|
454
452
|
*
|
|
@@ -547,18 +545,25 @@ export interface LocationLike {
|
|
|
547
545
|
/**
|
|
548
546
|
* The options of `createRouteMap` and of `createRouteMapFromTree`.
|
|
549
547
|
*/
|
|
550
|
-
export interface RouteMapOptions {
|
|
548
|
+
export interface RouteMapOptions extends CompileOptions {
|
|
551
549
|
/**
|
|
552
|
-
* The
|
|
550
|
+
* The cache of the state that a VISITED PATH resolves to, or `null` for a path that
|
|
551
|
+
* resolves to none.
|
|
553
552
|
*
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
553
|
+
* The default is a cache of this map alone, of 500 entries in each of two generations.
|
|
554
|
+
* Pass one to raise that bound, to share the resolution across maps, or to give it an
|
|
555
|
+
* eviction policy of your own: `createPatternCache(5000)` builds one, and so does any
|
|
556
|
+
* object with a `get` and a `set`.
|
|
558
557
|
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
558
|
+
* A cache that a caller passes is keyed by the ROUTE TABLE. Two maps built from the
|
|
559
|
+
* same mappings, in the same order, therefore read each other's answers — which is
|
|
560
|
+
* what a server that rebuilds its map for each request wants — and two maps built from
|
|
561
|
+
* different mappings never do, because a map with no route for a path writes `null`
|
|
562
|
+
* for it and a map that holds one must not read that.
|
|
563
|
+
*
|
|
564
|
+
* The keys are the paths that a visitor reaches, so the key space is unbounded: a
|
|
565
|
+
* cache with no bound of its own grows for the life of the process.
|
|
561
566
|
*/
|
|
562
|
-
|
|
567
|
+
pathCache?: PatternCache<string | null>;
|
|
563
568
|
}
|
|
564
569
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACzF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;;;;GAKG;AAEH;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,cAAc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;;;;;;;;;;;;;;OAiBG;IACH,SAAS,CAAC,EAAE,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CACxC"}
|
|
@@ -13,8 +13,8 @@ import type { RouteMapOptions } from "../types.js";
|
|
|
13
13
|
* actor route into a URL.
|
|
14
14
|
*
|
|
15
15
|
* @param machine - The XState v5 state machine, with a `meta.route` annotation on each state with a route.
|
|
16
|
-
* @param options - The optional configuration. Give `{
|
|
17
|
-
* default
|
|
16
|
+
* @param options - The optional configuration. Give `{ pathCache }` to replace the
|
|
17
|
+
* default LRU cache of the parameterized path lookups with one that you own.
|
|
18
18
|
* @returns A `RouteMap` for each adapter on `RouterBridgeBase`.
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-route-map.d.ts","sourceRoot":"","sources":["../../src/xstate/create-route-map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAG9C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,QAAQ,
|
|
1
|
+
{"version":3,"file":"create-route-map.d.ts","sourceRoot":"","sources":["../../src/xstate/create-route-map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAG9C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,QAAQ,CAa5F"}
|
|
@@ -13,8 +13,8 @@ import { RouteMap } from "../base-route-map.js";
|
|
|
13
13
|
* actor route into a URL.
|
|
14
14
|
*
|
|
15
15
|
* @param machine - The XState v5 state machine, with a `meta.route` annotation on each state with a route.
|
|
16
|
-
* @param options - The optional configuration. Give `{
|
|
17
|
-
* default
|
|
16
|
+
* @param options - The optional configuration. Give `{ pathCache }` to replace the
|
|
17
|
+
* default LRU cache of the parameterized path lookups with one that you own.
|
|
18
18
|
* @returns A `RouteMap` for each adapter on `RouterBridgeBase`.
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
@@ -27,7 +27,10 @@ import { RouteMap } from "../base-route-map.js";
|
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
29
|
export function createRouteMap(machine, options) {
|
|
30
|
-
|
|
30
|
+
// The options reach the EXTRACTION too. `extractMachineRoutes` parses the route of
|
|
31
|
+
// every node, so a caller that passes a cache for the isolation of a tenant would
|
|
32
|
+
// otherwise write each of those patterns into the shared default cache.
|
|
33
|
+
const routeTree = extractMachineRoutes(machine, options);
|
|
31
34
|
const routes = getRoutableRoutes(routeTree);
|
|
32
35
|
return new RouteMap(routes.map((node) => ({
|
|
33
36
|
stateId: node.stateId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-route-map.js","sourceRoot":"","sources":["../../src/xstate/create-route-map.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGhD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,cAAc,CAAC,OAAwB,EAAE,OAAyB;IACjF,MAAM,SAAS,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"create-route-map.js","sourceRoot":"","sources":["../../src/xstate/create-route-map.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGhD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,cAAc,CAAC,OAAwB,EAAE,OAAyB;IACjF,mFAAmF;IACnF,kFAAkF;IAClF,wEAAwE;IACxE,MAAM,SAAS,GAAG,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC5C,OAAO,IAAI,QAAQ,CAClB,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACrB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,IAAI,EAAE,IAAI,CAAC,QAAQ;KACnB,CAAC,CAAC,EACH,OAAO,CACP,CAAC;AACH,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ParseOptions } from "@xmachines/play-url";
|
|
1
2
|
import type { AnyStateMachine } from "xstate";
|
|
2
3
|
import type { RouteTree } from "../types.js";
|
|
3
4
|
import { type MachineGraph } from "./machine-to-graph.js";
|
|
@@ -13,5 +14,5 @@ import { type MachineGraph } from "./machine-to-graph.js";
|
|
|
13
14
|
* @param machine - The XState v5 state machine
|
|
14
15
|
* @returns The route tree, with its root, its byStateId map, its byPath map, and its graph
|
|
15
16
|
*/
|
|
16
|
-
export declare const extractMachineRoutes: (machine: AnyStateMachine) => RouteTree<MachineGraph>;
|
|
17
|
+
export declare const extractMachineRoutes: (machine: AnyStateMachine, options?: ParseOptions) => RouteTree<MachineGraph>;
|
|
17
18
|
//# sourceMappingURL=extract-routes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-routes.d.ts","sourceRoot":"","sources":["../../src/xstate/extract-routes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,KAAK,EAAE,SAAS,EAA4B,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"extract-routes.d.ts","sourceRoot":"","sources":["../../src/xstate/extract-routes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,KAAK,EAAE,SAAS,EAA4B,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAiF1E;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,GAChC,SAAS,eAAe,EACxB,UAAU,YAAY,KACpB,SAAS,CAAC,YAAY,CAoBxB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parsePattern } from "@xmachines/play-url";
|
|
2
2
|
import { machineToGraph } from "./machine-to-graph.js";
|
|
3
3
|
import { validateRouteFormat, validateStateExists } from "../validate-routes.js";
|
|
4
4
|
import { buildRouteTree } from "../build-tree.js";
|
|
@@ -27,7 +27,7 @@ const buildStatePath = (graphNode, graphNodeMap) => {
|
|
|
27
27
|
* Reads the route information of the MachineNodeData object of a graph node.
|
|
28
28
|
* The function returns null when the node has no route.
|
|
29
29
|
*/
|
|
30
|
-
const extractRouteFromNode = (graphNode, stateIds, graphNodeMap) => {
|
|
30
|
+
const extractRouteFromNode = (graphNode, stateIds, graphNodeMap, options) => {
|
|
31
31
|
const { stateId, route, meta } = graphNode.data;
|
|
32
32
|
// The node has no route
|
|
33
33
|
if (!route)
|
|
@@ -42,7 +42,7 @@ const extractRouteFromNode = (graphNode, stateIds, graphNodeMap) => {
|
|
|
42
42
|
// last expression that read the grammar on its own: it reported no pattern for
|
|
43
43
|
// `/docs/*`, for `/books{/:id}?` and for an escaped literal, so a consumer that reads
|
|
44
44
|
// `node.pattern` learned that a parameterized route is a literal path.
|
|
45
|
-
const pattern =
|
|
45
|
+
const pattern = parsePattern(route, options).parameterized ? route : undefined;
|
|
46
46
|
// Build the original shape of the metadata again, from the data of the graph
|
|
47
47
|
const metadata = meta && typeof meta === "object" && "route" in meta
|
|
48
48
|
? meta["route"]
|
|
@@ -71,7 +71,7 @@ const extractRouteFromNode = (graphNode, stateIds, graphNodeMap) => {
|
|
|
71
71
|
* @param machine - The XState v5 state machine
|
|
72
72
|
* @returns The route tree, with its root, its byStateId map, its byPath map, and its graph
|
|
73
73
|
*/
|
|
74
|
-
export const extractMachineRoutes = (machine) => {
|
|
74
|
+
export const extractMachineRoutes = (machine, options) => {
|
|
75
75
|
// 1. Convert the machine into a graph
|
|
76
76
|
const graph = machineToGraph(machine);
|
|
77
77
|
// 2. Build the set of the state IDs, for the check, and the node map, for a parent lookup in O(1)
|
|
@@ -79,7 +79,7 @@ export const extractMachineRoutes = (machine) => {
|
|
|
79
79
|
const graphNodeMap = new Map(graph.nodes.map((n) => [n.id, n]));
|
|
80
80
|
// 3. Read the routes of the graph nodes
|
|
81
81
|
const routes = graph.nodes
|
|
82
|
-
.map((node) => extractRouteFromNode(node, stateIds, graphNodeMap))
|
|
82
|
+
.map((node) => extractRouteFromNode(node, stateIds, graphNodeMap, options))
|
|
83
83
|
.filter((r) => r !== null);
|
|
84
84
|
// 4. Build the hierarchical tree, and attach the graph.
|
|
85
85
|
// buildRouteTree finds each duplicate route, AFTER it resolved each relative route
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-routes.js","sourceRoot":"","sources":["../../src/xstate/extract-routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"extract-routes.js","sourceRoot":"","sources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AI,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;SAC1E,MAAM,CAAC,CAAC,CAAC,EAAkB,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;IAE5C,wDAAwD;IACxD,mFAAmF;IACnF,4EAA4E;IAC5E,2EAA2E;IAC3E,UAAU;IACV,MAAM,IAAI,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IACpC,OAAO,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,CAAC;AAC3B,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xmachines/play-router",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Route maps, the router bridge base and the Routable capability of @xmachines/play. It names no state machine; the machine half is the ./xstate subpath.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"routing",
|
|
@@ -53,30 +53,33 @@
|
|
|
53
53
|
"test:coverage": "vitest run --coverage"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@
|
|
57
|
-
"@xmachines/play-url": "4.0.0",
|
|
58
|
-
"quick-lru": "^7.3.0"
|
|
56
|
+
"@xmachines/play-url": "5.0.1"
|
|
59
57
|
},
|
|
60
58
|
"devDependencies": {
|
|
59
|
+
"@statelyai/graph": "^2.4.0",
|
|
61
60
|
"@testing-library/jest-dom": "^7.0.1",
|
|
62
61
|
"@types/node": "^26.6.2",
|
|
63
62
|
"@vitest/browser-playwright": "^5.0.1",
|
|
64
|
-
"@xmachines/play": "
|
|
65
|
-
"@xmachines/play-
|
|
66
|
-
"@xmachines/play-view": "
|
|
67
|
-
"oxfmt": "^0.
|
|
68
|
-
"oxlint": "^1.
|
|
63
|
+
"@xmachines/play": "5.0.1",
|
|
64
|
+
"@xmachines/play-atom": "5.0.1",
|
|
65
|
+
"@xmachines/play-view": "5.0.1",
|
|
66
|
+
"oxfmt": "^0.70.0",
|
|
67
|
+
"oxlint": "^1.85.0",
|
|
69
68
|
"typescript": "^5.9.3 || ^6.0.3",
|
|
70
69
|
"vite": "^8.3.0",
|
|
71
70
|
"vitest": "^5.0.1",
|
|
72
71
|
"xstate": "^5.33.0"
|
|
73
72
|
},
|
|
74
73
|
"peerDependencies": {
|
|
75
|
-
"@
|
|
76
|
-
"@xmachines/play
|
|
74
|
+
"@statelyai/graph": "^2.4.0",
|
|
75
|
+
"@xmachines/play": "5.0.1",
|
|
76
|
+
"@xmachines/play-atom": "5.0.1",
|
|
77
77
|
"xstate": "^5.33.0"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
|
80
|
+
"@statelyai/graph": {
|
|
81
|
+
"optional": true
|
|
82
|
+
},
|
|
80
83
|
"xstate": {
|
|
81
84
|
"optional": true
|
|
82
85
|
}
|
|
@@ -84,5 +87,5 @@
|
|
|
84
87
|
"engines": {
|
|
85
88
|
"node": ">=24.0.0"
|
|
86
89
|
},
|
|
87
|
-
"_devDependencies_note": "xstate
|
|
90
|
+
"_devDependencies_note": "xstate and @statelyai/graph appear in both peerDependencies and devDependencies intentionally. devDependencies provides workspace resolution for local builds and tests. peerDependencies declares the consumer version constraint. Both hold the same range, to prevent drift."
|
|
88
91
|
}
|