import type { Schema } from '../../data/schema/types.js'; import type { DB } from '../../data/db/index.js'; import type { BackoffConfig } from '../../async/jobs/queue.js'; /** The default database name constant ('default') used when pipe() is called without a name argument. */ export declare const DEFAULT_DB: "__pipework_default__"; /** Auth requirement level for a handler — 'required', 'optional', or 'public'. */ export type AuthRequirement = 'required' | 'optional' | 'none'; /** Permission requirement attached to a handler — resource, action, scope. */ export interface PermissionMeta { readonly resource: string; readonly action: string; readonly scope?: string; } /** Retry configuration for job handlers — maxAttempts, backoff strategy, delay. */ export interface JobRetryConfig { readonly attempts: number; readonly backoff?: BackoffConfig; } /** * How a job's database transaction(s) are managed. * * - `'auto'` (default): the framework wraps the whole `.fit` run in one outer, * tenant-scoped transaction — atomic / all-or-nothing. * - `'manual'`: the framework propagates the job context but opens no outer * transaction. The handler receives a `checkpoint(fn)` primitive and owns its * own transaction boundaries, committing incrementally within a single warm * run. The contract shifts from atomic to at-least-once / idempotent-on-resume. */ export type JobTransactionMode = 'auto' | 'manual'; /** * The `checkpoint` primitive injected into a manual-transaction job's deps. * Each call opens a fresh top-level, tenant-scoped transaction (re-establishing * the tenant `SET LOCAL` session vars so database-side RLS sees the tenant), * runs `fn` with the participating databases bound, and commits durably and * independently of any other checkpoint. `TDb` is the record of databases the * handler declared with `.use()`. */ export type Checkpoint = (fn: (dbs: TDb) => Promise) => Promise; /** The erased runtime shape of {@link Checkpoint}, used where the db-deps type is not tracked. */ export type CheckpointFn = (fn: (dbs: Record) => Promise) => Promise; /** Metadata attached to a handler — route info, auth requirements, input/output schemas, database names. */ export interface HandlerMeta { readonly databases: readonly string[]; readonly requiresAuth: boolean; readonly authRequirement: AuthRequirement; readonly inputSchema: Schema | null; readonly outputSchemas: ReadonlyMap; readonly querySchema: Schema | null; readonly paramsSchema: Schema | null; readonly route: RouteMeta | null; readonly isJob: boolean; readonly jobType: string | null; readonly jobRetry: JobRetryConfig | null; readonly jobTimeout: number | null; readonly jobTransaction: JobTransactionMode; readonly permission: PermissionMeta | null; readonly wantsRequest: boolean; readonly wantsResponse: boolean; readonly wantsRawBody: boolean; } /** * What a route screen is shown: the request line and headers, plus the declared * body size. The body has not been read — nothing here forces it to be buffered. */ export interface ScreenedRequest { readonly method: string; readonly url: string; readonly headers: Readonly>; /** Parsed `content-length`, or null when the header is absent or unparseable. */ readonly contentLength: number | null; } /** A screen's refusal — the status and named reason sent instead of reading the body. */ export interface ScreenRefusal { readonly status: number; readonly reason: string; /** Extra fields merged into the response body alongside `reason`. */ readonly body?: Readonly>; } /** * Runs before the body is parsed and before the body limit applies. Return a * refusal to answer the request there and then; return nothing to let it through. */ export type RouteScreen = (request: ScreenedRequest) => ScreenRefusal | null | undefined | void | Promise; /** HTTP route metadata — method, path, and registered middleware. */ export interface RouteMeta { readonly method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; readonly path: string; /** Per-route max request body size in bytes — overrides the server-level bodyLimit for this route. */ readonly bodyLimit?: number; /** Pre-parse screen — inspects headers before the body is read, and may refuse. */ readonly screen?: RouteScreen; } /** HTTP method literal type — 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'. */ export type HttpMethod = RouteMeta['method']; /** A resolved handler produced by fitting().fit() — carries metadata, dependencies, and the handler function. */ export interface Handler, TReturn> { execute(deps: TDeps): Promise; readonly meta: HandlerMeta; } /** Extracts the dependency type from a Handler — InferDeps gives you the deps object shape. */ export type InferDeps = H extends Handler ? D : never; /** Extracts the return type from a Handler — InferReturn gives you the resolved return type. */ export type InferReturn = H extends Handler, infer R> ? R : never; /** Map of database names to their resolved DB instances for a handler. */ export type DatabaseDeps = Record; //# sourceMappingURL=types.d.ts.map