diff --git a/.changeset/beige-doodles-bow.md b/.changeset/beige-doodles-bow.md new file mode 100644 index 000000000000..96467d3242d8 --- /dev/null +++ b/.changeset/beige-doodles-bow.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Removes `state.provide()`, `state.resolve()`, `state.finalizeAll()`, and `App.Providers` from the public advanced routing API. These context provider extension points are now internal-only. If you were using them in an integration, use `locals` to share per-request state instead. diff --git a/packages/astro/src/core/fetch/fetch-state.ts b/packages/astro/src/core/fetch/fetch-state.ts index 729a169cf82b..bfaa96bbe58e 100644 --- a/packages/astro/src/core/fetch/fetch-state.ts +++ b/packages/astro/src/core/fetch/fetch-state.ts @@ -45,6 +45,8 @@ import { getFirstForwardedValue, validateForwardedHeaders } from '../app/validat * Describes a lazily-created value that handlers can contribute to the * request context. `create` is called at most once (on first `resolve`); * `finalize` runs during `finalizeAll` to clean up / persist. + * + * @internal Not for use by 3rd-party code. May change without notice. */ export interface ContextProvider { /** Factory called lazily on the first `resolve(key)`. */ @@ -91,24 +93,6 @@ export interface AstroFetchState { * [Astro reference](https://docs.astro.build/en/guides/routing/#rewrites) */ rewrite(payload: RewritePayload): Promise; - - /** - * Registers a context provider under the given key. The `create` - * factory is called lazily on the first `resolve(key)`. - */ - provide(key: string, provider: ContextProvider): void; - - /** - * Lazily resolves a provider registered under `key`. Returns - * `undefined` if no provider was registered for the key. - */ - resolve(key: string): T | undefined; - - /** - * Runs all registered provider `finalize` callbacks. Call this after - * the response is produced, typically in a `finally` block. - */ - finalizeAll(): Promise | void; } /** diff --git a/packages/astro/src/types/public/context.ts b/packages/astro/src/types/public/context.ts index 96fd9d196cf9..98ffd1724114 100644 --- a/packages/astro/src/types/public/context.ts +++ b/packages/astro/src/types/public/context.ts @@ -138,7 +138,7 @@ export interface AstroGlobal< export interface APIContext< Props extends Record = Record, Params extends Record = Record, -> extends App.Providers { +> { /** * The site provided in the astro config, parsed as an instance of `URL`, without base. * `undefined` if the site is not provided in the config. diff --git a/packages/astro/src/types/public/extendables.ts b/packages/astro/src/types/public/extendables.ts index 213503e6485b..8281328ef27b 100644 --- a/packages/astro/src/types/public/extendables.ts +++ b/packages/astro/src/types/public/extendables.ts @@ -15,25 +15,6 @@ declare global { * Optionally type the data stored in the session */ export interface SessionData {} - - /** - * Declare custom context providers to get typed access on `Astro` and `ctx`. - * Libraries and users register providers via `state.provide(key, { create, finalize? })`, - * and the corresponding types are declared here using module augmentation. - * - * Built-in providers like `session` are already typed by Astro and don't - * need to be declared here. - * - * @example - * ```ts - * declare namespace App { - * interface Providers { - * oauth: import('./lib/oauth').OAuthSession; - * } - * } - * ``` - */ - export interface Providers {} } namespace Astro {