schema-truth 0.8.1 → 0.8.2
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/{arktype-CRZ8vXZ5.js → arktype-CBV4bg-0.js} +86 -39
- package/dist/arktype.d.ts +1 -1
- package/dist/arktype.js +1 -1
- package/dist/cli/ajv.js +1 -1
- 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-eAY8LqwP.js → cli-CB9GJ7qa.js} +1 -1
- package/dist/{effect-BkWovUi3.js → effect-D9pvwi_6.js} +50 -23
- package/dist/effect.d.ts +1 -1
- package/dist/effect.js +1 -1
- package/dist/{helper-CbeedY35.js → helper-S7SSsYwh.js} +57 -3
- package/dist/{index-DYzAccyT.d.ts → index-EK43HM_z.d.ts} +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +7 -7
- package/dist/{typebox-wYeJqy7T.js → typebox-DGGKJLdP.js} +52 -31
- package/dist/typebox.d.ts +1 -1
- package/dist/typebox.js +1 -1
- package/dist/{valibot-DQUEDYKt.js → valibot-B6y4VQFF.js} +55 -25
- package/dist/valibot.d.ts +1 -1
- package/dist/valibot.js +1 -1
- package/dist/{yup-BMpa9Co1.js → yup-DuqQwHUv.js} +1 -1
- package/dist/yup.d.ts +1 -1
- package/dist/yup.js +1 -1
- package/dist/{zod-Dq9LtqPL.js → zod-CXo9NFuF.js} +73 -35
- package/dist/zod.d.ts +1 -1
- package/dist/zod.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { $ as QUOTE_OR_BACKSLASH_PATTERN, A as DEFINITION_REF_PREFIXES, B as MISSING_DEFINITION_PREFIX, C as ARROW_FUNCTION_PATTERN, D as DEFAULT_ROOT_NAME, E as DATE_PATTERN_SOURCE, F as INPUT_EXTENSIONS, G as NUMBER_WIRE_PATTERN, H as NOT_KEYWORD_UNSUPPORTED_MARKER, I as INTEGER_TEXT_PATTERN, J as OFFSET_PATTERN_SOURCE, K as NUMERIC_KEYWORDS, L as INTEGER_WIRE_PATTERN, M as FORMAT_PATTERNS, N as IDENTIFIER_PATTERN, O as DEFINITION_KEYWORDS, P as IF_THEN_ELSE_UNSUPPORTED_MARKER, Q as PARAM_STYLES, R as ISO_4217_CURRENCY_CODES, S as ARKTYPE_CODE_EXTENSION_KEYS, T as CONTENT_ENCODINGS, U as NUMBER_FORMATS, V as NON_IDENTIFIER_CHARACTER_PATTERN, W as NUMBER_RANGES, X as OUTPUT_EXTENSION, Y as OPENAPI_COMPONENT_SUFFIX_MAP, Z as PARAM_LOCATIONS, _ as XExtMessages, a as JSONSchemaNumberFormat, at as STRING_WIRE_LOCATIONS, b as ALL_CODE_EXTENSION_KEYS, c as JSONSchemaTypes, ct as VALIBOT_CODE_EXTENSION_KEYS, d as Ref, et as ROOT_REFS, f as parseSchemaFile, g as XExtParam, h as ParamStyle, i as JSONSchemaFormat, it as STRING_KEYWORDS, j as EFFECT_CODE_EXTENSION_KEYS, k as DEFINITION_POINTER_PATTERN, l as LocalRef, lt as WIRE_PRIMITIVE_ORDER, m as ParamIn, n as ExternalRef, nt as STRINGBOOL_TRUTHY_PATTERN, o as JSONSchemaStringFormat, ot as UNICODE_ESCAPE_PATTERN, p as XExtTransform, q as OBJECT_PROTOTYPE_PROPERTIES, r as JSONSchema, rt as STRING_FORMATS, s as JSONSchemaType, st as UNSAFE_GENERATED_MARKER, t as ContentEncoding, tt as STRINGBOOL_PATTERN, u as ParseError, ut as ZOD_CODE_EXTENSION_KEYS, v as XExtCode, w as COMPONENT_SCHEMA_REF_PREFIX, x as ANCHOR_REF_PATTERN, y as JSONValue, z as JSON_SCHEMA_TYPES } from "./index-G7UqNQ4w.js";
|
|
2
2
|
import { schemaToAjv } from "./ajv.js";
|
|
3
|
-
import { n as GenerateOptions, t as EmitOptions } from "./index-
|
|
3
|
+
import { n as GenerateOptions, r as SchemaDefinitions, t as EmitOptions } from "./index-EK43HM_z.js";
|
|
4
4
|
import { schemaToArktype } from "./arktype.js";
|
|
5
5
|
import { schemaToEffect } from "./effect.js";
|
|
6
6
|
import { TypeboxGenerateOptions, schemaToTypebox } from "./typebox.js";
|
|
@@ -87,6 +87,8 @@ export type TypeboxOptions = {
|
|
|
87
87
|
readonly paramIn?: ParamIn;
|
|
88
88
|
readonly cyclicRefs?: ReadonlySet<string>;
|
|
89
89
|
readonly ref?: string;
|
|
90
|
+
/** Definitions a `default` beside a `$ref` is checked against. */
|
|
91
|
+
readonly definitions?: SchemaDefinitions;
|
|
90
92
|
};
|
|
91
93
|
/**
|
|
92
94
|
* Options for a nested TypeBox node: the same as `options` but without a
|
|
@@ -121,6 +123,13 @@ export declare function valibot(schema: JSONSchema, rootName?: string, isValibot
|
|
|
121
123
|
export declare function yup(schema: JSONSchema): string;
|
|
122
124
|
//#endregion
|
|
123
125
|
//#region src/generator/zod/zod.d.ts
|
|
126
|
+
/**
|
|
127
|
+
* Re-push `issue` into `ctx` with `message`. Each issue code is narrowed first: the union of
|
|
128
|
+
* parsed issues does not type-check as a raw issue, while each member does.
|
|
129
|
+
*/
|
|
130
|
+
export declare function forwardIssue(message: string): string;
|
|
131
|
+
/** A message for the issues under the value (with a path); the root's own issues keep theirs. */
|
|
132
|
+
export declare function nestedIssueMessageWrap(inner: string, msg: string): string;
|
|
124
133
|
/**
|
|
125
134
|
* Generate Zod schema code from JSON Schema.
|
|
126
135
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { $ as DEFINITION_REF_PREFIXES, At as UNSAFE_GENERATED_MARKER, Ct as ROOT_REFS, Dt as STRING_KEYWORDS, Et as STRING_FORMATS, G as ARKTYPE_CODE_EXTENSION_KEYS, J as CONTENT_ENCODINGS, K as ARROW_FUNCTION_PATTERN, Mt as WIRE_PRIMITIVE_ORDER, Nt as ZOD_CODE_EXTENSION_KEYS, Ot as STRING_WIRE_LOCATIONS, Q as DEFINITION_POINTER_PATTERN, St as QUOTE_OR_BACKSLASH_PATTERN, Tt as STRINGBOOL_TRUTHY_PATTERN, U as ALL_CODE_EXTENSION_KEYS, W as ANCHOR_REF_PATTERN, X as DEFAULT_ROOT_NAME, Y as DATE_PATTERN_SOURCE, Z as DEFINITION_KEYWORDS, _t as OFFSET_PATTERN_SOURCE, a as encodeNonAscii, at as INTEGER_TEXT_PATTERN, bt as PARAM_LOCATIONS, c as normalizeTypes, ct as JSON_SCHEMA_TYPES, d as toPascalCase, dt as NOT_KEYWORD_UNSUPPORTED_MARKER, et as EFFECT_CODE_EXTENSION_KEYS, f as valibotError, ft as NUMBER_FORMATS, g as zodErrorPart, gt as OBJECT_PROTOTYPE_PROPERTIES, h as zodError, ht as NUMERIC_KEYWORDS, i as effectMessage, it as INPUT_EXTENSIONS, jt as VALIBOT_CODE_EXTENSION_KEYS, kt as UNICODE_ESCAPE_PATTERN, l as resolveOpenAPIRef, lt as MISSING_DEFINITION_PREFIX, m as zodBaseError, mt as NUMBER_WIRE_PATTERN, n as effectError, nt as IDENTIFIER_PATTERN, o as issueMessageExpression, ot as INTEGER_WIRE_PATTERN, p as valibotErrorPart, pt as NUMBER_RANGES, q as COMPONENT_SCHEMA_REF_PREFIX, r as effectErrorPart, rt as IF_THEN_ELSE_UNSUPPORTED_MARKER, s as makeSafeKey, st as ISO_4217_CURRENCY_CODES, t as coerceDefault, tt as FORMAT_PATTERNS, u as toIdentifierPascalCase, ut as NON_IDENTIFIER_CHARACTER_PATTERN, vt as OPENAPI_COMPONENT_SUFFIX_MAP, wt as STRINGBOOL_PATTERN, xt as PARAM_STYLES, yt as OUTPUT_EXTENSION } from "./utils-Bky98UmP.js";
|
|
2
2
|
import { i as fmt, n as parseSchemaFile, r as FormatError, t as ParseError } from "./parser-CyJ2auea.js";
|
|
3
3
|
import { n as ajv, t as schemaToAjv } from "./ajv-DS9gtNZC.js";
|
|
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 {
|
|
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, issueMessageExpression, makeSafeKey, nestedTypeboxOptions, normalizeTypes, parseSchemaFile, resolveOpenAPIRef, schemaToAjv, schemaToArktype, schemaToEffect, schemaToTypebox, schemaToValibot, schemaToYup, schemaToZod, toIdentifierPascalCase, toPascalCase, typebox, valibot, valibotError, valibotErrorPart, wholeValueMessage, yup, zod, zodBaseError, zodError, zodErrorPart };
|
|
4
|
+
import { n as arktype, t as schemaToArktype } from "./arktype-CBV4bg-0.js";
|
|
5
|
+
import { n as effect, r as wholeValueMessage, t as schemaToEffect } from "./effect-D9pvwi_6.js";
|
|
6
|
+
import { n as nestedTypeboxOptions, r as typebox, t as schemaToTypebox } from "./typebox-DGGKJLdP.js";
|
|
7
|
+
import { n as valibot, t as schemaToValibot } from "./valibot-B6y4VQFF.js";
|
|
8
|
+
import { n as yup, t as schemaToYup } from "./yup-DuqQwHUv.js";
|
|
9
|
+
import { i as zod, n as forwardIssue, r as nestedIssueMessageWrap, t as schemaToZod } from "./zod-CXo9NFuF.js";
|
|
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,5 +1,5 @@
|
|
|
1
1
|
import { $ as DEFINITION_REF_PREFIXES, C as hasNumericKeyword, D as isComposite, H as isStringWireLocation, M as isNullable, O as isDeepLocalPointer, R as isRootRef, S as hasFixedLength, V as isShapelessMember, X as DEFAULT_ROOT_NAME, c as normalizeTypes, dt as NOT_KEYWORD_UNSUPPORTED_MARKER, j as isNullTypeMember, k as isDefaultOnlyMember, l as resolveOpenAPIRef, s as makeSafeKey, w as hasStringKeyword, y as hasCombinator } from "./utils-Bky98UmP.js";
|
|
2
|
-
import {
|
|
2
|
+
import { B as emitOptionsOf, D as stringboolTruthyPattern, E as stringboolPattern, G as schemaNamer, H as planDocument, I as typeboxDefaultOpt, J as hasRootSelfReference, K as discriminatedMembers, L as typeboxMetaOpts, R as typeboxRefOpt, U as renderDefinitions, V as missingDefinitionComment, W as rootNameOf, X as itemsSchemaOf, Y as isOptionalByDefault, a as typeboxWrap, at as foldAllOfMembers, b as integerWirePattern, c as withPolymorphicBases, g as hoistNestedRefs, nt as hasNotKeyword, ot as isKeywordOnlyMember, q as cyclicDefinitionNames, st as patternSource, w as numberWirePattern, z as definitionsOf } from "./helper-S7SSsYwh.js";
|
|
3
3
|
//#region src/generator/typebox/enum.ts
|
|
4
4
|
function lit(v) {
|
|
5
5
|
if (v === null) return "null";
|
|
@@ -123,7 +123,7 @@ function number(schema, ref) {
|
|
|
123
123
|
function object(schema, rootName, isTypebox, options) {
|
|
124
124
|
const childOptions = nestedTypeboxOptions(options);
|
|
125
125
|
if (hasCombinator(schema)) return typebox(schema, rootName, isTypebox, options);
|
|
126
|
-
if (typeof schema.additionalProperties === "object") {
|
|
126
|
+
if (typeof schema.additionalProperties === "object" && schema.properties === void 0 && schema.patternProperties === void 0) {
|
|
127
127
|
const value = typebox(schema.additionalProperties, rootName, isTypebox, childOptions);
|
|
128
128
|
const recordOpts = [
|
|
129
129
|
...typeboxRefOpt(options?.ref),
|
|
@@ -144,6 +144,7 @@ function object(schema, rootName, isTypebox, options) {
|
|
|
144
144
|
}
|
|
145
145
|
const emptyOpts = [
|
|
146
146
|
...typeboxRefOpt(options?.ref),
|
|
147
|
+
schema.additionalProperties === false ? "additionalProperties:false" : typeof schema.additionalProperties === "object" ? `additionalProperties:${typebox(schema.additionalProperties, rootName, isTypebox, childOptions)}` : void 0,
|
|
147
148
|
...buildAdvancedOpts(schema, rootName, isTypebox, childOptions),
|
|
148
149
|
...typeboxMetaOpts(schema),
|
|
149
150
|
...typeboxDefaultOpt(schema)
|
|
@@ -151,12 +152,13 @@ function object(schema, rootName, isTypebox, options) {
|
|
|
151
152
|
return emptyOpts.length === 0 ? "Type.Object({})" : `Type.Object({},{${emptyOpts.join(",")}})`;
|
|
152
153
|
}
|
|
153
154
|
const required = new Set(schema.required);
|
|
154
|
-
const
|
|
155
|
+
const undeclaredRequired = (schema.required ?? []).filter((key) => !Object.hasOwn(schema.properties ?? {}, key)).map((key) => `${makeSafeKey(key)}:Type.Unknown()`);
|
|
156
|
+
const props = [...Object.entries(schema.properties).map(([key, propSchema]) => {
|
|
155
157
|
const parsed = typebox(propSchema, rootName, isTypebox, childOptions);
|
|
156
158
|
if (!parsed) return null;
|
|
157
159
|
const safeKey = makeSafeKey(key);
|
|
158
|
-
return required.has(key) || isOptionalByDefault(propSchema) ? `${safeKey}:${parsed}` : `${safeKey}:Type.Optional(${parsed})`;
|
|
159
|
-
}).filter((p) => p !== null);
|
|
160
|
+
return required.has(key) || isOptionalByDefault(propSchema, options?.definitions) ? `${safeKey}:${parsed}` : `${safeKey}:Type.Optional(${parsed})`;
|
|
161
|
+
}).filter((p) => p !== null), ...undeclaredRequired];
|
|
160
162
|
const objectErrorMessageEntries = [];
|
|
161
163
|
const objectErrorMessage = schema["x-error-message"];
|
|
162
164
|
if (objectErrorMessage) objectErrorMessageEntries.push(`type:${JSON.stringify(objectErrorMessage)}`);
|
|
@@ -188,7 +190,7 @@ function object(schema, rootName, isTypebox, options) {
|
|
|
188
190
|
const objectErrorMessageField = objectErrorMessageEntries.length > 0 ? `errorMessage:{${objectErrorMessageEntries.join(",")}}` : void 0;
|
|
189
191
|
const optParts = [
|
|
190
192
|
...typeboxRefOpt(options?.ref),
|
|
191
|
-
schema.additionalProperties === false ? "additionalProperties:false" : void 0,
|
|
193
|
+
schema.additionalProperties === false ? "additionalProperties:false" : typeof schema.additionalProperties === "object" ? `additionalProperties:${typebox(schema.additionalProperties, rootName, isTypebox, childOptions)}` : void 0,
|
|
192
194
|
...buildAdvancedOpts(schema, rootName, isTypebox, childOptions),
|
|
193
195
|
objectErrorMessageField,
|
|
194
196
|
...typeboxMetaOpts(schema),
|
|
@@ -209,6 +211,8 @@ function buildAdvancedOpts(schema, rootName, isTypebox, options) {
|
|
|
209
211
|
const thenOpt = schema.then ? `then:${typebox(schema.then, rootName, isTypebox, options)}` : void 0;
|
|
210
212
|
const elseOpt = schema.else ? `else:${typebox(schema.else, rootName, isTypebox, options)}` : void 0;
|
|
211
213
|
const requiredOpt = !schema.properties && Array.isArray(schema.required) && schema.required.length > 0 ? `required:${JSON.stringify(schema.required)}` : void 0;
|
|
214
|
+
const unevaluated = schema.unevaluatedProperties;
|
|
215
|
+
const unevaluatedOpt = unevaluated === false ? "unevaluatedProperties:false" : typeof unevaluated === "object" ? `unevaluatedProperties:${typebox(unevaluated, rootName, isTypebox, options)}` : void 0;
|
|
212
216
|
return [
|
|
213
217
|
typeof schema.minProperties === "number" ? `minProperties:${schema.minProperties}` : void 0,
|
|
214
218
|
typeof schema.maxProperties === "number" ? `maxProperties:${schema.maxProperties}` : void 0,
|
|
@@ -218,7 +222,8 @@ function buildAdvancedOpts(schema, rootName, isTypebox, options) {
|
|
|
218
222
|
ifOpt,
|
|
219
223
|
thenOpt,
|
|
220
224
|
elseOpt,
|
|
221
|
-
requiredOpt
|
|
225
|
+
requiredOpt,
|
|
226
|
+
unevaluatedOpt
|
|
222
227
|
];
|
|
223
228
|
}
|
|
224
229
|
//#endregion
|
|
@@ -290,7 +295,8 @@ function nestedTypeboxOptions(options) {
|
|
|
290
295
|
...options.openapi !== void 0 && { openapi: options.openapi },
|
|
291
296
|
...options.readonly !== void 0 && { readonly: options.readonly },
|
|
292
297
|
...options.paramIn !== void 0 && { paramIn: options.paramIn },
|
|
293
|
-
...options.cyclicRefs !== void 0 && { cyclicRefs: options.cyclicRefs }
|
|
298
|
+
...options.cyclicRefs !== void 0 && { cyclicRefs: options.cyclicRefs },
|
|
299
|
+
...options.definitions !== void 0 && { definitions: options.definitions }
|
|
294
300
|
};
|
|
295
301
|
}
|
|
296
302
|
/**
|
|
@@ -358,6 +364,7 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
|
|
|
358
364
|
const readonly = (v) => options?.readonly ? `Type.Readonly(${v})` : v;
|
|
359
365
|
const hostRef = options?.ref;
|
|
360
366
|
const childOptions = nestedTypeboxOptions(options);
|
|
367
|
+
const definitions = options?.definitions;
|
|
361
368
|
const named = (name, s) => options?.cyclicRefs?.has(name) ? byName(name, s) : name;
|
|
362
369
|
if (schema.$ref) {
|
|
363
370
|
const ref = (s) => {
|
|
@@ -380,13 +387,27 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
|
|
|
380
387
|
}
|
|
381
388
|
return "Type.Any()";
|
|
382
389
|
};
|
|
390
|
+
const withDefault = (s) => {
|
|
391
|
+
const defaultOpt = typeboxDefaultOpt(s, false, definitions);
|
|
392
|
+
const target = ref(s);
|
|
393
|
+
const inner = defaultOpt.length === 0 ? target : `Type.Intersect([${target}],{${defaultOpt.join(",")}})`;
|
|
394
|
+
return typeboxWrap(inner, s, definitions);
|
|
395
|
+
};
|
|
383
396
|
const items = itemsSchemaOf(schema.items);
|
|
384
|
-
if (schema.type === "array" && items?.$ref) return `Type.Array(${
|
|
385
|
-
return
|
|
397
|
+
if (schema.type === "array" && items?.$ref) return `Type.Array(${withDefault(items)})`;
|
|
398
|
+
return withDefault(schema);
|
|
386
399
|
}
|
|
387
400
|
if (schema.oneOf) {
|
|
388
401
|
if (schema.oneOf.length === 0) return typeboxWrap(tbPrim("Type.Any", schema, [], hostRef), schema);
|
|
389
|
-
const
|
|
402
|
+
const discriminated = discriminatedMembers(schema, schema.oneOf);
|
|
403
|
+
const schemas = schema.oneOf.map((s, i) => {
|
|
404
|
+
const member = typebox(s, rootName, isTypebox, childOptions);
|
|
405
|
+
const values = discriminated?.members[i]?.values;
|
|
406
|
+
if (discriminated === void 0 || values === void 0) return member;
|
|
407
|
+
const literals = values.map((value) => `Type.Literal(${JSON.stringify(value)})`);
|
|
408
|
+
const literal = literals.length === 1 ? literals[0] : `Type.Union([${literals.join(",")}])`;
|
|
409
|
+
return `Type.Intersect([${member},Type.Object({${makeSafeKey(discriminated.propertyName)}:${literal}})])`;
|
|
410
|
+
});
|
|
390
411
|
return typeboxWrap(tbComp("Type.Union", `[${schemas.join(",")}]`, schema, messageOpt(schema["x-oneOf-message"]), hostRef), schema);
|
|
391
412
|
}
|
|
392
413
|
if (schema.anyOf) {
|
|
@@ -405,22 +426,20 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
|
|
|
405
426
|
nullable
|
|
406
427
|
});
|
|
407
428
|
const unevaluated = schema.unevaluatedProperties;
|
|
408
|
-
const unevaluatedOpt = unevaluated === false ? ["unevaluatedProperties:false"] : typeof unevaluated === "object" && unevaluated !== null ? [`unevaluatedProperties:${typebox(unevaluated, rootName, isTypebox, childOptions)}`] : [];
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
nullable
|
|
423
|
-
});
|
|
429
|
+
const unevaluatedOpt = [...schema.patternProperties === void 0 ? [] : [`patternProperties:{${Object.entries(schema.patternProperties).map(([pattern, propSchema]) => `${JSON.stringify(pattern)}:${typebox(propSchema, rootName, isTypebox, childOptions)}`).join(",")}}`], ...unevaluated === false ? ["unevaluatedProperties:false"] : typeof unevaluated === "object" && unevaluated !== null ? [`unevaluatedProperties:${typebox(unevaluated, rootName, isTypebox, childOptions)}`] : []];
|
|
430
|
+
const { default: ownDefault, ...withoutDefault } = schema;
|
|
431
|
+
const withMergedDefault = {
|
|
432
|
+
...withoutDefault,
|
|
433
|
+
nullable,
|
|
434
|
+
...defaultValue !== void 0 ? { default: defaultValue } : ownDefault !== void 0 && { default: ownDefault }
|
|
435
|
+
};
|
|
436
|
+
const defaultOpt = typeboxDefaultOpt(withMergedDefault, false, definitions);
|
|
437
|
+
const baseResult = schemas.length === 1 && unevaluatedOpt.length === 0 && defaultOpt.length === 0 ? schemas[0] : tbComp("Type.Intersect", `[${schemas.join(",")}]`, withoutDefault, [
|
|
438
|
+
...messageOpt(schema["x-allOf-message"]),
|
|
439
|
+
...unevaluatedOpt,
|
|
440
|
+
...defaultOpt
|
|
441
|
+
], hostRef);
|
|
442
|
+
return typeboxWrap(baseResult, withMergedDefault, definitions);
|
|
424
443
|
}
|
|
425
444
|
if (schema.not) return typeboxWrap(tbPrim("Type.Any", schema, messageOpt(schema["x-not-message"]), hostRef), schema);
|
|
426
445
|
if (schema.const !== void 0) {
|
|
@@ -518,19 +537,21 @@ function schemaToTypebox(input, options) {
|
|
|
518
537
|
const exportType = options?.exportType ?? true;
|
|
519
538
|
const openapi = options?.openapi ?? false;
|
|
520
539
|
const hostRef = options?.ref;
|
|
540
|
+
const toName = schemaNamer(openapi);
|
|
541
|
+
const plan = planDocument(schema, rootNameOf(schema, toName));
|
|
542
|
+
const { rootName } = plan;
|
|
543
|
+
const definitions = definitionsOf(emitOptionsOf(options), plan.definitions);
|
|
521
544
|
const genOptions = {
|
|
522
545
|
openapi,
|
|
523
546
|
readonly: options?.readonly ?? false,
|
|
524
|
-
...options?.paramIn !== void 0 && { paramIn: options.paramIn }
|
|
547
|
+
...options?.paramIn !== void 0 && { paramIn: options.paramIn },
|
|
548
|
+
...definitions !== void 0 && { definitions }
|
|
525
549
|
};
|
|
526
550
|
const rootOptions = hostRef === void 0 ? genOptions : {
|
|
527
551
|
...genOptions,
|
|
528
552
|
ref: hostRef
|
|
529
553
|
};
|
|
530
554
|
const notKeywordPresent = hasNotKeyword(schema);
|
|
531
|
-
const toName = schemaNamer(openapi);
|
|
532
|
-
const plan = planDocument(schema, rootNameOf(schema, toName));
|
|
533
|
-
const { rootName } = plan;
|
|
534
555
|
if (hasRootSelfReference(plan.root, (ref) => isRootRef(ref) || openapi && resolveOpenAPIRef(ref) === rootName) || cyclicDefinitionNames(schema).size > 0) {
|
|
535
556
|
const cyclicRefs = /* @__PURE__ */ new Set([...plan.orderedNames.map(toName), rootName]);
|
|
536
557
|
const cyclicOptions = {
|
package/dist/typebox.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as JSONSchema } from "./index-G7UqNQ4w.js";
|
|
2
|
-
import { n as GenerateOptions } from "./index-
|
|
2
|
+
import { n as GenerateOptions } from "./index-EK43HM_z.js";
|
|
3
3
|
//#region src/generator/typebox/index.d.ts
|
|
4
4
|
/** The options of `schemaToTypebox`: the common ones, plus a host `$ref` name. */
|
|
5
5
|
export type TypeboxGenerateOptions = Omit<GenerateOptions, 'unsafeCodeExtensions'> & {
|
package/dist/typebox.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToTypebox } from "./typebox-
|
|
1
|
+
export { t as schemaToTypebox } from "./typebox-DGGKJLdP.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { At as UNSAFE_GENERATED_MARKER, B as isSchemaObject, F as isPrimitive, H as isStringWireLocation, M as isNullable, N as isObjectPrototypeProperty, S as hasFixedLength, T as hasType, V as isShapelessMember, X as DEFAULT_ROOT_NAME, at as INTEGER_TEXT_PATTERN, b as hasConditional, c as normalizeTypes, f as valibotError, j as isNullTypeMember, k as isDefaultOnlyMember, o as issueMessageExpression, p as valibotErrorPart, pt as NUMBER_RANGES, s as makeSafeKey, x as hasFixedItemCount, y as hasCombinator } from "./utils-Bky98UmP.js";
|
|
2
|
-
import { B as emitOptionsOf, C as isPrimitiveUnion, D as stringboolTruthyPattern, E as stringboolPattern, F as jsLiteral, G as schemaNamer, H as planDocument, J as
|
|
2
|
+
import { B as emitOptionsOf, C as isPrimitiveUnion, D as stringboolTruthyPattern, E as stringboolPattern, F as jsLiteral, G as schemaNamer, H as planDocument, J as hasRootSelfReference, K as discriminatedMembers, M as formatPattern, N as regexSource, O as unionPrimitiveTypes, S as isNullTextRead, T as ownProperties, U as renderDefinitions, W as rootNameOf, X as itemsSchemaOf, Y as isOptionalByDefault, at as foldAllOfMembers, b as integerWirePattern, c as withPolymorphicBases, ct as regexLiteral, d as propertyEmitOptions, f as withoutParameterSerialization, g as hoistNestedRefs, h as valueListLiteral, i as isEvaluatedKeyExpression, it as constraintPredicate, j as wireNumericKind, k as wireArrayOnce, l as hasParameterSerialization, m as notPredicate, n as valibotWrap, o as typeDeclaration, ot as isKeywordOnlyMember, p as isBigintFormat, r as evaluatedProperties, rt as constraintMessage, s as refTarget, tt as findCodeExtensionKeysInSchema, u as parameterReaders, w as numberWirePattern, y as impliedWireType, z as definitionsOf } from "./helper-S7SSsYwh.js";
|
|
3
3
|
//#region src/generator/valibot/type.ts
|
|
4
4
|
/** The TypeScript type declared beside a recursive Valibot schema: its output type. */
|
|
5
5
|
function type(schema, rootName = DEFAULT_ROOT_NAME) {
|
|
@@ -220,12 +220,20 @@ function object(schema, rootName, isValibot, options) {
|
|
|
220
220
|
const s = valibot(propSchema, rootName, isValibot, options);
|
|
221
221
|
return `v.check((input)=>Object.entries(input).every(([key,value])=>!new RegExp(${JSON.stringify(pattern)}).test(key)||v.safeParse(${s},value).success)${patternErrorArg})`;
|
|
222
222
|
}) : [];
|
|
223
|
-
if (typeof schema.additionalProperties === "object") {
|
|
223
|
+
if (typeof schema.additionalProperties === "object" && schema.properties === void 0 && schema.patternProperties === void 0) {
|
|
224
224
|
const record = `v.record(v.string(),${valibot(schema.additionalProperties, rootName, isValibot, options)})`;
|
|
225
|
-
const actions = [propertyNamesCheck()
|
|
225
|
+
const actions = [propertyNamesCheck()].filter((a) => a !== "");
|
|
226
226
|
return actions.length > 0 ? `v.pipe(${record},${actions.join(",")})` : record;
|
|
227
227
|
}
|
|
228
|
-
|
|
228
|
+
const properties = schema.properties ?? {};
|
|
229
|
+
const undeclaredRequired = (schema.required ?? []).filter((key) => !Object.hasOwn(properties, key));
|
|
230
|
+
const unevaluated = schema.unevaluatedProperties;
|
|
231
|
+
const closed = schema.additionalProperties === false || unevaluated === false;
|
|
232
|
+
const closedByCheck = closed && schema.patternProperties !== void 0;
|
|
233
|
+
const extraSchema = typeof schema.additionalProperties === "object" ? schema.additionalProperties : typeof unevaluated === "object" ? unevaluated : void 0;
|
|
234
|
+
const extraMessage = typeof schema.additionalProperties === "object" ? schema["x-additionalProperties-message"] : schema["x-unevaluatedProperties-message"];
|
|
235
|
+
const checksKeys = undeclaredRequired.length > 0 || extraSchema !== void 0 || closed;
|
|
236
|
+
if (!schema.properties && !checksKeys) {
|
|
229
237
|
if (schema.patternProperties) {
|
|
230
238
|
const record = `v.record(v.string(),v.unknown())`;
|
|
231
239
|
const actions = [propertyNamesCheck(), ...patternPropertiesChecks()].filter((a) => a !== "");
|
|
@@ -234,11 +242,11 @@ function object(schema, rootName, isValibot, options) {
|
|
|
234
242
|
if (schema.additionalProperties === true) return "v.any()";
|
|
235
243
|
return "v.object({})";
|
|
236
244
|
}
|
|
237
|
-
const
|
|
238
|
-
const objectKind = schema.additionalProperties === true ? "looseObject" :
|
|
245
|
+
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;
|
|
246
|
+
const objectKind = schema.additionalProperties === true ? "looseObject" : closed && !closedByCheck ? "strictObject" : readsUndeclaredKeys ? "looseObject" : "object";
|
|
239
247
|
const required = new Set(schema.required);
|
|
240
|
-
const hasOwnDefault = Object.values(
|
|
241
|
-
const props = Object.entries(
|
|
248
|
+
const hasOwnDefault = Object.values(properties).some((propSchema) => isOptionalByDefault(propSchema, options?.definitions));
|
|
249
|
+
const props = Object.entries(properties).map(([key, propSchema]) => {
|
|
242
250
|
const parsed = valibot(propSchema, rootName, isValibot, propertyEmitOptions(key, propSchema, options) ?? options);
|
|
243
251
|
if (!parsed) return null;
|
|
244
252
|
const safeKey = makeSafeKey(key);
|
|
@@ -249,7 +257,7 @@ function object(schema, rootName, isValibot, options) {
|
|
|
249
257
|
const propsMessage = schema["x-properties-message"];
|
|
250
258
|
const partialBase = propsMessage ? (() => {
|
|
251
259
|
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)}}}}))`;
|
|
260
|
+
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
261
|
})() : rawBase;
|
|
254
262
|
const minPropertiesCheck = typeof schema.minProperties === "number" ? `v.check((input)=>Object.keys(input).length>=${schema.minProperties}${minErrorArg})` : "";
|
|
255
263
|
const maxPropertiesCheck = typeof schema.maxProperties === "number" ? `v.check((input)=>Object.keys(input).length<=${schema.maxProperties}${maxErrorArg})` : "";
|
|
@@ -280,18 +288,26 @@ function object(schema, rootName, isValibot, options) {
|
|
|
280
288
|
}
|
|
281
289
|
return parts;
|
|
282
290
|
})();
|
|
291
|
+
const requiredPresentCheck = undeclaredRequired.length > 0 ? `v.check((input)=>${JSON.stringify(undeclaredRequired)}.every((key)=>key in input)${errorArg})` : "";
|
|
292
|
+
const isEvaluated = isEvaluatedKeyExpression({
|
|
293
|
+
names: Object.keys(properties),
|
|
294
|
+
patterns: Object.keys(schema.patternProperties ?? {})
|
|
295
|
+
}, "key");
|
|
296
|
+
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
297
|
const actions = [
|
|
284
298
|
minPropertiesCheck,
|
|
285
299
|
maxPropertiesCheck,
|
|
286
300
|
propertyNamesCheck(),
|
|
287
301
|
...patternPropertiesChecks(),
|
|
302
|
+
requiredPresentCheck,
|
|
303
|
+
unevaluatedKeysCheck,
|
|
288
304
|
...dependentRequiredChecks,
|
|
289
305
|
...dependentSchemasChecks,
|
|
290
306
|
additionalPropertiesCheck,
|
|
291
307
|
...ifThenElseChecks
|
|
292
308
|
].filter((a) => a !== "");
|
|
293
309
|
const objectExpr = actions.length > 0 ? `v.pipe(${partialBase},${actions.join(",")})` : partialBase;
|
|
294
|
-
const hasInheritedName = Object.keys(
|
|
310
|
+
const hasInheritedName = Object.keys(properties).some(isObjectPrototypeProperty);
|
|
295
311
|
return isStringWireLocation(options?.paramIn) && hasInheritedName ? `v.pipe(v.unknown(),v.transform(${ownProperties("input")}),${objectExpr})` : objectExpr;
|
|
296
312
|
}
|
|
297
313
|
//#endregion
|
|
@@ -409,21 +425,28 @@ function stringbool(errorArg) {
|
|
|
409
425
|
return `v.pipe(${stringboolItems(errorArg).join(",")})`;
|
|
410
426
|
}
|
|
411
427
|
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)}}}}))`;
|
|
428
|
+
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})`;
|
|
429
|
+
}
|
|
430
|
+
/** Add a key's issues (`result`) to the raw check. */
|
|
431
|
+
function forwardKeyIssues(message) {
|
|
432
|
+
return `for(const issue of result.issues){addIssue({message:${message === void 0 ? "issue.message" : JSON.stringify(message)}})}`;
|
|
413
433
|
}
|
|
414
434
|
/**
|
|
415
|
-
* An `allOf` with `unevaluatedProperties` beside it: the members'
|
|
416
|
-
* do not declare, so the keys
|
|
417
|
-
* parsed
|
|
435
|
+
* An `allOf` with `patternProperties` or `unevaluatedProperties` beside it: the members'
|
|
436
|
+
* objects strip what they do not declare, so the keys are checked on the input before it
|
|
437
|
+
* is parsed — a key a pattern matches against that pattern's schema, a key no member
|
|
438
|
+
* evaluates against `unevaluatedProperties`. `inner` as given when there is nothing to check.
|
|
418
439
|
*/
|
|
419
|
-
function
|
|
440
|
+
function objectKeysCheck(inner, schema, rootName, isValibot, options) {
|
|
441
|
+
const patterns = Object.entries(schema.patternProperties ?? {});
|
|
420
442
|
const unevaluated = schema.unevaluatedProperties;
|
|
421
|
-
|
|
422
|
-
const evaluated = evaluatedProperties(schema, options?.definitions);
|
|
423
|
-
if (evaluated === void 0) return inner;
|
|
424
|
-
const
|
|
443
|
+
const unevaluatedSchema = typeof unevaluated === "object" ? unevaluated : void 0;
|
|
444
|
+
const evaluated = unevaluated === false || unevaluatedSchema !== void 0 ? evaluatedProperties(schema, options?.definitions) : void 0;
|
|
445
|
+
if (patterns.length === 0 && evaluated === void 0) return inner;
|
|
446
|
+
const patternMessage = schema["x-patternProperties-message"];
|
|
447
|
+
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
448
|
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
|
|
449
|
+
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
450
|
}
|
|
428
451
|
/**
|
|
429
452
|
* Generate Valibot schema code from JSON Schema.
|
|
@@ -492,11 +515,18 @@ function node(schema, rootName, isValibot, options) {
|
|
|
492
515
|
}, rootName, isValibot, options);
|
|
493
516
|
if (schema.oneOf) {
|
|
494
517
|
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
518
|
const discriminator = schema.discriminator?.propertyName;
|
|
499
519
|
const hasRefOrAllOf = schema.oneOf.some((s) => s.$ref !== void 0 || s.allOf !== void 0);
|
|
520
|
+
const discriminated = hasRefOrAllOf ? discriminatedMembers(schema, schema.oneOf) : void 0;
|
|
521
|
+
const schemas = schema.oneOf.map((s, i) => {
|
|
522
|
+
const member = valibot(s, rootName, isValibot, options);
|
|
523
|
+
const values = discriminated?.members[i]?.values;
|
|
524
|
+
if (discriminated === void 0 || values === void 0) return member;
|
|
525
|
+
const literal = values.length === 1 ? `v.literal(${JSON.stringify(values[0])})` : `v.picklist(${JSON.stringify(values)})`;
|
|
526
|
+
return `v.intersect([${member},v.object({${makeSafeKey(discriminated.propertyName)}:${literal}})])`;
|
|
527
|
+
});
|
|
528
|
+
const oneOfMessage = schema["x-oneOf-message"];
|
|
529
|
+
const errorPart = valibotErrorPart(oneOfMessage);
|
|
500
530
|
return valibotWrap$1(discriminator && !hasRefOrAllOf ? `v.variant('${discriminator}',[${schemas.join(",")}]${errorPart})` : `v.union([${schemas.join(",")}]${errorPart})`, schema);
|
|
501
531
|
}
|
|
502
532
|
if (schema.anyOf) {
|
|
@@ -517,9 +547,9 @@ function node(schema, rootName, isValibot, options) {
|
|
|
517
547
|
});
|
|
518
548
|
const intersected = schemas.length === 1 ? schemas[0] : `v.intersect([${schemas.join(",")}])`;
|
|
519
549
|
const allOfMessage = schema["x-allOf-message"];
|
|
520
|
-
const checked =
|
|
550
|
+
const checked = objectKeysCheck(allOfMessage ? (() => {
|
|
521
551
|
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})}}}))`;
|
|
552
|
+
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
553
|
})() : intersected, schema, rootName, isValibot, options);
|
|
524
554
|
if (defaultValue !== void 0) return `v.optional(${nullable ? `v.nullable(${checked})` : checked},${jsLiteral(defaultValue)})`;
|
|
525
555
|
return valibotWrap$1(checked, {
|
package/dist/valibot.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as JSONSchema } from "./index-G7UqNQ4w.js";
|
|
2
|
-
import { n as GenerateOptions } from "./index-
|
|
2
|
+
import { n as GenerateOptions } from "./index-EK43HM_z.js";
|
|
3
3
|
//#region src/generator/valibot/index.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* A whole JSON Schema document as a Valibot module: imports, `$defs` in dependency
|
package/dist/valibot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToValibot } from "./valibot-
|
|
1
|
+
export { t as schemaToValibot } from "./valibot-B6y4VQFF.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as normalizeTypes, s as makeSafeKey } from "./utils-Bky98UmP.js";
|
|
2
|
-
import { G as schemaNamer, W as rootNameOf } from "./helper-
|
|
2
|
+
import { G as schemaNamer, W as rootNameOf } from "./helper-S7SSsYwh.js";
|
|
3
3
|
//#region src/generator/yup/integer.ts
|
|
4
4
|
/**
|
|
5
5
|
* Generate a Yup integer schema as `yup.number().integer()`, with `minimum`
|
package/dist/yup.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as JSONSchema } from "./index-G7UqNQ4w.js";
|
|
2
|
-
import { n as GenerateOptions } from "./index-
|
|
2
|
+
import { n as GenerateOptions } from "./index-EK43HM_z.js";
|
|
3
3
|
//#region src/generator/yup/index.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Convert a JSON Schema document to Yup schema source.
|
package/dist/yup.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToYup } from "./yup-
|
|
1
|
+
export { t as schemaToYup } from "./yup-DuqQwHUv.js";
|