UNPKG

jsonv-ts

Version:

JSON Schema builder and validator for TypeScript with static type inference, Hono middleware for OpenAPI generation and validation, and MCP server/client implementation. Lightweight, dependency-free, and built on Web Standards.

32 lines (31 loc) 1.27 kB
import type { Context, Env, Input, ValidationTargets } from "hono"; import type { BlankEnv, MiddlewareHandler } from "hono/types"; import type { Static, StaticCoerced, RemoveUnknownAdditionalProperties, Simplify, Schema } from "jsonv-ts"; export type Options = { coerce?: boolean; dropUnknown?: boolean; includeSchema?: boolean; skipOpenAPI?: boolean; }; type ValidationResult = { valid: boolean; errors: { keywordLocation: string; instanceLocation: string; error: string; data?: unknown; }[]; }; export type Hook<T, E extends Env, P extends string> = (result: { result: ValidationResult; data: T; }, c: Context<E, P>) => Response | Promise<Response> | void; export declare const validator: <S extends Schema, Target extends keyof ValidationTargets, P extends string, E extends Env = BlankEnv, Opts extends Options = Options, Out = Opts extends { coerce: false; } ? Static<S> : StaticCoerced<S>, I extends Input = { in: { [K in Target]: Static<S>; }; out: { [K in Target]: Opts extends { dropUnknown: true; } ? Simplify<RemoveUnknownAdditionalProperties<Out>> : Out; }; }>(target: Target, schema: S, options?: Opts, hook?: Hook<Out, E, P>) => MiddlewareHandler<E, P, I>; export {};