@beff/cli 0.0.97 → 0.0.98
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 +6 -0
- package/dist-cli/cli.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist-cli/cli.js
CHANGED
|
@@ -45781,7 +45781,7 @@ var fs = __toESM(require("fs"));
|
|
|
45781
45781
|
var path = __toESM(require("path"));
|
|
45782
45782
|
|
|
45783
45783
|
// ts-node/generated/bundle.ts
|
|
45784
|
-
var bundle_default = { "build-parsers.js": '\n\nfunction buildParsers(args) {\n const stringFormats = args?.stringFormats ?? {};\n \n for (const k of RequiredStringFormats) {\n if (stringFormats[k] == null) {\n throw new Error(`Missing custom format ${k}`);\n }\n }\n\n Object.keys(stringFormats).forEach((k) => {\n const v = stringFormats[k];\n \n registerStringFormatter(k, v);\n });\n\n const numberFormats = args?.numberFormats ?? {};\n \n for (const k of RequiredNumberFormats) {\n if (numberFormats[k] == null) {\n throw new Error(`Missing custom format ${k}`);\n }\n }\n\n Object.keys(numberFormats).forEach((k) => {\n const v = numberFormats[k];\n \n registerNumberFormatter(k, v);\n });\n\n let decoders = {};\n \n Object.keys(buildValidatorsInput).forEach((k) => {\n \n let v = buildValidatorsInput[k];\n const validate = (input, options) => {\n const disallowExtraProperties = options?.disallowExtraProperties ?? false;\n const ctx = { disallowExtraProperties };\n const ok = v(ctx, input);\n if (typeof ok !== "boolean") {\n throw new Error("INTERNAL ERROR: Expected boolean");\n }\n return ok;\n };\n\n \n const schemaFn = buildSchemaInput[k];\n const schema = () => {\n const ctx = {\n path: [],\n seen: {},\n };\n return schemaFn(ctx);\n };\n\n \n const describeFn = buildDescribeInput[k];\n const describe = () => {\n const ctx = {\n deps: {},\n };\n const out = describeFn(ctx);\n let sortedDepsKeys = Object.keys(ctx.deps).sort();\n \n \n \n \n const depsPart = sortedDepsKeys\n .map((key) => {\n return `type ${key} = ${ctx.deps[key]};`;\n })\n .join("\\n\\n");\n \n \n \n const outPart = `type Codec${k} = ${out};`;\n return [depsPart, outPart].filter((it) => it != null && it.length > 0).join("\\n\\n");\n };\n\n const safeParse = (input, options) => {\n const disallowExtraProperties = options?.disallowExtraProperties ?? false;\n const ok = validate(input, options);\n if (ok) {\n \n let p = buildParsersInput[k];\n let ctx = { disallowExtraProperties };\n const parsed = p(ctx, input);\n return { success: true, data: parsed };\n }\n \n let e = buildReportersInput[k];\n let ctx = { path: [], disallowExtraProperties };\n return {\n success: false,\n errors: e(ctx, input).slice(0, 10),\n };\n };\n const parse = (input, options) => {\n const safe = safeParse(input, options);\n if (safe.success) {\n return safe.data;\n }\n \n const explained = printErrors(safe.errors, []);\n throw new Error(`Failed to parse ${k} - ${explained}`);\n };\n const zod = () => {\n \n return z.custom(\n (data) => safeParse(data).success,\n (val) => {\n const errors = safeParse(val).errors;\n \n return printErrors(errors, []);\n },\n );\n };\n decoders[k] = {\n parse,\n safeParse,\n zod,\n name: k,\n validate,\n schema,\n describe,\n };\n });\n return decoders;\n}\n', "decoders.js": '\n\n\n\n\n\nconst JSON_PROTO = Object.getPrototypeOf({});\n\nfunction deepmergeConstructor(options) {\n function isNotPrototypeKey(value) {\n return value !== "constructor" && value !== "prototype" && value !== "__proto__";\n }\n\n function cloneArray(value) {\n let i = 0;\n const il = value.length;\n const result = new Array(il);\n for (i; i < il; ++i) {\n result[i] = clone(value[i]);\n }\n return result;\n }\n\n function cloneObject(target) {\n const result = {};\n\n if (cloneProtoObject && Object.getPrototypeOf(target) !== JSON_PROTO) {\n return cloneProtoObject(target);\n }\n\n const targetKeys = getKeys(target);\n let i, il, key;\n for (i = 0, il = targetKeys.length; i < il; ++i) {\n isNotPrototypeKey((key = targetKeys[i])) && (result[key] = clone(target[key]));\n }\n return result;\n }\n\n function concatArrays(target, source) {\n const tl = target.length;\n const sl = source.length;\n let i = 0;\n const result = new Array(tl + sl);\n for (i; i < tl; ++i) {\n result[i] = clone(target[i]);\n }\n for (i = 0; i < sl; ++i) {\n result[i + tl] = clone(source[i]);\n }\n return result;\n }\n\n const propertyIsEnumerable = Object.prototype.propertyIsEnumerable;\n function getSymbolsAndKeys(value) {\n const result = Object.keys(value);\n const keys = Object.getOwnPropertySymbols(value);\n for (let i = 0, il = keys.length; i < il; ++i) {\n \n propertyIsEnumerable.call(value, keys[i]) && result.push(keys[i]);\n }\n return result;\n }\n\n const getKeys = options?.symbols ? getSymbolsAndKeys : Object.keys;\n\n const cloneProtoObject =\n typeof options?.cloneProtoObject === "function" ? options.cloneProtoObject : undefined;\n\n function isMergeableObject(value) {\n return (\n typeof value === "object" && value !== null && !(value instanceof RegExp) && !(value instanceof Date)\n );\n }\n\n function isPrimitive(value) {\n return typeof value !== "object" || value === null;\n }\n\n const isPrimitiveOrBuiltIn =\n \n typeof Buffer !== "undefined"\n ? (value) =>\n typeof value !== "object" ||\n value === null ||\n value instanceof RegExp ||\n value instanceof Date ||\n \n value instanceof Buffer\n : (value) =>\n typeof value !== "object" || value === null || value instanceof RegExp || value instanceof Date;\n\n const mergeArray =\n options && typeof options.mergeArray === "function"\n ? options.mergeArray({ clone, deepmerge: _deepmerge, getKeys, isMergeableObject })\n : concatArrays;\n\n function clone(entry) {\n return isMergeableObject(entry) ? (Array.isArray(entry) ? cloneArray(entry) : cloneObject(entry)) : entry;\n }\n\n function mergeObject(target, source) {\n const result = {};\n const targetKeys = getKeys(target);\n const sourceKeys = getKeys(source);\n let i, il, key;\n for (i = 0, il = targetKeys.length; i < il; ++i) {\n isNotPrototypeKey((key = targetKeys[i])) &&\n sourceKeys.indexOf(key) === -1 &&\n (result[key] = clone(target[key]));\n }\n\n for (i = 0, il = sourceKeys.length; i < il; ++i) {\n if (!isNotPrototypeKey((key = sourceKeys[i]))) {\n continue;\n }\n\n if (key in target) {\n if (targetKeys.indexOf(key) !== -1) {\n if (\n cloneProtoObject &&\n isMergeableObject(source[key]) &&\n Object.getPrototypeOf(source[key]) !== JSON_PROTO\n ) {\n result[key] = cloneProtoObject(source[key]);\n } else {\n result[key] = _deepmerge(target[key], source[key]);\n }\n }\n } else {\n result[key] = clone(source[key]);\n }\n }\n return result;\n }\n\n function _deepmerge(target, source) {\n const sourceIsArray = Array.isArray(source);\n const targetIsArray = Array.isArray(target);\n\n if (isPrimitive(source)) {\n return source;\n } else if (isPrimitiveOrBuiltIn(target)) {\n return clone(source);\n } else if (sourceIsArray && targetIsArray) {\n return mergeArray(target, source);\n } else if (sourceIsArray !== targetIsArray) {\n return clone(source);\n } else {\n return mergeObject(target, source);\n }\n }\n\n function _deepmergeAll() {\n switch (arguments.length) {\n case 0:\n return {};\n case 1:\n return clone(arguments[0]);\n case 2:\n return _deepmerge(arguments[0], arguments[1]);\n }\n let result;\n for (let i = 0, il = arguments.length; i < il; ++i) {\n result = _deepmerge(result, arguments[i]);\n }\n return result;\n }\n\n return options?.all ? _deepmergeAll : _deepmerge;\n}\n\nfunction deepmergeArray(options) {\n const deepmerge = options.deepmerge;\n const clone = options.clone;\n return function (target, source) {\n let i = 0;\n const tl = target.length;\n const sl = source.length;\n const il = Math.max(target.length, source.length);\n const result = new Array(il);\n for (i = 0; i < il; ++i) {\n if (i < sl) {\n result[i] = deepmerge(target[i], source[i]);\n } else {\n result[i] = clone(target[i]);\n }\n }\n return result;\n };\n}\n\nconst deepmerge = deepmergeConstructor({ all: true, mergeArray: deepmergeArray });\n\nconst stringFormatters = {};\n\nfunction registerStringFormatter(name, validator) {\n stringFormatters[name] = validator;\n}\n\nconst numberFormatters = {};\n\nfunction registerNumberFormatter(name, validator) {\n numberFormatters[name] = validator;\n}\n\nfunction pushPath(ctx, key) {\n ctx.path.push(key);\n}\nfunction popPath(ctx) {\n ctx.path.pop();\n}\nfunction printPath(ctx) {\n return ctx.path.join(".");\n}\nfunction buildSchemaErrorMessage(ctx, message) {\n return `Failed to print schema. At ${printPath(ctx)}: ${message}`;\n}\nfunction buildError(ctx, message, received) {\n return [\n {\n message,\n path: [...ctx.path],\n received,\n },\n ];\n}\n\nfunction buildUnionError(ctx, errors, received) {\n return [\n {\n path: [...ctx.path],\n received,\n errors,\n isUnionError: true,\n message: "expected one of",\n },\n ];\n}\n\nfunction parseIdentity(ctx, input) {\n return input;\n}\n\nfunction validateString(ctx, input) {\n return typeof input === "string";\n}\n\nfunction reportString(ctx, input) {\n return buildError(ctx, "expected string", input);\n}\n\nfunction schemaString(ctx) {\n return {\n type: "string",\n };\n}\n\nfunction describeString(ctx) {\n return "string";\n}\n\nfunction validateNumber(ctx, input) {\n return typeof input === "number";\n}\n\nfunction reportNumber(ctx, input) {\n return buildError(ctx, "expected number", input);\n}\n\nfunction schemaNumber(ctx) {\n return {\n type: "number",\n };\n}\n\nfunction describeNumber(ctx) {\n return "number";\n}\n\nfunction validateBoolean(ctx, input) {\n return typeof input === "boolean";\n}\n\nfunction reportBoolean(ctx, input) {\n return buildError(ctx, "expected boolean", input);\n}\n\nfunction schemaBoolean(ctx) {\n return {\n type: "boolean",\n };\n}\n\nfunction describeBoolean(ctx) {\n return "boolean";\n}\n\nfunction validateAny(ctx, input) {\n return true;\n}\n\nfunction reportAny(ctx, input) {\n return buildError(ctx, "expected any", input);\n}\n\nfunction schemaAny(ctx) {\n return {};\n}\n\nfunction describeAny(ctx) {\n return "any";\n}\n\nfunction validateNull(ctx, input) {\n if (input == null) {\n return true;\n }\n return false;\n}\n\nfunction reportNull(ctx, input) {\n return buildError(ctx, "expected nullish value", input);\n}\n\nfunction schemaNull(ctx) {\n return {\n type: "null",\n };\n}\n\nfunction describeNull(ctx) {\n return "null";\n}\n\nfunction validateNever(ctx, input) {\n return false;\n}\n\nfunction reportNever(ctx, input) {\n return buildError(ctx, "expected never", input);\n}\n\nfunction schemaNever(ctx) {\n return {\n anyOf: [],\n };\n}\n\nfunction describeNever(ctx) {\n return "never";\n}\n\nfunction validateFunction(ctx, input) {\n return typeof input === "function";\n}\n\nfunction reportFunction(ctx, input) {\n return buildError(ctx, "expected function", input);\n}\n\nfunction schemaFunction(ctx) {\n throw new Error(buildSchemaErrorMessage(ctx, "Cannot generate JSON Schema for function"));\n}\n\nfunction describeFunction(ctx) {\n return "function";\n}\n\nclass ConstDecoder {\n constructor(value) {\n this.value = value;\n }\n\n validateConstDecoder(ctx, input) {\n return input === this.value;\n }\n\n parseConstDecoder(ctx, input) {\n return input;\n }\n\n reportConstDecoder(ctx, input) {\n return buildError(ctx, `expected ${JSON.stringify(this.value)}`, input);\n }\n\n schemaConstDecoder(ctx) {\n return {\n const: this.value,\n };\n }\n describeConstDecoder(ctx) {\n return JSON.stringify(this.value);\n }\n}\n\nclass RegexDecoder {\n constructor(regex, description) {\n this.regex = regex;\n this.description = description;\n }\n\n validateRegexDecoder(ctx, input) {\n if (typeof input === "string") {\n return this.regex.test(input);\n }\n return false;\n }\n\n parseRegexDecoder(ctx, input) {\n return input;\n }\n\n reportRegexDecoder(ctx, input) {\n return buildError(ctx, `expected string matching ${this.description}`, input);\n }\n\n schemaRegexDecoder(ctx) {\n return {\n type: "string",\n pattern: this.description,\n };\n }\n describeRegexDecoder(ctx) {\n return this.description;\n }\n}\n\nclass CodecDecoder {\n constructor(codec) {\n this.codec = codec;\n }\n validateCodecDecoder(ctx, input) {\n switch (this.codec) {\n case "Codec::ISO8061": {\n return input instanceof Date;\n }\n case "Codec::BigInt": {\n return typeof input === "bigint";\n }\n }\n return false;\n }\n parseCodecDecoder(ctx, input) {\n return input;\n }\n\n reportCodecDecoder(ctx, input) {\n switch (this.codec) {\n case "Codec::ISO8061": {\n return buildError(ctx, `expected Date`, input);\n }\n case "Codec::BigInt": {\n return buildError(ctx, `expected BigInt`, input);\n }\n }\n\n return buildError(ctx, `expected ${this.codec}`, input);\n }\n\n schemaCodecDecoder(ctx) {\n switch (this.codec) {\n case "Codec::ISO8061": {\n throw new Error(buildSchemaErrorMessage(ctx, "Cannot generate JSON Schema for Date"));\n }\n case "Codec::BigInt": {\n throw new Error(buildSchemaErrorMessage(ctx, "Cannot generate JSON Schema for BigInt"));\n }\n }\n\n throw new Error("INTERNAL ERROR: Unrecognized codec: " + this.codec);\n }\n describeCodecDecoder(ctx) {\n switch (this.codec) {\n case "Codec::ISO8061": {\n return "Date";\n }\n case "Codec::BigInt": {\n return "BigInt";\n }\n }\n throw new Error("INTERNAL ERROR: Unrecognized codec: " + this.codec);\n }\n}\n\nclass StringWithFormatsDecoder {\n constructor(...formats) {\n this.formats = formats;\n }\n\n validateStringWithFormatsDecoder(ctx, input) {\n if (typeof input !== "string") {\n return false;\n }\n\n for (const f of this.formats) {\n const validator = stringFormatters[f];\n\n if (validator == null) {\n return false;\n }\n\n if (!validator(input)) {\n return false;\n }\n }\n\n return true;\n }\n parseStringWithFormatsDecoder(ctx, input) {\n return input;\n }\n reportStringWithFormatsDecoder(ctx, input) {\n return buildError(ctx, `expected string with format "${this.formats.join(" and ")}"`, input);\n }\n schemaStringWithFormatsDecoder(ctx) {\n return {\n type: "string",\n format: this.formats.join(" and "),\n };\n }\n describeStringWithFormatsDecoder(ctx) {\n if (this.formats.length === 0) {\n throw new Error("INTERNAL ERROR: No formats provided");\n }\n const [first, ...rest] = this.formats;\n let acc = `StringFormat<"${first}">`;\n for (const r of rest) {\n acc = `StringFormatExtends<${acc}, "${r}">`;\n }\n return acc;\n }\n}\nclass NumberWithFormatsDecoder {\n constructor(...formats) {\n this.formats = formats;\n }\n\n validateNumberWithFormatsDecoder(ctx, input) {\n if (typeof input !== "number") {\n return false;\n }\n\n for (const f of this.formats) {\n const validator = numberFormatters[f];\n\n if (validator == null) {\n return false;\n }\n\n if (!validator(input)) {\n return false;\n }\n }\n\n return true;\n }\n parseNumberWithFormatsDecoder(ctx, input) {\n return input;\n }\n reportNumberWithFormatsDecoder(ctx, input) {\n return buildError(ctx, `expected number with format "${this.formats.join(" and ")}"`, input);\n }\n schemaNumberWithFormatsDecoder(ctx) {\n return {\n type: "number",\n format: this.formats.join(" and "),\n };\n }\n describeNumberWithFormatsDecoder(ctx) {\n if (this.formats.length === 0) {\n throw new Error("INTERNAL ERROR: No formats provided");\n }\n const [first, ...rest] = this.formats;\n let acc = `NumberFormat<"${first}">`;\n for (const r of rest) {\n acc = `NumberFormatExtends<${acc}, "${r}">`;\n }\n return acc;\n }\n}\n\nconst limitedCommaJoinJson = (arr) => {\n const limit = 3;\n if (arr.length < limit) {\n return arr.map((it) => JSON.stringify(it)).join(", ");\n }\n return (\n arr\n .slice(0, limit)\n .map((it) => JSON.stringify(it))\n .join(", ") + `...`\n );\n};\nclass AnyOfConstsDecoder {\n constructor(consts) {\n this.consts = consts;\n }\n validateAnyOfConstsDecoder(ctx, input) {\n if (input == null) {\n if (this.consts.includes(null) || this.consts.includes(undefined)) {\n return true;\n }\n }\n return this.consts.includes(input);\n }\n parseAnyOfConstsDecoder(ctx, input) {\n return input;\n }\n reportAnyOfConstsDecoder(ctx, input) {\n return buildError(ctx, `expected one of ${limitedCommaJoinJson(this.consts)}`, input);\n }\n schemaAnyOfConstsDecoder(ctx) {\n return {\n enum: this.consts,\n };\n }\n describeAnyOfConstsDecoder(ctx) {\n const parts = this.consts.map((it) => JSON.stringify(it));\n return parts.join(" | ");\n }\n}\n\nclass ObjectValidator {\n constructor(data, rest) {\n this.data = data;\n this.rest = rest;\n }\n\n validateObjectValidator(ctx, input) {\n if (typeof input === "object" && !Array.isArray(input) && input !== null) {\n const configKeys = Object.keys(this.data);\n for (const k of configKeys) {\n const validator = this.data[k];\n if (!validator(ctx, input[k])) {\n return false;\n }\n }\n\n if (this.rest != null) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n for (const k of extraKeys) {\n const v = input[k];\n if (!this.rest(ctx, v)) {\n return false;\n }\n }\n } else {\n if (ctx.disallowExtraProperties) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n\n if (extraKeys.length > 0) {\n return false;\n }\n }\n }\n\n return true;\n }\n return false;\n }\n}\n\nclass ObjectReporter {\n constructor(dataValidator, restValidator, dataReporter, restReporter) {\n this.dataValidator = dataValidator;\n this.restValidator = restValidator;\n this.dataReporter = dataReporter;\n this.restReporter = restReporter;\n }\n\n reportObjectReporter(ctx, input) {\n if (typeof input !== "object" || Array.isArray(input) || input === null) {\n return buildError(ctx, "expected object", input);\n }\n\n let acc = [];\n\n const configKeys = Object.keys(this.dataReporter);\n\n for (const k of configKeys) {\n const ok = this.dataValidator[k](ctx, input[k]);\n if (!ok) {\n pushPath(ctx, k);\n const arr2 = this.dataReporter[k](ctx, input[k]);\n acc.push(...arr2);\n popPath(ctx);\n }\n }\n\n if (this.restReporter != null) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n for (const k of extraKeys) {\n const ok = this.restValidator(ctx, input[k]);\n if (!ok) {\n pushPath(ctx, k);\n const arr2 = this.restReporter(ctx, input[k]);\n acc.push(...arr2);\n popPath(ctx);\n }\n }\n } else {\n if (ctx.disallowExtraProperties) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n if (extraKeys.length > 0) {\n \n return extraKeys.flatMap((k) => {\n pushPath(ctx, k);\n const err = buildError(ctx, `extra property`, input[k]);\n popPath(ctx);\n return err;\n });\n }\n }\n }\n\n return acc;\n }\n}\nclass ObjectParser {\n constructor(data, rest) {\n this.data = data;\n this.rest = rest;\n }\n\n parseObjectParser(ctx, input) {\n let acc = {};\n\n const inputKeys = Object.keys(input);\n\n for (const k of inputKeys) {\n const v = input[k];\n if (k in this.data) {\n const itemParsed = this.data[k](ctx, v);\n acc[k] = itemParsed;\n } else if (this.rest != null) {\n const restParsed = this.rest(ctx, v);\n acc[k] = restParsed;\n }\n }\n\n return acc;\n }\n}\n\nclass ObjectSchema {\n constructor(data, rest) {\n this.data = data;\n this.rest = rest;\n }\n\n schemaObjectSchema(ctx) {\n const properties = {};\n for (const k in this.data) {\n pushPath(ctx, k);\n properties[k] = this.data[k](ctx);\n popPath(ctx);\n }\n\n const required = Object.keys(this.data);\n\n const additionalProperties = this.rest != null ? this.rest(ctx) : false;\n\n return {\n type: "object",\n properties,\n required,\n additionalProperties,\n };\n }\n}\n\nclass ObjectDescribe {\n constructor(dataDescriber, restDescriber) {\n this.dataDescriber = dataDescriber;\n this.restDescriber = restDescriber;\n }\n describeObjectDescribe(ctx) {\n const sortedKeys = Object.keys(this.dataDescriber).sort();\n const props = sortedKeys\n .map((k) => {\n const describer = this.dataDescriber[k];\n return `${k}: ${describer(ctx)}`;\n })\n .join(", ");\n\n const rest = this.restDescriber != null ? `[K in string]: ${this.restDescriber(ctx)}` : null;\n\n const content = [props, rest].filter((it) => it != null && it.length > 0).join(", ");\n return `{ ${content} }`;\n }\n}\n\nclass MappedRecordValidator {\n constructor(keyValidator, valueValidator) {\n this.keyValidator = keyValidator;\n this.valueValidator = valueValidator;\n }\n\n validateMappedRecordValidator(ctx, input) {\n if (typeof input !== "object" || input == null) {\n return false;\n }\n\n for (const k in input) {\n const v = input[k];\n if (!this.keyValidator(ctx, k) || !this.valueValidator(ctx, v)) {\n return false;\n }\n }\n\n return true;\n }\n}\n\nclass MappedRecordParser {\n constructor(keyParser, valueParser) {\n this.keyParser = keyParser;\n this.valueParser = valueParser;\n }\n\n parseMappedRecordParser(ctx, input) {\n const result = {};\n for (const k in input) {\n const parsedKey = this.keyParser(ctx, k);\n const parsedValue = this.valueParser(ctx, input[k]);\n result[parsedKey] = parsedValue;\n }\n return result;\n }\n}\n\nclass MappedRecordSchema {\n constructor(keySchema, valueSchema) {\n this.keySchema = keySchema;\n this.valueSchema = valueSchema;\n }\n\n schemaMappedRecordSchema(ctx) {\n return {\n type: "object",\n additionalProperties: this.valueSchema(ctx),\n propertyNames: this.keySchema(ctx),\n };\n }\n}\n\nclass MappedRecordDescribe {\n constructor(keyDescriber, valueDescriber) {\n this.keyDescriber = keyDescriber;\n this.valueDescriber = valueDescriber;\n }\n describeMappedRecordDescribe(ctx) {\n const k = this.keyDescriber(ctx);\n const v = this.valueDescriber(ctx);\n return `Record<${k}, ${v}>`;\n }\n}\n\nclass MappedRecordReporter {\n constructor(keyValidator, valueValidator, keyReporter, valueReporter) {\n this.keyValidator = keyValidator;\n this.valueValidator = valueValidator;\n this.keyReporter = keyReporter;\n this.valueReporter = valueReporter;\n }\n\n reportMappedRecordReporter(ctx, input) {\n if (typeof input !== "object" || input == null) {\n return buildError(ctx, "expected object", input);\n }\n\n let acc = [];\n for (const k in input) {\n const v = input[k];\n const okKey = this.keyValidator(ctx, k);\n if (!okKey) {\n pushPath(ctx, k);\n const errs = this.keyReporter(ctx, k);\n acc.push(...errs);\n popPath(ctx);\n }\n const okValue = this.valueValidator(ctx, v);\n if (!okValue) {\n pushPath(ctx, k);\n const errs = this.valueReporter(ctx, v);\n acc.push(...errs);\n popPath(ctx);\n }\n }\n return acc;\n }\n}\n\nclass AnyOfDiscriminatedValidator {\n constructor(discriminator, mapping) {\n this.discriminator = discriminator;\n this.mapping = mapping;\n }\n\n validateAnyOfDiscriminatedValidator(ctx, input) {\n if (typeof input !== "object" || input == null) {\n return false;\n }\n const d = input[this.discriminator];\n if (d == null) {\n return false;\n }\n const v = this.mapping[d];\n if (v == null) {\n \n return false;\n }\n\n return v(ctx, input);\n }\n}\n\nclass AnyOfDiscriminatedParser {\n constructor(discriminator, mapping) {\n this.discriminator = discriminator;\n this.mapping = mapping;\n }\n\n parseAnyOfDiscriminatedParser(ctx, input) {\n const parser = this.mapping[input[this.discriminator]];\n if (parser == null) {\n throw new Error(\n "INTERNAL ERROR: Missing parser for discriminator " + JSON.stringify(input[this.discriminator]),\n );\n }\n return {\n ...parser(ctx, input),\n [this.discriminator]: input[this.discriminator],\n };\n }\n}\n\nclass AnyOfDiscriminatedReporter {\n constructor(discriminator, mapping) {\n this.discriminator = discriminator;\n this.mapping = mapping;\n }\n\n reportAnyOfDiscriminatedReporter(ctx, input) {\n if (input == null || typeof input !== "object") {\n return buildError(ctx, "expected object", input);\n }\n\n const d = input[this.discriminator];\n if (d == null) {\n return buildError(ctx, "expected discriminator key " + JSON.stringify(this.discriminator), input);\n }\n const v = this.mapping[d];\n if (v == null) {\n pushPath(ctx, this.discriminator);\n const errs = buildError(\n ctx,\n "expected one of " +\n Object.keys(this.mapping)\n .map((it) => JSON.stringify(it))\n .join(", "),\n d,\n );\n popPath(ctx);\n return errs;\n }\n return v(ctx, input);\n }\n}\n\nclass AnyOfDiscriminatedSchema {\n constructor(vs) {\n this.vs = vs;\n }\n\n schemaAnyOfDiscriminatedSchema(ctx) {\n \n return {\n anyOf: this.vs.map((v) => v(ctx)),\n };\n }\n}\n\nclass AnyOfDiscriminatedDescribe {\n constructor(vs) {\n this.vs = vs;\n }\n\n describeAnyOfDiscriminatedDescribe(ctx) {\n \n return `(${this.vs.map((v) => v(ctx)).join(" | ")})`;\n }\n}\n\nclass ArrayParser {\n constructor(innerParser) {\n this.innerParser = innerParser;\n }\n\n parseArrayParser(ctx, input) {\n return input.map((v) => this.innerParser(ctx, v));\n }\n}\n\nclass ArrayValidator {\n constructor(innerValidator) {\n this.innerValidator = innerValidator;\n }\n\n validateArrayValidator(ctx, input) {\n if (Array.isArray(input)) {\n for (let i = 0; i < input.length; i++) {\n const v = input[i];\n const ok = this.innerValidator(ctx, v);\n if (!ok) {\n return false;\n }\n }\n return true;\n }\n return false;\n }\n}\n\nclass ArrayReporter {\n constructor(innerValidator, innerReporter) {\n this.innerValidator = innerValidator;\n this.innerReporter = innerReporter;\n }\n\n reportArrayReporter(ctx, input) {\n if (!Array.isArray(input)) {\n return buildError(ctx, "expected array", input);\n }\n\n let acc = [];\n for (let i = 0; i < input.length; i++) {\n const ok = this.innerValidator(ctx, input[i]);\n if (!ok) {\n pushPath(ctx, `[${i}]`);\n const v = input[i];\n const arr2 = this.innerReporter(ctx, v);\n acc.push(...arr2);\n popPath(ctx);\n }\n }\n\n return acc;\n }\n}\n\nclass ArraySchema {\n constructor(innerSchema) {\n this.innerSchema = innerSchema;\n }\n\n schemaArraySchema(ctx) {\n pushPath(ctx, "[]");\n const items = this.innerSchema(ctx);\n popPath(ctx);\n return {\n type: "array",\n items,\n };\n }\n}\n\nclass ArrayDescribe {\n constructor(innerDescriber) {\n this.innerDescriber = innerDescriber;\n }\n describeArrayDescribe(ctx) {\n return `Array<${this.innerDescriber(ctx)}>`;\n }\n}\n\nclass AnyOfValidator {\n constructor(vs) {\n this.vs = vs;\n }\n validateAnyOfValidator(ctx, input) {\n for (const v of this.vs) {\n if (v(ctx, input)) {\n return true;\n }\n }\n return false;\n }\n}\nclass AnyOfParser {\n constructor(validators, parsers) {\n this.validators = validators;\n this.parsers = parsers;\n }\n parseAnyOfParser(ctx, input) {\n const items = [];\n for (let i = 0; i < this.validators.length; i++) {\n if (this.validators[i](ctx, input)) {\n items.push(this.parsers[i](ctx, input));\n }\n }\n return deepmerge(...items);\n }\n}\nclass AnyOfReporter {\n constructor(validators, reporters) {\n this.validators = validators;\n this.reporters = reporters;\n }\n reportAnyOfReporter(ctx, input) {\n const acc = [];\n const oldPaths = ctx.path;\n ctx.path = [];\n for (const v of this.reporters) {\n const errors = v(ctx, input);\n acc.push(...errors);\n }\n ctx.path = oldPaths;\n return buildUnionError(ctx, acc, input);\n }\n}\n\nclass AnyOfSchema {\n constructor(schemas) {\n this.schemas = schemas;\n }\n schemaAnyOfSchema(ctx) {\n return {\n anyOf: this.schemas.map((s) => s(ctx)),\n };\n }\n}\n\nclass AnyOfDescribe {\n constructor(describers) {\n this.describers = describers;\n }\n describeAnyOfDescribe(ctx) {\n return `(${this.describers.map((v) => v(ctx)).join(" | ")})`;\n }\n}\n\nclass AllOfValidator {\n constructor(vs) {\n this.vs = vs;\n }\n validateAllOfValidator(ctx, input) {\n for (const v of this.vs) {\n const isObj = typeof input === "object";\n if (!isObj) {\n return false;\n }\n if (!v(ctx, input)) {\n return false;\n }\n }\n return true;\n }\n}\n\nclass AllOfParser {\n constructor(validators, parsers) {\n this.validators = validators;\n this.parsers = parsers;\n }\n parseAllOfParser(ctx, input) {\n let acc = {};\n for (let i = 0; i < this.validators.length; i++) {\n const p = this.parsers[i];\n const parsed = p(ctx, input);\n if (typeof parsed !== "object") {\n throw new Error("INTERNAL ERROR: AllOfParser: Expected object");\n }\n acc = { ...acc, ...parsed };\n }\n return acc;\n }\n}\n\nclass AllOfReporter {\n constructor(validators, reporters) {\n this.validators = validators;\n this.reporters = reporters;\n }\n reportAllOfReporter(ctx, input) {\n const acc = [];\n for (const v of this.reporters) {\n const errors = v(ctx, input);\n acc.push(...errors);\n }\n return acc;\n }\n}\n\nclass AllOfSchema {\n constructor(schemas) {\n this.schemas = schemas;\n }\n schemaAllOfSchema(ctx) {\n return {\n allOf: this.schemas.map((s) => s(ctx)),\n };\n }\n}\n\nclass AllOfDescribe {\n constructor(describers) {\n this.describers = describers;\n }\n describeAllOfDescribe(ctx) {\n return `(${this.describers.map((v) => v(ctx)).join(" & ")})`;\n }\n}\n\nclass TupleValidator {\n constructor(prefix, rest) {\n this.prefix = prefix;\n this.rest = rest;\n }\n validateTupleValidator(ctx, input) {\n if (Array.isArray(input)) {\n let idx = 0;\n for (const prefixVal of this.prefix) {\n if (!prefixVal(ctx, input[idx])) {\n return false;\n }\n idx++;\n }\n const itemVal = this.rest;\n if (itemVal != null) {\n for (let i = idx; i < input.length; i++) {\n if (!itemVal(ctx, input[i])) {\n return false;\n }\n }\n } else {\n if (input.length > idx) {\n return false;\n }\n }\n return true;\n }\n return false;\n }\n}\n\nclass TupleParser {\n constructor(prefix, rest) {\n this.prefix = prefix;\n this.rest = rest;\n }\n parseTupleParser(ctx, input) {\n let idx = 0;\n let acc = [];\n for (const prefixParser of this.prefix) {\n acc.push(prefixParser(ctx, input[idx]));\n idx++;\n }\n if (this.rest != null) {\n for (let i = idx; i < input.length; i++) {\n acc.push(this.rest(ctx, input[i]));\n }\n }\n return acc;\n }\n}\n\nclass TupleReporter {\n constructor(prefixValidator, restValidator, prefixReporter, restReporter) {\n this.prefixValidator = prefixValidator;\n this.restValidator = restValidator;\n this.prefixReporter = prefixReporter;\n this.restReporter = restReporter;\n }\n reportTupleReporter(ctx, input) {\n if (!Array.isArray(input)) {\n return buildError(ctx, "expected tuple", input);\n }\n\n let idx = 0;\n\n let acc = [];\n\n for (const prefixReporter of this.prefixReporter) {\n const ok = this.prefixValidator[idx](ctx, input[idx]);\n if (!ok) {\n pushPath(ctx, `[${idx}]`);\n const errors = prefixReporter(ctx, input[idx]);\n acc.push(...errors);\n popPath(ctx);\n }\n idx++;\n }\n\n const restReporter = this.restReporter;\n if (restReporter != null) {\n for (let i = idx; i < input.length; i++) {\n const ok = this.restValidator(ctx, input[i]);\n if (!ok) {\n pushPath(ctx, `[${i}]`);\n const errors = restReporter(ctx, input[i]);\n acc.push(...errors);\n popPath(ctx);\n }\n }\n }\n\n return acc;\n }\n}\n\nclass TupleSchema {\n constructor(prefix, rest) {\n this.prefix = prefix;\n this.rest = rest;\n }\n\n schemaTupleSchema(ctx) {\n pushPath(ctx, "[]");\n const prefixItems = this.prefix.map((s) => s(ctx));\n const items = this.rest != null ? this.rest(ctx) : false;\n popPath(ctx);\n return {\n type: "array",\n prefixItems,\n items,\n };\n }\n}\n\nclass TupleDescribe {\n constructor(prefix, rest) {\n this.prefix = prefix;\n this.rest = rest;\n }\n describeTupleDescribe(ctx) {\n const prefix = this.prefix.map((d) => d(ctx)).join(", ");\n const rest = this.rest != null ? `...Array<${this.rest(ctx)}>` : null;\n\n const inner = [prefix, rest].filter((it) => it != null && it.length > 0).join(", ");\n return `[${inner}]`;\n }\n}\n', "parser.d.ts": 'import { BuildParserFunction } from "@beff/client";\n\ndeclare const _exports: {\n buildParsers: BuildParserFunction;\n};\n\nexport default _exports;\n' };
|
|
45784
|
+
var bundle_default = { "build-parsers.js": '\n\nfunction buildParsers(args) {\n const stringFormats = args?.stringFormats ?? {};\n \n for (const k of RequiredStringFormats) {\n if (stringFormats[k] == null) {\n throw new Error(`Missing custom format ${k}`);\n }\n }\n\n Object.keys(stringFormats).forEach((k) => {\n const v = stringFormats[k];\n \n registerStringFormatter(k, v);\n });\n\n const numberFormats = args?.numberFormats ?? {};\n \n for (const k of RequiredNumberFormats) {\n if (numberFormats[k] == null) {\n throw new Error(`Missing custom format ${k}`);\n }\n }\n\n Object.keys(numberFormats).forEach((k) => {\n const v = numberFormats[k];\n \n registerNumberFormatter(k, v);\n });\n\n let decoders = {};\n \n Object.keys(buildValidatorsInput).forEach((k) => {\n \n let v = buildValidatorsInput[k];\n const validate = (input, options) => {\n const disallowExtraProperties = options?.disallowExtraProperties ?? false;\n const ctx = { disallowExtraProperties };\n const ok = v(ctx, input);\n if (typeof ok !== "boolean") {\n throw new Error("INTERNAL ERROR: Expected boolean");\n }\n return ok;\n };\n\n \n const schemaFn = buildSchemaInput[k];\n const schema = () => {\n const ctx = {\n path: [],\n seen: {},\n };\n return schemaFn(ctx);\n };\n\n \n const describeFn = buildDescribeInput[k];\n const describe = () => {\n const ctx = {\n deps: {},\n };\n const out = describeFn(ctx);\n let sortedDepsKeys = Object.keys(ctx.deps).sort();\n \n \n \n \n const depsPart = sortedDepsKeys\n .map((key) => {\n return `type ${key} = ${ctx.deps[key]};`;\n })\n .join("\\n\\n");\n \n \n \n const outPart = `type Codec${k} = ${out};`;\n return [depsPart, outPart].filter((it) => it != null && it.length > 0).join("\\n\\n");\n };\n\n const safeParse = (input, options) => {\n const disallowExtraProperties = options?.disallowExtraProperties ?? false;\n const ok = validate(input, options);\n if (ok) {\n \n let p = buildParsersInput[k];\n let ctx = { disallowExtraProperties };\n const parsed = p(ctx, input);\n return { success: true, data: parsed };\n }\n \n let e = buildReportersInput[k];\n let ctx = { path: [], disallowExtraProperties };\n return {\n success: false,\n errors: e(ctx, input).slice(0, 10),\n };\n };\n const parse = (input, options) => {\n const safe = safeParse(input, options);\n if (safe.success) {\n return safe.data;\n }\n \n const explained = printErrors(safe.errors, []);\n throw new Error(`Failed to parse ${k} - ${explained}`);\n };\n const zod = () => {\n \n return z.custom(\n (data) => safeParse(data).success,\n (val) => {\n const errors = safeParse(val).errors;\n \n return printErrors(errors, []);\n },\n );\n };\n decoders[k] = {\n parse,\n safeParse,\n zod,\n name: k,\n validate,\n schema,\n describe,\n };\n });\n return decoders;\n}\n', "decoders.js": '\n\n\n\n\n\nconst JSON_PROTO = Object.getPrototypeOf({});\n\nfunction deepmergeConstructor(options) {\n function isNotPrototypeKey(value) {\n return value !== "constructor" && value !== "prototype" && value !== "__proto__";\n }\n\n function cloneArray(value) {\n let i = 0;\n const il = value.length;\n const result = new Array(il);\n for (i; i < il; ++i) {\n result[i] = clone(value[i]);\n }\n return result;\n }\n\n function cloneObject(target) {\n const result = {};\n\n if (cloneProtoObject && Object.getPrototypeOf(target) !== JSON_PROTO) {\n return cloneProtoObject(target);\n }\n\n const targetKeys = getKeys(target);\n let i, il, key;\n for (i = 0, il = targetKeys.length; i < il; ++i) {\n isNotPrototypeKey((key = targetKeys[i])) && (result[key] = clone(target[key]));\n }\n return result;\n }\n\n function concatArrays(target, source) {\n const tl = target.length;\n const sl = source.length;\n let i = 0;\n const result = new Array(tl + sl);\n for (i; i < tl; ++i) {\n result[i] = clone(target[i]);\n }\n for (i = 0; i < sl; ++i) {\n result[i + tl] = clone(source[i]);\n }\n return result;\n }\n\n const propertyIsEnumerable = Object.prototype.propertyIsEnumerable;\n function getSymbolsAndKeys(value) {\n const result = Object.keys(value);\n const keys = Object.getOwnPropertySymbols(value);\n for (let i = 0, il = keys.length; i < il; ++i) {\n \n propertyIsEnumerable.call(value, keys[i]) && result.push(keys[i]);\n }\n return result;\n }\n\n const getKeys = options?.symbols ? getSymbolsAndKeys : Object.keys;\n\n const cloneProtoObject =\n typeof options?.cloneProtoObject === "function" ? options.cloneProtoObject : undefined;\n\n function isMergeableObject(value) {\n return (\n typeof value === "object" && value !== null && !(value instanceof RegExp) && !(value instanceof Date)\n );\n }\n\n function isPrimitive(value) {\n return typeof value !== "object" || value === null;\n }\n\n const isPrimitiveOrBuiltIn =\n \n typeof Buffer !== "undefined"\n ? (value) =>\n typeof value !== "object" ||\n value === null ||\n value instanceof RegExp ||\n value instanceof Date ||\n \n value instanceof Buffer\n : (value) =>\n typeof value !== "object" || value === null || value instanceof RegExp || value instanceof Date;\n\n const mergeArray =\n options && typeof options.mergeArray === "function"\n ? options.mergeArray({ clone, deepmerge: _deepmerge, getKeys, isMergeableObject })\n : concatArrays;\n\n function clone(entry) {\n return isMergeableObject(entry) ? (Array.isArray(entry) ? cloneArray(entry) : cloneObject(entry)) : entry;\n }\n\n function mergeObject(target, source) {\n const result = {};\n const targetKeys = getKeys(target);\n const sourceKeys = getKeys(source);\n let i, il, key;\n for (i = 0, il = targetKeys.length; i < il; ++i) {\n isNotPrototypeKey((key = targetKeys[i])) &&\n sourceKeys.indexOf(key) === -1 &&\n (result[key] = clone(target[key]));\n }\n\n for (i = 0, il = sourceKeys.length; i < il; ++i) {\n if (!isNotPrototypeKey((key = sourceKeys[i]))) {\n continue;\n }\n\n if (key in target) {\n if (targetKeys.indexOf(key) !== -1) {\n if (\n cloneProtoObject &&\n isMergeableObject(source[key]) &&\n Object.getPrototypeOf(source[key]) !== JSON_PROTO\n ) {\n result[key] = cloneProtoObject(source[key]);\n } else {\n result[key] = _deepmerge(target[key], source[key]);\n }\n }\n } else {\n result[key] = clone(source[key]);\n }\n }\n return result;\n }\n\n function _deepmerge(target, source) {\n const sourceIsArray = Array.isArray(source);\n const targetIsArray = Array.isArray(target);\n\n if (isPrimitive(source)) {\n return source;\n } else if (isPrimitiveOrBuiltIn(target)) {\n return clone(source);\n } else if (sourceIsArray && targetIsArray) {\n return mergeArray(target, source);\n } else if (sourceIsArray !== targetIsArray) {\n return clone(source);\n } else {\n return mergeObject(target, source);\n }\n }\n\n function _deepmergeAll() {\n switch (arguments.length) {\n case 0:\n return {};\n case 1:\n return clone(arguments[0]);\n case 2:\n return _deepmerge(arguments[0], arguments[1]);\n }\n let result;\n for (let i = 0, il = arguments.length; i < il; ++i) {\n result = _deepmerge(result, arguments[i]);\n }\n return result;\n }\n\n return options?.all ? _deepmergeAll : _deepmerge;\n}\n\nfunction deepmergeArray(options) {\n const deepmerge = options.deepmerge;\n const clone = options.clone;\n return function (target, source) {\n let i = 0;\n const tl = target.length;\n const sl = source.length;\n const il = Math.max(target.length, source.length);\n const result = new Array(il);\n for (i = 0; i < il; ++i) {\n if (i < sl) {\n result[i] = deepmerge(target[i], source[i]);\n } else {\n result[i] = clone(target[i]);\n }\n }\n return result;\n };\n}\n\nconst deepmerge = deepmergeConstructor({ all: true, mergeArray: deepmergeArray });\n\nconst stringFormatters = {};\n\nfunction registerStringFormatter(name, validator) {\n stringFormatters[name] = validator;\n}\n\nconst numberFormatters = {};\n\nfunction registerNumberFormatter(name, validator) {\n numberFormatters[name] = validator;\n}\n\nfunction pushPath(ctx, key) {\n ctx.path.push(key);\n}\nfunction popPath(ctx) {\n ctx.path.pop();\n}\nfunction printPath(ctx) {\n return ctx.path.join(".");\n}\nfunction buildSchemaErrorMessage(ctx, message) {\n return `Failed to print schema. At ${printPath(ctx)}: ${message}`;\n}\nfunction buildError(ctx, message, received) {\n return [\n {\n message,\n path: [...ctx.path],\n received,\n },\n ];\n}\n\nfunction buildUnionError(ctx, errors, received) {\n return [\n {\n path: [...ctx.path],\n received,\n errors,\n isUnionError: true,\n message: "expected one of",\n },\n ];\n}\n\nfunction parseIdentity(ctx, input) {\n return input;\n}\n\nfunction validateString(ctx, input) {\n return typeof input === "string";\n}\n\nfunction reportString(ctx, input) {\n return buildError(ctx, "expected string", input);\n}\n\nfunction schemaString(ctx) {\n return {\n type: "string",\n };\n}\n\nfunction describeString(ctx) {\n return "string";\n}\n\nfunction validateNumber(ctx, input) {\n return typeof input === "number";\n}\n\nfunction reportNumber(ctx, input) {\n return buildError(ctx, "expected number", input);\n}\n\nfunction schemaNumber(ctx) {\n return {\n type: "number",\n };\n}\n\nfunction describeNumber(ctx) {\n return "number";\n}\n\nfunction validateBoolean(ctx, input) {\n return typeof input === "boolean";\n}\n\nfunction reportBoolean(ctx, input) {\n return buildError(ctx, "expected boolean", input);\n}\n\nfunction schemaBoolean(ctx) {\n return {\n type: "boolean",\n };\n}\n\nfunction describeBoolean(ctx) {\n return "boolean";\n}\n\nfunction validateAny(ctx, input) {\n return true;\n}\n\nfunction reportAny(ctx, input) {\n return buildError(ctx, "expected any", input);\n}\n\nfunction schemaAny(ctx) {\n return {};\n}\n\nfunction describeAny(ctx) {\n return "any";\n}\n\nfunction validateNull(ctx, input) {\n if (input == null) {\n return true;\n }\n return false;\n}\n\nfunction reportNull(ctx, input) {\n return buildError(ctx, "expected nullish value", input);\n}\n\nfunction schemaNull(ctx) {\n return {\n type: "null",\n };\n}\n\nfunction describeNull(ctx) {\n return "null";\n}\n\nfunction validateNever(ctx, input) {\n return false;\n}\n\nfunction reportNever(ctx, input) {\n return buildError(ctx, "expected never", input);\n}\n\nfunction schemaNever(ctx) {\n return {\n anyOf: [],\n };\n}\n\nfunction describeNever(ctx) {\n return "never";\n}\n\nfunction validateFunction(ctx, input) {\n return typeof input === "function";\n}\n\nfunction reportFunction(ctx, input) {\n return buildError(ctx, "expected function", input);\n}\n\nfunction schemaFunction(ctx) {\n throw new Error(buildSchemaErrorMessage(ctx, "Cannot generate JSON Schema for function"));\n}\n\nfunction describeFunction(ctx) {\n return "function";\n}\n\nclass ConstDecoder {\n constructor(value) {\n this.value = value;\n }\n\n validateConstDecoder(ctx, input) {\n return input === this.value;\n }\n\n parseConstDecoder(ctx, input) {\n return input;\n }\n\n reportConstDecoder(ctx, input) {\n return buildError(ctx, `expected ${JSON.stringify(this.value)}`, input);\n }\n\n schemaConstDecoder(ctx) {\n return {\n const: this.value,\n };\n }\n describeConstDecoder(ctx) {\n return JSON.stringify(this.value);\n }\n}\n\nclass RegexDecoder {\n constructor(regex, description) {\n this.regex = regex;\n this.description = description;\n }\n\n validateRegexDecoder(ctx, input) {\n if (typeof input === "string") {\n return this.regex.test(input);\n }\n return false;\n }\n\n parseRegexDecoder(ctx, input) {\n return input;\n }\n\n reportRegexDecoder(ctx, input) {\n return buildError(ctx, `expected string matching ${this.description}`, input);\n }\n\n schemaRegexDecoder(ctx) {\n return {\n type: "string",\n pattern: this.description,\n };\n }\n describeRegexDecoder(ctx) {\n return "`" + this.description + "`";\n }\n}\n\nclass CodecDecoder {\n constructor(codec) {\n this.codec = codec;\n }\n validateCodecDecoder(ctx, input) {\n switch (this.codec) {\n case "Codec::ISO8061": {\n return input instanceof Date;\n }\n case "Codec::BigInt": {\n return typeof input === "bigint";\n }\n }\n return false;\n }\n parseCodecDecoder(ctx, input) {\n return input;\n }\n\n reportCodecDecoder(ctx, input) {\n switch (this.codec) {\n case "Codec::ISO8061": {\n return buildError(ctx, `expected Date`, input);\n }\n case "Codec::BigInt": {\n return buildError(ctx, `expected BigInt`, input);\n }\n }\n\n return buildError(ctx, `expected ${this.codec}`, input);\n }\n\n schemaCodecDecoder(ctx) {\n switch (this.codec) {\n case "Codec::ISO8061": {\n throw new Error(buildSchemaErrorMessage(ctx, "Cannot generate JSON Schema for Date"));\n }\n case "Codec::BigInt": {\n throw new Error(buildSchemaErrorMessage(ctx, "Cannot generate JSON Schema for BigInt"));\n }\n }\n\n throw new Error("INTERNAL ERROR: Unrecognized codec: " + this.codec);\n }\n describeCodecDecoder(ctx) {\n switch (this.codec) {\n case "Codec::ISO8061": {\n return "Date";\n }\n case "Codec::BigInt": {\n return "BigInt";\n }\n }\n throw new Error("INTERNAL ERROR: Unrecognized codec: " + this.codec);\n }\n}\n\nclass StringWithFormatsDecoder {\n constructor(...formats) {\n this.formats = formats;\n }\n\n validateStringWithFormatsDecoder(ctx, input) {\n if (typeof input !== "string") {\n return false;\n }\n\n for (const f of this.formats) {\n const validator = stringFormatters[f];\n\n if (validator == null) {\n return false;\n }\n\n if (!validator(input)) {\n return false;\n }\n }\n\n return true;\n }\n parseStringWithFormatsDecoder(ctx, input) {\n return input;\n }\n reportStringWithFormatsDecoder(ctx, input) {\n return buildError(ctx, `expected string with format "${this.formats.join(" and ")}"`, input);\n }\n schemaStringWithFormatsDecoder(ctx) {\n return {\n type: "string",\n format: this.formats.join(" and "),\n };\n }\n describeStringWithFormatsDecoder(ctx) {\n if (this.formats.length === 0) {\n throw new Error("INTERNAL ERROR: No formats provided");\n }\n const [first, ...rest] = this.formats;\n let acc = `StringFormat<"${first}">`;\n for (const r of rest) {\n acc = `StringFormatExtends<${acc}, "${r}">`;\n }\n return acc;\n }\n}\nclass NumberWithFormatsDecoder {\n constructor(...formats) {\n this.formats = formats;\n }\n\n validateNumberWithFormatsDecoder(ctx, input) {\n if (typeof input !== "number") {\n return false;\n }\n\n for (const f of this.formats) {\n const validator = numberFormatters[f];\n\n if (validator == null) {\n return false;\n }\n\n if (!validator(input)) {\n return false;\n }\n }\n\n return true;\n }\n parseNumberWithFormatsDecoder(ctx, input) {\n return input;\n }\n reportNumberWithFormatsDecoder(ctx, input) {\n return buildError(ctx, `expected number with format "${this.formats.join(" and ")}"`, input);\n }\n schemaNumberWithFormatsDecoder(ctx) {\n return {\n type: "number",\n format: this.formats.join(" and "),\n };\n }\n describeNumberWithFormatsDecoder(ctx) {\n if (this.formats.length === 0) {\n throw new Error("INTERNAL ERROR: No formats provided");\n }\n const [first, ...rest] = this.formats;\n let acc = `NumberFormat<"${first}">`;\n for (const r of rest) {\n acc = `NumberFormatExtends<${acc}, "${r}">`;\n }\n return acc;\n }\n}\n\nconst limitedCommaJoinJson = (arr) => {\n const limit = 3;\n if (arr.length < limit) {\n return arr.map((it) => JSON.stringify(it)).join(", ");\n }\n return (\n arr\n .slice(0, limit)\n .map((it) => JSON.stringify(it))\n .join(", ") + `...`\n );\n};\nclass AnyOfConstsDecoder {\n constructor(consts) {\n this.consts = consts;\n }\n validateAnyOfConstsDecoder(ctx, input) {\n if (input == null) {\n if (this.consts.includes(null) || this.consts.includes(undefined)) {\n return true;\n }\n }\n return this.consts.includes(input);\n }\n parseAnyOfConstsDecoder(ctx, input) {\n return input;\n }\n reportAnyOfConstsDecoder(ctx, input) {\n return buildError(ctx, `expected one of ${limitedCommaJoinJson(this.consts)}`, input);\n }\n schemaAnyOfConstsDecoder(ctx) {\n return {\n enum: this.consts,\n };\n }\n describeAnyOfConstsDecoder(ctx) {\n const parts = this.consts.map((it) => JSON.stringify(it));\n return parts.join(" | ");\n }\n}\n\nclass ObjectValidator {\n constructor(data, rest) {\n this.data = data;\n this.rest = rest;\n }\n\n validateObjectValidator(ctx, input) {\n if (typeof input === "object" && !Array.isArray(input) && input !== null) {\n const configKeys = Object.keys(this.data);\n for (const k of configKeys) {\n const validator = this.data[k];\n if (!validator(ctx, input[k])) {\n return false;\n }\n }\n\n if (this.rest != null) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n for (const k of extraKeys) {\n const v = input[k];\n if (!this.rest(ctx, v)) {\n return false;\n }\n }\n } else {\n if (ctx.disallowExtraProperties) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n\n if (extraKeys.length > 0) {\n return false;\n }\n }\n }\n\n return true;\n }\n return false;\n }\n}\n\nclass ObjectReporter {\n constructor(dataValidator, restValidator, dataReporter, restReporter) {\n this.dataValidator = dataValidator;\n this.restValidator = restValidator;\n this.dataReporter = dataReporter;\n this.restReporter = restReporter;\n }\n\n reportObjectReporter(ctx, input) {\n if (typeof input !== "object" || Array.isArray(input) || input === null) {\n return buildError(ctx, "expected object", input);\n }\n\n let acc = [];\n\n const configKeys = Object.keys(this.dataReporter);\n\n for (const k of configKeys) {\n const ok = this.dataValidator[k](ctx, input[k]);\n if (!ok) {\n pushPath(ctx, k);\n const arr2 = this.dataReporter[k](ctx, input[k]);\n acc.push(...arr2);\n popPath(ctx);\n }\n }\n\n if (this.restReporter != null) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n for (const k of extraKeys) {\n const ok = this.restValidator(ctx, input[k]);\n if (!ok) {\n pushPath(ctx, k);\n const arr2 = this.restReporter(ctx, input[k]);\n acc.push(...arr2);\n popPath(ctx);\n }\n }\n } else {\n if (ctx.disallowExtraProperties) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n if (extraKeys.length > 0) {\n \n return extraKeys.flatMap((k) => {\n pushPath(ctx, k);\n const err = buildError(ctx, `extra property`, input[k]);\n popPath(ctx);\n return err;\n });\n }\n }\n }\n\n return acc;\n }\n}\nclass ObjectParser {\n constructor(data, rest) {\n this.data = data;\n this.rest = rest;\n }\n\n parseObjectParser(ctx, input) {\n let acc = {};\n\n const inputKeys = Object.keys(input);\n\n for (const k of inputKeys) {\n const v = input[k];\n if (k in this.data) {\n const itemParsed = this.data[k](ctx, v);\n acc[k] = itemParsed;\n } else if (this.rest != null) {\n const restParsed = this.rest(ctx, v);\n acc[k] = restParsed;\n }\n }\n\n return acc;\n }\n}\n\nclass ObjectSchema {\n constructor(data, rest) {\n this.data = data;\n this.rest = rest;\n }\n\n schemaObjectSchema(ctx) {\n const properties = {};\n for (const k in this.data) {\n pushPath(ctx, k);\n properties[k] = this.data[k](ctx);\n popPath(ctx);\n }\n\n const required = Object.keys(this.data);\n\n const additionalProperties = this.rest != null ? this.rest(ctx) : false;\n\n return {\n type: "object",\n properties,\n required,\n additionalProperties,\n };\n }\n}\n\nclass ObjectDescribe {\n constructor(dataDescriber, restDescriber) {\n this.dataDescriber = dataDescriber;\n this.restDescriber = restDescriber;\n }\n describeObjectDescribe(ctx) {\n const sortedKeys = Object.keys(this.dataDescriber).sort();\n const props = sortedKeys\n .map((k) => {\n const describer = this.dataDescriber[k];\n return `${k}: ${describer(ctx)}`;\n })\n .join(", ");\n\n const rest = this.restDescriber != null ? `[K in string]: ${this.restDescriber(ctx)}` : null;\n\n const content = [props, rest].filter((it) => it != null && it.length > 0).join(", ");\n return `{ ${content} }`;\n }\n}\n\nclass MappedRecordValidator {\n constructor(keyValidator, valueValidator) {\n this.keyValidator = keyValidator;\n this.valueValidator = valueValidator;\n }\n\n validateMappedRecordValidator(ctx, input) {\n if (typeof input !== "object" || input == null) {\n return false;\n }\n\n for (const k in input) {\n const v = input[k];\n if (!this.keyValidator(ctx, k) || !this.valueValidator(ctx, v)) {\n return false;\n }\n }\n\n return true;\n }\n}\n\nclass MappedRecordParser {\n constructor(keyParser, valueParser) {\n this.keyParser = keyParser;\n this.valueParser = valueParser;\n }\n\n parseMappedRecordParser(ctx, input) {\n const result = {};\n for (const k in input) {\n const parsedKey = this.keyParser(ctx, k);\n const parsedValue = this.valueParser(ctx, input[k]);\n result[parsedKey] = parsedValue;\n }\n return result;\n }\n}\n\nclass MappedRecordSchema {\n constructor(keySchema, valueSchema) {\n this.keySchema = keySchema;\n this.valueSchema = valueSchema;\n }\n\n schemaMappedRecordSchema(ctx) {\n return {\n type: "object",\n additionalProperties: this.valueSchema(ctx),\n propertyNames: this.keySchema(ctx),\n };\n }\n}\n\nclass MappedRecordDescribe {\n constructor(keyDescriber, valueDescriber) {\n this.keyDescriber = keyDescriber;\n this.valueDescriber = valueDescriber;\n }\n describeMappedRecordDescribe(ctx) {\n const k = this.keyDescriber(ctx);\n const v = this.valueDescriber(ctx);\n return `Record<${k}, ${v}>`;\n }\n}\n\nclass MappedRecordReporter {\n constructor(keyValidator, valueValidator, keyReporter, valueReporter) {\n this.keyValidator = keyValidator;\n this.valueValidator = valueValidator;\n this.keyReporter = keyReporter;\n this.valueReporter = valueReporter;\n }\n\n reportMappedRecordReporter(ctx, input) {\n if (typeof input !== "object" || input == null) {\n return buildError(ctx, "expected object", input);\n }\n\n let acc = [];\n for (const k in input) {\n const v = input[k];\n const okKey = this.keyValidator(ctx, k);\n if (!okKey) {\n pushPath(ctx, k);\n const errs = this.keyReporter(ctx, k);\n acc.push(...errs);\n popPath(ctx);\n }\n const okValue = this.valueValidator(ctx, v);\n if (!okValue) {\n pushPath(ctx, k);\n const errs = this.valueReporter(ctx, v);\n acc.push(...errs);\n popPath(ctx);\n }\n }\n return acc;\n }\n}\n\nclass AnyOfDiscriminatedValidator {\n constructor(discriminator, mapping) {\n this.discriminator = discriminator;\n this.mapping = mapping;\n }\n\n validateAnyOfDiscriminatedValidator(ctx, input) {\n if (typeof input !== "object" || input == null) {\n return false;\n }\n const d = input[this.discriminator];\n if (d == null) {\n return false;\n }\n const v = this.mapping[d];\n if (v == null) {\n \n return false;\n }\n\n return v(ctx, input);\n }\n}\n\nclass AnyOfDiscriminatedParser {\n constructor(discriminator, mapping) {\n this.discriminator = discriminator;\n this.mapping = mapping;\n }\n\n parseAnyOfDiscriminatedParser(ctx, input) {\n const parser = this.mapping[input[this.discriminator]];\n if (parser == null) {\n throw new Error(\n "INTERNAL ERROR: Missing parser for discriminator " + JSON.stringify(input[this.discriminator]),\n );\n }\n return {\n ...parser(ctx, input),\n [this.discriminator]: input[this.discriminator],\n };\n }\n}\n\nclass AnyOfDiscriminatedReporter {\n constructor(discriminator, mapping) {\n this.discriminator = discriminator;\n this.mapping = mapping;\n }\n\n reportAnyOfDiscriminatedReporter(ctx, input) {\n if (input == null || typeof input !== "object") {\n return buildError(ctx, "expected object", input);\n }\n\n const d = input[this.discriminator];\n if (d == null) {\n return buildError(ctx, "expected discriminator key " + JSON.stringify(this.discriminator), input);\n }\n const v = this.mapping[d];\n if (v == null) {\n pushPath(ctx, this.discriminator);\n const errs = buildError(\n ctx,\n "expected one of " +\n Object.keys(this.mapping)\n .map((it) => JSON.stringify(it))\n .join(", "),\n d,\n );\n popPath(ctx);\n return errs;\n }\n return v(ctx, input);\n }\n}\n\nclass AnyOfDiscriminatedSchema {\n constructor(vs) {\n this.vs = vs;\n }\n\n schemaAnyOfDiscriminatedSchema(ctx) {\n \n return {\n anyOf: this.vs.map((v) => v(ctx)),\n };\n }\n}\n\nclass AnyOfDiscriminatedDescribe {\n constructor(vs) {\n this.vs = vs;\n }\n\n describeAnyOfDiscriminatedDescribe(ctx) {\n \n return `(${this.vs.map((v) => v(ctx)).join(" | ")})`;\n }\n}\n\nclass ArrayParser {\n constructor(innerParser) {\n this.innerParser = innerParser;\n }\n\n parseArrayParser(ctx, input) {\n return input.map((v) => this.innerParser(ctx, v));\n }\n}\n\nclass ArrayValidator {\n constructor(innerValidator) {\n this.innerValidator = innerValidator;\n }\n\n validateArrayValidator(ctx, input) {\n if (Array.isArray(input)) {\n for (let i = 0; i < input.length; i++) {\n const v = input[i];\n const ok = this.innerValidator(ctx, v);\n if (!ok) {\n return false;\n }\n }\n return true;\n }\n return false;\n }\n}\n\nclass ArrayReporter {\n constructor(innerValidator, innerReporter) {\n this.innerValidator = innerValidator;\n this.innerReporter = innerReporter;\n }\n\n reportArrayReporter(ctx, input) {\n if (!Array.isArray(input)) {\n return buildError(ctx, "expected array", input);\n }\n\n let acc = [];\n for (let i = 0; i < input.length; i++) {\n const ok = this.innerValidator(ctx, input[i]);\n if (!ok) {\n pushPath(ctx, `[${i}]`);\n const v = input[i];\n const arr2 = this.innerReporter(ctx, v);\n acc.push(...arr2);\n popPath(ctx);\n }\n }\n\n return acc;\n }\n}\n\nclass ArraySchema {\n constructor(innerSchema) {\n this.innerSchema = innerSchema;\n }\n\n schemaArraySchema(ctx) {\n pushPath(ctx, "[]");\n const items = this.innerSchema(ctx);\n popPath(ctx);\n return {\n type: "array",\n items,\n };\n }\n}\n\nclass ArrayDescribe {\n constructor(innerDescriber) {\n this.innerDescriber = innerDescriber;\n }\n describeArrayDescribe(ctx) {\n return `Array<${this.innerDescriber(ctx)}>`;\n }\n}\n\nclass AnyOfValidator {\n constructor(vs) {\n this.vs = vs;\n }\n validateAnyOfValidator(ctx, input) {\n for (const v of this.vs) {\n if (v(ctx, input)) {\n return true;\n }\n }\n return false;\n }\n}\nclass AnyOfParser {\n constructor(validators, parsers) {\n this.validators = validators;\n this.parsers = parsers;\n }\n parseAnyOfParser(ctx, input) {\n const items = [];\n for (let i = 0; i < this.validators.length; i++) {\n if (this.validators[i](ctx, input)) {\n items.push(this.parsers[i](ctx, input));\n }\n }\n return deepmerge(...items);\n }\n}\nclass AnyOfReporter {\n constructor(validators, reporters) {\n this.validators = validators;\n this.reporters = reporters;\n }\n reportAnyOfReporter(ctx, input) {\n const acc = [];\n const oldPaths = ctx.path;\n ctx.path = [];\n for (const v of this.reporters) {\n const errors = v(ctx, input);\n acc.push(...errors);\n }\n ctx.path = oldPaths;\n return buildUnionError(ctx, acc, input);\n }\n}\n\nclass AnyOfSchema {\n constructor(schemas) {\n this.schemas = schemas;\n }\n schemaAnyOfSchema(ctx) {\n return {\n anyOf: this.schemas.map((s) => s(ctx)),\n };\n }\n}\n\nclass AnyOfDescribe {\n constructor(describers) {\n this.describers = describers;\n }\n describeAnyOfDescribe(ctx) {\n return `(${this.describers.map((v) => v(ctx)).join(" | ")})`;\n }\n}\n\nclass AllOfValidator {\n constructor(vs) {\n this.vs = vs;\n }\n validateAllOfValidator(ctx, input) {\n for (const v of this.vs) {\n const isObj = typeof input === "object";\n if (!isObj) {\n return false;\n }\n if (!v(ctx, input)) {\n return false;\n }\n }\n return true;\n }\n}\n\nclass AllOfParser {\n constructor(validators, parsers) {\n this.validators = validators;\n this.parsers = parsers;\n }\n parseAllOfParser(ctx, input) {\n let acc = {};\n for (let i = 0; i < this.validators.length; i++) {\n const p = this.parsers[i];\n const parsed = p(ctx, input);\n if (typeof parsed !== "object") {\n throw new Error("INTERNAL ERROR: AllOfParser: Expected object");\n }\n acc = { ...acc, ...parsed };\n }\n return acc;\n }\n}\n\nclass AllOfReporter {\n constructor(validators, reporters) {\n this.validators = validators;\n this.reporters = reporters;\n }\n reportAllOfReporter(ctx, input) {\n const acc = [];\n for (const v of this.reporters) {\n const errors = v(ctx, input);\n acc.push(...errors);\n }\n return acc;\n }\n}\n\nclass AllOfSchema {\n constructor(schemas) {\n this.schemas = schemas;\n }\n schemaAllOfSchema(ctx) {\n return {\n allOf: this.schemas.map((s) => s(ctx)),\n };\n }\n}\n\nclass AllOfDescribe {\n constructor(describers) {\n this.describers = describers;\n }\n describeAllOfDescribe(ctx) {\n return `(${this.describers.map((v) => v(ctx)).join(" & ")})`;\n }\n}\n\nclass TupleValidator {\n constructor(prefix, rest) {\n this.prefix = prefix;\n this.rest = rest;\n }\n validateTupleValidator(ctx, input) {\n if (Array.isArray(input)) {\n let idx = 0;\n for (const prefixVal of this.prefix) {\n if (!prefixVal(ctx, input[idx])) {\n return false;\n }\n idx++;\n }\n const itemVal = this.rest;\n if (itemVal != null) {\n for (let i = idx; i < input.length; i++) {\n if (!itemVal(ctx, input[i])) {\n return false;\n }\n }\n } else {\n if (input.length > idx) {\n return false;\n }\n }\n return true;\n }\n return false;\n }\n}\n\nclass TupleParser {\n constructor(prefix, rest) {\n this.prefix = prefix;\n this.rest = rest;\n }\n parseTupleParser(ctx, input) {\n let idx = 0;\n let acc = [];\n for (const prefixParser of this.prefix) {\n acc.push(prefixParser(ctx, input[idx]));\n idx++;\n }\n if (this.rest != null) {\n for (let i = idx; i < input.length; i++) {\n acc.push(this.rest(ctx, input[i]));\n }\n }\n return acc;\n }\n}\n\nclass TupleReporter {\n constructor(prefixValidator, restValidator, prefixReporter, restReporter) {\n this.prefixValidator = prefixValidator;\n this.restValidator = restValidator;\n this.prefixReporter = prefixReporter;\n this.restReporter = restReporter;\n }\n reportTupleReporter(ctx, input) {\n if (!Array.isArray(input)) {\n return buildError(ctx, "expected tuple", input);\n }\n\n let idx = 0;\n\n let acc = [];\n\n for (const prefixReporter of this.prefixReporter) {\n const ok = this.prefixValidator[idx](ctx, input[idx]);\n if (!ok) {\n pushPath(ctx, `[${idx}]`);\n const errors = prefixReporter(ctx, input[idx]);\n acc.push(...errors);\n popPath(ctx);\n }\n idx++;\n }\n\n const restReporter = this.restReporter;\n if (restReporter != null) {\n for (let i = idx; i < input.length; i++) {\n const ok = this.restValidator(ctx, input[i]);\n if (!ok) {\n pushPath(ctx, `[${i}]`);\n const errors = restReporter(ctx, input[i]);\n acc.push(...errors);\n popPath(ctx);\n }\n }\n }\n\n return acc;\n }\n}\n\nclass TupleSchema {\n constructor(prefix, rest) {\n this.prefix = prefix;\n this.rest = rest;\n }\n\n schemaTupleSchema(ctx) {\n pushPath(ctx, "[]");\n const prefixItems = this.prefix.map((s) => s(ctx));\n const items = this.rest != null ? this.rest(ctx) : false;\n popPath(ctx);\n return {\n type: "array",\n prefixItems,\n items,\n };\n }\n}\n\nclass TupleDescribe {\n constructor(prefix, rest) {\n this.prefix = prefix;\n this.rest = rest;\n }\n describeTupleDescribe(ctx) {\n const prefix = this.prefix.map((d) => d(ctx)).join(", ");\n const rest = this.rest != null ? `...Array<${this.rest(ctx)}>` : null;\n\n const inner = [prefix, rest].filter((it) => it != null && it.length > 0).join(", ");\n return `[${inner}]`;\n }\n}\n', "parser.d.ts": 'import { BuildParserFunction } from "@beff/client";\n\ndeclare const _exports: {\n buildParsers: BuildParserFunction;\n};\n\nexport default _exports;\n' };
|
|
45785
45785
|
|
|
45786
45786
|
// ts-node/bundle-to-disk.ts
|
|
45787
45787
|
var decodersExported = [
|