@loozo/angular-router 0.0.2 → 0.0.3

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 (37) hide show
  1. package/README.md +442 -79
  2. package/builders.json +2 -2
  3. package/fesm2022/loozo-angular-router-_core.mjs +348 -589
  4. package/fesm2022/loozo-angular-router-_core.mjs.map +1 -1
  5. package/fesm2022/loozo-angular-router-_generated.mjs +492 -617
  6. package/fesm2022/loozo-angular-router-_generated.mjs.map +1 -1
  7. package/fesm2022/loozo-angular-router.mjs +2 -19
  8. package/node/_core/src/path.d.ts +17 -0
  9. package/node/src/builders/application.js +9 -6
  10. package/node/src/builders/options.js +38 -58
  11. package/node/src/builders/serve.js +51 -8
  12. package/node/src/generation/anchor.d.ts +13 -0
  13. package/node/src/generation/anchor.js +92 -0
  14. package/node/src/generation/compiler.d.ts +6 -0
  15. package/node/src/generation/compiler.js +68 -0
  16. package/node/src/generation/emit.d.ts +3 -0
  17. package/node/src/generation/files.d.ts +26 -0
  18. package/node/src/generation/files.js +14 -3
  19. package/node/src/generation/filesystem.d.ts +7 -0
  20. package/node/src/generation/generate.d.ts +16 -0
  21. package/node/src/generation/generate.js +5 -4
  22. package/node/src/generation/index.d.ts +16 -0
  23. package/node/src/generation/index.js +15 -0
  24. package/node/src/generation/overlay.d.ts +3 -0
  25. package/node/src/generation/selectors.d.ts +2 -0
  26. package/node/src/generation/sources.d.ts +50 -0
  27. package/node/src/generation/sources.js +50 -10
  28. package/node/src/generation/validate.d.ts +12 -0
  29. package/node/src/generation/validate.js +38 -33
  30. package/package.json +7 -2
  31. package/schemas/application.json +743 -8
  32. package/schemas/serve.json +11 -32
  33. package/types/loozo-angular-router-_core.d.ts +159 -181
  34. package/types/loozo-angular-router-_generated.d.ts +131 -109
  35. package/types/loozo-angular-router.d.ts +2 -1
  36. package/.npmignore +0 -3
  37. package/fesm2022/loozo-angular-router.mjs.map +0 -1
@@ -1,633 +1,392 @@
1
- const presence = new WeakMap();
1
+ const presence = /* @__PURE__ */ new WeakMap();
2
2
  function codecPresence(codec) {
3
- return presence.get(codec);
3
+ return presence.get(codec);
4
4
  }
5
5
  function validateCodec(codec) {
6
- if (codec === null ||
7
- (typeof codec !== "object" && typeof codec !== "function") ||
8
- typeof codec.parse !== "function" ||
9
- typeof codec.stringify !== "function") {
10
- throw new TypeError("Codec must have callable parse and stringify methods");
11
- }
6
+ if (codec === null || typeof codec !== "object" && typeof codec !== "function" || typeof codec.parse !== "function" || typeof codec.stringify !== "function") throw new TypeError("Codec must have callable parse and stringify methods");
12
7
  }
13
- /**
14
- * Preserves strings verbatim, including empty strings and literal percent text.
15
- *
16
- * @remarks
17
- * Empty, dot and dotdot values are valid codec values but cannot be serialized
18
- * into path segments by URL creation. Search values may contain them.
19
- */
20
8
  const stringParam = {
21
- parse(raw) {
22
- return raw;
23
- },
24
- stringify(value) {
25
- if (typeof value !== "string") {
26
- throw new TypeError("Expected a string");
27
- }
28
- return value;
29
- },
9
+ parse(raw) {
10
+ return raw;
11
+ },
12
+ stringify(value) {
13
+ if (typeof value !== "string") throw new TypeError("Expected a string");
14
+ return value;
15
+ }
30
16
  };
31
- /**
32
- * Parses nonblank text with JavaScript `Number` and requires a finite result.
33
- *
34
- * @remarks
35
- * Whitespace around numbers, exponent notation and hexadecimal text are accepted.
36
- * Blank text, NaN and infinities throw. Stringification requires a finite number
37
- * and uses its JavaScript string representation (including `-0` becoming `"0"`).
38
- */
39
17
  const numberParam = {
40
- parse(raw) {
41
- const value = Number(raw);
42
- if (raw.trim() === "" || !Number.isFinite(value)) {
43
- throw new Error("Expected a finite number");
44
- }
45
- return value;
46
- },
47
- stringify(value) {
48
- if (typeof value !== "number" || !Number.isFinite(value)) {
49
- throw new Error("Expected a finite number");
50
- }
51
- return String(value);
52
- },
18
+ parse(raw) {
19
+ const value = Number(raw);
20
+ if (raw.trim() === "" || !Number.isFinite(value)) throw new Error("Expected a finite number");
21
+ return value;
22
+ },
23
+ stringify(value) {
24
+ if (typeof value !== "number" || !Number.isFinite(value)) throw new Error("Expected a finite number");
25
+ return String(value);
26
+ }
53
27
  };
54
- /**
55
- * Parses only lowercase `"true"` and `"false"`, and emits those same strings.
56
- * Other representations and nonboolean values throw.
57
- */
58
28
  const booleanParam = {
59
- parse(raw) {
60
- if (raw === "true") {
61
- return true;
62
- }
63
- if (raw === "false") {
64
- return false;
65
- }
66
- throw new Error("Expected true or false");
67
- },
68
- stringify(value) {
69
- if (value === true) {
70
- return "true";
71
- }
72
- if (value === false) {
73
- return "false";
74
- }
75
- throw new Error("Expected a boolean");
76
- },
29
+ parse(raw) {
30
+ if (raw === "true") return true;
31
+ if (raw === "false") return false;
32
+ throw new Error("Expected true or false");
33
+ },
34
+ stringify(value) {
35
+ if (value === true) return "true";
36
+ if (value === false) return "false";
37
+ throw new Error("Expected a boolean");
38
+ }
77
39
  };
78
- /**
79
- * Creates a case-sensitive string codec from a snapshotted list of members.
80
- *
81
- * @typeParam Values - The literal list from which the value union is inferred.
82
- * @param values - Allowed decoded strings; an empty string is valid when listed.
83
- * @returns A codec whose parser and stringifier reject nonmembers.
84
- * @throws TypeError if the list or its entries are malformed.
85
- *
86
- * @example
87
- * ```ts
88
- * const tab = enumParam(["details", "reviews"]);
89
- * tab.parse("reviews"); // "reviews"
90
- * ```
91
- */
92
40
  function enumParam(values) {
93
- if (!Array.isArray(values)) {
94
- throw new TypeError("Enum values must be a string list");
95
- }
96
- const members = new Set();
97
- for (const value of values) {
98
- if (typeof value !== "string") {
99
- throw new TypeError("Enum values must be strings");
100
- }
101
- members.add(value);
102
- }
103
- return {
104
- parse(raw) {
105
- if (!members.has(raw)) {
106
- throw new Error("Unknown enum value");
107
- }
108
- return raw;
109
- },
110
- stringify(value) {
111
- if (!members.has(value)) {
112
- throw new Error("Unknown enum value");
113
- }
114
- return value;
115
- },
116
- };
41
+ if (!Array.isArray(values)) throw new TypeError("Enum values must be a string list");
42
+ const members = /* @__PURE__ */ new Set();
43
+ for (const value of values) {
44
+ if (typeof value !== "string") throw new TypeError("Enum values must be strings");
45
+ members.add(value);
46
+ }
47
+ return {
48
+ parse(raw) {
49
+ if (!members.has(raw)) throw new Error("Unknown enum value");
50
+ return raw;
51
+ },
52
+ stringify(value) {
53
+ if (!members.has(value)) throw new Error("Unknown enum value");
54
+ return value;
55
+ }
56
+ };
117
57
  }
118
- /**
119
- * Makes a search key optional without changing the handling of present values.
120
- *
121
- * @remarks
122
- * Generated parsing omits absent keys; URL creation omits absent or `undefined`
123
- * values. The wrapper's parser delegates present strings unchanged, preserving
124
- * promises and failures. Its stringifier cannot serialize `undefined` directly.
125
- * This wrapper is not a path codec. For optional nullable values, wrap
126
- * {@link nullableSearchParam} with this function, not the other way around.
127
- *
128
- * @typeParam Value - The wrapped codec's logical value.
129
- * @param codec - The codec used for present search values.
130
- * @returns A search-only codec allowing omission.
131
- * @throws TypeError if the codec lacks callable parse/stringify methods.
132
- */
133
58
  function optionalSearchParam(codec) {
134
- validateCodec(codec);
135
- const wrapper = {
136
- parse(raw) {
137
- return codec.parse(raw);
138
- },
139
- stringify(value) {
140
- if (value === undefined) {
141
- throw new TypeError("Omitted search has no scalar representation");
142
- }
143
- return codec.stringify(value);
144
- },
145
- };
146
- presence.set(wrapper, "optional");
147
- return wrapper;
59
+ validateCodec(codec);
60
+ const wrapper = {
61
+ parse(raw) {
62
+ return codec.parse(raw);
63
+ },
64
+ stringify(value) {
65
+ if (value === void 0) throw new TypeError("Omitted search has no scalar representation");
66
+ return codec.stringify(value);
67
+ }
68
+ };
69
+ presence.set(wrapper, "optional");
70
+ return wrapper;
148
71
  }
149
- /**
150
- * Adds explicit null to a search codec, represented by the decoded text `"null"`.
151
- *
152
- * @remarks
153
- * The key remains required unless wrapped with {@link optionalSearchParam}.
154
- * Non-null values delegate unchanged, including promise/failure identity. The
155
- * text `"null"` is reserved by this wrapper even if the inner codec accepts it.
156
- * This wrapper is not a path codec and cannot wrap an optional search codec.
157
- *
158
- * @typeParam Value - The wrapped codec's non-null logical value.
159
- * @param codec - The codec used for values other than null.
160
- * @returns A search-only codec accepting and serializing null.
161
- * @throws TypeError if the codec is malformed or is an optional search wrapper.
162
- *
163
- * @example
164
- * ```ts
165
- * const score = optionalSearchParam(nullableSearchParam(numberParam));
166
- * // Omission, null, and a present number remain distinct.
167
- * ```
168
- */
169
72
  function nullableSearchParam(codec) {
170
- validateCodec(codec);
171
- if (codecPresence(codec) === "optional") {
172
- throw new TypeError("Nullable cannot wrap optional");
173
- }
174
- const wrapper = {
175
- parse(raw) {
176
- if (raw === "null") {
177
- return null;
178
- }
179
- return codec.parse(raw);
180
- },
181
- stringify(value) {
182
- if (value === null) {
183
- return "null";
184
- }
185
- return codec.stringify(value);
186
- },
187
- };
188
- presence.set(wrapper, "nullable");
189
- return wrapper;
73
+ validateCodec(codec);
74
+ if (codecPresence(codec) === "optional") throw new TypeError("Nullable cannot wrap optional");
75
+ const wrapper = {
76
+ parse(raw) {
77
+ if (raw === "null") return null;
78
+ return codec.parse(raw);
79
+ },
80
+ stringify(value) {
81
+ if (value === null) return "null";
82
+ return codec.stringify(value);
83
+ }
84
+ };
85
+ presence.set(wrapper, "nullable");
86
+ return wrapper;
190
87
  }
191
-
192
88
  function parsePath(path) {
193
- if (typeof path !== "string") {
194
- throw new TypeError("Path must be a string");
195
- }
196
- if (path === "") {
197
- return Object.freeze([]);
198
- }
199
- const segments = [];
200
- const scalarNames = new Set();
201
- const parts = path.split("/");
202
- for (let index = 0; index < parts.length; index += 1) {
203
- const part = parts[index];
204
- if (part.startsWith("$")) {
205
- let name = part.slice(1);
206
- let kind = "scalar";
207
- if (name.endsWith("[]")) {
208
- name = name.slice(0, -2);
209
- kind = "catchall";
210
- }
211
- if (name === "" ||
212
- name === "__proto__" ||
213
- name.startsWith("...") ||
214
- name.includes("?") ||
215
- name.includes("*") ||
216
- name.includes("[]")) {
217
- throw new TypeError(`Invalid parameter name: ${name}`);
218
- }
219
- if (kind === "catchall" && (index !== parts.length - 1 || scalarNames.has(name))) {
220
- throw new TypeError("Catchall must be terminal and cannot repeat a scalar name");
221
- }
222
- scalarNames.add(name);
223
- segments.push(Object.freeze({ kind, name }));
224
- }
225
- else {
226
- if (part === "" ||
227
- part === "." ||
228
- part === ".." ||
229
- part === "*" ||
230
- part === "**" ||
231
- part.startsWith(":")) {
232
- throw new TypeError(`Invalid static segment: ${part}`);
233
- }
234
- if (!part.isWellFormed()) {
235
- throw new TypeError("Static path Unicode must be well formed");
236
- }
237
- segments.push(Object.freeze({ kind: "static", text: part }));
238
- }
239
- }
240
- return Object.freeze(segments);
89
+ if (typeof path !== "string") throw new TypeError("Path must be a string");
90
+ if (path === "") return Object.freeze([]);
91
+ const segments = [];
92
+ const scalarNames = /* @__PURE__ */ new Set();
93
+ const parts = path.split("/");
94
+ for (let index = 0; index < parts.length; index += 1) {
95
+ const part = parts[index];
96
+ if (part.startsWith("$")) {
97
+ let name = part.slice(1);
98
+ let kind = "scalar";
99
+ if (name.endsWith("[]")) {
100
+ name = name.slice(0, -2);
101
+ kind = "catchall";
102
+ }
103
+ if (name === "" || name === "__proto__" || name.startsWith("...") || name.includes("?") || name.includes("*") || name.includes("[]")) throw new TypeError(`Invalid parameter name: ${name}`);
104
+ if (kind === "catchall" && (index !== parts.length - 1 || scalarNames.has(name))) throw new TypeError("Catchall must be terminal and cannot repeat a scalar name");
105
+ scalarNames.add(name);
106
+ segments.push(Object.freeze({
107
+ kind,
108
+ name
109
+ }));
110
+ } else {
111
+ if (part === "" || part === "." || part === ".." || part === "*" || part === "**" || part.startsWith(":")) throw new TypeError(`Invalid static segment: ${part}`);
112
+ if (!part.isWellFormed()) throw new TypeError("Static path Unicode must be well formed");
113
+ segments.push(Object.freeze({
114
+ kind: "static",
115
+ text: part
116
+ }));
117
+ }
118
+ }
119
+ return Object.freeze(segments);
241
120
  }
242
-
243
121
  function ownRecord(value, label, allowSymbols = false) {
244
- if (value === null || typeof value !== "object" || Array.isArray(value)) {
245
- throw new TypeError(`${label} must be an own record`);
246
- }
247
- const prototype = Object.getPrototypeOf(value);
248
- if (prototype !== Object.prototype && prototype !== null) {
249
- throw new TypeError(`${label} cannot contain inherited entries`);
250
- }
251
- for (const key of Reflect.ownKeys(value)) {
252
- if ((!allowSymbols && typeof key !== "string") ||
253
- !Object.prototype.propertyIsEnumerable.call(value, key)) {
254
- throw new TypeError(`${label} contains an unsupported key`);
255
- }
256
- }
257
- return value;
122
+ if (value === null || typeof value !== "object" || Array.isArray(value)) throw new TypeError(`${label} must be an own record`);
123
+ const prototype = Object.getPrototypeOf(value);
124
+ if (prototype !== Object.prototype && prototype !== null) throw new TypeError(`${label} cannot contain inherited entries`);
125
+ for (const key of Reflect.ownKeys(value)) if (!allowSymbols && typeof key !== "string" || !Object.prototype.propertyIsEnumerable.call(value, key)) throw new TypeError(`${label} contains an unsupported key`);
126
+ return value;
258
127
  }
259
128
  function checkKeys(record, allowed, label) {
260
- for (const key of Object.keys(record)) {
261
- if (!allowed.has(key)) {
262
- throw new TypeError(`Unknown ${label} key: ${key}`);
263
- }
264
- }
129
+ for (const key of Object.keys(record)) if (!allowed.has(key)) throw new TypeError(`Unknown ${label} key: ${key}`);
265
130
  }
266
131
  function has(record, key) {
267
- return Object.hasOwn(record, key);
132
+ return Object.hasOwn(record, key);
268
133
  }
269
-
270
- const routes = new WeakMap();
271
- const configKeys = new Set([
272
- "parent",
273
- "params",
274
- "search",
275
- "resolve",
276
- "runGuardsAndResolvers",
277
- "redirect",
278
- "fragments",
279
- "canActivate",
280
- "canActivateChild",
281
- "canMatch",
282
- "canDeactivate",
283
- "providers",
284
- "title",
285
- "data",
134
+ const routes = /* @__PURE__ */ new WeakMap();
135
+ const configKeys = /* @__PURE__ */ new Set([
136
+ "parent",
137
+ "params",
138
+ "search",
139
+ "resolve",
140
+ "runGuardsAndResolvers",
141
+ "redirect",
142
+ "fragments",
143
+ "canActivate",
144
+ "canActivateChild",
145
+ "canMatch",
146
+ "canDeactivate",
147
+ "providers",
148
+ "title",
149
+ "data"
286
150
  ]);
287
- const policies = new Set([
288
- "pathParamsChange",
289
- "pathParamsOrQueryParamsChange",
290
- "paramsChange",
291
- "paramsOrQueryParamsChange",
292
- "always",
151
+ const policies = /* @__PURE__ */ new Set([
152
+ "pathParamsChange",
153
+ "pathParamsOrQueryParamsChange",
154
+ "paramsChange",
155
+ "paramsOrQueryParamsChange",
156
+ "always"
293
157
  ]);
294
158
  const identityKey = "__loozoAngularRouterRouteId";
295
159
  function routeMetadata(route) {
296
- if (route === null || typeof route !== "object" || !routes.has(route)) {
297
- throw new TypeError("Expected a genuine route from this package instance");
298
- }
299
- return routes.get(route);
160
+ if (route === null || typeof route !== "object" || !routes.has(route)) throw new TypeError("Expected a genuine route from this package instance");
161
+ return routes.get(route);
300
162
  }
301
163
  function copyCodecs(value, path) {
302
- const record = ownRecord(value, "Codec map");
303
- const result = Object.create(null);
304
- for (const key of Object.keys(record)) {
305
- const codec = record[key];
306
- validateCodec(codec);
307
- if (path && codecPresence(codec) !== undefined) {
308
- throw new TypeError("Search wrappers cannot be path codecs");
309
- }
310
- result[key] = codec;
311
- }
312
- return Object.freeze(result);
164
+ const record = ownRecord(value, "Codec map");
165
+ const result = Object.create(null);
166
+ for (const key of Object.keys(record)) {
167
+ const codec = record[key];
168
+ validateCodec(codec);
169
+ if (path && codecPresence(codec) !== void 0) throw new TypeError("Search wrappers cannot be path codecs");
170
+ result[key] = codec;
171
+ }
172
+ return Object.freeze(result);
313
173
  }
314
174
  function snapshotRedirect(value, source) {
315
- const redirect = ownRecord(value, "Redirect");
316
- checkKeys(redirect, new Set(["to", "params", "search", "fragment"]), "redirect");
317
- const target = routeMetadata(redirect.to);
318
- const mapping = Object.create(null);
319
- if (has(redirect, "params")) {
320
- const supplied = ownRecord(redirect.params, "Redirect params");
321
- checkKeys(supplied, new Set(Object.keys(target.params)), "redirect params");
322
- for (const key of Object.keys(target.params)) {
323
- const sourceKey = supplied[key];
324
- if (!has(supplied, key) || typeof sourceKey !== "string" || !has(source.params, sourceKey)) {
325
- throw new TypeError(`Missing or invalid redirect mapping: ${key}`);
326
- }
327
- mapping[key] = sourceKey;
328
- }
329
- }
330
- else {
331
- for (const key of Object.keys(target.params)) {
332
- if (!has(source.params, key)) {
333
- throw new TypeError(`Cannot forward redirect param: ${key}`);
334
- }
335
- mapping[key] = key;
336
- }
337
- }
338
- const search = ownRecord(redirect.search, "Redirect search");
339
- let searchSnapshot;
340
- if (search.mode === "replace") {
341
- checkKeys(search, new Set(["mode", "values"]), "redirect search");
342
- const values = ownRecord(search.values, "Redirect replacement");
343
- validateSearchValues(target.search, values);
344
- searchSnapshot = { mode: "replace", values: Object.freeze({ ...values }) };
345
- }
346
- else if (search.mode === "preserve" || search.mode === "drop") {
347
- checkKeys(search, new Set(["mode"]), "redirect search");
348
- for (const key of Object.keys(target.search)) {
349
- if (codecPresence(target.search[key]) === "optional") {
350
- continue;
351
- }
352
- if (search.mode === "drop" ||
353
- !has(source.search, key) ||
354
- codecPresence(source.search[key]) === "optional") {
355
- throw new TypeError(`Redirect cannot guarantee required search: ${key}`);
356
- }
357
- }
358
- searchSnapshot = { mode: search.mode };
359
- }
360
- else {
361
- throw new TypeError("Invalid redirect search policy");
362
- }
363
- const fragment = ownRecord(redirect.fragment, "Redirect fragment");
364
- if (fragment.mode === "replace") {
365
- checkKeys(fragment, new Set(["mode", "value"]), "redirect fragment");
366
- if (typeof fragment.value !== "string" || !target.fragments.includes(fragment.value)) {
367
- throw new TypeError("Redirect fragment must belong to target declaration");
368
- }
369
- }
370
- else if (fragment.mode === "preserve" || fragment.mode === "drop") {
371
- checkKeys(fragment, new Set(["mode"]), "redirect fragment");
372
- }
373
- else {
374
- throw new TypeError("Invalid redirect fragment policy");
375
- }
376
- return Object.freeze({
377
- to: redirect.to,
378
- params: Object.freeze(mapping),
379
- search: Object.freeze(searchSnapshot),
380
- fragment: Object.freeze({ ...fragment }),
381
- });
175
+ const redirect = ownRecord(value, "Redirect");
176
+ checkKeys(redirect, /* @__PURE__ */ new Set([
177
+ "to",
178
+ "params",
179
+ "search",
180
+ "fragment"
181
+ ]), "redirect");
182
+ const target = routeMetadata(redirect.to);
183
+ const mapping = Object.create(null);
184
+ if (has(redirect, "params")) {
185
+ const supplied = ownRecord(redirect.params, "Redirect params");
186
+ checkKeys(supplied, new Set(Object.keys(target.params)), "redirect params");
187
+ for (const key of Object.keys(target.params)) {
188
+ const sourceKey = supplied[key];
189
+ if (!has(supplied, key) || typeof sourceKey !== "string" || !has(source.params, sourceKey)) throw new TypeError(`Missing or invalid redirect mapping: ${key}`);
190
+ mapping[key] = sourceKey;
191
+ }
192
+ } else for (const key of Object.keys(target.params)) {
193
+ if (!has(source.params, key)) throw new TypeError(`Cannot forward redirect param: ${key}`);
194
+ mapping[key] = key;
195
+ }
196
+ const search = ownRecord(redirect.search, "Redirect search");
197
+ let searchSnapshot;
198
+ if (search.mode === "replace") {
199
+ checkKeys(search, /* @__PURE__ */ new Set(["mode", "values"]), "redirect search");
200
+ const values = ownRecord(search.values, "Redirect replacement");
201
+ validateSearchValues(target.search, values);
202
+ searchSnapshot = {
203
+ mode: "replace",
204
+ values: Object.freeze({ ...values })
205
+ };
206
+ } else if (search.mode === "preserve" || search.mode === "drop") {
207
+ checkKeys(search, /* @__PURE__ */ new Set(["mode"]), "redirect search");
208
+ for (const key of Object.keys(target.search)) {
209
+ if (codecPresence(target.search[key]) === "optional") continue;
210
+ if (search.mode === "drop" || !has(source.search, key) || codecPresence(source.search[key]) === "optional") throw new TypeError(`Redirect cannot guarantee required search: ${key}`);
211
+ }
212
+ searchSnapshot = { mode: search.mode };
213
+ } else throw new TypeError("Invalid redirect search policy");
214
+ const fragment = ownRecord(redirect.fragment, "Redirect fragment");
215
+ if (fragment.mode === "replace") {
216
+ checkKeys(fragment, /* @__PURE__ */ new Set(["mode", "value"]), "redirect fragment");
217
+ if (typeof fragment.value !== "string" || !target.fragments.includes(fragment.value)) throw new TypeError("Redirect fragment must belong to target declaration");
218
+ } else if (fragment.mode === "preserve" || fragment.mode === "drop") checkKeys(fragment, /* @__PURE__ */ new Set(["mode"]), "redirect fragment");
219
+ else throw new TypeError("Invalid redirect fragment policy");
220
+ return Object.freeze({
221
+ to: redirect.to,
222
+ params: Object.freeze(mapping),
223
+ search: Object.freeze(searchSnapshot),
224
+ fragment: Object.freeze({ ...fragment })
225
+ });
382
226
  }
383
227
  function validateSearchValues(codecs, values) {
384
- checkKeys(values, new Set(Object.keys(codecs)), "search values");
385
- for (const key of Object.keys(codecs)) {
386
- if (codecPresence(codecs[key]) !== "optional" && !has(values, key)) {
387
- throw new TypeError(`Missing required search: ${key}`);
388
- }
389
- }
228
+ checkKeys(values, new Set(Object.keys(codecs)), "search values");
229
+ for (const key of Object.keys(codecs)) if (codecPresence(codecs[key]) !== "optional" && !has(values, key)) throw new TypeError(`Missing required search: ${key}`);
390
230
  }
391
231
  function defineRoute(path, config) {
392
- const supplied = ownRecord(config, "Route config");
393
- checkKeys(supplied, configKeys, "route config");
394
- const localSegments = parsePath(path);
395
- let parent;
396
- let inherited;
397
- if (has(supplied, "parent")) {
398
- inherited = routeMetadata(supplied.parent);
399
- parent = supplied.parent;
400
- for (const segment of inherited.segments) {
401
- if (segment.kind === "catchall") {
402
- throw new TypeError("Catchall declarations cannot have children");
403
- }
404
- }
405
- }
406
- const localNames = new Set();
407
- for (const segment of localSegments) {
408
- if (segment.kind !== "static") {
409
- localNames.add(segment.name);
410
- }
411
- }
412
- let localParams = Object.freeze(Object.create(null));
413
- if (localNames.size === 0) {
414
- if (has(supplied, "params")) {
415
- throw new TypeError("Static paths cannot declare params");
416
- }
417
- }
418
- else {
419
- localParams = copyCodecs(supplied.params, true);
420
- checkKeys(localParams, localNames, "local params");
421
- for (const key of localNames) {
422
- if (!has(localParams, key)) {
423
- throw new TypeError(`Missing local codec: ${key}`);
424
- }
425
- if (inherited && has(inherited.params, key)) {
426
- throw new TypeError(`Inherited param already owned: ${key}`);
427
- }
428
- }
429
- }
430
- let localSearch = Object.freeze(Object.create(null));
431
- if (has(supplied, "search")) {
432
- localSearch = copyCodecs(supplied.search, false);
433
- }
434
- for (const key of Object.keys(localSearch)) {
435
- if (inherited && has(inherited.search, key)) {
436
- throw new TypeError(`Inherited search already owned: ${key}`);
437
- }
438
- }
439
- const retained = { ...supplied };
440
- const result = { path: path };
441
- if (has(supplied, "resolve")) {
442
- const resolve = ownRecord(supplied.resolve, "Resolvers", true);
443
- const copied = Object.create(null);
444
- for (const key of Reflect.ownKeys(resolve)) {
445
- if (key === identityKey || typeof resolve[key] !== "function") {
446
- throw new TypeError(`Invalid resolver: ${String(key)}`);
447
- }
448
- copied[key] = resolve[key];
449
- }
450
- result.resolve = Object.freeze(copied);
451
- retained.resolve = result.resolve;
452
- }
453
- if (has(supplied, "runGuardsAndResolvers")) {
454
- const policy = supplied.runGuardsAndResolvers;
455
- if (typeof policy !== "function" && (typeof policy !== "string" || !policies.has(policy))) {
456
- throw new TypeError("Invalid native rerun policy");
457
- }
458
- result.runGuardsAndResolvers = policy;
459
- }
460
- for (const key of ["canActivate", "canActivateChild", "canMatch", "canDeactivate", "providers"]) {
461
- if (!has(supplied, key)) {
462
- continue;
463
- }
464
- const list = supplied[key];
465
- if (!Array.isArray(list)) {
466
- throw new TypeError(`${key} must be an array`);
467
- }
468
- if (key === "canActivate" || key === "canActivateChild" || key === "canMatch") {
469
- for (const callback of list) {
470
- if (typeof callback !== "function") {
471
- throw new TypeError(`${key} entries must be callbacks`);
472
- }
473
- }
474
- }
475
- else if (key === "canDeactivate") {
476
- for (const guard of list) {
477
- if (guard === null ||
478
- (typeof guard !== "function" && typeof guard !== "object" && typeof guard !== "string")) {
479
- throw new TypeError("canDeactivate entries must be native callbacks or tokens");
480
- }
481
- }
482
- }
483
- retained[key] = Object.freeze([...list]);
484
- }
485
- if (has(supplied, "title") &&
486
- typeof supplied.title !== "string" &&
487
- typeof supplied.title !== "function") {
488
- throw new TypeError("Invalid native title");
489
- }
490
- if (has(supplied, "data")) {
491
- const data = ownRecord(supplied.data, "Static data", true);
492
- if (has(data, identityKey)) {
493
- throw new TypeError("Static data cannot set generated identity");
494
- }
495
- retained.data = Object.freeze({ ...data });
496
- }
497
- const fragments = [];
498
- if (has(supplied, "fragments")) {
499
- if (!Array.isArray(supplied.fragments)) {
500
- throw new TypeError("Fragments must be a string list");
501
- }
502
- for (const name of supplied.fragments) {
503
- if (typeof name !== "string") {
504
- throw new TypeError("Fragment names must be strings");
505
- }
506
- fragments.push(name);
507
- }
508
- }
509
- retained.fragments = Object.freeze(fragments);
510
- retained.params = localParams;
511
- retained.search = localSearch;
512
- const metadata = {
513
- parent,
514
- localSegments,
515
- segments: Object.freeze([...(inherited?.segments ?? []), ...localSegments]),
516
- localParams,
517
- localSearch,
518
- params: Object.freeze({ ...inherited?.params, ...localParams }),
519
- search: Object.freeze({ ...inherited?.search, ...localSearch }),
520
- fragments: retained.fragments,
521
- config: retained,
522
- };
523
- if (has(supplied, "redirect")) {
524
- if (has(supplied, "canActivate") || has(supplied, "canMatch")) {
525
- throw new TypeError("Redirect cannot declare own canActivate or canMatch");
526
- }
527
- retained.redirect = snapshotRedirect(supplied.redirect, metadata);
528
- }
529
- Object.freeze(retained);
530
- routes.set(result, Object.freeze(metadata));
531
- return Object.freeze(result);
232
+ const supplied = ownRecord(config, "Route config");
233
+ checkKeys(supplied, configKeys, "route config");
234
+ const localSegments = parsePath(path);
235
+ let parent;
236
+ let inherited;
237
+ if (has(supplied, "parent")) {
238
+ inherited = routeMetadata(supplied.parent);
239
+ parent = supplied.parent;
240
+ for (const segment of inherited.segments) if (segment.kind === "catchall") throw new TypeError("Catchall declarations cannot have children");
241
+ }
242
+ const localNames = /* @__PURE__ */ new Set();
243
+ for (const segment of localSegments) if (segment.kind !== "static") localNames.add(segment.name);
244
+ let localParams = Object.freeze(Object.create(null));
245
+ if (localNames.size === 0) {
246
+ if (has(supplied, "params")) throw new TypeError("Static paths cannot declare params");
247
+ } else {
248
+ localParams = copyCodecs(supplied.params, true);
249
+ checkKeys(localParams, localNames, "local params");
250
+ for (const key of localNames) {
251
+ if (!has(localParams, key)) throw new TypeError(`Missing local codec: ${key}`);
252
+ if (inherited && has(inherited.params, key)) throw new TypeError(`Inherited param already owned: ${key}`);
253
+ }
254
+ }
255
+ let localSearch = Object.freeze(Object.create(null));
256
+ if (has(supplied, "search")) localSearch = copyCodecs(supplied.search, false);
257
+ for (const key of Object.keys(localSearch)) if (inherited && has(inherited.search, key)) throw new TypeError(`Inherited search already owned: ${key}`);
258
+ const retained = { ...supplied };
259
+ const result = { path };
260
+ if (has(supplied, "resolve")) {
261
+ const resolve = ownRecord(supplied.resolve, "Resolvers", true);
262
+ const copied = Object.create(null);
263
+ for (const key of Reflect.ownKeys(resolve)) {
264
+ if (key === identityKey || typeof resolve[key] !== "function") throw new TypeError(`Invalid resolver: ${String(key)}`);
265
+ copied[key] = resolve[key];
266
+ }
267
+ result.resolve = Object.freeze(copied);
268
+ retained.resolve = result.resolve;
269
+ }
270
+ if (has(supplied, "runGuardsAndResolvers")) {
271
+ const policy = supplied.runGuardsAndResolvers;
272
+ if (typeof policy !== "function" && (typeof policy !== "string" || !policies.has(policy))) throw new TypeError("Invalid native rerun policy");
273
+ result.runGuardsAndResolvers = policy;
274
+ }
275
+ for (const key of [
276
+ "canActivate",
277
+ "canActivateChild",
278
+ "canMatch",
279
+ "canDeactivate",
280
+ "providers"
281
+ ]) {
282
+ if (!has(supplied, key)) continue;
283
+ const list = supplied[key];
284
+ if (!Array.isArray(list)) throw new TypeError(`${key} must be an array`);
285
+ if (key === "canActivate" || key === "canActivateChild" || key === "canMatch") {
286
+ for (const callback of list) if (typeof callback !== "function") throw new TypeError(`${key} entries must be callbacks`);
287
+ } else if (key === "canDeactivate") {
288
+ for (const guard of list) if (guard === null || typeof guard !== "function" && typeof guard !== "object" && typeof guard !== "string") throw new TypeError("canDeactivate entries must be native callbacks or tokens");
289
+ }
290
+ retained[key] = Object.freeze([...list]);
291
+ }
292
+ if (has(supplied, "title") && typeof supplied.title !== "string" && typeof supplied.title !== "function") throw new TypeError("Invalid native title");
293
+ if (has(supplied, "data")) {
294
+ const data = ownRecord(supplied.data, "Static data", true);
295
+ if (has(data, identityKey)) throw new TypeError("Static data cannot set generated identity");
296
+ retained.data = Object.freeze({ ...data });
297
+ }
298
+ const fragments = [];
299
+ if (has(supplied, "fragments")) {
300
+ if (!Array.isArray(supplied.fragments)) throw new TypeError("Fragments must be a string list");
301
+ for (const name of supplied.fragments) {
302
+ if (typeof name !== "string") throw new TypeError("Fragment names must be strings");
303
+ fragments.push(name);
304
+ }
305
+ }
306
+ retained.fragments = Object.freeze(fragments);
307
+ retained.params = localParams;
308
+ retained.search = localSearch;
309
+ const metadata = {
310
+ parent,
311
+ localSegments,
312
+ segments: Object.freeze([...inherited?.segments ?? [], ...localSegments]),
313
+ localParams,
314
+ localSearch,
315
+ params: Object.freeze({
316
+ ...inherited?.params,
317
+ ...localParams
318
+ }),
319
+ search: Object.freeze({
320
+ ...inherited?.search,
321
+ ...localSearch
322
+ }),
323
+ fragments: retained.fragments,
324
+ config: retained
325
+ };
326
+ if (has(supplied, "redirect")) {
327
+ if (has(supplied, "canActivate") || has(supplied, "canMatch")) throw new TypeError("Redirect cannot declare own canActivate or canMatch");
328
+ retained.redirect = snapshotRedirect(supplied.redirect, metadata);
329
+ }
330
+ Object.freeze(retained);
331
+ routes.set(result, Object.freeze(metadata));
332
+ return Object.freeze(result);
532
333
  }
533
-
534
334
  function encode(value) {
535
- return encodeURIComponent(value).replaceAll("(", "%28").replaceAll(")", "%29");
335
+ return encodeURIComponent(value).replaceAll("(", "%28").replaceAll(")", "%29");
536
336
  }
537
337
  function stringify(codec, value, path) {
538
- const text = codec.stringify(value);
539
- if (typeof text !== "string") {
540
- throw new TypeError("Codec stringify must return a string");
541
- }
542
- if (path && (text === "" || text === "." || text === "..")) {
543
- throw new TypeError("Path output cannot be empty, dot or dotdot");
544
- }
545
- return encode(text);
338
+ const text = codec.stringify(value);
339
+ if (typeof text !== "string") throw new TypeError("Codec stringify must return a string");
340
+ if (path && (text === "" || text === "." || text === "..")) throw new TypeError("Path output cannot be empty, dot or dotdot");
341
+ return encode(text);
546
342
  }
547
343
  function createUrl(route, values) {
548
- const metadata = routeMetadata(route);
549
- const options = ownRecord(values, "URL options");
550
- checkKeys(options, new Set(["params", "search", "fragment"]), "URL options");
551
- const paramKeys = Object.keys(metadata.params);
552
- let params = Object.create(null);
553
- if (paramKeys.length === 0) {
554
- if (has(options, "params")) {
555
- throw new TypeError("Route has no path params");
556
- }
557
- }
558
- else {
559
- params = ownRecord(options.params, "Path values");
560
- checkKeys(params, new Set(paramKeys), "path values");
561
- for (const key of paramKeys) {
562
- if (!has(params, key)) {
563
- throw new TypeError(`Missing path value: ${key}`);
564
- }
565
- }
566
- }
567
- const searchKeys = Object.keys(metadata.search).sort();
568
- let search = Object.create(null);
569
- if (searchKeys.length === 0) {
570
- if (has(options, "search")) {
571
- throw new TypeError("Route has no search declarations");
572
- }
573
- }
574
- else {
575
- if (has(options, "search")) {
576
- search = ownRecord(options.search, "Search values");
577
- }
578
- validateSearchValues(metadata.search, search);
579
- }
580
- if (has(options, "fragment")) {
581
- if (typeof options.fragment !== "string" || !metadata.fragments.includes(options.fragment)) {
582
- throw new TypeError("Fragment must belong to this declaration");
583
- }
584
- }
585
- // Check all cardinalities before invoking application stringifiers.
586
- for (const segment of metadata.segments) {
587
- if (segment.kind === "catchall" && !Array.isArray(params[segment.name])) {
588
- throw new TypeError(`Catchall requires an array: ${segment.name}`);
589
- }
590
- }
591
- const parts = [];
592
- for (const segment of metadata.segments) {
593
- if (segment.kind === "static") {
594
- parts.push(encode(segment.text));
595
- }
596
- else if (segment.kind === "scalar") {
597
- parts.push(stringify(metadata.params[segment.name], params[segment.name], true));
598
- }
599
- else {
600
- for (const value of params[segment.name]) {
601
- parts.push(stringify(metadata.params[segment.name], value, true));
602
- }
603
- }
604
- }
605
- let url = `/${parts.join("/")}`;
606
- const query = [];
607
- for (const key of searchKeys) {
608
- const codec = metadata.search[key];
609
- const optional = codecPresence(codec) === "optional";
610
- if (optional && !has(search, key)) {
611
- continue;
612
- }
613
- const value = search[key];
614
- if (optional && value === undefined) {
615
- continue;
616
- }
617
- query.push(`${encode(key)}=${stringify(codec, value, false)}`);
618
- }
619
- if (query.length > 0) {
620
- url += `?${query.join("&")}`;
621
- }
622
- if (has(options, "fragment")) {
623
- url += `#${encode(options.fragment)}`;
624
- }
625
- return url;
344
+ const metadata = routeMetadata(route);
345
+ const options = ownRecord(values, "URL options");
346
+ checkKeys(options, /* @__PURE__ */ new Set([
347
+ "params",
348
+ "search",
349
+ "fragment"
350
+ ]), "URL options");
351
+ const paramKeys = Object.keys(metadata.params);
352
+ let params = Object.create(null);
353
+ if (paramKeys.length === 0) {
354
+ if (has(options, "params")) throw new TypeError("Route has no path params");
355
+ } else {
356
+ params = ownRecord(options.params, "Path values");
357
+ checkKeys(params, new Set(paramKeys), "path values");
358
+ for (const key of paramKeys) if (!has(params, key)) throw new TypeError(`Missing path value: ${key}`);
359
+ }
360
+ const searchKeys = Object.keys(metadata.search).sort();
361
+ let search = Object.create(null);
362
+ if (searchKeys.length === 0) {
363
+ if (has(options, "search")) throw new TypeError("Route has no search declarations");
364
+ } else {
365
+ if (has(options, "search")) search = ownRecord(options.search, "Search values");
366
+ validateSearchValues(metadata.search, search);
367
+ }
368
+ if (has(options, "fragment")) {
369
+ if (typeof options.fragment !== "string" || !metadata.fragments.includes(options.fragment)) throw new TypeError("Fragment must belong to this declaration");
370
+ }
371
+ for (const segment of metadata.segments) if (segment.kind === "catchall" && !Array.isArray(params[segment.name])) throw new TypeError(`Catchall requires an array: ${segment.name}`);
372
+ const parts = [];
373
+ for (const segment of metadata.segments) if (segment.kind === "static") parts.push(encode(segment.text));
374
+ else if (segment.kind === "scalar") parts.push(stringify(metadata.params[segment.name], params[segment.name], true));
375
+ else for (const value of params[segment.name]) parts.push(stringify(metadata.params[segment.name], value, true));
376
+ let url = `/${parts.join("/")}`;
377
+ const query = [];
378
+ for (const key of searchKeys) {
379
+ const codec = metadata.search[key];
380
+ const optional = codecPresence(codec) === "optional";
381
+ if (optional && !has(search, key)) continue;
382
+ const value = search[key];
383
+ if (optional && value === void 0) continue;
384
+ query.push(`${encode(key)}=${stringify(codec, value, false)}`);
385
+ }
386
+ if (query.length > 0) url += `?${query.join("&")}`;
387
+ if (has(options, "fragment")) url += `#${encode(options.fragment)}`;
388
+ return url;
626
389
  }
627
-
628
- /**
629
- * Generated bundle index. Do not edit.
630
- */
631
-
632
390
  export { booleanParam, codecPresence, createUrl, defineRoute, enumParam, nullableSearchParam, numberParam, optionalSearchParam, routeMetadata, stringParam };
633
- //# sourceMappingURL=loozo-angular-router-_core.mjs.map
391
+
392
+ //# sourceMappingURL=loozo-angular-router-_core.mjs.map