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.
30 lines (29 loc) • 1.83 kB
TypeScript
import { Node, Schema, type ISchemaOptions, type StrictOptions, type WalkOptions } from "../schema/schema";
import type { Merge, Static, StaticCoerced } from "../static";
export type StaticUnion2<T extends Schema[]> = T extends [
infer U,
...infer Rest
] ? U extends Schema ? Rest extends Schema[] ? StaticUnion<Rest> | Static<U> : Static<U> : never : never;
export type StaticUnion<T extends Schema[]> = {
[K in keyof T]: T[K] extends Schema ? Static<T[K]> : never;
}[number];
export type StaticUnionCoerced<T extends Schema[]> = {
[K in keyof T]: T[K] extends Schema ? StaticCoerced<T[K]> : never;
}[number];
export type StaticUnionCoercedOptions<O extends ISchemaOptions, T extends Schema[]> = O extends {
coerce: (...args: any[]) => infer C;
} ? C : T extends [infer U, ...infer Rest] ? U extends Schema ? Rest extends Schema[] ? StaticUnionCoerced<Rest> | StaticCoerced<U> : StaticCoerced<U> : never : never;
export interface IUnionOptions extends ISchemaOptions {
}
declare const unionTypeSymbol: unique symbol;
export declare class UnionSchema<T extends Schema[]> extends Schema<IUnionOptions, StaticUnion<T>, StaticUnionCoercedOptions<IUnionOptions, T>> {
[unionTypeSymbol]: "oneOf" | "anyOf";
constructor(schemas: T, type: "oneOf" | "anyOf", options?: IUnionOptions);
get schemas(): any;
children(opts?: WalkOptions): Node[];
}
export declare const anyOf: <const T extends Schema[], const O extends IUnionOptions>(schemas: T, options?: StrictOptions<IUnionOptions, O>) => Schema<O, StaticUnion<T>, StaticUnionCoercedOptions<O, T>> & Merge<O & {
anyOf: T;
}>;
export declare const oneOf: <const T extends Schema[], const O extends IUnionOptions>(schemas: T, options?: StrictOptions<IUnionOptions, O>) => Schema<O, StaticUnion<T>, StaticUnionCoercedOptions<O, T>> & O;
export {};