1 | import {NgModuleFactory, Provider} from '@angular/core';
|
2 |
|
3 | import {
|
4 | ApplicationBootstrapper,
|
5 | ApplicationStateReader,
|
6 | ComposedTransition,
|
7 | Postprocessor,
|
8 | VariantsMap,
|
9 | } from './contracts';
|
10 |
|
11 | import {PrebootQueryable} from './preboot';
|
12 | import {Route} from '../route';
|
13 | import {ServerPlatform} from '../platform/platform';
|
14 |
|
15 | // Extract routes from a compiled and running application instance
|
16 | export interface RouteExtractionOperation<M> {
|
17 | platform: ServerPlatform;
|
18 | moduleFactory: NgModuleFactory<M>;
|
19 | templateDocument: string;
|
20 | }
|
21 |
|
22 | export interface RenderOperation {
|
23 | // This is an HTML document containing the index.html build output of the application.
|
24 | // We inject the rendered content into this document, but it must still contain <script>
|
25 | // tags so that it will boot the client application after rendering the prerendered
|
26 | // HTML returned from the first HTTP request.
|
27 | templateDocument: string;
|
28 |
|
29 | // An optional array of routes to render concurrently
|
30 | routes: Array<Route>;
|
31 |
|
32 | // An optional platform factory function. If the API consumer wishes to construct their
|
33 | // own platform implementation that
|
34 | platform?: () => ServerPlatform;
|
35 |
|
36 | // An optional map of variants that describe the different states and request options
|
37 | // that we will render. Be careful because the space complexity of storing variants
|
38 | // is O(n!) so you should only have a few different variants of your application.
|
39 | // A good example of a variant might be an authenticated / anonymous boolean. You
|
40 | // would render each route separately and the variant transition function would call
|
41 | // some application service to place the application into an authenticated or anonymous
|
42 | // state. (This transition class would be part of your server code, not application code.
|
43 | // See the documentation in the readme and the definition of StateTransition<T> contract)
|
44 | variants: VariantsMap;
|
45 |
|
46 | // An optional state reader (either a function accepting an application injector, or a class
|
47 | // implementing the StateReader<T> contract). If you provide a class decorated with
|
48 | // @Injectable, we will instantiate the class in the context of the running application,
|
49 | // so it has access to all providers and services in the application. If it is not decorated,
|
50 | // it must be a function that just accepts a reference to the Injector instance itself,
|
51 | // which it can use to query services and providers.
|
52 | stateReader: ApplicationStateReader<any>;
|
53 |
|
54 | // Optional function to execute during application initialization.
|
55 | bootstrappers: Array<ApplicationBootstrapper>;
|
56 |
|
57 | // A chain of postprocessors that transform rendered HTML documents in some way. They will
|
58 | // be executed in order of definition, and each transform will receive as its argument the
|
59 | // results of the previous transformation.
|
60 | postprocessors: Array<Postprocessor>;
|
61 |
|
62 | // Optional preboot configuration, if preboot integration is desired
|
63 | preboot: PrebootQueryable;
|
64 |
|
65 | // Optional providers to use in application bootstrap process
|
66 | providers: Array<Provider>;
|
67 |
|
68 | // The number of milliseconds we will wait for the application zone to become stable on startup.
|
69 | // If this value is null, we will wait forever. It is recommended that you set this to a low
|
70 | // value if you are doing on-demand rendering. For build-time rendering, high values are fine.
|
71 | stabilizeTimeout?: number;
|
72 |
|
73 | // Do not fail the entire render process if some routes fail to render
|
74 | pessimistic?: boolean;
|
75 |
|
76 | // Enable 'blacklist by default' route rendering behaviour (each route you wish to render must be marked with `server: true')
|
77 | blacklist?: boolean;
|
78 | }
|
79 |
|
80 | // A render operation is an operation that forks into multiple concurrent suboperations,
|
81 | // which are represented with RenderVariantOperation<V, M>. Each route and variant
|
82 | // permutation will cause a separate parallel render operation and each of them instantiate
|
83 | // their own instance of the application. This is an internal contract, not part of the
|
84 | // public API
|
85 | export interface RenderVariantOperation<V> {
|
86 | scope: RenderOperation; /// parent render scope
|
87 | transition?: ComposedTransition; /// variant transition function composed from {@link VariantMap} and {@link variant}
|
88 | uri: string; /// an absolute URI including protocol and hostname
|
89 | variant?: V; /// variant options for this render operation
|
90 | } |
\ | No newline at end of file |