@wallarm-org/mcp 2.0.0 → 3.0.0-rc-feat-WDS-191.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/dist/index.js +2624 -1434
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -3,150 +3,34 @@ import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mc
|
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
import fs from "fs";
|
|
5
5
|
import path_0 from "path";
|
|
6
|
-
var core_a;
|
|
7
|
-
function $constructor(name, initializer, params) {
|
|
8
|
-
function init(inst, def) {
|
|
9
|
-
if (!inst._zod) Object.defineProperty(inst, "_zod", {
|
|
10
|
-
value: {
|
|
11
|
-
def,
|
|
12
|
-
constr: _,
|
|
13
|
-
traits: new Set()
|
|
14
|
-
},
|
|
15
|
-
enumerable: false
|
|
16
|
-
});
|
|
17
|
-
if (inst._zod.traits.has(name)) return;
|
|
18
|
-
inst._zod.traits.add(name);
|
|
19
|
-
initializer(inst, def);
|
|
20
|
-
const proto = _.prototype;
|
|
21
|
-
const keys = Object.keys(proto);
|
|
22
|
-
for(let i = 0; i < keys.length; i++){
|
|
23
|
-
const k = keys[i];
|
|
24
|
-
if (!(k in inst)) inst[k] = proto[k].bind(inst);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
const Parent = params?.Parent ?? Object;
|
|
28
|
-
class Definition extends Parent {
|
|
29
|
-
}
|
|
30
|
-
Object.defineProperty(Definition, "name", {
|
|
31
|
-
value: name
|
|
32
|
-
});
|
|
33
|
-
function _(def) {
|
|
34
|
-
var _a;
|
|
35
|
-
const inst = params?.Parent ? new Definition() : this;
|
|
36
|
-
init(inst, def);
|
|
37
|
-
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
38
|
-
for (const fn of inst._zod.deferred)fn();
|
|
39
|
-
return inst;
|
|
40
|
-
}
|
|
41
|
-
Object.defineProperty(_, "init", {
|
|
42
|
-
value: init
|
|
43
|
-
});
|
|
44
|
-
Object.defineProperty(_, Symbol.hasInstance, {
|
|
45
|
-
value: (inst)=>{
|
|
46
|
-
if (params?.Parent && inst instanceof params.Parent) return true;
|
|
47
|
-
return inst?._zod?.traits?.has(name);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
Object.defineProperty(_, "name", {
|
|
51
|
-
value: name
|
|
52
|
-
});
|
|
53
|
-
return _;
|
|
54
|
-
}
|
|
55
|
-
Symbol("zod_brand");
|
|
56
|
-
class $ZodAsyncError extends Error {
|
|
57
|
-
constructor(){
|
|
58
|
-
super("Encountered Promise during synchronous parse. Use .parseAsync() instead.");
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
class $ZodEncodeError extends Error {
|
|
62
|
-
constructor(name){
|
|
63
|
-
super(`Encountered unidirectional transform during encode: ${name}`);
|
|
64
|
-
this.name = "ZodEncodeError";
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
(core_a = globalThis).__zod_globalConfig ?? (core_a.__zod_globalConfig = {});
|
|
68
|
-
const globalConfig = globalThis.__zod_globalConfig;
|
|
69
|
-
function core_config(newConfig) {
|
|
70
|
-
if (newConfig) Object.assign(globalConfig, newConfig);
|
|
71
|
-
return globalConfig;
|
|
72
|
-
}
|
|
73
|
-
const cuid = /^[cC][0-9a-z]{6,}$/;
|
|
74
|
-
const cuid2 = /^[0-9a-z]+$/;
|
|
75
|
-
const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
|
|
76
|
-
const xid = /^[0-9a-vA-V]{20}$/;
|
|
77
|
-
const ksuid = /^[A-Za-z0-9]{27}$/;
|
|
78
|
-
const nanoid = /^[a-zA-Z0-9_-]{21}$/;
|
|
79
|
-
const duration = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
|
|
80
|
-
const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
|
|
81
|
-
const uuid = (version)=>{
|
|
82
|
-
if (!version) return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
|
|
83
|
-
return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
|
|
84
|
-
};
|
|
85
|
-
const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
|
|
86
|
-
const _emoji = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";
|
|
87
|
-
function emoji() {
|
|
88
|
-
return new RegExp(_emoji, "u");
|
|
89
|
-
}
|
|
90
|
-
const ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
91
|
-
const ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
|
|
92
|
-
const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
|
|
93
|
-
const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
94
|
-
const regexes_base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
|
95
|
-
const regexes_base64url = /^[A-Za-z0-9_-]*$/;
|
|
96
|
-
const httpProtocol = /^https?$/;
|
|
97
|
-
const e164 = /^\+[1-9]\d{6,14}$/;
|
|
98
|
-
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])))";
|
|
99
|
-
const date = /*@__PURE__*/ new RegExp(`^${dateSource}$`);
|
|
100
|
-
function timeSource(args) {
|
|
101
|
-
const hhmm = "(?:[01]\\d|2[0-3]):[0-5]\\d";
|
|
102
|
-
const regex = "number" == typeof args.precision ? -1 === args.precision ? `${hhmm}` : 0 === args.precision ? `${hhmm}:[0-5]\\d` : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}` : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
|
|
103
|
-
return regex;
|
|
104
|
-
}
|
|
105
|
-
function regexes_time(args) {
|
|
106
|
-
return new RegExp(`^${timeSource(args)}$`);
|
|
107
|
-
}
|
|
108
|
-
function datetime(args) {
|
|
109
|
-
const time = timeSource({
|
|
110
|
-
precision: args.precision
|
|
111
|
-
});
|
|
112
|
-
const opts = [
|
|
113
|
-
"Z"
|
|
114
|
-
];
|
|
115
|
-
if (args.local) opts.push("");
|
|
116
|
-
if (args.offset) opts.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");
|
|
117
|
-
const timeRegex = `${time}(?:${opts.join("|")})`;
|
|
118
|
-
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
|
|
119
|
-
}
|
|
120
|
-
const string = (params)=>{
|
|
121
|
-
const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : "[\\s\\S]*";
|
|
122
|
-
return new RegExp(`^${regex}$`);
|
|
123
|
-
};
|
|
124
|
-
const regexes_boolean = /^(?:true|false)$/i;
|
|
125
|
-
const lowercase = /^[^A-Z]*$/;
|
|
126
|
-
const uppercase = /^[^a-z]*$/;
|
|
127
6
|
function getEnumValues(entries) {
|
|
128
7
|
const numericValues = Object.values(entries).filter((v)=>"number" == typeof v);
|
|
129
8
|
const values = Object.entries(entries).filter(([k, _])=>-1 === numericValues.indexOf(+k)).map(([_, v])=>v);
|
|
130
9
|
return values;
|
|
131
10
|
}
|
|
11
|
+
function joinValues(array, separator = "|") {
|
|
12
|
+
return array.map((val)=>stringifyPrimitive(val)).join(separator);
|
|
13
|
+
}
|
|
132
14
|
function jsonStringifyReplacer(_, value) {
|
|
133
15
|
if ("bigint" == typeof value) return value.toString();
|
|
134
16
|
return value;
|
|
135
17
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
throw new Error("cached value already set");
|
|
18
|
+
class Cached {
|
|
19
|
+
constructor(getter){
|
|
20
|
+
this._getter = getter;
|
|
21
|
+
this._value = void 0;
|
|
22
|
+
}
|
|
23
|
+
get value() {
|
|
24
|
+
const getter = this._getter;
|
|
25
|
+
if (void 0 !== getter) {
|
|
26
|
+
this._value = getter();
|
|
27
|
+
this._getter = void 0;
|
|
148
28
|
}
|
|
149
|
-
|
|
29
|
+
return this._value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function util_cached(getter) {
|
|
33
|
+
return new Cached(getter);
|
|
150
34
|
}
|
|
151
35
|
function nullish(input) {
|
|
152
36
|
return null == input;
|
|
@@ -156,27 +40,7 @@ function cleanRegex(source) {
|
|
|
156
40
|
const end = source.endsWith("$") ? source.length - 1 : source.length;
|
|
157
41
|
return source.slice(start, end);
|
|
158
42
|
}
|
|
159
|
-
|
|
160
|
-
function defineLazy(object, key, getter) {
|
|
161
|
-
let value;
|
|
162
|
-
Object.defineProperty(object, key, {
|
|
163
|
-
get () {
|
|
164
|
-
if (value === EVALUATING) return;
|
|
165
|
-
if (void 0 === value) {
|
|
166
|
-
value = EVALUATING;
|
|
167
|
-
value = getter();
|
|
168
|
-
}
|
|
169
|
-
return value;
|
|
170
|
-
},
|
|
171
|
-
set (v) {
|
|
172
|
-
Object.defineProperty(object, key, {
|
|
173
|
-
value: v
|
|
174
|
-
});
|
|
175
|
-
},
|
|
176
|
-
configurable: true
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
function assignProp(target, prop, value) {
|
|
43
|
+
function util_assignProp(target, prop, value) {
|
|
180
44
|
Object.defineProperty(target, prop, {
|
|
181
45
|
value,
|
|
182
46
|
writable: true,
|
|
@@ -184,6 +48,46 @@ function assignProp(target, prop, value) {
|
|
|
184
48
|
configurable: true
|
|
185
49
|
});
|
|
186
50
|
}
|
|
51
|
+
function rawShape(def) {
|
|
52
|
+
const desc = Object.getOwnPropertyDescriptor(def, "shape");
|
|
53
|
+
return desc?.get ? desc.get.raw : desc?.value;
|
|
54
|
+
}
|
|
55
|
+
function sourceShape(schema) {
|
|
56
|
+
return rawShape(schema._zod.def) ?? schema._zod.def.shape;
|
|
57
|
+
}
|
|
58
|
+
function deferProp(target, key, getter) {
|
|
59
|
+
Object.defineProperty(target, key, {
|
|
60
|
+
get () {
|
|
61
|
+
const value = getter();
|
|
62
|
+
util_assignProp(this, key, value);
|
|
63
|
+
return value;
|
|
64
|
+
},
|
|
65
|
+
enumerable: true,
|
|
66
|
+
configurable: true
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function putProp(target, key, value) {
|
|
70
|
+
if (key in target) util_assignProp(target, key, value);
|
|
71
|
+
else target[key] = value;
|
|
72
|
+
}
|
|
73
|
+
function mirrorShape(target, source, keys, wrap) {
|
|
74
|
+
const raw = sourceShape(source);
|
|
75
|
+
for (const key of keys){
|
|
76
|
+
const desc = Object.getOwnPropertyDescriptor(raw, key);
|
|
77
|
+
if (desc.enumerable) if (desc.get) deferProp(target, key, ()=>{
|
|
78
|
+
const value = source._zod.def.shape[key];
|
|
79
|
+
return wrap ? wrap(value, key) : value;
|
|
80
|
+
});
|
|
81
|
+
else putProp(target, key, wrap ? wrap(desc.value, key) : desc.value);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function mirrorProps(target, source) {
|
|
85
|
+
for (const key of Reflect.ownKeys(source)){
|
|
86
|
+
const desc = Object.getOwnPropertyDescriptor(source, key);
|
|
87
|
+
if (desc.enumerable) if (desc.get) deferProp(target, key, ()=>source[key]);
|
|
88
|
+
else putProp(target, key, desc.value);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
187
91
|
function mergeDefs(...defs) {
|
|
188
92
|
const mergedDescriptors = {};
|
|
189
93
|
for (const def of defs){
|
|
@@ -202,7 +106,7 @@ const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace
|
|
|
202
106
|
function util_isObject(data) {
|
|
203
107
|
return "object" == typeof data && null !== data && !Array.isArray(data);
|
|
204
108
|
}
|
|
205
|
-
const util_allowsEval = /* @__PURE__*/
|
|
109
|
+
const util_allowsEval = /* @__PURE__*/ util_cached(()=>{
|
|
206
110
|
if (globalConfig.jitless) return false;
|
|
207
111
|
if ("u" > typeof navigator && navigator?.userAgent?.includes("Cloudflare")) return false;
|
|
208
112
|
try {
|
|
@@ -264,94 +168,113 @@ function normalizeParams(_params) {
|
|
|
264
168
|
};
|
|
265
169
|
return params;
|
|
266
170
|
}
|
|
171
|
+
function stringifyPrimitive(value) {
|
|
172
|
+
if ("bigint" == typeof value) return value.toString() + "n";
|
|
173
|
+
if ("string" == typeof value) return `"${value}"`;
|
|
174
|
+
return `${value}`;
|
|
175
|
+
}
|
|
267
176
|
function optionalKeys(shape) {
|
|
268
|
-
return Object.keys(shape).filter((k)=>
|
|
177
|
+
return Object.keys(shape).filter((k)=>void 0 !== shape[k]._zod.optin && "optional" === shape[k]._zod.optout);
|
|
269
178
|
}
|
|
179
|
+
// Wrapped in a `@__PURE__` IIFE: esbuild never tree-shakes a top-level initializer that contains a member access on `Number`, so the bare object literal survived into every bundle.
|
|
180
|
+
const NUMBER_FORMAT_RANGES = /*@__PURE__*/ (()=>({
|
|
181
|
+
safeint: [
|
|
182
|
+
Number.MIN_SAFE_INTEGER,
|
|
183
|
+
Number.MAX_SAFE_INTEGER
|
|
184
|
+
],
|
|
185
|
+
int32: [
|
|
186
|
+
-2147483648,
|
|
187
|
+
2147483647
|
|
188
|
+
],
|
|
189
|
+
uint32: [
|
|
190
|
+
0,
|
|
191
|
+
4294967295
|
|
192
|
+
],
|
|
193
|
+
float32: [
|
|
194
|
+
-3.4028234663852886e+38,
|
|
195
|
+
3.4028234663852886e38
|
|
196
|
+
],
|
|
197
|
+
float64: [
|
|
198
|
+
-Number.MAX_VALUE,
|
|
199
|
+
Number.MAX_VALUE
|
|
200
|
+
]
|
|
201
|
+
}))();
|
|
202
|
+
const BIGINT_FORMAT_RANGES = {
|
|
203
|
+
int64: [
|
|
204
|
+
/* @__PURE__*/ BigInt("-9223372036854775808"),
|
|
205
|
+
/* @__PURE__*/ BigInt("9223372036854775807")
|
|
206
|
+
],
|
|
207
|
+
uint64: [
|
|
208
|
+
/* @__PURE__*/ BigInt(0),
|
|
209
|
+
/* @__PURE__*/ BigInt("18446744073709551615")
|
|
210
|
+
]
|
|
211
|
+
};
|
|
270
212
|
function pick(schema, mask) {
|
|
271
213
|
const currDef = schema._zod.def;
|
|
272
214
|
const checks = currDef.checks;
|
|
273
215
|
const hasChecks = checks && checks.length > 0;
|
|
274
216
|
if (hasChecks) throw new Error(".pick() cannot be used on object schemas containing refinements");
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
|
|
280
|
-
if (mask[key]) newShape[key] = currDef.shape[key];
|
|
281
|
-
}
|
|
282
|
-
assignProp(this, "shape", newShape);
|
|
283
|
-
return newShape;
|
|
284
|
-
},
|
|
217
|
+
const newShape = {};
|
|
218
|
+
mirrorShape(newShape, schema, maskedKeys(schema, mask));
|
|
219
|
+
return clone(schema, mergeDefs(currDef, {
|
|
220
|
+
shape: newShape,
|
|
285
221
|
checks: []
|
|
286
|
-
});
|
|
287
|
-
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
function maskedKeys(schema, mask) {
|
|
225
|
+
const raw = sourceShape(schema);
|
|
226
|
+
const keys = [];
|
|
227
|
+
for (const key of Reflect.ownKeys(mask)){
|
|
228
|
+
if (!Object.getOwnPropertyDescriptor(raw, key)?.enumerable) throw new Error(`Unrecognized key: "${String(key)}"`);
|
|
229
|
+
if (mask[key]) keys.push(key);
|
|
230
|
+
}
|
|
231
|
+
return keys;
|
|
288
232
|
}
|
|
289
233
|
function omit(schema, mask) {
|
|
290
234
|
const currDef = schema._zod.def;
|
|
291
235
|
const checks = currDef.checks;
|
|
292
236
|
const hasChecks = checks && checks.length > 0;
|
|
293
237
|
if (hasChecks) throw new Error(".omit() cannot be used on object schemas containing refinements");
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
for(const key in mask){
|
|
300
|
-
if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
|
|
301
|
-
if (mask[key]) delete newShape[key];
|
|
302
|
-
}
|
|
303
|
-
assignProp(this, "shape", newShape);
|
|
304
|
-
return newShape;
|
|
305
|
-
},
|
|
238
|
+
const omitted = new Set(maskedKeys(schema, mask));
|
|
239
|
+
const newShape = {};
|
|
240
|
+
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)).filter((key)=>!omitted.has(key)));
|
|
241
|
+
return clone(schema, mergeDefs(currDef, {
|
|
242
|
+
shape: newShape,
|
|
306
243
|
checks: []
|
|
307
|
-
});
|
|
308
|
-
return clone(schema, def);
|
|
244
|
+
}));
|
|
309
245
|
}
|
|
310
246
|
function extend(schema, shape) {
|
|
311
247
|
if (!isPlainObject(shape)) throw new Error("Invalid input to extend: expected a plain object");
|
|
312
248
|
const checks = schema._zod.def.checks;
|
|
313
249
|
const hasChecks = checks && checks.length > 0;
|
|
314
250
|
if (hasChecks) {
|
|
315
|
-
const existingShape = schema
|
|
316
|
-
for(const key
|
|
251
|
+
const existingShape = sourceShape(schema);
|
|
252
|
+
for (const key of Reflect.ownKeys(shape))if (void 0 !== Object.getOwnPropertyDescriptor(existingShape, key)) throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
|
|
317
253
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
});
|
|
328
|
-
return clone(schema, def);
|
|
254
|
+
return clone(schema, mergeDefs(schema._zod.def, {
|
|
255
|
+
shape: extended(schema, shape)
|
|
256
|
+
}));
|
|
257
|
+
}
|
|
258
|
+
function extended(schema, shape) {
|
|
259
|
+
const newShape = {};
|
|
260
|
+
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)));
|
|
261
|
+
mirrorProps(newShape, shape);
|
|
262
|
+
return newShape;
|
|
329
263
|
}
|
|
330
264
|
function safeExtend(schema, shape) {
|
|
331
265
|
if (!isPlainObject(shape)) throw new Error("Invalid input to safeExtend: expected a plain object");
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
...schema._zod.def.shape,
|
|
336
|
-
...shape
|
|
337
|
-
};
|
|
338
|
-
assignProp(this, "shape", _shape);
|
|
339
|
-
return _shape;
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
return clone(schema, def);
|
|
266
|
+
return clone(schema, mergeDefs(schema._zod.def, {
|
|
267
|
+
shape: extended(schema, shape)
|
|
268
|
+
}));
|
|
343
269
|
}
|
|
344
|
-
function
|
|
270
|
+
function util_merge(a, b) {
|
|
271
|
+
if (!b?._zod?.def) throw new Error("Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.");
|
|
345
272
|
if (a._zod.def.checks?.length) throw new Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");
|
|
273
|
+
const newShape = {};
|
|
274
|
+
mirrorShape(newShape, a, Reflect.ownKeys(sourceShape(a)));
|
|
275
|
+
mirrorShape(newShape, b, Reflect.ownKeys(sourceShape(b)));
|
|
346
276
|
const def = mergeDefs(a._zod.def, {
|
|
347
|
-
|
|
348
|
-
const _shape = {
|
|
349
|
-
...a._zod.def.shape,
|
|
350
|
-
...b._zod.def.shape
|
|
351
|
-
};
|
|
352
|
-
assignProp(this, "shape", _shape);
|
|
353
|
-
return _shape;
|
|
354
|
-
},
|
|
277
|
+
shape: newShape,
|
|
355
278
|
get catchall () {
|
|
356
279
|
return b._zod.def.catchall;
|
|
357
280
|
},
|
|
@@ -359,58 +282,32 @@ function merge(a, b) {
|
|
|
359
282
|
});
|
|
360
283
|
return clone(a, def);
|
|
361
284
|
}
|
|
362
|
-
function partial(Class, schema, mask) {
|
|
285
|
+
function partial(Class, schema, mask, name = "partial") {
|
|
363
286
|
const currDef = schema._zod.def;
|
|
364
287
|
const checks = currDef.checks;
|
|
365
288
|
const hasChecks = checks && checks.length > 0;
|
|
366
|
-
if (hasChecks) throw new Error(
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
if (mask[key]) shape[key] = Class ? new Class({
|
|
376
|
-
type: "optional",
|
|
377
|
-
innerType: oldShape[key]
|
|
378
|
-
}) : oldShape[key];
|
|
379
|
-
}
|
|
380
|
-
else for(const key in oldShape)shape[key] = Class ? new Class({
|
|
381
|
-
type: "optional",
|
|
382
|
-
innerType: oldShape[key]
|
|
383
|
-
}) : oldShape[key];
|
|
384
|
-
assignProp(this, "shape", shape);
|
|
385
|
-
return shape;
|
|
386
|
-
},
|
|
289
|
+
if (hasChecks) throw new Error(`.${name}() cannot be used on object schemas containing refinements`);
|
|
290
|
+
const selected = mask ? new Set(maskedKeys(schema, mask)) : void 0;
|
|
291
|
+
const newShape = {};
|
|
292
|
+
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)), Class && ((value, key)=>selected && !selected.has(key) ? value : new Class({
|
|
293
|
+
type: "optional",
|
|
294
|
+
innerType: value
|
|
295
|
+
})));
|
|
296
|
+
return clone(schema, mergeDefs(schema._zod.def, {
|
|
297
|
+
shape: newShape,
|
|
387
298
|
checks: []
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
const
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
if (mask[key]) shape[key] = new Class({
|
|
401
|
-
type: "nonoptional",
|
|
402
|
-
innerType: oldShape[key]
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
else for(const key in oldShape)shape[key] = new Class({
|
|
406
|
-
type: "nonoptional",
|
|
407
|
-
innerType: oldShape[key]
|
|
408
|
-
});
|
|
409
|
-
assignProp(this, "shape", shape);
|
|
410
|
-
return shape;
|
|
411
|
-
}
|
|
412
|
-
});
|
|
413
|
-
return clone(schema, def);
|
|
299
|
+
}));
|
|
300
|
+
}
|
|
301
|
+
function util_required(Class, schema, mask) {
|
|
302
|
+
const selected = mask ? new Set(maskedKeys(schema, mask)) : void 0;
|
|
303
|
+
const newShape = {};
|
|
304
|
+
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)), (value, key)=>selected && !selected.has(key) ? value : new Class({
|
|
305
|
+
type: "nonoptional",
|
|
306
|
+
innerType: value
|
|
307
|
+
}));
|
|
308
|
+
return clone(schema, mergeDefs(schema._zod.def, {
|
|
309
|
+
shape: newShape
|
|
310
|
+
}));
|
|
414
311
|
}
|
|
415
312
|
function aborted(x, startIndex = 0) {
|
|
416
313
|
if (true === x.aborted) return true;
|
|
@@ -433,19 +330,55 @@ function prefixIssues(path, issues) {
|
|
|
433
330
|
function unwrapMessage(message) {
|
|
434
331
|
return "string" == typeof message ? message : message?.message;
|
|
435
332
|
}
|
|
333
|
+
function attachSchema(issues, start, inst) {
|
|
334
|
+
var _a;
|
|
335
|
+
for(let i = start; i < issues.length; i++)(_a = issues[i]).schema ?? (_a.schema = inst);
|
|
336
|
+
}
|
|
436
337
|
function finalizeIssue(iss, ctx, config) {
|
|
437
|
-
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
338
|
+
var _a;
|
|
339
|
+
const traits = iss.inst?._zod?.traits;
|
|
340
|
+
if (traits?.has("$ZodType")) if (traits.has("$ZodCheck")) (_a = iss).schema ?? (_a.schema = iss.inst);
|
|
341
|
+
else iss.schema = iss.inst;
|
|
342
|
+
const schemaError = iss.schema !== iss.inst ? iss.schema?._zod.def?.error : void 0;
|
|
343
|
+
const message = iss.message ? iss.message : unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(schemaError?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config.customError?.(iss)) ?? unwrapMessage(config.localeError?.(iss)) ?? "Invalid input";
|
|
344
|
+
const full = {};
|
|
345
|
+
for (const k of Object.keys(iss))if ("inst" !== k && "schema" !== k && "continue" !== k && "input" !== k && "__proto__" !== k) full[k] = iss[k];
|
|
346
|
+
full.path ?? (full.path = []);
|
|
347
|
+
full.message = message;
|
|
348
|
+
if (ctx?.reportInput) full.input = iss.input;
|
|
349
|
+
return full;
|
|
350
|
+
}
|
|
351
|
+
const highSurrogate = /[\uD800-\uDBFF]/;
|
|
352
|
+
function codePointLength(str) {
|
|
353
|
+
const units = str.length;
|
|
354
|
+
if (!highSurrogate.test(str)) return units;
|
|
355
|
+
let count = units;
|
|
356
|
+
for(let i = 0; i < units - 1; i++)if ((0xfc00 & str.charCodeAt(i)) === 0xd800 && (0xfc00 & str.charCodeAt(i + 1)) === 0xdc00) {
|
|
357
|
+
count--;
|
|
358
|
+
i++;
|
|
359
|
+
}
|
|
360
|
+
return count;
|
|
443
361
|
}
|
|
444
362
|
function getLengthableOrigin(input) {
|
|
445
363
|
if (Array.isArray(input)) return "array";
|
|
446
364
|
if ("string" == typeof input) return "string";
|
|
447
365
|
return "unknown";
|
|
448
366
|
}
|
|
367
|
+
function parsedType(data) {
|
|
368
|
+
const t = typeof data;
|
|
369
|
+
switch(t){
|
|
370
|
+
case "number":
|
|
371
|
+
return Number.isNaN(data) ? "nan" : "number";
|
|
372
|
+
case "object":
|
|
373
|
+
{
|
|
374
|
+
if (null === data) return "null";
|
|
375
|
+
if (Array.isArray(data)) return "array";
|
|
376
|
+
const obj = data;
|
|
377
|
+
if (obj && Object.getPrototypeOf(obj) !== Object.prototype && "constructor" in obj && obj.constructor) return obj.constructor.name;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return t;
|
|
381
|
+
}
|
|
449
382
|
function util_issue(...args) {
|
|
450
383
|
const [iss, input, inst] = args;
|
|
451
384
|
if ("string" == typeof iss) return {
|
|
@@ -458,93 +391,637 @@ function util_issue(...args) {
|
|
|
458
391
|
...iss
|
|
459
392
|
};
|
|
460
393
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
const $ZodCheckMaxLength = /*@__PURE__*/ $constructor("$ZodCheckMaxLength", (inst, def)=>{
|
|
468
|
-
var _a;
|
|
469
|
-
$ZodCheck.init(inst, def);
|
|
470
|
-
(_a = inst._zod.def).when ?? (_a.when = (payload)=>{
|
|
471
|
-
const val = payload.value;
|
|
472
|
-
return !nullish(val) && void 0 !== val.length;
|
|
473
|
-
});
|
|
474
|
-
inst._zod.onattach.push((inst)=>{
|
|
475
|
-
const curr = inst._zod.bag.maximum ?? 1 / 0;
|
|
476
|
-
if (def.maximum < curr) inst._zod.bag.maximum = def.maximum;
|
|
477
|
-
});
|
|
478
|
-
inst._zod.check = (payload)=>{
|
|
479
|
-
const input = payload.value;
|
|
480
|
-
const length = input.length;
|
|
481
|
-
if (length <= def.maximum) return;
|
|
482
|
-
const origin = getLengthableOrigin(input);
|
|
483
|
-
payload.issues.push({
|
|
484
|
-
origin,
|
|
485
|
-
code: "too_big",
|
|
486
|
-
maximum: def.maximum,
|
|
487
|
-
inclusive: true,
|
|
488
|
-
input,
|
|
489
|
-
inst,
|
|
490
|
-
continue: !def.abort
|
|
394
|
+
function util_members(proto, table) {
|
|
395
|
+
for(const key in table){
|
|
396
|
+
const desc = Object.getOwnPropertyDescriptor(table, key);
|
|
397
|
+
if (desc.get) Object.defineProperty(proto, key, {
|
|
398
|
+
...desc,
|
|
399
|
+
enumerable: false
|
|
491
400
|
});
|
|
492
|
-
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
inst._zod.onattach.push((inst)=>{
|
|
502
|
-
const curr = inst._zod.bag.minimum ?? -1 / 0;
|
|
503
|
-
if (def.minimum > curr) inst._zod.bag.minimum = def.minimum;
|
|
401
|
+
else defineBound(proto, key, desc.value);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
function util_own(inst, key, value, enumerable = true) {
|
|
405
|
+
Object.defineProperty(inst, key, {
|
|
406
|
+
configurable: true,
|
|
407
|
+
writable: true,
|
|
408
|
+
enumerable,
|
|
409
|
+
value
|
|
504
410
|
});
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
411
|
+
return value;
|
|
412
|
+
}
|
|
413
|
+
function hide(inst, key, value) {
|
|
414
|
+
return util_own(inst, key, value, false);
|
|
415
|
+
}
|
|
416
|
+
function derived(computes, table) {
|
|
417
|
+
for(const key in computes){
|
|
418
|
+
const compute = computes[key];
|
|
419
|
+
Object.defineProperty(table, key, {
|
|
420
|
+
configurable: true,
|
|
421
|
+
enumerable: true,
|
|
422
|
+
get () {
|
|
423
|
+
return util_own(this, key, compute(this));
|
|
424
|
+
},
|
|
425
|
+
set (value) {
|
|
426
|
+
util_own(this, key, value);
|
|
427
|
+
}
|
|
518
428
|
});
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
bag.maximum = def.length;
|
|
532
|
-
bag.length = def.length;
|
|
429
|
+
}
|
|
430
|
+
return table;
|
|
431
|
+
}
|
|
432
|
+
function defineBound(proto, key, fn) {
|
|
433
|
+
Object.defineProperty(proto, key, {
|
|
434
|
+
configurable: true,
|
|
435
|
+
get () {
|
|
436
|
+
return this == null ? fn : util_own(this, key, fn.bind(this));
|
|
437
|
+
},
|
|
438
|
+
set (value) {
|
|
439
|
+
util_own(this, key, value);
|
|
440
|
+
}
|
|
533
441
|
});
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
442
|
+
}
|
|
443
|
+
function claim(inst, sentinel) {
|
|
444
|
+
const proto = Object.getPrototypeOf(inst);
|
|
445
|
+
return sentinel in proto ? void 0 : proto;
|
|
446
|
+
}
|
|
447
|
+
let installing;
|
|
448
|
+
let broke = false;
|
|
449
|
+
const breaker = {
|
|
450
|
+
configurable: true,
|
|
451
|
+
get () {
|
|
452
|
+
broke = true;
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
function defineLazyInternal(inst, key, compute) {
|
|
456
|
+
const proto = Object.getPrototypeOf(inst._zod);
|
|
457
|
+
if (key in proto && installing !== inst._zod) {
|
|
458
|
+
installing = void 0;
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
installing = inst._zod;
|
|
462
|
+
Object.defineProperty(proto, key, {
|
|
463
|
+
configurable: true,
|
|
464
|
+
get () {
|
|
465
|
+
Object.defineProperty(this, key, breaker);
|
|
466
|
+
const outer = broke;
|
|
467
|
+
broke = false;
|
|
468
|
+
try {
|
|
469
|
+
const value = compute(this);
|
|
470
|
+
if (broke) delete this[key];
|
|
471
|
+
else Object.defineProperty(this, key, {
|
|
472
|
+
configurable: true,
|
|
473
|
+
writable: true,
|
|
474
|
+
value
|
|
475
|
+
});
|
|
476
|
+
broke = broke || outer;
|
|
477
|
+
return value;
|
|
478
|
+
} catch (err) {
|
|
479
|
+
delete this[key];
|
|
480
|
+
broke = broke || outer;
|
|
481
|
+
throw err;
|
|
482
|
+
}
|
|
483
|
+
},
|
|
484
|
+
set (value) {
|
|
485
|
+
Object.defineProperty(this, key, {
|
|
486
|
+
configurable: true,
|
|
487
|
+
writable: true,
|
|
488
|
+
value
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
function installLazyProp(inst, key, make, enumerable) {
|
|
494
|
+
const proto = claim(inst, key);
|
|
495
|
+
if (!proto) return;
|
|
496
|
+
Object.defineProperty(proto, key, {
|
|
497
|
+
configurable: true,
|
|
498
|
+
get () {
|
|
499
|
+
const desc = {
|
|
500
|
+
configurable: true,
|
|
501
|
+
writable: true,
|
|
502
|
+
enumerable,
|
|
503
|
+
value: void 0
|
|
504
|
+
};
|
|
505
|
+
Object.defineProperty(this, key, desc);
|
|
506
|
+
desc.value = make(this);
|
|
507
|
+
Object.defineProperty(this, key, desc);
|
|
508
|
+
return desc.value;
|
|
509
|
+
},
|
|
510
|
+
set (value) {
|
|
511
|
+
Object.defineProperty(this, key, {
|
|
512
|
+
configurable: true,
|
|
513
|
+
writable: true,
|
|
514
|
+
enumerable,
|
|
515
|
+
value
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
const CONSTANT_CATCH = "~constantCatch";
|
|
521
|
+
function constantCatch(value) {
|
|
522
|
+
const fn = ()=>value;
|
|
523
|
+
fn[CONSTANT_CATCH] = true;
|
|
524
|
+
return fn;
|
|
525
|
+
}
|
|
526
|
+
var core_a;
|
|
527
|
+
const _zodDesc = {
|
|
528
|
+
value: void 0,
|
|
529
|
+
enumerable: false
|
|
530
|
+
};
|
|
531
|
+
let _E = "captureStackTrace" in Error ? Error : null;
|
|
532
|
+
function newError(Definition) {
|
|
533
|
+
const E = _E;
|
|
534
|
+
if (E) {
|
|
535
|
+
const saved = E.stackTraceLimit;
|
|
536
|
+
if ("number" == typeof saved) {
|
|
537
|
+
try {
|
|
538
|
+
E.stackTraceLimit = 0;
|
|
539
|
+
} catch {
|
|
540
|
+
_E = null;
|
|
541
|
+
return new Definition();
|
|
542
|
+
}
|
|
543
|
+
try {
|
|
544
|
+
return new Definition();
|
|
545
|
+
} finally{
|
|
546
|
+
E.stackTraceLimit = saved;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return new Definition();
|
|
551
|
+
}
|
|
552
|
+
function $constructor(name, initializer, proto, params) {
|
|
553
|
+
const zodProto = {};
|
|
554
|
+
function Internals(def) {
|
|
555
|
+
this.def = def;
|
|
556
|
+
this.constr = _;
|
|
557
|
+
this.traits = new Set();
|
|
558
|
+
}
|
|
559
|
+
Internals.prototype = zodProto;
|
|
560
|
+
const protoMembers = proto;
|
|
561
|
+
const initialized = protoMembers && new WeakSet();
|
|
562
|
+
function init(inst, def) {
|
|
563
|
+
if (inst._zod) {
|
|
564
|
+
if (inst._zod.traits.has(name)) return;
|
|
565
|
+
} else {
|
|
566
|
+
_zodDesc.value = new Internals(def);
|
|
567
|
+
try {
|
|
568
|
+
Object.defineProperty(inst, "_zod", _zodDesc);
|
|
569
|
+
} finally{
|
|
570
|
+
_zodDesc.value = void 0;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
inst._zod.traits.add(name);
|
|
574
|
+
initializer(inst, def);
|
|
575
|
+
if (initialized) {
|
|
576
|
+
const own = Object.getPrototypeOf(inst);
|
|
577
|
+
const ctorProto = inst._zod.constr.prototype;
|
|
578
|
+
let up = own;
|
|
579
|
+
while(up && up !== ctorProto)up = Object.getPrototypeOf(up);
|
|
580
|
+
const target = up ?? own;
|
|
581
|
+
if (!initialized.has(target)) {
|
|
582
|
+
initialized.add(target);
|
|
583
|
+
util_members(target, protoMembers);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
const proto = _.prototype;
|
|
587
|
+
for(const k in proto)if (Object.prototype.hasOwnProperty.call(proto, k)) {
|
|
588
|
+
if (!(k in inst)) inst[k] = proto[k].bind(inst);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
const Parent = params?.Parent ?? Object;
|
|
592
|
+
class Definition extends Parent {
|
|
593
|
+
}
|
|
594
|
+
Object.defineProperty(Definition, "name", {
|
|
595
|
+
value: name
|
|
596
|
+
});
|
|
597
|
+
function _(def) {
|
|
598
|
+
const inst = params?.Parent ? newError(Definition) : this;
|
|
599
|
+
init(inst, def);
|
|
600
|
+
const deferred = inst._zod.deferred;
|
|
601
|
+
if (deferred) {
|
|
602
|
+
for (const fn of deferred)fn();
|
|
603
|
+
inst._zod.deferred = void 0;
|
|
604
|
+
}
|
|
605
|
+
const pp = globalThis.__zod_globalConfig?.postProcessor;
|
|
606
|
+
if (pp) pp(inst);
|
|
607
|
+
return inst;
|
|
608
|
+
}
|
|
609
|
+
Object.defineProperty(_, "init", {
|
|
610
|
+
value: init
|
|
611
|
+
});
|
|
612
|
+
Object.defineProperty(_, Symbol.hasInstance, {
|
|
613
|
+
value: (inst)=>{
|
|
614
|
+
if (params?.Parent && inst instanceof params.Parent) return true;
|
|
615
|
+
return inst?._zod?.traits?.has(name);
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
Object.defineProperty(_, "name", {
|
|
619
|
+
value: name
|
|
620
|
+
});
|
|
621
|
+
return _;
|
|
622
|
+
}
|
|
623
|
+
class $ZodAsyncError extends Error {
|
|
624
|
+
constructor(){
|
|
625
|
+
super("Encountered Promise during synchronous parse. Use .parseAsync() instead.");
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
class $ZodEncodeError extends Error {
|
|
629
|
+
constructor(name){
|
|
630
|
+
super(`Encountered unidirectional transform during encode: ${name}`);
|
|
631
|
+
this.name = "ZodEncodeError";
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
(core_a = globalThis).__zod_globalConfig ?? (core_a.__zod_globalConfig = {});
|
|
635
|
+
const globalConfig = globalThis.__zod_globalConfig;
|
|
636
|
+
function core_config(newConfig) {
|
|
637
|
+
if (newConfig) Object.assign(globalConfig, newConfig);
|
|
638
|
+
return globalConfig;
|
|
639
|
+
}
|
|
640
|
+
class $ZodCyclicError extends Error {
|
|
641
|
+
constructor(){
|
|
642
|
+
super("Cannot parse a reference cycle that closes through a transform");
|
|
643
|
+
this.name = "ZodCyclicError";
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
const STATE = "~memo";
|
|
647
|
+
const NO_ISSUES = [];
|
|
648
|
+
function isRef(value) {
|
|
649
|
+
return null !== value && "object" == typeof value;
|
|
650
|
+
}
|
|
651
|
+
function cloneIssues(issues) {
|
|
652
|
+
return issues.map((iss)=>iss.path ? {
|
|
653
|
+
...iss,
|
|
654
|
+
path: iss.path.slice()
|
|
655
|
+
} : {
|
|
656
|
+
...iss
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
const recursive = /*@__PURE__*/ new WeakMap();
|
|
660
|
+
const NONE = 0;
|
|
661
|
+
const ASSUMED = 1;
|
|
662
|
+
const PROVEN = 2;
|
|
663
|
+
function isRecursive(inst, stack, resolve) {
|
|
664
|
+
const cached = recursive.get(inst);
|
|
665
|
+
if (void 0 !== cached) return cached ? PROVEN : NONE;
|
|
666
|
+
if (stack.has(inst)) return PROVEN;
|
|
667
|
+
stack.add(inst);
|
|
668
|
+
let result = NONE;
|
|
669
|
+
const check = (child)=>{
|
|
670
|
+
if (result !== PROVEN && child?._zod) {
|
|
671
|
+
const answer = isRecursive(child, stack, resolve);
|
|
672
|
+
if (answer > result) result = answer;
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
const shape = (sh, spread)=>{
|
|
676
|
+
let answer = NONE;
|
|
677
|
+
for (const key of Reflect.ownKeys(sh)){
|
|
678
|
+
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
679
|
+
if (spread && !desc.enumerable) continue;
|
|
680
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve) : NONE;
|
|
681
|
+
if (child > answer) answer = child;
|
|
682
|
+
}
|
|
683
|
+
return answer;
|
|
684
|
+
};
|
|
685
|
+
const merge = (answer)=>{
|
|
686
|
+
if (answer > result) result = answer;
|
|
687
|
+
};
|
|
688
|
+
const def = inst._zod.def;
|
|
689
|
+
const kind = def.type;
|
|
690
|
+
switch(kind){
|
|
691
|
+
case "object":
|
|
692
|
+
{
|
|
693
|
+
const raw = rawShape(def);
|
|
694
|
+
merge(raw ? shape(raw, true) : ASSUMED);
|
|
695
|
+
check(def.catchall);
|
|
696
|
+
break;
|
|
697
|
+
}
|
|
698
|
+
case "array":
|
|
699
|
+
check(def.element);
|
|
700
|
+
break;
|
|
701
|
+
case "tuple":
|
|
702
|
+
for (const el of def.items)check(el);
|
|
703
|
+
check(def.rest);
|
|
704
|
+
break;
|
|
705
|
+
case "record":
|
|
706
|
+
case "map":
|
|
707
|
+
check(def.keyType);
|
|
708
|
+
check(def.valueType);
|
|
709
|
+
break;
|
|
710
|
+
case "set":
|
|
711
|
+
check(def.valueType);
|
|
712
|
+
break;
|
|
713
|
+
case "union":
|
|
714
|
+
for (const el of def.options)check(el);
|
|
715
|
+
break;
|
|
716
|
+
case "intersection":
|
|
717
|
+
check(def.left);
|
|
718
|
+
check(def.right);
|
|
719
|
+
break;
|
|
720
|
+
case "optional":
|
|
721
|
+
case "nullable":
|
|
722
|
+
case "default":
|
|
723
|
+
case "prefault":
|
|
724
|
+
case "catch":
|
|
725
|
+
case "readonly":
|
|
726
|
+
case "nonoptional":
|
|
727
|
+
case "promise":
|
|
728
|
+
case "success":
|
|
729
|
+
check(def.innerType);
|
|
730
|
+
break;
|
|
731
|
+
case "pipe":
|
|
732
|
+
check(def.in);
|
|
733
|
+
check(def.out);
|
|
734
|
+
break;
|
|
735
|
+
case "function":
|
|
736
|
+
check(def.input);
|
|
737
|
+
check(def.output);
|
|
738
|
+
break;
|
|
739
|
+
case "lazy":
|
|
740
|
+
{
|
|
741
|
+
const inner = def._cachedInner ?? (resolve ? inst._zod.innerType : void 0);
|
|
742
|
+
merge(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
743
|
+
break;
|
|
744
|
+
}
|
|
745
|
+
case "template_literal":
|
|
746
|
+
case "string":
|
|
747
|
+
case "number":
|
|
748
|
+
case "int":
|
|
749
|
+
case "boolean":
|
|
750
|
+
case "bigint":
|
|
751
|
+
case "symbol":
|
|
752
|
+
case "undefined":
|
|
753
|
+
case "null":
|
|
754
|
+
case "void":
|
|
755
|
+
case "never":
|
|
756
|
+
case "any":
|
|
757
|
+
case "unknown":
|
|
758
|
+
case "date":
|
|
759
|
+
case "nan":
|
|
760
|
+
case "enum":
|
|
761
|
+
case "literal":
|
|
762
|
+
case "file":
|
|
763
|
+
case "transform":
|
|
764
|
+
case "custom":
|
|
765
|
+
break;
|
|
766
|
+
default:
|
|
767
|
+
for(const key in def){
|
|
768
|
+
const desc = Object.getOwnPropertyDescriptor(def, key);
|
|
769
|
+
if (!desc || desc.get) continue;
|
|
770
|
+
const value = desc.value;
|
|
771
|
+
if (value && "object" == typeof value) {
|
|
772
|
+
if (value._zod) check(value);
|
|
773
|
+
else if (Array.isArray(value)) for (const el of value)check(el);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
stack.delete(inst);
|
|
778
|
+
return settle(inst, result);
|
|
779
|
+
}
|
|
780
|
+
function settle(inst, answer) {
|
|
781
|
+
if (answer !== ASSUMED) recursive.set(inst, answer === PROVEN);
|
|
782
|
+
return answer;
|
|
783
|
+
}
|
|
784
|
+
function bucketFor(state, inst) {
|
|
785
|
+
let bucket = state.buckets.get(inst);
|
|
786
|
+
if (!bucket) {
|
|
787
|
+
bucket = new WeakMap();
|
|
788
|
+
state.buckets.set(inst, bucket);
|
|
789
|
+
}
|
|
790
|
+
return bucket;
|
|
791
|
+
}
|
|
792
|
+
let handoff;
|
|
793
|
+
const memoizer_open = [];
|
|
794
|
+
const memoizer_memo = {
|
|
795
|
+
alloc (_inst, payload, empty) {
|
|
796
|
+
const bucket = handoff;
|
|
797
|
+
if (!bucket) return empty;
|
|
798
|
+
handoff = void 0;
|
|
799
|
+
const entry = {
|
|
800
|
+
value: empty,
|
|
801
|
+
issues: null
|
|
802
|
+
};
|
|
803
|
+
bucket.set(payload.value, entry);
|
|
804
|
+
memoizer_open.push(entry);
|
|
805
|
+
return empty;
|
|
806
|
+
},
|
|
807
|
+
guard (inst) {
|
|
808
|
+
var _a;
|
|
809
|
+
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
810
|
+
inst._zod.deferred.push(()=>{
|
|
811
|
+
const base = inst._zod.parse;
|
|
812
|
+
const wrapped = (payload, ctx)=>{
|
|
813
|
+
if ("backward" !== ctx.direction && isBackEdge(ctx, payload.value)) throw new $ZodCyclicError();
|
|
814
|
+
return base(payload, ctx);
|
|
815
|
+
};
|
|
816
|
+
inst._zod.parse = wrapped;
|
|
817
|
+
if (inst._zod.run === base) inst._zod.run = wrapped;
|
|
818
|
+
});
|
|
819
|
+
},
|
|
820
|
+
attach (inst) {
|
|
821
|
+
var _a;
|
|
822
|
+
let isRecursiveInst;
|
|
823
|
+
let rechecked = false;
|
|
824
|
+
let lastCtx;
|
|
825
|
+
let lastBucket;
|
|
826
|
+
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
827
|
+
inst._zod.deferred.push(()=>{
|
|
828
|
+
const base = inst._zod.parse;
|
|
829
|
+
const wrapped = (payload, ctx)=>{
|
|
830
|
+
if (void 0 === isRecursiveInst) {
|
|
831
|
+
const walked = isRecursive(inst, new Set(), false);
|
|
832
|
+
if (walked === NONE) {
|
|
833
|
+
inst._zod.parse = base;
|
|
834
|
+
if (inst._zod.run === wrapped) inst._zod.run = base;
|
|
835
|
+
return base(payload, ctx);
|
|
836
|
+
}
|
|
837
|
+
if (walked === PROVEN || rechecked) isRecursiveInst = true;
|
|
838
|
+
else rechecked = true;
|
|
839
|
+
}
|
|
840
|
+
const input = payload.value;
|
|
841
|
+
if (!isRef(input)) return base(payload, ctx);
|
|
842
|
+
let state = ctx[STATE];
|
|
843
|
+
if (!state) {
|
|
844
|
+
state = {
|
|
845
|
+
buckets: new WeakMap(),
|
|
846
|
+
backEdges: void 0
|
|
847
|
+
};
|
|
848
|
+
ctx[STATE] = state;
|
|
849
|
+
}
|
|
850
|
+
let bucket;
|
|
851
|
+
if (lastCtx === ctx) bucket = lastBucket;
|
|
852
|
+
else {
|
|
853
|
+
bucket = bucketFor(state, inst);
|
|
854
|
+
lastCtx = ctx;
|
|
855
|
+
lastBucket = bucket;
|
|
856
|
+
}
|
|
857
|
+
const hit = bucket.get(input);
|
|
858
|
+
if (hit) {
|
|
859
|
+
payload.value = hit.value;
|
|
860
|
+
if (hit.issues) {
|
|
861
|
+
if (hit.issues.length) payload.issues.push(...cloneIssues(hit.issues));
|
|
862
|
+
} else {
|
|
863
|
+
payload.memo = true;
|
|
864
|
+
state.backEdges ?? (state.backEdges = new WeakSet());
|
|
865
|
+
state.backEdges.add(hit.value);
|
|
866
|
+
}
|
|
867
|
+
return payload;
|
|
868
|
+
}
|
|
869
|
+
handoff = bucket;
|
|
870
|
+
const depth = memoizer_open.length;
|
|
871
|
+
const result = base(payload, ctx);
|
|
872
|
+
handoff = void 0;
|
|
873
|
+
const entry = memoizer_open.length > depth ? memoizer_open.pop() : void 0;
|
|
874
|
+
if (result instanceof Promise) return result.then((r)=>{
|
|
875
|
+
if (entry) entry.issues = r.issues.length ? cloneIssues(r.issues) : NO_ISSUES;
|
|
876
|
+
return r;
|
|
877
|
+
});
|
|
878
|
+
if (entry) entry.issues = result.issues.length ? cloneIssues(result.issues) : NO_ISSUES;
|
|
879
|
+
return result;
|
|
880
|
+
};
|
|
881
|
+
inst._zod.parse = wrapped;
|
|
882
|
+
if (inst._zod.run === base) inst._zod.run = wrapped;
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
function memoizer() {
|
|
887
|
+
return memoizer_memo;
|
|
888
|
+
}
|
|
889
|
+
function isBackEdge(ctx, value) {
|
|
890
|
+
const backEdges = ctx[STATE]?.backEdges;
|
|
891
|
+
return void 0 !== backEdges && isRef(value) && backEdges.has(value);
|
|
892
|
+
}
|
|
893
|
+
const cuid = /^[cC][0-9a-z]{6,}$/;
|
|
894
|
+
const cuid2 = /^[0-9a-z]+$/;
|
|
895
|
+
const ulid = /^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/;
|
|
896
|
+
const xid = /^[0-9a-vA-V]{20}$/;
|
|
897
|
+
const ksuid = /^[A-Za-z0-9]{27}$/;
|
|
898
|
+
const nanoid = /^[a-zA-Z0-9_-]{21}$/;
|
|
899
|
+
function nanoidOfLength(length) {
|
|
900
|
+
return new RegExp(`^[a-zA-Z0-9_-]{${length}}$`);
|
|
901
|
+
}
|
|
902
|
+
const duration = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
|
|
903
|
+
const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
|
|
904
|
+
const uuid = (version)=>{
|
|
905
|
+
if (!version) return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
|
|
906
|
+
return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
|
|
907
|
+
};
|
|
908
|
+
const email = /^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
|
|
909
|
+
const _emoji = "^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$";
|
|
910
|
+
function emoji() {
|
|
911
|
+
return new RegExp(_emoji, "u");
|
|
912
|
+
}
|
|
913
|
+
const ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
914
|
+
const ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
|
|
915
|
+
const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
|
|
916
|
+
const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
917
|
+
const regexes_base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
|
918
|
+
const regexes_base64url = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;
|
|
919
|
+
const httpProtocol = /^https?$/;
|
|
920
|
+
const e164 = /^\+[1-9]\d{6,14}$/;
|
|
921
|
+
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])))";
|
|
922
|
+
/** Anchors a pattern source. The interpolation lives here rather than at the call site because
|
|
923
|
+
* esbuild will not drop a `@__PURE__` call whose own argument interpolates a variable, but it
|
|
924
|
+
* will drop `anchor(dateSource)`. Keeping it inline pinned `date` into every bundle. */ function regexes_anchor(source) {
|
|
925
|
+
return new RegExp(`^${source}$`);
|
|
926
|
+
}
|
|
927
|
+
const date = /*@__PURE__*/ regexes_anchor(dateSource);
|
|
928
|
+
function timeSource(args) {
|
|
929
|
+
const hhmm = "(?:[01]\\d|2[0-3]):[0-5]\\d";
|
|
930
|
+
const regex = "number" == typeof args.precision ? -1 === args.precision ? `${hhmm}` : 0 === args.precision ? `${hhmm}:[0-5]\\d` : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}` : args.seconds ? `${hhmm}:[0-5]\\d(?:\\.\\d+)?` : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
|
|
931
|
+
return regex;
|
|
932
|
+
}
|
|
933
|
+
function time(args) {
|
|
934
|
+
return new RegExp(`^${timeSource(args)}$`);
|
|
935
|
+
}
|
|
936
|
+
function datetime(args) {
|
|
937
|
+
const opts = [
|
|
938
|
+
"Z"
|
|
939
|
+
];
|
|
940
|
+
if (args.offset) opts.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");
|
|
941
|
+
const qualified = `${timeSource({
|
|
942
|
+
precision: args.precision,
|
|
943
|
+
seconds: true
|
|
944
|
+
})}(?:${opts.join("|")})`;
|
|
945
|
+
const timeRegex = args.local ? `${qualified}|${timeSource({
|
|
946
|
+
precision: args.precision
|
|
947
|
+
})}` : qualified;
|
|
948
|
+
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
|
|
949
|
+
}
|
|
950
|
+
const anyString = /^[\s\S]{0,}$/;
|
|
951
|
+
const regexes_boolean = /^(?:true|false)$/i;
|
|
952
|
+
const lowercase = /^[^A-Z]*$/;
|
|
953
|
+
const uppercase = /^[^a-z]*$/;
|
|
954
|
+
const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def)=>{
|
|
955
|
+
var _a;
|
|
956
|
+
inst._zod ?? (inst._zod = {});
|
|
957
|
+
inst._zod.def = def;
|
|
958
|
+
(_a = inst._zod).onattach ?? (_a.onattach = []);
|
|
959
|
+
});
|
|
960
|
+
const _whenHasLength = (payload)=>{
|
|
961
|
+
const val = payload.value;
|
|
962
|
+
return !nullish(val) && void 0 !== val.length;
|
|
963
|
+
};
|
|
964
|
+
const $ZodCheckMaxLength = /*@__PURE__*/ $constructor("$ZodCheckMaxLength", (inst, def)=>{
|
|
965
|
+
var _a;
|
|
966
|
+
$ZodCheck.init(inst, def);
|
|
967
|
+
(_a = inst._zod.def).when ?? (_a.when = _whenHasLength);
|
|
968
|
+
inst._zod.check = (payload)=>{
|
|
969
|
+
const input = payload.value;
|
|
970
|
+
const units = input.length;
|
|
971
|
+
const length = "string" == typeof input && units > def.maximum ? codePointLength(input) : units;
|
|
972
|
+
if (length <= def.maximum) return;
|
|
973
|
+
const origin = getLengthableOrigin(input);
|
|
974
|
+
payload.issues.push({
|
|
975
|
+
origin,
|
|
976
|
+
code: "too_big",
|
|
977
|
+
maximum: def.maximum,
|
|
978
|
+
inclusive: true,
|
|
979
|
+
input,
|
|
980
|
+
inst,
|
|
981
|
+
continue: !def.abort
|
|
982
|
+
});
|
|
983
|
+
};
|
|
984
|
+
});
|
|
985
|
+
const $ZodCheckMinLength = /*@__PURE__*/ $constructor("$ZodCheckMinLength", (inst, def)=>{
|
|
986
|
+
var _a;
|
|
987
|
+
$ZodCheck.init(inst, def);
|
|
988
|
+
(_a = inst._zod.def).when ?? (_a.when = _whenHasLength);
|
|
989
|
+
inst._zod.check = (payload)=>{
|
|
990
|
+
const input = payload.value;
|
|
991
|
+
const units = input.length;
|
|
992
|
+
const length = "string" == typeof input && units >= def.minimum && units < 2 * def.minimum ? codePointLength(input) : units;
|
|
993
|
+
if (length >= def.minimum) return;
|
|
994
|
+
const origin = getLengthableOrigin(input);
|
|
995
|
+
payload.issues.push({
|
|
996
|
+
origin,
|
|
997
|
+
code: "too_small",
|
|
998
|
+
minimum: def.minimum,
|
|
999
|
+
inclusive: true,
|
|
1000
|
+
input,
|
|
1001
|
+
inst,
|
|
1002
|
+
continue: !def.abort
|
|
1003
|
+
});
|
|
1004
|
+
};
|
|
1005
|
+
});
|
|
1006
|
+
const $ZodCheckLengthEquals = /*@__PURE__*/ $constructor("$ZodCheckLengthEquals", (inst, def)=>{
|
|
1007
|
+
var _a;
|
|
1008
|
+
$ZodCheck.init(inst, def);
|
|
1009
|
+
(_a = inst._zod.def).when ?? (_a.when = _whenHasLength);
|
|
1010
|
+
inst._zod.check = (payload)=>{
|
|
1011
|
+
const input = payload.value;
|
|
1012
|
+
const units = input.length;
|
|
1013
|
+
const length = "string" == typeof input && units >= def.length && units <= 2 * def.length ? codePointLength(input) : units;
|
|
1014
|
+
if (length === def.length) return;
|
|
1015
|
+
const origin = getLengthableOrigin(input);
|
|
1016
|
+
const tooBig = length > def.length;
|
|
1017
|
+
payload.issues.push({
|
|
1018
|
+
origin,
|
|
1019
|
+
...tooBig ? {
|
|
1020
|
+
code: "too_big",
|
|
1021
|
+
maximum: def.length
|
|
1022
|
+
} : {
|
|
1023
|
+
code: "too_small",
|
|
1024
|
+
minimum: def.length
|
|
548
1025
|
},
|
|
549
1026
|
inclusive: true,
|
|
550
1027
|
exact: true,
|
|
@@ -557,14 +1034,6 @@ const $ZodCheckLengthEquals = /*@__PURE__*/ $constructor("$ZodCheckLengthEquals"
|
|
|
557
1034
|
const $ZodCheckStringFormat = /*@__PURE__*/ $constructor("$ZodCheckStringFormat", (inst, def)=>{
|
|
558
1035
|
var _a, _b;
|
|
559
1036
|
$ZodCheck.init(inst, def);
|
|
560
|
-
inst._zod.onattach.push((inst)=>{
|
|
561
|
-
const bag = inst._zod.bag;
|
|
562
|
-
bag.format = def.format;
|
|
563
|
-
if (def.pattern) {
|
|
564
|
-
bag.patterns ?? (bag.patterns = new Set());
|
|
565
|
-
bag.patterns.add(def.pattern);
|
|
566
|
-
}
|
|
567
|
-
});
|
|
568
1037
|
if (def.pattern) (_a = inst._zod).check ?? (_a.check = (payload)=>{
|
|
569
1038
|
def.pattern.lastIndex = 0;
|
|
570
1039
|
if (def.pattern.test(payload.value)) return;
|
|
@@ -609,13 +1078,8 @@ const $ZodCheckUpperCase = /*@__PURE__*/ $constructor("$ZodCheckUpperCase", (ins
|
|
|
609
1078
|
const $ZodCheckIncludes = /*@__PURE__*/ $constructor("$ZodCheckIncludes", (inst, def)=>{
|
|
610
1079
|
$ZodCheck.init(inst, def);
|
|
611
1080
|
const escapedRegex = escapeRegex(def.includes);
|
|
612
|
-
const pattern = new RegExp("number" == typeof def.position ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
|
|
1081
|
+
const pattern = new RegExp("number" == typeof def.position ? `^.{${def.position},}${escapedRegex}` : escapedRegex);
|
|
613
1082
|
def.pattern = pattern;
|
|
614
|
-
inst._zod.onattach.push((inst)=>{
|
|
615
|
-
const bag = inst._zod.bag;
|
|
616
|
-
bag.patterns ?? (bag.patterns = new Set());
|
|
617
|
-
bag.patterns.add(pattern);
|
|
618
|
-
});
|
|
619
1083
|
inst._zod.check = (payload)=>{
|
|
620
1084
|
if (payload.value.includes(def.includes, def.position)) return;
|
|
621
1085
|
payload.issues.push({
|
|
@@ -633,11 +1097,6 @@ const $ZodCheckStartsWith = /*@__PURE__*/ $constructor("$ZodCheckStartsWith", (i
|
|
|
633
1097
|
$ZodCheck.init(inst, def);
|
|
634
1098
|
const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
|
|
635
1099
|
def.pattern ?? (def.pattern = pattern);
|
|
636
|
-
inst._zod.onattach.push((inst)=>{
|
|
637
|
-
const bag = inst._zod.bag;
|
|
638
|
-
bag.patterns ?? (bag.patterns = new Set());
|
|
639
|
-
bag.patterns.add(pattern);
|
|
640
|
-
});
|
|
641
1100
|
inst._zod.check = (payload)=>{
|
|
642
1101
|
if (payload.value.startsWith(def.prefix)) return;
|
|
643
1102
|
payload.issues.push({
|
|
@@ -646,286 +1105,78 @@ const $ZodCheckStartsWith = /*@__PURE__*/ $constructor("$ZodCheckStartsWith", (i
|
|
|
646
1105
|
format: "starts_with",
|
|
647
1106
|
prefix: def.prefix,
|
|
648
1107
|
input: payload.value,
|
|
649
|
-
inst,
|
|
650
|
-
continue: !def.abort
|
|
651
|
-
});
|
|
652
|
-
};
|
|
653
|
-
});
|
|
654
|
-
const $ZodCheckEndsWith = /*@__PURE__*/ $constructor("$ZodCheckEndsWith", (inst, def)=>{
|
|
655
|
-
$ZodCheck.init(inst, def);
|
|
656
|
-
const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
|
|
657
|
-
def.pattern ?? (def.pattern = pattern);
|
|
658
|
-
inst._zod.onattach.push((inst)=>{
|
|
659
|
-
const bag = inst._zod.bag;
|
|
660
|
-
bag.patterns ?? (bag.patterns = new Set());
|
|
661
|
-
bag.patterns.add(pattern);
|
|
662
|
-
});
|
|
663
|
-
inst._zod.check = (payload)=>{
|
|
664
|
-
if (payload.value.endsWith(def.suffix)) return;
|
|
665
|
-
payload.issues.push({
|
|
666
|
-
origin: "string",
|
|
667
|
-
code: "invalid_format",
|
|
668
|
-
format: "ends_with",
|
|
669
|
-
suffix: def.suffix,
|
|
670
|
-
input: payload.value,
|
|
671
|
-
inst,
|
|
672
|
-
continue: !def.abort
|
|
673
|
-
});
|
|
674
|
-
};
|
|
675
|
-
});
|
|
676
|
-
const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (inst, def)=>{
|
|
677
|
-
$ZodCheck.init(inst, def);
|
|
678
|
-
inst._zod.check = (payload)=>{
|
|
679
|
-
payload.value = def.tx(payload.value);
|
|
680
|
-
};
|
|
681
|
-
});
|
|
682
|
-
class Doc {
|
|
683
|
-
constructor(args = []){
|
|
684
|
-
this.content = [];
|
|
685
|
-
this.indent = 0;
|
|
686
|
-
if (this) this.args = args;
|
|
687
|
-
}
|
|
688
|
-
indented(fn) {
|
|
689
|
-
this.indent += 1;
|
|
690
|
-
fn(this);
|
|
691
|
-
this.indent -= 1;
|
|
692
|
-
}
|
|
693
|
-
write(arg) {
|
|
694
|
-
if ("function" == typeof arg) {
|
|
695
|
-
arg(this, {
|
|
696
|
-
execution: "sync"
|
|
697
|
-
});
|
|
698
|
-
arg(this, {
|
|
699
|
-
execution: "async"
|
|
700
|
-
});
|
|
701
|
-
return;
|
|
702
|
-
}
|
|
703
|
-
const content = arg;
|
|
704
|
-
const lines = content.split("\n").filter((x)=>x);
|
|
705
|
-
const minIndent = Math.min(...lines.map((x)=>x.length - x.trimStart().length));
|
|
706
|
-
const dedented = lines.map((x)=>x.slice(minIndent)).map((x)=>" ".repeat(2 * this.indent) + x);
|
|
707
|
-
for (const line of dedented)this.content.push(line);
|
|
708
|
-
}
|
|
709
|
-
compile() {
|
|
710
|
-
const F = Function;
|
|
711
|
-
const args = this?.args;
|
|
712
|
-
const content = this?.content ?? [
|
|
713
|
-
""
|
|
714
|
-
];
|
|
715
|
-
const lines = [
|
|
716
|
-
...content.map((x)=>` ${x}`)
|
|
717
|
-
];
|
|
718
|
-
return new F(...args, lines.join("\n"));
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
const errors_initializer = (inst, def)=>{
|
|
722
|
-
inst.name = "$ZodError";
|
|
723
|
-
Object.defineProperty(inst, "_zod", {
|
|
724
|
-
value: inst._zod,
|
|
725
|
-
enumerable: false
|
|
726
|
-
});
|
|
727
|
-
Object.defineProperty(inst, "issues", {
|
|
728
|
-
value: def,
|
|
729
|
-
enumerable: false
|
|
730
|
-
});
|
|
731
|
-
inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
|
|
732
|
-
Object.defineProperty(inst, "toString", {
|
|
733
|
-
value: ()=>inst.message,
|
|
734
|
-
enumerable: false
|
|
735
|
-
});
|
|
736
|
-
};
|
|
737
|
-
const $ZodError = $constructor("$ZodError", errors_initializer);
|
|
738
|
-
const $ZodRealError = $constructor("$ZodError", errors_initializer, {
|
|
739
|
-
Parent: Error
|
|
740
|
-
});
|
|
741
|
-
function flattenError(error, mapper = (issue)=>issue.message) {
|
|
742
|
-
const fieldErrors = {};
|
|
743
|
-
const formErrors = [];
|
|
744
|
-
for (const sub of error.issues)if (sub.path.length > 0) {
|
|
745
|
-
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
746
|
-
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
747
|
-
} else formErrors.push(mapper(sub));
|
|
748
|
-
return {
|
|
749
|
-
formErrors,
|
|
750
|
-
fieldErrors
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
function formatError(error, mapper = (issue)=>issue.message) {
|
|
754
|
-
const fieldErrors = {
|
|
755
|
-
_errors: []
|
|
756
|
-
};
|
|
757
|
-
const processError = (error, path = [])=>{
|
|
758
|
-
for (const issue of error.issues)if ("invalid_union" === issue.code && issue.errors.length) issue.errors.map((issues)=>processError({
|
|
759
|
-
issues
|
|
760
|
-
}, [
|
|
761
|
-
...path,
|
|
762
|
-
...issue.path
|
|
763
|
-
]));
|
|
764
|
-
else if ("invalid_key" === issue.code) processError({
|
|
765
|
-
issues: issue.issues
|
|
766
|
-
}, [
|
|
767
|
-
...path,
|
|
768
|
-
...issue.path
|
|
769
|
-
]);
|
|
770
|
-
else if ("invalid_element" === issue.code) processError({
|
|
771
|
-
issues: issue.issues
|
|
772
|
-
}, [
|
|
773
|
-
...path,
|
|
774
|
-
...issue.path
|
|
775
|
-
]);
|
|
776
|
-
else {
|
|
777
|
-
const fullpath = [
|
|
778
|
-
...path,
|
|
779
|
-
...issue.path
|
|
780
|
-
];
|
|
781
|
-
if (0 === fullpath.length) fieldErrors._errors.push(mapper(issue));
|
|
782
|
-
else {
|
|
783
|
-
let curr = fieldErrors;
|
|
784
|
-
let i = 0;
|
|
785
|
-
while(i < fullpath.length){
|
|
786
|
-
const el = fullpath[i];
|
|
787
|
-
const terminal = i === fullpath.length - 1;
|
|
788
|
-
if (terminal) {
|
|
789
|
-
curr[el] = curr[el] || {
|
|
790
|
-
_errors: []
|
|
791
|
-
};
|
|
792
|
-
curr[el]._errors.push(mapper(issue));
|
|
793
|
-
} else curr[el] = curr[el] || {
|
|
794
|
-
_errors: []
|
|
795
|
-
};
|
|
796
|
-
curr = curr[el];
|
|
797
|
-
i++;
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
};
|
|
802
|
-
processError(error);
|
|
803
|
-
return fieldErrors;
|
|
804
|
-
}
|
|
805
|
-
const _parse = (_Err)=>(schema, value, _ctx, _params)=>{
|
|
806
|
-
const ctx = _ctx ? {
|
|
807
|
-
..._ctx,
|
|
808
|
-
async: false
|
|
809
|
-
} : {
|
|
810
|
-
async: false
|
|
811
|
-
};
|
|
812
|
-
const result = schema._zod.run({
|
|
813
|
-
value,
|
|
814
|
-
issues: []
|
|
815
|
-
}, ctx);
|
|
816
|
-
if (result instanceof Promise) throw new $ZodAsyncError();
|
|
817
|
-
if (result.issues.length) {
|
|
818
|
-
const e = new (_params?.Err ?? _Err)(result.issues.map((iss)=>finalizeIssue(iss, ctx, core_config())));
|
|
819
|
-
captureStackTrace(e, _params?.callee);
|
|
820
|
-
throw e;
|
|
821
|
-
}
|
|
822
|
-
return result.value;
|
|
823
|
-
};
|
|
824
|
-
const _parseAsync = (_Err)=>async (schema, value, _ctx, params)=>{
|
|
825
|
-
const ctx = _ctx ? {
|
|
826
|
-
..._ctx,
|
|
827
|
-
async: true
|
|
828
|
-
} : {
|
|
829
|
-
async: true
|
|
830
|
-
};
|
|
831
|
-
let result = schema._zod.run({
|
|
832
|
-
value,
|
|
833
|
-
issues: []
|
|
834
|
-
}, ctx);
|
|
835
|
-
if (result instanceof Promise) result = await result;
|
|
836
|
-
if (result.issues.length) {
|
|
837
|
-
const e = new (params?.Err ?? _Err)(result.issues.map((iss)=>finalizeIssue(iss, ctx, core_config())));
|
|
838
|
-
captureStackTrace(e, params?.callee);
|
|
839
|
-
throw e;
|
|
840
|
-
}
|
|
841
|
-
return result.value;
|
|
842
|
-
};
|
|
843
|
-
const _safeParse = (_Err)=>(schema, value, _ctx)=>{
|
|
844
|
-
const ctx = _ctx ? {
|
|
845
|
-
..._ctx,
|
|
846
|
-
async: false
|
|
847
|
-
} : {
|
|
848
|
-
async: false
|
|
849
|
-
};
|
|
850
|
-
const result = schema._zod.run({
|
|
851
|
-
value,
|
|
852
|
-
issues: []
|
|
853
|
-
}, ctx);
|
|
854
|
-
if (result instanceof Promise) throw new $ZodAsyncError();
|
|
855
|
-
return result.issues.length ? {
|
|
856
|
-
success: false,
|
|
857
|
-
error: new (_Err ?? $ZodError)(result.issues.map((iss)=>finalizeIssue(iss, ctx, core_config())))
|
|
858
|
-
} : {
|
|
859
|
-
success: true,
|
|
860
|
-
data: result.value
|
|
861
|
-
};
|
|
862
|
-
};
|
|
863
|
-
const safeParse = /* @__PURE__*/ _safeParse($ZodRealError);
|
|
864
|
-
const _safeParseAsync = (_Err)=>async (schema, value, _ctx)=>{
|
|
865
|
-
const ctx = _ctx ? {
|
|
866
|
-
..._ctx,
|
|
867
|
-
async: true
|
|
868
|
-
} : {
|
|
869
|
-
async: true
|
|
870
|
-
};
|
|
871
|
-
let result = schema._zod.run({
|
|
872
|
-
value,
|
|
873
|
-
issues: []
|
|
874
|
-
}, ctx);
|
|
875
|
-
if (result instanceof Promise) result = await result;
|
|
876
|
-
return result.issues.length ? {
|
|
877
|
-
success: false,
|
|
878
|
-
error: new _Err(result.issues.map((iss)=>finalizeIssue(iss, ctx, core_config())))
|
|
879
|
-
} : {
|
|
880
|
-
success: true,
|
|
881
|
-
data: result.value
|
|
882
|
-
};
|
|
883
|
-
};
|
|
884
|
-
const safeParseAsync = /* @__PURE__*/ _safeParseAsync($ZodRealError);
|
|
885
|
-
const _encode = (_Err)=>(schema, value, _ctx)=>{
|
|
886
|
-
const ctx = _ctx ? {
|
|
887
|
-
..._ctx,
|
|
888
|
-
direction: "backward"
|
|
889
|
-
} : {
|
|
890
|
-
direction: "backward"
|
|
891
|
-
};
|
|
892
|
-
return _parse(_Err)(schema, value, ctx);
|
|
893
|
-
};
|
|
894
|
-
const _decode = (_Err)=>(schema, value, _ctx)=>_parse(_Err)(schema, value, _ctx);
|
|
895
|
-
const _encodeAsync = (_Err)=>async (schema, value, _ctx)=>{
|
|
896
|
-
const ctx = _ctx ? {
|
|
897
|
-
..._ctx,
|
|
898
|
-
direction: "backward"
|
|
899
|
-
} : {
|
|
900
|
-
direction: "backward"
|
|
901
|
-
};
|
|
902
|
-
return _parseAsync(_Err)(schema, value, ctx);
|
|
903
|
-
};
|
|
904
|
-
const _decodeAsync = (_Err)=>async (schema, value, _ctx)=>_parseAsync(_Err)(schema, value, _ctx);
|
|
905
|
-
const _safeEncode = (_Err)=>(schema, value, _ctx)=>{
|
|
906
|
-
const ctx = _ctx ? {
|
|
907
|
-
..._ctx,
|
|
908
|
-
direction: "backward"
|
|
909
|
-
} : {
|
|
910
|
-
direction: "backward"
|
|
911
|
-
};
|
|
912
|
-
return _safeParse(_Err)(schema, value, ctx);
|
|
1108
|
+
inst,
|
|
1109
|
+
continue: !def.abort
|
|
1110
|
+
});
|
|
913
1111
|
};
|
|
914
|
-
|
|
915
|
-
const
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
1112
|
+
});
|
|
1113
|
+
const $ZodCheckEndsWith = /*@__PURE__*/ $constructor("$ZodCheckEndsWith", (inst, def)=>{
|
|
1114
|
+
$ZodCheck.init(inst, def);
|
|
1115
|
+
const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
|
|
1116
|
+
def.pattern ?? (def.pattern = pattern);
|
|
1117
|
+
inst._zod.check = (payload)=>{
|
|
1118
|
+
if (payload.value.endsWith(def.suffix)) return;
|
|
1119
|
+
payload.issues.push({
|
|
1120
|
+
origin: "string",
|
|
1121
|
+
code: "invalid_format",
|
|
1122
|
+
format: "ends_with",
|
|
1123
|
+
suffix: def.suffix,
|
|
1124
|
+
input: payload.value,
|
|
1125
|
+
inst,
|
|
1126
|
+
continue: !def.abort
|
|
1127
|
+
});
|
|
923
1128
|
};
|
|
924
|
-
|
|
1129
|
+
});
|
|
1130
|
+
const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (inst, def)=>{
|
|
1131
|
+
$ZodCheck.init(inst, def);
|
|
1132
|
+
inst._zod.check = (payload)=>{
|
|
1133
|
+
payload.value = def.tx(payload.value);
|
|
1134
|
+
};
|
|
1135
|
+
});
|
|
1136
|
+
class Doc {
|
|
1137
|
+
constructor(args = [], closed = {}){
|
|
1138
|
+
this.content = [];
|
|
1139
|
+
this.indent = 0;
|
|
1140
|
+
this.args = args;
|
|
1141
|
+
this.closed = closed;
|
|
1142
|
+
}
|
|
1143
|
+
indented(fn) {
|
|
1144
|
+
this.indent += 1;
|
|
1145
|
+
try {
|
|
1146
|
+
fn(this);
|
|
1147
|
+
} finally{
|
|
1148
|
+
this.indent -= 1;
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
write(arg) {
|
|
1152
|
+
if ("function" == typeof arg) {
|
|
1153
|
+
arg(this, {
|
|
1154
|
+
execution: "sync"
|
|
1155
|
+
});
|
|
1156
|
+
arg(this, {
|
|
1157
|
+
execution: "async"
|
|
1158
|
+
});
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
const content = arg;
|
|
1162
|
+
const lines = content.split("\n").filter((x)=>x);
|
|
1163
|
+
const minIndent = Math.min(...lines.map((x)=>x.length - x.trimStart().length));
|
|
1164
|
+
const dedented = lines.map((x)=>x.slice(minIndent)).map((x)=>" ".repeat(2 * this.indent) + x);
|
|
1165
|
+
for (const line of dedented)this.content.push(line);
|
|
1166
|
+
}
|
|
1167
|
+
compile() {
|
|
1168
|
+
const F = Function;
|
|
1169
|
+
const content = this?.content ?? [
|
|
1170
|
+
""
|
|
1171
|
+
];
|
|
1172
|
+
const factory = new F(...Object.keys(this.closed), `return function (${this.args.join(", ")}) {\n${content.join("\n")}\n};`);
|
|
1173
|
+
return factory(...Object.values(this.closed));
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
925
1176
|
const versions_version = {
|
|
926
1177
|
major: 4,
|
|
927
|
-
minor:
|
|
928
|
-
patch:
|
|
1178
|
+
minor: 6,
|
|
1179
|
+
patch: 5
|
|
929
1180
|
};
|
|
930
1181
|
const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def)=>{
|
|
931
1182
|
var _a;
|
|
@@ -933,10 +1184,13 @@ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def)=>{
|
|
|
933
1184
|
inst._zod.def = def;
|
|
934
1185
|
inst._zod.bag = inst._zod.bag || {};
|
|
935
1186
|
inst._zod.version = versions_version;
|
|
936
|
-
const
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
1187
|
+
const defChecks = inst._zod.def.checks;
|
|
1188
|
+
const checks = inst._zod.traits.has("$ZodCheck") ? [
|
|
1189
|
+
inst,
|
|
1190
|
+
...defChecks ?? []
|
|
1191
|
+
] : defChecks?.length ? [
|
|
1192
|
+
...defChecks
|
|
1193
|
+
] : [];
|
|
940
1194
|
for (const ch of checks)for (const fn of ch._zod.onattach)fn(inst);
|
|
941
1195
|
if (0 === checks.length) {
|
|
942
1196
|
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
@@ -945,6 +1199,7 @@ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def)=>{
|
|
|
945
1199
|
});
|
|
946
1200
|
} else {
|
|
947
1201
|
const runChecks = (payload, checks, ctx)=>{
|
|
1202
|
+
if (payload.memo) return payload;
|
|
948
1203
|
let isAborted = aborted(payload);
|
|
949
1204
|
let asyncResult;
|
|
950
1205
|
for (const ch of checks){
|
|
@@ -960,11 +1215,13 @@ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def)=>{
|
|
|
960
1215
|
await _;
|
|
961
1216
|
const nextLen = payload.issues.length;
|
|
962
1217
|
if (nextLen === currLen) return;
|
|
1218
|
+
attachSchema(payload.issues, currLen, inst);
|
|
963
1219
|
if (!isAborted) isAborted = aborted(payload, currLen);
|
|
964
1220
|
});
|
|
965
1221
|
else {
|
|
966
1222
|
const nextLen = payload.issues.length;
|
|
967
1223
|
if (nextLen === currLen) continue;
|
|
1224
|
+
attachSchema(payload.issues, currLen, inst);
|
|
968
1225
|
if (!isAborted) isAborted = aborted(payload, currLen);
|
|
969
1226
|
}
|
|
970
1227
|
}
|
|
@@ -1004,32 +1261,50 @@ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def)=>{
|
|
|
1004
1261
|
return runChecks(result, checks, ctx);
|
|
1005
1262
|
};
|
|
1006
1263
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
issues: r.error?.issues
|
|
1015
|
-
};
|
|
1016
|
-
} catch (_) {
|
|
1017
|
-
return safeParseAsync(inst, value).then((r)=>r.success ? {
|
|
1018
|
-
value: r.data
|
|
1019
|
-
} : {
|
|
1020
|
-
issues: r.error?.issues
|
|
1021
|
-
});
|
|
1022
|
-
}
|
|
1023
|
-
},
|
|
1024
|
-
vendor: "zod",
|
|
1025
|
-
version: 1
|
|
1026
|
-
}));
|
|
1264
|
+
}, {
|
|
1265
|
+
get "~standard" () {
|
|
1266
|
+
return hide(this, "~standard", standardProps(this));
|
|
1267
|
+
},
|
|
1268
|
+
set "~standard" (value){
|
|
1269
|
+
util_own(this, "~standard", value);
|
|
1270
|
+
}
|
|
1027
1271
|
});
|
|
1272
|
+
const toStandardResult = (r, ctx)=>r.issues.length ? {
|
|
1273
|
+
issues: r.issues.map((iss)=>finalizeIssue(iss, ctx, core_config()))
|
|
1274
|
+
} : {
|
|
1275
|
+
value: r.value
|
|
1276
|
+
};
|
|
1277
|
+
async function validateAsync(inst, value) {
|
|
1278
|
+
const ctx = {
|
|
1279
|
+
async: true
|
|
1280
|
+
};
|
|
1281
|
+
return toStandardResult(await inst._zod.run({
|
|
1282
|
+
value,
|
|
1283
|
+
issues: []
|
|
1284
|
+
}, ctx), ctx);
|
|
1285
|
+
}
|
|
1286
|
+
function standardProps(inst) {
|
|
1287
|
+
return {
|
|
1288
|
+
validate: (value)=>{
|
|
1289
|
+
const ctx = {
|
|
1290
|
+
async: false
|
|
1291
|
+
};
|
|
1292
|
+
try {
|
|
1293
|
+
const r = inst._zod.run({
|
|
1294
|
+
value,
|
|
1295
|
+
issues: []
|
|
1296
|
+
}, ctx);
|
|
1297
|
+
if (!(r instanceof Promise)) return toStandardResult(r, ctx);
|
|
1298
|
+
} catch (_) {}
|
|
1299
|
+
return validateAsync(inst, value);
|
|
1300
|
+
},
|
|
1301
|
+
vendor: "zod",
|
|
1302
|
+
version: 1
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1028
1305
|
const $ZodString = /*@__PURE__*/ $constructor("$ZodString", (inst, def)=>{
|
|
1029
1306
|
$ZodType.init(inst, def);
|
|
1030
|
-
inst._zod.pattern =
|
|
1031
|
-
...inst?._zod.bag?.patterns ?? []
|
|
1032
|
-
].pop() ?? string(inst._zod.bag);
|
|
1307
|
+
inst._zod.pattern = def.pattern ?? anyString;
|
|
1033
1308
|
inst._zod.parse = (payload, _)=>{
|
|
1034
1309
|
if (def.coerce) try {
|
|
1035
1310
|
payload.value = String(payload.value);
|
|
@@ -1074,48 +1349,89 @@ const $ZodEmail = /*@__PURE__*/ $constructor("$ZodEmail", (inst, def)=>{
|
|
|
1074
1349
|
def.pattern ?? (def.pattern = email);
|
|
1075
1350
|
$ZodStringFormat.init(inst, def);
|
|
1076
1351
|
});
|
|
1352
|
+
const URL_BAD_FORMAT = 1;
|
|
1353
|
+
const URL_UNPARSEABLE = 2;
|
|
1354
|
+
function canParseURL(input) {
|
|
1355
|
+
try {
|
|
1356
|
+
if ("u" > typeof URL && "function" == typeof URL.canParse) return URL.canParse(input);
|
|
1357
|
+
new URL(input);
|
|
1358
|
+
return true;
|
|
1359
|
+
} catch {
|
|
1360
|
+
return false;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
function validateURL(trimmed, def) {
|
|
1364
|
+
if (!("normalize" in def) && !("hostname" in def) && !("protocol" in def)) return canParseURL(trimmed) || URL_UNPARSEABLE;
|
|
1365
|
+
return parseURLObject(trimmed, def);
|
|
1366
|
+
}
|
|
1367
|
+
function parseURLObject(trimmed, def) {
|
|
1368
|
+
if (!def.normalize && def.protocol?.source === httpProtocol.source && !/^https?:\/\//i.test(trimmed)) return URL_BAD_FORMAT;
|
|
1369
|
+
try {
|
|
1370
|
+
if ("u" > typeof URL) {
|
|
1371
|
+
const URLStatic = URL;
|
|
1372
|
+
if ("function" == typeof URLStatic.parse) return URLStatic.parse(trimmed) ?? URL_UNPARSEABLE;
|
|
1373
|
+
}
|
|
1374
|
+
return new URL(trimmed);
|
|
1375
|
+
} catch {
|
|
1376
|
+
return URL_UNPARSEABLE;
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
const asciiTabOrNewline = /[\t\n\r]/g;
|
|
1380
|
+
function stripTabAndNewline(value) {
|
|
1381
|
+
return value.replace(asciiTabOrNewline, "");
|
|
1382
|
+
}
|
|
1383
|
+
function urlHostnameOk(url, hostname) {
|
|
1384
|
+
hostname.lastIndex = 0;
|
|
1385
|
+
return hostname.test(url.hostname);
|
|
1386
|
+
}
|
|
1387
|
+
function urlProtocolOk(url, protocol) {
|
|
1388
|
+
protocol.lastIndex = 0;
|
|
1389
|
+
return protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol);
|
|
1390
|
+
}
|
|
1077
1391
|
const $ZodURL = /*@__PURE__*/ $constructor("$ZodURL", (inst, def)=>{
|
|
1078
1392
|
$ZodStringFormat.init(inst, def);
|
|
1079
1393
|
inst._zod.check = (payload)=>{
|
|
1080
1394
|
try {
|
|
1081
1395
|
const trimmed = payload.value.trim();
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
inst,
|
|
1102
|
-
continue: !def.abort
|
|
1103
|
-
});
|
|
1104
|
-
}
|
|
1105
|
-
if (def.protocol) {
|
|
1106
|
-
def.protocol.lastIndex = 0;
|
|
1107
|
-
if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) payload.issues.push({
|
|
1108
|
-
code: "invalid_format",
|
|
1109
|
-
format: "url",
|
|
1110
|
-
note: "Invalid protocol",
|
|
1111
|
-
pattern: def.protocol.source,
|
|
1112
|
-
input: payload.value,
|
|
1113
|
-
inst,
|
|
1114
|
-
continue: !def.abort
|
|
1115
|
-
});
|
|
1396
|
+
const url = validateURL(trimmed, def);
|
|
1397
|
+
if (url === URL_BAD_FORMAT) return void payload.issues.push({
|
|
1398
|
+
code: "invalid_format",
|
|
1399
|
+
format: "url",
|
|
1400
|
+
note: "Invalid URL format",
|
|
1401
|
+
input: payload.value,
|
|
1402
|
+
inst,
|
|
1403
|
+
continue: !def.abort
|
|
1404
|
+
});
|
|
1405
|
+
if (url === URL_UNPARSEABLE) return void payload.issues.push({
|
|
1406
|
+
code: "invalid_format",
|
|
1407
|
+
format: "url",
|
|
1408
|
+
input: payload.value,
|
|
1409
|
+
inst,
|
|
1410
|
+
continue: !def.abort
|
|
1411
|
+
});
|
|
1412
|
+
if (true === url) {
|
|
1413
|
+
payload.value = stripTabAndNewline(trimmed);
|
|
1414
|
+
return;
|
|
1116
1415
|
}
|
|
1117
|
-
if (def.
|
|
1118
|
-
|
|
1416
|
+
if (def.hostname && !urlHostnameOk(url, def.hostname)) payload.issues.push({
|
|
1417
|
+
code: "invalid_format",
|
|
1418
|
+
format: "url",
|
|
1419
|
+
note: "Invalid hostname",
|
|
1420
|
+
pattern: def.hostname.source,
|
|
1421
|
+
input: payload.value,
|
|
1422
|
+
inst,
|
|
1423
|
+
continue: !def.abort
|
|
1424
|
+
});
|
|
1425
|
+
if (def.protocol && !urlProtocolOk(url, def.protocol)) payload.issues.push({
|
|
1426
|
+
code: "invalid_format",
|
|
1427
|
+
format: "url",
|
|
1428
|
+
note: "Invalid protocol",
|
|
1429
|
+
pattern: def.protocol.source,
|
|
1430
|
+
input: payload.value,
|
|
1431
|
+
inst,
|
|
1432
|
+
continue: !def.abort
|
|
1433
|
+
});
|
|
1434
|
+
payload.value = def.normalize ? url.href : stripTabAndNewline(trimmed);
|
|
1119
1435
|
return;
|
|
1120
1436
|
} catch (_) {
|
|
1121
1437
|
payload.issues.push({
|
|
@@ -1133,7 +1449,8 @@ const $ZodEmoji = /*@__PURE__*/ $constructor("$ZodEmoji", (inst, def)=>{
|
|
|
1133
1449
|
$ZodStringFormat.init(inst, def);
|
|
1134
1450
|
});
|
|
1135
1451
|
const $ZodNanoID = /*@__PURE__*/ $constructor("$ZodNanoID", (inst, def)=>{
|
|
1136
|
-
def.
|
|
1452
|
+
if (void 0 !== def.length && (!Number.isInteger(def.length) || def.length < 1)) throw new Error(`Invalid nanoid length: ${def.length}`);
|
|
1453
|
+
def.pattern ?? (def.pattern = void 0 === def.length ? nanoid : nanoidOfLength(def.length));
|
|
1137
1454
|
$ZodStringFormat.init(inst, def);
|
|
1138
1455
|
});
|
|
1139
1456
|
const $ZodCUID = /*@__PURE__*/ $constructor("$ZodCUID", (inst, def)=>{
|
|
@@ -1165,7 +1482,7 @@ const $ZodISODate = /*@__PURE__*/ $constructor("$ZodISODate", (inst, def)=>{
|
|
|
1165
1482
|
$ZodStringFormat.init(inst, def);
|
|
1166
1483
|
});
|
|
1167
1484
|
const $ZodISOTime = /*@__PURE__*/ $constructor("$ZodISOTime", (inst, def)=>{
|
|
1168
|
-
def.pattern ?? (def.pattern =
|
|
1485
|
+
def.pattern ?? (def.pattern = time(def));
|
|
1169
1486
|
$ZodStringFormat.init(inst, def);
|
|
1170
1487
|
});
|
|
1171
1488
|
const $ZodISODuration = /*@__PURE__*/ $constructor("$ZodISODuration", (inst, def)=>{
|
|
@@ -1175,52 +1492,50 @@ const $ZodISODuration = /*@__PURE__*/ $constructor("$ZodISODuration", (inst, def
|
|
|
1175
1492
|
const $ZodIPv4 = /*@__PURE__*/ $constructor("$ZodIPv4", (inst, def)=>{
|
|
1176
1493
|
def.pattern ?? (def.pattern = ipv4);
|
|
1177
1494
|
$ZodStringFormat.init(inst, def);
|
|
1178
|
-
inst._zod.bag.format = "ipv4";
|
|
1179
1495
|
});
|
|
1496
|
+
const ipv6Alphabet = /^[0-9a-fA-F:.]+$/;
|
|
1497
|
+
function isValidIPv6(value) {
|
|
1498
|
+
if (!ipv6Alphabet.test(value)) return false;
|
|
1499
|
+
return canParseURL(`http://[${value}]`);
|
|
1500
|
+
}
|
|
1180
1501
|
const $ZodIPv6 = /*@__PURE__*/ $constructor("$ZodIPv6", (inst, def)=>{
|
|
1181
1502
|
def.pattern ?? (def.pattern = ipv6);
|
|
1182
1503
|
$ZodStringFormat.init(inst, def);
|
|
1183
|
-
inst._zod.bag.format = "ipv6";
|
|
1184
1504
|
inst._zod.check = (payload)=>{
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
payload.
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
inst,
|
|
1193
|
-
continue: !def.abort
|
|
1194
|
-
});
|
|
1195
|
-
}
|
|
1505
|
+
if (!isValidIPv6(payload.value)) payload.issues.push({
|
|
1506
|
+
code: "invalid_format",
|
|
1507
|
+
format: "ipv6",
|
|
1508
|
+
input: payload.value,
|
|
1509
|
+
inst,
|
|
1510
|
+
continue: !def.abort
|
|
1511
|
+
});
|
|
1196
1512
|
};
|
|
1197
1513
|
});
|
|
1198
1514
|
const $ZodCIDRv4 = /*@__PURE__*/ $constructor("$ZodCIDRv4", (inst, def)=>{
|
|
1199
1515
|
def.pattern ?? (def.pattern = cidrv4);
|
|
1200
1516
|
$ZodStringFormat.init(inst, def);
|
|
1201
1517
|
});
|
|
1518
|
+
function isValidCIDRv6(value) {
|
|
1519
|
+
const parts = value.split("/");
|
|
1520
|
+
if (2 !== parts.length) return false;
|
|
1521
|
+
const [address, prefix] = parts;
|
|
1522
|
+
if (!prefix) return false;
|
|
1523
|
+
const prefixNum = Number(prefix);
|
|
1524
|
+
if (`${prefixNum}` !== prefix) return false;
|
|
1525
|
+
if (prefixNum < 0 || prefixNum > 128) return false;
|
|
1526
|
+
return isValidIPv6(address);
|
|
1527
|
+
}
|
|
1202
1528
|
const $ZodCIDRv6 = /*@__PURE__*/ $constructor("$ZodCIDRv6", (inst, def)=>{
|
|
1203
1529
|
def.pattern ?? (def.pattern = cidrv6);
|
|
1204
1530
|
$ZodStringFormat.init(inst, def);
|
|
1205
1531
|
inst._zod.check = (payload)=>{
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
if (prefixNum < 0 || prefixNum > 128) throw new Error();
|
|
1214
|
-
new URL(`http://[${address}]`);
|
|
1215
|
-
} catch {
|
|
1216
|
-
payload.issues.push({
|
|
1217
|
-
code: "invalid_format",
|
|
1218
|
-
format: "cidrv6",
|
|
1219
|
-
input: payload.value,
|
|
1220
|
-
inst,
|
|
1221
|
-
continue: !def.abort
|
|
1222
|
-
});
|
|
1223
|
-
}
|
|
1532
|
+
if (!isValidCIDRv6(payload.value)) payload.issues.push({
|
|
1533
|
+
code: "invalid_format",
|
|
1534
|
+
format: "cidrv6",
|
|
1535
|
+
input: payload.value,
|
|
1536
|
+
inst,
|
|
1537
|
+
continue: !def.abort
|
|
1538
|
+
});
|
|
1224
1539
|
};
|
|
1225
1540
|
});
|
|
1226
1541
|
function isValidBase64(data) {
|
|
@@ -1234,10 +1549,10 @@ function isValidBase64(data) {
|
|
|
1234
1549
|
return false;
|
|
1235
1550
|
}
|
|
1236
1551
|
}
|
|
1552
|
+
const base64Charset = /^[0-9a-zA-Z+/]*={0,2}$/;
|
|
1237
1553
|
const $ZodBase64 = /*@__PURE__*/ $constructor("$ZodBase64", (inst, def)=>{
|
|
1238
|
-
def.pattern ?? (def.pattern =
|
|
1554
|
+
def.pattern ?? (def.pattern = base64Charset);
|
|
1239
1555
|
$ZodStringFormat.init(inst, def);
|
|
1240
|
-
inst._zod.bag.contentEncoding = "base64";
|
|
1241
1556
|
inst._zod.check = (payload)=>{
|
|
1242
1557
|
if (isValidBase64(payload.value)) return;
|
|
1243
1558
|
payload.issues.push({
|
|
@@ -1249,16 +1564,16 @@ const $ZodBase64 = /*@__PURE__*/ $constructor("$ZodBase64", (inst, def)=>{
|
|
|
1249
1564
|
});
|
|
1250
1565
|
};
|
|
1251
1566
|
});
|
|
1567
|
+
const base64urlCharset = /^[A-Za-z0-9_-]*$/;
|
|
1252
1568
|
function isValidBase64URL(data) {
|
|
1253
|
-
if (!
|
|
1569
|
+
if (!base64urlCharset.test(data)) return false;
|
|
1254
1570
|
const base64 = data.replace(/[-_]/g, (c)=>"-" === c ? "+" : "/");
|
|
1255
1571
|
const padded = base64.padEnd(4 * Math.ceil(base64.length / 4), "=");
|
|
1256
1572
|
return isValidBase64(padded);
|
|
1257
1573
|
}
|
|
1258
1574
|
const $ZodBase64URL = /*@__PURE__*/ $constructor("$ZodBase64URL", (inst, def)=>{
|
|
1259
|
-
def.pattern ?? (def.pattern =
|
|
1575
|
+
def.pattern ?? (def.pattern = base64urlCharset);
|
|
1260
1576
|
$ZodStringFormat.init(inst, def);
|
|
1261
|
-
inst._zod.bag.contentEncoding = "base64url";
|
|
1262
1577
|
inst._zod.check = (payload)=>{
|
|
1263
1578
|
if (isValidBase64URL(payload.value)) return;
|
|
1264
1579
|
payload.issues.push({
|
|
@@ -1342,6 +1657,8 @@ function handleArrayResult(result, final, index) {
|
|
|
1342
1657
|
}
|
|
1343
1658
|
const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def)=>{
|
|
1344
1659
|
$ZodType.init(inst, def);
|
|
1660
|
+
const memo = globalConfig.memoizer;
|
|
1661
|
+
memo?.attach(inst);
|
|
1345
1662
|
inst._zod.parse = (payload, ctx)=>{
|
|
1346
1663
|
const input = payload.value;
|
|
1347
1664
|
if (!Array.isArray(input)) {
|
|
@@ -1353,8 +1670,9 @@ const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def)=>{
|
|
|
1353
1670
|
});
|
|
1354
1671
|
return payload;
|
|
1355
1672
|
}
|
|
1356
|
-
payload.value = Array(input.length);
|
|
1673
|
+
payload.value = memo ? memo.alloc(inst, payload, Array(input.length), ctx) : Array(input.length);
|
|
1357
1674
|
const proms = [];
|
|
1675
|
+
const abortEarly = ctx?.abortEarly;
|
|
1358
1676
|
for(let i = 0; i < input.length; i++){
|
|
1359
1677
|
const item = input[i];
|
|
1360
1678
|
const result = def.element._zod.run({
|
|
@@ -1362,19 +1680,24 @@ const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def)=>{
|
|
|
1362
1680
|
issues: []
|
|
1363
1681
|
}, ctx);
|
|
1364
1682
|
if (result instanceof Promise) proms.push(result.then((result)=>handleArrayResult(result, payload, i)));
|
|
1365
|
-
else
|
|
1683
|
+
else {
|
|
1684
|
+
handleArrayResult(result, payload, i);
|
|
1685
|
+
if (abortEarly && 0 !== result.issues.length && aborted(result)) break;
|
|
1686
|
+
}
|
|
1366
1687
|
}
|
|
1367
1688
|
if (proms.length) return Promise.all(proms).then(()=>payload);
|
|
1368
1689
|
return payload;
|
|
1369
1690
|
};
|
|
1370
1691
|
});
|
|
1371
|
-
function handlePropertyResult(result, final, key, input,
|
|
1692
|
+
function handlePropertyResult(result, final, key, input, optin, optout) {
|
|
1372
1693
|
const isPresent = key in input;
|
|
1694
|
+
const isOptionalOut = "optional" === optout;
|
|
1695
|
+
if (!isPresent && isOptionalOut && "optional" === optin) return;
|
|
1373
1696
|
if (result.issues.length) {
|
|
1374
|
-
if (
|
|
1697
|
+
if (void 0 !== optin && isOptionalOut && !isPresent) return;
|
|
1375
1698
|
final.issues.push(...prefixIssues(key, result.issues));
|
|
1376
1699
|
}
|
|
1377
|
-
if (!isPresent &&
|
|
1700
|
+
if (!isPresent && void 0 === optin) {
|
|
1378
1701
|
if (!result.issues.length) final.issues.push({
|
|
1379
1702
|
code: "invalid_type",
|
|
1380
1703
|
expected: "nonoptional",
|
|
@@ -1386,31 +1709,47 @@ function handlePropertyResult(result, final, key, input, isOptionalIn, isOptiona
|
|
|
1386
1709
|
return;
|
|
1387
1710
|
}
|
|
1388
1711
|
if (void 0 === result.value) {
|
|
1389
|
-
if (isPresent) final.value[key] = void 0;
|
|
1712
|
+
if (isPresent || "defaulted" === optin && !isOptionalOut) final.value[key] = void 0;
|
|
1390
1713
|
} else final.value[key] = result.value;
|
|
1391
1714
|
}
|
|
1715
|
+
const NO_SYMBOL_KEYS = [];
|
|
1392
1716
|
function normalizeDef(def) {
|
|
1393
1717
|
const keys = Object.keys(def.shape);
|
|
1394
|
-
|
|
1718
|
+
const ownSymbols = Object.getOwnPropertySymbols(def.shape);
|
|
1719
|
+
const symbolKeys = ownSymbols.length ? ownSymbols : NO_SYMBOL_KEYS;
|
|
1720
|
+
const allKeys = symbolKeys.length ? [
|
|
1721
|
+
...keys,
|
|
1722
|
+
...symbolKeys
|
|
1723
|
+
] : keys;
|
|
1724
|
+
for (const k of allKeys)if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) throw new Error(`Invalid element at key "${String(k)}": expected a Zod schema`);
|
|
1395
1725
|
const okeys = optionalKeys(def.shape);
|
|
1396
1726
|
return {
|
|
1397
1727
|
...def,
|
|
1398
|
-
|
|
1728
|
+
allKeys,
|
|
1729
|
+
symbolKeys,
|
|
1399
1730
|
keySet: new Set(keys),
|
|
1400
1731
|
numKeys: keys.length,
|
|
1401
1732
|
optionalKeys: new Set(okeys)
|
|
1402
1733
|
};
|
|
1403
1734
|
}
|
|
1404
|
-
function handleCatchall(proms, input, payload, ctx, def, inst) {
|
|
1735
|
+
function handleCatchall(proms, input, payload, ctx, def, inst, abortEarly) {
|
|
1405
1736
|
const unrecognized = [];
|
|
1406
1737
|
const keySet = def.keySet;
|
|
1407
1738
|
const _catchall = def.catchall._zod;
|
|
1408
1739
|
const t = _catchall.def.type;
|
|
1409
|
-
const
|
|
1410
|
-
const
|
|
1740
|
+
const optin = _catchall.optin;
|
|
1741
|
+
const optout = _catchall.optout;
|
|
1742
|
+
let seen = 0;
|
|
1411
1743
|
for(const key in input){
|
|
1412
|
-
if (
|
|
1744
|
+
if (abortEarly && payload.issues.length !== seen) {
|
|
1745
|
+
if (aborted(payload, seen)) break;
|
|
1746
|
+
seen = payload.issues.length;
|
|
1747
|
+
}
|
|
1413
1748
|
if (keySet.has(key)) continue;
|
|
1749
|
+
if ("__proto__" === key) {
|
|
1750
|
+
if ("never" === t) unrecognized.push(key);
|
|
1751
|
+
continue;
|
|
1752
|
+
}
|
|
1414
1753
|
if ("never" === t) {
|
|
1415
1754
|
unrecognized.push(key);
|
|
1416
1755
|
continue;
|
|
@@ -1419,14 +1758,15 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
|
|
|
1419
1758
|
value: input[key],
|
|
1420
1759
|
issues: []
|
|
1421
1760
|
}, ctx);
|
|
1422
|
-
if (r instanceof Promise) proms.push(r.then((r)=>handlePropertyResult(r, payload, key, input,
|
|
1423
|
-
else handlePropertyResult(r, payload, key, input,
|
|
1761
|
+
if (r instanceof Promise) proms.push(r.then((r)=>handlePropertyResult(r, payload, key, input, optin, optout)));
|
|
1762
|
+
else handlePropertyResult(r, payload, key, input, optin, optout);
|
|
1424
1763
|
}
|
|
1425
1764
|
if (unrecognized.length) payload.issues.push({
|
|
1426
1765
|
code: "unrecognized_keys",
|
|
1427
1766
|
keys: unrecognized,
|
|
1428
1767
|
input,
|
|
1429
|
-
inst
|
|
1768
|
+
inst,
|
|
1769
|
+
continue: true
|
|
1430
1770
|
});
|
|
1431
1771
|
if (!proms.length) return payload;
|
|
1432
1772
|
return Promise.all(proms).then(()=>payload);
|
|
@@ -1434,29 +1774,33 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
|
|
|
1434
1774
|
const $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def)=>{
|
|
1435
1775
|
$ZodType.init(inst, def);
|
|
1436
1776
|
const desc = Object.getOwnPropertyDescriptor(def, "shape");
|
|
1437
|
-
|
|
1438
|
-
|
|
1777
|
+
const sh = desc?.get ? desc.get.raw : def.shape ?? {};
|
|
1778
|
+
if (sh) {
|
|
1779
|
+
const get = ()=>{
|
|
1780
|
+
const newSh = {
|
|
1781
|
+
...sh
|
|
1782
|
+
};
|
|
1783
|
+
Object.defineProperty(def, "shape", {
|
|
1784
|
+
value: newSh
|
|
1785
|
+
});
|
|
1786
|
+
get.raw = newSh;
|
|
1787
|
+
return newSh;
|
|
1788
|
+
};
|
|
1789
|
+
get.raw = sh;
|
|
1439
1790
|
Object.defineProperty(def, "shape", {
|
|
1440
|
-
get
|
|
1441
|
-
const newSh = {
|
|
1442
|
-
...sh
|
|
1443
|
-
};
|
|
1444
|
-
Object.defineProperty(def, "shape", {
|
|
1445
|
-
value: newSh
|
|
1446
|
-
});
|
|
1447
|
-
return newSh;
|
|
1448
|
-
}
|
|
1791
|
+
get
|
|
1449
1792
|
});
|
|
1450
1793
|
}
|
|
1451
|
-
const _normalized =
|
|
1452
|
-
|
|
1453
|
-
const shape = def.shape;
|
|
1794
|
+
const _normalized = util_cached(()=>normalizeDef(def));
|
|
1795
|
+
defineLazyInternal(inst, "propValues", (zod)=>{
|
|
1796
|
+
const shape = zod.def.shape;
|
|
1454
1797
|
const propValues = {};
|
|
1455
1798
|
for(const key in shape){
|
|
1456
1799
|
const field = shape[key]._zod;
|
|
1457
1800
|
if (field.values) {
|
|
1458
|
-
propValues
|
|
1801
|
+
if (!Object.prototype.hasOwnProperty.call(propValues, key)) util_assignProp(propValues, key, new Set());
|
|
1459
1802
|
for (const v of field.values)propValues[key].add(v);
|
|
1803
|
+
if (void 0 !== field.optin) propValues[key].add(void 0);
|
|
1460
1804
|
}
|
|
1461
1805
|
}
|
|
1462
1806
|
return propValues;
|
|
@@ -1464,6 +1808,8 @@ const $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def)=>{
|
|
|
1464
1808
|
const isObject = util_isObject;
|
|
1465
1809
|
const catchall = def.catchall;
|
|
1466
1810
|
let value;
|
|
1811
|
+
const memo = globalConfig.memoizer;
|
|
1812
|
+
memo?.attach(inst);
|
|
1467
1813
|
inst._zod.parse = (payload, ctx)=>{
|
|
1468
1814
|
value ?? (value = _normalized.value);
|
|
1469
1815
|
const input = payload.value;
|
|
@@ -1476,94 +1822,104 @@ const $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def)=>{
|
|
|
1476
1822
|
});
|
|
1477
1823
|
return payload;
|
|
1478
1824
|
}
|
|
1479
|
-
payload.value = {};
|
|
1825
|
+
payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
|
|
1480
1826
|
const proms = [];
|
|
1481
1827
|
const shape = value.shape;
|
|
1482
|
-
|
|
1828
|
+
const abortEarly = ctx?.abortEarly;
|
|
1829
|
+
let seen = payload.issues.length;
|
|
1830
|
+
for (const key of value.allKeys){
|
|
1831
|
+
if (abortEarly && payload.issues.length !== seen) {
|
|
1832
|
+
if (aborted(payload, seen)) break;
|
|
1833
|
+
seen = payload.issues.length;
|
|
1834
|
+
}
|
|
1835
|
+
if ("__proto__" === key) continue;
|
|
1483
1836
|
const el = shape[key];
|
|
1484
|
-
const
|
|
1485
|
-
const
|
|
1837
|
+
const optin = el._zod.optin;
|
|
1838
|
+
const optout = el._zod.optout;
|
|
1486
1839
|
const r = el._zod.run({
|
|
1487
1840
|
value: input[key],
|
|
1488
1841
|
issues: []
|
|
1489
1842
|
}, ctx);
|
|
1490
|
-
if (r instanceof Promise) proms.push(r.then((r)=>handlePropertyResult(r, payload, key, input,
|
|
1491
|
-
else handlePropertyResult(r, payload, key, input,
|
|
1843
|
+
if (r instanceof Promise) proms.push(r.then((r)=>handlePropertyResult(r, payload, key, input, optin, optout)));
|
|
1844
|
+
else handlePropertyResult(r, payload, key, input, optin, optout);
|
|
1492
1845
|
}
|
|
1493
1846
|
if (!catchall) return proms.length ? Promise.all(proms).then(()=>payload) : payload;
|
|
1494
|
-
return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
|
|
1847
|
+
return handleCatchall(proms, input, payload, ctx, _normalized.value, inst, true === abortEarly);
|
|
1495
1848
|
};
|
|
1496
1849
|
});
|
|
1497
1850
|
const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def)=>{
|
|
1498
1851
|
$ZodObject.init(inst, def);
|
|
1499
1852
|
const superParse = inst._zod.parse;
|
|
1500
|
-
const _normalized =
|
|
1853
|
+
const _normalized = util_cached(()=>normalizeDef(def));
|
|
1854
|
+
const memo = globalConfig.memoizer;
|
|
1501
1855
|
const generateFastpass = (shape)=>{
|
|
1856
|
+
const normalized = _normalized.value;
|
|
1857
|
+
const syms = normalized.symbolKeys;
|
|
1502
1858
|
const doc = new Doc([
|
|
1503
|
-
"shape",
|
|
1504
1859
|
"payload",
|
|
1505
1860
|
"ctx"
|
|
1506
|
-
]
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
};
|
|
1861
|
+
], {
|
|
1862
|
+
shape,
|
|
1863
|
+
inst,
|
|
1864
|
+
memo,
|
|
1865
|
+
syms
|
|
1866
|
+
});
|
|
1867
|
+
const parseStr = (k)=>`shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
|
|
1868
|
+
const prefixStr = (id, k)=>`
|
|
1869
|
+
let ${id}_ab = false;
|
|
1870
|
+
for (let i = 0; i < ${id}.issues.length; i++) {
|
|
1871
|
+
const iss = ${id}.issues[i];
|
|
1872
|
+
iss.path = iss.path ? [${k}, ...iss.path] : [${k}];
|
|
1873
|
+
payload.issues.push(iss);
|
|
1874
|
+
if (iss.continue !== true) ${id}_ab = true;
|
|
1875
|
+
}
|
|
1876
|
+
if (${id}_ab && ctx && ctx.abortEarly) {
|
|
1877
|
+
payload.value = newResult;
|
|
1878
|
+
return payload;
|
|
1879
|
+
}`;
|
|
1512
1880
|
doc.write("const input = payload.value;");
|
|
1513
1881
|
const ids = Object.create(null);
|
|
1514
1882
|
let counter = 0;
|
|
1515
|
-
for (const key of normalized.
|
|
1516
|
-
doc.write("const newResult = {};");
|
|
1517
|
-
for (const key of normalized.
|
|
1883
|
+
for (const key of normalized.allKeys)ids[key] = `key_${counter++}`;
|
|
1884
|
+
doc.write(memo ? "const newResult = memo.alloc(inst, payload, {}, ctx);" : "const newResult = {};");
|
|
1885
|
+
for (const key of normalized.allKeys){
|
|
1886
|
+
if ("__proto__" === key) continue;
|
|
1518
1887
|
const id = ids[key];
|
|
1519
|
-
const k = esc(key);
|
|
1888
|
+
const k = "symbol" == typeof key ? `syms[${syms.indexOf(key)}]` : esc(key);
|
|
1889
|
+
const isPresent = `${k} in input`;
|
|
1520
1890
|
const schema = shape[key];
|
|
1521
|
-
const
|
|
1891
|
+
const optin = schema?._zod?.optin;
|
|
1892
|
+
const isOptionalIn = void 0 !== optin;
|
|
1522
1893
|
const isOptionalOut = schema?._zod?.optout === "optional";
|
|
1523
|
-
doc.write(`const ${id} = ${parseStr(
|
|
1524
|
-
if (isOptionalIn && isOptionalOut)
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
})));
|
|
1894
|
+
doc.write(`const ${id} = ${parseStr(k)};`);
|
|
1895
|
+
if (isOptionalIn && isOptionalOut) {
|
|
1896
|
+
const assign = "optional" === optin ? `${id}_present` : `${id}.value !== undefined || ${id}_present`;
|
|
1897
|
+
doc.write(`
|
|
1898
|
+
const ${id}_present = ${isPresent};
|
|
1899
|
+
if (!${id}.issues.length || ${id}_present) {
|
|
1900
|
+
if (${id}.issues.length) {${prefixStr(id, k)}
|
|
1531
1901
|
}
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
if (${k} in input) {
|
|
1536
|
-
newResult[${k}] = undefined;
|
|
1902
|
+
|
|
1903
|
+
if (${assign}) {
|
|
1904
|
+
newResult[${k}] = ${id}.value;
|
|
1537
1905
|
}
|
|
1538
|
-
} else {
|
|
1539
|
-
newResult[${k}] = ${id}.value;
|
|
1540
1906
|
}
|
|
1541
|
-
|
|
1907
|
+
|
|
1542
1908
|
`);
|
|
1543
|
-
else if (isOptionalIn)
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
...iss,
|
|
1547
|
-
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
|
1548
|
-
})));
|
|
1909
|
+
} else if (isOptionalIn) {
|
|
1910
|
+
doc.write(`
|
|
1911
|
+
if (${id}.issues.length) {${prefixStr(id, k)}
|
|
1549
1912
|
}
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
}
|
|
1555
|
-
} else {
|
|
1913
|
+
`);
|
|
1914
|
+
if ("defaulted" === optin) doc.write(`newResult[${k}] = ${id}.value;`);
|
|
1915
|
+
else doc.write(`
|
|
1916
|
+
if (${id}.value !== undefined || ${isPresent}) {
|
|
1556
1917
|
newResult[${k}] = ${id}.value;
|
|
1557
1918
|
}
|
|
1558
|
-
|
|
1559
1919
|
`);
|
|
1560
|
-
else doc.write(`
|
|
1561
|
-
const ${id}_present = ${
|
|
1562
|
-
if (${id}.issues.length) {
|
|
1563
|
-
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
|
1564
|
-
...iss,
|
|
1565
|
-
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
|
1566
|
-
})));
|
|
1920
|
+
} else doc.write(`
|
|
1921
|
+
const ${id}_present = ${isPresent};
|
|
1922
|
+
if (${id}.issues.length) {${prefixStr(id, k)}
|
|
1567
1923
|
}
|
|
1568
1924
|
if (!${id}_present && !${id}.issues.length) {
|
|
1569
1925
|
payload.issues.push({
|
|
@@ -1572,22 +1928,21 @@ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def)=>{
|
|
|
1572
1928
|
input: undefined,
|
|
1573
1929
|
path: [${k}]
|
|
1574
1930
|
});
|
|
1931
|
+
if (ctx && ctx.abortEarly) {
|
|
1932
|
+
payload.value = newResult;
|
|
1933
|
+
return payload;
|
|
1934
|
+
}
|
|
1575
1935
|
}
|
|
1576
1936
|
|
|
1577
1937
|
if (${id}_present) {
|
|
1578
|
-
|
|
1579
|
-
newResult[${k}] = undefined;
|
|
1580
|
-
} else {
|
|
1581
|
-
newResult[${k}] = ${id}.value;
|
|
1582
|
-
}
|
|
1938
|
+
newResult[${k}] = ${id}.value;
|
|
1583
1939
|
}
|
|
1584
1940
|
|
|
1585
1941
|
`);
|
|
1586
1942
|
}
|
|
1587
1943
|
doc.write("payload.value = newResult;");
|
|
1588
1944
|
doc.write("return payload;");
|
|
1589
|
-
|
|
1590
|
-
return (payload, ctx)=>fn(shape, payload, ctx);
|
|
1945
|
+
return doc.compile();
|
|
1591
1946
|
};
|
|
1592
1947
|
let fastpass;
|
|
1593
1948
|
const isObject = util_isObject;
|
|
@@ -1612,7 +1967,7 @@ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def)=>{
|
|
|
1612
1967
|
if (!fastpass) fastpass = generateFastpass(def.shape);
|
|
1613
1968
|
payload = fastpass(payload, ctx);
|
|
1614
1969
|
if (!catchall) return payload;
|
|
1615
|
-
return handleCatchall([], input, payload, ctx, value, inst);
|
|
1970
|
+
return handleCatchall([], input, payload, ctx, value, inst, ctx?.abortEarly === true);
|
|
1616
1971
|
}
|
|
1617
1972
|
return superParse(payload, ctx);
|
|
1618
1973
|
};
|
|
@@ -1637,14 +1992,14 @@ function handleUnionResults(results, final, inst, ctx) {
|
|
|
1637
1992
|
}
|
|
1638
1993
|
const $ZodUnion = /*@__PURE__*/ $constructor("$ZodUnion", (inst, def)=>{
|
|
1639
1994
|
$ZodType.init(inst, def);
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
if (def.options.every((o)=>o._zod.values)) return new Set(def.options.flatMap((option)=>Array.from(option._zod.values)));
|
|
1995
|
+
defineLazyInternal(inst, "optin", (zod)=>zod.def.options.some((o)=>"defaulted" === o._zod.optin) ? "defaulted" : zod.def.options.some((o)=>void 0 !== o._zod.optin) ? "optional" : void 0);
|
|
1996
|
+
defineLazyInternal(inst, "optout", (zod)=>zod.def.options.some((o)=>"optional" === o._zod.optout) ? "optional" : void 0);
|
|
1997
|
+
defineLazyInternal(inst, "values", (zod)=>{
|
|
1998
|
+
if (zod.def.options.every((o)=>o._zod.values)) return new Set(zod.def.options.flatMap((option)=>Array.from(option._zod.values)));
|
|
1644
1999
|
});
|
|
1645
|
-
|
|
1646
|
-
if (def.options.every((o)=>o._zod.pattern)) {
|
|
1647
|
-
const patterns = def.options.map((o)=>o._zod.pattern);
|
|
2000
|
+
defineLazyInternal(inst, "pattern", (zod)=>{
|
|
2001
|
+
if (zod.def.options.every((o)=>o._zod.pattern)) {
|
|
2002
|
+
const patterns = zod.def.options.map((o)=>o._zod.pattern);
|
|
1648
2003
|
return new RegExp(`^(${patterns.map((p)=>cleanRegex(p.source)).join("|")})$`);
|
|
1649
2004
|
}
|
|
1650
2005
|
});
|
|
@@ -1706,7 +2061,9 @@ function mergeValues(a, b) {
|
|
|
1706
2061
|
...a,
|
|
1707
2062
|
...b
|
|
1708
2063
|
};
|
|
2064
|
+
if (Object.prototype.hasOwnProperty.call(newObj, "__proto__")) delete newObj.__proto__;
|
|
1709
2065
|
for (const key of sharedKeys){
|
|
2066
|
+
if ("__proto__" === key) continue;
|
|
1710
2067
|
const sharedValue = mergeValues(a[key], b[key]);
|
|
1711
2068
|
if (!sharedValue.valid) return {
|
|
1712
2069
|
valid: false,
|
|
@@ -1754,28 +2111,45 @@ function mergeValues(a, b) {
|
|
|
1754
2111
|
function handleIntersectionResults(result, left, right) {
|
|
1755
2112
|
const unrecKeys = new Map();
|
|
1756
2113
|
let unrecIssue;
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
2114
|
+
const keyIssues = new Map();
|
|
2115
|
+
const collect = (iss, side)=>{
|
|
2116
|
+
let keys;
|
|
2117
|
+
if ("unrecognized_keys" !== iss.code || iss.path?.length) if ("invalid_key" !== iss.code || "record" !== iss.origin || iss.path?.length !== 1) return false;
|
|
2118
|
+
else {
|
|
2119
|
+
const k = String(iss.path[0]);
|
|
2120
|
+
if (!keyIssues.has(k)) keyIssues.set(k, iss);
|
|
2121
|
+
keys = [
|
|
2122
|
+
k
|
|
2123
|
+
];
|
|
2124
|
+
}
|
|
2125
|
+
else {
|
|
2126
|
+
unrecIssue ?? (unrecIssue = iss);
|
|
2127
|
+
keys = iss.keys;
|
|
2128
|
+
}
|
|
2129
|
+
for (const k of keys){
|
|
1760
2130
|
if (!unrecKeys.has(k)) unrecKeys.set(k, {});
|
|
1761
|
-
unrecKeys.get(k)
|
|
2131
|
+
unrecKeys.get(k)[side] = true;
|
|
1762
2132
|
}
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
}
|
|
1768
|
-
else result.issues.push(iss);
|
|
2133
|
+
return true;
|
|
2134
|
+
};
|
|
2135
|
+
for (const iss of left.issues)if (!collect(iss, "l")) result.issues.push(iss);
|
|
2136
|
+
for (const iss of right.issues)if (!collect(iss, "r")) result.issues.push(iss);
|
|
1769
2137
|
const bothKeys = [
|
|
1770
2138
|
...unrecKeys
|
|
1771
2139
|
].filter(([, f])=>f.l && f.r).map(([k])=>k);
|
|
1772
|
-
if (bothKeys.length
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
2140
|
+
if (bothKeys.length) {
|
|
2141
|
+
const aggregated = unrecIssue ? bothKeys.filter((k)=>unrecIssue.keys.includes(k)) : [];
|
|
2142
|
+
if (aggregated.length) result.issues.push({
|
|
2143
|
+
...unrecIssue,
|
|
2144
|
+
keys: aggregated
|
|
2145
|
+
});
|
|
2146
|
+
for (const k of bothKeys)if (!aggregated.includes(k) && keyIssues.has(k)) result.issues.push(keyIssues.get(k));
|
|
2147
|
+
}
|
|
1777
2148
|
const merged = mergeValues(left.value, right.value);
|
|
1778
|
-
if (!merged.valid)
|
|
2149
|
+
if (!merged.valid) {
|
|
2150
|
+
if (aborted(result)) return result;
|
|
2151
|
+
throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
|
|
2152
|
+
}
|
|
1779
2153
|
result.value = merged.data;
|
|
1780
2154
|
return result;
|
|
1781
2155
|
}
|
|
@@ -1784,7 +2158,10 @@ const $ZodEnum = /*@__PURE__*/ $constructor("$ZodEnum", (inst, def)=>{
|
|
|
1784
2158
|
const values = getEnumValues(def.entries);
|
|
1785
2159
|
const valuesSet = new Set(values);
|
|
1786
2160
|
inst._zod.values = valuesSet;
|
|
1787
|
-
inst
|
|
2161
|
+
defineLazyInternal(inst, "pattern", (zod)=>{
|
|
2162
|
+
const patternValues = getEnumValues(zod.def.entries).filter((k)=>propertyKeyTypes.has(typeof k));
|
|
2163
|
+
return new RegExp(patternValues.length ? `^(${patternValues.map((o)=>escapeRegex(o.toString())).join("|")})$` : "^[^\\s\\S]$");
|
|
2164
|
+
});
|
|
1788
2165
|
inst._zod.parse = (payload, _ctx)=>{
|
|
1789
2166
|
const input = payload.value;
|
|
1790
2167
|
if (valuesSet.has(input)) return payload;
|
|
@@ -1800,6 +2177,7 @@ const $ZodEnum = /*@__PURE__*/ $constructor("$ZodEnum", (inst, def)=>{
|
|
|
1800
2177
|
const $ZodTransform = /*@__PURE__*/ $constructor("$ZodTransform", (inst, def)=>{
|
|
1801
2178
|
$ZodType.init(inst, def);
|
|
1802
2179
|
inst._zod.optin = "optional";
|
|
2180
|
+
globalConfig.memoizer?.guard(inst);
|
|
1803
2181
|
inst._zod.parse = (payload, ctx)=>{
|
|
1804
2182
|
if ("backward" === ctx.direction) throw new $ZodEncodeError(inst.constructor.name);
|
|
1805
2183
|
const _out = def.transform(payload.value, payload);
|
|
@@ -1807,62 +2185,62 @@ const $ZodTransform = /*@__PURE__*/ $constructor("$ZodTransform", (inst, def)=>{
|
|
|
1807
2185
|
const output = _out instanceof Promise ? _out : Promise.resolve(_out);
|
|
1808
2186
|
return output.then((output)=>{
|
|
1809
2187
|
payload.value = output;
|
|
1810
|
-
payload.fallback = true;
|
|
1811
2188
|
return payload;
|
|
1812
2189
|
});
|
|
1813
2190
|
}
|
|
1814
2191
|
if (_out instanceof Promise) throw new $ZodAsyncError();
|
|
1815
2192
|
payload.value = _out;
|
|
1816
|
-
payload.fallback = true;
|
|
1817
2193
|
return payload;
|
|
1818
2194
|
};
|
|
1819
2195
|
});
|
|
1820
|
-
function handleOptionalResult(
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
value: void 0
|
|
1824
|
-
};
|
|
1825
|
-
return result;
|
|
2196
|
+
function handleOptionalResult(payload, result) {
|
|
2197
|
+
payload.value = result.issues.length ? void 0 : result.value;
|
|
2198
|
+
return payload;
|
|
1826
2199
|
}
|
|
1827
2200
|
const $ZodOptional = /*@__PURE__*/ $constructor("$ZodOptional", (inst, def)=>{
|
|
1828
2201
|
$ZodType.init(inst, def);
|
|
1829
|
-
inst._zod.optin
|
|
2202
|
+
defineLazyInternal(inst, "optin", (zod)=>"defaulted" === zod.def.innerType._zod.optin ? "defaulted" : "optional");
|
|
1830
2203
|
inst._zod.optout = "optional";
|
|
1831
|
-
|
|
1832
|
-
|
|
2204
|
+
defineLazyInternal(inst, "values", (zod)=>{
|
|
2205
|
+
const values = zod.def.innerType._zod.values;
|
|
2206
|
+
return values ? new Set([
|
|
2207
|
+
...values,
|
|
1833
2208
|
void 0
|
|
1834
|
-
]) : void 0
|
|
1835
|
-
|
|
1836
|
-
|
|
2209
|
+
]) : void 0;
|
|
2210
|
+
});
|
|
2211
|
+
defineLazyInternal(inst, "pattern", (zod)=>{
|
|
2212
|
+
const pattern = zod.def.innerType._zod.pattern;
|
|
1837
2213
|
return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
|
|
1838
2214
|
});
|
|
1839
2215
|
inst._zod.parse = (payload, ctx)=>{
|
|
1840
|
-
if (
|
|
1841
|
-
|
|
1842
|
-
const result = def.innerType._zod.run(
|
|
1843
|
-
|
|
1844
|
-
|
|
2216
|
+
if (void 0 === payload.value) {
|
|
2217
|
+
if ("defaulted" !== def.innerType._zod.optin) return payload;
|
|
2218
|
+
const result = def.innerType._zod.run({
|
|
2219
|
+
value: payload.value,
|
|
2220
|
+
issues: []
|
|
2221
|
+
}, ctx);
|
|
2222
|
+
if (result instanceof Promise) return result.then((result)=>handleOptionalResult(payload, result));
|
|
2223
|
+
return handleOptionalResult(payload, result);
|
|
1845
2224
|
}
|
|
1846
|
-
if (void 0 === payload.value) return payload;
|
|
1847
2225
|
return def.innerType._zod.run(payload, ctx);
|
|
1848
2226
|
};
|
|
1849
2227
|
});
|
|
1850
2228
|
const $ZodExactOptional = /*@__PURE__*/ $constructor("$ZodExactOptional", (inst, def)=>{
|
|
1851
2229
|
$ZodOptional.init(inst, def);
|
|
1852
|
-
|
|
1853
|
-
|
|
2230
|
+
defineLazyInternal(inst, "values", (zod)=>zod.def.innerType._zod.values);
|
|
2231
|
+
defineLazyInternal(inst, "pattern", (zod)=>zod.def.innerType._zod.pattern);
|
|
1854
2232
|
inst._zod.parse = (payload, ctx)=>def.innerType._zod.run(payload, ctx);
|
|
1855
2233
|
});
|
|
1856
2234
|
const $ZodNullable = /*@__PURE__*/ $constructor("$ZodNullable", (inst, def)=>{
|
|
1857
2235
|
$ZodType.init(inst, def);
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
const pattern = def.innerType._zod.pattern;
|
|
2236
|
+
defineLazyInternal(inst, "optin", (zod)=>zod.def.innerType._zod.optin);
|
|
2237
|
+
defineLazyInternal(inst, "optout", (zod)=>zod.def.innerType._zod.optout);
|
|
2238
|
+
defineLazyInternal(inst, "pattern", (zod)=>{
|
|
2239
|
+
const pattern = zod.def.innerType._zod.pattern;
|
|
1862
2240
|
return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
|
|
1863
2241
|
});
|
|
1864
|
-
|
|
1865
|
-
...def.innerType._zod.values,
|
|
2242
|
+
defineLazyInternal(inst, "values", (zod)=>zod.def.innerType._zod.values ? new Set([
|
|
2243
|
+
...zod.def.innerType._zod.values,
|
|
1866
2244
|
null
|
|
1867
2245
|
]) : void 0);
|
|
1868
2246
|
inst._zod.parse = (payload, ctx)=>{
|
|
@@ -1872,8 +2250,8 @@ const $ZodNullable = /*@__PURE__*/ $constructor("$ZodNullable", (inst, def)=>{
|
|
|
1872
2250
|
});
|
|
1873
2251
|
const $ZodDefault = /*@__PURE__*/ $constructor("$ZodDefault", (inst, def)=>{
|
|
1874
2252
|
$ZodType.init(inst, def);
|
|
1875
|
-
inst._zod.optin = "
|
|
1876
|
-
|
|
2253
|
+
inst._zod.optin = "defaulted";
|
|
2254
|
+
defineLazyInternal(inst, "values", (zod)=>zod.def.innerType._zod.values);
|
|
1877
2255
|
inst._zod.parse = (payload, ctx)=>{
|
|
1878
2256
|
if ("backward" === ctx.direction) return def.innerType._zod.run(payload, ctx);
|
|
1879
2257
|
if (void 0 === payload.value) {
|
|
@@ -1891,8 +2269,8 @@ function handleDefaultResult(payload, def) {
|
|
|
1891
2269
|
}
|
|
1892
2270
|
const $ZodPrefault = /*@__PURE__*/ $constructor("$ZodPrefault", (inst, def)=>{
|
|
1893
2271
|
$ZodType.init(inst, def);
|
|
1894
|
-
inst._zod.optin = "
|
|
1895
|
-
|
|
2272
|
+
inst._zod.optin = "defaulted";
|
|
2273
|
+
defineLazyInternal(inst, "values", (zod)=>zod.def.innerType._zod.values);
|
|
1896
2274
|
inst._zod.parse = (payload, ctx)=>{
|
|
1897
2275
|
if ("backward" === ctx.direction) return def.innerType._zod.run(payload, ctx);
|
|
1898
2276
|
if (void 0 === payload.value) payload.value = def.defaultValue;
|
|
@@ -1901,8 +2279,8 @@ const $ZodPrefault = /*@__PURE__*/ $constructor("$ZodPrefault", (inst, def)=>{
|
|
|
1901
2279
|
});
|
|
1902
2280
|
const $ZodNonOptional = /*@__PURE__*/ $constructor("$ZodNonOptional", (inst, def)=>{
|
|
1903
2281
|
$ZodType.init(inst, def);
|
|
1904
|
-
|
|
1905
|
-
const v = def.innerType._zod.values;
|
|
2282
|
+
defineLazyInternal(inst, "values", (zod)=>{
|
|
2283
|
+
const v = zod.def.innerType._zod.values;
|
|
1906
2284
|
return v ? new Set([
|
|
1907
2285
|
...v
|
|
1908
2286
|
].filter((x)=>void 0 !== x)) : void 0;
|
|
@@ -1922,50 +2300,43 @@ function handleNonOptionalResult(payload, inst) {
|
|
|
1922
2300
|
});
|
|
1923
2301
|
return payload;
|
|
1924
2302
|
}
|
|
2303
|
+
function handleCatchResult(payload, result, def, ctx) {
|
|
2304
|
+
if (!result.issues.length) {
|
|
2305
|
+
payload.value = result.value;
|
|
2306
|
+
if (result.memo) payload.memo = true;
|
|
2307
|
+
return payload;
|
|
2308
|
+
}
|
|
2309
|
+
payload.value = def.catchValue({
|
|
2310
|
+
...result,
|
|
2311
|
+
value: payload.value,
|
|
2312
|
+
error: {
|
|
2313
|
+
issues: result.issues.map((iss)=>finalizeIssue(iss, ctx, core_config()))
|
|
2314
|
+
},
|
|
2315
|
+
input: payload.value
|
|
2316
|
+
});
|
|
2317
|
+
return payload;
|
|
2318
|
+
}
|
|
1925
2319
|
const $ZodCatch = /*@__PURE__*/ $constructor("$ZodCatch", (inst, def)=>{
|
|
1926
2320
|
$ZodType.init(inst, def);
|
|
1927
|
-
inst._zod.optin
|
|
1928
|
-
|
|
1929
|
-
|
|
2321
|
+
defineLazyInternal(inst, "optin", (zod)=>"defaulted" === zod.def.innerType._zod.optin ? "defaulted" : "optional");
|
|
2322
|
+
defineLazyInternal(inst, "optout", (zod)=>zod.def.innerType._zod.optout);
|
|
2323
|
+
defineLazyInternal(inst, "values", (zod)=>zod.def.innerType._zod.values);
|
|
1930
2324
|
inst._zod.parse = (payload, ctx)=>{
|
|
1931
2325
|
if ("backward" === ctx.direction) return def.innerType._zod.run(payload, ctx);
|
|
1932
|
-
const result = def.innerType._zod.run(
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
error: {
|
|
1939
|
-
issues: result.issues.map((iss)=>finalizeIssue(iss, ctx, core_config()))
|
|
1940
|
-
},
|
|
1941
|
-
input: payload.value
|
|
1942
|
-
});
|
|
1943
|
-
payload.issues = [];
|
|
1944
|
-
payload.fallback = true;
|
|
1945
|
-
}
|
|
1946
|
-
return payload;
|
|
1947
|
-
});
|
|
1948
|
-
payload.value = result.value;
|
|
1949
|
-
if (result.issues.length) {
|
|
1950
|
-
payload.value = def.catchValue({
|
|
1951
|
-
...payload,
|
|
1952
|
-
error: {
|
|
1953
|
-
issues: result.issues.map((iss)=>finalizeIssue(iss, ctx, core_config()))
|
|
1954
|
-
},
|
|
1955
|
-
input: payload.value
|
|
1956
|
-
});
|
|
1957
|
-
payload.issues = [];
|
|
1958
|
-
payload.fallback = true;
|
|
1959
|
-
}
|
|
1960
|
-
return payload;
|
|
2326
|
+
const result = def.innerType._zod.run({
|
|
2327
|
+
value: payload.value,
|
|
2328
|
+
issues: []
|
|
2329
|
+
}, ctx);
|
|
2330
|
+
if (result instanceof Promise) return result.then((result)=>handleCatchResult(payload, result, def, ctx));
|
|
2331
|
+
return handleCatchResult(payload, result, def, ctx);
|
|
1961
2332
|
};
|
|
1962
2333
|
});
|
|
1963
2334
|
const $ZodPipe = /*@__PURE__*/ $constructor("$ZodPipe", (inst, def)=>{
|
|
1964
2335
|
$ZodType.init(inst, def);
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
2336
|
+
defineLazyInternal(inst, "values", (zod)=>zod.def.in._zod.values);
|
|
2337
|
+
defineLazyInternal(inst, "optin", (zod)=>zod.def.in._zod.optin);
|
|
2338
|
+
defineLazyInternal(inst, "optout", (zod)=>zod.def.out._zod.optout);
|
|
2339
|
+
defineLazyInternal(inst, "propValues", (zod)=>zod.def.in._zod.propValues);
|
|
1969
2340
|
inst._zod.parse = (payload, ctx)=>{
|
|
1970
2341
|
if ("backward" === ctx.direction) {
|
|
1971
2342
|
const right = def.out._zod.run(payload, ctx);
|
|
@@ -1978,22 +2349,21 @@ const $ZodPipe = /*@__PURE__*/ $constructor("$ZodPipe", (inst, def)=>{
|
|
|
1978
2349
|
};
|
|
1979
2350
|
});
|
|
1980
2351
|
function handlePipeResult(left, next, ctx) {
|
|
1981
|
-
if (left.issues.
|
|
2352
|
+
if (left.issues.some((iss)=>"unrecognized_keys" !== iss.code)) {
|
|
1982
2353
|
left.aborted = true;
|
|
1983
2354
|
return left;
|
|
1984
2355
|
}
|
|
1985
2356
|
return next._zod.run({
|
|
1986
2357
|
value: left.value,
|
|
1987
|
-
issues: left.issues
|
|
1988
|
-
fallback: left.fallback
|
|
2358
|
+
issues: left.issues
|
|
1989
2359
|
}, ctx);
|
|
1990
2360
|
}
|
|
1991
2361
|
const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def)=>{
|
|
1992
2362
|
$ZodType.init(inst, def);
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
2363
|
+
defineLazyInternal(inst, "propValues", (zod)=>zod.def.innerType._zod.propValues);
|
|
2364
|
+
defineLazyInternal(inst, "values", (zod)=>zod.def.innerType._zod.values);
|
|
2365
|
+
defineLazyInternal(inst, "optin", (zod)=>zod.def.innerType?._zod?.optin);
|
|
2366
|
+
defineLazyInternal(inst, "optout", (zod)=>zod.def.innerType?._zod?.optout);
|
|
1997
2367
|
inst._zod.parse = (payload, ctx)=>{
|
|
1998
2368
|
if ("backward" === ctx.direction) return def.innerType._zod.run(payload, ctx);
|
|
1999
2369
|
const result = def.innerType._zod.run(payload, ctx);
|
|
@@ -2002,7 +2372,7 @@ const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def)=>{
|
|
|
2002
2372
|
};
|
|
2003
2373
|
});
|
|
2004
2374
|
function handleReadonlyResult(payload) {
|
|
2005
|
-
payload.value = Object.freeze(payload.value);
|
|
2375
|
+
if (!payload.memo) payload.value = Object.freeze(payload.value);
|
|
2006
2376
|
return payload;
|
|
2007
2377
|
}
|
|
2008
2378
|
const $ZodCustom = /*@__PURE__*/ $constructor("$ZodCustom", (inst, def)=>{
|
|
@@ -2032,8 +2402,6 @@ function handleRefineResult(result, payload, input, inst) {
|
|
|
2032
2402
|
}
|
|
2033
2403
|
}
|
|
2034
2404
|
var registries_a;
|
|
2035
|
-
Symbol("ZodOutput");
|
|
2036
|
-
Symbol("ZodInput");
|
|
2037
2405
|
class $ZodRegistry {
|
|
2038
2406
|
constructor(){
|
|
2039
2407
|
this._map = new WeakMap();
|
|
@@ -2080,11 +2448,17 @@ function registries_registry() {
|
|
|
2080
2448
|
}
|
|
2081
2449
|
(registries_a = globalThis).__zod_globalRegistry ?? (registries_a.__zod_globalRegistry = registries_registry());
|
|
2082
2450
|
const globalRegistry = globalThis.__zod_globalRegistry;
|
|
2451
|
+
function snapshotChecks(def) {
|
|
2452
|
+
if (def.checks) def.checks = [
|
|
2453
|
+
...def.checks
|
|
2454
|
+
];
|
|
2455
|
+
return def;
|
|
2456
|
+
}
|
|
2083
2457
|
function _string(Class, params) {
|
|
2084
|
-
return new Class({
|
|
2458
|
+
return new Class(snapshotChecks({
|
|
2085
2459
|
type: "string",
|
|
2086
2460
|
...normalizeParams(params)
|
|
2087
|
-
});
|
|
2461
|
+
}));
|
|
2088
2462
|
}
|
|
2089
2463
|
function _email(Class, params) {
|
|
2090
2464
|
return new Class({
|
|
@@ -2453,7 +2827,7 @@ function _superRefine(fn, params) {
|
|
|
2453
2827
|
const _issue = issue;
|
|
2454
2828
|
if (_issue.fatal) _issue.continue = false;
|
|
2455
2829
|
_issue.code ?? (_issue.code = "custom");
|
|
2456
|
-
|
|
2830
|
+
if (!("input" in _issue)) _issue.input = payload.value;
|
|
2457
2831
|
_issue.inst ?? (_issue.inst = ch);
|
|
2458
2832
|
_issue.continue ?? (_issue.continue = !ch._zod.def.abort);
|
|
2459
2833
|
payload.issues.push(util_issue(_issue));
|
|
@@ -2471,6 +2845,10 @@ function _check(fn, params) {
|
|
|
2471
2845
|
ch._zod.check = fn;
|
|
2472
2846
|
return ch;
|
|
2473
2847
|
}
|
|
2848
|
+
function assignProps(target, ...sources) {
|
|
2849
|
+
for (const source of sources)for (const key of Reflect.ownKeys(source))if (Object.prototype.propertyIsEnumerable.call(source, key)) util_assignProp(target, key, source[key]);
|
|
2850
|
+
return target;
|
|
2851
|
+
}
|
|
2474
2852
|
function to_json_schema_initializeContext(params) {
|
|
2475
2853
|
let target = params?.target ?? "draft-2020-12";
|
|
2476
2854
|
if ("draft-4" === target) target = "draft-04";
|
|
@@ -2484,12 +2862,27 @@ function to_json_schema_initializeContext(params) {
|
|
|
2484
2862
|
io: params?.io ?? "output",
|
|
2485
2863
|
counter: 0,
|
|
2486
2864
|
seen: new Map(),
|
|
2865
|
+
sharedDefsExtractedFor: void 0,
|
|
2866
|
+
sharedEmitDoneFor: void 0,
|
|
2487
2867
|
cycles: params?.cycles ?? "ref",
|
|
2488
2868
|
reused: params?.reused ?? "inline",
|
|
2869
|
+
intersections: [],
|
|
2870
|
+
deferred: [],
|
|
2489
2871
|
external: params?.external ?? void 0
|
|
2490
2872
|
};
|
|
2491
2873
|
}
|
|
2492
|
-
function
|
|
2874
|
+
function to_json_schema_handleUnrepresentable(schema, ctx, json, params, message) {
|
|
2875
|
+
const result = "function" == typeof ctx.unrepresentable ? ctx.unrepresentable({
|
|
2876
|
+
zodSchema: schema,
|
|
2877
|
+
path: params.path,
|
|
2878
|
+
message
|
|
2879
|
+
}) : ctx.unrepresentable;
|
|
2880
|
+
if ("any" === result) return false;
|
|
2881
|
+
if (void 0 === result || "throw" === result) throw new Error(message);
|
|
2882
|
+
Object.assign(json, result);
|
|
2883
|
+
return true;
|
|
2884
|
+
}
|
|
2885
|
+
function to_json_schema_processSchema(schema, ctx, _params = {
|
|
2493
2886
|
path: [],
|
|
2494
2887
|
schemaPath: []
|
|
2495
2888
|
}) {
|
|
@@ -2509,6 +2902,8 @@ function to_json_schema_process(schema, ctx, _params = {
|
|
|
2509
2902
|
path: _params.path
|
|
2510
2903
|
};
|
|
2511
2904
|
ctx.seen.set(schema, result);
|
|
2905
|
+
ctx.sharedDefsExtractedFor = void 0;
|
|
2906
|
+
ctx.sharedEmitDoneFor = void 0;
|
|
2512
2907
|
const overrideSchema = schema._zod.toJSONSchema?.();
|
|
2513
2908
|
if (overrideSchema) result.schema = overrideSchema;
|
|
2514
2909
|
else {
|
|
@@ -2530,12 +2925,12 @@ function to_json_schema_process(schema, ctx, _params = {
|
|
|
2530
2925
|
const parent = schema._zod.parent;
|
|
2531
2926
|
if (parent) {
|
|
2532
2927
|
if (!result.ref) result.ref = parent;
|
|
2533
|
-
|
|
2928
|
+
to_json_schema_processSchema(parent, ctx, params);
|
|
2534
2929
|
ctx.seen.get(parent).isParent = true;
|
|
2535
2930
|
}
|
|
2536
2931
|
}
|
|
2537
2932
|
const meta = ctx.metadataRegistry.get(schema);
|
|
2538
|
-
if (meta)
|
|
2933
|
+
if (meta) assignProps(result.schema, meta);
|
|
2539
2934
|
if ("input" === ctx.io && isTransforming(schema)) {
|
|
2540
2935
|
delete result.schema.examples;
|
|
2541
2936
|
delete result.schema.default;
|
|
@@ -2545,9 +2940,13 @@ function to_json_schema_process(schema, ctx, _params = {
|
|
|
2545
2940
|
const _result = ctx.seen.get(schema);
|
|
2546
2941
|
return _result.schema;
|
|
2547
2942
|
}
|
|
2943
|
+
function encodeJSONPointerSegment(segment) {
|
|
2944
|
+
return segment.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
2945
|
+
}
|
|
2548
2946
|
function to_json_schema_extractDefs(ctx, schema) {
|
|
2549
2947
|
const root = ctx.seen.get(schema);
|
|
2550
2948
|
if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
|
|
2949
|
+
if (ctx.external && ctx.sharedDefsExtractedFor === ctx.external) return;
|
|
2551
2950
|
const idToSchema = new Map();
|
|
2552
2951
|
for (const entry of ctx.seen.entries()){
|
|
2553
2952
|
const id = ctx.metadataRegistry.get(entry[0])?.id;
|
|
@@ -2569,18 +2968,18 @@ function to_json_schema_extractDefs(ctx, schema) {
|
|
|
2569
2968
|
entry[1].defId = id;
|
|
2570
2969
|
return {
|
|
2571
2970
|
defId: id,
|
|
2572
|
-
ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}`
|
|
2971
|
+
ref: `${uriGenerator("__shared")}#/${defsSegment}/${encodeJSONPointerSegment(id)}`
|
|
2573
2972
|
};
|
|
2574
2973
|
}
|
|
2575
|
-
if (entry[1] === root) return {
|
|
2576
|
-
ref: "#"
|
|
2577
|
-
};
|
|
2578
2974
|
const uriPrefix = "#";
|
|
2579
2975
|
const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
|
|
2976
|
+
if (entry[1] === root && !entry[1].schema.id) return {
|
|
2977
|
+
ref: uriPrefix
|
|
2978
|
+
};
|
|
2580
2979
|
const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
|
|
2581
2980
|
return {
|
|
2582
2981
|
defId,
|
|
2583
|
-
ref: defUriPrefix + defId
|
|
2982
|
+
ref: defUriPrefix + encodeJSONPointerSegment(defId)
|
|
2584
2983
|
};
|
|
2585
2984
|
};
|
|
2586
2985
|
const extractToDef = (entry)=>{
|
|
@@ -2622,12 +3021,116 @@ function to_json_schema_extractDefs(ctx, schema) {
|
|
|
2622
3021
|
continue;
|
|
2623
3022
|
}
|
|
2624
3023
|
if (seen.count > 1) {
|
|
2625
|
-
if ("ref" === ctx.reused)
|
|
2626
|
-
|
|
2627
|
-
|
|
3024
|
+
if ("ref" === ctx.reused) extractToDef(entry);
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
if (ctx.external) ctx.sharedDefsExtractedFor = ctx.external;
|
|
3028
|
+
}
|
|
3029
|
+
function compactTypeUnion(schema) {
|
|
3030
|
+
const options = schema.anyOf;
|
|
3031
|
+
if (!Array.isArray(options) || 0 === options.length || void 0 !== schema.type) return;
|
|
3032
|
+
const types = [];
|
|
3033
|
+
for (const option of options){
|
|
3034
|
+
if (!option || "object" != typeof option) return;
|
|
3035
|
+
compactTypeUnion(option);
|
|
3036
|
+
const keys = Object.keys(option);
|
|
3037
|
+
if (1 !== keys.length || "type" !== keys[0]) return;
|
|
3038
|
+
const type = option.type;
|
|
3039
|
+
for (const member of Array.isArray(type) ? type : [
|
|
3040
|
+
type
|
|
3041
|
+
]){
|
|
3042
|
+
if ("string" != typeof member) return;
|
|
3043
|
+
if (!types.includes(member)) types.push(member);
|
|
3044
|
+
}
|
|
3045
|
+
}
|
|
3046
|
+
delete schema.anyOf;
|
|
3047
|
+
schema.type = 1 === types.length ? types[0] : types;
|
|
3048
|
+
}
|
|
3049
|
+
const FOLDABLE_KEYS = new Set([
|
|
3050
|
+
"type",
|
|
3051
|
+
"properties",
|
|
3052
|
+
"required",
|
|
3053
|
+
"additionalProperties"
|
|
3054
|
+
]);
|
|
3055
|
+
const UNION_KEYS = [
|
|
3056
|
+
"oneOf",
|
|
3057
|
+
"anyOf"
|
|
3058
|
+
];
|
|
3059
|
+
function undeclaredConstraint(member) {
|
|
3060
|
+
const extra = member.additionalProperties;
|
|
3061
|
+
if (void 0 === extra || false === extra || "object" != typeof extra || null === extra) return null;
|
|
3062
|
+
return Object.keys(extra).length ? extra : null;
|
|
3063
|
+
}
|
|
3064
|
+
function foldObjects(members) {
|
|
3065
|
+
const objects = [];
|
|
3066
|
+
for (const member of members){
|
|
3067
|
+
if ("object" != typeof member || "object" !== member.type) return null;
|
|
3068
|
+
for(const key in member)if (!FOLDABLE_KEYS.has(key)) return null;
|
|
3069
|
+
objects.push(member);
|
|
3070
|
+
}
|
|
3071
|
+
const properties = {};
|
|
3072
|
+
const required = new Set();
|
|
3073
|
+
for (const object of objects){
|
|
3074
|
+
for(const key in object.properties){
|
|
3075
|
+
if (Object.prototype.hasOwnProperty.call(properties, key)) continue;
|
|
3076
|
+
const parts = [];
|
|
3077
|
+
for (const other of objects){
|
|
3078
|
+
const part = other.properties?.[key] ?? undeclaredConstraint(other);
|
|
3079
|
+
if (null != part) {
|
|
3080
|
+
if (!parts.some((seen)=>JSON.stringify(seen) === JSON.stringify(part))) parts.push(part);
|
|
3081
|
+
}
|
|
2628
3082
|
}
|
|
3083
|
+
const merged = 1 === parts.length ? parts[0] : foldObjects(parts) ?? {
|
|
3084
|
+
allOf: parts
|
|
3085
|
+
};
|
|
3086
|
+
util_assignProp(properties, key, merged);
|
|
3087
|
+
}
|
|
3088
|
+
for (const key of object.required ?? [])required.add(key);
|
|
3089
|
+
}
|
|
3090
|
+
const folded = {
|
|
3091
|
+
type: "object",
|
|
3092
|
+
properties
|
|
3093
|
+
};
|
|
3094
|
+
if (required.size) folded.required = [
|
|
3095
|
+
...required
|
|
3096
|
+
];
|
|
3097
|
+
if (objects.every((object)=>false === object.additionalProperties)) folded.additionalProperties = false;
|
|
3098
|
+
else {
|
|
3099
|
+
const constraints = [];
|
|
3100
|
+
for (const object of objects){
|
|
3101
|
+
const constraint = undeclaredConstraint(object);
|
|
3102
|
+
if (constraint && !constraints.some((seen)=>JSON.stringify(seen) === JSON.stringify(constraint))) constraints.push(constraint);
|
|
2629
3103
|
}
|
|
3104
|
+
if (1 === constraints.length) folded.additionalProperties = constraints[0];
|
|
3105
|
+
else if (constraints.length > 1) folded.additionalProperties = {
|
|
3106
|
+
allOf: constraints
|
|
3107
|
+
};
|
|
2630
3108
|
}
|
|
3109
|
+
return folded;
|
|
3110
|
+
}
|
|
3111
|
+
function foldIntersection(json) {
|
|
3112
|
+
const allOf = json.allOf;
|
|
3113
|
+
if (!Array.isArray(allOf) || allOf.length < 2) return;
|
|
3114
|
+
for (const key of FOLDABLE_KEYS)if (key in json) return;
|
|
3115
|
+
const unions = allOf.filter((m)=>UNION_KEYS.some((k)=>Array.isArray(m[k])));
|
|
3116
|
+
let folded = null;
|
|
3117
|
+
if (unions.length) {
|
|
3118
|
+
const union = unions[0];
|
|
3119
|
+
const keyword = UNION_KEYS.find((k)=>Array.isArray(union[k]));
|
|
3120
|
+
if (1 !== Object.keys(union).length) return;
|
|
3121
|
+
const rest = allOf.filter((m)=>m !== union);
|
|
3122
|
+
const branches = union[keyword].map((branch)=>foldObjects([
|
|
3123
|
+
...rest,
|
|
3124
|
+
branch
|
|
3125
|
+
]));
|
|
3126
|
+
if (branches.some((b)=>!b)) return;
|
|
3127
|
+
folded = {
|
|
3128
|
+
[keyword]: branches
|
|
3129
|
+
};
|
|
3130
|
+
} else folded = foldObjects(allOf);
|
|
3131
|
+
if (!folded) return;
|
|
3132
|
+
delete json.allOf;
|
|
3133
|
+
assignProps(json, folded);
|
|
2631
3134
|
}
|
|
2632
3135
|
function to_json_schema_finalize(ctx, schema) {
|
|
2633
3136
|
const root = ctx.seen.get(schema);
|
|
@@ -2648,8 +3151,8 @@ function to_json_schema_finalize(ctx, schema) {
|
|
|
2648
3151
|
if (refSchema.$ref && ("draft-07" === ctx.target || "draft-04" === ctx.target || "openapi-3.0" === ctx.target)) {
|
|
2649
3152
|
schema.allOf = schema.allOf ?? [];
|
|
2650
3153
|
schema.allOf.push(refSchema);
|
|
2651
|
-
} else
|
|
2652
|
-
|
|
3154
|
+
} else assignProps(schema, refSchema);
|
|
3155
|
+
assignProps(schema, _cached);
|
|
2653
3156
|
const isParentRef = zodSchema._zod.parent === ref;
|
|
2654
3157
|
if (isParentRef) {
|
|
2655
3158
|
for(const key in schema)if ("$ref" !== key && "allOf" !== key) {
|
|
@@ -2681,9 +3184,29 @@ function to_json_schema_finalize(ctx, schema) {
|
|
|
2681
3184
|
path: seen.path ?? []
|
|
2682
3185
|
});
|
|
2683
3186
|
};
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
3187
|
+
if (!ctx.external || ctx.sharedEmitDoneFor !== ctx.external) {
|
|
3188
|
+
for (const entry of [
|
|
3189
|
+
...ctx.seen.entries()
|
|
3190
|
+
].reverse())flattenRef(entry[0]);
|
|
3191
|
+
if ("openapi-3.0" !== ctx.target) for (const entry of ctx.seen.entries())compactTypeUnion(entry[1].def ?? entry[1].schema);
|
|
3192
|
+
for (const rewrite of ctx.deferred)rewrite();
|
|
3193
|
+
if (ctx.intersections.length) {
|
|
3194
|
+
const carriers = new Map();
|
|
3195
|
+
for (const seen of ctx.seen.values())for (const json of [
|
|
3196
|
+
seen.schema,
|
|
3197
|
+
seen.def
|
|
3198
|
+
]){
|
|
3199
|
+
const allOf = json?.allOf;
|
|
3200
|
+
if (!Array.isArray(allOf)) continue;
|
|
3201
|
+
const existing = carriers.get(allOf);
|
|
3202
|
+
if (existing) existing.push(json);
|
|
3203
|
+
else carriers.set(allOf, [
|
|
3204
|
+
json
|
|
3205
|
+
]);
|
|
3206
|
+
}
|
|
3207
|
+
for (const allOf of ctx.intersections)for (const json of carriers.get(allOf) ?? [])foldIntersection(json);
|
|
3208
|
+
}
|
|
3209
|
+
}
|
|
2687
3210
|
const result = {};
|
|
2688
3211
|
if ("draft-2020-12" === ctx.target) result.$schema = "https://json-schema.org/draft/2020-12/schema";
|
|
2689
3212
|
else if ("draft-07" === ctx.target) result.$schema = "http://json-schema.org/draft-07/schema#";
|
|
@@ -2694,17 +3217,18 @@ function to_json_schema_finalize(ctx, schema) {
|
|
|
2694
3217
|
if (!id) throw new Error("Schema is missing an `id` property");
|
|
2695
3218
|
result.$id = ctx.external.uri(id);
|
|
2696
3219
|
}
|
|
2697
|
-
|
|
3220
|
+
assignProps(result, root.defId ? root.schema : root.def ?? root.schema);
|
|
2698
3221
|
const rootMetaId = ctx.metadataRegistry.get(schema)?.id;
|
|
2699
3222
|
if (void 0 !== rootMetaId && result.id === rootMetaId) delete result.id;
|
|
2700
3223
|
const defs = ctx.external?.defs ?? {};
|
|
2701
|
-
for (const entry of ctx.seen.entries()){
|
|
3224
|
+
if (!ctx.external || ctx.sharedEmitDoneFor !== ctx.external) for (const entry of ctx.seen.entries()){
|
|
2702
3225
|
const seen = entry[1];
|
|
2703
3226
|
if (seen.def && seen.defId) {
|
|
2704
3227
|
if (seen.def.id === seen.defId) delete seen.def.id;
|
|
2705
|
-
defs
|
|
3228
|
+
util_assignProp(defs, seen.defId, seen.def);
|
|
2706
3229
|
}
|
|
2707
3230
|
}
|
|
3231
|
+
if (ctx.external) ctx.sharedEmitDoneFor = ctx.external;
|
|
2708
3232
|
if (ctx.external) ;
|
|
2709
3233
|
else if (Object.keys(defs).length > 0) if ("draft-2020-12" === ctx.target) result.$defs = defs;
|
|
2710
3234
|
else result.definitions = defs;
|
|
@@ -2737,7 +3261,7 @@ function isTransforming(_schema, _ctx) {
|
|
|
2737
3261
|
if ("array" === def.type) return isTransforming(def.element, ctx);
|
|
2738
3262
|
if ("set" === def.type) return isTransforming(def.valueType, ctx);
|
|
2739
3263
|
if ("lazy" === def.type) return isTransforming(def.getter(), ctx);
|
|
2740
|
-
if ("promise" === def.type || "optional" === def.type || "nonoptional" === def.type || "nullable" === def.type || "readonly" === def.type || "default" === def.type || "prefault" === def.type) return isTransforming(def.innerType, ctx);
|
|
3264
|
+
if ("promise" === def.type || "optional" === def.type || "nonoptional" === def.type || "nullable" === def.type || "readonly" === def.type || "default" === def.type || "prefault" === def.type || "catch" === def.type) return isTransforming(def.innerType, ctx);
|
|
2741
3265
|
if ("intersection" === def.type) return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
|
|
2742
3266
|
if ("record" === def.type || "map" === def.type) return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
|
|
2743
3267
|
if ("pipe" === def.type) {
|
|
@@ -2763,7 +3287,7 @@ const createToJSONSchemaMethod = (schema, processors = {})=>(params)=>{
|
|
|
2763
3287
|
...params,
|
|
2764
3288
|
processors
|
|
2765
3289
|
});
|
|
2766
|
-
|
|
3290
|
+
to_json_schema_processSchema(schema, ctx);
|
|
2767
3291
|
to_json_schema_extractDefs(ctx, schema);
|
|
2768
3292
|
return to_json_schema_finalize(ctx, schema);
|
|
2769
3293
|
};
|
|
@@ -2775,10 +3299,87 @@ const createStandardJSONSchemaMethod = (schema, io, processors = {})=>(params)=>
|
|
|
2775
3299
|
io,
|
|
2776
3300
|
processors
|
|
2777
3301
|
});
|
|
2778
|
-
|
|
3302
|
+
to_json_schema_processSchema(schema, ctx);
|
|
2779
3303
|
to_json_schema_extractDefs(ctx, schema);
|
|
2780
3304
|
return to_json_schema_finalize(ctx, schema);
|
|
2781
3305
|
};
|
|
3306
|
+
const narrowMin = (agg, key, value)=>{
|
|
3307
|
+
if (void 0 === agg[key] || value > agg[key]) agg[key] = value;
|
|
3308
|
+
};
|
|
3309
|
+
const narrowMax = (agg, key, value)=>{
|
|
3310
|
+
if (void 0 === agg[key] || value < agg[key]) agg[key] = value;
|
|
3311
|
+
};
|
|
3312
|
+
const narrowBoth = (agg, value)=>{
|
|
3313
|
+
narrowMin(agg, "minimum", value);
|
|
3314
|
+
narrowMax(agg, "maximum", value);
|
|
3315
|
+
};
|
|
3316
|
+
const addDivisor = (agg, value)=>{
|
|
3317
|
+
agg.multipleOf ?? (agg.multipleOf = []);
|
|
3318
|
+
if (!agg.multipleOf.includes(value)) agg.multipleOf.push(value);
|
|
3319
|
+
};
|
|
3320
|
+
const addPattern = (agg, pattern)=>{
|
|
3321
|
+
agg.patterns ?? (agg.patterns = new Set());
|
|
3322
|
+
agg.patterns.add(pattern);
|
|
3323
|
+
};
|
|
3324
|
+
const intersectMime = (agg, mime)=>{
|
|
3325
|
+
agg.mime = agg.mime ? agg.mime.filter((m)=>mime.includes(m)) : [
|
|
3326
|
+
...mime
|
|
3327
|
+
];
|
|
3328
|
+
};
|
|
3329
|
+
const setFormat = (agg, format)=>{
|
|
3330
|
+
agg.format = format;
|
|
3331
|
+
if (format.includes("int")) agg.isInt = true;
|
|
3332
|
+
};
|
|
3333
|
+
const minContributor = (agg, def)=>narrowMin(agg, "minimum", def.minimum);
|
|
3334
|
+
const maxContributor = (agg, def)=>narrowMax(agg, "maximum", def.maximum);
|
|
3335
|
+
const formatContributor = (ranges)=>(agg, def)=>{
|
|
3336
|
+
setFormat(agg, def.format);
|
|
3337
|
+
const [minimum, maximum] = ranges[def.format];
|
|
3338
|
+
narrowMin(agg, "minimum", minimum);
|
|
3339
|
+
narrowMax(agg, "maximum", maximum);
|
|
3340
|
+
};
|
|
3341
|
+
const contributors = {
|
|
3342
|
+
greater_than: (agg, def)=>narrowMin(agg, def.inclusive ? "minimum" : "exclusiveMinimum", def.value),
|
|
3343
|
+
less_than: (agg, def)=>narrowMax(agg, def.inclusive ? "maximum" : "exclusiveMaximum", def.value),
|
|
3344
|
+
multiple_of: (agg, def)=>addDivisor(agg, def.value),
|
|
3345
|
+
number_format: formatContributor(NUMBER_FORMAT_RANGES),
|
|
3346
|
+
bigint_format: formatContributor(BIGINT_FORMAT_RANGES),
|
|
3347
|
+
min_length: minContributor,
|
|
3348
|
+
max_length: maxContributor,
|
|
3349
|
+
length_equals: (agg, def)=>narrowBoth(agg, def.length),
|
|
3350
|
+
min_size: minContributor,
|
|
3351
|
+
max_size: maxContributor,
|
|
3352
|
+
size_equals: (agg, def)=>narrowBoth(agg, def.size),
|
|
3353
|
+
string_format: (agg, def)=>{
|
|
3354
|
+
setFormat(agg, def.format);
|
|
3355
|
+
if (def.pattern) addPattern(agg, def.pattern);
|
|
3356
|
+
if ("base64" === def.format || "base64url" === def.format) agg.contentEncoding = def.format;
|
|
3357
|
+
if (def.local || -1 === def.precision) agg.laxFormat = true;
|
|
3358
|
+
},
|
|
3359
|
+
mime_type: (agg, def)=>intersectMime(agg, def.mime)
|
|
3360
|
+
};
|
|
3361
|
+
function aggregateChecks(schema) {
|
|
3362
|
+
const agg = {};
|
|
3363
|
+
const def = schema._zod.def;
|
|
3364
|
+
const list = schema._zod.traits.has("$ZodCheck") ? [
|
|
3365
|
+
schema,
|
|
3366
|
+
...def.checks ?? []
|
|
3367
|
+
] : def.checks ?? [];
|
|
3368
|
+
for (const ch of list)contributors[ch._zod.def.check]?.(agg, ch._zod.def);
|
|
3369
|
+
const bag = schema._zod.bag;
|
|
3370
|
+
if (void 0 !== bag.minimum) narrowMin(agg, "minimum", bag.minimum);
|
|
3371
|
+
if (void 0 !== bag.exclusiveMinimum) narrowMin(agg, "exclusiveMinimum", bag.exclusiveMinimum);
|
|
3372
|
+
if (void 0 !== bag.maximum) narrowMax(agg, "maximum", bag.maximum);
|
|
3373
|
+
if (void 0 !== bag.exclusiveMaximum) narrowMax(agg, "exclusiveMaximum", bag.exclusiveMaximum);
|
|
3374
|
+
if (void 0 !== bag.multipleOf) addDivisor(agg, bag.multipleOf);
|
|
3375
|
+
if (void 0 !== bag.format) {
|
|
3376
|
+
agg.format ?? (agg.format = bag.format);
|
|
3377
|
+
if (bag.format.includes("int")) agg.isInt = true;
|
|
3378
|
+
}
|
|
3379
|
+
if (bag.mime) intersectMime(agg, bag.mime);
|
|
3380
|
+
for (const pattern of bag.patterns ?? [])addPattern(agg, pattern);
|
|
3381
|
+
return agg;
|
|
3382
|
+
}
|
|
2782
3383
|
const formatMap = {
|
|
2783
3384
|
guid: "uuid",
|
|
2784
3385
|
url: "uri",
|
|
@@ -2786,25 +3387,36 @@ const formatMap = {
|
|
|
2786
3387
|
json_string: "json-string",
|
|
2787
3388
|
regex: ""
|
|
2788
3389
|
};
|
|
3390
|
+
const exactPatterns = new Map([
|
|
3391
|
+
[
|
|
3392
|
+
base64Charset,
|
|
3393
|
+
regexes_base64
|
|
3394
|
+
],
|
|
3395
|
+
[
|
|
3396
|
+
base64urlCharset,
|
|
3397
|
+
regexes_base64url
|
|
3398
|
+
]
|
|
3399
|
+
]);
|
|
3400
|
+
const exactPattern = (p)=>exactPatterns.get(p) ?? p;
|
|
2789
3401
|
const stringProcessor = (schema, ctx, _json, _params)=>{
|
|
2790
3402
|
const json = _json;
|
|
2791
3403
|
json.type = "string";
|
|
2792
|
-
const { minimum, maximum, format, patterns, contentEncoding } = schema
|
|
3404
|
+
const { minimum, maximum, format, patterns, contentEncoding, laxFormat } = aggregateChecks(schema);
|
|
2793
3405
|
if ("number" == typeof minimum) json.minLength = minimum;
|
|
2794
3406
|
if ("number" == typeof maximum) json.maxLength = maximum;
|
|
2795
3407
|
if (format) {
|
|
2796
3408
|
json.format = formatMap[format] ?? format;
|
|
2797
3409
|
if ("" === json.format) delete json.format;
|
|
2798
|
-
if ("time" === format) delete json.format;
|
|
3410
|
+
if ("time" === format || laxFormat) delete json.format;
|
|
2799
3411
|
}
|
|
2800
3412
|
if (contentEncoding) json.contentEncoding = contentEncoding;
|
|
2801
3413
|
if (patterns && patterns.size > 0) {
|
|
2802
|
-
const
|
|
3414
|
+
const patternList = [
|
|
2803
3415
|
...patterns
|
|
2804
|
-
];
|
|
2805
|
-
if (1 ===
|
|
2806
|
-
else if (
|
|
2807
|
-
...
|
|
3416
|
+
].map(exactPattern);
|
|
3417
|
+
if (1 === patternList.length) json.pattern = patternList[0].source;
|
|
3418
|
+
else if (patternList.length > 1) json.allOf = [
|
|
3419
|
+
...patternList.map((regex)=>({
|
|
2808
3420
|
..."draft-07" === ctx.target || "draft-04" === ctx.target || "openapi-3.0" === ctx.target ? {
|
|
2809
3421
|
type: "string"
|
|
2810
3422
|
} : {},
|
|
@@ -2823,24 +3435,28 @@ const unknownProcessor = (_schema, _ctx, _json, _params)=>{};
|
|
|
2823
3435
|
const enumProcessor = (schema, _ctx, json, _params)=>{
|
|
2824
3436
|
const def = schema._zod.def;
|
|
2825
3437
|
const values = getEnumValues(def.entries);
|
|
3438
|
+
if (0 === values.length) {
|
|
3439
|
+
json.not = {};
|
|
3440
|
+
return;
|
|
3441
|
+
}
|
|
2826
3442
|
if (values.every((v)=>"number" == typeof v)) json.type = "number";
|
|
2827
3443
|
if (values.every((v)=>"string" == typeof v)) json.type = "string";
|
|
2828
3444
|
json.enum = values;
|
|
2829
3445
|
};
|
|
2830
|
-
const customProcessor = (
|
|
2831
|
-
|
|
3446
|
+
const customProcessor = (schema, ctx, json, params)=>{
|
|
3447
|
+
to_json_schema_handleUnrepresentable(schema, ctx, json, params, "Custom types cannot be represented in JSON Schema");
|
|
2832
3448
|
};
|
|
2833
|
-
const transformProcessor = (
|
|
2834
|
-
|
|
3449
|
+
const transformProcessor = (schema, ctx, json, params)=>{
|
|
3450
|
+
to_json_schema_handleUnrepresentable(schema, ctx, json, params, "Transforms cannot be represented in JSON Schema");
|
|
2835
3451
|
};
|
|
2836
3452
|
const arrayProcessor = (schema, ctx, _json, params)=>{
|
|
2837
3453
|
const json = _json;
|
|
2838
3454
|
const def = schema._zod.def;
|
|
2839
|
-
const { minimum, maximum } = schema
|
|
3455
|
+
const { minimum, maximum } = aggregateChecks(schema);
|
|
2840
3456
|
if ("number" == typeof minimum) json.minItems = minimum;
|
|
2841
3457
|
if ("number" == typeof maximum) json.maxItems = maximum;
|
|
2842
3458
|
json.type = "array";
|
|
2843
|
-
json.items =
|
|
3459
|
+
json.items = to_json_schema_processSchema(def.element, ctx, {
|
|
2844
3460
|
...params,
|
|
2845
3461
|
path: [
|
|
2846
3462
|
...params.path,
|
|
@@ -2848,32 +3464,37 @@ const arrayProcessor = (schema, ctx, _json, params)=>{
|
|
|
2848
3464
|
]
|
|
2849
3465
|
});
|
|
2850
3466
|
};
|
|
3467
|
+
function inputOptin(schema) {
|
|
3468
|
+
const def = schema._zod.def;
|
|
3469
|
+
if ("pipe" === def.type && def.in._zod.traits.has("$ZodTransform")) return inputOptin(def.out);
|
|
3470
|
+
if ("catch" === def.type) return inputOptin(def.innerType);
|
|
3471
|
+
return schema._zod.optin;
|
|
3472
|
+
}
|
|
2851
3473
|
const objectProcessor = (schema, ctx, _json, params)=>{
|
|
2852
3474
|
const json = _json;
|
|
2853
3475
|
const def = schema._zod.def;
|
|
3476
|
+
const shape = def.shape;
|
|
3477
|
+
const symbolKeys = Object.getOwnPropertySymbols(shape);
|
|
3478
|
+
if (symbolKeys.length && to_json_schema_handleUnrepresentable(schema, ctx, json, params, "Symbol keys cannot be represented in JSON Schema")) return;
|
|
2854
3479
|
json.type = "object";
|
|
2855
3480
|
json.properties = {};
|
|
2856
|
-
const shape
|
|
2857
|
-
for(const key in shape)json.properties[key] = to_json_schema_process(shape[key], ctx, {
|
|
3481
|
+
for(const key in shape)util_assignProp(json.properties, key, to_json_schema_processSchema(shape[key], ctx, {
|
|
2858
3482
|
...params,
|
|
2859
3483
|
path: [
|
|
2860
3484
|
...params.path,
|
|
2861
3485
|
"properties",
|
|
2862
3486
|
key
|
|
2863
3487
|
]
|
|
2864
|
-
});
|
|
2865
|
-
const allKeys = new Set(Object.keys(shape));
|
|
2866
|
-
const requiredKeys = new Set([
|
|
2867
|
-
...allKeys
|
|
2868
|
-
].filter((key)=>{
|
|
2869
|
-
const v = def.shape[key]._zod;
|
|
2870
|
-
if ("input" === ctx.io) return void 0 === v.optin;
|
|
2871
|
-
return void 0 === v.optout;
|
|
2872
3488
|
}));
|
|
2873
|
-
|
|
3489
|
+
const requiredKeys = [];
|
|
3490
|
+
for (const key of Object.keys(shape)){
|
|
3491
|
+
const field = def.shape[key];
|
|
3492
|
+
if ("input" === ctx.io ? void 0 === inputOptin(field) : void 0 === field._zod.optout) requiredKeys.push(key);
|
|
3493
|
+
}
|
|
3494
|
+
if (requiredKeys.length > 0) json.required = requiredKeys;
|
|
2874
3495
|
if (def.catchall?._zod.def.type === "never") json.additionalProperties = false;
|
|
2875
3496
|
else if (def.catchall) {
|
|
2876
|
-
if (def.catchall) json.additionalProperties =
|
|
3497
|
+
if (def.catchall) json.additionalProperties = to_json_schema_processSchema(def.catchall, ctx, {
|
|
2877
3498
|
...params,
|
|
2878
3499
|
path: [
|
|
2879
3500
|
...params.path,
|
|
@@ -2885,7 +3506,7 @@ const objectProcessor = (schema, ctx, _json, params)=>{
|
|
|
2885
3506
|
const unionProcessor = (schema, ctx, json, params)=>{
|
|
2886
3507
|
const def = schema._zod.def;
|
|
2887
3508
|
const isExclusive = false === def.inclusive;
|
|
2888
|
-
const options = def.options.map((x, i)=>
|
|
3509
|
+
const options = def.options.map((x, i)=>to_json_schema_processSchema(x, ctx, {
|
|
2889
3510
|
...params,
|
|
2890
3511
|
path: [
|
|
2891
3512
|
...params.path,
|
|
@@ -2898,7 +3519,7 @@ const unionProcessor = (schema, ctx, json, params)=>{
|
|
|
2898
3519
|
};
|
|
2899
3520
|
const intersectionProcessor = (schema, ctx, json, params)=>{
|
|
2900
3521
|
const def = schema._zod.def;
|
|
2901
|
-
const a =
|
|
3522
|
+
const a = to_json_schema_processSchema(def.left, ctx, {
|
|
2902
3523
|
...params,
|
|
2903
3524
|
path: [
|
|
2904
3525
|
...params.path,
|
|
@@ -2906,7 +3527,7 @@ const intersectionProcessor = (schema, ctx, json, params)=>{
|
|
|
2906
3527
|
0
|
|
2907
3528
|
]
|
|
2908
3529
|
});
|
|
2909
|
-
const b =
|
|
3530
|
+
const b = to_json_schema_processSchema(def.right, ctx, {
|
|
2910
3531
|
...params,
|
|
2911
3532
|
path: [
|
|
2912
3533
|
...params.path,
|
|
@@ -2924,10 +3545,12 @@ const intersectionProcessor = (schema, ctx, json, params)=>{
|
|
|
2924
3545
|
]
|
|
2925
3546
|
];
|
|
2926
3547
|
json.allOf = allOf;
|
|
3548
|
+
ctx.intersections.push(allOf);
|
|
2927
3549
|
};
|
|
3550
|
+
new WeakMap();
|
|
2928
3551
|
const nullableProcessor = (schema, ctx, json, params)=>{
|
|
2929
3552
|
const def = schema._zod.def;
|
|
2930
|
-
const inner =
|
|
3553
|
+
const inner = to_json_schema_processSchema(def.innerType, ctx, params);
|
|
2931
3554
|
const seen = ctx.seen.get(schema);
|
|
2932
3555
|
if ("openapi-3.0" === ctx.target) {
|
|
2933
3556
|
seen.ref = def.innerType;
|
|
@@ -2941,401 +3564,953 @@ const nullableProcessor = (schema, ctx, json, params)=>{
|
|
|
2941
3564
|
};
|
|
2942
3565
|
const nonoptionalProcessor = (schema, ctx, _json, params)=>{
|
|
2943
3566
|
const def = schema._zod.def;
|
|
2944
|
-
|
|
3567
|
+
to_json_schema_processSchema(def.innerType, ctx, params);
|
|
2945
3568
|
const seen = ctx.seen.get(schema);
|
|
2946
3569
|
seen.ref = def.innerType;
|
|
2947
3570
|
};
|
|
3571
|
+
const UNREPRESENTABLE_DEFAULT = Symbol();
|
|
3572
|
+
function serializeDefaultValue(value, schema, ctx, json, params) {
|
|
3573
|
+
let unrepresentable = false;
|
|
3574
|
+
const serialized = JSON.stringify(value, (_, val)=>{
|
|
3575
|
+
if ("bigint" != typeof val) return val;
|
|
3576
|
+
unrepresentable = true;
|
|
3577
|
+
return null;
|
|
3578
|
+
});
|
|
3579
|
+
if (!unrepresentable) return JSON.parse(serialized);
|
|
3580
|
+
to_json_schema_handleUnrepresentable(schema, ctx, json, params, "BigInt defaults cannot be represented in JSON Schema");
|
|
3581
|
+
return UNREPRESENTABLE_DEFAULT;
|
|
3582
|
+
}
|
|
2948
3583
|
const defaultProcessor = (schema, ctx, json, params)=>{
|
|
2949
3584
|
const def = schema._zod.def;
|
|
2950
|
-
|
|
3585
|
+
to_json_schema_processSchema(def.innerType, ctx, params);
|
|
3586
|
+
const seen = ctx.seen.get(schema);
|
|
3587
|
+
seen.ref = def.innerType;
|
|
3588
|
+
const value = serializeDefaultValue(def.defaultValue, schema, ctx, json, params);
|
|
3589
|
+
if (value !== UNREPRESENTABLE_DEFAULT) json.default = value;
|
|
3590
|
+
};
|
|
3591
|
+
const prefaultProcessor = (schema, ctx, json, params)=>{
|
|
3592
|
+
const def = schema._zod.def;
|
|
3593
|
+
to_json_schema_processSchema(def.innerType, ctx, params);
|
|
3594
|
+
const seen = ctx.seen.get(schema);
|
|
3595
|
+
seen.ref = def.innerType;
|
|
3596
|
+
if ("input" !== ctx.io) return;
|
|
3597
|
+
const value = serializeDefaultValue(def.defaultValue, schema, ctx, json, params);
|
|
3598
|
+
if (value !== UNREPRESENTABLE_DEFAULT) json._prefault = value;
|
|
3599
|
+
};
|
|
3600
|
+
const catchProcessor = (schema, ctx, json, params)=>{
|
|
3601
|
+
const def = schema._zod.def;
|
|
3602
|
+
to_json_schema_processSchema(def.innerType, ctx, params);
|
|
3603
|
+
const seen = ctx.seen.get(schema);
|
|
3604
|
+
seen.ref = def.innerType;
|
|
3605
|
+
let catchValue;
|
|
3606
|
+
try {
|
|
3607
|
+
catchValue = def.catchValue(void 0);
|
|
3608
|
+
} catch {
|
|
3609
|
+
to_json_schema_handleUnrepresentable(schema, ctx, json, params, "Dynamic catch values are not supported in JSON Schema");
|
|
3610
|
+
return;
|
|
3611
|
+
}
|
|
3612
|
+
json.default = catchValue;
|
|
3613
|
+
};
|
|
3614
|
+
const pipeProcessor = (schema, ctx, _json, params)=>{
|
|
3615
|
+
const def = schema._zod.def;
|
|
3616
|
+
const inIsTransform = def.in._zod.traits.has("$ZodTransform");
|
|
3617
|
+
const innerType = "input" === ctx.io ? inIsTransform ? def.out : def.in : def.out;
|
|
3618
|
+
to_json_schema_processSchema(innerType, ctx, params);
|
|
3619
|
+
const seen = ctx.seen.get(schema);
|
|
3620
|
+
seen.ref = innerType;
|
|
3621
|
+
};
|
|
3622
|
+
const readonlyProcessor = (schema, ctx, json, params)=>{
|
|
3623
|
+
const def = schema._zod.def;
|
|
3624
|
+
to_json_schema_processSchema(def.innerType, ctx, params);
|
|
3625
|
+
const seen = ctx.seen.get(schema);
|
|
3626
|
+
seen.ref = def.innerType;
|
|
3627
|
+
json.readOnly = true;
|
|
3628
|
+
};
|
|
3629
|
+
const optionalProcessor = (schema, ctx, _json, params)=>{
|
|
3630
|
+
const def = schema._zod.def;
|
|
3631
|
+
to_json_schema_processSchema(def.innerType, ctx, params);
|
|
2951
3632
|
const seen = ctx.seen.get(schema);
|
|
2952
3633
|
seen.ref = def.innerType;
|
|
2953
|
-
json.default = JSON.parse(JSON.stringify(def.defaultValue));
|
|
2954
3634
|
};
|
|
2955
|
-
const
|
|
2956
|
-
const
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
3635
|
+
const en_error = ()=>{
|
|
3636
|
+
const Sizable = {
|
|
3637
|
+
string: {
|
|
3638
|
+
unit: "characters",
|
|
3639
|
+
verb: "to have"
|
|
3640
|
+
},
|
|
3641
|
+
file: {
|
|
3642
|
+
unit: "bytes",
|
|
3643
|
+
verb: "to have"
|
|
3644
|
+
},
|
|
3645
|
+
array: {
|
|
3646
|
+
unit: "items",
|
|
3647
|
+
verb: "to have"
|
|
3648
|
+
},
|
|
3649
|
+
set: {
|
|
3650
|
+
unit: "items",
|
|
3651
|
+
verb: "to have"
|
|
3652
|
+
},
|
|
3653
|
+
map: {
|
|
3654
|
+
unit: "entries",
|
|
3655
|
+
verb: "to have"
|
|
3656
|
+
}
|
|
3657
|
+
};
|
|
3658
|
+
function getSizing(origin) {
|
|
3659
|
+
return Sizable[origin] ?? null;
|
|
3660
|
+
}
|
|
3661
|
+
const FormatDictionary = {
|
|
3662
|
+
regex: "input",
|
|
3663
|
+
email: "email address",
|
|
3664
|
+
url: "URL",
|
|
3665
|
+
emoji: "emoji",
|
|
3666
|
+
uuid: "UUID",
|
|
3667
|
+
uuidv4: "UUIDv4",
|
|
3668
|
+
uuidv6: "UUIDv6",
|
|
3669
|
+
nanoid: "nanoid",
|
|
3670
|
+
guid: "GUID",
|
|
3671
|
+
cuid: "cuid",
|
|
3672
|
+
cuid2: "cuid2",
|
|
3673
|
+
ulid: "ULID",
|
|
3674
|
+
xid: "XID",
|
|
3675
|
+
ksuid: "KSUID",
|
|
3676
|
+
datetime: "ISO datetime",
|
|
3677
|
+
date: "ISO date",
|
|
3678
|
+
time: "ISO time",
|
|
3679
|
+
duration: "ISO duration",
|
|
3680
|
+
ipv4: "IPv4 address",
|
|
3681
|
+
ipv6: "IPv6 address",
|
|
3682
|
+
mac: "MAC address",
|
|
3683
|
+
cidrv4: "IPv4 range",
|
|
3684
|
+
cidrv6: "IPv6 range",
|
|
3685
|
+
base64: "base64-encoded string",
|
|
3686
|
+
base64url: "base64url-encoded string",
|
|
3687
|
+
json_string: "JSON string",
|
|
3688
|
+
e164: "E.164 number",
|
|
3689
|
+
currency_code: "currency code",
|
|
3690
|
+
credit_card: "credit card number",
|
|
3691
|
+
iban: "IBAN",
|
|
3692
|
+
jwt: "JWT",
|
|
3693
|
+
template_literal: "input"
|
|
3694
|
+
};
|
|
3695
|
+
const TypeDictionary = {
|
|
3696
|
+
nan: "NaN"
|
|
3697
|
+
};
|
|
3698
|
+
function getTypeName(type, input) {
|
|
3699
|
+
if ("number" === type && "number" == typeof input && !Number.isFinite(input)) return String(input);
|
|
3700
|
+
return TypeDictionary[type] ?? type;
|
|
3701
|
+
}
|
|
3702
|
+
return (issue)=>{
|
|
3703
|
+
switch(issue.code){
|
|
3704
|
+
case "invalid_type":
|
|
3705
|
+
{
|
|
3706
|
+
const expected = getTypeName(issue.expected);
|
|
3707
|
+
const receivedType = parsedType(issue.input);
|
|
3708
|
+
const received = getTypeName(receivedType, issue.input);
|
|
3709
|
+
return `Invalid input: expected ${expected}, received ${received}`;
|
|
3710
|
+
}
|
|
3711
|
+
case "invalid_value":
|
|
3712
|
+
if (1 === issue.values.length) return `Invalid input: expected ${stringifyPrimitive(issue.values[0])}`;
|
|
3713
|
+
return `Invalid option: expected one of ${joinValues(issue.values, "|")}`;
|
|
3714
|
+
case "too_big":
|
|
3715
|
+
{
|
|
3716
|
+
const adj = issue.exact ? "exactly " : issue.inclusive ? "<=" : "<";
|
|
3717
|
+
const sizing = getSizing(issue.origin);
|
|
3718
|
+
if (sizing) return `Too big: expected ${issue.origin ?? "value"} to have ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elements"}`;
|
|
3719
|
+
return `Too big: expected ${issue.origin ?? "value"} to be ${adj}${issue.maximum.toString()}`;
|
|
3720
|
+
}
|
|
3721
|
+
case "too_small":
|
|
3722
|
+
{
|
|
3723
|
+
const adj = issue.exact ? "exactly " : issue.inclusive ? ">=" : ">";
|
|
3724
|
+
const sizing = getSizing(issue.origin);
|
|
3725
|
+
if (sizing) return `Too small: expected ${issue.origin} to have ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
|
3726
|
+
return `Too small: expected ${issue.origin} to be ${adj}${issue.minimum.toString()}`;
|
|
3727
|
+
}
|
|
3728
|
+
case "invalid_format":
|
|
3729
|
+
{
|
|
3730
|
+
const _issue = issue;
|
|
3731
|
+
if ("starts_with" === _issue.format) return `Invalid string: must start with "${_issue.prefix}"`;
|
|
3732
|
+
if ("ends_with" === _issue.format) return `Invalid string: must end with "${_issue.suffix}"`;
|
|
3733
|
+
if ("includes" === _issue.format) return `Invalid string: must include "${_issue.includes}"`;
|
|
3734
|
+
if ("regex" === _issue.format) return `Invalid string: must match pattern ${_issue.pattern}`;
|
|
3735
|
+
return `Invalid ${FormatDictionary[_issue.format] ?? issue.format}`;
|
|
3736
|
+
}
|
|
3737
|
+
case "not_multiple_of":
|
|
3738
|
+
return `Invalid number: must be a multiple of ${issue.divisor}`;
|
|
3739
|
+
case "unrecognized_keys":
|
|
3740
|
+
return `Unrecognized key${issue.keys.length > 1 ? "s" : ""}: ${joinValues(issue.keys, ", ")}`;
|
|
3741
|
+
case "invalid_key":
|
|
3742
|
+
return `Invalid key in ${issue.origin}`;
|
|
3743
|
+
case "invalid_union":
|
|
3744
|
+
if (issue.options && Array.isArray(issue.options) && issue.options.length > 0) {
|
|
3745
|
+
const opts = issue.options.map((o)=>`'${o}'`).join(" | ");
|
|
3746
|
+
return `Invalid discriminator value. Expected ${opts}`;
|
|
3747
|
+
}
|
|
3748
|
+
if (false === issue.inclusive) return "Invalid input: more than one option matched";
|
|
3749
|
+
return "Invalid input";
|
|
3750
|
+
case "invalid_element":
|
|
3751
|
+
return `Invalid value in ${issue.origin}`;
|
|
3752
|
+
default:
|
|
3753
|
+
return "Invalid input";
|
|
3754
|
+
}
|
|
3755
|
+
};
|
|
3756
|
+
};
|
|
3757
|
+
function en() {
|
|
3758
|
+
return {
|
|
3759
|
+
localeError: en_error()
|
|
3760
|
+
};
|
|
3761
|
+
}
|
|
3762
|
+
function _getMessage() {
|
|
3763
|
+
const internals = this._zod;
|
|
3764
|
+
internals.message ?? (internals.message = JSON.stringify(internals.def, jsonStringifyReplacer, 2));
|
|
3765
|
+
return internals.message;
|
|
3766
|
+
}
|
|
3767
|
+
function _setMessage(value) {
|
|
3768
|
+
this._zod.message = value;
|
|
3769
|
+
}
|
|
3770
|
+
const _messageDesc = {
|
|
3771
|
+
get: _getMessage,
|
|
3772
|
+
set: _setMessage,
|
|
3773
|
+
enumerable: true,
|
|
3774
|
+
configurable: true
|
|
3775
|
+
};
|
|
3776
|
+
const _issuesDesc = {
|
|
3777
|
+
value: void 0,
|
|
3778
|
+
enumerable: false
|
|
3779
|
+
};
|
|
3780
|
+
const _installedToString = /* @__PURE__ */ new WeakSet([
|
|
3781
|
+
Object.prototype,
|
|
3782
|
+
Error.prototype
|
|
3783
|
+
]);
|
|
3784
|
+
const errors_initializer = (inst, def)=>{
|
|
3785
|
+
inst.name = "$ZodError";
|
|
3786
|
+
_issuesDesc.value = def;
|
|
3787
|
+
Object.defineProperty(inst, "issues", _issuesDesc);
|
|
3788
|
+
_issuesDesc.value = void 0;
|
|
3789
|
+
Object.defineProperty(inst, "message", _messageDesc);
|
|
3790
|
+
const proto = Object.getPrototypeOf(inst);
|
|
3791
|
+
if (!_installedToString.has(proto)) {
|
|
3792
|
+
_installedToString.add(proto);
|
|
3793
|
+
Object.defineProperty(proto, "toString", {
|
|
3794
|
+
configurable: true,
|
|
3795
|
+
enumerable: false,
|
|
3796
|
+
get () {
|
|
3797
|
+
const value = ()=>this.message;
|
|
3798
|
+
Object.defineProperty(this, "toString", {
|
|
3799
|
+
value,
|
|
3800
|
+
configurable: true,
|
|
3801
|
+
writable: true
|
|
3802
|
+
});
|
|
3803
|
+
return value;
|
|
3804
|
+
},
|
|
3805
|
+
set (value) {
|
|
3806
|
+
Object.defineProperty(this, "toString", {
|
|
3807
|
+
value,
|
|
3808
|
+
configurable: true,
|
|
3809
|
+
writable: true
|
|
3810
|
+
});
|
|
3811
|
+
}
|
|
3812
|
+
});
|
|
3813
|
+
}
|
|
3814
|
+
};
|
|
3815
|
+
const $ZodError = $constructor("$ZodError", errors_initializer);
|
|
3816
|
+
$constructor("$ZodError", errors_initializer, void 0, {
|
|
3817
|
+
Parent: Error
|
|
3818
|
+
});
|
|
3819
|
+
function errors_node(obj, key, make) {
|
|
3820
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) if ("__proto__" === key) Object.defineProperty(obj, key, {
|
|
3821
|
+
value: make(),
|
|
3822
|
+
writable: true,
|
|
3823
|
+
enumerable: true,
|
|
3824
|
+
configurable: true
|
|
3825
|
+
});
|
|
3826
|
+
else obj[key] = make();
|
|
3827
|
+
return obj[key];
|
|
3828
|
+
}
|
|
3829
|
+
function flattenError(error, mapper = (issue)=>issue.message) {
|
|
3830
|
+
const fieldErrors = {};
|
|
3831
|
+
const formErrors = [];
|
|
3832
|
+
for (const sub of error.issues)if (sub.path.length > 0) errors_node(fieldErrors, sub.path[0], ()=>[]).push(mapper(sub));
|
|
3833
|
+
else formErrors.push(mapper(sub));
|
|
3834
|
+
return {
|
|
3835
|
+
formErrors,
|
|
3836
|
+
fieldErrors
|
|
3837
|
+
};
|
|
3838
|
+
}
|
|
3839
|
+
function formatError(error, mapper = (issue)=>issue.message) {
|
|
3840
|
+
const fieldErrors = {
|
|
3841
|
+
_errors: []
|
|
3842
|
+
};
|
|
3843
|
+
const processError = (error, path = [])=>{
|
|
3844
|
+
for (const issue of error.issues)if ("invalid_union" === issue.code && issue.errors.length) issue.errors.map((issues)=>processError({
|
|
3845
|
+
issues
|
|
3846
|
+
}, [
|
|
3847
|
+
...path,
|
|
3848
|
+
...issue.path
|
|
3849
|
+
]));
|
|
3850
|
+
else if ("invalid_key" === issue.code) processError({
|
|
3851
|
+
issues: issue.issues
|
|
3852
|
+
}, [
|
|
3853
|
+
...path,
|
|
3854
|
+
...issue.path
|
|
3855
|
+
]);
|
|
3856
|
+
else if ("invalid_element" === issue.code) processError({
|
|
3857
|
+
issues: issue.issues
|
|
3858
|
+
}, [
|
|
3859
|
+
...path,
|
|
3860
|
+
...issue.path
|
|
3861
|
+
]);
|
|
3862
|
+
else {
|
|
3863
|
+
const fullpath = [
|
|
3864
|
+
...path,
|
|
3865
|
+
...issue.path
|
|
3866
|
+
];
|
|
3867
|
+
if (0 === fullpath.length) fieldErrors._errors.push(mapper(issue));
|
|
3868
|
+
else {
|
|
3869
|
+
let curr = fieldErrors;
|
|
3870
|
+
let i = 0;
|
|
3871
|
+
while(i < fullpath.length){
|
|
3872
|
+
const el = fullpath[i];
|
|
3873
|
+
const terminal = i === fullpath.length - 1;
|
|
3874
|
+
if ("_errors" === el) {
|
|
3875
|
+
if (terminal) curr._errors.push(mapper(issue));
|
|
3876
|
+
i++;
|
|
3877
|
+
continue;
|
|
3878
|
+
}
|
|
3879
|
+
if (!Object.prototype.hasOwnProperty.call(curr, el)) Object.defineProperty(curr, el, {
|
|
3880
|
+
value: {
|
|
3881
|
+
_errors: []
|
|
3882
|
+
},
|
|
3883
|
+
enumerable: true,
|
|
3884
|
+
writable: true,
|
|
3885
|
+
configurable: true
|
|
3886
|
+
});
|
|
3887
|
+
const node = curr[el];
|
|
3888
|
+
if (terminal) node._errors.push(mapper(issue));
|
|
3889
|
+
curr = node;
|
|
3890
|
+
i++;
|
|
3891
|
+
}
|
|
3892
|
+
}
|
|
3893
|
+
}
|
|
3894
|
+
};
|
|
3895
|
+
processError(error);
|
|
3896
|
+
return fieldErrors;
|
|
3897
|
+
}
|
|
3898
|
+
function finalizeParams(callee, params) {
|
|
3899
|
+
return {
|
|
3900
|
+
callee: params?.callee ?? callee,
|
|
3901
|
+
Err: params?.Err
|
|
3902
|
+
};
|
|
3903
|
+
}
|
|
3904
|
+
const parse_parse = (_Err)=>{
|
|
3905
|
+
const fn = (schema, value, _ctx, _params)=>{
|
|
3906
|
+
const ctx = _ctx ? {
|
|
3907
|
+
..._ctx,
|
|
3908
|
+
async: false
|
|
3909
|
+
} : {
|
|
3910
|
+
async: false
|
|
3911
|
+
};
|
|
3912
|
+
const result = schema._zod.run({
|
|
3913
|
+
value,
|
|
3914
|
+
issues: []
|
|
3915
|
+
}, ctx);
|
|
3916
|
+
if (result instanceof Promise) throw new $ZodAsyncError();
|
|
3917
|
+
if (result.issues.length) {
|
|
3918
|
+
const e = new (_params?.Err ?? _Err)(result.issues.map((iss)=>finalizeIssue(iss, ctx, core_config())));
|
|
3919
|
+
captureStackTrace(e, _params?.callee ?? fn);
|
|
3920
|
+
throw e;
|
|
3921
|
+
}
|
|
3922
|
+
return result.value;
|
|
3923
|
+
};
|
|
3924
|
+
return fn;
|
|
3925
|
+
};
|
|
3926
|
+
const parse_parseAsync = (_Err)=>{
|
|
3927
|
+
const fn = async (schema, value, _ctx, params)=>{
|
|
3928
|
+
const ctx = _ctx ? {
|
|
3929
|
+
..._ctx,
|
|
3930
|
+
async: true
|
|
3931
|
+
} : {
|
|
3932
|
+
async: true
|
|
3933
|
+
};
|
|
3934
|
+
let result = schema._zod.run({
|
|
3935
|
+
value,
|
|
3936
|
+
issues: []
|
|
3937
|
+
}, ctx);
|
|
3938
|
+
if (result instanceof Promise) result = await result;
|
|
3939
|
+
if (result.issues.length) {
|
|
3940
|
+
const e = new (params?.Err ?? _Err)(result.issues.map((iss)=>finalizeIssue(iss, ctx, core_config())));
|
|
3941
|
+
captureStackTrace(e, params?.callee ?? fn);
|
|
3942
|
+
throw e;
|
|
3943
|
+
}
|
|
3944
|
+
return result.value;
|
|
3945
|
+
};
|
|
3946
|
+
return fn;
|
|
3947
|
+
};
|
|
3948
|
+
const _safeParse = (_Err)=>(schema, value, _ctx)=>{
|
|
3949
|
+
const ctx = _ctx ? {
|
|
3950
|
+
..._ctx,
|
|
3951
|
+
async: false
|
|
3952
|
+
} : {
|
|
3953
|
+
async: false
|
|
3954
|
+
};
|
|
3955
|
+
const result = schema._zod.run({
|
|
3956
|
+
value,
|
|
3957
|
+
issues: []
|
|
3958
|
+
}, ctx);
|
|
3959
|
+
if (result instanceof Promise) throw new $ZodAsyncError();
|
|
3960
|
+
return result.issues.length ? failure(_Err, result.issues, ctx) : {
|
|
3961
|
+
success: true,
|
|
3962
|
+
data: result.value
|
|
3963
|
+
};
|
|
3964
|
+
};
|
|
3965
|
+
function failure(Err, issues, ctx) {
|
|
3966
|
+
let error;
|
|
3967
|
+
return {
|
|
3968
|
+
success: false,
|
|
3969
|
+
get error () {
|
|
3970
|
+
if (!error) {
|
|
3971
|
+
error = new Err(issues.map((iss)=>finalizeIssue(iss, ctx, core_config())));
|
|
3972
|
+
issues = void 0;
|
|
3973
|
+
ctx = void 0;
|
|
3974
|
+
}
|
|
3975
|
+
return error;
|
|
3976
|
+
},
|
|
3977
|
+
set error (e){
|
|
3978
|
+
error = e;
|
|
3979
|
+
issues = void 0;
|
|
3980
|
+
ctx = void 0;
|
|
3981
|
+
}
|
|
3982
|
+
};
|
|
3983
|
+
}
|
|
3984
|
+
const _safeParseAsync = (_Err)=>async (schema, value, _ctx)=>{
|
|
3985
|
+
const ctx = _ctx ? {
|
|
3986
|
+
..._ctx,
|
|
3987
|
+
async: true
|
|
3988
|
+
} : {
|
|
3989
|
+
async: true
|
|
3990
|
+
};
|
|
3991
|
+
let result = schema._zod.run({
|
|
3992
|
+
value,
|
|
3993
|
+
issues: []
|
|
3994
|
+
}, ctx);
|
|
3995
|
+
if (result instanceof Promise) result = await result;
|
|
3996
|
+
return result.issues.length ? failure(_Err, result.issues, ctx) : {
|
|
3997
|
+
success: true,
|
|
3998
|
+
data: result.value
|
|
3999
|
+
};
|
|
4000
|
+
};
|
|
4001
|
+
const COMPILE_INVALID = /* @__PURE__ */ Symbol.for("zod.compile.invalid");
|
|
4002
|
+
const COMPILE_FALLBACK = /* @__PURE__ */ Symbol.for("zod.compile.fallback");
|
|
4003
|
+
const validate = (schema, value, _ctx)=>{
|
|
4004
|
+
const validator = schema._zod.bag.validator;
|
|
4005
|
+
if (void 0 !== validator) {
|
|
4006
|
+
if (validator(value) !== COMPILE_INVALID) return true;
|
|
4007
|
+
if (true === validator.definite && void 0 === _ctx) return false;
|
|
4008
|
+
}
|
|
4009
|
+
return validateFallback(schema, value, _ctx);
|
|
4010
|
+
};
|
|
4011
|
+
function validateFallback(schema, value, _ctx) {
|
|
4012
|
+
const ctx = _ctx ? {
|
|
4013
|
+
..._ctx,
|
|
4014
|
+
async: false,
|
|
4015
|
+
abortEarly: true
|
|
4016
|
+
} : {
|
|
4017
|
+
async: false,
|
|
4018
|
+
abortEarly: true
|
|
4019
|
+
};
|
|
4020
|
+
const fallbackRun = schema._zod.bag.fallbackRun;
|
|
4021
|
+
let result;
|
|
4022
|
+
if (fallbackRun) {
|
|
4023
|
+
ctx[COMPILE_FALLBACK] = true;
|
|
4024
|
+
result = fallbackRun({
|
|
4025
|
+
value,
|
|
4026
|
+
issues: []
|
|
4027
|
+
}, ctx);
|
|
4028
|
+
} else result = schema._zod.run({
|
|
4029
|
+
value,
|
|
4030
|
+
issues: []
|
|
4031
|
+
}, ctx);
|
|
4032
|
+
if (result instanceof Promise) throw new $ZodAsyncError();
|
|
4033
|
+
return 0 === result.issues.length;
|
|
4034
|
+
}
|
|
4035
|
+
const parse_validateAsync = async (schema, value, _ctx)=>{
|
|
4036
|
+
const ctx = _ctx ? {
|
|
4037
|
+
..._ctx,
|
|
4038
|
+
async: true,
|
|
4039
|
+
abortEarly: true
|
|
4040
|
+
} : {
|
|
4041
|
+
async: true,
|
|
4042
|
+
abortEarly: true
|
|
4043
|
+
};
|
|
4044
|
+
let result = schema._zod.run({
|
|
4045
|
+
value,
|
|
4046
|
+
issues: []
|
|
4047
|
+
}, ctx);
|
|
4048
|
+
if (result instanceof Promise) result = await result;
|
|
4049
|
+
return 0 === result.issues.length;
|
|
2961
4050
|
};
|
|
2962
|
-
const
|
|
2963
|
-
const
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
}
|
|
2973
|
-
|
|
4051
|
+
const parse_encode = (_Err)=>{
|
|
4052
|
+
const parse = parse_parse(_Err);
|
|
4053
|
+
const fn = (schema, value, _ctx, _params)=>{
|
|
4054
|
+
const ctx = _ctx ? {
|
|
4055
|
+
..._ctx,
|
|
4056
|
+
direction: "backward"
|
|
4057
|
+
} : {
|
|
4058
|
+
direction: "backward"
|
|
4059
|
+
};
|
|
4060
|
+
return parse(schema, value, ctx, finalizeParams(fn, _params));
|
|
4061
|
+
};
|
|
4062
|
+
return fn;
|
|
2974
4063
|
};
|
|
2975
|
-
const
|
|
2976
|
-
const
|
|
2977
|
-
const
|
|
2978
|
-
|
|
2979
|
-
to_json_schema_process(innerType, ctx, params);
|
|
2980
|
-
const seen = ctx.seen.get(schema);
|
|
2981
|
-
seen.ref = innerType;
|
|
4064
|
+
const parse_decode = (_Err)=>{
|
|
4065
|
+
const parse = parse_parse(_Err);
|
|
4066
|
+
const fn = (schema, value, _ctx, _params)=>parse(schema, value, _ctx, finalizeParams(fn, _params));
|
|
4067
|
+
return fn;
|
|
2982
4068
|
};
|
|
2983
|
-
const
|
|
2984
|
-
const
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
4069
|
+
const parse_encodeAsync = (_Err)=>{
|
|
4070
|
+
const parseAsync = parse_parseAsync(_Err);
|
|
4071
|
+
const fn = async (schema, value, _ctx, _params)=>{
|
|
4072
|
+
const ctx = _ctx ? {
|
|
4073
|
+
..._ctx,
|
|
4074
|
+
direction: "backward"
|
|
4075
|
+
} : {
|
|
4076
|
+
direction: "backward"
|
|
4077
|
+
};
|
|
4078
|
+
return await parseAsync(schema, value, ctx, finalizeParams(fn, _params));
|
|
4079
|
+
};
|
|
4080
|
+
return fn;
|
|
2989
4081
|
};
|
|
2990
|
-
const
|
|
2991
|
-
const
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
seen.ref = def.innerType;
|
|
4082
|
+
const parse_decodeAsync = (_Err)=>{
|
|
4083
|
+
const parseAsync = parse_parseAsync(_Err);
|
|
4084
|
+
const fn = async (schema, value, _ctx, _params)=>await parseAsync(schema, value, _ctx, finalizeParams(fn, _params));
|
|
4085
|
+
return fn;
|
|
2995
4086
|
};
|
|
2996
|
-
const
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
}
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
4087
|
+
const _safeEncode = (_Err)=>(schema, value, _ctx)=>{
|
|
4088
|
+
const ctx = _ctx ? {
|
|
4089
|
+
..._ctx,
|
|
4090
|
+
direction: "backward"
|
|
4091
|
+
} : {
|
|
4092
|
+
direction: "backward"
|
|
4093
|
+
};
|
|
4094
|
+
return _safeParse(_Err)(schema, value, ctx);
|
|
4095
|
+
};
|
|
4096
|
+
const _safeDecode = (_Err)=>(schema, value, _ctx)=>_safeParse(_Err)(schema, value, _ctx);
|
|
4097
|
+
const _safeEncodeAsync = (_Err)=>async (schema, value, _ctx)=>{
|
|
4098
|
+
const ctx = _ctx ? {
|
|
4099
|
+
..._ctx,
|
|
4100
|
+
direction: "backward"
|
|
4101
|
+
} : {
|
|
4102
|
+
direction: "backward"
|
|
4103
|
+
};
|
|
4104
|
+
return _safeParseAsync(_Err)(schema, value, ctx);
|
|
4105
|
+
};
|
|
4106
|
+
const _safeDecodeAsync = (_Err)=>async (schema, value, _ctx)=>_safeParseAsync(_Err)(schema, value, _ctx);
|
|
4107
|
+
const _installedErrorProtos = /* @__PURE__ */ new WeakSet([
|
|
4108
|
+
Object.prototype,
|
|
4109
|
+
Error.prototype
|
|
4110
|
+
]);
|
|
4111
|
+
function _lazyMethod(proto, key, make) {
|
|
4112
|
+
Object.defineProperty(proto, key, {
|
|
4113
|
+
configurable: true,
|
|
4114
|
+
enumerable: false,
|
|
4115
|
+
get () {
|
|
4116
|
+
const value = make(this);
|
|
4117
|
+
Object.defineProperty(this, key, {
|
|
4118
|
+
value,
|
|
4119
|
+
configurable: true,
|
|
4120
|
+
writable: true
|
|
4121
|
+
});
|
|
4122
|
+
return value;
|
|
4123
|
+
},
|
|
4124
|
+
set (value) {
|
|
4125
|
+
Object.defineProperty(this, key, {
|
|
4126
|
+
value,
|
|
4127
|
+
configurable: true,
|
|
4128
|
+
writable: true
|
|
4129
|
+
});
|
|
4130
|
+
}
|
|
4131
|
+
});
|
|
3023
4132
|
}
|
|
3024
4133
|
const classic_errors_initializer = (inst, issues)=>{
|
|
3025
4134
|
$ZodError.init(inst, issues);
|
|
3026
4135
|
inst.name = "ZodError";
|
|
3027
|
-
Object.
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
}
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
},
|
|
3046
|
-
isEmpty: {
|
|
3047
|
-
get () {
|
|
3048
|
-
return 0 === inst.issues.length;
|
|
3049
|
-
}
|
|
4136
|
+
const proto = Object.getPrototypeOf(inst);
|
|
4137
|
+
if (_installedErrorProtos.has(proto)) return;
|
|
4138
|
+
_installedErrorProtos.add(proto);
|
|
4139
|
+
_lazyMethod(proto, "format", (self)=>(mapper)=>formatError(self, mapper));
|
|
4140
|
+
_lazyMethod(proto, "flatten", (self)=>(mapper)=>flattenError(self, mapper));
|
|
4141
|
+
_lazyMethod(proto, "addIssue", (self)=>(issue)=>{
|
|
4142
|
+
self.issues.push(issue);
|
|
4143
|
+
self.message = JSON.stringify(self.issues, jsonStringifyReplacer, 2);
|
|
4144
|
+
});
|
|
4145
|
+
_lazyMethod(proto, "addIssues", (self)=>(issues)=>{
|
|
4146
|
+
self.issues.push(...issues);
|
|
4147
|
+
self.message = JSON.stringify(self.issues, jsonStringifyReplacer, 2);
|
|
4148
|
+
});
|
|
4149
|
+
Object.defineProperty(proto, "isEmpty", {
|
|
4150
|
+
configurable: true,
|
|
4151
|
+
enumerable: false,
|
|
4152
|
+
get () {
|
|
4153
|
+
return 0 === this.issues.length;
|
|
3050
4154
|
}
|
|
3051
4155
|
});
|
|
3052
4156
|
};
|
|
3053
|
-
const ZodRealError = /*@__PURE__*/ $constructor("ZodError", classic_errors_initializer, {
|
|
4157
|
+
const ZodRealError = /*@__PURE__*/ $constructor("ZodError", classic_errors_initializer, void 0, {
|
|
3054
4158
|
Parent: Error
|
|
3055
4159
|
});
|
|
3056
|
-
const classic_parse_parse = /* @__PURE__ */
|
|
3057
|
-
const classic_parse_parseAsync = /* @__PURE__ */
|
|
4160
|
+
const classic_parse_parse = /* @__PURE__ */ parse_parse(ZodRealError);
|
|
4161
|
+
const classic_parse_parseAsync = /* @__PURE__ */ parse_parseAsync(ZodRealError);
|
|
3058
4162
|
const parse_safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
|
|
3059
4163
|
const parse_safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
|
|
3060
|
-
const
|
|
3061
|
-
const
|
|
3062
|
-
const
|
|
3063
|
-
const
|
|
4164
|
+
const classic_parse_encode = /* @__PURE__ */ parse_encode(ZodRealError);
|
|
4165
|
+
const classic_parse_decode = /* @__PURE__ */ parse_decode(ZodRealError);
|
|
4166
|
+
const classic_parse_encodeAsync = /* @__PURE__ */ parse_encodeAsync(ZodRealError);
|
|
4167
|
+
const classic_parse_decodeAsync = /* @__PURE__ */ parse_decodeAsync(ZodRealError);
|
|
3064
4168
|
const parse_safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
|
|
3065
4169
|
const parse_safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
|
|
3066
4170
|
const parse_safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
|
|
3067
4171
|
const parse_safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
if (!
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
}
|
|
3076
|
-
if (installed.has(group)) return;
|
|
3077
|
-
installed.add(group);
|
|
3078
|
-
for(const key in methods){
|
|
3079
|
-
const fn = methods[key];
|
|
3080
|
-
Object.defineProperty(proto, key, {
|
|
3081
|
-
configurable: true,
|
|
3082
|
-
enumerable: false,
|
|
3083
|
-
get () {
|
|
3084
|
-
const bound = fn.bind(this);
|
|
3085
|
-
Object.defineProperty(this, key, {
|
|
3086
|
-
configurable: true,
|
|
3087
|
-
writable: true,
|
|
3088
|
-
enumerable: true,
|
|
3089
|
-
value: bound
|
|
3090
|
-
});
|
|
3091
|
-
return bound;
|
|
3092
|
-
},
|
|
3093
|
-
set (v) {
|
|
3094
|
-
Object.defineProperty(this, key, {
|
|
3095
|
-
configurable: true,
|
|
3096
|
-
writable: true,
|
|
3097
|
-
enumerable: true,
|
|
3098
|
-
value: v
|
|
3099
|
-
});
|
|
3100
|
-
}
|
|
3101
|
-
});
|
|
3102
|
-
}
|
|
4172
|
+
function _ensureDefaultLocale() {
|
|
4173
|
+
if (!globalConfig.localeError) core_config(en());
|
|
4174
|
+
}
|
|
4175
|
+
function _ensureDefaultMemoizer() {
|
|
4176
|
+
if (!globalConfig.memoizer) core_config({
|
|
4177
|
+
memoizer: memoizer()
|
|
4178
|
+
});
|
|
3103
4179
|
}
|
|
3104
4180
|
const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def)=>{
|
|
4181
|
+
_ensureDefaultLocale();
|
|
3105
4182
|
$ZodType.init(inst, def);
|
|
3106
|
-
Object.assign(inst["~standard"], {
|
|
3107
|
-
jsonSchema: {
|
|
3108
|
-
input: createStandardJSONSchemaMethod(inst, "input"),
|
|
3109
|
-
output: createStandardJSONSchemaMethod(inst, "output")
|
|
3110
|
-
}
|
|
3111
|
-
});
|
|
3112
|
-
inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
|
|
3113
4183
|
inst.def = def;
|
|
3114
4184
|
inst.type = def.type;
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
4185
|
+
return inst;
|
|
4186
|
+
}, {
|
|
4187
|
+
check (...chks) {
|
|
4188
|
+
const def = this.def;
|
|
4189
|
+
return this.clone(mergeDefs(def, {
|
|
4190
|
+
checks: [
|
|
4191
|
+
...def.checks ?? [],
|
|
4192
|
+
...chks.map((ch)=>"function" == typeof ch ? {
|
|
4193
|
+
_zod: {
|
|
4194
|
+
check: ch,
|
|
4195
|
+
def: {
|
|
4196
|
+
check: "custom"
|
|
4197
|
+
},
|
|
4198
|
+
onattach: []
|
|
4199
|
+
}
|
|
4200
|
+
} : ch)
|
|
4201
|
+
]
|
|
4202
|
+
}), {
|
|
4203
|
+
parent: true
|
|
3120
4204
|
});
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
4205
|
+
},
|
|
4206
|
+
with (...chks) {
|
|
4207
|
+
return this.check(...chks);
|
|
4208
|
+
},
|
|
4209
|
+
clone (def, params) {
|
|
4210
|
+
return clone(this, def, params);
|
|
4211
|
+
},
|
|
4212
|
+
brand () {
|
|
4213
|
+
return this;
|
|
4214
|
+
},
|
|
4215
|
+
register (reg, meta) {
|
|
4216
|
+
reg.add(this, meta);
|
|
4217
|
+
return this;
|
|
4218
|
+
},
|
|
4219
|
+
refine (check, params) {
|
|
4220
|
+
return this.check(refine(check, params));
|
|
4221
|
+
},
|
|
4222
|
+
superRefine (refinement, params) {
|
|
4223
|
+
return this.check(superRefine(refinement, params));
|
|
4224
|
+
},
|
|
4225
|
+
overwrite (fn) {
|
|
4226
|
+
return this.check(_overwrite(fn));
|
|
4227
|
+
},
|
|
4228
|
+
optional () {
|
|
4229
|
+
return schemas_optional(this);
|
|
4230
|
+
},
|
|
4231
|
+
exactOptional () {
|
|
4232
|
+
return exactOptional(this);
|
|
4233
|
+
},
|
|
4234
|
+
nullable () {
|
|
4235
|
+
return nullable(this);
|
|
4236
|
+
},
|
|
4237
|
+
nullish () {
|
|
4238
|
+
return schemas_optional(nullable(this));
|
|
4239
|
+
},
|
|
4240
|
+
nonoptional (params) {
|
|
4241
|
+
return nonoptional(this, params);
|
|
4242
|
+
},
|
|
4243
|
+
array () {
|
|
4244
|
+
return schemas_array(this);
|
|
4245
|
+
},
|
|
4246
|
+
or (arg) {
|
|
4247
|
+
return schemas_union([
|
|
4248
|
+
this,
|
|
4249
|
+
arg
|
|
4250
|
+
]);
|
|
4251
|
+
},
|
|
4252
|
+
and (arg) {
|
|
4253
|
+
return intersection(this, arg);
|
|
4254
|
+
},
|
|
4255
|
+
transform (tx) {
|
|
4256
|
+
return pipe(this, transform(tx));
|
|
4257
|
+
},
|
|
4258
|
+
default (d) {
|
|
4259
|
+
return schemas_default(this, d);
|
|
4260
|
+
},
|
|
4261
|
+
prefault (d) {
|
|
4262
|
+
return prefault(this, d);
|
|
4263
|
+
},
|
|
4264
|
+
catch (params) {
|
|
4265
|
+
return schemas_catch(this, params);
|
|
4266
|
+
},
|
|
4267
|
+
pipe (target) {
|
|
4268
|
+
return pipe(this, target);
|
|
4269
|
+
},
|
|
4270
|
+
readonly () {
|
|
4271
|
+
return readonly(this);
|
|
4272
|
+
},
|
|
4273
|
+
describe (description) {
|
|
4274
|
+
const cl = this.clone();
|
|
4275
|
+
globalRegistry.add(cl, {
|
|
4276
|
+
description
|
|
3124
4277
|
});
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
}
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
}
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
}
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
}
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
const cl = this.clone();
|
|
3224
|
-
globalRegistry.add(cl, {
|
|
3225
|
-
description
|
|
3226
|
-
});
|
|
3227
|
-
return cl;
|
|
3228
|
-
},
|
|
3229
|
-
meta (...args) {
|
|
3230
|
-
if (0 === args.length) return globalRegistry.get(this);
|
|
3231
|
-
const cl = this.clone();
|
|
3232
|
-
globalRegistry.add(cl, args[0]);
|
|
3233
|
-
return cl;
|
|
3234
|
-
},
|
|
3235
|
-
isOptional () {
|
|
3236
|
-
return this.safeParse(void 0).success;
|
|
3237
|
-
},
|
|
3238
|
-
isNullable () {
|
|
3239
|
-
return this.safeParse(null).success;
|
|
3240
|
-
},
|
|
3241
|
-
apply (fn) {
|
|
3242
|
-
return fn(this);
|
|
3243
|
-
}
|
|
3244
|
-
});
|
|
3245
|
-
Object.defineProperty(inst, "description", {
|
|
3246
|
-
get () {
|
|
3247
|
-
return globalRegistry.get(inst)?.description;
|
|
3248
|
-
},
|
|
3249
|
-
configurable: true
|
|
3250
|
-
});
|
|
3251
|
-
return inst;
|
|
4278
|
+
return cl;
|
|
4279
|
+
},
|
|
4280
|
+
meta (...args) {
|
|
4281
|
+
if (0 === args.length) return globalRegistry.get(this);
|
|
4282
|
+
const cl = this.clone();
|
|
4283
|
+
globalRegistry.add(cl, args[0]);
|
|
4284
|
+
return cl;
|
|
4285
|
+
},
|
|
4286
|
+
isOptional () {
|
|
4287
|
+
return this.safeParse(void 0).success;
|
|
4288
|
+
},
|
|
4289
|
+
isNullable () {
|
|
4290
|
+
return this.safeParse(null).success;
|
|
4291
|
+
},
|
|
4292
|
+
apply (fn, ...args) {
|
|
4293
|
+
return 0 === args.length ? fn(this) : fn(this, ...args);
|
|
4294
|
+
},
|
|
4295
|
+
get "~standard" () {
|
|
4296
|
+
return hide(this, "~standard", {
|
|
4297
|
+
...standardProps(this),
|
|
4298
|
+
jsonSchema: {
|
|
4299
|
+
input: createStandardJSONSchemaMethod(this, "input"),
|
|
4300
|
+
output: createStandardJSONSchemaMethod(this, "output")
|
|
4301
|
+
}
|
|
4302
|
+
});
|
|
4303
|
+
},
|
|
4304
|
+
set "~standard" (value){
|
|
4305
|
+
util_own(this, "~standard", value);
|
|
4306
|
+
},
|
|
4307
|
+
parse: function _parse(data, params) {
|
|
4308
|
+
return classic_parse_parse(this, data, params, {
|
|
4309
|
+
callee: _parse
|
|
4310
|
+
});
|
|
4311
|
+
},
|
|
4312
|
+
parseAsync: async function _parseAsync(data, params) {
|
|
4313
|
+
return await classic_parse_parseAsync(this, data, params, {
|
|
4314
|
+
callee: _parseAsync
|
|
4315
|
+
});
|
|
4316
|
+
},
|
|
4317
|
+
safeParse (data, params) {
|
|
4318
|
+
return parse_safeParse(this, data, params);
|
|
4319
|
+
},
|
|
4320
|
+
async safeParseAsync (data, params) {
|
|
4321
|
+
return parse_safeParseAsync(this, data, params);
|
|
4322
|
+
},
|
|
4323
|
+
get spa () {
|
|
4324
|
+
return this?.safeParseAsync;
|
|
4325
|
+
},
|
|
4326
|
+
set spa (value){
|
|
4327
|
+
util_own(this, "spa", value);
|
|
4328
|
+
},
|
|
4329
|
+
validate (data, params) {
|
|
4330
|
+
return validate(this, data, params);
|
|
4331
|
+
},
|
|
4332
|
+
validateAsync (data, params) {
|
|
4333
|
+
return parse_validateAsync(this, data, params);
|
|
4334
|
+
},
|
|
4335
|
+
encode: function _encode(data, params) {
|
|
4336
|
+
return classic_parse_encode(this, data, params, {
|
|
4337
|
+
callee: _encode
|
|
4338
|
+
});
|
|
4339
|
+
},
|
|
4340
|
+
decode: function _decode(data, params) {
|
|
4341
|
+
return classic_parse_decode(this, data, params, {
|
|
4342
|
+
callee: _decode
|
|
4343
|
+
});
|
|
4344
|
+
},
|
|
4345
|
+
encodeAsync: async function _encodeAsync(data, params) {
|
|
4346
|
+
return await classic_parse_encodeAsync(this, data, params, {
|
|
4347
|
+
callee: _encodeAsync
|
|
4348
|
+
});
|
|
4349
|
+
},
|
|
4350
|
+
decodeAsync: async function _decodeAsync(data, params) {
|
|
4351
|
+
return await classic_parse_decodeAsync(this, data, params, {
|
|
4352
|
+
callee: _decodeAsync
|
|
4353
|
+
});
|
|
4354
|
+
},
|
|
4355
|
+
safeEncode (data, params) {
|
|
4356
|
+
return parse_safeEncode(this, data, params);
|
|
4357
|
+
},
|
|
4358
|
+
safeDecode (data, params) {
|
|
4359
|
+
return parse_safeDecode(this, data, params);
|
|
4360
|
+
},
|
|
4361
|
+
async safeEncodeAsync (data, params) {
|
|
4362
|
+
return parse_safeEncodeAsync(this, data, params);
|
|
4363
|
+
},
|
|
4364
|
+
async safeDecodeAsync (data, params) {
|
|
4365
|
+
return parse_safeDecodeAsync(this, data, params);
|
|
4366
|
+
},
|
|
4367
|
+
toJSONSchema (params) {
|
|
4368
|
+
return createToJSONSchemaMethod(this, {})(params);
|
|
4369
|
+
},
|
|
4370
|
+
get description () {
|
|
4371
|
+
return globalRegistry.get(this)?.description;
|
|
4372
|
+
},
|
|
4373
|
+
get _def () {
|
|
4374
|
+
return this._zod.def;
|
|
4375
|
+
}
|
|
3252
4376
|
});
|
|
3253
4377
|
const _ZodString = /*@__PURE__*/ $constructor("_ZodString", (inst, def)=>{
|
|
3254
4378
|
$ZodString.init(inst, def);
|
|
3255
4379
|
ZodType.init(inst, def);
|
|
3256
4380
|
inst._zod.processJSONSchema = (ctx, json, params)=>stringProcessor(inst, ctx, json, params);
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
});
|
|
4381
|
+
}, /*@__PURE__*/ derived({
|
|
4382
|
+
format: (inst)=>aggregateChecks(inst).format ?? null,
|
|
4383
|
+
minLength: (inst)=>aggregateChecks(inst).minimum ?? null,
|
|
4384
|
+
maxLength: (inst)=>aggregateChecks(inst).maximum ?? null
|
|
4385
|
+
}, {
|
|
4386
|
+
regex (...args) {
|
|
4387
|
+
return this.check(_regex(...args));
|
|
4388
|
+
},
|
|
4389
|
+
includes (...args) {
|
|
4390
|
+
return this.check(_includes(...args));
|
|
4391
|
+
},
|
|
4392
|
+
startsWith (...args) {
|
|
4393
|
+
return this.check(_startsWith(...args));
|
|
4394
|
+
},
|
|
4395
|
+
endsWith (...args) {
|
|
4396
|
+
return this.check(_endsWith(...args));
|
|
4397
|
+
},
|
|
4398
|
+
min (...args) {
|
|
4399
|
+
return this.check(_minLength(...args));
|
|
4400
|
+
},
|
|
4401
|
+
max (...args) {
|
|
4402
|
+
return this.check(_maxLength(...args));
|
|
4403
|
+
},
|
|
4404
|
+
length (...args) {
|
|
4405
|
+
return this.check(_length(...args));
|
|
4406
|
+
},
|
|
4407
|
+
nonempty (...args) {
|
|
4408
|
+
return this.check(_minLength(1, ...args));
|
|
4409
|
+
},
|
|
4410
|
+
lowercase (params) {
|
|
4411
|
+
return this.check(_lowercase(params));
|
|
4412
|
+
},
|
|
4413
|
+
uppercase (params) {
|
|
4414
|
+
return this.check(_uppercase(params));
|
|
4415
|
+
},
|
|
4416
|
+
trim () {
|
|
4417
|
+
return this.check(_trim());
|
|
4418
|
+
},
|
|
4419
|
+
normalize (...args) {
|
|
4420
|
+
return this.check(_normalize(...args));
|
|
4421
|
+
},
|
|
4422
|
+
toLowerCase () {
|
|
4423
|
+
return this.check(_toLowerCase());
|
|
4424
|
+
},
|
|
4425
|
+
toUpperCase () {
|
|
4426
|
+
return this.check(_toUpperCase());
|
|
4427
|
+
},
|
|
4428
|
+
slugify () {
|
|
4429
|
+
return this.check(_slugify());
|
|
4430
|
+
}
|
|
4431
|
+
}));
|
|
3309
4432
|
const ZodString = /*@__PURE__*/ $constructor("ZodString", (inst, def)=>{
|
|
3310
4433
|
$ZodString.init(inst, def);
|
|
3311
4434
|
_ZodString.init(inst, def);
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
4435
|
+
}, {
|
|
4436
|
+
email (params) {
|
|
4437
|
+
return this.check(_email(ZodEmail, params));
|
|
4438
|
+
},
|
|
4439
|
+
url (params) {
|
|
4440
|
+
return this.check(_url(ZodURL, params));
|
|
4441
|
+
},
|
|
4442
|
+
jwt (params) {
|
|
4443
|
+
return this.check(_jwt(ZodJWT, params));
|
|
4444
|
+
},
|
|
4445
|
+
emoji (params) {
|
|
4446
|
+
return this.check(api_emoji(ZodEmoji, params));
|
|
4447
|
+
},
|
|
4448
|
+
guid (params) {
|
|
4449
|
+
return this.check(_guid(ZodGUID, params));
|
|
4450
|
+
},
|
|
4451
|
+
uuid (params) {
|
|
4452
|
+
return this.check(_uuid(ZodUUID, params));
|
|
4453
|
+
},
|
|
4454
|
+
uuidv4 (params) {
|
|
4455
|
+
return this.check(_uuidv4(ZodUUID, params));
|
|
4456
|
+
},
|
|
4457
|
+
uuidv6 (params) {
|
|
4458
|
+
return this.check(_uuidv6(ZodUUID, params));
|
|
4459
|
+
},
|
|
4460
|
+
uuidv7 (params) {
|
|
4461
|
+
return this.check(_uuidv7(ZodUUID, params));
|
|
4462
|
+
},
|
|
4463
|
+
nanoid (params) {
|
|
4464
|
+
return this.check(_nanoid(ZodNanoID, params));
|
|
4465
|
+
},
|
|
4466
|
+
cuid (params) {
|
|
4467
|
+
return this.check(_cuid(ZodCUID, params));
|
|
4468
|
+
},
|
|
4469
|
+
cuid2 (params) {
|
|
4470
|
+
return this.check(_cuid2(ZodCUID2, params));
|
|
4471
|
+
},
|
|
4472
|
+
ulid (params) {
|
|
4473
|
+
return this.check(_ulid(ZodULID, params));
|
|
4474
|
+
},
|
|
4475
|
+
base64 (params) {
|
|
4476
|
+
return this.check(_base64(ZodBase64, params));
|
|
4477
|
+
},
|
|
4478
|
+
base64url (params) {
|
|
4479
|
+
return this.check(_base64url(ZodBase64URL, params));
|
|
4480
|
+
},
|
|
4481
|
+
xid (params) {
|
|
4482
|
+
return this.check(_xid(ZodXID, params));
|
|
4483
|
+
},
|
|
4484
|
+
ksuid (params) {
|
|
4485
|
+
return this.check(_ksuid(ZodKSUID, params));
|
|
4486
|
+
},
|
|
4487
|
+
ipv4 (params) {
|
|
4488
|
+
return this.check(_ipv4(ZodIPv4, params));
|
|
4489
|
+
},
|
|
4490
|
+
ipv6 (params) {
|
|
4491
|
+
return this.check(_ipv6(ZodIPv6, params));
|
|
4492
|
+
},
|
|
4493
|
+
cidrv4 (params) {
|
|
4494
|
+
return this.check(_cidrv4(ZodCIDRv4, params));
|
|
4495
|
+
},
|
|
4496
|
+
cidrv6 (params) {
|
|
4497
|
+
return this.check(_cidrv6(ZodCIDRv6, params));
|
|
4498
|
+
},
|
|
4499
|
+
e164 (params) {
|
|
4500
|
+
return this.check(_e164(ZodE164, params));
|
|
4501
|
+
},
|
|
4502
|
+
datetime (params) {
|
|
4503
|
+
return this.check(_isoDateTime(ZodISODateTime, params));
|
|
4504
|
+
},
|
|
4505
|
+
date (params) {
|
|
4506
|
+
return this.check(_isoDate(ZodISODate, params));
|
|
4507
|
+
},
|
|
4508
|
+
time (params) {
|
|
4509
|
+
return this.check(_isoTime(ZodISOTime, params));
|
|
4510
|
+
},
|
|
4511
|
+
duration (params) {
|
|
4512
|
+
return this.check(_isoDuration(ZodISODuration, params));
|
|
4513
|
+
}
|
|
3339
4514
|
});
|
|
3340
4515
|
function schemas_string(params) {
|
|
3341
4516
|
return _string(ZodString, params);
|
|
@@ -3344,6 +4519,22 @@ const ZodStringFormat = /*@__PURE__*/ $constructor("ZodStringFormat", (inst, def
|
|
|
3344
4519
|
$ZodStringFormat.init(inst, def);
|
|
3345
4520
|
_ZodString.init(inst, def);
|
|
3346
4521
|
});
|
|
4522
|
+
const ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def)=>{
|
|
4523
|
+
$ZodISODateTime.init(inst, def);
|
|
4524
|
+
ZodStringFormat.init(inst, def);
|
|
4525
|
+
});
|
|
4526
|
+
const ZodISODate = /*@__PURE__*/ $constructor("ZodISODate", (inst, def)=>{
|
|
4527
|
+
$ZodISODate.init(inst, def);
|
|
4528
|
+
ZodStringFormat.init(inst, def);
|
|
4529
|
+
});
|
|
4530
|
+
const ZodISOTime = /*@__PURE__*/ $constructor("ZodISOTime", (inst, def)=>{
|
|
4531
|
+
$ZodISOTime.init(inst, def);
|
|
4532
|
+
ZodStringFormat.init(inst, def);
|
|
4533
|
+
});
|
|
4534
|
+
const ZodISODuration = /*@__PURE__*/ $constructor("ZodISODuration", (inst, def)=>{
|
|
4535
|
+
$ZodISODuration.init(inst, def);
|
|
4536
|
+
ZodStringFormat.init(inst, def);
|
|
4537
|
+
});
|
|
3347
4538
|
const ZodEmail = /*@__PURE__*/ $constructor("ZodEmail", (inst, def)=>{
|
|
3348
4539
|
$ZodEmail.init(inst, def);
|
|
3349
4540
|
ZodStringFormat.init(inst, def);
|
|
@@ -3445,92 +4636,90 @@ function never(params) {
|
|
|
3445
4636
|
return _never(ZodNever, params);
|
|
3446
4637
|
}
|
|
3447
4638
|
const ZodArray = /*@__PURE__*/ $constructor("ZodArray", (inst, def)=>{
|
|
4639
|
+
_ensureDefaultMemoizer();
|
|
3448
4640
|
$ZodArray.init(inst, def);
|
|
3449
4641
|
ZodType.init(inst, def);
|
|
3450
4642
|
inst._zod.processJSONSchema = (ctx, json, params)=>arrayProcessor(inst, ctx, json, params);
|
|
3451
4643
|
inst.element = def.element;
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
});
|
|
4644
|
+
}, {
|
|
4645
|
+
min (n, params) {
|
|
4646
|
+
return this.check(_minLength(n, params));
|
|
4647
|
+
},
|
|
4648
|
+
nonempty (params) {
|
|
4649
|
+
return this.check(_minLength(1, params));
|
|
4650
|
+
},
|
|
4651
|
+
max (n, params) {
|
|
4652
|
+
return this.check(_maxLength(n, params));
|
|
4653
|
+
},
|
|
4654
|
+
length (n, params) {
|
|
4655
|
+
return this.check(_length(n, params));
|
|
4656
|
+
},
|
|
4657
|
+
unwrap () {
|
|
4658
|
+
return this.element;
|
|
4659
|
+
}
|
|
3469
4660
|
});
|
|
3470
4661
|
function schemas_array(element, params) {
|
|
3471
4662
|
return _array(ZodArray, element, params);
|
|
3472
4663
|
}
|
|
3473
4664
|
const ZodObject = /*@__PURE__*/ $constructor("ZodObject", (inst, def)=>{
|
|
4665
|
+
_ensureDefaultMemoizer();
|
|
3474
4666
|
$ZodObjectJIT.init(inst, def);
|
|
3475
4667
|
ZodType.init(inst, def);
|
|
3476
4668
|
inst._zod.processJSONSchema = (ctx, json, params)=>objectProcessor(inst, ctx, json, params);
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
}
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
return required(ZodNonOptional, this, args[0]);
|
|
3532
|
-
}
|
|
3533
|
-
});
|
|
4669
|
+
installLazyProp(inst, "shape", (self)=>self._zod.def.shape, false);
|
|
4670
|
+
}, {
|
|
4671
|
+
keyof () {
|
|
4672
|
+
return schemas_enum(Object.keys(this._zod.def.shape));
|
|
4673
|
+
},
|
|
4674
|
+
catchall (catchall) {
|
|
4675
|
+
return this.clone(mergeDefs(this._zod.def, {
|
|
4676
|
+
catchall: catchall
|
|
4677
|
+
}));
|
|
4678
|
+
},
|
|
4679
|
+
passthrough () {
|
|
4680
|
+
return this.clone(mergeDefs(this._zod.def, {
|
|
4681
|
+
catchall: unknown()
|
|
4682
|
+
}));
|
|
4683
|
+
},
|
|
4684
|
+
loose () {
|
|
4685
|
+
return this.clone(mergeDefs(this._zod.def, {
|
|
4686
|
+
catchall: unknown()
|
|
4687
|
+
}));
|
|
4688
|
+
},
|
|
4689
|
+
strict () {
|
|
4690
|
+
return this.clone(mergeDefs(this._zod.def, {
|
|
4691
|
+
catchall: never()
|
|
4692
|
+
}));
|
|
4693
|
+
},
|
|
4694
|
+
strip () {
|
|
4695
|
+
return this.clone(mergeDefs(this._zod.def, {
|
|
4696
|
+
catchall: void 0
|
|
4697
|
+
}));
|
|
4698
|
+
},
|
|
4699
|
+
extend (incoming) {
|
|
4700
|
+
return extend(this, incoming);
|
|
4701
|
+
},
|
|
4702
|
+
safeExtend (incoming) {
|
|
4703
|
+
return safeExtend(this, incoming);
|
|
4704
|
+
},
|
|
4705
|
+
merge (other) {
|
|
4706
|
+
return util_merge(this, other);
|
|
4707
|
+
},
|
|
4708
|
+
pick (mask) {
|
|
4709
|
+
return pick(this, mask);
|
|
4710
|
+
},
|
|
4711
|
+
omit (mask) {
|
|
4712
|
+
return omit(this, mask);
|
|
4713
|
+
},
|
|
4714
|
+
partial (...args) {
|
|
4715
|
+
return partial(ZodOptional, this, args[0]);
|
|
4716
|
+
},
|
|
4717
|
+
exactPartial (...args) {
|
|
4718
|
+
return partial(ZodExactOptional, this, args[0], "exactPartial");
|
|
4719
|
+
},
|
|
4720
|
+
required (...args) {
|
|
4721
|
+
return util_required(ZodNonOptional, this, args[0]);
|
|
4722
|
+
}
|
|
3534
4723
|
});
|
|
3535
4724
|
function schemas_object(shape, params) {
|
|
3536
4725
|
const def = {
|
|
@@ -3546,7 +4735,7 @@ const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def)=>{
|
|
|
3546
4735
|
inst._zod.processJSONSchema = (ctx, json, params)=>unionProcessor(inst, ctx, json, params);
|
|
3547
4736
|
inst.options = def.options;
|
|
3548
4737
|
});
|
|
3549
|
-
function
|
|
4738
|
+
function schemas_union(options, params) {
|
|
3550
4739
|
return new ZodUnion({
|
|
3551
4740
|
type: "union",
|
|
3552
4741
|
options: options,
|
|
@@ -3570,7 +4759,9 @@ const ZodEnum = /*@__PURE__*/ $constructor("ZodEnum", (inst, def)=>{
|
|
|
3570
4759
|
ZodType.init(inst, def);
|
|
3571
4760
|
inst._zod.processJSONSchema = (ctx, json, params)=>enumProcessor(inst, ctx, json, params);
|
|
3572
4761
|
inst.enum = def.entries;
|
|
3573
|
-
inst.options =
|
|
4762
|
+
inst.options = [
|
|
4763
|
+
...inst._zod.values
|
|
4764
|
+
];
|
|
3574
4765
|
const keys = new Set(Object.keys(def.entries));
|
|
3575
4766
|
inst.extract = (values, params)=>{
|
|
3576
4767
|
const newEntries = {};
|
|
@@ -3609,6 +4800,7 @@ function schemas_enum(values, params) {
|
|
|
3609
4800
|
});
|
|
3610
4801
|
}
|
|
3611
4802
|
const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def)=>{
|
|
4803
|
+
_ensureDefaultMemoizer();
|
|
3612
4804
|
$ZodTransform.init(inst, def);
|
|
3613
4805
|
ZodType.init(inst, def);
|
|
3614
4806
|
inst._zod.processJSONSchema = (ctx, json, params)=>transformProcessor(inst, ctx, json, params);
|
|
@@ -3620,7 +4812,7 @@ const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def)=>{
|
|
|
3620
4812
|
const _issue = issue;
|
|
3621
4813
|
if (_issue.fatal) _issue.continue = false;
|
|
3622
4814
|
_issue.code ?? (_issue.code = "custom");
|
|
3623
|
-
|
|
4815
|
+
if (!("input" in _issue)) _issue.input = payload.value;
|
|
3624
4816
|
_issue.inst ?? (_issue.inst = inst);
|
|
3625
4817
|
payload.issues.push(util_issue(_issue));
|
|
3626
4818
|
}
|
|
@@ -3628,11 +4820,9 @@ const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def)=>{
|
|
|
3628
4820
|
const output = def.transform(payload.value, payload);
|
|
3629
4821
|
if (output instanceof Promise) return output.then((output)=>{
|
|
3630
4822
|
payload.value = output;
|
|
3631
|
-
payload.fallback = true;
|
|
3632
4823
|
return payload;
|
|
3633
4824
|
});
|
|
3634
4825
|
payload.value = output;
|
|
3635
|
-
payload.fallback = true;
|
|
3636
4826
|
return payload;
|
|
3637
4827
|
};
|
|
3638
4828
|
});
|
|
@@ -3648,7 +4838,7 @@ const ZodOptional = /*@__PURE__*/ $constructor("ZodOptional", (inst, def)=>{
|
|
|
3648
4838
|
inst._zod.processJSONSchema = (ctx, json, params)=>optionalProcessor(inst, ctx, json, params);
|
|
3649
4839
|
inst.unwrap = ()=>inst._zod.def.innerType;
|
|
3650
4840
|
});
|
|
3651
|
-
function
|
|
4841
|
+
function schemas_optional(innerType) {
|
|
3652
4842
|
return new ZodOptional({
|
|
3653
4843
|
type: "optional",
|
|
3654
4844
|
innerType: innerType
|
|
@@ -3733,7 +4923,7 @@ function schemas_catch(innerType, catchValue) {
|
|
|
3733
4923
|
return new ZodCatch({
|
|
3734
4924
|
type: "catch",
|
|
3735
4925
|
innerType: innerType,
|
|
3736
|
-
catchValue: "function" == typeof catchValue ? catchValue : ()
|
|
4926
|
+
catchValue: "function" == typeof catchValue ? catchValue : constantCatch(catchValue)
|
|
3737
4927
|
});
|
|
3738
4928
|
}
|
|
3739
4929
|
const ZodPipe = /*@__PURE__*/ $constructor("ZodPipe", (inst, def)=>{
|