@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.
- package/README.md +93 -76
- package/dist/base-route-map.d.ts +63 -57
- package/dist/base-route-map.d.ts.map +1 -1
- package/dist/base-route-map.js +65 -59
- package/dist/base-route-map.js.map +1 -1
- package/dist/build-tree.d.ts +13 -12
- package/dist/build-tree.d.ts.map +1 -1
- package/dist/build-tree.js +30 -28
- package/dist/build-tree.js.map +1 -1
- package/dist/create-route-map-from-tree.d.ts +15 -15
- package/dist/create-route-map-from-tree.js +15 -15
- package/dist/create-route-map.d.ts +18 -16
- package/dist/create-route-map.d.ts.map +1 -1
- package/dist/create-route-map.js +10 -9
- package/dist/create-route-map.js.map +1 -1
- package/dist/errors.d.ts +40 -38
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +40 -38
- package/dist/errors.js.map +1 -1
- package/dist/extract-routes.d.ts +8 -7
- package/dist/extract-routes.d.ts.map +1 -1
- package/dist/extract-routes.js +31 -27
- package/dist/extract-routes.js.map +1 -1
- package/dist/find-route.d.ts +18 -15
- package/dist/find-route.d.ts.map +1 -1
- package/dist/find-route.js +42 -38
- package/dist/find-route.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -10
- package/dist/index.js.map +1 -1
- package/dist/machine-to-graph.d.ts +3 -2
- package/dist/machine-to-graph.d.ts.map +1 -1
- package/dist/machine-to-graph.js +20 -19
- package/dist/machine-to-graph.js.map +1 -1
- package/dist/query.d.ts +39 -37
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +62 -57
- package/dist/query.js.map +1 -1
- package/dist/router-bridge-base.d.ts +208 -190
- package/dist/router-bridge-base.d.ts.map +1 -1
- package/dist/router-bridge-base.js +235 -211
- package/dist/router-bridge-base.js.map +1 -1
- package/dist/router-sync.d.ts +41 -35
- package/dist/router-sync.d.ts.map +1 -1
- package/dist/router-sync.js +53 -45
- package/dist/router-sync.js.map +1 -1
- package/dist/types.d.ts +165 -147
- package/dist/types.d.ts.map +1 -1
- package/dist/url-pattern-utils.d.ts +53 -47
- package/dist/url-pattern-utils.d.ts.map +1 -1
- package/dist/url-pattern-utils.js +61 -55
- package/dist/url-pattern-utils.js.map +1 -1
- package/dist/validate-routes.d.ts +32 -31
- package/dist/validate-routes.d.ts.map +1 -1
- package/dist/validate-routes.js +30 -29
- package/dist/validate-routes.js.map +1 -1
- package/package.json +6 -5
package/dist/errors.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { PlayError } from "@xmachines/play";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* location change and send the
|
|
3
|
+
* The bridge throws this error when `RouterBridgeBase.syncActorFromRouter()`
|
|
4
|
+
* cannot process a location change of the router and send the `play.route` event to
|
|
5
|
+
* the actor.
|
|
5
6
|
*
|
|
6
|
-
* The `cause` property
|
|
7
|
+
* The `cause` property holds the original error.
|
|
7
8
|
*
|
|
8
9
|
* **Error code:** `PLAY_ROUTER_SYNC_FAILED`
|
|
9
10
|
*
|
|
@@ -24,17 +25,17 @@ export declare class RouterSyncError extends PlayError {
|
|
|
24
25
|
constructor(message: string, options?: ErrorOptions);
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
28
|
+
* `RouterBridgeBase.connect()` throws this error when a second bridge connects to an
|
|
29
|
+
* actor with an active bridge connection.
|
|
29
30
|
*
|
|
30
|
-
* One actor
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* One actor can hold one router bridge at a time. Two bridges of the same actor both
|
|
32
|
+
* receive and process every navigation event of the router. They therefore send two
|
|
33
|
+
* `play.route` events to the actor, and their `lastSyncedPath` values of the echo
|
|
34
|
+
* suppression contradict each other.
|
|
34
35
|
*
|
|
35
|
-
* **
|
|
36
|
-
*
|
|
37
|
-
*
|
|
36
|
+
* **The remedy:** call `bridge.disconnect()` on the first bridge before you connect
|
|
37
|
+
* the second one. You can also permit one active `connectRouter()` call for each
|
|
38
|
+
* actor at a time.
|
|
38
39
|
*
|
|
39
40
|
* **Error code:** `PLAY_ROUTER_DUPLICATE_BRIDGE`
|
|
40
41
|
*
|
|
@@ -55,20 +56,20 @@ export declare class DuplicateBridgeError extends PlayError {
|
|
|
55
56
|
constructor();
|
|
56
57
|
}
|
|
57
58
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
59
|
+
* The `RouteMap` constructor throws this error when the caller registers a
|
|
60
|
+
* parameterized route, the current runtime has no `URLPattern` API, and no polyfill
|
|
61
|
+
* is loaded.
|
|
61
62
|
*
|
|
62
|
-
* **
|
|
63
|
-
*
|
|
63
|
+
* **The remedy:** load `urlpattern-polyfill` at the entry point of your application,
|
|
64
|
+
* before each import of `@xmachines/play-router`:
|
|
64
65
|
*
|
|
65
66
|
* ```typescript
|
|
66
|
-
* //
|
|
67
|
+
* // the entry point of the application — it must run first
|
|
67
68
|
* import "urlpattern-polyfill";
|
|
68
69
|
* ```
|
|
69
70
|
*
|
|
70
|
-
* URLPattern is
|
|
71
|
-
*
|
|
71
|
+
* URLPattern is native in Node.js ≥ 24 and in a modern browser (Chrome 95+,
|
|
72
|
+
* Firefox 117+, Safari 16.4+). Use the polyfill for an older target.
|
|
72
73
|
*
|
|
73
74
|
* **Error code:** `PLAY_ROUTE_MAP_URLPATTERN_UNAVAILABLE`
|
|
74
75
|
*/
|
|
@@ -76,58 +77,59 @@ export declare class URLPatternUnavailableError extends PlayError {
|
|
|
76
77
|
constructor();
|
|
77
78
|
}
|
|
78
79
|
/**
|
|
79
|
-
*
|
|
80
|
-
* empty string path.
|
|
80
|
+
* `validateRouteFormat()` throws this error when a state declares a `meta.route`
|
|
81
|
+
* field with an empty string as its path.
|
|
81
82
|
*
|
|
82
83
|
* **Error code:** `PLAY_ROUTE_EMPTY_PATH`
|
|
83
84
|
*/
|
|
84
85
|
export declare class EmptyRoutePathError extends PlayError {
|
|
85
|
-
/** The state ID
|
|
86
|
+
/** The state ID with the empty route path. */
|
|
86
87
|
readonly stateId: string;
|
|
87
88
|
constructor(stateId: string);
|
|
88
89
|
}
|
|
89
90
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
91
|
+
* `validateStateExists()` throws this error when a route names a state ID that the
|
|
92
|
+
* machine graph does not hold.
|
|
92
93
|
*
|
|
93
94
|
* **Error code:** `PLAY_ROUTE_INVALID_STATE_ID`
|
|
94
95
|
*/
|
|
95
96
|
export declare class InvalidStateIdError extends PlayError {
|
|
96
|
-
/** The state ID
|
|
97
|
+
/** The state ID of the reference. The graph does not hold it. */
|
|
97
98
|
readonly stateId: string;
|
|
98
99
|
constructor(stateId: string);
|
|
99
100
|
}
|
|
100
101
|
/**
|
|
101
|
-
*
|
|
102
|
+
* `detectDuplicateRoutes()` throws this error when two states or more hold the same
|
|
103
|
+
* URL path.
|
|
102
104
|
*
|
|
103
105
|
* **Error code:** `PLAY_ROUTE_DUPLICATE_PATH`
|
|
104
106
|
*/
|
|
105
107
|
export declare class DuplicateRoutePathError extends PlayError {
|
|
106
|
-
/**
|
|
108
|
+
/** The list of the path → state-ID mappings of the conflict, for a person to read. */
|
|
107
109
|
readonly duplicates: string[];
|
|
108
110
|
constructor(duplicates: string[]);
|
|
109
111
|
}
|
|
110
112
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
+
* `machineToGraph()` throws this error when an XState state node has a `.type` value
|
|
114
|
+
* that the package does not know.
|
|
113
115
|
*
|
|
114
116
|
* **Error code:** `PLAY_ROUTE_UNKNOWN_STATE_TYPE`
|
|
115
117
|
*/
|
|
116
118
|
export declare class UnknownStateTypeError extends PlayError {
|
|
117
|
-
/** The
|
|
119
|
+
/** The string of the state type that the package does not know. */
|
|
118
120
|
readonly stateType: string;
|
|
119
121
|
/** The ID of the state node with the unknown type. */
|
|
120
122
|
readonly nodeId: string;
|
|
121
123
|
constructor(stateType: string, nodeId: string, validTypes: string[]);
|
|
122
124
|
}
|
|
123
125
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* original `URLPattern` constructor
|
|
126
|
+
* The `RouteMap` constructor throws this error when `URLPattern` cannot compile the
|
|
127
|
+
* string of a route pattern. The `pattern` field holds the string in question, and
|
|
128
|
+
* `cause` holds the original error of the `URLPattern` constructor.
|
|
127
129
|
*
|
|
128
|
-
*
|
|
129
|
-
* -
|
|
130
|
-
* -
|
|
130
|
+
* The common causes:
|
|
131
|
+
* - A parenthesis or a bracket without its pair in the string of the pattern
|
|
132
|
+
* - A character that a URL pathname pattern does not permit
|
|
131
133
|
*
|
|
132
134
|
* **Error code:** `PLAY_ROUTE_MAP_INVALID_PATTERN`
|
|
133
135
|
*
|
|
@@ -145,7 +147,7 @@ export declare class UnknownStateTypeError extends PlayError {
|
|
|
145
147
|
* ```
|
|
146
148
|
*/
|
|
147
149
|
export declare class InvalidRoutePatternError extends PlayError {
|
|
148
|
-
/** The route pattern
|
|
150
|
+
/** The string of the route pattern. URLPattern could not compile it. */
|
|
149
151
|
readonly pattern: string;
|
|
150
152
|
constructor(pattern: string, options?: ErrorOptions);
|
|
151
153
|
}
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,eAAgB,SAAQ,SAAS;gBACjC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAInD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;;CAUlD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,0BAA2B,SAAQ,SAAS;;CASxD;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;IACjD,8CAA8C;IAC9C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,MAAM;CAS3B;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;IACjD,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,MAAM;CAS3B;AAED;;;;;GAKG;AACH,qBAAa,uBAAwB,SAAQ,SAAS;IACrD,sFAAsF;IACtF,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC;gBAElB,UAAU,EAAE,MAAM,EAAE;CAWhC;AAED;;;;;GAKG;AACH,qBAAa,qBAAsB,SAAQ,SAAS;IACnD,mEAAmE;IACnE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE;CAWnE;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,wBAAyB,SAAQ,SAAS;IACtD,wEAAwE;IACxE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAUnD"}
|
package/dist/errors.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { PlayError } from "@xmachines/play";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* location change and send the
|
|
3
|
+
* The bridge throws this error when `RouterBridgeBase.syncActorFromRouter()`
|
|
4
|
+
* cannot process a location change of the router and send the `play.route` event to
|
|
5
|
+
* the actor.
|
|
5
6
|
*
|
|
6
|
-
* The `cause` property
|
|
7
|
+
* The `cause` property holds the original error.
|
|
7
8
|
*
|
|
8
9
|
* **Error code:** `PLAY_ROUTER_SYNC_FAILED`
|
|
9
10
|
*
|
|
@@ -27,17 +28,17 @@ export class RouterSyncError extends PlayError {
|
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
31
|
+
* `RouterBridgeBase.connect()` throws this error when a second bridge connects to an
|
|
32
|
+
* actor with an active bridge connection.
|
|
32
33
|
*
|
|
33
|
-
* One actor
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
34
|
+
* One actor can hold one router bridge at a time. Two bridges of the same actor both
|
|
35
|
+
* receive and process every navigation event of the router. They therefore send two
|
|
36
|
+
* `play.route` events to the actor, and their `lastSyncedPath` values of the echo
|
|
37
|
+
* suppression contradict each other.
|
|
37
38
|
*
|
|
38
|
-
* **
|
|
39
|
-
*
|
|
40
|
-
*
|
|
39
|
+
* **The remedy:** call `bridge.disconnect()` on the first bridge before you connect
|
|
40
|
+
* the second one. You can also permit one active `connectRouter()` call for each
|
|
41
|
+
* actor at a time.
|
|
41
42
|
*
|
|
42
43
|
* **Error code:** `PLAY_ROUTER_DUPLICATE_BRIDGE`
|
|
43
44
|
*
|
|
@@ -62,20 +63,20 @@ export class DuplicateBridgeError extends PlayError {
|
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
66
|
+
* The `RouteMap` constructor throws this error when the caller registers a
|
|
67
|
+
* parameterized route, the current runtime has no `URLPattern` API, and no polyfill
|
|
68
|
+
* is loaded.
|
|
68
69
|
*
|
|
69
|
-
* **
|
|
70
|
-
*
|
|
70
|
+
* **The remedy:** load `urlpattern-polyfill` at the entry point of your application,
|
|
71
|
+
* before each import of `@xmachines/play-router`:
|
|
71
72
|
*
|
|
72
73
|
* ```typescript
|
|
73
|
-
* //
|
|
74
|
+
* // the entry point of the application — it must run first
|
|
74
75
|
* import "urlpattern-polyfill";
|
|
75
76
|
* ```
|
|
76
77
|
*
|
|
77
|
-
* URLPattern is
|
|
78
|
-
*
|
|
78
|
+
* URLPattern is native in Node.js ≥ 24 and in a modern browser (Chrome 95+,
|
|
79
|
+
* Firefox 117+, Safari 16.4+). Use the polyfill for an older target.
|
|
79
80
|
*
|
|
80
81
|
* **Error code:** `PLAY_ROUTE_MAP_URLPATTERN_UNAVAILABLE`
|
|
81
82
|
*/
|
|
@@ -86,13 +87,13 @@ export class URLPatternUnavailableError extends PlayError {
|
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
/**
|
|
89
|
-
*
|
|
90
|
-
* empty string path.
|
|
90
|
+
* `validateRouteFormat()` throws this error when a state declares a `meta.route`
|
|
91
|
+
* field with an empty string as its path.
|
|
91
92
|
*
|
|
92
93
|
* **Error code:** `PLAY_ROUTE_EMPTY_PATH`
|
|
93
94
|
*/
|
|
94
95
|
export class EmptyRoutePathError extends PlayError {
|
|
95
|
-
/** The state ID
|
|
96
|
+
/** The state ID with the empty route path. */
|
|
96
97
|
stateId;
|
|
97
98
|
constructor(stateId) {
|
|
98
99
|
super("RouteMap", "PLAY_ROUTE_EMPTY_PATH", `Empty route path in state "${stateId}": routes must have a non-empty path`);
|
|
@@ -101,13 +102,13 @@ export class EmptyRoutePathError extends PlayError {
|
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
105
|
+
* `validateStateExists()` throws this error when a route names a state ID that the
|
|
106
|
+
* machine graph does not hold.
|
|
106
107
|
*
|
|
107
108
|
* **Error code:** `PLAY_ROUTE_INVALID_STATE_ID`
|
|
108
109
|
*/
|
|
109
110
|
export class InvalidStateIdError extends PlayError {
|
|
110
|
-
/** The state ID
|
|
111
|
+
/** The state ID of the reference. The graph does not hold it. */
|
|
111
112
|
stateId;
|
|
112
113
|
constructor(stateId) {
|
|
113
114
|
super("RouteMap", "PLAY_ROUTE_INVALID_STATE_ID", `Route references non-existent state ID: ${stateId}`);
|
|
@@ -116,12 +117,13 @@ export class InvalidStateIdError extends PlayError {
|
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
/**
|
|
119
|
-
*
|
|
120
|
+
* `detectDuplicateRoutes()` throws this error when two states or more hold the same
|
|
121
|
+
* URL path.
|
|
120
122
|
*
|
|
121
123
|
* **Error code:** `PLAY_ROUTE_DUPLICATE_PATH`
|
|
122
124
|
*/
|
|
123
125
|
export class DuplicateRoutePathError extends PlayError {
|
|
124
|
-
/**
|
|
126
|
+
/** The list of the path → state-ID mappings of the conflict, for a person to read. */
|
|
125
127
|
duplicates;
|
|
126
128
|
constructor(duplicates) {
|
|
127
129
|
super("RouteMap", "PLAY_ROUTE_DUPLICATE_PATH", `Duplicate route paths detected:\n${duplicates.join("\n")}\n\n` +
|
|
@@ -132,13 +134,13 @@ export class DuplicateRoutePathError extends PlayError {
|
|
|
132
134
|
}
|
|
133
135
|
}
|
|
134
136
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
+
* `machineToGraph()` throws this error when an XState state node has a `.type` value
|
|
138
|
+
* that the package does not know.
|
|
137
139
|
*
|
|
138
140
|
* **Error code:** `PLAY_ROUTE_UNKNOWN_STATE_TYPE`
|
|
139
141
|
*/
|
|
140
142
|
export class UnknownStateTypeError extends PlayError {
|
|
141
|
-
/** The
|
|
143
|
+
/** The string of the state type that the package does not know. */
|
|
142
144
|
stateType;
|
|
143
145
|
/** The ID of the state node with the unknown type. */
|
|
144
146
|
nodeId;
|
|
@@ -151,13 +153,13 @@ export class UnknownStateTypeError extends PlayError {
|
|
|
151
153
|
}
|
|
152
154
|
}
|
|
153
155
|
/**
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
* original `URLPattern` constructor
|
|
156
|
+
* The `RouteMap` constructor throws this error when `URLPattern` cannot compile the
|
|
157
|
+
* string of a route pattern. The `pattern` field holds the string in question, and
|
|
158
|
+
* `cause` holds the original error of the `URLPattern` constructor.
|
|
157
159
|
*
|
|
158
|
-
*
|
|
159
|
-
* -
|
|
160
|
-
* -
|
|
160
|
+
* The common causes:
|
|
161
|
+
* - A parenthesis or a bracket without its pair in the string of the pattern
|
|
162
|
+
* - A character that a URL pathname pattern does not permit
|
|
161
163
|
*
|
|
162
164
|
* **Error code:** `PLAY_ROUTE_MAP_INVALID_PATTERN`
|
|
163
165
|
*
|
|
@@ -175,7 +177,7 @@ export class UnknownStateTypeError extends PlayError {
|
|
|
175
177
|
* ```
|
|
176
178
|
*/
|
|
177
179
|
export class InvalidRoutePatternError extends PlayError {
|
|
178
|
-
/** The route pattern
|
|
180
|
+
/** The string of the route pattern. URLPattern could not compile it. */
|
|
179
181
|
pattern;
|
|
180
182
|
constructor(pattern, options) {
|
|
181
183
|
super("RouteMap", "PLAY_ROUTE_MAP_INVALID_PATTERN", `Invalid route pattern: "${pattern}"`, options);
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC7C,YAAY,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,kBAAkB,EAAE,yBAAyB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACvE,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAC/B,CAAC;CACD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,OAAO,oBA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;QACtC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC9B,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,OAAO,qBAAsB,SAAQ,SAAS;IACnD,mEAAmE;IAC1D,SAAS,CAAS;IAC3B,sDAAsD;IAC7C,MAAM,CAAS;IAExB,YAAY,SAAiB,EAAE,MAAc,EAAE,UAAoB;QAClE,KAAK,CACJ,gBAAgB,EAChB,+BAA+B,EAC/B,8BAA8B,SAAS,cAAc,MAAM,KAAK;YAC/D,oBAAoB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC7C,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;CACD;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,wBAAyB,SAAQ,SAAS;IACtD,wEAAwE;IAC/D,OAAO,CAAS;IAEzB,YAAY,OAAe,EAAE,OAAsB;QAClD,KAAK,CACJ,UAAU,EACV,gCAAgC,EAChC,2BAA2B,OAAO,GAAG,EACrC,OAAO,CACP,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;CACD"}
|
package/dist/extract-routes.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import type { AnyStateMachine } from "xstate";
|
|
2
2
|
import type { RouteTree } from "./types.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Reads the complete route tree from the graph of a state machine
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
* then walks graph nodes
|
|
8
|
-
*
|
|
9
|
-
* RouteTree for
|
|
6
|
+
* The function converts the XState machine into a Graph of @statelyai/graph, with
|
|
7
|
+
* machineToGraph(). It then walks the graph nodes: it reads the route metadata of
|
|
8
|
+
* each node, it checks each route reference, and it builds a hierarchical RouteTree.
|
|
9
|
+
* The RouteTree of the return value also holds the graph, for a later query that
|
|
10
|
+
* needs the transitions.
|
|
10
11
|
*
|
|
11
|
-
* @param machine - XState v5 state machine
|
|
12
|
-
* @returns
|
|
12
|
+
* @param machine - The XState v5 state machine
|
|
13
|
+
* @returns The route tree, with its root, its byStateId map, its byPath map, and its graph
|
|
13
14
|
*/
|
|
14
15
|
export declare const extractMachineRoutes: (machine: AnyStateMachine) => RouteTree;
|
|
15
16
|
//# sourceMappingURL=extract-routes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-routes.d.ts","sourceRoot":"","sources":["../src/extract-routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,KAAK,EAAE,SAAS,EAA6C,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"extract-routes.d.ts","sourceRoot":"","sources":["../src/extract-routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,KAAK,EAAE,SAAS,EAA6C,MAAM,YAAY,CAAC;AA6EvF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,GAAI,SAAS,eAAe,KAAG,SAoB/D,CAAC"}
|
package/dist/extract-routes.js
CHANGED
|
@@ -2,14 +2,16 @@ import { machineToGraph } from "./machine-to-graph.js";
|
|
|
2
2
|
import { validateRouteFormat, validateStateExists } from "./validate-routes.js";
|
|
3
3
|
import { buildRouteTree } from "./build-tree.js";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Builds the statePath of a graph node, and it walks the chain of the parentId
|
|
6
|
+
* values.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
8
|
+
* The function makes an array of the stateId segments, from the root to this node,
|
|
9
|
+
* and the array holds no root. This is the format of the parent lookup in
|
|
10
|
+
* buildRouteTree.
|
|
9
11
|
*
|
|
10
|
-
* @param graphNode - The node
|
|
11
|
-
* @param graphNodeMap -
|
|
12
|
-
* @returns
|
|
12
|
+
* @param graphNode - The node of the path
|
|
13
|
+
* @param graphNodeMap - The map from a node id to a GraphNode, for a parent lookup in O(1)
|
|
14
|
+
* @returns The array of the stateId segments, for example ["dashboard", "overview"]
|
|
13
15
|
*/
|
|
14
16
|
const buildStatePath = (graphNode, graphNodeMap) => {
|
|
15
17
|
const path = [];
|
|
@@ -21,22 +23,22 @@ const buildStatePath = (graphNode, graphNodeMap) => {
|
|
|
21
23
|
return path;
|
|
22
24
|
};
|
|
23
25
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
+
* Reads the route information of the MachineNodeData object of a graph node.
|
|
27
|
+
* The function returns null when the node has no route.
|
|
26
28
|
*/
|
|
27
29
|
const extractRouteFromNode = (graphNode, stateIds, graphNodeMap) => {
|
|
28
30
|
const { stateId, route, meta } = graphNode.data;
|
|
29
|
-
//
|
|
31
|
+
// The node has no route
|
|
30
32
|
if (!route)
|
|
31
33
|
return null;
|
|
32
|
-
//
|
|
34
|
+
// Check the format. The path must start with /
|
|
33
35
|
validateRouteFormat(route, stateId);
|
|
34
|
-
//
|
|
36
|
+
// Check that the graph holds the state. This test is redundant, and it guards against a corruption
|
|
35
37
|
validateStateExists(stateId, stateIds);
|
|
36
|
-
// Build statePath from
|
|
38
|
+
// Build the statePath from the chain of the parentId values. This works for an explicit ID and also for a generated one
|
|
37
39
|
const statePath = buildStatePath(graphNode, graphNodeMap);
|
|
38
40
|
const pattern = route.includes(":") ? route : undefined;
|
|
39
|
-
//
|
|
41
|
+
// Build the original shape of the metadata again, from the data of the graph
|
|
40
42
|
const metadata = meta && typeof meta === "object" && "route" in meta
|
|
41
43
|
? meta["route"]
|
|
42
44
|
: route;
|
|
@@ -53,30 +55,32 @@ const extractRouteFromNode = (graphNode, stateIds, graphNodeMap) => {
|
|
|
53
55
|
return result;
|
|
54
56
|
};
|
|
55
57
|
/**
|
|
56
|
-
*
|
|
58
|
+
* Reads the complete route tree from the graph of a state machine
|
|
57
59
|
*
|
|
58
|
-
*
|
|
59
|
-
* then walks graph nodes
|
|
60
|
-
*
|
|
61
|
-
* RouteTree for
|
|
60
|
+
* The function converts the XState machine into a Graph of @statelyai/graph, with
|
|
61
|
+
* machineToGraph(). It then walks the graph nodes: it reads the route metadata of
|
|
62
|
+
* each node, it checks each route reference, and it builds a hierarchical RouteTree.
|
|
63
|
+
* The RouteTree of the return value also holds the graph, for a later query that
|
|
64
|
+
* needs the transitions.
|
|
62
65
|
*
|
|
63
|
-
* @param machine - XState v5 state machine
|
|
64
|
-
* @returns
|
|
66
|
+
* @param machine - The XState v5 state machine
|
|
67
|
+
* @returns The route tree, with its root, its byStateId map, its byPath map, and its graph
|
|
65
68
|
*/
|
|
66
69
|
export const extractMachineRoutes = (machine) => {
|
|
67
|
-
// 1. Convert machine
|
|
70
|
+
// 1. Convert the machine into a graph
|
|
68
71
|
const graph = machineToGraph(machine);
|
|
69
|
-
// 2. Build state
|
|
72
|
+
// 2. Build the set of the state IDs, for the check, and the node map, for a parent lookup in O(1)
|
|
70
73
|
const stateIds = new Set(graph.nodes.map((n) => n.data.stateId));
|
|
71
74
|
const graphNodeMap = new Map(graph.nodes.map((n) => [n.id, n]));
|
|
72
|
-
// 3.
|
|
75
|
+
// 3. Read the routes of the graph nodes
|
|
73
76
|
const routes = graph.nodes
|
|
74
77
|
.map((node) => extractRouteFromNode(node, stateIds, graphNodeMap))
|
|
75
78
|
.filter((r) => r !== null);
|
|
76
|
-
// 4. Build hierarchical tree and attach graph.
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
//
|
|
79
|
+
// 4. Build the hierarchical tree, and attach the graph.
|
|
80
|
+
// buildRouteTree finds each duplicate route, AFTER it resolved each relative route
|
|
81
|
+
// to a complete path. The raw route strings are not comparable, because two
|
|
82
|
+
// relative "settings" routes below two different parents are two different
|
|
83
|
+
// routes.
|
|
80
84
|
const tree = buildRouteTree(routes);
|
|
81
85
|
return { ...tree, graph };
|
|
82
86
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-routes.js","sourceRoot":"","sources":["../src/extract-routes.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAqB,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD
|
|
1
|
+
{"version":3,"file":"extract-routes.js","sourceRoot":"","sources":["../src/extract-routes.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAqB,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD;;;;;;;;;;;GAWG;AACH,MAAM,cAAc,GAAG,CACtB,SAAqC,EACrC,YAAqD,EAC1C,EAAE;IACb,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,IAAI,OAAO,GAA2C,SAAS,CAAC;IAEhE,OAAO,OAAO,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,IAAI,OAAO,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC/E,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACnC,OAAO,GAAG,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,oBAAoB,GAAG,CAC5B,SAAqC,EACrC,QAAqB,EACrB,YAAqD,EAClC,EAAE;IACrB,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE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AAI,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAEhE,wCAAwC;IACxC,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK;SACxB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,oBAAoB,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;SACjE,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/dist/find-route.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { RouteTree, RouteNode } from "./types.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Finds a route node by its state ID
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* The function looks the route node up by the ID property of the state. It gives you
|
|
6
|
+
* the URL path of a state ID, for the update of the browser URL after a `play.route`
|
|
7
|
+
* transition.
|
|
7
8
|
*
|
|
8
|
-
* @param tree -
|
|
9
|
-
* @param id -
|
|
10
|
-
* @returns
|
|
9
|
+
* @param tree - The route tree, from extractMachineRoutes
|
|
10
|
+
* @param id - The state ID, for example 'dashboard' or 'settings.profile'
|
|
11
|
+
* @returns The route node, or undefined when the function finds none
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
13
14
|
* ```typescript
|
|
@@ -20,19 +21,21 @@ import type { RouteTree, RouteNode } from "./types.js";
|
|
|
20
21
|
*/
|
|
21
22
|
export declare const findRouteById: (tree: RouteTree, id: string) => RouteNode | undefined;
|
|
22
23
|
/**
|
|
23
|
-
*
|
|
24
|
+
* Finds a route node by its URL path
|
|
24
25
|
*
|
|
25
|
-
*
|
|
26
|
-
* URL for
|
|
26
|
+
* The function looks the route node up by the URL path. It gives you the state ID of
|
|
27
|
+
* a browser URL, for the `play.route` event of a navigation.
|
|
27
28
|
*
|
|
28
|
-
* When
|
|
29
|
-
* prefers
|
|
29
|
+
* When more than one state holds the same path, for example the root and a second
|
|
30
|
+
* state both at "/", the function prefers a node with a route, which means a node
|
|
31
|
+
* with a `meta.route` field, over a node without one.
|
|
30
32
|
*
|
|
31
|
-
*
|
|
33
|
+
* The function also matches a pattern of a dynamic route, for example
|
|
34
|
+
* '/settings/:section?'.
|
|
32
35
|
*
|
|
33
|
-
* @param tree -
|
|
34
|
-
* @param path - URL path
|
|
35
|
-
* @returns
|
|
36
|
+
* @param tree - The route tree, from extractMachineRoutes
|
|
37
|
+
* @param path - The URL path, for example '/dashboard' or '/settings/profile'
|
|
38
|
+
* @returns The route node, or undefined when the function finds none
|
|
36
39
|
*
|
|
37
40
|
* @example
|
|
38
41
|
* ```typescript
|
package/dist/find-route.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-route.d.ts","sourceRoot":"","sources":["../src/find-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"find-route.d.ts","sourceRoot":"","sources":["../src/find-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAsCvD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,SAAS,EAAE,IAAI,MAAM,KAAG,SAAS,GAAG,SAEvE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,SAAS,EAAE,MAAM,MAAM,KAAG,SAAS,GAAG,SAyB3E,CAAC"}
|