@angular/ssr 19.0.0-next.1 → 19.0.0-next.11
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/LICENSE +21 -0
- package/fesm2022/node.mjs +425 -0
- package/fesm2022/node.mjs.map +1 -0
- package/fesm2022/ssr.mjs +1302 -758
- package/fesm2022/ssr.mjs.map +1 -1
- package/index.d.ts +556 -95
- package/node/index.d.ts +207 -0
- package/package.json +13 -11
- package/third_party/critters/THIRD_PARTY_LICENSES.txt +350 -0
- package/{esm2022/index.mjs → third_party/critters/index.d.ts} +3 -2
- package/third_party/critters/index.js +13160 -0
- package/third_party/critters/index.js.map +7 -0
- package/esm2022/private_export.mjs +0 -10
- package/esm2022/public_api.mjs +0 -9
- package/esm2022/src/app-engine.mjs +0 -84
- package/esm2022/src/app.mjs +0 -167
- package/esm2022/src/assets.mjs +0 -44
- package/esm2022/src/common-engine/common-engine.mjs +0 -137
- package/esm2022/src/common-engine/inline-css-processor.mjs +0 -181
- package/esm2022/src/common-engine/peformance-profiler.mjs +0 -50
- package/esm2022/src/console.mjs +0 -34
- package/esm2022/src/hooks.mjs +0 -94
- package/esm2022/src/i18n.mjs +0 -41
- package/esm2022/src/manifest.mjs +0 -59
- package/esm2022/src/request.mjs +0 -63
- package/esm2022/src/response.mjs +0 -58
- package/esm2022/src/routes/ng-routes.mjs +0 -157
- package/esm2022/src/routes/route-tree.mjs +0 -180
- package/esm2022/src/routes/router.mjs +0 -88
- package/esm2022/src/tokens.mjs +0 -20
- package/esm2022/src/utils/ng.mjs +0 -51
- package/esm2022/src/utils/url.mjs +0 -85
package/index.d.ts
CHANGED
|
@@ -1,6 +1,81 @@
|
|
|
1
|
-
import { ApplicationRef } from '@angular/core';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { ApplicationRef } from '@angular/core';
|
|
2
|
+
import { default as default_2 } from 'critters';
|
|
3
|
+
import { EnvironmentProviders } from '@angular/core';
|
|
4
|
+
import { InjectionToken } from '@angular/core';
|
|
5
|
+
import type { Type } from '@angular/core';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Angular server application engine.
|
|
9
|
+
* Manages Angular server applications (including localized ones), handles rendering requests,
|
|
10
|
+
* and optionally transforms index HTML before rendering.
|
|
11
|
+
*
|
|
12
|
+
* @note This class should be instantiated once and used as a singleton across the server-side
|
|
13
|
+
* application to ensure consistent handling of rendering requests and resource management.
|
|
14
|
+
*
|
|
15
|
+
* @developerPreview
|
|
16
|
+
*/
|
|
17
|
+
export declare class AngularAppEngine {
|
|
18
|
+
/**
|
|
19
|
+
* Hooks for extending or modifying the behavior of the server application.
|
|
20
|
+
* These hooks are used by the Angular CLI when running the development server and
|
|
21
|
+
* provide extensibility points for the application lifecycle.
|
|
22
|
+
*
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
static ɵhooks: Hooks;
|
|
26
|
+
/**
|
|
27
|
+
* The manifest for the server application.
|
|
28
|
+
*/
|
|
29
|
+
private readonly manifest;
|
|
30
|
+
/**
|
|
31
|
+
* A cache that holds entry points, keyed by their potential locale string.
|
|
32
|
+
*/
|
|
33
|
+
private readonly entryPointsCache;
|
|
34
|
+
/**
|
|
35
|
+
* Renders a response for the given HTTP request using the server application.
|
|
36
|
+
*
|
|
37
|
+
* This method processes the request, determines the appropriate route and rendering context,
|
|
38
|
+
* and returns an HTTP response.
|
|
39
|
+
*
|
|
40
|
+
* If the request URL appears to be for a file (excluding `/index.html`), the method returns `null`.
|
|
41
|
+
* A request to `https://www.example.com/page/index.html` will render the Angular route
|
|
42
|
+
* corresponding to `https://www.example.com/page`.
|
|
43
|
+
*
|
|
44
|
+
* @param request - The incoming HTTP request object to be rendered.
|
|
45
|
+
* @param requestContext - Optional additional context for the request, such as metadata.
|
|
46
|
+
* @returns A promise that resolves to a Response object, or `null` if the request URL represents a file (e.g., `./logo.png`)
|
|
47
|
+
* rather than an application route.
|
|
48
|
+
*/
|
|
49
|
+
render(request: Request, requestContext?: unknown): Promise<Response | null>;
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves HTTP headers for a request associated with statically generated (SSG) pages,
|
|
52
|
+
* based on the URL pathname.
|
|
53
|
+
*
|
|
54
|
+
* @param request - The incoming request object.
|
|
55
|
+
* @returns A `Map` containing the HTTP headers as key-value pairs.
|
|
56
|
+
* @note This function should be used exclusively for retrieving headers of SSG pages.
|
|
57
|
+
*/
|
|
58
|
+
getPrerenderHeaders(request: Request): ReadonlyMap<string, string>;
|
|
59
|
+
/**
|
|
60
|
+
* Retrieves the exports for a specific entry point, caching the result.
|
|
61
|
+
*
|
|
62
|
+
* @param potentialLocale - The locale string used to find the corresponding entry point.
|
|
63
|
+
* @returns A promise that resolves to the entry point exports or `undefined` if not found.
|
|
64
|
+
*/
|
|
65
|
+
private getEntryPointExports;
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves the entry point for a given URL by determining the locale and mapping it to
|
|
68
|
+
* the appropriate application bundle.
|
|
69
|
+
*
|
|
70
|
+
* This method determines the appropriate entry point and locale for rendering the application by examining the URL.
|
|
71
|
+
* If there is only one entry point available, it is returned regardless of the URL.
|
|
72
|
+
* Otherwise, the method extracts a potential locale identifier from the URL and looks up the corresponding entry point.
|
|
73
|
+
*
|
|
74
|
+
* @param url - The URL of the request.
|
|
75
|
+
* @returns A promise that resolves to the entry point exports or `undefined` if not found.
|
|
76
|
+
*/
|
|
77
|
+
private getEntryPointExportsForUrl;
|
|
78
|
+
}
|
|
4
79
|
|
|
5
80
|
/**
|
|
6
81
|
* Manifest for the Angular server application engine, defining entry points.
|
|
@@ -12,12 +87,21 @@ declare interface AngularAppEngineManifest {
|
|
|
12
87
|
* - `key`: The base href for the entry point.
|
|
13
88
|
* - `value`: A function that returns a promise resolving to an object of type `EntryPointExports`.
|
|
14
89
|
*/
|
|
15
|
-
readonly entryPoints:
|
|
90
|
+
readonly entryPoints: ReadonlyMap<string, () => Promise<EntryPointExports>>;
|
|
16
91
|
/**
|
|
17
92
|
* The base path for the server application.
|
|
18
93
|
* This is used to determine the root path of the application.
|
|
19
94
|
*/
|
|
20
95
|
readonly basePath: string;
|
|
96
|
+
/**
|
|
97
|
+
* A map that associates static paths with their corresponding HTTP headers.
|
|
98
|
+
* Each entry in the map consists of:
|
|
99
|
+
* - `key`: The static path as a string.
|
|
100
|
+
* - `value`: An array of tuples, where each tuple contains:
|
|
101
|
+
* - `headerName`: The name of the HTTP header.
|
|
102
|
+
* - `headerValue`: The value of the HTTP header.
|
|
103
|
+
*/
|
|
104
|
+
readonly staticPathsHeaders: ReadonlyMap<string, readonly [headerName: string, headerValue: string][]>;
|
|
21
105
|
}
|
|
22
106
|
|
|
23
107
|
/**
|
|
@@ -30,12 +114,13 @@ declare interface AngularAppManifest {
|
|
|
30
114
|
* - `key`: The path of the asset.
|
|
31
115
|
* - `value`: A function returning a promise that resolves to the file contents of the asset.
|
|
32
116
|
*/
|
|
33
|
-
readonly assets:
|
|
117
|
+
readonly assets: ReadonlyMap<string, () => Promise<string>>;
|
|
34
118
|
/**
|
|
35
119
|
* The bootstrap mechanism for the server application.
|
|
36
|
-
* A function that returns a
|
|
120
|
+
* A function that returns a promise that resolves to an `NgModule` or a function
|
|
121
|
+
* returning a promise that resolves to an `ApplicationRef`.
|
|
37
122
|
*/
|
|
38
|
-
readonly bootstrap: () => AngularBootstrap
|
|
123
|
+
readonly bootstrap: () => Promise<AngularBootstrap>;
|
|
39
124
|
/**
|
|
40
125
|
* Indicates whether critical CSS should be inlined into the HTML.
|
|
41
126
|
* If set to `true`, critical CSS will be inlined for faster page rendering.
|
|
@@ -47,6 +132,11 @@ declare interface AngularAppManifest {
|
|
|
47
132
|
* It is used for route matching and navigation within the server application.
|
|
48
133
|
*/
|
|
49
134
|
readonly routes?: SerializableRouteTreeNode;
|
|
135
|
+
/**
|
|
136
|
+
* An optional string representing the locale or language code to be used for
|
|
137
|
+
* the application, aiding with localization and rendering content specific to the locale.
|
|
138
|
+
*/
|
|
139
|
+
readonly locale?: string;
|
|
50
140
|
}
|
|
51
141
|
|
|
52
142
|
/**
|
|
@@ -68,24 +158,24 @@ declare interface AngularRouterConfigResult {
|
|
|
68
158
|
*/
|
|
69
159
|
baseHref: string;
|
|
70
160
|
/**
|
|
71
|
-
* An array of `
|
|
161
|
+
* An array of `RouteTreeNodeMetadata` objects representing the application's routes.
|
|
72
162
|
*
|
|
73
|
-
* Each `
|
|
163
|
+
* Each `RouteTreeNodeMetadata` contains details about a specific route, such as its path and any
|
|
74
164
|
* associated redirection targets. This array is asynchronously generated and
|
|
75
165
|
* provides information on how routes are structured and resolved.
|
|
166
|
+
*/
|
|
167
|
+
routes: RouteTreeNodeMetadata[];
|
|
168
|
+
/**
|
|
169
|
+
* Optional configuration for server routes.
|
|
76
170
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* const result: AngularRouterConfigResult = {
|
|
80
|
-
* baseHref: '/app/',
|
|
81
|
-
* routes: [
|
|
82
|
-
* { route: '/home', redirectTo: '/welcome' },
|
|
83
|
-
* { route: '/about' },
|
|
84
|
-
* ],
|
|
85
|
-
* };
|
|
86
|
-
* ```
|
|
171
|
+
* This property allows you to specify an array of server routes for configuration.
|
|
172
|
+
* If not provided, the default configuration or behavior will be used.
|
|
87
173
|
*/
|
|
88
|
-
|
|
174
|
+
serverRoutesConfig?: ServerRoute[] | null;
|
|
175
|
+
/**
|
|
176
|
+
* A list of errors encountered during the route extraction process.
|
|
177
|
+
*/
|
|
178
|
+
errors: string[];
|
|
89
179
|
}
|
|
90
180
|
|
|
91
181
|
/**
|
|
@@ -111,6 +201,22 @@ declare class AngularServerApp {
|
|
|
111
201
|
* The router instance used for route matching and handling.
|
|
112
202
|
*/
|
|
113
203
|
private router;
|
|
204
|
+
/**
|
|
205
|
+
* The `inlineCriticalCssProcessor` is responsible for handling critical CSS inlining.
|
|
206
|
+
*/
|
|
207
|
+
private inlineCriticalCssProcessor;
|
|
208
|
+
/**
|
|
209
|
+
* The bootstrap mechanism for the server application.
|
|
210
|
+
*/
|
|
211
|
+
private boostrap;
|
|
212
|
+
/**
|
|
213
|
+
* Cache for storing critical CSS for pages.
|
|
214
|
+
* Stores a maximum of MAX_INLINE_CSS_CACHE_ENTRIES entries.
|
|
215
|
+
*
|
|
216
|
+
* Uses an LRU (Least Recently Used) eviction policy, meaning that when the cache is full,
|
|
217
|
+
* the least recently accessed page's critical CSS will be removed to make space for new entries.
|
|
218
|
+
*/
|
|
219
|
+
private readonly criticalCssLRUCache;
|
|
114
220
|
/**
|
|
115
221
|
* Renders a response for the given HTTP request using the server application.
|
|
116
222
|
*
|
|
@@ -118,11 +224,20 @@ declare class AngularServerApp {
|
|
|
118
224
|
*
|
|
119
225
|
* @param request - The incoming HTTP request to be rendered.
|
|
120
226
|
* @param requestContext - Optional additional context for rendering, such as request metadata.
|
|
121
|
-
* @param serverContext - The rendering context.
|
|
122
227
|
*
|
|
123
228
|
* @returns A promise that resolves to the HTTP response object resulting from the rendering, or null if no match is found.
|
|
124
229
|
*/
|
|
125
|
-
render(request: Request, requestContext?: unknown
|
|
230
|
+
render(request: Request, requestContext?: unknown): Promise<Response | null>;
|
|
231
|
+
/**
|
|
232
|
+
* Renders a page based on the provided URL via server-side rendering and returns the corresponding HTTP response.
|
|
233
|
+
* The rendering process can be interrupted by an abort signal, where the first resolved promise (either from the abort
|
|
234
|
+
* or the render process) will dictate the outcome.
|
|
235
|
+
*
|
|
236
|
+
* @param url - The full URL to be processed and rendered by the server.
|
|
237
|
+
* @param signal - (Optional) An `AbortSignal` object that allows for the cancellation of the rendering process.
|
|
238
|
+
* @returns A promise that resolves to the generated HTTP response object, or `null` if no matching route is found.
|
|
239
|
+
*/
|
|
240
|
+
renderStatic(url: URL, signal?: AbortSignal): Promise<Response | null>;
|
|
126
241
|
/**
|
|
127
242
|
* Creates a promise that rejects when the request is aborted.
|
|
128
243
|
*
|
|
@@ -135,8 +250,8 @@ declare class AngularServerApp {
|
|
|
135
250
|
* This method matches the request URL to a route and performs rendering if a matching route is found.
|
|
136
251
|
*
|
|
137
252
|
* @param request - The incoming HTTP request to be processed.
|
|
253
|
+
* @param isSsrMode - A boolean indicating whether the rendering is performed in server-side rendering (SSR) mode.
|
|
138
254
|
* @param requestContext - Optional additional context for rendering, such as request metadata.
|
|
139
|
-
* @param serverContext - The rendering context. Defaults to server-side rendering (SSR).
|
|
140
255
|
*
|
|
141
256
|
* @returns A promise that resolves to the rendered response, or null if no matching route is found.
|
|
142
257
|
*/
|
|
@@ -144,53 +259,35 @@ declare class AngularServerApp {
|
|
|
144
259
|
}
|
|
145
260
|
|
|
146
261
|
/**
|
|
147
|
-
*
|
|
262
|
+
* Annotates a request handler function with metadata, marking it as a special
|
|
263
|
+
* handler.
|
|
264
|
+
*
|
|
265
|
+
* @param handler - The request handler function to be annotated.
|
|
266
|
+
* @returns The same handler function passed in, with metadata attached.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* Example usage in a Hono application:
|
|
270
|
+
* ```ts
|
|
271
|
+
* const app = new Hono();
|
|
272
|
+
* export default createRequestHandler(app.fetch);
|
|
273
|
+
* ```
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* Example usage in a H3 application:
|
|
277
|
+
* ```ts
|
|
278
|
+
* const app = createApp();
|
|
279
|
+
* const handler = toWebHandler(app);
|
|
280
|
+
* export default createRequestHandler(handler);
|
|
281
|
+
* ```
|
|
282
|
+
* @developerPreview
|
|
148
283
|
*/
|
|
149
|
-
export declare
|
|
150
|
-
private options?;
|
|
151
|
-
private readonly templateCache;
|
|
152
|
-
private readonly inlineCriticalCssProcessor;
|
|
153
|
-
private readonly pageIsSSG;
|
|
154
|
-
constructor(options?: CommonEngineOptions | undefined);
|
|
155
|
-
/**
|
|
156
|
-
* Render an HTML document for a specific URL with specified
|
|
157
|
-
* render options
|
|
158
|
-
*/
|
|
159
|
-
render(opts: CommonEngineRenderOptions): Promise<string>;
|
|
160
|
-
private inlineCriticalCss;
|
|
161
|
-
private retrieveSSGPage;
|
|
162
|
-
private renderApplication;
|
|
163
|
-
/** Retrieve the document from the cache or the filesystem */
|
|
164
|
-
private getDocument;
|
|
165
|
-
}
|
|
284
|
+
export declare function createRequestHandler(handler: RequestHandlerFunction): RequestHandlerFunction;
|
|
166
285
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
bootstrap?: Type<{}> | (() => Promise<ApplicationRef>);
|
|
170
|
-
/** A set of platform level providers for all requests. */
|
|
171
|
-
providers?: StaticProvider[];
|
|
172
|
-
/** Enable request performance profiling data collection and printing the results in the server console. */
|
|
173
|
-
enablePerformanceProfiler?: boolean;
|
|
286
|
+
declare interface CrittersBase {
|
|
287
|
+
embedLinkedStylesheet(link: PartialHTMLElement, document: PartialDocument): Promise<unknown>;
|
|
174
288
|
}
|
|
175
289
|
|
|
176
|
-
|
|
177
|
-
/** A method that when invoked returns a promise that returns an `ApplicationRef` instance once resolved or an NgModule. */
|
|
178
|
-
bootstrap?: Type<{}> | (() => Promise<ApplicationRef>);
|
|
179
|
-
/** A set of platform level providers for the current request. */
|
|
180
|
-
providers?: StaticProvider[];
|
|
181
|
-
url?: string;
|
|
182
|
-
document?: string;
|
|
183
|
-
documentFilePath?: string;
|
|
184
|
-
/**
|
|
185
|
-
* Reduce render blocking requests by inlining critical CSS.
|
|
186
|
-
* Defaults to true.
|
|
187
|
-
*/
|
|
188
|
-
inlineCriticalCss?: boolean;
|
|
189
|
-
/**
|
|
190
|
-
* Base path location of index file.
|
|
191
|
-
* Defaults to the 'documentFilePath' dirname when not provided.
|
|
192
|
-
*/
|
|
193
|
-
publicPath?: string;
|
|
290
|
+
declare class CrittersBase extends default_2 {
|
|
194
291
|
}
|
|
195
292
|
|
|
196
293
|
/**
|
|
@@ -199,12 +296,14 @@ export declare interface CommonEngineRenderOptions {
|
|
|
199
296
|
declare interface EntryPointExports {
|
|
200
297
|
/**
|
|
201
298
|
* A reference to the function that creates an Angular server application instance.
|
|
299
|
+
*
|
|
300
|
+
* @note The return type is `unknown` to prevent circular dependency issues.
|
|
202
301
|
*/
|
|
203
|
-
ɵgetOrCreateAngularServerApp:
|
|
302
|
+
ɵgetOrCreateAngularServerApp: () => unknown;
|
|
204
303
|
/**
|
|
205
304
|
* A reference to the function that destroys the `AngularServerApp` instance.
|
|
206
305
|
*/
|
|
207
|
-
ɵdestroyAngularServerApp:
|
|
306
|
+
ɵdestroyAngularServerApp: () => void;
|
|
208
307
|
}
|
|
209
308
|
|
|
210
309
|
/**
|
|
@@ -261,34 +360,247 @@ declare interface HooksMapping {
|
|
|
261
360
|
|
|
262
361
|
|
|
263
362
|
/**
|
|
264
|
-
*
|
|
265
|
-
*
|
|
363
|
+
* Defines a handler function type for transforming HTML content.
|
|
364
|
+
* This function receives an object with the HTML to be processed.
|
|
266
365
|
*
|
|
267
|
-
* @param ctx -
|
|
268
|
-
* @returns The
|
|
366
|
+
* @param ctx - An object containing the URL and HTML content to be transformed.
|
|
367
|
+
* @returns The transformed HTML as a string or a promise that resolves to the transformed HTML.
|
|
269
368
|
*/
|
|
270
369
|
declare type HtmlTransformHandler = (ctx: {
|
|
370
|
+
url: URL;
|
|
271
371
|
html: string;
|
|
272
372
|
}) => string | Promise<string>;
|
|
273
373
|
|
|
374
|
+
/** Partial representation of an HTML `Document`. */
|
|
375
|
+
declare interface PartialDocument {
|
|
376
|
+
head: PartialHTMLElement;
|
|
377
|
+
createElement(tagName: string): PartialHTMLElement;
|
|
378
|
+
querySelector(selector: string): PartialHTMLElement | null;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/** Partial representation of an `HTMLElement`. */
|
|
382
|
+
declare interface PartialHTMLElement {
|
|
383
|
+
getAttribute(name: string): string | null;
|
|
384
|
+
setAttribute(name: string, value: string): void;
|
|
385
|
+
hasAttribute(name: string): boolean;
|
|
386
|
+
removeAttribute(name: string): void;
|
|
387
|
+
appendChild(child: PartialHTMLElement): void;
|
|
388
|
+
insertBefore(newNode: PartialHTMLElement, referenceNode?: PartialHTMLElement): void;
|
|
389
|
+
remove(): void;
|
|
390
|
+
name: string;
|
|
391
|
+
textContent: string;
|
|
392
|
+
tagName: string | null;
|
|
393
|
+
children: PartialHTMLElement[];
|
|
394
|
+
next: PartialHTMLElement | null;
|
|
395
|
+
prev: PartialHTMLElement | null;
|
|
396
|
+
}
|
|
397
|
+
|
|
274
398
|
/**
|
|
275
|
-
*
|
|
399
|
+
* Defines the fallback strategies for Static Site Generation (SSG) routes when a pre-rendered path is not available.
|
|
400
|
+
* This is particularly relevant for routes with parameterized URLs where some paths might not be pre-rendered at build time.
|
|
401
|
+
*
|
|
402
|
+
* @developerPreview
|
|
403
|
+
*/
|
|
404
|
+
export declare enum PrerenderFallback {
|
|
405
|
+
/**
|
|
406
|
+
* Fallback to Server-Side Rendering (SSR) if the pre-rendered path is not available.
|
|
407
|
+
* This strategy dynamically generates the page on the server at request time.
|
|
408
|
+
*/
|
|
409
|
+
Server = 0,
|
|
410
|
+
/**
|
|
411
|
+
* Fallback to Client-Side Rendering (CSR) if the pre-rendered path is not available.
|
|
412
|
+
* This strategy allows the page to be rendered on the client side.
|
|
413
|
+
*/
|
|
414
|
+
Client = 1,
|
|
415
|
+
/**
|
|
416
|
+
* No fallback; if the path is not pre-rendered, the server will not handle the request.
|
|
417
|
+
* This means the application will not provide any response for paths that are not pre-rendered.
|
|
418
|
+
*/
|
|
419
|
+
None = 2
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Configures the necessary providers for server routes configuration.
|
|
424
|
+
*
|
|
425
|
+
* @param routes - An array of server routes to be provided.
|
|
426
|
+
* @returns An `EnvironmentProviders` object that contains the server routes configuration.
|
|
427
|
+
* @developerPreview
|
|
276
428
|
*/
|
|
277
|
-
declare
|
|
429
|
+
export declare function provideServerRoutesConfig(routes: ServerRoute[]): EnvironmentProviders;
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Different rendering modes for server routes.
|
|
433
|
+
* @developerPreview
|
|
434
|
+
*/
|
|
435
|
+
export declare enum RenderMode {
|
|
436
|
+
/** AppShell rendering mode, typically used for pre-rendered shells of the application. */
|
|
437
|
+
AppShell = 0,
|
|
438
|
+
/** Server-Side Rendering (SSR) mode, where content is rendered on the server for each request. */
|
|
439
|
+
Server = 1,
|
|
440
|
+
/** Client-Side Rendering (CSR) mode, where content is rendered on the client side in the browser. */
|
|
441
|
+
Client = 2,
|
|
442
|
+
/** Static Site Generation (SSG) mode, where content is pre-rendered at build time and served as static files. */
|
|
443
|
+
Prerender = 3
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Injection token for the current request.
|
|
448
|
+
* @developerPreview
|
|
449
|
+
*/
|
|
450
|
+
export declare const REQUEST: InjectionToken<Request>;
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Injection token for additional request context.
|
|
454
|
+
* @developerPreview
|
|
455
|
+
*/
|
|
456
|
+
export declare const REQUEST_CONTEXT: InjectionToken<unknown>;
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Function for handling HTTP requests in a web environment.
|
|
461
|
+
*
|
|
462
|
+
* @param request - The incoming HTTP request object.
|
|
463
|
+
* @returns A Promise resolving to a `Response` object, `null`, or directly a `Response`,
|
|
464
|
+
* supporting both synchronous and asynchronous handling.
|
|
465
|
+
*/
|
|
466
|
+
declare type RequestHandlerFunction = (request: Request) => Promise<Response | null> | null | Response;
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Injection token for the response initialization options.
|
|
470
|
+
* @developerPreview
|
|
471
|
+
*/
|
|
472
|
+
export declare const RESPONSE_INIT: InjectionToken<ResponseInit>;
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* A route tree implementation that supports efficient route matching, including support for wildcard routes.
|
|
476
|
+
* This structure is useful for organizing and retrieving routes in a hierarchical manner,
|
|
477
|
+
* enabling complex routing scenarios with nested paths.
|
|
478
|
+
*
|
|
479
|
+
* @typeParam AdditionalMetadata - Type of additional metadata that can be associated with route nodes.
|
|
480
|
+
*/
|
|
481
|
+
declare class RouteTree<AdditionalMetadata extends Record<string, unknown> = {}> {
|
|
482
|
+
/**
|
|
483
|
+
* The root node of the route tree.
|
|
484
|
+
* All routes are stored and accessed relative to this root node.
|
|
485
|
+
*/
|
|
486
|
+
private readonly root;
|
|
487
|
+
/**
|
|
488
|
+
* A counter that tracks the order of route insertion.
|
|
489
|
+
* This ensures that routes are matched in the order they were defined,
|
|
490
|
+
* with earlier routes taking precedence.
|
|
491
|
+
*/
|
|
492
|
+
private insertionIndexCounter;
|
|
278
493
|
/**
|
|
279
|
-
*
|
|
494
|
+
* Inserts a new route into the route tree.
|
|
495
|
+
* The route is broken down into segments, and each segment is added to the tree.
|
|
496
|
+
* Parameterized segments (e.g., :id) are normalized to wildcards (*) for matching purposes.
|
|
280
497
|
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
498
|
+
* @param route - The route path to insert into the tree.
|
|
499
|
+
* @param metadata - Metadata associated with the route, excluding the route path itself.
|
|
283
500
|
*/
|
|
284
|
-
route: string;
|
|
501
|
+
insert(route: string, metadata: RouteTreeNodeMetadataWithoutRoute & AdditionalMetadata): void;
|
|
285
502
|
/**
|
|
286
|
-
*
|
|
503
|
+
* Matches a given route against the route tree and returns the best matching route's metadata.
|
|
504
|
+
* The best match is determined by the lowest insertion index, meaning the earliest defined route
|
|
505
|
+
* takes precedence.
|
|
287
506
|
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
507
|
+
* @param route - The route path to match against the route tree.
|
|
508
|
+
* @returns The metadata of the best matching route or `undefined` if no match is found.
|
|
290
509
|
*/
|
|
291
|
-
|
|
510
|
+
match(route: string): (RouteTreeNodeMetadata & AdditionalMetadata) | undefined;
|
|
511
|
+
/**
|
|
512
|
+
* Converts the route tree into a serialized format representation.
|
|
513
|
+
* This method converts the route tree into an array of metadata objects that describe the structure of the tree.
|
|
514
|
+
* The array represents the routes in a nested manner where each entry includes the route and its associated metadata.
|
|
515
|
+
*
|
|
516
|
+
* @returns An array of `RouteTreeNodeMetadata` objects representing the route tree structure.
|
|
517
|
+
* Each object includes the `route` and associated metadata of a route.
|
|
518
|
+
*/
|
|
519
|
+
toObject(): SerializableRouteTreeNode;
|
|
520
|
+
/**
|
|
521
|
+
* Constructs a `RouteTree` from an object representation.
|
|
522
|
+
* This method is used to recreate a `RouteTree` instance from an array of metadata objects.
|
|
523
|
+
* The array should be in the format produced by `toObject`, allowing for the reconstruction of the route tree
|
|
524
|
+
* with the same routes and metadata.
|
|
525
|
+
*
|
|
526
|
+
* @param value - An array of `RouteTreeNodeMetadata` objects that represent the serialized format of the route tree.
|
|
527
|
+
* Each object should include a `route` and its associated metadata.
|
|
528
|
+
* @returns A new `RouteTree` instance constructed from the provided metadata objects.
|
|
529
|
+
*/
|
|
530
|
+
static fromObject(value: SerializableRouteTreeNode): RouteTree;
|
|
531
|
+
/**
|
|
532
|
+
* A generator function that recursively traverses the route tree and yields the metadata of each node.
|
|
533
|
+
* This allows for easy and efficient iteration over all nodes in the tree.
|
|
534
|
+
*
|
|
535
|
+
* @param node - The current node to start the traversal from. Defaults to the root node of the tree.
|
|
536
|
+
*/
|
|
537
|
+
traverse(node?: RouteTreeNode<AdditionalMetadata>): Generator<RouteTreeNodeMetadata & AdditionalMetadata>;
|
|
538
|
+
/**
|
|
539
|
+
* Extracts the path segments from a given route string.
|
|
540
|
+
*
|
|
541
|
+
* @param route - The route string from which to extract segments.
|
|
542
|
+
* @returns An array of path segments.
|
|
543
|
+
*/
|
|
544
|
+
private getPathSegments;
|
|
545
|
+
/**
|
|
546
|
+
* Recursively traverses the route tree from a given node, attempting to match the remaining route segments.
|
|
547
|
+
* If the node is a leaf node (no more segments to match) and contains metadata, the node is yielded.
|
|
548
|
+
*
|
|
549
|
+
* This function prioritizes exact segment matches first, followed by wildcard matches (`*`),
|
|
550
|
+
* and finally deep wildcard matches (`**`) that consume all segments.
|
|
551
|
+
*
|
|
552
|
+
* @param remainingSegments - The remaining segments of the route path to match.
|
|
553
|
+
* @param node - The current node in the route tree to start traversal from.
|
|
554
|
+
*
|
|
555
|
+
* @returns The node that best matches the remaining segments or `undefined` if no match is found.
|
|
556
|
+
*/
|
|
557
|
+
private traverseBySegments;
|
|
558
|
+
/**
|
|
559
|
+
* Compares two nodes and returns the node with higher priority based on insertion index.
|
|
560
|
+
* A node with a lower insertion index is prioritized as it was defined earlier.
|
|
561
|
+
*
|
|
562
|
+
* @param currentBestMatchNode - The current best match node.
|
|
563
|
+
* @param candidateNode - The node being evaluated for higher priority based on insertion index.
|
|
564
|
+
* @returns The node with higher priority (i.e., lower insertion index). If one of the nodes is `undefined`, the other node is returned.
|
|
565
|
+
*/
|
|
566
|
+
private getHigherPriorityNode;
|
|
567
|
+
/**
|
|
568
|
+
* Creates an empty route tree node with the specified segment.
|
|
569
|
+
* This helper function is used during the tree construction.
|
|
570
|
+
*
|
|
571
|
+
* @param segment - The route segment that this node represents.
|
|
572
|
+
* @returns A new, empty route tree node.
|
|
573
|
+
*/
|
|
574
|
+
private createEmptyRouteTreeNode;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Represents a node within the route tree structure.
|
|
579
|
+
* Each node corresponds to a route segment and may have associated metadata and child nodes.
|
|
580
|
+
* The `AdditionalMetadata` type parameter allows for extending the node metadata with custom data.
|
|
581
|
+
*/
|
|
582
|
+
declare interface RouteTreeNode<AdditionalMetadata extends Record<string, unknown>> {
|
|
583
|
+
/**
|
|
584
|
+
* The segment value associated with this node.
|
|
585
|
+
* A segment is a single part of a route path, typically delimited by slashes (`/`).
|
|
586
|
+
* For example, in the route `/users/:id/profile`, the segments are `users`, `:id`, and `profile`.
|
|
587
|
+
* Segments can also be wildcards (`*`), which match any segment in that position of the route.
|
|
588
|
+
*/
|
|
589
|
+
segment: string;
|
|
590
|
+
/**
|
|
591
|
+
* The index indicating the order in which the route was inserted into the tree.
|
|
592
|
+
* This index helps determine the priority of routes during matching, with lower indexes
|
|
593
|
+
* indicating earlier inserted routes.
|
|
594
|
+
*/
|
|
595
|
+
insertionIndex: number;
|
|
596
|
+
/**
|
|
597
|
+
* A map of child nodes, keyed by their corresponding route segment or wildcard.
|
|
598
|
+
*/
|
|
599
|
+
children: Map<string, RouteTreeNode<AdditionalMetadata>>;
|
|
600
|
+
/**
|
|
601
|
+
* Optional metadata associated with this node, providing additional information such as redirects.
|
|
602
|
+
*/
|
|
603
|
+
metadata?: RouteTreeNodeMetadata & AdditionalMetadata;
|
|
292
604
|
}
|
|
293
605
|
|
|
294
606
|
/**
|
|
@@ -320,8 +632,25 @@ declare interface RouteTreeNodeMetadata {
|
|
|
320
632
|
* structure and content of the application.
|
|
321
633
|
*/
|
|
322
634
|
route: string;
|
|
635
|
+
/**
|
|
636
|
+
* Optional status code to return for this route.
|
|
637
|
+
*/
|
|
638
|
+
status?: number;
|
|
639
|
+
/**
|
|
640
|
+
* Optional additional headers to include in the response for this route.
|
|
641
|
+
*/
|
|
642
|
+
headers?: Record<string, string>;
|
|
643
|
+
/**
|
|
644
|
+
* Specifies the rendering mode used for this route.
|
|
645
|
+
* If not provided, the default rendering mode for the application will be used.
|
|
646
|
+
*/
|
|
647
|
+
renderMode?: RenderMode;
|
|
323
648
|
}
|
|
324
649
|
|
|
650
|
+
/**
|
|
651
|
+
* Represents metadata for a route tree node, excluding the 'route' path segment.
|
|
652
|
+
*/
|
|
653
|
+
declare type RouteTreeNodeMetadataWithoutRoute = Omit<RouteTreeNodeMetadata, 'route'>;
|
|
325
654
|
|
|
326
655
|
/**
|
|
327
656
|
* Represents the serialized format of a route tree as an array of node metadata objects.
|
|
@@ -329,6 +658,100 @@ declare interface RouteTreeNodeMetadata {
|
|
|
329
658
|
*/
|
|
330
659
|
declare type SerializableRouteTreeNode = ReadonlyArray<RouteTreeNodeMetadata>;
|
|
331
660
|
|
|
661
|
+
/**
|
|
662
|
+
* Server route configuration.
|
|
663
|
+
* @developerPreview
|
|
664
|
+
*/
|
|
665
|
+
export declare type ServerRoute = ServerRouteAppShell | ServerRouteClient | ServerRoutePrerender | ServerRoutePrerenderWithParams | ServerRouteServer;
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* A server route that uses AppShell rendering mode.
|
|
669
|
+
*/
|
|
670
|
+
declare interface ServerRouteAppShell extends Omit<ServerRouteCommon, 'headers' | 'status'> {
|
|
671
|
+
/** Specifies that the route uses AppShell rendering mode. */
|
|
672
|
+
renderMode: RenderMode.AppShell;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* A server route that uses Client-Side Rendering (CSR) mode.
|
|
677
|
+
*/
|
|
678
|
+
declare interface ServerRouteClient extends ServerRouteCommon {
|
|
679
|
+
/** Specifies that the route uses Client-Side Rendering (CSR) mode. */
|
|
680
|
+
renderMode: RenderMode.Client;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* Common interface for server routes, providing shared properties.
|
|
685
|
+
*/
|
|
686
|
+
declare interface ServerRouteCommon {
|
|
687
|
+
/** The path associated with this route. */
|
|
688
|
+
path: string;
|
|
689
|
+
/** Optional additional headers to include in the response for this route. */
|
|
690
|
+
headers?: Record<string, string>;
|
|
691
|
+
/** Optional status code to return for this route. */
|
|
692
|
+
status?: number;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* A server route that uses Static Site Generation (SSG) mode.
|
|
697
|
+
*/
|
|
698
|
+
declare interface ServerRoutePrerender extends Omit<ServerRouteCommon, 'status'> {
|
|
699
|
+
/** Specifies that the route uses Static Site Generation (SSG) mode. */
|
|
700
|
+
renderMode: RenderMode.Prerender;
|
|
701
|
+
/** Fallback cannot be specified unless `getPrerenderParams` is used. */
|
|
702
|
+
fallback?: never;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* A server route configuration that uses Static Site Generation (SSG) mode, including support for routes with parameters.
|
|
707
|
+
*/
|
|
708
|
+
declare interface ServerRoutePrerenderWithParams extends Omit<ServerRoutePrerender, 'fallback'> {
|
|
709
|
+
/**
|
|
710
|
+
* Optional strategy to use if the SSG path is not pre-rendered.
|
|
711
|
+
* This is especially relevant for routes with parameterized URLs, where some paths may not be pre-rendered at build time.
|
|
712
|
+
*
|
|
713
|
+
* This property determines how to handle requests for paths that are not pre-rendered:
|
|
714
|
+
* - `PrerenderFallback.Server`: Use Server-Side Rendering (SSR) to dynamically generate the page at request time.
|
|
715
|
+
* - `PrerenderFallback.Client`: Use Client-Side Rendering (CSR) to fetch and render the page on the client side.
|
|
716
|
+
* - `PrerenderFallback.None`: No fallback; if the path is not pre-rendered, the server will not handle the request.
|
|
717
|
+
*
|
|
718
|
+
* @default `PrerenderFallback.Server` if not provided.
|
|
719
|
+
*/
|
|
720
|
+
fallback?: PrerenderFallback;
|
|
721
|
+
/**
|
|
722
|
+
* A function that returns a Promise resolving to an array of objects, each representing a route path with URL parameters.
|
|
723
|
+
* This function runs in the injector context, allowing access to Angular services and dependencies.
|
|
724
|
+
*
|
|
725
|
+
* @returns A Promise resolving to an array where each element is an object with string keys (representing URL parameter names)
|
|
726
|
+
* and string values (representing the corresponding values for those parameters in the route path).
|
|
727
|
+
*
|
|
728
|
+
* @example
|
|
729
|
+
* ```typescript
|
|
730
|
+
* export const serverRouteConfig: ServerRoutes[] = [
|
|
731
|
+
* {
|
|
732
|
+
* path: '/product/:id',
|
|
733
|
+
* renderMode: RenderMode.Prerender,
|
|
734
|
+
* async getPrerenderParams() {
|
|
735
|
+
* const productService = inject(ProductService);
|
|
736
|
+
* const ids = await productService.getIds(); // Assuming this returns ['1', '2', '3']
|
|
737
|
+
*
|
|
738
|
+
* return ids.map(id => ({ id })); // Generates paths like: [{ id: '1' }, { id: '2' }, { id: '3' }]
|
|
739
|
+
* },
|
|
740
|
+
* },
|
|
741
|
+
* ];
|
|
742
|
+
* ```
|
|
743
|
+
*/
|
|
744
|
+
getPrerenderParams: () => Promise<Record<string, string>[]>;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* A server route that uses Server-Side Rendering (SSR) mode.
|
|
749
|
+
*/
|
|
750
|
+
declare interface ServerRouteServer extends ServerRouteCommon {
|
|
751
|
+
/** Specifies that the route uses Server-Side Rendering (SSR) mode. */
|
|
752
|
+
renderMode: RenderMode.Server;
|
|
753
|
+
}
|
|
754
|
+
|
|
332
755
|
/**
|
|
333
756
|
* Destroys the existing `AngularServerApp` instance, releasing associated resources and resetting the
|
|
334
757
|
* reference to `undefined`.
|
|
@@ -338,6 +761,30 @@ declare type SerializableRouteTreeNode = ReadonlyArray<RouteTreeNodeMetadata>;
|
|
|
338
761
|
*/
|
|
339
762
|
export declare function ɵdestroyAngularServerApp(): void;
|
|
340
763
|
|
|
764
|
+
/**
|
|
765
|
+
* Asynchronously extracts routes from the Angular application configuration
|
|
766
|
+
* and creates a `RouteTree` to manage server-side routing.
|
|
767
|
+
*
|
|
768
|
+
* @param url - The URL for server-side rendering. The URL is used to configure `ServerPlatformLocation`. This configuration is crucial
|
|
769
|
+
* for ensuring that API requests for relative paths succeed, which is essential for accurate route extraction.
|
|
770
|
+
* See:
|
|
771
|
+
* - https://github.com/angular/angular/blob/d608b857c689d17a7ffa33bbb510301014d24a17/packages/platform-server/src/location.ts#L51
|
|
772
|
+
* - https://github.com/angular/angular/blob/6882cc7d9eed26d3caeedca027452367ba25f2b9/packages/platform-server/src/http.ts#L44
|
|
773
|
+
* @param manifest - An optional `AngularAppManifest` that contains the application's routing and configuration details.
|
|
774
|
+
* If not provided, the default manifest is retrieved using `getAngularAppManifest()`.
|
|
775
|
+
* @param invokeGetPrerenderParams - A boolean flag indicating whether to invoke `getPrerenderParams` for parameterized SSG routes
|
|
776
|
+
* to handle prerendering paths. Defaults to `false`.
|
|
777
|
+
* @param includePrerenderFallbackRoutes - A flag indicating whether to include fallback routes in the result. Defaults to `true`.
|
|
778
|
+
*
|
|
779
|
+
* @returns A promise that resolves to an object containing:
|
|
780
|
+
* - `routeTree`: A populated `RouteTree` containing all extracted routes from the Angular application.
|
|
781
|
+
* - `errors`: An array of strings representing any errors encountered during the route extraction process.
|
|
782
|
+
*/
|
|
783
|
+
export declare function ɵextractRoutesAndCreateRouteTree(url: URL, manifest?: AngularAppManifest, invokeGetPrerenderParams?: boolean, includePrerenderFallbackRoutes?: boolean): Promise<{
|
|
784
|
+
routeTree: RouteTree;
|
|
785
|
+
errors: string[];
|
|
786
|
+
}>;
|
|
787
|
+
|
|
341
788
|
/**
|
|
342
789
|
* Retrieves or creates an instance of `AngularServerApp`.
|
|
343
790
|
* - If an instance of `AngularServerApp` already exists, it will return the existing one.
|
|
@@ -351,27 +798,41 @@ export declare function ɵgetOrCreateAngularServerApp(): AngularServerApp;
|
|
|
351
798
|
*
|
|
352
799
|
* This function initializes an Angular platform, bootstraps the application or module,
|
|
353
800
|
* and retrieves routes from the Angular router configuration. It handles both module-based
|
|
354
|
-
* and function-based bootstrapping. It yields the resulting routes as `
|
|
801
|
+
* and function-based bootstrapping. It yields the resulting routes as `RouteTreeNodeMetadata` objects or errors.
|
|
355
802
|
*
|
|
356
803
|
* @param bootstrap - A function that returns a promise resolving to an `ApplicationRef` or an Angular module to bootstrap.
|
|
357
804
|
* @param document - The initial HTML document used for server-side rendering.
|
|
358
805
|
* This document is necessary to render the application on the server.
|
|
359
806
|
* @param url - The URL for server-side rendering. The URL is used to configure `ServerPlatformLocation`. This configuration is crucial
|
|
360
807
|
* for ensuring that API requests for relative paths succeed, which is essential for accurate route extraction.
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
808
|
+
* @param invokeGetPrerenderParams - A boolean flag indicating whether to invoke `getPrerenderParams` for parameterized SSG routes
|
|
809
|
+
* to handle prerendering paths. Defaults to `false`.
|
|
810
|
+
* @param includePrerenderFallbackRoutes - A flag indicating whether to include fallback routes in the result. Defaults to `true`.
|
|
811
|
+
*
|
|
812
|
+
* @returns A promise that resolves to an object of type `AngularRouterConfigResult` or errors.
|
|
365
813
|
*/
|
|
366
|
-
export declare function ɵgetRoutesFromAngularRouterConfig(bootstrap: AngularBootstrap, document: string, url: URL): Promise<AngularRouterConfigResult>;
|
|
814
|
+
export declare function ɵgetRoutesFromAngularRouterConfig(bootstrap: AngularBootstrap, document: string, url: URL, invokeGetPrerenderParams?: boolean, includePrerenderFallbackRoutes?: boolean): Promise<AngularRouterConfigResult>;
|
|
367
815
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
816
|
+
export declare class ɵInlineCriticalCssProcessor extends CrittersBase {
|
|
817
|
+
readFile: (path: string) => Promise<string>;
|
|
818
|
+
readonly outputPath?: string | undefined;
|
|
819
|
+
private addedCspScriptsDocuments;
|
|
820
|
+
private documentNonces;
|
|
821
|
+
constructor(readFile: (path: string) => Promise<string>, outputPath?: string | undefined);
|
|
822
|
+
/**
|
|
823
|
+
* Override of the Critters `embedLinkedStylesheet` method
|
|
824
|
+
* that makes it work with Angular's CSP APIs.
|
|
825
|
+
*/
|
|
826
|
+
embedLinkedStylesheet(link: PartialHTMLElement, document: PartialDocument): Promise<unknown>;
|
|
827
|
+
/**
|
|
828
|
+
* Finds the CSP nonce for a specific document.
|
|
829
|
+
*/
|
|
830
|
+
private findCspNonce;
|
|
831
|
+
/**
|
|
832
|
+
* Inserts the `script` tag that swaps the critical CSS at runtime,
|
|
833
|
+
* if one hasn't been inserted into the document already.
|
|
834
|
+
*/
|
|
835
|
+
private conditionallyInsertCspLoadingScript;
|
|
375
836
|
}
|
|
376
837
|
|
|
377
838
|
/**
|