/** * RFC 3339 `date` / `time` / `date-time` / `duration` format validators. * * @packageDocumentation */ /** * RFC 3339 `full-date` (e.g. `"2024-01-31"`). * * @public */ declare function validateDate(value: string): boolean; /** * RFC 3339 `full-time` (e.g. `"12:34:56Z"` or `"12:34:56+02:00"`). * * @public */ declare function validateTime(value: string): boolean; /** * RFC 3339 `date-time` (e.g. `"2024-01-31T12:34:56Z"`). * * @public */ declare function validateDateTime(value: string): boolean; /** * ISO 8601 `duration` (e.g. `"P1Y2M10DT2H30M"`). * * @public */ declare function validateDuration(value: string): boolean; /** * Email format validators. These are pragmatic; the full RFC 5321 grammar * is enormous and most real-world "email validators" reject too few * strings. We allow any ASCII local-part + a sensible domain. * * @packageDocumentation */ /** * RFC 5321-ish `email` (ASCII). * * @public */ declare function validateEmail(value: string): boolean; /** * RFC 6531 internationalized `email`. * * @public */ declare function validateIdnEmail(value: string): boolean; /** * RFC 1123 / RFC 5890 hostname format validators. * * @packageDocumentation */ /** * RFC 1123 `hostname` (ASCII). Maximum 253 chars; each label 1-63 chars; * letters, digits, hyphens; no leading/trailing hyphen. * * @public */ declare function validateHostname(value: string): boolean; /** * RFC 5890 internationalized `hostname`. Same rules as {@link validateHostname} * after punycoding each label: accepts any non-empty label of unicode * letters, digits, and hyphens, 1-63 code points each. * * @public */ declare function validateIdnHostname(value: string): boolean; /** * IPv4 / IPv6 format validators. * * @packageDocumentation */ /** * RFC 2673 `ipv4` (e.g. `"192.168.1.1"`). * * @public */ declare function validateIpv4(value: string): boolean; /** * RFC 4291 `ipv6` (e.g. `"2001:db8::1"`). Supports compressed forms and * embedded IPv4 (e.g. `"::ffff:192.0.2.1"`). * * @public */ declare function validateIpv6(value: string): boolean; /** * Miscellaneous format validators: regex, uuid. * * @packageDocumentation */ /** * RFC 4122 `uuid`. * * @public */ declare function validateUuid(value: string): boolean; /** * ECMA 262 `regex`: the value must compile as a JavaScript regular * expression with the `u` flag (per JSON Schema 2020-12 recommendation). * * Standalone utility. The schema compiler registers its own `regex` * format inside `createDeps` so it shares the `regexCompiler` hook * with the `pattern` keyword; this function is not wired into * `builtInFormats`. Reach for it directly when you want u-mode * strictness independent of whatever compiler is configured. * * @public */ declare function validateRegex(value: string): boolean; /** * RFC 3986 (URI) and RFC 3987 (IRI) format validators. * * @packageDocumentation */ /** * RFC 3986 absolute `uri`. * * @public */ declare function validateUri(value: string): boolean; /** * RFC 3986 `uri-reference` (absolute or relative). * * @public */ declare function validateUriReference(value: string): boolean; /** * RFC 3987 `iri`. Accepts unicode characters in paths and fragments. * * @public */ declare function validateIri(value: string): boolean; /** * RFC 3987 `iri-reference` (absolute or relative IRI). * * @public */ declare function validateIriReference(value: string): boolean; /** * RFC 6570 `uri-template` (e.g. `"/pets/{id}"`, `"/search{?q,page}"`). * * @public */ declare function validateUriTemplate(value: string): boolean; /** * RFC 6901 `json-pointer`. * * @public */ declare function validateJsonPointer(value: string): boolean; /** * draft `relative-json-pointer`. * * @public */ declare function validateRelativeJsonPointer(value: string): boolean; /** * Every built-in format validator, keyed by its JSON Schema format name. * Hand to {@link @oav/schema!compileSchema#formats | compileSchema's formats * option} to get out-of-the-box format validation. * * `regex` is intentionally absent: `@oav/schema` registers its own * `regex` validator inside `createDeps` so it routes through the same * compiler as the `pattern` keyword (and honors the `regexCompiler` * option). Override by setting `formats: { regex: yourFn, ... }` if you * want a different policy. * * @public * * @example * ```ts * compileSchema(mySchema, { dialect: jsonSchemaDialect, formats: builtInFormats }); * ``` */ declare const builtInFormats: Record boolean>; /** * An Ajv-shaped format definition: `{ type, validate }`. oav's * `format` keyword only applies to string values (per JSON Schema * 2020-12 ยง6.3), so `type` is carried for shape compatibility but * not acted on; non-string values skip format validation regardless. * * Ajv's adjacent `async` / `compare` fields aren't used by oav and * are ignored by {@link fromAjvFormats}. * * @public */ interface AjvFormatDef { type?: "string" | "number"; validate: (value: unknown) => boolean; } /** * Convert a map of Ajv-shaped format definitions to the plain * predicate shape oav's `formats` option expects. One-way; pass the * result straight into `createValidator` / `compileSchema`. * * Main audience: migrants from `ajv-formats` or * `express-openapi-validator`'s `formats` option, who already have a * `Record` lying around and would * otherwise hand-roll the three-line conversion on every project. * * Non-boolean truthy returns from the source validator are coerced * to `true` (some adapter packages in the wild return `1` / strings). * * @public * * @example * ```ts * import { createValidator } from "@aahoughton/oav"; * import { fromAjvFormats } from "@aahoughton/oav/formats"; * * const validator = createValidator(spec, { * formats: fromAjvFormats(myAjvFormats), * }); * ``` */ declare function fromAjvFormats(defs: Record): Record boolean>; export { type AjvFormatDef, builtInFormats, fromAjvFormats, validateDate, validateDateTime, validateDuration, validateEmail, validateHostname, validateIdnEmail, validateIdnHostname, validateIpv4, validateIpv6, validateIri, validateIriReference, validateJsonPointer, validateRegex, validateRelativeJsonPointer, validateTime, validateUri, validateUriReference, validateUriTemplate, validateUuid };