import type { EnvironmentFor } from '../lib/environment.ts'; import type { Identity } from '../lib/identity.ts'; import type { HttpVersion, MethodOrAny } from '../lib/autogen/types.ts'; import type { UntypedSchemaDef } from '../lib/schema.ts'; import type { Timestamp } from '../lib/timestamp.ts'; import type { Uuid } from '../lib/uuid.ts'; import type { TransactionCtx } from './procedures.ts'; import type { HttpClient } from './http_internal.ts'; import type { Random } from './rng.ts'; import { type ModuleExport, type SchemaInner } from './schema.ts'; import { Headers, makeResponse, SyncResponse, type BodyInit, type HeadersInit, type ResponseInit } from './http_shared.ts'; export { Headers }; export { SyncResponse }; export type { BodyInit, HeadersInit, ResponseInit }; export { makeResponse }; export declare const httpHandlerFn: unique symbol; export interface RequestInit { body?: BodyInit | null; headers?: HeadersInit; method?: string; version?: HttpVersion; } type RequestInner = { headers: Headers; method: string; uri: string; version: HttpVersion; }; type RouteSpec = { handler: HttpHandlerExport; method: MethodOrAny; path: string; }; export declare const makeRequest: unique symbol; export declare class Request { #private; constructor(url: URL | string, init?: RequestInit); static [makeRequest](body: BodyInit | null, inner: RequestInner): Request; get headers(): Headers; get method(): string; get uri(): string; get url(): string; get version(): HttpVersion; arrayBuffer(): ArrayBuffer; bytes(): Uint8Array; json(): any; text(): string; } export type HandlerAliasViews = SchemaDef extends { namespaces: infer NS extends Record; } ? { readonly [K in keyof NS]: HandlerContext; } : {}; export interface HandlerContext { readonly env: EnvironmentFor; /** * The random `Identity` that the host created for this request. * * Each request has a different sender, which is also the sender of the transactions it opens. */ readonly sender: Identity; readonly timestamp: Timestamp; readonly http: HttpClient; readonly identity: Identity; readonly random: Random; readonly as: HandlerAliasViews; withTx(body: (ctx: TransactionCtx) => T): T; newUuidV4(): Uuid; newUuidV7(): Uuid; } export type HandlerFn = (ctx: HandlerContext, req: Request) => SyncResponse; export interface HttpHandlerExport extends HandlerFn, ModuleExport { [httpHandlerFn]: HandlerFn; } export interface HttpHandlerOpts { name: string; } export declare class Router { #private; constructor(routes?: RouteSpec[]); get(path: string, handler: HttpHandlerExport): Router; head(path: string, handler: HttpHandlerExport): Router; options(path: string, handler: HttpHandlerExport): Router; put(path: string, handler: HttpHandlerExport): Router; delete(path: string, handler: HttpHandlerExport): Router; post(path: string, handler: HttpHandlerExport): Router; patch(path: string, handler: HttpHandlerExport): Router; any(path: string, handler: HttpHandlerExport): Router; nest(path: string, subRouter: Router): Router; merge(otherRouter: Router): Router; intoRoutes(): RouteSpec[]; private addRoute; } export declare function makeHttpHandlerExport(ctx: SchemaInner, opts: HttpHandlerOpts | undefined, fn: HandlerFn): HttpHandlerExport; export declare function makeHttpRouterExport(ctx: SchemaInner, router: Router): ModuleExport; //# sourceMappingURL=http_handlers.d.ts.map