Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/beige-doodles-bow.md
Original file line number Diff line number Diff line change
@@ -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.
20 changes: 2 additions & 18 deletions packages/astro/src/core/fetch/fetch-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
/** Factory called lazily on the first `resolve(key)`. */
Expand Down Expand Up @@ -91,24 +93,6 @@ export interface AstroFetchState {
* [Astro reference](https://docs.astro.build/en/guides/routing/#rewrites)
*/
rewrite(payload: RewritePayload): Promise<Response>;

/**
* Registers a context provider under the given key. The `create`
* factory is called lazily on the first `resolve(key)`.
*/
provide<T>(key: string, provider: ContextProvider<T>): void;

/**
* Lazily resolves a provider registered under `key`. Returns
* `undefined` if no provider was registered for the key.
*/
resolve<T>(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> | void;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/types/public/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export interface AstroGlobal<
export interface APIContext<
Props extends Record<string, any> = Record<string, any>,
Params extends Record<string, string | undefined> = Record<string, string | undefined>,
> 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.
Expand Down
19 changes: 0 additions & 19 deletions packages/astro/src/types/public/extendables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading