@loozo/angular-router 0.0.0-stage → 0.0.1
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/.npmignore +3 -0
- package/LICENSE +21 -0
- package/README.md +114 -2
- package/builders.json +15 -0
- package/fesm2022/loozo-angular-router-_core.mjs +565 -0
- package/fesm2022/loozo-angular-router-_core.mjs.map +1 -0
- package/fesm2022/loozo-angular-router-_generated.mjs +658 -0
- package/fesm2022/loozo-angular-router-_generated.mjs.map +1 -0
- package/fesm2022/loozo-angular-router.mjs +6 -0
- package/fesm2022/loozo-angular-router.mjs.map +1 -0
- package/node/_core/src/path.js +50 -0
- package/node/src/builders/application.js +40 -0
- package/node/src/builders/options.js +70 -0
- package/node/src/builders/serve.js +155 -0
- package/node/src/generation/emit.js +245 -0
- package/node/src/generation/files.js +168 -0
- package/node/src/generation/generate.js +19 -0
- package/node/src/generation/selectors.js +60 -0
- package/node/src/generation/sources.js +493 -0
- package/node/src/generation/validate.js +463 -0
- package/package.json +47 -3
- package/schemas/application.json +17 -0
- package/schemas/serve.json +16 -0
- package/types/loozo-angular-router-_core.d.ts +185 -0
- package/types/loozo-angular-router-_generated.d.ts +56 -0
- package/types/loozo-angular-router.d.ts +1 -0
|
@@ -0,0 +1,658 @@
|
|
|
1
|
+
import { inject, Injector, runInInjectionContext, DestroyRef, PendingTasks, signal, resourceFromSnapshots } from '@angular/core';
|
|
2
|
+
import { Router, ActivatedRoute, NavigationStart, NavigationEnd, NavigationCancel, NavigationCancellationCode, NavigationSkipped, NavigationError } from '@angular/router';
|
|
3
|
+
import { Observable, isObservable, from } from 'rxjs';
|
|
4
|
+
import { routeMetadata, codecPresence, createUrl } from '@loozo/angular-router/_core';
|
|
5
|
+
|
|
6
|
+
function hasIdentity(snapshot, id) {
|
|
7
|
+
const data = snapshot.routeConfig?.data;
|
|
8
|
+
return (!!data &&
|
|
9
|
+
Object.hasOwn(data, "__loozoAngularRouterRouteId") &&
|
|
10
|
+
data.__loozoAngularRouterRouteId === id);
|
|
11
|
+
}
|
|
12
|
+
function assertIdentity(snapshot, id) {
|
|
13
|
+
if (!hasIdentity(snapshot, id)) {
|
|
14
|
+
throw new Error(`Generated route wiring identity mismatch: ${id}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function inputError(source, key, reason, cause) {
|
|
18
|
+
return Object.assign(new Error(`Invalid ${source} input ${key}: ${reason}`, { cause }), {
|
|
19
|
+
source,
|
|
20
|
+
key,
|
|
21
|
+
reason,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function validateRaw(source, key, raws, array) {
|
|
25
|
+
if (!array && raws.length === 0) {
|
|
26
|
+
throw inputError(source, key, "missing");
|
|
27
|
+
}
|
|
28
|
+
if (!array && raws.length > 1) {
|
|
29
|
+
throw inputError(source, key, "repeated");
|
|
30
|
+
}
|
|
31
|
+
if (raws.some((raw) => typeof raw !== "string")) {
|
|
32
|
+
throw inputError(source, key, "invalid", new TypeError("Raw input must be a decoded string"));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function pathJobs(definition, url) {
|
|
36
|
+
const metadata = routeMetadata(definition);
|
|
37
|
+
const local = new Map();
|
|
38
|
+
for (let index = 0; index < metadata.localSegments.length; index += 1) {
|
|
39
|
+
const segment = metadata.localSegments[index];
|
|
40
|
+
if (segment.kind === "static") {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
let raws = [];
|
|
44
|
+
const array = segment.kind === "catchall";
|
|
45
|
+
if (array) {
|
|
46
|
+
raws = url.slice(index).map((value) => value.path);
|
|
47
|
+
}
|
|
48
|
+
else if (index < url.length) {
|
|
49
|
+
raws = [url[index].path];
|
|
50
|
+
}
|
|
51
|
+
validateRaw("path", segment.name, raws, array);
|
|
52
|
+
// Repeated local scalars intentionally use Angular's last positional occurrence.
|
|
53
|
+
local.set(segment.name, {
|
|
54
|
+
source: "path",
|
|
55
|
+
key: segment.name,
|
|
56
|
+
raws,
|
|
57
|
+
array,
|
|
58
|
+
codec: metadata.localParams[segment.name],
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return [...local.values()];
|
|
62
|
+
}
|
|
63
|
+
function searchJobs(definition, snapshot) {
|
|
64
|
+
const metadata = routeMetadata(definition);
|
|
65
|
+
const jobs = [];
|
|
66
|
+
for (const key of Object.keys(metadata.search)) {
|
|
67
|
+
const codec = metadata.search[key];
|
|
68
|
+
const raws = snapshot.queryParamMap.getAll(key);
|
|
69
|
+
if (raws.length === 0 && codecPresence(codec) === "optional") {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
validateRaw("search", key, raws, false);
|
|
73
|
+
jobs.push({ source: "search", key, raws, array: false, codec });
|
|
74
|
+
}
|
|
75
|
+
return jobs;
|
|
76
|
+
}
|
|
77
|
+
async function runJobs(jobs) {
|
|
78
|
+
const params = Object.create(null);
|
|
79
|
+
const search = Object.create(null);
|
|
80
|
+
const pending = [];
|
|
81
|
+
for (const job of jobs) {
|
|
82
|
+
// Async boundaries convert every synchronous throw into an observed rejection.
|
|
83
|
+
pending.push((async () => {
|
|
84
|
+
try {
|
|
85
|
+
const elements = [];
|
|
86
|
+
for (const raw of job.raws) {
|
|
87
|
+
elements.push((async () => job.codec.parse(raw))());
|
|
88
|
+
}
|
|
89
|
+
const values = await Promise.all(elements);
|
|
90
|
+
let value = values[0];
|
|
91
|
+
if (job.array) {
|
|
92
|
+
value = Object.freeze(values);
|
|
93
|
+
}
|
|
94
|
+
if (job.source === "path") {
|
|
95
|
+
params[job.key] = value;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
search[job.key] = value;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (cause) {
|
|
102
|
+
throw inputError(job.source, job.key, "invalid", cause);
|
|
103
|
+
}
|
|
104
|
+
})());
|
|
105
|
+
}
|
|
106
|
+
await Promise.all(pending);
|
|
107
|
+
return Object.freeze({ params: Object.freeze(params), search: Object.freeze(search) });
|
|
108
|
+
}
|
|
109
|
+
const full = new WeakMap();
|
|
110
|
+
const matching = new WeakMap();
|
|
111
|
+
function operation(cache, definition, snapshot, collect) {
|
|
112
|
+
let snapshots = cache.get(definition);
|
|
113
|
+
if (!snapshots) {
|
|
114
|
+
snapshots = new WeakMap();
|
|
115
|
+
cache.set(definition, snapshots);
|
|
116
|
+
}
|
|
117
|
+
const existing = snapshots.get(snapshot);
|
|
118
|
+
if (existing) {
|
|
119
|
+
return existing;
|
|
120
|
+
}
|
|
121
|
+
// Insert before application code can run; even synchronous reentry joins the same operation.
|
|
122
|
+
const result = {
|
|
123
|
+
promise: Promise.resolve().then(() => runJobs(collect())),
|
|
124
|
+
outcome: undefined,
|
|
125
|
+
};
|
|
126
|
+
snapshots.set(snapshot, result);
|
|
127
|
+
result.promise.then((value) => {
|
|
128
|
+
result.outcome = { value };
|
|
129
|
+
}, (cause) => {
|
|
130
|
+
let error = cause;
|
|
131
|
+
if (!(error instanceof Error)) {
|
|
132
|
+
error = new Error("Route input failure", { cause });
|
|
133
|
+
}
|
|
134
|
+
result.outcome = { error };
|
|
135
|
+
});
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
function fullOperation(set, id, snapshot) {
|
|
139
|
+
assertIdentity(snapshot, id);
|
|
140
|
+
const binding = set.records[id];
|
|
141
|
+
return operation(full, binding.definition(), snapshot, () => {
|
|
142
|
+
const jobs = [];
|
|
143
|
+
for (const ownerId of binding.owners) {
|
|
144
|
+
const definition = set.records[ownerId].definition();
|
|
145
|
+
// Pathless/static owners contribute no positional input. Effective search belongs
|
|
146
|
+
// to this complete future record; inherited data is never positional authority.
|
|
147
|
+
if (!routeMetadata(definition).localSegments.some((segment) => segment.kind !== "static")) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const owner = [...snapshot.pathFromRoot]
|
|
151
|
+
.reverse()
|
|
152
|
+
.find((record) => hasIdentity(record, ownerId));
|
|
153
|
+
if (!owner) {
|
|
154
|
+
throw new Error(`Generated route ancestor missing: ${ownerId}`);
|
|
155
|
+
}
|
|
156
|
+
assertIdentity(owner, ownerId);
|
|
157
|
+
jobs.push(...pathJobs(definition, owner.url));
|
|
158
|
+
}
|
|
159
|
+
jobs.push(...searchJobs(binding.definition(), snapshot));
|
|
160
|
+
return jobs;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function parseInputs(set, id, snapshot) {
|
|
164
|
+
return fullOperation(set, id, snapshot).promise;
|
|
165
|
+
}
|
|
166
|
+
function matchingInputs(set, id, snapshot) {
|
|
167
|
+
assertIdentity(snapshot, id);
|
|
168
|
+
const definition = set.records[id].definition();
|
|
169
|
+
return operation(matching, definition, snapshot, () => [
|
|
170
|
+
...pathJobs(definition, snapshot.url),
|
|
171
|
+
...searchJobs(definition, snapshot),
|
|
172
|
+
]).promise;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function isPromiseResult(value) {
|
|
176
|
+
return !!value && typeof value.then === "function";
|
|
177
|
+
}
|
|
178
|
+
function bridge(inputs, callback) {
|
|
179
|
+
const injector = inject(Injector);
|
|
180
|
+
return new Observable((subscriber) => {
|
|
181
|
+
let subscription;
|
|
182
|
+
inputs().then((value) => {
|
|
183
|
+
if (subscriber.closed) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
const result = runInInjectionContext(injector, () => callback(value));
|
|
188
|
+
if (isObservable(result)) {
|
|
189
|
+
subscription = result.subscribe(subscriber);
|
|
190
|
+
}
|
|
191
|
+
else if (isPromiseResult(result)) {
|
|
192
|
+
subscription = from(Promise.resolve(result)).subscribe(subscriber);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
subscriber.next(result);
|
|
196
|
+
subscriber.complete();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
subscriber.error(error);
|
|
201
|
+
}
|
|
202
|
+
}, (error) => subscriber.error(error));
|
|
203
|
+
return () => subscription?.unsubscribe();
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
function callbacks(set, id) {
|
|
207
|
+
const config = routeMetadata(set.records[id].definition()).config;
|
|
208
|
+
const result = {};
|
|
209
|
+
const activate = config.canActivate;
|
|
210
|
+
if (activate) {
|
|
211
|
+
result.canActivate = activate.map((callback) => (snapshot, state) => {
|
|
212
|
+
assertIdentity(snapshot, id);
|
|
213
|
+
return bridge(() => parseInputs(set, id, snapshot), (inputs) => callback(inputs, snapshot, state));
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
const children = config.canActivateChild;
|
|
217
|
+
if (children) {
|
|
218
|
+
result.canActivateChild = children.map((callback) => (child, state) => {
|
|
219
|
+
let parent;
|
|
220
|
+
// The native ancestry includes child itself; only proper ancestors can declare this guard.
|
|
221
|
+
for (let index = child.pathFromRoot.length - 2; index >= 0; index -= 1) {
|
|
222
|
+
const ancestor = child.pathFromRoot[index];
|
|
223
|
+
if (hasIdentity(ancestor, id)) {
|
|
224
|
+
parent = ancestor;
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (!parent) {
|
|
229
|
+
throw new Error(`Generated guard ancestor missing: ${id}`);
|
|
230
|
+
}
|
|
231
|
+
assertIdentity(parent, id);
|
|
232
|
+
return bridge(() => parseInputs(set, id, parent), (inputs) => callback(inputs, child, state));
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
const matching = config.canMatch;
|
|
236
|
+
if (matching) {
|
|
237
|
+
result.canMatch = matching.map((callback) => (route, segments, snapshot) => {
|
|
238
|
+
assertIdentity(snapshot, id);
|
|
239
|
+
return bridge(() => matchingInputs(set, id, snapshot), (inputs) => callback(inputs, route, segments, snapshot));
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
const resolvers = config.resolve;
|
|
243
|
+
if (resolvers) {
|
|
244
|
+
const resolve = Object.create(null);
|
|
245
|
+
for (const key of Reflect.ownKeys(resolvers)) {
|
|
246
|
+
resolve[key] = (snapshot, state) => {
|
|
247
|
+
assertIdentity(snapshot, id);
|
|
248
|
+
return bridge(() => parseInputs(set, id, snapshot), (inputs) => resolvers[key](inputs, snapshot, state));
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
result.resolve = resolve;
|
|
252
|
+
}
|
|
253
|
+
return result;
|
|
254
|
+
}
|
|
255
|
+
function redirect(definition) {
|
|
256
|
+
return async (snapshot) => {
|
|
257
|
+
const router = inject(Router);
|
|
258
|
+
const source = routeMetadata(definition());
|
|
259
|
+
const config = source.config.redirect;
|
|
260
|
+
const target = routeMetadata(config.to);
|
|
261
|
+
const raw = new Map();
|
|
262
|
+
for (let index = 0; index < source.segments.length; index += 1) {
|
|
263
|
+
const segment = source.segments[index];
|
|
264
|
+
if (segment.kind === "scalar") {
|
|
265
|
+
raw.set(segment.name, {
|
|
266
|
+
values: snapshot.url.slice(index, index + 1).map((value) => value.path),
|
|
267
|
+
array: false,
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
else if (segment.kind === "catchall") {
|
|
271
|
+
raw.set(segment.name, {
|
|
272
|
+
values: snapshot.url.slice(index).map((value) => value.path),
|
|
273
|
+
array: true,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const jobs = [];
|
|
278
|
+
for (const key of new Set(Object.values(config.params))) {
|
|
279
|
+
const input = raw.get(key);
|
|
280
|
+
const raws = input?.values ?? [];
|
|
281
|
+
const array = input?.array ?? false;
|
|
282
|
+
validateRaw("path", key, raws, array);
|
|
283
|
+
jobs.push({ source: "path", key, raws, array, codec: source.params[key] });
|
|
284
|
+
}
|
|
285
|
+
if (config.search.mode === "preserve") {
|
|
286
|
+
for (const key of Object.keys(target.search)) {
|
|
287
|
+
const codec = target.search[key];
|
|
288
|
+
const raws = snapshot.queryParamMap.getAll(key);
|
|
289
|
+
if (raws.length === 0 && codecPresence(codec) === "optional") {
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
validateRaw("search", key, raws, false);
|
|
293
|
+
jobs.push({ source: "search", key, raws, array: false, codec });
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
// Every demand is prechecked. Async wrappers observe even synchronous preserved-search
|
|
297
|
+
// throws after earlier source jobs launch, without detaching those later rejections.
|
|
298
|
+
const logical = await runJobs(jobs);
|
|
299
|
+
const params = Object.create(null);
|
|
300
|
+
for (const [key, sourceKey] of Object.entries(config.params)) {
|
|
301
|
+
params[key] = logical.params[sourceKey];
|
|
302
|
+
}
|
|
303
|
+
const path = createUrlForPath(config.to, params);
|
|
304
|
+
const replacement = Object.create(null);
|
|
305
|
+
if (config.search.mode === "replace") {
|
|
306
|
+
const values = config.search.values;
|
|
307
|
+
for (const key of Object.keys(target.search).sort()) {
|
|
308
|
+
const codec = target.search[key];
|
|
309
|
+
if (codecPresence(codec) === "optional" &&
|
|
310
|
+
(!Object.hasOwn(values, key) || values[key] === undefined)) {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
const raw = codec.stringify(values[key]);
|
|
314
|
+
if (typeof raw !== "string") {
|
|
315
|
+
throw new TypeError(`Redirect search codec must stringify to a string: ${key}`);
|
|
316
|
+
}
|
|
317
|
+
replacement[key] = raw;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
// No native conversion before demanded codecs and destination stringification succeed.
|
|
321
|
+
const tree = router.parseUrl(path);
|
|
322
|
+
if (config.search.mode === "preserve") {
|
|
323
|
+
tree.queryParams = { ...snapshot.queryParams };
|
|
324
|
+
}
|
|
325
|
+
else if (config.search.mode === "replace") {
|
|
326
|
+
tree.queryParams = replacement;
|
|
327
|
+
}
|
|
328
|
+
if (config.fragment.mode === "preserve") {
|
|
329
|
+
tree.fragment = snapshot.fragment;
|
|
330
|
+
}
|
|
331
|
+
else if (config.fragment.mode === "replace") {
|
|
332
|
+
tree.fragment = config.fragment.value;
|
|
333
|
+
}
|
|
334
|
+
return tree;
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
function createUrlForPath(definition, params) {
|
|
338
|
+
const metadata = routeMetadata(definition);
|
|
339
|
+
const parts = [];
|
|
340
|
+
function encode(raw) {
|
|
341
|
+
if (raw === "" || raw === "." || raw === "..") {
|
|
342
|
+
throw new TypeError("Invalid redirect path value");
|
|
343
|
+
}
|
|
344
|
+
return encodeURIComponent(raw).replace(/\(/g, "%28").replace(/\)/g, "%29");
|
|
345
|
+
}
|
|
346
|
+
for (const segment of metadata.segments) {
|
|
347
|
+
if (segment.kind === "static") {
|
|
348
|
+
parts.push(encode(segment.text));
|
|
349
|
+
}
|
|
350
|
+
else if (segment.kind === "scalar") {
|
|
351
|
+
const raw = metadata.params[segment.name].stringify(params[segment.name]);
|
|
352
|
+
if (typeof raw !== "string") {
|
|
353
|
+
throw new TypeError("Redirect codec must stringify to a string");
|
|
354
|
+
}
|
|
355
|
+
parts.push(encode(raw));
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
const values = params[segment.name];
|
|
359
|
+
if (!Array.isArray(values)) {
|
|
360
|
+
throw new TypeError("Redirect catchall requires an array");
|
|
361
|
+
}
|
|
362
|
+
for (const value of values) {
|
|
363
|
+
const raw = metadata.params[segment.name].stringify(value);
|
|
364
|
+
if (typeof raw !== "string") {
|
|
365
|
+
throw new TypeError("Redirect codec must stringify to a string");
|
|
366
|
+
}
|
|
367
|
+
parts.push(encode(raw));
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return `/${parts.join("/")}`;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// Shared parsing has no view/task lifetime. Each handle owns its visibility and relevance.
|
|
375
|
+
function observeRoute(set, id) {
|
|
376
|
+
const activated = inject(ActivatedRoute);
|
|
377
|
+
const router = inject(Router);
|
|
378
|
+
const destroy = inject(DestroyRef);
|
|
379
|
+
const tasks = inject(PendingTasks);
|
|
380
|
+
assertIdentity(activated.snapshot, id);
|
|
381
|
+
const paired = signal({
|
|
382
|
+
status: "loading",
|
|
383
|
+
value: undefined,
|
|
384
|
+
}, /* @ts-ignore */
|
|
385
|
+
...(ngDevMode ? [{ debugName: "paired" }] : /* istanbul ignore next */ []));
|
|
386
|
+
const data = signal({
|
|
387
|
+
status: "loading",
|
|
388
|
+
value: undefined,
|
|
389
|
+
}, /* @ts-ignore */
|
|
390
|
+
...(ngDevMode ? [{ debugName: "data" }] : /* istanbul ignore next */ []));
|
|
391
|
+
let survivor;
|
|
392
|
+
let work;
|
|
393
|
+
let commitment = -1;
|
|
394
|
+
let pending;
|
|
395
|
+
let visible = false;
|
|
396
|
+
let destroyed = false;
|
|
397
|
+
let release;
|
|
398
|
+
let acquiring = false;
|
|
399
|
+
function track() {
|
|
400
|
+
if (release || destroyed || acquiring) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
// Native add synchronously notifies stability observers before returning ownership.
|
|
404
|
+
acquiring = true;
|
|
405
|
+
const cleanup = tasks.add();
|
|
406
|
+
acquiring = false;
|
|
407
|
+
if (destroyed) {
|
|
408
|
+
cleanup();
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
release = cleanup;
|
|
412
|
+
}
|
|
413
|
+
function untrack() {
|
|
414
|
+
const cleanup = release;
|
|
415
|
+
release = undefined;
|
|
416
|
+
cleanup?.();
|
|
417
|
+
}
|
|
418
|
+
function publish() {
|
|
419
|
+
if (!visible || destroyed || !work) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
if (!work.outcome) {
|
|
423
|
+
paired.set({ status: "loading", value: undefined });
|
|
424
|
+
track();
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
if ("value" in work.outcome) {
|
|
428
|
+
paired.set({ status: "resolved", value: work.outcome.value });
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
paired.set({ status: "error", error: work.outcome.error });
|
|
432
|
+
}
|
|
433
|
+
// A synchronous paired write always precedes package task removal.
|
|
434
|
+
untrack();
|
|
435
|
+
}
|
|
436
|
+
function adopt(snapshot) {
|
|
437
|
+
assertIdentity(snapshot, id);
|
|
438
|
+
if (snapshot === survivor) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
survivor = snapshot;
|
|
442
|
+
const joined = fullOperation(set, id, snapshot);
|
|
443
|
+
work = joined;
|
|
444
|
+
if (!joined.outcome) {
|
|
445
|
+
track();
|
|
446
|
+
}
|
|
447
|
+
joined.promise.then(() => {
|
|
448
|
+
if (work === joined) {
|
|
449
|
+
publish();
|
|
450
|
+
}
|
|
451
|
+
}, () => {
|
|
452
|
+
if (work === joined) {
|
|
453
|
+
publish();
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
function reconcile() {
|
|
458
|
+
const successful = router.lastSuccessfulNavigation();
|
|
459
|
+
if (successful && successful.id > commitment) {
|
|
460
|
+
commitment = successful.id;
|
|
461
|
+
adopt(activated.snapshot);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
function restore() {
|
|
465
|
+
if (destroyed) {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
reconcile();
|
|
469
|
+
if (!survivor) {
|
|
470
|
+
adopt(activated.snapshot);
|
|
471
|
+
}
|
|
472
|
+
const local = Object.create(null);
|
|
473
|
+
const resolvers = routeMetadata(set.records[id].definition()).config.resolve ?? {};
|
|
474
|
+
for (const key of Reflect.ownKeys(resolvers)) {
|
|
475
|
+
if (Object.hasOwn(survivor.data, key)) {
|
|
476
|
+
local[key] = survivor.data[key];
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
data.set({ status: "resolved", value: Object.freeze(local) });
|
|
480
|
+
visible = true;
|
|
481
|
+
publish();
|
|
482
|
+
}
|
|
483
|
+
function idleHandoff() {
|
|
484
|
+
queueMicrotask(() => {
|
|
485
|
+
if (destroyed || visible) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
const current = router.currentNavigation();
|
|
489
|
+
const successful = router.lastSuccessfulNavigation();
|
|
490
|
+
if (!current || current.id === successful?.id) {
|
|
491
|
+
pending = undefined;
|
|
492
|
+
restore();
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
function eligible(id) {
|
|
497
|
+
const current = router.currentNavigation();
|
|
498
|
+
const successful = router.lastSuccessfulNavigation();
|
|
499
|
+
if (current && current.id > id && current.id !== successful?.id) {
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
502
|
+
return pending === undefined || pending === id;
|
|
503
|
+
}
|
|
504
|
+
// Subscribe before reading native phase: constructors can run inside event delivery.
|
|
505
|
+
const subscription = router.events.subscribe((event) => {
|
|
506
|
+
if (destroyed) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
if (event instanceof NavigationStart) {
|
|
510
|
+
pending = event.id;
|
|
511
|
+
visible = false;
|
|
512
|
+
reconcile();
|
|
513
|
+
paired.set({ status: "loading", value: undefined });
|
|
514
|
+
data.set({ status: "loading", value: undefined });
|
|
515
|
+
}
|
|
516
|
+
else if (event instanceof NavigationEnd) {
|
|
517
|
+
// Even an old End may expose a newer true survivor; it cannot settle a newer Start.
|
|
518
|
+
reconcile();
|
|
519
|
+
if (eligible(event.id)) {
|
|
520
|
+
pending = undefined;
|
|
521
|
+
restore();
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
else if (event instanceof NavigationCancel) {
|
|
525
|
+
reconcile();
|
|
526
|
+
if (event.code === NavigationCancellationCode.Redirect ||
|
|
527
|
+
event.code === NavigationCancellationCode.SupersededByNewNavigation) {
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
if (eligible(event.id)) {
|
|
531
|
+
pending = undefined;
|
|
532
|
+
restore();
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
else if (event instanceof NavigationSkipped) {
|
|
536
|
+
reconcile();
|
|
537
|
+
if (eligible(event.id)) {
|
|
538
|
+
pending = undefined;
|
|
539
|
+
restore();
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
else if (event instanceof NavigationError && eligible(event.id)) {
|
|
543
|
+
reconcile();
|
|
544
|
+
pending = undefined;
|
|
545
|
+
visible = false;
|
|
546
|
+
let error = event.error;
|
|
547
|
+
if (!(error instanceof Error)) {
|
|
548
|
+
error = new Error("Navigation failure", { cause: event.error });
|
|
549
|
+
}
|
|
550
|
+
paired.set({ status: "error", error });
|
|
551
|
+
data.set({ status: "error", error });
|
|
552
|
+
untrack();
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
destroy.onDestroy(() => {
|
|
556
|
+
destroyed = true;
|
|
557
|
+
visible = false;
|
|
558
|
+
subscription.unsubscribe();
|
|
559
|
+
untrack();
|
|
560
|
+
});
|
|
561
|
+
// Synchronous task handoff prevents whenStable resolving before a missed-terminal microtask.
|
|
562
|
+
track();
|
|
563
|
+
if (!destroyed) {
|
|
564
|
+
const current = router.currentNavigation();
|
|
565
|
+
const successful = router.lastSuccessfulNavigation();
|
|
566
|
+
if (!current || current.id === successful?.id) {
|
|
567
|
+
restore();
|
|
568
|
+
}
|
|
569
|
+
else {
|
|
570
|
+
pending = current.id;
|
|
571
|
+
idleHandoff();
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
function project(key) {
|
|
575
|
+
const state = paired();
|
|
576
|
+
if (state.status === "error") {
|
|
577
|
+
return state;
|
|
578
|
+
}
|
|
579
|
+
return { status: state.status, value: state.value?.[key] };
|
|
580
|
+
}
|
|
581
|
+
return {
|
|
582
|
+
params: resourceFromSnapshots(() => project("params")),
|
|
583
|
+
search: resourceFromSnapshots(() => project("search")),
|
|
584
|
+
data: resourceFromSnapshots(() => data()),
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
const destinations = new WeakMap();
|
|
589
|
+
function createDestination(getSet, id) {
|
|
590
|
+
const destination = Object.freeze({});
|
|
591
|
+
destinations.set(destination, { getSet, id });
|
|
592
|
+
return destination;
|
|
593
|
+
}
|
|
594
|
+
function nativeOptions(definition) {
|
|
595
|
+
const config = routeMetadata(definition).config;
|
|
596
|
+
const options = {};
|
|
597
|
+
for (const key of ["providers", "title", "data", "canDeactivate", "runGuardsAndResolvers"]) {
|
|
598
|
+
if (Object.hasOwn(config, key)) {
|
|
599
|
+
options[key] = config[key];
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return options;
|
|
603
|
+
}
|
|
604
|
+
function injectGeneratedRoute(set, id) {
|
|
605
|
+
const router = inject(Router);
|
|
606
|
+
const view = observeRoute(set, id);
|
|
607
|
+
function url(args) {
|
|
608
|
+
if (args.length !== 1 && args.length !== 2) {
|
|
609
|
+
throw new TypeError("Expected values or a selected destination and values");
|
|
610
|
+
}
|
|
611
|
+
let target = id;
|
|
612
|
+
let values = args[0];
|
|
613
|
+
if (args.length === 2) {
|
|
614
|
+
const selector = args[0];
|
|
615
|
+
values = args[1];
|
|
616
|
+
if (typeof selector === "string") {
|
|
617
|
+
if (selector !== ".") {
|
|
618
|
+
if (Object.hasOwn(set.absolute, selector)) {
|
|
619
|
+
target = set.absolute[selector];
|
|
620
|
+
}
|
|
621
|
+
else if (Object.hasOwn(set.relative[id], selector)) {
|
|
622
|
+
target = set.relative[id][selector];
|
|
623
|
+
}
|
|
624
|
+
else {
|
|
625
|
+
throw new TypeError(`Unknown generated selector: ${selector}`);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
else {
|
|
630
|
+
if (typeof selector !== "object" || selector === null) {
|
|
631
|
+
throw new TypeError("Expected a literal selector or genuine generated destination");
|
|
632
|
+
}
|
|
633
|
+
const destination = destinations.get(selector);
|
|
634
|
+
if (!destination ||
|
|
635
|
+
destination.getSet() !== set ||
|
|
636
|
+
!Object.hasOwn(set.records, destination.id)) {
|
|
637
|
+
throw new TypeError("Expected a destination from the same generated set");
|
|
638
|
+
}
|
|
639
|
+
target = destination.id;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
return createUrl(set.destinations[target](), values);
|
|
643
|
+
}
|
|
644
|
+
return {
|
|
645
|
+
params: view.params,
|
|
646
|
+
search: view.search,
|
|
647
|
+
data: view.data,
|
|
648
|
+
link: ((...args) => router.parseUrl(url(args))),
|
|
649
|
+
navigate: ((...args) => router.navigateByUrl(url(args))),
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Generated bundle index. Do not edit.
|
|
655
|
+
*/
|
|
656
|
+
|
|
657
|
+
export { assertIdentity, callbacks, createDestination, injectGeneratedRoute, nativeOptions, parseInputs, redirect };
|
|
658
|
+
//# sourceMappingURL=loozo-angular-router-_generated.mjs.map
|