import type { StandardSchemaV1 } from "@standard-schema/spec"; import { type ContractDeprecationMeta } from "./lifecycle.js"; import type { OpenAPIOperationMeta } from "./openapi-meta.js"; import type { QueryTransport, QueryTransportCompatibility } from "./query-transport.js"; import type { BodyHttpMethod, ContractErrorResponses, ContractHeaderSchemas, ContractMeta, ContractResponses, HttpContractConfig, HttpMethod, MergeContractMeta, MergedContractErrorResponses, OmitMetaKeys, ResponsesFromErrorDefinitions, StandardSchema } from "./types.js"; /** * Fluent builder for one HTTP contract. * * A contract describes the transport boundary for one endpoint: method, path, * request schemas, response schemas, metadata, and route-owned catalog errors. * Builder methods are immutable; each call returns a new builder with narrower * types. */ export declare class ContractBuilder { readonly kind: "http"; readonly name: string; readonly namespace?: string; readonly localName: string; readonly method: TMethod; private readonly _path; private readonly _pathParams; private readonly _query; private readonly _queryTransport; private readonly _body; private readonly _headers; private readonly _responses; private readonly _meta; constructor(config: HttpContractConfig); /** * Request and response schemas attached to this contract. * * Server adapters use these for validation. Client and frontend integrations * use them for local validation and type inference. */ get schema(): { pathParams: TPathParams; query: TQuery; headers: THeaders; body: TBody; responses: TResponses; }; /** * Response schemas keyed by HTTP status code. */ get responseSchemas(): TResponses; /** * URL path template for this contract. */ get path(): TPath; /** * Metadata consumed by hooks, OpenAPI generation, and app conventions. */ get metadata(): TMeta; /** * Plain contract config consumed by framework internals and integrations. */ get config(): HttpContractConfig; /** * Attach a schema for dynamic path parameters. * * The schema validates parameters parsed from path templates such as * `/posts/:id` or `/posts/[id]`. */ pathParams(schema: TNewPathParams): ContractBuilder; /** * Attach a query schema and the deterministic URL transport for its input. * * The schema owns validation, defaults, and transforms. The transport owns * client encoding, server decoding, and OpenAPI serialization. */ query(schema: TNewQuery, transport: TTransport & QueryTransportCompatibility, TTransport>): ContractBuilder; /** * Attach a schema for a JSON request body. * * This method is only available on POST, PUT, and PATCH contracts. */ body(this: ContractBuilder, schema: TNewBody): ContractBuilder; /** * Attach a request header schema. * * Multiple schemas are evaluated in declaration order and their parsed * outputs are merged. This lets a contract inherit shared group headers and * still declare route-specific headers. */ headers(schema: TNewHeaders): ContractBuilder; /** * Add or replace route-owned response schemas by status code. * * These schemas describe business responses returned by route handlers. * Framework-owned errors such as request validation failures do not need to be * declared here. * * Use `null` for void/empty responses such as 204 No Content. */ responses(responseSchemas: TNewResponses): ContractBuilder & TNewResponses, TMeta, TPath>; /** * Declare route-owned application errors from an error catalog. * * Catalog errors use Beignet's standard error response envelope and remain * distinguishable from framework-owned errors. Declarations merge with * previously declared catalog errors, including shared group errors; later * declarations win when the same catalog key is declared twice. Use * `.responses()` when a route needs a custom error response body instead of * catalog semantics. */ errors(errorDefs: TErrorDefs): ContractBuilder> & ResponsesFromErrorDefinitions, OmitMetaKeys & { errors: MergedContractErrorResponses; }, TPath>; /** * Merge metadata into this contract. * * Hooks and tooling can read metadata for concerns such as auth, rate limits, * idempotency, OpenAPI, or app-specific conventions. */ meta(newMeta: TNewMeta): ContractBuilder, TPath>; /** * Mark this contract as deprecated for external clients. */ deprecated(deprecation: TDeprecation): ContractBuilder, TPath>; /** * Merge OpenAPI operation metadata into this contract. */ openapi>(patch: TPatch): ContractBuilder, TPath>; } /** * Options for creating one contract with `defineContract(...)`. */ export type DefineContractOptions = { /** HTTP method (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS) */ method: TMethod; /** URL path template (e.g., "/api/users/:id") */ path: TPath; /** Optional contract name (auto-generated from method + path if not provided) */ name?: string; }; /** * Create a new HTTP contract builder. * * Most apps prefer `defineContractGroup().namespace(...).prefix(...)` for * related feature contracts. Use this lower-level factory when a standalone * contract is clearer. * * @example * ```ts * const getTodo = defineContract({ * method: "GET", * path: "/api/todos/:id", * }) * .pathParams(z.object({ id: z.string() })) * .responses({ 200: TodoSchema }); * ``` * * @param options - HTTP method, path template, and optional contract name. * @returns A fluent contract builder. */ export declare function defineContract(options: DefineContractOptions): ContractBuilder, ContractMeta, TPath>; //# sourceMappingURL=contract-builder.d.ts.map