@tencent-ai/cloud-agent-sdk 0.1.6 → 0.2.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.cjs +164 -3953
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +157 -55
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +157 -55
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +168 -3957
- package/dist/index.mjs.map +1 -1
- package/dist/tencent-ai-cloud-agent-sdk-0.2.1.tgz +0 -0
- package/package.json +51 -12
- package/dist/index.browser.mjs +0 -15469
- package/dist/tencent-ai-cloud-agent-sdk-0.1.6.tgz +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,3843 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region ../agent-provider/node_modules/zod/v3/helpers/util.cjs
|
|
9
|
-
var require_util = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.getParsedType = exports.ZodParsedType = exports.objectUtil = exports.util = void 0;
|
|
12
|
-
var util;
|
|
13
|
-
(function(util) {
|
|
14
|
-
util.assertEqual = (_) => {};
|
|
15
|
-
function assertIs(_arg) {}
|
|
16
|
-
util.assertIs = assertIs;
|
|
17
|
-
function assertNever(_x) {
|
|
18
|
-
throw new Error();
|
|
19
|
-
}
|
|
20
|
-
util.assertNever = assertNever;
|
|
21
|
-
util.arrayToEnum = (items) => {
|
|
22
|
-
const obj = {};
|
|
23
|
-
for (const item of items) obj[item] = item;
|
|
24
|
-
return obj;
|
|
25
|
-
};
|
|
26
|
-
util.getValidEnumValues = (obj) => {
|
|
27
|
-
const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
28
|
-
const filtered = {};
|
|
29
|
-
for (const k of validKeys) filtered[k] = obj[k];
|
|
30
|
-
return util.objectValues(filtered);
|
|
31
|
-
};
|
|
32
|
-
util.objectValues = (obj) => {
|
|
33
|
-
return util.objectKeys(obj).map(function(e) {
|
|
34
|
-
return obj[e];
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
util.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
|
|
38
|
-
const keys = [];
|
|
39
|
-
for (const key in object) if (Object.prototype.hasOwnProperty.call(object, key)) keys.push(key);
|
|
40
|
-
return keys;
|
|
41
|
-
};
|
|
42
|
-
util.find = (arr, checker) => {
|
|
43
|
-
for (const item of arr) if (checker(item)) return item;
|
|
44
|
-
};
|
|
45
|
-
util.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
46
|
-
function joinValues(array, separator = " | ") {
|
|
47
|
-
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
48
|
-
}
|
|
49
|
-
util.joinValues = joinValues;
|
|
50
|
-
util.jsonStringifyReplacer = (_, value) => {
|
|
51
|
-
if (typeof value === "bigint") return value.toString();
|
|
52
|
-
return value;
|
|
53
|
-
};
|
|
54
|
-
})(util || (exports.util = util = {}));
|
|
55
|
-
var objectUtil;
|
|
56
|
-
(function(objectUtil) {
|
|
57
|
-
objectUtil.mergeShapes = (first, second) => {
|
|
58
|
-
return {
|
|
59
|
-
...first,
|
|
60
|
-
...second
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
})(objectUtil || (exports.objectUtil = objectUtil = {}));
|
|
64
|
-
exports.ZodParsedType = util.arrayToEnum([
|
|
65
|
-
"string",
|
|
66
|
-
"nan",
|
|
67
|
-
"number",
|
|
68
|
-
"integer",
|
|
69
|
-
"float",
|
|
70
|
-
"boolean",
|
|
71
|
-
"date",
|
|
72
|
-
"bigint",
|
|
73
|
-
"symbol",
|
|
74
|
-
"function",
|
|
75
|
-
"undefined",
|
|
76
|
-
"null",
|
|
77
|
-
"array",
|
|
78
|
-
"object",
|
|
79
|
-
"unknown",
|
|
80
|
-
"promise",
|
|
81
|
-
"void",
|
|
82
|
-
"never",
|
|
83
|
-
"map",
|
|
84
|
-
"set"
|
|
85
|
-
]);
|
|
86
|
-
const getParsedType = (data) => {
|
|
87
|
-
switch (typeof data) {
|
|
88
|
-
case "undefined": return exports.ZodParsedType.undefined;
|
|
89
|
-
case "string": return exports.ZodParsedType.string;
|
|
90
|
-
case "number": return Number.isNaN(data) ? exports.ZodParsedType.nan : exports.ZodParsedType.number;
|
|
91
|
-
case "boolean": return exports.ZodParsedType.boolean;
|
|
92
|
-
case "function": return exports.ZodParsedType.function;
|
|
93
|
-
case "bigint": return exports.ZodParsedType.bigint;
|
|
94
|
-
case "symbol": return exports.ZodParsedType.symbol;
|
|
95
|
-
case "object":
|
|
96
|
-
if (Array.isArray(data)) return exports.ZodParsedType.array;
|
|
97
|
-
if (data === null) return exports.ZodParsedType.null;
|
|
98
|
-
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") return exports.ZodParsedType.promise;
|
|
99
|
-
if (typeof Map !== "undefined" && data instanceof Map) return exports.ZodParsedType.map;
|
|
100
|
-
if (typeof Set !== "undefined" && data instanceof Set) return exports.ZodParsedType.set;
|
|
101
|
-
if (typeof Date !== "undefined" && data instanceof Date) return exports.ZodParsedType.date;
|
|
102
|
-
return exports.ZodParsedType.object;
|
|
103
|
-
default: return exports.ZodParsedType.unknown;
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
exports.getParsedType = getParsedType;
|
|
107
|
-
}));
|
|
108
|
-
|
|
109
|
-
//#endregion
|
|
110
|
-
//#region ../agent-provider/node_modules/zod/v3/ZodError.cjs
|
|
111
|
-
var require_ZodError = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
112
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
113
|
-
exports.ZodError = exports.quotelessJson = exports.ZodIssueCode = void 0;
|
|
114
|
-
const util_js_1 = require_util();
|
|
115
|
-
exports.ZodIssueCode = util_js_1.util.arrayToEnum([
|
|
116
|
-
"invalid_type",
|
|
117
|
-
"invalid_literal",
|
|
118
|
-
"custom",
|
|
119
|
-
"invalid_union",
|
|
120
|
-
"invalid_union_discriminator",
|
|
121
|
-
"invalid_enum_value",
|
|
122
|
-
"unrecognized_keys",
|
|
123
|
-
"invalid_arguments",
|
|
124
|
-
"invalid_return_type",
|
|
125
|
-
"invalid_date",
|
|
126
|
-
"invalid_string",
|
|
127
|
-
"too_small",
|
|
128
|
-
"too_big",
|
|
129
|
-
"invalid_intersection_types",
|
|
130
|
-
"not_multiple_of",
|
|
131
|
-
"not_finite"
|
|
132
|
-
]);
|
|
133
|
-
const quotelessJson = (obj) => {
|
|
134
|
-
return JSON.stringify(obj, null, 2).replace(/"([^"]+)":/g, "$1:");
|
|
135
|
-
};
|
|
136
|
-
exports.quotelessJson = quotelessJson;
|
|
137
|
-
var ZodError = class ZodError extends Error {
|
|
138
|
-
get errors() {
|
|
139
|
-
return this.issues;
|
|
140
|
-
}
|
|
141
|
-
constructor(issues) {
|
|
142
|
-
super();
|
|
143
|
-
this.issues = [];
|
|
144
|
-
this.addIssue = (sub) => {
|
|
145
|
-
this.issues = [...this.issues, sub];
|
|
146
|
-
};
|
|
147
|
-
this.addIssues = (subs = []) => {
|
|
148
|
-
this.issues = [...this.issues, ...subs];
|
|
149
|
-
};
|
|
150
|
-
const actualProto = new.target.prototype;
|
|
151
|
-
if (Object.setPrototypeOf) Object.setPrototypeOf(this, actualProto);
|
|
152
|
-
else this.__proto__ = actualProto;
|
|
153
|
-
this.name = "ZodError";
|
|
154
|
-
this.issues = issues;
|
|
155
|
-
}
|
|
156
|
-
format(_mapper) {
|
|
157
|
-
const mapper = _mapper || function(issue) {
|
|
158
|
-
return issue.message;
|
|
159
|
-
};
|
|
160
|
-
const fieldErrors = { _errors: [] };
|
|
161
|
-
const processError = (error) => {
|
|
162
|
-
for (const issue of error.issues) if (issue.code === "invalid_union") issue.unionErrors.map(processError);
|
|
163
|
-
else if (issue.code === "invalid_return_type") processError(issue.returnTypeError);
|
|
164
|
-
else if (issue.code === "invalid_arguments") processError(issue.argumentsError);
|
|
165
|
-
else if (issue.path.length === 0) fieldErrors._errors.push(mapper(issue));
|
|
166
|
-
else {
|
|
167
|
-
let curr = fieldErrors;
|
|
168
|
-
let i = 0;
|
|
169
|
-
while (i < issue.path.length) {
|
|
170
|
-
const el = issue.path[i];
|
|
171
|
-
if (!(i === issue.path.length - 1)) curr[el] = curr[el] || { _errors: [] };
|
|
172
|
-
else {
|
|
173
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
174
|
-
curr[el]._errors.push(mapper(issue));
|
|
175
|
-
}
|
|
176
|
-
curr = curr[el];
|
|
177
|
-
i++;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
processError(this);
|
|
182
|
-
return fieldErrors;
|
|
183
|
-
}
|
|
184
|
-
static assert(value) {
|
|
185
|
-
if (!(value instanceof ZodError)) throw new Error(`Not a ZodError: ${value}`);
|
|
186
|
-
}
|
|
187
|
-
toString() {
|
|
188
|
-
return this.message;
|
|
189
|
-
}
|
|
190
|
-
get message() {
|
|
191
|
-
return JSON.stringify(this.issues, util_js_1.util.jsonStringifyReplacer, 2);
|
|
192
|
-
}
|
|
193
|
-
get isEmpty() {
|
|
194
|
-
return this.issues.length === 0;
|
|
195
|
-
}
|
|
196
|
-
flatten(mapper = (issue) => issue.message) {
|
|
197
|
-
const fieldErrors = {};
|
|
198
|
-
const formErrors = [];
|
|
199
|
-
for (const sub of this.issues) if (sub.path.length > 0) {
|
|
200
|
-
const firstEl = sub.path[0];
|
|
201
|
-
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
|
202
|
-
fieldErrors[firstEl].push(mapper(sub));
|
|
203
|
-
} else formErrors.push(mapper(sub));
|
|
204
|
-
return {
|
|
205
|
-
formErrors,
|
|
206
|
-
fieldErrors
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
get formErrors() {
|
|
210
|
-
return this.flatten();
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
exports.ZodError = ZodError;
|
|
214
|
-
ZodError.create = (issues) => {
|
|
215
|
-
return new ZodError(issues);
|
|
216
|
-
};
|
|
217
|
-
}));
|
|
218
|
-
|
|
219
|
-
//#endregion
|
|
220
|
-
//#region ../agent-provider/node_modules/zod/v3/locales/en.cjs
|
|
221
|
-
var require_en = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
222
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
223
|
-
const ZodError_js_1 = require_ZodError();
|
|
224
|
-
const util_js_1 = require_util();
|
|
225
|
-
const errorMap = (issue, _ctx) => {
|
|
226
|
-
let message;
|
|
227
|
-
switch (issue.code) {
|
|
228
|
-
case ZodError_js_1.ZodIssueCode.invalid_type:
|
|
229
|
-
if (issue.received === util_js_1.ZodParsedType.undefined) message = "Required";
|
|
230
|
-
else message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
231
|
-
break;
|
|
232
|
-
case ZodError_js_1.ZodIssueCode.invalid_literal:
|
|
233
|
-
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util_js_1.util.jsonStringifyReplacer)}`;
|
|
234
|
-
break;
|
|
235
|
-
case ZodError_js_1.ZodIssueCode.unrecognized_keys:
|
|
236
|
-
message = `Unrecognized key(s) in object: ${util_js_1.util.joinValues(issue.keys, ", ")}`;
|
|
237
|
-
break;
|
|
238
|
-
case ZodError_js_1.ZodIssueCode.invalid_union:
|
|
239
|
-
message = `Invalid input`;
|
|
240
|
-
break;
|
|
241
|
-
case ZodError_js_1.ZodIssueCode.invalid_union_discriminator:
|
|
242
|
-
message = `Invalid discriminator value. Expected ${util_js_1.util.joinValues(issue.options)}`;
|
|
243
|
-
break;
|
|
244
|
-
case ZodError_js_1.ZodIssueCode.invalid_enum_value:
|
|
245
|
-
message = `Invalid enum value. Expected ${util_js_1.util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
246
|
-
break;
|
|
247
|
-
case ZodError_js_1.ZodIssueCode.invalid_arguments:
|
|
248
|
-
message = `Invalid function arguments`;
|
|
249
|
-
break;
|
|
250
|
-
case ZodError_js_1.ZodIssueCode.invalid_return_type:
|
|
251
|
-
message = `Invalid function return type`;
|
|
252
|
-
break;
|
|
253
|
-
case ZodError_js_1.ZodIssueCode.invalid_date:
|
|
254
|
-
message = `Invalid date`;
|
|
255
|
-
break;
|
|
256
|
-
case ZodError_js_1.ZodIssueCode.invalid_string:
|
|
257
|
-
if (typeof issue.validation === "object") if ("includes" in issue.validation) {
|
|
258
|
-
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
259
|
-
if (typeof issue.validation.position === "number") message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
260
|
-
} else if ("startsWith" in issue.validation) message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
261
|
-
else if ("endsWith" in issue.validation) message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
262
|
-
else util_js_1.util.assertNever(issue.validation);
|
|
263
|
-
else if (issue.validation !== "regex") message = `Invalid ${issue.validation}`;
|
|
264
|
-
else message = "Invalid";
|
|
265
|
-
break;
|
|
266
|
-
case ZodError_js_1.ZodIssueCode.too_small:
|
|
267
|
-
if (issue.type === "array") message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
268
|
-
else if (issue.type === "string") message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
269
|
-
else if (issue.type === "number") message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
270
|
-
else if (issue.type === "bigint") message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
271
|
-
else if (issue.type === "date") message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
272
|
-
else message = "Invalid input";
|
|
273
|
-
break;
|
|
274
|
-
case ZodError_js_1.ZodIssueCode.too_big:
|
|
275
|
-
if (issue.type === "array") message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
276
|
-
else if (issue.type === "string") message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
277
|
-
else if (issue.type === "number") message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
278
|
-
else if (issue.type === "bigint") message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
279
|
-
else if (issue.type === "date") message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
280
|
-
else message = "Invalid input";
|
|
281
|
-
break;
|
|
282
|
-
case ZodError_js_1.ZodIssueCode.custom:
|
|
283
|
-
message = `Invalid input`;
|
|
284
|
-
break;
|
|
285
|
-
case ZodError_js_1.ZodIssueCode.invalid_intersection_types:
|
|
286
|
-
message = `Intersection results could not be merged`;
|
|
287
|
-
break;
|
|
288
|
-
case ZodError_js_1.ZodIssueCode.not_multiple_of:
|
|
289
|
-
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
290
|
-
break;
|
|
291
|
-
case ZodError_js_1.ZodIssueCode.not_finite:
|
|
292
|
-
message = "Number must be finite";
|
|
293
|
-
break;
|
|
294
|
-
default:
|
|
295
|
-
message = _ctx.defaultError;
|
|
296
|
-
util_js_1.util.assertNever(issue);
|
|
297
|
-
}
|
|
298
|
-
return { message };
|
|
299
|
-
};
|
|
300
|
-
exports.default = errorMap;
|
|
301
|
-
}));
|
|
302
|
-
|
|
303
|
-
//#endregion
|
|
304
|
-
//#region ../agent-provider/node_modules/zod/v3/errors.cjs
|
|
305
|
-
var require_errors$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
306
|
-
var __importDefault = exports && exports.__importDefault || function(mod) {
|
|
307
|
-
return mod && mod.__esModule ? mod : { "default": mod };
|
|
308
|
-
};
|
|
309
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
310
|
-
exports.defaultErrorMap = void 0;
|
|
311
|
-
exports.setErrorMap = setErrorMap;
|
|
312
|
-
exports.getErrorMap = getErrorMap;
|
|
313
|
-
const en_js_1 = __importDefault(require_en());
|
|
314
|
-
exports.defaultErrorMap = en_js_1.default;
|
|
315
|
-
let overrideErrorMap = en_js_1.default;
|
|
316
|
-
function setErrorMap(map) {
|
|
317
|
-
overrideErrorMap = map;
|
|
318
|
-
}
|
|
319
|
-
function getErrorMap() {
|
|
320
|
-
return overrideErrorMap;
|
|
321
|
-
}
|
|
322
|
-
}));
|
|
323
|
-
|
|
324
|
-
//#endregion
|
|
325
|
-
//#region ../agent-provider/node_modules/zod/v3/helpers/parseUtil.cjs
|
|
326
|
-
var require_parseUtil = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
327
|
-
var __importDefault = exports && exports.__importDefault || function(mod) {
|
|
328
|
-
return mod && mod.__esModule ? mod : { "default": mod };
|
|
329
|
-
};
|
|
330
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
331
|
-
exports.isAsync = exports.isValid = exports.isDirty = exports.isAborted = exports.OK = exports.DIRTY = exports.INVALID = exports.ParseStatus = exports.EMPTY_PATH = exports.makeIssue = void 0;
|
|
332
|
-
exports.addIssueToContext = addIssueToContext;
|
|
333
|
-
const errors_js_1 = require_errors$1();
|
|
334
|
-
const en_js_1 = __importDefault(require_en());
|
|
335
|
-
const makeIssue = (params) => {
|
|
336
|
-
const { data, path, errorMaps, issueData } = params;
|
|
337
|
-
const fullPath = [...path, ...issueData.path || []];
|
|
338
|
-
const fullIssue = {
|
|
339
|
-
...issueData,
|
|
340
|
-
path: fullPath
|
|
341
|
-
};
|
|
342
|
-
if (issueData.message !== void 0) return {
|
|
343
|
-
...issueData,
|
|
344
|
-
path: fullPath,
|
|
345
|
-
message: issueData.message
|
|
346
|
-
};
|
|
347
|
-
let errorMessage = "";
|
|
348
|
-
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
349
|
-
for (const map of maps) errorMessage = map(fullIssue, {
|
|
350
|
-
data,
|
|
351
|
-
defaultError: errorMessage
|
|
352
|
-
}).message;
|
|
353
|
-
return {
|
|
354
|
-
...issueData,
|
|
355
|
-
path: fullPath,
|
|
356
|
-
message: errorMessage
|
|
357
|
-
};
|
|
358
|
-
};
|
|
359
|
-
exports.makeIssue = makeIssue;
|
|
360
|
-
exports.EMPTY_PATH = [];
|
|
361
|
-
function addIssueToContext(ctx, issueData) {
|
|
362
|
-
const overrideMap = (0, errors_js_1.getErrorMap)();
|
|
363
|
-
const issue = (0, exports.makeIssue)({
|
|
364
|
-
issueData,
|
|
365
|
-
data: ctx.data,
|
|
366
|
-
path: ctx.path,
|
|
367
|
-
errorMaps: [
|
|
368
|
-
ctx.common.contextualErrorMap,
|
|
369
|
-
ctx.schemaErrorMap,
|
|
370
|
-
overrideMap,
|
|
371
|
-
overrideMap === en_js_1.default ? void 0 : en_js_1.default
|
|
372
|
-
].filter((x) => !!x)
|
|
373
|
-
});
|
|
374
|
-
ctx.common.issues.push(issue);
|
|
375
|
-
}
|
|
376
|
-
var ParseStatus = class ParseStatus {
|
|
377
|
-
constructor() {
|
|
378
|
-
this.value = "valid";
|
|
379
|
-
}
|
|
380
|
-
dirty() {
|
|
381
|
-
if (this.value === "valid") this.value = "dirty";
|
|
382
|
-
}
|
|
383
|
-
abort() {
|
|
384
|
-
if (this.value !== "aborted") this.value = "aborted";
|
|
385
|
-
}
|
|
386
|
-
static mergeArray(status, results) {
|
|
387
|
-
const arrayValue = [];
|
|
388
|
-
for (const s of results) {
|
|
389
|
-
if (s.status === "aborted") return exports.INVALID;
|
|
390
|
-
if (s.status === "dirty") status.dirty();
|
|
391
|
-
arrayValue.push(s.value);
|
|
392
|
-
}
|
|
393
|
-
return {
|
|
394
|
-
status: status.value,
|
|
395
|
-
value: arrayValue
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
static async mergeObjectAsync(status, pairs) {
|
|
399
|
-
const syncPairs = [];
|
|
400
|
-
for (const pair of pairs) {
|
|
401
|
-
const key = await pair.key;
|
|
402
|
-
const value = await pair.value;
|
|
403
|
-
syncPairs.push({
|
|
404
|
-
key,
|
|
405
|
-
value
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
409
|
-
}
|
|
410
|
-
static mergeObjectSync(status, pairs) {
|
|
411
|
-
const finalObject = {};
|
|
412
|
-
for (const pair of pairs) {
|
|
413
|
-
const { key, value } = pair;
|
|
414
|
-
if (key.status === "aborted") return exports.INVALID;
|
|
415
|
-
if (value.status === "aborted") return exports.INVALID;
|
|
416
|
-
if (key.status === "dirty") status.dirty();
|
|
417
|
-
if (value.status === "dirty") status.dirty();
|
|
418
|
-
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) finalObject[key.value] = value.value;
|
|
419
|
-
}
|
|
420
|
-
return {
|
|
421
|
-
status: status.value,
|
|
422
|
-
value: finalObject
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
exports.ParseStatus = ParseStatus;
|
|
427
|
-
exports.INVALID = Object.freeze({ status: "aborted" });
|
|
428
|
-
const DIRTY = (value) => ({
|
|
429
|
-
status: "dirty",
|
|
430
|
-
value
|
|
431
|
-
});
|
|
432
|
-
exports.DIRTY = DIRTY;
|
|
433
|
-
const OK = (value) => ({
|
|
434
|
-
status: "valid",
|
|
435
|
-
value
|
|
436
|
-
});
|
|
437
|
-
exports.OK = OK;
|
|
438
|
-
const isAborted = (x) => x.status === "aborted";
|
|
439
|
-
exports.isAborted = isAborted;
|
|
440
|
-
const isDirty = (x) => x.status === "dirty";
|
|
441
|
-
exports.isDirty = isDirty;
|
|
442
|
-
const isValid = (x) => x.status === "valid";
|
|
443
|
-
exports.isValid = isValid;
|
|
444
|
-
const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
445
|
-
exports.isAsync = isAsync;
|
|
446
|
-
}));
|
|
447
|
-
|
|
448
|
-
//#endregion
|
|
449
|
-
//#region ../agent-provider/node_modules/zod/v3/helpers/typeAliases.cjs
|
|
450
|
-
var require_typeAliases = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
451
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
452
|
-
}));
|
|
453
|
-
|
|
454
|
-
//#endregion
|
|
455
|
-
//#region ../agent-provider/node_modules/zod/v3/helpers/errorUtil.cjs
|
|
456
|
-
var require_errorUtil = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
457
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
458
|
-
exports.errorUtil = void 0;
|
|
459
|
-
var errorUtil;
|
|
460
|
-
(function(errorUtil) {
|
|
461
|
-
errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
462
|
-
errorUtil.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
463
|
-
})(errorUtil || (exports.errorUtil = errorUtil = {}));
|
|
464
|
-
}));
|
|
465
|
-
|
|
466
|
-
//#endregion
|
|
467
|
-
//#region ../agent-provider/node_modules/zod/v3/types.cjs
|
|
468
|
-
var require_types$4 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
469
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
470
|
-
exports.discriminatedUnion = exports.date = exports.boolean = exports.bigint = exports.array = exports.any = exports.coerce = exports.ZodFirstPartyTypeKind = exports.late = exports.ZodSchema = exports.Schema = exports.ZodReadonly = exports.ZodPipeline = exports.ZodBranded = exports.BRAND = exports.ZodNaN = exports.ZodCatch = exports.ZodDefault = exports.ZodNullable = exports.ZodOptional = exports.ZodTransformer = exports.ZodEffects = exports.ZodPromise = exports.ZodNativeEnum = exports.ZodEnum = exports.ZodLiteral = exports.ZodLazy = exports.ZodFunction = exports.ZodSet = exports.ZodMap = exports.ZodRecord = exports.ZodTuple = exports.ZodIntersection = exports.ZodDiscriminatedUnion = exports.ZodUnion = exports.ZodObject = exports.ZodArray = exports.ZodVoid = exports.ZodNever = exports.ZodUnknown = exports.ZodAny = exports.ZodNull = exports.ZodUndefined = exports.ZodSymbol = exports.ZodDate = exports.ZodBoolean = exports.ZodBigInt = exports.ZodNumber = exports.ZodString = exports.ZodType = void 0;
|
|
471
|
-
exports.NEVER = exports.void = exports.unknown = exports.union = exports.undefined = exports.tuple = exports.transformer = exports.symbol = exports.string = exports.strictObject = exports.set = exports.record = exports.promise = exports.preprocess = exports.pipeline = exports.ostring = exports.optional = exports.onumber = exports.oboolean = exports.object = exports.number = exports.nullable = exports.null = exports.never = exports.nativeEnum = exports.nan = exports.map = exports.literal = exports.lazy = exports.intersection = exports.instanceof = exports.function = exports.enum = exports.effect = void 0;
|
|
472
|
-
exports.datetimeRegex = datetimeRegex;
|
|
473
|
-
exports.custom = custom;
|
|
474
|
-
const ZodError_js_1 = require_ZodError();
|
|
475
|
-
const errors_js_1 = require_errors$1();
|
|
476
|
-
const errorUtil_js_1 = require_errorUtil();
|
|
477
|
-
const parseUtil_js_1 = require_parseUtil();
|
|
478
|
-
const util_js_1 = require_util();
|
|
479
|
-
var ParseInputLazyPath = class {
|
|
480
|
-
constructor(parent, value, path, key) {
|
|
481
|
-
this._cachedPath = [];
|
|
482
|
-
this.parent = parent;
|
|
483
|
-
this.data = value;
|
|
484
|
-
this._path = path;
|
|
485
|
-
this._key = key;
|
|
486
|
-
}
|
|
487
|
-
get path() {
|
|
488
|
-
if (!this._cachedPath.length) if (Array.isArray(this._key)) this._cachedPath.push(...this._path, ...this._key);
|
|
489
|
-
else this._cachedPath.push(...this._path, this._key);
|
|
490
|
-
return this._cachedPath;
|
|
491
|
-
}
|
|
492
|
-
};
|
|
493
|
-
const handleResult = (ctx, result) => {
|
|
494
|
-
if ((0, parseUtil_js_1.isValid)(result)) return {
|
|
495
|
-
success: true,
|
|
496
|
-
data: result.value
|
|
497
|
-
};
|
|
498
|
-
else {
|
|
499
|
-
if (!ctx.common.issues.length) throw new Error("Validation failed but no issues detected.");
|
|
500
|
-
return {
|
|
501
|
-
success: false,
|
|
502
|
-
get error() {
|
|
503
|
-
if (this._error) return this._error;
|
|
504
|
-
this._error = new ZodError_js_1.ZodError(ctx.common.issues);
|
|
505
|
-
return this._error;
|
|
506
|
-
}
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
};
|
|
510
|
-
function processCreateParams(params) {
|
|
511
|
-
if (!params) return {};
|
|
512
|
-
const { errorMap, invalid_type_error, required_error, description } = params;
|
|
513
|
-
if (errorMap && (invalid_type_error || required_error)) throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
514
|
-
if (errorMap) return {
|
|
515
|
-
errorMap,
|
|
516
|
-
description
|
|
517
|
-
};
|
|
518
|
-
const customMap = (iss, ctx) => {
|
|
519
|
-
const { message } = params;
|
|
520
|
-
if (iss.code === "invalid_enum_value") return { message: message ?? ctx.defaultError };
|
|
521
|
-
if (typeof ctx.data === "undefined") return { message: message ?? required_error ?? ctx.defaultError };
|
|
522
|
-
if (iss.code !== "invalid_type") return { message: ctx.defaultError };
|
|
523
|
-
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
524
|
-
};
|
|
525
|
-
return {
|
|
526
|
-
errorMap: customMap,
|
|
527
|
-
description
|
|
528
|
-
};
|
|
529
|
-
}
|
|
530
|
-
var ZodType = class {
|
|
531
|
-
get description() {
|
|
532
|
-
return this._def.description;
|
|
533
|
-
}
|
|
534
|
-
_getType(input) {
|
|
535
|
-
return (0, util_js_1.getParsedType)(input.data);
|
|
536
|
-
}
|
|
537
|
-
_getOrReturnCtx(input, ctx) {
|
|
538
|
-
return ctx || {
|
|
539
|
-
common: input.parent.common,
|
|
540
|
-
data: input.data,
|
|
541
|
-
parsedType: (0, util_js_1.getParsedType)(input.data),
|
|
542
|
-
schemaErrorMap: this._def.errorMap,
|
|
543
|
-
path: input.path,
|
|
544
|
-
parent: input.parent
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
_processInputParams(input) {
|
|
548
|
-
return {
|
|
549
|
-
status: new parseUtil_js_1.ParseStatus(),
|
|
550
|
-
ctx: {
|
|
551
|
-
common: input.parent.common,
|
|
552
|
-
data: input.data,
|
|
553
|
-
parsedType: (0, util_js_1.getParsedType)(input.data),
|
|
554
|
-
schemaErrorMap: this._def.errorMap,
|
|
555
|
-
path: input.path,
|
|
556
|
-
parent: input.parent
|
|
557
|
-
}
|
|
558
|
-
};
|
|
559
|
-
}
|
|
560
|
-
_parseSync(input) {
|
|
561
|
-
const result = this._parse(input);
|
|
562
|
-
if ((0, parseUtil_js_1.isAsync)(result)) throw new Error("Synchronous parse encountered promise.");
|
|
563
|
-
return result;
|
|
564
|
-
}
|
|
565
|
-
_parseAsync(input) {
|
|
566
|
-
const result = this._parse(input);
|
|
567
|
-
return Promise.resolve(result);
|
|
568
|
-
}
|
|
569
|
-
parse(data, params) {
|
|
570
|
-
const result = this.safeParse(data, params);
|
|
571
|
-
if (result.success) return result.data;
|
|
572
|
-
throw result.error;
|
|
573
|
-
}
|
|
574
|
-
safeParse(data, params) {
|
|
575
|
-
const ctx = {
|
|
576
|
-
common: {
|
|
577
|
-
issues: [],
|
|
578
|
-
async: params?.async ?? false,
|
|
579
|
-
contextualErrorMap: params?.errorMap
|
|
580
|
-
},
|
|
581
|
-
path: params?.path || [],
|
|
582
|
-
schemaErrorMap: this._def.errorMap,
|
|
583
|
-
parent: null,
|
|
584
|
-
data,
|
|
585
|
-
parsedType: (0, util_js_1.getParsedType)(data)
|
|
586
|
-
};
|
|
587
|
-
return handleResult(ctx, this._parseSync({
|
|
588
|
-
data,
|
|
589
|
-
path: ctx.path,
|
|
590
|
-
parent: ctx
|
|
591
|
-
}));
|
|
592
|
-
}
|
|
593
|
-
"~validate"(data) {
|
|
594
|
-
const ctx = {
|
|
595
|
-
common: {
|
|
596
|
-
issues: [],
|
|
597
|
-
async: !!this["~standard"].async
|
|
598
|
-
},
|
|
599
|
-
path: [],
|
|
600
|
-
schemaErrorMap: this._def.errorMap,
|
|
601
|
-
parent: null,
|
|
602
|
-
data,
|
|
603
|
-
parsedType: (0, util_js_1.getParsedType)(data)
|
|
604
|
-
};
|
|
605
|
-
if (!this["~standard"].async) try {
|
|
606
|
-
const result = this._parseSync({
|
|
607
|
-
data,
|
|
608
|
-
path: [],
|
|
609
|
-
parent: ctx
|
|
610
|
-
});
|
|
611
|
-
return (0, parseUtil_js_1.isValid)(result) ? { value: result.value } : { issues: ctx.common.issues };
|
|
612
|
-
} catch (err) {
|
|
613
|
-
if (err?.message?.toLowerCase()?.includes("encountered")) this["~standard"].async = true;
|
|
614
|
-
ctx.common = {
|
|
615
|
-
issues: [],
|
|
616
|
-
async: true
|
|
617
|
-
};
|
|
618
|
-
}
|
|
619
|
-
return this._parseAsync({
|
|
620
|
-
data,
|
|
621
|
-
path: [],
|
|
622
|
-
parent: ctx
|
|
623
|
-
}).then((result) => (0, parseUtil_js_1.isValid)(result) ? { value: result.value } : { issues: ctx.common.issues });
|
|
624
|
-
}
|
|
625
|
-
async parseAsync(data, params) {
|
|
626
|
-
const result = await this.safeParseAsync(data, params);
|
|
627
|
-
if (result.success) return result.data;
|
|
628
|
-
throw result.error;
|
|
629
|
-
}
|
|
630
|
-
async safeParseAsync(data, params) {
|
|
631
|
-
const ctx = {
|
|
632
|
-
common: {
|
|
633
|
-
issues: [],
|
|
634
|
-
contextualErrorMap: params?.errorMap,
|
|
635
|
-
async: true
|
|
636
|
-
},
|
|
637
|
-
path: params?.path || [],
|
|
638
|
-
schemaErrorMap: this._def.errorMap,
|
|
639
|
-
parent: null,
|
|
640
|
-
data,
|
|
641
|
-
parsedType: (0, util_js_1.getParsedType)(data)
|
|
642
|
-
};
|
|
643
|
-
const maybeAsyncResult = this._parse({
|
|
644
|
-
data,
|
|
645
|
-
path: ctx.path,
|
|
646
|
-
parent: ctx
|
|
647
|
-
});
|
|
648
|
-
return handleResult(ctx, await ((0, parseUtil_js_1.isAsync)(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult)));
|
|
649
|
-
}
|
|
650
|
-
refine(check, message) {
|
|
651
|
-
const getIssueProperties = (val) => {
|
|
652
|
-
if (typeof message === "string" || typeof message === "undefined") return { message };
|
|
653
|
-
else if (typeof message === "function") return message(val);
|
|
654
|
-
else return message;
|
|
655
|
-
};
|
|
656
|
-
return this._refinement((val, ctx) => {
|
|
657
|
-
const result = check(val);
|
|
658
|
-
const setError = () => ctx.addIssue({
|
|
659
|
-
code: ZodError_js_1.ZodIssueCode.custom,
|
|
660
|
-
...getIssueProperties(val)
|
|
661
|
-
});
|
|
662
|
-
if (typeof Promise !== "undefined" && result instanceof Promise) return result.then((data) => {
|
|
663
|
-
if (!data) {
|
|
664
|
-
setError();
|
|
665
|
-
return false;
|
|
666
|
-
} else return true;
|
|
667
|
-
});
|
|
668
|
-
if (!result) {
|
|
669
|
-
setError();
|
|
670
|
-
return false;
|
|
671
|
-
} else return true;
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
refinement(check, refinementData) {
|
|
675
|
-
return this._refinement((val, ctx) => {
|
|
676
|
-
if (!check(val)) {
|
|
677
|
-
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
678
|
-
return false;
|
|
679
|
-
} else return true;
|
|
680
|
-
});
|
|
681
|
-
}
|
|
682
|
-
_refinement(refinement) {
|
|
683
|
-
return new ZodEffects({
|
|
684
|
-
schema: this,
|
|
685
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
686
|
-
effect: {
|
|
687
|
-
type: "refinement",
|
|
688
|
-
refinement
|
|
689
|
-
}
|
|
690
|
-
});
|
|
691
|
-
}
|
|
692
|
-
superRefine(refinement) {
|
|
693
|
-
return this._refinement(refinement);
|
|
694
|
-
}
|
|
695
|
-
constructor(def) {
|
|
696
|
-
/** Alias of safeParseAsync */
|
|
697
|
-
this.spa = this.safeParseAsync;
|
|
698
|
-
this._def = def;
|
|
699
|
-
this.parse = this.parse.bind(this);
|
|
700
|
-
this.safeParse = this.safeParse.bind(this);
|
|
701
|
-
this.parseAsync = this.parseAsync.bind(this);
|
|
702
|
-
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
703
|
-
this.spa = this.spa.bind(this);
|
|
704
|
-
this.refine = this.refine.bind(this);
|
|
705
|
-
this.refinement = this.refinement.bind(this);
|
|
706
|
-
this.superRefine = this.superRefine.bind(this);
|
|
707
|
-
this.optional = this.optional.bind(this);
|
|
708
|
-
this.nullable = this.nullable.bind(this);
|
|
709
|
-
this.nullish = this.nullish.bind(this);
|
|
710
|
-
this.array = this.array.bind(this);
|
|
711
|
-
this.promise = this.promise.bind(this);
|
|
712
|
-
this.or = this.or.bind(this);
|
|
713
|
-
this.and = this.and.bind(this);
|
|
714
|
-
this.transform = this.transform.bind(this);
|
|
715
|
-
this.brand = this.brand.bind(this);
|
|
716
|
-
this.default = this.default.bind(this);
|
|
717
|
-
this.catch = this.catch.bind(this);
|
|
718
|
-
this.describe = this.describe.bind(this);
|
|
719
|
-
this.pipe = this.pipe.bind(this);
|
|
720
|
-
this.readonly = this.readonly.bind(this);
|
|
721
|
-
this.isNullable = this.isNullable.bind(this);
|
|
722
|
-
this.isOptional = this.isOptional.bind(this);
|
|
723
|
-
this["~standard"] = {
|
|
724
|
-
version: 1,
|
|
725
|
-
vendor: "zod",
|
|
726
|
-
validate: (data) => this["~validate"](data)
|
|
727
|
-
};
|
|
728
|
-
}
|
|
729
|
-
optional() {
|
|
730
|
-
return ZodOptional.create(this, this._def);
|
|
731
|
-
}
|
|
732
|
-
nullable() {
|
|
733
|
-
return ZodNullable.create(this, this._def);
|
|
734
|
-
}
|
|
735
|
-
nullish() {
|
|
736
|
-
return this.nullable().optional();
|
|
737
|
-
}
|
|
738
|
-
array() {
|
|
739
|
-
return ZodArray.create(this);
|
|
740
|
-
}
|
|
741
|
-
promise() {
|
|
742
|
-
return ZodPromise.create(this, this._def);
|
|
743
|
-
}
|
|
744
|
-
or(option) {
|
|
745
|
-
return ZodUnion.create([this, option], this._def);
|
|
746
|
-
}
|
|
747
|
-
and(incoming) {
|
|
748
|
-
return ZodIntersection.create(this, incoming, this._def);
|
|
749
|
-
}
|
|
750
|
-
transform(transform) {
|
|
751
|
-
return new ZodEffects({
|
|
752
|
-
...processCreateParams(this._def),
|
|
753
|
-
schema: this,
|
|
754
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
755
|
-
effect: {
|
|
756
|
-
type: "transform",
|
|
757
|
-
transform
|
|
758
|
-
}
|
|
759
|
-
});
|
|
760
|
-
}
|
|
761
|
-
default(def) {
|
|
762
|
-
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
763
|
-
return new ZodDefault({
|
|
764
|
-
...processCreateParams(this._def),
|
|
765
|
-
innerType: this,
|
|
766
|
-
defaultValue: defaultValueFunc,
|
|
767
|
-
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
768
|
-
});
|
|
769
|
-
}
|
|
770
|
-
brand() {
|
|
771
|
-
return new ZodBranded({
|
|
772
|
-
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
773
|
-
type: this,
|
|
774
|
-
...processCreateParams(this._def)
|
|
775
|
-
});
|
|
776
|
-
}
|
|
777
|
-
catch(def) {
|
|
778
|
-
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
779
|
-
return new ZodCatch({
|
|
780
|
-
...processCreateParams(this._def),
|
|
781
|
-
innerType: this,
|
|
782
|
-
catchValue: catchValueFunc,
|
|
783
|
-
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
784
|
-
});
|
|
785
|
-
}
|
|
786
|
-
describe(description) {
|
|
787
|
-
const This = this.constructor;
|
|
788
|
-
return new This({
|
|
789
|
-
...this._def,
|
|
790
|
-
description
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
pipe(target) {
|
|
794
|
-
return ZodPipeline.create(this, target);
|
|
795
|
-
}
|
|
796
|
-
readonly() {
|
|
797
|
-
return ZodReadonly.create(this);
|
|
798
|
-
}
|
|
799
|
-
isOptional() {
|
|
800
|
-
return this.safeParse(void 0).success;
|
|
801
|
-
}
|
|
802
|
-
isNullable() {
|
|
803
|
-
return this.safeParse(null).success;
|
|
804
|
-
}
|
|
805
|
-
};
|
|
806
|
-
exports.ZodType = ZodType;
|
|
807
|
-
exports.Schema = ZodType;
|
|
808
|
-
exports.ZodSchema = ZodType;
|
|
809
|
-
const cuidRegex = /^c[^\s-]{8,}$/i;
|
|
810
|
-
const cuid2Regex = /^[0-9a-z]+$/;
|
|
811
|
-
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
812
|
-
const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
|
813
|
-
const nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
814
|
-
const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
815
|
-
const durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
|
816
|
-
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
817
|
-
const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
818
|
-
let emojiRegex;
|
|
819
|
-
const ipv4Regex = /^(?:(?: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])$/;
|
|
820
|
-
const ipv4CidrRegex = /^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/;
|
|
821
|
-
const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
822
|
-
const ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
823
|
-
const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
824
|
-
const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
825
|
-
const dateRegexSource = `((\\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])))`;
|
|
826
|
-
const dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
827
|
-
function timeRegexSource(args) {
|
|
828
|
-
let secondsRegexSource = `[0-5]\\d`;
|
|
829
|
-
if (args.precision) secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
830
|
-
else if (args.precision == null) secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
831
|
-
const secondsQuantifier = args.precision ? "+" : "?";
|
|
832
|
-
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
833
|
-
}
|
|
834
|
-
function timeRegex(args) {
|
|
835
|
-
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
836
|
-
}
|
|
837
|
-
function datetimeRegex(args) {
|
|
838
|
-
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
839
|
-
const opts = [];
|
|
840
|
-
opts.push(args.local ? `Z?` : `Z`);
|
|
841
|
-
if (args.offset) opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
842
|
-
regex = `${regex}(${opts.join("|")})`;
|
|
843
|
-
return new RegExp(`^${regex}$`);
|
|
844
|
-
}
|
|
845
|
-
function isValidIP(ip, version) {
|
|
846
|
-
if ((version === "v4" || !version) && ipv4Regex.test(ip)) return true;
|
|
847
|
-
if ((version === "v6" || !version) && ipv6Regex.test(ip)) return true;
|
|
848
|
-
return false;
|
|
849
|
-
}
|
|
850
|
-
function isValidJWT(jwt, alg) {
|
|
851
|
-
if (!jwtRegex.test(jwt)) return false;
|
|
852
|
-
try {
|
|
853
|
-
const [header] = jwt.split(".");
|
|
854
|
-
if (!header) return false;
|
|
855
|
-
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
856
|
-
const decoded = JSON.parse(atob(base64));
|
|
857
|
-
if (typeof decoded !== "object" || decoded === null) return false;
|
|
858
|
-
if ("typ" in decoded && decoded?.typ !== "JWT") return false;
|
|
859
|
-
if (!decoded.alg) return false;
|
|
860
|
-
if (alg && decoded.alg !== alg) return false;
|
|
861
|
-
return true;
|
|
862
|
-
} catch {
|
|
863
|
-
return false;
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
function isValidCidr(ip, version) {
|
|
867
|
-
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) return true;
|
|
868
|
-
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) return true;
|
|
869
|
-
return false;
|
|
870
|
-
}
|
|
871
|
-
var ZodString = class ZodString extends ZodType {
|
|
872
|
-
_parse(input) {
|
|
873
|
-
if (this._def.coerce) input.data = String(input.data);
|
|
874
|
-
if (this._getType(input) !== util_js_1.ZodParsedType.string) {
|
|
875
|
-
const ctx = this._getOrReturnCtx(input);
|
|
876
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
877
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
878
|
-
expected: util_js_1.ZodParsedType.string,
|
|
879
|
-
received: ctx.parsedType
|
|
880
|
-
});
|
|
881
|
-
return parseUtil_js_1.INVALID;
|
|
882
|
-
}
|
|
883
|
-
const status = new parseUtil_js_1.ParseStatus();
|
|
884
|
-
let ctx = void 0;
|
|
885
|
-
for (const check of this._def.checks) if (check.kind === "min") {
|
|
886
|
-
if (input.data.length < check.value) {
|
|
887
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
888
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
889
|
-
code: ZodError_js_1.ZodIssueCode.too_small,
|
|
890
|
-
minimum: check.value,
|
|
891
|
-
type: "string",
|
|
892
|
-
inclusive: true,
|
|
893
|
-
exact: false,
|
|
894
|
-
message: check.message
|
|
895
|
-
});
|
|
896
|
-
status.dirty();
|
|
897
|
-
}
|
|
898
|
-
} else if (check.kind === "max") {
|
|
899
|
-
if (input.data.length > check.value) {
|
|
900
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
901
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
902
|
-
code: ZodError_js_1.ZodIssueCode.too_big,
|
|
903
|
-
maximum: check.value,
|
|
904
|
-
type: "string",
|
|
905
|
-
inclusive: true,
|
|
906
|
-
exact: false,
|
|
907
|
-
message: check.message
|
|
908
|
-
});
|
|
909
|
-
status.dirty();
|
|
910
|
-
}
|
|
911
|
-
} else if (check.kind === "length") {
|
|
912
|
-
const tooBig = input.data.length > check.value;
|
|
913
|
-
const tooSmall = input.data.length < check.value;
|
|
914
|
-
if (tooBig || tooSmall) {
|
|
915
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
916
|
-
if (tooBig) (0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
917
|
-
code: ZodError_js_1.ZodIssueCode.too_big,
|
|
918
|
-
maximum: check.value,
|
|
919
|
-
type: "string",
|
|
920
|
-
inclusive: true,
|
|
921
|
-
exact: true,
|
|
922
|
-
message: check.message
|
|
923
|
-
});
|
|
924
|
-
else if (tooSmall) (0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
925
|
-
code: ZodError_js_1.ZodIssueCode.too_small,
|
|
926
|
-
minimum: check.value,
|
|
927
|
-
type: "string",
|
|
928
|
-
inclusive: true,
|
|
929
|
-
exact: true,
|
|
930
|
-
message: check.message
|
|
931
|
-
});
|
|
932
|
-
status.dirty();
|
|
933
|
-
}
|
|
934
|
-
} else if (check.kind === "email") {
|
|
935
|
-
if (!emailRegex.test(input.data)) {
|
|
936
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
937
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
938
|
-
validation: "email",
|
|
939
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
940
|
-
message: check.message
|
|
941
|
-
});
|
|
942
|
-
status.dirty();
|
|
943
|
-
}
|
|
944
|
-
} else if (check.kind === "emoji") {
|
|
945
|
-
if (!emojiRegex) emojiRegex = new RegExp(_emojiRegex, "u");
|
|
946
|
-
if (!emojiRegex.test(input.data)) {
|
|
947
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
948
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
949
|
-
validation: "emoji",
|
|
950
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
951
|
-
message: check.message
|
|
952
|
-
});
|
|
953
|
-
status.dirty();
|
|
954
|
-
}
|
|
955
|
-
} else if (check.kind === "uuid") {
|
|
956
|
-
if (!uuidRegex.test(input.data)) {
|
|
957
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
958
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
959
|
-
validation: "uuid",
|
|
960
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
961
|
-
message: check.message
|
|
962
|
-
});
|
|
963
|
-
status.dirty();
|
|
964
|
-
}
|
|
965
|
-
} else if (check.kind === "nanoid") {
|
|
966
|
-
if (!nanoidRegex.test(input.data)) {
|
|
967
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
968
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
969
|
-
validation: "nanoid",
|
|
970
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
971
|
-
message: check.message
|
|
972
|
-
});
|
|
973
|
-
status.dirty();
|
|
974
|
-
}
|
|
975
|
-
} else if (check.kind === "cuid") {
|
|
976
|
-
if (!cuidRegex.test(input.data)) {
|
|
977
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
978
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
979
|
-
validation: "cuid",
|
|
980
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
981
|
-
message: check.message
|
|
982
|
-
});
|
|
983
|
-
status.dirty();
|
|
984
|
-
}
|
|
985
|
-
} else if (check.kind === "cuid2") {
|
|
986
|
-
if (!cuid2Regex.test(input.data)) {
|
|
987
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
988
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
989
|
-
validation: "cuid2",
|
|
990
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
991
|
-
message: check.message
|
|
992
|
-
});
|
|
993
|
-
status.dirty();
|
|
994
|
-
}
|
|
995
|
-
} else if (check.kind === "ulid") {
|
|
996
|
-
if (!ulidRegex.test(input.data)) {
|
|
997
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
998
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
999
|
-
validation: "ulid",
|
|
1000
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
1001
|
-
message: check.message
|
|
1002
|
-
});
|
|
1003
|
-
status.dirty();
|
|
1004
|
-
}
|
|
1005
|
-
} else if (check.kind === "url") try {
|
|
1006
|
-
new URL(input.data);
|
|
1007
|
-
} catch {
|
|
1008
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1009
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1010
|
-
validation: "url",
|
|
1011
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
1012
|
-
message: check.message
|
|
1013
|
-
});
|
|
1014
|
-
status.dirty();
|
|
1015
|
-
}
|
|
1016
|
-
else if (check.kind === "regex") {
|
|
1017
|
-
check.regex.lastIndex = 0;
|
|
1018
|
-
if (!check.regex.test(input.data)) {
|
|
1019
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1020
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1021
|
-
validation: "regex",
|
|
1022
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
1023
|
-
message: check.message
|
|
1024
|
-
});
|
|
1025
|
-
status.dirty();
|
|
1026
|
-
}
|
|
1027
|
-
} else if (check.kind === "trim") input.data = input.data.trim();
|
|
1028
|
-
else if (check.kind === "includes") {
|
|
1029
|
-
if (!input.data.includes(check.value, check.position)) {
|
|
1030
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1031
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1032
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
1033
|
-
validation: {
|
|
1034
|
-
includes: check.value,
|
|
1035
|
-
position: check.position
|
|
1036
|
-
},
|
|
1037
|
-
message: check.message
|
|
1038
|
-
});
|
|
1039
|
-
status.dirty();
|
|
1040
|
-
}
|
|
1041
|
-
} else if (check.kind === "toLowerCase") input.data = input.data.toLowerCase();
|
|
1042
|
-
else if (check.kind === "toUpperCase") input.data = input.data.toUpperCase();
|
|
1043
|
-
else if (check.kind === "startsWith") {
|
|
1044
|
-
if (!input.data.startsWith(check.value)) {
|
|
1045
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1046
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1047
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
1048
|
-
validation: { startsWith: check.value },
|
|
1049
|
-
message: check.message
|
|
1050
|
-
});
|
|
1051
|
-
status.dirty();
|
|
1052
|
-
}
|
|
1053
|
-
} else if (check.kind === "endsWith") {
|
|
1054
|
-
if (!input.data.endsWith(check.value)) {
|
|
1055
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1056
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1057
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
1058
|
-
validation: { endsWith: check.value },
|
|
1059
|
-
message: check.message
|
|
1060
|
-
});
|
|
1061
|
-
status.dirty();
|
|
1062
|
-
}
|
|
1063
|
-
} else if (check.kind === "datetime") {
|
|
1064
|
-
if (!datetimeRegex(check).test(input.data)) {
|
|
1065
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1066
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1067
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
1068
|
-
validation: "datetime",
|
|
1069
|
-
message: check.message
|
|
1070
|
-
});
|
|
1071
|
-
status.dirty();
|
|
1072
|
-
}
|
|
1073
|
-
} else if (check.kind === "date") {
|
|
1074
|
-
if (!dateRegex.test(input.data)) {
|
|
1075
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1076
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1077
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
1078
|
-
validation: "date",
|
|
1079
|
-
message: check.message
|
|
1080
|
-
});
|
|
1081
|
-
status.dirty();
|
|
1082
|
-
}
|
|
1083
|
-
} else if (check.kind === "time") {
|
|
1084
|
-
if (!timeRegex(check).test(input.data)) {
|
|
1085
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1086
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1087
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
1088
|
-
validation: "time",
|
|
1089
|
-
message: check.message
|
|
1090
|
-
});
|
|
1091
|
-
status.dirty();
|
|
1092
|
-
}
|
|
1093
|
-
} else if (check.kind === "duration") {
|
|
1094
|
-
if (!durationRegex.test(input.data)) {
|
|
1095
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1096
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1097
|
-
validation: "duration",
|
|
1098
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
1099
|
-
message: check.message
|
|
1100
|
-
});
|
|
1101
|
-
status.dirty();
|
|
1102
|
-
}
|
|
1103
|
-
} else if (check.kind === "ip") {
|
|
1104
|
-
if (!isValidIP(input.data, check.version)) {
|
|
1105
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1106
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1107
|
-
validation: "ip",
|
|
1108
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
1109
|
-
message: check.message
|
|
1110
|
-
});
|
|
1111
|
-
status.dirty();
|
|
1112
|
-
}
|
|
1113
|
-
} else if (check.kind === "jwt") {
|
|
1114
|
-
if (!isValidJWT(input.data, check.alg)) {
|
|
1115
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1116
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1117
|
-
validation: "jwt",
|
|
1118
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
1119
|
-
message: check.message
|
|
1120
|
-
});
|
|
1121
|
-
status.dirty();
|
|
1122
|
-
}
|
|
1123
|
-
} else if (check.kind === "cidr") {
|
|
1124
|
-
if (!isValidCidr(input.data, check.version)) {
|
|
1125
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1126
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1127
|
-
validation: "cidr",
|
|
1128
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
1129
|
-
message: check.message
|
|
1130
|
-
});
|
|
1131
|
-
status.dirty();
|
|
1132
|
-
}
|
|
1133
|
-
} else if (check.kind === "base64") {
|
|
1134
|
-
if (!base64Regex.test(input.data)) {
|
|
1135
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1136
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1137
|
-
validation: "base64",
|
|
1138
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
1139
|
-
message: check.message
|
|
1140
|
-
});
|
|
1141
|
-
status.dirty();
|
|
1142
|
-
}
|
|
1143
|
-
} else if (check.kind === "base64url") {
|
|
1144
|
-
if (!base64urlRegex.test(input.data)) {
|
|
1145
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1146
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1147
|
-
validation: "base64url",
|
|
1148
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
1149
|
-
message: check.message
|
|
1150
|
-
});
|
|
1151
|
-
status.dirty();
|
|
1152
|
-
}
|
|
1153
|
-
} else util_js_1.util.assertNever(check);
|
|
1154
|
-
return {
|
|
1155
|
-
status: status.value,
|
|
1156
|
-
value: input.data
|
|
1157
|
-
};
|
|
1158
|
-
}
|
|
1159
|
-
_regex(regex, validation, message) {
|
|
1160
|
-
return this.refinement((data) => regex.test(data), {
|
|
1161
|
-
validation,
|
|
1162
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
|
1163
|
-
...errorUtil_js_1.errorUtil.errToObj(message)
|
|
1164
|
-
});
|
|
1165
|
-
}
|
|
1166
|
-
_addCheck(check) {
|
|
1167
|
-
return new ZodString({
|
|
1168
|
-
...this._def,
|
|
1169
|
-
checks: [...this._def.checks, check]
|
|
1170
|
-
});
|
|
1171
|
-
}
|
|
1172
|
-
email(message) {
|
|
1173
|
-
return this._addCheck({
|
|
1174
|
-
kind: "email",
|
|
1175
|
-
...errorUtil_js_1.errorUtil.errToObj(message)
|
|
1176
|
-
});
|
|
1177
|
-
}
|
|
1178
|
-
url(message) {
|
|
1179
|
-
return this._addCheck({
|
|
1180
|
-
kind: "url",
|
|
1181
|
-
...errorUtil_js_1.errorUtil.errToObj(message)
|
|
1182
|
-
});
|
|
1183
|
-
}
|
|
1184
|
-
emoji(message) {
|
|
1185
|
-
return this._addCheck({
|
|
1186
|
-
kind: "emoji",
|
|
1187
|
-
...errorUtil_js_1.errorUtil.errToObj(message)
|
|
1188
|
-
});
|
|
1189
|
-
}
|
|
1190
|
-
uuid(message) {
|
|
1191
|
-
return this._addCheck({
|
|
1192
|
-
kind: "uuid",
|
|
1193
|
-
...errorUtil_js_1.errorUtil.errToObj(message)
|
|
1194
|
-
});
|
|
1195
|
-
}
|
|
1196
|
-
nanoid(message) {
|
|
1197
|
-
return this._addCheck({
|
|
1198
|
-
kind: "nanoid",
|
|
1199
|
-
...errorUtil_js_1.errorUtil.errToObj(message)
|
|
1200
|
-
});
|
|
1201
|
-
}
|
|
1202
|
-
cuid(message) {
|
|
1203
|
-
return this._addCheck({
|
|
1204
|
-
kind: "cuid",
|
|
1205
|
-
...errorUtil_js_1.errorUtil.errToObj(message)
|
|
1206
|
-
});
|
|
1207
|
-
}
|
|
1208
|
-
cuid2(message) {
|
|
1209
|
-
return this._addCheck({
|
|
1210
|
-
kind: "cuid2",
|
|
1211
|
-
...errorUtil_js_1.errorUtil.errToObj(message)
|
|
1212
|
-
});
|
|
1213
|
-
}
|
|
1214
|
-
ulid(message) {
|
|
1215
|
-
return this._addCheck({
|
|
1216
|
-
kind: "ulid",
|
|
1217
|
-
...errorUtil_js_1.errorUtil.errToObj(message)
|
|
1218
|
-
});
|
|
1219
|
-
}
|
|
1220
|
-
base64(message) {
|
|
1221
|
-
return this._addCheck({
|
|
1222
|
-
kind: "base64",
|
|
1223
|
-
...errorUtil_js_1.errorUtil.errToObj(message)
|
|
1224
|
-
});
|
|
1225
|
-
}
|
|
1226
|
-
base64url(message) {
|
|
1227
|
-
return this._addCheck({
|
|
1228
|
-
kind: "base64url",
|
|
1229
|
-
...errorUtil_js_1.errorUtil.errToObj(message)
|
|
1230
|
-
});
|
|
1231
|
-
}
|
|
1232
|
-
jwt(options) {
|
|
1233
|
-
return this._addCheck({
|
|
1234
|
-
kind: "jwt",
|
|
1235
|
-
...errorUtil_js_1.errorUtil.errToObj(options)
|
|
1236
|
-
});
|
|
1237
|
-
}
|
|
1238
|
-
ip(options) {
|
|
1239
|
-
return this._addCheck({
|
|
1240
|
-
kind: "ip",
|
|
1241
|
-
...errorUtil_js_1.errorUtil.errToObj(options)
|
|
1242
|
-
});
|
|
1243
|
-
}
|
|
1244
|
-
cidr(options) {
|
|
1245
|
-
return this._addCheck({
|
|
1246
|
-
kind: "cidr",
|
|
1247
|
-
...errorUtil_js_1.errorUtil.errToObj(options)
|
|
1248
|
-
});
|
|
1249
|
-
}
|
|
1250
|
-
datetime(options) {
|
|
1251
|
-
if (typeof options === "string") return this._addCheck({
|
|
1252
|
-
kind: "datetime",
|
|
1253
|
-
precision: null,
|
|
1254
|
-
offset: false,
|
|
1255
|
-
local: false,
|
|
1256
|
-
message: options
|
|
1257
|
-
});
|
|
1258
|
-
return this._addCheck({
|
|
1259
|
-
kind: "datetime",
|
|
1260
|
-
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1261
|
-
offset: options?.offset ?? false,
|
|
1262
|
-
local: options?.local ?? false,
|
|
1263
|
-
...errorUtil_js_1.errorUtil.errToObj(options?.message)
|
|
1264
|
-
});
|
|
1265
|
-
}
|
|
1266
|
-
date(message) {
|
|
1267
|
-
return this._addCheck({
|
|
1268
|
-
kind: "date",
|
|
1269
|
-
message
|
|
1270
|
-
});
|
|
1271
|
-
}
|
|
1272
|
-
time(options) {
|
|
1273
|
-
if (typeof options === "string") return this._addCheck({
|
|
1274
|
-
kind: "time",
|
|
1275
|
-
precision: null,
|
|
1276
|
-
message: options
|
|
1277
|
-
});
|
|
1278
|
-
return this._addCheck({
|
|
1279
|
-
kind: "time",
|
|
1280
|
-
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1281
|
-
...errorUtil_js_1.errorUtil.errToObj(options?.message)
|
|
1282
|
-
});
|
|
1283
|
-
}
|
|
1284
|
-
duration(message) {
|
|
1285
|
-
return this._addCheck({
|
|
1286
|
-
kind: "duration",
|
|
1287
|
-
...errorUtil_js_1.errorUtil.errToObj(message)
|
|
1288
|
-
});
|
|
1289
|
-
}
|
|
1290
|
-
regex(regex, message) {
|
|
1291
|
-
return this._addCheck({
|
|
1292
|
-
kind: "regex",
|
|
1293
|
-
regex,
|
|
1294
|
-
...errorUtil_js_1.errorUtil.errToObj(message)
|
|
1295
|
-
});
|
|
1296
|
-
}
|
|
1297
|
-
includes(value, options) {
|
|
1298
|
-
return this._addCheck({
|
|
1299
|
-
kind: "includes",
|
|
1300
|
-
value,
|
|
1301
|
-
position: options?.position,
|
|
1302
|
-
...errorUtil_js_1.errorUtil.errToObj(options?.message)
|
|
1303
|
-
});
|
|
1304
|
-
}
|
|
1305
|
-
startsWith(value, message) {
|
|
1306
|
-
return this._addCheck({
|
|
1307
|
-
kind: "startsWith",
|
|
1308
|
-
value,
|
|
1309
|
-
...errorUtil_js_1.errorUtil.errToObj(message)
|
|
1310
|
-
});
|
|
1311
|
-
}
|
|
1312
|
-
endsWith(value, message) {
|
|
1313
|
-
return this._addCheck({
|
|
1314
|
-
kind: "endsWith",
|
|
1315
|
-
value,
|
|
1316
|
-
...errorUtil_js_1.errorUtil.errToObj(message)
|
|
1317
|
-
});
|
|
1318
|
-
}
|
|
1319
|
-
min(minLength, message) {
|
|
1320
|
-
return this._addCheck({
|
|
1321
|
-
kind: "min",
|
|
1322
|
-
value: minLength,
|
|
1323
|
-
...errorUtil_js_1.errorUtil.errToObj(message)
|
|
1324
|
-
});
|
|
1325
|
-
}
|
|
1326
|
-
max(maxLength, message) {
|
|
1327
|
-
return this._addCheck({
|
|
1328
|
-
kind: "max",
|
|
1329
|
-
value: maxLength,
|
|
1330
|
-
...errorUtil_js_1.errorUtil.errToObj(message)
|
|
1331
|
-
});
|
|
1332
|
-
}
|
|
1333
|
-
length(len, message) {
|
|
1334
|
-
return this._addCheck({
|
|
1335
|
-
kind: "length",
|
|
1336
|
-
value: len,
|
|
1337
|
-
...errorUtil_js_1.errorUtil.errToObj(message)
|
|
1338
|
-
});
|
|
1339
|
-
}
|
|
1340
|
-
/**
|
|
1341
|
-
* Equivalent to `.min(1)`
|
|
1342
|
-
*/
|
|
1343
|
-
nonempty(message) {
|
|
1344
|
-
return this.min(1, errorUtil_js_1.errorUtil.errToObj(message));
|
|
1345
|
-
}
|
|
1346
|
-
trim() {
|
|
1347
|
-
return new ZodString({
|
|
1348
|
-
...this._def,
|
|
1349
|
-
checks: [...this._def.checks, { kind: "trim" }]
|
|
1350
|
-
});
|
|
1351
|
-
}
|
|
1352
|
-
toLowerCase() {
|
|
1353
|
-
return new ZodString({
|
|
1354
|
-
...this._def,
|
|
1355
|
-
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
1356
|
-
});
|
|
1357
|
-
}
|
|
1358
|
-
toUpperCase() {
|
|
1359
|
-
return new ZodString({
|
|
1360
|
-
...this._def,
|
|
1361
|
-
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
1362
|
-
});
|
|
1363
|
-
}
|
|
1364
|
-
get isDatetime() {
|
|
1365
|
-
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
1366
|
-
}
|
|
1367
|
-
get isDate() {
|
|
1368
|
-
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
1369
|
-
}
|
|
1370
|
-
get isTime() {
|
|
1371
|
-
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
1372
|
-
}
|
|
1373
|
-
get isDuration() {
|
|
1374
|
-
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
1375
|
-
}
|
|
1376
|
-
get isEmail() {
|
|
1377
|
-
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
1378
|
-
}
|
|
1379
|
-
get isURL() {
|
|
1380
|
-
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
1381
|
-
}
|
|
1382
|
-
get isEmoji() {
|
|
1383
|
-
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
1384
|
-
}
|
|
1385
|
-
get isUUID() {
|
|
1386
|
-
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
1387
|
-
}
|
|
1388
|
-
get isNANOID() {
|
|
1389
|
-
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
1390
|
-
}
|
|
1391
|
-
get isCUID() {
|
|
1392
|
-
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
1393
|
-
}
|
|
1394
|
-
get isCUID2() {
|
|
1395
|
-
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
1396
|
-
}
|
|
1397
|
-
get isULID() {
|
|
1398
|
-
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
1399
|
-
}
|
|
1400
|
-
get isIP() {
|
|
1401
|
-
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1402
|
-
}
|
|
1403
|
-
get isCIDR() {
|
|
1404
|
-
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1405
|
-
}
|
|
1406
|
-
get isBase64() {
|
|
1407
|
-
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1408
|
-
}
|
|
1409
|
-
get isBase64url() {
|
|
1410
|
-
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1411
|
-
}
|
|
1412
|
-
get minLength() {
|
|
1413
|
-
let min = null;
|
|
1414
|
-
for (const ch of this._def.checks) if (ch.kind === "min") {
|
|
1415
|
-
if (min === null || ch.value > min) min = ch.value;
|
|
1416
|
-
}
|
|
1417
|
-
return min;
|
|
1418
|
-
}
|
|
1419
|
-
get maxLength() {
|
|
1420
|
-
let max = null;
|
|
1421
|
-
for (const ch of this._def.checks) if (ch.kind === "max") {
|
|
1422
|
-
if (max === null || ch.value < max) max = ch.value;
|
|
1423
|
-
}
|
|
1424
|
-
return max;
|
|
1425
|
-
}
|
|
1426
|
-
};
|
|
1427
|
-
exports.ZodString = ZodString;
|
|
1428
|
-
ZodString.create = (params) => {
|
|
1429
|
-
return new ZodString({
|
|
1430
|
-
checks: [],
|
|
1431
|
-
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
1432
|
-
coerce: params?.coerce ?? false,
|
|
1433
|
-
...processCreateParams(params)
|
|
1434
|
-
});
|
|
1435
|
-
};
|
|
1436
|
-
function floatSafeRemainder(val, step) {
|
|
1437
|
-
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
1438
|
-
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
1439
|
-
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
1440
|
-
return Number.parseInt(val.toFixed(decCount).replace(".", "")) % Number.parseInt(step.toFixed(decCount).replace(".", "")) / 10 ** decCount;
|
|
1441
|
-
}
|
|
1442
|
-
var ZodNumber = class ZodNumber extends ZodType {
|
|
1443
|
-
constructor() {
|
|
1444
|
-
super(...arguments);
|
|
1445
|
-
this.min = this.gte;
|
|
1446
|
-
this.max = this.lte;
|
|
1447
|
-
this.step = this.multipleOf;
|
|
1448
|
-
}
|
|
1449
|
-
_parse(input) {
|
|
1450
|
-
if (this._def.coerce) input.data = Number(input.data);
|
|
1451
|
-
if (this._getType(input) !== util_js_1.ZodParsedType.number) {
|
|
1452
|
-
const ctx = this._getOrReturnCtx(input);
|
|
1453
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1454
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
1455
|
-
expected: util_js_1.ZodParsedType.number,
|
|
1456
|
-
received: ctx.parsedType
|
|
1457
|
-
});
|
|
1458
|
-
return parseUtil_js_1.INVALID;
|
|
1459
|
-
}
|
|
1460
|
-
let ctx = void 0;
|
|
1461
|
-
const status = new parseUtil_js_1.ParseStatus();
|
|
1462
|
-
for (const check of this._def.checks) if (check.kind === "int") {
|
|
1463
|
-
if (!util_js_1.util.isInteger(input.data)) {
|
|
1464
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1465
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1466
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
1467
|
-
expected: "integer",
|
|
1468
|
-
received: "float",
|
|
1469
|
-
message: check.message
|
|
1470
|
-
});
|
|
1471
|
-
status.dirty();
|
|
1472
|
-
}
|
|
1473
|
-
} else if (check.kind === "min") {
|
|
1474
|
-
if (check.inclusive ? input.data < check.value : input.data <= check.value) {
|
|
1475
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1476
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1477
|
-
code: ZodError_js_1.ZodIssueCode.too_small,
|
|
1478
|
-
minimum: check.value,
|
|
1479
|
-
type: "number",
|
|
1480
|
-
inclusive: check.inclusive,
|
|
1481
|
-
exact: false,
|
|
1482
|
-
message: check.message
|
|
1483
|
-
});
|
|
1484
|
-
status.dirty();
|
|
1485
|
-
}
|
|
1486
|
-
} else if (check.kind === "max") {
|
|
1487
|
-
if (check.inclusive ? input.data > check.value : input.data >= check.value) {
|
|
1488
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1489
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1490
|
-
code: ZodError_js_1.ZodIssueCode.too_big,
|
|
1491
|
-
maximum: check.value,
|
|
1492
|
-
type: "number",
|
|
1493
|
-
inclusive: check.inclusive,
|
|
1494
|
-
exact: false,
|
|
1495
|
-
message: check.message
|
|
1496
|
-
});
|
|
1497
|
-
status.dirty();
|
|
1498
|
-
}
|
|
1499
|
-
} else if (check.kind === "multipleOf") {
|
|
1500
|
-
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
1501
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1502
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1503
|
-
code: ZodError_js_1.ZodIssueCode.not_multiple_of,
|
|
1504
|
-
multipleOf: check.value,
|
|
1505
|
-
message: check.message
|
|
1506
|
-
});
|
|
1507
|
-
status.dirty();
|
|
1508
|
-
}
|
|
1509
|
-
} else if (check.kind === "finite") {
|
|
1510
|
-
if (!Number.isFinite(input.data)) {
|
|
1511
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1512
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1513
|
-
code: ZodError_js_1.ZodIssueCode.not_finite,
|
|
1514
|
-
message: check.message
|
|
1515
|
-
});
|
|
1516
|
-
status.dirty();
|
|
1517
|
-
}
|
|
1518
|
-
} else util_js_1.util.assertNever(check);
|
|
1519
|
-
return {
|
|
1520
|
-
status: status.value,
|
|
1521
|
-
value: input.data
|
|
1522
|
-
};
|
|
1523
|
-
}
|
|
1524
|
-
gte(value, message) {
|
|
1525
|
-
return this.setLimit("min", value, true, errorUtil_js_1.errorUtil.toString(message));
|
|
1526
|
-
}
|
|
1527
|
-
gt(value, message) {
|
|
1528
|
-
return this.setLimit("min", value, false, errorUtil_js_1.errorUtil.toString(message));
|
|
1529
|
-
}
|
|
1530
|
-
lte(value, message) {
|
|
1531
|
-
return this.setLimit("max", value, true, errorUtil_js_1.errorUtil.toString(message));
|
|
1532
|
-
}
|
|
1533
|
-
lt(value, message) {
|
|
1534
|
-
return this.setLimit("max", value, false, errorUtil_js_1.errorUtil.toString(message));
|
|
1535
|
-
}
|
|
1536
|
-
setLimit(kind, value, inclusive, message) {
|
|
1537
|
-
return new ZodNumber({
|
|
1538
|
-
...this._def,
|
|
1539
|
-
checks: [...this._def.checks, {
|
|
1540
|
-
kind,
|
|
1541
|
-
value,
|
|
1542
|
-
inclusive,
|
|
1543
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
1544
|
-
}]
|
|
1545
|
-
});
|
|
1546
|
-
}
|
|
1547
|
-
_addCheck(check) {
|
|
1548
|
-
return new ZodNumber({
|
|
1549
|
-
...this._def,
|
|
1550
|
-
checks: [...this._def.checks, check]
|
|
1551
|
-
});
|
|
1552
|
-
}
|
|
1553
|
-
int(message) {
|
|
1554
|
-
return this._addCheck({
|
|
1555
|
-
kind: "int",
|
|
1556
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
1557
|
-
});
|
|
1558
|
-
}
|
|
1559
|
-
positive(message) {
|
|
1560
|
-
return this._addCheck({
|
|
1561
|
-
kind: "min",
|
|
1562
|
-
value: 0,
|
|
1563
|
-
inclusive: false,
|
|
1564
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
1565
|
-
});
|
|
1566
|
-
}
|
|
1567
|
-
negative(message) {
|
|
1568
|
-
return this._addCheck({
|
|
1569
|
-
kind: "max",
|
|
1570
|
-
value: 0,
|
|
1571
|
-
inclusive: false,
|
|
1572
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
1573
|
-
});
|
|
1574
|
-
}
|
|
1575
|
-
nonpositive(message) {
|
|
1576
|
-
return this._addCheck({
|
|
1577
|
-
kind: "max",
|
|
1578
|
-
value: 0,
|
|
1579
|
-
inclusive: true,
|
|
1580
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
1581
|
-
});
|
|
1582
|
-
}
|
|
1583
|
-
nonnegative(message) {
|
|
1584
|
-
return this._addCheck({
|
|
1585
|
-
kind: "min",
|
|
1586
|
-
value: 0,
|
|
1587
|
-
inclusive: true,
|
|
1588
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
1589
|
-
});
|
|
1590
|
-
}
|
|
1591
|
-
multipleOf(value, message) {
|
|
1592
|
-
return this._addCheck({
|
|
1593
|
-
kind: "multipleOf",
|
|
1594
|
-
value,
|
|
1595
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
1596
|
-
});
|
|
1597
|
-
}
|
|
1598
|
-
finite(message) {
|
|
1599
|
-
return this._addCheck({
|
|
1600
|
-
kind: "finite",
|
|
1601
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
1602
|
-
});
|
|
1603
|
-
}
|
|
1604
|
-
safe(message) {
|
|
1605
|
-
return this._addCheck({
|
|
1606
|
-
kind: "min",
|
|
1607
|
-
inclusive: true,
|
|
1608
|
-
value: Number.MIN_SAFE_INTEGER,
|
|
1609
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
1610
|
-
})._addCheck({
|
|
1611
|
-
kind: "max",
|
|
1612
|
-
inclusive: true,
|
|
1613
|
-
value: Number.MAX_SAFE_INTEGER,
|
|
1614
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
1615
|
-
});
|
|
1616
|
-
}
|
|
1617
|
-
get minValue() {
|
|
1618
|
-
let min = null;
|
|
1619
|
-
for (const ch of this._def.checks) if (ch.kind === "min") {
|
|
1620
|
-
if (min === null || ch.value > min) min = ch.value;
|
|
1621
|
-
}
|
|
1622
|
-
return min;
|
|
1623
|
-
}
|
|
1624
|
-
get maxValue() {
|
|
1625
|
-
let max = null;
|
|
1626
|
-
for (const ch of this._def.checks) if (ch.kind === "max") {
|
|
1627
|
-
if (max === null || ch.value < max) max = ch.value;
|
|
1628
|
-
}
|
|
1629
|
-
return max;
|
|
1630
|
-
}
|
|
1631
|
-
get isInt() {
|
|
1632
|
-
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util_js_1.util.isInteger(ch.value));
|
|
1633
|
-
}
|
|
1634
|
-
get isFinite() {
|
|
1635
|
-
let max = null;
|
|
1636
|
-
let min = null;
|
|
1637
|
-
for (const ch of this._def.checks) if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") return true;
|
|
1638
|
-
else if (ch.kind === "min") {
|
|
1639
|
-
if (min === null || ch.value > min) min = ch.value;
|
|
1640
|
-
} else if (ch.kind === "max") {
|
|
1641
|
-
if (max === null || ch.value < max) max = ch.value;
|
|
1642
|
-
}
|
|
1643
|
-
return Number.isFinite(min) && Number.isFinite(max);
|
|
1644
|
-
}
|
|
1645
|
-
};
|
|
1646
|
-
exports.ZodNumber = ZodNumber;
|
|
1647
|
-
ZodNumber.create = (params) => {
|
|
1648
|
-
return new ZodNumber({
|
|
1649
|
-
checks: [],
|
|
1650
|
-
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
1651
|
-
coerce: params?.coerce || false,
|
|
1652
|
-
...processCreateParams(params)
|
|
1653
|
-
});
|
|
1654
|
-
};
|
|
1655
|
-
var ZodBigInt = class ZodBigInt extends ZodType {
|
|
1656
|
-
constructor() {
|
|
1657
|
-
super(...arguments);
|
|
1658
|
-
this.min = this.gte;
|
|
1659
|
-
this.max = this.lte;
|
|
1660
|
-
}
|
|
1661
|
-
_parse(input) {
|
|
1662
|
-
if (this._def.coerce) try {
|
|
1663
|
-
input.data = BigInt(input.data);
|
|
1664
|
-
} catch {
|
|
1665
|
-
return this._getInvalidInput(input);
|
|
1666
|
-
}
|
|
1667
|
-
if (this._getType(input) !== util_js_1.ZodParsedType.bigint) return this._getInvalidInput(input);
|
|
1668
|
-
let ctx = void 0;
|
|
1669
|
-
const status = new parseUtil_js_1.ParseStatus();
|
|
1670
|
-
for (const check of this._def.checks) if (check.kind === "min") {
|
|
1671
|
-
if (check.inclusive ? input.data < check.value : input.data <= check.value) {
|
|
1672
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1673
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1674
|
-
code: ZodError_js_1.ZodIssueCode.too_small,
|
|
1675
|
-
type: "bigint",
|
|
1676
|
-
minimum: check.value,
|
|
1677
|
-
inclusive: check.inclusive,
|
|
1678
|
-
message: check.message
|
|
1679
|
-
});
|
|
1680
|
-
status.dirty();
|
|
1681
|
-
}
|
|
1682
|
-
} else if (check.kind === "max") {
|
|
1683
|
-
if (check.inclusive ? input.data > check.value : input.data >= check.value) {
|
|
1684
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1685
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1686
|
-
code: ZodError_js_1.ZodIssueCode.too_big,
|
|
1687
|
-
type: "bigint",
|
|
1688
|
-
maximum: check.value,
|
|
1689
|
-
inclusive: check.inclusive,
|
|
1690
|
-
message: check.message
|
|
1691
|
-
});
|
|
1692
|
-
status.dirty();
|
|
1693
|
-
}
|
|
1694
|
-
} else if (check.kind === "multipleOf") {
|
|
1695
|
-
if (input.data % check.value !== BigInt(0)) {
|
|
1696
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1697
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1698
|
-
code: ZodError_js_1.ZodIssueCode.not_multiple_of,
|
|
1699
|
-
multipleOf: check.value,
|
|
1700
|
-
message: check.message
|
|
1701
|
-
});
|
|
1702
|
-
status.dirty();
|
|
1703
|
-
}
|
|
1704
|
-
} else util_js_1.util.assertNever(check);
|
|
1705
|
-
return {
|
|
1706
|
-
status: status.value,
|
|
1707
|
-
value: input.data
|
|
1708
|
-
};
|
|
1709
|
-
}
|
|
1710
|
-
_getInvalidInput(input) {
|
|
1711
|
-
const ctx = this._getOrReturnCtx(input);
|
|
1712
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1713
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
1714
|
-
expected: util_js_1.ZodParsedType.bigint,
|
|
1715
|
-
received: ctx.parsedType
|
|
1716
|
-
});
|
|
1717
|
-
return parseUtil_js_1.INVALID;
|
|
1718
|
-
}
|
|
1719
|
-
gte(value, message) {
|
|
1720
|
-
return this.setLimit("min", value, true, errorUtil_js_1.errorUtil.toString(message));
|
|
1721
|
-
}
|
|
1722
|
-
gt(value, message) {
|
|
1723
|
-
return this.setLimit("min", value, false, errorUtil_js_1.errorUtil.toString(message));
|
|
1724
|
-
}
|
|
1725
|
-
lte(value, message) {
|
|
1726
|
-
return this.setLimit("max", value, true, errorUtil_js_1.errorUtil.toString(message));
|
|
1727
|
-
}
|
|
1728
|
-
lt(value, message) {
|
|
1729
|
-
return this.setLimit("max", value, false, errorUtil_js_1.errorUtil.toString(message));
|
|
1730
|
-
}
|
|
1731
|
-
setLimit(kind, value, inclusive, message) {
|
|
1732
|
-
return new ZodBigInt({
|
|
1733
|
-
...this._def,
|
|
1734
|
-
checks: [...this._def.checks, {
|
|
1735
|
-
kind,
|
|
1736
|
-
value,
|
|
1737
|
-
inclusive,
|
|
1738
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
1739
|
-
}]
|
|
1740
|
-
});
|
|
1741
|
-
}
|
|
1742
|
-
_addCheck(check) {
|
|
1743
|
-
return new ZodBigInt({
|
|
1744
|
-
...this._def,
|
|
1745
|
-
checks: [...this._def.checks, check]
|
|
1746
|
-
});
|
|
1747
|
-
}
|
|
1748
|
-
positive(message) {
|
|
1749
|
-
return this._addCheck({
|
|
1750
|
-
kind: "min",
|
|
1751
|
-
value: BigInt(0),
|
|
1752
|
-
inclusive: false,
|
|
1753
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
1754
|
-
});
|
|
1755
|
-
}
|
|
1756
|
-
negative(message) {
|
|
1757
|
-
return this._addCheck({
|
|
1758
|
-
kind: "max",
|
|
1759
|
-
value: BigInt(0),
|
|
1760
|
-
inclusive: false,
|
|
1761
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
1762
|
-
});
|
|
1763
|
-
}
|
|
1764
|
-
nonpositive(message) {
|
|
1765
|
-
return this._addCheck({
|
|
1766
|
-
kind: "max",
|
|
1767
|
-
value: BigInt(0),
|
|
1768
|
-
inclusive: true,
|
|
1769
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
1770
|
-
});
|
|
1771
|
-
}
|
|
1772
|
-
nonnegative(message) {
|
|
1773
|
-
return this._addCheck({
|
|
1774
|
-
kind: "min",
|
|
1775
|
-
value: BigInt(0),
|
|
1776
|
-
inclusive: true,
|
|
1777
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
1778
|
-
});
|
|
1779
|
-
}
|
|
1780
|
-
multipleOf(value, message) {
|
|
1781
|
-
return this._addCheck({
|
|
1782
|
-
kind: "multipleOf",
|
|
1783
|
-
value,
|
|
1784
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
1785
|
-
});
|
|
1786
|
-
}
|
|
1787
|
-
get minValue() {
|
|
1788
|
-
let min = null;
|
|
1789
|
-
for (const ch of this._def.checks) if (ch.kind === "min") {
|
|
1790
|
-
if (min === null || ch.value > min) min = ch.value;
|
|
1791
|
-
}
|
|
1792
|
-
return min;
|
|
1793
|
-
}
|
|
1794
|
-
get maxValue() {
|
|
1795
|
-
let max = null;
|
|
1796
|
-
for (const ch of this._def.checks) if (ch.kind === "max") {
|
|
1797
|
-
if (max === null || ch.value < max) max = ch.value;
|
|
1798
|
-
}
|
|
1799
|
-
return max;
|
|
1800
|
-
}
|
|
1801
|
-
};
|
|
1802
|
-
exports.ZodBigInt = ZodBigInt;
|
|
1803
|
-
ZodBigInt.create = (params) => {
|
|
1804
|
-
return new ZodBigInt({
|
|
1805
|
-
checks: [],
|
|
1806
|
-
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
1807
|
-
coerce: params?.coerce ?? false,
|
|
1808
|
-
...processCreateParams(params)
|
|
1809
|
-
});
|
|
1810
|
-
};
|
|
1811
|
-
var ZodBoolean = class extends ZodType {
|
|
1812
|
-
_parse(input) {
|
|
1813
|
-
if (this._def.coerce) input.data = Boolean(input.data);
|
|
1814
|
-
if (this._getType(input) !== util_js_1.ZodParsedType.boolean) {
|
|
1815
|
-
const ctx = this._getOrReturnCtx(input);
|
|
1816
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1817
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
1818
|
-
expected: util_js_1.ZodParsedType.boolean,
|
|
1819
|
-
received: ctx.parsedType
|
|
1820
|
-
});
|
|
1821
|
-
return parseUtil_js_1.INVALID;
|
|
1822
|
-
}
|
|
1823
|
-
return (0, parseUtil_js_1.OK)(input.data);
|
|
1824
|
-
}
|
|
1825
|
-
};
|
|
1826
|
-
exports.ZodBoolean = ZodBoolean;
|
|
1827
|
-
ZodBoolean.create = (params) => {
|
|
1828
|
-
return new ZodBoolean({
|
|
1829
|
-
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
1830
|
-
coerce: params?.coerce || false,
|
|
1831
|
-
...processCreateParams(params)
|
|
1832
|
-
});
|
|
1833
|
-
};
|
|
1834
|
-
var ZodDate = class ZodDate extends ZodType {
|
|
1835
|
-
_parse(input) {
|
|
1836
|
-
if (this._def.coerce) input.data = new Date(input.data);
|
|
1837
|
-
if (this._getType(input) !== util_js_1.ZodParsedType.date) {
|
|
1838
|
-
const ctx = this._getOrReturnCtx(input);
|
|
1839
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1840
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
1841
|
-
expected: util_js_1.ZodParsedType.date,
|
|
1842
|
-
received: ctx.parsedType
|
|
1843
|
-
});
|
|
1844
|
-
return parseUtil_js_1.INVALID;
|
|
1845
|
-
}
|
|
1846
|
-
if (Number.isNaN(input.data.getTime())) {
|
|
1847
|
-
const ctx = this._getOrReturnCtx(input);
|
|
1848
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, { code: ZodError_js_1.ZodIssueCode.invalid_date });
|
|
1849
|
-
return parseUtil_js_1.INVALID;
|
|
1850
|
-
}
|
|
1851
|
-
const status = new parseUtil_js_1.ParseStatus();
|
|
1852
|
-
let ctx = void 0;
|
|
1853
|
-
for (const check of this._def.checks) if (check.kind === "min") {
|
|
1854
|
-
if (input.data.getTime() < check.value) {
|
|
1855
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1856
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1857
|
-
code: ZodError_js_1.ZodIssueCode.too_small,
|
|
1858
|
-
message: check.message,
|
|
1859
|
-
inclusive: true,
|
|
1860
|
-
exact: false,
|
|
1861
|
-
minimum: check.value,
|
|
1862
|
-
type: "date"
|
|
1863
|
-
});
|
|
1864
|
-
status.dirty();
|
|
1865
|
-
}
|
|
1866
|
-
} else if (check.kind === "max") {
|
|
1867
|
-
if (input.data.getTime() > check.value) {
|
|
1868
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1869
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1870
|
-
code: ZodError_js_1.ZodIssueCode.too_big,
|
|
1871
|
-
message: check.message,
|
|
1872
|
-
inclusive: true,
|
|
1873
|
-
exact: false,
|
|
1874
|
-
maximum: check.value,
|
|
1875
|
-
type: "date"
|
|
1876
|
-
});
|
|
1877
|
-
status.dirty();
|
|
1878
|
-
}
|
|
1879
|
-
} else util_js_1.util.assertNever(check);
|
|
1880
|
-
return {
|
|
1881
|
-
status: status.value,
|
|
1882
|
-
value: new Date(input.data.getTime())
|
|
1883
|
-
};
|
|
1884
|
-
}
|
|
1885
|
-
_addCheck(check) {
|
|
1886
|
-
return new ZodDate({
|
|
1887
|
-
...this._def,
|
|
1888
|
-
checks: [...this._def.checks, check]
|
|
1889
|
-
});
|
|
1890
|
-
}
|
|
1891
|
-
min(minDate, message) {
|
|
1892
|
-
return this._addCheck({
|
|
1893
|
-
kind: "min",
|
|
1894
|
-
value: minDate.getTime(),
|
|
1895
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
1896
|
-
});
|
|
1897
|
-
}
|
|
1898
|
-
max(maxDate, message) {
|
|
1899
|
-
return this._addCheck({
|
|
1900
|
-
kind: "max",
|
|
1901
|
-
value: maxDate.getTime(),
|
|
1902
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
1903
|
-
});
|
|
1904
|
-
}
|
|
1905
|
-
get minDate() {
|
|
1906
|
-
let min = null;
|
|
1907
|
-
for (const ch of this._def.checks) if (ch.kind === "min") {
|
|
1908
|
-
if (min === null || ch.value > min) min = ch.value;
|
|
1909
|
-
}
|
|
1910
|
-
return min != null ? new Date(min) : null;
|
|
1911
|
-
}
|
|
1912
|
-
get maxDate() {
|
|
1913
|
-
let max = null;
|
|
1914
|
-
for (const ch of this._def.checks) if (ch.kind === "max") {
|
|
1915
|
-
if (max === null || ch.value < max) max = ch.value;
|
|
1916
|
-
}
|
|
1917
|
-
return max != null ? new Date(max) : null;
|
|
1918
|
-
}
|
|
1919
|
-
};
|
|
1920
|
-
exports.ZodDate = ZodDate;
|
|
1921
|
-
ZodDate.create = (params) => {
|
|
1922
|
-
return new ZodDate({
|
|
1923
|
-
checks: [],
|
|
1924
|
-
coerce: params?.coerce || false,
|
|
1925
|
-
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
1926
|
-
...processCreateParams(params)
|
|
1927
|
-
});
|
|
1928
|
-
};
|
|
1929
|
-
var ZodSymbol = class extends ZodType {
|
|
1930
|
-
_parse(input) {
|
|
1931
|
-
if (this._getType(input) !== util_js_1.ZodParsedType.symbol) {
|
|
1932
|
-
const ctx = this._getOrReturnCtx(input);
|
|
1933
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1934
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
1935
|
-
expected: util_js_1.ZodParsedType.symbol,
|
|
1936
|
-
received: ctx.parsedType
|
|
1937
|
-
});
|
|
1938
|
-
return parseUtil_js_1.INVALID;
|
|
1939
|
-
}
|
|
1940
|
-
return (0, parseUtil_js_1.OK)(input.data);
|
|
1941
|
-
}
|
|
1942
|
-
};
|
|
1943
|
-
exports.ZodSymbol = ZodSymbol;
|
|
1944
|
-
ZodSymbol.create = (params) => {
|
|
1945
|
-
return new ZodSymbol({
|
|
1946
|
-
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
1947
|
-
...processCreateParams(params)
|
|
1948
|
-
});
|
|
1949
|
-
};
|
|
1950
|
-
var ZodUndefined = class extends ZodType {
|
|
1951
|
-
_parse(input) {
|
|
1952
|
-
if (this._getType(input) !== util_js_1.ZodParsedType.undefined) {
|
|
1953
|
-
const ctx = this._getOrReturnCtx(input);
|
|
1954
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1955
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
1956
|
-
expected: util_js_1.ZodParsedType.undefined,
|
|
1957
|
-
received: ctx.parsedType
|
|
1958
|
-
});
|
|
1959
|
-
return parseUtil_js_1.INVALID;
|
|
1960
|
-
}
|
|
1961
|
-
return (0, parseUtil_js_1.OK)(input.data);
|
|
1962
|
-
}
|
|
1963
|
-
};
|
|
1964
|
-
exports.ZodUndefined = ZodUndefined;
|
|
1965
|
-
ZodUndefined.create = (params) => {
|
|
1966
|
-
return new ZodUndefined({
|
|
1967
|
-
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
1968
|
-
...processCreateParams(params)
|
|
1969
|
-
});
|
|
1970
|
-
};
|
|
1971
|
-
var ZodNull = class extends ZodType {
|
|
1972
|
-
_parse(input) {
|
|
1973
|
-
if (this._getType(input) !== util_js_1.ZodParsedType.null) {
|
|
1974
|
-
const ctx = this._getOrReturnCtx(input);
|
|
1975
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
1976
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
1977
|
-
expected: util_js_1.ZodParsedType.null,
|
|
1978
|
-
received: ctx.parsedType
|
|
1979
|
-
});
|
|
1980
|
-
return parseUtil_js_1.INVALID;
|
|
1981
|
-
}
|
|
1982
|
-
return (0, parseUtil_js_1.OK)(input.data);
|
|
1983
|
-
}
|
|
1984
|
-
};
|
|
1985
|
-
exports.ZodNull = ZodNull;
|
|
1986
|
-
ZodNull.create = (params) => {
|
|
1987
|
-
return new ZodNull({
|
|
1988
|
-
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
1989
|
-
...processCreateParams(params)
|
|
1990
|
-
});
|
|
1991
|
-
};
|
|
1992
|
-
var ZodAny = class extends ZodType {
|
|
1993
|
-
constructor() {
|
|
1994
|
-
super(...arguments);
|
|
1995
|
-
this._any = true;
|
|
1996
|
-
}
|
|
1997
|
-
_parse(input) {
|
|
1998
|
-
return (0, parseUtil_js_1.OK)(input.data);
|
|
1999
|
-
}
|
|
2000
|
-
};
|
|
2001
|
-
exports.ZodAny = ZodAny;
|
|
2002
|
-
ZodAny.create = (params) => {
|
|
2003
|
-
return new ZodAny({
|
|
2004
|
-
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
2005
|
-
...processCreateParams(params)
|
|
2006
|
-
});
|
|
2007
|
-
};
|
|
2008
|
-
var ZodUnknown = class extends ZodType {
|
|
2009
|
-
constructor() {
|
|
2010
|
-
super(...arguments);
|
|
2011
|
-
this._unknown = true;
|
|
2012
|
-
}
|
|
2013
|
-
_parse(input) {
|
|
2014
|
-
return (0, parseUtil_js_1.OK)(input.data);
|
|
2015
|
-
}
|
|
2016
|
-
};
|
|
2017
|
-
exports.ZodUnknown = ZodUnknown;
|
|
2018
|
-
ZodUnknown.create = (params) => {
|
|
2019
|
-
return new ZodUnknown({
|
|
2020
|
-
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
2021
|
-
...processCreateParams(params)
|
|
2022
|
-
});
|
|
2023
|
-
};
|
|
2024
|
-
var ZodNever = class extends ZodType {
|
|
2025
|
-
_parse(input) {
|
|
2026
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2027
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2028
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
2029
|
-
expected: util_js_1.ZodParsedType.never,
|
|
2030
|
-
received: ctx.parsedType
|
|
2031
|
-
});
|
|
2032
|
-
return parseUtil_js_1.INVALID;
|
|
2033
|
-
}
|
|
2034
|
-
};
|
|
2035
|
-
exports.ZodNever = ZodNever;
|
|
2036
|
-
ZodNever.create = (params) => {
|
|
2037
|
-
return new ZodNever({
|
|
2038
|
-
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
2039
|
-
...processCreateParams(params)
|
|
2040
|
-
});
|
|
2041
|
-
};
|
|
2042
|
-
var ZodVoid = class extends ZodType {
|
|
2043
|
-
_parse(input) {
|
|
2044
|
-
if (this._getType(input) !== util_js_1.ZodParsedType.undefined) {
|
|
2045
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2046
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2047
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
2048
|
-
expected: util_js_1.ZodParsedType.void,
|
|
2049
|
-
received: ctx.parsedType
|
|
2050
|
-
});
|
|
2051
|
-
return parseUtil_js_1.INVALID;
|
|
2052
|
-
}
|
|
2053
|
-
return (0, parseUtil_js_1.OK)(input.data);
|
|
2054
|
-
}
|
|
2055
|
-
};
|
|
2056
|
-
exports.ZodVoid = ZodVoid;
|
|
2057
|
-
ZodVoid.create = (params) => {
|
|
2058
|
-
return new ZodVoid({
|
|
2059
|
-
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
2060
|
-
...processCreateParams(params)
|
|
2061
|
-
});
|
|
2062
|
-
};
|
|
2063
|
-
var ZodArray = class ZodArray extends ZodType {
|
|
2064
|
-
_parse(input) {
|
|
2065
|
-
const { ctx, status } = this._processInputParams(input);
|
|
2066
|
-
const def = this._def;
|
|
2067
|
-
if (ctx.parsedType !== util_js_1.ZodParsedType.array) {
|
|
2068
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2069
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
2070
|
-
expected: util_js_1.ZodParsedType.array,
|
|
2071
|
-
received: ctx.parsedType
|
|
2072
|
-
});
|
|
2073
|
-
return parseUtil_js_1.INVALID;
|
|
2074
|
-
}
|
|
2075
|
-
if (def.exactLength !== null) {
|
|
2076
|
-
const tooBig = ctx.data.length > def.exactLength.value;
|
|
2077
|
-
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
2078
|
-
if (tooBig || tooSmall) {
|
|
2079
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2080
|
-
code: tooBig ? ZodError_js_1.ZodIssueCode.too_big : ZodError_js_1.ZodIssueCode.too_small,
|
|
2081
|
-
minimum: tooSmall ? def.exactLength.value : void 0,
|
|
2082
|
-
maximum: tooBig ? def.exactLength.value : void 0,
|
|
2083
|
-
type: "array",
|
|
2084
|
-
inclusive: true,
|
|
2085
|
-
exact: true,
|
|
2086
|
-
message: def.exactLength.message
|
|
2087
|
-
});
|
|
2088
|
-
status.dirty();
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
if (def.minLength !== null) {
|
|
2092
|
-
if (ctx.data.length < def.minLength.value) {
|
|
2093
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2094
|
-
code: ZodError_js_1.ZodIssueCode.too_small,
|
|
2095
|
-
minimum: def.minLength.value,
|
|
2096
|
-
type: "array",
|
|
2097
|
-
inclusive: true,
|
|
2098
|
-
exact: false,
|
|
2099
|
-
message: def.minLength.message
|
|
2100
|
-
});
|
|
2101
|
-
status.dirty();
|
|
2102
|
-
}
|
|
2103
|
-
}
|
|
2104
|
-
if (def.maxLength !== null) {
|
|
2105
|
-
if (ctx.data.length > def.maxLength.value) {
|
|
2106
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2107
|
-
code: ZodError_js_1.ZodIssueCode.too_big,
|
|
2108
|
-
maximum: def.maxLength.value,
|
|
2109
|
-
type: "array",
|
|
2110
|
-
inclusive: true,
|
|
2111
|
-
exact: false,
|
|
2112
|
-
message: def.maxLength.message
|
|
2113
|
-
});
|
|
2114
|
-
status.dirty();
|
|
2115
|
-
}
|
|
2116
|
-
}
|
|
2117
|
-
if (ctx.common.async) return Promise.all([...ctx.data].map((item, i) => {
|
|
2118
|
-
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2119
|
-
})).then((result) => {
|
|
2120
|
-
return parseUtil_js_1.ParseStatus.mergeArray(status, result);
|
|
2121
|
-
});
|
|
2122
|
-
const result = [...ctx.data].map((item, i) => {
|
|
2123
|
-
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2124
|
-
});
|
|
2125
|
-
return parseUtil_js_1.ParseStatus.mergeArray(status, result);
|
|
2126
|
-
}
|
|
2127
|
-
get element() {
|
|
2128
|
-
return this._def.type;
|
|
2129
|
-
}
|
|
2130
|
-
min(minLength, message) {
|
|
2131
|
-
return new ZodArray({
|
|
2132
|
-
...this._def,
|
|
2133
|
-
minLength: {
|
|
2134
|
-
value: minLength,
|
|
2135
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
2136
|
-
}
|
|
2137
|
-
});
|
|
2138
|
-
}
|
|
2139
|
-
max(maxLength, message) {
|
|
2140
|
-
return new ZodArray({
|
|
2141
|
-
...this._def,
|
|
2142
|
-
maxLength: {
|
|
2143
|
-
value: maxLength,
|
|
2144
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
2145
|
-
}
|
|
2146
|
-
});
|
|
2147
|
-
}
|
|
2148
|
-
length(len, message) {
|
|
2149
|
-
return new ZodArray({
|
|
2150
|
-
...this._def,
|
|
2151
|
-
exactLength: {
|
|
2152
|
-
value: len,
|
|
2153
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
2154
|
-
}
|
|
2155
|
-
});
|
|
2156
|
-
}
|
|
2157
|
-
nonempty(message) {
|
|
2158
|
-
return this.min(1, message);
|
|
2159
|
-
}
|
|
2160
|
-
};
|
|
2161
|
-
exports.ZodArray = ZodArray;
|
|
2162
|
-
ZodArray.create = (schema, params) => {
|
|
2163
|
-
return new ZodArray({
|
|
2164
|
-
type: schema,
|
|
2165
|
-
minLength: null,
|
|
2166
|
-
maxLength: null,
|
|
2167
|
-
exactLength: null,
|
|
2168
|
-
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
2169
|
-
...processCreateParams(params)
|
|
2170
|
-
});
|
|
2171
|
-
};
|
|
2172
|
-
function deepPartialify(schema) {
|
|
2173
|
-
if (schema instanceof ZodObject) {
|
|
2174
|
-
const newShape = {};
|
|
2175
|
-
for (const key in schema.shape) {
|
|
2176
|
-
const fieldSchema = schema.shape[key];
|
|
2177
|
-
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
2178
|
-
}
|
|
2179
|
-
return new ZodObject({
|
|
2180
|
-
...schema._def,
|
|
2181
|
-
shape: () => newShape
|
|
2182
|
-
});
|
|
2183
|
-
} else if (schema instanceof ZodArray) return new ZodArray({
|
|
2184
|
-
...schema._def,
|
|
2185
|
-
type: deepPartialify(schema.element)
|
|
2186
|
-
});
|
|
2187
|
-
else if (schema instanceof ZodOptional) return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
2188
|
-
else if (schema instanceof ZodNullable) return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
2189
|
-
else if (schema instanceof ZodTuple) return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
2190
|
-
else return schema;
|
|
2191
|
-
}
|
|
2192
|
-
var ZodObject = class ZodObject extends ZodType {
|
|
2193
|
-
constructor() {
|
|
2194
|
-
super(...arguments);
|
|
2195
|
-
this._cached = null;
|
|
2196
|
-
/**
|
|
2197
|
-
* @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
|
|
2198
|
-
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
|
2199
|
-
*/
|
|
2200
|
-
this.nonstrict = this.passthrough;
|
|
2201
|
-
/**
|
|
2202
|
-
* @deprecated Use `.extend` instead
|
|
2203
|
-
* */
|
|
2204
|
-
this.augment = this.extend;
|
|
2205
|
-
}
|
|
2206
|
-
_getCached() {
|
|
2207
|
-
if (this._cached !== null) return this._cached;
|
|
2208
|
-
const shape = this._def.shape();
|
|
2209
|
-
this._cached = {
|
|
2210
|
-
shape,
|
|
2211
|
-
keys: util_js_1.util.objectKeys(shape)
|
|
2212
|
-
};
|
|
2213
|
-
return this._cached;
|
|
2214
|
-
}
|
|
2215
|
-
_parse(input) {
|
|
2216
|
-
if (this._getType(input) !== util_js_1.ZodParsedType.object) {
|
|
2217
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2218
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2219
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
2220
|
-
expected: util_js_1.ZodParsedType.object,
|
|
2221
|
-
received: ctx.parsedType
|
|
2222
|
-
});
|
|
2223
|
-
return parseUtil_js_1.INVALID;
|
|
2224
|
-
}
|
|
2225
|
-
const { status, ctx } = this._processInputParams(input);
|
|
2226
|
-
const { shape, keys: shapeKeys } = this._getCached();
|
|
2227
|
-
const extraKeys = [];
|
|
2228
|
-
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
2229
|
-
for (const key in ctx.data) if (!shapeKeys.includes(key)) extraKeys.push(key);
|
|
2230
|
-
}
|
|
2231
|
-
const pairs = [];
|
|
2232
|
-
for (const key of shapeKeys) {
|
|
2233
|
-
const keyValidator = shape[key];
|
|
2234
|
-
const value = ctx.data[key];
|
|
2235
|
-
pairs.push({
|
|
2236
|
-
key: {
|
|
2237
|
-
status: "valid",
|
|
2238
|
-
value: key
|
|
2239
|
-
},
|
|
2240
|
-
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
2241
|
-
alwaysSet: key in ctx.data
|
|
2242
|
-
});
|
|
2243
|
-
}
|
|
2244
|
-
if (this._def.catchall instanceof ZodNever) {
|
|
2245
|
-
const unknownKeys = this._def.unknownKeys;
|
|
2246
|
-
if (unknownKeys === "passthrough") for (const key of extraKeys) pairs.push({
|
|
2247
|
-
key: {
|
|
2248
|
-
status: "valid",
|
|
2249
|
-
value: key
|
|
2250
|
-
},
|
|
2251
|
-
value: {
|
|
2252
|
-
status: "valid",
|
|
2253
|
-
value: ctx.data[key]
|
|
2254
|
-
}
|
|
2255
|
-
});
|
|
2256
|
-
else if (unknownKeys === "strict") {
|
|
2257
|
-
if (extraKeys.length > 0) {
|
|
2258
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2259
|
-
code: ZodError_js_1.ZodIssueCode.unrecognized_keys,
|
|
2260
|
-
keys: extraKeys
|
|
2261
|
-
});
|
|
2262
|
-
status.dirty();
|
|
2263
|
-
}
|
|
2264
|
-
} else if (unknownKeys === "strip") {} else throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
2265
|
-
} else {
|
|
2266
|
-
const catchall = this._def.catchall;
|
|
2267
|
-
for (const key of extraKeys) {
|
|
2268
|
-
const value = ctx.data[key];
|
|
2269
|
-
pairs.push({
|
|
2270
|
-
key: {
|
|
2271
|
-
status: "valid",
|
|
2272
|
-
value: key
|
|
2273
|
-
},
|
|
2274
|
-
value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
2275
|
-
alwaysSet: key in ctx.data
|
|
2276
|
-
});
|
|
2277
|
-
}
|
|
2278
|
-
}
|
|
2279
|
-
if (ctx.common.async) return Promise.resolve().then(async () => {
|
|
2280
|
-
const syncPairs = [];
|
|
2281
|
-
for (const pair of pairs) {
|
|
2282
|
-
const key = await pair.key;
|
|
2283
|
-
const value = await pair.value;
|
|
2284
|
-
syncPairs.push({
|
|
2285
|
-
key,
|
|
2286
|
-
value,
|
|
2287
|
-
alwaysSet: pair.alwaysSet
|
|
2288
|
-
});
|
|
2289
|
-
}
|
|
2290
|
-
return syncPairs;
|
|
2291
|
-
}).then((syncPairs) => {
|
|
2292
|
-
return parseUtil_js_1.ParseStatus.mergeObjectSync(status, syncPairs);
|
|
2293
|
-
});
|
|
2294
|
-
else return parseUtil_js_1.ParseStatus.mergeObjectSync(status, pairs);
|
|
2295
|
-
}
|
|
2296
|
-
get shape() {
|
|
2297
|
-
return this._def.shape();
|
|
2298
|
-
}
|
|
2299
|
-
strict(message) {
|
|
2300
|
-
errorUtil_js_1.errorUtil.errToObj;
|
|
2301
|
-
return new ZodObject({
|
|
2302
|
-
...this._def,
|
|
2303
|
-
unknownKeys: "strict",
|
|
2304
|
-
...message !== void 0 ? { errorMap: (issue, ctx) => {
|
|
2305
|
-
const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
|
2306
|
-
if (issue.code === "unrecognized_keys") return { message: errorUtil_js_1.errorUtil.errToObj(message).message ?? defaultError };
|
|
2307
|
-
return { message: defaultError };
|
|
2308
|
-
} } : {}
|
|
2309
|
-
});
|
|
2310
|
-
}
|
|
2311
|
-
strip() {
|
|
2312
|
-
return new ZodObject({
|
|
2313
|
-
...this._def,
|
|
2314
|
-
unknownKeys: "strip"
|
|
2315
|
-
});
|
|
2316
|
-
}
|
|
2317
|
-
passthrough() {
|
|
2318
|
-
return new ZodObject({
|
|
2319
|
-
...this._def,
|
|
2320
|
-
unknownKeys: "passthrough"
|
|
2321
|
-
});
|
|
2322
|
-
}
|
|
2323
|
-
extend(augmentation) {
|
|
2324
|
-
return new ZodObject({
|
|
2325
|
-
...this._def,
|
|
2326
|
-
shape: () => ({
|
|
2327
|
-
...this._def.shape(),
|
|
2328
|
-
...augmentation
|
|
2329
|
-
})
|
|
2330
|
-
});
|
|
2331
|
-
}
|
|
2332
|
-
/**
|
|
2333
|
-
* Prior to zod@1.0.12 there was a bug in the
|
|
2334
|
-
* inferred type of merged objects. Please
|
|
2335
|
-
* upgrade if you are experiencing issues.
|
|
2336
|
-
*/
|
|
2337
|
-
merge(merging) {
|
|
2338
|
-
return new ZodObject({
|
|
2339
|
-
unknownKeys: merging._def.unknownKeys,
|
|
2340
|
-
catchall: merging._def.catchall,
|
|
2341
|
-
shape: () => ({
|
|
2342
|
-
...this._def.shape(),
|
|
2343
|
-
...merging._def.shape()
|
|
2344
|
-
}),
|
|
2345
|
-
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
2346
|
-
});
|
|
2347
|
-
}
|
|
2348
|
-
setKey(key, schema) {
|
|
2349
|
-
return this.augment({ [key]: schema });
|
|
2350
|
-
}
|
|
2351
|
-
catchall(index) {
|
|
2352
|
-
return new ZodObject({
|
|
2353
|
-
...this._def,
|
|
2354
|
-
catchall: index
|
|
2355
|
-
});
|
|
2356
|
-
}
|
|
2357
|
-
pick(mask) {
|
|
2358
|
-
const shape = {};
|
|
2359
|
-
for (const key of util_js_1.util.objectKeys(mask)) if (mask[key] && this.shape[key]) shape[key] = this.shape[key];
|
|
2360
|
-
return new ZodObject({
|
|
2361
|
-
...this._def,
|
|
2362
|
-
shape: () => shape
|
|
2363
|
-
});
|
|
2364
|
-
}
|
|
2365
|
-
omit(mask) {
|
|
2366
|
-
const shape = {};
|
|
2367
|
-
for (const key of util_js_1.util.objectKeys(this.shape)) if (!mask[key]) shape[key] = this.shape[key];
|
|
2368
|
-
return new ZodObject({
|
|
2369
|
-
...this._def,
|
|
2370
|
-
shape: () => shape
|
|
2371
|
-
});
|
|
2372
|
-
}
|
|
2373
|
-
/**
|
|
2374
|
-
* @deprecated
|
|
2375
|
-
*/
|
|
2376
|
-
deepPartial() {
|
|
2377
|
-
return deepPartialify(this);
|
|
2378
|
-
}
|
|
2379
|
-
partial(mask) {
|
|
2380
|
-
const newShape = {};
|
|
2381
|
-
for (const key of util_js_1.util.objectKeys(this.shape)) {
|
|
2382
|
-
const fieldSchema = this.shape[key];
|
|
2383
|
-
if (mask && !mask[key]) newShape[key] = fieldSchema;
|
|
2384
|
-
else newShape[key] = fieldSchema.optional();
|
|
2385
|
-
}
|
|
2386
|
-
return new ZodObject({
|
|
2387
|
-
...this._def,
|
|
2388
|
-
shape: () => newShape
|
|
2389
|
-
});
|
|
2390
|
-
}
|
|
2391
|
-
required(mask) {
|
|
2392
|
-
const newShape = {};
|
|
2393
|
-
for (const key of util_js_1.util.objectKeys(this.shape)) if (mask && !mask[key]) newShape[key] = this.shape[key];
|
|
2394
|
-
else {
|
|
2395
|
-
let newField = this.shape[key];
|
|
2396
|
-
while (newField instanceof ZodOptional) newField = newField._def.innerType;
|
|
2397
|
-
newShape[key] = newField;
|
|
2398
|
-
}
|
|
2399
|
-
return new ZodObject({
|
|
2400
|
-
...this._def,
|
|
2401
|
-
shape: () => newShape
|
|
2402
|
-
});
|
|
2403
|
-
}
|
|
2404
|
-
keyof() {
|
|
2405
|
-
return createZodEnum(util_js_1.util.objectKeys(this.shape));
|
|
2406
|
-
}
|
|
2407
|
-
};
|
|
2408
|
-
exports.ZodObject = ZodObject;
|
|
2409
|
-
ZodObject.create = (shape, params) => {
|
|
2410
|
-
return new ZodObject({
|
|
2411
|
-
shape: () => shape,
|
|
2412
|
-
unknownKeys: "strip",
|
|
2413
|
-
catchall: ZodNever.create(),
|
|
2414
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2415
|
-
...processCreateParams(params)
|
|
2416
|
-
});
|
|
2417
|
-
};
|
|
2418
|
-
ZodObject.strictCreate = (shape, params) => {
|
|
2419
|
-
return new ZodObject({
|
|
2420
|
-
shape: () => shape,
|
|
2421
|
-
unknownKeys: "strict",
|
|
2422
|
-
catchall: ZodNever.create(),
|
|
2423
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2424
|
-
...processCreateParams(params)
|
|
2425
|
-
});
|
|
2426
|
-
};
|
|
2427
|
-
ZodObject.lazycreate = (shape, params) => {
|
|
2428
|
-
return new ZodObject({
|
|
2429
|
-
shape,
|
|
2430
|
-
unknownKeys: "strip",
|
|
2431
|
-
catchall: ZodNever.create(),
|
|
2432
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2433
|
-
...processCreateParams(params)
|
|
2434
|
-
});
|
|
2435
|
-
};
|
|
2436
|
-
var ZodUnion = class extends ZodType {
|
|
2437
|
-
_parse(input) {
|
|
2438
|
-
const { ctx } = this._processInputParams(input);
|
|
2439
|
-
const options = this._def.options;
|
|
2440
|
-
function handleResults(results) {
|
|
2441
|
-
for (const result of results) if (result.result.status === "valid") return result.result;
|
|
2442
|
-
for (const result of results) if (result.result.status === "dirty") {
|
|
2443
|
-
ctx.common.issues.push(...result.ctx.common.issues);
|
|
2444
|
-
return result.result;
|
|
2445
|
-
}
|
|
2446
|
-
const unionErrors = results.map((result) => new ZodError_js_1.ZodError(result.ctx.common.issues));
|
|
2447
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2448
|
-
code: ZodError_js_1.ZodIssueCode.invalid_union,
|
|
2449
|
-
unionErrors
|
|
2450
|
-
});
|
|
2451
|
-
return parseUtil_js_1.INVALID;
|
|
2452
|
-
}
|
|
2453
|
-
if (ctx.common.async) return Promise.all(options.map(async (option) => {
|
|
2454
|
-
const childCtx = {
|
|
2455
|
-
...ctx,
|
|
2456
|
-
common: {
|
|
2457
|
-
...ctx.common,
|
|
2458
|
-
issues: []
|
|
2459
|
-
},
|
|
2460
|
-
parent: null
|
|
2461
|
-
};
|
|
2462
|
-
return {
|
|
2463
|
-
result: await option._parseAsync({
|
|
2464
|
-
data: ctx.data,
|
|
2465
|
-
path: ctx.path,
|
|
2466
|
-
parent: childCtx
|
|
2467
|
-
}),
|
|
2468
|
-
ctx: childCtx
|
|
2469
|
-
};
|
|
2470
|
-
})).then(handleResults);
|
|
2471
|
-
else {
|
|
2472
|
-
let dirty = void 0;
|
|
2473
|
-
const issues = [];
|
|
2474
|
-
for (const option of options) {
|
|
2475
|
-
const childCtx = {
|
|
2476
|
-
...ctx,
|
|
2477
|
-
common: {
|
|
2478
|
-
...ctx.common,
|
|
2479
|
-
issues: []
|
|
2480
|
-
},
|
|
2481
|
-
parent: null
|
|
2482
|
-
};
|
|
2483
|
-
const result = option._parseSync({
|
|
2484
|
-
data: ctx.data,
|
|
2485
|
-
path: ctx.path,
|
|
2486
|
-
parent: childCtx
|
|
2487
|
-
});
|
|
2488
|
-
if (result.status === "valid") return result;
|
|
2489
|
-
else if (result.status === "dirty" && !dirty) dirty = {
|
|
2490
|
-
result,
|
|
2491
|
-
ctx: childCtx
|
|
2492
|
-
};
|
|
2493
|
-
if (childCtx.common.issues.length) issues.push(childCtx.common.issues);
|
|
2494
|
-
}
|
|
2495
|
-
if (dirty) {
|
|
2496
|
-
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
2497
|
-
return dirty.result;
|
|
2498
|
-
}
|
|
2499
|
-
const unionErrors = issues.map((issues) => new ZodError_js_1.ZodError(issues));
|
|
2500
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2501
|
-
code: ZodError_js_1.ZodIssueCode.invalid_union,
|
|
2502
|
-
unionErrors
|
|
2503
|
-
});
|
|
2504
|
-
return parseUtil_js_1.INVALID;
|
|
2505
|
-
}
|
|
2506
|
-
}
|
|
2507
|
-
get options() {
|
|
2508
|
-
return this._def.options;
|
|
2509
|
-
}
|
|
2510
|
-
};
|
|
2511
|
-
exports.ZodUnion = ZodUnion;
|
|
2512
|
-
ZodUnion.create = (types, params) => {
|
|
2513
|
-
return new ZodUnion({
|
|
2514
|
-
options: types,
|
|
2515
|
-
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
2516
|
-
...processCreateParams(params)
|
|
2517
|
-
});
|
|
2518
|
-
};
|
|
2519
|
-
const getDiscriminator = (type) => {
|
|
2520
|
-
if (type instanceof ZodLazy) return getDiscriminator(type.schema);
|
|
2521
|
-
else if (type instanceof ZodEffects) return getDiscriminator(type.innerType());
|
|
2522
|
-
else if (type instanceof ZodLiteral) return [type.value];
|
|
2523
|
-
else if (type instanceof ZodEnum) return type.options;
|
|
2524
|
-
else if (type instanceof ZodNativeEnum) return util_js_1.util.objectValues(type.enum);
|
|
2525
|
-
else if (type instanceof ZodDefault) return getDiscriminator(type._def.innerType);
|
|
2526
|
-
else if (type instanceof ZodUndefined) return [void 0];
|
|
2527
|
-
else if (type instanceof ZodNull) return [null];
|
|
2528
|
-
else if (type instanceof ZodOptional) return [void 0, ...getDiscriminator(type.unwrap())];
|
|
2529
|
-
else if (type instanceof ZodNullable) return [null, ...getDiscriminator(type.unwrap())];
|
|
2530
|
-
else if (type instanceof ZodBranded) return getDiscriminator(type.unwrap());
|
|
2531
|
-
else if (type instanceof ZodReadonly) return getDiscriminator(type.unwrap());
|
|
2532
|
-
else if (type instanceof ZodCatch) return getDiscriminator(type._def.innerType);
|
|
2533
|
-
else return [];
|
|
2534
|
-
};
|
|
2535
|
-
var ZodDiscriminatedUnion = class ZodDiscriminatedUnion extends ZodType {
|
|
2536
|
-
_parse(input) {
|
|
2537
|
-
const { ctx } = this._processInputParams(input);
|
|
2538
|
-
if (ctx.parsedType !== util_js_1.ZodParsedType.object) {
|
|
2539
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2540
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
2541
|
-
expected: util_js_1.ZodParsedType.object,
|
|
2542
|
-
received: ctx.parsedType
|
|
2543
|
-
});
|
|
2544
|
-
return parseUtil_js_1.INVALID;
|
|
2545
|
-
}
|
|
2546
|
-
const discriminator = this.discriminator;
|
|
2547
|
-
const discriminatorValue = ctx.data[discriminator];
|
|
2548
|
-
const option = this.optionsMap.get(discriminatorValue);
|
|
2549
|
-
if (!option) {
|
|
2550
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2551
|
-
code: ZodError_js_1.ZodIssueCode.invalid_union_discriminator,
|
|
2552
|
-
options: Array.from(this.optionsMap.keys()),
|
|
2553
|
-
path: [discriminator]
|
|
2554
|
-
});
|
|
2555
|
-
return parseUtil_js_1.INVALID;
|
|
2556
|
-
}
|
|
2557
|
-
if (ctx.common.async) return option._parseAsync({
|
|
2558
|
-
data: ctx.data,
|
|
2559
|
-
path: ctx.path,
|
|
2560
|
-
parent: ctx
|
|
2561
|
-
});
|
|
2562
|
-
else return option._parseSync({
|
|
2563
|
-
data: ctx.data,
|
|
2564
|
-
path: ctx.path,
|
|
2565
|
-
parent: ctx
|
|
2566
|
-
});
|
|
2567
|
-
}
|
|
2568
|
-
get discriminator() {
|
|
2569
|
-
return this._def.discriminator;
|
|
2570
|
-
}
|
|
2571
|
-
get options() {
|
|
2572
|
-
return this._def.options;
|
|
2573
|
-
}
|
|
2574
|
-
get optionsMap() {
|
|
2575
|
-
return this._def.optionsMap;
|
|
2576
|
-
}
|
|
2577
|
-
/**
|
|
2578
|
-
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
2579
|
-
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
2580
|
-
* have a different value for each object in the union.
|
|
2581
|
-
* @param discriminator the name of the discriminator property
|
|
2582
|
-
* @param types an array of object schemas
|
|
2583
|
-
* @param params
|
|
2584
|
-
*/
|
|
2585
|
-
static create(discriminator, options, params) {
|
|
2586
|
-
const optionsMap = /* @__PURE__ */ new Map();
|
|
2587
|
-
for (const type of options) {
|
|
2588
|
-
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
2589
|
-
if (!discriminatorValues.length) throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
2590
|
-
for (const value of discriminatorValues) {
|
|
2591
|
-
if (optionsMap.has(value)) throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
2592
|
-
optionsMap.set(value, type);
|
|
2593
|
-
}
|
|
2594
|
-
}
|
|
2595
|
-
return new ZodDiscriminatedUnion({
|
|
2596
|
-
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
2597
|
-
discriminator,
|
|
2598
|
-
options,
|
|
2599
|
-
optionsMap,
|
|
2600
|
-
...processCreateParams(params)
|
|
2601
|
-
});
|
|
2602
|
-
}
|
|
2603
|
-
};
|
|
2604
|
-
exports.ZodDiscriminatedUnion = ZodDiscriminatedUnion;
|
|
2605
|
-
function mergeValues(a, b) {
|
|
2606
|
-
const aType = (0, util_js_1.getParsedType)(a);
|
|
2607
|
-
const bType = (0, util_js_1.getParsedType)(b);
|
|
2608
|
-
if (a === b) return {
|
|
2609
|
-
valid: true,
|
|
2610
|
-
data: a
|
|
2611
|
-
};
|
|
2612
|
-
else if (aType === util_js_1.ZodParsedType.object && bType === util_js_1.ZodParsedType.object) {
|
|
2613
|
-
const bKeys = util_js_1.util.objectKeys(b);
|
|
2614
|
-
const sharedKeys = util_js_1.util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
2615
|
-
const newObj = {
|
|
2616
|
-
...a,
|
|
2617
|
-
...b
|
|
2618
|
-
};
|
|
2619
|
-
for (const key of sharedKeys) {
|
|
2620
|
-
const sharedValue = mergeValues(a[key], b[key]);
|
|
2621
|
-
if (!sharedValue.valid) return { valid: false };
|
|
2622
|
-
newObj[key] = sharedValue.data;
|
|
2623
|
-
}
|
|
2624
|
-
return {
|
|
2625
|
-
valid: true,
|
|
2626
|
-
data: newObj
|
|
2627
|
-
};
|
|
2628
|
-
} else if (aType === util_js_1.ZodParsedType.array && bType === util_js_1.ZodParsedType.array) {
|
|
2629
|
-
if (a.length !== b.length) return { valid: false };
|
|
2630
|
-
const newArray = [];
|
|
2631
|
-
for (let index = 0; index < a.length; index++) {
|
|
2632
|
-
const itemA = a[index];
|
|
2633
|
-
const itemB = b[index];
|
|
2634
|
-
const sharedValue = mergeValues(itemA, itemB);
|
|
2635
|
-
if (!sharedValue.valid) return { valid: false };
|
|
2636
|
-
newArray.push(sharedValue.data);
|
|
2637
|
-
}
|
|
2638
|
-
return {
|
|
2639
|
-
valid: true,
|
|
2640
|
-
data: newArray
|
|
2641
|
-
};
|
|
2642
|
-
} else if (aType === util_js_1.ZodParsedType.date && bType === util_js_1.ZodParsedType.date && +a === +b) return {
|
|
2643
|
-
valid: true,
|
|
2644
|
-
data: a
|
|
2645
|
-
};
|
|
2646
|
-
else return { valid: false };
|
|
2647
|
-
}
|
|
2648
|
-
var ZodIntersection = class extends ZodType {
|
|
2649
|
-
_parse(input) {
|
|
2650
|
-
const { status, ctx } = this._processInputParams(input);
|
|
2651
|
-
const handleParsed = (parsedLeft, parsedRight) => {
|
|
2652
|
-
if ((0, parseUtil_js_1.isAborted)(parsedLeft) || (0, parseUtil_js_1.isAborted)(parsedRight)) return parseUtil_js_1.INVALID;
|
|
2653
|
-
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
2654
|
-
if (!merged.valid) {
|
|
2655
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, { code: ZodError_js_1.ZodIssueCode.invalid_intersection_types });
|
|
2656
|
-
return parseUtil_js_1.INVALID;
|
|
2657
|
-
}
|
|
2658
|
-
if ((0, parseUtil_js_1.isDirty)(parsedLeft) || (0, parseUtil_js_1.isDirty)(parsedRight)) status.dirty();
|
|
2659
|
-
return {
|
|
2660
|
-
status: status.value,
|
|
2661
|
-
value: merged.data
|
|
2662
|
-
};
|
|
2663
|
-
};
|
|
2664
|
-
if (ctx.common.async) return Promise.all([this._def.left._parseAsync({
|
|
2665
|
-
data: ctx.data,
|
|
2666
|
-
path: ctx.path,
|
|
2667
|
-
parent: ctx
|
|
2668
|
-
}), this._def.right._parseAsync({
|
|
2669
|
-
data: ctx.data,
|
|
2670
|
-
path: ctx.path,
|
|
2671
|
-
parent: ctx
|
|
2672
|
-
})]).then(([left, right]) => handleParsed(left, right));
|
|
2673
|
-
else return handleParsed(this._def.left._parseSync({
|
|
2674
|
-
data: ctx.data,
|
|
2675
|
-
path: ctx.path,
|
|
2676
|
-
parent: ctx
|
|
2677
|
-
}), this._def.right._parseSync({
|
|
2678
|
-
data: ctx.data,
|
|
2679
|
-
path: ctx.path,
|
|
2680
|
-
parent: ctx
|
|
2681
|
-
}));
|
|
2682
|
-
}
|
|
2683
|
-
};
|
|
2684
|
-
exports.ZodIntersection = ZodIntersection;
|
|
2685
|
-
ZodIntersection.create = (left, right, params) => {
|
|
2686
|
-
return new ZodIntersection({
|
|
2687
|
-
left,
|
|
2688
|
-
right,
|
|
2689
|
-
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
2690
|
-
...processCreateParams(params)
|
|
2691
|
-
});
|
|
2692
|
-
};
|
|
2693
|
-
var ZodTuple = class ZodTuple extends ZodType {
|
|
2694
|
-
_parse(input) {
|
|
2695
|
-
const { status, ctx } = this._processInputParams(input);
|
|
2696
|
-
if (ctx.parsedType !== util_js_1.ZodParsedType.array) {
|
|
2697
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2698
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
2699
|
-
expected: util_js_1.ZodParsedType.array,
|
|
2700
|
-
received: ctx.parsedType
|
|
2701
|
-
});
|
|
2702
|
-
return parseUtil_js_1.INVALID;
|
|
2703
|
-
}
|
|
2704
|
-
if (ctx.data.length < this._def.items.length) {
|
|
2705
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2706
|
-
code: ZodError_js_1.ZodIssueCode.too_small,
|
|
2707
|
-
minimum: this._def.items.length,
|
|
2708
|
-
inclusive: true,
|
|
2709
|
-
exact: false,
|
|
2710
|
-
type: "array"
|
|
2711
|
-
});
|
|
2712
|
-
return parseUtil_js_1.INVALID;
|
|
2713
|
-
}
|
|
2714
|
-
if (!this._def.rest && ctx.data.length > this._def.items.length) {
|
|
2715
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2716
|
-
code: ZodError_js_1.ZodIssueCode.too_big,
|
|
2717
|
-
maximum: this._def.items.length,
|
|
2718
|
-
inclusive: true,
|
|
2719
|
-
exact: false,
|
|
2720
|
-
type: "array"
|
|
2721
|
-
});
|
|
2722
|
-
status.dirty();
|
|
2723
|
-
}
|
|
2724
|
-
const items = [...ctx.data].map((item, itemIndex) => {
|
|
2725
|
-
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
2726
|
-
if (!schema) return null;
|
|
2727
|
-
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
2728
|
-
}).filter((x) => !!x);
|
|
2729
|
-
if (ctx.common.async) return Promise.all(items).then((results) => {
|
|
2730
|
-
return parseUtil_js_1.ParseStatus.mergeArray(status, results);
|
|
2731
|
-
});
|
|
2732
|
-
else return parseUtil_js_1.ParseStatus.mergeArray(status, items);
|
|
2733
|
-
}
|
|
2734
|
-
get items() {
|
|
2735
|
-
return this._def.items;
|
|
2736
|
-
}
|
|
2737
|
-
rest(rest) {
|
|
2738
|
-
return new ZodTuple({
|
|
2739
|
-
...this._def,
|
|
2740
|
-
rest
|
|
2741
|
-
});
|
|
2742
|
-
}
|
|
2743
|
-
};
|
|
2744
|
-
exports.ZodTuple = ZodTuple;
|
|
2745
|
-
ZodTuple.create = (schemas, params) => {
|
|
2746
|
-
if (!Array.isArray(schemas)) throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
2747
|
-
return new ZodTuple({
|
|
2748
|
-
items: schemas,
|
|
2749
|
-
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
2750
|
-
rest: null,
|
|
2751
|
-
...processCreateParams(params)
|
|
2752
|
-
});
|
|
2753
|
-
};
|
|
2754
|
-
var ZodRecord = class ZodRecord extends ZodType {
|
|
2755
|
-
get keySchema() {
|
|
2756
|
-
return this._def.keyType;
|
|
2757
|
-
}
|
|
2758
|
-
get valueSchema() {
|
|
2759
|
-
return this._def.valueType;
|
|
2760
|
-
}
|
|
2761
|
-
_parse(input) {
|
|
2762
|
-
const { status, ctx } = this._processInputParams(input);
|
|
2763
|
-
if (ctx.parsedType !== util_js_1.ZodParsedType.object) {
|
|
2764
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2765
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
2766
|
-
expected: util_js_1.ZodParsedType.object,
|
|
2767
|
-
received: ctx.parsedType
|
|
2768
|
-
});
|
|
2769
|
-
return parseUtil_js_1.INVALID;
|
|
2770
|
-
}
|
|
2771
|
-
const pairs = [];
|
|
2772
|
-
const keyType = this._def.keyType;
|
|
2773
|
-
const valueType = this._def.valueType;
|
|
2774
|
-
for (const key in ctx.data) pairs.push({
|
|
2775
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
2776
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
2777
|
-
alwaysSet: key in ctx.data
|
|
2778
|
-
});
|
|
2779
|
-
if (ctx.common.async) return parseUtil_js_1.ParseStatus.mergeObjectAsync(status, pairs);
|
|
2780
|
-
else return parseUtil_js_1.ParseStatus.mergeObjectSync(status, pairs);
|
|
2781
|
-
}
|
|
2782
|
-
get element() {
|
|
2783
|
-
return this._def.valueType;
|
|
2784
|
-
}
|
|
2785
|
-
static create(first, second, third) {
|
|
2786
|
-
if (second instanceof ZodType) return new ZodRecord({
|
|
2787
|
-
keyType: first,
|
|
2788
|
-
valueType: second,
|
|
2789
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
2790
|
-
...processCreateParams(third)
|
|
2791
|
-
});
|
|
2792
|
-
return new ZodRecord({
|
|
2793
|
-
keyType: ZodString.create(),
|
|
2794
|
-
valueType: first,
|
|
2795
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
2796
|
-
...processCreateParams(second)
|
|
2797
|
-
});
|
|
2798
|
-
}
|
|
2799
|
-
};
|
|
2800
|
-
exports.ZodRecord = ZodRecord;
|
|
2801
|
-
var ZodMap = class extends ZodType {
|
|
2802
|
-
get keySchema() {
|
|
2803
|
-
return this._def.keyType;
|
|
2804
|
-
}
|
|
2805
|
-
get valueSchema() {
|
|
2806
|
-
return this._def.valueType;
|
|
2807
|
-
}
|
|
2808
|
-
_parse(input) {
|
|
2809
|
-
const { status, ctx } = this._processInputParams(input);
|
|
2810
|
-
if (ctx.parsedType !== util_js_1.ZodParsedType.map) {
|
|
2811
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2812
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
2813
|
-
expected: util_js_1.ZodParsedType.map,
|
|
2814
|
-
received: ctx.parsedType
|
|
2815
|
-
});
|
|
2816
|
-
return parseUtil_js_1.INVALID;
|
|
2817
|
-
}
|
|
2818
|
-
const keyType = this._def.keyType;
|
|
2819
|
-
const valueType = this._def.valueType;
|
|
2820
|
-
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
2821
|
-
return {
|
|
2822
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
2823
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
|
|
2824
|
-
};
|
|
2825
|
-
});
|
|
2826
|
-
if (ctx.common.async) {
|
|
2827
|
-
const finalMap = /* @__PURE__ */ new Map();
|
|
2828
|
-
return Promise.resolve().then(async () => {
|
|
2829
|
-
for (const pair of pairs) {
|
|
2830
|
-
const key = await pair.key;
|
|
2831
|
-
const value = await pair.value;
|
|
2832
|
-
if (key.status === "aborted" || value.status === "aborted") return parseUtil_js_1.INVALID;
|
|
2833
|
-
if (key.status === "dirty" || value.status === "dirty") status.dirty();
|
|
2834
|
-
finalMap.set(key.value, value.value);
|
|
2835
|
-
}
|
|
2836
|
-
return {
|
|
2837
|
-
status: status.value,
|
|
2838
|
-
value: finalMap
|
|
2839
|
-
};
|
|
2840
|
-
});
|
|
2841
|
-
} else {
|
|
2842
|
-
const finalMap = /* @__PURE__ */ new Map();
|
|
2843
|
-
for (const pair of pairs) {
|
|
2844
|
-
const key = pair.key;
|
|
2845
|
-
const value = pair.value;
|
|
2846
|
-
if (key.status === "aborted" || value.status === "aborted") return parseUtil_js_1.INVALID;
|
|
2847
|
-
if (key.status === "dirty" || value.status === "dirty") status.dirty();
|
|
2848
|
-
finalMap.set(key.value, value.value);
|
|
2849
|
-
}
|
|
2850
|
-
return {
|
|
2851
|
-
status: status.value,
|
|
2852
|
-
value: finalMap
|
|
2853
|
-
};
|
|
2854
|
-
}
|
|
2855
|
-
}
|
|
2856
|
-
};
|
|
2857
|
-
exports.ZodMap = ZodMap;
|
|
2858
|
-
ZodMap.create = (keyType, valueType, params) => {
|
|
2859
|
-
return new ZodMap({
|
|
2860
|
-
valueType,
|
|
2861
|
-
keyType,
|
|
2862
|
-
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
2863
|
-
...processCreateParams(params)
|
|
2864
|
-
});
|
|
2865
|
-
};
|
|
2866
|
-
var ZodSet = class ZodSet extends ZodType {
|
|
2867
|
-
_parse(input) {
|
|
2868
|
-
const { status, ctx } = this._processInputParams(input);
|
|
2869
|
-
if (ctx.parsedType !== util_js_1.ZodParsedType.set) {
|
|
2870
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2871
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
2872
|
-
expected: util_js_1.ZodParsedType.set,
|
|
2873
|
-
received: ctx.parsedType
|
|
2874
|
-
});
|
|
2875
|
-
return parseUtil_js_1.INVALID;
|
|
2876
|
-
}
|
|
2877
|
-
const def = this._def;
|
|
2878
|
-
if (def.minSize !== null) {
|
|
2879
|
-
if (ctx.data.size < def.minSize.value) {
|
|
2880
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2881
|
-
code: ZodError_js_1.ZodIssueCode.too_small,
|
|
2882
|
-
minimum: def.minSize.value,
|
|
2883
|
-
type: "set",
|
|
2884
|
-
inclusive: true,
|
|
2885
|
-
exact: false,
|
|
2886
|
-
message: def.minSize.message
|
|
2887
|
-
});
|
|
2888
|
-
status.dirty();
|
|
2889
|
-
}
|
|
2890
|
-
}
|
|
2891
|
-
if (def.maxSize !== null) {
|
|
2892
|
-
if (ctx.data.size > def.maxSize.value) {
|
|
2893
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2894
|
-
code: ZodError_js_1.ZodIssueCode.too_big,
|
|
2895
|
-
maximum: def.maxSize.value,
|
|
2896
|
-
type: "set",
|
|
2897
|
-
inclusive: true,
|
|
2898
|
-
exact: false,
|
|
2899
|
-
message: def.maxSize.message
|
|
2900
|
-
});
|
|
2901
|
-
status.dirty();
|
|
2902
|
-
}
|
|
2903
|
-
}
|
|
2904
|
-
const valueType = this._def.valueType;
|
|
2905
|
-
function finalizeSet(elements) {
|
|
2906
|
-
const parsedSet = /* @__PURE__ */ new Set();
|
|
2907
|
-
for (const element of elements) {
|
|
2908
|
-
if (element.status === "aborted") return parseUtil_js_1.INVALID;
|
|
2909
|
-
if (element.status === "dirty") status.dirty();
|
|
2910
|
-
parsedSet.add(element.value);
|
|
2911
|
-
}
|
|
2912
|
-
return {
|
|
2913
|
-
status: status.value,
|
|
2914
|
-
value: parsedSet
|
|
2915
|
-
};
|
|
2916
|
-
}
|
|
2917
|
-
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
2918
|
-
if (ctx.common.async) return Promise.all(elements).then((elements) => finalizeSet(elements));
|
|
2919
|
-
else return finalizeSet(elements);
|
|
2920
|
-
}
|
|
2921
|
-
min(minSize, message) {
|
|
2922
|
-
return new ZodSet({
|
|
2923
|
-
...this._def,
|
|
2924
|
-
minSize: {
|
|
2925
|
-
value: minSize,
|
|
2926
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
2927
|
-
}
|
|
2928
|
-
});
|
|
2929
|
-
}
|
|
2930
|
-
max(maxSize, message) {
|
|
2931
|
-
return new ZodSet({
|
|
2932
|
-
...this._def,
|
|
2933
|
-
maxSize: {
|
|
2934
|
-
value: maxSize,
|
|
2935
|
-
message: errorUtil_js_1.errorUtil.toString(message)
|
|
2936
|
-
}
|
|
2937
|
-
});
|
|
2938
|
-
}
|
|
2939
|
-
size(size, message) {
|
|
2940
|
-
return this.min(size, message).max(size, message);
|
|
2941
|
-
}
|
|
2942
|
-
nonempty(message) {
|
|
2943
|
-
return this.min(1, message);
|
|
2944
|
-
}
|
|
2945
|
-
};
|
|
2946
|
-
exports.ZodSet = ZodSet;
|
|
2947
|
-
ZodSet.create = (valueType, params) => {
|
|
2948
|
-
return new ZodSet({
|
|
2949
|
-
valueType,
|
|
2950
|
-
minSize: null,
|
|
2951
|
-
maxSize: null,
|
|
2952
|
-
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
2953
|
-
...processCreateParams(params)
|
|
2954
|
-
});
|
|
2955
|
-
};
|
|
2956
|
-
var ZodFunction = class ZodFunction extends ZodType {
|
|
2957
|
-
constructor() {
|
|
2958
|
-
super(...arguments);
|
|
2959
|
-
this.validate = this.implement;
|
|
2960
|
-
}
|
|
2961
|
-
_parse(input) {
|
|
2962
|
-
const { ctx } = this._processInputParams(input);
|
|
2963
|
-
if (ctx.parsedType !== util_js_1.ZodParsedType.function) {
|
|
2964
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
2965
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
2966
|
-
expected: util_js_1.ZodParsedType.function,
|
|
2967
|
-
received: ctx.parsedType
|
|
2968
|
-
});
|
|
2969
|
-
return parseUtil_js_1.INVALID;
|
|
2970
|
-
}
|
|
2971
|
-
function makeArgsIssue(args, error) {
|
|
2972
|
-
return (0, parseUtil_js_1.makeIssue)({
|
|
2973
|
-
data: args,
|
|
2974
|
-
path: ctx.path,
|
|
2975
|
-
errorMaps: [
|
|
2976
|
-
ctx.common.contextualErrorMap,
|
|
2977
|
-
ctx.schemaErrorMap,
|
|
2978
|
-
(0, errors_js_1.getErrorMap)(),
|
|
2979
|
-
errors_js_1.defaultErrorMap
|
|
2980
|
-
].filter((x) => !!x),
|
|
2981
|
-
issueData: {
|
|
2982
|
-
code: ZodError_js_1.ZodIssueCode.invalid_arguments,
|
|
2983
|
-
argumentsError: error
|
|
2984
|
-
}
|
|
2985
|
-
});
|
|
2986
|
-
}
|
|
2987
|
-
function makeReturnsIssue(returns, error) {
|
|
2988
|
-
return (0, parseUtil_js_1.makeIssue)({
|
|
2989
|
-
data: returns,
|
|
2990
|
-
path: ctx.path,
|
|
2991
|
-
errorMaps: [
|
|
2992
|
-
ctx.common.contextualErrorMap,
|
|
2993
|
-
ctx.schemaErrorMap,
|
|
2994
|
-
(0, errors_js_1.getErrorMap)(),
|
|
2995
|
-
errors_js_1.defaultErrorMap
|
|
2996
|
-
].filter((x) => !!x),
|
|
2997
|
-
issueData: {
|
|
2998
|
-
code: ZodError_js_1.ZodIssueCode.invalid_return_type,
|
|
2999
|
-
returnTypeError: error
|
|
3000
|
-
}
|
|
3001
|
-
});
|
|
3002
|
-
}
|
|
3003
|
-
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
3004
|
-
const fn = ctx.data;
|
|
3005
|
-
if (this._def.returns instanceof ZodPromise) {
|
|
3006
|
-
const me = this;
|
|
3007
|
-
return (0, parseUtil_js_1.OK)(async function(...args) {
|
|
3008
|
-
const error = new ZodError_js_1.ZodError([]);
|
|
3009
|
-
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
3010
|
-
error.addIssue(makeArgsIssue(args, e));
|
|
3011
|
-
throw error;
|
|
3012
|
-
});
|
|
3013
|
-
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
3014
|
-
return await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
3015
|
-
error.addIssue(makeReturnsIssue(result, e));
|
|
3016
|
-
throw error;
|
|
3017
|
-
});
|
|
3018
|
-
});
|
|
3019
|
-
} else {
|
|
3020
|
-
const me = this;
|
|
3021
|
-
return (0, parseUtil_js_1.OK)(function(...args) {
|
|
3022
|
-
const parsedArgs = me._def.args.safeParse(args, params);
|
|
3023
|
-
if (!parsedArgs.success) throw new ZodError_js_1.ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
3024
|
-
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
3025
|
-
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
3026
|
-
if (!parsedReturns.success) throw new ZodError_js_1.ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
3027
|
-
return parsedReturns.data;
|
|
3028
|
-
});
|
|
3029
|
-
}
|
|
3030
|
-
}
|
|
3031
|
-
parameters() {
|
|
3032
|
-
return this._def.args;
|
|
3033
|
-
}
|
|
3034
|
-
returnType() {
|
|
3035
|
-
return this._def.returns;
|
|
3036
|
-
}
|
|
3037
|
-
args(...items) {
|
|
3038
|
-
return new ZodFunction({
|
|
3039
|
-
...this._def,
|
|
3040
|
-
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
3041
|
-
});
|
|
3042
|
-
}
|
|
3043
|
-
returns(returnType) {
|
|
3044
|
-
return new ZodFunction({
|
|
3045
|
-
...this._def,
|
|
3046
|
-
returns: returnType
|
|
3047
|
-
});
|
|
3048
|
-
}
|
|
3049
|
-
implement(func) {
|
|
3050
|
-
return this.parse(func);
|
|
3051
|
-
}
|
|
3052
|
-
strictImplement(func) {
|
|
3053
|
-
return this.parse(func);
|
|
3054
|
-
}
|
|
3055
|
-
static create(args, returns, params) {
|
|
3056
|
-
return new ZodFunction({
|
|
3057
|
-
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
3058
|
-
returns: returns || ZodUnknown.create(),
|
|
3059
|
-
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
3060
|
-
...processCreateParams(params)
|
|
3061
|
-
});
|
|
3062
|
-
}
|
|
3063
|
-
};
|
|
3064
|
-
exports.ZodFunction = ZodFunction;
|
|
3065
|
-
var ZodLazy = class extends ZodType {
|
|
3066
|
-
get schema() {
|
|
3067
|
-
return this._def.getter();
|
|
3068
|
-
}
|
|
3069
|
-
_parse(input) {
|
|
3070
|
-
const { ctx } = this._processInputParams(input);
|
|
3071
|
-
return this._def.getter()._parse({
|
|
3072
|
-
data: ctx.data,
|
|
3073
|
-
path: ctx.path,
|
|
3074
|
-
parent: ctx
|
|
3075
|
-
});
|
|
3076
|
-
}
|
|
3077
|
-
};
|
|
3078
|
-
exports.ZodLazy = ZodLazy;
|
|
3079
|
-
ZodLazy.create = (getter, params) => {
|
|
3080
|
-
return new ZodLazy({
|
|
3081
|
-
getter,
|
|
3082
|
-
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
3083
|
-
...processCreateParams(params)
|
|
3084
|
-
});
|
|
3085
|
-
};
|
|
3086
|
-
var ZodLiteral = class extends ZodType {
|
|
3087
|
-
_parse(input) {
|
|
3088
|
-
if (input.data !== this._def.value) {
|
|
3089
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3090
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
3091
|
-
received: ctx.data,
|
|
3092
|
-
code: ZodError_js_1.ZodIssueCode.invalid_literal,
|
|
3093
|
-
expected: this._def.value
|
|
3094
|
-
});
|
|
3095
|
-
return parseUtil_js_1.INVALID;
|
|
3096
|
-
}
|
|
3097
|
-
return {
|
|
3098
|
-
status: "valid",
|
|
3099
|
-
value: input.data
|
|
3100
|
-
};
|
|
3101
|
-
}
|
|
3102
|
-
get value() {
|
|
3103
|
-
return this._def.value;
|
|
3104
|
-
}
|
|
3105
|
-
};
|
|
3106
|
-
exports.ZodLiteral = ZodLiteral;
|
|
3107
|
-
ZodLiteral.create = (value, params) => {
|
|
3108
|
-
return new ZodLiteral({
|
|
3109
|
-
value,
|
|
3110
|
-
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
3111
|
-
...processCreateParams(params)
|
|
3112
|
-
});
|
|
3113
|
-
};
|
|
3114
|
-
function createZodEnum(values, params) {
|
|
3115
|
-
return new ZodEnum({
|
|
3116
|
-
values,
|
|
3117
|
-
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
3118
|
-
...processCreateParams(params)
|
|
3119
|
-
});
|
|
3120
|
-
}
|
|
3121
|
-
var ZodEnum = class ZodEnum extends ZodType {
|
|
3122
|
-
_parse(input) {
|
|
3123
|
-
if (typeof input.data !== "string") {
|
|
3124
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3125
|
-
const expectedValues = this._def.values;
|
|
3126
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
3127
|
-
expected: util_js_1.util.joinValues(expectedValues),
|
|
3128
|
-
received: ctx.parsedType,
|
|
3129
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type
|
|
3130
|
-
});
|
|
3131
|
-
return parseUtil_js_1.INVALID;
|
|
3132
|
-
}
|
|
3133
|
-
if (!this._cache) this._cache = new Set(this._def.values);
|
|
3134
|
-
if (!this._cache.has(input.data)) {
|
|
3135
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3136
|
-
const expectedValues = this._def.values;
|
|
3137
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
3138
|
-
received: ctx.data,
|
|
3139
|
-
code: ZodError_js_1.ZodIssueCode.invalid_enum_value,
|
|
3140
|
-
options: expectedValues
|
|
3141
|
-
});
|
|
3142
|
-
return parseUtil_js_1.INVALID;
|
|
3143
|
-
}
|
|
3144
|
-
return (0, parseUtil_js_1.OK)(input.data);
|
|
3145
|
-
}
|
|
3146
|
-
get options() {
|
|
3147
|
-
return this._def.values;
|
|
3148
|
-
}
|
|
3149
|
-
get enum() {
|
|
3150
|
-
const enumValues = {};
|
|
3151
|
-
for (const val of this._def.values) enumValues[val] = val;
|
|
3152
|
-
return enumValues;
|
|
3153
|
-
}
|
|
3154
|
-
get Values() {
|
|
3155
|
-
const enumValues = {};
|
|
3156
|
-
for (const val of this._def.values) enumValues[val] = val;
|
|
3157
|
-
return enumValues;
|
|
3158
|
-
}
|
|
3159
|
-
get Enum() {
|
|
3160
|
-
const enumValues = {};
|
|
3161
|
-
for (const val of this._def.values) enumValues[val] = val;
|
|
3162
|
-
return enumValues;
|
|
3163
|
-
}
|
|
3164
|
-
extract(values, newDef = this._def) {
|
|
3165
|
-
return ZodEnum.create(values, {
|
|
3166
|
-
...this._def,
|
|
3167
|
-
...newDef
|
|
3168
|
-
});
|
|
3169
|
-
}
|
|
3170
|
-
exclude(values, newDef = this._def) {
|
|
3171
|
-
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
3172
|
-
...this._def,
|
|
3173
|
-
...newDef
|
|
3174
|
-
});
|
|
3175
|
-
}
|
|
3176
|
-
};
|
|
3177
|
-
exports.ZodEnum = ZodEnum;
|
|
3178
|
-
ZodEnum.create = createZodEnum;
|
|
3179
|
-
var ZodNativeEnum = class extends ZodType {
|
|
3180
|
-
_parse(input) {
|
|
3181
|
-
const nativeEnumValues = util_js_1.util.getValidEnumValues(this._def.values);
|
|
3182
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3183
|
-
if (ctx.parsedType !== util_js_1.ZodParsedType.string && ctx.parsedType !== util_js_1.ZodParsedType.number) {
|
|
3184
|
-
const expectedValues = util_js_1.util.objectValues(nativeEnumValues);
|
|
3185
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
3186
|
-
expected: util_js_1.util.joinValues(expectedValues),
|
|
3187
|
-
received: ctx.parsedType,
|
|
3188
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type
|
|
3189
|
-
});
|
|
3190
|
-
return parseUtil_js_1.INVALID;
|
|
3191
|
-
}
|
|
3192
|
-
if (!this._cache) this._cache = new Set(util_js_1.util.getValidEnumValues(this._def.values));
|
|
3193
|
-
if (!this._cache.has(input.data)) {
|
|
3194
|
-
const expectedValues = util_js_1.util.objectValues(nativeEnumValues);
|
|
3195
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
3196
|
-
received: ctx.data,
|
|
3197
|
-
code: ZodError_js_1.ZodIssueCode.invalid_enum_value,
|
|
3198
|
-
options: expectedValues
|
|
3199
|
-
});
|
|
3200
|
-
return parseUtil_js_1.INVALID;
|
|
3201
|
-
}
|
|
3202
|
-
return (0, parseUtil_js_1.OK)(input.data);
|
|
3203
|
-
}
|
|
3204
|
-
get enum() {
|
|
3205
|
-
return this._def.values;
|
|
3206
|
-
}
|
|
3207
|
-
};
|
|
3208
|
-
exports.ZodNativeEnum = ZodNativeEnum;
|
|
3209
|
-
ZodNativeEnum.create = (values, params) => {
|
|
3210
|
-
return new ZodNativeEnum({
|
|
3211
|
-
values,
|
|
3212
|
-
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
3213
|
-
...processCreateParams(params)
|
|
3214
|
-
});
|
|
3215
|
-
};
|
|
3216
|
-
var ZodPromise = class extends ZodType {
|
|
3217
|
-
unwrap() {
|
|
3218
|
-
return this._def.type;
|
|
3219
|
-
}
|
|
3220
|
-
_parse(input) {
|
|
3221
|
-
const { ctx } = this._processInputParams(input);
|
|
3222
|
-
if (ctx.parsedType !== util_js_1.ZodParsedType.promise && ctx.common.async === false) {
|
|
3223
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
3224
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
3225
|
-
expected: util_js_1.ZodParsedType.promise,
|
|
3226
|
-
received: ctx.parsedType
|
|
3227
|
-
});
|
|
3228
|
-
return parseUtil_js_1.INVALID;
|
|
3229
|
-
}
|
|
3230
|
-
const promisified = ctx.parsedType === util_js_1.ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
3231
|
-
return (0, parseUtil_js_1.OK)(promisified.then((data) => {
|
|
3232
|
-
return this._def.type.parseAsync(data, {
|
|
3233
|
-
path: ctx.path,
|
|
3234
|
-
errorMap: ctx.common.contextualErrorMap
|
|
3235
|
-
});
|
|
3236
|
-
}));
|
|
3237
|
-
}
|
|
3238
|
-
};
|
|
3239
|
-
exports.ZodPromise = ZodPromise;
|
|
3240
|
-
ZodPromise.create = (schema, params) => {
|
|
3241
|
-
return new ZodPromise({
|
|
3242
|
-
type: schema,
|
|
3243
|
-
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
3244
|
-
...processCreateParams(params)
|
|
3245
|
-
});
|
|
3246
|
-
};
|
|
3247
|
-
var ZodEffects = class extends ZodType {
|
|
3248
|
-
innerType() {
|
|
3249
|
-
return this._def.schema;
|
|
3250
|
-
}
|
|
3251
|
-
sourceType() {
|
|
3252
|
-
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
3253
|
-
}
|
|
3254
|
-
_parse(input) {
|
|
3255
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3256
|
-
const effect = this._def.effect || null;
|
|
3257
|
-
const checkCtx = {
|
|
3258
|
-
addIssue: (arg) => {
|
|
3259
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, arg);
|
|
3260
|
-
if (arg.fatal) status.abort();
|
|
3261
|
-
else status.dirty();
|
|
3262
|
-
},
|
|
3263
|
-
get path() {
|
|
3264
|
-
return ctx.path;
|
|
3265
|
-
}
|
|
3266
|
-
};
|
|
3267
|
-
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
3268
|
-
if (effect.type === "preprocess") {
|
|
3269
|
-
const processed = effect.transform(ctx.data, checkCtx);
|
|
3270
|
-
if (ctx.common.async) return Promise.resolve(processed).then(async (processed) => {
|
|
3271
|
-
if (status.value === "aborted") return parseUtil_js_1.INVALID;
|
|
3272
|
-
const result = await this._def.schema._parseAsync({
|
|
3273
|
-
data: processed,
|
|
3274
|
-
path: ctx.path,
|
|
3275
|
-
parent: ctx
|
|
3276
|
-
});
|
|
3277
|
-
if (result.status === "aborted") return parseUtil_js_1.INVALID;
|
|
3278
|
-
if (result.status === "dirty") return (0, parseUtil_js_1.DIRTY)(result.value);
|
|
3279
|
-
if (status.value === "dirty") return (0, parseUtil_js_1.DIRTY)(result.value);
|
|
3280
|
-
return result;
|
|
3281
|
-
});
|
|
3282
|
-
else {
|
|
3283
|
-
if (status.value === "aborted") return parseUtil_js_1.INVALID;
|
|
3284
|
-
const result = this._def.schema._parseSync({
|
|
3285
|
-
data: processed,
|
|
3286
|
-
path: ctx.path,
|
|
3287
|
-
parent: ctx
|
|
3288
|
-
});
|
|
3289
|
-
if (result.status === "aborted") return parseUtil_js_1.INVALID;
|
|
3290
|
-
if (result.status === "dirty") return (0, parseUtil_js_1.DIRTY)(result.value);
|
|
3291
|
-
if (status.value === "dirty") return (0, parseUtil_js_1.DIRTY)(result.value);
|
|
3292
|
-
return result;
|
|
3293
|
-
}
|
|
3294
|
-
}
|
|
3295
|
-
if (effect.type === "refinement") {
|
|
3296
|
-
const executeRefinement = (acc) => {
|
|
3297
|
-
const result = effect.refinement(acc, checkCtx);
|
|
3298
|
-
if (ctx.common.async) return Promise.resolve(result);
|
|
3299
|
-
if (result instanceof Promise) throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
3300
|
-
return acc;
|
|
3301
|
-
};
|
|
3302
|
-
if (ctx.common.async === false) {
|
|
3303
|
-
const inner = this._def.schema._parseSync({
|
|
3304
|
-
data: ctx.data,
|
|
3305
|
-
path: ctx.path,
|
|
3306
|
-
parent: ctx
|
|
3307
|
-
});
|
|
3308
|
-
if (inner.status === "aborted") return parseUtil_js_1.INVALID;
|
|
3309
|
-
if (inner.status === "dirty") status.dirty();
|
|
3310
|
-
executeRefinement(inner.value);
|
|
3311
|
-
return {
|
|
3312
|
-
status: status.value,
|
|
3313
|
-
value: inner.value
|
|
3314
|
-
};
|
|
3315
|
-
} else return this._def.schema._parseAsync({
|
|
3316
|
-
data: ctx.data,
|
|
3317
|
-
path: ctx.path,
|
|
3318
|
-
parent: ctx
|
|
3319
|
-
}).then((inner) => {
|
|
3320
|
-
if (inner.status === "aborted") return parseUtil_js_1.INVALID;
|
|
3321
|
-
if (inner.status === "dirty") status.dirty();
|
|
3322
|
-
return executeRefinement(inner.value).then(() => {
|
|
3323
|
-
return {
|
|
3324
|
-
status: status.value,
|
|
3325
|
-
value: inner.value
|
|
3326
|
-
};
|
|
3327
|
-
});
|
|
3328
|
-
});
|
|
3329
|
-
}
|
|
3330
|
-
if (effect.type === "transform") if (ctx.common.async === false) {
|
|
3331
|
-
const base = this._def.schema._parseSync({
|
|
3332
|
-
data: ctx.data,
|
|
3333
|
-
path: ctx.path,
|
|
3334
|
-
parent: ctx
|
|
3335
|
-
});
|
|
3336
|
-
if (!(0, parseUtil_js_1.isValid)(base)) return parseUtil_js_1.INVALID;
|
|
3337
|
-
const result = effect.transform(base.value, checkCtx);
|
|
3338
|
-
if (result instanceof Promise) throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
3339
|
-
return {
|
|
3340
|
-
status: status.value,
|
|
3341
|
-
value: result
|
|
3342
|
-
};
|
|
3343
|
-
} else return this._def.schema._parseAsync({
|
|
3344
|
-
data: ctx.data,
|
|
3345
|
-
path: ctx.path,
|
|
3346
|
-
parent: ctx
|
|
3347
|
-
}).then((base) => {
|
|
3348
|
-
if (!(0, parseUtil_js_1.isValid)(base)) return parseUtil_js_1.INVALID;
|
|
3349
|
-
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
3350
|
-
status: status.value,
|
|
3351
|
-
value: result
|
|
3352
|
-
}));
|
|
3353
|
-
});
|
|
3354
|
-
util_js_1.util.assertNever(effect);
|
|
3355
|
-
}
|
|
3356
|
-
};
|
|
3357
|
-
exports.ZodEffects = ZodEffects;
|
|
3358
|
-
exports.ZodTransformer = ZodEffects;
|
|
3359
|
-
ZodEffects.create = (schema, effect, params) => {
|
|
3360
|
-
return new ZodEffects({
|
|
3361
|
-
schema,
|
|
3362
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
3363
|
-
effect,
|
|
3364
|
-
...processCreateParams(params)
|
|
3365
|
-
});
|
|
3366
|
-
};
|
|
3367
|
-
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
3368
|
-
return new ZodEffects({
|
|
3369
|
-
schema,
|
|
3370
|
-
effect: {
|
|
3371
|
-
type: "preprocess",
|
|
3372
|
-
transform: preprocess
|
|
3373
|
-
},
|
|
3374
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
3375
|
-
...processCreateParams(params)
|
|
3376
|
-
});
|
|
3377
|
-
};
|
|
3378
|
-
var ZodOptional = class extends ZodType {
|
|
3379
|
-
_parse(input) {
|
|
3380
|
-
if (this._getType(input) === util_js_1.ZodParsedType.undefined) return (0, parseUtil_js_1.OK)(void 0);
|
|
3381
|
-
return this._def.innerType._parse(input);
|
|
3382
|
-
}
|
|
3383
|
-
unwrap() {
|
|
3384
|
-
return this._def.innerType;
|
|
3385
|
-
}
|
|
3386
|
-
};
|
|
3387
|
-
exports.ZodOptional = ZodOptional;
|
|
3388
|
-
ZodOptional.create = (type, params) => {
|
|
3389
|
-
return new ZodOptional({
|
|
3390
|
-
innerType: type,
|
|
3391
|
-
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
3392
|
-
...processCreateParams(params)
|
|
3393
|
-
});
|
|
3394
|
-
};
|
|
3395
|
-
var ZodNullable = class extends ZodType {
|
|
3396
|
-
_parse(input) {
|
|
3397
|
-
if (this._getType(input) === util_js_1.ZodParsedType.null) return (0, parseUtil_js_1.OK)(null);
|
|
3398
|
-
return this._def.innerType._parse(input);
|
|
3399
|
-
}
|
|
3400
|
-
unwrap() {
|
|
3401
|
-
return this._def.innerType;
|
|
3402
|
-
}
|
|
3403
|
-
};
|
|
3404
|
-
exports.ZodNullable = ZodNullable;
|
|
3405
|
-
ZodNullable.create = (type, params) => {
|
|
3406
|
-
return new ZodNullable({
|
|
3407
|
-
innerType: type,
|
|
3408
|
-
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
3409
|
-
...processCreateParams(params)
|
|
3410
|
-
});
|
|
3411
|
-
};
|
|
3412
|
-
var ZodDefault = class extends ZodType {
|
|
3413
|
-
_parse(input) {
|
|
3414
|
-
const { ctx } = this._processInputParams(input);
|
|
3415
|
-
let data = ctx.data;
|
|
3416
|
-
if (ctx.parsedType === util_js_1.ZodParsedType.undefined) data = this._def.defaultValue();
|
|
3417
|
-
return this._def.innerType._parse({
|
|
3418
|
-
data,
|
|
3419
|
-
path: ctx.path,
|
|
3420
|
-
parent: ctx
|
|
3421
|
-
});
|
|
3422
|
-
}
|
|
3423
|
-
removeDefault() {
|
|
3424
|
-
return this._def.innerType;
|
|
3425
|
-
}
|
|
3426
|
-
};
|
|
3427
|
-
exports.ZodDefault = ZodDefault;
|
|
3428
|
-
ZodDefault.create = (type, params) => {
|
|
3429
|
-
return new ZodDefault({
|
|
3430
|
-
innerType: type,
|
|
3431
|
-
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
3432
|
-
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
3433
|
-
...processCreateParams(params)
|
|
3434
|
-
});
|
|
3435
|
-
};
|
|
3436
|
-
var ZodCatch = class extends ZodType {
|
|
3437
|
-
_parse(input) {
|
|
3438
|
-
const { ctx } = this._processInputParams(input);
|
|
3439
|
-
const newCtx = {
|
|
3440
|
-
...ctx,
|
|
3441
|
-
common: {
|
|
3442
|
-
...ctx.common,
|
|
3443
|
-
issues: []
|
|
3444
|
-
}
|
|
3445
|
-
};
|
|
3446
|
-
const result = this._def.innerType._parse({
|
|
3447
|
-
data: newCtx.data,
|
|
3448
|
-
path: newCtx.path,
|
|
3449
|
-
parent: { ...newCtx }
|
|
3450
|
-
});
|
|
3451
|
-
if ((0, parseUtil_js_1.isAsync)(result)) return result.then((result) => {
|
|
3452
|
-
return {
|
|
3453
|
-
status: "valid",
|
|
3454
|
-
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
3455
|
-
get error() {
|
|
3456
|
-
return new ZodError_js_1.ZodError(newCtx.common.issues);
|
|
3457
|
-
},
|
|
3458
|
-
input: newCtx.data
|
|
3459
|
-
})
|
|
3460
|
-
};
|
|
3461
|
-
});
|
|
3462
|
-
else return {
|
|
3463
|
-
status: "valid",
|
|
3464
|
-
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
3465
|
-
get error() {
|
|
3466
|
-
return new ZodError_js_1.ZodError(newCtx.common.issues);
|
|
3467
|
-
},
|
|
3468
|
-
input: newCtx.data
|
|
3469
|
-
})
|
|
3470
|
-
};
|
|
3471
|
-
}
|
|
3472
|
-
removeCatch() {
|
|
3473
|
-
return this._def.innerType;
|
|
3474
|
-
}
|
|
3475
|
-
};
|
|
3476
|
-
exports.ZodCatch = ZodCatch;
|
|
3477
|
-
ZodCatch.create = (type, params) => {
|
|
3478
|
-
return new ZodCatch({
|
|
3479
|
-
innerType: type,
|
|
3480
|
-
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
3481
|
-
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
3482
|
-
...processCreateParams(params)
|
|
3483
|
-
});
|
|
3484
|
-
};
|
|
3485
|
-
var ZodNaN = class extends ZodType {
|
|
3486
|
-
_parse(input) {
|
|
3487
|
-
if (this._getType(input) !== util_js_1.ZodParsedType.nan) {
|
|
3488
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3489
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
|
3490
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
|
3491
|
-
expected: util_js_1.ZodParsedType.nan,
|
|
3492
|
-
received: ctx.parsedType
|
|
3493
|
-
});
|
|
3494
|
-
return parseUtil_js_1.INVALID;
|
|
3495
|
-
}
|
|
3496
|
-
return {
|
|
3497
|
-
status: "valid",
|
|
3498
|
-
value: input.data
|
|
3499
|
-
};
|
|
3500
|
-
}
|
|
3501
|
-
};
|
|
3502
|
-
exports.ZodNaN = ZodNaN;
|
|
3503
|
-
ZodNaN.create = (params) => {
|
|
3504
|
-
return new ZodNaN({
|
|
3505
|
-
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
3506
|
-
...processCreateParams(params)
|
|
3507
|
-
});
|
|
3508
|
-
};
|
|
3509
|
-
exports.BRAND = Symbol("zod_brand");
|
|
3510
|
-
var ZodBranded = class extends ZodType {
|
|
3511
|
-
_parse(input) {
|
|
3512
|
-
const { ctx } = this._processInputParams(input);
|
|
3513
|
-
const data = ctx.data;
|
|
3514
|
-
return this._def.type._parse({
|
|
3515
|
-
data,
|
|
3516
|
-
path: ctx.path,
|
|
3517
|
-
parent: ctx
|
|
3518
|
-
});
|
|
3519
|
-
}
|
|
3520
|
-
unwrap() {
|
|
3521
|
-
return this._def.type;
|
|
3522
|
-
}
|
|
3523
|
-
};
|
|
3524
|
-
exports.ZodBranded = ZodBranded;
|
|
3525
|
-
var ZodPipeline = class ZodPipeline extends ZodType {
|
|
3526
|
-
_parse(input) {
|
|
3527
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3528
|
-
if (ctx.common.async) {
|
|
3529
|
-
const handleAsync = async () => {
|
|
3530
|
-
const inResult = await this._def.in._parseAsync({
|
|
3531
|
-
data: ctx.data,
|
|
3532
|
-
path: ctx.path,
|
|
3533
|
-
parent: ctx
|
|
3534
|
-
});
|
|
3535
|
-
if (inResult.status === "aborted") return parseUtil_js_1.INVALID;
|
|
3536
|
-
if (inResult.status === "dirty") {
|
|
3537
|
-
status.dirty();
|
|
3538
|
-
return (0, parseUtil_js_1.DIRTY)(inResult.value);
|
|
3539
|
-
} else return this._def.out._parseAsync({
|
|
3540
|
-
data: inResult.value,
|
|
3541
|
-
path: ctx.path,
|
|
3542
|
-
parent: ctx
|
|
3543
|
-
});
|
|
3544
|
-
};
|
|
3545
|
-
return handleAsync();
|
|
3546
|
-
} else {
|
|
3547
|
-
const inResult = this._def.in._parseSync({
|
|
3548
|
-
data: ctx.data,
|
|
3549
|
-
path: ctx.path,
|
|
3550
|
-
parent: ctx
|
|
3551
|
-
});
|
|
3552
|
-
if (inResult.status === "aborted") return parseUtil_js_1.INVALID;
|
|
3553
|
-
if (inResult.status === "dirty") {
|
|
3554
|
-
status.dirty();
|
|
3555
|
-
return {
|
|
3556
|
-
status: "dirty",
|
|
3557
|
-
value: inResult.value
|
|
3558
|
-
};
|
|
3559
|
-
} else return this._def.out._parseSync({
|
|
3560
|
-
data: inResult.value,
|
|
3561
|
-
path: ctx.path,
|
|
3562
|
-
parent: ctx
|
|
3563
|
-
});
|
|
3564
|
-
}
|
|
3565
|
-
}
|
|
3566
|
-
static create(a, b) {
|
|
3567
|
-
return new ZodPipeline({
|
|
3568
|
-
in: a,
|
|
3569
|
-
out: b,
|
|
3570
|
-
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
3571
|
-
});
|
|
3572
|
-
}
|
|
3573
|
-
};
|
|
3574
|
-
exports.ZodPipeline = ZodPipeline;
|
|
3575
|
-
var ZodReadonly = class extends ZodType {
|
|
3576
|
-
_parse(input) {
|
|
3577
|
-
const result = this._def.innerType._parse(input);
|
|
3578
|
-
const freeze = (data) => {
|
|
3579
|
-
if ((0, parseUtil_js_1.isValid)(data)) data.value = Object.freeze(data.value);
|
|
3580
|
-
return data;
|
|
3581
|
-
};
|
|
3582
|
-
return (0, parseUtil_js_1.isAsync)(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
3583
|
-
}
|
|
3584
|
-
unwrap() {
|
|
3585
|
-
return this._def.innerType;
|
|
3586
|
-
}
|
|
3587
|
-
};
|
|
3588
|
-
exports.ZodReadonly = ZodReadonly;
|
|
3589
|
-
ZodReadonly.create = (type, params) => {
|
|
3590
|
-
return new ZodReadonly({
|
|
3591
|
-
innerType: type,
|
|
3592
|
-
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
3593
|
-
...processCreateParams(params)
|
|
3594
|
-
});
|
|
3595
|
-
};
|
|
3596
|
-
function cleanParams(params, data) {
|
|
3597
|
-
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
3598
|
-
return typeof p === "string" ? { message: p } : p;
|
|
3599
|
-
}
|
|
3600
|
-
function custom(check, _params = {}, fatal) {
|
|
3601
|
-
if (check) return ZodAny.create().superRefine((data, ctx) => {
|
|
3602
|
-
const r = check(data);
|
|
3603
|
-
if (r instanceof Promise) return r.then((r) => {
|
|
3604
|
-
if (!r) {
|
|
3605
|
-
const params = cleanParams(_params, data);
|
|
3606
|
-
const _fatal = params.fatal ?? fatal ?? true;
|
|
3607
|
-
ctx.addIssue({
|
|
3608
|
-
code: "custom",
|
|
3609
|
-
...params,
|
|
3610
|
-
fatal: _fatal
|
|
3611
|
-
});
|
|
3612
|
-
}
|
|
3613
|
-
});
|
|
3614
|
-
if (!r) {
|
|
3615
|
-
const params = cleanParams(_params, data);
|
|
3616
|
-
const _fatal = params.fatal ?? fatal ?? true;
|
|
3617
|
-
ctx.addIssue({
|
|
3618
|
-
code: "custom",
|
|
3619
|
-
...params,
|
|
3620
|
-
fatal: _fatal
|
|
3621
|
-
});
|
|
3622
|
-
}
|
|
3623
|
-
});
|
|
3624
|
-
return ZodAny.create();
|
|
3625
|
-
}
|
|
3626
|
-
exports.late = { object: ZodObject.lazycreate };
|
|
3627
|
-
var ZodFirstPartyTypeKind;
|
|
3628
|
-
(function(ZodFirstPartyTypeKind) {
|
|
3629
|
-
ZodFirstPartyTypeKind["ZodString"] = "ZodString";
|
|
3630
|
-
ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
|
|
3631
|
-
ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
|
|
3632
|
-
ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
|
|
3633
|
-
ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
|
|
3634
|
-
ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
|
|
3635
|
-
ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
|
|
3636
|
-
ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
|
|
3637
|
-
ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
|
|
3638
|
-
ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
|
|
3639
|
-
ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
|
|
3640
|
-
ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
|
|
3641
|
-
ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
|
|
3642
|
-
ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
|
|
3643
|
-
ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
|
|
3644
|
-
ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
|
|
3645
|
-
ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
3646
|
-
ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
|
|
3647
|
-
ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
|
|
3648
|
-
ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
|
|
3649
|
-
ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
|
|
3650
|
-
ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
|
|
3651
|
-
ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
|
|
3652
|
-
ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
|
|
3653
|
-
ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
|
|
3654
|
-
ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
|
|
3655
|
-
ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
|
|
3656
|
-
ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
|
|
3657
|
-
ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
|
|
3658
|
-
ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
|
|
3659
|
-
ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
|
|
3660
|
-
ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
|
|
3661
|
-
ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
|
|
3662
|
-
ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
|
|
3663
|
-
ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
|
|
3664
|
-
ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
|
|
3665
|
-
})(ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = ZodFirstPartyTypeKind = {}));
|
|
3666
|
-
const instanceOfType = (cls, params = { message: `Input not instance of ${cls.name}` }) => custom((data) => data instanceof cls, params);
|
|
3667
|
-
exports.instanceof = instanceOfType;
|
|
3668
|
-
const stringType = ZodString.create;
|
|
3669
|
-
exports.string = stringType;
|
|
3670
|
-
const numberType = ZodNumber.create;
|
|
3671
|
-
exports.number = numberType;
|
|
3672
|
-
const nanType = ZodNaN.create;
|
|
3673
|
-
exports.nan = nanType;
|
|
3674
|
-
const bigIntType = ZodBigInt.create;
|
|
3675
|
-
exports.bigint = bigIntType;
|
|
3676
|
-
const booleanType = ZodBoolean.create;
|
|
3677
|
-
exports.boolean = booleanType;
|
|
3678
|
-
const dateType = ZodDate.create;
|
|
3679
|
-
exports.date = dateType;
|
|
3680
|
-
const symbolType = ZodSymbol.create;
|
|
3681
|
-
exports.symbol = symbolType;
|
|
3682
|
-
const undefinedType = ZodUndefined.create;
|
|
3683
|
-
exports.undefined = undefinedType;
|
|
3684
|
-
const nullType = ZodNull.create;
|
|
3685
|
-
exports.null = nullType;
|
|
3686
|
-
const anyType = ZodAny.create;
|
|
3687
|
-
exports.any = anyType;
|
|
3688
|
-
const unknownType = ZodUnknown.create;
|
|
3689
|
-
exports.unknown = unknownType;
|
|
3690
|
-
const neverType = ZodNever.create;
|
|
3691
|
-
exports.never = neverType;
|
|
3692
|
-
const voidType = ZodVoid.create;
|
|
3693
|
-
exports.void = voidType;
|
|
3694
|
-
const arrayType = ZodArray.create;
|
|
3695
|
-
exports.array = arrayType;
|
|
3696
|
-
const objectType = ZodObject.create;
|
|
3697
|
-
exports.object = objectType;
|
|
3698
|
-
const strictObjectType = ZodObject.strictCreate;
|
|
3699
|
-
exports.strictObject = strictObjectType;
|
|
3700
|
-
const unionType = ZodUnion.create;
|
|
3701
|
-
exports.union = unionType;
|
|
3702
|
-
const discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
3703
|
-
exports.discriminatedUnion = discriminatedUnionType;
|
|
3704
|
-
const intersectionType = ZodIntersection.create;
|
|
3705
|
-
exports.intersection = intersectionType;
|
|
3706
|
-
const tupleType = ZodTuple.create;
|
|
3707
|
-
exports.tuple = tupleType;
|
|
3708
|
-
const recordType = ZodRecord.create;
|
|
3709
|
-
exports.record = recordType;
|
|
3710
|
-
const mapType = ZodMap.create;
|
|
3711
|
-
exports.map = mapType;
|
|
3712
|
-
const setType = ZodSet.create;
|
|
3713
|
-
exports.set = setType;
|
|
3714
|
-
const functionType = ZodFunction.create;
|
|
3715
|
-
exports.function = functionType;
|
|
3716
|
-
const lazyType = ZodLazy.create;
|
|
3717
|
-
exports.lazy = lazyType;
|
|
3718
|
-
const literalType = ZodLiteral.create;
|
|
3719
|
-
exports.literal = literalType;
|
|
3720
|
-
const enumType = ZodEnum.create;
|
|
3721
|
-
exports.enum = enumType;
|
|
3722
|
-
const nativeEnumType = ZodNativeEnum.create;
|
|
3723
|
-
exports.nativeEnum = nativeEnumType;
|
|
3724
|
-
const promiseType = ZodPromise.create;
|
|
3725
|
-
exports.promise = promiseType;
|
|
3726
|
-
const effectsType = ZodEffects.create;
|
|
3727
|
-
exports.effect = effectsType;
|
|
3728
|
-
exports.transformer = effectsType;
|
|
3729
|
-
const optionalType = ZodOptional.create;
|
|
3730
|
-
exports.optional = optionalType;
|
|
3731
|
-
const nullableType = ZodNullable.create;
|
|
3732
|
-
exports.nullable = nullableType;
|
|
3733
|
-
const preprocessType = ZodEffects.createWithPreprocess;
|
|
3734
|
-
exports.preprocess = preprocessType;
|
|
3735
|
-
const pipelineType = ZodPipeline.create;
|
|
3736
|
-
exports.pipeline = pipelineType;
|
|
3737
|
-
const ostring = () => stringType().optional();
|
|
3738
|
-
exports.ostring = ostring;
|
|
3739
|
-
const onumber = () => numberType().optional();
|
|
3740
|
-
exports.onumber = onumber;
|
|
3741
|
-
const oboolean = () => booleanType().optional();
|
|
3742
|
-
exports.oboolean = oboolean;
|
|
3743
|
-
exports.coerce = {
|
|
3744
|
-
string: ((arg) => ZodString.create({
|
|
3745
|
-
...arg,
|
|
3746
|
-
coerce: true
|
|
3747
|
-
})),
|
|
3748
|
-
number: ((arg) => ZodNumber.create({
|
|
3749
|
-
...arg,
|
|
3750
|
-
coerce: true
|
|
3751
|
-
})),
|
|
3752
|
-
boolean: ((arg) => ZodBoolean.create({
|
|
3753
|
-
...arg,
|
|
3754
|
-
coerce: true
|
|
3755
|
-
})),
|
|
3756
|
-
bigint: ((arg) => ZodBigInt.create({
|
|
3757
|
-
...arg,
|
|
3758
|
-
coerce: true
|
|
3759
|
-
})),
|
|
3760
|
-
date: ((arg) => ZodDate.create({
|
|
3761
|
-
...arg,
|
|
3762
|
-
coerce: true
|
|
3763
|
-
}))
|
|
3764
|
-
};
|
|
3765
|
-
exports.NEVER = parseUtil_js_1.INVALID;
|
|
3766
|
-
}));
|
|
3767
|
-
|
|
3768
|
-
//#endregion
|
|
3769
|
-
//#region ../agent-provider/node_modules/zod/v3/external.cjs
|
|
3770
|
-
var require_external = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
3771
|
-
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
3772
|
-
if (k2 === void 0) k2 = k;
|
|
3773
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
3774
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = {
|
|
3775
|
-
enumerable: true,
|
|
3776
|
-
get: function() {
|
|
3777
|
-
return m[k];
|
|
3778
|
-
}
|
|
3779
|
-
};
|
|
3780
|
-
Object.defineProperty(o, k2, desc);
|
|
3781
|
-
}) : (function(o, m, k, k2) {
|
|
3782
|
-
if (k2 === void 0) k2 = k;
|
|
3783
|
-
o[k2] = m[k];
|
|
3784
|
-
}));
|
|
3785
|
-
var __exportStar = exports && exports.__exportStar || function(m, exports$6) {
|
|
3786
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports$6, p)) __createBinding(exports$6, m, p);
|
|
3787
|
-
};
|
|
3788
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3789
|
-
__exportStar(require_errors$1(), exports);
|
|
3790
|
-
__exportStar(require_parseUtil(), exports);
|
|
3791
|
-
__exportStar(require_typeAliases(), exports);
|
|
3792
|
-
__exportStar(require_util(), exports);
|
|
3793
|
-
__exportStar(require_types$4(), exports);
|
|
3794
|
-
__exportStar(require_ZodError(), exports);
|
|
3795
|
-
}));
|
|
3796
|
-
|
|
3797
|
-
//#endregion
|
|
3798
|
-
//#region ../agent-provider/node_modules/zod/index.cjs
|
|
3799
|
-
var require_zod = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
3800
|
-
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
3801
|
-
if (k2 === void 0) k2 = k;
|
|
3802
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
3803
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = {
|
|
3804
|
-
enumerable: true,
|
|
3805
|
-
get: function() {
|
|
3806
|
-
return m[k];
|
|
3807
|
-
}
|
|
3808
|
-
};
|
|
3809
|
-
Object.defineProperty(o, k2, desc);
|
|
3810
|
-
}) : (function(o, m, k, k2) {
|
|
3811
|
-
if (k2 === void 0) k2 = k;
|
|
3812
|
-
o[k2] = m[k];
|
|
3813
|
-
}));
|
|
3814
|
-
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
3815
|
-
Object.defineProperty(o, "default", {
|
|
3816
|
-
enumerable: true,
|
|
3817
|
-
value: v
|
|
3818
|
-
});
|
|
3819
|
-
}) : function(o, v) {
|
|
3820
|
-
o["default"] = v;
|
|
3821
|
-
});
|
|
3822
|
-
var __importStar = exports && exports.__importStar || function(mod) {
|
|
3823
|
-
if (mod && mod.__esModule) return mod;
|
|
3824
|
-
var result = {};
|
|
3825
|
-
if (mod != null) {
|
|
3826
|
-
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
3827
|
-
}
|
|
3828
|
-
__setModuleDefault(result, mod);
|
|
3829
|
-
return result;
|
|
3830
|
-
};
|
|
3831
|
-
var __exportStar = exports && exports.__exportStar || function(m, exports$5) {
|
|
3832
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports$5, p)) __createBinding(exports$5, m, p);
|
|
3833
|
-
};
|
|
3834
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3835
|
-
exports.z = void 0;
|
|
3836
|
-
const z = __importStar(require_external());
|
|
3837
|
-
exports.z = z;
|
|
3838
|
-
__exportStar(require_external(), exports);
|
|
3839
|
-
exports.default = z;
|
|
3840
|
-
}));
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
6
|
+
});
|
|
3841
7
|
|
|
3842
8
|
//#endregion
|
|
3843
9
|
//#region ../agent-provider/lib/common/_legacy/tool-schemas.js
|
|
@@ -3852,7 +18,7 @@ var require_tool_schemas = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
3852
18
|
exports.ToolOutputSchemas = exports.ToolInputSchemas = void 0;
|
|
3853
19
|
exports.validateToolInput = validateToolInput;
|
|
3854
20
|
exports.validateToolOutput = validateToolOutput;
|
|
3855
|
-
const zod_1 =
|
|
21
|
+
const zod_1 = __require("zod");
|
|
3856
22
|
/**
|
|
3857
23
|
* 工具输入 Schema 定义
|
|
3858
24
|
* 用于验证和约束 rawInput
|
|
@@ -7327,7 +3493,8 @@ var require_types$3 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
7327
3493
|
exports.ExtensionMethod = {
|
|
7328
3494
|
ARTIFACT: "_codebuddy.ai/artifact",
|
|
7329
3495
|
QUESTION: "_codebuddy.ai/question",
|
|
7330
|
-
CHECKPOINT: "_codebuddy.ai/checkpoint"
|
|
3496
|
+
CHECKPOINT: "_codebuddy.ai/checkpoint",
|
|
3497
|
+
USAGE: "_codebuddy.ai/usage"
|
|
7331
3498
|
};
|
|
7332
3499
|
/**
|
|
7333
3500
|
* All known extension methods
|
|
@@ -7335,7 +3502,8 @@ var require_types$3 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
7335
3502
|
exports.KNOWN_EXTENSIONS = [
|
|
7336
3503
|
exports.ExtensionMethod.ARTIFACT,
|
|
7337
3504
|
exports.ExtensionMethod.QUESTION,
|
|
7338
|
-
exports.ExtensionMethod.CHECKPOINT
|
|
3505
|
+
exports.ExtensionMethod.CHECKPOINT,
|
|
3506
|
+
exports.ExtensionMethod.USAGE
|
|
7339
3507
|
];
|
|
7340
3508
|
}));
|
|
7341
3509
|
|
|
@@ -7938,14 +4106,14 @@ var require_artifacts = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
7938
4106
|
const { event } = notification;
|
|
7939
4107
|
if (event === "deleted") {
|
|
7940
4108
|
const { artifact } = notification;
|
|
7941
|
-
const existing = this.artifacts.get(artifact.
|
|
7942
|
-
(_a = this.logger) === null || _a === void 0 || _a.debug(`Artifact deleted: ${artifact.
|
|
7943
|
-
this.artifacts.delete(artifact.
|
|
4109
|
+
const existing = this.artifacts.get(artifact.uri);
|
|
4110
|
+
(_a = this.logger) === null || _a === void 0 || _a.debug(`Artifact deleted: ${artifact.uri}`);
|
|
4111
|
+
this.artifacts.delete(artifact.uri);
|
|
7944
4112
|
if (existing) this.notifyCallbacks(existing, event);
|
|
7945
4113
|
} else {
|
|
7946
4114
|
const { artifact } = notification;
|
|
7947
|
-
(_b = this.logger) === null || _b === void 0 || _b.debug(`Artifact ${event}: ${artifact.
|
|
7948
|
-
this.artifacts.set(artifact.
|
|
4115
|
+
(_b = this.logger) === null || _b === void 0 || _b.debug(`Artifact ${event}: ${artifact.uri} (${artifact.type})`);
|
|
4116
|
+
this.artifacts.set(artifact.uri, artifact);
|
|
7949
4117
|
this.notifyCallbacks(artifact, event);
|
|
7950
4118
|
}
|
|
7951
4119
|
}
|
|
@@ -7958,10 +4126,10 @@ var require_artifacts = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
7958
4126
|
}
|
|
7959
4127
|
}
|
|
7960
4128
|
/**
|
|
7961
|
-
* Get an artifact by
|
|
4129
|
+
* Get an artifact by URI (used internally for deleted event handling)
|
|
7962
4130
|
*/
|
|
7963
|
-
get(
|
|
7964
|
-
return this.artifacts.get(
|
|
4131
|
+
get(uri) {
|
|
4132
|
+
return this.artifacts.get(uri);
|
|
7965
4133
|
}
|
|
7966
4134
|
/**
|
|
7967
4135
|
* Clear all artifacts
|
|
@@ -8154,33 +4322,14 @@ var require_permissions = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
8154
4322
|
var require_questions = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
8155
4323
|
/**
|
|
8156
4324
|
* Question Manager for Streamable HTTP ACP Client
|
|
8157
|
-
* Handles ask_followup_question
|
|
8158
|
-
*
|
|
8159
|
-
* This provides a strongly-typed API for the "question" input type,
|
|
8160
|
-
* while the underlying protocol uses the generic _codebuddy.ai/tool_input extMethod.
|
|
4325
|
+
* Handles ask_followup_question requests with timeout support
|
|
8161
4326
|
*/
|
|
8162
4327
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8163
4328
|
exports.QuestionManager = void 0;
|
|
8164
4329
|
const constants_js_1 = require_constants();
|
|
8165
4330
|
const errors_js_1 = require_errors();
|
|
8166
4331
|
/**
|
|
8167
|
-
* Converts ToolInputRequest to QuestionRequest for client-facing API
|
|
8168
|
-
*/
|
|
8169
|
-
function toQuestionRequest(params) {
|
|
8170
|
-
const schema = params.schema;
|
|
8171
|
-
return {
|
|
8172
|
-
sessionId: params.sessionId,
|
|
8173
|
-
toolCallId: params.toolCallId,
|
|
8174
|
-
questions: schema.questions,
|
|
8175
|
-
timeout: params.timeout,
|
|
8176
|
-
_meta: params._meta
|
|
8177
|
-
};
|
|
8178
|
-
}
|
|
8179
|
-
/**
|
|
8180
4332
|
* Manages question requests from the agent (ask_followup_question tool)
|
|
8181
|
-
*
|
|
8182
|
-
* Provides strongly-typed methods for handling questions while internally
|
|
8183
|
-
* using the generic ToolInputRequest/ToolInputResponse protocol types.
|
|
8184
4333
|
*/
|
|
8185
4334
|
var QuestionManager = class {
|
|
8186
4335
|
constructor(config = {}) {
|
|
@@ -8199,27 +4348,27 @@ var require_questions = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
8199
4348
|
this.callbacks = callbacks;
|
|
8200
4349
|
}
|
|
8201
4350
|
/**
|
|
8202
|
-
* Handle a
|
|
8203
|
-
*
|
|
4351
|
+
* Handle a question request from the agent
|
|
4352
|
+
* Called when receiving _codebuddy.ai/question extMethod
|
|
8204
4353
|
*/
|
|
8205
|
-
async handleRequest(
|
|
4354
|
+
async handleRequest(request) {
|
|
8206
4355
|
var _a;
|
|
8207
|
-
const toolCallId =
|
|
4356
|
+
const toolCallId = request.toolCallId;
|
|
8208
4357
|
(_a = this.config.logger) === null || _a === void 0 || _a.debug(`Question request received: ${toolCallId}`);
|
|
8209
4358
|
return new Promise((resolve, reject) => {
|
|
8210
4359
|
var _a, _b, _c;
|
|
8211
4360
|
const pending = {
|
|
8212
|
-
|
|
4361
|
+
request,
|
|
8213
4362
|
resolve,
|
|
8214
4363
|
reject,
|
|
8215
4364
|
createdAt: Date.now()
|
|
8216
4365
|
};
|
|
8217
|
-
const timeout = (_a =
|
|
4366
|
+
const timeout = (_a = request.timeout) !== null && _a !== void 0 ? _a : this.config.timeout;
|
|
8218
4367
|
if (timeout && timeout > 0) pending.timeoutId = setTimeout(() => {
|
|
8219
4368
|
this.handleTimeout(toolCallId);
|
|
8220
4369
|
}, timeout);
|
|
8221
4370
|
this.pending.set(toolCallId, pending);
|
|
8222
|
-
|
|
4371
|
+
(_c = (_b = this.callbacks).onRequest) === null || _c === void 0 || _c.call(_b, toolCallId, request);
|
|
8223
4372
|
});
|
|
8224
4373
|
}
|
|
8225
4374
|
/**
|
|
@@ -8231,10 +4380,10 @@ var require_questions = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
8231
4380
|
if (!pending) return;
|
|
8232
4381
|
(_a = this.config.logger) === null || _a === void 0 || _a.warn(`Question request timed out: ${toolCallId}`);
|
|
8233
4382
|
(_c = (_b = this.callbacks).onTimeout) === null || _c === void 0 || _c.call(_b, toolCallId);
|
|
8234
|
-
if (this.config.autoCancelOnTimeout) pending.resolve({
|
|
4383
|
+
if (this.config.autoCancelOnTimeout) pending.resolve({
|
|
8235
4384
|
outcome: "cancelled",
|
|
8236
4385
|
reason: "timeout"
|
|
8237
|
-
}
|
|
4386
|
+
});
|
|
8238
4387
|
else pending.reject(new errors_js_1.TimeoutError("question", (_d = this.config.timeout) !== null && _d !== void 0 ? _d : constants_js_1.DEFAULT_QUESTION_TIMEOUT));
|
|
8239
4388
|
this.pending.delete(toolCallId);
|
|
8240
4389
|
}
|
|
@@ -8251,10 +4400,10 @@ var require_questions = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
8251
4400
|
}
|
|
8252
4401
|
if (pending.timeoutId) clearTimeout(pending.timeoutId);
|
|
8253
4402
|
(_b = this.config.logger) === null || _b === void 0 || _b.debug(`Question answered: ${toolCallId}`);
|
|
8254
|
-
pending.resolve({
|
|
4403
|
+
pending.resolve({
|
|
8255
4404
|
outcome: "submitted",
|
|
8256
|
-
|
|
8257
|
-
}
|
|
4405
|
+
answers
|
|
4406
|
+
});
|
|
8258
4407
|
this.pending.delete(toolCallId);
|
|
8259
4408
|
(_d = (_c = this.callbacks).onAnswered) === null || _d === void 0 || _d.call(_c, toolCallId, answers);
|
|
8260
4409
|
return true;
|
|
@@ -8272,10 +4421,10 @@ var require_questions = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
8272
4421
|
}
|
|
8273
4422
|
if (pending.timeoutId) clearTimeout(pending.timeoutId);
|
|
8274
4423
|
(_b = this.config.logger) === null || _b === void 0 || _b.debug(`Question cancelled: ${toolCallId}${reason ? ` - ${reason}` : ""}`);
|
|
8275
|
-
pending.resolve({
|
|
4424
|
+
pending.resolve({
|
|
8276
4425
|
outcome: "cancelled",
|
|
8277
4426
|
reason
|
|
8278
|
-
}
|
|
4427
|
+
});
|
|
8279
4428
|
this.pending.delete(toolCallId);
|
|
8280
4429
|
(_d = (_c = this.callbacks).onCancelled) === null || _d === void 0 || _d.call(_c, toolCallId, reason);
|
|
8281
4430
|
return true;
|
|
@@ -8285,8 +4434,8 @@ var require_questions = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
8285
4434
|
*/
|
|
8286
4435
|
getPending() {
|
|
8287
4436
|
const result = /* @__PURE__ */ new Map();
|
|
8288
|
-
for (const [id, pending] of this.pending)
|
|
8289
|
-
request:
|
|
4437
|
+
for (const [id, pending] of this.pending) result.set(id, {
|
|
4438
|
+
request: pending.request,
|
|
8290
4439
|
createdAt: pending.createdAt
|
|
8291
4440
|
});
|
|
8292
4441
|
return result;
|
|
@@ -8296,9 +4445,9 @@ var require_questions = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
8296
4445
|
*/
|
|
8297
4446
|
getPendingById(toolCallId) {
|
|
8298
4447
|
const pending = this.pending.get(toolCallId);
|
|
8299
|
-
if (!pending
|
|
4448
|
+
if (!pending) return void 0;
|
|
8300
4449
|
return {
|
|
8301
|
-
request:
|
|
4450
|
+
request: pending.request,
|
|
8302
4451
|
createdAt: pending.createdAt
|
|
8303
4452
|
};
|
|
8304
4453
|
}
|
|
@@ -8321,10 +4470,10 @@ var require_questions = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
8321
4470
|
var _a, _b, _c;
|
|
8322
4471
|
for (const [toolCallId, pending] of this.pending) {
|
|
8323
4472
|
if (pending.timeoutId) clearTimeout(pending.timeoutId);
|
|
8324
|
-
pending.resolve({
|
|
4473
|
+
pending.resolve({
|
|
8325
4474
|
outcome: "cancelled",
|
|
8326
4475
|
reason: "cleared"
|
|
8327
|
-
}
|
|
4476
|
+
});
|
|
8328
4477
|
(_b = (_a = this.callbacks).onCancelled) === null || _b === void 0 || _b.call(_a, toolCallId, "cleared");
|
|
8329
4478
|
}
|
|
8330
4479
|
this.pending.clear();
|
|
@@ -8691,7 +4840,7 @@ var require_client$3 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
8691
4840
|
await this.handleExtNotification(method, params);
|
|
8692
4841
|
},
|
|
8693
4842
|
extMethod: async (method, params) => {
|
|
8694
|
-
return this.handleExtMethod(method, params);
|
|
4843
|
+
return await this.handleExtMethod(method, params);
|
|
8695
4844
|
}
|
|
8696
4845
|
};
|
|
8697
4846
|
}
|
|
@@ -8869,18 +5018,17 @@ var require_client$3 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
8869
5018
|
return this.permissionManager.handleRequest(params);
|
|
8870
5019
|
}
|
|
8871
5020
|
async handleExtNotification(method, params) {
|
|
8872
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k
|
|
5021
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
8873
5022
|
if (method === constants_js_1.ExtensionMethod.ARTIFACT) {
|
|
8874
5023
|
const notification = params;
|
|
8875
5024
|
const artifactData = notification.artifact;
|
|
8876
5025
|
console.log("[ACP-Client] Received artifact notification:", {
|
|
8877
5026
|
event: notification.event,
|
|
8878
|
-
|
|
8879
|
-
artifactType: artifactData === null || artifactData === void 0 ? void 0 : artifactData.type
|
|
8880
|
-
rawMeta: artifactData === null || artifactData === void 0 ? void 0 : artifactData._meta
|
|
5027
|
+
artifactUri: artifactData === null || artifactData === void 0 ? void 0 : artifactData.uri,
|
|
5028
|
+
artifactType: artifactData === null || artifactData === void 0 ? void 0 : artifactData.type
|
|
8881
5029
|
});
|
|
8882
5030
|
if (notification.event === "deleted") {
|
|
8883
|
-
const existing = this.artifactManager.get(notification.artifact.
|
|
5031
|
+
const existing = this.artifactManager.get(notification.artifact.uri);
|
|
8884
5032
|
this.artifactManager.handleNotification(notification);
|
|
8885
5033
|
if (existing) {
|
|
8886
5034
|
await ((_b = (_a = this.options).onArtifact) === null || _b === void 0 ? void 0 : _b.call(_a, existing, "deleted"));
|
|
@@ -8889,30 +5037,28 @@ var require_client$3 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
8889
5037
|
} else {
|
|
8890
5038
|
const { artifact, event } = notification;
|
|
8891
5039
|
this.artifactManager.handleNotification(notification);
|
|
8892
|
-
const
|
|
8893
|
-
console.log("[ACP-Client]
|
|
5040
|
+
const storedArtifact = this.artifactManager.get(artifact.uri) || artifact;
|
|
5041
|
+
console.log("[ACP-Client] Stored artifact:", {
|
|
8894
5042
|
event,
|
|
8895
|
-
|
|
8896
|
-
artifactType:
|
|
8897
|
-
|
|
8898
|
-
hasContent: !!((_c = normalizedArtifact._meta) === null || _c === void 0 ? void 0 : _c.content),
|
|
8899
|
-
hasOverview: !!((_d = normalizedArtifact._meta) === null || _d === void 0 ? void 0 : _d.overview)
|
|
5043
|
+
artifactUri: storedArtifact.uri,
|
|
5044
|
+
artifactType: storedArtifact.type,
|
|
5045
|
+
hasText: storedArtifact.type === "plan" ? !!storedArtifact.text : void 0
|
|
8900
5046
|
});
|
|
8901
|
-
await ((
|
|
5047
|
+
await ((_d = (_c = this.options).onArtifact) === null || _d === void 0 ? void 0 : _d.call(_c, storedArtifact, event));
|
|
8902
5048
|
if (event === "created") {
|
|
8903
5049
|
console.log("[ACP-Client] Emitting artifactCreated event");
|
|
8904
|
-
this.emitter.emit("artifactCreated",
|
|
8905
|
-
if (
|
|
5050
|
+
this.emitter.emit("artifactCreated", storedArtifact);
|
|
5051
|
+
if (storedArtifact.type === "plan") await ((_f = (_e = this.options).onPlanReady) === null || _f === void 0 ? void 0 : _f.call(_e, storedArtifact));
|
|
8906
5052
|
} else {
|
|
8907
5053
|
console.log("[ACP-Client] Emitting artifactUpdated event");
|
|
8908
|
-
this.emitter.emit("artifactUpdated",
|
|
5054
|
+
this.emitter.emit("artifactUpdated", storedArtifact);
|
|
8909
5055
|
}
|
|
8910
5056
|
}
|
|
8911
5057
|
return;
|
|
8912
5058
|
}
|
|
8913
|
-
if (method ===
|
|
5059
|
+
if (method === constants_js_1.ExtensionMethod.USAGE) {
|
|
8914
5060
|
const usage = (0, extensions_js_1.parseUsageUpdate)(params);
|
|
8915
|
-
await ((
|
|
5061
|
+
await ((_h = (_g = this.options).onUsageUpdate) === null || _h === void 0 ? void 0 : _h.call(_g, usage));
|
|
8916
5062
|
this.emitter.emit("usageUpdate", usage);
|
|
8917
5063
|
return;
|
|
8918
5064
|
}
|
|
@@ -8922,17 +5068,17 @@ var require_client$3 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
8922
5068
|
else if (notification.event === "updated") this.emitter.emit("checkpointUpdated", notification.checkpoint);
|
|
8923
5069
|
return;
|
|
8924
5070
|
}
|
|
8925
|
-
await ((
|
|
5071
|
+
await ((_k = (_j = this.options).onExtNotification) === null || _k === void 0 ? void 0 : _k.call(_j, method, params));
|
|
8926
5072
|
await this.extensionManager.handleNotification(method, params);
|
|
8927
5073
|
}
|
|
8928
5074
|
async handleExtMethod(method, params) {
|
|
8929
5075
|
var _a;
|
|
8930
|
-
if (method === constants_js_1.ExtensionMethod.QUESTION)
|
|
8931
|
-
const request = params;
|
|
8932
|
-
return await this.questionManager.handleRequest(request);
|
|
8933
|
-
}
|
|
5076
|
+
if (method === constants_js_1.ExtensionMethod.QUESTION) return this.questionManager.handleRequest(params);
|
|
8934
5077
|
(_a = this.options.logger) === null || _a === void 0 || _a.warn(`Unknown extension method: ${method}`);
|
|
8935
|
-
return {
|
|
5078
|
+
return {
|
|
5079
|
+
outcome: "cancelled",
|
|
5080
|
+
reason: "unknown method"
|
|
5081
|
+
};
|
|
8936
5082
|
}
|
|
8937
5083
|
ensureInitialized(operation) {
|
|
8938
5084
|
if (this.state !== "initialized") throw new errors_js_1.InvalidStateError(operation, this.state, ["initialized"]);
|
|
@@ -9178,9 +5324,8 @@ var require_cloud_connection = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
9178
5324
|
onArtifact: (artifact, event) => {
|
|
9179
5325
|
console.log("[CloudConnection] onArtifact callback:", {
|
|
9180
5326
|
event,
|
|
9181
|
-
|
|
9182
|
-
artifactType: artifact.type
|
|
9183
|
-
metaKeys: artifact._meta ? Object.keys(artifact._meta) : []
|
|
5327
|
+
artifactUri: artifact.uri,
|
|
5328
|
+
artifactType: artifact.type
|
|
9184
5329
|
});
|
|
9185
5330
|
if (event === "created") this.emit("artifactCreated", artifact);
|
|
9186
5331
|
else if (event === "updated") this.emit("artifactUpdated", artifact);
|
|
@@ -10662,11 +6807,11 @@ var require_local_connection = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
10662
6807
|
const artifact = params.artifact;
|
|
10663
6808
|
console.log("[LocalConnection] Emitting artifact event:", {
|
|
10664
6809
|
event,
|
|
10665
|
-
|
|
6810
|
+
artifactUri: artifact === null || artifact === void 0 ? void 0 : artifact.uri
|
|
10666
6811
|
});
|
|
10667
|
-
if (artifact === null || artifact === void 0 ? void 0 : artifact.
|
|
10668
|
-
if (event === "created" || event === "updated") this.artifactCache.set(artifact.
|
|
10669
|
-
else if (event === "deleted") this.artifactCache.delete(artifact.
|
|
6812
|
+
if (artifact === null || artifact === void 0 ? void 0 : artifact.uri) {
|
|
6813
|
+
if (event === "created" || event === "updated") this.artifactCache.set(artifact.uri, artifact);
|
|
6814
|
+
else if (event === "deleted") this.artifactCache.delete(artifact.uri);
|
|
10670
6815
|
}
|
|
10671
6816
|
if (event === "created") this.emit("artifactCreated", artifact);
|
|
10672
6817
|
else if (event === "updated") this.emit("artifactUpdated", artifact);
|
|
@@ -10870,8 +7015,8 @@ var require_local_connection = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
10870
7015
|
getArtifacts() {
|
|
10871
7016
|
return new Map(this.artifactCache);
|
|
10872
7017
|
}
|
|
10873
|
-
getArtifact(
|
|
10874
|
-
return this.artifactCache.get(
|
|
7018
|
+
getArtifact(uri) {
|
|
7019
|
+
return this.artifactCache.get(uri);
|
|
10875
7020
|
}
|
|
10876
7021
|
getArtifactsByType(type) {
|
|
10877
7022
|
return Array.from(this.artifactCache.values()).filter((artifact) => artifact.type === type);
|
|
@@ -11586,25 +7731,8 @@ var require_local_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
11586
7731
|
* @returns 包含归档的 session ID 的对象
|
|
11587
7732
|
*/
|
|
11588
7733
|
async archive(sessionId) {
|
|
11589
|
-
|
|
11590
|
-
|
|
11591
|
-
try {
|
|
11592
|
-
const response = await this.channel.callMethod("__backend__", {
|
|
11593
|
-
type: "backend",
|
|
11594
|
-
requestId: `req-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
11595
|
-
params: {
|
|
11596
|
-
type: "backend:archive-session-request",
|
|
11597
|
-
params: { sessionId }
|
|
11598
|
-
}
|
|
11599
|
-
}, 5e3);
|
|
11600
|
-
if (!((_a = response.data) === null || _a === void 0 ? void 0 : _a.success)) throw new Error(((_b = response.data) === null || _b === void 0 ? void 0 : _b.error) || "Archive failed");
|
|
11601
|
-
this.sessionCwdMap.delete(sessionId);
|
|
11602
|
-
this.log(`Session archived: ${sessionId}`);
|
|
11603
|
-
return { id: sessionId };
|
|
11604
|
-
} catch (error) {
|
|
11605
|
-
this.log(`Failed to archive session ${sessionId}:`, error);
|
|
11606
|
-
throw error;
|
|
11607
|
-
}
|
|
7734
|
+
await this.delete(sessionId);
|
|
7735
|
+
return { id: sessionId };
|
|
11608
7736
|
}
|
|
11609
7737
|
/**
|
|
11610
7738
|
* 注册 sessionId → cwd 映射
|
|
@@ -11712,6 +7840,41 @@ var require_local_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
11712
7840
|
}
|
|
11713
7841
|
}
|
|
11714
7842
|
/**
|
|
7843
|
+
* 选择文件夹
|
|
7844
|
+
* 通过 BackendService 的 __backend__ session 处理
|
|
7845
|
+
*
|
|
7846
|
+
* @param params 文件夹选择参数
|
|
7847
|
+
* @returns 选择结果
|
|
7848
|
+
*/
|
|
7849
|
+
async pickFolder(params) {
|
|
7850
|
+
var _a;
|
|
7851
|
+
this.log("Picking folder:", params);
|
|
7852
|
+
try {
|
|
7853
|
+
const response = await this.channel.callMethod("__backend__", {
|
|
7854
|
+
type: "backend",
|
|
7855
|
+
requestId: `req-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
7856
|
+
params: {
|
|
7857
|
+
type: "backend:pick-folder",
|
|
7858
|
+
params
|
|
7859
|
+
}
|
|
7860
|
+
}, 3e4);
|
|
7861
|
+
this.log("pickFolder() response:", response.data);
|
|
7862
|
+
const data = response.data;
|
|
7863
|
+
return {
|
|
7864
|
+
folderPaths: (data === null || data === void 0 ? void 0 : data.paths) || [],
|
|
7865
|
+
canceled: (_a = data === null || data === void 0 ? void 0 : data.cancelled) !== null && _a !== void 0 ? _a : true,
|
|
7866
|
+
error: data === null || data === void 0 ? void 0 : data.error
|
|
7867
|
+
};
|
|
7868
|
+
} catch (error) {
|
|
7869
|
+
this.log("pickFolder() failed:", error);
|
|
7870
|
+
return {
|
|
7871
|
+
folderPaths: [],
|
|
7872
|
+
canceled: true,
|
|
7873
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
7874
|
+
};
|
|
7875
|
+
}
|
|
7876
|
+
}
|
|
7877
|
+
/**
|
|
11715
7878
|
* 获取当前工作区列表
|
|
11716
7879
|
* 这是 LocalAgentProvider 特有的能力,通过 shared ACP client 发送请求,
|
|
11717
7880
|
* 使用 __workspace__ session ID,由 Main Process 直接处理
|
|
@@ -12308,22 +8471,20 @@ var require_session = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
12308
8471
|
});
|
|
12309
8472
|
connection.on("artifactCreated", (artifact) => {
|
|
12310
8473
|
console.log("[Session] Forwarding artifactCreated:", {
|
|
12311
|
-
|
|
12312
|
-
artifactType: artifact.type
|
|
12313
|
-
metaKeys: artifact._meta ? Object.keys(artifact._meta) : []
|
|
8474
|
+
artifactUri: artifact.uri,
|
|
8475
|
+
artifactType: artifact.type
|
|
12314
8476
|
});
|
|
12315
8477
|
this.emit("artifactCreated", artifact);
|
|
12316
8478
|
});
|
|
12317
8479
|
connection.on("artifactUpdated", (artifact) => {
|
|
12318
8480
|
console.log("[Session] Forwarding artifactUpdated:", {
|
|
12319
|
-
|
|
12320
|
-
artifactType: artifact.type
|
|
12321
|
-
metaKeys: artifact._meta ? Object.keys(artifact._meta) : []
|
|
8481
|
+
artifactUri: artifact.uri,
|
|
8482
|
+
artifactType: artifact.type
|
|
12322
8483
|
});
|
|
12323
8484
|
this.emit("artifactUpdated", artifact);
|
|
12324
8485
|
});
|
|
12325
8486
|
connection.on("artifactDeleted", (artifact) => {
|
|
12326
|
-
console.log("[Session] Forwarding artifactDeleted:", {
|
|
8487
|
+
console.log("[Session] Forwarding artifactDeleted:", { artifactUri: artifact.uri });
|
|
12327
8488
|
this.emit("artifactDeleted", artifact);
|
|
12328
8489
|
});
|
|
12329
8490
|
connection.on("permissionRequest", (request) => {
|
|
@@ -12693,6 +8854,31 @@ var require_client$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
12693
8854
|
};
|
|
12694
8855
|
}
|
|
12695
8856
|
},
|
|
8857
|
+
pickFolder: async (params) => {
|
|
8858
|
+
var _a, _b;
|
|
8859
|
+
try {
|
|
8860
|
+
if (this.provider && this.provider.pickFolder) {
|
|
8861
|
+
const result = await this.provider.pickFolder(params);
|
|
8862
|
+
(_a = this.logger) === null || _a === void 0 || _a.info("Folder picker completed", {
|
|
8863
|
+
folderPaths: result.folderPaths,
|
|
8864
|
+
canceled: result.canceled
|
|
8865
|
+
});
|
|
8866
|
+
return result;
|
|
8867
|
+
}
|
|
8868
|
+
return {
|
|
8869
|
+
folderPaths: [],
|
|
8870
|
+
canceled: true,
|
|
8871
|
+
error: "Provider does not support pickFolder"
|
|
8872
|
+
};
|
|
8873
|
+
} catch (error) {
|
|
8874
|
+
(_b = this.logger) === null || _b === void 0 || _b.error("Failed to pick folder", error);
|
|
8875
|
+
return {
|
|
8876
|
+
folderPaths: [],
|
|
8877
|
+
canceled: true,
|
|
8878
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
8879
|
+
};
|
|
8880
|
+
}
|
|
8881
|
+
},
|
|
12696
8882
|
models: this.createModelsResource()
|
|
12697
8883
|
};
|
|
12698
8884
|
}
|
|
@@ -14687,6 +10873,28 @@ var require_types = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
14687
10873
|
* 定义 IBackendProvider 接口和配置
|
|
14688
10874
|
*/
|
|
14689
10875
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10876
|
+
exports.CommodityCode = void 0;
|
|
10877
|
+
/**
|
|
10878
|
+
* 套餐代码
|
|
10879
|
+
*/
|
|
10880
|
+
/**
|
|
10881
|
+
* TCACA_code_001_PqouKr6QWV CodeBuddy海外版免费包
|
|
10882
|
+
* TCACA_code_002_AkiJS3ZHF5 CodeBuddy海外版Pro版本包-包月/CodeBuddy Pro Plan - Monthly:
|
|
10883
|
+
* TCACA_code_006_DbXS0lrypC CodeBuddy海外版一次性免费赠送2周的Pro版本包/CodeBuddy One-time Free 2-Week Pro Plan Trial
|
|
10884
|
+
* TCACA_code_007_nzdH5h4Nl0 CodeBuddy海外版运营裂变包/CodeBuddy Growth Plan
|
|
10885
|
+
* TCACA_code_003_FAnt7lcmRT CodeBuddy海外版Pro版本包-包年/CodeBuddy Pro Plan - Yearly
|
|
10886
|
+
* TCACA_code_008_cfWoLwvjU4 赠送月包
|
|
10887
|
+
*/
|
|
10888
|
+
var CommodityCode;
|
|
10889
|
+
(function(CommodityCode) {
|
|
10890
|
+
CommodityCode["free"] = "TCACA_code_001_PqouKr6QWV";
|
|
10891
|
+
CommodityCode["proMon"] = "TCACA_code_002_AkiJS3ZHF5";
|
|
10892
|
+
CommodityCode["gift"] = "TCACA_code_006_DbXS0lrypC";
|
|
10893
|
+
CommodityCode["activity"] = "TCACA_code_007_nzdH5h4Nl0";
|
|
10894
|
+
CommodityCode["proYear"] = "TCACA_code_003_FAnt7lcmRT";
|
|
10895
|
+
CommodityCode["freeMon"] = "TCACA_code_008_cfWoLwvjU4";
|
|
10896
|
+
CommodityCode["extra"] = "TCACA_code_009_0XmEQc2xOf";
|
|
10897
|
+
})(CommodityCode || (exports.CommodityCode = CommodityCode = {}));
|
|
14690
10898
|
}));
|
|
14691
10899
|
|
|
14692
10900
|
//#endregion
|
|
@@ -14752,10 +10960,11 @@ var require_backend_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
14752
10960
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14753
10961
|
exports.BackendProvider = void 0;
|
|
14754
10962
|
exports.createBackendProvider = createBackendProvider;
|
|
10963
|
+
const types_1 = require_types();
|
|
14755
10964
|
/** 获取当前域名的登录页面 URL */
|
|
14756
10965
|
const getLoginUrl = () => `${window.location.origin}/login`;
|
|
14757
10966
|
/** 获取当前域名的账号选择页面 URL */
|
|
14758
|
-
const getSelectAccountUrl = () => `${window.location.origin}/select`;
|
|
10967
|
+
const getSelectAccountUrl = () => `${window.location.origin}/login/select`;
|
|
14759
10968
|
/** localStorage 中存储选中账号 ID 的 key */
|
|
14760
10969
|
const SELECTED_ACCOUNT_KEY = "CODEBUDDY_IDE_SELECTED_ACCOUNT_ID";
|
|
14761
10970
|
/**
|
|
@@ -14899,7 +11108,7 @@ var require_backend_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
14899
11108
|
if (account.type === "personal") return account.uid === selectedAccountId;
|
|
14900
11109
|
return account.enterpriseId === selectedAccountId;
|
|
14901
11110
|
});
|
|
14902
|
-
if (selectedAccount) {
|
|
11111
|
+
if (selectedAccount) try {
|
|
14903
11112
|
const plan = await this.getCurrentPlan();
|
|
14904
11113
|
const editionType = this.getEditionDisplayType(selectedAccount.type, plan.isPro);
|
|
14905
11114
|
console.log("account", {
|
|
@@ -14912,6 +11121,8 @@ var require_backend_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
14912
11121
|
...plan,
|
|
14913
11122
|
editionType
|
|
14914
11123
|
};
|
|
11124
|
+
} catch (error) {
|
|
11125
|
+
return { ...selectedAccount };
|
|
14915
11126
|
}
|
|
14916
11127
|
}
|
|
14917
11128
|
if (accounts.length === 1) {
|
|
@@ -14932,7 +11143,7 @@ var require_backend_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
14932
11143
|
};
|
|
14933
11144
|
}
|
|
14934
11145
|
const redirectUrl = encodeURIComponent(window.location.href);
|
|
14935
|
-
window.location.href = `${getSelectAccountUrl()}?redirect_uri=${redirectUrl}`;
|
|
11146
|
+
window.location.href = `${getSelectAccountUrl()}?platform=website&state=0&redirect_uri=${redirectUrl}`;
|
|
14936
11147
|
return null;
|
|
14937
11148
|
} catch (error) {
|
|
14938
11149
|
console.error("[BackendProvider] getAccount failed:", error);
|
|
@@ -14987,8 +11198,8 @@ var require_backend_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
14987
11198
|
const result = await response.json();
|
|
14988
11199
|
const resources = ((_b = (_a = result === null || result === void 0 ? void 0 : result.Response) === null || _a === void 0 ? void 0 : _a.Data) === null || _b === void 0 ? void 0 : _b.Accounts) || (result === null || result === void 0 ? void 0 : result.Accounts) || [];
|
|
14989
11200
|
if (!resources || resources.length === 0) return defaultPlan;
|
|
14990
|
-
const proPlan = resources.find((r) => r.PackageCode ===
|
|
14991
|
-
const trialPlan = resources.find((r) => r.PackageCode ===
|
|
11201
|
+
const proPlan = resources.find((r) => r.PackageCode === types_1.CommodityCode.proYear || r.PackageCode === types_1.CommodityCode.proMon);
|
|
11202
|
+
const trialPlan = resources.find((r) => r.PackageCode === types_1.CommodityCode.gift);
|
|
14992
11203
|
const activePlan = proPlan || trialPlan;
|
|
14993
11204
|
if (activePlan) return {
|
|
14994
11205
|
isPro: !!proPlan,
|
|
@@ -15022,7 +11233,7 @@ var require_backend_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
15022
11233
|
*/
|
|
15023
11234
|
async login() {
|
|
15024
11235
|
const redirectUrl = encodeURIComponent(window.location.href);
|
|
15025
|
-
window.location.href = `${getLoginUrl()}?redirect_uri=${redirectUrl}
|
|
11236
|
+
window.location.href = `${getLoginUrl()}?platform=website&state=0&redirect_uri=${redirectUrl}`;
|
|
15026
11237
|
}
|
|
15027
11238
|
/**
|
|
15028
11239
|
* 登出账号
|