schema-truth 0.8.13 → 0.8.14

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.
@@ -1,4 +1,4 @@
1
- import { St as normalizeTypes, c as sanitizeSchema, xt as makeSafeKey } from "./helper-ByoddrXL.js";
1
+ import { Dt as normalizeTypes, Et as makeSafeKey, c as sanitizeSchema } from "./helper-DpwdwX03.js";
2
2
  // src/generator/ajv/integer.ts
3
3
  /**
4
4
  * Reconstruct a draft-07 integer schema. `minimum` is the only numeric keyword
package/dist/ajv.js CHANGED
@@ -1 +1 @@
1
- export { t as schemaToAjv } from "./ajv-DjHkU79T.js";
1
+ export { t as schemaToAjv } from "./ajv-BzXa3loS.js";
@@ -1,23 +1,27 @@
1
- import { A as unionPrimitiveTypes, Bn as UNSAFE_GENERATED_MARKER, Bt as isDeepLocalPointer, C as isNullMatchedFirst, Cn as NUMBER_RANGES, Ct as resolveOpenAPIRef, D as ownProperties, E as numberWirePattern, F as regexSource, G as planDocument, H as definitionsOf, Ht as isNullTypeMember, J as schemaNamer, M as wireNullText, Mn as QUOTE_OR_BACKSLASH_PATTERN, N as wireNumericKind, Nt as hasFixedItemCount, O as stringboolPattern, P as formatPattern, Pt as hasFixedLength, Q as enumWithoutWrappedNull, Qt as isStringWireLocation, Rt as isArktypeDefinition, S as integerWirePattern, St as normalizeTypes, T as isPrimitiveUnion, U as emitOptionsOf, Ut as isNullable, W as missingDefinitionComment, Wt as isObjectPrototypeProperty, Xt as isSchemaObject, Y as discriminatedMembers, Yt as isRootRef, Zt as isShapelessMember, _ as valueListLiteral, at as callbackType, bt as issueMessageExpression, c as sanitizeSchema, d as hasParameterSerialization, dt as foldAllOfMembers, et as itemsSchemaOf, f as parameterReaders, ft as isKeywordOnlyMember, g as notPredicate, h as isBigintFormat, hn as INTEGER_TEXT_PATTERN, i as isEvaluatedKeyExpression, it as callbackReturn, j as wireArrayOnce, jt as hasCombinator, k as stringboolTruthyPattern, ln as DEFINITION_REF_PREFIXES, lt as constraintMessage, m as withoutParameterSerialization, mt as regexLiteral, nt as arktypeUnionLimit, on as DEFAULT_ROOT_NAME, ot as dslUnionMembers, p as propertyEmitOptions, q as rootNameOf, qt as isQuoted, r as evaluatedProperties, rt as arktypeWrap, st as findCodeExtensionKeysInSchema, tt as arktypePreprocess, u as withPolymorphicBases, ut as constraintPredicate, v as hoistNestedRefs, w as isNullTextRead, x as impliedWireType, xt as makeSafeKey, zt as isComposite } from "./helper-ByoddrXL.js";
2
- import { n as bigintCall, r as bigintLiteral, t as bigintBounds } from "./bigint-CkHij6xv.js";
1
+ import { A as unionPrimitiveTypes, C as isNullMatchedFirst, D as ownProperties, Dt as normalizeTypes, E as numberWirePattern, Et as makeSafeKey, F as regexSource, G as planDocument, Gn as UNSAFE_GENERATED_MARKER, Gt as isDeepLocalPointer, H as definitionsOf, It as hasCombinator, J as schemaNamer, Jt as isNullable, Ln as QUOTE_OR_BACKSLASH_PATTERN, M as wireNullText, N as wireNumericKind, O as stringboolPattern, On as NUMBER_RANGES, Ot as resolveOpenAPIRef, P as formatPattern, Q as enumWithoutWrappedNull, Qt as isQuoted, Rt as hasFixedItemCount, S as integerWirePattern, T as isPrimitiveUnion, Tt as issueMessageExpression, U as emitOptionsOf, Ut as isArktypeDefinition, W as missingDefinitionComment, Wt as isComposite, Y as discriminatedMembers, Yt as isObjectPrototypeProperty, _ as valueListLiteral, at as arktypePreprocess, bn as INTEGER_TEXT_PATTERN, c as sanitizeSchema, ct as callbackReturn, d as hasParameterSerialization, dn as DEFAULT_ROOT_NAME, dt as findCodeExtensionKeysInSchema, en as isRootRef, et as itemsSchemaOf, f as parameterReaders, g as notPredicate, gt as isKeywordOnlyMember, h as isBigintFormat, ht as foldAllOfMembers, i as isEvaluatedKeyExpression, it as bigintValueLiteral, j as wireArrayOnce, k as stringboolTruthyPattern, lt as callbackType, m as withoutParameterSerialization, mn as DEFINITION_REF_PREFIXES, mt as constraintPredicate, nn as isShapelessMember, nt as bigintCall, ot as arktypeUnionLimit, p as propertyEmitOptions, pt as constraintMessage, q as rootNameOf, qt as isNullTypeMember, r as evaluatedProperties, rn as isStringWireLocation, rt as bigintLiteral, st as arktypeWrap, tn as isSchemaObject, tt as bigintBounds, u as withPolymorphicBases, ut as dslUnionMembers, v as hoistNestedRefs, vt as regexLiteral, w as isNullTextRead, x as impliedWireType, zt as hasFixedLength } from "./helper-DpwdwX03.js";
3
2
  // src/generator/arktype/number.ts
4
- /** The comparators of a numeric node: `>= 1`, `< 5`, `% 2`. */
3
+ /**
4
+ * The comparators of a numeric node: `>= 1`, `< 5`, `% 2`. A 2020-12 numeric
5
+ * `exclusiveMinimum` beside `minimum` is a bound of its own, and only the stricter of the
6
+ * two is emitted: it says as much as both, and ArkType throws on a definition whose
7
+ * bounds leave no value (`number >= 0 & number > 10 & number <= 5`) when it is loaded.
8
+ */
5
9
  function numericConstraints(schema) {
6
10
  return [
7
- schema.minimum !== void 0 ? {
8
- op: schema.exclusiveMinimum === true ? ">" : ">=",
9
- value: String(schema.minimum)
10
- } : typeof schema.exclusiveMinimum === "number" ? {
11
+ typeof schema.exclusiveMinimum === "number" && (schema.minimum === void 0 || schema.exclusiveMinimum >= schema.minimum) ? {
11
12
  op: ">",
12
13
  value: String(schema.exclusiveMinimum)
13
- } : void 0,
14
- schema.maximum !== void 0 ? {
15
- op: schema.exclusiveMaximum === true ? "<" : "<=",
16
- value: String(schema.maximum)
17
- } : typeof schema.exclusiveMaximum === "number" ? {
14
+ } : schema.minimum === void 0 ? void 0 : {
15
+ op: schema.exclusiveMinimum === true ? ">" : ">=",
16
+ value: String(schema.minimum)
17
+ },
18
+ typeof schema.exclusiveMaximum === "number" && (schema.maximum === void 0 || schema.exclusiveMaximum <= schema.maximum) ? {
18
19
  op: "<",
19
20
  value: String(schema.exclusiveMaximum)
20
- } : void 0,
21
+ } : schema.maximum === void 0 ? void 0 : {
22
+ op: schema.exclusiveMaximum === true ? "<" : "<=",
23
+ value: String(schema.maximum)
24
+ },
21
25
  schema.multipleOf !== void 0 ? {
22
26
  op: "%",
23
27
  value: String(schema.multipleOf)
@@ -189,7 +193,7 @@ function integer(schema, options) {
189
193
  function lit(v, isBigint) {
190
194
  if (v === null) return "null";
191
195
  if (typeof v === "string") return `'${v}'`;
192
- if (typeof v === "number" && isBigint) return `${v}n`;
196
+ if (typeof v === "number" && isBigint) return bigintValueLiteral(v);
193
197
  if (typeof v === "number" || typeof v === "boolean") return String(v);
194
198
  return JSON.stringify(v) ?? "null";
195
199
  }
@@ -524,7 +528,7 @@ function keywordConstraint(schema) {
524
528
  }
525
529
  function formatConst(value, isBigint) {
526
530
  if (typeof value === "string") return `"'${value}'"`;
527
- if (typeof value === "number" && isBigint) return `"${value}n"`;
531
+ if (typeof value === "number" && isBigint) return `"${bigintValueLiteral(value)}"`;
528
532
  if (typeof value === "number" || typeof value === "boolean") return `"${String(value)}"`;
529
533
  if (value !== null && typeof value === "object") return "\"unknown\"";
530
534
  return `"${JSON.stringify(value) ?? "null"}"`;
package/dist/arktype.js CHANGED
@@ -1 +1 @@
1
- export { t as schemaToArktype } from "./arktype-CbrtmKWv.js";
1
+ export { t as schemaToArktype } from "./arktype-o5UiPNHq.js";
package/dist/cli/ajv.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { t as schemaToAjv } from "../ajv-DjHkU79T.js";
3
- import { n as version, t as cli } from "../cli-D_Sr9uXp.js";
2
+ import { t as schemaToAjv } from "../ajv-BzXa3loS.js";
3
+ import { n as version, t as cli } from "../cli-6GScU3W_.js";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
6
6
  import * as NodeServices from "@effect/platform-node/NodeServices";
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { t as schemaToArktype } from "../arktype-CbrtmKWv.js";
3
- import { n as version, t as cli } from "../cli-D_Sr9uXp.js";
2
+ import { t as schemaToArktype } from "../arktype-o5UiPNHq.js";
3
+ import { n as version, t as cli } from "../cli-6GScU3W_.js";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
6
6
  import * as NodeServices from "@effect/platform-node/NodeServices";
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { t as schemaToEffect } from "../effect-BqLfzMgM.js";
3
- import { n as version, t as cli } from "../cli-D_Sr9uXp.js";
2
+ import { t as schemaToEffect } from "../effect-CYQf9Lw6.js";
3
+ import { n as version, t as cli } from "../cli-6GScU3W_.js";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
6
6
  import * as NodeServices from "@effect/platform-node/NodeServices";
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { t as schemaToTypebox } from "../typebox-DdFjzmqK.js";
3
- import { n as version, t as cli } from "../cli-D_Sr9uXp.js";
2
+ import { t as schemaToTypebox } from "../typebox-2MLHaziq.js";
3
+ import { n as version, t as cli } from "../cli-6GScU3W_.js";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
6
6
  import * as NodeServices from "@effect/platform-node/NodeServices";
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { t as schemaToValibot } from "../valibot-Bz-mcsf9.js";
3
- import { n as version, t as cli } from "../cli-D_Sr9uXp.js";
2
+ import { t as schemaToValibot } from "../valibot-CRyUoeJj.js";
3
+ import { n as version, t as cli } from "../cli-6GScU3W_.js";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
6
6
  import * as NodeServices from "@effect/platform-node/NodeServices";
package/dist/cli/yup.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { t as schemaToYup } from "../yup-rbHu00QS.js";
3
- import { n as version, t as cli } from "../cli-D_Sr9uXp.js";
2
+ import { t as schemaToYup } from "../yup-BqKfyIcd.js";
3
+ import { n as version, t as cli } from "../cli-6GScU3W_.js";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
6
6
  import * as NodeServices from "@effect/platform-node/NodeServices";
package/dist/cli/zod.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { t as schemaToZod } from "../zod-Cvj9YJY_.js";
3
- import { n as version, t as cli } from "../cli-D_Sr9uXp.js";
2
+ import { t as schemaToZod } from "../zod-xz1vNbs5.js";
3
+ import { n as version, t as cli } from "../cli-6GScU3W_.js";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
6
6
  import * as NodeServices from "@effect/platform-node/NodeServices";
@@ -1,4 +1,4 @@
1
- import { Jt as isRecord } from "./helper-ByoddrXL.js";
1
+ import { $t as isRecord } from "./helper-DpwdwX03.js";
2
2
  import { i as fmt, n as parseSchemaFile } from "./parser-RBrkz7ZL.js";
3
3
  import * as Effect from "effect/Effect";
4
4
  import path from "node:path";
@@ -9,7 +9,7 @@ import * as Stdio from "effect/Stdio";
9
9
  import "@effect/platform-node/NodeFileSystem";
10
10
  import * as FileSystem from "effect/FileSystem";
11
11
  // package.json
12
- var version = "0.8.13";
12
+ var version = "0.8.14";
13
13
  // src/file/index.ts
14
14
  /** Creates the directory and its parents. An existing directory is not an error. */
15
15
  function mkdir(dir) {
@@ -1,5 +1,4 @@
1
- import { A as unionPrimitiveTypes, Bn as UNSAFE_GENERATED_MARKER, Cn as NUMBER_RANGES, D as ownProperties, E as numberWirePattern, F as regexSource, G as planDocument, H as definitionsOf, Ht as isNullTypeMember, J as schemaNamer, K as renderDefinitions, L as deepEqualExpression, Lt as hasType, Mt as hasConditional, N as wireNumericKind, Nt as hasFixedItemCount, O as stringboolPattern, P as formatPattern, Pt as hasFixedLength, Q as enumWithoutWrappedNull, Qt as isStringWireLocation, R as jsLiteral, S as integerWirePattern, St as normalizeTypes, T as isPrimitiveUnion, U as emitOptionsOf, Ut as isNullable, Vt as isDefaultOnlyMember, Wt as isObjectPrototypeProperty, Xt as isSchemaObject, Y as discriminatedMembers, Z as hasRootSelfReference, Zt as isShapelessMember, _ as valueListLiteral, _t as effectErrorPart, b as effectWrap, c as sanitizeSchema, d as hasParameterSerialization, dt as foldAllOfMembers, et as itemsSchemaOf, f as parameterReaders, ft as isKeywordOnlyMember, g as notPredicate, gt as effectError, h as isBigintFormat, hn as INTEGER_TEXT_PATTERN, i as isEvaluatedKeyExpression, j as wireArrayOnce, jt as hasCombinator, k as stringboolTruthyPattern, l as refTarget, lt as constraintMessage, m as withoutParameterSerialization, mt as regexLiteral, on as DEFAULT_ROOT_NAME, p as propertyEmitOptions, q as rootNameOf, r as evaluatedProperties, s as typeDeclaration, st as findCodeExtensionKeysInSchema, u as withPolymorphicBases, ut as constraintPredicate, v as hoistNestedRefs, vt as effectMessage, w as isNullTextRead, x as impliedWireType, xt as makeSafeKey, y as effectPreprocess, zt as isComposite } from "./helper-ByoddrXL.js";
2
- import { n as bigintCall, r as bigintLiteral, t as bigintBounds } from "./bigint-CkHij6xv.js";
1
+ import { A as unionPrimitiveTypes, Ct as effectMessage, D as ownProperties, Dt as normalizeTypes, E as numberWirePattern, Et as makeSafeKey, F as regexSource, G as planDocument, Gn as UNSAFE_GENERATED_MARKER, H as definitionsOf, Ht as hasType, It as hasCombinator, J as schemaNamer, Jt as isNullable, K as renderDefinitions, Kt as isDefaultOnlyMember, L as deepEqualExpression, Lt as hasConditional, N as wireNumericKind, O as stringboolPattern, On as NUMBER_RANGES, P as formatPattern, Q as enumWithoutWrappedNull, R as jsLiteral, Rt as hasFixedItemCount, S as integerWirePattern, St as effectErrorPart, T as isPrimitiveUnion, U as emitOptionsOf, Wt as isComposite, Y as discriminatedMembers, Yt as isObjectPrototypeProperty, Z as hasRootSelfReference, _ as valueListLiteral, b as effectWrap, bn as INTEGER_TEXT_PATTERN, c as sanitizeSchema, d as hasParameterSerialization, dn as DEFAULT_ROOT_NAME, dt as findCodeExtensionKeysInSchema, et as itemsSchemaOf, f as parameterReaders, g as notPredicate, gt as isKeywordOnlyMember, h as isBigintFormat, ht as foldAllOfMembers, i as isEvaluatedKeyExpression, it as bigintValueLiteral, j as wireArrayOnce, k as stringboolTruthyPattern, l as refTarget, m as withoutParameterSerialization, mt as constraintPredicate, nn as isShapelessMember, nt as bigintCall, p as propertyEmitOptions, pt as constraintMessage, q as rootNameOf, qt as isNullTypeMember, r as evaluatedProperties, rn as isStringWireLocation, rt as bigintLiteral, s as typeDeclaration, tn as isSchemaObject, tt as bigintBounds, u as withPolymorphicBases, v as hoistNestedRefs, vt as regexLiteral, w as isNullTextRead, x as impliedWireType, xt as effectError, y as effectPreprocess, zt as hasFixedLength } from "./helper-DpwdwX03.js";
3
2
  // src/generator/effect/number.ts
4
3
  /** The bound and `multipleOf` checks of a numeric node. */
5
4
  function numberChecks(schema, lit = (n) => `${n}`, suffix = "") {
@@ -16,12 +15,12 @@ function numberChecks(schema, lit = (n) => `${n}`, suffix = "") {
16
15
  return [
17
16
  (() => {
18
17
  if (schema.minimum !== void 0) return schema.exclusiveMinimum === true ? `Schema.isGreaterThan${suffix}(${lit(schema.minimum)}${exMinErrorPart})` : `Schema.isGreaterThanOrEqualTo${suffix}(${lit(schema.minimum)}${minErrorPart})`;
19
- if (typeof schema.exclusiveMinimum === "number") return `Schema.isGreaterThan${suffix}(${lit(schema.exclusiveMinimum)}${exMinErrorPart})`;
20
18
  })(),
19
+ typeof schema.exclusiveMinimum === "number" ? `Schema.isGreaterThan${suffix}(${lit(schema.exclusiveMinimum)}${exMinErrorPart})` : void 0,
21
20
  (() => {
22
21
  if (schema.maximum !== void 0) return schema.exclusiveMaximum === true ? `Schema.isLessThan${suffix}(${lit(schema.maximum)}${exMaxErrorPart})` : `Schema.isLessThanOrEqualTo${suffix}(${lit(schema.maximum)}${maxErrorPart})`;
23
- if (typeof schema.exclusiveMaximum === "number") return `Schema.isLessThan${suffix}(${lit(schema.exclusiveMaximum)}${exMaxErrorPart})`;
24
22
  })(),
23
+ typeof schema.exclusiveMaximum === "number" ? `Schema.isLessThan${suffix}(${lit(schema.exclusiveMaximum)}${exMaxErrorPart})` : void 0,
25
24
  schema.multipleOf === void 0 ? void 0 : suffix === "BigInt" ? `Schema.makeFilter((input)=>input%${lit(schema.multipleOf)}===0n${multipleOfErrorPart})` : `Schema.isMultipleOf(${lit(schema.multipleOf)}${multipleOfErrorPart})`
26
25
  ].filter((v) => v !== void 0);
27
26
  }
@@ -93,7 +92,7 @@ function integer(schema, options) {
93
92
  function literal(v, isBigint) {
94
93
  if (v === null) return "null";
95
94
  if (typeof v === "string") return `"${v}"`;
96
- if (typeof v === "number" && isBigint) return `${v}n`;
95
+ if (typeof v === "number" && isBigint) return bigintValueLiteral(v);
97
96
  if (typeof v === "number" || typeof v === "boolean") return String(v);
98
97
  return JSON.stringify(v) ?? "null";
99
98
  }
@@ -548,7 +547,7 @@ function node(schema, rootName, isEffect, options) {
548
547
  }
549
548
  if (schema.const !== void 0) {
550
549
  const constMessage = schema["x-const-message"] ?? schema["x-error-message"];
551
- const literalCode = typeof schema.const === "number" && isInt64(schema) ? `Schema.Literal(${schema.const}n)` : isComposite(schema.const) ? deepEqualSchema([schema.const]) : `Schema.Literal(${JSON.stringify(schema.const)})`;
550
+ const literalCode = typeof schema.const === "number" && isInt64(schema) ? `Schema.Literal(${bigintValueLiteral(schema.const)})` : isComposite(schema.const) ? deepEqualSchema([schema.const]) : `Schema.Literal(${JSON.stringify(schema.const)})`;
552
551
  const withMessage = constMessage ? `${literalCode}.annotate(${effectError(constMessage)})` : literalCode;
553
552
  const input = literalInput([schema.const]);
554
553
  return effectWrap$1(input ? `${input}.pipe(Schema.decodeTo(${withMessage}))` : withMessage, schema);
package/dist/effect.js CHANGED
@@ -1 +1 @@
1
- export { t as schemaToEffect } from "./effect-BqLfzMgM.js";
1
+ export { t as schemaToEffect } from "./effect-CYQf9Lw6.js";
@@ -1725,6 +1725,127 @@ function arktypeWrap(arktypeStr, schema, options) {
1725
1725
  if (inScope && isDefinition(withCodeExts)) return `[${withCodeExts},"@",${text}]`;
1726
1726
  return `${isDefinition(withCodeExts) ? `type(${withCodeExts})` : withCodeExts}.describe(${text})`;
1727
1727
  }
1728
+ // src/helper/bigint.ts
1729
+ /** A bigint literal, `5n`, spelled in digits however the number prints. */
1730
+ function bigintLiteral(n) {
1731
+ return `${BigInt(n)}n`;
1732
+ }
1733
+ /**
1734
+ * A schema value (a `default`, an `enum` member) as the literal of a bigint schema: `1e21`
1735
+ * is `1000000000000000000000n`, not `1e+21n`, which does not parse. A fractional or
1736
+ * non-finite number is no bigint (`BigInt(1.5)` throws) and stays a number literal, which
1737
+ * no bigint equals.
1738
+ */
1739
+ function bigintValueLiteral(n) {
1740
+ return Number.isInteger(n) ? bigintLiteral(n) : String(n);
1741
+ }
1742
+ /**
1743
+ * A `BigInt(5)` call, the spelling `format: bigint` has always used. A divisor a number
1744
+ * cannot hold exactly is written as a literal, `12345678901234567n`, which keeps every digit.
1745
+ */
1746
+ function bigintCall(n) {
1747
+ return typeof n === "bigint" ? `${n}n` : `BigInt(${n})`;
1748
+ }
1749
+ /**
1750
+ * A bigint check takes an integer, but a schema's bound can be fractional: `BigInt(0.5)`
1751
+ * throws a `RangeError` and `0.5n` does not parse. A fractional bound is rounded to the
1752
+ * integer that admits the same bigints: an inclusive minimum and an exclusive maximum
1753
+ * round up, an inclusive maximum and an exclusive minimum round down. A non-finite bound
1754
+ * (a YAML `.inf`) is left out; `sanitizeSchema` drops it before the generator anyway.
1755
+ */
1756
+ function bigintBound(value, round) {
1757
+ return value !== void 0 && Number.isFinite(value) ? Math[round](value) : void 0;
1758
+ }
1759
+ /**
1760
+ * The positive integer divisor a bigint `multipleOf` check can use. An integer is taken as
1761
+ * it is (`BigInt(value)` is exact for any integer a number holds), and a negative one by its
1762
+ * absolute value, which has the same multiples. A bigint `x` is a multiple of `p / q` (in
1763
+ * lowest terms) exactly when it is a multiple of `p`, so a fraction reduces to its
1764
+ * numerator: 2.5 is 5/2 and becomes `5`. The fraction is read from the number's shortest
1765
+ * decimal spelling. Zero or a non-finite divisor has no such integer and is left out (a
1766
+ * bigint `% 0n` throws). A reduced divisor a number cannot hold exactly stays a bigint.
1767
+ */
1768
+ function bigintDivisor(value) {
1769
+ if (typeof value !== "number" || !Number.isFinite(value) || value === 0) return void 0;
1770
+ const magnitude = Math.abs(value);
1771
+ if (Number.isInteger(magnitude)) return magnitude;
1772
+ const match = /^(\d+)(?:\.(\d+))?(?:e-(\d+))?$/.exec(String(magnitude));
1773
+ if (!match) return void 0;
1774
+ const [, whole = "", fraction = "", exponent = "0"] = match;
1775
+ const scale = fraction.length + Number(exponent);
1776
+ const numerator = BigInt(whole + fraction);
1777
+ let [a, b] = [numerator, 10n ** BigInt(scale)];
1778
+ while (b !== 0n) [a, b] = [b, a % b];
1779
+ const divisor = numerator / a;
1780
+ return BigInt(Number(divisor)) === divisor ? Number(divisor) : divisor;
1781
+ }
1782
+ /**
1783
+ * The schema with its bounds and `multipleOf` made integers a bigint check can take: see
1784
+ * {@link bigintBound} and {@link bigintDivisor}. A bound or divisor that has no such
1785
+ * integer is left out, together with the draft-04 boolean or the message that belongs to it.
1786
+ */
1787
+ function bigintBounds(schema) {
1788
+ const { minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, "x-multipleOf-message": multipleOfMessage, ...rest } = schema;
1789
+ const isExclusiveMin = exclusiveMinimum === true;
1790
+ const isExclusiveMax = exclusiveMaximum === true;
1791
+ const min = bigintBound(minimum, isExclusiveMin ? "floor" : "ceil");
1792
+ const max = bigintBound(maximum, isExclusiveMax ? "ceil" : "floor");
1793
+ const exMin = typeof exclusiveMinimum === "number" ? bigintBound(exclusiveMinimum, "floor") : min !== void 0 ? exclusiveMinimum : void 0;
1794
+ const exMax = typeof exclusiveMaximum === "number" ? bigintBound(exclusiveMaximum, "ceil") : max !== void 0 ? exclusiveMaximum : void 0;
1795
+ const divisor = bigintDivisor(multipleOf);
1796
+ return {
1797
+ ...rest,
1798
+ ...min !== void 0 && { minimum: min },
1799
+ ...max !== void 0 && { maximum: max },
1800
+ ...exMin !== void 0 && { exclusiveMinimum: exMin },
1801
+ ...exMax !== void 0 && { exclusiveMaximum: exMax },
1802
+ ...divisor !== void 0 && { multipleOf: divisor },
1803
+ ...divisor !== void 0 && multipleOfMessage !== void 0 && { "x-multipleOf-message": multipleOfMessage }
1804
+ };
1805
+ }
1806
+ /**
1807
+ * Whether a bigint-format node is emitted as bigints. An `enum` or `const` is spelled with
1808
+ * bigint literals for `int64` / `uint64` and with number literals for `format: bigint`;
1809
+ * any other node is a bigint schema only as an `integer` (a `number` with the format is a
1810
+ * plain number schema).
1811
+ */
1812
+ function isBigintSchema(node) {
1813
+ if (node.enum !== void 0 || node.const !== void 0) return node.format !== "bigint";
1814
+ return (node.type === void 0 ? [] : [node.type].flat()).includes("integer");
1815
+ }
1816
+ /**
1817
+ * Whether a default can be written for a node of the given bigint format: a fraction has
1818
+ * no bigint spelling, and `BigInt(1.5)` would throw as the generated module loads.
1819
+ */
1820
+ function isWritableBigintDefault(value, format) {
1821
+ return typeof value !== "number" || format === void 0 || Number.isInteger(value);
1822
+ }
1823
+ /**
1824
+ * The bigint `format` (`int64`, `uint64` or `bigint`) a node's values have: its own, or the
1825
+ * one on the definition its `$ref` names, on an `allOf` member or on every non-null member
1826
+ * of a union (the first one's), so a `default` beside a
1827
+ * `$ref` is written as the bigint the target holds. `holdsBigint` narrows which nodes count,
1828
+ * for a target that spells some of them (an `enum`) with numbers. A reference already being
1829
+ * read ends the search, as a cycle does.
1830
+ */
1831
+ function bigintFormatOf(schema, definitions, holdsBigint = () => true) {
1832
+ const search = (node, reading) => {
1833
+ const { format } = node;
1834
+ if ((format === "int64" || format === "uint64" || format === "bigint") && holdsBigint(node)) return format;
1835
+ if (node.$ref !== void 0 && !reading.has(node.$ref)) {
1836
+ const target = definitionOf$1(node.$ref, definitions);
1837
+ const found = target === void 0 ? void 0 : search(target, /* @__PURE__ */ new Set([...reading, node.$ref]));
1838
+ if (found !== void 0) return found;
1839
+ }
1840
+ for (const member of node.allOf ?? []) {
1841
+ const found = search(member, reading);
1842
+ if (found !== void 0) return found;
1843
+ }
1844
+ const [first, ...rest] = (node.anyOf ?? node.oneOf ?? []).filter((member) => member.type !== "null").map((member) => search(member, reading));
1845
+ return first !== void 0 && rest.every((found) => found !== void 0) ? first : void 0;
1846
+ };
1847
+ return search(schema, /* @__PURE__ */ new Set());
1848
+ }
1728
1849
  // src/helper/schema.ts
1729
1850
  /** `definitions` and `$defs` read as one map, `$defs` winning on a shared name. */
1730
1851
  function collectDefinitions(schema) {
@@ -2080,6 +2201,7 @@ function typeboxDefaultOpt(schema, stringWire = false, definitions) {
2080
2201
  const result = coerceDefault(schema, schema.default, definitions);
2081
2202
  if (!result.keep) return [];
2082
2203
  const value = stringWire ? String(result.value) : result.value;
2204
+ if (typeof value === "number" && bigintFormatOf(schema, definitions, isBigintSchema) === "bigint") return Number.isInteger(value) ? [`default:${bigintLiteral(value)}`] : [];
2083
2205
  return [`default:${typeof value === "boolean" || typeof value === "number" ? `${value}` : JSON.stringify(value)}`];
2084
2206
  }
2085
2207
  /**
@@ -2317,10 +2439,10 @@ function effectPreprocess(readers, inner) {
2317
2439
  return `Schema.Unknown.pipe(${readers.map((reader) => `Schema.decodeTo(Schema.Unknown,SchemaTransformation.transform<unknown,unknown>({decode:${reader},encode:(output)=>output}))`).join(",")},Schema.decodeTo(${inner}))`;
2318
2440
  }
2319
2441
  /** A default as the Effect literal of the schema's decoded type: a bigint for a 64-bit integer. */
2320
- function defaultLiteral$1(schema, value) {
2442
+ function defaultLiteral$1(format, value) {
2321
2443
  if (typeof value === "number") {
2322
- if (schema.format === "int64" || schema.format === "uint64") return `${value}n`;
2323
- if (schema.format === "bigint") return `BigInt(${value})`;
2444
+ if (format === "int64" || format === "uint64") return bigintValueLiteral(value);
2445
+ if (format === "bigint") return `BigInt(${value})`;
2324
2446
  }
2325
2447
  return jsLiteral(value);
2326
2448
  }
@@ -2354,7 +2476,8 @@ function effectWrap(effectStr, schema, options) {
2354
2476
  const withCodeExts = codeChain.length === 0 ? withBrand : `${withBrand}${codeChain.join("")}`;
2355
2477
  const defaultResult = schema.default !== void 0 ? coerceDefault(schema, schema.default, options?.definitions) : void 0;
2356
2478
  const decodingDefault = options?.stringWire === true ? "Schema.withDecodingDefaultType" : "Schema.withDecodingDefault";
2357
- const withDefault = defaultResult?.keep ? `${withCodeExts}.pipe(${decodingDefault}(Effect.succeed(${defaultLiteral$1(schema, defaultResult.value)})))` : withCodeExts;
2479
+ const defaultFormat = typeof defaultResult?.value === "number" ? bigintFormatOf(schema, options?.definitions, isBigintSchema) : void 0;
2480
+ const withDefault = defaultResult?.keep === true && isWritableBigintDefault(defaultResult.value, defaultFormat) ? `${withCodeExts}.pipe(${decodingDefault}(Effect.succeed(${defaultLiteral$1(defaultFormat, defaultResult.value)})))` : withCodeExts;
2358
2481
  const examples = examplesOf(schema);
2359
2482
  const ann = {};
2360
2483
  if (schema.description !== void 0) ann.description = schema.description;
@@ -2471,7 +2594,7 @@ function isBigintFormat(schema) {
2471
2594
  }
2472
2595
  /** A value as a TypeScript literal. Numbers of a bigint schema are `0n`, not `0`. */
2473
2596
  function literal(value, bigint) {
2474
- if (bigint && typeof value === "number" && Number.isFinite(value)) return `${value}n`;
2597
+ if (bigint && typeof value === "number" && Number.isInteger(value)) return bigintLiteral(value);
2475
2598
  return JSON.stringify(value);
2476
2599
  }
2477
2600
  /**
@@ -2977,7 +3100,7 @@ function nonNullType(schema, flavour, rootName) {
2977
3100
  return `(${members.join(" & ")})`;
2978
3101
  }
2979
3102
  if (schema.not) return "unknown";
2980
- const literal = (value) => typeof value === "number" && isInt64(schema) ? `${value}n` : jsLiteral(value);
3103
+ const literal = (value) => typeof value === "number" && isInt64(schema) ? bigintValueLiteral(value) : jsLiteral(value);
2981
3104
  if (schema.const !== void 0) return literal(schema.const);
2982
3105
  if (schema.enum) {
2983
3106
  if (schema.enum.length === 1) return literal(schema.enum[0]);
@@ -3105,11 +3228,11 @@ function unlessEvaluated(isEvaluated, body) {
3105
3228
  }
3106
3229
  // src/helper/valibot-wrap.ts
3107
3230
  /** A default as the Valibot literal of the schema's input: a bigint for a 64-bit integer. */
3108
- function defaultLiteral(schema, value, stringWire) {
3231
+ function defaultLiteral(format, value, stringWire) {
3109
3232
  if (stringWire) return jsLiteral(wireDefaultValue(value));
3110
3233
  if (typeof value === "number") {
3111
- if (schema.format === "int64" || schema.format === "uint64") return `${value}n`;
3112
- if (schema.format === "bigint") return `BigInt(${value})`;
3234
+ if (format === "int64" || format === "uint64") return bigintValueLiteral(value);
3235
+ if (format === "bigint") return `BigInt(${value})`;
3113
3236
  }
3114
3237
  return jsLiteral(value);
3115
3238
  }
@@ -3136,7 +3259,8 @@ function valibotWrap(valibotStr, schema, options) {
3136
3259
  const withNullable = isNullable(schema) && options?.nullSchema !== true || nullText && !isNullMatchedFirst(schema) ? `v.nullable(${valibotStr})` : valibotStr;
3137
3260
  const withNullText = nullText ? `v.pipe(v.unknown(),v.transform(${wireNullText("input")}),${withNullable})` : withNullable;
3138
3261
  const defaultResult = schema.default !== void 0 ? coerceDefault(schema, schema.default, options?.definitions) : void 0;
3139
- const withDefault = defaultResult?.keep ? `v.optional(${withNullText},${defaultLiteral(schema, defaultResult.value, options?.stringWire === true)})` : withNullText;
3262
+ const defaultFormat = typeof defaultResult?.value === "number" ? bigintFormatOf(schema, options?.definitions, isBigintSchema) : void 0;
3263
+ const withDefault = defaultResult?.keep === true && isWritableBigintDefault(defaultResult.value, defaultFormat) ? `v.optional(${withNullText},${defaultLiteral(defaultFormat, defaultResult.value, options?.stringWire === true)})` : withNullText;
3140
3264
  const examples = examplesOf(schema);
3141
3265
  const actions = [];
3142
3266
  if (schema.description !== void 0) actions.push(`v.description(${JSON.stringify(schema.description)})`);
@@ -3174,11 +3298,13 @@ function valibotWrap(valibotStr, schema, options) {
3174
3298
  * @see https://zod.dev/metadata
3175
3299
  */
3176
3300
  function zodWrap(zodStr, schema, options) {
3301
+ const bigintFormat = () => bigintFormatOf(schema, options?.definitions, isBigintSchema);
3177
3302
  const formatLiteral = (value) => {
3178
3303
  if (typeof value === "boolean") return `${value}`;
3179
3304
  if (typeof value === "number") {
3180
- if (schema.format === "int64" || schema.format === "uint64") return `${value}n`;
3181
- if (schema.format === "bigint") return `BigInt(${value})`;
3305
+ const format = bigintFormat();
3306
+ if (format === "int64" || format === "uint64") return bigintValueLiteral(value);
3307
+ if (format === "bigint") return `BigInt(${value})`;
3182
3308
  return `${value}`;
3183
3309
  }
3184
3310
  if (schema.type === "date" && typeof value === "string") return `new Date(${JSON.stringify(value)})`;
@@ -3186,7 +3312,7 @@ function zodWrap(zodStr, schema, options) {
3186
3312
  };
3187
3313
  const defaultResult = schema.default !== void 0 ? coerceDefault(schema, schema.default, options?.definitions) : void 0;
3188
3314
  const withNullable = isNullable(schema) && options?.nullSchema !== true ? `${zodStr}.nullable()` : zodStr;
3189
- const withDefault = defaultResult?.keep ? `${withNullable}.default(${formatLiteral(defaultResult.value)})` : withNullable;
3315
+ const withDefault = defaultResult?.keep === true && (typeof defaultResult.value !== "number" || isWritableBigintDefault(defaultResult.value, bigintFormat())) ? `${withNullable}.default(${formatLiteral(defaultResult.value)})` : withNullable;
3190
3316
  const withReadonly = schema["x-readonly"] === true ? `${withDefault}.readonly()` : withDefault;
3191
3317
  const withPrefault = schema["x-prefault"] !== void 0 ? `${withReadonly}.prefault(${formatLiteral(schema["x-prefault"])})` : withReadonly;
3192
3318
  const withCatch = schema["x-catch"] !== void 0 ? `${withPrefault}.catch(${formatLiteral(schema["x-catch"])})` : withPrefault;
@@ -3213,4 +3339,4 @@ function zodWrap(zodStr, schema, options) {
3213
3339
  if (preprocess) return preprocess;
3214
3340
  return withMeta;
3215
3341
  }
3216
- export { isOptionalByDefault as $, ALL_CODE_EXTENSION_KEYS as $t, unionPrimitiveTypes as A, PARAM_LOCATIONS as An, zodErrorPart as At, typeboxMetaOpts as B, UNSAFE_GENERATED_MARKER as Bn, isDeepLocalPointer as Bt, isNullMatchedFirst as C, NUMBER_RANGES as Cn, resolveOpenAPIRef as Ct, ownProperties as D, OFFSET_PATTERN_SOURCE as Dn, valibotErrorPart as Dt, numberWirePattern as E, OBJECT_PROTOTYPE_PROPERTIES as En, valibotError as Et, regexSource as F, STRINGBOOL_TRUTHY_PATTERN as Fn, hasNumericKeyword as Ft, planDocument as G, isPlainObject as Gt, definitionsOf as H, WIRE_PRIMITIVE_ORDER as Hn, isNullTypeMember as Ht, timePattern as I, STRING_FORMATS as In, hasStringKeyword as It, schemaNamer as J, isRecord as Jt, renderDefinitions as K, isPrimitive as Kt, deepEqualExpression as L, STRING_KEYWORDS as Ln, hasType as Lt, wireNullText as M, QUOTE_OR_BACKSLASH_PATTERN as Mn, hasConditional as Mt, wireNumericKind as N, ROOT_REFS as Nn, hasFixedItemCount as Nt, stringboolPattern as O, OPENAPI_COMPONENT_SUFFIX_MAP as On, zodBaseError as Ot, formatPattern as P, STRINGBOOL_PATTERN as Pn, hasFixedLength as Pt, enumWithoutWrappedNull as Q, isStringWireLocation as Qt, jsLiteral as R, STRING_WIRE_LOCATIONS as Rn, isArktypeDefinition as Rt, integerWirePattern as S, NUMBER_FORMATS as Sn, normalizeTypes as St, isPrimitiveUnion as T, NUMERIC_KEYWORDS as Tn, toPascalCase as Tt, emitOptionsOf as U, ZOD_CODE_EXTENSION_KEYS as Un, isNullable as Ut, typeboxRefOpt as V, VALIBOT_CODE_EXTENSION_KEYS as Vn, isDefaultOnlyMember as Vt, missingDefinitionComment as W, isObjectPrototypeProperty as Wt, cyclicDefinitionNames as X, isSchemaObject as Xt, discriminatedMembers as Y, isRootRef as Yt, hasRootSelfReference as Z, isShapelessMember as Zt, valueListLiteral as _, ISO_4217_CURRENCY_CODES as _n, effectErrorPart as _t, unlessEvaluated as a, DATE_PATTERN_SOURCE as an, callbackType as at, effectWrap as b, NON_IDENTIFIER_CHARACTER_PATTERN as bn, issueMessageExpression as bt, sanitizeSchema as c, DEFINITION_POINTER_PATTERN as cn, hasNotKeyword as ct, hasParameterSerialization as d, FORMAT_PATTERNS as dn, foldAllOfMembers as dt, ANCHOR_REF_PATTERN as en, itemsSchemaOf as et, parameterReaders as f, IDENTIFIER_PATTERN as fn, isKeywordOnlyMember as ft, notPredicate as g, INTEGER_WIRE_PATTERN as gn, effectError as gt, isBigintFormat as h, INTEGER_TEXT_PATTERN as hn, coerceDefault as ht, isEvaluatedKeyExpression as i, CONTENT_ENCODINGS as in, callbackReturn as it, wireArrayOnce as j, PARAM_STYLES as jn, hasCombinator as jt, stringboolTruthyPattern as k, OUTPUT_EXTENSION as kn, zodError as kt, refTarget as l, DEFINITION_REF_PREFIXES as ln, constraintMessage as lt, withoutParameterSerialization as m, INPUT_EXTENSIONS as mn, regexLiteral as mt, valibotWrap as n, ARROW_FUNCTION_PATTERN as nn, arktypeUnionLimit as nt, typeboxWrap as o, DEFAULT_ROOT_NAME as on, dslUnionMembers as ot, propertyEmitOptions as p, IF_THEN_ELSE_UNSUPPORTED_MARKER as pn, patternSource as pt, rootNameOf as q, isQuoted as qt, evaluatedProperties as r, COMPONENT_SCHEMA_REF_PREFIX as rn, arktypeWrap as rt, typeDeclaration as s, DEFINITION_KEYWORDS as sn, findCodeExtensionKeysInSchema as st, zodWrap as t, ARKTYPE_CODE_EXTENSION_KEYS as tn, arktypePreprocess as tt, withPolymorphicBases as u, EFFECT_CODE_EXTENSION_KEYS as un, constraintPredicate as ut, hoistNestedRefs as v, JSON_SCHEMA_TYPES as vn, effectMessage as vt, isNullTextRead as w, NUMBER_WIRE_PATTERN as wn, toIdentifierPascalCase as wt, impliedWireType as x, NOT_KEYWORD_UNSUPPORTED_MARKER as xn, makeSafeKey as xt, effectPreprocess as y, MISSING_DEFINITION_PREFIX as yn, encodeNonAscii as yt, typeboxDefaultOpt as z, UNICODE_ESCAPE_PATTERN as zn, isComposite as zt };
3342
+ export { isOptionalByDefault as $, isRecord as $t, unionPrimitiveTypes as A, NUMERIC_KEYWORDS as An, toPascalCase as At, typeboxMetaOpts as B, STRINGBOOL_TRUTHY_PATTERN as Bn, hasNumericKeyword as Bt, isNullMatchedFirst as C, JSON_SCHEMA_TYPES as Cn, effectMessage as Ct, ownProperties as D, NUMBER_FORMATS as Dn, normalizeTypes as Dt, numberWirePattern as E, NOT_KEYWORD_UNSUPPORTED_MARKER as En, makeSafeKey as Et, regexSource as F, PARAM_LOCATIONS as Fn, zodErrorPart as Ft, planDocument as G, UNSAFE_GENERATED_MARKER as Gn, isDeepLocalPointer as Gt, definitionsOf as H, STRING_KEYWORDS as Hn, hasType as Ht, timePattern as I, PARAM_STYLES as In, hasCombinator as It, schemaNamer as J, ZOD_CODE_EXTENSION_KEYS as Jn, isNullable as Jt, renderDefinitions as K, VALIBOT_CODE_EXTENSION_KEYS as Kn, isDefaultOnlyMember as Kt, deepEqualExpression as L, QUOTE_OR_BACKSLASH_PATTERN as Ln, hasConditional as Lt, wireNullText as M, OFFSET_PATTERN_SOURCE as Mn, valibotErrorPart as Mt, wireNumericKind as N, OPENAPI_COMPONENT_SUFFIX_MAP as Nn, zodBaseError as Nt, stringboolPattern as O, NUMBER_RANGES as On, resolveOpenAPIRef as Ot, formatPattern as P, OUTPUT_EXTENSION as Pn, zodError as Pt, enumWithoutWrappedNull as Q, isQuoted as Qt, jsLiteral as R, ROOT_REFS as Rn, hasFixedItemCount as Rt, integerWirePattern as S, ISO_4217_CURRENCY_CODES as Sn, effectErrorPart as St, isPrimitiveUnion as T, NON_IDENTIFIER_CHARACTER_PATTERN as Tn, issueMessageExpression as Tt, emitOptionsOf as U, STRING_WIRE_LOCATIONS as Un, isArktypeDefinition as Ut, typeboxRefOpt as V, STRING_FORMATS as Vn, hasStringKeyword as Vt, missingDefinitionComment as W, UNICODE_ESCAPE_PATTERN as Wn, isComposite as Wt, cyclicDefinitionNames as X, isPlainObject as Xt, discriminatedMembers as Y, isObjectPrototypeProperty as Yt, hasRootSelfReference as Z, isPrimitive as Zt, valueListLiteral as _, IDENTIFIER_PATTERN as _n, patternSource as _t, unlessEvaluated as a, ANCHOR_REF_PATTERN as an, arktypePreprocess as at, effectWrap as b, INTEGER_TEXT_PATTERN as bn, definitionOf$1 as bt, sanitizeSchema as c, COMPONENT_SCHEMA_REF_PREFIX as cn, callbackReturn as ct, hasParameterSerialization as d, DEFAULT_ROOT_NAME as dn, findCodeExtensionKeysInSchema as dt, isRootRef as en, itemsSchemaOf as et, parameterReaders as f, DEFINITION_KEYWORDS as fn, hasNotKeyword as ft, notPredicate as g, FORMAT_PATTERNS as gn, isKeywordOnlyMember as gt, isBigintFormat as h, EFFECT_CODE_EXTENSION_KEYS as hn, foldAllOfMembers as ht, isEvaluatedKeyExpression as i, ALL_CODE_EXTENSION_KEYS as in, bigintValueLiteral as it, wireArrayOnce as j, OBJECT_PROTOTYPE_PROPERTIES as jn, valibotError as jt, stringboolTruthyPattern as k, NUMBER_WIRE_PATTERN as kn, toIdentifierPascalCase as kt, refTarget as l, CONTENT_ENCODINGS as ln, callbackType as lt, withoutParameterSerialization as m, DEFINITION_REF_PREFIXES as mn, constraintPredicate as mt, valibotWrap as n, isShapelessMember as nn, bigintCall as nt, typeboxWrap as o, ARKTYPE_CODE_EXTENSION_KEYS as on, arktypeUnionLimit as ot, propertyEmitOptions as p, DEFINITION_POINTER_PATTERN as pn, constraintMessage as pt, rootNameOf as q, WIRE_PRIMITIVE_ORDER as qn, isNullTypeMember as qt, evaluatedProperties as r, isStringWireLocation as rn, bigintLiteral as rt, typeDeclaration as s, ARROW_FUNCTION_PATTERN as sn, arktypeWrap as st, zodWrap as t, isSchemaObject as tn, bigintBounds as tt, withPolymorphicBases as u, DATE_PATTERN_SOURCE as un, dslUnionMembers as ut, hoistNestedRefs as v, IF_THEN_ELSE_UNSUPPORTED_MARKER as vn, regexLiteral as vt, isNullTextRead as w, MISSING_DEFINITION_PREFIX as wn, encodeNonAscii as wt, impliedWireType as x, INTEGER_WIRE_PATTERN as xn, effectError as xt, effectPreprocess as y, INPUT_EXTENSIONS as yn, coerceDefault as yt, typeboxDefaultOpt as z, STRINGBOOL_PATTERN as zn, hasFixedLength as zt };
package/dist/index.d.ts CHANGED
@@ -111,6 +111,7 @@ export declare function normalizeTypes(types?: string | readonly string[]): stri
111
111
  export type DefaultSchema = {
112
112
  readonly $ref?: string;
113
113
  readonly type?: string | readonly string[];
114
+ readonly format?: string;
114
115
  readonly nullable?: boolean;
115
116
  readonly enum?: readonly unknown[];
116
117
  readonly const?: unknown;
@@ -168,6 +169,10 @@ type DefaultResult = {
168
169
  export declare function coerceDefault(schema: DefaultSchema, value: unknown, definitions?: {
169
170
  readonly [name: string]: DefaultSchema;
170
171
  }): DefaultResult;
172
+ /** The definition a local `$ref` names, when `definitions` has it. */
173
+ export declare function definitionOf(ref: string, definitions: {
174
+ readonly [name: string]: DefaultSchema;
175
+ } | undefined): DefaultSchema | undefined;
171
176
  /**
172
177
  * A message as the expression an emitted check evaluates for each issue: an arrow source
173
178
  * is applied to the issue, a sentence becomes a string literal.
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { $t as ALL_CODE_EXTENSION_KEYS, An as PARAM_LOCATIONS, At as zodErrorPart, Bn as UNSAFE_GENERATED_MARKER, Cn as NUMBER_RANGES, Ct as resolveOpenAPIRef, Dn as OFFSET_PATTERN_SOURCE, Dt as valibotErrorPart, En as OBJECT_PROTOTYPE_PROPERTIES, Et as valibotError, Fn as STRINGBOOL_TRUTHY_PATTERN, Hn as WIRE_PRIMITIVE_ORDER, In as STRING_FORMATS, Ln as STRING_KEYWORDS, Mn as QUOTE_OR_BACKSLASH_PATTERN, Nn as ROOT_REFS, On as OPENAPI_COMPONENT_SUFFIX_MAP, Ot as zodBaseError, Pn as STRINGBOOL_PATTERN, Rn as STRING_WIRE_LOCATIONS, Sn as NUMBER_FORMATS, St as normalizeTypes, Tn as NUMERIC_KEYWORDS, Tt as toPascalCase, Un as ZOD_CODE_EXTENSION_KEYS, Vn as VALIBOT_CODE_EXTENSION_KEYS, _n as ISO_4217_CURRENCY_CODES, _t as effectErrorPart, an as DATE_PATTERN_SOURCE, bn as NON_IDENTIFIER_CHARACTER_PATTERN, bt as issueMessageExpression, cn as DEFINITION_POINTER_PATTERN, dn as FORMAT_PATTERNS, en as ANCHOR_REF_PATTERN, fn as IDENTIFIER_PATTERN, gn as INTEGER_WIRE_PATTERN, gt as effectError, hn as INTEGER_TEXT_PATTERN, ht as coerceDefault, in as CONTENT_ENCODINGS, jn as PARAM_STYLES, kn as OUTPUT_EXTENSION, kt as zodError, ln as DEFINITION_REF_PREFIXES, mn as INPUT_EXTENSIONS, nn as ARROW_FUNCTION_PATTERN, on as DEFAULT_ROOT_NAME, pn as IF_THEN_ELSE_UNSUPPORTED_MARKER, rn as COMPONENT_SCHEMA_REF_PREFIX, sn as DEFINITION_KEYWORDS, tn as ARKTYPE_CODE_EXTENSION_KEYS, un as EFFECT_CODE_EXTENSION_KEYS, vn as JSON_SCHEMA_TYPES, vt as effectMessage, wn as NUMBER_WIRE_PATTERN, wt as toIdentifierPascalCase, xn as NOT_KEYWORD_UNSUPPORTED_MARKER, xt as makeSafeKey, yn as MISSING_DEFINITION_PREFIX, yt as encodeNonAscii, zn as UNICODE_ESCAPE_PATTERN } from "./helper-ByoddrXL.js";
1
+ import { An as NUMERIC_KEYWORDS, At as toPascalCase, Bn as STRINGBOOL_TRUTHY_PATTERN, Cn as JSON_SCHEMA_TYPES, Ct as effectMessage, Dn as NUMBER_FORMATS, Dt as normalizeTypes, En as NOT_KEYWORD_UNSUPPORTED_MARKER, Et as makeSafeKey, Fn as PARAM_LOCATIONS, Ft as zodErrorPart, Gn as UNSAFE_GENERATED_MARKER, Hn as STRING_KEYWORDS, In as PARAM_STYLES, Jn as ZOD_CODE_EXTENSION_KEYS, Kn as VALIBOT_CODE_EXTENSION_KEYS, Ln as QUOTE_OR_BACKSLASH_PATTERN, Mn as OFFSET_PATTERN_SOURCE, Mt as valibotErrorPart, Nn as OPENAPI_COMPONENT_SUFFIX_MAP, Nt as zodBaseError, On as NUMBER_RANGES, Ot as resolveOpenAPIRef, Pn as OUTPUT_EXTENSION, Pt as zodError, Rn as ROOT_REFS, Sn as ISO_4217_CURRENCY_CODES, St as effectErrorPart, Tn as NON_IDENTIFIER_CHARACTER_PATTERN, Tt as issueMessageExpression, Un as STRING_WIRE_LOCATIONS, Vn as STRING_FORMATS, Wn as UNICODE_ESCAPE_PATTERN, _n as IDENTIFIER_PATTERN, an as ANCHOR_REF_PATTERN, bn as INTEGER_TEXT_PATTERN, bt as definitionOf, cn as COMPONENT_SCHEMA_REF_PREFIX, dn as DEFAULT_ROOT_NAME, fn as DEFINITION_KEYWORDS, gn as FORMAT_PATTERNS, hn as EFFECT_CODE_EXTENSION_KEYS, in as ALL_CODE_EXTENSION_KEYS, jn as OBJECT_PROTOTYPE_PROPERTIES, jt as valibotError, kn as NUMBER_WIRE_PATTERN, kt as toIdentifierPascalCase, ln as CONTENT_ENCODINGS, mn as DEFINITION_REF_PREFIXES, on as ARKTYPE_CODE_EXTENSION_KEYS, pn as DEFINITION_POINTER_PATTERN, qn as WIRE_PRIMITIVE_ORDER, sn as ARROW_FUNCTION_PATTERN, un as DATE_PATTERN_SOURCE, vn as IF_THEN_ELSE_UNSUPPORTED_MARKER, wn as MISSING_DEFINITION_PREFIX, wt as encodeNonAscii, xn as INTEGER_WIRE_PATTERN, xt as effectError, yn as INPUT_EXTENSIONS, yt as coerceDefault, zn as STRINGBOOL_PATTERN } from "./helper-DpwdwX03.js";
2
2
  import { i as fmt, n as parseSchemaFile, r as FormatError, t as ParseError } from "./parser-RBrkz7ZL.js";
3
- import { n as ajv, t as schemaToAjv } from "./ajv-DjHkU79T.js";
4
- import { n as arktype, t as schemaToArktype } from "./arktype-CbrtmKWv.js";
5
- import { n as effect, r as wholeValueMessage, t as schemaToEffect } from "./effect-BqLfzMgM.js";
6
- import { n as nestedTypeboxOptions, r as typebox, t as schemaToTypebox } from "./typebox-DdFjzmqK.js";
7
- import { n as valibot, t as schemaToValibot } from "./valibot-Bz-mcsf9.js";
8
- import { n as yup, t as schemaToYup } from "./yup-rbHu00QS.js";
9
- import { i as zod, n as forwardIssue, r as nestedIssueMessageWrap, t as schemaToZod } from "./zod-Cvj9YJY_.js";
10
- export { ALL_CODE_EXTENSION_KEYS, ANCHOR_REF_PATTERN, ARKTYPE_CODE_EXTENSION_KEYS, ARROW_FUNCTION_PATTERN, COMPONENT_SCHEMA_REF_PREFIX, CONTENT_ENCODINGS, DATE_PATTERN_SOURCE, DEFAULT_ROOT_NAME, DEFINITION_KEYWORDS, DEFINITION_POINTER_PATTERN, DEFINITION_REF_PREFIXES, EFFECT_CODE_EXTENSION_KEYS, FORMAT_PATTERNS, FormatError, IDENTIFIER_PATTERN, IF_THEN_ELSE_UNSUPPORTED_MARKER, INPUT_EXTENSIONS, INTEGER_TEXT_PATTERN, INTEGER_WIRE_PATTERN, ISO_4217_CURRENCY_CODES, JSON_SCHEMA_TYPES, MISSING_DEFINITION_PREFIX, NON_IDENTIFIER_CHARACTER_PATTERN, NOT_KEYWORD_UNSUPPORTED_MARKER, NUMBER_FORMATS, NUMBER_RANGES, NUMBER_WIRE_PATTERN, NUMERIC_KEYWORDS, OBJECT_PROTOTYPE_PROPERTIES, OFFSET_PATTERN_SOURCE, OPENAPI_COMPONENT_SUFFIX_MAP, OUTPUT_EXTENSION, PARAM_LOCATIONS, PARAM_STYLES, ParseError, QUOTE_OR_BACKSLASH_PATTERN, ROOT_REFS, STRINGBOOL_PATTERN, STRINGBOOL_TRUTHY_PATTERN, STRING_FORMATS, STRING_KEYWORDS, STRING_WIRE_LOCATIONS, UNICODE_ESCAPE_PATTERN, UNSAFE_GENERATED_MARKER, VALIBOT_CODE_EXTENSION_KEYS, WIRE_PRIMITIVE_ORDER, ZOD_CODE_EXTENSION_KEYS, ajv, arktype, coerceDefault, effect, effectError, effectErrorPart, effectMessage, encodeNonAscii, fmt, forwardIssue, issueMessageExpression, makeSafeKey, nestedIssueMessageWrap, nestedTypeboxOptions, normalizeTypes, parseSchemaFile, resolveOpenAPIRef, schemaToAjv, schemaToArktype, schemaToEffect, schemaToTypebox, schemaToValibot, schemaToYup, schemaToZod, toIdentifierPascalCase, toPascalCase, typebox, valibot, valibotError, valibotErrorPart, wholeValueMessage, yup, zod, zodBaseError, zodError, zodErrorPart };
3
+ import { n as ajv, t as schemaToAjv } from "./ajv-BzXa3loS.js";
4
+ import { n as arktype, t as schemaToArktype } from "./arktype-o5UiPNHq.js";
5
+ import { n as effect, r as wholeValueMessage, t as schemaToEffect } from "./effect-CYQf9Lw6.js";
6
+ import { n as nestedTypeboxOptions, r as typebox, t as schemaToTypebox } from "./typebox-2MLHaziq.js";
7
+ import { n as valibot, t as schemaToValibot } from "./valibot-CRyUoeJj.js";
8
+ import { n as yup, t as schemaToYup } from "./yup-BqKfyIcd.js";
9
+ import { i as zod, n as forwardIssue, r as nestedIssueMessageWrap, t as schemaToZod } from "./zod-xz1vNbs5.js";
10
+ export { ALL_CODE_EXTENSION_KEYS, ANCHOR_REF_PATTERN, ARKTYPE_CODE_EXTENSION_KEYS, ARROW_FUNCTION_PATTERN, COMPONENT_SCHEMA_REF_PREFIX, CONTENT_ENCODINGS, DATE_PATTERN_SOURCE, DEFAULT_ROOT_NAME, DEFINITION_KEYWORDS, DEFINITION_POINTER_PATTERN, DEFINITION_REF_PREFIXES, EFFECT_CODE_EXTENSION_KEYS, FORMAT_PATTERNS, FormatError, IDENTIFIER_PATTERN, IF_THEN_ELSE_UNSUPPORTED_MARKER, INPUT_EXTENSIONS, INTEGER_TEXT_PATTERN, INTEGER_WIRE_PATTERN, ISO_4217_CURRENCY_CODES, JSON_SCHEMA_TYPES, MISSING_DEFINITION_PREFIX, NON_IDENTIFIER_CHARACTER_PATTERN, NOT_KEYWORD_UNSUPPORTED_MARKER, NUMBER_FORMATS, NUMBER_RANGES, NUMBER_WIRE_PATTERN, NUMERIC_KEYWORDS, OBJECT_PROTOTYPE_PROPERTIES, OFFSET_PATTERN_SOURCE, OPENAPI_COMPONENT_SUFFIX_MAP, OUTPUT_EXTENSION, PARAM_LOCATIONS, PARAM_STYLES, ParseError, QUOTE_OR_BACKSLASH_PATTERN, ROOT_REFS, STRINGBOOL_PATTERN, STRINGBOOL_TRUTHY_PATTERN, STRING_FORMATS, STRING_KEYWORDS, STRING_WIRE_LOCATIONS, UNICODE_ESCAPE_PATTERN, UNSAFE_GENERATED_MARKER, VALIBOT_CODE_EXTENSION_KEYS, WIRE_PRIMITIVE_ORDER, ZOD_CODE_EXTENSION_KEYS, ajv, arktype, coerceDefault, definitionOf, effect, effectError, effectErrorPart, effectMessage, encodeNonAscii, fmt, forwardIssue, issueMessageExpression, makeSafeKey, nestedIssueMessageWrap, nestedTypeboxOptions, normalizeTypes, parseSchemaFile, resolveOpenAPIRef, schemaToAjv, schemaToArktype, schemaToEffect, schemaToTypebox, schemaToValibot, schemaToYup, schemaToZod, toIdentifierPascalCase, toPascalCase, typebox, valibot, valibotError, valibotErrorPart, wholeValueMessage, yup, zod, zodBaseError, zodError, zodErrorPart };
@@ -1,5 +1,4 @@
1
- import { $ as isOptionalByDefault, B as typeboxMetaOpts, Bt as isDeepLocalPointer, Ct as resolveOpenAPIRef, Ft as hasNumericKeyword, G as planDocument, H as definitionsOf, Ht as isNullTypeMember, It as hasStringKeyword, J as schemaNamer, K as renderDefinitions, O as stringboolPattern, Pt as hasFixedLength, Q as enumWithoutWrappedNull, Qt as isStringWireLocation, St as normalizeTypes, U as emitOptionsOf, Ut as isNullable, V as typeboxRefOpt, Vt as isDefaultOnlyMember, W as missingDefinitionComment, X as cyclicDefinitionNames, Y as discriminatedMembers, Yt as isRootRef, Z as hasRootSelfReference, Zt as isShapelessMember, c as sanitizeSchema, ct as hasNotKeyword, dt as foldAllOfMembers, et as itemsSchemaOf, ft as isKeywordOnlyMember, gn as INTEGER_WIRE_PATTERN, jt as hasCombinator, k as stringboolTruthyPattern, ln as DEFINITION_REF_PREFIXES, o as typeboxWrap, on as DEFAULT_ROOT_NAME, pt as patternSource, q as rootNameOf, u as withPolymorphicBases, v as hoistNestedRefs, wn as NUMBER_WIRE_PATTERN, xn as NOT_KEYWORD_UNSUPPORTED_MARKER, xt as makeSafeKey, z as typeboxDefaultOpt, zt as isComposite } from "./helper-ByoddrXL.js";
2
- import { t as bigintBounds } from "./bigint-CkHij6xv.js";
1
+ import { $ as isOptionalByDefault, B as typeboxMetaOpts, Bt as hasNumericKeyword, Dt as normalizeTypes, En as NOT_KEYWORD_UNSUPPORTED_MARKER, Et as makeSafeKey, G as planDocument, Gt as isDeepLocalPointer, H as definitionsOf, It as hasCombinator, J as schemaNamer, Jt as isNullable, K as renderDefinitions, Kt as isDefaultOnlyMember, O as stringboolPattern, Ot as resolveOpenAPIRef, Q as enumWithoutWrappedNull, U as emitOptionsOf, V as typeboxRefOpt, Vt as hasStringKeyword, W as missingDefinitionComment, Wt as isComposite, X as cyclicDefinitionNames, Y as discriminatedMembers, Z as hasRootSelfReference, _t as patternSource, c as sanitizeSchema, dn as DEFAULT_ROOT_NAME, en as isRootRef, et as itemsSchemaOf, ft as hasNotKeyword, gt as isKeywordOnlyMember, ht as foldAllOfMembers, k as stringboolTruthyPattern, kn as NUMBER_WIRE_PATTERN, mn as DEFINITION_REF_PREFIXES, nn as isShapelessMember, o as typeboxWrap, q as rootNameOf, qt as isNullTypeMember, rn as isStringWireLocation, tt as bigintBounds, u as withPolymorphicBases, v as hoistNestedRefs, xn as INTEGER_WIRE_PATTERN, z as typeboxDefaultOpt, zt as hasFixedLength } from "./helper-DpwdwX03.js";
3
2
  // src/generator/typebox/enum.ts
4
3
  function lit(v) {
5
4
  if (v === null) return "null";
@@ -394,12 +393,12 @@ function keywordSchema(schema) {
394
393
  * embedding any meta options from the schema. Returns `Type.X(payload)` when
395
394
  * no options.
396
395
  */
397
- function tbComp(name, payload, schema, extraOpts = [], ref) {
396
+ function tbComp(name, payload, schema, extraOpts = [], ref, definitions) {
398
397
  const opts = [
399
398
  ...typeboxRefOpt(ref),
400
399
  ...extraOpts,
401
400
  ...typeboxMetaOpts(schema),
402
- ...typeboxDefaultOpt(schema)
401
+ ...typeboxDefaultOpt(schema, false, definitions)
403
402
  ];
404
403
  return opts.length === 0 ? `${name}(${payload})` : `${name}(${payload},{${opts.join(",")}})`;
405
404
  }
@@ -459,13 +458,13 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
459
458
  const literal = literals.length === 1 ? literals[0] : `Type.Union([${literals.join(",")}])`;
460
459
  return `Type.Intersect([${member},Type.Object({${makeSafeKey(discriminated.propertyName)}:${literal}})])`;
461
460
  });
462
- return typeboxWrap(tbComp("Type.Union", `[${schemas.join(",")}]`, schema, messageOpt(schema["x-oneOf-message"]), hostRef), schema);
461
+ return typeboxWrap(tbComp("Type.Union", `[${schemas.join(",")}]`, schema, messageOpt(schema["x-oneOf-message"]), hostRef, definitions), schema);
463
462
  }
464
463
  if (schema.anyOf) {
465
464
  if (schema.anyOf.length === 0) return typeboxWrap(tbPrim("Type.Any", schema, [], hostRef), schema);
466
465
  const schemas = schema.anyOf.map((s) => typebox(s, rootName, isTypebox, childOptions));
467
466
  const anyOfMessage = schema["x-implication-message"] ?? schema["x-anyOf-message"];
468
- return typeboxWrap(tbComp("Type.Union", `[${schemas.join(",")}]`, schema, messageOpt(anyOfMessage), hostRef), schema);
467
+ return typeboxWrap(tbComp("Type.Union", `[${schemas.join(",")}]`, schema, messageOpt(anyOfMessage), hostRef, definitions), schema);
469
468
  }
470
469
  if (schema.allOf) {
471
470
  if (schema.allOf.length === 0) return typeboxWrap(tbPrim("Type.Any", schema, [], hostRef), schema);
package/dist/typebox.js CHANGED
@@ -1 +1 @@
1
- export { t as schemaToTypebox } from "./typebox-DdFjzmqK.js";
1
+ export { t as schemaToTypebox } from "./typebox-2MLHaziq.js";
@@ -1,5 +1,4 @@
1
- import { $ as isOptionalByDefault, A as unionPrimitiveTypes, Bn as UNSAFE_GENERATED_MARKER, Cn as NUMBER_RANGES, D as ownProperties, Dt as valibotErrorPart, E as numberWirePattern, Et as valibotError, F as regexSource, G as planDocument, H as definitionsOf, Ht as isNullTypeMember, J as schemaNamer, K as renderDefinitions, Kt as isPrimitive, L as deepEqualExpression, Lt as hasType, Mt as hasConditional, N as wireNumericKind, Nt as hasFixedItemCount, O as stringboolPattern, P as formatPattern, Pt as hasFixedLength, Q as enumWithoutWrappedNull, Qt as isStringWireLocation, R as jsLiteral, S as integerWirePattern, St as normalizeTypes, T as isPrimitiveUnion, U as emitOptionsOf, Ut as isNullable, Vt as isDefaultOnlyMember, Wt as isObjectPrototypeProperty, Xt as isSchemaObject, Y as discriminatedMembers, Z as hasRootSelfReference, Zt as isShapelessMember, _ as valueListLiteral, a as unlessEvaluated, bt as issueMessageExpression, c as sanitizeSchema, d as hasParameterSerialization, dt as foldAllOfMembers, et as itemsSchemaOf, f as parameterReaders, ft as isKeywordOnlyMember, g as notPredicate, h as isBigintFormat, hn as INTEGER_TEXT_PATTERN, i as isEvaluatedKeyExpression, j as wireArrayOnce, jt as hasCombinator, k as stringboolTruthyPattern, l as refTarget, lt as constraintMessage, m as withoutParameterSerialization, mt as regexLiteral, n as valibotWrap, on as DEFAULT_ROOT_NAME, p as propertyEmitOptions, q as rootNameOf, r as evaluatedProperties, s as typeDeclaration, st as findCodeExtensionKeysInSchema, u as withPolymorphicBases, ut as constraintPredicate, v as hoistNestedRefs, w as isNullTextRead, x as impliedWireType, xt as makeSafeKey } from "./helper-ByoddrXL.js";
2
- import { n as bigintCall, r as bigintLiteral, t as bigintBounds } from "./bigint-CkHij6xv.js";
1
+ import { $ as isOptionalByDefault, A as unionPrimitiveTypes, D as ownProperties, Dt as normalizeTypes, E as numberWirePattern, Et as makeSafeKey, F as regexSource, G as planDocument, Gn as UNSAFE_GENERATED_MARKER, H as definitionsOf, Ht as hasType, It as hasCombinator, J as schemaNamer, Jt as isNullable, K as renderDefinitions, Kt as isDefaultOnlyMember, L as deepEqualExpression, Lt as hasConditional, Mt as valibotErrorPart, N as wireNumericKind, O as stringboolPattern, On as NUMBER_RANGES, P as formatPattern, Q as enumWithoutWrappedNull, R as jsLiteral, Rt as hasFixedItemCount, S as integerWirePattern, T as isPrimitiveUnion, Tt as issueMessageExpression, U as emitOptionsOf, Y as discriminatedMembers, Yt as isObjectPrototypeProperty, Z as hasRootSelfReference, Zt as isPrimitive, _ as valueListLiteral, a as unlessEvaluated, bn as INTEGER_TEXT_PATTERN, c as sanitizeSchema, d as hasParameterSerialization, dn as DEFAULT_ROOT_NAME, dt as findCodeExtensionKeysInSchema, et as itemsSchemaOf, f as parameterReaders, g as notPredicate, gt as isKeywordOnlyMember, h as isBigintFormat, ht as foldAllOfMembers, i as isEvaluatedKeyExpression, it as bigintValueLiteral, j as wireArrayOnce, jt as valibotError, k as stringboolTruthyPattern, l as refTarget, m as withoutParameterSerialization, mt as constraintPredicate, n as valibotWrap, nn as isShapelessMember, nt as bigintCall, p as propertyEmitOptions, pt as constraintMessage, q as rootNameOf, qt as isNullTypeMember, r as evaluatedProperties, rn as isStringWireLocation, rt as bigintLiteral, s as typeDeclaration, tn as isSchemaObject, tt as bigintBounds, u as withPolymorphicBases, v as hoistNestedRefs, vt as regexLiteral, w as isNullTextRead, x as impliedWireType, zt as hasFixedLength } from "./helper-DpwdwX03.js";
3
2
  // src/generator/valibot/type.ts
4
3
  /** The TypeScript type declared beside a recursive Valibot schema: its output type. */
5
4
  function type(schema, rootName = DEFAULT_ROOT_NAME) {
@@ -24,12 +23,12 @@ function numberActions(schema, lit = (n) => `${n}`) {
24
23
  return [
25
24
  (() => {
26
25
  if (schema.minimum !== void 0) return schema.exclusiveMinimum === true ? `v.gtValue(${lit(schema.minimum)}${exMinErrorPart})` : `v.minValue(${lit(schema.minimum)}${minErrorPart})`;
27
- if (typeof schema.exclusiveMinimum === "number") return `v.gtValue(${lit(schema.exclusiveMinimum)}${exMinErrorPart})`;
28
26
  })(),
27
+ typeof schema.exclusiveMinimum === "number" ? `v.gtValue(${lit(schema.exclusiveMinimum)}${exMinErrorPart})` : void 0,
29
28
  (() => {
30
29
  if (schema.maximum !== void 0) return schema.exclusiveMaximum === true ? `v.ltValue(${lit(schema.maximum)}${exMaxErrorPart})` : `v.maxValue(${lit(schema.maximum)}${maxErrorPart})`;
31
- if (typeof schema.exclusiveMaximum === "number") return `v.ltValue(${lit(schema.exclusiveMaximum)}${exMaxErrorPart})`;
32
30
  })(),
31
+ typeof schema.exclusiveMaximum === "number" ? `v.ltValue(${lit(schema.exclusiveMaximum)}${exMaxErrorPart})` : void 0,
33
32
  schema.multipleOf !== void 0 ? `v.multipleOf(${lit(schema.multipleOf)}${multipleOfErrorPart})` : void 0
34
33
  ].filter((v) => v !== void 0);
35
34
  }
@@ -128,7 +127,7 @@ function integer(schema, options) {
128
127
  function lit(v, isBigint) {
129
128
  if (v === null) return "null";
130
129
  if (typeof v === "string") return `'${v.replaceAll("'", "\\'")}'`;
131
- if (typeof v === "number" && isBigint) return `${v}n`;
130
+ if (typeof v === "number" && isBigint) return bigintValueLiteral(v);
132
131
  if (typeof v === "number" || typeof v === "boolean") return String(v);
133
132
  return JSON.stringify(v) ?? "null";
134
133
  }
@@ -577,7 +576,7 @@ function node(schema, rootName, isValibot, options) {
577
576
  const msgArg = constMessage ? valibotError(constMessage) : "";
578
577
  const errorPart = msgArg ? `,${msgArg}` : "";
579
578
  if (value === null) return valibotWrap$1(`v.null(${msgArg})`, schema);
580
- const literal = typeof value === "number" && isInt64(schema) ? `v.literal(${value}n${errorPart})` : isPrimitive(value) ? `v.literal(${JSON.stringify(value)}${errorPart})` : `v.custom<${JSON.stringify(value)}>((input) => ${deepEqualExpression(value, "input")}${errorPart})`;
579
+ const literal = typeof value === "number" && isInt64(schema) ? `v.literal(${bigintValueLiteral(value)}${errorPart})` : isPrimitive(value) ? `v.literal(${JSON.stringify(value)}${errorPart})` : `v.custom<${JSON.stringify(value)}>((input) => ${deepEqualExpression(value, "input")}${errorPart})`;
581
580
  const input = literalInput([value]);
582
581
  return valibotWrap$1(input ? prependPipe(input, literal) : literal, schema);
583
582
  }
package/dist/valibot.js CHANGED
@@ -1 +1 @@
1
- export { t as schemaToValibot } from "./valibot-Bz-mcsf9.js";
1
+ export { t as schemaToValibot } from "./valibot-CRyUoeJj.js";
@@ -1,4 +1,4 @@
1
- import { J as schemaNamer, St as normalizeTypes, c as sanitizeSchema, q as rootNameOf, xt as makeSafeKey } from "./helper-ByoddrXL.js";
1
+ import { Dt as normalizeTypes, Et as makeSafeKey, J as schemaNamer, c as sanitizeSchema, q as rootNameOf } from "./helper-DpwdwX03.js";
2
2
  // src/generator/yup/integer.ts
3
3
  /**
4
4
  * Generate a Yup integer schema as `yup.number().integer()`, with `minimum`
package/dist/yup.js CHANGED
@@ -1 +1 @@
1
- export { t as schemaToYup } from "./yup-rbHu00QS.js";
1
+ export { t as schemaToYup } from "./yup-BqKfyIcd.js";
@@ -1,5 +1,4 @@
1
- import { A as unionPrimitiveTypes, At as zodErrorPart, Bn as UNSAFE_GENERATED_MARKER, C as isNullMatchedFirst, E as numberWirePattern, G as planDocument, Gt as isPlainObject, H as definitionsOf, Ht as isNullTypeMember, I as timePattern, J as schemaNamer, K as renderDefinitions, Kt as isPrimitive, L as deepEqualExpression, Lt as hasType, M as wireNullText, Mt as hasConditional, N as wireNumericKind, Ot as zodBaseError, Pt as hasFixedLength, Q as enumWithoutWrappedNull, Qt as isStringWireLocation, S as integerWirePattern, St as normalizeTypes, T as isPrimitiveUnion, U as emitOptionsOf, Ut as isNullable, Vt as isDefaultOnlyMember, Wt as isObjectPrototypeProperty, Xt as isSchemaObject, Y as discriminatedMembers, Z as hasRootSelfReference, Zt as isShapelessMember, _ as valueListLiteral, _n as ISO_4217_CURRENCY_CODES, a as unlessEvaluated, bt as issueMessageExpression, c as sanitizeSchema, d as hasParameterSerialization, dt as foldAllOfMembers, et as itemsSchemaOf, f as parameterReaders, ft as isKeywordOnlyMember, g as notPredicate, h as isBigintFormat, i as isEvaluatedKeyExpression, j as wireArrayOnce, jt as hasCombinator, kt as zodError, l as refTarget, lt as constraintMessage, m as withoutParameterSerialization, mt as regexLiteral, on as DEFAULT_ROOT_NAME, p as propertyEmitOptions, q as rootNameOf, r as evaluatedProperties, s as typeDeclaration, st as findCodeExtensionKeysInSchema, t as zodWrap, u as withPolymorphicBases, ut as constraintPredicate, v as hoistNestedRefs, w as isNullTextRead, x as impliedWireType, xt as makeSafeKey, zt as isComposite } from "./helper-ByoddrXL.js";
2
- import { n as bigintCall, r as bigintLiteral, t as bigintBounds } from "./bigint-CkHij6xv.js";
1
+ import { A as unionPrimitiveTypes, C as isNullMatchedFirst, Dt as normalizeTypes, E as numberWirePattern, Et as makeSafeKey, Ft as zodErrorPart, G as planDocument, Gn as UNSAFE_GENERATED_MARKER, H as definitionsOf, Ht as hasType, I as timePattern, It as hasCombinator, J as schemaNamer, Jt as isNullable, K as renderDefinitions, Kt as isDefaultOnlyMember, L as deepEqualExpression, Lt as hasConditional, M as wireNullText, N as wireNumericKind, Nt as zodBaseError, Pt as zodError, Q as enumWithoutWrappedNull, S as integerWirePattern, Sn as ISO_4217_CURRENCY_CODES, T as isPrimitiveUnion, Tt as issueMessageExpression, U as emitOptionsOf, Wt as isComposite, Xt as isPlainObject, Y as discriminatedMembers, Yt as isObjectPrototypeProperty, Z as hasRootSelfReference, Zt as isPrimitive, _ as valueListLiteral, a as unlessEvaluated, c as sanitizeSchema, d as hasParameterSerialization, dn as DEFAULT_ROOT_NAME, dt as findCodeExtensionKeysInSchema, et as itemsSchemaOf, f as parameterReaders, g as notPredicate, gt as isKeywordOnlyMember, h as isBigintFormat, ht as foldAllOfMembers, i as isEvaluatedKeyExpression, it as bigintValueLiteral, j as wireArrayOnce, l as refTarget, m as withoutParameterSerialization, mt as constraintPredicate, nn as isShapelessMember, nt as bigintCall, p as propertyEmitOptions, pt as constraintMessage, q as rootNameOf, qt as isNullTypeMember, r as evaluatedProperties, rn as isStringWireLocation, rt as bigintLiteral, s as typeDeclaration, t as zodWrap, tn as isSchemaObject, tt as bigintBounds, u as withPolymorphicBases, v as hoistNestedRefs, vt as regexLiteral, w as isNullTextRead, x as impliedWireType, zt as hasFixedLength } from "./helper-DpwdwX03.js";
3
2
  // src/generator/zod/type.ts
4
3
  /** The TypeScript type declared beside a recursive Zod schema. */
5
4
  function type(schema, rootName = DEFAULT_ROOT_NAME) {
@@ -19,6 +18,11 @@ function type(schema, rootName = DEFAULT_ROOT_NAME) {
19
18
  function zodWireNumber(kind, inner) {
20
19
  return `z.preprocess((val)=>typeof val==='string'&&${kind === "integer" ? integerWirePattern() : numberWirePattern()}.test(val)?Number(val):val,${inner})`;
21
20
  }
21
+ /** Two chained checks as one, or `undefined` when neither is there. */
22
+ function joinChecks(first, second) {
23
+ if (first === void 0) return second;
24
+ return second === void 0 ? first : `${first}${second}`;
25
+ }
22
26
  /**
23
27
  * Generates a Zod schema for number types (number / float32 / float64), with
24
28
  * min/max/multipleOf constraints and `x-*-message` vendor extensions translated
@@ -39,30 +43,28 @@ function number(schema, options) {
39
43
  const minErrorPart = minErrorArg ? `,${minErrorArg}` : "";
40
44
  const exMinErrorArg = exclusiveMinMessage ? zodError(exclusiveMinMessage) : "";
41
45
  const exMinErrorPart = exMinErrorArg ? `,${exMinErrorArg}` : "";
42
- const minimum = (() => {
46
+ const minimum = joinChecks((() => {
43
47
  if (schema.minimum !== void 0) {
44
48
  if (schema.minimum === 0 && schema.exclusiveMinimum === true) return `.positive(${exMinErrorArg})`;
45
49
  if (schema.minimum === 0 && schema.exclusiveMinimum === false) return `.nonnegative(${minErrorArg})`;
46
50
  if (schema.exclusiveMinimum === true) return `.gt(${schema.minimum}${exMinErrorPart})`;
47
51
  return `.min(${schema.minimum}${minErrorPart})`;
48
52
  }
49
- if (typeof schema.exclusiveMinimum === "number") return `.gt(${schema.exclusiveMinimum}${exMinErrorPart})`;
50
- })();
53
+ })(), typeof schema.exclusiveMinimum === "number" ? `.gt(${schema.exclusiveMinimum}${exMinErrorPart})` : void 0);
51
54
  const maximumMessage = schema["x-maximum-message"];
52
55
  const exclusiveMaxMessage = schema["x-exclusiveMaximum-message"];
53
56
  const maxErrorArg = maximumMessage ? zodError(maximumMessage) : "";
54
57
  const maxErrorPart = maxErrorArg ? `,${maxErrorArg}` : "";
55
58
  const exMaxErrorArg = exclusiveMaxMessage ? zodError(exclusiveMaxMessage) : "";
56
59
  const exMaxErrorPart = exMaxErrorArg ? `,${exMaxErrorArg}` : "";
57
- const maximum = (() => {
60
+ const maximum = joinChecks((() => {
58
61
  if (schema.maximum !== void 0) {
59
62
  if (schema.maximum === 0 && schema.exclusiveMaximum === true) return `.negative(${exMaxErrorArg})`;
60
63
  if (schema.maximum === 0 && schema.exclusiveMaximum === false) return `.nonpositive(${maxErrorArg})`;
61
64
  if (schema.exclusiveMaximum === true) return `.lt(${schema.maximum}${exMaxErrorPart})`;
62
65
  return `.max(${schema.maximum}${maxErrorPart})`;
63
66
  }
64
- if (typeof schema.exclusiveMaximum === "number") return `.lt(${schema.exclusiveMaximum}${exMaxErrorPart})`;
65
- })();
67
+ })(), typeof schema.exclusiveMaximum === "number" ? `.lt(${schema.exclusiveMaximum}${exMaxErrorPart})` : void 0);
66
68
  const multipleOfMessage = schema["x-multipleOf-message"];
67
69
  const multipleOfErrorArg = multipleOfMessage ? `,${zodError(multipleOfMessage)}` : baseErrorArg ? `,${baseErrorArg}` : "";
68
70
  const innerChain = [
@@ -121,28 +123,26 @@ function integer(node, options) {
121
123
  const minErrorPart = minErrorArg ? `,${minErrorArg}` : "";
122
124
  const exMinErrorArg = exclusiveMinMessage ? zodError(exclusiveMinMessage) : "";
123
125
  const exMinErrorPart = exMinErrorArg ? `,${exMinErrorArg}` : "";
124
- const minimum = (() => {
125
- if (schema.minimum === void 0 && schema.exclusiveMinimum === void 0) return;
126
- const value = schema.minimum ?? schema.exclusiveMinimum;
127
- if (value === 0 && schema.exclusiveMinimum === true) return `.positive(${exMinErrorArg})`;
128
- if (value === 0 && schema.exclusiveMinimum === false) return `.nonnegative(${minErrorArg})`;
129
- if ((schema.exclusiveMinimum === true || schema.minimum === void 0) && typeof value === "number") return `.gt(${lit(value)}${exMinErrorPart})`;
130
- if (typeof schema.minimum === "number") return `.min(${lit(schema.minimum)}${minErrorPart})`;
131
- })();
126
+ const minimum = joinChecks((() => {
127
+ if (typeof schema.minimum !== "number") return void 0;
128
+ if (schema.minimum === 0 && schema.exclusiveMinimum === true) return `.positive(${exMinErrorArg})`;
129
+ if (schema.minimum === 0 && schema.exclusiveMinimum === false) return `.nonnegative(${minErrorArg})`;
130
+ if (schema.exclusiveMinimum === true) return `.gt(${lit(schema.minimum)}${exMinErrorPart})`;
131
+ return `.min(${lit(schema.minimum)}${minErrorPart})`;
132
+ })(), typeof schema.exclusiveMinimum === "number" ? `.gt(${lit(schema.exclusiveMinimum)}${exMinErrorPart})` : void 0);
132
133
  const maximumMessage = schema["x-maximum-message"] ?? errorMessage;
133
134
  const exclusiveMaxMessage = schema["x-exclusiveMaximum-message"] ?? errorMessage;
134
135
  const maxErrorArg = maximumMessage ? zodError(maximumMessage) : "";
135
136
  const maxErrorPart = maxErrorArg ? `,${maxErrorArg}` : "";
136
137
  const exMaxErrorArg = exclusiveMaxMessage ? zodError(exclusiveMaxMessage) : "";
137
138
  const exMaxErrorPart = exMaxErrorArg ? `,${exMaxErrorArg}` : "";
138
- const maximum = (() => {
139
- if (schema.maximum === void 0 && schema.exclusiveMaximum === void 0) return;
140
- const value = schema.maximum ?? schema.exclusiveMaximum;
141
- if (value === 0 && schema.exclusiveMaximum === true) return `.negative(${exMaxErrorArg})`;
142
- if (value === 0 && schema.exclusiveMaximum === false) return `.nonpositive(${maxErrorArg})`;
143
- if ((schema.exclusiveMaximum === true || schema.maximum === void 0) && typeof value === "number") return `.lt(${lit(value)}${exMaxErrorPart})`;
144
- if (typeof schema.maximum === "number") return `.max(${lit(schema.maximum)}${maxErrorPart})`;
145
- })();
139
+ const maximum = joinChecks((() => {
140
+ if (typeof schema.maximum !== "number") return void 0;
141
+ if (schema.maximum === 0 && schema.exclusiveMaximum === true) return `.negative(${exMaxErrorArg})`;
142
+ if (schema.maximum === 0 && schema.exclusiveMaximum === false) return `.nonpositive(${maxErrorArg})`;
143
+ if (schema.exclusiveMaximum === true) return `.lt(${lit(schema.maximum)}${exMaxErrorPart})`;
144
+ return `.max(${lit(schema.maximum)}${maxErrorPart})`;
145
+ })(), typeof schema.exclusiveMaximum === "number" ? `.lt(${lit(schema.exclusiveMaximum)}${exMaxErrorPart})` : void 0);
146
146
  const multipleOfMessage = schema["x-multipleOf-message"] ?? errorMessage;
147
147
  const multipleOfErrorArg = zodErrorPart(multipleOfMessage);
148
148
  const multipleOf = schema.multipleOf !== void 0 ? `.multipleOf(${lit(schema.multipleOf)}${multipleOfErrorArg})` : void 0;
@@ -187,7 +187,7 @@ function integer(node, options) {
187
187
  function lit(v, isBigint) {
188
188
  if (v === null) return "null";
189
189
  if (typeof v === "string") return `'${v.replaceAll("'", "\\'")}'`;
190
- if (typeof v === "number" && isBigint) return `${v}n`;
190
+ if (typeof v === "number" && isBigint) return bigintValueLiteral(v);
191
191
  if (typeof v === "number" || typeof v === "boolean") return String(v);
192
192
  return JSON.stringify(v) ?? "null";
193
193
  }
@@ -710,7 +710,7 @@ function node(schema, rootName, isZod, options) {
710
710
  const value = schema.const;
711
711
  const constMessage = schema["x-const-message"] ?? schema["x-error-message"];
712
712
  const errorPart = zodErrorPart(constMessage);
713
- const literal = typeof value === "number" && isInt64(schema) ? `z.literal(${value}n${errorPart})` : isPrimitive(value) ? `z.literal(${JSON.stringify(value)}${errorPart})` : `z.custom<${JSON.stringify(value)}>((input) => ${deepEqualExpression(value, "input")}${errorPart})`;
713
+ const literal = typeof value === "number" && isInt64(schema) ? `z.literal(${bigintValueLiteral(value)}${errorPart})` : isPrimitive(value) ? `z.literal(${JSON.stringify(value)}${errorPart})` : `z.custom<${JSON.stringify(value)}>((input) => ${deepEqualExpression(value, "input")}${errorPart})`;
714
714
  return zodWrap$1(literalInput([value], literal) ?? literal, schema);
715
715
  }
716
716
  if (schema.enum) {
package/dist/zod.js CHANGED
@@ -1 +1 @@
1
- export { t as schemaToZod } from "./zod-Cvj9YJY_.js";
1
+ export { t as schemaToZod } from "./zod-xz1vNbs5.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "schema-truth",
3
- "version": "0.8.13",
3
+ "version": "0.8.14",
4
4
  "description": "Generate Zod/Valibot/Effect/TypeBox/ArkType/Ajv/Yup schemas from JSON or YAML files",
5
5
  "keywords": [
6
6
  "ajv",
@@ -1,70 +0,0 @@
1
- // src/helper/bigint.ts
2
- /** A bigint literal, `5n`, spelled in digits however the number prints. */
3
- function bigintLiteral(n) {
4
- return `${BigInt(n)}n`;
5
- }
6
- /**
7
- * A `BigInt(5)` call, the spelling `format: bigint` has always used. A divisor a number
8
- * cannot hold exactly is written as a literal, `12345678901234567n`, which keeps every digit.
9
- */
10
- function bigintCall(n) {
11
- return typeof n === "bigint" ? `${n}n` : `BigInt(${n})`;
12
- }
13
- /**
14
- * A bigint check takes an integer, but a schema's bound can be fractional: `BigInt(0.5)`
15
- * throws a `RangeError` and `0.5n` does not parse. A fractional bound is rounded to the
16
- * integer that admits the same bigints: an inclusive minimum and an exclusive maximum
17
- * round up, an inclusive maximum and an exclusive minimum round down. A non-finite bound
18
- * (a YAML `.inf`) is left out; `sanitizeSchema` drops it before the generator anyway.
19
- */
20
- function bigintBound(value, round) {
21
- return value !== void 0 && Number.isFinite(value) ? Math[round](value) : void 0;
22
- }
23
- /**
24
- * The positive integer divisor a bigint `multipleOf` check can use. An integer is taken as
25
- * it is (`BigInt(value)` is exact for any integer a number holds), and a negative one by its
26
- * absolute value, which has the same multiples. A bigint `x` is a multiple of `p / q` (in
27
- * lowest terms) exactly when it is a multiple of `p`, so a fraction reduces to its
28
- * numerator: 2.5 is 5/2 and becomes `5`. The fraction is read from the number's shortest
29
- * decimal spelling. Zero or a non-finite divisor has no such integer and is left out (a
30
- * bigint `% 0n` throws). A reduced divisor a number cannot hold exactly stays a bigint.
31
- */
32
- function bigintDivisor(value) {
33
- if (typeof value !== "number" || !Number.isFinite(value) || value === 0) return void 0;
34
- const magnitude = Math.abs(value);
35
- if (Number.isInteger(magnitude)) return magnitude;
36
- const match = /^(\d+)(?:\.(\d+))?(?:e-(\d+))?$/.exec(String(magnitude));
37
- if (!match) return void 0;
38
- const [, whole = "", fraction = "", exponent = "0"] = match;
39
- const scale = fraction.length + Number(exponent);
40
- const numerator = BigInt(whole + fraction);
41
- let [a, b] = [numerator, 10n ** BigInt(scale)];
42
- while (b !== 0n) [a, b] = [b, a % b];
43
- const divisor = numerator / a;
44
- return BigInt(Number(divisor)) === divisor ? Number(divisor) : divisor;
45
- }
46
- /**
47
- * The schema with its bounds and `multipleOf` made integers a bigint check can take: see
48
- * {@link bigintBound} and {@link bigintDivisor}. A bound or divisor that has no such
49
- * integer is left out, together with the draft-04 boolean or the message that belongs to it.
50
- */
51
- function bigintBounds(schema) {
52
- const { minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, "x-multipleOf-message": multipleOfMessage, ...rest } = schema;
53
- const isExclusiveMin = exclusiveMinimum === true;
54
- const isExclusiveMax = exclusiveMaximum === true;
55
- const min = bigintBound(minimum, isExclusiveMin ? "floor" : "ceil");
56
- const max = bigintBound(maximum, isExclusiveMax ? "ceil" : "floor");
57
- const exMin = typeof exclusiveMinimum === "number" ? bigintBound(exclusiveMinimum, "floor") : min !== void 0 ? exclusiveMinimum : void 0;
58
- const exMax = typeof exclusiveMaximum === "number" ? bigintBound(exclusiveMaximum, "ceil") : max !== void 0 ? exclusiveMaximum : void 0;
59
- const divisor = bigintDivisor(multipleOf);
60
- return {
61
- ...rest,
62
- ...min !== void 0 && { minimum: min },
63
- ...max !== void 0 && { maximum: max },
64
- ...exMin !== void 0 && { exclusiveMinimum: exMin },
65
- ...exMax !== void 0 && { exclusiveMaximum: exMax },
66
- ...divisor !== void 0 && { multipleOf: divisor },
67
- ...divisor !== void 0 && multipleOfMessage !== void 0 && { "x-multipleOf-message": multipleOfMessage }
68
- };
69
- }
70
- export { bigintCall as n, bigintLiteral as r, bigintBounds as t };