schema-truth 0.8.2 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{ajv-DS9gtNZC.js → ajv-DejgT2o1.js} +8 -14
- package/dist/ajv.d.ts +2 -4
- package/dist/ajv.js +1 -1
- package/dist/{arktype-CBV4bg-0.js → arktype-CzTltPwP.js} +9 -17
- package/dist/arktype.d.ts +3 -5
- package/dist/arktype.js +1 -1
- package/dist/cli/ajv.js +3 -4
- package/dist/cli/arktype.js +3 -4
- package/dist/cli/effect.js +3 -4
- package/dist/cli/typebox.js +3 -4
- package/dist/cli/valibot.js +3 -4
- package/dist/cli/yup.js +3 -4
- package/dist/cli/zod.js +3 -4
- package/dist/{cli-CB9GJ7qa.js → cli-71Np9i5L.js} +6 -9
- package/dist/{effect-D9pvwi_6.js → effect-Dj8qARFi.js} +21 -22
- package/dist/effect.d.ts +3 -5
- package/dist/effect.js +1 -1
- package/dist/{helper-S7SSsYwh.js → helper-WSNbEQKr.js} +1344 -52
- package/dist/{index-G7UqNQ4w.d.ts → index-DLVjyrKu.d.ts} +0 -14
- package/dist/{index-EK43HM_z.d.ts → index-DU2Nd8eI.d.ts} +1 -5
- package/dist/index.d.ts +2 -20
- package/dist/index.js +9 -9
- package/dist/{parser-CyJ2auea.js → parser-RBrkz7ZL.js} +2 -4
- package/dist/{typebox-DGGKJLdP.js → typebox-RAJnIZwI.js} +9 -17
- package/dist/typebox.d.ts +3 -5
- package/dist/typebox.js +1 -1
- package/dist/{valibot-B6y4VQFF.js → valibot-CLUhG6tp.js} +12 -21
- package/dist/valibot.d.ts +3 -5
- package/dist/valibot.js +1 -1
- package/dist/{yup-DuqQwHUv.js → yup-DfE_ofEu.js} +9 -15
- package/dist/yup.d.ts +3 -5
- package/dist/yup.js +1 -1
- package/dist/{zod-CXo9NFuF.js → zod-BhYAQ3iW.js} +12 -22
- package/dist/zod.d.ts +3 -5
- package/dist/zod.js +1 -1
- package/package.json +5 -5
- package/dist/utils-Bky98UmP.js +0 -1146
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { At as
|
|
2
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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-
|
|
2
|
-
import { n as GenerateOptions } from "./index-
|
|
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-
|
|
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.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"description": "Generate Zod/Valibot/Effect/TypeBox/ArkType/Ajv/Yup schemas from JSON or YAML files",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ajv",
|
|
@@ -104,11 +104,11 @@
|
|
|
104
104
|
},
|
|
105
105
|
"dependencies": {
|
|
106
106
|
"@apidevtools/json-schema-ref-parser": "^16.0.5",
|
|
107
|
-
"@effect/platform-node": "4.
|
|
108
|
-
"effect": "4.
|
|
109
|
-
"oxfmt": "^0.
|
|
107
|
+
"@effect/platform-node": "4.1.1",
|
|
108
|
+
"effect": "4.1.1",
|
|
109
|
+
"oxfmt": "^0.75.0"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
|
-
"@types/node": "26.6.
|
|
112
|
+
"@types/node": "26.6.6"
|
|
113
113
|
}
|
|
114
114
|
}
|