@loozo/angular-router 0.0.1 → 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.
- package/README.md +455 -63
- package/builders.json +2 -2
- package/fesm2022/loozo-angular-router-_core.mjs +348 -521
- package/fesm2022/loozo-angular-router-_core.mjs.map +1 -1
- package/fesm2022/loozo-angular-router-_generated.mjs +492 -617
- package/fesm2022/loozo-angular-router-_generated.mjs.map +1 -1
- package/fesm2022/loozo-angular-router.mjs +2 -6
- package/node/_core/src/path.d.ts +17 -0
- package/node/src/builders/application.js +9 -6
- package/node/src/builders/options.js +58 -52
- package/node/src/builders/serve.js +51 -8
- package/node/src/generation/anchor.d.ts +13 -0
- package/node/src/generation/anchor.js +92 -0
- package/node/src/generation/compiler.d.ts +6 -0
- package/node/src/generation/compiler.js +68 -0
- package/node/src/generation/emit.d.ts +3 -0
- package/node/src/generation/emit.js +26 -1
- package/node/src/generation/files.d.ts +26 -0
- package/node/src/generation/files.js +42 -10
- package/node/src/generation/filesystem.d.ts +7 -0
- package/node/src/generation/filesystem.js +343 -0
- package/node/src/generation/generate.d.ts +16 -0
- package/node/src/generation/generate.js +18 -6
- package/node/src/generation/index.d.ts +16 -0
- package/node/src/generation/index.js +15 -0
- package/node/src/generation/overlay.d.ts +3 -0
- package/node/src/generation/overlay.js +84 -0
- package/node/src/generation/selectors.d.ts +2 -0
- package/node/src/generation/sources.d.ts +50 -0
- package/node/src/generation/sources.js +109 -28
- package/node/src/generation/validate.d.ts +12 -0
- package/node/src/generation/validate.js +53 -33
- package/package.json +7 -2
- package/schemas/application.json +765 -7
- package/schemas/serve.json +11 -9
- package/types/loozo-angular-router-_core.d.ts +401 -124
- package/types/loozo-angular-router-_generated.d.ts +181 -44
- package/types/loozo-angular-router.d.ts +2 -1
- package/.npmignore +0 -3
- package/fesm2022/loozo-angular-router.mjs.map +0 -1
|
@@ -1,565 +1,392 @@
|
|
|
1
|
-
const presence = new WeakMap();
|
|
1
|
+
const presence = /* @__PURE__ */ new WeakMap();
|
|
2
2
|
function codecPresence(codec) {
|
|
3
|
-
|
|
3
|
+
return presence.get(codec);
|
|
4
4
|
}
|
|
5
5
|
function validateCodec(codec) {
|
|
6
|
-
|
|
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
8
|
const stringParam = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return value;
|
|
22
|
-
},
|
|
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
|
+
}
|
|
23
16
|
};
|
|
24
17
|
const numberParam = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
throw new Error("Expected a finite number");
|
|
35
|
-
}
|
|
36
|
-
return String(value);
|
|
37
|
-
},
|
|
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
|
+
}
|
|
38
27
|
};
|
|
39
28
|
const booleanParam = {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (value === true) {
|
|
51
|
-
return "true";
|
|
52
|
-
}
|
|
53
|
-
if (value === false) {
|
|
54
|
-
return "false";
|
|
55
|
-
}
|
|
56
|
-
throw new Error("Expected a boolean");
|
|
57
|
-
},
|
|
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
|
+
}
|
|
58
39
|
};
|
|
59
40
|
function enumParam(values) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
},
|
|
77
|
-
stringify(value) {
|
|
78
|
-
if (!members.has(value)) {
|
|
79
|
-
throw new Error("Unknown enum value");
|
|
80
|
-
}
|
|
81
|
-
return value;
|
|
82
|
-
},
|
|
83
|
-
};
|
|
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
|
+
};
|
|
84
57
|
}
|
|
85
58
|
function optionalSearchParam(codec) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
presence.set(wrapper, "optional");
|
|
99
|
-
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;
|
|
100
71
|
}
|
|
101
72
|
function nullableSearchParam(codec) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
return codec.stringify(value);
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
presence.set(wrapper, "nullable");
|
|
121
|
-
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;
|
|
122
87
|
}
|
|
123
|
-
|
|
124
88
|
function parsePath(path) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
if (part === "" ||
|
|
159
|
-
part === "." ||
|
|
160
|
-
part === ".." ||
|
|
161
|
-
part === "*" ||
|
|
162
|
-
part === "**" ||
|
|
163
|
-
part.startsWith(":")) {
|
|
164
|
-
throw new TypeError(`Invalid static segment: ${part}`);
|
|
165
|
-
}
|
|
166
|
-
if (!part.isWellFormed()) {
|
|
167
|
-
throw new TypeError("Static path Unicode must be well formed");
|
|
168
|
-
}
|
|
169
|
-
segments.push(Object.freeze({ kind: "static", text: part }));
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
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);
|
|
173
120
|
}
|
|
174
|
-
|
|
175
121
|
function ownRecord(value, label, allowSymbols = false) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
throw new TypeError(`${label} cannot contain inherited entries`);
|
|
182
|
-
}
|
|
183
|
-
for (const key of Reflect.ownKeys(value)) {
|
|
184
|
-
if ((!allowSymbols && typeof key !== "string") ||
|
|
185
|
-
!Object.prototype.propertyIsEnumerable.call(value, key)) {
|
|
186
|
-
throw new TypeError(`${label} contains an unsupported key`);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
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;
|
|
190
127
|
}
|
|
191
128
|
function checkKeys(record, allowed, label) {
|
|
192
|
-
|
|
193
|
-
if (!allowed.has(key)) {
|
|
194
|
-
throw new TypeError(`Unknown ${label} key: ${key}`);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
129
|
+
for (const key of Object.keys(record)) if (!allowed.has(key)) throw new TypeError(`Unknown ${label} key: ${key}`);
|
|
197
130
|
}
|
|
198
131
|
function has(record, key) {
|
|
199
|
-
|
|
132
|
+
return Object.hasOwn(record, key);
|
|
200
133
|
}
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
"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"
|
|
218
150
|
]);
|
|
219
|
-
const policies = new Set([
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
151
|
+
const policies = /* @__PURE__ */ new Set([
|
|
152
|
+
"pathParamsChange",
|
|
153
|
+
"pathParamsOrQueryParamsChange",
|
|
154
|
+
"paramsChange",
|
|
155
|
+
"paramsOrQueryParamsChange",
|
|
156
|
+
"always"
|
|
225
157
|
]);
|
|
226
158
|
const identityKey = "__loozoAngularRouterRouteId";
|
|
227
159
|
function routeMetadata(route) {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
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);
|
|
232
162
|
}
|
|
233
163
|
function copyCodecs(value, path) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
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);
|
|
245
173
|
}
|
|
246
174
|
function snapshotRedirect(value, source) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
if (typeof fragment.value !== "string" || !target.fragments.includes(fragment.value)) {
|
|
299
|
-
throw new TypeError("Redirect fragment must belong to target declaration");
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
else if (fragment.mode === "preserve" || fragment.mode === "drop") {
|
|
303
|
-
checkKeys(fragment, new Set(["mode"]), "redirect fragment");
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
throw new TypeError("Invalid redirect fragment policy");
|
|
307
|
-
}
|
|
308
|
-
return Object.freeze({
|
|
309
|
-
to: redirect.to,
|
|
310
|
-
params: Object.freeze(mapping),
|
|
311
|
-
search: Object.freeze(searchSnapshot),
|
|
312
|
-
fragment: Object.freeze({ ...fragment }),
|
|
313
|
-
});
|
|
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
|
+
});
|
|
314
226
|
}
|
|
315
227
|
function validateSearchValues(codecs, values) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
if (codecPresence(codecs[key]) !== "optional" && !has(values, key)) {
|
|
319
|
-
throw new TypeError(`Missing required search: ${key}`);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
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}`);
|
|
322
230
|
}
|
|
323
231
|
function defineRoute(path, config) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
throw new TypeError("Static data cannot set generated identity");
|
|
426
|
-
}
|
|
427
|
-
retained.data = Object.freeze({ ...data });
|
|
428
|
-
}
|
|
429
|
-
const fragments = [];
|
|
430
|
-
if (has(supplied, "fragments")) {
|
|
431
|
-
if (!Array.isArray(supplied.fragments)) {
|
|
432
|
-
throw new TypeError("Fragments must be a string list");
|
|
433
|
-
}
|
|
434
|
-
for (const name of supplied.fragments) {
|
|
435
|
-
if (typeof name !== "string") {
|
|
436
|
-
throw new TypeError("Fragment names must be strings");
|
|
437
|
-
}
|
|
438
|
-
fragments.push(name);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
retained.fragments = Object.freeze(fragments);
|
|
442
|
-
retained.params = localParams;
|
|
443
|
-
retained.search = localSearch;
|
|
444
|
-
const metadata = {
|
|
445
|
-
parent,
|
|
446
|
-
localSegments,
|
|
447
|
-
segments: Object.freeze([...(inherited?.segments ?? []), ...localSegments]),
|
|
448
|
-
localParams,
|
|
449
|
-
localSearch,
|
|
450
|
-
params: Object.freeze({ ...inherited?.params, ...localParams }),
|
|
451
|
-
search: Object.freeze({ ...inherited?.search, ...localSearch }),
|
|
452
|
-
fragments: retained.fragments,
|
|
453
|
-
config: retained,
|
|
454
|
-
};
|
|
455
|
-
if (has(supplied, "redirect")) {
|
|
456
|
-
if (has(supplied, "canActivate") || has(supplied, "canMatch")) {
|
|
457
|
-
throw new TypeError("Redirect cannot declare own canActivate or canMatch");
|
|
458
|
-
}
|
|
459
|
-
retained.redirect = snapshotRedirect(supplied.redirect, metadata);
|
|
460
|
-
}
|
|
461
|
-
Object.freeze(retained);
|
|
462
|
-
routes.set(result, Object.freeze(metadata));
|
|
463
|
-
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);
|
|
464
333
|
}
|
|
465
|
-
|
|
466
334
|
function encode(value) {
|
|
467
|
-
|
|
335
|
+
return encodeURIComponent(value).replaceAll("(", "%28").replaceAll(")", "%29");
|
|
468
336
|
}
|
|
469
337
|
function stringify(codec, value, path) {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
if (path && (text === "" || text === "." || text === "..")) {
|
|
475
|
-
throw new TypeError("Path output cannot be empty, dot or dotdot");
|
|
476
|
-
}
|
|
477
|
-
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);
|
|
478
342
|
}
|
|
479
343
|
function createUrl(route, values) {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
if (segment.kind === "static") {
|
|
526
|
-
parts.push(encode(segment.text));
|
|
527
|
-
}
|
|
528
|
-
else if (segment.kind === "scalar") {
|
|
529
|
-
parts.push(stringify(metadata.params[segment.name], params[segment.name], true));
|
|
530
|
-
}
|
|
531
|
-
else {
|
|
532
|
-
for (const value of params[segment.name]) {
|
|
533
|
-
parts.push(stringify(metadata.params[segment.name], value, true));
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
let url = `/${parts.join("/")}`;
|
|
538
|
-
const query = [];
|
|
539
|
-
for (const key of searchKeys) {
|
|
540
|
-
const codec = metadata.search[key];
|
|
541
|
-
const optional = codecPresence(codec) === "optional";
|
|
542
|
-
if (optional && !has(search, key)) {
|
|
543
|
-
continue;
|
|
544
|
-
}
|
|
545
|
-
const value = search[key];
|
|
546
|
-
if (optional && value === undefined) {
|
|
547
|
-
continue;
|
|
548
|
-
}
|
|
549
|
-
query.push(`${encode(key)}=${stringify(codec, value, false)}`);
|
|
550
|
-
}
|
|
551
|
-
if (query.length > 0) {
|
|
552
|
-
url += `?${query.join("&")}`;
|
|
553
|
-
}
|
|
554
|
-
if (has(options, "fragment")) {
|
|
555
|
-
url += `#${encode(options.fragment)}`;
|
|
556
|
-
}
|
|
557
|
-
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;
|
|
558
389
|
}
|
|
559
|
-
|
|
560
|
-
/**
|
|
561
|
-
* Generated bundle index. Do not edit.
|
|
562
|
-
*/
|
|
563
|
-
|
|
564
390
|
export { booleanParam, codecPresence, createUrl, defineRoute, enumParam, nullableSearchParam, numberParam, optionalSearchParam, routeMetadata, stringParam };
|
|
565
|
-
|
|
391
|
+
|
|
392
|
+
//# sourceMappingURL=loozo-angular-router-_core.mjs.map
|