@loozo/angular-router 0.0.2 → 0.0.4
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 +565 -80
- package/builders.json +2 -2
- package/fesm2022/loozo-angular-router-_core.mjs +332 -595
- package/fesm2022/loozo-angular-router-_core.mjs.map +1 -1
- package/fesm2022/loozo-angular-router-_generated.mjs +335 -627
- package/fesm2022/loozo-angular-router-_generated.mjs.map +1 -1
- package/fesm2022/loozo-angular-router.mjs +2 -19
- package/node/_core/src/path.d.ts +17 -0
- package/node/src/builders/application.js +19 -7
- package/node/src/builders/options.js +47 -61
- package/node/src/builders/serve.js +66 -16
- 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 -8
- package/node/src/generation/files.d.ts +26 -0
- package/node/src/generation/files.js +14 -3
- package/node/src/generation/filesystem.d.ts +7 -0
- package/node/src/generation/filesystem.js +261 -69
- package/node/src/generation/generate.d.ts +16 -0
- package/node/src/generation/generate.js +10 -4
- 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/selectors.d.ts +2 -0
- package/node/src/generation/sources.d.ts +50 -0
- package/node/src/generation/sources.js +57 -12
- package/node/src/generation/validate.d.ts +12 -0
- package/node/src/generation/validate.js +53 -57
- package/package.json +7 -2
- package/schemas/application.json +764 -20
- package/schemas/serve.json +144 -30
- package/snippets/angular.json +29 -0
- package/snippets/generated/destinations.generated.ts +126 -0
- package/snippets/generated/routes.generated.ts +35 -0
- package/snippets/src/catalog.ts +20 -0
- package/snippets/src/docs-url.ts +8 -0
- package/snippets/src/index.html +11 -0
- package/snippets/src/main.ts +6 -0
- package/snippets/src/product-url.ts +8 -0
- package/snippets/src/routes/products/$productId/page.ts +20 -0
- package/snippets/src/routes/products/$productId/route.generated.ts +24 -0
- package/snippets/src/routes/products/$productId/route.ts +7 -0
- package/snippets/src/routes/reports/$reportId/page.ts +9 -0
- package/snippets/src/routes/reports/$reportId/route.generated.ts +24 -0
- package/snippets/src/routes/reports/$reportId/route.ts +6 -0
- package/snippets/src/routes/teams/$teamId/items/$id/inputs.ts +15 -0
- package/snippets/src/routes/teams/$teamId/items/$id/links.ts +13 -0
- package/snippets/src/routes/teams/$teamId/items/$id/page.ts +9 -0
- package/snippets/src/routes/teams/$teamId/items/$id/route.generated.ts +24 -0
- package/snippets/src/routes/teams/$teamId/items/$id/route.ts +18 -0
- package/snippets/src/routes/teams/$teamId/members/$memberId/page.ts +9 -0
- package/snippets/src/routes/teams/$teamId/members/$memberId/route.generated.ts +24 -0
- package/snippets/src/routes/teams/$teamId/members/$memberId/route.ts +7 -0
- package/snippets/src/routes/teams/$teamId/old-items/$id/route.ts +13 -0
- package/snippets/src/routes/teams/$teamId/route.generated.ts +24 -0
- package/snippets/src/routes/teams/$teamId/route.ts +6 -0
- package/snippets/src/shell.ts +9 -0
- package/snippets/src/slug.ts +14 -0
- package/snippets/tsconfig.app.json +14 -0
- package/snippets/tsconfig.routes.json +5 -0
- package/types/loozo-angular-router-_core.d.ts +262 -242
- package/types/loozo-angular-router-_generated.d.ts +155 -116
- package/types/loozo-angular-router.d.ts +2 -1
- package/.npmignore +0 -3
- package/fesm2022/loozo-angular-router.mjs.map +0 -1
|
@@ -1,27 +1,62 @@
|
|
|
1
|
-
import { ActivatedRouteSnapshot,
|
|
2
|
-
import { AnyRoute, ParamsOf, SearchOf, UrlValues } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { ActivatedRouteSnapshot, PartialMatchRouteSnapshot, RedirectFunction, Route, UrlTree } from "@angular/router";
|
|
2
|
+
import { AnyRoute, ParamsOf, SearchOf, UrlValues } from "@loozo/angular-router/_core";
|
|
3
|
+
import { Signal } from "@angular/core";
|
|
5
4
|
interface RecordBinding {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
readonly definition: () => AnyRoute;
|
|
6
|
+
readonly owners: readonly string[];
|
|
8
7
|
}
|
|
9
8
|
interface RouteSet {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
readonly records: Readonly<Record<string, RecordBinding>>;
|
|
10
|
+
readonly destinations: Readonly<Record<string, () => AnyRoute>>;
|
|
11
|
+
readonly absolute: Readonly<Record<string, string>>;
|
|
12
|
+
readonly relative: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
14
13
|
}
|
|
15
14
|
interface Parsed {
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
readonly params: Readonly<Record<string, unknown>>;
|
|
16
|
+
readonly search: Readonly<Record<string, unknown>>;
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
interface Job {
|
|
19
|
+
readonly key: string;
|
|
20
|
+
readonly raws: readonly string[];
|
|
21
|
+
readonly array: boolean;
|
|
22
|
+
readonly codec: {
|
|
23
|
+
parse(raw: string): unknown;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
declare function hasIdentity(snapshot: Pick<ActivatedRouteSnapshot, "routeConfig">, id: string): boolean;
|
|
27
|
+
export declare function assertIdentity(snapshot: Pick<ActivatedRouteSnapshot, "routeConfig">, id: string): void;
|
|
28
|
+
declare function validateRaw(key: string, raws: readonly unknown[], array: boolean): asserts raws is readonly string[];
|
|
29
|
+
declare function pathJobs(definition: AnyRoute, url: readonly {
|
|
30
|
+
path: string;
|
|
31
|
+
}[]): Job[];
|
|
32
|
+
/** Parses prechecked path jobs; the first codec failure is an input error. */
|
|
33
|
+
declare function runPathJobs(jobs: readonly Job[]): Readonly<Record<string, unknown>>;
|
|
34
|
+
/**
|
|
35
|
+
* Parses a declaration's effective search. It never fails on input: a missing,
|
|
36
|
+
* repeated or invalid value reads as the key's fallback, or leaves it absent.
|
|
37
|
+
*/
|
|
38
|
+
declare function parseSearch(definition: AnyRoute, snapshot: Pick<ActivatedRouteSnapshot, "queryParamMap">): Readonly<Record<string, unknown>>;
|
|
39
|
+
/** The effective inputs of a complete snapshot, shared by guards, resolvers and handles. */
|
|
40
|
+
export declare function parseInputs(set: RouteSet, id: string, snapshot: ActivatedRouteSnapshot): Parsed;
|
|
41
|
+
/**
|
|
42
|
+
* Parses a matching candidate's own path params only. Angular passes one partial
|
|
43
|
+
* snapshot to all of a candidate's canMatch guards, so they share this result.
|
|
44
|
+
*
|
|
45
|
+
* @returns An input error when a param is invalid; throws only programming errors.
|
|
46
|
+
*/
|
|
47
|
+
declare function pathInputs(set: RouteSet, id: string, snapshot: PartialMatchRouteSnapshot): {
|
|
48
|
+
params: Readonly<Record<string, unknown>>;
|
|
49
|
+
} | {
|
|
50
|
+
error: Error;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Local path params plus effective search for a candidate's canMatch guards, the
|
|
54
|
+
* generated one included, or undefined when the path params fail: the generated
|
|
55
|
+
* guard owns that outcome.
|
|
56
|
+
*/
|
|
57
|
+
declare function matchingInputs(set: RouteSet, id: string, snapshot: PartialMatchRouteSnapshot): Parsed | undefined;
|
|
58
|
+
export declare function callbacks(set: RouteSet, id: string): Pick<Route, "canActivate" | "canActivateChild" | "canMatch" | "resolve" | "title">;
|
|
59
|
+
export declare function redirect(definition: () => AnyRoute): RedirectFunction;
|
|
25
60
|
declare const destinationBrand: unique symbol;
|
|
26
61
|
/**
|
|
27
62
|
* An inert nominal reference exported as `destination` by a route-local facade.
|
|
@@ -37,17 +72,21 @@ declare const destinationBrand: unique symbol;
|
|
|
37
72
|
* @typeParam Set - The generator's nominal route-set identity.
|
|
38
73
|
* @typeParam Id - The exact generated declaration identity.
|
|
39
74
|
*/
|
|
40
|
-
declare class Destination<Target extends AnyRoute, Set = unknown, Id extends string = string> {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
75
|
+
export declare class Destination<Target extends AnyRoute, Set = unknown, Id extends string = string> {
|
|
76
|
+
#private;
|
|
77
|
+
/** Type-only nominal brand carrying the reference's identity; not populated at runtime. */
|
|
78
|
+
readonly [destinationBrand]: {
|
|
79
|
+
/** Type-only: the referenced route's input and fragment schema. */
|
|
80
|
+
readonly target: Target;
|
|
81
|
+
/** Type-only: the generator's nominal route-set identity. */
|
|
82
|
+
readonly set: Set;
|
|
83
|
+
/** Type-only: the exact generated declaration identity. */
|
|
84
|
+
readonly id: Id;
|
|
85
|
+
};
|
|
47
86
|
}
|
|
48
|
-
declare function createDestination<Target extends AnyRoute, Set, Id extends string>(getSet: () => RouteSet, id: Id): Destination<Target, Set, Id>;
|
|
87
|
+
export declare function createDestination<Target extends AnyRoute, Set, Id extends string>(getSet: () => RouteSet, id: Id): Destination<Target, Set, Id>;
|
|
49
88
|
type DataOf<Target> = Target extends {
|
|
50
|
-
|
|
89
|
+
readonly __data?: infer Data;
|
|
51
90
|
} ? Readonly<Data> : never;
|
|
52
91
|
type IsUnion<Value, Whole = Value> = Value extends unknown ? [Whole] extends [Value] ? false : true : never;
|
|
53
92
|
/**
|
|
@@ -55,14 +94,16 @@ type IsUnion<Value, Whole = Value> = Value extends unknown ? [Whole] extends [Va
|
|
|
55
94
|
*
|
|
56
95
|
* @remarks
|
|
57
96
|
* Obtain it in an Angular injection context for the exact generated activated
|
|
58
|
-
* record. Params
|
|
59
|
-
*
|
|
60
|
-
*
|
|
97
|
+
* record. Params, search and data are readonly Angular Signals of the route's
|
|
98
|
+
* committed snapshot, with values from the first read. Data contains only local
|
|
99
|
+
* resolver results, not static/ancestor data or title.
|
|
61
100
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
101
|
+
* While a navigation is pending, the signals keep the current snapshot's values;
|
|
102
|
+
* when a navigation commits a new snapshot for this route, all three change
|
|
103
|
+
* together. Cancellation, failure or a same-URL skip leaves them unchanged. For
|
|
104
|
+
* pending-navigation UI, read Angular's `Router.currentNavigation()`. There is no
|
|
105
|
+
* resolved-data cache. Reading params or search throws only when a path codec
|
|
106
|
+
* rejects a value it accepted while matching, a programming error.
|
|
66
107
|
*
|
|
67
108
|
* Selectors are single known authored literals, not concrete URLs or string
|
|
68
109
|
* unions. `.` is exact-current; other absolute/relative selections use generated
|
|
@@ -86,86 +127,84 @@ type IsUnion<Value, Whole = Value> = Value extends unknown ? [Whole] extends [Va
|
|
|
86
127
|
* // Bind link to Angular RouterLink, or call route.navigate with the same values.
|
|
87
128
|
* ```
|
|
88
129
|
*/
|
|
89
|
-
interface Handle<Target extends AnyRoute, Selected extends Record<string, AnyRoute> = {}, Set = unknown, References extends Record<string, AnyRoute> = {}> {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
130
|
+
export interface Handle<Target extends AnyRoute, Selected extends Record<string, AnyRoute> = {}, Set = unknown, References extends Record<string, AnyRoute> = {}> {
|
|
131
|
+
/** Effective positional params of the committed snapshot; kept while a navigation is pending. */
|
|
132
|
+
readonly params: Signal<Readonly<ParamsOf<Target>>>;
|
|
133
|
+
/** Effective declared search, from the same snapshot as params; absent keys have no value or fallback. */
|
|
134
|
+
readonly search: Signal<Readonly<SearchOf<Target>>>;
|
|
135
|
+
/** Own native resolver results only, from the same snapshot as params. */
|
|
136
|
+
readonly data: Signal<DataOf<Target>>;
|
|
137
|
+
/**
|
|
138
|
+
* Creates a native UrlTree for this exact declaration without navigating.
|
|
139
|
+
*
|
|
140
|
+
* @param values - Explicit effective params/search and optional own fragment.
|
|
141
|
+
* @returns Router.parseUrl's result, suitable for Angular RouterLink.
|
|
142
|
+
* @throws Synchronous URL validation, encoding or stringifier failures before Angular.
|
|
143
|
+
*/
|
|
144
|
+
link<Keys extends keyof SearchOf<Target> = never>(values: UrlValues<Target, Keys>): UrlTree;
|
|
145
|
+
/**
|
|
146
|
+
* Creates a UrlTree for the exact bound declaration, not its pathless winner.
|
|
147
|
+
*
|
|
148
|
+
* @param selector - The exact-current literal `.`.
|
|
149
|
+
* @param values - Explicit values for this declaration, with no current-input reuse.
|
|
150
|
+
* @returns Router.parseUrl's result without navigating.
|
|
151
|
+
* @throws Synchronous URL validation, encoding or stringifier failures before Angular.
|
|
152
|
+
*/
|
|
153
|
+
link<Keys extends keyof SearchOf<Target> = never>(selector: ".", values: UrlValues<Target, Keys>): UrlTree;
|
|
154
|
+
/**
|
|
155
|
+
* Creates a UrlTree for a statically admitted absolute/relative authored selector.
|
|
156
|
+
*
|
|
157
|
+
* @param selector - A single known template literal, never a concrete URL.
|
|
158
|
+
* @param values - The selected target's complete explicit values.
|
|
159
|
+
* @returns Router.parseUrl's result without navigating.
|
|
160
|
+
* @throws Synchronously for unknown selectors or invalid URL values.
|
|
161
|
+
*/
|
|
162
|
+
link<const Selector extends keyof Selected & string, Keys extends keyof SearchOf<NoInfer<Selected[Selector]>> = never>(selector: Selector & (IsUnion<Selector> extends true ? never : unknown), values: UrlValues<NoInfer<Selected[Selector]>, Keys>): UrlTree;
|
|
163
|
+
/**
|
|
164
|
+
* Creates a UrlTree for a generated reference's own exact declaration.
|
|
165
|
+
*
|
|
166
|
+
* @param selector - A genuine destination exported by a facade in this route set.
|
|
167
|
+
* @param values - The referenced declaration's complete explicit values.
|
|
168
|
+
* @returns Router.parseUrl's result without navigating.
|
|
169
|
+
* @throws Synchronously for foreign/fake references or invalid URL values.
|
|
170
|
+
*/
|
|
171
|
+
link<const Id extends keyof References & string, Keys extends keyof SearchOf<NoInfer<References[Id]>> = never>(selector: Destination<NoInfer<References[Id]>, Set, Id> & (IsUnion<Id> extends true ? never : unknown), values: UrlValues<NoInfer<References[Id]>, Keys>): UrlTree;
|
|
172
|
+
/**
|
|
173
|
+
* Navigates to this exact declaration via Router.navigateByUrl.
|
|
174
|
+
*
|
|
175
|
+
* @param values - Explicit effective params/search and optional own fragment.
|
|
176
|
+
* @returns Angular's identical Promise; Angular owns skips, redirects and failures.
|
|
177
|
+
* @throws Synchronous URL validation, encoding or stringifier failures before Angular.
|
|
178
|
+
*/
|
|
179
|
+
navigate<Keys extends keyof SearchOf<Target> = never>(values: UrlValues<Target, Keys>): Promise<boolean>;
|
|
180
|
+
/**
|
|
181
|
+
* Navigates to the exact bound declaration, not its pathless winner.
|
|
182
|
+
*
|
|
183
|
+
* @param selector - The exact-current literal `.`.
|
|
184
|
+
* @param values - Explicit values for this declaration, with no current-input reuse.
|
|
185
|
+
* @returns Angular's identical Router.navigateByUrl Promise.
|
|
186
|
+
* @throws Synchronous URL validation, encoding or stringifier failures before Angular.
|
|
187
|
+
*/
|
|
188
|
+
navigate<Keys extends keyof SearchOf<Target> = never>(selector: ".", values: UrlValues<Target, Keys>): Promise<boolean>;
|
|
189
|
+
/**
|
|
190
|
+
* Navigates to a statically admitted absolute/relative authored selector.
|
|
191
|
+
*
|
|
192
|
+
* @param selector - A single known template literal, never a concrete URL.
|
|
193
|
+
* @param values - The selected target's complete explicit values.
|
|
194
|
+
* @returns Angular's identical Router.navigateByUrl Promise.
|
|
195
|
+
* @throws Synchronously for unknown selectors or invalid URL values.
|
|
196
|
+
*/
|
|
197
|
+
navigate<const Selector extends keyof Selected & string, Keys extends keyof SearchOf<NoInfer<Selected[Selector]>> = never>(selector: Selector & (IsUnion<Selector> extends true ? never : unknown), values: UrlValues<NoInfer<Selected[Selector]>, Keys>): Promise<boolean>;
|
|
198
|
+
/**
|
|
199
|
+
* Navigates to a generated reference's own exact declaration.
|
|
200
|
+
*
|
|
201
|
+
* @param selector - A genuine destination exported by a facade in this route set.
|
|
202
|
+
* @param values - The referenced declaration's complete explicit values.
|
|
203
|
+
* @returns Angular's identical Router.navigateByUrl Promise.
|
|
204
|
+
* @throws Synchronously for foreign/fake references or invalid URL values.
|
|
205
|
+
*/
|
|
206
|
+
navigate<const Id extends keyof References & string, Keys extends keyof SearchOf<NoInfer<References[Id]>> = never>(selector: Destination<NoInfer<References[Id]>, Set, Id> & (IsUnion<Id> extends true ? never : unknown), values: UrlValues<NoInfer<References[Id]>, Keys>): Promise<boolean>;
|
|
166
207
|
}
|
|
167
|
-
declare function nativeOptions(definition: AnyRoute): Record<string, unknown>;
|
|
168
|
-
declare function injectGeneratedRoute<Target extends AnyRoute, Selected extends Record<string, AnyRoute>, Set, References extends Record<string, AnyRoute>>(set: RouteSet, id: string): Handle<Target, Selected, Set, References>;
|
|
169
|
-
|
|
170
|
-
export { Destination, assertIdentity, callbacks, createDestination, injectGeneratedRoute, nativeOptions, parseInputs, redirect };
|
|
171
|
-
export type { Handle, RecordBinding, RouteSet };
|
|
208
|
+
export declare function nativeOptions(definition: AnyRoute): Record<string, unknown>;
|
|
209
|
+
export declare function injectGeneratedRoute<Target extends AnyRoute, Selected extends Record<string, AnyRoute>, Set, References extends Record<string, AnyRoute>>(set: RouteSet, id: string): Handle<Target, Selected, Set, References>;
|
|
210
|
+
export type { RecordBinding, RouteSet };
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { ParamCodec, Route, booleanParam, createUrl, defineRoute, enumParam, numberParam, stringParam, withFallback } from "@loozo/angular-router/_core";
|
|
2
|
+
export { type ParamCodec, type Route, booleanParam, createUrl, defineRoute, enumParam, numberParam, stringParam, withFallback };
|
package/.npmignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loozo-angular-router.mjs","sources":["../../src/index.ts","../../src/loozo-angular-router.ts"],"sourcesContent":["/**\n * Typed declarations, scalar codecs and synchronous URLs for Angular's native router.\n *\n * @remarks\n * Install generated `routes` with Angular's provideRouter and import the colocated\n * `injectRoute`/`destination` facade for typed resources, links and navigation.\n * Generate through the application/serve Architect companions. The `_core` and\n * `_generated` subpaths are internal package/generator coupling, not supported\n * application metadata or graph APIs.\n *\n * @packageDocumentation\n */\nexport {\n defineRoute,\n createUrl,\n stringParam,\n numberParam,\n booleanParam,\n enumParam,\n optionalSearchParam,\n nullableSearchParam,\n} from \"@loozo/angular-router/_core\";\nexport type { Route, ParamCodec } from \"@loozo/angular-router/_core\";\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;;AAWG;;ACXH;;AAEG"}
|