@beff/cli 0.0.101 → 0.0.103
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 +17 -172
- package/package.json +1 -1
- package/pkg/beff_wasm.d.ts +1 -7
- package/pkg/beff_wasm.js +27 -39
- package/pkg/beff_wasm_bg.wasm +0 -0
- package/pkg/beff_wasm_bg.wasm.d.ts +0 -1
package/CHANGELOG.md
CHANGED
package/dist-cli/cli.js
CHANGED
|
@@ -45781,87 +45781,9 @@ 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', "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' };
|
|
45784
|
+
var bundle_default = { "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 TypeofRuntype {\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 AnyRuntype {\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 NullRuntype {\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 NeverRuntype {\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 ConstRuntype {\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 RegexRuntype {\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 DateRuntype {\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 BigIntRuntype {\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 StringWithFormatRuntype {\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 NumberWithFormatRuntype {\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 AnyOfConstsRuntype {\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 TupleRuntype {\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 AllOfRuntype {\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 AnyOfRuntype {\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 ArrayRuntype {\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 AnyOfDiscriminatedRuntype {\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 MappedRecordRuntype {\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 ObjectRuntype {\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 RefRuntype {\n refName;\n constructor(refName) {\n this.refName = refName;\n }\n describe(ctx) {\n const name = this.refName;\n const to = namedRuntypes[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 = namedRuntypes[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 = namedRuntypes[this.refName];\n return to.validate(ctx, input);\n }\n parseAfterValidation(ctx, input) {\n const to = namedRuntypes[this.refName];\n return to.parseAfterValidation(ctx, input);\n }\n reportDecodeError(ctx, input) {\n const to = namedRuntypes[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(buildParsersInput)) {\n const impl = buildParsersInput[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', "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
|
-
var decodersExported = [
|
|
45788
|
-
"registerStringFormatter",
|
|
45789
|
-
"registerNumberFormatter",
|
|
45790
|
-
"ObjectValidator",
|
|
45791
|
-
"ObjectParser",
|
|
45792
|
-
"MappedRecordParser",
|
|
45793
|
-
"MappedRecordValidator",
|
|
45794
|
-
"ArrayParser",
|
|
45795
|
-
"ArrayValidator",
|
|
45796
|
-
"CodecDecoder",
|
|
45797
|
-
"StringWithFormatsDecoder",
|
|
45798
|
-
"NumberWithFormatsDecoder",
|
|
45799
|
-
"AnyOfValidator",
|
|
45800
|
-
"AnyOfParser",
|
|
45801
|
-
"AllOfValidator",
|
|
45802
|
-
"AllOfParser",
|
|
45803
|
-
"TupleParser",
|
|
45804
|
-
"TupleValidator",
|
|
45805
|
-
"RegexDecoder",
|
|
45806
|
-
"ConstDecoder",
|
|
45807
|
-
"AnyOfConstsDecoder",
|
|
45808
|
-
"AnyOfDiscriminatedParser",
|
|
45809
|
-
"AnyOfDiscriminatedValidator",
|
|
45810
|
-
"validateString",
|
|
45811
|
-
"validateNumber",
|
|
45812
|
-
"validateFunction",
|
|
45813
|
-
"validateBoolean",
|
|
45814
|
-
"validateAny",
|
|
45815
|
-
"validateNull",
|
|
45816
|
-
"validateNever",
|
|
45817
|
-
"parseIdentity",
|
|
45818
|
-
//
|
|
45819
|
-
"reportString",
|
|
45820
|
-
"reportNumber",
|
|
45821
|
-
"reportNull",
|
|
45822
|
-
"reportBoolean",
|
|
45823
|
-
"reportAny",
|
|
45824
|
-
"reportNever",
|
|
45825
|
-
"reportFunction",
|
|
45826
|
-
"ArrayReporter",
|
|
45827
|
-
"ObjectReporter",
|
|
45828
|
-
"TupleReporter",
|
|
45829
|
-
"AnyOfReporter",
|
|
45830
|
-
"AllOfReporter",
|
|
45831
|
-
"AnyOfDiscriminatedReporter",
|
|
45832
|
-
"MappedRecordReporter",
|
|
45833
|
-
//
|
|
45834
|
-
"schemaString",
|
|
45835
|
-
"schemaNumber",
|
|
45836
|
-
"schemaBoolean",
|
|
45837
|
-
"schemaNull",
|
|
45838
|
-
"schemaAny",
|
|
45839
|
-
"schemaNever",
|
|
45840
|
-
"schemaFunction",
|
|
45841
|
-
"ArraySchema",
|
|
45842
|
-
"ObjectSchema",
|
|
45843
|
-
"TupleSchema",
|
|
45844
|
-
"AnyOfSchema",
|
|
45845
|
-
"AllOfSchema",
|
|
45846
|
-
"AnyOfDiscriminatedSchema",
|
|
45847
|
-
"MappedRecordSchema",
|
|
45848
|
-
//
|
|
45849
|
-
"describeString",
|
|
45850
|
-
"describeNumber",
|
|
45851
|
-
"describeBoolean",
|
|
45852
|
-
"describeNull",
|
|
45853
|
-
"describeAny",
|
|
45854
|
-
"describeNever",
|
|
45855
|
-
"describeFunction",
|
|
45856
|
-
"ArrayDescribe",
|
|
45857
|
-
"ObjectDescribe",
|
|
45858
|
-
"TupleDescribe",
|
|
45859
|
-
"AnyOfDescribe",
|
|
45860
|
-
"AllOfDescribe",
|
|
45861
|
-
"AnyOfDiscriminatedDescribe",
|
|
45862
|
-
"MappedRecordDescribe",
|
|
45863
|
-
"wrap_describe"
|
|
45864
|
-
];
|
|
45865
45787
|
var esmTag = (mod) => {
|
|
45866
45788
|
if (mod === "cjs") {
|
|
45867
45789
|
return `
|
|
@@ -45873,52 +45795,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
45873
45795
|
return "";
|
|
45874
45796
|
};
|
|
45875
45797
|
var exportCode = (mod) => mod === "esm" ? "export default" : "exports.default =";
|
|
45876
|
-
var finalizeValidatorsCode = (wasmCode, mod) => {
|
|
45877
|
-
const exportedItems = [
|
|
45878
|
-
...decodersExported,
|
|
45879
|
-
"validators",
|
|
45880
|
-
"parsers",
|
|
45881
|
-
"reporters",
|
|
45882
|
-
"schemas",
|
|
45883
|
-
"describers"
|
|
45884
|
-
].join(", ");
|
|
45885
|
-
const exports2 = [exportCode(mod), `{ ${exportedItems} };`].join(" ");
|
|
45886
|
-
return [
|
|
45887
|
-
//
|
|
45888
|
-
"//@ts-nocheck",
|
|
45889
|
-
bundle_default["decoders.js"],
|
|
45890
|
-
esmTag(mod),
|
|
45891
|
-
wasmCode.js_validators,
|
|
45892
|
-
exports2
|
|
45893
|
-
].join("\n");
|
|
45894
|
-
};
|
|
45895
|
-
var importValidators = (mod) => {
|
|
45896
|
-
const i = [...decodersExported, "validators", "parsers", "reporters", "schemas", "describers", "c"].join(
|
|
45897
|
-
", "
|
|
45898
|
-
);
|
|
45899
|
-
const importRest = mod === "esm" ? `import {printErrors} from '@beff/client';
|
|
45900
|
-
import {z} from 'zod';
|
|
45901
|
-
import validatorsMod from "./validators.js"; const { ${i} } = validatorsMod;` : `const {printErrors} = require('beff/client');
|
|
45902
|
-
const {z} = require('zod');
|
|
45903
|
-
const { ${i} } = require('./validators.js').default;`;
|
|
45904
|
-
return [importRest].join("\n");
|
|
45905
|
-
};
|
|
45906
|
-
var finalizeParserFile = (wasmCode, mod, stringFormats, numberFormats) => {
|
|
45907
|
-
const exportedItems = ["buildParsers"].join(", ");
|
|
45908
|
-
const exports2 = [exportCode(mod), `{ ${exportedItems} };`].join(" ");
|
|
45909
|
-
const stringFormatsCode = `const RequiredStringFormats = ${JSON.stringify(stringFormats)};`;
|
|
45910
|
-
const numberFormatsCode = `const RequiredNumberFormats = ${JSON.stringify(numberFormats)};`;
|
|
45911
|
-
return [
|
|
45912
|
-
"//@ts-nocheck",
|
|
45913
|
-
esmTag(mod),
|
|
45914
|
-
importValidators(mod),
|
|
45915
|
-
stringFormatsCode,
|
|
45916
|
-
numberFormatsCode,
|
|
45917
|
-
wasmCode.js_built_parsers,
|
|
45918
|
-
bundle_default["build-parsers.js"],
|
|
45919
|
-
exports2
|
|
45920
|
-
].join("\n");
|
|
45921
|
-
};
|
|
45922
45798
|
var V2_ESM_IMPORT = `import {
|
|
45923
45799
|
printErrors
|
|
45924
45800
|
} from "@beff/client";`;
|
|
@@ -45941,7 +45817,7 @@ var finalizeParserV2File = (wasmCode, mod, stringFormats, numberFormats) => {
|
|
|
45941
45817
|
genV2,
|
|
45942
45818
|
stringFormatsCode,
|
|
45943
45819
|
numberFormatsCode,
|
|
45944
|
-
wasmCode
|
|
45820
|
+
wasmCode,
|
|
45945
45821
|
exports2
|
|
45946
45822
|
].join("\n");
|
|
45947
45823
|
};
|
|
@@ -45955,48 +45831,21 @@ var execProject = (bundler, projectPath, projectJson, verbose) => {
|
|
|
45955
45831
|
if (!fs.existsSync(outputDir)) {
|
|
45956
45832
|
fs.mkdirSync(outputDir);
|
|
45957
45833
|
}
|
|
45958
|
-
|
|
45959
|
-
|
|
45960
|
-
|
|
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
|
-
}
|
|
45834
|
+
const outResult = bundler.bundle_v2(parserEntryPoint, projectJson.settings);
|
|
45835
|
+
if (outResult == null) {
|
|
45836
|
+
return "failed";
|
|
45999
45837
|
}
|
|
45838
|
+
fs.writeFileSync(
|
|
45839
|
+
path.join(outputDir, "parser.js"),
|
|
45840
|
+
finalizeParserV2File(
|
|
45841
|
+
outResult,
|
|
45842
|
+
mod,
|
|
45843
|
+
projectJson.settings.stringFormats.map((it) => it.name) ?? [],
|
|
45844
|
+
projectJson.settings.numberFormats.map((it) => it.name) ?? []
|
|
45845
|
+
)
|
|
45846
|
+
);
|
|
45847
|
+
fs.writeFileSync(path.join(outputDir, "parser.d.ts"), bundle_default["parser.d.ts"]);
|
|
45848
|
+
return "ok";
|
|
46000
45849
|
};
|
|
46001
45850
|
|
|
46002
45851
|
// ts-node/bundler.ts
|
|
@@ -46148,9 +45997,6 @@ var Bundler = class {
|
|
|
46148
45997
|
onFileRead(cb) {
|
|
46149
45998
|
this.cbs.push(cb);
|
|
46150
45999
|
}
|
|
46151
|
-
bundle(parser_entrypoint, settings) {
|
|
46152
|
-
return wasm.bundle_to_string(parser_entrypoint ?? "", serializeSettings(settings));
|
|
46153
|
-
}
|
|
46154
46000
|
bundle_v2(parser_entrypoint, settings) {
|
|
46155
46001
|
return wasm.bundle_to_string_v2(parser_entrypoint ?? "", serializeSettings(settings));
|
|
46156
46002
|
}
|
|
@@ -46197,8 +46043,7 @@ var readProjectJson = (projectPath) => {
|
|
|
46197
46043
|
parser: projectJson.parser == null ? projectJson.parser : String(projectJson.parser),
|
|
46198
46044
|
outputDir: String(projectJson.outputDir),
|
|
46199
46045
|
module: projectJson.module,
|
|
46200
|
-
settings: parseUserSettings(projectJson)
|
|
46201
|
-
codegen: projectJson.codegen == null ? 2 : projectJson.codegen === 2 ? 2 : 1
|
|
46046
|
+
settings: parseUserSettings(projectJson)
|
|
46202
46047
|
};
|
|
46203
46048
|
};
|
|
46204
46049
|
var getProjectPath = (projectPath) => {
|
package/package.json
CHANGED
package/pkg/beff_wasm.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @param {any} settings
|
|
6
6
|
* @returns {any}
|
|
7
7
|
*/
|
|
8
|
-
export function
|
|
8
|
+
export function bundle_to_diagnostics(parser_entry_point: string, settings: any): any;
|
|
9
9
|
/**
|
|
10
10
|
* @param {string} parser_entry_point
|
|
11
11
|
* @param {any} settings
|
|
@@ -18,12 +18,6 @@ export function bundle_to_string_v2(parser_entry_point: string, settings: any):
|
|
|
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
|
-
/**
|
|
27
21
|
* @param {boolean} verbose
|
|
28
22
|
*/
|
|
29
23
|
export function init(verbose: boolean): void;
|
package/pkg/beff_wasm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
let imports = {};
|
|
2
2
|
imports['__wbindgen_placeholder__'] = module.exports;
|
|
3
3
|
let wasm;
|
|
4
|
-
const {
|
|
4
|
+
const { TextDecoder, TextEncoder } = require(`util`);
|
|
5
5
|
|
|
6
6
|
const heap = new Array(128).fill(undefined);
|
|
7
7
|
|
|
@@ -23,7 +23,9 @@ function takeObject(idx) {
|
|
|
23
23
|
return ret;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
let
|
|
26
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
27
|
+
|
|
28
|
+
cachedTextDecoder.decode();
|
|
27
29
|
|
|
28
30
|
let cachedUint8Memory0 = null;
|
|
29
31
|
|
|
@@ -34,6 +36,22 @@ function getUint8Memory0() {
|
|
|
34
36
|
return cachedUint8Memory0;
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
function getStringFromWasm0(ptr, len) {
|
|
40
|
+
ptr = ptr >>> 0;
|
|
41
|
+
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function addHeapObject(obj) {
|
|
45
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
46
|
+
const idx = heap_next;
|
|
47
|
+
heap_next = heap[idx];
|
|
48
|
+
|
|
49
|
+
heap[idx] = obj;
|
|
50
|
+
return idx;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let WASM_VECTOR_LEN = 0;
|
|
54
|
+
|
|
37
55
|
let cachedTextEncoder = new TextEncoder('utf-8');
|
|
38
56
|
|
|
39
57
|
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
@@ -110,24 +128,6 @@ function getFloat64Memory0() {
|
|
|
110
128
|
return cachedFloat64Memory0;
|
|
111
129
|
}
|
|
112
130
|
|
|
113
|
-
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
114
|
-
|
|
115
|
-
cachedTextDecoder.decode();
|
|
116
|
-
|
|
117
|
-
function getStringFromWasm0(ptr, len) {
|
|
118
|
-
ptr = ptr >>> 0;
|
|
119
|
-
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function addHeapObject(obj) {
|
|
123
|
-
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
124
|
-
const idx = heap_next;
|
|
125
|
-
heap_next = heap[idx];
|
|
126
|
-
|
|
127
|
-
heap[idx] = obj;
|
|
128
|
-
return idx;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
131
|
function debugString(val) {
|
|
132
132
|
// primitive types
|
|
133
133
|
const type = typeof val;
|
|
@@ -197,10 +197,10 @@ function debugString(val) {
|
|
|
197
197
|
* @param {any} settings
|
|
198
198
|
* @returns {any}
|
|
199
199
|
*/
|
|
200
|
-
module.exports.
|
|
200
|
+
module.exports.bundle_to_diagnostics = function(parser_entry_point, settings) {
|
|
201
201
|
const ptr0 = passStringToWasm0(parser_entry_point, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
202
202
|
const len0 = WASM_VECTOR_LEN;
|
|
203
|
-
const ret = wasm.
|
|
203
|
+
const ret = wasm.bundle_to_diagnostics(ptr0, len0, addHeapObject(settings));
|
|
204
204
|
return takeObject(ret);
|
|
205
205
|
};
|
|
206
206
|
|
|
@@ -228,18 +228,6 @@ 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
|
-
|
|
243
231
|
/**
|
|
244
232
|
* @param {boolean} verbose
|
|
245
233
|
*/
|
|
@@ -279,6 +267,11 @@ module.exports.__wbg_resolveimport_0872cceae2662468 = function(arg0, arg1, arg2,
|
|
|
279
267
|
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
|
280
268
|
};
|
|
281
269
|
|
|
270
|
+
module.exports.__wbindgen_string_new = function(arg0, arg1) {
|
|
271
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
272
|
+
return addHeapObject(ret);
|
|
273
|
+
};
|
|
274
|
+
|
|
282
275
|
module.exports.__wbindgen_is_undefined = function(arg0) {
|
|
283
276
|
const ret = getObject(arg0) === undefined;
|
|
284
277
|
return ret;
|
|
@@ -346,11 +339,6 @@ module.exports.__wbindgen_number_new = function(arg0) {
|
|
|
346
339
|
return addHeapObject(ret);
|
|
347
340
|
};
|
|
348
341
|
|
|
349
|
-
module.exports.__wbindgen_string_new = function(arg0, arg1) {
|
|
350
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
351
|
-
return addHeapObject(ret);
|
|
352
|
-
};
|
|
353
|
-
|
|
354
342
|
module.exports.__wbindgen_bigint_from_u64 = function(arg0) {
|
|
355
343
|
const ret = BigInt.asUintN(64, arg0);
|
|
356
344
|
return addHeapObject(ret);
|
package/pkg/beff_wasm_bg.wasm
CHANGED
|
Binary file
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
4
|
export function bundle_to_diagnostics(a: number, b: number, c: number): number;
|
|
5
|
-
export function bundle_to_string(a: number, b: number, c: number): number;
|
|
6
5
|
export function bundle_to_string_v2(a: number, b: number, c: number): number;
|
|
7
6
|
export function init(a: number): void;
|
|
8
7
|
export function update_file_content(a: number, b: number, c: number, d: number): void;
|