import type { EmbeddableSchema } from "./ir.js"; import { type NarrowContext, type Type as OmpType, type ToJsonSchemaOptions } from "./type.js"; export interface Meta { title?: string; description?: string; default?: unknown; examples?: unknown[]; [key: string]: unknown; } export interface StringOpts extends Meta { minLength?: number; maxLength?: number; pattern?: string; format?: string; } export interface NumberOpts extends Meta { minimum?: number; maximum?: number; exclusiveMinimum?: number; exclusiveMaximum?: number; multipleOf?: number; } export interface ArrayOpts extends Meta { minItems?: number; maxItems?: number; uniqueItems?: boolean; } export interface ObjectOpts extends Meta { additionalProperties?: boolean | AnySchema; } declare const OPTIONAL_INNER: unique symbol; declare const OBJECT_INFO: unique symbol; export interface TypeBoxValidationFailure { message: string; } export type TypeBoxSafeParseResult = { success: true; data: T; } | { success: false; error: TypeBoxValidationFailure; }; interface LegacyTypeBoxCompat { /** TypeBox compatibility validator used by legacy extension loaders. */ __validator(data: unknown): T | TypeBoxValidationFailure; /** Zod-style compatibility parser used by legacy extensions. */ safeParse(input: unknown): TypeBoxSafeParseResult; } /** * Erased schema surface accepted anywhere this facade takes a schema, native * omptype schemas included (those carry no legacy compat members). * * Members use method syntax so parameter positions stay bivariant: the typed * {@link TTyped} form is invariant in its static type (its `in`/`out` * validators are), so a concrete `TString` is not assignable to * `TTyped`. Erasing here is what keeps `TString`, `TObject<…>` and * friends assignable to a plain schema annotation. */ export interface AnySchema extends EmbeddableSchema { (data: unknown): unknown; readonly infer: unknown; readonly hasSteps: boolean; toJsonSchema(options?: ToJsonSchemaOptions): Record; } /** * Every schema this facade returns: the TypeBox `TSchema` analog. Erased like * {@link AnySchema}, plus the legacy compat members builder results carry. */ export interface TSchema extends AnySchema { /** TypeBox compatibility validator used by legacy extension loaders. */ __validator(data: unknown): unknown; /** Zod-style compatibility parser used by legacy extensions. */ safeParse(input: unknown): TypeBoxSafeParseResult; } /** Schema carrying a statically known type; every `TXxx` alias resolves here. */ export type TTyped = OmpType & LegacyTypeBoxCompat; export type Static = T["infer"]; export type TAny = TTyped; export type TUnknown = TTyped; export type TNever = TTyped; export type TNull = TTyped; export type TString = TTyped; export type TNumber = TTyped; export type TInteger = TTyped; export type TBoolean = TTyped; export type TLiteral = TTyped; export type TArray = TTyped[]>; export type TTuple = TTyped<{ -readonly [K in keyof E]: Static; }>; export type TOptional = TTyped | undefined> & { readonly [OPTIONAL_INNER]: E; }; export type TUnion = TTyped>; export type TIntersect = TTyped>>; export type TEnum = TTyped; export type TRecord = TTyped, PropertyKey>, Static>>; export type TNullable = TTyped | null>; export type TReadonly = TTyped>>; export type TUnsafe = TTyped; type OptionalKeys

> = { [K in keyof P]-?: P[K] extends { readonly [OPTIONAL_INNER]: AnySchema; } ? K : never; }[keyof P]; type RequiredKeys

> = Exclude>; type ObjectStatic

> = { [K in RequiredKeys

]: Static; } & { [K in OptionalKeys

]?: Exclude, undefined>; }; export type TObject

= Record> = TTyped>; type RequiredProps

> = { [K in keyof P]: P[K] extends TOptional ? E : P[K]; }; interface RuntimeType extends OmpType { [OPTIONAL_INNER]?: AnySchema; [OBJECT_INFO]?: ObjectInfo; describe(description: string): RuntimeType; default(value: T | (() => T)): RuntimeType; or(schema: schema): RuntimeType>; and(schema: schema): RuntimeType>; array(): RuntimeType; atLeastLength(bound: number): RuntimeType; atMostLength(bound: number): RuntimeType; atLeast(bound: number): RuntimeType; atMost(bound: number): RuntimeType; narrow(predicate: (value: T, ctx: NarrowContext) => value is N): RuntimeType; narrow(predicate: (value: T, ctx: NarrowContext) => boolean): RuntimeType; } type CompatRuntime = RuntimeType & LegacyTypeBoxCompat; type ObjectInfo = { props: Record; additionalProperties?: boolean | AnySchema; }; declare function tString(opts?: StringOpts): TString; declare function tLiteral(value: V, opts?: Meta): TLiteral; declare function tNever(opts?: Meta): TNever; declare function tUnion(schemas: E, opts?: Meta): TUnion; declare function tIntersect(schemas: E, opts?: Meta): TTyped>>; type UnionToIntersection = (U extends unknown ? (value: U) => void : never) extends (value: infer I) => void ? I : never; declare function tEnum | readonly (string | number)[]>(values: E, opts?: Meta): TTyped; declare function tArray(item: E, opts?: ArrayOpts): TArray; declare function tTuple(items: E, opts?: Meta): TTuple; declare function tObject>(properties: P, opts?: ObjectOpts): TObject

; declare function tRecord(key: K, value: V, opts?: Meta): TRecord; declare function tOptional(schema: E, opts?: Meta): TOptional; declare function tNullable(schema: E, opts?: Meta): TTyped | null>; declare function tPartial

>(schema: TObject

): TTyped>>; declare function tRequired

>(schema: TObject

): TObject>; declare function tPick

, const K extends readonly (keyof P)[]>(schema: TObject

, keys: K): TObject>; declare function tOmit

, const K extends readonly (keyof P)[]>(schema: TObject

, keys: K): TObject>; declare function tComposite>[]>(schemas: E, opts?: ObjectOpts): TTyped>>; declare function tUnsafe(_jsonSchema?: Record): TUnsafe; export declare const Type: { readonly String: typeof tString; readonly Number: (opts?: NumberOpts) => TNumber; readonly Integer: (opts?: NumberOpts) => TNumber; readonly Boolean: (opts?: Meta) => CompatRuntime; readonly Null: (opts?: Meta) => CompatRuntime; readonly Any: (opts?: Meta) => CompatRuntime; readonly Unknown: (opts?: Meta) => CompatRuntime; readonly Never: typeof tNever; readonly Literal: typeof tLiteral; readonly Union: typeof tUnion; readonly Intersect: typeof tIntersect; readonly Enum: typeof tEnum; readonly Array: typeof tArray; readonly Tuple: typeof tTuple; readonly Object: typeof tObject; readonly Record: typeof tRecord; readonly Optional: typeof tOptional; readonly Nullable: typeof tNullable; readonly Readonly: (schema: E) => TReadonly; readonly Partial: typeof tPartial; readonly Required: typeof tRequired; readonly Pick: typeof tPick; readonly Omit: typeof tOmit; readonly Composite: typeof tComposite; readonly Unsafe: typeof tUnsafe; }; export type TypeBuilder = typeof Type; declare const _default: { Type: { readonly String: typeof tString; readonly Number: (opts?: NumberOpts) => TNumber; readonly Integer: (opts?: NumberOpts) => TNumber; readonly Boolean: (opts?: Meta) => CompatRuntime; readonly Null: (opts?: Meta) => CompatRuntime; readonly Any: (opts?: Meta) => CompatRuntime; readonly Unknown: (opts?: Meta) => CompatRuntime; readonly Never: typeof tNever; readonly Literal: typeof tLiteral; readonly Union: typeof tUnion; readonly Intersect: typeof tIntersect; readonly Enum: typeof tEnum; readonly Array: typeof tArray; readonly Tuple: typeof tTuple; readonly Object: typeof tObject; readonly Record: typeof tRecord; readonly Optional: typeof tOptional; readonly Nullable: typeof tNullable; readonly Readonly: (schema: E) => TReadonly; readonly Partial: typeof tPartial; readonly Required: typeof tRequired; readonly Pick: typeof tPick; readonly Omit: typeof tOmit; readonly Composite: typeof tComposite; readonly Unsafe: typeof tUnsafe; }; }; export default _default;