@xmachines/play-router 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +93 -76
  2. package/dist/base-route-map.d.ts +63 -57
  3. package/dist/base-route-map.d.ts.map +1 -1
  4. package/dist/base-route-map.js +65 -59
  5. package/dist/base-route-map.js.map +1 -1
  6. package/dist/build-tree.d.ts +13 -12
  7. package/dist/build-tree.d.ts.map +1 -1
  8. package/dist/build-tree.js +30 -28
  9. package/dist/build-tree.js.map +1 -1
  10. package/dist/create-route-map-from-tree.d.ts +15 -15
  11. package/dist/create-route-map-from-tree.js +15 -15
  12. package/dist/create-route-map.d.ts +18 -16
  13. package/dist/create-route-map.d.ts.map +1 -1
  14. package/dist/create-route-map.js +10 -9
  15. package/dist/create-route-map.js.map +1 -1
  16. package/dist/errors.d.ts +40 -38
  17. package/dist/errors.d.ts.map +1 -1
  18. package/dist/errors.js +40 -38
  19. package/dist/errors.js.map +1 -1
  20. package/dist/extract-routes.d.ts +8 -7
  21. package/dist/extract-routes.d.ts.map +1 -1
  22. package/dist/extract-routes.js +31 -27
  23. package/dist/extract-routes.js.map +1 -1
  24. package/dist/find-route.d.ts +18 -15
  25. package/dist/find-route.d.ts.map +1 -1
  26. package/dist/find-route.js +42 -38
  27. package/dist/find-route.js.map +1 -1
  28. package/dist/index.d.ts +6 -1
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +11 -10
  31. package/dist/index.js.map +1 -1
  32. package/dist/machine-to-graph.d.ts +3 -2
  33. package/dist/machine-to-graph.d.ts.map +1 -1
  34. package/dist/machine-to-graph.js +20 -19
  35. package/dist/machine-to-graph.js.map +1 -1
  36. package/dist/query.d.ts +39 -37
  37. package/dist/query.d.ts.map +1 -1
  38. package/dist/query.js +62 -57
  39. package/dist/query.js.map +1 -1
  40. package/dist/router-bridge-base.d.ts +208 -190
  41. package/dist/router-bridge-base.d.ts.map +1 -1
  42. package/dist/router-bridge-base.js +235 -211
  43. package/dist/router-bridge-base.js.map +1 -1
  44. package/dist/router-sync.d.ts +41 -35
  45. package/dist/router-sync.d.ts.map +1 -1
  46. package/dist/router-sync.js +53 -45
  47. package/dist/router-sync.js.map +1 -1
  48. package/dist/types.d.ts +165 -147
  49. package/dist/types.d.ts.map +1 -1
  50. package/dist/url-pattern-utils.d.ts +53 -47
  51. package/dist/url-pattern-utils.d.ts.map +1 -1
  52. package/dist/url-pattern-utils.js +61 -55
  53. package/dist/url-pattern-utils.js.map +1 -1
  54. package/dist/validate-routes.d.ts +32 -31
  55. package/dist/validate-routes.d.ts.map +1 -1
  56. package/dist/validate-routes.js +30 -29
  57. package/dist/validate-routes.js.map +1 -1
  58. package/package.json +6 -5
@@ -1,26 +1,27 @@
1
1
  import { getURLPatternCtor, getCompiledPattern } from "./url-pattern-utils.js";
2
2
  import { URLPatternUnavailableError, InvalidRoutePatternError } from "./errors.js";
3
3
  /**
4
- * Check if a URL path matches a route pattern using URLPattern.
4
+ * Tells you if a URL path matches a route pattern, with URLPattern.
5
5
  *
6
- * For static patterns (no `:param`) falls back to a direct equality check so
7
- * URLPattern is never required for polyfill-free environments that only use
8
- * static routes.
6
+ * For a static pattern, which holds no `:param`, the function makes a direct
7
+ * equality test. Therefore an environment with static routes only needs URLPattern
8
+ * never, and it needs no polyfill.
9
9
  *
10
- * Uses the shared module-level compiled-pattern cache (`getCompiledPattern`)
11
- * so repeated lookups never recompile the same pattern, and hyphenated param
12
- * names (`:cat-id`) are normalized exactly as `RouteMap` does the same single
13
- * matching engine underneath.
10
+ * The function uses the compiled-pattern cache of the module level
11
+ * (`getCompiledPattern`). A repeated lookup therefore compiles the same pattern
12
+ * never again. The cache also normalizes a param name with a hyphen (`:cat-id`)
13
+ * exactly like `RouteMap`: one match engine is below both.
14
14
  *
15
- * Throws `URLPatternUnavailableError` when a parameterised pattern is tested
16
- * and URLPattern is not available on `globalThis`.
17
- * Throws `InvalidRoutePatternError` when URLPattern cannot compile the pattern.
15
+ * The function throws a `URLPatternUnavailableError` when it tests a parameterized
16
+ * pattern and `globalThis` holds no URLPattern.
17
+ * It throws an `InvalidRoutePatternError` when URLPattern cannot compile the
18
+ * pattern.
18
19
  *
19
- * Private not exported from the package public API.
20
+ * This function is private. The public API of the package does not export it.
20
21
  *
21
- * @param path - URL path (e.g., '/settings', '/settings/billing')
22
- * @param pattern - Route pattern (e.g., '/settings/:section?')
23
- * @returns True if path matches pattern
22
+ * @param path - The URL path, for example '/settings' or '/settings/billing'
23
+ * @param pattern - The route pattern, for example '/settings/:section?'
24
+ * @returns True when the path matches the pattern
24
25
  */
25
26
  function matchesPattern(path, pattern) {
26
27
  if (!pattern.includes(":"))
@@ -36,14 +37,15 @@ function matchesPattern(path, pattern) {
36
37
  }
37
38
  }
38
39
  /**
39
- * Find route node by state ID
40
+ * Finds a route node by its state ID
40
41
  *
41
- * Looks up route node using the state's ID property. Used to get URL path
42
- * from state ID for browser URL sync after play.route transitions.
42
+ * The function looks the route node up by the ID property of the state. It gives you
43
+ * the URL path of a state ID, for the update of the browser URL after a `play.route`
44
+ * transition.
43
45
  *
44
- * @param tree - Route tree from extractMachineRoutes
45
- * @param id - State ID (e.g., 'dashboard', 'settings.profile')
46
- * @returns Route node if found, undefined otherwise
46
+ * @param tree - The route tree, from extractMachineRoutes
47
+ * @param id - The state ID, for example 'dashboard' or 'settings.profile'
48
+ * @returns The route node, or undefined when the function finds none
47
49
  *
48
50
  * @example
49
51
  * ```typescript
@@ -58,19 +60,21 @@ export const findRouteById = (tree, id) => {
58
60
  return tree.byStateId.get(id);
59
61
  };
60
62
  /**
61
- * Find route node by URL path
63
+ * Finds a route node by its URL path
62
64
  *
63
- * Looks up route node using the URL path. Used to get state ID from browser
64
- * URL for sending play.route events on navigation.
65
+ * The function looks the route node up by the URL path. It gives you the state ID of
66
+ * a browser URL, for the `play.route` event of a navigation.
65
67
  *
66
- * When multiple states share the same path (e.g., root and a state both at "/"),
67
- * prefers routable nodes (with meta.route) over non-routable nodes.
68
+ * When more than one state holds the same path, for example the root and a second
69
+ * state both at "/", the function prefers a node with a route, which means a node
70
+ * with a `meta.route` field, over a node without one.
68
71
  *
69
- * Supports pattern matching for dynamic routes (e.g., '/settings/:section?').
72
+ * The function also matches a pattern of a dynamic route, for example
73
+ * '/settings/:section?'.
70
74
  *
71
- * @param tree - Route tree from extractMachineRoutes
72
- * @param path - URL path (e.g., '/dashboard', '/settings/profile')
73
- * @returns Route node if found, undefined otherwise
75
+ * @param tree - The route tree, from extractMachineRoutes
76
+ * @param path - The URL path, for example '/dashboard' or '/settings/profile'
77
+ * @returns The route node, or undefined when the function finds none
74
78
  *
75
79
  * @example
76
80
  * ```typescript
@@ -79,25 +83,25 @@ export const findRouteById = (tree, id) => {
79
83
  * ```
80
84
  */
81
85
  export const findRouteByPath = (tree, path) => {
82
- // 1. Try exact match first (fast path for static routes)
86
+ // 1. Try the exact match first. This is the fast path of a static route
83
87
  const node = tree.byPath.get(path);
84
88
  if (node?.routable) {
85
89
  return node;
86
90
  }
87
- // 2. If exact match not found or non-routable, try pattern matching
88
- // This handles:
89
- // - Routes with parameters (e.g., '/settings/:section?')
90
- // - Multiple states sharing same path (prefer routable)
91
+ // 2. Without an exact match, and for a node without a route, try the pattern match.
92
+ // This handles three cases:
93
+ // - a route with a parameter, for example '/settings/:section?'
94
+ // - more than one state at the same path, where a state with a route wins
91
95
  for (const candidate of tree.byStateId.values()) {
92
96
  if (!candidate.routable) {
93
- continue; // Skip non-routable nodes
97
+ continue; // Skip each node without a route
94
98
  }
95
- // Check if path matches this node's pattern
99
+ // Test the path against the pattern of this node
96
100
  if (matchesPattern(path, candidate.fullPath)) {
97
101
  return candidate;
98
102
  }
99
103
  }
100
- // 3. Fallback: if we had a non-routable exact match, return it
104
+ // 3. The fallback: return the exact match of a node without a route, when one is present
101
105
  return node;
102
106
  };
103
107
  //# sourceMappingURL=find-route.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"find-route.js","s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,EAAU,EAAyB,EAAE;IACnF,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC/B,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAe,EAAE,IAAY,EAAyB,EAAE;IACvF,wEAAwE;IACxE,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAEnC,IAAI,IAAI,EAAE,QAAQ,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACb,CAAC;IAED,oFAAoF;IACpF,4BAA4B;IAC5B,gEAAgE;IAChE,0EAA0E;IAC1E,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;QACjD,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;YACzB,SAAS,CAAC,iCAAiC;QAC5C,CAAC;QAED,iDAAiD;QACjD,IAAI,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC9C,OAAO,SAAS,CAAC;QAClB,CAAC;IACF,CAAC;IAED,yFAAyF;IACzF,OAAO,IAAI,CAAC;AACb,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { RouteMapping } from "./base-route-map.js";
1
2
  export { RouterBridgeBase } from "./router-bridge-base.js";
2
3
  export type { RouteWatcherHandle } from "./router-bridge-base.js";
3
4
  export { sanitizePathname, buildPlayRouteEvent, extractQuery, extractRouteParams, } from "./router-sync.js";
@@ -10,7 +11,11 @@ export { getNavigableRoutes, getRoutableRoutes, routeExists, getTransitionReacha
10
11
  export { machineToGraph } from "./machine-to-graph.js";
11
12
  export type { MachineGraph } from "./machine-to-graph.js";
12
13
  export type { RouteInfo, RouteNode, RouteTree, RouteObject, RouteMetadata, PlayRouteEvent, RoutableActor, PlayActor, RouterBridge, MachineNodeData, MachineEdgeData, WindowLike, LocationLike, } from "./types.js";
13
- export { RouteMap, type RouteMapping, type RouteMapping as BaseRouteMapping, } from "./base-route-map.js";
14
+ export { RouteMap, type RouteMapping } from "./base-route-map.js";
15
+ /**
16
+ * @deprecated Use {@link RouteMapping}. Will be removed in the next major.
17
+ */
18
+ export type BaseRouteMapping = RouteMapping;
14
19
  export { createRouteMap } from "./create-route-map.js";
15
20
  export type { RouteMapOptions } from "./create-route-map.js";
16
21
  export { createRouteMapFromTree } from "./create-route-map-from-tree.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAGlE,OAAO,EACN,gBAAgB,EAChB,mBAAmB,EACnB,YAAY,EACZ,kBAAkB,GAClB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,UAAU,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAG/E,OAAO,EACN,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EACN,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,EACX,4BAA4B,EAC5B,gBAAgB,GAChB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,YAAY,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D,YAAY,EACX,SAAS,EACT,SAAS,EACT,SAAS,EACT,WAAW,EACX,aAAa,EACb,cAAc,EACd,aAAa,EACb,SAAS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AuB,CAAC;AAE1D,YAAY,EACX,SAAS,EACT,SAAS,EACT,SAAS,EACT,WAAW,EACX,aAAa,EACb,cAAc,EACd,aAAa,EACb,SAAS,EACT,YAAY,EACZ,eAAe,EACf,eAAe,EACf,UAAU,EACV,YAAY,GACZ,MAAM,YAAY,CAAC;AAKpB,OAAO,EAAE,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAElE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAI5C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAGzE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js CHANGED
@@ -1,21 +1,22 @@
1
- // RouterBridgeBase — public API for community adapters
1
+ // RouterBridgeBase — the public API of an adapter of the community
2
2
  export { RouterBridgeBase } from "./router-bridge-base.js";
3
- // Router sync utilities — used by play-dom-router and adapters that bypass syncActorFromRouter()
3
+ // The router sync utilities — play-dom-router uses them, and also each adapter that passes around syncActorFromRouter()
4
4
  export { sanitizePathname, buildPlayRouteEvent, extractQuery, extractRouteParams, } from "./router-sync.js";
5
- // Route utilities (existing)
5
+ // The route utilities
6
6
  export { validateRouteFormat, validateStateExists, detectDuplicateRoutes, } from "./validate-routes.js";
7
7
  export { buildRouteTree } from "./build-tree.js";
8
8
  export { extractMachineRoutes } from "./extract-routes.js";
9
9
  export { getNavigableRoutes, getRoutableRoutes, routeExists, getTransitionReachableRoutes, isRouteReachable, } from "./query.js";
10
- // Graph adapter — converts XState machines to @statelyai/graph Graph
10
+ // The graph adapter — it converts an XState machine into a Graph of @statelyai/graph
11
11
  export { machineToGraph } from "./machine-to-graph.js";
12
- // Shared bidirectional route mapping base class.
13
- // RouteMapping is exported directly; BaseRouteMapping kept as alias for compatibility.
14
- export { RouteMap, } from "./base-route-map.js";
15
- // Factories: create a RouteMap from a machine or a route tree.
16
- // All RouterBridgeBase adapters use these instead of rolling their own factories.
12
+ // The shared base class of the route map for both directions.
13
+ // This module exports RouteMapping directly. BaseRouteMapping stays as an alias, for
14
+ // the compatibility.
15
+ export { RouteMap } from "./base-route-map.js";
16
+ // The factories: each one creates a RouteMap from a machine or from a route tree.
17
+ // Every RouterBridgeBase adapter uses them, and it writes no factory of its own.
17
18
  export { createRouteMap } from "./create-route-map.js";
18
19
  export { createRouteMapFromTree } from "./create-route-map-from-tree.js";
19
- // Route lookup helpers matchesPattern is private within find-route.ts
20
+ // The helpers of a route lookup. matchesPattern stays private inside find-route.ts
20
21
  export { findRouteById, findRouteByPath } from "./find-route.js";
21
22
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAG3D,iGAAiG;AACjG,OAAO,EACN,gBAAgB,EAChB,mBAAmB,EACnB,YAAY,EACZ,kBAAkB,GAClB,MAAM,kBAAkB,CAAC;AAG1B,6BAA6B;AAC7B,OAAO,EACN,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,GACrB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EACN,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,EACX,4BAA4B,EAC5B,gBAAgB,GAChB,MAAM,YAAY,CAAC;AAEpB,qEAAqE;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAmBvD,iDAAiD;AACjD,uFAAuF;AACvF,OAAO,EACN,QAAQ,GAGR,MAAM,qBAAqB,CAAC;AAE7B,+DAA+D;AAC/D,kFAAkF;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE,wEAAwE;AACxE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,mEAAmE;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAG3D,wHAAwH;AACxH,OAAO,EACN,gBAAgB,EAChB,mBAAmB,EACnB,YAAY,EACZ,kBAAkB,GAClB,MAAM,kBAAkB,CAAC;AAG1B,sBAAsB;AACtB,OAAO,EACN,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,GACrB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EACN,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,EACX,4BAA4B,EAC5B,gBAAgB,GAChB,MAAM,YAAY,CAAC;AAEpB,qFAAqF;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAmBvD,8DAA8D;AAC9D,qFAAqF;AACrF,qBAAqB;AACrB,OAAO,EAAE,QAAQ,EAAqB,MAAM,qBAAqB,CAAC;AAOlE,kFAAkF;AAClF,iFAAiF;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE,mFAAmF;AACnF,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
@@ -2,8 +2,9 @@ import type { AnyStateMachine } from "xstate";
2
2
  import { type Graph } from "@statelyai/graph";
3
3
  import type { MachineNodeData, MachineEdgeData } from "./types.js";
4
4
  /**
5
- * Typed @statelyai/graph Graph representing a state machine.
6
- * Provides hierarchy queries, traversal algorithms, and reachability checks.
5
+ * The typed Graph of @statelyai/graph that represents a state machine.
6
+ * It gives you the queries of the hierarchy, the algorithms of a walk, and the tests
7
+ * of the reachability.
7
8
  *
8
9
  * @example
9
10
  * ```typescript
@@ -1 +1 @@
1
- {"version":3,"file":"machine-to-graph.d.ts","sourceRoot":"","sources":["../src/machine-to-graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAe,KAAK,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGnE;;;;;;;;;;GAUG;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;AAqDnE,eAAO,MAAM,cAAc,GAAI,SAAS,eAAe,KAAG,YAwEzD,CAAC"}
1
+ {"version":3,"file":"machine-to-graph.d.ts","sourceRoot":"","sources":["../src/machine-to-graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAe,KAAK,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGnE;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;AAsDnE,eAAO,MAAM,cAAc,GAAI,SAAS,eAAe,KAAG,YAwEzD,CAAC"}
@@ -2,21 +2,21 @@ import { toDirectedGraph } from "xstate/graph";
2
2
  import { createGraph } from "@statelyai/graph";
3
3
  import { UnknownStateTypeError } from "./errors.js";
4
4
  /**
5
- * Convert an XState v5 state machine to a typed @statelyai/graph Graph.
5
+ * Converts an XState v5 state machine into a typed Graph of @statelyai/graph.
6
6
  *
7
- * The conversion pipeline is:
8
- * `XState Machine → toDirectedGraph() → DirectedGraphNode hierarchy → createGraph() → Graph`
7
+ * The pipeline of the conversion is:
8
+ * `XState Machine → toDirectedGraph() → the hierarchy of the DirectedGraphNode objects → createGraph() → Graph`
9
9
  *
10
- * The resulting graph captures:
11
- * - **Hierarchy**: node parentId reflects XState compound/parallel nesting
12
- * - **Edges**: all transitions with event types and optional guard types
13
- * - **Metadata**: state type, meta object, and extracted route path
10
+ * The graph of the result holds three things:
11
+ * - **The hierarchy**: the parentId of a node shows the compound nesting and the parallel nesting of XState
12
+ * - **The edges**: every transition, with its event types and with its optional guard types
13
+ * - **The metadata**: the state type, the meta object, and the route path from the extraction
14
14
  *
15
- * @param machine - XState v5 state machine (any shape)
16
- * @returns Typed directed graph with MachineNodeData on nodes and MachineEdgeData on edges
15
+ * @param machine - The XState v5 state machine, in each shape
16
+ * @returns The typed directed graph, with a MachineNodeData object on each node and a MachineEdgeData object on each edge
17
17
  *
18
18
  * @example
19
- * Convert a simple machine and query its routes
19
+ * The conversion of a simple machine, and a query of its routes
20
20
  * ```typescript
21
21
  * import { createMachine } from "xstate";
22
22
  * import { getChildren, getSuccessors } from "@statelyai/graph";
@@ -36,13 +36,14 @@ import { UnknownStateTypeError } from "./errors.js";
36
36
  * const successors = getSuccessors(graph, "app.home"); // [about]
37
37
  * ```
38
38
  *
39
- * @see {@link MachineNodeData} for node data shape
40
- * @see {@link MachineEdgeData} for edge data shape
41
- * @see https://github.com/statelyai/graph for @statelyai/graph API reference
39
+ * @see {@link MachineNodeData} for the shape of the data of a node
40
+ * @see {@link MachineEdgeData} for the shape of the data of an edge
41
+ * @see https://github.com/statelyai/graph for the API reference of @statelyai/graph
42
42
  */
43
43
  /**
44
- * Set of valid XState state types for runtime validation.
45
- * Guards against future XState changes or unexpected machine shapes.
44
+ * The set of the valid XState state types, for the check at run time.
45
+ * It guards against a later change of XState, and against a machine shape that the
46
+ * package does not expect.
46
47
  */
47
48
  const VALID_STATE_TYPES = new Set([
48
49
  "atomic",
@@ -53,7 +54,7 @@ const VALID_STATE_TYPES = new Set([
53
54
  ]);
54
55
  export const machineToGraph = (machine) => {
55
56
  const dg = toDirectedGraph(machine);
56
- // Flatten DirectedGraphNode hierarchy into flat node/edge arrays
57
+ // Convert the hierarchy of the DirectedGraphNode objects into a flat array of nodes and a flat array of edges
57
58
  const nodes = [];
58
59
  const edges = [];
59
60
  let edgeCounter = 0;
@@ -66,7 +67,7 @@ export const machineToGraph = (machine) => {
66
67
  : typeof metaRoute === "object" && metaRoute !== null && "path" in metaRoute
67
68
  ? metaRoute.path
68
69
  : undefined;
69
- // Runtime assertion: validate state type before casting
70
+ // An assertion at run time: check the state type before the cast
70
71
  if (!VALID_STATE_TYPES.has(sn.type)) {
71
72
  throw new UnknownStateTypeError(sn.type, sn.id, [...VALID_STATE_TYPES]);
72
73
  }
@@ -84,7 +85,7 @@ export const machineToGraph = (machine) => {
84
85
  else {
85
86
  nodes.push({ id: dgNode.id, data: nodeData });
86
87
  }
87
- // Collect edges from THIS node (edges are on source node, not graph root)
88
+ // Collect the edges of THIS node. An edge is on its source node, and not on the root of the graph
88
89
  for (const edge of dgNode.edges) {
89
90
  const edgeData = {
90
91
  eventType: edge.label.text,
@@ -99,7 +100,7 @@ export const machineToGraph = (machine) => {
99
100
  data: edgeData,
100
101
  });
101
102
  }
102
- // Recurse into children with current node as parent
103
+ // Walk into the children, with this node as their parent
103
104
  for (const child of dgNode.children) {
104
105
  walk(child, dgNode.id);
105
106
  }
@@ -1 +1 @@
1
- {"version":3,"file":"machine-to-graph.js","sourceRoot":"","sources":["../src/machine-to-graph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAA0B,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,WAAW,EAAc,MAAM,kBAAkB,CAAC;AAE3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAA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EAAE;gBACxB,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE;gBACxB,IAAI,EAAE,QAAQ;aACd,CAAC,CAAC;QACJ,CAAC;QAED,yDAAyD;QACzD,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YACrC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;QACxB,CAAC;IACF,CAAC,CAAC;IAEF,IAAI,CAAC,EAAE,CAAC,CAAC;IAET,OAAO,WAAW,CAAC;QAClB,IAAI,EAAE,UAAU;QAChB,aAAa,EAAE,EAAE,CAAC,EAAE;QACpB,KAAK;QACL,KAAK;KACL,CAAC,CAAC;AACJ,CAAC,CAAC"}
package/dist/query.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import type { Graph } from "@statelyai/graph";
2
2
  import type { RouteTree, RouteNode, MachineNodeData, MachineEdgeData } from "./types.js";
3
3
  /**
4
- * Get all routes navigable from given state
4
+ * Returns every route of a navigation from the given state
5
5
  *
6
- * Returns child routes of the specified state. Future enhancement will
7
- * include sibling routes reachable via transitions.
6
+ * The function returns the child routes of the state. A later version also returns
7
+ * the sibling routes of a transition.
8
8
  *
9
- * @param tree - Route tree from extractMachineRoutes()
10
- * @param stateId - Current state ID
11
- * @returns Array of route nodes reachable from state
9
+ * @param tree - The route tree, from extractMachineRoutes()
10
+ * @param stateId - The ID of the current state
11
+ * @returns The array of the route nodes that the state can reach
12
12
  *
13
13
  * @example
14
14
  * ```typescript
@@ -19,14 +19,14 @@ import type { RouteTree, RouteNode, MachineNodeData, MachineEdgeData } from "./t
19
19
  */
20
20
  export declare const getNavigableRoutes: (tree: RouteTree, stateId: string) => RouteNode[];
21
21
  /**
22
- * Get all routable routes from tree as flat array
22
+ * Returns every route of the tree that has a route, in one flat array
23
23
  *
24
- * Returns all routes that have meta.route defined, excluding non-routable
25
- * states and the synthetic root node. Useful for dynamically generating
26
- * router configurations in framework adapters.
24
+ * The function returns each route with a `meta.route` field. It returns no state
25
+ * without a route, and no synthetic root node. Use it to generate a router
26
+ * configuration in a framework adapter dynamically.
27
27
  *
28
- * @param tree - Route tree from extractMachineRoutes()
29
- * @returns Array of routable route nodes with path and stateId
28
+ * @param tree - The route tree, from extractMachineRoutes()
29
+ * @returns The array of the route nodes with a route, with their path and their stateId
30
30
  *
31
31
  * @example
32
32
  * ```typescript
@@ -41,58 +41,60 @@ export declare const getNavigableRoutes: (tree: RouteTree, stateId: string) => R
41
41
  */
42
42
  export declare const getRoutableRoutes: (tree: RouteTree) => RouteNode[];
43
43
  /**
44
- * Validate route path exists in tree
44
+ * Tells you if a route path is in the tree
45
45
  *
46
- * Checks if path has corresponding state with meta.route.
46
+ * The function tests if the path has a state with a `meta.route` field.
47
47
  *
48
- * @param tree - Route tree from extractMachineRoutes()
49
- * @param path - Full route path (e.g., '/dashboard/settings')
50
- * @returns true if path exists, false otherwise
48
+ * @param tree - The route tree, from extractMachineRoutes()
49
+ * @param path - The complete route path, for example '/dashboard/settings'
50
+ * @returns true when the tree holds the path. In every other case, false
51
51
  */
52
52
  export declare const routeExists: (tree: RouteTree, path: string) => boolean;
53
53
  /**
54
- * Get routes reachable via transitions from current state
54
+ * Returns the routes that a transition from the current state can reach
55
55
  *
56
- * Uses the @statelyai/graph successor algorithm to find all states
57
- * directly reachable via transition edges from the given state,
58
- * then filters to those with defined routes.
56
+ * The function uses the successor algorithm of @statelyai/graph. It finds every
57
+ * state of a direct transition edge from the given state, then it keeps the states
58
+ * with a route.
59
59
  *
60
- * Returned values are the RAW `meta.route` strings from the machine — relative
61
- * routes (e.g. `"detail"`) are NOT resolved to full paths and cannot be used as
62
- * `tree.byPath` keys. For resolved `RouteNode`s use `getNavigableRoutes`, which
63
- * resolves reachable states through `tree.byStateId`.
60
+ * The values of the return are the RAW `meta.route` strings of the machine. The
61
+ * function does NOT resolve a relative route, for example `"detail"`, to a complete
62
+ * path, and such a value is therefore no key of `tree.byPath`. For a resolved
63
+ * `RouteNode`, use `getNavigableRoutes`: that function resolves each state that the
64
+ * transition reaches through `tree.byStateId`.
64
65
  *
65
- * @param graph - Machine graph from RouteTree.graph
66
- * @param stateId - Current state ID (e.g., "test.home")
67
- * @returns Array of raw route strings reachable via transitions
66
+ * @param graph - The machine graph, from RouteTree.graph
67
+ * @param stateId - The ID of the current state, for example "test.home"
68
+ * @returns The array of the raw route strings that a transition can reach
68
69
  *
69
70
  * @example
70
71
  * ```typescript
71
72
  * const tree = extractMachineRoutes(machine);
72
73
  * if (tree.graph) {
73
74
  * const reachable = getTransitionReachableRoutes(tree.graph, 'auth.loggedIn');
74
- * // ['/dashboard', '/settings'] — routes reachable via transitions
75
+ * // ['/dashboard', '/settings'] — the routes that a transition can reach
75
76
  * }
76
77
  * ```
77
78
  */
78
79
  export declare const getTransitionReachableRoutes: (graph: Graph<MachineNodeData, MachineEdgeData>, stateId: string) => string[];
79
80
  /**
80
- * Check if a route is reachable from current state via transitions
81
+ * Tells you if a transition from the current state can reach a route
81
82
  *
82
- * Uses @statelyai/graph path-finding to determine if there exists
83
- * a chain of transition edges from the source state to the target state.
83
+ * The function uses the path search of @statelyai/graph. It decides if a chain of
84
+ * transition edges is present from the state of the origin to the state of the
85
+ * target.
84
86
  *
85
- * @param graph - Machine graph from RouteTree.graph
86
- * @param fromStateId - Source state ID
87
- * @param toStateId - Target state ID
88
- * @returns true if a transition path exists, false otherwise
87
+ * @param graph - The machine graph, from RouteTree.graph
88
+ * @param fromStateId - The ID of the state of the origin
89
+ * @param toStateId - The ID of the state of the target
90
+ * @returns true when a transition path is present. In every other case, false
89
91
  *
90
92
  * @example
91
93
  * ```typescript
92
94
  * const tree = extractMachineRoutes(machine);
93
95
  * if (tree.graph) {
94
96
  * const canReach = isRouteReachable(tree.graph, 'auth.login', 'auth.dashboard');
95
- * // true if login dashboard transition path exists
97
+ * // it is true when a transition path from login to dashboard is present
96
98
  * }
97
99
  * ```
98
100
  */
@@ -1 +1 @@
1
- {"version":3,"file":"query.d.ts","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