import type { StandardSchemaV1 } from '@standard-schema/spec'; import { type MaybePromise, Method } from './types'; import { type Logger } from './logger'; import { type RepliesType, type Reply, type ReplyFrom } from './reply'; import { type Data } from './data'; import type { ExtensionsFrom, MiddlewareList } from './middleware'; type RouteContext = IsDo extends true ? { isDurableObject: true; /** * @deprecated */ state: DurableObjectState; } : { isDurableObject: false; /** * @deprecated */ ctx: ExecutionContext; }; type BodyFromSchema = { body: T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput : unknown; }; type ParamsFromSchema = { params: T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput : Partial>; }; type QueryFromSchema = { query: T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput : Partial>; }; type RouteParams = BodyFromSchema & ParamsFromSchema & QueryFromSchema; type RouteMethod = Method | keyof typeof Method; export interface Route { name: string; method: Method; pathname: string; compatibilityDate?: string; before?: MiddlewareList; after?: MiddlewareList; handler: (input: { event: any; env: Environment; ctx: any; logger: Logger; }) => MaybePromise; replies?: RepliesType; schemas: { body?: StandardSchemaV1; params?: StandardSchemaV1; query?: StandardSchemaV1; }; } export type RouteResult = { exact: true; route: Route; } | { exact: false; route?: Route; }; export interface RouterOptions { prefix?: string; } export declare class Router { private options; private routes; private ready; constructor(options: RouterOptions); register: (options: { name?: string; method?: RouteMethod | RouteMethod[]; pathname?: RoutePath; compatibilityDate?: string; before?: RBefore; after?: RAfter; replies?: Replies; body?: Body; params?: Params; query?: Query; }, handler: (input: { event: Data & RouteContext & RouteParams & { reply: ReplyFrom; } & { _raw: unknown; } & ExtensionsFrom & ExtensionsFrom; env: Environment; ctx: IsDo extends true ? DurableObjectState : ExecutionContext; logger: Logger; }) => MaybePromise) => void; find: (pathname?: string, method?: string, compatibilityDate?: string, ignoreCompatibilityDate?: boolean) => RouteResult; init: () => void; getRoutes: () => Route[]; } export {};