Skip to content

Commit a55341b

Browse files
committed
refactor(core): add REQUEST, RESPONSE_INIT and REQUEST_CONTEXT tokens (angular#58669)
This commit introduces the `REQUEST`, `RESPONSE_INIT` and `REQUEST_CONTEXT` tokens, which will replace similar ones from https://github.com/angular/angular-cli/blob/28503186230b5e22b84499641d56c9c981fdab1d/packages/angular/ssr/tokens/src/tokens.ts, so those tokens would be imported in application code via `@angular/core` package. PR Close angular#58669
1 parent 8ac02ec commit a55341b

File tree

7 files changed

+83
-12
lines changed

7 files changed

+83
-12
lines changed

adev/src/assets/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ copy_to_directory(
7171
"//packages/service-worker:service-worker_docs",
7272
"//packages/ssr:ssr_docs",
7373
"//packages/ssr:ssr_node_docs",
74-
"//packages/ssr:ssr_tokens_docs",
7574
"//packages/upgrade:upgrade_docs",
7675
"//packages/upgrade/static:upgrade_static_docs",
7776
"//packages/upgrade/static/testing:upgrade_static_testing_docs",

goldens/public-api/core/index.api.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,12 @@ export interface RendererType2 {
15621562
styles: string[];
15631563
}
15641564

1565+
// @public
1566+
export const REQUEST: InjectionToken<Request | null>;
1567+
1568+
// @public
1569+
export const REQUEST_CONTEXT: InjectionToken<unknown>;
1570+
15651571
// @public
15661572
export function resolveForwardRef<T>(type: T): T;
15671573

@@ -1618,6 +1624,9 @@ export enum ResourceStatus {
16181624
Resolved = 4
16191625
}
16201626

1627+
// @public
1628+
export const RESPONSE_INIT: InjectionToken<ResponseInit | null>;
1629+
16211630
// @public
16221631
export function runInInjectionContext<ReturnT>(injector: Injector, fn: () => ReturnT): ReturnT;
16231632

packages/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ generate_api_manifest(
101101
"//packages/service-worker:service-worker_docs_extraction",
102102
"//packages/ssr:ssr_docs_extraction",
103103
"//packages/ssr:ssr_node_docs_extraction",
104-
"//packages/ssr:ssr_tokens_docs_extraction",
105104
"//packages/upgrade:upgrade_docs_extraction",
106105
"//packages/upgrade/static:upgrade_static_docs_extraction",
107106
"//packages/upgrade/static/testing:upgrade_static_testing_docs_extraction",
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
import {InjectionToken} from '../di/injection_token';
10+
11+
/**
12+
* Injection token representing the current HTTP request object.
13+
*
14+
* Use this token to access the current request when handling server-side
15+
* rendering (SSR).
16+
*
17+
* @remarks
18+
* This token may be `null` in the following scenarios:
19+
*
20+
* * During the build processes.
21+
* * When the application is rendered in the browser (client-side rendering).
22+
* * When performing static site generation (SSG).
23+
* * During route extraction in development (at the time of the request).
24+
*
25+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request | `Request` on MDN}
26+
*
27+
* @developerPreview
28+
*/
29+
export const REQUEST = new InjectionToken<Request | null>('REQUEST', {
30+
providedIn: 'platform',
31+
factory: () => null,
32+
});
33+
34+
/**
35+
* Injection token for response initialization options.
36+
*
37+
* Use this token to provide response options for configuring or initializing
38+
* HTTP responses in server-side rendering or API endpoints.
39+
*
40+
* @remarks
41+
* This token may be `null` in the following scenarios:
42+
*
43+
* * During the build processes.
44+
* * When the application is rendered in the browser (client-side rendering).
45+
* * When performing static site generation (SSG).
46+
* * During route extraction in development (at the time of the request).
47+
*
48+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Response/Response | `ResponseInit` on MDN}
49+
*
50+
* @developerPreview
51+
*/
52+
export const RESPONSE_INIT = new InjectionToken<ResponseInit | null>('RESPONSE_INIT', {
53+
providedIn: 'platform',
54+
factory: () => null,
55+
});
56+
57+
/**
58+
* Injection token for additional request context.
59+
*
60+
* Use this token to pass custom metadata or context related to the current request in server-side rendering.
61+
*
62+
* @remarks
63+
* This token is only available during server-side rendering and will be `null` in other contexts.
64+
*
65+
* @developerPreview
66+
*/
67+
export const REQUEST_CONTEXT = new InjectionToken<unknown>('REQUEST_CONTEXT', {
68+
providedIn: 'platform',
69+
factory: () => null,
70+
});

packages/core/src/core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export {
115115
export {ApplicationConfig, mergeApplicationConfig} from './application/application_config';
116116
export {makeStateKey, StateKey, TransferState} from './transfer_state';
117117
export {booleanAttribute, numberAttribute} from './util/coercion';
118+
export {REQUEST, REQUEST_CONTEXT, RESPONSE_INIT} from './application/platform_tokens';
118119

119120
import {global} from './util/global';
120121
if (typeof ngDevMode !== 'undefined' && ngDevMode) {

packages/core/test/bundling/defer/bundle.golden_symbols.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,9 @@
18861886
{
18871887
"name": "init_platform_ref"
18881888
},
1889+
{
1890+
"name": "init_platform_tokens"
1891+
},
18891892
{
18901893
"name": "init_profiler"
18911894
},

packages/ssr/BUILD.bazel

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,3 @@ generate_api_docs(
2222
entry_point = "@npm//:node_modules/@angular/ssr/node/index.d.ts",
2323
module_name = "@angular/ssr/node",
2424
)
25-
26-
generate_api_docs(
27-
name = "ssr_tokens_docs",
28-
srcs = [
29-
"//packages:common_files_and_deps_for_docs",
30-
"@npm//@angular/ssr",
31-
],
32-
entry_point = "@npm//:node_modules/@angular/ssr/tokens/index.d.ts",
33-
module_name = "@angular/ssr/tokens",
34-
)

0 commit comments

Comments
 (0)