import * as _sinclair_typebox from '@sinclair/typebox'; import { TypeBoxError, TSchema, StaticDecode, Kind, Static, SchemaOptions, StringOptions, TString, TTransform, ObjectOptions, TRecord, TLiteralValue, TLiteral, TObject } from '@sinclair/typebox'; import { ValueError } from '@sinclair/typebox/errors'; import { TypeCheck } from '@sinclair/typebox/compiler'; import { ValueError as ValueError$1 } from '@sinclair/typebox/value'; declare class TypeBoxDecodeEnvError extends TypeBoxError { readonly error: ValueError; constructor(message: string, error: ValueError); } /** * Create an object from environment variables. * * Function will clean, convert, default and decode the environment variables. * * Pulls the values from `process.env` by default. * * @example * const env = createEnv( * t.Object({ * APP_ENV: t.Optional(t.String()), * NODE_ENV: t.String({ default: "development" }), * BOOL_FLAG: t.Boolean(), * }), * ); */ declare function createEnv(schema: T, env?: Record): StaticDecode; declare function cacheCompile(schema: T, references?: TSchema[]): TypeCheck; type EnhanceErrorsOptions = { /** * Prefix to add to the path of each error. * * Useful if you want to avoid empty paths. */ prefix?: string; /** * Converts TypeBox's `/` based JSON path to a `.` based path. * * Uses {@link formatTypeBoxPath}. * * Dot-path notion is usually better supported in most libraries. */ formatPath?: boolean; /** * Convert error types to snake case. * * This is usually preferred for API responses. * * Implicitly sets `useTypeName` to `true`. * ``` * "ArrayMinItems" -> "array_min_items" * ``` */ snakeCaseType?: boolean; }; type EnhancedValueError = Omit & { type: string; }; /** * Apply various transformations to the errors, to improve the output. * @param errors - The errors to enhance. * @param opts - Options to customize the transformations. */ declare function enhanceErrors(errors: Iterable, opts?: EnhanceErrorsOptions): Generator; type BasicValueError = Omit; type MergedNumericValueError = BasicValueError & { errors: Record; }; type MergedStringValueError = BasicValueError & { errors: Record; }; type MergedValueError = BasicValueError & { errors: Record; }; /** * Merges multiple errors for a path into a single object per path, * with an array of errors, see {@link MergedValueError}. * * @param errors - The errors to merge. * @param stripEmptyPaths - Whether to strip errors with empty paths. */ declare function mergeErrors(errors: Iterable, stripEmptyPaths?: boolean): MergedNumericValueError[]; declare function mergeErrors(errors: Iterable, stripEmptyPaths?: boolean): MergedStringValueError[]; /** * Converts TypeBox's `/` based JSON path to a `.` based path. * * @example * formatTypeBoxPath("/a/b/c") // -> "a.b.c" */ declare function formatTypeBoxPath(path: string): string; interface TUnionOneOf extends TSchema { [Kind]: "UnionOneOf"; static: { [K in keyof T]: Static; }[number]; oneOf: T; } /** `[Experimental]` Creates a Union type with a `oneOf` schema representation */ declare function UnionOneOf(oneOf: [...T], options?: SchemaOptions): TUnionOneOf; interface TUnionEnum extends TSchema { [Kind]: "UnionEnum"; static: T[number]; enum: T; } /** `[Experimental]` Creates a Union type with a `enum` schema representation */ declare function UnionEnum(values: [...T], options?: SchemaOptions): TUnionEnum; declare function Nullable(schema: T): _sinclair_typebox.TUnion<[T, _sinclair_typebox.TNull]>; /** Creates a schema that allows `null` and `undefined` values. */ declare function Nullish(schema: T): _sinclair_typebox.TOptional<_sinclair_typebox.TUnion<[T, _sinclair_typebox.TNull]>>; declare function UUID(options?: StringOptions): TString; /** * Resulting schema object is a string with the `date-time` format, the typescript * type is of `Date`. * * Strings are coerced to dates during decode and stringify during encode. * If you do not use decode, the value will be a string. */ declare function DateString(options?: StringOptions): TTransform; /** * Creates a valid record map for OpenAPI 3.0, as it does not support * `patternProperties` which is what typebox uses for the default `Record` kind. */ declare function RecordString(schema: T, options?: ObjectOptions): TRecord; /** Creates a union of strings with a `enum` schema representation */ declare function StringEnum(values: [...T], options?: SchemaOptions): TUnionEnum; /** * Drop-in replacement for `t.Literal` that adds the `type` and `enum` properties, * for backwards compatibility with OpenAPI 3.0. * * You should override `Literal` with this function, for OpenAPI 3.0 compatibility. */ declare function LiteralEnum(value: T, options?: SchemaOptions): TLiteral; /** * Check if schema should be downgraded to OpenAPI 3.0. * * Should be run before `downgradeSchema` as a performance optimisation, to avoid having to partially clone * the schema and perform the downgrades. */ declare function shouldDowngradeSchema(schema: TSchema): boolean; /** * Downgrade schema to OpenAPI 3.0 nullable format. * * (performs a partial clone on the schema) */ declare function downgradeSchema(schema: T): T; declare function downgradeSchemaIfNeeded(schema: TSchema): TSchema; declare const t: _sinclair_typebox.JavaScriptTypeBuilder & { UnionOneOf: typeof UnionOneOf; UnionEnum: typeof UnionEnum; Nullable: typeof Nullable; Nullish: typeof Nullish; UUID: typeof UUID; DateString: typeof DateString; RecordString: typeof RecordString; StringEnum: typeof StringEnum; LiteralEnum: typeof LiteralEnum; }; type TParamSchema = { name: string; required: boolean; schema: Omit; description?: string; example?: any; examples?: any; }; /** Creates a parameter schema for OpenAPI from a JSON schema */ declare function getParamSchema(name: string, { description, example, examples, ...schema }: TSchema, required?: boolean): TParamSchema; /** Creates an array of parameter schemas for OpenAPI from a JSON schema */ declare function getParamSchemas(obj: TObject): TParamSchema[]; /** Check if the schema has an `id` property. */ declare function hasSchemaId(schema: TSchema): boolean; export { DateString, type EnhanceErrorsOptions, LiteralEnum, type MergedNumericValueError, type MergedStringValueError, type MergedValueError, Nullable, Nullish, RecordString, StringEnum, type TUnionEnum, type TUnionOneOf, TypeBoxDecodeEnvError, UUID, UnionEnum, UnionOneOf, cacheCompile, createEnv, downgradeSchema, downgradeSchemaIfNeeded, enhanceErrors, formatTypeBoxPath, getParamSchema, getParamSchemas, hasSchemaId, mergeErrors, shouldDowngradeSchema, t };