Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

Commit

Permalink
Update pages.d.ts (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
GregBrimble committed Apr 22, 2022
1 parent fab61ed commit b96c23c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-knives-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/workers-types": minor
---

feature: Adds the `PagesPluginFunction` type and internal `functionPath` to Functions' context.
21 changes: 21 additions & 0 deletions manual-ts/pages.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ type Params<P extends string = any> = Record<P, string | string[]>;

type EventContext<Env, P extends string, Data> = {
request: Request;
functionPath: string;
waitUntil: (promise: Promise<any>) => void;
next: (input?: Request | string, init?: RequestInit) => Promise<Response>;
env: Env & { ASSETS: { fetch: typeof fetch } };
Expand All @@ -14,3 +15,23 @@ declare type PagesFunction<
Params extends string = any,
Data extends Record<string, unknown> = Record<string, unknown>
> = (context: EventContext<Env, Params, Data>) => Response | Promise<Response>;

type EventPluginContext<Env, P extends string, Data, PluginArgs> = {
request: Request;
functionPath: string;
waitUntil: (promise: Promise<any>) => void;
next: (input?: Request | string, init?: RequestInit) => Promise<Response>;
env: Env & { ASSETS: { fetch: typeof fetch } };
params: Params<P>;
data: Data;
pluginArgs: PluginArgs;
};

declare type PagesPluginFunction<
Env = unknown,
Params extends string = any,
Data extends Record<string, unknown> = Record<string, unknown>,
PluginArgs = unknown
> = (
context: EventPluginContext<Env, Params, Data, PluginArgs>
) => Response | Promise<Response>;

0 comments on commit b96c23c

Please sign in to comment.