@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,658 +1,533 @@
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
-
1
+ import { DestroyRef, Injector, PendingTasks, inject, resourceFromSnapshots, runInInjectionContext, signal } from "@angular/core";
2
+ import { ActivatedRoute, NavigationCancel, NavigationCancellationCode, NavigationEnd, NavigationError, NavigationSkipped, NavigationStart, Router } from "@angular/router";
3
+ import { Observable, from, isObservable } from "rxjs";
4
+ import { codecPresence, createUrl, routeMetadata } from "@loozo/angular-router/_core";
6
5
  function hasIdentity(snapshot, id) {
7
- const data = snapshot.routeConfig?.data;
8
- return (!!data &&
9
- Object.hasOwn(data, "__loozoAngularRouterRouteId") &&
10
- data.__loozoAngularRouterRouteId === id);
6
+ const data = snapshot.routeConfig?.data;
7
+ return !!data && Object.hasOwn(data, "__loozoAngularRouterRouteId") && data.__loozoAngularRouterRouteId === id;
11
8
  }
12
9
  function assertIdentity(snapshot, id) {
13
- if (!hasIdentity(snapshot, id)) {
14
- throw new Error(`Generated route wiring identity mismatch: ${id}`);
15
- }
10
+ if (!hasIdentity(snapshot, id)) throw new Error(`Generated route wiring identity mismatch: ${id}`);
16
11
  }
17
12
  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
- });
13
+ return Object.assign(new Error(`Invalid ${source} input ${key}: ${reason}`, { cause }), {
14
+ source,
15
+ key,
16
+ reason
17
+ });
23
18
  }
24
19
  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
- }
20
+ if (!array && raws.length === 0) throw inputError(source, key, "missing");
21
+ if (!array && raws.length > 1) throw inputError(source, key, "repeated");
22
+ if (raws.some((raw) => typeof raw !== "string")) throw inputError(source, key, "invalid", /* @__PURE__ */ new TypeError("Raw input must be a decoded string"));
34
23
  }
35
24
  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()];
25
+ const metadata = routeMetadata(definition);
26
+ const local = /* @__PURE__ */ new Map();
27
+ for (let index = 0; index < metadata.localSegments.length; index += 1) {
28
+ const segment = metadata.localSegments[index];
29
+ if (segment.kind === "static") continue;
30
+ let raws = [];
31
+ const array = segment.kind === "catchall";
32
+ if (array) raws = url.slice(index).map((value) => value.path);
33
+ else if (index < url.length) raws = [url[index].path];
34
+ validateRaw("path", segment.name, raws, array);
35
+ local.set(segment.name, {
36
+ source: "path",
37
+ key: segment.name,
38
+ raws,
39
+ array,
40
+ codec: metadata.localParams[segment.name]
41
+ });
42
+ }
43
+ return [...local.values()];
62
44
  }
63
45
  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;
46
+ const metadata = routeMetadata(definition);
47
+ const jobs = [];
48
+ for (const key of Object.keys(metadata.search)) {
49
+ const codec = metadata.search[key];
50
+ const raws = snapshot.queryParamMap.getAll(key);
51
+ if (raws.length === 0 && codecPresence(codec) === "optional") continue;
52
+ validateRaw("search", key, raws, false);
53
+ jobs.push({
54
+ source: "search",
55
+ key,
56
+ raws,
57
+ array: false,
58
+ codec
59
+ });
60
+ }
61
+ return jobs;
76
62
  }
77
63
  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) });
64
+ const params = Object.create(null);
65
+ const search = Object.create(null);
66
+ const pending = [];
67
+ for (const job of jobs) pending.push((async () => {
68
+ try {
69
+ const elements = [];
70
+ for (const raw of job.raws) elements.push((async () => job.codec.parse(raw))());
71
+ const values = await Promise.all(elements);
72
+ let value = values[0];
73
+ if (job.array) value = Object.freeze(values);
74
+ if (job.source === "path") params[job.key] = value;
75
+ else search[job.key] = value;
76
+ } catch (cause) {
77
+ throw inputError(job.source, job.key, "invalid", cause);
78
+ }
79
+ })());
80
+ await Promise.all(pending);
81
+ return Object.freeze({
82
+ params: Object.freeze(params),
83
+ search: Object.freeze(search)
84
+ });
108
85
  }
109
- const full = new WeakMap();
110
- const matching = new WeakMap();
86
+ const full = /* @__PURE__ */ new WeakMap();
87
+ const matching = /* @__PURE__ */ new WeakMap();
111
88
  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;
89
+ let snapshots = cache.get(definition);
90
+ if (!snapshots) {
91
+ snapshots = /* @__PURE__ */ new WeakMap();
92
+ cache.set(definition, snapshots);
93
+ }
94
+ const existing = snapshots.get(snapshot);
95
+ if (existing) return existing;
96
+ const result = {
97
+ promise: Promise.resolve().then(() => runJobs(collect())),
98
+ outcome: void 0
99
+ };
100
+ snapshots.set(snapshot, result);
101
+ result.promise.then((value) => {
102
+ result.outcome = { value };
103
+ }, (cause) => {
104
+ let error = cause;
105
+ if (!(error instanceof Error)) error = new Error("Route input failure", { cause });
106
+ result.outcome = { error };
107
+ });
108
+ return result;
137
109
  }
138
110
  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
- });
111
+ assertIdentity(snapshot, id);
112
+ const binding = set.records[id];
113
+ return operation(full, binding.definition(), snapshot, () => {
114
+ const jobs = [];
115
+ for (const ownerId of binding.owners) {
116
+ const definition = set.records[ownerId].definition();
117
+ if (!routeMetadata(definition).localSegments.some((segment) => segment.kind !== "static")) continue;
118
+ const owner = [...snapshot.pathFromRoot].reverse().find((record) => hasIdentity(record, ownerId));
119
+ if (!owner) throw new Error(`Generated route ancestor missing: ${ownerId}`);
120
+ assertIdentity(owner, ownerId);
121
+ jobs.push(...pathJobs(definition, owner.url));
122
+ }
123
+ jobs.push(...searchJobs(binding.definition(), snapshot));
124
+ return jobs;
125
+ });
162
126
  }
163
127
  function parseInputs(set, id, snapshot) {
164
- return fullOperation(set, id, snapshot).promise;
128
+ return fullOperation(set, id, snapshot).promise;
165
129
  }
166
130
  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;
131
+ assertIdentity(snapshot, id);
132
+ const definition = set.records[id].definition();
133
+ return operation(matching, definition, snapshot, () => [...pathJobs(definition, snapshot.url), ...searchJobs(definition, snapshot)]).promise;
173
134
  }
174
-
175
135
  function isPromiseResult(value) {
176
- return !!value && typeof value.then === "function";
136
+ return !!value && typeof value.then === "function";
177
137
  }
178
138
  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
- });
139
+ const injector = inject(Injector);
140
+ return new Observable((subscriber) => {
141
+ let subscription;
142
+ inputs().then((value) => {
143
+ if (subscriber.closed) return;
144
+ try {
145
+ const result = runInInjectionContext(injector, () => callback(value));
146
+ if (isObservable(result)) subscription = result.subscribe(subscriber);
147
+ else if (isPromiseResult(result)) subscription = from(Promise.resolve(result)).subscribe(subscriber);
148
+ else {
149
+ subscriber.next(result);
150
+ subscriber.complete();
151
+ }
152
+ } catch (error) {
153
+ subscriber.error(error);
154
+ }
155
+ }, (error) => subscriber.error(error));
156
+ return () => subscription?.unsubscribe();
157
+ });
205
158
  }
206
159
  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;
160
+ const config = routeMetadata(set.records[id].definition()).config;
161
+ const result = {};
162
+ const activate = config.canActivate;
163
+ if (activate) result.canActivate = activate.map((callback) => (snapshot, state) => {
164
+ assertIdentity(snapshot, id);
165
+ return bridge(() => parseInputs(set, id, snapshot), (inputs) => callback(inputs, snapshot, state));
166
+ });
167
+ const children = config.canActivateChild;
168
+ if (children) result.canActivateChild = children.map((callback) => (child, state) => {
169
+ let parent;
170
+ for (let index = child.pathFromRoot.length - 2; index >= 0; index -= 1) {
171
+ const ancestor = child.pathFromRoot[index];
172
+ if (hasIdentity(ancestor, id)) {
173
+ parent = ancestor;
174
+ break;
175
+ }
176
+ }
177
+ if (!parent) throw new Error(`Generated guard ancestor missing: ${id}`);
178
+ assertIdentity(parent, id);
179
+ return bridge(() => parseInputs(set, id, parent), (inputs) => callback(inputs, child, state));
180
+ });
181
+ const matching = config.canMatch;
182
+ if (matching) result.canMatch = matching.map((callback) => (route, segments, snapshot) => {
183
+ assertIdentity(snapshot, id);
184
+ return bridge(() => matchingInputs(set, id, snapshot), (inputs) => callback(inputs, route, segments, snapshot));
185
+ });
186
+ const resolvers = config.resolve;
187
+ if (resolvers) {
188
+ const resolve = Object.create(null);
189
+ for (const key of Reflect.ownKeys(resolvers)) resolve[key] = (snapshot, state) => {
190
+ assertIdentity(snapshot, id);
191
+ return bridge(() => parseInputs(set, id, snapshot), (inputs) => resolvers[key](inputs, snapshot, state));
192
+ };
193
+ result.resolve = resolve;
194
+ }
195
+ return result;
254
196
  }
255
197
  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
- };
198
+ return async (snapshot) => {
199
+ const router = inject(Router);
200
+ const source = routeMetadata(definition());
201
+ const config = source.config.redirect;
202
+ const target = routeMetadata(config.to);
203
+ const raw = /* @__PURE__ */ new Map();
204
+ for (let index = 0; index < source.segments.length; index += 1) {
205
+ const segment = source.segments[index];
206
+ if (segment.kind === "scalar") raw.set(segment.name, {
207
+ values: snapshot.url.slice(index, index + 1).map((value) => value.path),
208
+ array: false
209
+ });
210
+ else if (segment.kind === "catchall") raw.set(segment.name, {
211
+ values: snapshot.url.slice(index).map((value) => value.path),
212
+ array: true
213
+ });
214
+ }
215
+ const jobs = [];
216
+ for (const key of new Set(Object.values(config.params))) {
217
+ const input = raw.get(key);
218
+ const raws = input?.values ?? [];
219
+ const array = input?.array ?? false;
220
+ validateRaw("path", key, raws, array);
221
+ jobs.push({
222
+ source: "path",
223
+ key,
224
+ raws,
225
+ array,
226
+ codec: source.params[key]
227
+ });
228
+ }
229
+ if (config.search.mode === "preserve") for (const key of Object.keys(target.search)) {
230
+ const codec = target.search[key];
231
+ const raws = snapshot.queryParamMap.getAll(key);
232
+ if (raws.length === 0 && codecPresence(codec) === "optional") continue;
233
+ validateRaw("search", key, raws, false);
234
+ jobs.push({
235
+ source: "search",
236
+ key,
237
+ raws,
238
+ array: false,
239
+ codec
240
+ });
241
+ }
242
+ const logical = await runJobs(jobs);
243
+ const params = Object.create(null);
244
+ for (const [key, sourceKey] of Object.entries(config.params)) params[key] = logical.params[sourceKey];
245
+ const path = createUrlForPath(config.to, params);
246
+ const replacement = Object.create(null);
247
+ if (config.search.mode === "replace") {
248
+ const values = config.search.values;
249
+ for (const key of Object.keys(target.search).sort()) {
250
+ const codec = target.search[key];
251
+ if (codecPresence(codec) === "optional" && (!Object.hasOwn(values, key) || values[key] === void 0)) continue;
252
+ const raw = codec.stringify(values[key]);
253
+ if (typeof raw !== "string") throw new TypeError(`Redirect search codec must stringify to a string: ${key}`);
254
+ replacement[key] = raw;
255
+ }
256
+ }
257
+ const tree = router.parseUrl(path);
258
+ if (config.search.mode === "preserve") tree.queryParams = { ...snapshot.queryParams };
259
+ else if (config.search.mode === "replace") tree.queryParams = replacement;
260
+ if (config.fragment.mode === "preserve") tree.fragment = snapshot.fragment;
261
+ else if (config.fragment.mode === "replace") tree.fragment = config.fragment.value;
262
+ return tree;
263
+ };
336
264
  }
337
265
  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("/")}`;
266
+ const metadata = routeMetadata(definition);
267
+ const parts = [];
268
+ function encode(raw) {
269
+ if (raw === "" || raw === "." || raw === "..") throw new TypeError("Invalid redirect path value");
270
+ return encodeURIComponent(raw).replace(/\(/g, "%28").replace(/\)/g, "%29");
271
+ }
272
+ for (const segment of metadata.segments) if (segment.kind === "static") parts.push(encode(segment.text));
273
+ else if (segment.kind === "scalar") {
274
+ const raw = metadata.params[segment.name].stringify(params[segment.name]);
275
+ if (typeof raw !== "string") throw new TypeError("Redirect codec must stringify to a string");
276
+ parts.push(encode(raw));
277
+ } else {
278
+ const values = params[segment.name];
279
+ if (!Array.isArray(values)) throw new TypeError("Redirect catchall requires an array");
280
+ for (const value of values) {
281
+ const raw = metadata.params[segment.name].stringify(value);
282
+ if (typeof raw !== "string") throw new TypeError("Redirect codec must stringify to a string");
283
+ parts.push(encode(raw));
284
+ }
285
+ }
286
+ return `/${parts.join("/")}`;
372
287
  }
373
-
374
- // Shared parsing has no view/task lifetime. Each handle owns its visibility and relevance.
375
288
  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
- };
289
+ const activated = inject(ActivatedRoute);
290
+ const router = inject(Router);
291
+ const destroy = inject(DestroyRef);
292
+ const tasks = inject(PendingTasks);
293
+ assertIdentity(activated.snapshot, id);
294
+ const paired = signal({
295
+ status: "loading",
296
+ value: void 0
297
+ }, ...ngDevMode ? [{ debugName: "paired" }] : /* istanbul ignore next */ []);
298
+ const data = signal({
299
+ status: "loading",
300
+ value: void 0
301
+ }, ...ngDevMode ? [{ debugName: "data" }] : /* istanbul ignore next */ []);
302
+ let survivor;
303
+ let work;
304
+ let commitment = -1;
305
+ let pending;
306
+ let visible = false;
307
+ let destroyed = false;
308
+ let release;
309
+ let acquiring = false;
310
+ function track() {
311
+ if (release || destroyed || acquiring) return;
312
+ acquiring = true;
313
+ const cleanup = tasks.add();
314
+ acquiring = false;
315
+ if (destroyed) {
316
+ cleanup();
317
+ return;
318
+ }
319
+ release = cleanup;
320
+ }
321
+ function untrack() {
322
+ const cleanup = release;
323
+ release = void 0;
324
+ cleanup?.();
325
+ }
326
+ function publish() {
327
+ if (!visible || destroyed || !work) return;
328
+ if (!work.outcome) {
329
+ paired.set({
330
+ status: "loading",
331
+ value: void 0
332
+ });
333
+ track();
334
+ return;
335
+ }
336
+ if ("value" in work.outcome) paired.set({
337
+ status: "resolved",
338
+ value: work.outcome.value
339
+ });
340
+ else paired.set({
341
+ status: "error",
342
+ error: work.outcome.error
343
+ });
344
+ untrack();
345
+ }
346
+ function adopt(snapshot) {
347
+ assertIdentity(snapshot, id);
348
+ if (snapshot === survivor) return;
349
+ survivor = snapshot;
350
+ const joined = fullOperation(set, id, snapshot);
351
+ work = joined;
352
+ if (!joined.outcome) track();
353
+ joined.promise.then(() => {
354
+ if (work === joined) publish();
355
+ }, () => {
356
+ if (work === joined) publish();
357
+ });
358
+ }
359
+ function reconcile() {
360
+ const successful = router.lastSuccessfulNavigation();
361
+ if (successful && successful.id > commitment) {
362
+ commitment = successful.id;
363
+ adopt(activated.snapshot);
364
+ }
365
+ }
366
+ function restore() {
367
+ if (destroyed) return;
368
+ reconcile();
369
+ if (!survivor) adopt(activated.snapshot);
370
+ const local = Object.create(null);
371
+ const resolvers = routeMetadata(set.records[id].definition()).config.resolve ?? {};
372
+ for (const key of Reflect.ownKeys(resolvers)) if (Object.hasOwn(survivor.data, key)) local[key] = survivor.data[key];
373
+ data.set({
374
+ status: "resolved",
375
+ value: Object.freeze(local)
376
+ });
377
+ visible = true;
378
+ publish();
379
+ }
380
+ function idleHandoff() {
381
+ queueMicrotask(() => {
382
+ if (destroyed || visible) return;
383
+ const current = router.currentNavigation();
384
+ const successful = router.lastSuccessfulNavigation();
385
+ if (!current || current.id === successful?.id) {
386
+ pending = void 0;
387
+ restore();
388
+ }
389
+ });
390
+ }
391
+ function eligible(id) {
392
+ const current = router.currentNavigation();
393
+ const successful = router.lastSuccessfulNavigation();
394
+ if (current && current.id > id && current.id !== successful?.id) return false;
395
+ return pending === void 0 || pending === id;
396
+ }
397
+ const subscription = router.events.subscribe((event) => {
398
+ if (destroyed) return;
399
+ if (event instanceof NavigationStart) {
400
+ pending = event.id;
401
+ visible = false;
402
+ reconcile();
403
+ paired.set({
404
+ status: "loading",
405
+ value: void 0
406
+ });
407
+ data.set({
408
+ status: "loading",
409
+ value: void 0
410
+ });
411
+ } else if (event instanceof NavigationEnd) {
412
+ reconcile();
413
+ if (eligible(event.id)) {
414
+ pending = void 0;
415
+ restore();
416
+ }
417
+ } else if (event instanceof NavigationCancel) {
418
+ reconcile();
419
+ if (event.code === NavigationCancellationCode.Redirect || event.code === NavigationCancellationCode.SupersededByNewNavigation) return;
420
+ if (eligible(event.id)) {
421
+ pending = void 0;
422
+ restore();
423
+ }
424
+ } else if (event instanceof NavigationSkipped) {
425
+ reconcile();
426
+ if (eligible(event.id)) {
427
+ pending = void 0;
428
+ restore();
429
+ }
430
+ } else if (event instanceof NavigationError && eligible(event.id)) {
431
+ reconcile();
432
+ pending = void 0;
433
+ visible = false;
434
+ let error = event.error;
435
+ if (!(error instanceof Error)) error = new Error("Navigation failure", { cause: event.error });
436
+ paired.set({
437
+ status: "error",
438
+ error
439
+ });
440
+ data.set({
441
+ status: "error",
442
+ error
443
+ });
444
+ untrack();
445
+ }
446
+ });
447
+ destroy.onDestroy(() => {
448
+ destroyed = true;
449
+ visible = false;
450
+ subscription.unsubscribe();
451
+ untrack();
452
+ });
453
+ track();
454
+ if (!destroyed) {
455
+ const current = router.currentNavigation();
456
+ const successful = router.lastSuccessfulNavigation();
457
+ if (!current || current.id === successful?.id) restore();
458
+ else {
459
+ pending = current.id;
460
+ idleHandoff();
461
+ }
462
+ }
463
+ function project(key) {
464
+ const state = paired();
465
+ if (state.status === "error") return state;
466
+ return {
467
+ status: state.status,
468
+ value: state.value?.[key]
469
+ };
470
+ }
471
+ return {
472
+ params: resourceFromSnapshots(() => project("params")),
473
+ search: resourceFromSnapshots(() => project("search")),
474
+ data: resourceFromSnapshots(() => data())
475
+ };
586
476
  }
587
-
588
- const destinations = new WeakMap();
477
+ const destinations = /* @__PURE__ */ new WeakMap();
589
478
  function createDestination(getSet, id) {
590
- const destination = Object.freeze({});
591
- destinations.set(destination, { getSet, id });
592
- return destination;
479
+ const destination = Object.freeze({});
480
+ destinations.set(destination, {
481
+ getSet,
482
+ id
483
+ });
484
+ return destination;
593
485
  }
594
486
  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;
487
+ const config = routeMetadata(definition).config;
488
+ const options = {};
489
+ for (const key of [
490
+ "providers",
491
+ "title",
492
+ "data",
493
+ "canDeactivate",
494
+ "runGuardsAndResolvers"
495
+ ]) if (Object.hasOwn(config, key)) options[key] = config[key];
496
+ return options;
603
497
  }
604
498
  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
- };
499
+ const router = inject(Router);
500
+ const view = observeRoute(set, id);
501
+ function url(args) {
502
+ if (args.length !== 1 && args.length !== 2) throw new TypeError("Expected values or a selected destination and values");
503
+ let target = id;
504
+ let values = args[0];
505
+ if (args.length === 2) {
506
+ const selector = args[0];
507
+ values = args[1];
508
+ if (typeof selector === "string") {
509
+ if (selector !== ".") {
510
+ if (Object.hasOwn(set.absolute, selector)) target = set.absolute[selector];
511
+ else if (Object.hasOwn(set.relative[id], selector)) target = set.relative[id][selector];
512
+ else throw new TypeError(`Unknown generated selector: ${selector}`);
513
+ }
514
+ } else {
515
+ if (typeof selector !== "object" || selector === null) throw new TypeError("Expected a literal selector or genuine generated destination");
516
+ const destination = destinations.get(selector);
517
+ if (!destination || destination.getSet() !== set || !Object.hasOwn(set.records, destination.id)) throw new TypeError("Expected a destination from the same generated set");
518
+ target = destination.id;
519
+ }
520
+ }
521
+ return createUrl(set.destinations[target](), values);
522
+ }
523
+ return {
524
+ params: view.params,
525
+ search: view.search,
526
+ data: view.data,
527
+ link: ((...args) => router.parseUrl(url(args))),
528
+ navigate: ((...args) => router.navigateByUrl(url(args)))
529
+ };
651
530
  }
652
-
653
- /**
654
- * Generated bundle index. Do not edit.
655
- */
656
-
657
531
  export { assertIdentity, callbacks, createDestination, injectGeneratedRoute, nativeOptions, parseInputs, redirect };
658
- //# sourceMappingURL=loozo-angular-router-_generated.mjs.map
532
+
533
+ //# sourceMappingURL=loozo-angular-router-_generated.mjs.map