schema-truth 0.8.2 → 0.8.4

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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -2
  3. package/dist/{ajv-DS9gtNZC.js → ajv-DejgT2o1.js} +8 -14
  4. package/dist/ajv.d.ts +2 -4
  5. package/dist/ajv.js +1 -1
  6. package/dist/{arktype-CBV4bg-0.js → arktype-CzTltPwP.js} +9 -17
  7. package/dist/arktype.d.ts +3 -5
  8. package/dist/arktype.js +1 -1
  9. package/dist/cli/ajv.d.ts +0 -0
  10. package/dist/cli/ajv.js +3 -4
  11. package/dist/cli/arktype.d.ts +0 -0
  12. package/dist/cli/arktype.js +3 -4
  13. package/dist/cli/effect.d.ts +0 -0
  14. package/dist/cli/effect.js +3 -4
  15. package/dist/cli/typebox.d.ts +0 -0
  16. package/dist/cli/typebox.js +3 -4
  17. package/dist/cli/valibot.d.ts +0 -0
  18. package/dist/cli/valibot.js +3 -4
  19. package/dist/cli/yup.d.ts +0 -0
  20. package/dist/cli/yup.js +3 -4
  21. package/dist/cli/zod.d.ts +0 -0
  22. package/dist/cli/zod.js +3 -4
  23. package/dist/{cli-CB9GJ7qa.js → cli-CGTme770.js} +6 -9
  24. package/dist/{effect-D9pvwi_6.js → effect-Dj8qARFi.js} +21 -22
  25. package/dist/effect.d.ts +3 -5
  26. package/dist/effect.js +1 -1
  27. package/dist/{helper-S7SSsYwh.js → helper-WSNbEQKr.js} +1344 -52
  28. package/dist/{index-G7UqNQ4w.d.ts → index-DLVjyrKu.d.ts} +0 -14
  29. package/dist/{index-EK43HM_z.d.ts → index-DU2Nd8eI.d.ts} +1 -5
  30. package/dist/index.d.ts +2 -20
  31. package/dist/index.js +9 -9
  32. package/dist/{parser-CyJ2auea.js → parser-RBrkz7ZL.js} +2 -4
  33. package/dist/{typebox-DGGKJLdP.js → typebox-RAJnIZwI.js} +9 -17
  34. package/dist/typebox.d.ts +3 -5
  35. package/dist/typebox.js +1 -1
  36. package/dist/{valibot-B6y4VQFF.js → valibot-CLUhG6tp.js} +12 -21
  37. package/dist/valibot.d.ts +3 -5
  38. package/dist/valibot.js +1 -1
  39. package/dist/{yup-DuqQwHUv.js → yup-DfE_ofEu.js} +9 -15
  40. package/dist/yup.d.ts +3 -5
  41. package/dist/yup.js +1 -1
  42. package/dist/{zod-CXo9NFuF.js → zod-BhYAQ3iW.js} +12 -22
  43. package/dist/zod.d.ts +3 -5
  44. package/dist/zod.js +1 -1
  45. package/package.json +17 -15
  46. package/dist/utils-Bky98UmP.js +0 -1146
@@ -1,6 +1,5 @@
1
- import { At as UNSAFE_GENERATED_MARKER, B as isSchemaObject, D as isComposite, F as isPrimitive, H as isStringWireLocation, M as isNullable, N as isObjectPrototypeProperty, P as isPlainObject, S as hasFixedLength, T as hasType, V as isShapelessMember, X as DEFAULT_ROOT_NAME, b as hasConditional, c as normalizeTypes, g as zodErrorPart, h as zodError, j as isNullTypeMember, k as isDefaultOnlyMember, m as zodBaseError, o as issueMessageExpression, s as makeSafeKey, st as ISO_4217_CURRENCY_CODES, y as hasCombinator } from "./utils-Bky98UmP.js";
2
- import { A as wireNullText, B as emitOptionsOf, C as isPrimitiveUnion, G as schemaNamer, H as planDocument, J as hasRootSelfReference, K as discriminatedMembers, O as unionPrimitiveTypes, P as timePattern, S as isNullTextRead, U as renderDefinitions, W as rootNameOf, X as itemsSchemaOf, at as foldAllOfMembers, b as integerWirePattern, c as withPolymorphicBases, ct as regexLiteral, d as propertyEmitOptions, f as withoutParameterSerialization, g as hoistNestedRefs, h as valueListLiteral, i as isEvaluatedKeyExpression, it as constraintPredicate, j as wireNumericKind, k as wireArrayOnce, l as hasParameterSerialization, m as notPredicate, o as typeDeclaration, ot as isKeywordOnlyMember, p as isBigintFormat, r as evaluatedProperties, rt as constraintMessage, s as refTarget, t as zodWrap, tt as findCodeExtensionKeysInSchema, u as parameterReaders, w as numberWirePattern, x as isNullMatchedFirst, y as impliedWireType, z as definitionsOf } from "./helper-S7SSsYwh.js";
3
- //#region src/generator/zod/type.ts
1
+ import { A as wireArrayOnce, At as hasFixedLength, Bt as isObjectPrototypeProperty, C as isNullTextRead, Dt as hasCombinator, Et as zodErrorPart, F as timePattern, Ft as isComposite, G as renderDefinitions, H as emitOptionsOf, Ht as isPrimitive, I as deepEqualExpression, In as UNSAFE_GENERATED_MARKER, J as discriminatedMembers, Jt as isStringWireLocation, K as rootNameOf, Kt as isSchemaObject, Lt as isDefaultOnlyMember, M as wireNumericKind, Nt as hasType, Ot as hasConditional, Q as itemsSchemaOf, Rt as isNullTypeMember, S as isNullMatchedFirst, T as numberWirePattern, Tt as zodError, V as definitionsOf, Vt as isPlainObject, W as planDocument, X as hasRootSelfReference, _ as hoistNestedRefs, _t as makeSafeKey, at as constraintMessage, b as impliedWireType, c as refTarget, ct as isKeywordOnlyMember, d as parameterReaders, f as propertyEmitOptions, g as valueListLiteral, gt as issueMessageExpression, h as notPredicate, i as isEvaluatedKeyExpression, j as wireNullText, k as unionPrimitiveTypes, l as withPolymorphicBases, m as isBigintFormat, nn as DEFAULT_ROOT_NAME, o as typeDeclaration, ot as constraintPredicate, p as withoutParameterSerialization, pn as ISO_4217_CURRENCY_CODES, q as schemaNamer, qt as isShapelessMember, r as evaluatedProperties, rt as findCodeExtensionKeysInSchema, s as sanitizeSchema, st as foldAllOfMembers, t as zodWrap, u as hasParameterSerialization, ut as regexLiteral, vt as normalizeTypes, w as isPrimitiveUnion, wt as zodBaseError, x as integerWirePattern, zt as isNullable } from "./helper-WSNbEQKr.js";
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) {
6
5
  return typeDeclaration(schema, {
@@ -8,8 +7,7 @@ function type(schema, rootName = DEFAULT_ROOT_NAME) {
8
7
  readonly: false
9
8
  }, rootName);
10
9
  }
11
- //#endregion
12
- //#region src/generator/zod/number.ts
10
+ // src/generator/zod/number.ts
13
11
  /**
14
12
  * Wire text checked against the integer or JSON number grammar, then read with `Number`.
15
13
  * `z.coerce.number()` uses `Number` on its own, which accepts `""`, `" "` and `"0x10"`.
@@ -73,8 +71,7 @@ function number(schema, options) {
73
71
  if (isCoerce && (isFloat32 || isFloat64)) return `z.coerce.number(${baseErrorArg}).pipe(${innerChain})`;
74
72
  return innerChain;
75
73
  }
76
- //#endregion
77
- //#region src/generator/zod/integer.ts
74
+ // src/generator/zod/integer.ts
78
75
  /** Whether a node is a 64-bit integer: a value beyond 2^53 that Zod reads as a bigint. */
79
76
  function isInt64(schema) {
80
77
  return schema.format === "int64" || schema.format === "uint64";
@@ -165,8 +162,7 @@ function integer(schema, options) {
165
162
  if (is64) return `${int64Input(readsText, baseErrorArg)}.pipe(${innerChain})`;
166
163
  return innerChain;
167
164
  }
168
- //#endregion
169
- //#region src/generator/zod/enum.ts
165
+ // src/generator/zod/enum.ts
170
166
  /**
171
167
  * Generates a Zod enum schema. String enums map to `z.enum`, number/integer/
172
168
  * boolean enums to `z.union([z.literal(...), ...])`, array enums to `z.tuple`
@@ -217,8 +213,7 @@ function _enum(schema) {
217
213
  if (schema.enum.length > 1) return `z.union([${schema.enum.map(innerLit).join(",")}]${errorArg})`;
218
214
  return outerLit(schema.enum[0]);
219
215
  }
220
- //#endregion
221
- //#region src/generator/zod/object.ts
216
+ // src/generator/zod/object.ts
222
217
  /**
223
218
  * A parameter object answers an `Object.prototype` name it was not sent with the inherited
224
219
  * member. Copied onto a null-prototype object, it holds only what the request carried.
@@ -317,8 +312,7 @@ function object(schema, rootName, isZod, options) {
317
312
  const hasInheritedName = Object.keys(properties).some(isObjectPrototypeProperty);
318
313
  return isStringWireLocation(options?.paramIn) && hasInheritedName ? `z.preprocess(${OWN_PROPERTIES_PREPROCESS},${objectExpr})` : objectExpr;
319
314
  }
320
- //#endregion
321
- //#region src/generator/zod/parameter.ts
315
+ // src/generator/zod/parameter.ts
322
316
  /**
323
317
  * Wraps the root expression of a parameter's schema in what reads the parameter's
324
318
  * serialization: `allowEmptyValue`, a JSON `content`, or its `style` / `explode`.
@@ -328,8 +322,7 @@ function object(schema, rootName, isZod, options) {
328
322
  function parameter(schema, inner, options) {
329
323
  return parameterReaders(schema, options, "val").reduceRight((acc, step) => `z.preprocess(${step},${acc})`, inner);
330
324
  }
331
- //#endregion
332
- //#region src/generator/zod/string.ts
325
+ // src/generator/zod/string.ts
333
326
  /** The formats Zod checks with a top-level validator, keyed by the lower-cased format. */
334
327
  const FORMAT_STRING = {
335
328
  email: "email()",
@@ -529,8 +522,7 @@ function string(schema) {
529
522
  if (transforms !== "") return `z.string(${baseErrorArg})${transforms}.pipe(${formatBase}${restChecks})`;
530
523
  return `${formatBase}${restChecks}`;
531
524
  }
532
- //#endregion
533
- //#region src/generator/zod/zod.ts
525
+ // src/generator/zod/zod.ts
534
526
  /**
535
527
  * Zod v4 issue codes, in the order `zod/v4/core/errors.d.ts` declares them. The
536
528
  * `x-allOf-message` wrapper matches each in turn and replaces its message.
@@ -710,7 +702,7 @@ function node(schema, rootName, isZod, options) {
710
702
  const value = schema.const;
711
703
  const constMessage = schema["x-const-message"] ?? schema["x-error-message"];
712
704
  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)}>()`;
705
+ 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})`;
714
706
  const input = literalInput([value]);
715
707
  return zodWrap$1(input ? `${input}.pipe(${literal})` : literal, schema);
716
708
  }
@@ -817,14 +809,13 @@ function node(schema, rootName, isZod, options) {
817
809
  if (typeof schema.additionalProperties === "object") return readonly(zodWrap$1(object(schema, rootName, isZod, options), schema));
818
810
  return zodWrap$1("z.any()", schema);
819
811
  }
820
- //#endregion
821
- //#region src/generator/zod/index.ts
812
+ // src/generator/zod/index.ts
822
813
  /**
823
814
  * A whole JSON Schema document as a Zod module: imports, `$defs` in dependency order,
824
815
  * the root export, and the inferred type.
825
816
  */
826
817
  function schemaToZod(input, options) {
827
- const schema = withPolymorphicBases(hoistNestedRefs(input));
818
+ const schema = withPolymorphicBases(hoistNestedRefs(sanitizeSchema(input)));
828
819
  const exportType = options?.exportType ?? true;
829
820
  const baseOptions = emitOptionsOf(options);
830
821
  const codeExtensionsPresent = baseOptions.unsafeCodeExtensions === true && findCodeExtensionKeysInSchema(schema).length > 0;
@@ -850,5 +841,4 @@ function schemaToZod(input, options) {
850
841
  ...exportType ? [`export type ${rootName} = z.infer<typeof ${rootName}>`] : []
851
842
  ].filter(Boolean).join("\n\n");
852
843
  }
853
- //#endregion
854
844
  export { zod as i, forwardIssue as n, nestedIssueMessageWrap as r, schemaToZod as t };
package/dist/zod.d.ts CHANGED
@@ -1,9 +1,7 @@
1
- import { r as JSONSchema } from "./index-G7UqNQ4w.js";
2
- import { n as GenerateOptions } from "./index-EK43HM_z.js";
3
- //#region src/generator/zod/index.d.ts
1
+ import { r as JSONSchema } from "./index-DLVjyrKu.js";
2
+ import { n as GenerateOptions } from "./index-DU2Nd8eI.js";
4
3
  /**
5
4
  * A whole JSON Schema document as a Zod module: imports, `$defs` in dependency order,
6
5
  * the root export, and the inferred type.
7
6
  */
8
- export declare function schemaToZod(input: JSONSchema, options?: GenerateOptions): string;
9
- //#endregion
7
+ export declare function schemaToZod(input: JSONSchema, options?: GenerateOptions): string;
package/dist/zod.js CHANGED
@@ -1 +1 @@
1
- export { t as schemaToZod } from "./zod-CXo9NFuF.js";
1
+ export { t as schemaToZod } from "./zod-BhYAQ3iW.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "schema-truth",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "description": "Generate Zod/Valibot/Effect/TypeBox/ArkType/Ajv/Yup schemas from JSON or YAML files",
5
5
  "keywords": [
6
6
  "ajv",
@@ -11,14 +11,15 @@
11
11
  "yup",
12
12
  "zod"
13
13
  ],
14
- "homepage": "https://github.com/nakita628/schema-truth",
14
+ "homepage": "https://github.com/nakita628/truth/tree/main/npm/schema-truth#readme",
15
15
  "bugs": {
16
- "url": "https://github.com/nakita628/schema-truth/issues"
16
+ "url": "https://github.com/nakita628/truth/issues"
17
17
  },
18
18
  "license": "MIT",
19
19
  "repository": {
20
20
  "type": "git",
21
- "url": "git+https://github.com/nakita628/schema-truth.git"
21
+ "url": "git+https://github.com/nakita628/truth.git",
22
+ "directory": "npm/schema-truth"
22
23
  },
23
24
  "bin": {
24
25
  "schema-truth-ajv": "dist/cli/ajv.js",
@@ -94,21 +95,22 @@
94
95
  }
95
96
  },
96
97
  "publishConfig": {
97
- "access": "public"
98
+ "access": "public",
99
+ "provenance": true
100
+ },
101
+ "dependencies": {
102
+ "@apidevtools/json-schema-ref-parser": "^16.0.5",
103
+ "@effect/platform-node": "4.1.2",
104
+ "effect": "4.1.2",
105
+ "oxfmt": "^0.75.0"
106
+ },
107
+ "devDependencies": {
108
+ "@types/node": "26.6.6"
98
109
  },
99
110
  "scripts": {
100
111
  "build": "vp pack",
101
112
  "check": "vp check",
102
113
  "fix": "vp check --fix",
103
114
  "test": "vp test"
104
- },
105
- "dependencies": {
106
- "@apidevtools/json-schema-ref-parser": "^16.0.5",
107
- "@effect/platform-node": "4.0.5",
108
- "effect": "4.0.5",
109
- "oxfmt": "^0.74.0"
110
- },
111
- "devDependencies": {
112
- "@types/node": "26.6.5"
113
115
  }
114
- }
116
+ }