import type { CookieJar } from './cookies.js'; import type { ResponseBuilder } from './response.js'; import type { LoggerService } from './logger.js'; export type Constructor = new (...args: any[]) => T; export type Resolve = (token: Constructor | string) => T; export type Scope = 'singleton' | 'transient' | 'request'; export interface ConnInfo { remoteAddress?: string; remotePort?: number; family?: 'IPv4' | 'IPv6'; } export interface RequestContext { req: Request; res: ResponseBuilder; params: Record; query: Record; rawQuery: URLSearchParams; /** * Connection info for the request, resolved lazily and cached. `{}` when the * runtime exposes no socket address (e.g. unit tests without `_conn`). The * `remoteAddress` is always the honest socket IP, never a proxy header. */ readonly conn: ConnInfo; /** * Client IP. Resolves from trusted proxy headers when `trustProxy` is set * (see `MiiaOptions.trustProxy`), otherwise falls back to `conn.remoteAddress`. */ readonly ip: string | undefined; /** * Cookie accessor, resolved lazily and cached. Reads incoming cookies from the * request `Cookie` header (`get`/`getAll`/`has`) and writes response cookies * (`set`/`delete`) through the `ResponseBuilder`. */ readonly cookies: CookieJar; /** * Returns the parsed JSON body, cached per request. * After the route's `body` schema runs, returns the validated (and possibly transformed) data. * * Reads the body through `text()`. An empty body (or none, e.g. a GET) resolves to * `undefined`; a body that is not valid JSON rejects with `BadRequestException` (400). * `json()` and `text()` share one read and can be combined in any order. The raw * stream (`req.body`, `req.formData()`, `req.arrayBuffer()`) is available only * before the first call to either. */ json(): Promise; /** * Returns the raw request body as text, cached per request. * * Shares its read with `json()`. After the route's `body` schema runs it still * returns the raw text, not the validated data. */ text(): Promise; /** @internal Used by the built-in JSON body reader to store validated data. */ _setBody(value: unknown): void; } export type Middleware = (ctx: RequestContext, next: () => Promise) => void | Promise; export interface CanActivate { canActivate(ctx: RequestContext): boolean | Promise; } export type Guard = Constructor; /** A status a guard can reject with, declared on the guard class via `GUARD_RESPONSES`. */ export type GuardResponseDeclaration = number | { status: number; description?: string; }; export interface FactoryProvider { token: string | Constructor; factory: ((resolve: Resolve) => T) | (() => T); scope?: Scope; } export type ProviderDefinition = Constructor | FactoryProvider; export interface ModuleOptions { imports?: (Constructor | ConfiguredModule)[]; controllers?: Constructor[]; providers?: ProviderDefinition[]; prefix?: string; } export interface ConfiguredModule { module: Constructor; providers?: ProviderDefinition[]; } export interface ZodLikeIssue { path?: PropertyKey[]; message: string; code?: string; } export interface ZodLike { safeParse(data: unknown): { success: true; data: T; } | { success: false; error: { issues: ZodLikeIssue[]; }; }; } /** Request schemas for a route that takes a body: POST, PUT, PATCH, DELETE. */ export interface RouteOptions { body?: ZodLike; query?: ZodLike; params?: ZodLike; } /** Request schemas for GET, HEAD and OPTIONS, which take no body. */ export interface RouteOptionsWithoutBody { query?: ZodLike; params?: ZodLike; body?: never; } export interface BodyReader { /** Media type for the spec, e.g. 'multipart/form-data'. */ contentType: string; /** Reads the raw body into the value the schema validates. */ read(ctx: RequestContext): Promise; /** Stores validated data so the handler's own accessor returns it. */ commit(ctx: RequestContext, data: unknown): void; } export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS'; export interface RouteDefinition { method: HttpMethod; path: string; handlerName: string; } export interface ListenInfo { port: number; hostname: string; fetch: (req: Request) => Response | Promise; logger?: LoggerService; /** * Adapter-level body cap computed by Miia: max(app `maxBodySize`, all * `@BodyLimit` values), or `false` when limits are disabled. Adapters fall * back to their own 1 MiB default when undefined (standalone serve() usage). * * It is a ceiling, not the last word: for a body with no declared length, * core narrows an adapter's `_bodyLimit` to the matched route's own limit * once routing has happened, and never widens what the adapter already set. */ maxBodySize?: number | false; } export interface ServerHandle { close(): void | Promise; } export type ListenAdapter = (info: ListenInfo) => void | ServerHandle | Promise | Promise; //# sourceMappingURL=types.d.ts.map