@angular/ssr 19.0.0-next.0 → 19.0.0-next.10

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/index.d.ts CHANGED
@@ -1,6 +1,143 @@
1
- import { ApplicationRef } from '@angular/core';
2
- import { StaticProvider } from '@angular/core';
3
- import { Type } from '@angular/core';
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
+ }
79
+
80
+ /**
81
+ * Manifest for the Angular server application engine, defining entry points.
82
+ */
83
+ declare interface AngularAppEngineManifest {
84
+ /**
85
+ * A map of entry points for the server application.
86
+ * Each entry in the map consists of:
87
+ * - `key`: The base href for the entry point.
88
+ * - `value`: A function that returns a promise resolving to an object of type `EntryPointExports`.
89
+ */
90
+ readonly entryPoints: ReadonlyMap<string, () => Promise<EntryPointExports>>;
91
+ /**
92
+ * The base path for the server application.
93
+ * This is used to determine the root path of the application.
94
+ */
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][]>;
105
+ }
106
+
107
+ /**
108
+ * Manifest for a specific Angular server application, defining assets and bootstrap logic.
109
+ */
110
+ declare interface AngularAppManifest {
111
+ /**
112
+ * A map of assets required by the server application.
113
+ * Each entry in the map consists of:
114
+ * - `key`: The path of the asset.
115
+ * - `value`: A function returning a promise that resolves to the file contents of the asset.
116
+ */
117
+ readonly assets: ReadonlyMap<string, () => Promise<string>>;
118
+ /**
119
+ * The bootstrap mechanism for the server application.
120
+ * A function that returns a promise that resolves to an `NgModule` or a function
121
+ * returning a promise that resolves to an `ApplicationRef`.
122
+ */
123
+ readonly bootstrap: () => Promise<AngularBootstrap>;
124
+ /**
125
+ * Indicates whether critical CSS should be inlined into the HTML.
126
+ * If set to `true`, critical CSS will be inlined for faster page rendering.
127
+ */
128
+ readonly inlineCriticalCss?: boolean;
129
+ /**
130
+ * The route tree representation for the routing configuration of the application.
131
+ * This represents the routing information of the application, mapping route paths to their corresponding metadata.
132
+ * It is used for route matching and navigation within the server application.
133
+ */
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;
140
+ }
4
141
 
5
142
  /**
6
143
  * Represents the bootstrap mechanism for an Angular application.
@@ -21,113 +158,695 @@ declare interface AngularRouterConfigResult {
21
158
  */
22
159
  baseHref: string;
23
160
  /**
24
- * An array of `RouteResult` objects representing the application's routes.
161
+ * An array of `RouteTreeNodeMetadata` objects representing the application's routes.
25
162
  *
26
- * Each `RouteResult` contains details about a specific route, such as its path and any
163
+ * Each `RouteTreeNodeMetadata` contains details about a specific route, such as its path and any
27
164
  * associated redirection targets. This array is asynchronously generated and
28
165
  * provides information on how routes are structured and resolved.
166
+ */
167
+ routes: RouteTreeNodeMetadata[];
168
+ /**
169
+ * Optional configuration for server routes.
170
+ *
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.
173
+ */
174
+ serverRoutesConfig?: ServerRoute[] | null;
175
+ /**
176
+ * A list of errors encountered during the route extraction process.
177
+ */
178
+ errors: string[];
179
+ }
180
+
181
+ /**
182
+ * Represents a locale-specific Angular server application managed by the server application engine.
183
+ *
184
+ * The `AngularServerApp` class handles server-side rendering and asset management for a specific locale.
185
+ */
186
+ declare class AngularServerApp {
187
+ /**
188
+ * Hooks for extending or modifying the behavior of the server application.
189
+ * This instance can be used to attach custom functionality to various events in the server application lifecycle.
190
+ */
191
+ hooks: Hooks;
192
+ /**
193
+ * The manifest associated with this server application.
194
+ */
195
+ private readonly manifest;
196
+ /**
197
+ * An instance of ServerAsset that handles server-side asset.
198
+ */
199
+ private readonly assets;
200
+ /**
201
+ * The router instance used for route matching and handling.
202
+ */
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;
220
+ /**
221
+ * Renders a response for the given HTTP request using the server application.
222
+ *
223
+ * This method processes the request and returns a response based on the specified rendering context.
224
+ *
225
+ * @param request - The incoming HTTP request to be rendered.
226
+ * @param requestContext - Optional additional context for rendering, such as request metadata.
227
+ *
228
+ * @returns A promise that resolves to the HTTP response object resulting from the rendering, or null if no match is found.
229
+ */
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>;
241
+ /**
242
+ * Creates a promise that rejects when the request is aborted.
243
+ *
244
+ * @param request - The HTTP request to monitor for abortion.
245
+ * @returns A promise that never resolves but rejects with an `AbortError` if the request is aborted.
246
+ */
247
+ private createAbortPromise;
248
+ /**
249
+ * Handles the server-side rendering process for the given HTTP request.
250
+ * This method matches the request URL to a route and performs rendering if a matching route is found.
251
+ *
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.
254
+ * @param requestContext - Optional additional context for rendering, such as request metadata.
255
+ *
256
+ * @returns A promise that resolves to the rendered response, or null if no matching route is found.
257
+ */
258
+ private handleRendering;
259
+ }
260
+
261
+ /**
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
283
+ */
284
+ export declare function createRequestHandler(handler: RequestHandlerFunction): RequestHandlerFunction;
285
+
286
+ declare interface CrittersBase {
287
+ embedLinkedStylesheet(link: PartialHTMLElement, document: PartialDocument): Promise<unknown>;
288
+ }
289
+
290
+ declare class CrittersBase extends default_2 {
291
+ }
292
+
293
+ /**
294
+ * Represents the exports of an Angular server application entry point.
295
+ */
296
+ declare interface EntryPointExports {
297
+ /**
298
+ * A reference to the function that creates an Angular server application instance.
29
299
  *
30
- * Example:
300
+ * @note The return type is `unknown` to prevent circular dependency issues.
301
+ */
302
+ ɵgetOrCreateAngularServerApp: () => unknown;
303
+ /**
304
+ * A reference to the function that destroys the `AngularServerApp` instance.
305
+ */
306
+ ɵdestroyAngularServerApp: () => void;
307
+ }
308
+
309
+ /**
310
+ * Defines the names of available hooks for registering and triggering custom logic within the application.
311
+ */
312
+ declare type HookName = keyof HooksMapping;
313
+
314
+ /**
315
+ * Manages a collection of hooks and provides methods to register and execute them.
316
+ * Hooks are functions that can be invoked with specific arguments to allow modifications or enhancements.
317
+ */
318
+ declare class Hooks {
319
+ /**
320
+ * A map of hook names to arrays of hook functions.
321
+ * Each hook name can have multiple associated functions, which are executed in sequence.
322
+ */
323
+ private readonly store;
324
+ /**
325
+ * Registers a new hook function under the specified hook name.
326
+ * This function should be a function that takes an argument of type `T` and returns a `string` or `Promise<string>`.
327
+ *
328
+ * @template Hook - The type of the hook name. It should be one of the keys of `HooksMapping`.
329
+ * @param name - The name of the hook under which the function will be registered.
330
+ * @param handler - A function to be executed when the hook is triggered. The handler will be called with an argument
331
+ * that may be modified by the hook functions.
332
+ *
333
+ * @remarks
334
+ * - If there are existing handlers registered under the given hook name, the new handler will be added to the list.
335
+ * - If no handlers are registered under the given hook name, a new list will be created with the handler as its first element.
336
+ *
337
+ * @example
31
338
  * ```typescript
32
- * const result: AngularRouterConfigResult = {
33
- * baseHref: '/app/',
34
- * routes: [
35
- * { route: '/home', redirectTo: '/welcome' },
36
- * { route: '/about' },
37
- * ],
38
- * };
339
+ * hooks.on('html:transform:pre', async (ctx) => {
340
+ * return ctx.html.replace(/foo/g, 'bar');
341
+ * });
39
342
  * ```
40
343
  */
41
- routes: RouteResult[];
344
+ on<Hook extends HookName>(name: Hook, handler: HooksMapping[Hook]): void;
345
+ /**
346
+ * Checks if there are any hooks registered under the specified name.
347
+ *
348
+ * @param name - The name of the hook to check.
349
+ * @returns `true` if there are hooks registered under the specified name, otherwise `false`.
350
+ */
351
+ has(name: HookName): boolean;
42
352
  }
43
353
 
44
354
  /**
45
- * A common engine to use to server render an application.
355
+ * Mapping of hook names to their corresponding handler types.
46
356
  */
47
- export declare class CommonEngine {
48
- private options?;
49
- private readonly templateCache;
50
- private readonly inlineCriticalCssProcessor;
51
- private readonly pageIsSSG;
52
- constructor(options?: CommonEngineOptions | undefined);
357
+ declare interface HooksMapping {
358
+ 'html:transform:pre': HtmlTransformHandler;
359
+ }
360
+
361
+
362
+ /**
363
+ * Defines a handler function type for transforming HTML content.
364
+ * This function receives an object with the HTML to be processed.
365
+ *
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.
368
+ */
369
+ declare type HtmlTransformHandler = (ctx: {
370
+ url: URL;
371
+ html: string;
372
+ }) => string | Promise<string>;
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
+
398
+ /**
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 {
53
405
  /**
54
- * Render an HTML document for a specific URL with specified
55
- * render options
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.
56
408
  */
57
- render(opts: CommonEngineRenderOptions): Promise<string>;
58
- private inlineCriticalCss;
59
- private retrieveSSGPage;
60
- private renderApplication;
61
- /** Retrieve the document from the cache or the filesystem */
62
- private getDocument;
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
428
+ */
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
63
444
  }
64
445
 
65
- export declare interface CommonEngineOptions {
66
- /** A method that when invoked returns a promise that returns an `ApplicationRef` instance once resolved or an NgModule. */
67
- bootstrap?: Type<{}> | (() => Promise<ApplicationRef>);
68
- /** A set of platform level providers for all requests. */
69
- providers?: StaticProvider[];
70
- /** Enable request performance profiling data collection and printing the results in the server console. */
71
- enablePerformanceProfiler?: boolean;
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;
493
+ /**
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.
497
+ *
498
+ * @param route - The route path to insert into the tree.
499
+ * @param metadata - Metadata associated with the route, excluding the route path itself.
500
+ */
501
+ insert(route: string, metadata: RouteTreeNodeMetadataWithoutRoute & AdditionalMetadata): void;
502
+ /**
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.
506
+ *
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.
509
+ */
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;
72
575
  }
73
576
 
74
- export declare interface CommonEngineRenderOptions {
75
- /** A method that when invoked returns a promise that returns an `ApplicationRef` instance once resolved or an NgModule. */
76
- bootstrap?: Type<{}> | (() => Promise<ApplicationRef>);
77
- /** A set of platform level providers for the current request. */
78
- providers?: StaticProvider[];
79
- url?: string;
80
- document?: string;
81
- documentFilePath?: string;
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;
82
590
  /**
83
- * Reduce render blocking requests by inlining critical CSS.
84
- * Defaults to true.
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.
85
594
  */
86
- inlineCriticalCss?: boolean;
595
+ insertionIndex: number;
87
596
  /**
88
- * Base path location of index file.
89
- * Defaults to the 'documentFilePath' dirname when not provided.
597
+ * A map of child nodes, keyed by their corresponding route segment or wildcard.
90
598
  */
91
- publicPath?: string;
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;
92
604
  }
93
605
 
94
606
  /**
95
- * Represents the result of processing a route.
607
+ * Describes metadata associated with a node in the route tree.
608
+ * This metadata includes information such as the route path and optional redirect instructions.
96
609
  */
97
- declare interface RouteResult {
610
+ declare interface RouteTreeNodeMetadata {
611
+ /**
612
+ * Optional redirect path associated with this node.
613
+ * This defines where to redirect if this route is matched.
614
+ */
615
+ redirectTo?: string;
98
616
  /**
99
- * The resolved path of the route.
617
+ * The route path for this node.
100
618
  *
101
- * This string represents the complete URL path for the route after it has been
102
- * resolved, including any parent routes or path segments that have been joined.
619
+ * A "route" is a URL path or pattern that is used to navigate to different parts of a web application.
620
+ * It is made up of one or more segments separated by slashes `/`. For instance, in the URL `/products/details/42`,
621
+ * the full route is `/products/details/42`, with segments `products`, `details`, and `42`.
622
+ *
623
+ * Routes define how URLs map to views or components in an application. Each route segment contributes to
624
+ * the overall path that determines which view or component is displayed.
625
+ *
626
+ * - **Static Routes**: These routes have fixed segments. For example, `/about` or `/contact`.
627
+ * - **Parameterized Routes**: These include dynamic segments that act as placeholders, such as `/users/:id`,
628
+ * where `:id` could be any user ID.
629
+ *
630
+ * In the context of `RouteTreeNodeMetadata`, the `route` property represents the complete path that this node
631
+ * in the route tree corresponds to. This path is used to determine how a specific URL in the browser maps to the
632
+ * structure and content of the application.
103
633
  */
104
634
  route: string;
105
635
  /**
106
- * The target path for route redirection, if applicable.
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;
648
+ }
649
+
650
+ /**
651
+ * Represents metadata for a route tree node, excluding the 'route' path segment.
652
+ */
653
+ declare type RouteTreeNodeMetadataWithoutRoute = Omit<RouteTreeNodeMetadata, 'route'>;
654
+
655
+ /**
656
+ * Represents the serialized format of a route tree as an array of node metadata objects.
657
+ * Each entry in the array corresponds to a specific node's metadata within the route tree.
658
+ */
659
+ declare type SerializableRouteTreeNode = ReadonlyArray<RouteTreeNodeMetadata>;
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.
107
717
  *
108
- * If this route has a `redirectTo` property in the configuration, this field will
109
- * contain the full resolved URL path that the route should redirect to.
718
+ * @default `PrerenderFallback.Server` if not provided.
110
719
  */
111
- redirectTo?: string;
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;
112
753
  }
113
754
 
755
+ /**
756
+ * Destroys the existing `AngularServerApp` instance, releasing associated resources and resetting the
757
+ * reference to `undefined`.
758
+ *
759
+ * This function is primarily used to enable the recreation of the `AngularServerApp` instance,
760
+ * typically when server configuration or application state needs to be refreshed.
761
+ */
762
+ export declare function ɵdestroyAngularServerApp(): void;
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
+
788
+ /**
789
+ * Retrieves or creates an instance of `AngularServerApp`.
790
+ * - If an instance of `AngularServerApp` already exists, it will return the existing one.
791
+ * - If no instance exists, it will create a new one with the provided options.
792
+ * @returns The existing or newly created instance of `AngularServerApp`.
793
+ */
794
+ export declare function ɵgetOrCreateAngularServerApp(): AngularServerApp;
795
+
114
796
  /**
115
797
  * Retrieves routes from the given Angular application.
116
798
  *
117
799
  * This function initializes an Angular platform, bootstraps the application or module,
118
800
  * and retrieves routes from the Angular router configuration. It handles both module-based
119
- * and function-based bootstrapping. It yields the resulting routes as `RouteResult` objects.
801
+ * and function-based bootstrapping. It yields the resulting routes as `RouteTreeNodeMetadata` objects or errors.
120
802
  *
121
803
  * @param bootstrap - A function that returns a promise resolving to an `ApplicationRef` or an Angular module to bootstrap.
122
804
  * @param document - The initial HTML document used for server-side rendering.
123
805
  * This document is necessary to render the application on the server.
124
806
  * @param url - The URL for server-side rendering. The URL is used to configure `ServerPlatformLocation`. This configuration is crucial
125
807
  * for ensuring that API requests for relative paths succeed, which is essential for accurate route extraction.
126
- * See:
127
- * - https://github.com/angular/angular/blob/d608b857c689d17a7ffa33bbb510301014d24a17/packages/platform-server/src/location.ts#L51
128
- * - https://github.com/angular/angular/blob/6882cc7d9eed26d3caeedca027452367ba25f2b9/packages/platform-server/src/http.ts#L44
129
- * @returns A promise that resolves to an object of type `AngularRouterConfigResult`.
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.
813
+ */
814
+ export declare function ɵgetRoutesFromAngularRouterConfig(bootstrap: AngularBootstrap, document: string, url: URL, invokeGetPrerenderParams?: boolean, includePrerenderFallbackRoutes?: boolean): Promise<AngularRouterConfigResult>;
815
+
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;
836
+ }
837
+
838
+ /**
839
+ * Sets the Angular app engine manifest.
840
+ *
841
+ * @param manifest - The engine manifest object to set.
842
+ */
843
+ export declare function ɵsetAngularAppEngineManifest(manifest: AngularAppEngineManifest): void;
844
+
845
+ /**
846
+ * Sets the Angular app manifest.
847
+ *
848
+ * @param manifest - The manifest object to set for the Angular application.
130
849
  */
131
- export declare function ɵgetRoutesFromAngularRouterConfig(bootstrap: AngularBootstrap, document: string, url: URL): Promise<AngularRouterConfigResult>;
850
+ export declare function ɵsetAngularAppManifest(manifest: AngularAppManifest): void;
132
851
 
133
852
  export { }