Skip to content

Commit

Permalink
refactor(core): add REQUEST, RESPONSE_INIT and REQUEST_CONTEXT
Browse files Browse the repository at this point in the history
…tokens

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.
  • Loading branch information
AndrewKushnir committed Nov 14, 2024
1 parent 64cfe18 commit 66c8254
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 12 deletions.
1 change: 0 additions & 1 deletion adev/src/assets/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ copy_to_directory(
"//packages/service-worker:service-worker_docs",
"//packages/ssr:ssr_docs",
"//packages/ssr:ssr_node_docs",
"//packages/ssr:ssr_tokens_docs",
"//packages/upgrade:upgrade_docs",
"//packages/upgrade/static:upgrade_static_docs",
"//packages/upgrade/static/testing:upgrade_static_testing_docs",
Expand Down
9 changes: 9 additions & 0 deletions goldens/public-api/core/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,12 @@ export interface RendererType2 {
styles: string[];
}

// @public
export const REQUEST: InjectionToken<Request | null>;

// @public
export const REQUEST_CONTEXT: InjectionToken<unknown>;

// @public
export function resolveForwardRef<T>(type: T): T;

Expand Down Expand Up @@ -1618,6 +1624,9 @@ export enum ResourceStatus {
Resolved = 4
}

// @public
export const RESPONSE_INIT: InjectionToken<ResponseInit | null>;

// @public
export function runInInjectionContext<ReturnT>(injector: Injector, fn: () => ReturnT): ReturnT;

Expand Down
1 change: 0 additions & 1 deletion packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ generate_api_manifest(
"//packages/service-worker:service-worker_docs_extraction",
"//packages/ssr:ssr_docs_extraction",
"//packages/ssr:ssr_node_docs_extraction",
"//packages/ssr:ssr_tokens_docs_extraction",
"//packages/upgrade:upgrade_docs_extraction",
"//packages/upgrade/static:upgrade_static_docs_extraction",
"//packages/upgrade/static/testing:upgrade_static_testing_docs_extraction",
Expand Down
70 changes: 70 additions & 0 deletions packages/core/src/application/platform_tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

import {InjectionToken} from '../di/injection_token';

/**
* Injection token representing the current HTTP request object.
*
* Use this token to access the current request when handling server-side
* rendering (SSR).
*
* @remarks
* This token may be `null` in the following scenarios:
*
* * During the build processes.
* * When the application is rendered in the browser (client-side rendering).
* * When performing static site generation (SSG).
* * During route extraction in development (at the time of the request).
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request | `Request` on MDN}
*
* @developerPreview
*/
export const REQUEST = new InjectionToken<Request | null>('REQUEST', {
providedIn: 'platform',
factory: () => null,
});

/**
* Injection token for response initialization options.
*
* Use this token to provide response options for configuring or initializing
* HTTP responses in server-side rendering or API endpoints.
*
* @remarks
* This token may be `null` in the following scenarios:
*
* * During the build processes.
* * When the application is rendered in the browser (client-side rendering).
* * When performing static site generation (SSG).
* * During route extraction in development (at the time of the request).
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Response/Response | `ResponseInit` on MDN}
*
* @developerPreview
*/
export const RESPONSE_INIT = new InjectionToken<ResponseInit | null>('RESPONSE_INIT', {
providedIn: 'platform',
factory: () => null,
});

/**
* Injection token for additional request context.
*
* Use this token to pass custom metadata or context related to the current request in server-side rendering.
*
* @remarks
* This token is only available during server-side rendering and will be `null` in other contexts.
*
* @developerPreview
*/
export const REQUEST_CONTEXT = new InjectionToken<unknown>('REQUEST_CONTEXT', {
providedIn: 'platform',
factory: () => null,
});
1 change: 1 addition & 0 deletions packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export {
export {ApplicationConfig, mergeApplicationConfig} from './application/application_config';
export {makeStateKey, StateKey, TransferState} from './transfer_state';
export {booleanAttribute, numberAttribute} from './util/coercion';
export {REQUEST, REQUEST_CONTEXT, RESPONSE_INIT} from './application/platform_tokens';

import {global} from './util/global';
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/test/bundling/defer/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,9 @@
{
"name": "init_platform_ref"
},
{
"name": "init_platform_tokens"
},
{
"name": "init_profiler"
},
Expand Down
10 changes: 0 additions & 10 deletions packages/ssr/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,3 @@ generate_api_docs(
entry_point = "@npm//:node_modules/@angular/ssr/node/index.d.ts",
module_name = "@angular/ssr/node",
)

generate_api_docs(
name = "ssr_tokens_docs",
srcs = [
"//packages:common_files_and_deps_for_docs",
"@npm//@angular/ssr",
],
entry_point = "@npm//:node_modules/@angular/ssr/tokens/index.d.ts",
module_name = "@angular/ssr/tokens",
)

0 comments on commit 66c8254

Please sign in to comment.