schema-truth 0.8.8 → 0.8.10
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/dist/{ajv-B4_v47gT.js → ajv-Oz83L2oz.js} +1 -1
- package/dist/ajv.js +1 -1
- package/dist/{arktype-C3NDHHVK.js → arktype-DDbxpolC.js} +26 -26
- package/dist/arktype.js +1 -1
- package/dist/cli/ajv.js +2 -2
- package/dist/cli/arktype.js +2 -2
- package/dist/cli/effect.js +2 -2
- package/dist/cli/typebox.js +2 -2
- package/dist/cli/valibot.js +2 -2
- package/dist/cli/yup.js +2 -2
- package/dist/cli/zod.js +2 -2
- package/dist/{cli-CS_1z6nJ.js → cli-C90ppADh.js} +8 -8
- package/dist/{effect-BFmI1iE2.js → effect-CHLS1Yit.js} +18 -18
- package/dist/effect.js +1 -1
- package/dist/{helper-C-PSZHCx.js → helper-OCkRyx4U.js} +47 -49
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -8
- package/dist/{typebox-D8PiVdQo.js → typebox-DNkk6MCh.js} +39 -15
- package/dist/typebox.js +1 -1
- package/dist/{valibot-LwlmJZa1.js → valibot-Vj1GeCcx.js} +19 -19
- package/dist/valibot.js +1 -1
- package/dist/{yup-CkaQI_2s.js → yup-DKlaai37.js} +1 -1
- package/dist/yup.js +1 -1
- package/dist/{zod-CHHsf7VI.js → zod-04J51AMt.js} +22 -22
- package/dist/zod.js +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { s as sanitizeSchema, vt as makeSafeKey, yt as normalizeTypes } from "./helper-
|
|
1
|
+
import { s as sanitizeSchema, vt as makeSafeKey, yt as normalizeTypes } from "./helper-OCkRyx4U.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-
|
|
1
|
+
export { t as schemaToAjv } from "./ajv-Oz83L2oz.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as itemsSchemaOf, A as wireArrayOnce, At as hasFixedItemCount, Bt as isNullable, C as isNullTextRead, D as stringboolPattern, E as ownProperties, Ft as isArktypeDefinition, H as emitOptionsOf, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, Kt as isRootRef, Ln as UNSAFE_GENERATED_MARKER, Lt as isDeepLocalPointer, M as wireNumericKind, N as formatPattern, O as stringboolTruthyPattern, Ot as hasCombinator, P as regexSource, S as isNullMatchedFirst, T as numberWirePattern, U as missingDefinitionComment, V as definitionsOf, Vt as isObjectPrototypeProperty, W as planDocument, Wt as isQuoted, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, _t as issueMessageExpression, b as impliedWireType, bn as NUMBER_RANGES, bt as resolveOpenAPIRef, ct as foldAllOfMembers, d as parameterReaders, dt as regexLiteral, et as arktypePreprocess, f as propertyEmitOptions, fn as INTEGER_TEXT_PATTERN, g as valueListLiteral, h as notPredicate, i as isEvaluatedKeyExpression, it as findCodeExtensionKeysInSchema, j as wireNullText, jt as hasFixedLength, k as unionPrimitiveTypes, kn as QUOTE_OR_BACKSLASH_PATTERN, l as withPolymorphicBases, lt as isKeywordOnlyMember, m as isBigintFormat, nt as callbackReturn, on as DEFINITION_REF_PREFIXES, ot as constraintMessage, p as withoutParameterSerialization, q as schemaNamer, qt as isSchemaObject, r as evaluatedProperties, rn as DEFAULT_ROOT_NAME, rt as callbackType, s as sanitizeSchema, st as constraintPredicate, tt as arktypeWrap, u as hasParameterSerialization, vt as makeSafeKey, w as isPrimitiveUnion, x as integerWirePattern, yt as normalizeTypes, zt as isNullTypeMember } from "./helper-
|
|
1
|
+
import { $ as itemsSchemaOf, A as wireArrayOnce, At as hasFixedItemCount, Bt as isNullable, C as isNullTextRead, D as stringboolPattern, E as ownProperties, Ft as isArktypeDefinition, H as emitOptionsOf, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, Kt as isRootRef, Ln as UNSAFE_GENERATED_MARKER, Lt as isDeepLocalPointer, M as wireNumericKind, N as formatPattern, O as stringboolTruthyPattern, Ot as hasCombinator, P as regexSource, S as isNullMatchedFirst, T as numberWirePattern, U as missingDefinitionComment, V as definitionsOf, Vt as isObjectPrototypeProperty, W as planDocument, Wt as isQuoted, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, _t as issueMessageExpression, b as impliedWireType, bn as NUMBER_RANGES, bt as resolveOpenAPIRef, ct as foldAllOfMembers, d as parameterReaders, dt as regexLiteral, et as arktypePreprocess, f as propertyEmitOptions, fn as INTEGER_TEXT_PATTERN, g as valueListLiteral, h as notPredicate, i as isEvaluatedKeyExpression, it as findCodeExtensionKeysInSchema, j as wireNullText, jt as hasFixedLength, k as unionPrimitiveTypes, kn as QUOTE_OR_BACKSLASH_PATTERN, l as withPolymorphicBases, lt as isKeywordOnlyMember, m as isBigintFormat, nt as callbackReturn, on as DEFINITION_REF_PREFIXES, ot as constraintMessage, p as withoutParameterSerialization, q as schemaNamer, qt as isSchemaObject, r as evaluatedProperties, rn as DEFAULT_ROOT_NAME, rt as callbackType, s as sanitizeSchema, st as constraintPredicate, tt as arktypeWrap, u as hasParameterSerialization, vt as makeSafeKey, w as isPrimitiveUnion, x as integerWirePattern, yt as normalizeTypes, zt as isNullTypeMember } from "./helper-OCkRyx4U.js";
|
|
2
2
|
// src/generator/arktype/number.ts
|
|
3
3
|
/** The comparators of a numeric node: `>= 1`, `< 5`, `% 2`. */
|
|
4
4
|
function numericConstraints(schema) {
|
|
@@ -301,19 +301,19 @@ function object(schema, rootName, isArktype, options) {
|
|
|
301
301
|
const minPropertiesNarrow = typeof schema.minProperties === "number" ? narrowPredicate(`Object.keys(data).length >= ${schema.minProperties}`, minimumMessage) : "";
|
|
302
302
|
const maxPropertiesNarrow = typeof schema.maxProperties === "number" ? narrowPredicate(`Object.keys(data).length <= ${schema.maxProperties}`, maximumMessage) : "";
|
|
303
303
|
const dependentRequiredNarrows = schema.dependentRequired ? Object.entries(schema.dependentRequired).map(([key, deps]) => {
|
|
304
|
-
return narrowPredicate(`!('${key}' in data) || (${deps.map((
|
|
304
|
+
return narrowPredicate(`!('${key}' in data) || (${deps.map((dependency) => `'${dependency}' in data`).join(" && ")})`, depReqMessage);
|
|
305
305
|
}) : [];
|
|
306
306
|
const dependentSchemasNarrows = schema.dependentSchemas ? Object.entries(schema.dependentSchemas).map(([key, subSchema]) => {
|
|
307
307
|
return narrowPredicate(`!('${key}' in data) || ${callbackType(arktype(subSchema, rootName, isArktype, options), isArktype)}.allows(data)`, depSchMessage);
|
|
308
308
|
}) : [];
|
|
309
309
|
const additionalPropertiesNarrow = schema.additionalProperties === false && (addlPropsMessage !== void 0 || schema.patternProperties !== void 0) ? narrowPredicate(`Object.keys(data).every((key) => ${isEvaluated})`, addlPropsMessage) : "";
|
|
310
310
|
const unevaluatedPropertiesNarrow = (() => {
|
|
311
|
-
const
|
|
312
|
-
if (
|
|
311
|
+
const restSchema = typeof schema.additionalProperties === "object" ? schema.additionalProperties : schema.unevaluatedProperties;
|
|
312
|
+
if (restSchema === void 0 || restSchema === true) return "";
|
|
313
313
|
const message = typeof schema.additionalProperties === "object" ? addlPropsMessage : unevalPropsRawMessage;
|
|
314
|
-
if (
|
|
315
|
-
if (typeof
|
|
316
|
-
const s = callbackType(arktype(
|
|
314
|
+
if (restSchema === false) return narrowPredicate(`Object.keys(data).every((key) => ${isEvaluated})`, message);
|
|
315
|
+
if (typeof restSchema === "object") {
|
|
316
|
+
const s = callbackType(arktype(restSchema, rootName, isArktype, options), isArktype);
|
|
317
317
|
return narrowPredicate(`Object.entries(data).every(([key, value]) => ${isEvaluated} || ${s}.allows(value))`, message);
|
|
318
318
|
}
|
|
319
319
|
return "";
|
|
@@ -419,7 +419,7 @@ function string(schema) {
|
|
|
419
419
|
schema["x-toLowerCase"] === true || transformFormat === "string.lower" ? "string.lower" : void 0,
|
|
420
420
|
schema["x-toUpperCase"] === true || transformFormat === "string.upper" ? "string.upper" : void 0,
|
|
421
421
|
typeof schema["x-normalize"] === "string" ? `string.normalize.${schema["x-normalize"]}` : void 0
|
|
422
|
-
].filter((
|
|
422
|
+
].filter((transform) => transform !== void 0);
|
|
423
423
|
const format = formatDefinition(schema, transformFormat === void 0 ? formatName : void 0);
|
|
424
424
|
const hasMorph = transforms.length > 0;
|
|
425
425
|
const constrain = (expr, pattern) => hasMorph ? `${expr}.to(${pattern})` : `${expr}.and(${pattern})`;
|
|
@@ -450,7 +450,7 @@ function string(schema) {
|
|
|
450
450
|
const sub = schema["x-includes"];
|
|
451
451
|
narrows.push(`.narrow((data: string, ctx) => data.includes(${JSON.stringify(sub)}) || ctx.mustBe(${JSON.stringify(`must include ${JSON.stringify(sub)}`)}))`);
|
|
452
452
|
}
|
|
453
|
-
const morphed = transforms.reduce((acc,
|
|
453
|
+
const morphed = transforms.reduce((acc, transform) => acc === void 0 ? `type("${transform}")` : `${acc}.to("${transform}")`, void 0);
|
|
454
454
|
const based = morphed === void 0 ? format : format === "\"string\"" ? morphed : validateWith(morphed, format);
|
|
455
455
|
const patterned = schema.pattern && !patternMessage ? constrain(isQuoted(based) ? `type(${based})` : based, regexLiteral(schema.pattern)) : based;
|
|
456
456
|
if (narrows.length === 0 && !errorMessage) return patterned;
|
|
@@ -646,10 +646,10 @@ function node(schema, rootName, isArktype, options) {
|
|
|
646
646
|
const definitions = members.map((s) => s.type === "integer" ? integer(s) : number(s));
|
|
647
647
|
const isInteger = members.some((s) => s.type === "integer");
|
|
648
648
|
return arktypeWrap$1(wireNumeric(isInteger ? numberMorph("isSafeInteger", "an integer") : numberMorph("isFinite", "a number"), definitions.every(isQuoted) ? (() => {
|
|
649
|
-
const parts = definitions.map((
|
|
649
|
+
const parts = definitions.map((definition) => definition.slice(1, -1)).filter((definition) => definition !== "number" && definition !== "number.integer");
|
|
650
650
|
if (parts.length === 0) return isInteger ? "\"number.integer\"" : "\"number\"";
|
|
651
651
|
return `"${parts.join(" & ")}"`;
|
|
652
|
-
})() : definitions.length === 1 ? definitions[0] : intersectionStr(definitions, isArktype)), {
|
|
652
|
+
})() : definitions.length === 1 && definitions[0] !== void 0 ? definitions[0] : intersectionStr(definitions, isArktype)), {
|
|
653
653
|
...schema,
|
|
654
654
|
nullable
|
|
655
655
|
});
|
|
@@ -660,7 +660,7 @@ function node(schema, rootName, isArktype, options) {
|
|
|
660
660
|
nullable
|
|
661
661
|
});
|
|
662
662
|
const intersected = [...schemas, ...objectKeysMembers(schema, rootName, isArktype, options)];
|
|
663
|
-
return arktypeWrap$1(intersected.length === 1 ? intersected[0] : intersectionStr(intersected, isArktype), {
|
|
663
|
+
return arktypeWrap$1(intersected.length === 1 && intersected[0] !== void 0 ? intersected[0] : intersectionStr(intersected, isArktype), {
|
|
664
664
|
...schema,
|
|
665
665
|
nullable
|
|
666
666
|
});
|
|
@@ -711,42 +711,42 @@ function node(schema, rootName, isArktype, options) {
|
|
|
711
711
|
}
|
|
712
712
|
if (schema.properties) return readonly(arktypeWrap$1(object(schema, rootName, isArktype, options), schema));
|
|
713
713
|
const types = normalizeTypes(schema.type);
|
|
714
|
-
const primitive = (
|
|
715
|
-
if (
|
|
716
|
-
if (
|
|
714
|
+
const primitive = (primitiveType) => {
|
|
715
|
+
if (primitiveType === "string") return string(schema);
|
|
716
|
+
if (primitiveType === "number") {
|
|
717
717
|
const definition = number(schema);
|
|
718
718
|
return isWireCoerced ? wireNumeric(numberMorph("isFinite", "a number"), definition) : definition;
|
|
719
719
|
}
|
|
720
|
-
if (
|
|
720
|
+
if (primitiveType === "integer") {
|
|
721
721
|
if (isInt64(schema) || schema.format === "bigint") return integer(schema, { wire: isWireCoerced });
|
|
722
722
|
const definition = integer(schema);
|
|
723
723
|
return isWireCoerced ? wireNumeric(numberMorph("isSafeInteger", "an integer"), definition) : definition;
|
|
724
724
|
}
|
|
725
|
-
if (
|
|
725
|
+
if (primitiveType !== "boolean") return void 0;
|
|
726
726
|
return isWireCoerced ? stringbool() : "\"boolean\"";
|
|
727
727
|
};
|
|
728
728
|
if (isPrimitiveUnion(types, isWireCoerced)) return arktypeWrap$1(unionOf(unionPrimitiveTypes(types, isWireCoerced).map(primitive).filter((m) => m !== void 0), void 0), schema);
|
|
729
|
-
for (const
|
|
729
|
+
for (const primitiveType of [
|
|
730
730
|
"string",
|
|
731
731
|
"number",
|
|
732
732
|
"integer",
|
|
733
733
|
"boolean"
|
|
734
734
|
]) {
|
|
735
|
-
if (!types.includes(
|
|
736
|
-
const expression = primitive(
|
|
735
|
+
if (!types.includes(primitiveType)) continue;
|
|
736
|
+
const expression = primitive(primitiveType);
|
|
737
737
|
if (expression !== void 0) return arktypeWrap$1(expression, schema);
|
|
738
738
|
}
|
|
739
739
|
if (types.includes("array")) {
|
|
740
|
-
if (schema.prefixItems
|
|
740
|
+
if (schema.prefixItems !== void 0 && schema.prefixItems.length > 0) {
|
|
741
741
|
const items = schema.prefixItems.map((s) => arktype(s, rootName, isArktype, options));
|
|
742
|
-
const
|
|
743
|
-
const baseTuple = arktypeWrap$1(wireArray(describeWithMessage(isSchemaObject(
|
|
744
|
-
const rest = arktype(
|
|
742
|
+
const unevaluatedItems = schema.unevaluatedItems;
|
|
743
|
+
const baseTuple = arktypeWrap$1(wireArray(describeWithMessage(isSchemaObject(unevaluatedItems) ? (() => {
|
|
744
|
+
const rest = arktype(unevaluatedItems, rootName, isArktype, options);
|
|
745
745
|
const restInner = isQuoted(rest) ? rest.slice(1, -1) : rest;
|
|
746
746
|
return `type([${items.join(",")},"...","${restInner}[]"])`;
|
|
747
747
|
})() : `type([${items.join(",")}])`, schema["x-prefixItems-message"])), schema);
|
|
748
748
|
const unevalItemsMessage = schema["x-unevaluatedItems-message"];
|
|
749
|
-
return
|
|
749
|
+
return unevaluatedItems === false && unevalItemsMessage ? `${baseTuple}.describe(${JSON.stringify(unevalItemsMessage)})` : baseTuple;
|
|
750
750
|
}
|
|
751
751
|
const itemSchema = itemsSchemaOf(schema.items);
|
|
752
752
|
const items = itemSchema ? arktype(itemSchema, rootName, isArktype, options) : "\"unknown\"";
|
|
@@ -770,7 +770,7 @@ function node(schema, rootName, isArktype, options) {
|
|
|
770
770
|
maxContainsMessage
|
|
771
771
|
].some(Boolean);
|
|
772
772
|
const andWith = (a, b) => isArktype && isArktypeDefinition(a) ? `[${a},"&",${b}]` : `type(${a}).and(type(${b}))`;
|
|
773
|
-
const narrowWith = (a,
|
|
773
|
+
const narrowWith = (a, narrowing) => isArktype && isArktypeDefinition(a) ? `[${a},":",${narrowing}]` : `${isArktypeDefinition(a) ? `type(${a})` : a}.narrow(${narrowing})`;
|
|
774
774
|
const lengthExpr = isFixedLength ? hasArrayMessage ? narrowWith(base, `(data: unknown[], ctx) => data.length === ${minItems} || ctx.mustBe(${JSON.stringify(fixedItemsMessage ?? `must contain exactly ${minItems} items`)})`) : andWith(base, `"unknown[] == ${minItems}"`) : typeof minItems === "number" && typeof maxItems === "number" ? hasArrayMessage ? narrowWith(narrowWith(base, `(data: unknown[], ctx) => data.length >= ${minItems} || ctx.mustBe(${JSON.stringify(minItemsMessage ?? `must contain at least ${minItems} items`)})`), `(data: unknown[], ctx) => data.length <= ${maxItems} || ctx.mustBe(${JSON.stringify(maxItemsMessage ?? `must contain at most ${maxItems} items`)})`) : andWith(base, `"${minItems} <= unknown[] <= ${maxItems}"`) : typeof minItems === "number" ? hasArrayMessage ? narrowWith(base, `(data: unknown[], ctx) => data.length >= ${minItems} || ctx.mustBe(${JSON.stringify(minItemsMessage ?? `must contain at least ${minItems} items`)})`) : andWith(base, `"unknown[] >= ${minItems}"`) : typeof maxItems === "number" ? hasArrayMessage ? narrowWith(base, `(data: unknown[], ctx) => data.length <= ${maxItems} || ctx.mustBe(${JSON.stringify(maxItemsMessage ?? `must contain at most ${maxItems} items`)})`) : andWith(base, `"unknown[] <= ${maxItems}"`) : base;
|
|
775
775
|
const uniqueExpr = schema.uniqueItems === true ? narrowWith(lengthExpr, `(data: unknown[], ctx) => new Set(data).size === data.length${uniqueItemsMessage ? ` || ctx.mustBe(${JSON.stringify(uniqueItemsMessage)})` : ""}`) : lengthExpr;
|
|
776
776
|
return arktypeWrap$1(wireArray(describeWithMessage((() => {
|
package/dist/arktype.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToArktype } from "./arktype-
|
|
1
|
+
export { t as schemaToArktype } from "./arktype-DDbxpolC.js";
|
package/dist/cli/ajv.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as schemaToAjv } from "../ajv-
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
2
|
+
import { t as schemaToAjv } from "../ajv-Oz83L2oz.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-C90ppADh.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/arktype.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as schemaToArktype } from "../arktype-
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
2
|
+
import { t as schemaToArktype } from "../arktype-DDbxpolC.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-C90ppADh.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/effect.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as schemaToEffect } from "../effect-
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
2
|
+
import { t as schemaToEffect } from "../effect-CHLS1Yit.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-C90ppADh.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/typebox.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as schemaToTypebox } from "../typebox-
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
2
|
+
import { t as schemaToTypebox } from "../typebox-DNkk6MCh.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-C90ppADh.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/valibot.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as schemaToValibot } from "../valibot-
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
2
|
+
import { t as schemaToValibot } from "../valibot-Vj1GeCcx.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-C90ppADh.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-
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
2
|
+
import { t as schemaToYup } from "../yup-DKlaai37.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-C90ppADh.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-
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
2
|
+
import { t as schemaToZod } from "../zod-04J51AMt.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-C90ppADh.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 { Gt as isRecord } from "./helper-
|
|
1
|
+
import { Gt as isRecord } from "./helper-OCkRyx4U.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.
|
|
12
|
+
var version = "0.8.10";
|
|
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) {
|
|
@@ -23,11 +23,11 @@ function mkdir(dir) {
|
|
|
23
23
|
* Skipping the identical write keeps a no-op generation from changing mtime. An
|
|
24
24
|
* unreadable existing file falls through to the write rather than failing here.
|
|
25
25
|
*/
|
|
26
|
-
function writeFile(path,
|
|
26
|
+
function writeFile(path, content) {
|
|
27
27
|
return Effect.gen(function* () {
|
|
28
28
|
const fs = yield* FileSystem.FileSystem;
|
|
29
|
-
if ((yield* fs.readFileString(path).pipe(Effect.orElseSucceed(() => null))) ===
|
|
30
|
-
yield* fs.writeFileString(path,
|
|
29
|
+
if ((yield* fs.readFileString(path).pipe(Effect.orElseSucceed(() => null))) === content) return;
|
|
30
|
+
yield* fs.writeFileString(path, content);
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
// src/cli/index.ts
|
|
@@ -70,8 +70,8 @@ function platformCause(error) {
|
|
|
70
70
|
* `mapError` at the end is where all of it turns into rendered CLI output. The
|
|
71
71
|
* `FileSystem` it writes through comes from the environment the caller provides.
|
|
72
72
|
*/
|
|
73
|
-
function generate(generator) {
|
|
74
|
-
return
|
|
73
|
+
function generate(generator, args) {
|
|
74
|
+
return Effect.gen(function* () {
|
|
75
75
|
const schema = yield* parseSchemaFile(args.input);
|
|
76
76
|
const source = yield* fmt(generator(schema, {
|
|
77
77
|
exportType: args.exportType,
|
|
@@ -93,7 +93,7 @@ function generate(generator) {
|
|
|
93
93
|
* from one definition rather than one copy per target that can drift apart.
|
|
94
94
|
*/
|
|
95
95
|
function makeCli(options) {
|
|
96
|
-
return Command.make(options.name, commandLine, generate(options.generator)).pipe(Command.withDescription(options.description), Command.withExamples([
|
|
96
|
+
return Command.make(options.name, commandLine, (args) => generate(options.generator, args)).pipe(Command.withDescription(options.description), Command.withExamples([
|
|
97
97
|
{
|
|
98
98
|
command: `${options.name} schema.json -o src/schema.ts`,
|
|
99
99
|
description: "Generate a schema file"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as itemsSchemaOf, A as wireArrayOnce, At as hasFixedItemCount, Bt as isNullable, C as isNullTextRead, D as stringboolPattern, E as ownProperties, G as renderDefinitions, H as emitOptionsOf, I as deepEqualExpression, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, L as jsLiteral, Ln as UNSAFE_GENERATED_MARKER, M as wireNumericKind, N as formatPattern, O as stringboolTruthyPattern, Ot as hasCombinator, P as regexSource, Pt as hasType, Rt as isDefaultOnlyMember, T as numberWirePattern, V as definitionsOf, Vt as isObjectPrototypeProperty, W as planDocument, X as hasRootSelfReference, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, b as impliedWireType, bn as NUMBER_RANGES, c as refTarget, ct as foldAllOfMembers, d as parameterReaders, dt as regexLiteral, f as propertyEmitOptions, fn as INTEGER_TEXT_PATTERN, g as valueListLiteral, h as notPredicate, ht as effectMessage, i as isEvaluatedKeyExpression, it as findCodeExtensionKeysInSchema, jt as hasFixedLength, k as unionPrimitiveTypes, kt as hasConditional, l as withPolymorphicBases, lt as isKeywordOnlyMember, m as isBigintFormat, mt as effectErrorPart, o as typeDeclaration, ot as constraintMessage, p as withoutParameterSerialization, pt as effectError, q as schemaNamer, qt as isSchemaObject, r as evaluatedProperties, rn as DEFAULT_ROOT_NAME, s as sanitizeSchema, st as constraintPredicate, u as hasParameterSerialization, v as effectPreprocess, vt as makeSafeKey, w as isPrimitiveUnion, x as integerWirePattern, y as effectWrap, yt as normalizeTypes, zt as isNullTypeMember } from "./helper-
|
|
1
|
+
import { $ as itemsSchemaOf, A as wireArrayOnce, At as hasFixedItemCount, Bt as isNullable, C as isNullTextRead, D as stringboolPattern, E as ownProperties, G as renderDefinitions, H as emitOptionsOf, I as deepEqualExpression, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, L as jsLiteral, Ln as UNSAFE_GENERATED_MARKER, M as wireNumericKind, N as formatPattern, O as stringboolTruthyPattern, Ot as hasCombinator, P as regexSource, Pt as hasType, Rt as isDefaultOnlyMember, T as numberWirePattern, V as definitionsOf, Vt as isObjectPrototypeProperty, W as planDocument, X as hasRootSelfReference, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, b as impliedWireType, bn as NUMBER_RANGES, c as refTarget, ct as foldAllOfMembers, d as parameterReaders, dt as regexLiteral, f as propertyEmitOptions, fn as INTEGER_TEXT_PATTERN, g as valueListLiteral, h as notPredicate, ht as effectMessage, i as isEvaluatedKeyExpression, it as findCodeExtensionKeysInSchema, jt as hasFixedLength, k as unionPrimitiveTypes, kt as hasConditional, l as withPolymorphicBases, lt as isKeywordOnlyMember, m as isBigintFormat, mt as effectErrorPart, o as typeDeclaration, ot as constraintMessage, p as withoutParameterSerialization, pt as effectError, q as schemaNamer, qt as isSchemaObject, r as evaluatedProperties, rn as DEFAULT_ROOT_NAME, s as sanitizeSchema, st as constraintPredicate, u as hasParameterSerialization, v as effectPreprocess, vt as makeSafeKey, w as isPrimitiveUnion, x as integerWirePattern, y as effectWrap, yt as normalizeTypes, zt as isNullTypeMember } from "./helper-OCkRyx4U.js";
|
|
2
2
|
// src/generator/effect/number.ts
|
|
3
3
|
/** The bound and `multipleOf` checks of a numeric node. */
|
|
4
4
|
function numberChecks(schema, lit = (n) => `${n}`, suffix = "") {
|
|
@@ -126,7 +126,7 @@ function _enum(schema) {
|
|
|
126
126
|
const lit = (v) => literal(v, isBigint);
|
|
127
127
|
const errorMessage = schema["x-enum-message"] ?? schema["x-error-message"];
|
|
128
128
|
const annotate = (code) => errorMessage ? `${code}.annotate(${effectError(errorMessage)})` : code;
|
|
129
|
-
const tuple = (
|
|
129
|
+
const tuple = (members) => `Schema.Tuple([${members.map((i) => `Schema.Literal(${lit(i)})`).join(",")}])`;
|
|
130
130
|
const literals = (values) => {
|
|
131
131
|
const nonNull = values.filter((v) => v !== null);
|
|
132
132
|
if (nonNull.length === 0) return "Schema.Null";
|
|
@@ -217,7 +217,7 @@ function object(schema, rootName, isEffect, options) {
|
|
|
217
217
|
const minPropertiesFilter = typeof schema.minProperties === "number" ? `Schema.makeFilter((input)=>Object.keys(input).length>=${schema.minProperties}${minErrorArg})` : "";
|
|
218
218
|
const maxPropertiesFilter = typeof schema.maxProperties === "number" ? `Schema.makeFilter((input)=>Object.keys(input).length<=${schema.maxProperties}${maxErrorArg})` : "";
|
|
219
219
|
const dependentRequiredFilters = schema.dependentRequired ? Object.entries(schema.dependentRequired).map(([key, deps]) => {
|
|
220
|
-
return `Schema.makeFilter((input)=>!('${key}' in input)||(${deps.map((
|
|
220
|
+
return `Schema.makeFilter((input)=>!('${key}' in input)||(${deps.map((dependency) => `'${dependency}' in input`).join("&&")})${depReqErrorArg})`;
|
|
221
221
|
}) : [];
|
|
222
222
|
const dependentSchemasFilters = schema.dependentSchemas ? Object.entries(schema.dependentSchemas).map(([key, subSchema]) => {
|
|
223
223
|
return `Schema.makeFilter((input)=>!('${key}' in input)||Schema.is(${effect(subSchema, rootName, isEffect, options)})(input)${depSchErrorArg})`;
|
|
@@ -514,7 +514,7 @@ function node(schema, rootName, isEffect, options) {
|
|
|
514
514
|
...schema,
|
|
515
515
|
nullable
|
|
516
516
|
});
|
|
517
|
-
const intersected = schemas.length === 1 ? schemas[0] : intersect(schemas);
|
|
517
|
+
const intersected = schemas.length === 1 && schemas[0] !== void 0 ? schemas[0] : intersect(schemas);
|
|
518
518
|
const allOfMessage = schema["x-allOf-message"];
|
|
519
519
|
const baseResult = objectKeysCheck(allOfMessage ? wholeValueMessage(intersected, allOfMessage) : intersected, schema, rootName, isEffect, options);
|
|
520
520
|
if (defaultValue !== void 0) return `${nullable ? `Schema.NullOr(${baseResult})` : baseResult}.pipe(${isWireCoerced ? "Schema.withDecodingDefaultType" : "Schema.withDecodingDefault"}(Effect.succeed(${jsLiteral(defaultValue)})))`;
|
|
@@ -561,33 +561,33 @@ function node(schema, rootName, isEffect, options) {
|
|
|
561
561
|
}
|
|
562
562
|
if (schema.properties) return effectWrap$1(object(schema, rootName, isEffect, options), schema);
|
|
563
563
|
const types = normalizeTypes(schema.type);
|
|
564
|
-
const primitive = (
|
|
565
|
-
if (
|
|
566
|
-
if (
|
|
567
|
-
if (
|
|
568
|
-
if (
|
|
564
|
+
const primitive = (primitiveType) => {
|
|
565
|
+
if (primitiveType === "string") return string(schema);
|
|
566
|
+
if (primitiveType === "number") return number(schema, { wire: isWireCoerced });
|
|
567
|
+
if (primitiveType === "integer") return integer(schema, { wire: isWireCoerced });
|
|
568
|
+
if (primitiveType !== "boolean") return void 0;
|
|
569
569
|
const errorMessage = schema["x-error-message"];
|
|
570
570
|
const base = isWireCoerced ? stringbool() : "Schema.Boolean";
|
|
571
571
|
return errorMessage ? `${base}.annotate(${effectError(errorMessage)})` : base;
|
|
572
572
|
};
|
|
573
573
|
if (isPrimitiveUnion(types, isWireCoerced)) return effectWrap$1(`Schema.Union([${unionPrimitiveTypes(types, isWireCoerced).map(primitive).filter((m) => m !== void 0).join(",")}])`, schema);
|
|
574
|
-
for (const
|
|
574
|
+
for (const primitiveType of [
|
|
575
575
|
"string",
|
|
576
576
|
"number",
|
|
577
577
|
"integer",
|
|
578
578
|
"boolean"
|
|
579
579
|
]) {
|
|
580
|
-
if (!types.includes(
|
|
581
|
-
const expression = primitive(
|
|
580
|
+
if (!types.includes(primitiveType)) continue;
|
|
581
|
+
const expression = primitive(primitiveType);
|
|
582
582
|
if (expression !== void 0) return effectWrap$1(expression, schema);
|
|
583
583
|
}
|
|
584
584
|
if (types.includes("array")) {
|
|
585
585
|
const elementMessageWrap = wholeValueMessage;
|
|
586
|
-
if (schema.prefixItems
|
|
586
|
+
if (schema.prefixItems !== void 0 && schema.prefixItems.length > 0) {
|
|
587
587
|
const items = schema.prefixItems.map((s) => effect(s, rootName, isEffect, options));
|
|
588
|
-
const
|
|
588
|
+
const unevaluatedItems = schema.unevaluatedItems;
|
|
589
589
|
const tuple = `Schema.Tuple([${items.join(",")}])`;
|
|
590
|
-
const tupleExpr = isSchemaObject(
|
|
590
|
+
const tupleExpr = isSchemaObject(unevaluatedItems) ? `Schema.TupleWithRest(${tuple},[${effect(unevaluatedItems, rootName, isEffect, options)}])` : tuple;
|
|
591
591
|
const prefixItemsMessage = schema["x-prefixItems-message"];
|
|
592
592
|
return effectWrap$1(wireArray(prefixItemsMessage ? elementMessageWrap(tupleExpr, prefixItemsMessage) : tupleExpr), schema);
|
|
593
593
|
}
|
|
@@ -606,9 +606,9 @@ function node(schema, rootName, isEffect, options) {
|
|
|
606
606
|
const uniqueItemsMessage = schema["x-uniqueItems-message"];
|
|
607
607
|
const uniqueArg = effectErrorPart(uniqueItemsMessage);
|
|
608
608
|
const containsChecks = (() => {
|
|
609
|
-
const
|
|
610
|
-
if (!
|
|
611
|
-
const containsSchema = effect(
|
|
609
|
+
const contains = schema.contains;
|
|
610
|
+
if (!contains) return [];
|
|
611
|
+
const containsSchema = effect(contains, rootName, isEffect, options);
|
|
612
612
|
const minC = schema.minContains;
|
|
613
613
|
const maxC = schema.maxContains;
|
|
614
614
|
const errorMessage = schema["x-error-message"];
|
package/dist/effect.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToEffect } from "./effect-
|
|
1
|
+
export { t as schemaToEffect } from "./effect-CHLS1Yit.js";
|
|
@@ -670,7 +670,7 @@ function isDeepLocalPointer($ref) {
|
|
|
670
670
|
"components/schemas/",
|
|
671
671
|
"definitions/",
|
|
672
672
|
"$defs/"
|
|
673
|
-
].find((
|
|
673
|
+
].find((container) => fragment.startsWith(container));
|
|
674
674
|
return matched ? fragment.slice(matched.length).includes("/") : false;
|
|
675
675
|
}
|
|
676
676
|
/**
|
|
@@ -848,13 +848,13 @@ function toIdentifierPascalCase(name) {
|
|
|
848
848
|
const parts = encodeNonAscii(name).split(/[^a-zA-Z0-9]+/u).filter(Boolean);
|
|
849
849
|
if (parts.length === 0) return DEFAULT_ROOT_NAME;
|
|
850
850
|
const result = parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
851
|
-
if (/^[0-9]/u.test(result)) return `_${result}`.replace(/([0-9])([a-z])/u, (_,
|
|
851
|
+
if (/^[0-9]/u.test(result)) return `_${result}`.replace(/([0-9])([a-z])/u, (_, digit, letter) => `${digit}${letter.toUpperCase()}`);
|
|
852
852
|
return result;
|
|
853
853
|
}
|
|
854
|
-
function normalizeTypes(
|
|
855
|
-
if (
|
|
856
|
-
if (typeof
|
|
857
|
-
return [...
|
|
854
|
+
function normalizeTypes(types) {
|
|
855
|
+
if (types === void 0) return [];
|
|
856
|
+
if (typeof types === "string") return [types];
|
|
857
|
+
return [...types];
|
|
858
858
|
}
|
|
859
859
|
/**
|
|
860
860
|
* Reconcile a schema's `default` value with the type the schema actually emits
|
|
@@ -903,7 +903,7 @@ function conformDefault(schema, value, definitions, reading) {
|
|
|
903
903
|
keep: true,
|
|
904
904
|
value
|
|
905
905
|
};
|
|
906
|
-
const conform = (s, v,
|
|
906
|
+
const conform = (s, v, seen = reading) => conformDefault(s, v, definitions, seen);
|
|
907
907
|
if (schema.$ref !== void 0) {
|
|
908
908
|
const target = reading.has(schema.$ref) ? void 0 : definitionOf$1(schema.$ref, definitions);
|
|
909
909
|
if (target === void 0) return value === null && schema.nullable !== true ? drop : asIs;
|
|
@@ -928,9 +928,9 @@ function conformDefault(schema, value, definitions, reading) {
|
|
|
928
928
|
if (schema.const !== void 0) return JSON.stringify(schema.const) === JSON.stringify(value) ? asIs : drop;
|
|
929
929
|
if (types.length === 0 && schema.allOf !== void 0) return schema.allOf.filter((member) => {
|
|
930
930
|
const memberTypes = normalizeTypes(member.type);
|
|
931
|
-
return memberTypes.length === 0 || memberTypes.some((
|
|
931
|
+
return memberTypes.length === 0 || memberTypes.some((memberType) => memberType !== "null");
|
|
932
932
|
}).reduce((result, member) => result.keep ? conform(member, result.value) : result, asIs);
|
|
933
|
-
const valueTypes = types.filter((
|
|
933
|
+
const valueTypes = types.filter((valueType) => valueType !== "null");
|
|
934
934
|
if (types.length > 0 && valueTypes.length === 0) return drop;
|
|
935
935
|
if (valueTypes.length === 0) return schema.properties !== void 0 ? readObject(schema, value, conform) ?? drop : asIs;
|
|
936
936
|
const read = (type) => {
|
|
@@ -973,7 +973,7 @@ function conformDefault(schema, value, definitions, reading) {
|
|
|
973
973
|
return asIs;
|
|
974
974
|
};
|
|
975
975
|
const own = valueTypes.find((type) => typeOf(value) === type || type === "number" && typeof value === "number");
|
|
976
|
-
return (own === void 0 ? void 0 : read(own)) ?? valueTypes.map(read).find((
|
|
976
|
+
return (own === void 0 ? void 0 : read(own)) ?? valueTypes.map(read).find((result) => result !== void 0) ?? drop;
|
|
977
977
|
}
|
|
978
978
|
/** An object default as a value of the schema, or `undefined` when it is not one. */
|
|
979
979
|
function readObject(schema, value, conform) {
|
|
@@ -986,8 +986,9 @@ function readObject(schema, value, conform) {
|
|
|
986
986
|
if ((schema.required ?? []).some((key) => !Object.hasOwn(value, key))) return void 0;
|
|
987
987
|
const kept = {};
|
|
988
988
|
for (const [key, item] of Object.entries(value)) {
|
|
989
|
-
|
|
990
|
-
|
|
989
|
+
const property = Object.hasOwn(declared, key) ? declared[key] : void 0;
|
|
990
|
+
if (property === void 0) continue;
|
|
991
|
+
const result = conform(property, item);
|
|
991
992
|
if (!result.keep) return void 0;
|
|
992
993
|
kept[key] = result.value;
|
|
993
994
|
}
|
|
@@ -1185,16 +1186,14 @@ function rewriteBracedHex(pattern) {
|
|
|
1185
1186
|
if (char === "\\" && pattern.startsWith("x{", index + 1)) {
|
|
1186
1187
|
const close = pattern.indexOf("}", index + 3);
|
|
1187
1188
|
const hex = close > index + 3 ? pattern.slice(index + 3, close) : "";
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
if (codePoint
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
continue;
|
|
1197
|
-
}
|
|
1189
|
+
const codePoint = /^[0-9A-Fa-f]+$/u.test(hex) ? Number.parseInt(hex, 16) : NaN;
|
|
1190
|
+
if (codePoint <= 1114111) {
|
|
1191
|
+
if (codePoint > 65535) {
|
|
1192
|
+
unicode = true;
|
|
1193
|
+
out += `\\u{${hex}}`;
|
|
1194
|
+
} else out += `\\u${hex.padStart(4, "0")}`;
|
|
1195
|
+
index = close;
|
|
1196
|
+
continue;
|
|
1198
1197
|
}
|
|
1199
1198
|
}
|
|
1200
1199
|
out += char;
|
|
@@ -1486,14 +1485,14 @@ function leastCommonMultiple(left, right) {
|
|
|
1486
1485
|
return multiple;
|
|
1487
1486
|
}
|
|
1488
1487
|
function greatestCommonDivisor(left, right) {
|
|
1489
|
-
let
|
|
1490
|
-
let
|
|
1491
|
-
while (
|
|
1492
|
-
const next =
|
|
1493
|
-
|
|
1494
|
-
|
|
1488
|
+
let a = left;
|
|
1489
|
+
let b = right;
|
|
1490
|
+
while (b !== 0) {
|
|
1491
|
+
const next = a % b;
|
|
1492
|
+
a = b;
|
|
1493
|
+
b = next;
|
|
1495
1494
|
}
|
|
1496
|
-
return
|
|
1495
|
+
return a;
|
|
1497
1496
|
}
|
|
1498
1497
|
function numericGuard(schema, param) {
|
|
1499
1498
|
const checks = [];
|
|
@@ -2191,7 +2190,7 @@ function impliedWireType(schema) {
|
|
|
2191
2190
|
* reads text, so the string member is tried last.
|
|
2192
2191
|
*/
|
|
2193
2192
|
function unionPrimitiveTypes(types, isWire) {
|
|
2194
|
-
return (isWire ? WIRE_PRIMITIVE_ORDER.filter((
|
|
2193
|
+
return (isWire ? WIRE_PRIMITIVE_ORDER.filter((primitiveType) => types.includes(primitiveType)) : types).filter((primitiveType) => (primitiveType === "string" || primitiveType === "number" || primitiveType === "boolean" || primitiveType === "integer") && !(primitiveType === "integer" && types.includes("number")));
|
|
2195
2194
|
}
|
|
2196
2195
|
/** Whether a `type` list is a union of primitives alone: more than one, and no array or object. */
|
|
2197
2196
|
function isPrimitiveUnion(types, isWire) {
|
|
@@ -2467,7 +2466,7 @@ function notPredicate(inner, param, parameter = param, bigint = false) {
|
|
|
2467
2466
|
return body === void 0 ? void 0 : `(${parameter}) => ${body}`;
|
|
2468
2467
|
}
|
|
2469
2468
|
if (Array.isArray(inner.type)) {
|
|
2470
|
-
const bodies = normalizeTypes(inner.type).map((
|
|
2469
|
+
const bodies = normalizeTypes(inner.type).map((typeName) => notTypeBody(typeName, param)).filter((body) => body !== void 0).map((body) => `(${body})`);
|
|
2471
2470
|
if (bodies.length > 0) return `(${parameter}) => ${bodies.join(" && ")}`;
|
|
2472
2471
|
}
|
|
2473
2472
|
}
|
|
@@ -2837,7 +2836,7 @@ function conform(shape, value) {
|
|
|
2837
2836
|
case "type": {
|
|
2838
2837
|
if (typeof value === "string") return value;
|
|
2839
2838
|
if (!Array.isArray(value)) return void 0;
|
|
2840
|
-
const types = value.filter((
|
|
2839
|
+
const types = value.filter((member) => typeof member === "string");
|
|
2841
2840
|
return types.length > 0 ? types : void 0;
|
|
2842
2841
|
}
|
|
2843
2842
|
case "stringList": return Array.isArray(value) ? value.flatMap((v) => typeof v === "string" ? [v] : isPlainObject(v) || Array.isArray(v) ? [] : [String(v)]) : void 0;
|
|
@@ -2927,8 +2926,9 @@ function nonNullType(schema, flavour, rootName) {
|
|
|
2927
2926
|
if (schema.oneOf || schema.anyOf) return `(${(schema.oneOf ?? schema.anyOf ?? []).map(type).join(" | ")})`;
|
|
2928
2927
|
if (schema.allOf) {
|
|
2929
2928
|
const members = schema.allOf.filter((s) => !isShapelessMember(s)).map(type);
|
|
2930
|
-
|
|
2931
|
-
if (
|
|
2929
|
+
const [member, ...others] = members;
|
|
2930
|
+
if (member === void 0) return "unknown";
|
|
2931
|
+
if (others.length === 0) return member;
|
|
2932
2932
|
return `(${members.join(" & ")})`;
|
|
2933
2933
|
}
|
|
2934
2934
|
if (schema.not) return "unknown";
|
|
@@ -2941,11 +2941,8 @@ function nonNullType(schema, flavour, rootName) {
|
|
|
2941
2941
|
const readonly = flavour.readonly ? "readonly " : "";
|
|
2942
2942
|
const object = () => {
|
|
2943
2943
|
if (!schema.properties) {
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
return `{ [key: string]: ${type(schema.additionalProperties)} }`;
|
|
2947
|
-
}
|
|
2948
|
-
return "{ [key: string]: unknown }";
|
|
2944
|
+
const additional = schema.additionalProperties;
|
|
2945
|
+
return isPlainObject(additional) ? `{ [key: string]: ${type(additional)} }` : "{ [key: string]: unknown }";
|
|
2949
2946
|
}
|
|
2950
2947
|
const required = new Set(schema.required);
|
|
2951
2948
|
return `{${Object.entries(schema.properties).map(([key, propSchema]) => {
|
|
@@ -2955,22 +2952,23 @@ function nonNullType(schema, flavour, rootName) {
|
|
|
2955
2952
|
}).join("; ")}}`;
|
|
2956
2953
|
};
|
|
2957
2954
|
if (schema.properties) return object();
|
|
2958
|
-
const
|
|
2955
|
+
const types = normalizeTypes(schema.type);
|
|
2959
2956
|
const integerType = isInt64(schema) || schema.format === "bigint" ? "bigint" : "number";
|
|
2960
2957
|
const primitives = [
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2958
|
+
types.includes("string") ? "string" : void 0,
|
|
2959
|
+
types.includes("number") ? "number" : types.includes("integer") ? integerType : void 0,
|
|
2960
|
+
types.includes("boolean") ? "boolean" : void 0
|
|
2964
2961
|
].filter((p) => p !== void 0);
|
|
2965
|
-
if (primitives.length > 1 && !
|
|
2966
|
-
|
|
2967
|
-
if (
|
|
2962
|
+
if (primitives.length > 1 && !types.includes("array") && !types.includes("object")) return `(${primitives.join(" | ")})`;
|
|
2963
|
+
const [primitive] = primitives;
|
|
2964
|
+
if (primitive !== void 0) return primitive;
|
|
2965
|
+
if (types.includes("array")) {
|
|
2968
2966
|
const items = itemsSchemaOf(schema.items);
|
|
2969
2967
|
return items ? `${readonly}${type(items)}[]` : `${readonly}unknown[]`;
|
|
2970
2968
|
}
|
|
2971
|
-
if (
|
|
2972
|
-
if (
|
|
2973
|
-
if (
|
|
2969
|
+
if (types.includes("object")) return object();
|
|
2970
|
+
if (types.includes("date")) return "Date";
|
|
2971
|
+
if (types.length === 1 && types[0] === "null") return "null";
|
|
2974
2972
|
return "unknown";
|
|
2975
2973
|
}
|
|
2976
2974
|
// src/helper/typebox-wrap.ts
|
package/dist/index.d.ts
CHANGED
|
@@ -106,7 +106,7 @@ export declare function encodeNonAscii(name: string): string;
|
|
|
106
106
|
* ```
|
|
107
107
|
*/
|
|
108
108
|
export declare function toIdentifierPascalCase(name: string): string;
|
|
109
|
-
export declare function normalizeTypes(
|
|
109
|
+
export declare function normalizeTypes(types?: string | readonly string[]): string[];
|
|
110
110
|
/** The keywords of a schema node {@link coerceDefault} reads a `default` against. */
|
|
111
111
|
export type DefaultSchema = {
|
|
112
112
|
readonly $ref?: string;
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { $t as ARROW_FUNCTION_PATTERN, An as ROOT_REFS, Bn as ZOD_CODE_EXTENSION_KEYS, Cn as OBJECT_PROTOTYPE_PROPERTIES, Ct as valibotError, Dn as PARAM_LOCATIONS, Dt as zodErrorPart, En as OUTPUT_EXTENSION, Et as zodError, Fn as STRING_WIRE_LOCATIONS, In as UNICODE_ESCAPE_PATTERN, Ln as UNSAFE_GENERATED_MARKER, Mn as STRINGBOOL_TRUTHY_PATTERN, Nn as STRING_FORMATS, On as PARAM_STYLES, Pn as STRING_KEYWORDS, Qt as ARKTYPE_CODE_EXTENSION_KEYS, Rn as VALIBOT_CODE_EXTENSION_KEYS, Sn as NUMERIC_KEYWORDS, St as toPascalCase, Tn as OPENAPI_COMPONENT_SUFFIX_MAP, Tt as zodBaseError, Xt as ALL_CODE_EXTENSION_KEYS, Zt as ANCHOR_REF_PATTERN, _n as NON_IDENTIFIER_CHARACTER_PATTERN, _t as issueMessageExpression, an as DEFINITION_POINTER_PATTERN, bn as NUMBER_RANGES, bt as resolveOpenAPIRef, cn as FORMAT_PATTERNS, dn as INPUT_EXTENSIONS, en as COMPONENT_SCHEMA_REF_PREFIX, fn as INTEGER_TEXT_PATTERN, ft as coerceDefault, gn as MISSING_DEFINITION_PREFIX, gt as encodeNonAscii, hn as JSON_SCHEMA_TYPES, ht as effectMessage, in as DEFINITION_KEYWORDS, jn as STRINGBOOL_PATTERN, kn as QUOTE_OR_BACKSLASH_PATTERN, ln as IDENTIFIER_PATTERN, mn as ISO_4217_CURRENCY_CODES, mt as effectErrorPart, nn as DATE_PATTERN_SOURCE, on as DEFINITION_REF_PREFIXES, pn as INTEGER_WIRE_PATTERN, pt as effectError, rn as DEFAULT_ROOT_NAME, sn as EFFECT_CODE_EXTENSION_KEYS, tn as CONTENT_ENCODINGS, un as IF_THEN_ELSE_UNSUPPORTED_MARKER, vn as NOT_KEYWORD_UNSUPPORTED_MARKER, vt as makeSafeKey, wn as OFFSET_PATTERN_SOURCE, wt as valibotErrorPart, xn as NUMBER_WIRE_PATTERN, xt as toIdentifierPascalCase, yn as NUMBER_FORMATS, yt as normalizeTypes, zn as WIRE_PRIMITIVE_ORDER } from "./helper-
|
|
1
|
+
import { $t as ARROW_FUNCTION_PATTERN, An as ROOT_REFS, Bn as ZOD_CODE_EXTENSION_KEYS, Cn as OBJECT_PROTOTYPE_PROPERTIES, Ct as valibotError, Dn as PARAM_LOCATIONS, Dt as zodErrorPart, En as OUTPUT_EXTENSION, Et as zodError, Fn as STRING_WIRE_LOCATIONS, In as UNICODE_ESCAPE_PATTERN, Ln as UNSAFE_GENERATED_MARKER, Mn as STRINGBOOL_TRUTHY_PATTERN, Nn as STRING_FORMATS, On as PARAM_STYLES, Pn as STRING_KEYWORDS, Qt as ARKTYPE_CODE_EXTENSION_KEYS, Rn as VALIBOT_CODE_EXTENSION_KEYS, Sn as NUMERIC_KEYWORDS, St as toPascalCase, Tn as OPENAPI_COMPONENT_SUFFIX_MAP, Tt as zodBaseError, Xt as ALL_CODE_EXTENSION_KEYS, Zt as ANCHOR_REF_PATTERN, _n as NON_IDENTIFIER_CHARACTER_PATTERN, _t as issueMessageExpression, an as DEFINITION_POINTER_PATTERN, bn as NUMBER_RANGES, bt as resolveOpenAPIRef, cn as FORMAT_PATTERNS, dn as INPUT_EXTENSIONS, en as COMPONENT_SCHEMA_REF_PREFIX, fn as INTEGER_TEXT_PATTERN, ft as coerceDefault, gn as MISSING_DEFINITION_PREFIX, gt as encodeNonAscii, hn as JSON_SCHEMA_TYPES, ht as effectMessage, in as DEFINITION_KEYWORDS, jn as STRINGBOOL_PATTERN, kn as QUOTE_OR_BACKSLASH_PATTERN, ln as IDENTIFIER_PATTERN, mn as ISO_4217_CURRENCY_CODES, mt as effectErrorPart, nn as DATE_PATTERN_SOURCE, on as DEFINITION_REF_PREFIXES, pn as INTEGER_WIRE_PATTERN, pt as effectError, rn as DEFAULT_ROOT_NAME, sn as EFFECT_CODE_EXTENSION_KEYS, tn as CONTENT_ENCODINGS, un as IF_THEN_ELSE_UNSUPPORTED_MARKER, vn as NOT_KEYWORD_UNSUPPORTED_MARKER, vt as makeSafeKey, wn as OFFSET_PATTERN_SOURCE, wt as valibotErrorPart, xn as NUMBER_WIRE_PATTERN, xt as toIdentifierPascalCase, yn as NUMBER_FORMATS, yt as normalizeTypes, zn as WIRE_PRIMITIVE_ORDER } from "./helper-OCkRyx4U.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-
|
|
4
|
-
import { n as arktype, t as schemaToArktype } from "./arktype-
|
|
5
|
-
import { n as effect, r as wholeValueMessage, t as schemaToEffect } from "./effect-
|
|
6
|
-
import { n as nestedTypeboxOptions, r as typebox, t as schemaToTypebox } from "./typebox-
|
|
7
|
-
import { n as valibot, t as schemaToValibot } from "./valibot-
|
|
8
|
-
import { n as yup, t as schemaToYup } from "./yup-
|
|
9
|
-
import { i as zod, n as forwardIssue, r as nestedIssueMessageWrap, t as schemaToZod } from "./zod-
|
|
3
|
+
import { n as ajv, t as schemaToAjv } from "./ajv-Oz83L2oz.js";
|
|
4
|
+
import { n as arktype, t as schemaToArktype } from "./arktype-DDbxpolC.js";
|
|
5
|
+
import { n as effect, r as wholeValueMessage, t as schemaToEffect } from "./effect-CHLS1Yit.js";
|
|
6
|
+
import { n as nestedTypeboxOptions, r as typebox, t as schemaToTypebox } from "./typebox-DNkk6MCh.js";
|
|
7
|
+
import { n as valibot, t as schemaToValibot } from "./valibot-Vj1GeCcx.js";
|
|
8
|
+
import { n as yup, t as schemaToYup } from "./yup-DKlaai37.js";
|
|
9
|
+
import { i as zod, n as forwardIssue, r as nestedIssueMessageWrap, t as schemaToZod } from "./zod-04J51AMt.js";
|
|
10
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 };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as itemsSchemaOf, B as typeboxRefOpt, Bt as isNullable, D as stringboolPattern, G as renderDefinitions, H as emitOptionsOf, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, Kt as isRootRef, Lt as isDeepLocalPointer, Mt as hasNumericKeyword, Nt as hasStringKeyword, O as stringboolTruthyPattern, Ot as hasCombinator, Q as isOptionalByDefault, R as typeboxDefaultOpt, Rt as isDefaultOnlyMember, U as missingDefinitionComment, V as definitionsOf, W as planDocument, X as hasRootSelfReference, Y as cyclicDefinitionNames, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, a as typeboxWrap, at as hasNotKeyword, bt as resolveOpenAPIRef, ct as foldAllOfMembers, jt as hasFixedLength, l as withPolymorphicBases, lt as isKeywordOnlyMember, on as DEFINITION_REF_PREFIXES, pn as INTEGER_WIRE_PATTERN, q as schemaNamer, rn as DEFAULT_ROOT_NAME, s as sanitizeSchema, ut as patternSource, vn as NOT_KEYWORD_UNSUPPORTED_MARKER, vt as makeSafeKey, xn as NUMBER_WIRE_PATTERN, yt as normalizeTypes, z as typeboxMetaOpts, zt as isNullTypeMember } from "./helper-
|
|
1
|
+
import { $ as itemsSchemaOf, B as typeboxRefOpt, Bt as isNullable, D as stringboolPattern, G as renderDefinitions, H as emitOptionsOf, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, Kt as isRootRef, Lt as isDeepLocalPointer, Mt as hasNumericKeyword, Nt as hasStringKeyword, O as stringboolTruthyPattern, Ot as hasCombinator, Q as isOptionalByDefault, R as typeboxDefaultOpt, Rt as isDefaultOnlyMember, U as missingDefinitionComment, V as definitionsOf, W as planDocument, X as hasRootSelfReference, Y as cyclicDefinitionNames, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, a as typeboxWrap, at as hasNotKeyword, bt as resolveOpenAPIRef, ct as foldAllOfMembers, jt as hasFixedLength, l as withPolymorphicBases, lt as isKeywordOnlyMember, on as DEFINITION_REF_PREFIXES, pn as INTEGER_WIRE_PATTERN, q as schemaNamer, rn as DEFAULT_ROOT_NAME, s as sanitizeSchema, ut as patternSource, vn as NOT_KEYWORD_UNSUPPORTED_MARKER, vt as makeSafeKey, xn as NUMBER_WIRE_PATTERN, yt as normalizeTypes, z as typeboxMetaOpts, zt as isNullTypeMember } from "./helper-OCkRyx4U.js";
|
|
2
2
|
// src/generator/typebox/enum.ts
|
|
3
3
|
function lit(v) {
|
|
4
4
|
if (v === null) return "null";
|
|
@@ -29,6 +29,22 @@ function _enum(schema, ref) {
|
|
|
29
29
|
return `Type.Union([${schema.enum.map(member).join(",")}]${optsTrailer})`;
|
|
30
30
|
}
|
|
31
31
|
// src/generator/typebox/integer.ts
|
|
32
|
+
function bigintBound(keyword, value, round) {
|
|
33
|
+
return typeof value === "number" && Number.isFinite(value) ? `${keyword}:${Math[round](value)}` : void 0;
|
|
34
|
+
}
|
|
35
|
+
function bigintDivisor(value) {
|
|
36
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) return void 0;
|
|
37
|
+
const match = /^(\d+)(?:\.(\d+))?(?:e([+-]\d+))?$/.exec(String(value));
|
|
38
|
+
if (!match) return void 0;
|
|
39
|
+
const [, whole, fraction = "", exponent = "0"] = match;
|
|
40
|
+
const numerator = BigInt(whole + fraction);
|
|
41
|
+
const scale = Number(exponent) - fraction.length;
|
|
42
|
+
if (scale >= 0) return numerator * 10n ** BigInt(scale);
|
|
43
|
+
let [a, b] = [numerator, 10n ** BigInt(-scale)];
|
|
44
|
+
while (b !== 0n) [a, b] = [b, a % b];
|
|
45
|
+
const divisor = numerator / a;
|
|
46
|
+
return BigInt(Number(divisor)) === divisor ? Number(divisor) : void 0;
|
|
47
|
+
}
|
|
32
48
|
function integer(schema, ref) {
|
|
33
49
|
const errorMessage = schema["x-error-message"];
|
|
34
50
|
const requiredMessage = schema["x-required-message"];
|
|
@@ -36,11 +52,14 @@ function integer(schema, ref) {
|
|
|
36
52
|
const maxMessage = schema["x-maximum-message"];
|
|
37
53
|
const exclusiveMinimumMessage = schema["x-exclusiveMinimum-message"];
|
|
38
54
|
const exclusiveMaximumMessage = schema["x-exclusiveMaximum-message"];
|
|
39
|
-
const
|
|
55
|
+
const minimumKeyword = schema.exclusiveMinimum === true && schema.minimum !== void 0 ? "exclusiveMinimum" : "minimum";
|
|
56
|
+
const maximumKeyword = schema.exclusiveMaximum === true && schema.maximum !== void 0 ? "exclusiveMaximum" : "maximum";
|
|
57
|
+
const bigintMultipleOf = schema.format === "bigint" ? bigintDivisor(schema.multipleOf) : void 0;
|
|
58
|
+
const multipleOfMessage = schema.format === "bigint" && bigintMultipleOf === void 0 ? void 0 : schema["x-multipleOf-message"];
|
|
40
59
|
const perKeywordEntries = [];
|
|
41
60
|
if (requiredMessage) perKeywordEntries.push(`required:${JSON.stringify(requiredMessage)}`);
|
|
42
|
-
if (minMessage) perKeywordEntries.push(`minimum:${JSON.stringify(minMessage)}`);
|
|
43
|
-
if (maxMessage) perKeywordEntries.push(`maximum:${JSON.stringify(maxMessage)}`);
|
|
61
|
+
if (minMessage && minimumKeyword === "minimum") perKeywordEntries.push(`minimum:${JSON.stringify(minMessage)}`);
|
|
62
|
+
if (maxMessage && maximumKeyword === "maximum") perKeywordEntries.push(`maximum:${JSON.stringify(maxMessage)}`);
|
|
44
63
|
if (exclusiveMinimumMessage) perKeywordEntries.push(`exclusiveMinimum:${JSON.stringify(exclusiveMinimumMessage)}`);
|
|
45
64
|
if (exclusiveMaximumMessage) perKeywordEntries.push(`exclusiveMaximum:${JSON.stringify(exclusiveMaximumMessage)}`);
|
|
46
65
|
if (multipleOfMessage) perKeywordEntries.push(`multipleOf:${JSON.stringify(multipleOfMessage)}`);
|
|
@@ -49,8 +68,11 @@ function integer(schema, ref) {
|
|
|
49
68
|
if (schema.format === "bigint") {
|
|
50
69
|
const opts = [
|
|
51
70
|
...typeboxRefOpt(ref),
|
|
52
|
-
schema.minimum
|
|
53
|
-
schema.
|
|
71
|
+
bigintBound(minimumKeyword, schema.minimum, minimumKeyword === "minimum" ? "ceil" : "floor"),
|
|
72
|
+
bigintBound("exclusiveMinimum", schema.exclusiveMinimum, "floor"),
|
|
73
|
+
bigintBound(maximumKeyword, schema.maximum, maximumKeyword === "maximum" ? "floor" : "ceil"),
|
|
74
|
+
bigintBound("exclusiveMaximum", schema.exclusiveMaximum, "ceil"),
|
|
75
|
+
bigintMultipleOf !== void 0 ? `multipleOf:${bigintMultipleOf}` : void 0,
|
|
54
76
|
errorMessageField,
|
|
55
77
|
...metaOpts
|
|
56
78
|
].filter((v) => v !== void 0);
|
|
@@ -59,9 +81,9 @@ function integer(schema, ref) {
|
|
|
59
81
|
}
|
|
60
82
|
const opts = [
|
|
61
83
|
...typeboxRefOpt(ref),
|
|
62
|
-
schema.minimum !== void 0 ?
|
|
84
|
+
schema.minimum !== void 0 ? `${minimumKeyword}:${schema.minimum}` : void 0,
|
|
63
85
|
typeof schema.exclusiveMinimum === "number" ? `exclusiveMinimum:${schema.exclusiveMinimum}` : void 0,
|
|
64
|
-
schema.maximum !== void 0 ?
|
|
86
|
+
schema.maximum !== void 0 ? `${maximumKeyword}:${schema.maximum}` : void 0,
|
|
65
87
|
typeof schema.exclusiveMaximum === "number" ? `exclusiveMaximum:${schema.exclusiveMaximum}` : void 0,
|
|
66
88
|
schema.multipleOf !== void 0 ? `multipleOf:${schema.multipleOf}` : void 0,
|
|
67
89
|
errorMessageField,
|
|
@@ -78,20 +100,22 @@ function number(schema, ref) {
|
|
|
78
100
|
const maxMessage = schema["x-maximum-message"];
|
|
79
101
|
const exclusiveMinimumMessage = schema["x-exclusiveMinimum-message"];
|
|
80
102
|
const exclusiveMaximumMessage = schema["x-exclusiveMaximum-message"];
|
|
103
|
+
const minimumKeyword = schema.exclusiveMinimum === true && schema.minimum !== void 0 ? "exclusiveMinimum" : "minimum";
|
|
104
|
+
const maximumKeyword = schema.exclusiveMaximum === true && schema.maximum !== void 0 ? "exclusiveMaximum" : "maximum";
|
|
81
105
|
const multipleOfMessage = schema["x-multipleOf-message"];
|
|
82
106
|
const perKeywordEntries = [];
|
|
83
107
|
if (requiredMessage) perKeywordEntries.push(`required:${JSON.stringify(requiredMessage)}`);
|
|
84
|
-
if (minMessage) perKeywordEntries.push(`minimum:${JSON.stringify(minMessage)}`);
|
|
85
|
-
if (maxMessage) perKeywordEntries.push(`maximum:${JSON.stringify(maxMessage)}`);
|
|
108
|
+
if (minMessage && minimumKeyword === "minimum") perKeywordEntries.push(`minimum:${JSON.stringify(minMessage)}`);
|
|
109
|
+
if (maxMessage && maximumKeyword === "maximum") perKeywordEntries.push(`maximum:${JSON.stringify(maxMessage)}`);
|
|
86
110
|
if (exclusiveMinimumMessage) perKeywordEntries.push(`exclusiveMinimum:${JSON.stringify(exclusiveMinimumMessage)}`);
|
|
87
111
|
if (exclusiveMaximumMessage) perKeywordEntries.push(`exclusiveMaximum:${JSON.stringify(exclusiveMaximumMessage)}`);
|
|
88
112
|
if (multipleOfMessage) perKeywordEntries.push(`multipleOf:${JSON.stringify(multipleOfMessage)}`);
|
|
89
113
|
const errorMessageField = perKeywordEntries.length === 0 ? errorMessage ? `errorMessage:${JSON.stringify(errorMessage)}` : void 0 : `errorMessage:{${perKeywordEntries.join(",")}${errorMessage ? `,_:${JSON.stringify(errorMessage)}` : ""}}`;
|
|
90
114
|
const opts = [
|
|
91
115
|
...typeboxRefOpt(ref),
|
|
92
|
-
schema.minimum !== void 0 ?
|
|
116
|
+
schema.minimum !== void 0 ? `${minimumKeyword}:${schema.minimum}` : void 0,
|
|
93
117
|
typeof schema.exclusiveMinimum === "number" ? `exclusiveMinimum:${schema.exclusiveMinimum}` : void 0,
|
|
94
|
-
schema.maximum !== void 0 ?
|
|
118
|
+
schema.maximum !== void 0 ? `${maximumKeyword}:${schema.maximum}` : void 0,
|
|
95
119
|
typeof schema.exclusiveMaximum === "number" ? `exclusiveMaximum:${schema.exclusiveMaximum}` : void 0,
|
|
96
120
|
schema.multipleOf !== void 0 ? `multipleOf:${schema.multipleOf}` : void 0,
|
|
97
121
|
errorMessageField,
|
|
@@ -475,7 +499,7 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
|
|
|
475
499
|
...defaultValue !== void 0 ? { default: defaultValue } : ownDefault !== void 0 && { default: ownDefault }
|
|
476
500
|
};
|
|
477
501
|
const defaultOpt = typeboxDefaultOpt(withMergedDefault, false, definitions);
|
|
478
|
-
const baseResult = schemas.length === 1 && unevaluatedOpt.length === 0 && defaultOpt.length === 0 ? schemas[0] : tbComp("Type.Intersect", `[${schemas.join(",")}]`, withoutDefault, [
|
|
502
|
+
const baseResult = schemas.length === 1 && schemas[0] !== void 0 && unevaluatedOpt.length === 0 && defaultOpt.length === 0 ? schemas[0] : tbComp("Type.Intersect", `[${schemas.join(",")}]`, withoutDefault, [
|
|
479
503
|
...messageOpt(schema["x-allOf-message"]),
|
|
480
504
|
...unevaluatedOpt,
|
|
481
505
|
...defaultOpt
|
|
@@ -484,7 +508,7 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
|
|
|
484
508
|
}
|
|
485
509
|
if (schema.not) {
|
|
486
510
|
const { not: dropped, ...withoutNot } = schema;
|
|
487
|
-
if (
|
|
511
|
+
if (withoutNot.type !== void 0) return typebox(withoutNot, rootName, isTypebox, options);
|
|
488
512
|
return typeboxWrap(tbPrim("Type.Any", schema, messageOpt(schema["x-not-message"]), hostRef), schema);
|
|
489
513
|
}
|
|
490
514
|
if (schema.const !== void 0) {
|
|
@@ -519,7 +543,7 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
|
|
|
519
543
|
return typeboxWrap(tbPrim("Type.Boolean", schema, [], hostRef), schema);
|
|
520
544
|
}
|
|
521
545
|
if (types.includes("array")) {
|
|
522
|
-
if (schema.prefixItems
|
|
546
|
+
if (schema.prefixItems !== void 0 && schema.prefixItems.length > 0) {
|
|
523
547
|
const items = schema.prefixItems.map((s) => typebox(s, rootName, isTypebox, childOptions));
|
|
524
548
|
const prefixItemsMessage = schema["x-prefixItems-message"];
|
|
525
549
|
const tupleOpts = prefixItemsMessage ? [`errorMessage:{prefixItems:${JSON.stringify(prefixItemsMessage)},items:${JSON.stringify(prefixItemsMessage)}}`] : [];
|
package/dist/typebox.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToTypebox } from "./typebox-
|
|
1
|
+
export { t as schemaToTypebox } from "./typebox-DNkk6MCh.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as itemsSchemaOf, A as wireArrayOnce, At as hasFixedItemCount, Bt as isNullable, C as isNullTextRead, Ct as valibotError, D as stringboolPattern, E as ownProperties, G as renderDefinitions, H as emitOptionsOf, I as deepEqualExpression, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, L as jsLiteral, Ln as UNSAFE_GENERATED_MARKER, M as wireNumericKind, N as formatPattern, O as stringboolTruthyPattern, Ot as hasCombinator, P as regexSource, Pt as hasType, Q as isOptionalByDefault, Rt as isDefaultOnlyMember, T as numberWirePattern, Ut as isPrimitive, V as definitionsOf, Vt as isObjectPrototypeProperty, W as planDocument, X as hasRootSelfReference, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, _t as issueMessageExpression, b as impliedWireType, bn as NUMBER_RANGES, c as refTarget, ct as foldAllOfMembers, d as parameterReaders, dt as regexLiteral, f as propertyEmitOptions, fn as INTEGER_TEXT_PATTERN, g as valueListLiteral, h as notPredicate, i as isEvaluatedKeyExpression, it as findCodeExtensionKeysInSchema, jt as hasFixedLength, k as unionPrimitiveTypes, kt as hasConditional, l as withPolymorphicBases, lt as isKeywordOnlyMember, m as isBigintFormat, n as valibotWrap, o as typeDeclaration, ot as constraintMessage, p as withoutParameterSerialization, q as schemaNamer, qt as isSchemaObject, r as evaluatedProperties, rn as DEFAULT_ROOT_NAME, s as sanitizeSchema, st as constraintPredicate, u as hasParameterSerialization, vt as makeSafeKey, w as isPrimitiveUnion, wt as valibotErrorPart, x as integerWirePattern, yt as normalizeTypes, zt as isNullTypeMember } from "./helper-
|
|
1
|
+
import { $ as itemsSchemaOf, A as wireArrayOnce, At as hasFixedItemCount, Bt as isNullable, C as isNullTextRead, Ct as valibotError, D as stringboolPattern, E as ownProperties, G as renderDefinitions, H as emitOptionsOf, I as deepEqualExpression, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, L as jsLiteral, Ln as UNSAFE_GENERATED_MARKER, M as wireNumericKind, N as formatPattern, O as stringboolTruthyPattern, Ot as hasCombinator, P as regexSource, Pt as hasType, Q as isOptionalByDefault, Rt as isDefaultOnlyMember, T as numberWirePattern, Ut as isPrimitive, V as definitionsOf, Vt as isObjectPrototypeProperty, W as planDocument, X as hasRootSelfReference, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, _t as issueMessageExpression, b as impliedWireType, bn as NUMBER_RANGES, c as refTarget, ct as foldAllOfMembers, d as parameterReaders, dt as regexLiteral, f as propertyEmitOptions, fn as INTEGER_TEXT_PATTERN, g as valueListLiteral, h as notPredicate, i as isEvaluatedKeyExpression, it as findCodeExtensionKeysInSchema, jt as hasFixedLength, k as unionPrimitiveTypes, kt as hasConditional, l as withPolymorphicBases, lt as isKeywordOnlyMember, m as isBigintFormat, n as valibotWrap, o as typeDeclaration, ot as constraintMessage, p as withoutParameterSerialization, q as schemaNamer, qt as isSchemaObject, r as evaluatedProperties, rn as DEFAULT_ROOT_NAME, s as sanitizeSchema, st as constraintPredicate, u as hasParameterSerialization, vt as makeSafeKey, w as isPrimitiveUnion, wt as valibotErrorPart, x as integerWirePattern, yt as normalizeTypes, zt as isNullTypeMember } from "./helper-OCkRyx4U.js";
|
|
2
2
|
// src/generator/valibot/type.ts
|
|
3
3
|
/** The TypeScript type declared beside a recursive Valibot schema: its output type. */
|
|
4
4
|
function type(schema, rootName = DEFAULT_ROOT_NAME) {
|
|
@@ -159,8 +159,8 @@ function _enum(schema) {
|
|
|
159
159
|
};
|
|
160
160
|
const innerLit = (v) => litSchema(v, "");
|
|
161
161
|
const outerLit = (v) => litSchema(v, errorArg);
|
|
162
|
-
const innerTuple = (
|
|
163
|
-
const outerTuple = (
|
|
162
|
+
const innerTuple = (members) => `v.tuple([${members.map(innerLit).join(",")}])`;
|
|
163
|
+
const outerTuple = (members) => `v.tuple([${members.map(innerLit).join(",")}]${errorArg})`;
|
|
164
164
|
if (hasType(schema, "number") || hasType(schema, "integer") || hasType(schema, "boolean")) return schema.enum.length > 1 ? `v.union([${schema.enum.map(innerLit).join(",")}]${errorArg})` : outerLit(schema.enum[0]);
|
|
165
165
|
if (hasType(schema, "array")) {
|
|
166
166
|
if (schema.enum.length === 1 && Array.isArray(schema.enum[0])) return outerTuple(schema.enum[0]);
|
|
@@ -257,7 +257,7 @@ function object(schema, rootName, isValibot, options) {
|
|
|
257
257
|
const minPropertiesCheck = typeof schema.minProperties === "number" ? `v.check((input)=>Object.keys(input).length>=${schema.minProperties}${minErrorArg})` : "";
|
|
258
258
|
const maxPropertiesCheck = typeof schema.maxProperties === "number" ? `v.check((input)=>Object.keys(input).length<=${schema.maxProperties}${maxErrorArg})` : "";
|
|
259
259
|
const dependentRequiredChecks = schema.dependentRequired ? Object.entries(schema.dependentRequired).map(([key, deps]) => {
|
|
260
|
-
return `v.check((input)=>!('${key}' in input)||(${deps.map((
|
|
260
|
+
return `v.check((input)=>!('${key}' in input)||(${deps.map((dependency) => `'${dependency}' in input`).join("&&")})${depReqErrorArg})`;
|
|
261
261
|
}) : [];
|
|
262
262
|
const dependentSchemasChecks = schema.dependentSchemas ? Object.entries(schema.dependentSchemas).map(([key, subSchema]) => {
|
|
263
263
|
return `v.check((input)=>!('${key}' in input)||v.safeParse(${valibot(subSchema, rootName, isValibot, options)},input).success${depSchErrorArg})`;
|
|
@@ -539,7 +539,7 @@ function node(schema, rootName, isValibot, options) {
|
|
|
539
539
|
...schema,
|
|
540
540
|
nullable
|
|
541
541
|
});
|
|
542
|
-
const intersected = schemas.length === 1 ? schemas[0] : `v.intersect([${schemas.join(",")}])`;
|
|
542
|
+
const intersected = schemas.length === 1 && schemas[0] !== void 0 ? schemas[0] : `v.intersect([${schemas.join(",")}])`;
|
|
543
543
|
const allOfMessage = schema["x-allOf-message"];
|
|
544
544
|
const checked = objectKeysCheck(allOfMessage ? (() => {
|
|
545
545
|
const msgExpr = issueMessageExpression(allOfMessage);
|
|
@@ -593,33 +593,33 @@ function node(schema, rootName, isValibot, options) {
|
|
|
593
593
|
}
|
|
594
594
|
if (schema.properties) return readonly(valibotWrap$1(object(schema, rootName, isValibot, options), schema));
|
|
595
595
|
const types = normalizeTypes(schema.type);
|
|
596
|
-
const primitive = (
|
|
597
|
-
if (
|
|
598
|
-
if (
|
|
599
|
-
if (
|
|
600
|
-
if (
|
|
596
|
+
const primitive = (primitiveType) => {
|
|
597
|
+
if (primitiveType === "string") return string(schema);
|
|
598
|
+
if (primitiveType === "number") return number(schema, { wire: isWireCoerced });
|
|
599
|
+
if (primitiveType === "integer") return integer(schema, { wire: isWireCoerced });
|
|
600
|
+
if (primitiveType !== "boolean") return void 0;
|
|
601
601
|
const errorMessage = schema["x-error-message"];
|
|
602
602
|
const errorArg = errorMessage ? valibotError(errorMessage) : "";
|
|
603
603
|
return isWireCoerced ? stringbool(errorArg) : `v.boolean(${errorArg})`;
|
|
604
604
|
};
|
|
605
605
|
if (isPrimitiveUnion(types, isWireCoerced)) return valibotWrap$1(`v.union([${unionPrimitiveTypes(types, isWireCoerced).map(primitive).filter((m) => m !== void 0).join(",")}])`, schema);
|
|
606
|
-
for (const
|
|
606
|
+
for (const primitiveType of [
|
|
607
607
|
"string",
|
|
608
608
|
"number",
|
|
609
609
|
"integer",
|
|
610
610
|
"boolean"
|
|
611
611
|
]) {
|
|
612
|
-
if (!types.includes(
|
|
613
|
-
const expression = primitive(
|
|
612
|
+
if (!types.includes(primitiveType)) continue;
|
|
613
|
+
const expression = primitive(primitiveType);
|
|
614
614
|
if (expression !== void 0) return valibotWrap$1(expression, schema);
|
|
615
615
|
}
|
|
616
616
|
if (types.includes("array")) {
|
|
617
|
-
if (schema.prefixItems
|
|
617
|
+
if (schema.prefixItems !== void 0 && schema.prefixItems.length > 0) {
|
|
618
618
|
const items = schema.prefixItems.map((s) => valibot(s, rootName, isValibot, options));
|
|
619
|
-
const
|
|
619
|
+
const unevaluatedItems = schema.unevaluatedItems;
|
|
620
620
|
const unevaluatedItemsMessage = schema["x-unevaluatedItems-message"];
|
|
621
621
|
const unevaluatedItemsArg = valibotErrorPart(unevaluatedItemsMessage);
|
|
622
|
-
const tupleExpr = isSchemaObject(
|
|
622
|
+
const tupleExpr = isSchemaObject(unevaluatedItems) ? `v.tupleWithRest([${items.join(",")}],${valibot(unevaluatedItems, rootName, isValibot, options)})` : unevaluatedItems === false ? `v.strictTuple([${items.join(",")}]${unevaluatedItemsArg})` : `v.tuple([${items.join(",")}])`;
|
|
623
623
|
const prefixItemsMessage = schema["x-prefixItems-message"];
|
|
624
624
|
return readonly(valibotWrap$1(wireArray(prefixItemsMessage ? elementMessageWrap(tupleExpr, prefixItemsMessage) : tupleExpr), schema));
|
|
625
625
|
}
|
|
@@ -638,9 +638,9 @@ function node(schema, rootName, isValibot, options) {
|
|
|
638
638
|
const uniqueItemsMessage = schema["x-uniqueItems-message"];
|
|
639
639
|
const uniqueArg = valibotErrorPart(uniqueItemsMessage);
|
|
640
640
|
const containsActions = (() => {
|
|
641
|
-
const
|
|
642
|
-
if (!
|
|
643
|
-
const containsSchema = valibot(
|
|
641
|
+
const contains = schema.contains;
|
|
642
|
+
if (!contains) return [];
|
|
643
|
+
const containsSchema = valibot(contains, rootName, isValibot, options);
|
|
644
644
|
const minC = schema.minContains;
|
|
645
645
|
const maxC = schema.maxContains;
|
|
646
646
|
const errorMessage = schema["x-error-message"];
|
package/dist/valibot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToValibot } from "./valibot-
|
|
1
|
+
export { t as schemaToValibot } from "./valibot-Vj1GeCcx.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { K as rootNameOf, q as schemaNamer, s as sanitizeSchema, vt as makeSafeKey, yt as normalizeTypes } from "./helper-
|
|
1
|
+
import { K as rootNameOf, q as schemaNamer, s as sanitizeSchema, vt as makeSafeKey, yt as normalizeTypes } from "./helper-OCkRyx4U.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-
|
|
1
|
+
export { t as schemaToYup } from "./yup-DKlaai37.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as itemsSchemaOf, A as wireArrayOnce, Bt as isNullable, C as isNullTextRead, Dt as zodErrorPart, Et as zodError, F as timePattern, G as renderDefinitions, H as emitOptionsOf, Ht as isPlainObject, I as deepEqualExpression, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, Ln as UNSAFE_GENERATED_MARKER, M as wireNumericKind, Ot as hasCombinator, Pt as hasType, Rt as isDefaultOnlyMember, S as isNullMatchedFirst, T as numberWirePattern, Tt as zodBaseError, Ut as isPrimitive, V as definitionsOf, Vt as isObjectPrototypeProperty, W as planDocument, X as hasRootSelfReference, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, _t as issueMessageExpression, b as impliedWireType, c as refTarget, ct as foldAllOfMembers, d as parameterReaders, dt as regexLiteral, f as propertyEmitOptions, g as valueListLiteral, h as notPredicate, i as isEvaluatedKeyExpression, it as findCodeExtensionKeysInSchema, j as wireNullText, jt as hasFixedLength, k as unionPrimitiveTypes, kt as hasConditional, l as withPolymorphicBases, lt as isKeywordOnlyMember, m as isBigintFormat, mn as ISO_4217_CURRENCY_CODES, o as typeDeclaration, ot as constraintMessage, p as withoutParameterSerialization, q as schemaNamer, qt as isSchemaObject, r as evaluatedProperties, rn as DEFAULT_ROOT_NAME, s as sanitizeSchema, st as constraintPredicate, t as zodWrap, u as hasParameterSerialization, vt as makeSafeKey, w as isPrimitiveUnion, x as integerWirePattern, yt as normalizeTypes, zt as isNullTypeMember } from "./helper-
|
|
1
|
+
import { $ as itemsSchemaOf, A as wireArrayOnce, Bt as isNullable, C as isNullTextRead, Dt as zodErrorPart, Et as zodError, F as timePattern, G as renderDefinitions, H as emitOptionsOf, Ht as isPlainObject, I as deepEqualExpression, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, Ln as UNSAFE_GENERATED_MARKER, M as wireNumericKind, Ot as hasCombinator, Pt as hasType, Rt as isDefaultOnlyMember, S as isNullMatchedFirst, T as numberWirePattern, Tt as zodBaseError, Ut as isPrimitive, V as definitionsOf, Vt as isObjectPrototypeProperty, W as planDocument, X as hasRootSelfReference, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, _t as issueMessageExpression, b as impliedWireType, c as refTarget, ct as foldAllOfMembers, d as parameterReaders, dt as regexLiteral, f as propertyEmitOptions, g as valueListLiteral, h as notPredicate, i as isEvaluatedKeyExpression, it as findCodeExtensionKeysInSchema, j as wireNullText, jt as hasFixedLength, k as unionPrimitiveTypes, kt as hasConditional, l as withPolymorphicBases, lt as isKeywordOnlyMember, m as isBigintFormat, mn as ISO_4217_CURRENCY_CODES, o as typeDeclaration, ot as constraintMessage, p as withoutParameterSerialization, q as schemaNamer, qt as isSchemaObject, r as evaluatedProperties, rn as DEFAULT_ROOT_NAME, s as sanitizeSchema, st as constraintPredicate, t as zodWrap, u as hasParameterSerialization, vt as makeSafeKey, w as isPrimitiveUnion, x as integerWirePattern, yt as normalizeTypes, zt as isNullTypeMember } from "./helper-OCkRyx4U.js";
|
|
2
2
|
// src/generator/zod/type.ts
|
|
3
3
|
/** The TypeScript type declared beside a recursive Zod schema. */
|
|
4
4
|
function type(schema, rootName = DEFAULT_ROOT_NAME) {
|
|
@@ -196,13 +196,13 @@ function _enum(schema) {
|
|
|
196
196
|
const errorArg = zodErrorPart(errorMessage);
|
|
197
197
|
const valueSchema = (v) => {
|
|
198
198
|
if (Array.isArray(v)) return `z.tuple([${v.map(valueSchema).join(",")}])`;
|
|
199
|
-
if (isPlainObject(v)) return `z.strictObject({${Object.entries(v).map(([k,
|
|
199
|
+
if (isPlainObject(v)) return `z.strictObject({${Object.entries(v).map(([k, member]) => `${makeSafeKey(k)}:${valueSchema(member)}`).join(",")}})`;
|
|
200
200
|
return `z.literal(${lit(v, isBigint)})`;
|
|
201
201
|
};
|
|
202
202
|
const innerLit = (v) => valueSchema(v);
|
|
203
203
|
const outerLit = (v) => isComposite(v) ? valueSchema(v) : `z.literal(${lit(v, isBigint)}${errorArg})`;
|
|
204
|
-
const innerTuple = (
|
|
205
|
-
const outerTuple = (
|
|
204
|
+
const innerTuple = (members) => `z.tuple([${members.map(innerLit).join(",")}])`;
|
|
205
|
+
const outerTuple = (members) => `z.tuple([${members.map(innerLit).join(",")}]${errorArg})`;
|
|
206
206
|
if (hasType(schema, "number") || hasType(schema, "integer") || hasType(schema, "boolean")) return schema.enum.length > 1 ? `z.union([${schema.enum.map(innerLit).join(",")}]${errorArg})` : outerLit(schema.enum[0]);
|
|
207
207
|
if (hasType(schema, "array")) {
|
|
208
208
|
if (schema.enum.length === 1 && Array.isArray(schema.enum[0])) return outerTuple(schema.enum[0]);
|
|
@@ -280,7 +280,7 @@ function object(schema, rootName, isZod, options) {
|
|
|
280
280
|
return `.refine((val)=>Object.entries(val).every(([key,value])=>!new RegExp(${JSON.stringify(pattern)}).test(key)||${z}.safeParse(value).success)${patternErrorArg})`;
|
|
281
281
|
}).join("") : "";
|
|
282
282
|
const dependentRequired = schema.dependentRequired ? Object.entries(schema.dependentRequired).map(([key, deps]) => {
|
|
283
|
-
return `.refine((val)=>!('${key}' in val)||(${deps.map((
|
|
283
|
+
return `.refine((val)=>!('${key}' in val)||(${deps.map((dependency) => `'${dependency}' in val`).join("&&")})${depReqErrorArg})`;
|
|
284
284
|
}).join("") : "";
|
|
285
285
|
const dependentSchemas = schema.dependentSchemas ? Object.entries(schema.dependentSchemas).map(([key, subSchema]) => {
|
|
286
286
|
return `.refine((val)=>!('${key}' in val)||${zod(subSchema, rootName, isZod, options)}.safeParse(val).success${depSchErrorArg})`;
|
|
@@ -562,7 +562,7 @@ function zodNotPredicate(inner, parent) {
|
|
|
562
562
|
* parsed issues does not type-check as a raw issue, while each member does.
|
|
563
563
|
*/
|
|
564
564
|
function forwardIssue(message) {
|
|
565
|
-
return ZOD_ISSUE_CODES.map((
|
|
565
|
+
return ZOD_ISSUE_CODES.map((code, i) => `${i === 0 ? "" : "else "}if(issue.code==='${code}'){ctx.issues.push({...issue,input:issue.input,message:${message}})}`).join("");
|
|
566
566
|
}
|
|
567
567
|
/** A message for the issues under the value (with a path); the root's own issues keep theirs. */
|
|
568
568
|
function nestedIssueMessageWrap(inner, msg) {
|
|
@@ -678,7 +678,7 @@ function node(schema, rootName, isZod, options) {
|
|
|
678
678
|
...schema,
|
|
679
679
|
nullable
|
|
680
680
|
});
|
|
681
|
-
const intersected = schemas.length === 1 ? schemas[0] : schemas.reduce((acc, s) => `z.intersection(${acc},${s})`);
|
|
681
|
+
const intersected = schemas.length === 1 && schemas[0] !== void 0 ? schemas[0] : schemas.reduce((acc, s) => `z.intersection(${acc},${s})`);
|
|
682
682
|
const allOfMessage = schema["x-allOf-message"];
|
|
683
683
|
const checked = objectKeysCheck(allOfMessage ? (() => {
|
|
684
684
|
const branches = forwardIssue(issueMessageExpression(allOfMessage));
|
|
@@ -722,25 +722,25 @@ function node(schema, rootName, isZod, options) {
|
|
|
722
722
|
}
|
|
723
723
|
if (schema.properties) return readonly(zodWrap$1(object(schema, rootName, isZod, options), schema));
|
|
724
724
|
const types = normalizeTypes(schema.type);
|
|
725
|
-
const primitive = (
|
|
726
|
-
if (
|
|
727
|
-
if (
|
|
728
|
-
if (
|
|
729
|
-
if (
|
|
725
|
+
const primitive = (primitiveType) => {
|
|
726
|
+
if (primitiveType === "string") return string(schema);
|
|
727
|
+
if (primitiveType === "number") return number(schema, { wire: isWireCoerced });
|
|
728
|
+
if (primitiveType === "integer") return integer(schema, { wire: isWireCoerced });
|
|
729
|
+
if (primitiveType !== "boolean") return void 0;
|
|
730
730
|
const errorMessage = schema["x-error-message"];
|
|
731
731
|
const errorArg = errorMessage ? zodError(errorMessage) : "";
|
|
732
732
|
if (isStringWireParam) return `z.stringbool(${errorArg ? `{error:${errorArg.replaceAll(/^{error:|}$/g, "")}}` : ""})`;
|
|
733
733
|
return `z.${schema["x-coerce"] === true ? "coerce." : ""}boolean(${errorArg})`;
|
|
734
734
|
};
|
|
735
735
|
if (isPrimitiveUnion(types, isWireCoerced)) return zodWrap$1(`z.union([${unionPrimitiveTypes(types, isWireCoerced).map(primitive).filter((m) => m !== void 0).join(",")}])`, schema);
|
|
736
|
-
for (const
|
|
736
|
+
for (const primitiveType of [
|
|
737
737
|
"string",
|
|
738
738
|
"number",
|
|
739
739
|
"integer",
|
|
740
740
|
"boolean"
|
|
741
741
|
]) {
|
|
742
|
-
if (!types.includes(
|
|
743
|
-
const expression = primitive(
|
|
742
|
+
if (!types.includes(primitiveType)) continue;
|
|
743
|
+
const expression = primitive(primitiveType);
|
|
744
744
|
if (expression !== void 0) return zodWrap$1(expression, schema);
|
|
745
745
|
}
|
|
746
746
|
if (types.includes("array")) {
|
|
@@ -754,13 +754,13 @@ function node(schema, rootName, isZod, options) {
|
|
|
754
754
|
const fixedItemsError = zodErrorPart(minItemsMessage ?? maxItemsMessage);
|
|
755
755
|
const uniqueMessage = schema["x-uniqueItems-message"];
|
|
756
756
|
const uniqueError = zodErrorPart(uniqueMessage);
|
|
757
|
-
if (schema.prefixItems
|
|
757
|
+
if (schema.prefixItems !== void 0 && schema.prefixItems.length > 0) {
|
|
758
758
|
const items = schema.prefixItems.map((s) => zod(s, rootName, isZod, options));
|
|
759
|
-
const
|
|
759
|
+
const unevaluatedItems = schema.unevaluatedItems;
|
|
760
760
|
const unevaluatedItemsMessage = schema["x-unevaluatedItems-message"];
|
|
761
761
|
const unevaluatedItemsError = zodErrorPart(unevaluatedItemsMessage);
|
|
762
|
-
const rest = isSchemaObject(
|
|
763
|
-
const tupleExpr = `z.tuple(${rest ? `[${items.join(",")}],${rest}` : `[${items.join(",")}]`}${
|
|
762
|
+
const rest = isSchemaObject(unevaluatedItems) ? zod(unevaluatedItems, rootName, isZod, options) : void 0;
|
|
763
|
+
const tupleExpr = `z.tuple(${rest ? `[${items.join(",")}],${rest}` : `[${items.join(",")}]`}${unevaluatedItems === false && unevaluatedItemsMessage ? unevaluatedItemsError : baseError})`;
|
|
764
764
|
const prefixItemsMessage = schema["x-prefixItems-message"];
|
|
765
765
|
return readonly(zodWrap$1(wireArray(prefixItemsMessage ? elementMessageWrap(tupleExpr, prefixItemsMessage) : tupleExpr), schema));
|
|
766
766
|
}
|
|
@@ -771,9 +771,9 @@ function node(schema, rootName, isZod, options) {
|
|
|
771
771
|
const base = itemsMessage ? elementMessageWrap(arrayBase, itemsMessage) : arrayBase;
|
|
772
772
|
const unique = schema.uniqueItems === true ? `.refine((val)=>new Set(val).size===val.length${uniqueError})` : "";
|
|
773
773
|
const containsChain = (() => {
|
|
774
|
-
const
|
|
775
|
-
if (!
|
|
776
|
-
const containsZod = zod(
|
|
774
|
+
const containsSchema = schema.contains;
|
|
775
|
+
if (!containsSchema) return "";
|
|
776
|
+
const containsZod = zod(containsSchema, rootName, isZod, options);
|
|
777
777
|
const minC = schema.minContains;
|
|
778
778
|
const maxC = schema.maxContains;
|
|
779
779
|
const fallback = schema["x-contains-message"] ?? errorMessage;
|
package/dist/zod.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToZod } from "./zod-
|
|
1
|
+
export { t as schemaToZod } from "./zod-04J51AMt.js";
|