schema-truth 0.8.1 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{ajv-DS9gtNZC.js → ajv-DejgT2o1.js} +8 -14
- package/dist/ajv.d.ts +2 -4
- package/dist/ajv.js +1 -1
- package/dist/{arktype-CRZ8vXZ5.js → arktype-CzTltPwP.js} +94 -55
- package/dist/arktype.d.ts +3 -5
- package/dist/arktype.js +1 -1
- package/dist/cli/ajv.js +3 -4
- package/dist/cli/arktype.js +3 -4
- package/dist/cli/effect.js +3 -4
- package/dist/cli/typebox.js +3 -4
- package/dist/cli/valibot.js +3 -4
- package/dist/cli/yup.js +3 -4
- package/dist/cli/zod.js +3 -4
- package/dist/{cli-eAY8LqwP.js → cli-71Np9i5L.js} +6 -9
- package/dist/{effect-BkWovUi3.js → effect-Dj8qARFi.js} +70 -44
- package/dist/effect.d.ts +3 -5
- package/dist/effect.js +1 -1
- package/dist/{helper-CbeedY35.js → helper-WSNbEQKr.js} +1398 -52
- package/dist/{index-G7UqNQ4w.d.ts → index-DLVjyrKu.d.ts} +0 -14
- package/dist/{index-DYzAccyT.d.ts → index-DU2Nd8eI.d.ts} +2 -6
- package/dist/index.d.ts +11 -20
- package/dist/index.js +10 -10
- package/dist/{parser-CyJ2auea.js → parser-RBrkz7ZL.js} +2 -4
- package/dist/{typebox-wYeJqy7T.js → typebox-RAJnIZwI.js} +60 -47
- package/dist/typebox.d.ts +3 -5
- package/dist/typebox.js +1 -1
- package/dist/{valibot-DQUEDYKt.js → valibot-CLUhG6tp.js} +66 -45
- package/dist/valibot.d.ts +3 -5
- package/dist/valibot.js +1 -1
- package/dist/{yup-BMpa9Co1.js → yup-DfE_ofEu.js} +9 -15
- package/dist/yup.d.ts +3 -5
- package/dist/yup.js +1 -1
- package/dist/{zod-Dq9LtqPL.js → zod-BhYAQ3iW.js} +84 -56
- package/dist/zod.d.ts +3 -5
- package/dist/zod.js +1 -1
- package/package.json +5 -5
- package/dist/utils-Bky98UmP.js +0 -1146
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { At as
|
|
2
|
-
|
|
3
|
-
//#region src/generator/valibot/type.ts
|
|
1
|
+
import { A as wireArrayOnce, At as hasFixedLength, Bt as isObjectPrototypeProperty, C as isNullTextRead, Ct as valibotErrorPart, D as stringboolPattern, Dt as hasCombinator, E as ownProperties, G as renderDefinitions, H as emitOptionsOf, Ht as isPrimitive, I as deepEqualExpression, In as UNSAFE_GENERATED_MARKER, J as discriminatedMembers, Jt as isStringWireLocation, K as rootNameOf, Kt as isSchemaObject, L as jsLiteral, Lt as isDefaultOnlyMember, M as wireNumericKind, N as formatPattern, Nt as hasType, O as stringboolTruthyPattern, Ot as hasConditional, P as regexSource, Q as itemsSchemaOf, Rt as isNullTypeMember, St as valibotError, T as numberWirePattern, V as definitionsOf, W as planDocument, X as hasRootSelfReference, Z as isOptionalByDefault, _ as hoistNestedRefs, _t as makeSafeKey, at as constraintMessage, b as impliedWireType, c as refTarget, ct as isKeywordOnlyMember, d as parameterReaders, dn as INTEGER_TEXT_PATTERN, f as propertyEmitOptions, g as valueListLiteral, gt as issueMessageExpression, h as notPredicate, i as isEvaluatedKeyExpression, k as unionPrimitiveTypes, kt as hasFixedItemCount, l as withPolymorphicBases, m as isBigintFormat, n as valibotWrap, nn as DEFAULT_ROOT_NAME, o as typeDeclaration, ot as constraintPredicate, p as withoutParameterSerialization, q as schemaNamer, qt as isShapelessMember, r as evaluatedProperties, rt as findCodeExtensionKeysInSchema, s as sanitizeSchema, st as foldAllOfMembers, u as hasParameterSerialization, ut as regexLiteral, vt as normalizeTypes, w as isPrimitiveUnion, x as integerWirePattern, yn as NUMBER_RANGES, zt as isNullable } from "./helper-WSNbEQKr.js";
|
|
2
|
+
// src/generator/valibot/type.ts
|
|
4
3
|
/** The TypeScript type declared beside a recursive Valibot schema: its output type. */
|
|
5
4
|
function type(schema, rootName = DEFAULT_ROOT_NAME) {
|
|
6
5
|
return typeDeclaration(schema, {
|
|
@@ -8,8 +7,7 @@ function type(schema, rootName = DEFAULT_ROOT_NAME) {
|
|
|
8
7
|
readonly: false
|
|
9
8
|
}, rootName);
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
//#region src/generator/valibot/number.ts
|
|
10
|
+
// src/generator/valibot/number.ts
|
|
13
11
|
/** The `v.minValue` / `v.maxValue` / `v.gtValue` / `v.ltValue` / `v.multipleOf` actions of a numeric node. */
|
|
14
12
|
function numberActions(schema, lit = (n) => `${n}`) {
|
|
15
13
|
const minimumMessage = schema["x-minimum-message"];
|
|
@@ -63,8 +61,7 @@ function number(schema, options) {
|
|
|
63
61
|
if (actions.length > 0) return `v.pipe(${base},${actions.join(",")})`;
|
|
64
62
|
return errorMessage ? base : "v.number()";
|
|
65
63
|
}
|
|
66
|
-
|
|
67
|
-
//#region src/generator/valibot/integer.ts
|
|
64
|
+
// src/generator/valibot/integer.ts
|
|
68
65
|
/** Whether a node is a 64-bit integer: a value beyond 2^53 that is read as a bigint. */
|
|
69
66
|
function isInt64(schema) {
|
|
70
67
|
return schema.format === "int64" || schema.format === "uint64";
|
|
@@ -126,8 +123,7 @@ function integer(schema, options) {
|
|
|
126
123
|
...actions
|
|
127
124
|
].join(",")})`;
|
|
128
125
|
}
|
|
129
|
-
|
|
130
|
-
//#region src/generator/valibot/enum.ts
|
|
126
|
+
// src/generator/valibot/enum.ts
|
|
131
127
|
function lit(v, isBigint) {
|
|
132
128
|
if (v === null) return "null";
|
|
133
129
|
if (typeof v === "string") return `'${v.replaceAll("'", "\\'")}'`;
|
|
@@ -159,7 +155,7 @@ function _enum(schema) {
|
|
|
159
155
|
const litSchema = (v, errPart) => {
|
|
160
156
|
if (v === null) return `v.null(${errPart.replace(/^,/, "")})`;
|
|
161
157
|
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") return `v.literal(${lit(v, isBigint)}${errPart})`;
|
|
162
|
-
return `v.custom<${JSON.stringify(v)}>((input) =>
|
|
158
|
+
return `v.custom<${JSON.stringify(v)}>((input) => ${deepEqualExpression(v, "input")}${errPart})`;
|
|
163
159
|
};
|
|
164
160
|
const innerLit = (v) => litSchema(v, "");
|
|
165
161
|
const outerLit = (v) => litSchema(v, errorArg);
|
|
@@ -177,8 +173,7 @@ function _enum(schema) {
|
|
|
177
173
|
if (schema.enum.length > 1) return `v.union([${schema.enum.map(innerLit).join(",")}]${errorArg})`;
|
|
178
174
|
return outerLit(schema.enum[0]);
|
|
179
175
|
}
|
|
180
|
-
|
|
181
|
-
//#region src/generator/valibot/object.ts
|
|
176
|
+
// src/generator/valibot/object.ts
|
|
182
177
|
/**
|
|
183
178
|
* Generate a Valibot object schema for a JSON Schema object node.
|
|
184
179
|
*
|
|
@@ -220,12 +215,20 @@ function object(schema, rootName, isValibot, options) {
|
|
|
220
215
|
const s = valibot(propSchema, rootName, isValibot, options);
|
|
221
216
|
return `v.check((input)=>Object.entries(input).every(([key,value])=>!new RegExp(${JSON.stringify(pattern)}).test(key)||v.safeParse(${s},value).success)${patternErrorArg})`;
|
|
222
217
|
}) : [];
|
|
223
|
-
if (typeof schema.additionalProperties === "object") {
|
|
218
|
+
if (typeof schema.additionalProperties === "object" && schema.properties === void 0 && schema.patternProperties === void 0) {
|
|
224
219
|
const record = `v.record(v.string(),${valibot(schema.additionalProperties, rootName, isValibot, options)})`;
|
|
225
|
-
const actions = [propertyNamesCheck()
|
|
220
|
+
const actions = [propertyNamesCheck()].filter((a) => a !== "");
|
|
226
221
|
return actions.length > 0 ? `v.pipe(${record},${actions.join(",")})` : record;
|
|
227
222
|
}
|
|
228
|
-
|
|
223
|
+
const properties = schema.properties ?? {};
|
|
224
|
+
const undeclaredRequired = (schema.required ?? []).filter((key) => !Object.hasOwn(properties, key));
|
|
225
|
+
const unevaluated = schema.unevaluatedProperties;
|
|
226
|
+
const closed = schema.additionalProperties === false || unevaluated === false;
|
|
227
|
+
const closedByCheck = closed && schema.patternProperties !== void 0;
|
|
228
|
+
const extraSchema = typeof schema.additionalProperties === "object" ? schema.additionalProperties : typeof unevaluated === "object" ? unevaluated : void 0;
|
|
229
|
+
const extraMessage = typeof schema.additionalProperties === "object" ? schema["x-additionalProperties-message"] : schema["x-unevaluatedProperties-message"];
|
|
230
|
+
const checksKeys = undeclaredRequired.length > 0 || extraSchema !== void 0 || closed;
|
|
231
|
+
if (!schema.properties && !checksKeys) {
|
|
229
232
|
if (schema.patternProperties) {
|
|
230
233
|
const record = `v.record(v.string(),v.unknown())`;
|
|
231
234
|
const actions = [propertyNamesCheck(), ...patternPropertiesChecks()].filter((a) => a !== "");
|
|
@@ -234,11 +237,11 @@ function object(schema, rootName, isValibot, options) {
|
|
|
234
237
|
if (schema.additionalProperties === true) return "v.any()";
|
|
235
238
|
return "v.object({})";
|
|
236
239
|
}
|
|
237
|
-
const
|
|
238
|
-
const objectKind = schema.additionalProperties === true ? "looseObject" :
|
|
240
|
+
const readsUndeclaredKeys = hasConditional(schema) || schema.patternProperties !== void 0 || schema.propertyNames !== void 0 || schema.minProperties !== void 0 || schema.maxProperties !== void 0 || schema.dependentRequired !== void 0 || schema.dependentSchemas !== void 0 || undeclaredRequired.length > 0 || extraSchema !== void 0 || closedByCheck;
|
|
241
|
+
const objectKind = schema.additionalProperties === true ? "looseObject" : closed && !closedByCheck ? "strictObject" : readsUndeclaredKeys ? "looseObject" : "object";
|
|
239
242
|
const required = new Set(schema.required);
|
|
240
|
-
const hasOwnDefault = Object.values(
|
|
241
|
-
const props = Object.entries(
|
|
243
|
+
const hasOwnDefault = Object.values(properties).some((propSchema) => isOptionalByDefault(propSchema, options?.definitions));
|
|
244
|
+
const props = Object.entries(properties).map(([key, propSchema]) => {
|
|
242
245
|
const parsed = valibot(propSchema, rootName, isValibot, propertyEmitOptions(key, propSchema, options) ?? options);
|
|
243
246
|
if (!parsed) return null;
|
|
244
247
|
const safeKey = makeSafeKey(key);
|
|
@@ -249,7 +252,7 @@ function object(schema, rootName, isValibot, options) {
|
|
|
249
252
|
const propsMessage = schema["x-properties-message"];
|
|
250
253
|
const partialBase = propsMessage ? (() => {
|
|
251
254
|
const msgExpr = issueMessageExpression(propsMessage);
|
|
252
|
-
return `v.pipe(v.unknown(),v.rawCheck(({dataset,addIssue})=>{if(!dataset.typed)return;const result=v.safeParse(${rawBase},dataset.value);if(!result.success){for(const issue of result.issues){if(issue.path&&issue.path.length>0){addIssue({message:${msgExpr},path:issue.path})}else{addIssue(issue)}}}}))`;
|
|
255
|
+
return `v.pipe(v.unknown(),v.rawCheck(({dataset,addIssue})=>{if(!dataset.typed)return;const result=v.safeParse(${rawBase},dataset.value);if(!result.success){for(const issue of result.issues){if(issue.path&&issue.path.length>0){addIssue({message:${msgExpr},path:issue.path})}else{addIssue({message:issue.message})}}}}),${rawBase})`;
|
|
253
256
|
})() : rawBase;
|
|
254
257
|
const minPropertiesCheck = typeof schema.minProperties === "number" ? `v.check((input)=>Object.keys(input).length>=${schema.minProperties}${minErrorArg})` : "";
|
|
255
258
|
const maxPropertiesCheck = typeof schema.maxProperties === "number" ? `v.check((input)=>Object.keys(input).length<=${schema.maxProperties}${maxErrorArg})` : "";
|
|
@@ -280,22 +283,29 @@ function object(schema, rootName, isValibot, options) {
|
|
|
280
283
|
}
|
|
281
284
|
return parts;
|
|
282
285
|
})();
|
|
286
|
+
const requiredPresentCheck = undeclaredRequired.length > 0 ? `v.check((input)=>${JSON.stringify(undeclaredRequired)}.every((key)=>key in input)${errorArg})` : "";
|
|
287
|
+
const isEvaluated = isEvaluatedKeyExpression({
|
|
288
|
+
names: Object.keys(properties),
|
|
289
|
+
patterns: Object.keys(schema.patternProperties ?? {})
|
|
290
|
+
}, "key");
|
|
291
|
+
const unevaluatedKeysCheck = closedByCheck ? `v.check((input)=>Object.keys(input).every((key)=>${isEvaluated})${valibotErrorPart(strictExtrasMessage ?? errorMessage)})` : extraSchema !== void 0 ? `v.check((input)=>Object.entries(input).every(([key,value])=>${isEvaluated}||v.safeParse(${valibot(extraSchema, rootName, isValibot, options)},value).success)${valibotErrorPart(extraMessage ?? errorMessage)})` : "";
|
|
283
292
|
const actions = [
|
|
284
293
|
minPropertiesCheck,
|
|
285
294
|
maxPropertiesCheck,
|
|
286
295
|
propertyNamesCheck(),
|
|
287
296
|
...patternPropertiesChecks(),
|
|
297
|
+
requiredPresentCheck,
|
|
298
|
+
unevaluatedKeysCheck,
|
|
288
299
|
...dependentRequiredChecks,
|
|
289
300
|
...dependentSchemasChecks,
|
|
290
301
|
additionalPropertiesCheck,
|
|
291
302
|
...ifThenElseChecks
|
|
292
303
|
].filter((a) => a !== "");
|
|
293
304
|
const objectExpr = actions.length > 0 ? `v.pipe(${partialBase},${actions.join(",")})` : partialBase;
|
|
294
|
-
const hasInheritedName = Object.keys(
|
|
305
|
+
const hasInheritedName = Object.keys(properties).some(isObjectPrototypeProperty);
|
|
295
306
|
return isStringWireLocation(options?.paramIn) && hasInheritedName ? `v.pipe(v.unknown(),v.transform(${ownProperties("input")}),${objectExpr})` : objectExpr;
|
|
296
307
|
}
|
|
297
|
-
|
|
298
|
-
//#region src/generator/valibot/string.ts
|
|
308
|
+
// src/generator/valibot/string.ts
|
|
299
309
|
/** The formats Valibot checks with an action of its own, keyed by the lower-cased format. */
|
|
300
310
|
const FORMAT_ACTION = {
|
|
301
311
|
email: "v.email()",
|
|
@@ -373,8 +383,7 @@ function string(schema) {
|
|
|
373
383
|
if (actions.length > 0) return `v.pipe(v.string(${baseErrorArg}),${actions.join(",")})`;
|
|
374
384
|
return errorMessage ? `v.string(${baseErrorArg})` : "v.string()";
|
|
375
385
|
}
|
|
376
|
-
|
|
377
|
-
//#region src/generator/valibot/valibot.ts
|
|
386
|
+
// src/generator/valibot/valibot.ts
|
|
378
387
|
/** `inner` with `prefix` ahead of it in one pipe: an existing pipe is opened, not nested. */
|
|
379
388
|
function prependPipe(prefix, inner) {
|
|
380
389
|
if (inner.startsWith("v.pipe(") && inner.endsWith(")")) {
|
|
@@ -409,21 +418,28 @@ function stringbool(errorArg) {
|
|
|
409
418
|
return `v.pipe(${stringboolItems(errorArg).join(",")})`;
|
|
410
419
|
}
|
|
411
420
|
function elementMessageWrap(inner, msg) {
|
|
412
|
-
return `v.pipe(v.unknown(),v.rawCheck(({dataset,addIssue})=>{if(!dataset.typed)return;const result=v.safeParse(${inner},dataset.value);if(!result.success){for(const issue of result.issues){if(issue.path&&issue.path.length>0){addIssue({message:${issueMessageExpression(msg)},path:issue.path})}else{addIssue(issue)}}}}))`;
|
|
421
|
+
return `v.pipe(v.unknown(),v.rawCheck(({dataset,addIssue})=>{if(!dataset.typed)return;const result=v.safeParse(${inner},dataset.value);if(!result.success){for(const issue of result.issues){if(issue.path&&issue.path.length>0){addIssue({message:${issueMessageExpression(msg)},path:issue.path})}else{addIssue({message:issue.message})}}}}),${inner})`;
|
|
422
|
+
}
|
|
423
|
+
/** Add a key's issues (`result`) to the raw check. */
|
|
424
|
+
function forwardKeyIssues(message) {
|
|
425
|
+
return `for(const issue of result.issues){addIssue({message:${message === void 0 ? "issue.message" : JSON.stringify(message)}})}`;
|
|
413
426
|
}
|
|
414
427
|
/**
|
|
415
|
-
* An `allOf` with `unevaluatedProperties` beside it: the members'
|
|
416
|
-
* do not declare, so the keys
|
|
417
|
-
* parsed
|
|
428
|
+
* An `allOf` with `patternProperties` or `unevaluatedProperties` beside it: the members'
|
|
429
|
+
* objects strip what they do not declare, so the keys are checked on the input before it
|
|
430
|
+
* is parsed — a key a pattern matches against that pattern's schema, a key no member
|
|
431
|
+
* evaluates against `unevaluatedProperties`. `inner` as given when there is nothing to check.
|
|
418
432
|
*/
|
|
419
|
-
function
|
|
433
|
+
function objectKeysCheck(inner, schema, rootName, isValibot, options) {
|
|
434
|
+
const patterns = Object.entries(schema.patternProperties ?? {});
|
|
420
435
|
const unevaluated = schema.unevaluatedProperties;
|
|
421
|
-
|
|
422
|
-
const evaluated = evaluatedProperties(schema, options?.definitions);
|
|
423
|
-
if (evaluated === void 0) return inner;
|
|
424
|
-
const
|
|
436
|
+
const unevaluatedSchema = typeof unevaluated === "object" ? unevaluated : void 0;
|
|
437
|
+
const evaluated = unevaluated === false || unevaluatedSchema !== void 0 ? evaluatedProperties(schema, options?.definitions) : void 0;
|
|
438
|
+
if (patterns.length === 0 && evaluated === void 0) return inner;
|
|
439
|
+
const patternMessage = schema["x-patternProperties-message"];
|
|
440
|
+
const patternChecks = patterns.map(([pattern, propSchema]) => `if(new RegExp(${JSON.stringify(pattern)}).test(k)){const result=v.safeParse(${valibot(propSchema, rootName, isValibot, options)},val);if(!result.success){${forwardKeyIssues(patternMessage)}}}`).join("");
|
|
425
441
|
const message = schema["x-unevaluatedProperties-message"];
|
|
426
|
-
return `v.pipe(v.unknown(),v.rawCheck(({dataset,addIssue})=>{if(!dataset.typed)return;const o=dataset.value;if(typeof o!=='object'||o===null||Array.isArray(o))return
|
|
442
|
+
return `v.pipe(v.unknown(),v.rawCheck(({dataset,addIssue})=>{if(!dataset.typed)return;const o=dataset.value;if(typeof o!=='object'||o===null||Array.isArray(o))return;for(const [k,val] of Object.entries(o)){${patternChecks}${evaluated === void 0 ? "" : `if(!(${isEvaluatedKeyExpression(evaluated, "k")})){${unevaluatedSchema === void 0 ? `addIssue({message:${message === void 0 ? `'Unevaluated property: '+k` : JSON.stringify(message)}})` : `const result=v.safeParse(${valibot(unevaluatedSchema, rootName, isValibot, options)},val);if(!result.success){${forwardKeyIssues(message)}}`}}`}}}),${inner})`;
|
|
427
443
|
}
|
|
428
444
|
/**
|
|
429
445
|
* Generate Valibot schema code from JSON Schema.
|
|
@@ -492,11 +508,18 @@ function node(schema, rootName, isValibot, options) {
|
|
|
492
508
|
}, rootName, isValibot, options);
|
|
493
509
|
if (schema.oneOf) {
|
|
494
510
|
if (schema.oneOf.length === 0) return valibotWrap$1("v.any()", schema);
|
|
495
|
-
const schemas = schema.oneOf.map((s) => valibot(s, rootName, isValibot, options));
|
|
496
|
-
const oneOfMessage = schema["x-oneOf-message"];
|
|
497
|
-
const errorPart = valibotErrorPart(oneOfMessage);
|
|
498
511
|
const discriminator = schema.discriminator?.propertyName;
|
|
499
512
|
const hasRefOrAllOf = schema.oneOf.some((s) => s.$ref !== void 0 || s.allOf !== void 0);
|
|
513
|
+
const discriminated = hasRefOrAllOf ? discriminatedMembers(schema, schema.oneOf) : void 0;
|
|
514
|
+
const schemas = schema.oneOf.map((s, i) => {
|
|
515
|
+
const member = valibot(s, rootName, isValibot, options);
|
|
516
|
+
const values = discriminated?.members[i]?.values;
|
|
517
|
+
if (discriminated === void 0 || values === void 0) return member;
|
|
518
|
+
const literal = values.length === 1 ? `v.literal(${JSON.stringify(values[0])})` : `v.picklist(${JSON.stringify(values)})`;
|
|
519
|
+
return `v.intersect([${member},v.object({${makeSafeKey(discriminated.propertyName)}:${literal}})])`;
|
|
520
|
+
});
|
|
521
|
+
const oneOfMessage = schema["x-oneOf-message"];
|
|
522
|
+
const errorPart = valibotErrorPart(oneOfMessage);
|
|
500
523
|
return valibotWrap$1(discriminator && !hasRefOrAllOf ? `v.variant('${discriminator}',[${schemas.join(",")}]${errorPart})` : `v.union([${schemas.join(",")}]${errorPart})`, schema);
|
|
501
524
|
}
|
|
502
525
|
if (schema.anyOf) {
|
|
@@ -517,9 +540,9 @@ function node(schema, rootName, isValibot, options) {
|
|
|
517
540
|
});
|
|
518
541
|
const intersected = schemas.length === 1 ? schemas[0] : `v.intersect([${schemas.join(",")}])`;
|
|
519
542
|
const allOfMessage = schema["x-allOf-message"];
|
|
520
|
-
const checked =
|
|
543
|
+
const checked = objectKeysCheck(allOfMessage ? (() => {
|
|
521
544
|
const msgExpr = issueMessageExpression(allOfMessage);
|
|
522
|
-
return `v.pipe(v.unknown(),v.rawCheck(({dataset,addIssue})=>{if(!dataset.typed)return;const result=v.safeParse(${intersected},dataset.value);if(!result.success){for(const issue of result.issues){addIssue({message:${msgExpr},path:issue.path})}}}))`;
|
|
545
|
+
return `v.pipe(v.unknown(),v.rawCheck(({dataset,addIssue})=>{if(!dataset.typed)return;const result=v.safeParse(${intersected},dataset.value);if(!result.success){for(const issue of result.issues){addIssue({message:${msgExpr},path:issue.path})}}}),${intersected})`;
|
|
523
546
|
})() : intersected, schema, rootName, isValibot, options);
|
|
524
547
|
if (defaultValue !== void 0) return `v.optional(${nullable ? `v.nullable(${checked})` : checked},${jsLiteral(defaultValue)})`;
|
|
525
548
|
return valibotWrap$1(checked, {
|
|
@@ -552,7 +575,7 @@ function node(schema, rootName, isValibot, options) {
|
|
|
552
575
|
const msgArg = constMessage ? valibotError(constMessage) : "";
|
|
553
576
|
const errorPart = msgArg ? `,${msgArg}` : "";
|
|
554
577
|
if (value === null) return valibotWrap$1(`v.null(${msgArg})`, schema);
|
|
555
|
-
const literal = typeof value === "number" && isInt64(schema) ? `v.literal(${value}n${errorPart})` : isPrimitive(value) ? `v.literal(${JSON.stringify(value)}${errorPart})` : `v.custom<${JSON.stringify(value)}>((input) =>
|
|
578
|
+
const literal = typeof value === "number" && isInt64(schema) ? `v.literal(${value}n${errorPart})` : isPrimitive(value) ? `v.literal(${JSON.stringify(value)}${errorPart})` : `v.custom<${JSON.stringify(value)}>((input) => ${deepEqualExpression(value, "input")}${errorPart})`;
|
|
556
579
|
const input = literalInput([value]);
|
|
557
580
|
return valibotWrap$1(input ? prependPipe(input, literal) : literal, schema);
|
|
558
581
|
}
|
|
@@ -658,8 +681,7 @@ function node(schema, rootName, isValibot, options) {
|
|
|
658
681
|
if (typeof schema.additionalProperties === "object") return readonly(valibotWrap$1(object(schema, rootName, isValibot, options), schema));
|
|
659
682
|
return valibotWrap$1("v.any()", schema);
|
|
660
683
|
}
|
|
661
|
-
|
|
662
|
-
//#region src/generator/valibot/index.ts
|
|
684
|
+
// src/generator/valibot/index.ts
|
|
663
685
|
/**
|
|
664
686
|
* A recursive declaration needs an explicit annotation, since the schema is referenced
|
|
665
687
|
* inside its own initializer. `GenericSchema<TInput, TOutput>` pins the input to the
|
|
@@ -675,7 +697,7 @@ function annotation(name) {
|
|
|
675
697
|
* order, the root export, and the inferred output type.
|
|
676
698
|
*/
|
|
677
699
|
function schemaToValibot(input, options) {
|
|
678
|
-
const schema = withPolymorphicBases(hoistNestedRefs(input));
|
|
700
|
+
const schema = withPolymorphicBases(hoistNestedRefs(sanitizeSchema(input)));
|
|
679
701
|
const exportType = options?.exportType ?? true;
|
|
680
702
|
const baseOptions = emitOptionsOf(options);
|
|
681
703
|
const codeExtensionsPresent = baseOptions.unsafeCodeExtensions === true && findCodeExtensionKeysInSchema(schema).length > 0;
|
|
@@ -701,5 +723,4 @@ function schemaToValibot(input, options) {
|
|
|
701
723
|
...exportType ? [`export type ${rootName}Output = v.InferOutput<typeof ${rootName}>`] : []
|
|
702
724
|
].filter(Boolean).join("\n\n");
|
|
703
725
|
}
|
|
704
|
-
//#endregion
|
|
705
726
|
export { valibot as n, schemaToValibot as t };
|
package/dist/valibot.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { r as JSONSchema } from "./index-
|
|
2
|
-
import { n as GenerateOptions } from "./index-
|
|
3
|
-
//#region src/generator/valibot/index.d.ts
|
|
1
|
+
import { r as JSONSchema } from "./index-DLVjyrKu.js";
|
|
2
|
+
import { n as GenerateOptions } from "./index-DU2Nd8eI.js";
|
|
4
3
|
/**
|
|
5
4
|
* A whole JSON Schema document as a Valibot module: imports, `$defs` in dependency
|
|
6
5
|
* order, the root export, and the inferred output type.
|
|
7
6
|
*/
|
|
8
|
-
export declare function schemaToValibot(input: JSONSchema, options?: GenerateOptions): string;
|
|
9
|
-
//#endregion
|
|
7
|
+
export declare function schemaToValibot(input: JSONSchema, options?: GenerateOptions): string;
|
package/dist/valibot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToValibot } from "./valibot-
|
|
1
|
+
export { t as schemaToValibot } from "./valibot-CLUhG6tp.js";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/generator/yup/integer.ts
|
|
1
|
+
import { K as rootNameOf, _t as makeSafeKey, q as schemaNamer, s as sanitizeSchema, vt as normalizeTypes } from "./helper-WSNbEQKr.js";
|
|
2
|
+
// src/generator/yup/integer.ts
|
|
4
3
|
/**
|
|
5
4
|
* Generate a Yup integer schema as `yup.number().integer()`, with `minimum`
|
|
6
5
|
* as `.min(...)`. Other numeric keywords are silent no-ops in this slice.
|
|
@@ -8,8 +7,7 @@ import { G as schemaNamer, W as rootNameOf } from "./helper-CbeedY35.js";
|
|
|
8
7
|
function integer(schema) {
|
|
9
8
|
return `yup.number().integer()${typeof schema.minimum === "number" ? `.min(${schema.minimum})` : ""}`;
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
//#region src/generator/yup/number.ts
|
|
10
|
+
// src/generator/yup/number.ts
|
|
13
11
|
/**
|
|
14
12
|
* Generate a Yup number schema. `minimum` becomes `.min(...)`; other numeric
|
|
15
13
|
* keywords are silent no-ops in this slice.
|
|
@@ -17,8 +15,7 @@ function integer(schema) {
|
|
|
17
15
|
function number(schema) {
|
|
18
16
|
return `yup.number()${typeof schema.minimum === "number" ? `.min(${schema.minimum})` : ""}`;
|
|
19
17
|
}
|
|
20
|
-
|
|
21
|
-
//#region src/generator/yup/object.ts
|
|
18
|
+
// src/generator/yup/object.ts
|
|
22
19
|
/**
|
|
23
20
|
* Generate a Yup object schema for a JSON Schema object node.
|
|
24
21
|
*
|
|
@@ -34,8 +31,7 @@ function object(schema) {
|
|
|
34
31
|
return `${makeSafeKey(key)}:${parsed}${suffix}`;
|
|
35
32
|
}).join(",")}})`;
|
|
36
33
|
}
|
|
37
|
-
|
|
38
|
-
//#region src/generator/yup/string.ts
|
|
34
|
+
// src/generator/yup/string.ts
|
|
39
35
|
/**
|
|
40
36
|
* Generate a Yup string schema. `format: email` becomes `.email()`; every
|
|
41
37
|
* other string keyword is a silent no-op in this slice.
|
|
@@ -43,8 +39,7 @@ function object(schema) {
|
|
|
43
39
|
function string(schema) {
|
|
44
40
|
return schema.format === "email" ? "yup.string().email()" : "yup.string()";
|
|
45
41
|
}
|
|
46
|
-
|
|
47
|
-
//#region src/generator/yup/yup.ts
|
|
42
|
+
// src/generator/yup/yup.ts
|
|
48
43
|
/**
|
|
49
44
|
* Generate a Yup expression from one JSON Schema node.
|
|
50
45
|
*
|
|
@@ -65,8 +60,7 @@ function yup(schema) {
|
|
|
65
60
|
if (types.includes("object")) return object(schema);
|
|
66
61
|
return "yup.mixed()";
|
|
67
62
|
}
|
|
68
|
-
|
|
69
|
-
//#region src/generator/yup/index.ts
|
|
63
|
+
// src/generator/yup/index.ts
|
|
70
64
|
/**
|
|
71
65
|
* Convert a JSON Schema document to Yup schema source.
|
|
72
66
|
*
|
|
@@ -79,7 +73,8 @@ function yup(schema) {
|
|
|
79
73
|
* @param options.openapi - Enable OpenAPI component-aware naming (default: false)
|
|
80
74
|
* @returns Generated TypeScript/Yup code string
|
|
81
75
|
*/
|
|
82
|
-
function schemaToYup(
|
|
76
|
+
function schemaToYup(input, options) {
|
|
77
|
+
const schema = sanitizeSchema(input);
|
|
83
78
|
const exportType = options?.exportType ?? true;
|
|
84
79
|
const rootName = rootNameOf(schema, schemaNamer(options?.openapi));
|
|
85
80
|
return [
|
|
@@ -88,5 +83,4 @@ function schemaToYup(schema, options) {
|
|
|
88
83
|
...exportType ? [`export type ${rootName} = yup.InferType<typeof ${rootName}>`] : []
|
|
89
84
|
].join("\n\n");
|
|
90
85
|
}
|
|
91
|
-
//#endregion
|
|
92
86
|
export { yup as n, schemaToYup as t };
|
package/dist/yup.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { r as JSONSchema } from "./index-
|
|
2
|
-
import { n as GenerateOptions } from "./index-
|
|
3
|
-
//#region src/generator/yup/index.d.ts
|
|
1
|
+
import { r as JSONSchema } from "./index-DLVjyrKu.js";
|
|
2
|
+
import { n as GenerateOptions } from "./index-DU2Nd8eI.js";
|
|
4
3
|
/**
|
|
5
4
|
* Convert a JSON Schema document to Yup schema source.
|
|
6
5
|
*
|
|
@@ -13,5 +12,4 @@ import { n as GenerateOptions } from "./index-DYzAccyT.js";
|
|
|
13
12
|
* @param options.openapi - Enable OpenAPI component-aware naming (default: false)
|
|
14
13
|
* @returns Generated TypeScript/Yup code string
|
|
15
14
|
*/
|
|
16
|
-
export declare function schemaToYup(
|
|
17
|
-
//#endregion
|
|
15
|
+
export declare function schemaToYup(input: JSONSchema, options?: GenerateOptions): string;
|
package/dist/yup.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToYup } from "./yup-
|
|
1
|
+
export { t as schemaToYup } from "./yup-DfE_ofEu.js";
|