@beff/cli 0.0.99 → 0.0.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist-cli/cli.js +75 -20
- package/package.json +1 -1
- package/pkg/beff_wasm.d.ts +7 -1
- package/pkg/beff_wasm.js +14 -2
- package/pkg/beff_wasm_bg.wasm +0 -0
- package/pkg/beff_wasm_bg.wasm.d.ts +1 -0
package/CHANGELOG.md
CHANGED
package/dist-cli/cli.js
CHANGED
|
@@ -45781,7 +45781,7 @@ var fs = __toESM(require("fs"));
|
|
|
45781
45781
|
var path = __toESM(require("path"));
|
|
45782
45782
|
|
|
45783
45783
|
// ts-node/generated/bundle.ts
|
|
45784
|
-
var bundle_default = { "build-parsers.js": '\n\nfunction buildParsers(args) {\n const stringFormats = args?.stringFormats ?? {};\n \n for (const k of RequiredStringFormats) {\n if (stringFormats[k] == null) {\n throw new Error(`Missing custom format ${k}`);\n }\n }\n\n Object.keys(stringFormats).forEach((k) => {\n const v = stringFormats[k];\n \n registerStringFormatter(k, v);\n });\n\n const numberFormats = args?.numberFormats ?? {};\n \n for (const k of RequiredNumberFormats) {\n if (numberFormats[k] == null) {\n throw new Error(`Missing custom format ${k}`);\n }\n }\n\n Object.keys(numberFormats).forEach((k) => {\n const v = numberFormats[k];\n \n registerNumberFormatter(k, v);\n });\n\n let decoders = {};\n \n Object.keys(buildValidatorsInput).forEach((k) => {\n \n let v = buildValidatorsInput[k];\n const validate = (input, options) => {\n const disallowExtraProperties = options?.disallowExtraProperties ?? false;\n const ctx = { disallowExtraProperties };\n const ok = v(ctx, input);\n if (typeof ok !== "boolean") {\n throw new Error("INTERNAL ERROR: Expected boolean");\n }\n return ok;\n };\n\n \n const schemaFn = buildSchemaInput[k];\n const schema = () => {\n const ctx = {\n path: [],\n seen: {},\n };\n return schemaFn(ctx);\n };\n\n \n const describeFn = buildDescribeInput[k];\n const describe = () => {\n const ctx = {\n deps: {},\n deps_counter: {},\n measure: true,\n };\n let out = describeFn(ctx);\n ctx["deps"] = {};\n ctx["measure"] = false;\n out = describeFn(ctx);\n let sortedDepsKeys = Object.keys(ctx.deps).sort();\n \n \n \n \n const depsPart = sortedDepsKeys\n .map((key) => {\n return `type ${key} = ${ctx.deps[key]};`;\n })\n .join("\\n\\n");\n \n \n \n const outPart = `type Codec${k} = ${out};`;\n return [depsPart, outPart].filter((it) => it != null && it.length > 0).join("\\n\\n");\n };\n\n const safeParse = (input, options) => {\n const disallowExtraProperties = options?.disallowExtraProperties ?? false;\n const ok = validate(input, options);\n if (ok) {\n \n let p = buildParsersInput[k];\n let ctx = { disallowExtraProperties };\n const parsed = p(ctx, input);\n return { success: true, data: parsed };\n }\n \n let e = buildReportersInput[k];\n let ctx = { path: [], disallowExtraProperties };\n return {\n success: false,\n errors: e(ctx, input).slice(0, 10),\n };\n };\n const parse = (input, options) => {\n const safe = safeParse(input, options);\n if (safe.success) {\n return safe.data;\n }\n \n const explained = printErrors(safe.errors, []);\n throw new Error(`Failed to parse ${k} - ${explained}`);\n };\n const zod = () => {\n \n return z.custom(\n (data) => safeParse(data).success,\n (val) => {\n const errors = safeParse(val).errors;\n \n return printErrors(errors, []);\n },\n );\n };\n decoders[k] = {\n parse,\n safeParse,\n zod,\n name: k,\n validate,\n schema,\n describe,\n };\n });\n return decoders;\n}\n', "decoders.js": '\n\n\n\n\n\nconst JSON_PROTO = Object.getPrototypeOf({});\n\nfunction deepmergeConstructor(options) {\n function isNotPrototypeKey(value) {\n return value !== "constructor" && value !== "prototype" && value !== "__proto__";\n }\n\n function cloneArray(value) {\n let i = 0;\n const il = value.length;\n const result = new Array(il);\n for (i; i < il; ++i) {\n result[i] = clone(value[i]);\n }\n return result;\n }\n\n function cloneObject(target) {\n const result = {};\n\n if (cloneProtoObject && Object.getPrototypeOf(target) !== JSON_PROTO) {\n return cloneProtoObject(target);\n }\n\n const targetKeys = getKeys(target);\n let i, il, key;\n for (i = 0, il = targetKeys.length; i < il; ++i) {\n isNotPrototypeKey((key = targetKeys[i])) && (result[key] = clone(target[key]));\n }\n return result;\n }\n\n function concatArrays(target, source) {\n const tl = target.length;\n const sl = source.length;\n let i = 0;\n const result = new Array(tl + sl);\n for (i; i < tl; ++i) {\n result[i] = clone(target[i]);\n }\n for (i = 0; i < sl; ++i) {\n result[i + tl] = clone(source[i]);\n }\n return result;\n }\n\n const propertyIsEnumerable = Object.prototype.propertyIsEnumerable;\n function getSymbolsAndKeys(value) {\n const result = Object.keys(value);\n const keys = Object.getOwnPropertySymbols(value);\n for (let i = 0, il = keys.length; i < il; ++i) {\n \n propertyIsEnumerable.call(value, keys[i]) && result.push(keys[i]);\n }\n return result;\n }\n\n const getKeys = options?.symbols ? getSymbolsAndKeys : Object.keys;\n\n const cloneProtoObject =\n typeof options?.cloneProtoObject === "function" ? options.cloneProtoObject : undefined;\n\n function isMergeableObject(value) {\n return (\n typeof value === "object" && value !== null && !(value instanceof RegExp) && !(value instanceof Date)\n );\n }\n\n function isPrimitive(value) {\n return typeof value !== "object" || value === null;\n }\n\n const isPrimitiveOrBuiltIn =\n \n typeof Buffer !== "undefined"\n ? (value) =>\n typeof value !== "object" ||\n value === null ||\n value instanceof RegExp ||\n value instanceof Date ||\n \n value instanceof Buffer\n : (value) =>\n typeof value !== "object" || value === null || value instanceof RegExp || value instanceof Date;\n\n const mergeArray =\n options && typeof options.mergeArray === "function"\n ? options.mergeArray({ clone, deepmerge: _deepmerge, getKeys, isMergeableObject })\n : concatArrays;\n\n function clone(entry) {\n return isMergeableObject(entry) ? (Array.isArray(entry) ? cloneArray(entry) : cloneObject(entry)) : entry;\n }\n\n function mergeObject(target, source) {\n const result = {};\n const targetKeys = getKeys(target);\n const sourceKeys = getKeys(source);\n let i, il, key;\n for (i = 0, il = targetKeys.length; i < il; ++i) {\n isNotPrototypeKey((key = targetKeys[i])) &&\n sourceKeys.indexOf(key) === -1 &&\n (result[key] = clone(target[key]));\n }\n\n for (i = 0, il = sourceKeys.length; i < il; ++i) {\n if (!isNotPrototypeKey((key = sourceKeys[i]))) {\n continue;\n }\n\n if (key in target) {\n if (targetKeys.indexOf(key) !== -1) {\n if (\n cloneProtoObject &&\n isMergeableObject(source[key]) &&\n Object.getPrototypeOf(source[key]) !== JSON_PROTO\n ) {\n result[key] = cloneProtoObject(source[key]);\n } else {\n result[key] = _deepmerge(target[key], source[key]);\n }\n }\n } else {\n result[key] = clone(source[key]);\n }\n }\n return result;\n }\n\n function _deepmerge(target, source) {\n const sourceIsArray = Array.isArray(source);\n const targetIsArray = Array.isArray(target);\n\n if (isPrimitive(source)) {\n return source;\n } else if (isPrimitiveOrBuiltIn(target)) {\n return clone(source);\n } else if (sourceIsArray && targetIsArray) {\n return mergeArray(target, source);\n } else if (sourceIsArray !== targetIsArray) {\n return clone(source);\n } else {\n return mergeObject(target, source);\n }\n }\n\n function _deepmergeAll() {\n switch (arguments.length) {\n case 0:\n return {};\n case 1:\n return clone(arguments[0]);\n case 2:\n return _deepmerge(arguments[0], arguments[1]);\n }\n let result;\n for (let i = 0, il = arguments.length; i < il; ++i) {\n result = _deepmerge(result, arguments[i]);\n }\n return result;\n }\n\n return options?.all ? _deepmergeAll : _deepmerge;\n}\n\nfunction deepmergeArray(options) {\n const deepmerge = options.deepmerge;\n const clone = options.clone;\n return function (target, source) {\n let i = 0;\n const tl = target.length;\n const sl = source.length;\n const il = Math.max(target.length, source.length);\n const result = new Array(il);\n for (i = 0; i < il; ++i) {\n if (i < sl) {\n result[i] = deepmerge(target[i], source[i]);\n } else {\n result[i] = clone(target[i]);\n }\n }\n return result;\n };\n}\n\nconst deepmerge = deepmergeConstructor({ all: true, mergeArray: deepmergeArray });\n\nconst stringFormatters = {};\n\nfunction registerStringFormatter(name, validator) {\n stringFormatters[name] = validator;\n}\n\nconst numberFormatters = {};\n\nfunction registerNumberFormatter(name, validator) {\n numberFormatters[name] = validator;\n}\n\nfunction pushPath(ctx, key) {\n ctx.path.push(key);\n}\nfunction popPath(ctx) {\n ctx.path.pop();\n}\nfunction printPath(ctx) {\n return ctx.path.join(".");\n}\nfunction buildSchemaErrorMessage(ctx, message) {\n return `Failed to print schema. At ${printPath(ctx)}: ${message}`;\n}\nfunction buildError(ctx, message, received) {\n return [\n {\n message,\n path: [...ctx.path],\n received,\n },\n ];\n}\n\nfunction buildUnionError(ctx, errors, received) {\n return [\n {\n path: [...ctx.path],\n received,\n errors,\n isUnionError: true,\n message: "expected one of",\n },\n ];\n}\n\nfunction parseIdentity(ctx, input) {\n return input;\n}\n\nfunction validateString(ctx, input) {\n return typeof input === "string";\n}\n\nfunction reportString(ctx, input) {\n return buildError(ctx, "expected string", input);\n}\n\nfunction schemaString(ctx) {\n return {\n type: "string",\n };\n}\n\nfunction describeString(ctx) {\n return "string";\n}\n\nfunction validateNumber(ctx, input) {\n return typeof input === "number";\n}\n\nfunction reportNumber(ctx, input) {\n return buildError(ctx, "expected number", input);\n}\n\nfunction schemaNumber(ctx) {\n return {\n type: "number",\n };\n}\n\nfunction describeNumber(ctx) {\n return "number";\n}\n\nfunction validateBoolean(ctx, input) {\n return typeof input === "boolean";\n}\n\nfunction reportBoolean(ctx, input) {\n return buildError(ctx, "expected boolean", input);\n}\n\nfunction schemaBoolean(ctx) {\n return {\n type: "boolean",\n };\n}\n\nfunction describeBoolean(ctx) {\n return "boolean";\n}\n\nfunction validateAny(ctx, input) {\n return true;\n}\n\nfunction reportAny(ctx, input) {\n return buildError(ctx, "expected any", input);\n}\n\nfunction schemaAny(ctx) {\n return {};\n}\n\nfunction describeAny(ctx) {\n return "any";\n}\n\nfunction validateNull(ctx, input) {\n if (input == null) {\n return true;\n }\n return false;\n}\n\nfunction reportNull(ctx, input) {\n return buildError(ctx, "expected nullish value", input);\n}\n\nfunction schemaNull(ctx) {\n return {\n type: "null",\n };\n}\n\nfunction describeNull(ctx) {\n return "null";\n}\n\nfunction validateNever(ctx, input) {\n return false;\n}\n\nfunction reportNever(ctx, input) {\n return buildError(ctx, "expected never", input);\n}\n\nfunction schemaNever(ctx) {\n return {\n anyOf: [],\n };\n}\n\nfunction describeNever(ctx) {\n return "never";\n}\n\nfunction validateFunction(ctx, input) {\n return typeof input === "function";\n}\n\nfunction reportFunction(ctx, input) {\n return buildError(ctx, "expected function", input);\n}\n\nfunction schemaFunction(ctx) {\n throw new Error(buildSchemaErrorMessage(ctx, "Cannot generate JSON Schema for function"));\n}\n\nfunction describeFunction(ctx) {\n return "function";\n}\n\nclass ConstDecoder {\n constructor(value) {\n this.value = value;\n }\n\n validateConstDecoder(ctx, input) {\n return input === this.value;\n }\n\n parseConstDecoder(ctx, input) {\n return input;\n }\n\n reportConstDecoder(ctx, input) {\n return buildError(ctx, `expected ${JSON.stringify(this.value)}`, input);\n }\n\n schemaConstDecoder(ctx) {\n return {\n const: this.value,\n };\n }\n describeConstDecoder(ctx) {\n return JSON.stringify(this.value);\n }\n}\n\nclass RegexDecoder {\n constructor(regex, description) {\n this.regex = regex;\n this.description = description;\n }\n\n validateRegexDecoder(ctx, input) {\n if (typeof input === "string") {\n return this.regex.test(input);\n }\n return false;\n }\n\n parseRegexDecoder(ctx, input) {\n return input;\n }\n\n reportRegexDecoder(ctx, input) {\n return buildError(ctx, `expected string matching ${this.description}`, input);\n }\n\n schemaRegexDecoder(ctx) {\n return {\n type: "string",\n pattern: this.description,\n };\n }\n describeRegexDecoder(ctx) {\n return "`" + this.description + "`";\n }\n}\n\nclass CodecDecoder {\n constructor(codec) {\n this.codec = codec;\n }\n validateCodecDecoder(ctx, input) {\n switch (this.codec) {\n case "Codec::ISO8061": {\n return input instanceof Date;\n }\n case "Codec::BigInt": {\n return typeof input === "bigint";\n }\n }\n return false;\n }\n parseCodecDecoder(ctx, input) {\n return input;\n }\n\n reportCodecDecoder(ctx, input) {\n switch (this.codec) {\n case "Codec::ISO8061": {\n return buildError(ctx, `expected Date`, input);\n }\n case "Codec::BigInt": {\n return buildError(ctx, `expected BigInt`, input);\n }\n }\n\n return buildError(ctx, `expected ${this.codec}`, input);\n }\n\n schemaCodecDecoder(ctx) {\n switch (this.codec) {\n case "Codec::ISO8061": {\n throw new Error(buildSchemaErrorMessage(ctx, "Cannot generate JSON Schema for Date"));\n }\n case "Codec::BigInt": {\n throw new Error(buildSchemaErrorMessage(ctx, "Cannot generate JSON Schema for BigInt"));\n }\n }\n\n throw new Error("INTERNAL ERROR: Unrecognized codec: " + this.codec);\n }\n describeCodecDecoder(ctx) {\n switch (this.codec) {\n case "Codec::ISO8061": {\n return "Date";\n }\n case "Codec::BigInt": {\n return "BigInt";\n }\n }\n throw new Error("INTERNAL ERROR: Unrecognized codec: " + this.codec);\n }\n}\n\nclass StringWithFormatsDecoder {\n constructor(...formats) {\n this.formats = formats;\n }\n\n validateStringWithFormatsDecoder(ctx, input) {\n if (typeof input !== "string") {\n return false;\n }\n\n for (const f of this.formats) {\n const validator = stringFormatters[f];\n\n if (validator == null) {\n return false;\n }\n\n if (!validator(input)) {\n return false;\n }\n }\n\n return true;\n }\n parseStringWithFormatsDecoder(ctx, input) {\n return input;\n }\n reportStringWithFormatsDecoder(ctx, input) {\n return buildError(ctx, `expected string with format "${this.formats.join(" and ")}"`, input);\n }\n schemaStringWithFormatsDecoder(ctx) {\n return {\n type: "string",\n format: this.formats.join(" and "),\n };\n }\n describeStringWithFormatsDecoder(ctx) {\n if (this.formats.length === 0) {\n throw new Error("INTERNAL ERROR: No formats provided");\n }\n const [first, ...rest] = this.formats;\n let acc = `StringFormat<"${first}">`;\n for (const r of rest) {\n acc = `StringFormatExtends<${acc}, "${r}">`;\n }\n return acc;\n }\n}\nclass NumberWithFormatsDecoder {\n constructor(...formats) {\n this.formats = formats;\n }\n\n validateNumberWithFormatsDecoder(ctx, input) {\n if (typeof input !== "number") {\n return false;\n }\n\n for (const f of this.formats) {\n const validator = numberFormatters[f];\n\n if (validator == null) {\n return false;\n }\n\n if (!validator(input)) {\n return false;\n }\n }\n\n return true;\n }\n parseNumberWithFormatsDecoder(ctx, input) {\n return input;\n }\n reportNumberWithFormatsDecoder(ctx, input) {\n return buildError(ctx, `expected number with format "${this.formats.join(" and ")}"`, input);\n }\n schemaNumberWithFormatsDecoder(ctx) {\n return {\n type: "number",\n format: this.formats.join(" and "),\n };\n }\n describeNumberWithFormatsDecoder(ctx) {\n if (this.formats.length === 0) {\n throw new Error("INTERNAL ERROR: No formats provided");\n }\n const [first, ...rest] = this.formats;\n let acc = `NumberFormat<"${first}">`;\n for (const r of rest) {\n acc = `NumberFormatExtends<${acc}, "${r}">`;\n }\n return acc;\n }\n}\n\nconst limitedCommaJoinJson = (arr) => {\n const limit = 3;\n if (arr.length < limit) {\n return arr.map((it) => JSON.stringify(it)).join(", ");\n }\n return (\n arr\n .slice(0, limit)\n .map((it) => JSON.stringify(it))\n .join(", ") + `...`\n );\n};\nclass AnyOfConstsDecoder {\n constructor(consts) {\n this.consts = consts;\n }\n validateAnyOfConstsDecoder(ctx, input) {\n if (input == null) {\n if (this.consts.includes(null) || this.consts.includes(undefined)) {\n return true;\n }\n }\n return this.consts.includes(input);\n }\n parseAnyOfConstsDecoder(ctx, input) {\n return input;\n }\n reportAnyOfConstsDecoder(ctx, input) {\n return buildError(ctx, `expected one of ${limitedCommaJoinJson(this.consts)}`, input);\n }\n schemaAnyOfConstsDecoder(ctx) {\n return {\n enum: this.consts,\n };\n }\n describeAnyOfConstsDecoder(ctx) {\n const parts = this.consts.map((it) => JSON.stringify(it));\n return parts.join(" | ");\n }\n}\n\nclass ObjectValidator {\n constructor(data, rest) {\n this.data = data;\n this.rest = rest;\n }\n\n validateObjectValidator(ctx, input) {\n if (typeof input === "object" && !Array.isArray(input) && input !== null) {\n const configKeys = Object.keys(this.data);\n for (const k of configKeys) {\n const validator = this.data[k];\n if (!validator(ctx, input[k])) {\n return false;\n }\n }\n\n if (this.rest != null) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n for (const k of extraKeys) {\n const v = input[k];\n if (!this.rest(ctx, v)) {\n return false;\n }\n }\n } else {\n if (ctx.disallowExtraProperties) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n\n if (extraKeys.length > 0) {\n return false;\n }\n }\n }\n\n return true;\n }\n return false;\n }\n}\n\nclass ObjectReporter {\n constructor(dataValidator, restValidator, dataReporter, restReporter) {\n this.dataValidator = dataValidator;\n this.restValidator = restValidator;\n this.dataReporter = dataReporter;\n this.restReporter = restReporter;\n }\n\n reportObjectReporter(ctx, input) {\n if (typeof input !== "object" || Array.isArray(input) || input === null) {\n return buildError(ctx, "expected object", input);\n }\n\n let acc = [];\n\n const configKeys = Object.keys(this.dataReporter);\n\n for (const k of configKeys) {\n const ok = this.dataValidator[k](ctx, input[k]);\n if (!ok) {\n pushPath(ctx, k);\n const arr2 = this.dataReporter[k](ctx, input[k]);\n acc.push(...arr2);\n popPath(ctx);\n }\n }\n\n if (this.restReporter != null) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n for (const k of extraKeys) {\n const ok = this.restValidator(ctx, input[k]);\n if (!ok) {\n pushPath(ctx, k);\n const arr2 = this.restReporter(ctx, input[k]);\n acc.push(...arr2);\n popPath(ctx);\n }\n }\n } else {\n if (ctx.disallowExtraProperties) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n if (extraKeys.length > 0) {\n \n return extraKeys.flatMap((k) => {\n pushPath(ctx, k);\n const err = buildError(ctx, `extra property`, input[k]);\n popPath(ctx);\n return err;\n });\n }\n }\n }\n\n return acc;\n }\n}\nclass ObjectParser {\n constructor(data, rest) {\n this.data = data;\n this.rest = rest;\n }\n\n parseObjectParser(ctx, input) {\n let acc = {};\n\n const inputKeys = Object.keys(input);\n\n for (const k of inputKeys) {\n const v = input[k];\n if (k in this.data) {\n const itemParsed = this.data[k](ctx, v);\n acc[k] = itemParsed;\n } else if (this.rest != null) {\n const restParsed = this.rest(ctx, v);\n acc[k] = restParsed;\n }\n }\n\n return acc;\n }\n}\n\nclass ObjectSchema {\n constructor(data, rest) {\n this.data = data;\n this.rest = rest;\n }\n\n schemaObjectSchema(ctx) {\n const properties = {};\n for (const k in this.data) {\n pushPath(ctx, k);\n properties[k] = this.data[k](ctx);\n popPath(ctx);\n }\n\n const required = Object.keys(this.data);\n\n const additionalProperties = this.rest != null ? this.rest(ctx) : false;\n\n return {\n type: "object",\n properties,\n required,\n additionalProperties,\n };\n }\n}\n\nclass ObjectDescribe {\n constructor(dataDescriber, restDescriber) {\n this.dataDescriber = dataDescriber;\n this.restDescriber = restDescriber;\n }\n describeObjectDescribe(ctx) {\n const sortedKeys = Object.keys(this.dataDescriber).sort();\n const props = sortedKeys\n .map((k) => {\n const describer = this.dataDescriber[k];\n return `${k}: ${describer(ctx)}`;\n })\n .join(", ");\n\n const rest = this.restDescriber != null ? `[K in string]: ${this.restDescriber(ctx)}` : null;\n\n const content = [props, rest].filter((it) => it != null && it.length > 0).join(", ");\n return `{ ${content} }`;\n }\n}\n\nclass MappedRecordValidator {\n constructor(keyValidator, valueValidator) {\n this.keyValidator = keyValidator;\n this.valueValidator = valueValidator;\n }\n\n validateMappedRecordValidator(ctx, input) {\n if (typeof input !== "object" || input == null) {\n return false;\n }\n\n for (const k in input) {\n const v = input[k];\n if (!this.keyValidator(ctx, k) || !this.valueValidator(ctx, v)) {\n return false;\n }\n }\n\n return true;\n }\n}\n\nclass MappedRecordParser {\n constructor(keyParser, valueParser) {\n this.keyParser = keyParser;\n this.valueParser = valueParser;\n }\n\n parseMappedRecordParser(ctx, input) {\n const result = {};\n for (const k in input) {\n const parsedKey = this.keyParser(ctx, k);\n const parsedValue = this.valueParser(ctx, input[k]);\n result[parsedKey] = parsedValue;\n }\n return result;\n }\n}\n\nclass MappedRecordSchema {\n constructor(keySchema, valueSchema) {\n this.keySchema = keySchema;\n this.valueSchema = valueSchema;\n }\n\n schemaMappedRecordSchema(ctx) {\n return {\n type: "object",\n additionalProperties: this.valueSchema(ctx),\n propertyNames: this.keySchema(ctx),\n };\n }\n}\n\nclass MappedRecordDescribe {\n constructor(keyDescriber, valueDescriber) {\n this.keyDescriber = keyDescriber;\n this.valueDescriber = valueDescriber;\n }\n describeMappedRecordDescribe(ctx) {\n const k = this.keyDescriber(ctx);\n const v = this.valueDescriber(ctx);\n return `Record<${k}, ${v}>`;\n }\n}\n\nclass MappedRecordReporter {\n constructor(keyValidator, valueValidator, keyReporter, valueReporter) {\n this.keyValidator = keyValidator;\n this.valueValidator = valueValidator;\n this.keyReporter = keyReporter;\n this.valueReporter = valueReporter;\n }\n\n reportMappedRecordReporter(ctx, input) {\n if (typeof input !== "object" || input == null) {\n return buildError(ctx, "expected object", input);\n }\n\n let acc = [];\n for (const k in input) {\n const v = input[k];\n const okKey = this.keyValidator(ctx, k);\n if (!okKey) {\n pushPath(ctx, k);\n const errs = this.keyReporter(ctx, k);\n acc.push(...errs);\n popPath(ctx);\n }\n const okValue = this.valueValidator(ctx, v);\n if (!okValue) {\n pushPath(ctx, k);\n const errs = this.valueReporter(ctx, v);\n acc.push(...errs);\n popPath(ctx);\n }\n }\n return acc;\n }\n}\n\nclass AnyOfDiscriminatedValidator {\n constructor(discriminator, mapping) {\n this.discriminator = discriminator;\n this.mapping = mapping;\n }\n\n validateAnyOfDiscriminatedValidator(ctx, input) {\n if (typeof input !== "object" || input == null) {\n return false;\n }\n const d = input[this.discriminator];\n if (d == null) {\n return false;\n }\n const v = this.mapping[d];\n if (v == null) {\n \n return false;\n }\n\n return v(ctx, input);\n }\n}\n\nclass AnyOfDiscriminatedParser {\n constructor(discriminator, mapping) {\n this.discriminator = discriminator;\n this.mapping = mapping;\n }\n\n parseAnyOfDiscriminatedParser(ctx, input) {\n const parser = this.mapping[input[this.discriminator]];\n if (parser == null) {\n throw new Error(\n "INTERNAL ERROR: Missing parser for discriminator " + JSON.stringify(input[this.discriminator]),\n );\n }\n return {\n ...parser(ctx, input),\n [this.discriminator]: input[this.discriminator],\n };\n }\n}\n\nclass AnyOfDiscriminatedReporter {\n constructor(discriminator, mapping) {\n this.discriminator = discriminator;\n this.mapping = mapping;\n }\n\n reportAnyOfDiscriminatedReporter(ctx, input) {\n if (input == null || typeof input !== "object") {\n return buildError(ctx, "expected object", input);\n }\n\n const d = input[this.discriminator];\n if (d == null) {\n return buildError(ctx, "expected discriminator key " + JSON.stringify(this.discriminator), input);\n }\n const v = this.mapping[d];\n if (v == null) {\n pushPath(ctx, this.discriminator);\n const errs = buildError(\n ctx,\n "expected one of " +\n Object.keys(this.mapping)\n .map((it) => JSON.stringify(it))\n .join(", "),\n d,\n );\n popPath(ctx);\n return errs;\n }\n return v(ctx, input);\n }\n}\n\nclass AnyOfDiscriminatedSchema {\n constructor(vs) {\n this.vs = vs;\n }\n\n schemaAnyOfDiscriminatedSchema(ctx) {\n \n return {\n anyOf: this.vs.map((v) => v(ctx)),\n };\n }\n}\n\nclass AnyOfDiscriminatedDescribe {\n constructor(vs) {\n this.vs = vs;\n }\n\n describeAnyOfDiscriminatedDescribe(ctx) {\n \n return `(${this.vs.map((v) => v(ctx)).join(" | ")})`;\n }\n}\n\nclass ArrayParser {\n constructor(innerParser) {\n this.innerParser = innerParser;\n }\n\n parseArrayParser(ctx, input) {\n return input.map((v) => this.innerParser(ctx, v));\n }\n}\n\nclass ArrayValidator {\n constructor(innerValidator) {\n this.innerValidator = innerValidator;\n }\n\n validateArrayValidator(ctx, input) {\n if (Array.isArray(input)) {\n for (let i = 0; i < input.length; i++) {\n const v = input[i];\n const ok = this.innerValidator(ctx, v);\n if (!ok) {\n return false;\n }\n }\n return true;\n }\n return false;\n }\n}\n\nclass ArrayReporter {\n constructor(innerValidator, innerReporter) {\n this.innerValidator = innerValidator;\n this.innerReporter = innerReporter;\n }\n\n reportArrayReporter(ctx, input) {\n if (!Array.isArray(input)) {\n return buildError(ctx, "expected array", input);\n }\n\n let acc = [];\n for (let i = 0; i < input.length; i++) {\n const ok = this.innerValidator(ctx, input[i]);\n if (!ok) {\n pushPath(ctx, `[${i}]`);\n const v = input[i];\n const arr2 = this.innerReporter(ctx, v);\n acc.push(...arr2);\n popPath(ctx);\n }\n }\n\n return acc;\n }\n}\n\nclass ArraySchema {\n constructor(innerSchema) {\n this.innerSchema = innerSchema;\n }\n\n schemaArraySchema(ctx) {\n pushPath(ctx, "[]");\n const items = this.innerSchema(ctx);\n popPath(ctx);\n return {\n type: "array",\n items,\n };\n }\n}\n\nclass ArrayDescribe {\n constructor(innerDescriber) {\n this.innerDescriber = innerDescriber;\n }\n describeArrayDescribe(ctx) {\n return `Array<${this.innerDescriber(ctx)}>`;\n }\n}\n\nclass AnyOfValidator {\n constructor(vs) {\n this.vs = vs;\n }\n validateAnyOfValidator(ctx, input) {\n for (const v of this.vs) {\n if (v(ctx, input)) {\n return true;\n }\n }\n return false;\n }\n}\nclass AnyOfParser {\n constructor(validators, parsers) {\n this.validators = validators;\n this.parsers = parsers;\n }\n parseAnyOfParser(ctx, input) {\n const items = [];\n for (let i = 0; i < this.validators.length; i++) {\n if (this.validators[i](ctx, input)) {\n items.push(this.parsers[i](ctx, input));\n }\n }\n return deepmerge(...items);\n }\n}\nclass AnyOfReporter {\n constructor(validators, reporters) {\n this.validators = validators;\n this.reporters = reporters;\n }\n reportAnyOfReporter(ctx, input) {\n const acc = [];\n const oldPaths = ctx.path;\n ctx.path = [];\n for (const v of this.reporters) {\n const errors = v(ctx, input);\n acc.push(...errors);\n }\n ctx.path = oldPaths;\n return buildUnionError(ctx, acc, input);\n }\n}\n\nclass AnyOfSchema {\n constructor(schemas) {\n this.schemas = schemas;\n }\n schemaAnyOfSchema(ctx) {\n return {\n anyOf: this.schemas.map((s) => s(ctx)),\n };\n }\n}\n\nclass AnyOfDescribe {\n constructor(describers) {\n this.describers = describers;\n }\n describeAnyOfDescribe(ctx) {\n return `(${this.describers.map((v) => v(ctx)).join(" | ")})`;\n }\n}\n\nclass AllOfValidator {\n constructor(vs) {\n this.vs = vs;\n }\n validateAllOfValidator(ctx, input) {\n for (const v of this.vs) {\n const isObj = typeof input === "object";\n if (!isObj) {\n return false;\n }\n if (!v(ctx, input)) {\n return false;\n }\n }\n return true;\n }\n}\n\nclass AllOfParser {\n constructor(validators, parsers) {\n this.validators = validators;\n this.parsers = parsers;\n }\n parseAllOfParser(ctx, input) {\n let acc = {};\n for (let i = 0; i < this.validators.length; i++) {\n const p = this.parsers[i];\n const parsed = p(ctx, input);\n if (typeof parsed !== "object") {\n throw new Error("INTERNAL ERROR: AllOfParser: Expected object");\n }\n acc = { ...acc, ...parsed };\n }\n return acc;\n }\n}\n\nclass AllOfReporter {\n constructor(validators, reporters) {\n this.validators = validators;\n this.reporters = reporters;\n }\n reportAllOfReporter(ctx, input) {\n const acc = [];\n for (const v of this.reporters) {\n const errors = v(ctx, input);\n acc.push(...errors);\n }\n return acc;\n }\n}\n\nclass AllOfSchema {\n constructor(schemas) {\n this.schemas = schemas;\n }\n schemaAllOfSchema(ctx) {\n return {\n allOf: this.schemas.map((s) => s(ctx)),\n };\n }\n}\n\nclass AllOfDescribe {\n constructor(describers) {\n this.describers = describers;\n }\n describeAllOfDescribe(ctx) {\n return `(${this.describers.map((v) => v(ctx)).join(" & ")})`;\n }\n}\n\nclass TupleValidator {\n constructor(prefix, rest) {\n this.prefix = prefix;\n this.rest = rest;\n }\n validateTupleValidator(ctx, input) {\n if (Array.isArray(input)) {\n let idx = 0;\n for (const prefixVal of this.prefix) {\n if (!prefixVal(ctx, input[idx])) {\n return false;\n }\n idx++;\n }\n const itemVal = this.rest;\n if (itemVal != null) {\n for (let i = idx; i < input.length; i++) {\n if (!itemVal(ctx, input[i])) {\n return false;\n }\n }\n } else {\n if (input.length > idx) {\n return false;\n }\n }\n return true;\n }\n return false;\n }\n}\n\nclass TupleParser {\n constructor(prefix, rest) {\n this.prefix = prefix;\n this.rest = rest;\n }\n parseTupleParser(ctx, input) {\n let idx = 0;\n let acc = [];\n for (const prefixParser of this.prefix) {\n acc.push(prefixParser(ctx, input[idx]));\n idx++;\n }\n if (this.rest != null) {\n for (let i = idx; i < input.length; i++) {\n acc.push(this.rest(ctx, input[i]));\n }\n }\n return acc;\n }\n}\n\nclass TupleReporter {\n constructor(prefixValidator, restValidator, prefixReporter, restReporter) {\n this.prefixValidator = prefixValidator;\n this.restValidator = restValidator;\n this.prefixReporter = prefixReporter;\n this.restReporter = restReporter;\n }\n reportTupleReporter(ctx, input) {\n if (!Array.isArray(input)) {\n return buildError(ctx, "expected tuple", input);\n }\n\n let idx = 0;\n\n let acc = [];\n\n for (const prefixReporter of this.prefixReporter) {\n const ok = this.prefixValidator[idx](ctx, input[idx]);\n if (!ok) {\n pushPath(ctx, `[${idx}]`);\n const errors = prefixReporter(ctx, input[idx]);\n acc.push(...errors);\n popPath(ctx);\n }\n idx++;\n }\n\n const restReporter = this.restReporter;\n if (restReporter != null) {\n for (let i = idx; i < input.length; i++) {\n const ok = this.restValidator(ctx, input[i]);\n if (!ok) {\n pushPath(ctx, `[${i}]`);\n const errors = restReporter(ctx, input[i]);\n acc.push(...errors);\n popPath(ctx);\n }\n }\n }\n\n return acc;\n }\n}\n\nclass TupleSchema {\n constructor(prefix, rest) {\n this.prefix = prefix;\n this.rest = rest;\n }\n\n schemaTupleSchema(ctx) {\n pushPath(ctx, "[]");\n const prefixItems = this.prefix.map((s) => s(ctx));\n const items = this.rest != null ? this.rest(ctx) : false;\n popPath(ctx);\n return {\n type: "array",\n prefixItems,\n items,\n };\n }\n}\n\nclass TupleDescribe {\n constructor(prefix, rest) {\n this.prefix = prefix;\n this.rest = rest;\n }\n describeTupleDescribe(ctx) {\n const prefix = this.prefix.map((d) => d(ctx)).join(", ");\n const rest = this.rest != null ? `...Array<${this.rest(ctx)}>` : null;\n\n const inner = [prefix, rest].filter((it) => it != null && it.length > 0).join(", ");\n return `[${inner}]`;\n }\n}\n', "parser.d.ts": 'import { BuildParserFunction } from "@beff/client";\n\ndeclare const _exports: {\n buildParsers: BuildParserFunction;\n};\n\nexport default _exports;\n' };
|
|
45784
|
+
var bundle_default = { "build-parsers.js": '\n\nfunction buildParsers(args) {\n const stringFormats = args?.stringFormats ?? {};\n \n for (const k of RequiredStringFormats) {\n if (stringFormats[k] == null) {\n throw new Error(`Missing custom format ${k}`);\n }\n }\n\n Object.keys(stringFormats).forEach((k) => {\n const v = stringFormats[k];\n \n registerStringFormatter(k, v);\n });\n\n const numberFormats = args?.numberFormats ?? {};\n \n for (const k of RequiredNumberFormats) {\n if (numberFormats[k] == null) {\n throw new Error(`Missing custom format ${k}`);\n }\n }\n\n Object.keys(numberFormats).forEach((k) => {\n const v = numberFormats[k];\n \n registerNumberFormatter(k, v);\n });\n\n let decoders = {};\n \n Object.keys(buildValidatorsInput).forEach((k) => {\n \n let v = buildValidatorsInput[k];\n const validate = (input, options) => {\n const disallowExtraProperties = options?.disallowExtraProperties ?? false;\n const ctx = { disallowExtraProperties };\n const ok = v(ctx, input);\n if (typeof ok !== "boolean") {\n throw new Error("INTERNAL ERROR: Expected boolean");\n }\n return ok;\n };\n\n \n const schemaFn = buildSchemaInput[k];\n const schema = () => {\n const ctx = {\n path: [],\n seen: {},\n };\n return schemaFn(ctx);\n };\n\n \n const describeFn = buildDescribeInput[k];\n const describe = () => {\n const ctx = {\n deps: {},\n deps_counter: {},\n measure: true,\n };\n let out = describeFn(ctx);\n ctx["deps"] = {};\n ctx["measure"] = false;\n out = describeFn(ctx);\n let sortedDepsKeys = Object.keys(ctx.deps).sort();\n \n \n \n \n const depsPart = sortedDepsKeys\n .map((key) => {\n return `type ${key} = ${ctx.deps[key]};`;\n })\n .join("\\n\\n");\n \n \n \n const outPart = `type Codec${k} = ${out};`;\n return [depsPart, outPart].filter((it) => it != null && it.length > 0).join("\\n\\n");\n };\n\n const safeParse = (input, options) => {\n const disallowExtraProperties = options?.disallowExtraProperties ?? false;\n const ok = validate(input, options);\n if (ok) {\n \n let p = buildParsersInput[k];\n let ctx = { disallowExtraProperties };\n const parsed = p(ctx, input);\n return { success: true, data: parsed };\n }\n \n let e = buildReportersInput[k];\n let ctx = { path: [], disallowExtraProperties };\n return {\n success: false,\n errors: e(ctx, input).slice(0, 10),\n };\n };\n const parse = (input, options) => {\n const safe = safeParse(input, options);\n if (safe.success) {\n return safe.data;\n }\n \n const explained = printErrors(safe.errors, []);\n throw new Error(`Failed to parse ${k} - ${explained}`);\n };\n const zod = () => {\n \n return z.custom(\n (data) => safeParse(data).success,\n (val) => {\n const errors = safeParse(val).errors;\n \n return printErrors(errors, []);\n },\n );\n };\n decoders[k] = {\n parse,\n safeParse,\n zod,\n name: k,\n validate,\n schema,\n describe,\n };\n });\n return decoders;\n}\n', "codegen-v2.js": '"use strict";\nimport {\n printErrors\n} from "@beff/client";\nconst JSON_PROTO = Object.getPrototypeOf({});\nfunction deepmergeConstructor(options) {\n function isNotPrototypeKey(value) {\n return value !== "constructor" && value !== "prototype" && value !== "__proto__";\n }\n function cloneArray(value) {\n let i = 0;\n const il = value.length;\n const result = new Array(il);\n for (i; i < il; ++i) {\n result[i] = clone(value[i]);\n }\n return result;\n }\n function cloneObject(target) {\n const result = {};\n if (cloneProtoObject && Object.getPrototypeOf(target) !== JSON_PROTO) {\n return cloneProtoObject(target);\n }\n const targetKeys = getKeys(target);\n let i, il, key;\n for (i = 0, il = targetKeys.length; i < il; ++i) {\n isNotPrototypeKey(key = targetKeys[i]) && (result[key] = clone(target[key]));\n }\n return result;\n }\n function concatArrays(target, source) {\n const tl = target.length;\n const sl = source.length;\n let i = 0;\n const result = new Array(tl + sl);\n for (i; i < tl; ++i) {\n result[i] = clone(target[i]);\n }\n for (i = 0; i < sl; ++i) {\n result[i + tl] = clone(source[i]);\n }\n return result;\n }\n const propertyIsEnumerable = Object.prototype.propertyIsEnumerable;\n function getSymbolsAndKeys(value) {\n const result = Object.keys(value);\n const keys = Object.getOwnPropertySymbols(value);\n for (let i = 0, il = keys.length; i < il; ++i) {\n propertyIsEnumerable.call(value, keys[i]) && result.push(keys[i]);\n }\n return result;\n }\n const getKeys = options?.symbols ? getSymbolsAndKeys : Object.keys;\n const cloneProtoObject = typeof options?.cloneProtoObject === "function" ? options.cloneProtoObject : void 0;\n function isMergeableObject(value) {\n return typeof value === "object" && value !== null && !(value instanceof RegExp) && !(value instanceof Date);\n }\n function isPrimitive(value) {\n return typeof value !== "object" || value === null;\n }\n const isPrimitiveOrBuiltIn = (\n \n typeof Buffer !== "undefined" ? (value) => typeof value !== "object" || value === null || value instanceof RegExp || value instanceof Date || \n value instanceof Buffer : (value) => typeof value !== "object" || value === null || value instanceof RegExp || value instanceof Date\n );\n const mergeArray = options && typeof options.mergeArray === "function" ? options.mergeArray({ clone, deepmerge: _deepmerge, getKeys, isMergeableObject }) : concatArrays;\n function clone(entry) {\n return isMergeableObject(entry) ? Array.isArray(entry) ? cloneArray(entry) : cloneObject(entry) : entry;\n }\n function mergeObject(target, source) {\n const result = {};\n const targetKeys = getKeys(target);\n const sourceKeys = getKeys(source);\n let i, il, key;\n for (i = 0, il = targetKeys.length; i < il; ++i) {\n isNotPrototypeKey(key = targetKeys[i]) && sourceKeys.indexOf(key) === -1 && \n (result[key] = clone(target[key]));\n }\n for (i = 0, il = sourceKeys.length; i < il; ++i) {\n if (!isNotPrototypeKey(key = sourceKeys[i])) {\n continue;\n }\n if (key in target) {\n if (targetKeys.indexOf(key) !== -1) {\n if (cloneProtoObject && isMergeableObject(source[key]) && Object.getPrototypeOf(source[key]) !== JSON_PROTO) {\n result[key] = cloneProtoObject(source[key]);\n } else {\n result[key] = _deepmerge(target[key], source[key]);\n }\n }\n } else {\n result[key] = clone(source[key]);\n }\n }\n return result;\n }\n function _deepmerge(target, source) {\n const sourceIsArray = Array.isArray(source);\n const targetIsArray = Array.isArray(target);\n if (isPrimitive(source)) {\n return source;\n } else if (isPrimitiveOrBuiltIn(target)) {\n return clone(source);\n } else if (sourceIsArray && targetIsArray) {\n return mergeArray(target, source);\n } else if (sourceIsArray !== targetIsArray) {\n return clone(source);\n } else {\n return mergeObject(target, source);\n }\n }\n function _deepmergeAll() {\n switch (arguments.length) {\n case 0:\n return {};\n case 1:\n return clone(arguments[0]);\n case 2:\n return _deepmerge(arguments[0], arguments[1]);\n }\n let result;\n for (let i = 0, il = arguments.length; i < il; ++i) {\n result = _deepmerge(result, arguments[i]);\n }\n return result;\n }\n return _deepmergeAll;\n}\nfunction deepmergeArray(options) {\n const deepmerge2 = options.deepmerge;\n const clone = options.clone;\n return function(target, source) {\n let i = 0;\n const tl = target.length;\n const sl = source.length;\n const il = Math.max(target.length, source.length);\n const result = new Array(il);\n for (i = 0; i < il; ++i) {\n if (i < sl) {\n result[i] = deepmerge2(target[i], source[i]);\n } else {\n result[i] = clone(target[i]);\n }\n }\n return result;\n };\n}\nconst deepmerge = deepmergeConstructor({ mergeArray: deepmergeArray });\nfunction buildUnionError(ctx, errors, received) {\n return [\n {\n path: [...ctx.path],\n received,\n errors,\n isUnionError: true\n }\n ];\n}\nfunction buildError(ctx, message, received) {\n return [\n {\n message,\n path: [...ctx.path],\n received\n }\n ];\n}\nfunction pushPath(ctx, key) {\n ctx.path.push(key);\n}\nfunction popPath(ctx) {\n ctx.path.pop();\n}\nfunction printPath(ctx) {\n return ctx.path.join(".");\n}\nfunction buildSchemaErrorMessage(ctx, message) {\n return `Failed to print schema. At ${printPath(ctx)}: ${message}`;\n}\nconst limitedCommaJoinJson = (arr) => {\n const limit = 3;\n if (arr.length < limit) {\n return arr.map((it) => JSON.stringify(it)).join(", ");\n }\n return arr.slice(0, limit).map((it) => JSON.stringify(it)).join(", ") + `...`;\n};\nconst stringFormatters = {};\nfunction registerStringFormatter(name, validator) {\n stringFormatters[name] = validator;\n}\nconst numberFormatters = {};\nfunction registerNumberFormatter(name, validator) {\n numberFormatters[name] = validator;\n}\nclass ParserTypeOfImpl {\n typeName;\n constructor(typeName) {\n this.typeName = typeName;\n }\n describe(_ctx) {\n return this.typeName;\n }\n schema(_ctx) {\n return { type: this.typeName };\n }\n validate(_ctx, input) {\n return typeof input === this.typeName;\n }\n parseAfterValidation(_ctx, input) {\n return input;\n }\n reportDecodeError(ctx, input) {\n return buildError(ctx, "expected " + this.typeName, input);\n }\n}\nclass ParserAnyImpl {\n describe(_ctx) {\n return "any";\n }\n schema(_ctx) {\n return {};\n }\n validate(_ctx, _input) {\n return true;\n }\n parseAfterValidation(_ctx, input) {\n return input;\n }\n reportDecodeError(ctx, input) {\n return buildError(ctx, "expected any", input);\n }\n}\nclass ParserNullImpl {\n describe(_ctx) {\n return "null";\n }\n schema(_ctx) {\n return { type: "null" };\n }\n validate(_ctx, input) {\n return input == null;\n }\n parseAfterValidation(_ctx, input) {\n return input;\n }\n reportDecodeError(ctx, input) {\n return buildError(ctx, "expected nullish value", input);\n }\n}\nclass ParserNeverImpl {\n describe(_ctx) {\n return "never";\n }\n schema(_ctx) {\n return { anyOf: [] };\n }\n validate(_ctx, _input) {\n return false;\n }\n parseAfterValidation(_ctx, _input) {\n throw new Error("unreachable");\n }\n reportDecodeError(ctx, input) {\n return buildError(ctx, "expected never", input);\n }\n}\nclass ParserConstImpl {\n value;\n constructor(value) {\n this.value = value ?? null;\n }\n describe(_ctx) {\n return JSON.stringify(this.value);\n }\n schema(_ctx) {\n return { const: this.value };\n }\n validate(_ctx, input) {\n if (this.value == null) {\n return input == this.value;\n }\n return input === this.value;\n }\n parseAfterValidation(_ctx, input) {\n return input;\n }\n reportDecodeError(ctx, input) {\n return buildError(ctx, `expected ${JSON.stringify(this.value)}`, input);\n }\n}\nclass ParserRegexImpl {\n regex;\n description;\n constructor(regex, description) {\n this.regex = regex;\n this.description = description;\n }\n describe(_ctx) {\n return "`" + this.description + "`";\n }\n schema(_ctx) {\n return { type: "string", pattern: this.description };\n }\n validate(_ctx, input) {\n if (typeof input === "string") {\n return this.regex.test(input);\n }\n return false;\n }\n parseAfterValidation(ctx, input) {\n return input;\n }\n reportDecodeError(ctx, input) {\n return buildError(ctx, `expected string matching ${this.description}`, input);\n }\n}\nclass ParserDateImpl {\n describe(_ctx) {\n return "Date";\n }\n schema(ctx) {\n throw new Error(buildSchemaErrorMessage(ctx, "Cannot generate JSON Schema for Date"));\n }\n validate(_ctx, input) {\n return input instanceof Date;\n }\n parseAfterValidation(ctx, input) {\n return input;\n }\n reportDecodeError(ctx, input) {\n return buildError(ctx, `expected Date`, input);\n }\n}\nclass ParserBigIntImpl {\n describe(_ctx) {\n return "BigInt";\n }\n schema(ctx) {\n throw new Error(buildSchemaErrorMessage(ctx, "Cannot generate JSON Schema for BigInt"));\n }\n validate(_ctx, input) {\n return typeof input === "bigint";\n }\n parseAfterValidation(ctx, input) {\n return input;\n }\n reportDecodeError(ctx, input) {\n return buildError(ctx, `expected BigInt`, input);\n }\n}\nclass ParserStringWithFormatImpl {\n formats;\n constructor(formats) {\n this.formats = formats;\n }\n describe(ctx) {\n if (this.formats.length === 0) {\n throw new Error("INTERNAL ERROR: No formats provided");\n }\n const [first, ...rest] = this.formats;\n let acc = `StringFormat<"${first}">`;\n for (const r of rest) {\n acc = `StringFormatExtends<${acc}, "${r}">`;\n }\n return acc;\n }\n schema(ctx) {\n return {\n type: "string",\n format: this.formats.join(" and ")\n };\n }\n validate(ctx, input) {\n if (typeof input !== "string") {\n return false;\n }\n for (const f of this.formats) {\n const validator = stringFormatters[f];\n if (validator == null) {\n return false;\n }\n if (!validator(input)) {\n return false;\n }\n }\n return true;\n }\n parseAfterValidation(ctx, input) {\n return input;\n }\n reportDecodeError(ctx, input) {\n return buildError(ctx, `expected string with format "${this.formats.join(" and ")}"`, input);\n }\n}\nclass ParserNumberWithFormatImpl {\n formats;\n constructor(formats) {\n this.formats = formats;\n }\n describe(ctx) {\n if (this.formats.length === 0) {\n throw new Error("INTERNAL ERROR: No formats provided");\n }\n const [first, ...rest] = this.formats;\n let acc = `NumberFormat<"${first}">`;\n for (const r of rest) {\n acc = `NumberFormatExtends<${acc}, "${r}">`;\n }\n return acc;\n }\n schema(ctx) {\n return {\n type: "number",\n format: this.formats.join(" and ")\n };\n }\n validate(ctx, input) {\n if (typeof input !== "number") {\n return false;\n }\n for (const f of this.formats) {\n const validator = numberFormatters[f];\n if (validator == null) {\n return false;\n }\n if (!validator(input)) {\n return false;\n }\n }\n return true;\n }\n parseAfterValidation(ctx, input) {\n return input;\n }\n reportDecodeError(ctx, input) {\n return buildError(ctx, `expected number with format "${this.formats.join(" and ")}"`, input);\n }\n}\nclass ParserAnyOfConstsImpl {\n values;\n constructor(values) {\n this.values = values;\n }\n describe(ctx) {\n const parts = this.values.map((it) => JSON.stringify(it));\n return parts.join(" | ");\n }\n schema(ctx) {\n return {\n enum: this.values\n };\n }\n validate(ctx, input) {\n if (input == null) {\n if (this.values.includes(null)) {\n return true;\n }\n }\n return this.values.includes(input);\n }\n parseAfterValidation(ctx, input) {\n return input;\n }\n reportDecodeError(ctx, input) {\n return buildError(ctx, `expected one of ${limitedCommaJoinJson(this.values)}`, input);\n }\n}\nclass ParserTupleImpl {\n prefix;\n rest;\n constructor(prefix, rest) {\n this.prefix = prefix;\n this.rest = rest;\n }\n describe(ctx) {\n const prefix = this.prefix.map((it) => it.describe(ctx)).join(", ");\n const rest = this.rest != null ? `...Array<${this.rest.describe(ctx)}>` : null;\n const inner = [prefix, rest].filter((it) => it != null && it.length > 0).join(", ");\n return `[${inner}]`;\n }\n schema(ctx) {\n pushPath(ctx, "[]");\n const prefixItems = this.prefix.map((it) => it.schema(ctx));\n const items = this.rest != null ? this.rest.schema(ctx) : false;\n popPath(ctx);\n return {\n type: "array",\n prefixItems,\n items\n };\n }\n validate(ctx, input) {\n if (Array.isArray(input)) {\n let idx = 0;\n for (const prefixItem of this.prefix) {\n if (!prefixItem.validate(ctx, input[idx])) {\n return false;\n }\n idx++;\n }\n if (this.rest != null) {\n for (let i = idx; i < input.length; i++) {\n if (!this.rest.validate(ctx, input[i])) {\n return false;\n }\n }\n } else {\n if (input.length > idx) {\n return false;\n }\n }\n return true;\n }\n return false;\n }\n parseAfterValidation(ctx, input) {\n let idx = 0;\n let acc = [];\n for (const prefixItem of this.prefix) {\n acc.push(prefixItem.parseAfterValidation(ctx, input[idx]));\n idx++;\n }\n if (this.rest != null) {\n for (let i = idx; i < input.length; i++) {\n acc.push(this.rest.parseAfterValidation(ctx, input[i]));\n }\n }\n return acc;\n }\n reportDecodeError(ctx, input) {\n if (!Array.isArray(input)) {\n return buildError(ctx, "expected tuple", input);\n }\n let idx = 0;\n let acc = [];\n for (const prefixItem of this.prefix) {\n const ok = prefixItem.validate(ctx, input[idx]);\n if (!ok) {\n pushPath(ctx, `[${idx}]`);\n const errors = prefixItem.reportDecodeError(ctx, input[idx]);\n acc.push(...errors);\n popPath(ctx);\n }\n idx++;\n }\n if (this.rest != null) {\n for (let i = idx; i < input.length; i++) {\n const ok = this.rest.validate(ctx, input[i]);\n if (!ok) {\n pushPath(ctx, `[${i}]`);\n const errors = this.rest.reportDecodeError(ctx, input[i]);\n acc.push(...errors);\n popPath(ctx);\n }\n }\n }\n return acc;\n }\n}\nclass ParserAllOfImpl {\n schemas;\n constructor(schemas) {\n this.schemas = schemas;\n }\n describe(ctx) {\n return `(${this.schemas.map((it) => it.describe(ctx)).join(" & ")})`;\n }\n schema(ctx) {\n return {\n allOf: this.schemas.map((it) => it.schema(ctx))\n };\n }\n validate(ctx, input) {\n for (const it of this.schemas) {\n const isObj = typeof input === "object";\n if (!isObj) {\n return false;\n }\n if (!it.validate(ctx, input)) {\n return false;\n }\n }\n return true;\n }\n parseAfterValidation(ctx, input) {\n let acc = {};\n for (const it of this.schemas) {\n const parsed = it.parseAfterValidation(ctx, input);\n if (typeof parsed !== "object") {\n throw new Error("INTERNAL ERROR: AllOfParser: Expected object");\n }\n acc = { ...acc, ...parsed };\n }\n return acc;\n }\n reportDecodeError(ctx, input) {\n const acc = [];\n for (const v of this.schemas) {\n const errors = v.reportDecodeError(ctx, input);\n acc.push(...errors);\n }\n return acc;\n }\n}\nclass ParserAnyOfImpl {\n schemas;\n constructor(schemas) {\n this.schemas = schemas;\n }\n schema(ctx) {\n return {\n anyOf: this.schemas.map((it) => it.schema(ctx))\n };\n }\n validate(ctx, input) {\n for (const it of this.schemas) {\n if (it.validate(ctx, input)) {\n return true;\n }\n }\n return false;\n }\n parseAfterValidation(ctx, input) {\n const items = [];\n for (const it of this.schemas) {\n if (it.validate(ctx, input)) {\n items.push(it.parseAfterValidation(ctx, input));\n }\n }\n return deepmerge(...items);\n }\n reportDecodeError(ctx, input) {\n const acc = [];\n const oldPaths = ctx.path;\n ctx.path = [];\n for (const v of this.schemas) {\n const errors = v.reportDecodeError(ctx, input);\n acc.push(...errors);\n }\n ctx.path = oldPaths;\n return buildUnionError(ctx, acc, input);\n }\n describe(ctx) {\n return `(${this.schemas.map((it) => it.describe(ctx)).join(" | ")})`;\n }\n}\nclass ParserArrayImpl {\n itemParser;\n constructor(itemParser) {\n this.itemParser = itemParser;\n }\n schema(ctx) {\n pushPath(ctx, "[]");\n const items = this.itemParser.schema(ctx);\n popPath(ctx);\n return {\n type: "array",\n items\n };\n }\n validate(ctx, input) {\n if (Array.isArray(input)) {\n for (let i = 0; i < input.length; i++) {\n const v = input[i];\n const ok = this.itemParser.validate(ctx, v);\n if (!ok) {\n return false;\n }\n }\n return true;\n }\n return false;\n }\n parseAfterValidation(ctx, input) {\n return input.map((v) => this.itemParser.parseAfterValidation(ctx, v));\n }\n reportDecodeError(ctx, input) {\n if (!Array.isArray(input)) {\n return buildError(ctx, "expected array", input);\n }\n let acc = [];\n for (let i = 0; i < input.length; i++) {\n const ok = this.itemParser.validate(ctx, input[i]);\n if (!ok) {\n pushPath(ctx, `[${i}]`);\n const v = input[i];\n const arr2 = this.itemParser.reportDecodeError(ctx, v);\n acc.push(...arr2);\n popPath(ctx);\n }\n }\n return acc;\n }\n describe(ctx) {\n return `Array<${this.itemParser.describe(ctx)}>`;\n }\n}\nclass ParserAnyOfDiscriminatedImpl {\n schemas;\n discriminator;\n mapping;\n constructor(schemas, discriminator, mapping) {\n this.schemas = schemas;\n this.discriminator = discriminator;\n this.mapping = mapping;\n }\n schema(ctx) {\n return {\n anyOf: this.schemas.map((it) => it.schema(ctx))\n };\n }\n validate(ctx, input) {\n if (typeof input !== "object" || input == null) {\n return false;\n }\n const d = input[this.discriminator];\n if (d == null) {\n return false;\n }\n const v = this.mapping[d];\n if (v == null) {\n return false;\n }\n return v.validate(ctx, input);\n }\n parseAfterValidation(ctx, input) {\n const parser = this.mapping[input[this.discriminator]];\n if (parser == null) {\n throw new Error(\n "INTERNAL ERROR: Missing parser for discriminator " + JSON.stringify(input[this.discriminator])\n );\n }\n return {\n ...parser.parseAfterValidation(ctx, input),\n [this.discriminator]: input[this.discriminator]\n };\n }\n reportDecodeError(ctx, input) {\n if (input == null || typeof input !== "object") {\n return buildError(ctx, "expected object", input);\n }\n const d = input[this.discriminator];\n if (d == null) {\n return buildError(ctx, "expected discriminator key " + JSON.stringify(this.discriminator), input);\n }\n const v = this.mapping[d];\n if (v == null) {\n pushPath(ctx, this.discriminator);\n const errs = buildError(\n ctx,\n "expected one of " + Object.keys(this.mapping).map((it) => JSON.stringify(it)).join(", "),\n d\n );\n popPath(ctx);\n return errs;\n }\n return v.reportDecodeError(ctx, input);\n }\n describe(ctx) {\n return `(${this.schemas.map((it) => it.describe(ctx)).join(" | ")})`;\n }\n}\nclass ParserMappedRecordImpl {\n keyParser;\n valueParser;\n constructor(keyParser, valueParser) {\n this.keyParser = keyParser;\n this.valueParser = valueParser;\n }\n describe(ctx) {\n const k = this.keyParser.describe(ctx);\n const v = this.valueParser.describe(ctx);\n return `Record<${k}, ${v}>`;\n }\n schema(ctx) {\n return {\n type: "object",\n additionalProperties: this.valueParser.schema(ctx),\n propertyNames: this.keyParser.schema(ctx)\n };\n }\n validate(ctx, input) {\n if (typeof input !== "object" || input == null) {\n return false;\n }\n for (const k in input) {\n const v = input[k];\n if (!this.keyParser.validate(ctx, k) || !this.valueParser.validate(ctx, v)) {\n return false;\n }\n }\n return true;\n }\n parseAfterValidation(ctx, input) {\n const result = {};\n for (const k in input) {\n const parsedKey = this.keyParser.parseAfterValidation(ctx, k);\n const parsedValue = this.valueParser.parseAfterValidation(ctx, input[k]);\n result[parsedKey] = parsedValue;\n }\n return result;\n }\n reportDecodeError(ctx, input) {\n if (typeof input !== "object" || input == null) {\n return buildError(ctx, "expected object", input);\n }\n let acc = [];\n for (const k in input) {\n const v = input[k];\n const okKey = this.keyParser.validate(ctx, k);\n if (!okKey) {\n pushPath(ctx, k);\n const errs = this.keyParser.reportDecodeError(ctx, k);\n acc.push(...errs);\n popPath(ctx);\n }\n const okValue = this.valueParser.validate(ctx, v);\n if (!okValue) {\n pushPath(ctx, k);\n const errs = this.valueParser.reportDecodeError(ctx, v);\n acc.push(...errs);\n popPath(ctx);\n }\n }\n return acc;\n }\n}\nclass ParserObjectImpl {\n properties;\n restParser;\n constructor(properties, restParser) {\n this.properties = properties;\n this.restParser = restParser;\n }\n describe(ctx) {\n const sortedKeys = Object.keys(this.properties).sort();\n const props = sortedKeys.map((k) => {\n const it = this.properties[k];\n return `${k}: ${it.describe(ctx)}`;\n }).join(", ");\n const rest = this.restParser != null ? `[K in string]: ${this.restParser.describe(ctx)}` : null;\n const content = [props, rest].filter((it) => it != null && it.length > 0).join(", ");\n return `{ ${content} }`;\n }\n schema(ctx) {\n const properties = {};\n for (const k in this.properties) {\n pushPath(ctx, k);\n properties[k] = this.properties[k].schema(ctx);\n popPath(ctx);\n }\n const required = Object.keys(this.properties);\n const additionalProperties = this.restParser != null ? this.restParser.schema(ctx) : false;\n return {\n type: "object",\n properties,\n required,\n additionalProperties\n };\n }\n validate(ctx, input) {\n if (typeof input === "object" && !Array.isArray(input) && input !== null) {\n const configKeys = Object.keys(this.properties);\n for (const k of configKeys) {\n const validator = this.properties[k];\n if (!validator.validate(ctx, input[k])) {\n return false;\n }\n }\n if (this.restParser != null) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n for (const k of extraKeys) {\n const v = input[k];\n if (!this.restParser.validate(ctx, v)) {\n return false;\n }\n }\n } else {\n if (ctx.disallowExtraProperties) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n if (extraKeys.length > 0) {\n return false;\n }\n }\n }\n return true;\n }\n return false;\n }\n parseAfterValidation(ctx, input) {\n let acc = {};\n const inputKeys = Object.keys(input);\n for (const k of inputKeys) {\n const v = input[k];\n if (k in this.properties) {\n const itemParsed = this.properties[k].parseAfterValidation(ctx, v);\n acc[k] = itemParsed;\n } else if (this.restParser != null) {\n const restParsed = this.restParser.parseAfterValidation(ctx, v);\n acc[k] = restParsed;\n }\n }\n return acc;\n }\n reportDecodeError(ctx, input) {\n if (typeof input !== "object" || Array.isArray(input) || input === null) {\n return buildError(ctx, "expected object", input);\n }\n let acc = [];\n const configKeys = Object.keys(this.properties);\n for (const k of configKeys) {\n const ok = this.properties[k].validate(ctx, input[k]);\n if (!ok) {\n pushPath(ctx, k);\n const arr2 = this.properties[k].reportDecodeError(ctx, input[k]);\n acc.push(...arr2);\n popPath(ctx);\n }\n }\n if (this.restParser != null) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n for (const k of extraKeys) {\n const ok = this.restParser.validate(ctx, input[k]);\n if (!ok) {\n pushPath(ctx, k);\n const arr2 = this.restParser.reportDecodeError(ctx, input[k]);\n acc.push(...arr2);\n popPath(ctx);\n }\n }\n } else {\n if (ctx.disallowExtraProperties) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n if (extraKeys.length > 0) {\n return extraKeys.flatMap((k) => {\n pushPath(ctx, k);\n const err = buildError(ctx, `extra property`, input[k]);\n popPath(ctx);\n return err;\n });\n }\n }\n }\n return acc;\n }\n}\nclass ParserRefImpl {\n refName;\n constructor(refName) {\n this.refName = refName;\n }\n describe(ctx) {\n const name = this.refName;\n const to = namedParsers[this.refName];\n if (ctx.measure) {\n ctx.deps_counter[name] = (ctx.deps_counter[name] || 0) + 1;\n if (ctx.deps[name]) {\n return name;\n }\n ctx.deps[name] = true;\n ctx.deps[name] = to.describe(ctx);\n return name;\n } else {\n if (ctx.deps_counter[name] > 1) {\n if (!ctx.deps[name]) {\n ctx.deps[name] = true;\n ctx.deps[name] = to.describe(ctx);\n }\n return name;\n } else {\n return to.describe(ctx);\n }\n }\n }\n schema(ctx) {\n const name = this.refName;\n const to = namedParsers[this.refName];\n if (ctx.seen[name]) {\n return {};\n }\n ctx.seen[name] = true;\n var tmp = to.schema(ctx);\n delete ctx.seen[name];\n return tmp;\n }\n validate(ctx, input) {\n const to = namedParsers[this.refName];\n return to.validate(ctx, input);\n }\n parseAfterValidation(ctx, input) {\n const to = namedParsers[this.refName];\n return to.parseAfterValidation(ctx, input);\n }\n reportDecodeError(ctx, input) {\n const to = namedParsers[this.refName];\n return to.reportDecodeError(ctx, input);\n }\n}\nconst buildParsers = (args) => {\n const stringFormats = args?.stringFormats ?? {};\n for (const k of RequiredStringFormats) {\n if (stringFormats[k] == null) {\n throw new Error(`Missing custom format ${k}`);\n }\n }\n Object.keys(stringFormats).forEach((k) => {\n const v = stringFormats[k];\n registerStringFormatter(k, v);\n });\n const numberFormats = args?.numberFormats ?? {};\n for (const k of RequiredNumberFormats) {\n if (numberFormats[k] == null) {\n throw new Error(`Missing custom format ${k}`);\n }\n }\n Object.keys(numberFormats).forEach((k) => {\n const v = numberFormats[k];\n registerNumberFormatter(k, v);\n });\n let acc = {};\n for (const k of Object.keys(buildValidatorsInput)) {\n const impl = buildValidatorsInput[k];\n const validate = (input, options) => {\n const disallowExtraProperties = options?.disallowExtraProperties ?? false;\n const ctx = { disallowExtraProperties };\n const ok = impl.validate(ctx, input);\n if (typeof ok !== "boolean") {\n throw new Error("INTERNAL ERROR: Expected boolean");\n }\n return ok;\n };\n const schema = () => {\n const ctx = {\n path: [],\n seen: {}\n };\n return impl.schema(ctx);\n };\n const describe = () => {\n const ctx = {\n deps: {},\n deps_counter: {},\n measure: true\n };\n let out = impl.describe(ctx);\n ctx["deps"] = {};\n ctx["measure"] = false;\n out = impl.describe(ctx);\n let sortedDepsKeys = Object.keys(ctx.deps).sort();\n const depsPart = sortedDepsKeys.map((key) => {\n return `type ${key} = ${ctx.deps[key]};`;\n }).join("\\n\\n");\n const outPart = `type Codec${k} = ${out};`;\n return [depsPart, outPart].filter((it2) => it2 != null && it2.length > 0).join("\\n\\n");\n };\n const safeParse = (input, options) => {\n const disallowExtraProperties = options?.disallowExtraProperties ?? false;\n const ok = validate(input, options);\n if (ok) {\n let ctx2 = { disallowExtraProperties };\n const parsed = impl.parseAfterValidation(ctx2, input);\n return { success: true, data: parsed };\n }\n let ctx = { path: [], disallowExtraProperties };\n return {\n success: false,\n errors: impl.reportDecodeError(ctx, input).slice(0, 10)\n };\n };\n const parse = (input, options) => {\n const safe = safeParse(input, options);\n if (safe.success) {\n return safe.data;\n }\n const explained = printErrors(safe.errors, []);\n throw new Error(`Failed to parse ${k} - ${explained}`);\n };\n const zod = () => {\n return z.custom(\n (data) => validate(data),\n (val) => {\n const errors = impl.reportDecodeError({ path: [], disallowExtraProperties: false }, val);\n return printErrors(errors, []);\n }\n );\n };\n const it = {\n validate,\n schema,\n describe,\n safeParse,\n parse,\n zod,\n name: k\n };\n acc[k] = it;\n }\n return acc;\n};\n', "decoders.js": '\n\n\n\n\n\nconst JSON_PROTO = Object.getPrototypeOf({});\n\nfunction deepmergeConstructor(options) {\n function isNotPrototypeKey(value) {\n return value !== "constructor" && value !== "prototype" && value !== "__proto__";\n }\n\n function cloneArray(value) {\n let i = 0;\n const il = value.length;\n const result = new Array(il);\n for (i; i < il; ++i) {\n result[i] = clone(value[i]);\n }\n return result;\n }\n\n function cloneObject(target) {\n const result = {};\n\n if (cloneProtoObject && Object.getPrototypeOf(target) !== JSON_PROTO) {\n return cloneProtoObject(target);\n }\n\n const targetKeys = getKeys(target);\n let i, il, key;\n for (i = 0, il = targetKeys.length; i < il; ++i) {\n isNotPrototypeKey((key = targetKeys[i])) && (result[key] = clone(target[key]));\n }\n return result;\n }\n\n function concatArrays(target, source) {\n const tl = target.length;\n const sl = source.length;\n let i = 0;\n const result = new Array(tl + sl);\n for (i; i < tl; ++i) {\n result[i] = clone(target[i]);\n }\n for (i = 0; i < sl; ++i) {\n result[i + tl] = clone(source[i]);\n }\n return result;\n }\n\n const propertyIsEnumerable = Object.prototype.propertyIsEnumerable;\n function getSymbolsAndKeys(value) {\n const result = Object.keys(value);\n const keys = Object.getOwnPropertySymbols(value);\n for (let i = 0, il = keys.length; i < il; ++i) {\n \n propertyIsEnumerable.call(value, keys[i]) && result.push(keys[i]);\n }\n return result;\n }\n\n const getKeys = options?.symbols ? getSymbolsAndKeys : Object.keys;\n\n const cloneProtoObject =\n typeof options?.cloneProtoObject === "function" ? options.cloneProtoObject : undefined;\n\n function isMergeableObject(value) {\n return (\n typeof value === "object" && value !== null && !(value instanceof RegExp) && !(value instanceof Date)\n );\n }\n\n function isPrimitive(value) {\n return typeof value !== "object" || value === null;\n }\n\n const isPrimitiveOrBuiltIn =\n \n typeof Buffer !== "undefined"\n ? (value) =>\n typeof value !== "object" ||\n value === null ||\n value instanceof RegExp ||\n value instanceof Date ||\n \n value instanceof Buffer\n : (value) =>\n typeof value !== "object" || value === null || value instanceof RegExp || value instanceof Date;\n\n const mergeArray =\n options && typeof options.mergeArray === "function"\n ? options.mergeArray({ clone, deepmerge: _deepmerge, getKeys, isMergeableObject })\n : concatArrays;\n\n function clone(entry) {\n return isMergeableObject(entry) ? (Array.isArray(entry) ? cloneArray(entry) : cloneObject(entry)) : entry;\n }\n\n function mergeObject(target, source) {\n const result = {};\n const targetKeys = getKeys(target);\n const sourceKeys = getKeys(source);\n let i, il, key;\n for (i = 0, il = targetKeys.length; i < il; ++i) {\n isNotPrototypeKey((key = targetKeys[i])) &&\n sourceKeys.indexOf(key) === -1 &&\n (result[key] = clone(target[key]));\n }\n\n for (i = 0, il = sourceKeys.length; i < il; ++i) {\n if (!isNotPrototypeKey((key = sourceKeys[i]))) {\n continue;\n }\n\n if (key in target) {\n if (targetKeys.indexOf(key) !== -1) {\n if (\n cloneProtoObject &&\n isMergeableObject(source[key]) &&\n Object.getPrototypeOf(source[key]) !== JSON_PROTO\n ) {\n result[key] = cloneProtoObject(source[key]);\n } else {\n result[key] = _deepmerge(target[key], source[key]);\n }\n }\n } else {\n result[key] = clone(source[key]);\n }\n }\n return result;\n }\n\n function _deepmerge(target, source) {\n const sourceIsArray = Array.isArray(source);\n const targetIsArray = Array.isArray(target);\n\n if (isPrimitive(source)) {\n return source;\n } else if (isPrimitiveOrBuiltIn(target)) {\n return clone(source);\n } else if (sourceIsArray && targetIsArray) {\n return mergeArray(target, source);\n } else if (sourceIsArray !== targetIsArray) {\n return clone(source);\n } else {\n return mergeObject(target, source);\n }\n }\n\n function _deepmergeAll() {\n switch (arguments.length) {\n case 0:\n return {};\n case 1:\n return clone(arguments[0]);\n case 2:\n return _deepmerge(arguments[0], arguments[1]);\n }\n let result;\n for (let i = 0, il = arguments.length; i < il; ++i) {\n result = _deepmerge(result, arguments[i]);\n }\n return result;\n }\n\n return options?.all ? _deepmergeAll : _deepmerge;\n}\n\nfunction deepmergeArray(options) {\n const deepmerge = options.deepmerge;\n const clone = options.clone;\n return function (target, source) {\n let i = 0;\n const tl = target.length;\n const sl = source.length;\n const il = Math.max(target.length, source.length);\n const result = new Array(il);\n for (i = 0; i < il; ++i) {\n if (i < sl) {\n result[i] = deepmerge(target[i], source[i]);\n } else {\n result[i] = clone(target[i]);\n }\n }\n return result;\n };\n}\n\nconst deepmerge = deepmergeConstructor({ all: true, mergeArray: deepmergeArray });\n\nconst stringFormatters = {};\n\nfunction registerStringFormatter(name, validator) {\n stringFormatters[name] = validator;\n}\n\nconst numberFormatters = {};\n\nfunction registerNumberFormatter(name, validator) {\n numberFormatters[name] = validator;\n}\n\nfunction pushPath(ctx, key) {\n ctx.path.push(key);\n}\nfunction popPath(ctx) {\n ctx.path.pop();\n}\nfunction printPath(ctx) {\n return ctx.path.join(".");\n}\nfunction buildSchemaErrorMessage(ctx, message) {\n return `Failed to print schema. At ${printPath(ctx)}: ${message}`;\n}\nfunction buildError(ctx, message, received) {\n return [\n {\n message,\n path: [...ctx.path],\n received,\n },\n ];\n}\n\nfunction buildUnionError(ctx, errors, received) {\n return [\n {\n path: [...ctx.path],\n received,\n errors,\n isUnionError: true,\n message: "expected one of",\n },\n ];\n}\n\nfunction parseIdentity(ctx, input) {\n return input;\n}\n\nfunction validateString(ctx, input) {\n return typeof input === "string";\n}\n\nfunction reportString(ctx, input) {\n return buildError(ctx, "expected string", input);\n}\n\nfunction schemaString(ctx) {\n return {\n type: "string",\n };\n}\n\nfunction describeString(ctx) {\n return "string";\n}\n\nfunction validateNumber(ctx, input) {\n return typeof input === "number";\n}\n\nfunction reportNumber(ctx, input) {\n return buildError(ctx, "expected number", input);\n}\n\nfunction schemaNumber(ctx) {\n return {\n type: "number",\n };\n}\n\nfunction describeNumber(ctx) {\n return "number";\n}\n\nfunction validateBoolean(ctx, input) {\n return typeof input === "boolean";\n}\n\nfunction reportBoolean(ctx, input) {\n return buildError(ctx, "expected boolean", input);\n}\n\nfunction schemaBoolean(ctx) {\n return {\n type: "boolean",\n };\n}\n\nfunction describeBoolean(ctx) {\n return "boolean";\n}\n\nfunction validateAny(ctx, input) {\n return true;\n}\n\nfunction reportAny(ctx, input) {\n return buildError(ctx, "expected any", input);\n}\n\nfunction schemaAny(ctx) {\n return {};\n}\n\nfunction describeAny(ctx) {\n return "any";\n}\n\nfunction validateNull(ctx, input) {\n if (input == null) {\n return true;\n }\n return false;\n}\n\nfunction reportNull(ctx, input) {\n return buildError(ctx, "expected nullish value", input);\n}\n\nfunction schemaNull(ctx) {\n return {\n type: "null",\n };\n}\n\nfunction describeNull(ctx) {\n return "null";\n}\n\nfunction validateNever(ctx, input) {\n return false;\n}\n\nfunction reportNever(ctx, input) {\n return buildError(ctx, "expected never", input);\n}\n\nfunction schemaNever(ctx) {\n return {\n anyOf: [],\n };\n}\n\nfunction describeNever(ctx) {\n return "never";\n}\n\nfunction validateFunction(ctx, input) {\n return typeof input === "function";\n}\n\nfunction reportFunction(ctx, input) {\n return buildError(ctx, "expected function", input);\n}\n\nfunction schemaFunction(ctx) {\n throw new Error(buildSchemaErrorMessage(ctx, "Cannot generate JSON Schema for function"));\n}\n\nfunction describeFunction(ctx) {\n return "function";\n}\n\nclass ConstDecoder {\n constructor(value) {\n this.value = value;\n }\n\n validateConstDecoder(ctx, input) {\n return input === this.value;\n }\n\n parseConstDecoder(ctx, input) {\n return input;\n }\n\n reportConstDecoder(ctx, input) {\n return buildError(ctx, `expected ${JSON.stringify(this.value)}`, input);\n }\n\n schemaConstDecoder(ctx) {\n return {\n const: this.value,\n };\n }\n describeConstDecoder(ctx) {\n return JSON.stringify(this.value);\n }\n}\n\nclass RegexDecoder {\n constructor(regex, description) {\n this.regex = regex;\n this.description = description;\n }\n\n validateRegexDecoder(ctx, input) {\n if (typeof input === "string") {\n return this.regex.test(input);\n }\n return false;\n }\n\n parseRegexDecoder(ctx, input) {\n return input;\n }\n\n reportRegexDecoder(ctx, input) {\n return buildError(ctx, `expected string matching ${this.description}`, input);\n }\n\n schemaRegexDecoder(ctx) {\n return {\n type: "string",\n pattern: this.description,\n };\n }\n describeRegexDecoder(ctx) {\n return "`" + this.description + "`";\n }\n}\n\nclass CodecDecoder {\n constructor(codec) {\n this.codec = codec;\n }\n validateCodecDecoder(ctx, input) {\n switch (this.codec) {\n case "Codec::ISO8061": {\n return input instanceof Date;\n }\n case "Codec::BigInt": {\n return typeof input === "bigint";\n }\n }\n return false;\n }\n parseCodecDecoder(ctx, input) {\n return input;\n }\n\n reportCodecDecoder(ctx, input) {\n switch (this.codec) {\n case "Codec::ISO8061": {\n return buildError(ctx, `expected Date`, input);\n }\n case "Codec::BigInt": {\n return buildError(ctx, `expected BigInt`, input);\n }\n }\n\n return buildError(ctx, `expected ${this.codec}`, input);\n }\n\n schemaCodecDecoder(ctx) {\n switch (this.codec) {\n case "Codec::ISO8061": {\n throw new Error(buildSchemaErrorMessage(ctx, "Cannot generate JSON Schema for Date"));\n }\n case "Codec::BigInt": {\n throw new Error(buildSchemaErrorMessage(ctx, "Cannot generate JSON Schema for BigInt"));\n }\n }\n\n throw new Error("INTERNAL ERROR: Unrecognized codec: " + this.codec);\n }\n describeCodecDecoder(ctx) {\n switch (this.codec) {\n case "Codec::ISO8061": {\n return "Date";\n }\n case "Codec::BigInt": {\n return "BigInt";\n }\n }\n throw new Error("INTERNAL ERROR: Unrecognized codec: " + this.codec);\n }\n}\n\nclass StringWithFormatsDecoder {\n constructor(...formats) {\n this.formats = formats;\n }\n\n validateStringWithFormatsDecoder(ctx, input) {\n if (typeof input !== "string") {\n return false;\n }\n\n for (const f of this.formats) {\n const validator = stringFormatters[f];\n\n if (validator == null) {\n return false;\n }\n\n if (!validator(input)) {\n return false;\n }\n }\n\n return true;\n }\n parseStringWithFormatsDecoder(ctx, input) {\n return input;\n }\n reportStringWithFormatsDecoder(ctx, input) {\n return buildError(ctx, `expected string with format "${this.formats.join(" and ")}"`, input);\n }\n schemaStringWithFormatsDecoder(ctx) {\n return {\n type: "string",\n format: this.formats.join(" and "),\n };\n }\n describeStringWithFormatsDecoder(ctx) {\n if (this.formats.length === 0) {\n throw new Error("INTERNAL ERROR: No formats provided");\n }\n const [first, ...rest] = this.formats;\n let acc = `StringFormat<"${first}">`;\n for (const r of rest) {\n acc = `StringFormatExtends<${acc}, "${r}">`;\n }\n return acc;\n }\n}\nclass NumberWithFormatsDecoder {\n constructor(...formats) {\n this.formats = formats;\n }\n\n validateNumberWithFormatsDecoder(ctx, input) {\n if (typeof input !== "number") {\n return false;\n }\n\n for (const f of this.formats) {\n const validator = numberFormatters[f];\n\n if (validator == null) {\n return false;\n }\n\n if (!validator(input)) {\n return false;\n }\n }\n\n return true;\n }\n parseNumberWithFormatsDecoder(ctx, input) {\n return input;\n }\n reportNumberWithFormatsDecoder(ctx, input) {\n return buildError(ctx, `expected number with format "${this.formats.join(" and ")}"`, input);\n }\n schemaNumberWithFormatsDecoder(ctx) {\n return {\n type: "number",\n format: this.formats.join(" and "),\n };\n }\n describeNumberWithFormatsDecoder(ctx) {\n if (this.formats.length === 0) {\n throw new Error("INTERNAL ERROR: No formats provided");\n }\n const [first, ...rest] = this.formats;\n let acc = `NumberFormat<"${first}">`;\n for (const r of rest) {\n acc = `NumberFormatExtends<${acc}, "${r}">`;\n }\n return acc;\n }\n}\n\nconst limitedCommaJoinJson = (arr) => {\n const limit = 3;\n if (arr.length < limit) {\n return arr.map((it) => JSON.stringify(it)).join(", ");\n }\n return (\n arr\n .slice(0, limit)\n .map((it) => JSON.stringify(it))\n .join(", ") + `...`\n );\n};\nclass AnyOfConstsDecoder {\n constructor(consts) {\n this.consts = consts;\n }\n validateAnyOfConstsDecoder(ctx, input) {\n if (input == null) {\n if (this.consts.includes(null) || this.consts.includes(undefined)) {\n return true;\n }\n }\n return this.consts.includes(input);\n }\n parseAnyOfConstsDecoder(ctx, input) {\n return input;\n }\n reportAnyOfConstsDecoder(ctx, input) {\n return buildError(ctx, `expected one of ${limitedCommaJoinJson(this.consts)}`, input);\n }\n schemaAnyOfConstsDecoder(ctx) {\n return {\n enum: this.consts,\n };\n }\n describeAnyOfConstsDecoder(ctx) {\n const parts = this.consts.map((it) => JSON.stringify(it));\n return parts.join(" | ");\n }\n}\n\nclass ObjectValidator {\n constructor(data, rest) {\n this.data = data;\n this.rest = rest;\n }\n\n validateObjectValidator(ctx, input) {\n if (typeof input === "object" && !Array.isArray(input) && input !== null) {\n const configKeys = Object.keys(this.data);\n for (const k of configKeys) {\n const validator = this.data[k];\n if (!validator(ctx, input[k])) {\n return false;\n }\n }\n\n if (this.rest != null) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n for (const k of extraKeys) {\n const v = input[k];\n if (!this.rest(ctx, v)) {\n return false;\n }\n }\n } else {\n if (ctx.disallowExtraProperties) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n\n if (extraKeys.length > 0) {\n return false;\n }\n }\n }\n\n return true;\n }\n return false;\n }\n}\n\nclass ObjectReporter {\n constructor(dataValidator, restValidator, dataReporter, restReporter) {\n this.dataValidator = dataValidator;\n this.restValidator = restValidator;\n this.dataReporter = dataReporter;\n this.restReporter = restReporter;\n }\n\n reportObjectReporter(ctx, input) {\n if (typeof input !== "object" || Array.isArray(input) || input === null) {\n return buildError(ctx, "expected object", input);\n }\n\n let acc = [];\n\n const configKeys = Object.keys(this.dataReporter);\n\n for (const k of configKeys) {\n const ok = this.dataValidator[k](ctx, input[k]);\n if (!ok) {\n pushPath(ctx, k);\n const arr2 = this.dataReporter[k](ctx, input[k]);\n acc.push(...arr2);\n popPath(ctx);\n }\n }\n\n if (this.restReporter != null) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n for (const k of extraKeys) {\n const ok = this.restValidator(ctx, input[k]);\n if (!ok) {\n pushPath(ctx, k);\n const arr2 = this.restReporter(ctx, input[k]);\n acc.push(...arr2);\n popPath(ctx);\n }\n }\n } else {\n if (ctx.disallowExtraProperties) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n if (extraKeys.length > 0) {\n \n return extraKeys.flatMap((k) => {\n pushPath(ctx, k);\n const err = buildError(ctx, `extra property`, input[k]);\n popPath(ctx);\n return err;\n });\n }\n }\n }\n\n return acc;\n }\n}\nclass ObjectParser {\n constructor(data, rest) {\n this.data = data;\n this.rest = rest;\n }\n\n parseObjectParser(ctx, input) {\n let acc = {};\n\n const inputKeys = Object.keys(input);\n\n for (const k of inputKeys) {\n const v = input[k];\n if (k in this.data) {\n const itemParsed = this.data[k](ctx, v);\n acc[k] = itemParsed;\n } else if (this.rest != null) {\n const restParsed = this.rest(ctx, v);\n acc[k] = restParsed;\n }\n }\n\n return acc;\n }\n}\n\nclass ObjectSchema {\n constructor(data, rest) {\n this.data = data;\n this.rest = rest;\n }\n\n schemaObjectSchema(ctx) {\n const properties = {};\n for (const k in this.data) {\n pushPath(ctx, k);\n properties[k] = this.data[k](ctx);\n popPath(ctx);\n }\n\n const required = Object.keys(this.data);\n\n const additionalProperties = this.rest != null ? this.rest(ctx) : false;\n\n return {\n type: "object",\n properties,\n required,\n additionalProperties,\n };\n }\n}\n\nclass ObjectDescribe {\n constructor(dataDescriber, restDescriber) {\n this.dataDescriber = dataDescriber;\n this.restDescriber = restDescriber;\n }\n describeObjectDescribe(ctx) {\n const sortedKeys = Object.keys(this.dataDescriber).sort();\n const props = sortedKeys\n .map((k) => {\n const describer = this.dataDescriber[k];\n return `${k}: ${describer(ctx)}`;\n })\n .join(", ");\n\n const rest = this.restDescriber != null ? `[K in string]: ${this.restDescriber(ctx)}` : null;\n\n const content = [props, rest].filter((it) => it != null && it.length > 0).join(", ");\n return `{ ${content} }`;\n }\n}\n\nclass MappedRecordValidator {\n constructor(keyValidator, valueValidator) {\n this.keyValidator = keyValidator;\n this.valueValidator = valueValidator;\n }\n\n validateMappedRecordValidator(ctx, input) {\n if (typeof input !== "object" || input == null) {\n return false;\n }\n\n for (const k in input) {\n const v = input[k];\n if (!this.keyValidator(ctx, k) || !this.valueValidator(ctx, v)) {\n return false;\n }\n }\n\n return true;\n }\n}\n\nclass MappedRecordParser {\n constructor(keyParser, valueParser) {\n this.keyParser = keyParser;\n this.valueParser = valueParser;\n }\n\n parseMappedRecordParser(ctx, input) {\n const result = {};\n for (const k in input) {\n const parsedKey = this.keyParser(ctx, k);\n const parsedValue = this.valueParser(ctx, input[k]);\n result[parsedKey] = parsedValue;\n }\n return result;\n }\n}\n\nclass MappedRecordSchema {\n constructor(keySchema, valueSchema) {\n this.keySchema = keySchema;\n this.valueSchema = valueSchema;\n }\n\n schemaMappedRecordSchema(ctx) {\n return {\n type: "object",\n additionalProperties: this.valueSchema(ctx),\n propertyNames: this.keySchema(ctx),\n };\n }\n}\n\nclass MappedRecordDescribe {\n constructor(keyDescriber, valueDescriber) {\n this.keyDescriber = keyDescriber;\n this.valueDescriber = valueDescriber;\n }\n describeMappedRecordDescribe(ctx) {\n const k = this.keyDescriber(ctx);\n const v = this.valueDescriber(ctx);\n return `Record<${k}, ${v}>`;\n }\n}\n\nclass MappedRecordReporter {\n constructor(keyValidator, valueValidator, keyReporter, valueReporter) {\n this.keyValidator = keyValidator;\n this.valueValidator = valueValidator;\n this.keyReporter = keyReporter;\n this.valueReporter = valueReporter;\n }\n\n reportMappedRecordReporter(ctx, input) {\n if (typeof input !== "object" || input == null) {\n return buildError(ctx, "expected object", input);\n }\n\n let acc = [];\n for (const k in input) {\n const v = input[k];\n const okKey = this.keyValidator(ctx, k);\n if (!okKey) {\n pushPath(ctx, k);\n const errs = this.keyReporter(ctx, k);\n acc.push(...errs);\n popPath(ctx);\n }\n const okValue = this.valueValidator(ctx, v);\n if (!okValue) {\n pushPath(ctx, k);\n const errs = this.valueReporter(ctx, v);\n acc.push(...errs);\n popPath(ctx);\n }\n }\n return acc;\n }\n}\n\nclass AnyOfDiscriminatedValidator {\n constructor(discriminator, mapping) {\n this.discriminator = discriminator;\n this.mapping = mapping;\n }\n\n validateAnyOfDiscriminatedValidator(ctx, input) {\n if (typeof input !== "object" || input == null) {\n return false;\n }\n const d = input[this.discriminator];\n if (d == null) {\n return false;\n }\n const v = this.mapping[d];\n if (v == null) {\n \n return false;\n }\n\n return v(ctx, input);\n }\n}\n\nclass AnyOfDiscriminatedParser {\n constructor(discriminator, mapping) {\n this.discriminator = discriminator;\n this.mapping = mapping;\n }\n\n parseAnyOfDiscriminatedParser(ctx, input) {\n const parser = this.mapping[input[this.discriminator]];\n if (parser == null) {\n throw new Error(\n "INTERNAL ERROR: Missing parser for discriminator " + JSON.stringify(input[this.discriminator]),\n );\n }\n return {\n ...parser(ctx, input),\n [this.discriminator]: input[this.discriminator],\n };\n }\n}\n\nclass AnyOfDiscriminatedReporter {\n constructor(discriminator, mapping) {\n this.discriminator = discriminator;\n this.mapping = mapping;\n }\n\n reportAnyOfDiscriminatedReporter(ctx, input) {\n if (input == null || typeof input !== "object") {\n return buildError(ctx, "expected object", input);\n }\n\n const d = input[this.discriminator];\n if (d == null) {\n return buildError(ctx, "expected discriminator key " + JSON.stringify(this.discriminator), input);\n }\n const v = this.mapping[d];\n if (v == null) {\n pushPath(ctx, this.discriminator);\n const errs = buildError(\n ctx,\n "expected one of " +\n Object.keys(this.mapping)\n .map((it) => JSON.stringify(it))\n .join(", "),\n d,\n );\n popPath(ctx);\n return errs;\n }\n return v(ctx, input);\n }\n}\n\nclass AnyOfDiscriminatedSchema {\n constructor(vs) {\n this.vs = vs;\n }\n\n schemaAnyOfDiscriminatedSchema(ctx) {\n \n return {\n anyOf: this.vs.map((v) => v(ctx)),\n };\n }\n}\n\nclass AnyOfDiscriminatedDescribe {\n constructor(vs) {\n this.vs = vs;\n }\n\n describeAnyOfDiscriminatedDescribe(ctx) {\n \n return `(${this.vs.map((v) => v(ctx)).join(" | ")})`;\n }\n}\n\nclass ArrayParser {\n constructor(innerParser) {\n this.innerParser = innerParser;\n }\n\n parseArrayParser(ctx, input) {\n return input.map((v) => this.innerParser(ctx, v));\n }\n}\n\nclass ArrayValidator {\n constructor(innerValidator) {\n this.innerValidator = innerValidator;\n }\n\n validateArrayValidator(ctx, input) {\n if (Array.isArray(input)) {\n for (let i = 0; i < input.length; i++) {\n const v = input[i];\n const ok = this.innerValidator(ctx, v);\n if (!ok) {\n return false;\n }\n }\n return true;\n }\n return false;\n }\n}\n\nclass ArrayReporter {\n constructor(innerValidator, innerReporter) {\n this.innerValidator = innerValidator;\n this.innerReporter = innerReporter;\n }\n\n reportArrayReporter(ctx, input) {\n if (!Array.isArray(input)) {\n return buildError(ctx, "expected array", input);\n }\n\n let acc = [];\n for (let i = 0; i < input.length; i++) {\n const ok = this.innerValidator(ctx, input[i]);\n if (!ok) {\n pushPath(ctx, `[${i}]`);\n const v = input[i];\n const arr2 = this.innerReporter(ctx, v);\n acc.push(...arr2);\n popPath(ctx);\n }\n }\n\n return acc;\n }\n}\n\nclass ArraySchema {\n constructor(innerSchema) {\n this.innerSchema = innerSchema;\n }\n\n schemaArraySchema(ctx) {\n pushPath(ctx, "[]");\n const items = this.innerSchema(ctx);\n popPath(ctx);\n return {\n type: "array",\n items,\n };\n }\n}\n\nclass ArrayDescribe {\n constructor(innerDescriber) {\n this.innerDescriber = innerDescriber;\n }\n describeArrayDescribe(ctx) {\n return `Array<${this.innerDescriber(ctx)}>`;\n }\n}\n\nclass AnyOfValidator {\n constructor(vs) {\n this.vs = vs;\n }\n validateAnyOfValidator(ctx, input) {\n for (const v of this.vs) {\n if (v(ctx, input)) {\n return true;\n }\n }\n return false;\n }\n}\nclass AnyOfParser {\n constructor(validators, parsers) {\n this.validators = validators;\n this.parsers = parsers;\n }\n parseAnyOfParser(ctx, input) {\n const items = [];\n for (let i = 0; i < this.validators.length; i++) {\n if (this.validators[i](ctx, input)) {\n items.push(this.parsers[i](ctx, input));\n }\n }\n return deepmerge(...items);\n }\n}\nclass AnyOfReporter {\n constructor(validators, reporters) {\n this.validators = validators;\n this.reporters = reporters;\n }\n reportAnyOfReporter(ctx, input) {\n const acc = [];\n const oldPaths = ctx.path;\n ctx.path = [];\n for (const v of this.reporters) {\n const errors = v(ctx, input);\n acc.push(...errors);\n }\n ctx.path = oldPaths;\n return buildUnionError(ctx, acc, input);\n }\n}\n\nclass AnyOfSchema {\n constructor(schemas) {\n this.schemas = schemas;\n }\n schemaAnyOfSchema(ctx) {\n return {\n anyOf: this.schemas.map((s) => s(ctx)),\n };\n }\n}\n\nclass AnyOfDescribe {\n constructor(describers) {\n this.describers = describers;\n }\n describeAnyOfDescribe(ctx) {\n return `(${this.describers.map((v) => v(ctx)).join(" | ")})`;\n }\n}\n\nclass AllOfValidator {\n constructor(vs) {\n this.vs = vs;\n }\n validateAllOfValidator(ctx, input) {\n for (const v of this.vs) {\n const isObj = typeof input === "object";\n if (!isObj) {\n return false;\n }\n if (!v(ctx, input)) {\n return false;\n }\n }\n return true;\n }\n}\n\nclass AllOfParser {\n constructor(validators, parsers) {\n this.validators = validators;\n this.parsers = parsers;\n }\n parseAllOfParser(ctx, input) {\n let acc = {};\n for (let i = 0; i < this.validators.length; i++) {\n const p = this.parsers[i];\n const parsed = p(ctx, input);\n if (typeof parsed !== "object") {\n throw new Error("INTERNAL ERROR: AllOfParser: Expected object");\n }\n acc = { ...acc, ...parsed };\n }\n return acc;\n }\n}\n\nclass AllOfReporter {\n constructor(validators, reporters) {\n this.validators = validators;\n this.reporters = reporters;\n }\n reportAllOfReporter(ctx, input) {\n const acc = [];\n for (const v of this.reporters) {\n const errors = v(ctx, input);\n acc.push(...errors);\n }\n return acc;\n }\n}\n\nclass AllOfSchema {\n constructor(schemas) {\n this.schemas = schemas;\n }\n schemaAllOfSchema(ctx) {\n return {\n allOf: this.schemas.map((s) => s(ctx)),\n };\n }\n}\n\nclass AllOfDescribe {\n constructor(describers) {\n this.describers = describers;\n }\n describeAllOfDescribe(ctx) {\n return `(${this.describers.map((v) => v(ctx)).join(" & ")})`;\n }\n}\n\nclass TupleValidator {\n constructor(prefix, rest) {\n this.prefix = prefix;\n this.rest = rest;\n }\n validateTupleValidator(ctx, input) {\n if (Array.isArray(input)) {\n let idx = 0;\n for (const prefixVal of this.prefix) {\n if (!prefixVal(ctx, input[idx])) {\n return false;\n }\n idx++;\n }\n const itemVal = this.rest;\n if (itemVal != null) {\n for (let i = idx; i < input.length; i++) {\n if (!itemVal(ctx, input[i])) {\n return false;\n }\n }\n } else {\n if (input.length > idx) {\n return false;\n }\n }\n return true;\n }\n return false;\n }\n}\n\nclass TupleParser {\n constructor(prefix, rest) {\n this.prefix = prefix;\n this.rest = rest;\n }\n parseTupleParser(ctx, input) {\n let idx = 0;\n let acc = [];\n for (const prefixParser of this.prefix) {\n acc.push(prefixParser(ctx, input[idx]));\n idx++;\n }\n if (this.rest != null) {\n for (let i = idx; i < input.length; i++) {\n acc.push(this.rest(ctx, input[i]));\n }\n }\n return acc;\n }\n}\n\nclass TupleReporter {\n constructor(prefixValidator, restValidator, prefixReporter, restReporter) {\n this.prefixValidator = prefixValidator;\n this.restValidator = restValidator;\n this.prefixReporter = prefixReporter;\n this.restReporter = restReporter;\n }\n reportTupleReporter(ctx, input) {\n if (!Array.isArray(input)) {\n return buildError(ctx, "expected tuple", input);\n }\n\n let idx = 0;\n\n let acc = [];\n\n for (const prefixReporter of this.prefixReporter) {\n const ok = this.prefixValidator[idx](ctx, input[idx]);\n if (!ok) {\n pushPath(ctx, `[${idx}]`);\n const errors = prefixReporter(ctx, input[idx]);\n acc.push(...errors);\n popPath(ctx);\n }\n idx++;\n }\n\n const restReporter = this.restReporter;\n if (restReporter != null) {\n for (let i = idx; i < input.length; i++) {\n const ok = this.restValidator(ctx, input[i]);\n if (!ok) {\n pushPath(ctx, `[${i}]`);\n const errors = restReporter(ctx, input[i]);\n acc.push(...errors);\n popPath(ctx);\n }\n }\n }\n\n return acc;\n }\n}\n\nclass TupleSchema {\n constructor(prefix, rest) {\n this.prefix = prefix;\n this.rest = rest;\n }\n\n schemaTupleSchema(ctx) {\n pushPath(ctx, "[]");\n const prefixItems = this.prefix.map((s) => s(ctx));\n const items = this.rest != null ? this.rest(ctx) : false;\n popPath(ctx);\n return {\n type: "array",\n prefixItems,\n items,\n };\n }\n}\n\nclass TupleDescribe {\n constructor(prefix, rest) {\n this.prefix = prefix;\n this.rest = rest;\n }\n describeTupleDescribe(ctx) {\n const prefix = this.prefix.map((d) => d(ctx)).join(", ");\n const rest = this.rest != null ? `...Array<${this.rest(ctx)}>` : null;\n\n const inner = [prefix, rest].filter((it) => it != null && it.length > 0).join(", ");\n return `[${inner}]`;\n }\n}\n\nfunction wrap_describe(fn, name) {\n return (ctx, input) => {\n if (ctx.measure) {\n ctx.deps_counter[name] = (ctx.deps_counter[name] || 0) + 1;\n if (ctx.deps[name]) {\n return name;\n }\n ctx.deps[name] = true;\n ctx.deps[name] = fn(ctx, input);\n return name;\n } else {\n if (ctx.deps_counter[name] > 1) {\n if (!ctx.deps[name]) {\n ctx.deps[name] = true;\n ctx.deps[name] = fn(ctx, input);\n }\n return name;\n } else {\n return fn(ctx, input);\n }\n }\n };\n}\n', "parser.d.ts": 'import { BuildParserFunction } from "@beff/client";\n\ndeclare const _exports: {\n buildParsers: BuildParserFunction;\n};\n\nexport default _exports;\n' };
|
|
45785
45785
|
|
|
45786
45786
|
// ts-node/bundle-to-disk.ts
|
|
45787
45787
|
var decodersExported = [
|
|
@@ -45859,7 +45859,8 @@ var decodersExported = [
|
|
|
45859
45859
|
"AnyOfDescribe",
|
|
45860
45860
|
"AllOfDescribe",
|
|
45861
45861
|
"AnyOfDiscriminatedDescribe",
|
|
45862
|
-
"MappedRecordDescribe"
|
|
45862
|
+
"MappedRecordDescribe",
|
|
45863
|
+
"wrap_describe"
|
|
45863
45864
|
];
|
|
45864
45865
|
var esmTag = (mod) => {
|
|
45865
45866
|
if (mod === "cjs") {
|
|
@@ -45918,34 +45919,84 @@ var finalizeParserFile = (wasmCode, mod, stringFormats, numberFormats) => {
|
|
|
45918
45919
|
exports2
|
|
45919
45920
|
].join("\n");
|
|
45920
45921
|
};
|
|
45922
|
+
var V2_ESM_IMPORT = `import {
|
|
45923
|
+
printErrors
|
|
45924
|
+
} from "@beff/client";`;
|
|
45925
|
+
var V2_CJS_IMPORT = `const { printErrors } = require("@beff/client");`;
|
|
45926
|
+
var finalizeParserV2File = (wasmCode, mod, stringFormats, numberFormats) => {
|
|
45927
|
+
const exportedItems = ["buildParsers"].join(", ");
|
|
45928
|
+
const exports2 = [exportCode(mod), `{ ${exportedItems} };`].join(" ");
|
|
45929
|
+
const stringFormatsCode = `const RequiredStringFormats = ${JSON.stringify(stringFormats)};`;
|
|
45930
|
+
const numberFormatsCode = `const RequiredNumberFormats = ${JSON.stringify(numberFormats)};`;
|
|
45931
|
+
let genV2 = bundle_default["codegen-v2.js"].replace(V2_ESM_IMPORT, "");
|
|
45932
|
+
let zod_import = `import { z } from "zod";`;
|
|
45933
|
+
if (mod == "cjs") {
|
|
45934
|
+
zod_import = `const { z } = require("zod");`;
|
|
45935
|
+
}
|
|
45936
|
+
return [
|
|
45937
|
+
"//@ts-nocheck",
|
|
45938
|
+
esmTag(mod),
|
|
45939
|
+
zod_import,
|
|
45940
|
+
mod === "esm" ? V2_ESM_IMPORT : V2_CJS_IMPORT,
|
|
45941
|
+
genV2,
|
|
45942
|
+
stringFormatsCode,
|
|
45943
|
+
numberFormatsCode,
|
|
45944
|
+
wasmCode.js_built_parsers,
|
|
45945
|
+
exports2
|
|
45946
|
+
].join("\n");
|
|
45947
|
+
};
|
|
45921
45948
|
var execProject = (bundler, projectPath, projectJson, verbose) => {
|
|
45922
45949
|
const mod = projectJson.module ?? "esm";
|
|
45923
45950
|
const parserEntryPoint = projectJson.parser ? path.join(path.dirname(projectPath), projectJson.parser) : void 0;
|
|
45924
45951
|
if (verbose) {
|
|
45925
45952
|
console.log(`JS: Parser entry point ${parserEntryPoint}`);
|
|
45926
45953
|
}
|
|
45927
|
-
const outResult = bundler.bundle(parserEntryPoint, projectJson.settings);
|
|
45928
|
-
if (outResult == null) {
|
|
45929
|
-
return "failed";
|
|
45930
|
-
}
|
|
45931
45954
|
const outputDir = path.join(path.dirname(projectPath), projectJson.outputDir);
|
|
45932
45955
|
if (!fs.existsSync(outputDir)) {
|
|
45933
45956
|
fs.mkdirSync(outputDir);
|
|
45934
45957
|
}
|
|
45935
|
-
|
|
45936
|
-
|
|
45937
|
-
|
|
45938
|
-
|
|
45939
|
-
|
|
45940
|
-
|
|
45941
|
-
|
|
45942
|
-
|
|
45943
|
-
|
|
45944
|
-
|
|
45945
|
-
|
|
45946
|
-
|
|
45958
|
+
switch (projectJson.codegen) {
|
|
45959
|
+
case 1: {
|
|
45960
|
+
const outResult = bundler.bundle(parserEntryPoint, projectJson.settings);
|
|
45961
|
+
if (outResult == null) {
|
|
45962
|
+
return "failed";
|
|
45963
|
+
}
|
|
45964
|
+
fs.writeFileSync(path.join(outputDir, "validators.js"), finalizeValidatorsCode(outResult, mod));
|
|
45965
|
+
if (projectJson.parser) {
|
|
45966
|
+
fs.writeFileSync(
|
|
45967
|
+
path.join(outputDir, "parser.js"),
|
|
45968
|
+
finalizeParserFile(
|
|
45969
|
+
outResult,
|
|
45970
|
+
mod,
|
|
45971
|
+
projectJson.settings.stringFormats.map((it) => it.name) ?? [],
|
|
45972
|
+
projectJson.settings.numberFormats.map((it) => it.name) ?? []
|
|
45973
|
+
)
|
|
45974
|
+
);
|
|
45975
|
+
fs.writeFileSync(path.join(outputDir, "parser.d.ts"), bundle_default["parser.d.ts"]);
|
|
45976
|
+
}
|
|
45977
|
+
return "ok";
|
|
45978
|
+
}
|
|
45979
|
+
case 2: {
|
|
45980
|
+
const outResult = bundler.bundle_v2(parserEntryPoint, projectJson.settings);
|
|
45981
|
+
if (outResult == null) {
|
|
45982
|
+
return "failed";
|
|
45983
|
+
}
|
|
45984
|
+
fs.writeFileSync(
|
|
45985
|
+
path.join(outputDir, "parser.js"),
|
|
45986
|
+
finalizeParserV2File(
|
|
45987
|
+
outResult,
|
|
45988
|
+
mod,
|
|
45989
|
+
projectJson.settings.stringFormats.map((it) => it.name) ?? [],
|
|
45990
|
+
projectJson.settings.numberFormats.map((it) => it.name) ?? []
|
|
45991
|
+
)
|
|
45992
|
+
);
|
|
45993
|
+
fs.writeFileSync(path.join(outputDir, "parser.d.ts"), bundle_default["parser.d.ts"]);
|
|
45994
|
+
return "ok";
|
|
45995
|
+
}
|
|
45996
|
+
default: {
|
|
45997
|
+
throw `Unsupported codegen version: ${projectJson.codegen}`;
|
|
45998
|
+
}
|
|
45947
45999
|
}
|
|
45948
|
-
return "ok";
|
|
45949
46000
|
};
|
|
45950
46001
|
|
|
45951
46002
|
// ts-node/bundler.ts
|
|
@@ -46100,6 +46151,9 @@ var Bundler = class {
|
|
|
46100
46151
|
bundle(parser_entrypoint, settings) {
|
|
46101
46152
|
return wasm.bundle_to_string(parser_entrypoint ?? "", serializeSettings(settings));
|
|
46102
46153
|
}
|
|
46154
|
+
bundle_v2(parser_entrypoint, settings) {
|
|
46155
|
+
return wasm.bundle_to_string_v2(parser_entrypoint ?? "", serializeSettings(settings));
|
|
46156
|
+
}
|
|
46103
46157
|
diagnostics(parser_entrypoint, settings) {
|
|
46104
46158
|
return wasm.bundle_to_diagnostics(parser_entrypoint ?? "", serializeSettings(settings));
|
|
46105
46159
|
}
|
|
@@ -46143,7 +46197,8 @@ var readProjectJson = (projectPath) => {
|
|
|
46143
46197
|
parser: projectJson.parser == null ? projectJson.parser : String(projectJson.parser),
|
|
46144
46198
|
outputDir: String(projectJson.outputDir),
|
|
46145
46199
|
module: projectJson.module,
|
|
46146
|
-
settings: parseUserSettings(projectJson)
|
|
46200
|
+
settings: parseUserSettings(projectJson),
|
|
46201
|
+
codegen: projectJson.codegen == null ? 2 : projectJson.codegen === 2 ? 2 : 1
|
|
46147
46202
|
};
|
|
46148
46203
|
};
|
|
46149
46204
|
var getProjectPath = (projectPath) => {
|
package/package.json
CHANGED
package/pkg/beff_wasm.d.ts
CHANGED
|
@@ -11,13 +11,19 @@ export function bundle_to_string(parser_entry_point: string, settings: any): any
|
|
|
11
11
|
* @param {any} settings
|
|
12
12
|
* @returns {any}
|
|
13
13
|
*/
|
|
14
|
-
export function
|
|
14
|
+
export function bundle_to_string_v2(parser_entry_point: string, settings: any): any;
|
|
15
15
|
/**
|
|
16
16
|
* @param {string} file_name
|
|
17
17
|
* @param {string} content
|
|
18
18
|
*/
|
|
19
19
|
export function update_file_content(file_name: string, content: string): void;
|
|
20
20
|
/**
|
|
21
|
+
* @param {string} parser_entry_point
|
|
22
|
+
* @param {any} settings
|
|
23
|
+
* @returns {any}
|
|
24
|
+
*/
|
|
25
|
+
export function bundle_to_diagnostics(parser_entry_point: string, settings: any): any;
|
|
26
|
+
/**
|
|
21
27
|
* @param {boolean} verbose
|
|
22
28
|
*/
|
|
23
29
|
export function init(verbose: boolean): void;
|
package/pkg/beff_wasm.js
CHANGED
|
@@ -209,10 +209,10 @@ module.exports.bundle_to_string = function(parser_entry_point, settings) {
|
|
|
209
209
|
* @param {any} settings
|
|
210
210
|
* @returns {any}
|
|
211
211
|
*/
|
|
212
|
-
module.exports.
|
|
212
|
+
module.exports.bundle_to_string_v2 = function(parser_entry_point, settings) {
|
|
213
213
|
const ptr0 = passStringToWasm0(parser_entry_point, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
214
214
|
const len0 = WASM_VECTOR_LEN;
|
|
215
|
-
const ret = wasm.
|
|
215
|
+
const ret = wasm.bundle_to_string_v2(ptr0, len0, addHeapObject(settings));
|
|
216
216
|
return takeObject(ret);
|
|
217
217
|
};
|
|
218
218
|
|
|
@@ -228,6 +228,18 @@ module.exports.update_file_content = function(file_name, content) {
|
|
|
228
228
|
wasm.update_file_content(ptr0, len0, ptr1, len1);
|
|
229
229
|
};
|
|
230
230
|
|
|
231
|
+
/**
|
|
232
|
+
* @param {string} parser_entry_point
|
|
233
|
+
* @param {any} settings
|
|
234
|
+
* @returns {any}
|
|
235
|
+
*/
|
|
236
|
+
module.exports.bundle_to_diagnostics = function(parser_entry_point, settings) {
|
|
237
|
+
const ptr0 = passStringToWasm0(parser_entry_point, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
238
|
+
const len0 = WASM_VECTOR_LEN;
|
|
239
|
+
const ret = wasm.bundle_to_diagnostics(ptr0, len0, addHeapObject(settings));
|
|
240
|
+
return takeObject(ret);
|
|
241
|
+
};
|
|
242
|
+
|
|
231
243
|
/**
|
|
232
244
|
* @param {boolean} verbose
|
|
233
245
|
*/
|
package/pkg/beff_wasm_bg.wasm
CHANGED
|
Binary file
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
4
|
export function bundle_to_diagnostics(a: number, b: number, c: number): number;
|
|
5
5
|
export function bundle_to_string(a: number, b: number, c: number): number;
|
|
6
|
+
export function bundle_to_string_v2(a: number, b: number, c: number): number;
|
|
6
7
|
export function init(a: number): void;
|
|
7
8
|
export function update_file_content(a: number, b: number, c: number, d: number): void;
|
|
8
9
|
export function __wbindgen_malloc(a: number, b: number): number;
|