UNPKG

express-zod-api

Version:

A Typescript framework to help you get an API server up and running with I/O schema validation and custom middlewares in minutes.

80 lines (79 loc) 2.82 kB
import { D as ClientMethod, O as Method, f as Tag } from "./routing-BAxxZ1xA.js"; import { z } from "zod"; import { ReferenceObject, SchemaObjectValue, TagObject } from "openapi3-ts/oas32"; interface ReqResCommons { makeRef: (key: object | string, value: SchemaObjectValue | ReferenceObject, proposedName?: string) => ReferenceObject; path: string; method: ClientMethod; seenIds: Map<string, z.core.$ZodType>; } interface OpenAPIContext extends ReqResCommons { isResponse: boolean; } type Depicter = ( zodCtx: { zodSchema: z.core.$ZodType; jsonSchema: z.core.JSONSchema.BaseSchema; }, oasCtx: OpenAPIContext, ) => z.core.JSONSchema.BaseSchema | SchemaObjectValue; /** @desc Using defaultIsHeader when returns null or undefined */ type IsHeader = (name: string, method: ClientMethod, path: string) => boolean | null | undefined; type BrandHandling = Record<string | symbol, Depicter>; interface TagDetails extends Pick<TagObject, "summary" | "description" | "externalDocs" | "kind"> { /** @desc shorthand for externalDocs.url */ url?: string; parent?: Tag; } declare const depictTags: (tags: Partial<Record<Tag, string | TagDetails>>) => TagObject[]; /** @desc Ensures the summary string does not exceed the limit */ declare const trimSummary: (summary?: string, limit?: number) => string | undefined; /** @desc An error related to the wrong Routing declaration */ declare class RoutingError extends Error { name: string; readonly cause: { method: Method; path: string; }; constructor(message: string, method: Method, path: string); } /** * @desc An error related to the generating of the documentation * */ declare class DocumentationError extends Error { name: string; readonly cause: string; constructor(message: string, { method, path, isResponse }: Pick<OpenAPIContext, "path" | "method" | "isResponse">); } /** @desc An error related to the input and output schemas declaration */ declare class IOSchemaError extends Error { name: string; } /** @desc An error of validating the Endpoint handler's returns against the Endpoint output schema */ declare class OutputValidationError extends IOSchemaError { readonly cause: z.ZodError; name: string; constructor(cause: z.ZodError); } /** @desc An error of validating the input sources against the Middleware or Endpoint input schema */ declare class InputValidationError extends IOSchemaError { readonly cause: z.ZodError; name: string; constructor(cause: z.ZodError); } declare class MissingPeerError extends Error { name: string; constructor(module: string); } export { RoutingError as a, IsHeader as c, OutputValidationError as i, depictTags as l, InputValidationError as n, BrandHandling as o, MissingPeerError as r, Depicter as s, DocumentationError as t, trimSummary as u, };