@hookform/resolvers
Version:
React Hook Form validation resolvers: Yup, Joi, Superstruct, Zod, Vest, Class Validator, io-ts, Nope, computed-types, TypeBox, arktype, Typanion and Effect-TS
1 lines • 396 kB
Source Map (JSON)
{"version":3,"file":"arktype.modern.mjs","sources":["../../node_modules/.pnpm/@arktype+util@0.0.44/node_modules/@arktype/util/out/arrays.js","../../node_modules/.pnpm/@arktype+util@0.0.44/node_modules/@arktype/util/out/errors.js","../../node_modules/.pnpm/@arktype+util@0.0.44/node_modules/@arktype/util/out/flatMorph.js","../../node_modules/.pnpm/@arktype+util@0.0.44/node_modules/@arktype/util/out/records.js","../../node_modules/.pnpm/@arktype+util@0.0.44/node_modules/@arktype/util/out/functions.js","../../node_modules/.pnpm/@arktype+util@0.0.44/node_modules/@arktype/util/out/domain.js","../../node_modules/.pnpm/@arktype+util@0.0.44/node_modules/@arktype/util/out/objectKinds.js","../../node_modules/.pnpm/@arktype+util@0.0.44/node_modules/@arktype/util/out/primitive.js","../../node_modules/.pnpm/@arktype+util@0.0.44/node_modules/@arktype/util/out/registry.js","../../node_modules/.pnpm/@arktype+util@0.0.44/node_modules/@arktype/util/out/compilation.js","../../node_modules/.pnpm/@arktype+util@0.0.44/node_modules/@arktype/util/out/hkt.js","../../node_modules/.pnpm/@arktype+util@0.0.44/node_modules/@arktype/util/out/numericLiterals.js","../../node_modules/.pnpm/@arktype+util@0.0.44/node_modules/@arktype/util/out/serialize.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/shared/utils.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/shared/implement.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/config.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/shared/errors.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/shared/traversal.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/node.js","../../node_modules/.pnpm/@arktype+util@0.0.44/node_modules/@arktype/util/out/clone.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/shared/disjoint.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/shared/intersections.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/constraint.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/predicate.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/refinements/divisor.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/refinements/range.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/refinements/after.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/refinements/before.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/refinements/exactLength.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/refinements/max.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/refinements/maxLength.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/refinements/kinds.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/refinements/min.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/refinements/minLength.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/refinements/regex.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/roots/root.js","../../node_modules/.pnpm/@arktype+util@0.0.44/node_modules/@arktype/util/out/strings.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/roots/utils.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/roots/alias.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/roots/basis.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/roots/domain.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/shared/declare.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/roots/intersection.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/roots/morph.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/roots/proto.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/roots/union.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/roots/unit.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/structure/index.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/structure/prop.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/structure/optional.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/structure/required.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/structure/sequence.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/structure/shared.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/structure/structure.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/kinds.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/module.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/parse.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/shared/compile.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/scope.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/generic.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/keywords/tsKeywords.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/keywords/internal.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/keywords/jsObjects.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/keywords/utils/regex.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/keywords/parsing.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/keywords/utils/date.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/keywords/utils/ip.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/keywords/validation.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/keywords/utils/creditCard.js","../../node_modules/.pnpm/@arktype+schema@0.1.6/node_modules/@arktype/schema/out/keywords/keywords.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/generic.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/parser/string/shift/scanner.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/parser/objectLiteral.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/parser/string/reduce/shared.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/parser/string/shift/operand/genericArgs.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/parser/string/shift/operand/unenclosed.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/parser/tuple.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/parser/definition.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/parser/string/shift/operand/date.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/parser/string/shift/operator/bounds.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/parser/string/shift/operator/divisor.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/parser/string/shift/operator/operator.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/parser/generic.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/parser/string/shift/operand/enclosed.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/parser/string/shift/operand/operand.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/parser/semantic/validate.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/parser/string/string.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/parser/string/reduce/dynamic.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/type.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/scope.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/match.js","../../node_modules/.pnpm/arktype@2.0.0-dev.14/node_modules/arktype/out/ark.js","../src/arktype.ts"],"sourcesContent":["export const getPath = (root, path) => {\n let result = root;\n for (const segment of path) {\n if (typeof result !== \"object\" || result === null)\n return undefined;\n result = result[segment];\n }\n return result;\n};\nexport const intersectUniqueLists = (l, r) => {\n const intersection = [...l];\n for (const item of r)\n if (!l.includes(item))\n intersection.push(item);\n return intersection;\n};\nexport const arrayFrom = (data) => (Array.isArray(data) ? data : [data]);\nexport const spliterate = (list, by) => {\n const result = [[], []];\n for (const item of list) {\n if (by(item))\n result[0].push(item);\n else\n result[1].push(item);\n }\n return result;\n};\nexport const ReadonlyArray = Array;\nexport const includes = (array, element) => array.includes(element);\nexport const range = (length, offset = 0) => [...new Array(length)].map((_, i) => i + offset);\n/**\n * Adds a value or array to an array, returning the concatenated result\n *\n * @param to The array to which `value` is to be added. If `to` is `undefined`, a new array\n * is created as `[value]` if value was not undefined, otherwise `[]`.\n * @param value The value to add to the array. If `value` is `undefined`, does nothing.\n * @param opts\n * \t\tprepend: If true, adds the element to the beginning of the array instead of the end\n */\nexport const append = (to, value, opts) => {\n if (value === undefined)\n return to ?? [];\n if (to === undefined) {\n return (value === undefined ? []\n : Array.isArray(value) ? value\n : [value]);\n }\n if (opts?.prepend)\n Array.isArray(value) ? to.unshift(...value) : to.unshift(value);\n else\n Array.isArray(value) ? to.push(...value) : to.push(value);\n return to;\n};\n/**\n * Concatenates an element or list with a readonly list\n *\n * @param {to} to - The base list.\n * @param {elementOrList} elementOrList - The element or list to concatenate.\n */\nexport const conflatenate = (to, elementOrList) => {\n if (elementOrList === undefined || elementOrList === null)\n return to ?? [];\n if (to === undefined || to === null)\n return arrayFrom(elementOrList);\n return to.concat(elementOrList);\n};\n/**\n * Concatenates a variadic list of elements or lists with a readonly list\n *\n * @param {to} to - The base list.\n * @param {elementsOrLists} elementsOrLists - The elements or lists to concatenate.\n */\nexport const conflatenateAll = (...elementsOrLists) => elementsOrLists.reduce(conflatenate, []);\n/**\n * Appends a value to an array if it is not already included, returning the array\n *\n * @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array\n * is created including only `value`.\n * @param value The value to append to the array. If `to` includes `value`, nothing is appended.\n */\nexport const appendUnique = (to, value) => {\n if (to === undefined)\n return [value];\n if (!to.includes(value))\n to.push(value);\n return to;\n};\nexport const groupBy = (array, discriminant) => array.reduce((result, item) => {\n const key = item[discriminant];\n result[key] ??= [];\n result[key].push(item);\n return result;\n}, {});\n","export class InternalArktypeError extends Error {\n}\nexport const throwInternalError = message => throwError(message, InternalArktypeError);\nexport const throwError = (message, ctor = Error) => {\n throw new ctor(message);\n};\nexport class ParseError extends Error {\n name = \"ParseError\";\n}\nexport const throwParseError = message => throwError(message, ParseError);\n","// eslint-disable-next-line prefer-arrow-functions/prefer-arrow-functions\nexport function flatMorph(o, flatMapEntry) {\n const inputIsArray = Array.isArray(o);\n const entries = Object.entries(o).flatMap((entry, i) => {\n const result = inputIsArray ? flatMapEntry(i, entry[1]) : flatMapEntry(...entry, i);\n const entrySet = Array.isArray(result[0]) || result.length === 0 ?\n // if we have an empty array (for filtering) or an array with\n // another array as its first element, treat it as a list of\n result\n // otherwise, it should be a single entry, so nest it in a tuple\n // so it doesn't get spread when the result is flattened\n : [result];\n return entrySet;\n });\n const objectResult = Object.fromEntries(entries);\n return typeof entries[0]?.[0] === \"number\" ?\n Object.values(objectResult)\n : objectResult;\n}\n","import { flatMorph } from \"./flatMorph.js\";\nexport const entriesOf = (o) => Object.entries(o);\nexport const fromEntries = (entries) => Object.fromEntries(entries);\nexport const keysOf = (o) => Object.keys(o);\nexport const isKeyOf = (k, o) => k in o;\nexport const hasKey = (o, k) => k in o;\n// must be defined this way to avoid https://github.com/microsoft/TypeScript/issues/55049\nexport const hasDefinedKey = (o, k) => o[k] !== undefined;\nexport const InnerDynamicBase = class {\n constructor(properties) {\n Object.assign(this, properties);\n }\n};\n/** @ts-expect-error (needed to extend `t`, but safe given ShallowClone's implementation) **/\nexport class DynamicBase extends InnerDynamicBase {\n}\nexport const NoopBase = class {\n};\n/** @ts-expect-error (see DynamicBase) **/\nexport class CastableBase extends NoopBase {\n}\nexport const splitByKeys = (o, leftKeys) => {\n const l = {};\n const r = {};\n let k;\n for (k in o) {\n if (k in leftKeys)\n l[k] = o[k];\n else\n r[k] = o[k];\n }\n return [l, r];\n};\nexport const pick = (o, keys) => splitByKeys(o, keys)[0];\nexport const omit = (o, keys) => splitByKeys(o, keys)[1];\nexport const isEmptyObject = (o) => Object.keys(o).length === 0;\nexport const stringAndSymbolicEntriesOf = (o) => [\n ...Object.entries(o),\n ...Object.getOwnPropertySymbols(o).map(k => [k, o[k]])\n];\n/** Like Object.assign, but it will preserve getters instead of evaluating them. */\nexport const defineProperties = (base, merged) => \n// declared like this to avoid https://github.com/microsoft/TypeScript/issues/55049\nObject.defineProperties(base, Object.getOwnPropertyDescriptors(merged));\nexport const invert = (t) => flatMorph(t, (k, v) => [v, k]);\nexport const unset = Symbol(\"represents an uninitialized value\");\n","import { throwInternalError } from \"./errors.js\";\nimport { NoopBase, unset } from \"./records.js\";\nexport const bound = (target, ctx) => {\n ctx.addInitializer(function () {\n this[ctx.name] = this[ctx.name].bind(this);\n });\n};\nexport const cached = (target, context) => function () {\n const value = target.call(this);\n Object.defineProperty(this, context.name, context.kind === \"getter\" ?\n { value }\n : {\n value: () => value,\n enumerable: false\n });\n return value;\n};\nexport const cachedThunk = (thunk) => {\n let result = unset;\n return () => (result === unset ? (result = thunk()) : result);\n};\nexport const isThunk = (value) => typeof value === \"function\" && value.length === 0;\nexport const tryCatch = (fn, onError) => {\n try {\n return fn();\n }\n catch (e) {\n return onError?.(e);\n }\n};\nexport const DynamicFunction = class extends Function {\n constructor(...args) {\n const params = args.slice(0, -1);\n const body = args.at(-1);\n try {\n super(...params, body);\n }\n catch (e) {\n return throwInternalError(`Encountered an unexpected error while compiling your definition:\n Message: ${e} \n Source: (${args.slice(0, -1)}) => {\n ${args.at(-1)}\n }`);\n }\n }\n};\n/** @ts-expect-error required to cast function type */\nexport class Callable extends NoopBase {\n constructor(f, opts) {\n super();\n return Object.assign(Object.setPrototypeOf(f.bind(opts?.bind ?? this), this.constructor.prototype), opts?.attach);\n }\n}\n/**\n * Checks if the environment has Content Security Policy (CSP) enabled,\n * preventing JIT-optimized code from being compiled via new Function().\n *\n * @returns `true` if a function created using new Function() can be\n * successfully invoked in the environment, `false` otherwise.\n *\n * The result is cached for subsequent invocations.\n */\nexport const envHasCsp = cachedThunk(() => {\n try {\n return new Function(\"return false\")();\n }\n catch (e) {\n return true;\n }\n});\n","export const hasDomain = (data, kind) => domainOf(data) === kind;\nexport const domainOf = (data) => {\n const builtinType = typeof data;\n return (builtinType === \"object\" ?\n data === null ?\n \"null\"\n : \"object\"\n : builtinType === \"function\" ? \"object\"\n : builtinType);\n};\nconst enumerableDomainDescriptions = {\n boolean: \"boolean\",\n null: \"null\",\n undefined: \"undefined\"\n};\nconst nonEnumerableDomainDescriptions = {\n bigint: \"a bigint\",\n number: \"a number\",\n object: \"an object\",\n string: \"a string\",\n symbol: \"a symbol\"\n};\n/** Each domain's completion for the phrase \"must be _____\" */\nexport const domainDescriptions = {\n ...nonEnumerableDomainDescriptions,\n ...enumerableDomainDescriptions\n};\n","import { domainOf } from \"./domain.js\";\nimport { isKeyOf } from \"./records.js\";\n// Built-in object constructors based on a subset of:\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects\nexport const builtinConstructors = {\n Array,\n Date,\n Error,\n Function,\n Map,\n RegExp,\n Set,\n String,\n Number,\n Boolean,\n WeakMap,\n WeakSet,\n Promise\n};\nexport const objectKindOf = (data) => {\n let prototype = Object.getPrototypeOf(data);\n while (prototype?.constructor &&\n (!isKeyOf(prototype.constructor.name, builtinConstructors) ||\n !(data instanceof builtinConstructors[prototype.constructor.name])))\n prototype = Object.getPrototypeOf(prototype);\n const name = prototype?.constructor?.name;\n if (name === undefined || name === \"Object\")\n return undefined;\n return name;\n};\nexport const objectKindOrDomainOf = (data) => (typeof data === \"object\" && data !== null ?\n objectKindOf(data) ?? \"object\"\n : domainOf(data));\nexport const hasObjectKind = (data, kind) => objectKindOf(data) === kind;\nexport const isArray = (data) => Array.isArray(data);\n/** Each defaultObjectKind's completion for the phrase \"must be _____\" */\nexport const objectKindDescriptions = {\n Array: \"an array\",\n Function: \"a function\",\n Date: \"a Date\",\n RegExp: \"a RegExp\",\n Error: \"an Error\",\n Map: \"a Map\",\n Set: \"a Set\",\n String: \"a String object\",\n Number: \"a Number object\",\n Boolean: \"a Boolean object\",\n Promise: \"a Promise\",\n WeakMap: \"a WeakMap\",\n WeakSet: \"a WeakSet\"\n};\n// this will only return an object kind if it's the root constructor\n// example TypeError would return undefined not 'Error'\nexport const getExactBuiltinConstructorName = (ctor) => {\n const constructorName = Object(ctor).name ?? null;\n return (constructorName &&\n isKeyOf(constructorName, builtinConstructors) &&\n builtinConstructors[constructorName] === ctor) ?\n constructorName\n : null;\n};\n/**\n * Returns an array of constructors for all ancestors (i.e., prototypes) of a given object.\n *\n * @param {object} o - The object to find the ancestors of.\n * @returns {Function[]} An array of constructors for all ancestors of the object.\n */\nexport const ancestorsOf = (o) => {\n let proto = Object.getPrototypeOf(o);\n const result = [];\n while (proto !== null) {\n result.push(proto.constructor);\n proto = Object.getPrototypeOf(proto);\n }\n return result;\n};\n/** Mimics output of TS's keyof operator at runtime */\nexport const prototypeKeysOf = (value) => {\n const result = [];\n let curr = value;\n while (curr !== Object.prototype && curr !== null && curr !== undefined) {\n for (const k of Object.getOwnPropertyNames(curr))\n if (k !== \"constructor\" && !result.includes(k))\n result.push(k);\n for (const symbol of Object.getOwnPropertySymbols(curr))\n if (!result.includes(symbol))\n result.push(symbol);\n curr = Object.getPrototypeOf(curr);\n }\n return result;\n};\nconst baseKeysByDomain = {\n bigint: prototypeKeysOf(0n),\n boolean: prototypeKeysOf(false),\n null: [],\n number: prototypeKeysOf(0),\n // TS doesn't include the Object prototype in keyof, so keyof object is never\n object: [],\n string: prototypeKeysOf(\"\"),\n symbol: prototypeKeysOf(Symbol()),\n undefined: []\n};\nexport const getBaseDomainKeys = (domain) => [...baseKeysByDomain[domain]];\nexport const constructorExtends = (ctor, base) => {\n let current = ctor.prototype;\n while (current !== null) {\n if (current === base.prototype)\n return true;\n current = Object.getPrototypeOf(current);\n }\n return false;\n};\n","export const serializePrimitive = (value) => (typeof value === \"string\" ? JSON.stringify(value)\n : typeof value === \"bigint\" ? `${value}n`\n : `${value}`);\n","import { domainOf, hasDomain } from \"./domain.js\";\nimport { throwInternalError } from \"./errors.js\";\nimport { objectKindOf } from \"./objectKinds.js\";\nimport { serializePrimitive } from \"./primitive.js\";\nexport const registry = {};\nglobalThis.$ark = registry;\nconst namesByResolution = new WeakMap();\nconst nameCounts = {};\nexport const register = (value) => {\n const existingName = namesByResolution.get(value);\n if (existingName)\n return existingName;\n let name = baseNameFor(value);\n if (nameCounts[name])\n name = `${name}${nameCounts[name]++}`;\n else\n nameCounts[name] = 1;\n registry[name] = value;\n namesByResolution.set(value, name);\n return name;\n};\nexport const reference = (name) => `$ark.${name}`;\nexport const registeredReference = (value) => reference(register(value));\nexport const isDotAccessible = (keyName) => /^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(keyName);\nexport const compileSerializedValue = (value) => hasDomain(value, \"object\") || typeof value === \"symbol\" ?\n registeredReference(value)\n : serializePrimitive(value);\nconst baseNameFor = (value) => {\n switch (typeof value) {\n case \"object\": {\n if (value === null)\n break;\n const prefix = objectKindOf(value) ?? \"object\";\n // convert to camelCase\n return prefix[0].toLowerCase() + prefix.slice(1);\n }\n case \"function\":\n return isDotAccessible(value.name) ? value.name : \"fn\";\n case \"symbol\":\n return value.description && isDotAccessible(value.description) ?\n value.description\n : \"symbol\";\n }\n return throwInternalError(`Unexpected attempt to register serializable value of type ${domainOf(value)}`);\n};\n","import { DynamicFunction } from \"./functions.js\";\nimport { CastableBase } from \"./records.js\";\nimport { isDotAccessible, registeredReference } from \"./registry.js\";\nexport class CompiledFunction extends CastableBase {\n argNames;\n body = \"\";\n constructor(...args) {\n super();\n this.argNames = args;\n for (const arg of args) {\n if (arg in this) {\n throw new Error(`Arg name '${arg}' would overwrite an existing property on FunctionBody`);\n }\n ;\n this[arg] = arg;\n }\n }\n indentation = 0;\n indent() {\n this.indentation += 4;\n return this;\n }\n dedent() {\n this.indentation -= 4;\n return this;\n }\n prop(key, optional = false) {\n return compileLiteralPropAccess(key, optional);\n }\n index(key, optional = false) {\n return indexPropAccess(`${key}`, optional);\n }\n line(statement) {\n ;\n this.body += `${\" \".repeat(this.indentation)}${statement}\\n`;\n return this;\n }\n const(identifier, expression) {\n this.line(`const ${identifier} = ${expression}`);\n return this;\n }\n let(identifier, expression) {\n return this.line(`let ${identifier} = ${expression}`);\n }\n set(identifier, expression) {\n return this.line(`${identifier} = ${expression}`);\n }\n if(condition, then) {\n return this.block(`if (${condition})`, then);\n }\n elseIf(condition, then) {\n return this.block(`else if (${condition})`, then);\n }\n else(then) {\n return this.block(\"else\", then);\n }\n /** Current index is \"i\" */\n for(until, body, initialValue = 0) {\n return this.block(`for (let i = ${initialValue}; ${until}; i++)`, body);\n }\n /** Current key is \"k\" */\n forIn(object, body) {\n return this.block(`for (const k in ${object})`, body);\n }\n block(prefix, contents, suffix = \"\") {\n this.line(`${prefix} {`);\n this.indent();\n contents(this);\n this.dedent();\n return this.line(`}${suffix}`);\n }\n return(expression = \"\") {\n return this.line(`return ${expression}`);\n }\n compile() {\n return new DynamicFunction(...this.argNames, this.body);\n }\n}\nexport const compileLiteralPropAccess = (key, optional = false) => {\n if (typeof key === \"string\" && isDotAccessible(key))\n return `${optional ? \"?\" : \"\"}.${key}`;\n return indexPropAccess(serializeLiteralKey(key), optional);\n};\nexport const serializeLiteralKey = (key) => typeof key === \"symbol\" ? registeredReference(key) : JSON.stringify(key);\nexport const indexPropAccess = (key, optional = false) => `${optional ? \"?.\" : \"\"}[${key}]`;\n","/** A small set of HKT utility types based on https://github.com/poteat/hkt-toolbelt */\nexport var Hkt;\n(function (Hkt) {\n class Kind {\n }\n Hkt.Kind = Kind;\n class Instantiable {\n }\n Hkt.Instantiable = Instantiable;\n Hkt.reify = (def) => def.hkt;\n class UnaryKind {\n }\n Hkt.UnaryKind = UnaryKind;\n Hkt.pipe = (...kinds) => In => kinds.reduce((out, kind) => kind.hkt(out), In);\n})(Hkt || (Hkt = {}));\n","import { throwParseError } from \"./errors.js\";\n/**\n * The goal of the number literal and bigint literal regular expressions is to:\n *\n * 1. Ensure definitions form a bijection with the values they represent.\n * 2. Attempt to mirror TypeScript's own format for stringification of numeric\n * values such that the regex should match a given definition if any only if\n * a precise literal type will be inferred (in TS4.8+).\n */\n/**\n * Matches a well-formatted numeric expression according to the following rules:\n * 1. Must include an integer portion (i.e. '.321' must be written as '0.321')\n * 2. The first digit of the value must not be 0, unless the entire integer portion is 0\n * 3. If the value includes a decimal, its last digit may not be 0\n * 4. The value may not be \"-0\"\n */\nexport const wellFormedNumberMatcher = /^(?!^-0$)-?(?:0|[1-9]\\d*)(?:\\.\\d*[1-9])?$/;\nexport const isWellFormedNumber = wellFormedNumberMatcher.test.bind(wellFormedNumberMatcher);\nconst numberLikeMatcher = /^-?\\d*\\.?\\d*$/;\nconst isNumberLike = (s) => s.length !== 0 && numberLikeMatcher.test(s);\n/**\n * Matches a well-formatted integer according to the following rules:\n * 1. must begin with an integer, the first digit of which cannot be 0 unless the entire value is 0\n * 2. The value may not be \"-0\"\n */\nexport const wellFormedIntegerMatcher = /^(?:0|(?:-?[1-9]\\d*))$/;\nexport const isWellFormedInteger = wellFormedIntegerMatcher.test.bind(wellFormedIntegerMatcher);\nconst integerLikeMatcher = /^-?\\d+$/;\nconst isIntegerLike = integerLikeMatcher.test.bind(integerLikeMatcher);\nconst numericLiteralDescriptions = {\n number: \"a number\",\n bigint: \"a bigint\",\n integer: \"an integer\"\n};\nexport const writeMalformedNumericLiteralMessage = (def, kind) => `'${def}' was parsed as ${numericLiteralDescriptions[kind]} but could not be narrowed to a literal value. Avoid unnecessary leading or trailing zeros and other abnormal notation`;\nconst isWellFormed = (def, kind) => kind === \"number\" ? isWellFormedNumber(def) : isWellFormedInteger(def);\nconst parseKind = (def, kind) => kind === \"number\" ? Number(def) : Number.parseInt(def);\nconst isKindLike = (def, kind) => kind === \"number\" ? isNumberLike(def) : isIntegerLike(def);\nexport const tryParseNumber = (token, options) => parseNumeric(token, \"number\", options);\nexport const tryParseInteger = (token, options) => parseNumeric(token, \"integer\", options);\nconst parseNumeric = (token, kind, options) => {\n const value = parseKind(token, kind);\n if (!Number.isNaN(value)) {\n if (isKindLike(token, kind)) {\n if (options?.strict) {\n return isWellFormed(token, kind) ? value : (throwParseError(writeMalformedNumericLiteralMessage(token, kind)));\n }\n return value;\n }\n }\n return (options?.errorOnFail ?\n throwParseError(options?.errorOnFail === true ?\n `Failed to parse ${numericLiteralDescriptions[kind]} from '${token}'`\n : options?.errorOnFail)\n : undefined);\n};\nexport const tryParseWellFormedBigint = (def) => {\n if (def[def.length - 1] !== \"n\")\n return;\n const maybeIntegerLiteral = def.slice(0, -1);\n let value;\n try {\n value = BigInt(maybeIntegerLiteral);\n }\n catch {\n return;\n }\n if (wellFormedIntegerMatcher.test(maybeIntegerLiteral))\n return value;\n if (integerLikeMatcher.test(maybeIntegerLiteral)) {\n // If the definition looks like a bigint but is\n // not well-formed, throw.\n return throwParseError(writeMalformedNumericLiteralMessage(def, \"bigint\"));\n }\n};\n","import { domainOf } from \"./domain.js\";\nimport { serializePrimitive } from \"./primitive.js\";\nimport { register } from \"./registry.js\";\nexport const snapshot = (data, opts = { onUndefined: \"(undefined)\" }) => _serialize(data, opts, []);\nexport const print = (data, indent) => console.log(printable(data, indent));\nexport const printable = (data, indent) => {\n switch (domainOf(data)) {\n case \"object\":\n return data instanceof Date ?\n data.toDateString()\n : JSON.stringify(_serialize(data, printableOpts, []), null, indent);\n case \"symbol\":\n return printableOpts.onSymbol(data);\n default:\n return serializePrimitive(data);\n }\n};\nconst printableOpts = {\n onCycle: () => \"(cycle)\",\n onSymbol: v => `Symbol(${register(v)})`,\n onFunction: v => `Function(${register(v)})`\n};\nconst _serialize = (data, opts, seen) => {\n switch (domainOf(data)) {\n case \"object\": {\n if (typeof data === \"function\")\n return printableOpts.onFunction(data);\n if (seen.includes(data))\n return \"(cycle)\";\n const nextSeen = [...seen, data];\n if (Array.isArray(data))\n return data.map(item => _serialize(item, opts, nextSeen));\n if (data instanceof Date)\n return data.toDateString();\n const result = {};\n for (const k in data)\n result[k] = _serialize(data[k], opts, nextSeen);\n return result;\n }\n case \"symbol\":\n return printableOpts.onSymbol(data);\n case \"bigint\":\n return `${data}n`;\n case \"undefined\":\n return opts.onUndefined ?? \"undefined\";\n default:\n return data;\n }\n};\n","import { flatMorph, isArray, isDotAccessible, printable } from \"@arktype/util\";\nexport const makeRootAndArrayPropertiesMutable = (o) => \n// TODO: this cast should not be required, but it seems TS is referencing\n// the wrong parameters here?\nflatMorph(o, (k, v) => [k, isArray(v) ? [...v] : v]);\nexport const pathToPropString = (path) => {\n const propAccessChain = path.reduce((s, k) => typeof k === \"string\" && isDotAccessible(k) ?\n `${s}.${k}`\n : `${s}[${printable(k)}]`, \"\");\n return propAccessChain[0] === \".\" ? propAccessChain.slice(1) : propAccessChain;\n};\nexport const arkKind = Symbol(\"ArkTypeInternalKind\");\nexport const hasArkKind = (value, kind) => value?.[arkKind] === kind;\nexport const isNode = (value) => hasArkKind(value, \"root\") || hasArkKind(value, \"constraint\");\n// ideally this could be just declared since it is not used at runtime,\n// but it doesn't play well with typescript-eslint: https://github.com/typescript-eslint/typescript-eslint/issues/4608\n// easiest solution seems to be just having it declared as a value so it doesn't break when we import at runtime\nexport const inferred = Symbol(\"inferred\");\n","import { compileSerializedValue, flatMorph, printable, throwParseError } from \"@arktype/util\";\nimport { isNode } from \"./utils.js\";\nexport const basisKinds = [\"unit\", \"proto\", \"domain\"];\nexport const structuralKinds = [\n \"required\",\n \"optional\",\n \"index\",\n \"sequence\"\n];\nexport const refinementKinds = [\n \"regex\",\n \"divisor\",\n \"exactLength\",\n \"max\",\n \"min\",\n \"maxLength\",\n \"minLength\",\n \"before\",\n \"after\"\n];\nexport const constraintKinds = [\n ...refinementKinds,\n ...structuralKinds,\n \"structure\",\n \"predicate\"\n];\nexport const rootKinds = [\n \"alias\",\n \"union\",\n \"morph\",\n \"unit\",\n \"intersection\",\n \"proto\",\n \"domain\"\n];\nexport const nodeKinds = [...rootKinds, ...constraintKinds];\nexport const constraintKeys = flatMorph(constraintKinds, (i, kind) => [kind, 1]);\nexport const structureKeys = flatMorph([...structuralKinds, \"undeclared\"], (i, k) => [k, 1]);\nexport const precedenceByKind = flatMorph(nodeKinds, (i, kind) => [kind, i]);\nexport const isNodeKind = (value) => typeof value === \"string\" && value in precedenceByKind;\nexport function assertNodeKind(value, kind) {\n const valueIsNode = isNode(value);\n if (!valueIsNode || value.kind !== kind) {\n throwParseError(`Expected node of kind ${kind} (was ${valueIsNode ? `${value.kind} node` : printable(value)})`);\n }\n}\nexport const precedenceOfKind = (kind) => precedenceByKind[kind];\nexport const schemaKindsRightOf = (kind) => rootKinds.slice(precedenceOfKind(kind) + 1);\nexport const defaultValueSerializer = (v) => {\n if (typeof v === \"string\" ||\n typeof v === \"boolean\" ||\n typeof v === \"number\" ||\n v === null)\n return v;\n return compileSerializedValue(v);\n};\nexport const compileErrorContext = (ctx) => {\n let result = \"{ \";\n for (const [k, v] of Object.entries(ctx))\n result += `${k}: ${compileSerializedValue(v)}, `;\n return result + \" }\";\n};\nexport const implementNode = (_) => {\n const implementation = _;\n if (implementation.hasAssociatedError) {\n implementation.defaults.expected ??= ctx => \"description\" in ctx ?\n ctx.description\n : implementation.defaults.description(ctx);\n implementation.defaults.actual ??= data => printable(data);\n implementation.defaults.problem ??= ctx => `must be ${ctx.expected}${ctx.actual ? ` (was ${ctx.actual})` : \"\"}`;\n implementation.defaults.message ??= ctx => {\n if (ctx.path.length === 0)\n return ctx.problem;\n const problemWithLocation = `${ctx.propString} ${ctx.problem}`;\n if (problemWithLocation[0] === \"[\") {\n // clarify paths like [1], [0][1], and [\"key!\"] that could be confusing\n return `value at ${problemWithLocation}`;\n }\n return problemWithLocation;\n };\n }\n return implementation;\n};\n","import { isNodeKind } from \"./shared/implement.js\";\nexport const globalConfig = {};\nexport const mergeConfigs = (base, extensions) => {\n const result = { ...base };\n let k;\n for (k in extensions) {\n result[k] =\n isNodeKind(k) ?\n {\n ...base[k],\n ...extensions[k]\n }\n : extensions[k];\n }\n return result;\n};\nexport const configure = (config) => Object.assign(globalConfig, mergeConfigs(globalConfig, config));\n","import { CastableBase, ReadonlyArray, defineProperties } from \"@arktype/util\";\nimport { arkKind, pathToPropString } from \"./utils.js\";\nexport class ArkError extends CastableBase {\n input;\n [arkKind] = \"error\";\n path;\n data;\n nodeConfig;\n constructor(input, ctx) {\n super();\n this.input = input;\n defineProperties(this, input);\n const data = ctx.data;\n if (input.code === \"union\") {\n // flatten union errors to avoid repeating context like \"foo must be foo must be\"...\n input.errors = input.errors.flatMap(e => e.hasCode(\"union\") ? e.errors : e);\n }\n this.nodeConfig = ctx.config[this.code];\n this.path = input.path ?? [...ctx.path];\n if (input.relativePath)\n this.path.push(...input.relativePath);\n this.data = \"data\" in input ? input.data : data;\n }\n hasCode(code) {\n return this.code === code;\n }\n get propString() {\n return pathToPropString(this.path);\n }\n get expected() {\n return (this.input.expected ?? this.nodeConfig.expected?.(this.input));\n }\n get actual() {\n // null is a valid value of actual meaning it should be omitted, so\n // check for undefined explicitly\n return this.input.actual !== undefined ?\n this.input.actual\n : this.nodeConfig.actual?.(this.data);\n }\n get problem() {\n return this.input.problem ?? this.nodeConfig.problem(this);\n }\n get message() {\n return this.input.message ?? this.nodeConfig.message(this);\n }\n toString() {\n return this.message;\n }\n throw() {\n throw this;\n }\n}\nexport class ArkErrors extends ReadonlyArray {\n ctx;\n constructor(ctx) {\n super();\n this.ctx = ctx;\n }\n byPath = {};\n count = 0;\n mutable = this;\n add(error) {\n const existing = this.byPath[error.propString];\n if (existing) {\n const errorIntersection = new ArkError({\n code: \"intersection\",\n errors: existing.hasCode(\"intersection\") ?\n [...existing.errors, error]\n : [existing, error]\n }, this.ctx);\n const existingIndex = this.indexOf(existing);\n // If existing is found (which it always should be unless this was externally mutated),\n // replace it with the new problem intersection. In case it isn't for whatever reason,\n // just append the intersection.\n this.mutable[existingIndex === -1 ? this.length : existingIndex] =\n errorIntersection;\n this.byPath[error.propString] = errorIntersection;\n }\n else {\n this.byPath[error.propString] = error;\n this.mutable.push(error);\n }\n this.count++;\n }\n get summary() {\n return this.toString();\n }\n get message() {\n return this.toString();\n }\n toString() {\n return this.join(\"\\n\");\n }\n throw() {\n throw this;\n }\n}\n","import { ArkError, ArkErrors } from \"./errors.js\";\nexport class TraversalContext {\n root;\n config;\n path = [];\n queuedMorphs = [];\n errors = new ArkErrors(this);\n branches = [];\n seen = {};\n constructor(root, config) {\n this.root = root;\n this.config = config;\n }\n get currentBranch() {\n return this.branches.at(-1);\n }\n queueMorphs(morphs) {\n const input = {\n path: [...this.path],\n morphs\n };\n this.currentBranch?.queuedMorphs.push(input) ??\n this.queuedMorphs.push(input);\n }\n finalize() {\n if (this.hasError())\n return this.errors;\n let out = this.root;\n if (this.queuedMorphs.length) {\n for (let i = 0; i < this.queuedMorphs.length; i++) {\n const { path, morphs } = this.queuedMorphs[i];\n const key = path.at(-1);\n let parent;\n if (key !== undefined) {\n // find the object on which the key to be morphed exists\n parent = out;\n for (let pathIndex = 0; pathIndex < path.length - 1; pathIndex++)\n parent = parent[path[pathIndex]];\n }\n this.path = path;\n for (const morph of morphs) {\n const result = morph(parent === undefined ? out : parent[key], this);\n if (result instanceof ArkErrors)\n return result;\n if (this.hasError())\n return this.errors;\n if (result instanceof ArkError) {\n // if an ArkError was returned but wasn't added to these\n // errors, add it then return\n this.error(result);\n return this.errors;\n }\n // apply the morph function and assign the result to the\n // corresponding property, or to root if path is empty\n if (parent === undefined)\n out = result;\n else\n parent[key] = result;\n }\n }\n }\n return out;\n }\n get currentErrorCount() {\n return (this.currentBranch ?\n this.currentBranch.error ?\n 1\n : 0\n : this.errors.count);\n }\n hasError() {\n return this.currentErrorCount !== 0;\n }\n get failFast() {\n return this.branches.length !== 0;\n }\n error(input) {\n const errCtx = typeof input === \"object\" ?\n input.code ?\n input\n : { ...input, code: \"predicate\" }\n : { code: \"predicate\", expected: input };\n const error = new ArkError(errCtx, this);\n if (this.currentBranch)\n this.currentBranch.error = error;\n else\n this.errors.add(error);\n return error;\n }\n get data() {\n let result = this.root;\n for (const segment of this.path)\n result = result?.[segment];\n return result;\n }\n invalid(input) {\n this.error(input);\n return false;\n }\n pushBranch() {\n this.branches.push({\n error: undefined,\n queuedMorphs: []\n });\n }\n popBranch() {\n return this.branches.pop();\n }\n}\n","import { Callable, flatMorph, includes, isArray, isEmptyObject, shallowClone, throwError } from \"@arktype/util\";\nimport { basisKinds, constraintKinds, precedenceOfKind, refinementKinds, rootKinds } from \"./shared/implement.js\";\nimport { TraversalContext } from \"./shared/traversal.js\";\nexport class BaseNode extends Callable {\n attachments;\n constructor(attachments) {\n super(\n // pipedFromCtx allows us internally to reuse TraversalContext\n // through pipes and keep track of piped paths. It is not exposed\n (data, pipedFromCtx) => {\n if (!this.includesMorph &&\n !this.allowsRequiresContext &&\n this.allows(data))\n return data;\n if (pipedFromCtx)\n return this.traverseApply(data, pipedFromCtx);\n const ctx = new TraversalContext(data, this.$.resolvedConfig);\n this.traverseApply(data, ctx);\n return ctx.finalize();\n }, { attach: attachments });\n this.attachments = attachments;\n }\n qualifiedId = `${this.$.id}${this.id}`;\n includesMorph = this.kind === \"morph\" ||\n (this.hasKind(\"optional\") && this.hasDefault()) ||\n (this.hasKind(\"structure\") && this.undeclared === \"delete\") ||\n this.children.some(child => child.includesMorph);\n allowsRequiresContext = \n // if a predicate accepts exactly one arg, we can safely skip passing context\n (this.hasKind(\"predicate\") && this.inner.predicate.length !== 1) ||\n this.kind === \"alias\" ||\n this.children.some(child => child.allowsRequiresContext);\n referencesById = this.children.reduce((result, child) => Object.assign(result, child.referencesById), { [this.id]: this });\n get references() {\n return Object.values(this.referencesById);\n }\n precedence = precedenceOfKind(this.kind);\n jit = false;\n allows = (data) => {\n if (this.allowsRequiresContext) {\n return this.traverseAllows(data, new TraversalContext(data, this.$.resolvedConfig));\n }\n return this.traverseAllows(data);\n };\n traverse(data) {\n return this(data);\n }\n // unfortunately we can't use the @cached\n // decorator from @arktype/util on these for now\n // as they cause a deopt in V8\n _in;\n get in() {\n this._in ??= this.getIo(\"in\");\n return this._in;\n }\n _out;\n get out() {\n this._out ??= this.getIo(\"out\");\n return this._out;\n }\n _description;\n get description() {\n this._description ??=\n this.inner.description ??\n this.$.resolvedConfig[this.kind].description?.(this);\n return this._description;\n }\n getIo(kind) {\n if (!this.includesMorph)\n return this;\n const ioInner = {};\n for (const [k, v] of this.entries) {\n const keySchemaImplementation = this.impl.keys[k];\n if (keySchemaImplementation.meta)\n continue;\n if (keySchemaImplementation.child) {\n const childValue = v;\n ioInner[k] =\n isArray(childValue) ?\n childValue.map(child => child[kind])\n : childValue[kind];\n }\n else\n ioInner[k] = v;\n }\n return this.$.node(this.kind, ioInner);\n }\n toJSON() {\n return this.json;\n }\n toString() {\n return this.expression;\n }\n equals(other) {\n return this.typeHash === other.typeHash;\n }\n hasKind(kind) {\n return this.kind === kind;\n }\n isBasis() {\n return includes(basisKinds, this.kind);\n }\n isConstraint() {\n return includes(constraintKinds, this.kind);\n }\n isRefinement() {\n return includes(refinementKinds, this.kind);\n }\n isRoot() {\n return includes(rootKinds, this.kind);\n }\n hasUnit(value) {\n return this.hasKind(\"unit\") && this.allows(value);\n }\n hasOpenIntersection() {\n return this.impl.intersectionIsOpen;\n }\n get nestableExpression() {\n return this.expression;\n }\n bindScope($) {\n if (this.$ === $)\n return this;\n return new this.constructor(Object.assign(shallowClone(this.attachments), { $ }));\n }\n firstReference(filter) {\n return this.references.find(n => n !== this && filter(n));\n }\n firstReferenceOrThrow(filter) {\n return (this.firstReference(filter) ??\n throwError(`${this.id} had no references matching predicate ${filter}`));\n }\n firstReferenceOfKind(kind) {\n return this.fir