@xmachines/play-router 2.2.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/README.md +103 -109
  2. package/dist/base-route-map.d.ts +7 -1
  3. package/dist/base-route-map.d.ts.map +1 -1
  4. package/dist/base-route-map.js +25 -12
  5. package/dist/base-route-map.js.map +1 -1
  6. package/dist/build-tree.d.ts +16 -1
  7. package/dist/build-tree.d.ts.map +1 -1
  8. package/dist/build-tree.js +23 -6
  9. package/dist/build-tree.js.map +1 -1
  10. package/dist/create-route-map-from-tree.d.ts +12 -6
  11. package/dist/create-route-map-from-tree.d.ts.map +1 -1
  12. package/dist/create-route-map-from-tree.js +13 -5
  13. package/dist/create-route-map-from-tree.js.map +1 -1
  14. package/dist/errors.d.ts +2 -134
  15. package/dist/errors.d.ts.map +1 -1
  16. package/dist/errors.js +11 -151
  17. package/dist/errors.js.map +1 -1
  18. package/dist/find-route.d.ts.map +1 -1
  19. package/dist/find-route.js +14 -19
  20. package/dist/find-route.js.map +1 -1
  21. package/dist/index.d.ts +7 -16
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +10 -11
  24. package/dist/index.js.map +1 -1
  25. package/dist/provider-lifecycle.d.ts +28 -6
  26. package/dist/provider-lifecycle.d.ts.map +1 -1
  27. package/dist/provider-lifecycle.js +16 -2
  28. package/dist/provider-lifecycle.js.map +1 -1
  29. package/dist/router-bridge-base.d.ts +42 -23
  30. package/dist/router-bridge-base.d.ts.map +1 -1
  31. package/dist/router-bridge-base.js +257 -84
  32. package/dist/router-bridge-base.js.map +1 -1
  33. package/dist/router-sync.d.ts +1 -1
  34. package/dist/router-sync.d.ts.map +1 -1
  35. package/dist/router-sync.js +28 -13
  36. package/dist/router-sync.js.map +1 -1
  37. package/dist/types.d.ts +186 -87
  38. package/dist/types.d.ts.map +1 -1
  39. package/dist/{create-route-map.d.ts → xstate/create-route-map.d.ts} +6 -20
  40. package/dist/xstate/create-route-map.d.ts.map +1 -0
  41. package/dist/{create-route-map.js → xstate/create-route-map.js} +5 -3
  42. package/dist/xstate/create-route-map.js.map +1 -0
  43. package/dist/{extract-routes.d.ts → xstate/extract-routes.d.ts} +3 -2
  44. package/dist/xstate/extract-routes.d.ts.map +1 -0
  45. package/dist/{extract-routes.js → xstate/extract-routes.js} +8 -3
  46. package/dist/xstate/extract-routes.js.map +1 -0
  47. package/dist/xstate/index.d.ts +35 -0
  48. package/dist/xstate/index.d.ts.map +1 -0
  49. package/dist/xstate/index.js +33 -0
  50. package/dist/xstate/index.js.map +1 -0
  51. package/dist/{machine-to-graph.d.ts → xstate/machine-to-graph.d.ts} +1 -1
  52. package/dist/xstate/machine-to-graph.d.ts.map +1 -0
  53. package/dist/{machine-to-graph.js → xstate/machine-to-graph.js} +2 -2
  54. package/dist/xstate/machine-to-graph.js.map +1 -0
  55. package/dist/xstate/machine-types.d.ts +42 -0
  56. package/dist/xstate/machine-types.d.ts.map +1 -0
  57. package/dist/xstate/machine-types.js +2 -0
  58. package/dist/xstate/machine-types.js.map +1 -0
  59. package/dist/{query.d.ts → xstate/query.d.ts} +6 -4
  60. package/dist/xstate/query.d.ts.map +1 -0
  61. package/dist/{query.js → xstate/query.js} +3 -2
  62. package/dist/xstate/query.js.map +1 -0
  63. package/package.json +26 -20
  64. package/dist/base-path.d.ts +0 -209
  65. package/dist/base-path.d.ts.map +0 -1
  66. package/dist/base-path.js +0 -418
  67. package/dist/base-path.js.map +0 -1
  68. package/dist/create-route-map.d.ts.map +0 -1
  69. package/dist/create-route-map.js.map +0 -1
  70. package/dist/extract-routes.d.ts.map +0 -1
  71. package/dist/extract-routes.js.map +0 -1
  72. package/dist/framework-params.d.ts +0 -144
  73. package/dist/framework-params.d.ts.map +0 -1
  74. package/dist/framework-params.js +0 -291
  75. package/dist/framework-params.js.map +0 -1
  76. package/dist/machine-to-graph.d.ts.map +0 -1
  77. package/dist/machine-to-graph.js.map +0 -1
  78. package/dist/query.d.ts.map +0 -1
  79. package/dist/query.js.map +0 -1
  80. package/dist/url-pattern-utils.d.ts +0 -93
  81. package/dist/url-pattern-utils.d.ts.map +0 -1
  82. package/dist/url-pattern-utils.js +0 -233
  83. package/dist/url-pattern-utils.js.map +0 -1
@@ -1,291 +0,0 @@
1
- /**
2
- * The params of a framework router, reconciled with the pattern of the machine.
3
- *
4
- * A framework that parses the params itself — Vue Router and SolidJS Router both do —
5
- * lets a bridge keep that parse instead of running URLPattern again. The decision that
6
- * makes it safe is the same in each of them, and the source of the params is the one
7
- * thing that differs, so the decision lives here and each bridge supplies its source.
8
- *
9
- * @see [Multi-router integration](../../docs/examples/multi-router-integration.md)
10
- */
11
- /**
12
- * The expression reads each NAMED parameter of a route pattern of the route map, for
13
- * example `userId` of `/profile/:userId`, `section` of `/settings/:section?`, and
14
- * `cat-id` of `/docs/:cat-id`. A `*` wildcard carries no name, and the expression
15
- * therefore matches it not.
16
- */
17
- const PATTERN_PARAM_NAME_RE = /:([A-Za-z_$][A-Za-z0-9_$-]*)(\?)?/g;
18
- /**
19
- * Reads the names of every `:param` of a route pattern of the route map.
20
- *
21
- * @param pattern - A route pattern, for example `/profile/:userId`.
22
- * @returns The names, in the order that the pattern declares them. A fresh array, because
23
- * `readPatternParams` caches the one it holds.
24
- */
25
- export function getPatternParamNames(pattern) {
26
- return [...readPatternParams(pattern).names];
27
- }
28
- /**
29
- * The names of each pattern that this module has read, kept at the module level.
30
- *
31
- * {@link resolveFrameworkParams} runs on EVERY navigation, and the answer for one
32
- * pattern never changes: a pattern is a static string of the route map. The number of
33
- * the route patterns of the application therefore bounds this cache, exactly as it
34
- * bounds the compiled-pattern cache of `url-pattern-utils.ts`.
35
- */
36
- const patternParamCache = new Map();
37
- /**
38
- * Reads the declared names and the REQUIRED names of a pattern in ONE scan.
39
- *
40
- * {@link resolveFrameworkParams} needs both lists for every navigation, and two calls
41
- * walked the pattern two times and allocated two match arrays for one answer. The two
42
- * exported readers stay, because each one names what a caller asks for.
43
- *
44
- * The result is CACHED, and each caller therefore treats the two arrays as read-only.
45
- */
46
- function readPatternParams(pattern) {
47
- const cached = patternParamCache.get(pattern);
48
- if (cached)
49
- return cached;
50
- const names = [];
51
- const required = [];
52
- for (const match of pattern.matchAll(PATTERN_PARAM_NAME_RE)) {
53
- const name = match[1] ?? "";
54
- names.push(name);
55
- if (match[2] === undefined)
56
- required.push(name);
57
- }
58
- const read = { names, required };
59
- patternParamCache.set(pattern, read);
60
- return read;
61
- }
62
- /**
63
- * The names of every param the pattern REQUIRES, so `:name?` is left out.
64
- *
65
- * An optional segment that did not match has no value, and a framework reports none.
66
- * That is a complete answer and not a partial one, so a MIXED pattern such as
67
- * `/profile/:userId/:tab?` keeps the parse of the framework when only `:tab` is absent.
68
- * A caller that counted that absence as a gap would fall back to the URLPattern
69
- * extraction, which THROWS on a runtime with no URLPattern — for a route the framework
70
- * had already answered.
71
- *
72
- * A pattern whose params are ALL optional reports nothing at all, which reads the same
73
- * as "the framework matched another route", so {@link pickOwnParams} falls back for it.
74
- * {@link resolveFrameworkParams} settles that case from the PATH instead, and it needs
75
- * no URLPattern to do it.
76
- *
77
- * @param pattern - A route pattern, for example `/profile/:userId/:tab?`.
78
- * @returns The required names, in the order that the pattern declares them. A fresh
79
- * array, because `readPatternParams` caches the one it holds.
80
- */
81
- export function getRequiredPatternParamNames(pattern) {
82
- return [...readPatternParams(pattern).required];
83
- }
84
- /**
85
- * Keeps the entries of `params` whose name the pattern of the machine declares, and
86
- * only when the result covers EVERY name of that pattern.
87
- *
88
- * A complete pick is an answer, and a partial pick is not: a wrapper route of the host
89
- * can declare a subset of the params of the machine — a tenant segment, for example,
90
- * but not the document one — and keeping that subset drops the rest from a route that
91
- * declares them. The caller falls back to its own extraction for `null`.
92
- *
93
- * The result has a null prototype, so a param named `__proto__` stays an own key.
94
- *
95
- * An OPTIONAL name of the pattern (`:name?`) is covered whether the framework reports
96
- * it or not: a segment that did not match has no value, and that is a complete answer.
97
- * At least one declared name must come back, though — a framework that reports none
98
- * matched another route, and the path may still hold a value that only the fallback
99
- * reads. A pattern whose params are ALL optional therefore always answers `null` here
100
- * when the framework reports nothing; {@link resolveFrameworkParams} then reads the PATH,
101
- * which settles the question without the framework and without URLPattern.
102
- *
103
- * @param params - The params of the framework router. {@link cleanFrameworkParams}
104
- * removes each empty value already, and one that reaches here anyway counts as
105
- * absent: an empty value says that the segment did not match, and never that the
106
- * path carries the empty string.
107
- * @param names - The names that the pattern of the machine declares.
108
- * @param requiredNames - The names the pattern REQUIRES. The default treats every name
109
- * as required, so a two-argument call keeps the strict test.
110
- * @returns The params of the machine, or `null` when the framework covers them not.
111
- */
112
- export function pickOwnParams(params, names, requiredNames = names) {
113
- const required = new Set(requiredNames);
114
- const picked = Object.create(null);
115
- for (const name of names) {
116
- // `Object.hasOwn` first, and not a bare read: this function is exported, so a
117
- // caller can hand it a plain object, and `params["constructor"]` then walks the
118
- // prototype chain and answers with a function for a name that the object holds not.
119
- const value = Object.hasOwn(params, name)
120
- ? params[name] // nosemgrep: gitlab.eslint.detect-object-injection
121
- : undefined;
122
- // An ABSENT value, and an empty one: {@link cleanFrameworkParams} drops both
123
- // already, and this function is exported, so a caller of its own reaches here with
124
- // either. A `?? ""` fallback wrote the empty value into the pick instead — the
125
- // exact value that cleaning exists to remove — and that entry then counted as "the
126
- // framework matched this route", so the pick won over the fallback that reads the
127
- // value the PATH carries.
128
- if (value === undefined || value === null || value === "") {
129
- if (required.has(name))
130
- return null;
131
- continue;
132
- }
133
- picked[name] = value; // nosemgrep: gitlab.eslint.detect-object-injection
134
- }
135
- // NONE of the declared names came back, so the framework matched another route — a
136
- // catch-all, in practice — and it knows nothing about this pattern. An empty pick
137
- // would then drop a value the PATH carries: `/settings/security` against
138
- // `/settings/:section?` holds "security", and only the fallback reads it. One name
139
- // present is what says the framework matched this route, and an optional segment that
140
- // did not match is genuinely absent.
141
- if (names.length > 0 && Object.keys(picked).length === 0)
142
- return null;
143
- // Spread at the boundary: `event.params` reaches a machine of the user, and it was a
144
- // plain object before this release. A spread creates OWN properties, so a param named
145
- // "__proto__" stays a key while the value keeps a prototype — `hasOwnProperty` on it
146
- // therefore answers instead of throwing.
147
- return { ...picked };
148
- }
149
- /**
150
- * The params of a framework router, in the shape that {@link pickOwnParams} reads.
151
- *
152
- * Every framework reports a param that its own route DECLARES and that the location
153
- * did not fill: Vue Router gives `undefined` or `""`, and SolidJS Router does the
154
- * same. Such an entry is not an answer, and a pick that kept it would send an empty
155
- * value to the actor as though the path carried one. Drop it here instead, one time,
156
- * because the rule belongs to the decision of {@link resolveFrameworkParams} and not
157
- * to a bridge: `VueRouterBridge` and `SolidRouterBridge` held one copy each.
158
- *
159
- * A value of an array — the splat of a catch-all route of Vue Router — becomes its
160
- * `String()` form, exactly as a single value does.
161
- *
162
- * The result has a null prototype, for the same reason {@link pickOwnParams} gives: a
163
- * plain `{}` accumulator turns `cleaned["__proto__"] = value` into a write of the
164
- * PROTOTYPE setter, which drops a string value in silence. `pickOwnParams` then read
165
- * `Object.hasOwn(params, "__proto__")` as `false`, called the pick incomplete, and fell
166
- * back to the URLPattern extraction — which THROWS on a runtime with no URLPattern, for
167
- * a route the framework had answered already.
168
- *
169
- * @param params - The raw params of the framework router.
170
- * @returns The params with no absent value, each one a string.
171
- */
172
- export function cleanFrameworkParams(params) {
173
- const cleaned = Object.create(null);
174
- for (const [name, value] of Object.entries(params)) {
175
- if (value === undefined || value === null)
176
- continue;
177
- // The test runs on the STRING, and not on the raw value: a repeatable segment that
178
- // the location did not fill comes back as an EMPTY ARRAY from Vue Router, and `[]`
179
- // is not `""`. A raw test therefore let it through as `String([])`, which is the
180
- // empty value this function exists to drop — `pickOwnParams` then picked it and the
181
- // actor received `{ section: "" }` as though the path carried a value.
182
- const text = String(value);
183
- if (text === "")
184
- continue;
185
- cleaned[name] = text; // nosemgrep: gitlab.eslint.detect-object-injection
186
- }
187
- return cleaned;
188
- }
189
- /** A segment that is exactly one optional param, for example `:section?`. */
190
- const OPTIONAL_SEGMENT_RE = /^:[A-Za-z_$][A-Za-z0-9_$-]*\?$/;
191
- /**
192
- * True when the path IS the pattern with every optional segment absent.
193
- *
194
- * The test reads the PATH, and it trusts the framework with nothing. A pattern whose
195
- * trailing segments are all optional has a bare form that holds no `:` and no `*` —
196
- * `/settings/:section?` has the bare form `/settings` — and a path that equals that
197
- * form can only match the pattern with every optional group absent. No param has a
198
- * value, so `{}` is the complete answer whatever route the framework matched, and the
199
- * URLPattern fallback has nothing to add.
200
- *
201
- * The function answers `false` for anything it cannot prove:
202
- *
203
- * - An optional segment that is NOT trailing. `/a/:b?/c` matches `/a//c` for URLPattern,
204
- * because the `/` before the group is a literal of its own, so `/a/c` is no bare form.
205
- * - A remaining segment that holds a `:` or a `*`. A required param has a value that
206
- * only the fallback reads, and a wildcard matches a path of any length.
207
- *
208
- * @param pathname - The machine-side path, with the mount prefix already removed.
209
- * @param pattern - The route pattern of the machine.
210
- */
211
- function pathIsBareForm(pathname, pattern) {
212
- const segments = pattern.split("/");
213
- let end = segments.length;
214
- while (end > 0 && OPTIONAL_SEGMENT_RE.test(segments.at(end - 1) ?? ""))
215
- end -= 1;
216
- // Nothing was optional at the end, so the pattern needs a value somewhere.
217
- if (end === segments.length)
218
- return false;
219
- const kept = segments.slice(0, end);
220
- if (kept.some((segment) => segment.includes(":") || segment.includes("*")))
221
- return false;
222
- return trimPath(kept.join("/")) === trimPath(pathname);
223
- }
224
- /**
225
- * One comparable form for a path: no query, no fragment, and no trailing slash.
226
- *
227
- * The root stays `"/"`, because a bare pattern of `/:section?` has the bare form `""`
228
- * and the path of that page is `"/"`.
229
- */
230
- function trimPath(path) {
231
- const cut = path.split(/[?#]/)[0] ?? "";
232
- const trimmed = cut.length > 1 && cut.endsWith("/") ? cut.slice(0, -1) : cut;
233
- return trimmed === "" ? "/" : trimmed;
234
- }
235
- /**
236
- * Decides which params describe the route of the machine.
237
- *
238
- * The three branches, in the order that they apply:
239
- *
240
- * - **The pattern declares no name** — a static path, a bare `*` wildcard, or an
241
- * unknown stateId. The answer is `{}`. The params of the framework must NOT travel
242
- * here: under a catch-all they hold the splat of the host, and that value would reach
243
- * the actor as a param of the machine. This branch also reaches no URLPattern, which
244
- * matters: the extraction needs the constructor even for a pattern with no parameter,
245
- * so a delegation would throw on a runtime without the API.
246
- * - **The bridge sits under a mount** — the framework matched a route of the HOST by
247
- * construction, because the machine owns the suffix of the path only. Its params
248
- * therefore describe this pattern never, whatever they are named, and a name that
249
- * happens to collide carries the value of the host. Read the params of the machine
250
- * from its own pattern instead.
251
- * - **The framework covers every REQUIRED name** — it matched the machine route. Keep
252
- * its parse, together with its decoding. An optional `:name?` that the framework
253
- * reports not is covered too: a segment that did not match has no value. A gap in a
254
- * required name falls back, because keeping it would drop a name the route declares.
255
- * - **The path IS the bare form of the pattern** — every optional segment is absent, so
256
- * `{}` is the complete answer. The branch reads the path and trusts the framework with
257
- * nothing, which is what makes it safe under a catch-all of the host, and it calls
258
- * URLPattern for a location that needs none.
259
- *
260
- * None of this decides whether the APPLICATION needs a URLPattern polyfill. A `RouteMap`
261
- * that holds one parameterized route compiles it in the CONSTRUCTOR, and it throws a
262
- * `URLPatternUnavailableError` there when the runtime has no URLPattern. The polyfill
263
- * question is therefore settled at startup: only a route map of static paths alone
264
- * escapes it. What these branches decide is whether a NAVIGATION calls URLPattern again.
265
- *
266
- * @returns The path parameters of the machine route, or `{}`.
267
- */
268
- export function resolveFrameworkParams({ pattern, basePath, pathname, frameworkParams, fallback, }) {
269
- if (!pattern)
270
- return {};
271
- // One scan of the pattern, for both lists: this runs on every navigation.
272
- const { names, required } = readPatternParams(pattern);
273
- if (names.length === 0)
274
- return {};
275
- if (basePath !== "")
276
- return fallback();
277
- const picked = pickOwnParams(frameworkParams(), names, required);
278
- if (picked !== null)
279
- return picked;
280
- // The framework reported none of the names. That is ambiguous on its own — it means
281
- // "the segment is absent" or "another route matched" — and the PATH settles it
282
- // without the framework and without URLPattern: a path that is the bare form of the
283
- // pattern fills no optional segment, so `{}` is the complete answer.
284
- //
285
- // Only an all-optional pattern reaches this: `pathIsBareForm` refuses a bare form
286
- // that still holds a `:`, so a missing REQUIRED name still falls back.
287
- if (pathname !== undefined && pathIsBareForm(pathname, pattern))
288
- return {};
289
- return fallback();
290
- }
291
- //# sourceMappingURL=framework-params.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"framework-params.js","sourceRoot":"","sources":["../src/framework-params.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;GAKG;AACH,MAAM,qBAAqB,GAAG,oCAAoC,CAAC;AAEnE;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAe;IACnD,OAAO,CAAC,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAmD,CAAC;AAErF;;;;;;;;GAQG;AACH,SAAS,iBAAiB,CAAC,OAAe;IACzC,MAAM,MAAM,GAAG,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9C,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC;QAC7D,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC5B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS;YAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjD,CAAC;IACD,MAAM,IAAI,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;IACjC,iBAAiB,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,C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Q,EAAE,CAAC;IAEvC,MAAM,MAAM,GAAG,aAAa,CAAC,eAAe,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;IACjE,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAEnC,oFAAoF;IACpF,+EAA+E;IAC/E,oFAAoF;IACpF,qEAAqE;IACrE,EAAE;IACF,kFAAkF;IAClF,uEAAuE;IACvE,IAAI,QAAQ,KAAK,SAAS,IAAI,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC;QAAE,OAAO,EAAE,CAAC;IAE3E,OAAO,QAAQ,EAAE,CAAC;AACnB,CAAC"}
@@ -1 +0,0 @@
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"}
@@ -1 +0,0 @@
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,aAAa,CAAC;AAgBpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH;;;;GAIG;AACH,MAAM,iBAAiB,GAAwB,IAAI,GAAG,CAAC;IACtD,QAAQ;IACR,UAAU;IACV,U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ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAa,MAAM,kBAAkB,CAAC;AAEzD,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACzF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAIN,KAAK,eAAe,EACpB,MAAM,gBAAgB,CAAC;AAqBxB;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,kBAAkB,GAAI,MAAM,SAAS,EAAE,SAAS,MAAM,KAAG,SAAS,EA0B9E,CAAC;AAkBF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,SAAS,KAAG,SAAS,EAW5D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,SAAS,EAAE,MAAM,MAAM,KAAG,OAE3D,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,4BAA4B,GACxC,OAAO,KAAK,CAAC,eAAe,EAAE,eAAe,CAAC,EAC9C,SAAS,MAAM,KACb,MAAM,EAER,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,gBAAgB,GAC5B,OAAO,KAAK,CAAC,eAAe,EAAE,eAAe,CAAC,EAC9C,aAAa,MAAM,EACnB,WAAW,MAAM,KACf,OAKF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,SAAS,EAAE,UAAU,eAAe,KAAG,YAAY,EAazF,CAAC"}
package/dist/query.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,OA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ern that this package uses.
3
- * The package therefore needs no hard dependency on the complete type declaration of
4
- * URLPattern.
5
- */
6
- export type URLPatternLike = {
7
- exec(input: {
8
- pathname: string;
9
- }): {
10
- pathname: {
11
- groups: Record<string, string | undefined>;
12
- };
13
- } | null;
14
- test(input: {
15
- pathname: string;
16
- }): boolean;
17
- };
18
- /** The constructor type of a URLPatternLike instance. */
19
- export type URLPatternCtor = new (init: {
20
- pathname: string;
21
- }) => URLPatternLike;
22
- /**
23
- * Returns the URLPattern constructor of `globalThis`, or `undefined` when it is
24
- * absent: in Node < 24, and in an older browser without a polyfill.
25
- */
26
- export declare function getURLPatternCtor(): URLPatternCtor | undefined;
27
- /**
28
- * Tells you if a route path is a parameterized pattern, and not a concrete URL.
29
- *
30
- * A pattern holds a `:param` segment, which is necessary or optional, or the `*`
31
- * wildcard, or both. Each of them needs a URLPattern match, and each of them carries
32
- * no concrete value. Therefore the code can push such a path to a browser URL
33
- * never.
34
- *
35
- * This function is THE single source of truth of the question "is this path a
36
- * pattern?". `RouteMap` uses it for its decision between the static map and the
37
- * index of the pattern buckets, and `RouterBridgeBase.resolveNavigationPath` uses it
38
- * to skip a route of no navigation. The two tests therefore cannot move apart.
39
- *
40
- * @param path - The string of a URL path or of a route pattern, for example `/profile/:userId` or `/docs/*`
41
- * @returns `true` when the path holds a `:param` or a `*` pattern syntax
42
- */
43
- export declare function isParameterizedPattern(path: string): boolean;
44
- /**
45
- * Normalizes a route path, so that each of its parameter names is a valid URLPattern
46
- * identifier.
47
- *
48
- * URLPattern requires a valid JS identifier as a parameter name, and such an
49
- * identifier holds no hyphen. Therefore the function replaces a name with a hyphen,
50
- * for example `:cat-id`, with the equivalent name with an underscore (`:cat_id`),
51
- * for the compilation step of URLPattern. A caller that needs the values of the
52
- * captured groups, and not a test of the match alone, must map each normalized group
53
- * name back to the original param name with {@link getNormalizedParamNameMap}.
54
- *
55
- * @example
56
- * normalizeParamNames("/docs/:cat-id/:page-num?")
57
- * // → "/docs/:cat_id/:page_num?"
58
- */
59
- export declare function normalizeParamNames(path: string): string;
60
- /**
61
- * Builds the map from each normalized URLPattern group name back to the original
62
- * param name, which holds a hyphen, of a route pattern.
63
- *
64
- * The map holds only the params that {@link normalizeParamNames} rewrote. A param
65
- * with a valid identifier keeps its own name, and it needs no entry.
66
- *
67
- * @example
68
- * getNormalizedParamNameMap("/docs/:cat-id/:plain")
69
- * // → Map { "cat_id" → "cat-id" }
70
- */
71
- export declare function getNormalizedParamNameMap(path: string): Map<string, string>;
72
- export declare function getCompiledPattern(pattern: string, Ctor: URLPatternCtor): URLPatternLike;
73
- /**
74
- * Computes the key of the bucket index of a path or of a pattern.
75
- *
76
- * The key is the first path segment, for example `"settings"` of `"/settings/:id"`.
77
- * A first segment with a parameter (`:lang`) goes into the `"*"` wildcard bucket.
78
- * The root path `"/"` gives the key `"/"`.
79
- *
80
- * @param path - The string of a URL path or of a route pattern
81
- */
82
- export declare function getIndexKey(path: string): string;
83
- /**
84
- * Joins the bucket of the named segment and the wildcard bucket of one index key.
85
- * The order of the insertion stays, through the `order` field.
86
- *
87
- * @param patternBuckets - The map from a bucket key to its ordered pattern entries
88
- * @param indexKey - The key of the first segment, from `getIndexKey`
89
- */
90
- export declare function getCandidates<T extends {
91
- order: number;
92
- }>(patternBuckets: Map<string, T[]>, indexKey: string): T[];
93
- //# sourceMappingURL=url-pattern-utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"url-pattern-utils.d.ts","sourceRoot":"","sources":["../src/url-pattern-utils.ts"],"names":[],"mappings":"AAgBA;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAC5B,IAAI,CAAC,KAAK,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG;QAClC,QAAQ,EAAE;YAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;SAAE,CAAC;KACzD,GAAG,IAAI,CAAC;IACT,IAAI,CAAC,KAAK,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;CAC3C,CAAC;AAEF,yDAAyD;AACzD,MAAM,MAAM,cAAc,GAAG,KAAK,IAAI,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,KAAK,cAAc,CAAC;AAEhF;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,SAAS,CAE9D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE5D;AASD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIxD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAO3E;AA0ED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,cAAc,CAqBxF;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMhD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,EACxD,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAChC,QAAQ,EAAE,MAAM,GACd,CAAC,EAAE,CA2BL"}
@@ -1,233 +0,0 @@
1
- /**
2
- * The shared URLPattern utilities — an internal module. index.ts does not export it
3
- *
4
- * This module holds the common URLPattern work of four files:
5
- * - `create-route-map.ts`
6
- * - `base-route-map.ts`
7
- * - `find-route.ts`
8
- * - `router-bridge-base.ts`
9
- *
10
- * The module reads URLPattern from globalThis. A consumer must load a polyfill in an
11
- * environment without the native API: Node < 24, and an older browser.
12
- *
13
- * @internal
14
- */
15
- import { InvalidRoutePatternError } from "./errors.js";
16
- /**
17
- * Returns the URLPattern constructor of `globalThis`, or `undefined` when it is
18
- * absent: in Node < 24, and in an older browser without a polyfill.
19
- */
20
- export function getURLPatternCtor() {
21
- return globalThis["URLPattern"];
22
- }
23
- /**
24
- * Tells you if a route path is a parameterized pattern, and not a concrete URL.
25
- *
26
- * A pattern holds a `:param` segment, which is necessary or optional, or the `*`
27
- * wildcard, or both. Each of them needs a URLPattern match, and each of them carries
28
- * no concrete value. Therefore the code can push such a path to a browser URL
29
- * never.
30
- *
31
- * This function is THE single source of truth of the question "is this path a
32
- * pattern?". `RouteMap` uses it for its decision between the static map and the
33
- * index of the pattern buckets, and `RouterBridgeBase.resolveNavigationPath` uses it
34
- * to skip a route of no navigation. The two tests therefore cannot move apart.
35
- *
36
- * @param path - The string of a URL path or of a route pattern, for example `/profile/:userId` or `/docs/*`
37
- * @returns `true` when the path holds a `:param` or a `*` pattern syntax
38
- */
39
- export function isParameterizedPattern(path) {
40
- return path.includes(":") || path.includes("*");
41
- }
42
- /**
43
- * The expression matches a `:param` name with a hyphen, for example `:cat-id` or
44
- * `:page-num?`. URLPattern requires a valid JS identifier as a parameter name.
45
- * Therefore the code must rewrite a name with a hyphen before the compilation.
46
- */
47
- const HYPHENATED_PARAM_RE = /:([A-Za-z][A-Za-z0-9]*(?:-[A-Za-z0-9]+)+)(\??)/g;
48
- /**
49
- * Normalizes a route path, so that each of its parameter names is a valid URLPattern
50
- * identifier.
51
- *
52
- * URLPattern requires a valid JS identifier as a parameter name, and such an
53
- * identifier holds no hyphen. Therefore the function replaces a name with a hyphen,
54
- * for example `:cat-id`, with the equivalent name with an underscore (`:cat_id`),
55
- * for the compilation step of URLPattern. A caller that needs the values of the
56
- * captured groups, and not a test of the match alone, must map each normalized group
57
- * name back to the original param name with {@link getNormalizedParamNameMap}.
58
- *
59
- * @example
60
- * normalizeParamNames("/docs/:cat-id/:page-num?")
61
- * // → "/docs/:cat_id/:page_num?"
62
- */
63
- export function normalizeParamNames(path) {
64
- return path.replace(HYPHENATED_PARAM_RE, (_m, name, optional) => {
65
- return `:${name.replace(/-/g, "_")}${optional}`;
66
- });
67
- }
68
- /**
69
- * Builds the map from each normalized URLPattern group name back to the original
70
- * param name, which holds a hyphen, of a route pattern.
71
- *
72
- * The map holds only the params that {@link normalizeParamNames} rewrote. A param
73
- * with a valid identifier keeps its own name, and it needs no entry.
74
- *
75
- * @example
76
- * getNormalizedParamNameMap("/docs/:cat-id/:plain")
77
- * // → Map { "cat_id" → "cat-id" }
78
- */
79
- export function getNormalizedParamNameMap(path) {
80
- const nameMap = new Map();
81
- for (const match of path.matchAll(HYPHENATED_PARAM_RE)) {
82
- const original = match[1];
83
- nameMap.set(original.replace(/-/g, "_"), original);
84
- }
85
- return nameMap;
86
- }
87
- /**
88
- * The cache of the compiled URLPattern instances at the module level. The key is the
89
- * string of the pattern.
90
- *
91
- * The code compiles a route pattern on every lookup path of a navigation
92
- * (`extractRouteParams` and `findRouteByPath`), and also one time for each
93
- * `RouteMap` construction. A new compilation of the same route pattern each time is
94
- * lost work. The number of the different route patterns of the route maps of the
95
- * application limits the growth of the cache. The cache goes away when the
96
- * URLPattern constructor changes, and a test changes `globalThis.URLPattern`.
97
- */
98
- const compiledPatternCache = new Map();
99
- let compiledPatternCtor;
100
- /**
101
- * Compiles a route pattern into a `URLPattern`, and it uses the cache of the module
102
- * level again.
103
- *
104
- * {@link normalizeParamNames} normalizes the pattern before the compilation. A param
105
- * name with a hyphen (`:cat-id`) therefore becomes a valid URLPattern identifier
106
- * (`:cat_id`). A caller that reads the values of the groups must map each normalized
107
- * name back with {@link getNormalizedParamNameMap}.
108
- *
109
- * An error of the compilation from the URLPattern constructor goes to the caller
110
- * without a change. A caller that needs a typed error wraps this function in an
111
- * `InvalidRoutePatternError`.
112
- *
113
- * @param pattern - The string of the route pattern, for example `/profile/:userId`
114
- * @param Ctor - The URLPattern constructor, from {@link getURLPatternCtor}
115
- */
116
- /**
117
- * Reads EVERY declared `:param` name, and not the hyphenated ones alone.
118
- *
119
- * {@link assertNoParamNameCollision} needs the plain names too: `:cat_id` is the name
120
- * that `:cat-id` collides WITH, and it holds no hyphen of its own.
121
- */
122
- const ANY_PARAM_NAME_RE = /:([A-Za-z][A-Za-z0-9_]*(?:-[A-Za-z0-9_]+)*)/g;
123
- /**
124
- * Refuses a pattern whose params land on ONE URLPattern identifier.
125
- *
126
- * `normalizeParamNames` rewrites a hyphen to an underscore, so `:cat-id` compiles as
127
- * `:cat_id`. A pattern that declares `:cat-id` AND `:cat_id` therefore gives URLPattern
128
- * one group name two times, and URLPattern refuses it with
129
- * `TypeError: Failed to construct URLPattern`.
130
- *
131
- * The refusal is right, and the message was not: the pattern is valid as the caller
132
- * wrote it, and the fault is a rewrite that this library makes and that no caller asked
133
- * for. Name the two params and the rule instead.
134
- *
135
- * @throws {InvalidRoutePatternError} When two declared names give one identifier.
136
- */
137
- function assertNoParamNameCollision(pattern) {
138
- const seen = new Map();
139
- for (const match of pattern.matchAll(ANY_PARAM_NAME_RE)) {
140
- const name = match[1] ?? "";
141
- const normalized = name.replace(/-/g, "_");
142
- const earlier = seen.get(normalized);
143
- // An identical name two times is the duplicate of the caller, and URLPattern says
144
- // so clearly enough. This guard is for two DIFFERENT names that meet.
145
- if (earlier !== undefined && earlier !== name) {
146
- throw new InvalidRoutePatternError(pattern, {
147
- reason: `The params ":${earlier}" and ":${name}" both compile to the group ` +
148
- `":${normalized}", because URLPattern needs a name with no hyphen and this ` +
149
- `library rewrites each hyphen to an underscore. Rename one of the two.`,
150
- });
151
- }
152
- seen.set(normalized, name);
153
- }
154
- }
155
- export function getCompiledPattern(pattern, Ctor) {
156
- if (Ctor !== compiledPatternCtor) {
157
- compiledPatternCache.clear();
158
- compiledPatternCtor = Ctor;
159
- }
160
- let compiled = compiledPatternCache.get(pattern);
161
- if (compiled === undefined) {
162
- assertNoParamNameCollision(pattern);
163
- // The wrap belongs HERE, at the one place that compiles. `RouteMap` wrapped the
164
- // call of its own and `extractRouteParams` wrapped nothing, so a consumer that read
165
- // the params of a route the map never held received a bare
166
- // `TypeError: Failed to construct URLPattern` — no error code, and a type that the
167
- // error contract of this package does not name.
168
- try {
169
- compiled = new Ctor({ pathname: normalizeParamNames(pattern) });
170
- }
171
- catch (error) {
172
- throw new InvalidRoutePatternError(pattern, { cause: error });
173
- }
174
- compiledPatternCache.set(pattern, compiled);
175
- }
176
- return compiled;
177
- }
178
- /**
179
- * Computes the key of the bucket index of a path or of a pattern.
180
- *
181
- * The key is the first path segment, for example `"settings"` of `"/settings/:id"`.
182
- * A first segment with a parameter (`:lang`) goes into the `"*"` wildcard bucket.
183
- * The root path `"/"` gives the key `"/"`.
184
- *
185
- * @param path - The string of a URL path or of a route pattern
186
- */
187
- export function getIndexKey(path) {
188
- const trimmed = path.startsWith("/") ? path.slice(1) : path;
189
- if (trimmed.length === 0)
190
- return "/";
191
- const segment = trimmed.split("/")[0];
192
- if (segment === undefined || segment.startsWith(":"))
193
- return "*";
194
- return segment;
195
- }
196
- /**
197
- * Joins the bucket of the named segment and the wildcard bucket of one index key.
198
- * The order of the insertion stays, through the `order` field.
199
- *
200
- * @param patternBuckets - The map from a bucket key to its ordered pattern entries
201
- * @param indexKey - The key of the first segment, from `getIndexKey`
202
- */
203
- export function getCandidates(patternBuckets, indexKey) {
204
- const bucket = patternBuckets.get(indexKey) ?? [];
205
- const wildcardBucket = patternBuckets.get("*") ?? [];
206
- if (bucket.length === 0)
207
- return wildcardBucket;
208
- if (wildcardBucket.length === 0)
209
- return bucket;
210
- const merged = [];
211
- let b = 0;
212
- let w = 0;
213
- while (b < bucket.length && w < wildcardBucket.length) {
214
- if (bucket[b].order < wildcardBucket[w].order) {
215
- merged.push(bucket[b]);
216
- b += 1;
217
- }
218
- else {
219
- merged.push(wildcardBucket[w]);
220
- w += 1;
221
- }
222
- }
223
- while (b < bucket.length) {
224
- merged.push(bucket[b]);
225
- b += 1;
226
- }
227
- while (w < wildcardBucket.length) {
228
- merged.push(wildcardBucket[w]);
229
- w += 1;
230
- }
231
- return merged;
232
- }
233
- //# sourceMappingURL=url-pattern-utils.js.map