@beff/cli 0.0.114 → 0.0.115

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @beff/cli
2
2
 
3
+ ## 0.0.115
4
+
5
+ ### Patch Changes
6
+
7
+ - bundle code with lib
8
+
3
9
  ## 0.0.114
4
10
 
5
11
  ### Patch Changes
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 = { "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 NullishRuntype {\n description;\n constructor(description) {\n this.description = description;\n }\n describe(_ctx) {\n return this.description;\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 const inner = parts.join(" | ");\n return `(${inner})`;\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 OptionalField {\n t;\n constructor(t) {\n this.t = t;\n }\n schema(ctx) {\n const inner = this.t.schema(ctx);\n return {\n anyOf: [inner, { type: "null" }]\n };\n }\n validate(ctx, input) {\n if (input == null) {\n return true;\n }\n return this.t.validate(ctx, input);\n }\n parseAfterValidation(ctx, input) {\n if (input == null) {\n return input;\n }\n return this.t.parseAfterValidation(ctx, input);\n }\n reportDecodeError(ctx, input) {\n const acc = [];\n acc.push(...buildError(ctx, "expected nullish value", input));\n return [...acc, ...this.t.reportDecodeError(ctx, input)];\n }\n describe(ctx) {\n return this.t.describe(ctx);\n }\n}\nclass ObjectRuntype {\n properties;\n indexedPropertiesParser;\n constructor(properties, indexedPropertiesParser) {\n this.properties = properties;\n this.indexedPropertiesParser = indexedPropertiesParser;\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 const optionalMark = it instanceof OptionalField ? "?" : "";\n return `${k}${optionalMark}: ${it.describe(ctx)}`;\n }).join(", ");\n const indexPropsParats = this.indexedPropertiesParser.map(({ key, value }) => {\n return `[K in ${key.describe(ctx)}]: ${value.describe(ctx)}`;\n });\n const rest = indexPropsParats.join(", ");\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 const item = this.properties[k];\n properties[k] = item.schema(ctx);\n popPath(ctx);\n }\n const required = Object.keys(this.properties);\n const base = {\n type: "object",\n properties,\n required\n };\n const indexSchemas = this.indexedPropertiesParser.map(({ key, value }) => {\n pushPath(ctx, "[key]");\n const keySchema = key.schema(ctx);\n popPath(ctx);\n pushPath(ctx, "[value]");\n const valueSchema = value.schema(ctx);\n popPath(ctx);\n return {\n type: "object",\n additionalProperties: valueSchema,\n propertyNames: keySchema\n };\n });\n if (indexSchemas.length === 0) {\n return { ...base, additionalProperties: false };\n }\n return {\n allOf: [base, ...indexSchemas]\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.indexedPropertiesParser.length > 0) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n for (const k of extraKeys) {\n let isValid = false;\n for (const p of this.indexedPropertiesParser) {\n if (!p.key.validate(ctx, k)) {\n continue;\n }\n const v = input[k];\n if (!p.value.validate(ctx, v)) {\n continue;\n }\n isValid = true;\n break;\n }\n if (!isValid) {\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.indexedPropertiesParser.length > 0) {\n for (const p of this.indexedPropertiesParser) {\n const isValid = p.key.validate(ctx, k) && p.value.validate(ctx, v);\n if (isValid) {\n const itemParsed = p.value.parseAfterValidation(ctx, v);\n const keyParsed = p.key.parseAfterValidation(ctx, k);\n acc[keyParsed] = itemParsed;\n }\n }\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.indexedPropertiesParser.length > 0) {\n const inputKeys = Object.keys(input);\n const extraKeys = inputKeys.filter((k) => !configKeys.includes(k));\n for (const k of extraKeys) {\n for (const p of this.indexedPropertiesParser) {\n const keyOk = p.key.validate(ctx, k);\n const valueOk = p.value.validate(ctx, input[k]);\n const ok = keyOk && valueOk;\n if (!ok) {\n pushPath(ctx, k);\n if (!keyOk) {\n const keyReported = p.key.reportDecodeError(ctx, k);\n acc.push(...keyReported);\n }\n if (!valueOk) {\n const valueReported = p.value.reportDecodeError(ctx, input[k]);\n acc.push(...valueReported);\n }\n popPath(ctx);\n }\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' };
45784
+ var bundle_default = { "codegen-v2.js": '"use strict";\n\nimport {\n TypeofRuntype,\n AnyRuntype,\n NullishRuntype,\n NeverRuntype,\n ConstRuntype,\n RegexRuntype,\n DateRuntype,\n BigIntRuntype,\n StringWithFormatRuntype,\n NumberWithFormatRuntype,\n AnyOfConstsRuntype,\n TupleRuntype,\n AllOfRuntype,\n AnyOfRuntype,\n ArrayRuntype,\n AnyOfDiscriminatedRuntype,\n ObjectRuntype,\n OptionalFieldRuntype,\n registerStringFormatter,\n registerNumberFormatter,\n buildParserFromRuntype,\n} from "@beff/client/codegen-v2";\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 hash(ctx) {\n const name = this.refName;\n const to = namedRuntypes[this.refName];\n if (ctx.seen[name]) {\n return generateHashFromString(name);\n }\n ctx.seen[name] = true;\n var tmp = to.hash(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}\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 it = buildParserFromRuntype(buildParsersInput[k], k, false);\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
45787
  var esmTag = (mod) => {
@@ -45795,25 +45795,19 @@ Object.defineProperty(exports, "__esModule", {
45795
45795
  return "";
45796
45796
  };
45797
45797
  var exportCode = (mod) => mod === "esm" ? "export default" : "exports.default =";
45798
- var V2_ESM_IMPORT = `import {
45799
- printErrors
45800
- } from "@beff/client";`;
45801
- var V2_CJS_IMPORT = `const { printErrors } = require("@beff/client");`;
45802
45798
  var finalizeParserV2File = (wasmCode, mod, stringFormats, numberFormats) => {
45803
45799
  const exportedItems = ["buildParsers"].join(", ");
45804
45800
  const exports2 = [exportCode(mod), `{ ${exportedItems} };`].join(" ");
45805
45801
  const stringFormatsCode = `const RequiredStringFormats = ${JSON.stringify(stringFormats)};`;
45806
45802
  const numberFormatsCode = `const RequiredNumberFormats = ${JSON.stringify(numberFormats)};`;
45807
- let genV2 = bundle_default["codegen-v2.js"].replace(V2_ESM_IMPORT, "");
45808
- let zod_import = `import { z } from "zod";`;
45809
- if (mod == "cjs") {
45810
- zod_import = `const { z } = require("zod");`;
45803
+ let genV2 = bundle_default["codegen-v2.js"];
45804
+ if (mod === "cjs") {
45805
+ genV2 = genV2.replace("import {", "const {").replace('} from "@beff/client/codegen-v2";', '} = require("@beff/client/codegen-v2");');
45811
45806
  }
45812
45807
  return [
45808
+ //
45813
45809
  "//@ts-nocheck",
45814
45810
  esmTag(mod),
45815
- zod_import,
45816
- mod === "esm" ? V2_ESM_IMPORT : V2_CJS_IMPORT,
45817
45811
  genV2,
45818
45812
  stringFormatsCode,
45819
45813
  numberFormatsCode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beff/cli",
3
- "version": "0.0.114",
3
+ "version": "0.0.115",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "beff": "./bin/index.js"
Binary file