import type { StandardSchemaV1 } from "./standard-schema.ts"; /** The Standard Typed interface. This is a base type extended by other specs. */ export interface StandardTypedV1 { /** The Standard properties. */ readonly "~standard": StandardTypedV1.Props; } export declare namespace StandardTypedV1 { /** The Standard Typed properties interface. */ export interface Props { /** The version number of the standard. */ readonly version: 1; /** The vendor name of the schema library. */ readonly vendor: string; /** Inferred types associated with the schema. */ readonly types?: Types | undefined; } /** The Standard Typed types interface. */ export interface Types { /** The input type of the schema. */ readonly input: Input; /** The output type of the schema. */ readonly output: Output; } /** Infers the input type of a Standard Typed. */ export type InferInput = NonNullable< Schema["~standard"]["types"] >["input"]; /** Infers the output type of a Standard Typed. */ export type InferOutput = NonNullable< Schema["~standard"]["types"] >["output"]; } /** The Standard JSON Schema interface. */ export interface StandardJSONSchemaV1 { /** The Standard JSON Schema properties. */ readonly "~standard": StandardJSONSchemaV1.Props; } export declare namespace StandardJSONSchemaV1 { /** The Standard JSON Schema properties interface. */ export interface Props extends StandardTypedV1.Props< Input, Output > { /** Methods for generating the input/output JSON Schema. */ readonly jsonSchema: StandardJSONSchemaV1.Converter; } /** The Standard JSON Schema converter interface. */ export interface Converter { /** Converts the input type to JSON Schema. May throw if conversion is not supported. */ readonly input: (options: StandardJSONSchemaV1.Options) => Record; /** Converts the output type to JSON Schema. May throw if conversion is not supported. */ readonly output: (options: StandardJSONSchemaV1.Options) => Record; } /** * The target version of the generated JSON Schema. * * `openapi-3.0` is a best-effort target for OpenAPI 3.0 schema objects. */ export type Target = "draft-2020-12" | "draft-07" | "openapi-3.0" | ({} & string); /** The options for the input/output methods. */ export interface Options { /** Specifies the target version of the generated JSON Schema. */ readonly target: Target; /** Explicit support for additional vendor-specific parameters, if needed. */ readonly libraryOptions?: Record | undefined; } /** The Standard types interface. */ export interface Types extends StandardTypedV1.Types< Input, Output > {} /** Infers the input type of a Standard JSON Schema. */ export type InferInput = StandardTypedV1.InferInput; /** Infers the output type of a Standard JSON Schema. */ export type InferOutput = StandardTypedV1.InferOutput; } export type CombinedSchemaV1 = StandardSchemaV1 & StandardJSONSchemaV1; export type JsonSchemaDirection = "input" | "output"; export function isStandardJSONSchema(value: unknown): value is StandardJSONSchemaV1 { const maybeStandard = (value as { "~standard"?: StandardJSONSchemaV1["~standard"] } | null)?.[ "~standard" ]; return ( typeof value === "object" && value !== null && typeof maybeStandard?.jsonSchema?.input === "function" && typeof maybeStandard?.jsonSchema?.output === "function" ); } export function materializeStandardJSONSchema( schema: StandardJSONSchemaV1, direction: JsonSchemaDirection, options: StandardJSONSchemaV1.Options, ): Record { return direction === "input" ? schema["~standard"].jsonSchema.input(options) : schema["~standard"].jsonSchema.output(options); }