schema-truth 0.8.7 → 0.8.9
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-BjWqjOc9.js → ajv-Oz83L2oz.js} +1 -1
- package/dist/ajv.js +1 -1
- package/dist/{arktype-pHeYh_IG.js → arktype-DDbxpolC.js} +42 -57
- 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-CLh6PrSG.js → cli-PNyg10lA.js} +8 -8
- package/dist/{effect-CM1XVqvf.js → effect-CHLS1Yit.js} +19 -19
- package/dist/effect.js +1 -1
- package/dist/{helper-1oDB5NHM.js → helper-OCkRyx4U.js} +54 -50
- package/dist/index.d.ts +71 -65
- package/dist/index.js +8 -8
- package/dist/{typebox-CnmZohGb.js → typebox-fUy-Ywxw.js} +18 -14
- package/dist/typebox.js +1 -1
- package/dist/{valibot-1p_Y7fu6.js → valibot-Vj1GeCcx.js} +20 -20
- package/dist/valibot.js +1 -1
- package/dist/{yup-IOat93gr.js → yup-DKlaai37.js} +1 -1
- package/dist/yup.js +1 -1
- package/dist/{zod-q9c0XhJO.js → zod-04J51AMt.js} +23 -23
- package/dist/zod.js +1 -1
- package/package.json +1 -1
|
@@ -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 = [];
|
|
@@ -1837,7 +1836,8 @@ function definitionName(ref) {
|
|
|
1837
1836
|
* The discriminator values that select each `oneOf` / `anyOf` member (OpenAPI 3.x
|
|
1838
1837
|
* Discriminator Object): the `mapping` keys whose target names the member's `$ref`, or,
|
|
1839
1838
|
* when the mapping names it nowhere, the definition name itself (the implicit mapping).
|
|
1840
|
-
* `undefined` when the
|
|
1839
|
+
* A member's `values` is `undefined` when it is not a `$ref` the mapping can name, and the
|
|
1840
|
+
* whole result is `undefined` when the node has no discriminator property.
|
|
1841
1841
|
*/
|
|
1842
1842
|
function discriminatedMembers(schema, members) {
|
|
1843
1843
|
const propertyName = schema.discriminator?.propertyName;
|
|
@@ -2190,7 +2190,7 @@ function impliedWireType(schema) {
|
|
|
2190
2190
|
* reads text, so the string member is tried last.
|
|
2191
2191
|
*/
|
|
2192
2192
|
function unionPrimitiveTypes(types, isWire) {
|
|
2193
|
-
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")));
|
|
2194
2194
|
}
|
|
2195
2195
|
/** Whether a `type` list is a union of primitives alone: more than one, and no array or object. */
|
|
2196
2196
|
function isPrimitiveUnion(types, isWire) {
|
|
@@ -2466,7 +2466,7 @@ function notPredicate(inner, param, parameter = param, bigint = false) {
|
|
|
2466
2466
|
return body === void 0 ? void 0 : `(${parameter}) => ${body}`;
|
|
2467
2467
|
}
|
|
2468
2468
|
if (Array.isArray(inner.type)) {
|
|
2469
|
-
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})`);
|
|
2470
2470
|
if (bodies.length > 0) return `(${parameter}) => ${bodies.join(" && ")}`;
|
|
2471
2471
|
}
|
|
2472
2472
|
}
|
|
@@ -2690,6 +2690,11 @@ function withPolymorphicBases(schema) {
|
|
|
2690
2690
|
* Resolves a `$ref` for the Zod, Valibot and Effect generators, which name declarations
|
|
2691
2691
|
* alike: a definition is `Name` inside a document (`isDocument`), `NameSchema` when a
|
|
2692
2692
|
* single schema is emitted under the default root name, and a thunk everywhere else.
|
|
2693
|
+
*
|
|
2694
|
+
* The `kind` says how the declaration is reached from the node being emitted: `lazy` through
|
|
2695
|
+
* a deferred thunk (`z.lazy`, `v.lazy`, `Schema.suspend`), `value` by its identifier because
|
|
2696
|
+
* it is known to be initialised first, `unknown` for a pointer into a sub-schema, which has
|
|
2697
|
+
* no declaration of its own, and `any` for a `$ref` the generators do not follow.
|
|
2693
2698
|
*/
|
|
2694
2699
|
function refTarget(ref, rootName, isDocument, openapi) {
|
|
2695
2700
|
if (isRootRef(ref)) return {
|
|
@@ -2831,7 +2836,7 @@ function conform(shape, value) {
|
|
|
2831
2836
|
case "type": {
|
|
2832
2837
|
if (typeof value === "string") return value;
|
|
2833
2838
|
if (!Array.isArray(value)) return void 0;
|
|
2834
|
-
const types = value.filter((
|
|
2839
|
+
const types = value.filter((member) => typeof member === "string");
|
|
2835
2840
|
return types.length > 0 ? types : void 0;
|
|
2836
2841
|
}
|
|
2837
2842
|
case "stringList": return Array.isArray(value) ? value.flatMap((v) => typeof v === "string" ? [v] : isPlainObject(v) || Array.isArray(v) ? [] : [String(v)]) : void 0;
|
|
@@ -2921,8 +2926,9 @@ function nonNullType(schema, flavour, rootName) {
|
|
|
2921
2926
|
if (schema.oneOf || schema.anyOf) return `(${(schema.oneOf ?? schema.anyOf ?? []).map(type).join(" | ")})`;
|
|
2922
2927
|
if (schema.allOf) {
|
|
2923
2928
|
const members = schema.allOf.filter((s) => !isShapelessMember(s)).map(type);
|
|
2924
|
-
|
|
2925
|
-
if (
|
|
2929
|
+
const [member, ...others] = members;
|
|
2930
|
+
if (member === void 0) return "unknown";
|
|
2931
|
+
if (others.length === 0) return member;
|
|
2926
2932
|
return `(${members.join(" & ")})`;
|
|
2927
2933
|
}
|
|
2928
2934
|
if (schema.not) return "unknown";
|
|
@@ -2935,11 +2941,8 @@ function nonNullType(schema, flavour, rootName) {
|
|
|
2935
2941
|
const readonly = flavour.readonly ? "readonly " : "";
|
|
2936
2942
|
const object = () => {
|
|
2937
2943
|
if (!schema.properties) {
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
return `{ [key: string]: ${type(schema.additionalProperties)} }`;
|
|
2941
|
-
}
|
|
2942
|
-
return "{ [key: string]: unknown }";
|
|
2944
|
+
const additional = schema.additionalProperties;
|
|
2945
|
+
return isPlainObject(additional) ? `{ [key: string]: ${type(additional)} }` : "{ [key: string]: unknown }";
|
|
2943
2946
|
}
|
|
2944
2947
|
const required = new Set(schema.required);
|
|
2945
2948
|
return `{${Object.entries(schema.properties).map(([key, propSchema]) => {
|
|
@@ -2949,22 +2952,23 @@ function nonNullType(schema, flavour, rootName) {
|
|
|
2949
2952
|
}).join("; ")}}`;
|
|
2950
2953
|
};
|
|
2951
2954
|
if (schema.properties) return object();
|
|
2952
|
-
const
|
|
2955
|
+
const types = normalizeTypes(schema.type);
|
|
2953
2956
|
const integerType = isInt64(schema) || schema.format === "bigint" ? "bigint" : "number";
|
|
2954
2957
|
const primitives = [
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
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
|
|
2958
2961
|
].filter((p) => p !== void 0);
|
|
2959
|
-
if (primitives.length > 1 && !
|
|
2960
|
-
|
|
2961
|
-
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")) {
|
|
2962
2966
|
const items = itemsSchemaOf(schema.items);
|
|
2963
2967
|
return items ? `${readonly}${type(items)}[]` : `${readonly}unknown[]`;
|
|
2964
2968
|
}
|
|
2965
|
-
if (
|
|
2966
|
-
if (
|
|
2967
|
-
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";
|
|
2968
2972
|
return "unknown";
|
|
2969
2973
|
}
|
|
2970
2974
|
// src/helper/typebox-wrap.ts
|
package/dist/index.d.ts
CHANGED
|
@@ -60,70 +60,6 @@ export declare function wholeValueMessage(inner: string, message: string): strin
|
|
|
60
60
|
* has no separate runtime "readonly" wrapper.
|
|
61
61
|
*/
|
|
62
62
|
export declare function effect(schema: JSONSchema, rootName?: string, isEffect?: boolean, options?: EmitOptions): string;
|
|
63
|
-
/**
|
|
64
|
-
* Generation options threaded through every TypeBox emitter.
|
|
65
|
-
*
|
|
66
|
-
* `cyclicRefs` holds the PascalCase names that `schemaToTypebox` is emitting
|
|
67
|
-
* inside a single `Type.Cyclic($defs, root)` map. References to those names
|
|
68
|
-
* become `Type.Ref('Name')` instead of a bare identifier, because a `const`
|
|
69
|
-
* cannot reference a peer that is declared later in the cycle.
|
|
70
|
-
*
|
|
71
|
-
* `ref` is a host `$ref` name for the **current** node only (the outermost
|
|
72
|
-
* `Type.*` factory). Nested calls drop it so properties and `$defs` members
|
|
73
|
-
* do not inherit the root's name.
|
|
74
|
-
*/
|
|
75
|
-
export type TypeboxOptions = {
|
|
76
|
-
readonly openapi?: boolean;
|
|
77
|
-
readonly readonly?: boolean;
|
|
78
|
-
readonly paramIn?: ParamIn;
|
|
79
|
-
readonly cyclicRefs?: ReadonlySet<string>;
|
|
80
|
-
readonly ref?: string;
|
|
81
|
-
/** Definitions a `default` beside a `$ref` is checked against. */
|
|
82
|
-
readonly definitions?: SchemaDefinitions;
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Options for a nested TypeBox node: the same as `options` but without a
|
|
86
|
-
* host `ref`, so only the outermost factory of a declaration receives it.
|
|
87
|
-
*/
|
|
88
|
-
export declare function nestedTypeboxOptions(options?: TypeboxOptions): TypeboxOptions | undefined;
|
|
89
|
-
export declare function typebox(schema: JSONSchema, rootName?: string, isTypebox?: boolean, options?: TypeboxOptions): string;
|
|
90
|
-
/**
|
|
91
|
-
* Generate Valibot schema code from JSON Schema.
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```ts
|
|
95
|
-
* valibot({ type: 'string' }, 'MySchema') // 'v.string()'
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
export declare function valibot(schema: JSONSchema, rootName?: string, isValibot?: boolean, options?: EmitOptions): string;
|
|
99
|
-
/**
|
|
100
|
-
* Generate a Yup expression from one JSON Schema node.
|
|
101
|
-
*
|
|
102
|
-
* Unsupported keywords, combinators, `$ref` and `x-*` extensions are silent
|
|
103
|
-
* no-ops. Unknown nodes fall back to `yup.mixed()`.
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* ```ts
|
|
107
|
-
* yup({ type: 'string' }) // 'yup.string()'
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
|
-
export declare function yup(schema: JSONSchema): string;
|
|
111
|
-
/**
|
|
112
|
-
* Re-push `issue` into `ctx` with `message`. Each issue code is narrowed first: the union of
|
|
113
|
-
* parsed issues does not type-check as a raw issue, while each member does.
|
|
114
|
-
*/
|
|
115
|
-
export declare function forwardIssue(message: string): string;
|
|
116
|
-
/** A message for the issues under the value (with a path); the root's own issues keep theirs. */
|
|
117
|
-
export declare function nestedIssueMessageWrap(inner: string, msg: string): string;
|
|
118
|
-
/**
|
|
119
|
-
* Generate Zod schema code from JSON Schema.
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* ```ts
|
|
123
|
-
* zod({ type: 'string' }, 'MySchema') // 'z.string()'
|
|
124
|
-
* ```
|
|
125
|
-
*/
|
|
126
|
-
export declare function zod(schema: JSONSchema, rootName?: string, isZod?: boolean, options?: EmitOptions): string;
|
|
127
63
|
/**
|
|
128
64
|
* Convert string to PascalCase (first character uppercase).
|
|
129
65
|
*
|
|
@@ -170,7 +106,7 @@ export declare function encodeNonAscii(name: string): string;
|
|
|
170
106
|
* ```
|
|
171
107
|
*/
|
|
172
108
|
export declare function toIdentifierPascalCase(name: string): string;
|
|
173
|
-
export declare function normalizeTypes(
|
|
109
|
+
export declare function normalizeTypes(types?: string | readonly string[]): string[];
|
|
174
110
|
/** The keywords of a schema node {@link coerceDefault} reads a `default` against. */
|
|
175
111
|
export type DefaultSchema = {
|
|
176
112
|
readonly $ref?: string;
|
|
@@ -320,4 +256,74 @@ export declare function resolveOpenAPIRef($ref: string): string | null;
|
|
|
320
256
|
* ```
|
|
321
257
|
*/
|
|
322
258
|
export declare function makeSafeKey(key: string): string;
|
|
259
|
+
/**
|
|
260
|
+
* Generation options threaded through every TypeBox emitter.
|
|
261
|
+
*
|
|
262
|
+
* `cyclicRefs` holds the PascalCase names that `schemaToTypebox` is emitting
|
|
263
|
+
* inside a single `Type.Cyclic($defs, root)` map. References to those names
|
|
264
|
+
* become `Type.Ref('Name')` instead of a bare identifier, because a `const`
|
|
265
|
+
* cannot reference a peer that is declared later in the cycle.
|
|
266
|
+
*
|
|
267
|
+
* `ref` is a host `$ref` name for the **current** node only (the outermost
|
|
268
|
+
* `Type.*` factory). Nested calls drop it so properties and `$defs` members
|
|
269
|
+
* do not inherit the root's name.
|
|
270
|
+
*/
|
|
271
|
+
export type TypeboxOptions = {
|
|
272
|
+
readonly openapi?: boolean;
|
|
273
|
+
readonly readonly?: boolean;
|
|
274
|
+
readonly paramIn?: ParamIn;
|
|
275
|
+
readonly cyclicRefs?: ReadonlySet<string>;
|
|
276
|
+
readonly ref?: string;
|
|
277
|
+
/** Definitions a `default` beside a `$ref` is checked against. */
|
|
278
|
+
readonly definitions?: SchemaDefinitions;
|
|
279
|
+
};
|
|
280
|
+
/**
|
|
281
|
+
* Options for a nested TypeBox node: the same as `options` but without a
|
|
282
|
+
* host `ref`, so only the outermost factory of a declaration receives it.
|
|
283
|
+
*/
|
|
284
|
+
export declare function nestedTypeboxOptions(options?: TypeboxOptions): {
|
|
285
|
+
openapi?: boolean;
|
|
286
|
+
readonly?: boolean;
|
|
287
|
+
paramIn?: "cookie" | "formData" | "header" | "path" | "query";
|
|
288
|
+
cyclicRefs?: ReadonlySet<string>;
|
|
289
|
+
definitions?: SchemaDefinitions;
|
|
290
|
+
} | undefined;
|
|
291
|
+
export declare function typebox(schema: JSONSchema, rootName?: string, isTypebox?: boolean, options?: TypeboxOptions): string;
|
|
292
|
+
/**
|
|
293
|
+
* Generate Valibot schema code from JSON Schema.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```ts
|
|
297
|
+
* valibot({ type: 'string' }, 'MySchema') // 'v.string()'
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
export declare function valibot(schema: JSONSchema, rootName?: string, isValibot?: boolean, options?: EmitOptions): string;
|
|
301
|
+
/**
|
|
302
|
+
* Generate a Yup expression from one JSON Schema node.
|
|
303
|
+
*
|
|
304
|
+
* Unsupported keywords, combinators, `$ref` and `x-*` extensions are silent
|
|
305
|
+
* no-ops. Unknown nodes fall back to `yup.mixed()`.
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```ts
|
|
309
|
+
* yup({ type: 'string' }) // 'yup.string()'
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
export declare function yup(schema: JSONSchema): string;
|
|
313
|
+
/**
|
|
314
|
+
* Re-push `issue` into `ctx` with `message`. Each issue code is narrowed first: the union of
|
|
315
|
+
* parsed issues does not type-check as a raw issue, while each member does.
|
|
316
|
+
*/
|
|
317
|
+
export declare function forwardIssue(message: string): string;
|
|
318
|
+
/** A message for the issues under the value (with a path); the root's own issues keep theirs. */
|
|
319
|
+
export declare function nestedIssueMessageWrap(inner: string, msg: string): string;
|
|
320
|
+
/**
|
|
321
|
+
* Generate Zod schema code from JSON Schema.
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```ts
|
|
325
|
+
* zod({ type: 'string' }, 'MySchema') // 'z.string()'
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
export declare function zod(schema: JSONSchema, rootName?: string, isZod?: boolean, options?: EmitOptions): string;
|
|
323
329
|
export { ALL_CODE_EXTENSION_KEYS, ANCHOR_REF_PATTERN, ARKTYPE_CODE_EXTENSION_KEYS, ARROW_FUNCTION_PATTERN, COMPONENT_SCHEMA_REF_PREFIX, CONTENT_ENCODINGS, ContentEncoding, DATE_PATTERN_SOURCE, DEFAULT_ROOT_NAME, DEFINITION_KEYWORDS, DEFINITION_POINTER_PATTERN, DEFINITION_REF_PREFIXES, EFFECT_CODE_EXTENSION_KEYS, type EmitOptions, ExternalRef, FORMAT_PATTERNS, type GenerateOptions, IDENTIFIER_PATTERN, IF_THEN_ELSE_UNSUPPORTED_MARKER, INPUT_EXTENSIONS, INTEGER_TEXT_PATTERN, INTEGER_WIRE_PATTERN, ISO_4217_CURRENCY_CODES, JSONSchema, JSONSchemaFormat, JSONSchemaNumberFormat, JSONSchemaStringFormat, JSONSchemaType, JSONSchemaTypes, type JSONValue, JSON_SCHEMA_TYPES, LocalRef, 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, type ParamIn, type ParamStyle, ParseError, QUOTE_OR_BACKSLASH_PATTERN, ROOT_REFS, Ref, STRINGBOOL_PATTERN, STRINGBOOL_TRUTHY_PATTERN, STRING_FORMATS, STRING_KEYWORDS, STRING_WIRE_LOCATIONS, TypeboxGenerateOptions, UNICODE_ESCAPE_PATTERN, UNSAFE_GENERATED_MARKER, VALIBOT_CODE_EXTENSION_KEYS, WIRE_PRIMITIVE_ORDER, type XExtCode, type XExtMessages, type XExtParam, type XExtTransform, ZOD_CODE_EXTENSION_KEYS, parseSchemaFile, schemaToAjv, schemaToArktype, schemaToEffect, schemaToTypebox, schemaToValibot, schemaToYup, schemaToZod };
|
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-fUy-Ywxw.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";
|
|
@@ -36,11 +36,13 @@ function integer(schema, ref) {
|
|
|
36
36
|
const maxMessage = schema["x-maximum-message"];
|
|
37
37
|
const exclusiveMinimumMessage = schema["x-exclusiveMinimum-message"];
|
|
38
38
|
const exclusiveMaximumMessage = schema["x-exclusiveMaximum-message"];
|
|
39
|
+
const minimumKeyword = schema.exclusiveMinimum === true && schema.minimum !== void 0 ? "exclusiveMinimum" : "minimum";
|
|
40
|
+
const maximumKeyword = schema.exclusiveMaximum === true && schema.maximum !== void 0 ? "exclusiveMaximum" : "maximum";
|
|
39
41
|
const multipleOfMessage = schema["x-multipleOf-message"];
|
|
40
42
|
const perKeywordEntries = [];
|
|
41
43
|
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)}`);
|
|
44
|
+
if (minMessage && minimumKeyword === "minimum") perKeywordEntries.push(`minimum:${JSON.stringify(minMessage)}`);
|
|
45
|
+
if (maxMessage && maximumKeyword === "maximum") perKeywordEntries.push(`maximum:${JSON.stringify(maxMessage)}`);
|
|
44
46
|
if (exclusiveMinimumMessage) perKeywordEntries.push(`exclusiveMinimum:${JSON.stringify(exclusiveMinimumMessage)}`);
|
|
45
47
|
if (exclusiveMaximumMessage) perKeywordEntries.push(`exclusiveMaximum:${JSON.stringify(exclusiveMaximumMessage)}`);
|
|
46
48
|
if (multipleOfMessage) perKeywordEntries.push(`multipleOf:${JSON.stringify(multipleOfMessage)}`);
|
|
@@ -49,8 +51,8 @@ function integer(schema, ref) {
|
|
|
49
51
|
if (schema.format === "bigint") {
|
|
50
52
|
const opts = [
|
|
51
53
|
...typeboxRefOpt(ref),
|
|
52
|
-
schema.minimum !== void 0 ?
|
|
53
|
-
schema.maximum !== void 0 ?
|
|
54
|
+
schema.minimum !== void 0 ? `${minimumKeyword}:BigInt(${schema.minimum})` : void 0,
|
|
55
|
+
schema.maximum !== void 0 ? `${maximumKeyword}:BigInt(${schema.maximum})` : void 0,
|
|
54
56
|
errorMessageField,
|
|
55
57
|
...metaOpts
|
|
56
58
|
].filter((v) => v !== void 0);
|
|
@@ -59,9 +61,9 @@ function integer(schema, ref) {
|
|
|
59
61
|
}
|
|
60
62
|
const opts = [
|
|
61
63
|
...typeboxRefOpt(ref),
|
|
62
|
-
schema.minimum !== void 0 ?
|
|
64
|
+
schema.minimum !== void 0 ? `${minimumKeyword}:${schema.minimum}` : void 0,
|
|
63
65
|
typeof schema.exclusiveMinimum === "number" ? `exclusiveMinimum:${schema.exclusiveMinimum}` : void 0,
|
|
64
|
-
schema.maximum !== void 0 ?
|
|
66
|
+
schema.maximum !== void 0 ? `${maximumKeyword}:${schema.maximum}` : void 0,
|
|
65
67
|
typeof schema.exclusiveMaximum === "number" ? `exclusiveMaximum:${schema.exclusiveMaximum}` : void 0,
|
|
66
68
|
schema.multipleOf !== void 0 ? `multipleOf:${schema.multipleOf}` : void 0,
|
|
67
69
|
errorMessageField,
|
|
@@ -78,20 +80,22 @@ function number(schema, ref) {
|
|
|
78
80
|
const maxMessage = schema["x-maximum-message"];
|
|
79
81
|
const exclusiveMinimumMessage = schema["x-exclusiveMinimum-message"];
|
|
80
82
|
const exclusiveMaximumMessage = schema["x-exclusiveMaximum-message"];
|
|
83
|
+
const minimumKeyword = schema.exclusiveMinimum === true && schema.minimum !== void 0 ? "exclusiveMinimum" : "minimum";
|
|
84
|
+
const maximumKeyword = schema.exclusiveMaximum === true && schema.maximum !== void 0 ? "exclusiveMaximum" : "maximum";
|
|
81
85
|
const multipleOfMessage = schema["x-multipleOf-message"];
|
|
82
86
|
const perKeywordEntries = [];
|
|
83
87
|
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)}`);
|
|
88
|
+
if (minMessage && minimumKeyword === "minimum") perKeywordEntries.push(`minimum:${JSON.stringify(minMessage)}`);
|
|
89
|
+
if (maxMessage && maximumKeyword === "maximum") perKeywordEntries.push(`maximum:${JSON.stringify(maxMessage)}`);
|
|
86
90
|
if (exclusiveMinimumMessage) perKeywordEntries.push(`exclusiveMinimum:${JSON.stringify(exclusiveMinimumMessage)}`);
|
|
87
91
|
if (exclusiveMaximumMessage) perKeywordEntries.push(`exclusiveMaximum:${JSON.stringify(exclusiveMaximumMessage)}`);
|
|
88
92
|
if (multipleOfMessage) perKeywordEntries.push(`multipleOf:${JSON.stringify(multipleOfMessage)}`);
|
|
89
93
|
const errorMessageField = perKeywordEntries.length === 0 ? errorMessage ? `errorMessage:${JSON.stringify(errorMessage)}` : void 0 : `errorMessage:{${perKeywordEntries.join(",")}${errorMessage ? `,_:${JSON.stringify(errorMessage)}` : ""}}`;
|
|
90
94
|
const opts = [
|
|
91
95
|
...typeboxRefOpt(ref),
|
|
92
|
-
schema.minimum !== void 0 ?
|
|
96
|
+
schema.minimum !== void 0 ? `${minimumKeyword}:${schema.minimum}` : void 0,
|
|
93
97
|
typeof schema.exclusiveMinimum === "number" ? `exclusiveMinimum:${schema.exclusiveMinimum}` : void 0,
|
|
94
|
-
schema.maximum !== void 0 ?
|
|
98
|
+
schema.maximum !== void 0 ? `${maximumKeyword}:${schema.maximum}` : void 0,
|
|
95
99
|
typeof schema.exclusiveMaximum === "number" ? `exclusiveMaximum:${schema.exclusiveMaximum}` : void 0,
|
|
96
100
|
schema.multipleOf !== void 0 ? `multipleOf:${schema.multipleOf}` : void 0,
|
|
97
101
|
errorMessageField,
|
|
@@ -475,7 +479,7 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
|
|
|
475
479
|
...defaultValue !== void 0 ? { default: defaultValue } : ownDefault !== void 0 && { default: ownDefault }
|
|
476
480
|
};
|
|
477
481
|
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, [
|
|
482
|
+
const baseResult = schemas.length === 1 && schemas[0] !== void 0 && unevaluatedOpt.length === 0 && defaultOpt.length === 0 ? schemas[0] : tbComp("Type.Intersect", `[${schemas.join(",")}]`, withoutDefault, [
|
|
479
483
|
...messageOpt(schema["x-allOf-message"]),
|
|
480
484
|
...unevaluatedOpt,
|
|
481
485
|
...defaultOpt
|
|
@@ -484,7 +488,7 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
|
|
|
484
488
|
}
|
|
485
489
|
if (schema.not) {
|
|
486
490
|
const { not: dropped, ...withoutNot } = schema;
|
|
487
|
-
if (
|
|
491
|
+
if (withoutNot.type !== void 0) return typebox(withoutNot, rootName, isTypebox, options);
|
|
488
492
|
return typeboxWrap(tbPrim("Type.Any", schema, messageOpt(schema["x-not-message"]), hostRef), schema);
|
|
489
493
|
}
|
|
490
494
|
if (schema.const !== void 0) {
|
|
@@ -519,7 +523,7 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
|
|
|
519
523
|
return typeboxWrap(tbPrim("Type.Boolean", schema, [], hostRef), schema);
|
|
520
524
|
}
|
|
521
525
|
if (types.includes("array")) {
|
|
522
|
-
if (schema.prefixItems
|
|
526
|
+
if (schema.prefixItems !== void 0 && schema.prefixItems.length > 0) {
|
|
523
527
|
const items = schema.prefixItems.map((s) => typebox(s, rootName, isTypebox, childOptions));
|
|
524
528
|
const prefixItemsMessage = schema["x-prefixItems-message"];
|
|
525
529
|
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-fUy-Ywxw.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"];
|
|
@@ -701,7 +701,7 @@ function schemaToValibot(input, options) {
|
|
|
701
701
|
const schema = withPolymorphicBases(hoistNestedRefs(sanitizeSchema(input)));
|
|
702
702
|
const exportType = options?.exportType ?? true;
|
|
703
703
|
const baseOptions = emitOptionsOf(options);
|
|
704
|
-
const codeExtensionsPresent = baseOptions.unsafeCodeExtensions
|
|
704
|
+
const codeExtensionsPresent = baseOptions.unsafeCodeExtensions && findCodeExtensionKeysInSchema(schema).length > 0;
|
|
705
705
|
const toName = schemaNamer(baseOptions.openapi);
|
|
706
706
|
const plan = planDocument(schema, rootNameOf(schema, toName));
|
|
707
707
|
const definitions = definitionsOf(baseOptions, plan.definitions);
|
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";
|