schema-truth 0.7.0 → 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/{ajv-DTP2FXRr.js → ajv-DS9gtNZC.js} +1 -1
- package/dist/ajv.d.ts +1 -1
- package/dist/ajv.js +1 -1
- package/dist/{arktype-BdvvaBQX.js → arktype-CBV4bg-0.js} +179 -75
- package/dist/arktype.d.ts +3 -3
- 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-CL2mSark.js → cli-CB9GJ7qa.js} +2 -2
- package/dist/{effect-mUknRPv_.js → effect-D9pvwi_6.js} +91 -31
- package/dist/effect.d.ts +3 -3
- package/dist/effect.js +1 -1
- package/dist/{helper-Cfvb5UDq.js → helper-S7SSsYwh.js} +777 -40
- package/dist/{index-C2L8Ty0-.d.ts → index-EK43HM_z.d.ts} +29 -25
- package/dist/{index-DbV3dEmN.d.ts → index-G7UqNQ4w.d.ts} +54 -2
- package/dist/index.d.ts +63 -25
- package/dist/index.js +9 -9
- package/dist/{typebox-BdWJv3ND.js → typebox-DGGKJLdP.js} +82 -42
- package/dist/typebox.d.ts +3 -3
- package/dist/typebox.js +1 -1
- package/dist/{utils-WNBq1HR0.js → utils-Bky98UmP.js} +160 -31
- package/dist/{valibot-CaJIynCH.js → valibot-B6y4VQFF.js} +107 -36
- package/dist/valibot.d.ts +3 -3
- package/dist/valibot.js +1 -1
- package/dist/{yup-CM2TSFig.js → yup-DuqQwHUv.js} +2 -2
- package/dist/yup.d.ts +2 -2
- package/dist/yup.js +1 -1
- package/dist/{zod-BsXLZfwK.js → zod-CXo9NFuF.js} +192 -115
- package/dist/zod.d.ts +3 -3
- package/dist/zod.js +1 -1
- package/package.json +1 -1
|
@@ -158,6 +158,17 @@ const STRINGBOOL_PATTERN = /^(?:true|1|yes|on|y|enabled|false|0|no|off|n|disable
|
|
|
158
158
|
const STRINGBOOL_TRUTHY_PATTERN = /^(?:true|1|yes|on|y|enabled)$/i;
|
|
159
159
|
/** The text of a 64-bit integer: a sign and digits, which `BigInt` reads losslessly. */
|
|
160
160
|
const INTEGER_TEXT_PATTERN = /^-?\d+$/;
|
|
161
|
+
/**
|
|
162
|
+
* Integer text on the string wire. A sign and digits, with no leading zero, no exponent
|
|
163
|
+
* and no fraction: `Number` and `parseInt` both accept more than this (`""`, `" "`,
|
|
164
|
+
* `"0x10"`, `"1e3"`, `"1.9xyz"`).
|
|
165
|
+
*/
|
|
166
|
+
const INTEGER_WIRE_PATTERN = /^-?(?:0|[1-9]\d*)$/;
|
|
167
|
+
/**
|
|
168
|
+
* Number text on the string wire: the JSON number grammar (RFC 8259). An exponent is a
|
|
169
|
+
* number (`1e3`) and is not an integer. Blank, hex and trailing junk are not numbers.
|
|
170
|
+
*/
|
|
171
|
+
const NUMBER_WIRE_PATTERN = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
|
|
161
172
|
/** The range of each fixed-width numeric format, as the literals the generators emit. */
|
|
162
173
|
const NUMBER_RANGES = {
|
|
163
174
|
int32: {
|
|
@@ -849,56 +860,174 @@ function normalizeTypes(t) {
|
|
|
849
860
|
}
|
|
850
861
|
/**
|
|
851
862
|
* Reconcile a schema's `default` value with the type the schema actually emits
|
|
852
|
-
* so the generated `.default(...)` stays assignable.
|
|
863
|
+
* so the generated `.default(...)` stays assignable. The default is kept only
|
|
864
|
+
* when it is a value of the schema, read the way a document usually writes it:
|
|
853
865
|
*
|
|
854
|
-
* - `null` on a
|
|
855
|
-
*
|
|
856
|
-
* - a
|
|
857
|
-
*
|
|
858
|
-
*
|
|
866
|
+
* - `null` is kept only on a nullable schema (or one whose `enum` lists it).
|
|
867
|
+
* - an `enum` / `const` takes only what it lists.
|
|
868
|
+
* - text that spells a value of the schema's type is read as that value: `'true'`
|
|
869
|
+
* for a boolean, `'7'` for a number or an integer; a number or a boolean for a
|
|
870
|
+
* string is written as text. Any other scalar of the wrong type is dropped
|
|
871
|
+
* (`'null'` for an integer, `'strict'` with the quotes for an enum).
|
|
872
|
+
* - an array keeps its items when every one is a value of `items`.
|
|
873
|
+
* - an object default drops keys the schema does not declare, when the emitted
|
|
874
|
+
* object has no index signature (`additionalProperties` is not `true` or a
|
|
875
|
+
* schema, and there are no `patternProperties`), and needs every `required`
|
|
876
|
+
* key. A loose or record schema keeps every key.
|
|
877
|
+
* - a `$ref`, or an `allOf` the node has no type of its own beside, is read as
|
|
878
|
+
* the definition it names when `definitions` has it; a `oneOf` / `anyOf` keeps
|
|
879
|
+
* the default when a member takes it, whatever `type` sits beside it.
|
|
880
|
+
* - a node with nothing to check against (no `type`, an unknown `$ref`) keeps
|
|
881
|
+
* the default as written.
|
|
859
882
|
*
|
|
860
|
-
*
|
|
861
|
-
*
|
|
862
|
-
* mismatches and schemas without an explicit `type` (`oneOf`/`$ref` only)
|
|
863
|
-
* pass through untouched — JSON Schema 2020-12 §9.9.4.1 treats `default` as
|
|
864
|
-
* an annotation with no validity guarantee, so anything finer would need a
|
|
865
|
-
* full validator.
|
|
883
|
+
* JSON Schema 2020-12 §9.9.4.1 treats `default` as an annotation with no
|
|
884
|
+
* validity guarantee, so an invalid one is dropped rather than reported.
|
|
866
885
|
*
|
|
867
886
|
* @example
|
|
868
887
|
* ```ts
|
|
869
|
-
* coerceDefault({ type: 'boolean' }, 'true')
|
|
870
|
-
* coerceDefault({ type: '
|
|
888
|
+
* coerceDefault({ type: 'boolean' }, 'true') // { keep: true, value: true }
|
|
889
|
+
* coerceDefault({ type: 'number' }, '7') // { keep: true, value: 7 }
|
|
890
|
+
* coerceDefault({ type: 'object' }, null) // { keep: false, value: null }
|
|
871
891
|
* coerceDefault({ type: 'object', nullable: true }, null) // { keep: true, value: null }
|
|
872
|
-
* coerceDefault({ type: 'array' }, 'eval')
|
|
892
|
+
* coerceDefault({ type: 'array' }, 'eval') // { keep: false, value: 'eval' }
|
|
893
|
+
* coerceDefault({ enum: ['a', 'b'] }, "'a'") // { keep: false, value: "'a'" }
|
|
873
894
|
* ```
|
|
874
895
|
*/
|
|
875
|
-
function coerceDefault(schema, value) {
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
896
|
+
function coerceDefault(schema, value, definitions) {
|
|
897
|
+
return conformDefault(schema, value, definitions, /* @__PURE__ */ new Set());
|
|
898
|
+
}
|
|
899
|
+
function conformDefault(schema, value, definitions, reading) {
|
|
900
|
+
const drop = {
|
|
879
901
|
keep: false,
|
|
880
902
|
value
|
|
881
903
|
};
|
|
882
|
-
|
|
904
|
+
const asIs = {
|
|
883
905
|
keep: true,
|
|
884
|
-
value: value === "true"
|
|
885
|
-
};
|
|
886
|
-
const isComposite = Array.isArray(value) || typeof value === "object" && value !== null;
|
|
887
|
-
const allowsComposite = types.length === 0 || types.includes("array") || types.includes("object");
|
|
888
|
-
if (isComposite && !allowsComposite) return {
|
|
889
|
-
keep: false,
|
|
890
906
|
value
|
|
891
907
|
};
|
|
892
|
-
const
|
|
893
|
-
if (
|
|
894
|
-
|
|
908
|
+
const conform = (s, v, r = reading) => conformDefault(s, v, definitions, r);
|
|
909
|
+
if (schema.$ref !== void 0) {
|
|
910
|
+
const target = reading.has(schema.$ref) ? void 0 : definitionOf(schema.$ref, definitions);
|
|
911
|
+
if (target === void 0) return value === null && schema.nullable !== true ? drop : asIs;
|
|
912
|
+
const { $ref, ...beside } = schema;
|
|
913
|
+
return conform({
|
|
914
|
+
...target,
|
|
915
|
+
...beside
|
|
916
|
+
}, value, /* @__PURE__ */ new Set([...reading, $ref]));
|
|
917
|
+
}
|
|
918
|
+
const types = normalizeTypes(schema.type);
|
|
919
|
+
const isNullable = schema.nullable === true || types.includes("null") || schema.enum?.includes(null) === true || schema.const === null;
|
|
920
|
+
if (value === null) {
|
|
921
|
+
if (isNullable) return asIs;
|
|
922
|
+
return [...schema.oneOf ?? [], ...schema.anyOf ?? []].some((member) => conform(member, null).keep) ? asIs : drop;
|
|
923
|
+
}
|
|
924
|
+
const members = schema.oneOf ?? schema.anyOf;
|
|
925
|
+
if (members !== void 0 && members.length > 0) {
|
|
926
|
+
const results = members.map((member) => conform(member, value));
|
|
927
|
+
return results.find((result) => result.keep && result.value === value) ?? results.find((result) => result.keep) ?? drop;
|
|
928
|
+
}
|
|
929
|
+
if (schema.enum !== void 0) return schema.enum.some((member) => member === value) ? asIs : drop;
|
|
930
|
+
if (schema.const !== void 0) return JSON.stringify(schema.const) === JSON.stringify(value) ? asIs : drop;
|
|
931
|
+
if (types.length === 0 && schema.allOf !== void 0) return schema.allOf.filter((member) => {
|
|
932
|
+
const memberTypes = normalizeTypes(member.type);
|
|
933
|
+
return memberTypes.length === 0 || memberTypes.some((t) => t !== "null");
|
|
934
|
+
}).reduce((result, member) => result.keep ? conform(member, result.value) : result, asIs);
|
|
935
|
+
const valueTypes = types.filter((t) => t !== "null");
|
|
936
|
+
if (types.length > 0 && valueTypes.length === 0) return drop;
|
|
937
|
+
if (valueTypes.length === 0) return schema.properties !== void 0 ? readObject(schema, value, conform) ?? drop : asIs;
|
|
938
|
+
const read = (type) => {
|
|
939
|
+
if (type === "boolean") {
|
|
940
|
+
if (typeof value === "boolean") return asIs;
|
|
941
|
+
if (value === "true" || value === "false") return {
|
|
942
|
+
keep: true,
|
|
943
|
+
value: value === "true"
|
|
944
|
+
};
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
if (type === "number" || type === "integer") {
|
|
948
|
+
const number = typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" && Number.isFinite(Number(value)) ? Number(value) : void 0;
|
|
949
|
+
if (number === void 0) return void 0;
|
|
950
|
+
if (type === "integer" && !Number.isInteger(number)) return void 0;
|
|
951
|
+
return {
|
|
952
|
+
keep: true,
|
|
953
|
+
value: number
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
if (type === "string") {
|
|
957
|
+
if (typeof value === "string") return asIs;
|
|
958
|
+
if (typeof value === "number" || typeof value === "boolean") return {
|
|
959
|
+
keep: true,
|
|
960
|
+
value: String(value)
|
|
961
|
+
};
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
if (type === "array") {
|
|
965
|
+
if (!Array.isArray(value)) return void 0;
|
|
966
|
+
const items = schema.items;
|
|
967
|
+
if (!isDefaultSchemaObject(items)) return asIs;
|
|
968
|
+
const readItems = value.map((item) => conform(items, item));
|
|
969
|
+
return readItems.every((item) => item.keep) ? {
|
|
970
|
+
keep: true,
|
|
971
|
+
value: readItems.map((item) => item.value)
|
|
972
|
+
} : void 0;
|
|
973
|
+
}
|
|
974
|
+
if (type === "object") return readObject(schema, value, conform);
|
|
975
|
+
return asIs;
|
|
976
|
+
};
|
|
977
|
+
const own = valueTypes.find((type) => typeOf(value) === type || type === "number" && typeof value === "number");
|
|
978
|
+
return (own === void 0 ? void 0 : read(own)) ?? valueTypes.map(read).find((r) => r !== void 0) ?? drop;
|
|
979
|
+
}
|
|
980
|
+
/** An object default as a value of the schema, or `undefined` when it is not one. */
|
|
981
|
+
function readObject(schema, value, conform) {
|
|
982
|
+
if (!isDeclaredObject(value)) return void 0;
|
|
983
|
+
if (schema.properties === void 0 || canHoldUndeclaredKeys(schema)) return {
|
|
984
|
+
keep: true,
|
|
895
985
|
value
|
|
896
986
|
};
|
|
987
|
+
const declared = schema.properties;
|
|
988
|
+
if ((schema.required ?? []).some((key) => !Object.hasOwn(value, key))) return void 0;
|
|
989
|
+
const kept = {};
|
|
990
|
+
for (const [key, item] of Object.entries(value)) {
|
|
991
|
+
if (!Object.hasOwn(declared, key)) continue;
|
|
992
|
+
const result = conform(declared[key], item);
|
|
993
|
+
if (!result.keep) return void 0;
|
|
994
|
+
kept[key] = result.value;
|
|
995
|
+
}
|
|
897
996
|
return {
|
|
898
997
|
keep: true,
|
|
899
|
-
value
|
|
998
|
+
value: kept
|
|
900
999
|
};
|
|
901
1000
|
}
|
|
1001
|
+
/** The definition a local `$ref` names, when `definitions` has it. */
|
|
1002
|
+
function definitionOf(ref, definitions) {
|
|
1003
|
+
if (definitions === void 0) return void 0;
|
|
1004
|
+
for (const prefix of DEFINITION_REF_PREFIXES) {
|
|
1005
|
+
if (!ref.startsWith(prefix)) continue;
|
|
1006
|
+
const rest = ref.slice(prefix.length);
|
|
1007
|
+
if (rest === "" || rest.includes("/")) return void 0;
|
|
1008
|
+
const name = decodeURIComponent(rest);
|
|
1009
|
+
return Object.hasOwn(definitions, name) ? definitions[name] : void 0;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
function typeOf(value) {
|
|
1013
|
+
if (typeof value === "boolean") return "boolean";
|
|
1014
|
+
if (typeof value === "number") return Number.isInteger(value) ? "integer" : "number";
|
|
1015
|
+
if (typeof value === "string") return "string";
|
|
1016
|
+
if (Array.isArray(value)) return "array";
|
|
1017
|
+
if (isDeclaredObject(value)) return "object";
|
|
1018
|
+
}
|
|
1019
|
+
function isDefaultSchemaObject(value) {
|
|
1020
|
+
return typeof value === "object" && !Array.isArray(value);
|
|
1021
|
+
}
|
|
1022
|
+
function isDeclaredObject(value) {
|
|
1023
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1024
|
+
}
|
|
1025
|
+
/** Whether a generated object type accepts keys the schema does not name. */
|
|
1026
|
+
function canHoldUndeclaredKeys(schema) {
|
|
1027
|
+
if (schema.additionalProperties === true || typeof schema.additionalProperties === "object") return true;
|
|
1028
|
+
if (schema.patternProperties !== void 0) return true;
|
|
1029
|
+
return schema.unevaluatedProperties === true || typeof schema.unevaluatedProperties === "object";
|
|
1030
|
+
}
|
|
902
1031
|
/**
|
|
903
1032
|
* A message as the expression an emitted check evaluates for each issue: an arrow source
|
|
904
1033
|
* is applied to the issue, a sentence becomes a string literal.
|
|
@@ -1014,4 +1143,4 @@ function makeSafeKey(key) {
|
|
|
1014
1143
|
return isValidIdentifier(key) ? key : JSON.stringify(key);
|
|
1015
1144
|
}
|
|
1016
1145
|
//#endregion
|
|
1017
|
-
export { DEFINITION_REF_PREFIXES as $, isDefinitionKeyword as A,
|
|
1146
|
+
export { DEFINITION_REF_PREFIXES as $, isDefinitionKeyword as A, UNSAFE_GENERATED_MARKER as At, isSchemaObject as B, hasNumericKeyword as C, ROOT_REFS as Ct, isComposite as D, STRING_KEYWORDS as Dt, isArktypeDefinition as E, STRING_FORMATS as Et, isPrimitive as F, ARKTYPE_CODE_EXTENSION_KEYS as G, isStringWireLocation as H, isQuoted as I, CONTENT_ENCODINGS as J, ARROW_FUNCTION_PATTERN as K, isRecord as L, isNullable as M, WIRE_PRIMITIVE_ORDER as Mt, isObjectPrototypeProperty as N, ZOD_CODE_EXTENSION_KEYS as Nt, isDeepLocalPointer as O, STRING_WIRE_LOCATIONS as Ot, isPlainObject as P, DEFINITION_POINTER_PATTERN as Q, isRootRef as R, hasFixedLength as S, QUOTE_OR_BACKSLASH_PATTERN as St, hasType as T, STRINGBOOL_TRUTHY_PATTERN as Tt, ALL_CODE_EXTENSION_KEYS as U, isShapelessMember as V, ANCHOR_REF_PATTERN as W, DEFAULT_ROOT_NAME as X, DATE_PATTERN_SOURCE as Y, DEFINITION_KEYWORDS as Z, canBeNull as _, OFFSET_PATTERN_SOURCE as _t, encodeNonAscii as a, INTEGER_TEXT_PATTERN as at, hasConditional as b, PARAM_LOCATIONS as bt, normalizeTypes as c, JSON_SCHEMA_TYPES as ct, toPascalCase as d, NOT_KEYWORD_UNSUPPORTED_MARKER as dt, EFFECT_CODE_EXTENSION_KEYS as et, valibotError as f, NUMBER_FORMATS as ft, zodErrorPart as g, OBJECT_PROTOTYPE_PROPERTIES as gt, zodError as h, NUMERIC_KEYWORDS as ht, effectMessage as i, INPUT_EXTENSIONS as it, isNullTypeMember as j, VALIBOT_CODE_EXTENSION_KEYS as jt, isDefaultOnlyMember as k, UNICODE_ESCAPE_PATTERN as kt, resolveOpenAPIRef as l, MISSING_DEFINITION_PREFIX as lt, zodBaseError as m, NUMBER_WIRE_PATTERN as mt, effectError as n, IDENTIFIER_PATTERN as nt, issueMessageExpression as o, INTEGER_WIRE_PATTERN as ot, valibotErrorPart as p, NUMBER_RANGES as pt, COMPONENT_SCHEMA_REF_PREFIX as q, effectErrorPart as r, IF_THEN_ELSE_UNSUPPORTED_MARKER as rt, makeSafeKey as s, ISO_4217_CURRENCY_CODES as st, coerceDefault as t, FORMAT_PATTERNS as tt, toIdentifierPascalCase as u, NON_IDENTIFIER_CHARACTER_PATTERN as ut, canBeString as v, OPENAPI_COMPONENT_SUFFIX_MAP as vt, hasStringKeyword as w, STRINGBOOL_PATTERN as wt, hasFixedItemCount as x, PARAM_STYLES as xt, hasCombinator as y, OUTPUT_EXTENSION as yt, isSchemaList as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as isSchemaObject, F as isPrimitive, H as isStringWireLocation, M as isNullable, N as isObjectPrototypeProperty,
|
|
2
|
-
import {
|
|
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 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) {
|
|
@@ -41,8 +41,9 @@ function rangeActions(format) {
|
|
|
41
41
|
return [`v.minValue(${range.minimum})`, `v.maxValue(${range.maximum})`];
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* The Valibot schema of a number node. On the string wire the text
|
|
45
|
-
*
|
|
44
|
+
* The Valibot schema of a number node. On the string wire the text has to match the JSON
|
|
45
|
+
* number grammar before `Number` reads it, then it is checked finite; `float` / `float32`
|
|
46
|
+
* carries its range.
|
|
46
47
|
*/
|
|
47
48
|
function number(schema, options) {
|
|
48
49
|
const errorMessage = schema["x-error-message"];
|
|
@@ -55,7 +56,10 @@ function number(schema, options) {
|
|
|
55
56
|
...numberActions(schema)
|
|
56
57
|
];
|
|
57
58
|
const base = `v.number(${baseErrorArg})`;
|
|
58
|
-
if (options?.wire === true)
|
|
59
|
+
if (options?.wire === true) {
|
|
60
|
+
const regexError = baseErrorArg === "" ? "" : `,${baseErrorArg}`;
|
|
61
|
+
return `v.pipe(v.string(),v.regex(${numberWirePattern()}${regexError}),v.transform((input)=>Number(input)),${base},${actions.join(",")})`;
|
|
62
|
+
}
|
|
59
63
|
if (actions.length > 0) return `v.pipe(${base},${actions.join(",")})`;
|
|
60
64
|
return errorMessage ? base : "v.number()";
|
|
61
65
|
}
|
|
@@ -82,7 +86,8 @@ function int64Input(isWire, baseErrorArg = "") {
|
|
|
82
86
|
/**
|
|
83
87
|
* The Valibot schema of an integer node. `int64` / `uint64` are bigints wherever they
|
|
84
88
|
* come from, `bigint` is one too, `int32` / `uint32` carry their range, and on the
|
|
85
|
-
* string wire the text
|
|
89
|
+
* string wire the text has to match the integer grammar before `Number` reads it, and is
|
|
90
|
+
* then checked a safe integer.
|
|
86
91
|
*/
|
|
87
92
|
function integer(schema, options) {
|
|
88
93
|
const isWire = options?.wire === true;
|
|
@@ -110,8 +115,13 @@ function integer(schema, options) {
|
|
|
110
115
|
...rangeActions(schema.format),
|
|
111
116
|
...numberActions(schema)
|
|
112
117
|
];
|
|
118
|
+
const regexError = baseErrorArg === "" ? "" : `,${baseErrorArg}`;
|
|
113
119
|
return `v.pipe(${[
|
|
114
|
-
...isWire ? [
|
|
120
|
+
...isWire ? [
|
|
121
|
+
"v.string()",
|
|
122
|
+
`v.regex(${integerWirePattern()}${regexError})`,
|
|
123
|
+
"v.transform((input)=>Number(input))"
|
|
124
|
+
] : [],
|
|
115
125
|
`v.number(${baseErrorArg})`,
|
|
116
126
|
...actions
|
|
117
127
|
].join(",")})`;
|
|
@@ -210,12 +220,20 @@ function object(schema, rootName, isValibot, options) {
|
|
|
210
220
|
const s = valibot(propSchema, rootName, isValibot, options);
|
|
211
221
|
return `v.check((input)=>Object.entries(input).every(([key,value])=>!new RegExp(${JSON.stringify(pattern)}).test(key)||v.safeParse(${s},value).success)${patternErrorArg})`;
|
|
212
222
|
}) : [];
|
|
213
|
-
if (typeof schema.additionalProperties === "object") {
|
|
223
|
+
if (typeof schema.additionalProperties === "object" && schema.properties === void 0 && schema.patternProperties === void 0) {
|
|
214
224
|
const record = `v.record(v.string(),${valibot(schema.additionalProperties, rootName, isValibot, options)})`;
|
|
215
|
-
const actions = [propertyNamesCheck()
|
|
225
|
+
const actions = [propertyNamesCheck()].filter((a) => a !== "");
|
|
216
226
|
return actions.length > 0 ? `v.pipe(${record},${actions.join(",")})` : record;
|
|
217
227
|
}
|
|
218
|
-
|
|
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) {
|
|
219
237
|
if (schema.patternProperties) {
|
|
220
238
|
const record = `v.record(v.string(),v.unknown())`;
|
|
221
239
|
const actions = [propertyNamesCheck(), ...patternPropertiesChecks()].filter((a) => a !== "");
|
|
@@ -224,22 +242,22 @@ function object(schema, rootName, isValibot, options) {
|
|
|
224
242
|
if (schema.additionalProperties === true) return "v.any()";
|
|
225
243
|
return "v.object({})";
|
|
226
244
|
}
|
|
227
|
-
const
|
|
228
|
-
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";
|
|
229
247
|
const required = new Set(schema.required);
|
|
230
|
-
const hasOwnDefault = Object.values(
|
|
231
|
-
const props = Object.entries(
|
|
232
|
-
const parsed = valibot(propSchema, rootName, isValibot, options);
|
|
248
|
+
const hasOwnDefault = Object.values(properties).some((propSchema) => isOptionalByDefault(propSchema, options?.definitions));
|
|
249
|
+
const props = Object.entries(properties).map(([key, propSchema]) => {
|
|
250
|
+
const parsed = valibot(propSchema, rootName, isValibot, propertyEmitOptions(key, propSchema, options) ?? options);
|
|
233
251
|
if (!parsed) return null;
|
|
234
252
|
const safeKey = makeSafeKey(key);
|
|
235
|
-
return required.has(key) || isOptionalByDefault(propSchema) ? `${safeKey}:${parsed}` : `${safeKey}:v.optional(${parsed})`;
|
|
253
|
+
return required.has(key) || isOptionalByDefault(propSchema, options?.definitions) ? `${safeKey}:${parsed}` : `${safeKey}:v.optional(${parsed})`;
|
|
236
254
|
}).filter((p) => p !== null);
|
|
237
255
|
const strictMessageArg = objectKind === "strictObject" ? valibotErrorPart(strictExtrasMessage) : "";
|
|
238
256
|
const rawBase = required.size === 0 && !hasOwnDefault && props.every((p) => p.includes("v.optional(")) ? `v.partial(v.${objectKind}({${props.map((p) => p.replace(/^(.+?):v\.optional\((.+)\)$/u, "$1:$2")).join(",")}}${strictMessageArg}))` : `v.${objectKind}({${props.join(",")}}${strictMessageArg})`;
|
|
239
257
|
const propsMessage = schema["x-properties-message"];
|
|
240
258
|
const partialBase = propsMessage ? (() => {
|
|
241
259
|
const msgExpr = issueMessageExpression(propsMessage);
|
|
242
|
-
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})`;
|
|
243
261
|
})() : rawBase;
|
|
244
262
|
const minPropertiesCheck = typeof schema.minProperties === "number" ? `v.check((input)=>Object.keys(input).length>=${schema.minProperties}${minErrorArg})` : "";
|
|
245
263
|
const maxPropertiesCheck = typeof schema.maxProperties === "number" ? `v.check((input)=>Object.keys(input).length<=${schema.maxProperties}${maxErrorArg})` : "";
|
|
@@ -270,18 +288,26 @@ function object(schema, rootName, isValibot, options) {
|
|
|
270
288
|
}
|
|
271
289
|
return parts;
|
|
272
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)})` : "";
|
|
273
297
|
const actions = [
|
|
274
298
|
minPropertiesCheck,
|
|
275
299
|
maxPropertiesCheck,
|
|
276
300
|
propertyNamesCheck(),
|
|
277
301
|
...patternPropertiesChecks(),
|
|
302
|
+
requiredPresentCheck,
|
|
303
|
+
unevaluatedKeysCheck,
|
|
278
304
|
...dependentRequiredChecks,
|
|
279
305
|
...dependentSchemasChecks,
|
|
280
306
|
additionalPropertiesCheck,
|
|
281
307
|
...ifThenElseChecks
|
|
282
308
|
].filter((a) => a !== "");
|
|
283
309
|
const objectExpr = actions.length > 0 ? `v.pipe(${partialBase},${actions.join(",")})` : partialBase;
|
|
284
|
-
const hasInheritedName = Object.keys(
|
|
310
|
+
const hasInheritedName = Object.keys(properties).some(isObjectPrototypeProperty);
|
|
285
311
|
return isStringWireLocation(options?.paramIn) && hasInheritedName ? `v.pipe(v.unknown(),v.transform(${ownProperties("input")}),${objectExpr})` : objectExpr;
|
|
286
312
|
}
|
|
287
313
|
//#endregion
|
|
@@ -399,7 +425,28 @@ function stringbool(errorArg) {
|
|
|
399
425
|
return `v.pipe(${stringboolItems(errorArg).join(",")})`;
|
|
400
426
|
}
|
|
401
427
|
function elementMessageWrap(inner, msg) {
|
|
402
|
-
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)}})}`;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
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.
|
|
439
|
+
*/
|
|
440
|
+
function objectKeysCheck(inner, schema, rootName, isValibot, options) {
|
|
441
|
+
const patterns = Object.entries(schema.patternProperties ?? {});
|
|
442
|
+
const unevaluated = schema.unevaluatedProperties;
|
|
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("");
|
|
448
|
+
const message = schema["x-unevaluatedProperties-message"];
|
|
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})`;
|
|
403
450
|
}
|
|
404
451
|
/**
|
|
405
452
|
* Generate Valibot schema code from JSON Schema.
|
|
@@ -416,6 +463,10 @@ function valibot(schema, rootName = DEFAULT_ROOT_NAME, isValibot = false, option
|
|
|
416
463
|
}
|
|
417
464
|
return node(schema, rootName, isValibot, options);
|
|
418
465
|
}
|
|
466
|
+
/** A keyword-only `allOf` member: the keywords apply when the value has their type. */
|
|
467
|
+
function keywordConstraint(schema) {
|
|
468
|
+
return `v.pipe(v.any(),v.check((input) => ${constraintPredicate(schema, "input")}${valibotErrorPart(constraintMessage(schema))}))`;
|
|
469
|
+
}
|
|
419
470
|
function node(schema, rootName, isValibot, options) {
|
|
420
471
|
const isStringWireParam = isStringWireLocation(options?.paramIn);
|
|
421
472
|
const isWireCoerced = isStringWireParam && schema["x-coerce"] !== false;
|
|
@@ -429,14 +480,19 @@ function node(schema, rootName, isValibot, options) {
|
|
|
429
480
|
};
|
|
430
481
|
const valibotWrap$1 = (valibotStr, s) => valibotWrap(valibotStr, s, {
|
|
431
482
|
...codeExtOpts,
|
|
432
|
-
...wireOptions(s)
|
|
483
|
+
...wireOptions(s),
|
|
484
|
+
...options?.definitions !== void 0 && { definitions: options.definitions }
|
|
433
485
|
});
|
|
434
486
|
const readonly = (v) => options?.readonly ? `v.pipe(${v},v.readonly())` : v;
|
|
435
487
|
const wireArray = (v) => isStringWireParam ? preprocess([wireArrayOnce("input")], v) : v;
|
|
436
488
|
const literalInput = (values) => {
|
|
437
489
|
if (values.every((v) => typeof v === "number")) {
|
|
438
490
|
if (isInt64(schema)) return int64Input(isWireCoerced);
|
|
439
|
-
if (isWireCoerced) return [
|
|
491
|
+
if (isWireCoerced) return [
|
|
492
|
+
"v.string()",
|
|
493
|
+
`v.regex(${wireNumericKind(schema, values) === "integer" ? integerWirePattern() : numberWirePattern()})`,
|
|
494
|
+
"v.transform((input)=>Number(input))"
|
|
495
|
+
];
|
|
440
496
|
}
|
|
441
497
|
if (isWireCoerced && values.every((v) => typeof v === "boolean")) return stringboolItems("");
|
|
442
498
|
};
|
|
@@ -459,11 +515,18 @@ function node(schema, rootName, isValibot, options) {
|
|
|
459
515
|
}, rootName, isValibot, options);
|
|
460
516
|
if (schema.oneOf) {
|
|
461
517
|
if (schema.oneOf.length === 0) return valibotWrap$1("v.any()", schema);
|
|
462
|
-
const schemas = schema.oneOf.map((s) => valibot(s, rootName, isValibot, options));
|
|
463
|
-
const oneOfMessage = schema["x-oneOf-message"];
|
|
464
|
-
const errorPart = valibotErrorPart(oneOfMessage);
|
|
465
518
|
const discriminator = schema.discriminator?.propertyName;
|
|
466
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);
|
|
467
530
|
return valibotWrap$1(discriminator && !hasRefOrAllOf ? `v.variant('${discriminator}',[${schemas.join(",")}]${errorPart})` : `v.union([${schemas.join(",")}]${errorPart})`, schema);
|
|
468
531
|
}
|
|
469
532
|
if (schema.anyOf) {
|
|
@@ -477,19 +540,19 @@ function node(schema, rootName, isValibot, options) {
|
|
|
477
540
|
if (schema.allOf.length === 0) return valibotWrap$1("v.any()", schema);
|
|
478
541
|
const nullable = isNullable(schema) || schema.allOf.some(isNullTypeMember);
|
|
479
542
|
const defaultValue = schema.allOf.find(isDefaultOnlyMember)?.default;
|
|
480
|
-
const schemas = schema.allOf.filter((s) => !isShapelessMember(s)).map((s) => valibot(s, rootName, isValibot, options));
|
|
543
|
+
const schemas = foldAllOfMembers(schema.allOf.filter((s) => !isShapelessMember(s)), isWireCoerced).map((s) => isKeywordOnlyMember(s) ? keywordConstraint(s) : valibot(s, rootName, isValibot, options));
|
|
481
544
|
if (schemas.length === 0) return valibotWrap$1("v.any()", {
|
|
482
545
|
...schema,
|
|
483
546
|
nullable
|
|
484
547
|
});
|
|
485
548
|
const intersected = schemas.length === 1 ? schemas[0] : `v.intersect([${schemas.join(",")}])`;
|
|
486
549
|
const allOfMessage = schema["x-allOf-message"];
|
|
487
|
-
const
|
|
550
|
+
const checked = objectKeysCheck(allOfMessage ? (() => {
|
|
488
551
|
const msgExpr = issueMessageExpression(allOfMessage);
|
|
489
|
-
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})}}}))`;
|
|
490
|
-
})() : intersected;
|
|
491
|
-
if (defaultValue !== void 0) return `v.optional(${nullable ? `v.nullable(${
|
|
492
|
-
return valibotWrap$1(
|
|
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})`;
|
|
553
|
+
})() : intersected, schema, rootName, isValibot, options);
|
|
554
|
+
if (defaultValue !== void 0) return `v.optional(${nullable ? `v.nullable(${checked})` : checked},${jsLiteral(defaultValue)})`;
|
|
555
|
+
return valibotWrap$1(checked, {
|
|
493
556
|
...schema,
|
|
494
557
|
nullable
|
|
495
558
|
});
|
|
@@ -500,9 +563,10 @@ function node(schema, rootName, isValibot, options) {
|
|
|
500
563
|
const notMessage = schema["x-not-message"];
|
|
501
564
|
const errorPart = valibotErrorPart(notMessage);
|
|
502
565
|
const predicate = (() => {
|
|
503
|
-
const
|
|
566
|
+
const bigint = isBigintFormat(withoutNot);
|
|
567
|
+
const shared = notPredicate(inner, "input", "input", bigint);
|
|
504
568
|
if (shared !== void 0) return shared;
|
|
505
|
-
if (Array.isArray(inner.enum)) return `(input) => !${
|
|
569
|
+
if (Array.isArray(inner.enum)) return `(input) => !${valueListLiteral(inner.enum, bigint)}.some((item) => item === input)`;
|
|
506
570
|
return `(input) => !v.safeParse(${valibot(inner, rootName, isValibot, options)},input).success`;
|
|
507
571
|
})();
|
|
508
572
|
if (withoutNot.type !== void 0) {
|
|
@@ -621,6 +685,7 @@ function node(schema, rootName, isValibot, options) {
|
|
|
621
685
|
return valibotWrap$1("v.date()", schema);
|
|
622
686
|
}
|
|
623
687
|
if (types.length === 1 && types[0] === "null") return valibotWrap$1("v.null()", schema);
|
|
688
|
+
if (typeof schema.additionalProperties === "object") return readonly(valibotWrap$1(object(schema, rootName, isValibot, options), schema));
|
|
624
689
|
return valibotWrap$1("v.any()", schema);
|
|
625
690
|
}
|
|
626
691
|
//#endregion
|
|
@@ -639,12 +704,18 @@ function annotation(name) {
|
|
|
639
704
|
* A whole JSON Schema document as a Valibot module: imports, `$defs` in dependency
|
|
640
705
|
* order, the root export, and the inferred output type.
|
|
641
706
|
*/
|
|
642
|
-
function schemaToValibot(
|
|
707
|
+
function schemaToValibot(input, options) {
|
|
708
|
+
const schema = withPolymorphicBases(hoistNestedRefs(input));
|
|
643
709
|
const exportType = options?.exportType ?? true;
|
|
644
|
-
const
|
|
645
|
-
const codeExtensionsPresent =
|
|
646
|
-
const toName = schemaNamer(
|
|
710
|
+
const baseOptions = emitOptionsOf(options);
|
|
711
|
+
const codeExtensionsPresent = baseOptions.unsafeCodeExtensions === true && findCodeExtensionKeysInSchema(schema).length > 0;
|
|
712
|
+
const toName = schemaNamer(baseOptions.openapi);
|
|
647
713
|
const plan = planDocument(schema, rootNameOf(schema, toName));
|
|
714
|
+
const definitions = definitionsOf(baseOptions, plan.definitions);
|
|
715
|
+
const emitOptions = definitions === void 0 ? baseOptions : {
|
|
716
|
+
...baseOptions,
|
|
717
|
+
definitions
|
|
718
|
+
};
|
|
648
719
|
const { rootName } = plan;
|
|
649
720
|
const needsTypeDef = plan.hasDefinitions || hasRootSelfReference(schema);
|
|
650
721
|
const typeDefsCode = needsTypeDef ? [`type _${rootName} = ${type(plan.root, rootName)}`, renderDefinitions(plan, toName, (def, name) => `type _${name} = ${type(def, name)}`)].filter(Boolean).join("\n\n") : "";
|
package/dist/valibot.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { r as JSONSchema } from "./index-
|
|
2
|
-
import { n as GenerateOptions } from "./index-
|
|
1
|
+
import { r as JSONSchema } from "./index-G7UqNQ4w.js";
|
|
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
|
|
6
6
|
* order, the root export, and the inferred output type.
|
|
7
7
|
*/
|
|
8
|
-
export declare function schemaToValibot(
|
|
8
|
+
export declare function schemaToValibot(input: JSONSchema, options?: GenerateOptions): string;
|
|
9
9
|
//#endregion
|
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
|
-
import { c as normalizeTypes, s as makeSafeKey } from "./utils-
|
|
2
|
-
import {
|
|
1
|
+
import { c as normalizeTypes, s as makeSafeKey } from "./utils-Bky98UmP.js";
|
|
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
|
-
import { r as JSONSchema } from "./index-
|
|
2
|
-
import { n as GenerateOptions } from "./index-
|
|
1
|
+
import { r as JSONSchema } from "./index-G7UqNQ4w.js";
|
|
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";
|