@@uncurried @@warning("-30") type never module Path: { type t let empty: t let dynamic: t external toString: t => string = "%identity" let toArray: t => array let fromArray: array => t let fromLocation: string => t let concat: (t, t) => t } type numberFormat = | @as("int32") Int32 | @as("port") Port type format = numberFormat @unboxed type additionalItemsMode = | @as("strip") Strip | @as("strict") Strict type tag = | @as("string") String | @as("number") Number | @as("never") Never | @as("unknown") Unknown | @as("bigint") BigInt | @as("boolean") Boolean | @as("symbol") Symbol | @as("null") Null | @as("undefined") Undefined | @as("nan") NaN | @as("function") Function | @as("instance") Instance | @as("array") Array | @as("object") Object | @as("union") Union | @as("json") JSON @tag("type") type rec t<'value> = private | @as("never") Never({name?: string, title?: string, description?: string, deprecated?: bool}) | @as("unknown") Unknown({ name?: string, description?: string, title?: string, deprecated?: bool, examples?: array, }) | @as("string") String({ const?: string, name?: string, title?: string, description?: string, deprecated?: bool, examples?: array, }) | @as("number") Number({ const?: float, format?: numberFormat, name?: string, title?: string, description?: string, deprecated?: bool, examples?: array, }) | @as("bigint") BigInt({ const?: bigint, name?: string, title?: string, description?: string, deprecated?: bool, examples?: array, }) | @as("boolean") Boolean({ const?: bool, name?: string, title?: string, description?: string, deprecated?: bool, examples?: array, }) | @as("symbol") Symbol({ const?: Js.Types.symbol, name?: string, title?: string, description?: string, deprecated?: bool, examples?: array, }) | @as("null") Null({ const: Js.Types.null_val, name?: string, title?: string, description?: string, deprecated?: bool, }) | @as("undefined") Undefined({ const: unit, name?: string, title?: string, description?: string, deprecated?: bool, }) | @as("nan") NaN({ const: float, name?: string, title?: string, description?: string, deprecated?: bool, }) | @as("function") Function({ const?: Js.Types.function_val, name?: string, title?: string, description?: string, deprecated?: bool, examples?: array, }) | @as("instance") Instance({ class: unknown, const?: Js.Types.obj_val, name?: string, title?: string, description?: string, deprecated?: bool, examples?: array, }) | @as("array") Array({ items: array, additionalItems: additionalItems, unnest?: bool, name?: string, title?: string, description?: string, deprecated?: bool, examples?: array>, }) | @as("object") Object({ items: array, fields: dict, additionalItems: additionalItems, name?: string, title?: string, description?: string, deprecated?: bool, examples?: array>, }) | @as("union") Union({ anyOf: array>, has: has, name?: string, title?: string, description?: string, deprecated?: bool, examples?: array, }) | @as("json") JSON({ name?: string, title?: string, description?: string, deprecated?: bool, examples?: array, }) and schema<'a> = t<'a> and meta<'value> = { name?: string, title?: string, description?: string, deprecated?: bool, examples?: array<'value>, } and untagged = private { @as("type") tag: tag, const?: unknown, class?: unknown, format?: format, name?: string, title?: string, description?: string, deprecated?: bool, examples?: array, unnest?: bool, noValidation?: bool, items?: array, fields?: dict, additionalItems?: additionalItems, anyOf?: array>, has?: dict, } @unboxed and additionalItems = | ...additionalItemsMode | Schema(t) and item = { schema: t, location: string, inlinedLocation: string, } and has = { string?: bool, number?: bool, never?: bool, unknown?: bool, bigint?: bool, boolean?: bool, symbol?: bool, null?: bool, undefined?: bool, nan?: bool, function?: bool, instance?: bool, array?: bool, object?: bool, } and flag and error = private { message: string, reason: string, path: Path.t, code: errorCode, flag: flag, } and errorCode = | OperationFailed(string) | InvalidOperation({description: string}) | InvalidType({expected: schema, received: unknown, unionErrors?: array}) | ExcessField(string) | UnexpectedAsync | InvalidJsonSchema(schema) type exn += private Error(error) type s<'value> = { schema: t<'value>, fail: 'a. (string, ~path: Path.t=?) => 'a, } module Flag: { @inline let none: flag @inline let typeValidation: flag @inline let async: flag @inline let assertOutput: flag @inline let jsonableOutput: flag @inline let jsonStringOutput: flag @inline let reverse: flag external with: (flag, flag) => flag = "%orint" let has: (flag, flag) => bool } let never: t let unknown: t let unit: t let nullAsUnit: t let string: t let bool: t let int: t let float: t let bigint: t let symbol: t let json: (~validate: bool) => t let literal: 'value => t<'value> let array: t<'value> => t> let unnest: t<'value> => t> let list: t<'value> => t> let instance: unknown => t let dict: t<'value> => t> let option: t<'value> => t> let null: t<'value> => t> let nullable: t<'value> => t> let nullableAsOption: t<'value> => t> let jsonString: (t<'value>, ~space: int=?) => t<'value> let union: array> => t<'value> let enum: array<'value> => t<'value> let meta: (t<'value>, meta<'value>) => t<'value> module Catch: { type s<'value> = { @as("e") error: error, @as("i") input: unknown, @as("s") schema: t<'value>, @as("f") fail: 'a. (string, ~path: Path.t=?) => 'a, } } let catch: (t<'value>, Catch.s<'value> => 'value) => t<'value> type transformDefinition<'input, 'output> = { @as("p") parser?: 'input => 'output, @as("a") asyncParser?: 'input => promise<'output>, @as("s") serializer?: 'output => 'input, } let transform: (t<'input>, s<'output> => transformDefinition<'input, 'output>) => t<'output> let refine: (t<'value>, s<'value> => 'value => unit) => t<'value> let shape: (t<'value>, 'value => 'shape) => t<'shape> let to: (t<'from>, t<'to>) => t<'to> type rec input<'value, 'computed> = | @as("Output") Value: input<'value, 'value> | @as("Input") Unknown: input<'value, unknown> | Any: input<'value, 'any> | Json: input<'value, Js.Json.t> | JsonString: input<'value, string> type rec output<'value, 'computed> = | @as("Output") Value: output<'value, 'value> | @as("Input") Unknown: output<'value, unknown> | Assert: output<'value, unit> | Json: output<'value, Js.Json.t> | JsonString: output<'value, string> type rec mode<'output, 'computed> = | Sync: mode<'output, 'output> | Async: mode<'output, promise<'output>> let compile: ( t<'value>, ~input: input<'value, 'input>, ~output: output<'value, 'transformedOutput>, ~mode: mode<'transformedOutput, 'output>, ~typeValidation: bool=?, ) => 'input => 'output let parseOrThrow: ('any, t<'value>) => 'value let parseJsonOrThrow: (Js.Json.t, t<'value>) => 'value let parseJsonStringOrThrow: (string, t<'value>) => 'value let parseAsyncOrThrow: ('any, t<'value>) => promise<'value> let convertOrThrow: ('any, t<'value>) => 'value let convertToJsonOrThrow: ('any, t<'value>) => Js.Json.t let convertToJsonStringOrThrow: ('any, t<'value>) => string let convertAsyncOrThrow: ('any, t<'value>) => promise<'value> let reverseConvertOrThrow: ('value, t<'value>) => unknown let reverseConvertToJsonOrThrow: ('value, t<'value>) => Js.Json.t let reverseConvertToJsonStringOrThrow: ('value, t<'value>, ~space: int=?) => string let assertOrThrow: ('any, t<'value>) => unit let isAsync: t<'value> => bool let recursive: (t<'value> => t<'value>) => t<'value> let noValidation: (t<'value>, bool) => t<'value> let toExpression: t<'value> => string external toUnknown: t<'any> => t = "%identity" external untag: t<'any> => untagged = "%identity" module Schema: { type s = {@as("m") matches: 'value. t<'value> => 'value} } let schema: (Schema.s => 'value) => t<'value> module Object: { type rec s = { @as("f") field: 'value. (string, t<'value>) => 'value, fieldOr: 'value. (string, t<'value>, 'value) => 'value, tag: 'value. (string, 'value) => unit, nested: string => s, flatten: 'value. t<'value> => 'value, } } let object: (Object.s => 'value) => t<'value> let strip: t<'value> => t<'value> let deepStrip: t<'value> => t<'value> let strict: t<'value> => t<'value> let deepStrict: t<'value> => t<'value> module Tuple: { type s = { item: 'value. (int, t<'value>) => 'value, tag: 'value. (int, 'value) => unit, } } let tuple: (Tuple.s => 'value) => t<'value> let tuple1: t<'value> => t<'value> let tuple2: (t<'v1>, t<'v2>) => t<('v1, 'v2)> let tuple3: (t<'v1>, t<'v2>, t<'v3>) => t<('v1, 'v2, 'v3)> module Option: { type default = Value(unknown) | Callback(unit => unknown) let default: t<'value> => option let getOr: (t>, 'value) => t<'value> let getOrWith: (t>, unit => 'value) => t<'value> } module String: { module Refinement: { type kind = | Min({length: int}) | Max({length: int}) | Length({length: int}) | Email | Uuid | Cuid | Url | Pattern({re: Js.Re.t}) | Datetime type t = { kind: kind, message: string, } } let refinements: t<'value> => array } module Int: { module Refinement: { type kind = | Min({value: int}) | Max({value: int}) type t = { kind: kind, message: string, } } let refinements: t<'value> => array } module Float: { module Refinement: { type kind = | Min({value: float}) | Max({value: float}) type t = { kind: kind, message: string, } } let refinements: t<'value> => array } module Array: { module Refinement: { type kind = | Min({length: int}) | Max({length: int}) | Length({length: int}) type t = { kind: kind, message: string, } } let refinements: t<'value> => array } module Metadata: { module Id: { type t<'metadata> let make: (~namespace: string, ~name: string) => t<'metadata> } let get: (t<'value>, ~id: Id.t<'metadata>) => option<'metadata> let set: (t<'value>, ~id: Id.t<'metadata>, 'metadata) => t<'value> } let reverse: t<'value> => t module ErrorClass: { type t let value: t let constructor: (~code: errorCode, ~flag: flag, ~path: Path.t) => error } // ============= // Built-in refinements // ============= let min: (t<'value>, int, ~message: string=?) => t<'value> let floatMin: (t, float, ~message: string=?) => t let max: (t<'value>, int, ~message: string=?) => t<'value> let floatMax: (t, float, ~message: string=?) => t let length: (t<'value>, int, ~message: string=?) => t<'value> let port: (t, ~message: string=?) => t let email: (t, ~message: string=?) => t let uuid: (t, ~message: string=?) => t let cuid: (t, ~message: string=?) => t let url: (t, ~message: string=?) => t let pattern: (t, Js.Re.t, ~message: string=?) => t let datetime: (t, ~message: string=?) => t let trim: t => t let toJSONSchema: t<'value> => JSONSchema.t let fromJSONSchema: JSONSchema.t => t let extendJSONSchema: (t<'value>, JSONSchema.t) => t<'value> type globalConfigOverride = { defaultAdditionalItems?: additionalItemsMode, disableNanNumberValidation?: bool, } let global: globalConfigOverride => unit // ============= // JS/TS API // ============= @tag("success") type jsResult<'value> let js_safe: (unit => 'v) => jsResult<'v> let js_safeAsync: (unit => promise<'v>) => promise> let js_union: array => t<'value> let js_optional: (t<'v>, option) => t> let js_nullable: (t<'v>, option) => t> let js_asyncParserRefine: (t<'output>, ('output, s<'output>) => promise) => t<'output> let js_refine: (t<'output>, ('output, s<'output>) => unit) => t<'output> let js_transform: ( t<'output>, ~parser: ('output, s<'transformed>) => 'transformed=?, ~serializer: ('transformed, s<'transformed>) => 'output=?, ) => t<'transformed> let js_schema: unknown => t let js_merge: (t, t) => t