UNPKG

@beignet/core

Version:

Core framework primitives for Beignet

38 lines 2.56 kB
import { type HttpContractConfig } from "../contracts/index.js"; import type { HttpResponse, HttpResponseHeaders, HttpResponseLike } from "./http.js"; import type { ResponseFinalizerResponseOwner } from "./internal-hooks.js"; export type ResponseOwner = ResponseFinalizerResponseOwner; export declare function errorResponse(status: number, code: string, message: string, details?: unknown): HttpResponseLike; export declare function normalizeResponse(res: HttpResponseLike): HttpResponseLike; export declare function isWebResponse(value: unknown): value is Response; export declare function normalizeHttpResponse(res: HttpResponse): HttpResponse; export declare function withFrameworkErrorOwnerHeader(res: HttpResponseLike, owner: ResponseOwner): HttpResponseLike; /** Apply contract-owned deprecation headers to any response representation. */ export declare function withContractLifecycleHeaders(res: HttpResponse, contract: HttpContractConfig): HttpResponse; export declare function responseOwnerFor(res: HttpResponse, owner?: ResponseOwner): ResponseOwner; export declare function responseForHooks(res: HttpResponse): HttpResponseLike; /** * Merge hook-applied header changes onto a native web Response. * * Starts from the native response's `Headers` so `set-cookie` multiplicity is * preserved, then applies headers the beforeSend chain added or changed * relative to the original headers-only view. The body stream passes through * untouched; status and statusText are preserved. */ export declare function mergeNativeResponseHeaders(nativeResponse: Response, originalHeaders: HttpResponseHeaders, finalHeaders: HttpResponseHeaders): Response; export declare function isHttpResponseLike(value: unknown): value is HttpResponseLike; export declare class ResponseContractViolationError extends Error { readonly code: "RESPONSE_VALIDATION_ERROR" | "UNDECLARED_RESPONSE_STATUS"; readonly details?: unknown; constructor(args: { code: "RESPONSE_VALIDATION_ERROR" | "UNDECLARED_RESPONSE_STATUS"; message: string; details?: unknown; }); } export declare function finalizeResponse<C extends HttpContractConfig>(contract: C, res: HttpResponseLike, responseValidationExemptStatus?: number, options?: { validateContract?: boolean; }): Promise<HttpResponseLike>; export declare function toContractViolationResponse(error: ResponseContractViolationError): HttpResponseLike; export declare function defaultErrorResponse(err: unknown, ctx?: unknown): HttpResponseLike; //# sourceMappingURL=response-finalization.d.ts.map