@es-joy/jsoe 0.27.0 → 0.28.1
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/CHANGES.md +37 -0
- package/README.md +3 -1
- package/badges/coverage-badge.svg +1 -1
- package/badges/tests-badge.svg +1 -0
- package/dist/formats/schema.d.ts +11 -0
- package/dist/formats/schema.d.ts.map +1 -1
- package/dist/formats/structuredCloning.d.ts.map +1 -1
- package/dist/fundamentalTypes/arrayType.d.ts.map +1 -1
- package/dist/fundamentalTypes/stringType.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/typeChoices.d.ts +32 -2
- package/dist/typeChoices.d.ts.map +1 -1
- package/dist/types.d.ts +8 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/rawTypesonEditor.d.ts +110 -0
- package/dist/utils/rawTypesonEditor.d.ts.map +1 -0
- package/dist/vendor-imports.d.ts +4 -0
- package/docs/proposals/raw-typeson-edit-view.md +575 -0
- package/mmr.json +6 -0
- package/package.json +34 -12
- package/pnpm-workspace.yaml +32 -30
- package/src/formats/schema.js +10 -15
- package/src/formats/structuredCloning.js +24 -17
- package/src/fundamentalTypes/arrayType.js +119 -23
- package/src/fundamentalTypes/blobType.js +16 -16
- package/src/fundamentalTypes/fileType.js +13 -13
- package/src/fundamentalTypes/regexpType.js +1 -1
- package/src/fundamentalTypes/stringType.js +5 -0
- package/src/jsoe.css +12 -0
- package/src/subTypes/blobHTMLType.js +1 -1
- package/src/superTypes/dommatrixType.js +1 -1
- package/src/superTypes/errorsSpecialType.js +1 -1
- package/src/typeChoices.js +37 -10
- package/src/types.js +13 -8
- package/src/utils/media.js +3 -3
- package/src/utils/rawTypesonEditor.js +669 -0
- package/src/vendor-imports.js +12 -0
- package/tsconfig.json +1 -1
- package/typings/json-6.d.ts +12 -0
- package/vendor/@codemirror/autocomplete/dist/index.js +2125 -0
- package/vendor/@codemirror/commands/dist/index.js +1826 -0
- package/vendor/@codemirror/lang-javascript/dist/index.js +513 -0
- package/vendor/@codemirror/language/dist/index.js +2693 -0
- package/vendor/@codemirror/lint/dist/index.js +956 -0
- package/vendor/@codemirror/search/dist/index.js +1238 -0
- package/vendor/@codemirror/state/dist/index.js +3947 -0
- package/vendor/@codemirror/view/dist/index.js +11867 -0
- package/vendor/@lezer/common/dist/index.js +2202 -0
- package/vendor/@lezer/highlight/dist/index.js +927 -0
- package/vendor/@lezer/javascript/dist/index.js +192 -0
- package/vendor/@lezer/lr/dist/index.js +1889 -0
- package/vendor/@marijn/find-cluster-break/src/index.js +87 -0
- package/vendor/codemirror/dist/index.js +96 -0
- package/vendor/crelt/index.js +28 -0
- package/vendor/jamilih/dist/jml.mjs +898 -25
- package/vendor/json-6/dist/index.mjs +1783 -0
- package/vendor/style-mod/src/style-mod.js +172 -0
- package/vendor/w3c-keyname/index.js +119 -0
- package/vendor/zod/classic/checks.d.ts +1 -1
- package/vendor/zod/classic/checks.js +1 -1
- package/vendor/zod/classic/schemas.d.ts +2 -6
- package/vendor/zod/classic/schemas.js +9 -13
- package/vendor/zod/core/api.d.ts +8 -4
- package/vendor/zod/core/api.js +11 -23
- package/vendor/zod/core/checks.d.ts +16 -0
- package/vendor/zod/core/checks.js +31 -0
- package/vendor/zod/core/compile.js +20 -24
- package/vendor/zod/core/core.js +1 -1
- package/vendor/zod/core/json-schema-processors.d.ts +0 -1
- package/vendor/zod/core/json-schema-processors.js +8 -43
- package/vendor/zod/core/memoizer.js +2 -5
- package/vendor/zod/core/regexes.d.ts +1 -0
- package/vendor/zod/core/regexes.js +2 -0
- package/vendor/zod/core/schemas.d.ts +8 -23
- package/vendor/zod/core/schemas.js +39 -80
- package/vendor/zod/core/to-json-schema.d.ts +0 -3
- package/vendor/zod/core/to-json-schema.js +1 -1
- package/vendor/zod/core/util.js +0 -4
- package/vendor/zod/core/versions.js +1 -1
- package/vendor/zod/core/visit.js +0 -12
- package/vendor/zod/locales/ar.js +1 -0
- package/vendor/zod/locales/az.js +1 -0
- package/vendor/zod/locales/be.js +1 -0
- package/vendor/zod/locales/bg.js +1 -0
- package/vendor/zod/locales/bn.js +1 -0
- package/vendor/zod/locales/ca.js +1 -0
- package/vendor/zod/locales/ckb.js +1 -0
- package/vendor/zod/locales/cs.js +1 -0
- package/vendor/zod/locales/da.js +1 -0
- package/vendor/zod/locales/de.js +1 -0
- package/vendor/zod/locales/el.js +1 -0
- package/vendor/zod/locales/en.js +1 -0
- package/vendor/zod/locales/eo.js +1 -0
- package/vendor/zod/locales/es.js +1 -0
- package/vendor/zod/locales/fa.js +1 -0
- package/vendor/zod/locales/fi.js +1 -0
- package/vendor/zod/locales/fr-CA.js +1 -0
- package/vendor/zod/locales/fr.js +1 -0
- package/vendor/zod/locales/gu.js +1 -0
- package/vendor/zod/locales/he.js +1 -0
- package/vendor/zod/locales/hi.js +1 -0
- package/vendor/zod/locales/hr.js +1 -0
- package/vendor/zod/locales/hu.js +1 -0
- package/vendor/zod/locales/hy.js +1 -0
- package/vendor/zod/locales/id.js +1 -0
- package/vendor/zod/locales/is.js +1 -0
- package/vendor/zod/locales/it.js +1 -0
- package/vendor/zod/locales/ja.js +1 -0
- package/vendor/zod/locales/ka.js +1 -0
- package/vendor/zod/locales/km.js +1 -0
- package/vendor/zod/locales/kn.js +1 -0
- package/vendor/zod/locales/ko.js +1 -0
- package/vendor/zod/locales/lt.js +1 -0
- package/vendor/zod/locales/mk.js +1 -0
- package/vendor/zod/locales/ms.js +1 -0
- package/vendor/zod/locales/ne.js +1 -0
- package/vendor/zod/locales/nl.js +1 -0
- package/vendor/zod/locales/nn.js +1 -0
- package/vendor/zod/locales/no.js +1 -0
- package/vendor/zod/locales/ota.js +1 -0
- package/vendor/zod/locales/pl.js +1 -0
- package/vendor/zod/locales/ps.js +1 -0
- package/vendor/zod/locales/pt-BR.js +1 -0
- package/vendor/zod/locales/pt.js +1 -0
- package/vendor/zod/locales/ro.js +1 -0
- package/vendor/zod/locales/ru.js +1 -0
- package/vendor/zod/locales/sk.js +1 -0
- package/vendor/zod/locales/sl.js +1 -0
- package/vendor/zod/locales/sv.js +1 -0
- package/vendor/zod/locales/ta.js +1 -0
- package/vendor/zod/locales/tg.js +1 -0
- package/vendor/zod/locales/th.js +1 -0
- package/vendor/zod/locales/tk.js +1 -0
- package/vendor/zod/locales/tr.js +1 -0
- package/vendor/zod/locales/uk.js +1 -0
- package/vendor/zod/locales/ur.js +1 -0
- package/vendor/zod/locales/uz.js +1 -0
- package/vendor/zod/locales/vi.js +1 -0
- package/vendor/zod/locales/yo.js +1 -0
- package/vendor/zod/locales/zh-CN.js +1 -0
- package/vendor/zod/locales/zh-TW.js +1 -0
- package/vendor/zod/mini/checks.d.ts +1 -1
- package/vendor/zod/mini/checks.js +1 -1
- package/vendor/zod/mini/schemas.d.ts +2 -5
- package/vendor/zod/mini/schemas.js +9 -11
- package/vendor/zodexy/dist/esm/index.js +4 -33
- package/vendor/zodexy/dist/schema.zodexy.json +1 -17
|
@@ -2,7 +2,7 @@ import { $ZodAsyncError } from "./core.js";
|
|
|
2
2
|
import { Doc } from "./doc.js";
|
|
3
3
|
import { isBackEdge, isRecursiveSchema } from "./memoizer.js";
|
|
4
4
|
import * as regexes from "./regexes.js";
|
|
5
|
-
import { isValidBase64, isValidBase64URL, isValidCIDRv6, isValidCreditCard, isValidIBAN, isValidIPv6, isValidJWT, mergeValues,
|
|
5
|
+
import { isValidBase64, isValidBase64URL, isValidCIDRv6, isValidCreditCard, isValidIBAN, isValidIPv6, isValidJWT, mergeValues, stripTabAndNewline, urlHostnameOk, urlProtocolOk, validateURL, } from "./schemas.js";
|
|
6
6
|
import * as util from "./util.js";
|
|
7
7
|
/** @internal Sentinel the compiled fast path returns when validation fails. */
|
|
8
8
|
export const INVALID = Symbol.for("zod.compile.invalid");
|
|
@@ -330,7 +330,7 @@ function generateChecks(doc, ctx, schema, accessor) {
|
|
|
330
330
|
generatePropertyCheck(doc, ctx, def, currentAccessor);
|
|
331
331
|
break;
|
|
332
332
|
case "properties":
|
|
333
|
-
generatePropertiesChecks(doc, ctx, def, currentAccessor
|
|
333
|
+
generatePropertiesChecks(doc, ctx, def, currentAccessor);
|
|
334
334
|
break;
|
|
335
335
|
case "overwrite": {
|
|
336
336
|
// Overwrite transforms the value - create new variable for transformed result
|
|
@@ -458,15 +458,13 @@ function generateMimeTypeCheck(doc, ctx, def, accessor) {
|
|
|
458
458
|
}
|
|
459
459
|
}
|
|
460
460
|
// asserts each named property in place; children compile assert-only because z.properties never rebuilds its input
|
|
461
|
-
function generatePropertiesChecks(doc, ctx, def, accessor
|
|
462
|
-
// a custom `when` gates the assertion at runtime; inside a union a wrongly-run branch is absorbed as a branch failure rather than falling back, so refuse at codegen
|
|
461
|
+
function generatePropertiesChecks(doc, ctx, def, accessor) {
|
|
462
|
+
// a custom `when` gates the assertion at runtime; inside a union a wrongly-run branch is absorbed as a branch failure rather than falling back, so refuse at codegen
|
|
463
463
|
if (def.when) {
|
|
464
464
|
throw new ZodCompileUnsupportedError(`check with a custom "when" condition`);
|
|
465
465
|
}
|
|
466
|
-
// matches the runtime gate
|
|
467
|
-
doc.write(
|
|
468
|
-
? `if (${accessor} === null || (typeof ${accessor} !== "object" && typeof ${accessor} !== "function")) return INVALID;`
|
|
469
|
-
: `if (${accessor} == null) return INVALID;`);
|
|
466
|
+
// matches the runtime gate: the base schema already typed the value, so only a nullish one is rejected
|
|
467
|
+
doc.write(`if (${accessor} == null) return INVALID;`);
|
|
470
468
|
const shape = def.shape;
|
|
471
469
|
for (const key of Reflect.ownKeys(shape)) {
|
|
472
470
|
// a symbol has no source literal, so it is hoisted as a constant
|
|
@@ -579,8 +577,7 @@ const PATTERN_IS_COMPLETE = new Set([
|
|
|
579
577
|
"uuid",
|
|
580
578
|
"xid",
|
|
581
579
|
]);
|
|
582
|
-
|
|
583
|
-
function generateStringFormatCheck(doc, ctx, def, accessor) {
|
|
580
|
+
function generateStringFormatCheck(doc, ctx, def, accessor, needsValue = true) {
|
|
584
581
|
// Some string formats do runtime validation beyond their advertised pattern. For cheap pure utility checks, hoist the runtime function and call it so the fast path stays correct without cloning the utility logic into codegen.
|
|
585
582
|
const fmt = def.format;
|
|
586
583
|
if (fmt === "base64") {
|
|
@@ -626,7 +623,7 @@ function generateStringFormatCheck(doc, ctx, def, accessor) {
|
|
|
626
623
|
formatDef.hostname !== undefined ||
|
|
627
624
|
formatDef.protocol !== undefined) {
|
|
628
625
|
// Same three predicates the runtime calls, in the same order, so there is no second URL implementation to drift. Which options exist is known now, so the calls the runtime makes conditionally are emitted conditionally instead.
|
|
629
|
-
const parseConst = addConstant(ctx,
|
|
626
|
+
const parseConst = addConstant(ctx, validateURL);
|
|
630
627
|
const defConst = addConstant(ctx, def);
|
|
631
628
|
const trimVar = newVar(ctx);
|
|
632
629
|
const urlVar = newVar(ctx);
|
|
@@ -641,6 +638,8 @@ function generateStringFormatCheck(doc, ctx, def, accessor) {
|
|
|
641
638
|
const protocolConst = addConstant(ctx, urlProtocolOk);
|
|
642
639
|
doc.write(`if (!${protocolConst}(${urlVar}, ${defConst}.protocol)) return INVALID;`);
|
|
643
640
|
}
|
|
641
|
+
if (!needsValue)
|
|
642
|
+
return null;
|
|
644
643
|
const outputVar = newVar(ctx);
|
|
645
644
|
const outputExpr = formatDef.normalize ? `${urlVar}.href` : `${addConstant(ctx, stripTabAndNewline)}(${trimVar})`;
|
|
646
645
|
doc.write(`const ${outputVar} = ${outputExpr};`);
|
|
@@ -705,7 +704,7 @@ function generateCheck(doc, ctx, schema, accessor, needsValue = true) {
|
|
|
705
704
|
let typeAccessor;
|
|
706
705
|
switch (type) {
|
|
707
706
|
case "string":
|
|
708
|
-
typeAccessor = generateStringCheck(doc, ctx, schema, accessor);
|
|
707
|
+
typeAccessor = generateStringCheck(doc, ctx, schema, accessor, buildsValue);
|
|
709
708
|
break;
|
|
710
709
|
case "number":
|
|
711
710
|
typeAccessor = generateNumberCheck(doc, schema, accessor);
|
|
@@ -817,10 +816,6 @@ function generateCheck(doc, ctx, schema, accessor, needsValue = true) {
|
|
|
817
816
|
case "custom":
|
|
818
817
|
typeAccessor = generateCustomCheck(doc, ctx, schema, accessor);
|
|
819
818
|
break;
|
|
820
|
-
case "properties":
|
|
821
|
-
generatePropertiesChecks(doc, ctx, schema._zod.def, accessor, true);
|
|
822
|
-
typeAccessor = accessor;
|
|
823
|
-
break;
|
|
824
819
|
case "transform":
|
|
825
820
|
typeAccessor = generateTransformCheck(doc, ctx, schema, accessor);
|
|
826
821
|
break;
|
|
@@ -838,13 +833,13 @@ function generateCheck(doc, ctx, schema, accessor, needsValue = true) {
|
|
|
838
833
|
// Generate checks after the type-specific validation (may transform value)
|
|
839
834
|
return generateChecks(doc, ctx, schema, typeAccessor);
|
|
840
835
|
}
|
|
841
|
-
function generateStringCheck(doc, ctx, schema, accessor) {
|
|
836
|
+
function generateStringCheck(doc, ctx, schema, accessor, needsValue = true) {
|
|
842
837
|
doc.write(`if (typeof ${accessor} !== "string") return INVALID;`);
|
|
843
838
|
// z.email() carries its format on the def, z.string().email() in def.checks; both route here so the format table has no second copy to drift from.
|
|
844
839
|
const def = schema._zod.def;
|
|
845
840
|
if (def.format === undefined)
|
|
846
841
|
return accessor;
|
|
847
|
-
return generateStringFormatCheck(doc, ctx, def, accessor);
|
|
842
|
+
return generateStringFormatCheck(doc, ctx, def, accessor, needsValue);
|
|
848
843
|
}
|
|
849
844
|
function generateNumberCheck(doc, schema, accessor) {
|
|
850
845
|
// Runtime z.number() rejects NaN and ±Infinity. Number.isFinite covers both.
|
|
@@ -979,9 +974,9 @@ function generateObjectCheck(doc, ctx, schema, accessor, buildsValue = true) {
|
|
|
979
974
|
}
|
|
980
975
|
}
|
|
981
976
|
// else: strip mode (no catchall) - unknown keys ignored, only include known keys
|
|
982
|
-
//
|
|
977
|
+
// defaulted required outputs keep their keys even when undefined
|
|
983
978
|
const outputVar = newVar(ctx);
|
|
984
|
-
const hasConditionalKeys = allKeys.some((k) =>
|
|
979
|
+
const hasConditionalKeys = allKeys.some((k) => mayOmitUndefined(propShape[k]) || dropsWhenAbsent(propShape[k]));
|
|
985
980
|
// Assert mode: every declared key is validated above, so the output literal and the unknown-key copy are pure waste. A `never` catchall already emitted its rejection loop; a schema catchall still has to validate the values it would otherwise have stored.
|
|
986
981
|
if (!buildsValue) {
|
|
987
982
|
if (unknownKeysMode === "schema") {
|
|
@@ -1011,7 +1006,7 @@ function generateObjectCheck(doc, ctx, schema, accessor, buildsValue = true) {
|
|
|
1011
1006
|
if (dropsWhenAbsent(propShape[k])) {
|
|
1012
1007
|
doc.write(`if (${kx} in ${accessor}) ${outputVar}[${kx}] = ${out};`);
|
|
1013
1008
|
}
|
|
1014
|
-
else if (
|
|
1009
|
+
else if (mayOmitUndefined(propShape[k])) {
|
|
1015
1010
|
doc.write(`if (${out} !== undefined || ${kx} in ${accessor}) ${outputVar}[${kx}] = ${out};`);
|
|
1016
1011
|
}
|
|
1017
1012
|
else {
|
|
@@ -1154,9 +1149,10 @@ function fastPathAcceptsAbsence(schema) {
|
|
|
1154
1149
|
function dropsWhenAbsent(schema) {
|
|
1155
1150
|
return schema._zod.optin === "optional" && schema._zod.optout === "optional";
|
|
1156
1151
|
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1152
|
+
function mayOmitUndefined(schema) {
|
|
1153
|
+
return (schema._zod.optin !== "defaulted" || schema._zod.optout === "optional") && mayOutputUndefined(schema);
|
|
1154
|
+
}
|
|
1155
|
+
// whether a schema's success-path output can be undefined
|
|
1160
1156
|
function mayOutputUndefined(schema) {
|
|
1161
1157
|
const def = schema._zod.def;
|
|
1162
1158
|
switch (def.type) {
|
package/vendor/zod/core/core.js
CHANGED
|
@@ -41,7 +41,6 @@ export declare const mapProcessor: Processor<schemas.$ZodMap>;
|
|
|
41
41
|
export declare const setProcessor: Processor<schemas.$ZodSet>;
|
|
42
42
|
export declare const arrayProcessor: Processor<schemas.$ZodArray>;
|
|
43
43
|
export declare const objectProcessor: Processor<schemas.$ZodObject>;
|
|
44
|
-
export declare const propertiesProcessor: Processor<schemas.$ZodProperties>;
|
|
45
44
|
export declare const unionProcessor: Processor<schemas.$ZodUnion>;
|
|
46
45
|
export declare const intersectionProcessor: Processor<schemas.$ZodIntersection>;
|
|
47
46
|
export declare const tupleProcessor: Processor<schemas.$ZodTuple>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as regexes from "./regexes.js";
|
|
2
2
|
import { base64Charset, base64urlCharset } from "./schemas.js";
|
|
3
|
-
import { extractDefs, finalize, handleUnrepresentable, initializeContext,
|
|
3
|
+
import { extractDefs, finalize, handleUnrepresentable, initializeContext, processSchema, } from "./to-json-schema.js";
|
|
4
4
|
import { BIGINT_FORMAT_RANGES, NUMBER_FORMAT_RANGES, assignProp, getEnumValues } from "./util.js";
|
|
5
5
|
const narrowMin = (agg, key, value) => {
|
|
6
6
|
if (agg[key] === undefined || value > agg[key])
|
|
@@ -395,18 +395,15 @@ export const objectProcessor = (schema, ctx, _json, params) => {
|
|
|
395
395
|
}));
|
|
396
396
|
}
|
|
397
397
|
// required keys
|
|
398
|
-
const
|
|
399
|
-
const
|
|
398
|
+
const requiredKeys = [];
|
|
399
|
+
for (const key of Object.keys(shape)) {
|
|
400
400
|
const field = def.shape[key];
|
|
401
|
-
if (ctx.io === "input") {
|
|
402
|
-
|
|
401
|
+
if (ctx.io === "input" ? inputOptin(field) === undefined : field._zod.optout === undefined) {
|
|
402
|
+
requiredKeys.push(key);
|
|
403
403
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
}));
|
|
408
|
-
if (requiredKeys.size > 0) {
|
|
409
|
-
json.required = Array.from(requiredKeys);
|
|
404
|
+
}
|
|
405
|
+
if (requiredKeys.length > 0) {
|
|
406
|
+
json.required = requiredKeys;
|
|
410
407
|
}
|
|
411
408
|
// catchall
|
|
412
409
|
if (def.catchall?._zod.def.type === "never") {
|
|
@@ -425,37 +422,6 @@ export const objectProcessor = (schema, ctx, _json, params) => {
|
|
|
425
422
|
});
|
|
426
423
|
}
|
|
427
424
|
};
|
|
428
|
-
// asserts named properties in place and passes everything else through, so no additionalProperties constraint is emitted
|
|
429
|
-
export const propertiesProcessor = (schema, ctx, _json, params) => {
|
|
430
|
-
const json = _json;
|
|
431
|
-
const def = schema._zod.def;
|
|
432
|
-
// dropping a symbol key silently would emit a schema that asserts less than this one does
|
|
433
|
-
if (Object.getOwnPropertySymbols(def.shape).length &&
|
|
434
|
-
handleUnrepresentable(schema, ctx, json, params, "Symbol keys cannot be represented in JSON Schema")) {
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
|
-
// the parsed value is the input, so an output-mode emission would describe a transformed value this schema never returns
|
|
438
|
-
if (ctx.io === "output") {
|
|
439
|
-
for (const key in def.shape) {
|
|
440
|
-
if (isTransforming(def.shape[key]) &&
|
|
441
|
-
handleUnrepresentable(schema, ctx, json, params, `z.properties() returns its input, so the output of a transforming schema at key "${key}" cannot be represented in JSON Schema`)) {
|
|
442
|
-
return;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
json.type = "object";
|
|
447
|
-
json.properties = {};
|
|
448
|
-
for (const key in def.shape) {
|
|
449
|
-
assignProp(json.properties, key, processSchema(def.shape[key], ctx, {
|
|
450
|
-
...params,
|
|
451
|
-
path: [...params.path, "properties", key],
|
|
452
|
-
}));
|
|
453
|
-
}
|
|
454
|
-
// input-side optionality in both modes: the parsed value is the input, so a defaulted key that stays absent must not be required of the output either
|
|
455
|
-
const required = Object.keys(def.shape).filter((key) => inputOptin(def.shape[key]) === undefined);
|
|
456
|
-
if (required.length > 0)
|
|
457
|
-
json.required = required;
|
|
458
|
-
};
|
|
459
425
|
export const unionProcessor = (schema, ctx, json, params) => {
|
|
460
426
|
const def = schema._zod.def;
|
|
461
427
|
// Exclusive unions (inclusive === false) use oneOf (exactly one match) instead of anyOf (one or more matches). This includes both z.xor() and discriminated unions
|
|
@@ -815,7 +781,6 @@ export const allProcessors = {
|
|
|
815
781
|
file: fileProcessor,
|
|
816
782
|
success: successProcessor,
|
|
817
783
|
custom: customProcessor,
|
|
818
|
-
properties: propertiesProcessor,
|
|
819
784
|
function: functionProcessor,
|
|
820
785
|
transform: transformProcessor,
|
|
821
786
|
map: mapProcessor,
|
|
@@ -8,9 +8,9 @@ export class $ZodCyclicError extends Error {
|
|
|
8
8
|
/** Keyed off the context object every schema in one parse call already shares. */
|
|
9
9
|
const STATE = "~memo";
|
|
10
10
|
const NO_ISSUES = [];
|
|
11
|
-
// a value a cycle can close through
|
|
11
|
+
// a value a cycle can close through
|
|
12
12
|
function isRef(value) {
|
|
13
|
-
return value !== null &&
|
|
13
|
+
return value !== null && typeof value === "object";
|
|
14
14
|
}
|
|
15
15
|
// Receivers prefix paths in place, so the cache and every hand-out need their own copies.
|
|
16
16
|
function cloneIssues(issues) {
|
|
@@ -67,9 +67,6 @@ function isRecursive(inst, stack, resolve) {
|
|
|
67
67
|
check(def.catchall);
|
|
68
68
|
break;
|
|
69
69
|
}
|
|
70
|
-
case "properties":
|
|
71
|
-
merge(shape(def.shape, false));
|
|
72
|
-
break;
|
|
73
70
|
case "array":
|
|
74
71
|
check(def.element);
|
|
75
72
|
break;
|
|
@@ -46,6 +46,7 @@ export declare const domain: RegExp;
|
|
|
46
46
|
export declare const httpProtocol: RegExp;
|
|
47
47
|
export declare const e164: RegExp;
|
|
48
48
|
export declare const creditCard: RegExp;
|
|
49
|
+
export declare const currencyCode: RegExp;
|
|
49
50
|
export declare const iban: RegExp;
|
|
50
51
|
export declare const date: RegExp;
|
|
51
52
|
export declare function time(args: {
|
|
@@ -66,6 +66,8 @@ export const httpProtocol = /^https?$/;
|
|
|
66
66
|
export const e164 = /^\+[1-9]\d{6,14}$/;
|
|
67
67
|
// Credit card shape: 12–19 digits, optionally separated by single spaces or single hyphens. ISO/IEC 7812 caps the PAN at 19 digits; 12 is the shortest issued length (Maestro).
|
|
68
68
|
export const creditCard = /^\d(?:[ -]?\d){11,18}$/;
|
|
69
|
+
// ISO 4217 alpha codes from the SIX list, regenerated by scripts/update-iso-4217.ts
|
|
70
|
+
export const currencyCode = /^(?:AED|AFN|ALL|AMD|AOA|ARS|AUD|AWG|AZN|BAM|BBD|BDT|BHD|BIF|BMD|BND|BOB|BOV|BRL|BSD|BTN|BWP|BYN|BZD|CAD|CDF|CHE|CHF|CHW|CLF|CLP|CNY|COP|COU|CRC|CUP|CVE|CZK|DJF|DKK|DOP|DZD|EGP|ERN|ETB|EUR|FJD|FKP|GBP|GEL|GHS|GIP|GMD|GNF|GTQ|GYD|HKD|HNL|HTG|HUF|IDR|ILS|INR|IQD|IRR|ISK|JMD|JOD|JPY|KES|KGS|KHR|KMF|KPW|KRW|KWD|KYD|KZT|LAK|LBP|LKR|LRD|LSL|LYD|MAD|MDL|MGA|MKD|MMK|MNT|MOP|MRU|MUR|MVR|MWK|MXN|MXV|MYR|MZN|NAD|NGN|NIO|NOK|NPR|NZD|OMR|PAB|PEN|PGK|PHP|PKR|PLN|PYG|QAR|RON|RSD|RUB|RWF|SAR|SBD|SCR|SDG|SEK|SGD|SHP|SLE|SOS|SRD|SSP|STN|SVC|SYP|SZL|THB|TJS|TMT|TND|TOP|TRY|TTD|TWD|TZS|UAH|UGX|USD|USN|UYI|UYU|UYW|UZS|VED|VES|VND|VUV|WST|XAD|XAF|XAG|XAU|XBA|XBB|XBC|XBD|XCD|XCG|XDR|XOF|XPD|XPF|XPT|XSU|XTS|XUA|XXX|YER|ZAR|ZMW|ZWG)$/;
|
|
69
71
|
// iban electronic format: 2-letter country, check digits 02-98 (the only values `98 - remainder` can produce), 11-30 bban characters
|
|
70
72
|
export const iban = /^[A-Z]{2}(?!00|01|99)\d{2}[A-Z0-9]{11,30}$/;
|
|
71
73
|
const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
|
|
@@ -41,7 +41,7 @@ export interface ParsePayload<T = unknown> {
|
|
|
41
41
|
}
|
|
42
42
|
export type CheckFn<T> = (input: ParsePayload<T>) => util.MaybeAsync<void>;
|
|
43
43
|
export interface $ZodTypeDef {
|
|
44
|
-
type: "string" | "number" | "int" | "boolean" | "bigint" | "symbol" | "null" | "undefined" | "void" | "never" | "any" | "unknown" | "date" | "object" | "record" | "file" | "array" | "tuple" | "union" | "intersection" | "map" | "set" | "enum" | "literal" | "nullable" | "optional" | "nonoptional" | "success" | "transform" | "default" | "prefault" | "catch" | "nan" | "pipe" | "readonly" | "template_literal" | "promise" | "lazy" | "function" | "custom"
|
|
44
|
+
type: "string" | "number" | "int" | "boolean" | "bigint" | "symbol" | "null" | "undefined" | "void" | "never" | "any" | "unknown" | "date" | "object" | "record" | "file" | "array" | "tuple" | "union" | "intersection" | "map" | "set" | "enum" | "literal" | "nullable" | "optional" | "nonoptional" | "success" | "transform" | "default" | "prefault" | "catch" | "nan" | "pipe" | "readonly" | "template_literal" | "promise" | "lazy" | "function" | "custom";
|
|
45
45
|
error?: errors.$ZodErrorMap<never> | undefined;
|
|
46
46
|
checks?: checks.$ZodCheck<never>[];
|
|
47
47
|
}
|
|
@@ -188,9 +188,11 @@ export interface $ZodURL extends $ZodType {
|
|
|
188
188
|
}
|
|
189
189
|
/** The `://` guard rejected the input before the URL constructor saw it. */
|
|
190
190
|
export declare const URL_BAD_FORMAT = 1;
|
|
191
|
-
/** The URL
|
|
191
|
+
/** The URL parser rejected the input. */
|
|
192
192
|
export declare const URL_UNPARSEABLE = 2;
|
|
193
|
-
|
|
193
|
+
export declare function canParseURL(input: string): boolean;
|
|
194
|
+
export declare function validateURL(trimmed: string, def: Pick<$ZodURLDef, "protocol" | "hostname" | "normalize">): URL | true | typeof URL_BAD_FORMAT | typeof URL_UNPARSEABLE;
|
|
195
|
+
/** Parses a URL while preserving the non-normalizing HTTP guard. */
|
|
194
196
|
export declare function parseURLObject(trimmed: string, def: Pick<$ZodURLDef, "protocol" | "normalize">): URL | typeof URL_BAD_FORMAT | typeof URL_UNPARSEABLE;
|
|
195
197
|
/** The URL parser deletes every ASCII tab, LF and CR from its input before it parses, so `new URL("https://exa\nmple.com")` reports on `example.com`. Applying the same deletion to the returned value closes the half of that divergence which can move the host; the parser's other rewrite, stripping C0 controls at the edges, cannot. */
|
|
196
198
|
export declare function stripTabAndNewline(value: string): string;
|
|
@@ -1010,7 +1012,7 @@ export interface $ZodPrefaultDef<T extends SomeType = $ZodType> extends $ZodType
|
|
|
1010
1012
|
/** The default value. May be a getter. */
|
|
1011
1013
|
defaultValue: core.input<T>;
|
|
1012
1014
|
}
|
|
1013
|
-
export interface $ZodPrefaultInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<
|
|
1015
|
+
export interface $ZodPrefaultInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<T>, core.input<T> | undefined> {
|
|
1014
1016
|
def: $ZodPrefaultDef<T>;
|
|
1015
1017
|
optin: "defaulted";
|
|
1016
1018
|
optout?: "optional" | undefined;
|
|
@@ -1267,22 +1269,5 @@ export interface $ZodCustom<O = unknown, I = unknown> extends $ZodType {
|
|
|
1267
1269
|
_zod: $ZodCustomInternals<O, I>;
|
|
1268
1270
|
}
|
|
1269
1271
|
export declare const $ZodCustom: core.$constructor<$ZodCustom>;
|
|
1270
|
-
export
|
|
1271
|
-
|
|
1272
|
-
check: "properties";
|
|
1273
|
-
shape: Shape;
|
|
1274
|
-
}
|
|
1275
|
-
export interface $ZodPropertiesInternals<Shape extends $ZodShape = $ZodShape> extends $ZodTypeInternals<$InferObjectInput<Shape, {}>, $InferObjectInput<Shape, {}>>, checks.$ZodCheckInternals<{
|
|
1276
|
-
-readonly [k in keyof Shape]: util.Widen<core.input<Shape[k]>>;
|
|
1277
|
-
}> {
|
|
1278
|
-
def: $ZodPropertiesDef<Shape>;
|
|
1279
|
-
isst: errors.$ZodIssueInvalidType;
|
|
1280
|
-
issc: errors.$ZodIssue;
|
|
1281
|
-
}
|
|
1282
|
-
export interface $ZodProperties<Shape extends $ZodShape = $ZodShape> extends $ZodType {
|
|
1283
|
-
_zod: $ZodPropertiesInternals<Shape>;
|
|
1284
|
-
[Symbol.iterator](): Iterator<this>;
|
|
1285
|
-
}
|
|
1286
|
-
export declare const $ZodProperties: core.$constructor<$ZodProperties>;
|
|
1287
|
-
export type $ZodTypes = $ZodString | $ZodNumber | $ZodBigInt | $ZodBoolean | $ZodDate | $ZodSymbol | $ZodUndefined | $ZodNullable | $ZodNull | $ZodAny | $ZodUnknown | $ZodNever | $ZodVoid | $ZodArray | $ZodObject | $ZodUnion | $ZodIntersection | $ZodTuple | $ZodRecord | $ZodMap | $ZodSet | $ZodLiteral | $ZodEnum | $ZodFunction | $ZodPromise | $ZodLazy | $ZodOptional | $ZodDefault | $ZodPrefault | $ZodTemplateLiteral | $ZodCustom | $ZodProperties | $ZodTransform | $ZodNonOptional | $ZodReadonly | $ZodNaN | $ZodPipe | $ZodSuccess | $ZodCatch | $ZodFile;
|
|
1288
|
-
export type $ZodStringFormatTypes = $ZodGUID | $ZodUUID | $ZodEmail | $ZodURL | $ZodEmoji | $ZodNanoID | $ZodCUID | $ZodCUID2 | $ZodULID | $ZodXID | $ZodKSUID | $ZodISODateTime | $ZodISODate | $ZodISOTime | $ZodISODuration | $ZodIPv4 | $ZodIPv6 | $ZodMAC | $ZodCIDRv4 | $ZodCIDRv6 | $ZodBase64 | $ZodBase64URL | $ZodE164 | $ZodCreditCard | $ZodIBAN | $ZodJWT | $ZodCustomStringFormat<"hex"> | $ZodCustomStringFormat<util.HashFormat> | $ZodCustomStringFormat<"hostname">;
|
|
1272
|
+
export type $ZodTypes = $ZodString | $ZodNumber | $ZodBigInt | $ZodBoolean | $ZodDate | $ZodSymbol | $ZodUndefined | $ZodNullable | $ZodNull | $ZodAny | $ZodUnknown | $ZodNever | $ZodVoid | $ZodArray | $ZodObject | $ZodUnion | $ZodIntersection | $ZodTuple | $ZodRecord | $ZodMap | $ZodSet | $ZodLiteral | $ZodEnum | $ZodFunction | $ZodPromise | $ZodLazy | $ZodOptional | $ZodDefault | $ZodPrefault | $ZodTemplateLiteral | $ZodCustom | $ZodTransform | $ZodNonOptional | $ZodReadonly | $ZodNaN | $ZodPipe | $ZodSuccess | $ZodCatch | $ZodFile;
|
|
1273
|
+
export type $ZodStringFormatTypes = $ZodGUID | $ZodUUID | $ZodEmail | $ZodURL | $ZodEmoji | $ZodNanoID | $ZodCUID | $ZodCUID2 | $ZodULID | $ZodXID | $ZodKSUID | $ZodISODateTime | $ZodISODate | $ZodISOTime | $ZodISODuration | $ZodIPv4 | $ZodIPv6 | $ZodMAC | $ZodCIDRv4 | $ZodCIDRv6 | $ZodBase64 | $ZodBase64URL | $ZodE164 | $ZodCreditCard | $ZodIBAN | $ZodJWT | $ZodCustomStringFormat<"hex"> | $ZodCustomStringFormat<util.HashFormat> | $ZodCustomStringFormat<"hostname"> | $ZodCustomStringFormat<"currency_code">;
|
|
@@ -209,15 +209,37 @@ export const $ZodEmail = /*@__PURE__*/ core.$constructor("$ZodEmail", (inst, def
|
|
|
209
209
|
});
|
|
210
210
|
/** The `://` guard rejected the input before the URL constructor saw it. */
|
|
211
211
|
export const URL_BAD_FORMAT = 1;
|
|
212
|
-
/** The URL
|
|
212
|
+
/** The URL parser rejected the input. */
|
|
213
213
|
export const URL_UNPARSEABLE = 2;
|
|
214
|
-
|
|
214
|
+
export function canParseURL(input) {
|
|
215
|
+
try {
|
|
216
|
+
if (typeof URL !== "undefined" && typeof URL.canParse === "function")
|
|
217
|
+
return URL.canParse(input);
|
|
218
|
+
new URL(input);
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
export function validateURL(trimmed, def) {
|
|
226
|
+
if (!("normalize" in def) && !("hostname" in def) && !("protocol" in def)) {
|
|
227
|
+
return canParseURL(trimmed) || URL_UNPARSEABLE;
|
|
228
|
+
}
|
|
229
|
+
return parseURLObject(trimmed, def);
|
|
230
|
+
}
|
|
231
|
+
/** Parses a URL while preserving the non-normalizing HTTP guard. */
|
|
215
232
|
export function parseURLObject(trimmed, def) {
|
|
216
233
|
// When normalize is off, require :// for http/https URLs. This prevents strings like "http:example.com" or "https:/path" from being silently accepted
|
|
217
234
|
if (!def.normalize && def.protocol?.source === regexes.httpProtocol.source && !/^https?:\/\//i.test(trimmed)) {
|
|
218
235
|
return URL_BAD_FORMAT;
|
|
219
236
|
}
|
|
220
237
|
try {
|
|
238
|
+
if (typeof URL !== "undefined") {
|
|
239
|
+
const URLStatic = URL;
|
|
240
|
+
if (typeof URLStatic.parse === "function")
|
|
241
|
+
return URLStatic.parse(trimmed) ?? URL_UNPARSEABLE;
|
|
242
|
+
}
|
|
221
243
|
// @ts-ignore
|
|
222
244
|
return new URL(trimmed);
|
|
223
245
|
}
|
|
@@ -244,7 +266,7 @@ export const $ZodURL = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) =>
|
|
|
244
266
|
try {
|
|
245
267
|
// Trim whitespace from input
|
|
246
268
|
const trimmed = payload.value.trim();
|
|
247
|
-
const url =
|
|
269
|
+
const url = validateURL(trimmed, def);
|
|
248
270
|
if (url === URL_BAD_FORMAT) {
|
|
249
271
|
payload.issues.push({
|
|
250
272
|
code: "invalid_format",
|
|
@@ -266,6 +288,10 @@ export const $ZodURL = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) =>
|
|
|
266
288
|
});
|
|
267
289
|
return;
|
|
268
290
|
}
|
|
291
|
+
if (url === true) {
|
|
292
|
+
payload.value = stripTabAndNewline(trimmed);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
269
295
|
if (def.hostname && !urlHostnameOk(url, def.hostname)) {
|
|
270
296
|
payload.issues.push({
|
|
271
297
|
code: "invalid_format",
|
|
@@ -363,14 +389,7 @@ const ipv6Alphabet = /^[0-9a-fA-F:.]+$/;
|
|
|
363
389
|
export function isValidIPv6(value) {
|
|
364
390
|
if (!ipv6Alphabet.test(value))
|
|
365
391
|
return false;
|
|
366
|
-
|
|
367
|
-
// @ts-ignore
|
|
368
|
-
new URL(`http://[${value}]`);
|
|
369
|
-
return true;
|
|
370
|
-
}
|
|
371
|
-
catch {
|
|
372
|
-
return false;
|
|
373
|
-
}
|
|
392
|
+
return canParseURL(`http://[${value}]`);
|
|
374
393
|
}
|
|
375
394
|
export const $ZodIPv6 = /*@__PURE__*/ core.$constructor("$ZodIPv6", (inst, def) => {
|
|
376
395
|
def.pattern ?? (def.pattern = regexes.ipv6);
|
|
@@ -869,7 +888,7 @@ function handlePropertyResult(result, final, key, input, optin, optout) {
|
|
|
869
888
|
return;
|
|
870
889
|
}
|
|
871
890
|
if (result.value === undefined) {
|
|
872
|
-
if (isPresent) {
|
|
891
|
+
if (isPresent || (optin === "defaulted" && !isOptionalOut)) {
|
|
873
892
|
final.value[key] = undefined;
|
|
874
893
|
}
|
|
875
894
|
}
|
|
@@ -1124,16 +1143,17 @@ export const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (i
|
|
|
1124
1143
|
doc.write(`
|
|
1125
1144
|
if (${id}.issues.length) {${prefixStr(id, k)}
|
|
1126
1145
|
}
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1146
|
+
`);
|
|
1147
|
+
if (optin === "defaulted") {
|
|
1148
|
+
doc.write(`newResult[${k}] = ${id}.value;`);
|
|
1149
|
+
}
|
|
1150
|
+
else {
|
|
1151
|
+
doc.write(`
|
|
1152
|
+
if (${id}.value !== undefined || ${isPresent}) {
|
|
1133
1153
|
newResult[${k}] = ${id}.value;
|
|
1134
1154
|
}
|
|
1135
|
-
|
|
1136
1155
|
`);
|
|
1156
|
+
}
|
|
1137
1157
|
}
|
|
1138
1158
|
}
|
|
1139
1159
|
doc.write(`payload.value = newResult;`);
|
|
@@ -2584,64 +2604,3 @@ function handleRefineResult(result, payload, input, inst) {
|
|
|
2584
2604
|
payload.issues.push(util.issue(_iss));
|
|
2585
2605
|
}
|
|
2586
2606
|
}
|
|
2587
|
-
// asserts in place: the child result's value is discarded, matching z.property(), because a nested object or array schema rebuilds its output even when nothing transformed
|
|
2588
|
-
function handlePropertiesResult(result, payload, key) {
|
|
2589
|
-
if (result.issues.length) {
|
|
2590
|
-
payload.issues.push(...util.prefixIssues(key, result.issues));
|
|
2591
|
-
}
|
|
2592
|
-
}
|
|
2593
|
-
export const $ZodProperties = /*@__PURE__*/ core.$constructor("$ZodProperties", (inst, def) => {
|
|
2594
|
-
// $ZodType.init prepends an instance that already carries the $ZodCheck trait to its own `checks`, which would run the shape a second time and cost the parse context. Initializing the check trait after it keeps the schema role in `parse`, where the context arrives.
|
|
2595
|
-
$ZodType.init(inst, def);
|
|
2596
|
-
checks.$ZodCheck.init(inst, def);
|
|
2597
|
-
const memo = core.globalConfig.memoizer;
|
|
2598
|
-
memo?.attach(inst);
|
|
2599
|
-
// key and schema snapshotted together: reading one live and the other cached lets a later mutation of the caller's shape object pair a stale key with a missing schema
|
|
2600
|
-
let entries;
|
|
2601
|
-
const runShape = (payload, ctx) => {
|
|
2602
|
-
entries ?? (entries = Reflect.ownKeys(def.shape).map((key) => [key, def.shape[key]]));
|
|
2603
|
-
const input = payload.value;
|
|
2604
|
-
let proms;
|
|
2605
|
-
for (const [key, schema] of entries) {
|
|
2606
|
-
const result = schema._zod.run({ value: input[key], issues: [] }, ctx);
|
|
2607
|
-
if (result instanceof Promise) {
|
|
2608
|
-
proms ?? (proms = []);
|
|
2609
|
-
proms.push(result.then((result) => handlePropertiesResult(result, payload, key)));
|
|
2610
|
-
}
|
|
2611
|
-
else {
|
|
2612
|
-
handlePropertiesResult(result, payload, key);
|
|
2613
|
-
}
|
|
2614
|
-
}
|
|
2615
|
-
if (proms)
|
|
2616
|
-
return Promise.all(proms).then(() => undefined);
|
|
2617
|
-
return undefined;
|
|
2618
|
-
};
|
|
2619
|
-
inst._zod.parse = (payload, ctx) => {
|
|
2620
|
-
const input = payload.value;
|
|
2621
|
-
// as a schema this is the type gate, and it infers an object shape, so a primitive is a type error. A function passes: its properties read like any other object's, and z.instanceof allows one.
|
|
2622
|
-
if (input === null || (typeof input !== "object" && typeof input !== "function")) {
|
|
2623
|
-
payload.issues.push({ expected: "object", code: "invalid_type", input, inst });
|
|
2624
|
-
return payload;
|
|
2625
|
-
}
|
|
2626
|
-
// both sides declare the shape's input type, so the assertion runs forward in either direction; encoding the children backward would reject the very type this schema claims to take
|
|
2627
|
-
if (ctx.direction === "backward")
|
|
2628
|
-
ctx = { ...ctx, direction: "forward" };
|
|
2629
|
-
// the input is its own output here, so it registers as its own memo entry: a cycle re-entering this node hits the bucket instead of recursing forever
|
|
2630
|
-
if (memo)
|
|
2631
|
-
memo.alloc(inst, payload, input, ctx);
|
|
2632
|
-
const result = runShape(payload, ctx);
|
|
2633
|
-
return result instanceof Promise ? result.then(() => payload) : payload;
|
|
2634
|
-
};
|
|
2635
|
-
// as a check the base schema already typed the value, so this only asserts the properties — which read on a primitive too, matching z.property() on a string's length. It gets no context of its own, so a cycle through a spread schema is not tracked.
|
|
2636
|
-
inst._zod.check = (payload) => {
|
|
2637
|
-
if (payload.value == null) {
|
|
2638
|
-
payload.issues.push({ expected: "object", code: "invalid_type", input: payload.value, inst });
|
|
2639
|
-
return undefined;
|
|
2640
|
-
}
|
|
2641
|
-
return runShape(payload, {});
|
|
2642
|
-
};
|
|
2643
|
-
}, {
|
|
2644
|
-
*[Symbol.iterator]() {
|
|
2645
|
-
yield this;
|
|
2646
|
-
},
|
|
2647
|
-
});
|
|
@@ -137,9 +137,6 @@ export declare function processSchema<T extends schemas.$ZodType>(schema: T, ctx
|
|
|
137
137
|
export { processSchema as process };
|
|
138
138
|
export declare function extractDefs<T extends schemas.$ZodType>(ctx: ToJSONSchemaContext, schema: T): void;
|
|
139
139
|
export declare function finalize<T extends schemas.$ZodType>(ctx: ToJSONSchemaContext, schema: T): ZodStandardJSONSchemaPayload<T>;
|
|
140
|
-
export declare function isTransforming(_schema: schemas.$ZodType, _ctx?: {
|
|
141
|
-
seen: Set<schemas.$ZodType>;
|
|
142
|
-
}): boolean;
|
|
143
140
|
export type ZodStandardSchemaWithJSON<T> = StandardSchemaWithJSONProps<core.input<T>, core.output<T>>;
|
|
144
141
|
export interface ZodStandardJSONSchemaPayload<T> extends JSONSchema.BaseSchema {
|
|
145
142
|
"~standard": ZodStandardSchemaWithJSON<T>;
|
|
@@ -572,7 +572,7 @@ export function finalize(ctx, schema) {
|
|
|
572
572
|
throw new Error("Error converting schema to JSON.");
|
|
573
573
|
}
|
|
574
574
|
}
|
|
575
|
-
|
|
575
|
+
function isTransforming(_schema, _ctx) {
|
|
576
576
|
const ctx = _ctx ?? { seen: new Set() };
|
|
577
577
|
if (ctx.seen.has(_schema))
|
|
578
578
|
return false;
|
package/vendor/zod/core/util.js
CHANGED
|
@@ -725,10 +725,6 @@ export function members(proto, table) {
|
|
|
725
725
|
else
|
|
726
726
|
defineBound(proto, key, desc.value);
|
|
727
727
|
}
|
|
728
|
-
// for..in sees no symbol keys, so well-known members like Symbol.iterator install here
|
|
729
|
-
for (const sym of Object.getOwnPropertySymbols(table)) {
|
|
730
|
-
defineBound(proto, sym, table[sym]);
|
|
731
|
-
}
|
|
732
728
|
}
|
|
733
729
|
/** Shadows a prototype member with an own value, so a getter that builds from the instance runs once. */
|
|
734
730
|
export function own(inst, key, value, enumerable = true) {
|
package/vendor/zod/core/visit.js
CHANGED
|
@@ -135,18 +135,6 @@ export function visit(schema, fnOrHandlers) {
|
|
|
135
135
|
const { _cachedInner, ...rest } = def;
|
|
136
136
|
return clone(s, { ...rest, getter: () => run(original()) });
|
|
137
137
|
}
|
|
138
|
-
case "properties": {
|
|
139
|
-
const oldShape = def.shape;
|
|
140
|
-
let changed = false;
|
|
141
|
-
const newShape = {};
|
|
142
|
-
for (const k of Reflect.ownKeys(oldShape)) {
|
|
143
|
-
const mapped = run(oldShape[k]);
|
|
144
|
-
if (mapped !== oldShape[k])
|
|
145
|
-
changed = true;
|
|
146
|
-
newShape[k] = mapped;
|
|
147
|
-
}
|
|
148
|
-
return changed ? clone(s, { ...def, shape: newShape }) : s;
|
|
149
|
-
}
|
|
150
138
|
// A leaf by choice: `parts` are regex fragments, not data positions.
|
|
151
139
|
case "template_literal":
|
|
152
140
|
// Leaves.
|
package/vendor/zod/locales/ar.js
CHANGED
package/vendor/zod/locales/az.js
CHANGED
package/vendor/zod/locales/be.js
CHANGED
package/vendor/zod/locales/bg.js
CHANGED
package/vendor/zod/locales/bn.js
CHANGED
package/vendor/zod/locales/ca.js
CHANGED