integrate-sdk 0.4.13 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,20 @@
1
+ var __create = Object.create;
2
+ var __getProtoOf = Object.getPrototypeOf;
1
3
  var __defProp = Object.defineProperty;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __toESM = (mod, isNodeMode, target) => {
7
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
8
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
9
+ for (let key of __getOwnPropNames(mod))
10
+ if (!__hasOwnProp.call(to, key))
11
+ __defProp(to, key, {
12
+ get: () => mod[key],
13
+ enumerable: true
14
+ });
15
+ return to;
16
+ };
17
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
2
18
  var __export = (target, all) => {
3
19
  for (var name in all)
4
20
  __defProp(target, name, {
@@ -1966,39 +1982,4097 @@ function createSimplePlugin(config) {
1966
1982
  onDisconnect: config.onDisconnect
1967
1983
  };
1968
1984
  }
1969
- // src/integrations/vercel-ai.ts
1970
- function getProviderForTool(client, toolName) {
1971
- return client.getProviderForTool?.(toolName);
1985
+ // node_modules/zod/v3/external.js
1986
+ var exports_external = {};
1987
+ __export(exports_external, {
1988
+ void: () => voidType,
1989
+ util: () => util,
1990
+ unknown: () => unknownType,
1991
+ union: () => unionType,
1992
+ undefined: () => undefinedType,
1993
+ tuple: () => tupleType,
1994
+ transformer: () => effectsType,
1995
+ symbol: () => symbolType,
1996
+ string: () => stringType,
1997
+ strictObject: () => strictObjectType,
1998
+ setErrorMap: () => setErrorMap,
1999
+ set: () => setType,
2000
+ record: () => recordType,
2001
+ quotelessJson: () => quotelessJson,
2002
+ promise: () => promiseType,
2003
+ preprocess: () => preprocessType,
2004
+ pipeline: () => pipelineType,
2005
+ ostring: () => ostring,
2006
+ optional: () => optionalType,
2007
+ onumber: () => onumber,
2008
+ oboolean: () => oboolean,
2009
+ objectUtil: () => objectUtil,
2010
+ object: () => objectType,
2011
+ number: () => numberType,
2012
+ nullable: () => nullableType,
2013
+ null: () => nullType,
2014
+ never: () => neverType,
2015
+ nativeEnum: () => nativeEnumType,
2016
+ nan: () => nanType,
2017
+ map: () => mapType,
2018
+ makeIssue: () => makeIssue,
2019
+ literal: () => literalType,
2020
+ lazy: () => lazyType,
2021
+ late: () => late,
2022
+ isValid: () => isValid,
2023
+ isDirty: () => isDirty,
2024
+ isAsync: () => isAsync,
2025
+ isAborted: () => isAborted,
2026
+ intersection: () => intersectionType,
2027
+ instanceof: () => instanceOfType,
2028
+ getParsedType: () => getParsedType,
2029
+ getErrorMap: () => getErrorMap,
2030
+ function: () => functionType,
2031
+ enum: () => enumType,
2032
+ effect: () => effectsType,
2033
+ discriminatedUnion: () => discriminatedUnionType,
2034
+ defaultErrorMap: () => en_default,
2035
+ datetimeRegex: () => datetimeRegex,
2036
+ date: () => dateType,
2037
+ custom: () => custom,
2038
+ coerce: () => coerce,
2039
+ boolean: () => booleanType,
2040
+ bigint: () => bigIntType,
2041
+ array: () => arrayType,
2042
+ any: () => anyType,
2043
+ addIssueToContext: () => addIssueToContext,
2044
+ ZodVoid: () => ZodVoid,
2045
+ ZodUnknown: () => ZodUnknown,
2046
+ ZodUnion: () => ZodUnion,
2047
+ ZodUndefined: () => ZodUndefined,
2048
+ ZodType: () => ZodType,
2049
+ ZodTuple: () => ZodTuple,
2050
+ ZodTransformer: () => ZodEffects,
2051
+ ZodSymbol: () => ZodSymbol,
2052
+ ZodString: () => ZodString,
2053
+ ZodSet: () => ZodSet,
2054
+ ZodSchema: () => ZodType,
2055
+ ZodRecord: () => ZodRecord,
2056
+ ZodReadonly: () => ZodReadonly,
2057
+ ZodPromise: () => ZodPromise,
2058
+ ZodPipeline: () => ZodPipeline,
2059
+ ZodParsedType: () => ZodParsedType,
2060
+ ZodOptional: () => ZodOptional,
2061
+ ZodObject: () => ZodObject,
2062
+ ZodNumber: () => ZodNumber,
2063
+ ZodNullable: () => ZodNullable,
2064
+ ZodNull: () => ZodNull,
2065
+ ZodNever: () => ZodNever,
2066
+ ZodNativeEnum: () => ZodNativeEnum,
2067
+ ZodNaN: () => ZodNaN,
2068
+ ZodMap: () => ZodMap,
2069
+ ZodLiteral: () => ZodLiteral,
2070
+ ZodLazy: () => ZodLazy,
2071
+ ZodIssueCode: () => ZodIssueCode,
2072
+ ZodIntersection: () => ZodIntersection,
2073
+ ZodFunction: () => ZodFunction,
2074
+ ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
2075
+ ZodError: () => ZodError,
2076
+ ZodEnum: () => ZodEnum,
2077
+ ZodEffects: () => ZodEffects,
2078
+ ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
2079
+ ZodDefault: () => ZodDefault,
2080
+ ZodDate: () => ZodDate,
2081
+ ZodCatch: () => ZodCatch,
2082
+ ZodBranded: () => ZodBranded,
2083
+ ZodBoolean: () => ZodBoolean,
2084
+ ZodBigInt: () => ZodBigInt,
2085
+ ZodArray: () => ZodArray,
2086
+ ZodAny: () => ZodAny,
2087
+ Schema: () => ZodType,
2088
+ ParseStatus: () => ParseStatus,
2089
+ OK: () => OK,
2090
+ NEVER: () => NEVER,
2091
+ INVALID: () => INVALID,
2092
+ EMPTY_PATH: () => EMPTY_PATH,
2093
+ DIRTY: () => DIRTY,
2094
+ BRAND: () => BRAND
2095
+ });
2096
+
2097
+ // node_modules/zod/v3/helpers/util.js
2098
+ var util;
2099
+ (function(util2) {
2100
+ util2.assertEqual = (_) => {};
2101
+ function assertIs(_arg) {}
2102
+ util2.assertIs = assertIs;
2103
+ function assertNever(_x) {
2104
+ throw new Error;
2105
+ }
2106
+ util2.assertNever = assertNever;
2107
+ util2.arrayToEnum = (items) => {
2108
+ const obj = {};
2109
+ for (const item of items) {
2110
+ obj[item] = item;
2111
+ }
2112
+ return obj;
2113
+ };
2114
+ util2.getValidEnumValues = (obj) => {
2115
+ const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
2116
+ const filtered = {};
2117
+ for (const k of validKeys) {
2118
+ filtered[k] = obj[k];
2119
+ }
2120
+ return util2.objectValues(filtered);
2121
+ };
2122
+ util2.objectValues = (obj) => {
2123
+ return util2.objectKeys(obj).map(function(e) {
2124
+ return obj[e];
2125
+ });
2126
+ };
2127
+ util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
2128
+ const keys = [];
2129
+ for (const key in object) {
2130
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
2131
+ keys.push(key);
2132
+ }
2133
+ }
2134
+ return keys;
2135
+ };
2136
+ util2.find = (arr, checker) => {
2137
+ for (const item of arr) {
2138
+ if (checker(item))
2139
+ return item;
2140
+ }
2141
+ return;
2142
+ };
2143
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
2144
+ function joinValues(array, separator = " | ") {
2145
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
2146
+ }
2147
+ util2.joinValues = joinValues;
2148
+ util2.jsonStringifyReplacer = (_, value) => {
2149
+ if (typeof value === "bigint") {
2150
+ return value.toString();
2151
+ }
2152
+ return value;
2153
+ };
2154
+ })(util || (util = {}));
2155
+ var objectUtil;
2156
+ (function(objectUtil2) {
2157
+ objectUtil2.mergeShapes = (first, second) => {
2158
+ return {
2159
+ ...first,
2160
+ ...second
2161
+ };
2162
+ };
2163
+ })(objectUtil || (objectUtil = {}));
2164
+ var ZodParsedType = util.arrayToEnum([
2165
+ "string",
2166
+ "nan",
2167
+ "number",
2168
+ "integer",
2169
+ "float",
2170
+ "boolean",
2171
+ "date",
2172
+ "bigint",
2173
+ "symbol",
2174
+ "function",
2175
+ "undefined",
2176
+ "null",
2177
+ "array",
2178
+ "object",
2179
+ "unknown",
2180
+ "promise",
2181
+ "void",
2182
+ "never",
2183
+ "map",
2184
+ "set"
2185
+ ]);
2186
+ var getParsedType = (data) => {
2187
+ const t = typeof data;
2188
+ switch (t) {
2189
+ case "undefined":
2190
+ return ZodParsedType.undefined;
2191
+ case "string":
2192
+ return ZodParsedType.string;
2193
+ case "number":
2194
+ return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
2195
+ case "boolean":
2196
+ return ZodParsedType.boolean;
2197
+ case "function":
2198
+ return ZodParsedType.function;
2199
+ case "bigint":
2200
+ return ZodParsedType.bigint;
2201
+ case "symbol":
2202
+ return ZodParsedType.symbol;
2203
+ case "object":
2204
+ if (Array.isArray(data)) {
2205
+ return ZodParsedType.array;
2206
+ }
2207
+ if (data === null) {
2208
+ return ZodParsedType.null;
2209
+ }
2210
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
2211
+ return ZodParsedType.promise;
2212
+ }
2213
+ if (typeof Map !== "undefined" && data instanceof Map) {
2214
+ return ZodParsedType.map;
2215
+ }
2216
+ if (typeof Set !== "undefined" && data instanceof Set) {
2217
+ return ZodParsedType.set;
2218
+ }
2219
+ if (typeof Date !== "undefined" && data instanceof Date) {
2220
+ return ZodParsedType.date;
2221
+ }
2222
+ return ZodParsedType.object;
2223
+ default:
2224
+ return ZodParsedType.unknown;
2225
+ }
2226
+ };
2227
+
2228
+ // node_modules/zod/v3/ZodError.js
2229
+ var ZodIssueCode = util.arrayToEnum([
2230
+ "invalid_type",
2231
+ "invalid_literal",
2232
+ "custom",
2233
+ "invalid_union",
2234
+ "invalid_union_discriminator",
2235
+ "invalid_enum_value",
2236
+ "unrecognized_keys",
2237
+ "invalid_arguments",
2238
+ "invalid_return_type",
2239
+ "invalid_date",
2240
+ "invalid_string",
2241
+ "too_small",
2242
+ "too_big",
2243
+ "invalid_intersection_types",
2244
+ "not_multiple_of",
2245
+ "not_finite"
2246
+ ]);
2247
+ var quotelessJson = (obj) => {
2248
+ const json = JSON.stringify(obj, null, 2);
2249
+ return json.replace(/"([^"]+)":/g, "$1:");
2250
+ };
2251
+
2252
+ class ZodError extends Error {
2253
+ get errors() {
2254
+ return this.issues;
2255
+ }
2256
+ constructor(issues) {
2257
+ super();
2258
+ this.issues = [];
2259
+ this.addIssue = (sub) => {
2260
+ this.issues = [...this.issues, sub];
2261
+ };
2262
+ this.addIssues = (subs = []) => {
2263
+ this.issues = [...this.issues, ...subs];
2264
+ };
2265
+ const actualProto = new.target.prototype;
2266
+ if (Object.setPrototypeOf) {
2267
+ Object.setPrototypeOf(this, actualProto);
2268
+ } else {
2269
+ this.__proto__ = actualProto;
2270
+ }
2271
+ this.name = "ZodError";
2272
+ this.issues = issues;
2273
+ }
2274
+ format(_mapper) {
2275
+ const mapper = _mapper || function(issue) {
2276
+ return issue.message;
2277
+ };
2278
+ const fieldErrors = { _errors: [] };
2279
+ const processError = (error) => {
2280
+ for (const issue of error.issues) {
2281
+ if (issue.code === "invalid_union") {
2282
+ issue.unionErrors.map(processError);
2283
+ } else if (issue.code === "invalid_return_type") {
2284
+ processError(issue.returnTypeError);
2285
+ } else if (issue.code === "invalid_arguments") {
2286
+ processError(issue.argumentsError);
2287
+ } else if (issue.path.length === 0) {
2288
+ fieldErrors._errors.push(mapper(issue));
2289
+ } else {
2290
+ let curr = fieldErrors;
2291
+ let i = 0;
2292
+ while (i < issue.path.length) {
2293
+ const el = issue.path[i];
2294
+ const terminal = i === issue.path.length - 1;
2295
+ if (!terminal) {
2296
+ curr[el] = curr[el] || { _errors: [] };
2297
+ } else {
2298
+ curr[el] = curr[el] || { _errors: [] };
2299
+ curr[el]._errors.push(mapper(issue));
2300
+ }
2301
+ curr = curr[el];
2302
+ i++;
2303
+ }
2304
+ }
2305
+ }
2306
+ };
2307
+ processError(this);
2308
+ return fieldErrors;
2309
+ }
2310
+ static assert(value) {
2311
+ if (!(value instanceof ZodError)) {
2312
+ throw new Error(`Not a ZodError: ${value}`);
2313
+ }
2314
+ }
2315
+ toString() {
2316
+ return this.message;
2317
+ }
2318
+ get message() {
2319
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
2320
+ }
2321
+ get isEmpty() {
2322
+ return this.issues.length === 0;
2323
+ }
2324
+ flatten(mapper = (issue) => issue.message) {
2325
+ const fieldErrors = {};
2326
+ const formErrors = [];
2327
+ for (const sub of this.issues) {
2328
+ if (sub.path.length > 0) {
2329
+ const firstEl = sub.path[0];
2330
+ fieldErrors[firstEl] = fieldErrors[firstEl] || [];
2331
+ fieldErrors[firstEl].push(mapper(sub));
2332
+ } else {
2333
+ formErrors.push(mapper(sub));
2334
+ }
2335
+ }
2336
+ return { formErrors, fieldErrors };
2337
+ }
2338
+ get formErrors() {
2339
+ return this.flatten();
2340
+ }
1972
2341
  }
1973
- function normalizeSchema(schema) {
1974
- if (!schema || typeof schema !== "object") {
2342
+ ZodError.create = (issues) => {
2343
+ const error = new ZodError(issues);
2344
+ return error;
2345
+ };
2346
+
2347
+ // node_modules/zod/v3/locales/en.js
2348
+ var errorMap = (issue, _ctx) => {
2349
+ let message;
2350
+ switch (issue.code) {
2351
+ case ZodIssueCode.invalid_type:
2352
+ if (issue.received === ZodParsedType.undefined) {
2353
+ message = "Required";
2354
+ } else {
2355
+ message = `Expected ${issue.expected}, received ${issue.received}`;
2356
+ }
2357
+ break;
2358
+ case ZodIssueCode.invalid_literal:
2359
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
2360
+ break;
2361
+ case ZodIssueCode.unrecognized_keys:
2362
+ message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
2363
+ break;
2364
+ case ZodIssueCode.invalid_union:
2365
+ message = `Invalid input`;
2366
+ break;
2367
+ case ZodIssueCode.invalid_union_discriminator:
2368
+ message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
2369
+ break;
2370
+ case ZodIssueCode.invalid_enum_value:
2371
+ message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
2372
+ break;
2373
+ case ZodIssueCode.invalid_arguments:
2374
+ message = `Invalid function arguments`;
2375
+ break;
2376
+ case ZodIssueCode.invalid_return_type:
2377
+ message = `Invalid function return type`;
2378
+ break;
2379
+ case ZodIssueCode.invalid_date:
2380
+ message = `Invalid date`;
2381
+ break;
2382
+ case ZodIssueCode.invalid_string:
2383
+ if (typeof issue.validation === "object") {
2384
+ if ("includes" in issue.validation) {
2385
+ message = `Invalid input: must include "${issue.validation.includes}"`;
2386
+ if (typeof issue.validation.position === "number") {
2387
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
2388
+ }
2389
+ } else if ("startsWith" in issue.validation) {
2390
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
2391
+ } else if ("endsWith" in issue.validation) {
2392
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
2393
+ } else {
2394
+ util.assertNever(issue.validation);
2395
+ }
2396
+ } else if (issue.validation !== "regex") {
2397
+ message = `Invalid ${issue.validation}`;
2398
+ } else {
2399
+ message = "Invalid";
2400
+ }
2401
+ break;
2402
+ case ZodIssueCode.too_small:
2403
+ if (issue.type === "array")
2404
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
2405
+ else if (issue.type === "string")
2406
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
2407
+ else if (issue.type === "number")
2408
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
2409
+ else if (issue.type === "bigint")
2410
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
2411
+ else if (issue.type === "date")
2412
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
2413
+ else
2414
+ message = "Invalid input";
2415
+ break;
2416
+ case ZodIssueCode.too_big:
2417
+ if (issue.type === "array")
2418
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
2419
+ else if (issue.type === "string")
2420
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
2421
+ else if (issue.type === "number")
2422
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
2423
+ else if (issue.type === "bigint")
2424
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
2425
+ else if (issue.type === "date")
2426
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
2427
+ else
2428
+ message = "Invalid input";
2429
+ break;
2430
+ case ZodIssueCode.custom:
2431
+ message = `Invalid input`;
2432
+ break;
2433
+ case ZodIssueCode.invalid_intersection_types:
2434
+ message = `Intersection results could not be merged`;
2435
+ break;
2436
+ case ZodIssueCode.not_multiple_of:
2437
+ message = `Number must be a multiple of ${issue.multipleOf}`;
2438
+ break;
2439
+ case ZodIssueCode.not_finite:
2440
+ message = "Number must be finite";
2441
+ break;
2442
+ default:
2443
+ message = _ctx.defaultError;
2444
+ util.assertNever(issue);
2445
+ }
2446
+ return { message };
2447
+ };
2448
+ var en_default = errorMap;
2449
+
2450
+ // node_modules/zod/v3/errors.js
2451
+ var overrideErrorMap = en_default;
2452
+ function setErrorMap(map) {
2453
+ overrideErrorMap = map;
2454
+ }
2455
+ function getErrorMap() {
2456
+ return overrideErrorMap;
2457
+ }
2458
+ // node_modules/zod/v3/helpers/parseUtil.js
2459
+ var makeIssue = (params) => {
2460
+ const { data, path, errorMaps, issueData } = params;
2461
+ const fullPath = [...path, ...issueData.path || []];
2462
+ const fullIssue = {
2463
+ ...issueData,
2464
+ path: fullPath
2465
+ };
2466
+ if (issueData.message !== undefined) {
1975
2467
  return {
1976
- type: "object",
1977
- properties: {},
1978
- additionalProperties: false
2468
+ ...issueData,
2469
+ path: fullPath,
2470
+ message: issueData.message
1979
2471
  };
1980
2472
  }
1981
- if (schema.type === "None" || schema.type === null || schema.type === undefined) {
2473
+ let errorMessage = "";
2474
+ const maps = errorMaps.filter((m) => !!m).slice().reverse();
2475
+ for (const map of maps) {
2476
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
2477
+ }
2478
+ return {
2479
+ ...issueData,
2480
+ path: fullPath,
2481
+ message: errorMessage
2482
+ };
2483
+ };
2484
+ var EMPTY_PATH = [];
2485
+ function addIssueToContext(ctx, issueData) {
2486
+ const overrideMap = getErrorMap();
2487
+ const issue = makeIssue({
2488
+ issueData,
2489
+ data: ctx.data,
2490
+ path: ctx.path,
2491
+ errorMaps: [
2492
+ ctx.common.contextualErrorMap,
2493
+ ctx.schemaErrorMap,
2494
+ overrideMap,
2495
+ overrideMap === en_default ? undefined : en_default
2496
+ ].filter((x) => !!x)
2497
+ });
2498
+ ctx.common.issues.push(issue);
2499
+ }
2500
+
2501
+ class ParseStatus {
2502
+ constructor() {
2503
+ this.value = "valid";
2504
+ }
2505
+ dirty() {
2506
+ if (this.value === "valid")
2507
+ this.value = "dirty";
2508
+ }
2509
+ abort() {
2510
+ if (this.value !== "aborted")
2511
+ this.value = "aborted";
2512
+ }
2513
+ static mergeArray(status, results) {
2514
+ const arrayValue = [];
2515
+ for (const s of results) {
2516
+ if (s.status === "aborted")
2517
+ return INVALID;
2518
+ if (s.status === "dirty")
2519
+ status.dirty();
2520
+ arrayValue.push(s.value);
2521
+ }
2522
+ return { status: status.value, value: arrayValue };
2523
+ }
2524
+ static async mergeObjectAsync(status, pairs) {
2525
+ const syncPairs = [];
2526
+ for (const pair of pairs) {
2527
+ const key = await pair.key;
2528
+ const value = await pair.value;
2529
+ syncPairs.push({
2530
+ key,
2531
+ value
2532
+ });
2533
+ }
2534
+ return ParseStatus.mergeObjectSync(status, syncPairs);
2535
+ }
2536
+ static mergeObjectSync(status, pairs) {
2537
+ const finalObject = {};
2538
+ for (const pair of pairs) {
2539
+ const { key, value } = pair;
2540
+ if (key.status === "aborted")
2541
+ return INVALID;
2542
+ if (value.status === "aborted")
2543
+ return INVALID;
2544
+ if (key.status === "dirty")
2545
+ status.dirty();
2546
+ if (value.status === "dirty")
2547
+ status.dirty();
2548
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
2549
+ finalObject[key.value] = value.value;
2550
+ }
2551
+ }
2552
+ return { status: status.value, value: finalObject };
2553
+ }
2554
+ }
2555
+ var INVALID = Object.freeze({
2556
+ status: "aborted"
2557
+ });
2558
+ var DIRTY = (value) => ({ status: "dirty", value });
2559
+ var OK = (value) => ({ status: "valid", value });
2560
+ var isAborted = (x) => x.status === "aborted";
2561
+ var isDirty = (x) => x.status === "dirty";
2562
+ var isValid = (x) => x.status === "valid";
2563
+ var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
2564
+ // node_modules/zod/v3/helpers/errorUtil.js
2565
+ var errorUtil;
2566
+ (function(errorUtil2) {
2567
+ errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
2568
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
2569
+ })(errorUtil || (errorUtil = {}));
2570
+
2571
+ // node_modules/zod/v3/types.js
2572
+ class ParseInputLazyPath {
2573
+ constructor(parent, value, path, key) {
2574
+ this._cachedPath = [];
2575
+ this.parent = parent;
2576
+ this.data = value;
2577
+ this._path = path;
2578
+ this._key = key;
2579
+ }
2580
+ get path() {
2581
+ if (!this._cachedPath.length) {
2582
+ if (Array.isArray(this._key)) {
2583
+ this._cachedPath.push(...this._path, ...this._key);
2584
+ } else {
2585
+ this._cachedPath.push(...this._path, this._key);
2586
+ }
2587
+ }
2588
+ return this._cachedPath;
2589
+ }
2590
+ }
2591
+ var handleResult = (ctx, result) => {
2592
+ if (isValid(result)) {
2593
+ return { success: true, data: result.value };
2594
+ } else {
2595
+ if (!ctx.common.issues.length) {
2596
+ throw new Error("Validation failed but no issues detected.");
2597
+ }
1982
2598
  return {
1983
- type: "object",
1984
- properties: schema.properties || {},
1985
- additionalProperties: schema.additionalProperties ?? false,
1986
- required: schema.required || []
2599
+ success: false,
2600
+ get error() {
2601
+ if (this._error)
2602
+ return this._error;
2603
+ const error = new ZodError(ctx.common.issues);
2604
+ this._error = error;
2605
+ return this._error;
2606
+ }
1987
2607
  };
1988
2608
  }
1989
- if (schema.type !== "object") {
2609
+ };
2610
+ function processCreateParams(params) {
2611
+ if (!params)
2612
+ return {};
2613
+ const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
2614
+ if (errorMap2 && (invalid_type_error || required_error)) {
2615
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
2616
+ }
2617
+ if (errorMap2)
2618
+ return { errorMap: errorMap2, description };
2619
+ const customMap = (iss, ctx) => {
2620
+ const { message } = params;
2621
+ if (iss.code === "invalid_enum_value") {
2622
+ return { message: message ?? ctx.defaultError };
2623
+ }
2624
+ if (typeof ctx.data === "undefined") {
2625
+ return { message: message ?? required_error ?? ctx.defaultError };
2626
+ }
2627
+ if (iss.code !== "invalid_type")
2628
+ return { message: ctx.defaultError };
2629
+ return { message: message ?? invalid_type_error ?? ctx.defaultError };
2630
+ };
2631
+ return { errorMap: customMap, description };
2632
+ }
2633
+
2634
+ class ZodType {
2635
+ get description() {
2636
+ return this._def.description;
2637
+ }
2638
+ _getType(input) {
2639
+ return getParsedType(input.data);
2640
+ }
2641
+ _getOrReturnCtx(input, ctx) {
2642
+ return ctx || {
2643
+ common: input.parent.common,
2644
+ data: input.data,
2645
+ parsedType: getParsedType(input.data),
2646
+ schemaErrorMap: this._def.errorMap,
2647
+ path: input.path,
2648
+ parent: input.parent
2649
+ };
2650
+ }
2651
+ _processInputParams(input) {
1990
2652
  return {
1991
- type: "object",
1992
- properties: {},
1993
- additionalProperties: false
2653
+ status: new ParseStatus,
2654
+ ctx: {
2655
+ common: input.parent.common,
2656
+ data: input.data,
2657
+ parsedType: getParsedType(input.data),
2658
+ schemaErrorMap: this._def.errorMap,
2659
+ path: input.path,
2660
+ parent: input.parent
2661
+ }
2662
+ };
2663
+ }
2664
+ _parseSync(input) {
2665
+ const result = this._parse(input);
2666
+ if (isAsync(result)) {
2667
+ throw new Error("Synchronous parse encountered promise.");
2668
+ }
2669
+ return result;
2670
+ }
2671
+ _parseAsync(input) {
2672
+ const result = this._parse(input);
2673
+ return Promise.resolve(result);
2674
+ }
2675
+ parse(data, params) {
2676
+ const result = this.safeParse(data, params);
2677
+ if (result.success)
2678
+ return result.data;
2679
+ throw result.error;
2680
+ }
2681
+ safeParse(data, params) {
2682
+ const ctx = {
2683
+ common: {
2684
+ issues: [],
2685
+ async: params?.async ?? false,
2686
+ contextualErrorMap: params?.errorMap
2687
+ },
2688
+ path: params?.path || [],
2689
+ schemaErrorMap: this._def.errorMap,
2690
+ parent: null,
2691
+ data,
2692
+ parsedType: getParsedType(data)
2693
+ };
2694
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
2695
+ return handleResult(ctx, result);
2696
+ }
2697
+ "~validate"(data) {
2698
+ const ctx = {
2699
+ common: {
2700
+ issues: [],
2701
+ async: !!this["~standard"].async
2702
+ },
2703
+ path: [],
2704
+ schemaErrorMap: this._def.errorMap,
2705
+ parent: null,
2706
+ data,
2707
+ parsedType: getParsedType(data)
2708
+ };
2709
+ if (!this["~standard"].async) {
2710
+ try {
2711
+ const result = this._parseSync({ data, path: [], parent: ctx });
2712
+ return isValid(result) ? {
2713
+ value: result.value
2714
+ } : {
2715
+ issues: ctx.common.issues
2716
+ };
2717
+ } catch (err) {
2718
+ if (err?.message?.toLowerCase()?.includes("encountered")) {
2719
+ this["~standard"].async = true;
2720
+ }
2721
+ ctx.common = {
2722
+ issues: [],
2723
+ async: true
2724
+ };
2725
+ }
2726
+ }
2727
+ return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
2728
+ value: result.value
2729
+ } : {
2730
+ issues: ctx.common.issues
2731
+ });
2732
+ }
2733
+ async parseAsync(data, params) {
2734
+ const result = await this.safeParseAsync(data, params);
2735
+ if (result.success)
2736
+ return result.data;
2737
+ throw result.error;
2738
+ }
2739
+ async safeParseAsync(data, params) {
2740
+ const ctx = {
2741
+ common: {
2742
+ issues: [],
2743
+ contextualErrorMap: params?.errorMap,
2744
+ async: true
2745
+ },
2746
+ path: params?.path || [],
2747
+ schemaErrorMap: this._def.errorMap,
2748
+ parent: null,
2749
+ data,
2750
+ parsedType: getParsedType(data)
2751
+ };
2752
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
2753
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
2754
+ return handleResult(ctx, result);
2755
+ }
2756
+ refine(check, message) {
2757
+ const getIssueProperties = (val) => {
2758
+ if (typeof message === "string" || typeof message === "undefined") {
2759
+ return { message };
2760
+ } else if (typeof message === "function") {
2761
+ return message(val);
2762
+ } else {
2763
+ return message;
2764
+ }
2765
+ };
2766
+ return this._refinement((val, ctx) => {
2767
+ const result = check(val);
2768
+ const setError = () => ctx.addIssue({
2769
+ code: ZodIssueCode.custom,
2770
+ ...getIssueProperties(val)
2771
+ });
2772
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
2773
+ return result.then((data) => {
2774
+ if (!data) {
2775
+ setError();
2776
+ return false;
2777
+ } else {
2778
+ return true;
2779
+ }
2780
+ });
2781
+ }
2782
+ if (!result) {
2783
+ setError();
2784
+ return false;
2785
+ } else {
2786
+ return true;
2787
+ }
2788
+ });
2789
+ }
2790
+ refinement(check, refinementData) {
2791
+ return this._refinement((val, ctx) => {
2792
+ if (!check(val)) {
2793
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
2794
+ return false;
2795
+ } else {
2796
+ return true;
2797
+ }
2798
+ });
2799
+ }
2800
+ _refinement(refinement) {
2801
+ return new ZodEffects({
2802
+ schema: this,
2803
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
2804
+ effect: { type: "refinement", refinement }
2805
+ });
2806
+ }
2807
+ superRefine(refinement) {
2808
+ return this._refinement(refinement);
2809
+ }
2810
+ constructor(def) {
2811
+ this.spa = this.safeParseAsync;
2812
+ this._def = def;
2813
+ this.parse = this.parse.bind(this);
2814
+ this.safeParse = this.safeParse.bind(this);
2815
+ this.parseAsync = this.parseAsync.bind(this);
2816
+ this.safeParseAsync = this.safeParseAsync.bind(this);
2817
+ this.spa = this.spa.bind(this);
2818
+ this.refine = this.refine.bind(this);
2819
+ this.refinement = this.refinement.bind(this);
2820
+ this.superRefine = this.superRefine.bind(this);
2821
+ this.optional = this.optional.bind(this);
2822
+ this.nullable = this.nullable.bind(this);
2823
+ this.nullish = this.nullish.bind(this);
2824
+ this.array = this.array.bind(this);
2825
+ this.promise = this.promise.bind(this);
2826
+ this.or = this.or.bind(this);
2827
+ this.and = this.and.bind(this);
2828
+ this.transform = this.transform.bind(this);
2829
+ this.brand = this.brand.bind(this);
2830
+ this.default = this.default.bind(this);
2831
+ this.catch = this.catch.bind(this);
2832
+ this.describe = this.describe.bind(this);
2833
+ this.pipe = this.pipe.bind(this);
2834
+ this.readonly = this.readonly.bind(this);
2835
+ this.isNullable = this.isNullable.bind(this);
2836
+ this.isOptional = this.isOptional.bind(this);
2837
+ this["~standard"] = {
2838
+ version: 1,
2839
+ vendor: "zod",
2840
+ validate: (data) => this["~validate"](data)
1994
2841
  };
1995
2842
  }
1996
- return schema;
2843
+ optional() {
2844
+ return ZodOptional.create(this, this._def);
2845
+ }
2846
+ nullable() {
2847
+ return ZodNullable.create(this, this._def);
2848
+ }
2849
+ nullish() {
2850
+ return this.nullable().optional();
2851
+ }
2852
+ array() {
2853
+ return ZodArray.create(this);
2854
+ }
2855
+ promise() {
2856
+ return ZodPromise.create(this, this._def);
2857
+ }
2858
+ or(option) {
2859
+ return ZodUnion.create([this, option], this._def);
2860
+ }
2861
+ and(incoming) {
2862
+ return ZodIntersection.create(this, incoming, this._def);
2863
+ }
2864
+ transform(transform) {
2865
+ return new ZodEffects({
2866
+ ...processCreateParams(this._def),
2867
+ schema: this,
2868
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
2869
+ effect: { type: "transform", transform }
2870
+ });
2871
+ }
2872
+ default(def) {
2873
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
2874
+ return new ZodDefault({
2875
+ ...processCreateParams(this._def),
2876
+ innerType: this,
2877
+ defaultValue: defaultValueFunc,
2878
+ typeName: ZodFirstPartyTypeKind.ZodDefault
2879
+ });
2880
+ }
2881
+ brand() {
2882
+ return new ZodBranded({
2883
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
2884
+ type: this,
2885
+ ...processCreateParams(this._def)
2886
+ });
2887
+ }
2888
+ catch(def) {
2889
+ const catchValueFunc = typeof def === "function" ? def : () => def;
2890
+ return new ZodCatch({
2891
+ ...processCreateParams(this._def),
2892
+ innerType: this,
2893
+ catchValue: catchValueFunc,
2894
+ typeName: ZodFirstPartyTypeKind.ZodCatch
2895
+ });
2896
+ }
2897
+ describe(description) {
2898
+ const This = this.constructor;
2899
+ return new This({
2900
+ ...this._def,
2901
+ description
2902
+ });
2903
+ }
2904
+ pipe(target) {
2905
+ return ZodPipeline.create(this, target);
2906
+ }
2907
+ readonly() {
2908
+ return ZodReadonly.create(this);
2909
+ }
2910
+ isOptional() {
2911
+ return this.safeParse(undefined).success;
2912
+ }
2913
+ isNullable() {
2914
+ return this.safeParse(null).success;
2915
+ }
2916
+ }
2917
+ var cuidRegex = /^c[^\s-]{8,}$/i;
2918
+ var cuid2Regex = /^[0-9a-z]+$/;
2919
+ var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
2920
+ var 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;
2921
+ var nanoidRegex = /^[a-z0-9_-]{21}$/i;
2922
+ var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
2923
+ var 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)?)??$/;
2924
+ var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
2925
+ var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
2926
+ var emojiRegex;
2927
+ var 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])$/;
2928
+ var 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])$/;
2929
+ var 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]))$/;
2930
+ var 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])$/;
2931
+ var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
2932
+ var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
2933
+ var 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])))`;
2934
+ var dateRegex = new RegExp(`^${dateRegexSource}$`);
2935
+ function timeRegexSource(args) {
2936
+ let secondsRegexSource = `[0-5]\\d`;
2937
+ if (args.precision) {
2938
+ secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
2939
+ } else if (args.precision == null) {
2940
+ secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
2941
+ }
2942
+ const secondsQuantifier = args.precision ? "+" : "?";
2943
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
2944
+ }
2945
+ function timeRegex(args) {
2946
+ return new RegExp(`^${timeRegexSource(args)}$`);
2947
+ }
2948
+ function datetimeRegex(args) {
2949
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
2950
+ const opts = [];
2951
+ opts.push(args.local ? `Z?` : `Z`);
2952
+ if (args.offset)
2953
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
2954
+ regex = `${regex}(${opts.join("|")})`;
2955
+ return new RegExp(`^${regex}$`);
2956
+ }
2957
+ function isValidIP(ip, version) {
2958
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
2959
+ return true;
2960
+ }
2961
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
2962
+ return true;
2963
+ }
2964
+ return false;
2965
+ }
2966
+ function isValidJWT(jwt, alg) {
2967
+ if (!jwtRegex.test(jwt))
2968
+ return false;
2969
+ try {
2970
+ const [header] = jwt.split(".");
2971
+ if (!header)
2972
+ return false;
2973
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
2974
+ const decoded = JSON.parse(atob(base64));
2975
+ if (typeof decoded !== "object" || decoded === null)
2976
+ return false;
2977
+ if ("typ" in decoded && decoded?.typ !== "JWT")
2978
+ return false;
2979
+ if (!decoded.alg)
2980
+ return false;
2981
+ if (alg && decoded.alg !== alg)
2982
+ return false;
2983
+ return true;
2984
+ } catch {
2985
+ return false;
2986
+ }
2987
+ }
2988
+ function isValidCidr(ip, version) {
2989
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
2990
+ return true;
2991
+ }
2992
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
2993
+ return true;
2994
+ }
2995
+ return false;
2996
+ }
2997
+
2998
+ class ZodString extends ZodType {
2999
+ _parse(input) {
3000
+ if (this._def.coerce) {
3001
+ input.data = String(input.data);
3002
+ }
3003
+ const parsedType = this._getType(input);
3004
+ if (parsedType !== ZodParsedType.string) {
3005
+ const ctx2 = this._getOrReturnCtx(input);
3006
+ addIssueToContext(ctx2, {
3007
+ code: ZodIssueCode.invalid_type,
3008
+ expected: ZodParsedType.string,
3009
+ received: ctx2.parsedType
3010
+ });
3011
+ return INVALID;
3012
+ }
3013
+ const status = new ParseStatus;
3014
+ let ctx = undefined;
3015
+ for (const check of this._def.checks) {
3016
+ if (check.kind === "min") {
3017
+ if (input.data.length < check.value) {
3018
+ ctx = this._getOrReturnCtx(input, ctx);
3019
+ addIssueToContext(ctx, {
3020
+ code: ZodIssueCode.too_small,
3021
+ minimum: check.value,
3022
+ type: "string",
3023
+ inclusive: true,
3024
+ exact: false,
3025
+ message: check.message
3026
+ });
3027
+ status.dirty();
3028
+ }
3029
+ } else if (check.kind === "max") {
3030
+ if (input.data.length > check.value) {
3031
+ ctx = this._getOrReturnCtx(input, ctx);
3032
+ addIssueToContext(ctx, {
3033
+ code: ZodIssueCode.too_big,
3034
+ maximum: check.value,
3035
+ type: "string",
3036
+ inclusive: true,
3037
+ exact: false,
3038
+ message: check.message
3039
+ });
3040
+ status.dirty();
3041
+ }
3042
+ } else if (check.kind === "length") {
3043
+ const tooBig = input.data.length > check.value;
3044
+ const tooSmall = input.data.length < check.value;
3045
+ if (tooBig || tooSmall) {
3046
+ ctx = this._getOrReturnCtx(input, ctx);
3047
+ if (tooBig) {
3048
+ addIssueToContext(ctx, {
3049
+ code: ZodIssueCode.too_big,
3050
+ maximum: check.value,
3051
+ type: "string",
3052
+ inclusive: true,
3053
+ exact: true,
3054
+ message: check.message
3055
+ });
3056
+ } else if (tooSmall) {
3057
+ addIssueToContext(ctx, {
3058
+ code: ZodIssueCode.too_small,
3059
+ minimum: check.value,
3060
+ type: "string",
3061
+ inclusive: true,
3062
+ exact: true,
3063
+ message: check.message
3064
+ });
3065
+ }
3066
+ status.dirty();
3067
+ }
3068
+ } else if (check.kind === "email") {
3069
+ if (!emailRegex.test(input.data)) {
3070
+ ctx = this._getOrReturnCtx(input, ctx);
3071
+ addIssueToContext(ctx, {
3072
+ validation: "email",
3073
+ code: ZodIssueCode.invalid_string,
3074
+ message: check.message
3075
+ });
3076
+ status.dirty();
3077
+ }
3078
+ } else if (check.kind === "emoji") {
3079
+ if (!emojiRegex) {
3080
+ emojiRegex = new RegExp(_emojiRegex, "u");
3081
+ }
3082
+ if (!emojiRegex.test(input.data)) {
3083
+ ctx = this._getOrReturnCtx(input, ctx);
3084
+ addIssueToContext(ctx, {
3085
+ validation: "emoji",
3086
+ code: ZodIssueCode.invalid_string,
3087
+ message: check.message
3088
+ });
3089
+ status.dirty();
3090
+ }
3091
+ } else if (check.kind === "uuid") {
3092
+ if (!uuidRegex.test(input.data)) {
3093
+ ctx = this._getOrReturnCtx(input, ctx);
3094
+ addIssueToContext(ctx, {
3095
+ validation: "uuid",
3096
+ code: ZodIssueCode.invalid_string,
3097
+ message: check.message
3098
+ });
3099
+ status.dirty();
3100
+ }
3101
+ } else if (check.kind === "nanoid") {
3102
+ if (!nanoidRegex.test(input.data)) {
3103
+ ctx = this._getOrReturnCtx(input, ctx);
3104
+ addIssueToContext(ctx, {
3105
+ validation: "nanoid",
3106
+ code: ZodIssueCode.invalid_string,
3107
+ message: check.message
3108
+ });
3109
+ status.dirty();
3110
+ }
3111
+ } else if (check.kind === "cuid") {
3112
+ if (!cuidRegex.test(input.data)) {
3113
+ ctx = this._getOrReturnCtx(input, ctx);
3114
+ addIssueToContext(ctx, {
3115
+ validation: "cuid",
3116
+ code: ZodIssueCode.invalid_string,
3117
+ message: check.message
3118
+ });
3119
+ status.dirty();
3120
+ }
3121
+ } else if (check.kind === "cuid2") {
3122
+ if (!cuid2Regex.test(input.data)) {
3123
+ ctx = this._getOrReturnCtx(input, ctx);
3124
+ addIssueToContext(ctx, {
3125
+ validation: "cuid2",
3126
+ code: ZodIssueCode.invalid_string,
3127
+ message: check.message
3128
+ });
3129
+ status.dirty();
3130
+ }
3131
+ } else if (check.kind === "ulid") {
3132
+ if (!ulidRegex.test(input.data)) {
3133
+ ctx = this._getOrReturnCtx(input, ctx);
3134
+ addIssueToContext(ctx, {
3135
+ validation: "ulid",
3136
+ code: ZodIssueCode.invalid_string,
3137
+ message: check.message
3138
+ });
3139
+ status.dirty();
3140
+ }
3141
+ } else if (check.kind === "url") {
3142
+ try {
3143
+ new URL(input.data);
3144
+ } catch {
3145
+ ctx = this._getOrReturnCtx(input, ctx);
3146
+ addIssueToContext(ctx, {
3147
+ validation: "url",
3148
+ code: ZodIssueCode.invalid_string,
3149
+ message: check.message
3150
+ });
3151
+ status.dirty();
3152
+ }
3153
+ } else if (check.kind === "regex") {
3154
+ check.regex.lastIndex = 0;
3155
+ const testResult = check.regex.test(input.data);
3156
+ if (!testResult) {
3157
+ ctx = this._getOrReturnCtx(input, ctx);
3158
+ addIssueToContext(ctx, {
3159
+ validation: "regex",
3160
+ code: ZodIssueCode.invalid_string,
3161
+ message: check.message
3162
+ });
3163
+ status.dirty();
3164
+ }
3165
+ } else if (check.kind === "trim") {
3166
+ input.data = input.data.trim();
3167
+ } else if (check.kind === "includes") {
3168
+ if (!input.data.includes(check.value, check.position)) {
3169
+ ctx = this._getOrReturnCtx(input, ctx);
3170
+ addIssueToContext(ctx, {
3171
+ code: ZodIssueCode.invalid_string,
3172
+ validation: { includes: check.value, position: check.position },
3173
+ message: check.message
3174
+ });
3175
+ status.dirty();
3176
+ }
3177
+ } else if (check.kind === "toLowerCase") {
3178
+ input.data = input.data.toLowerCase();
3179
+ } else if (check.kind === "toUpperCase") {
3180
+ input.data = input.data.toUpperCase();
3181
+ } else if (check.kind === "startsWith") {
3182
+ if (!input.data.startsWith(check.value)) {
3183
+ ctx = this._getOrReturnCtx(input, ctx);
3184
+ addIssueToContext(ctx, {
3185
+ code: ZodIssueCode.invalid_string,
3186
+ validation: { startsWith: check.value },
3187
+ message: check.message
3188
+ });
3189
+ status.dirty();
3190
+ }
3191
+ } else if (check.kind === "endsWith") {
3192
+ if (!input.data.endsWith(check.value)) {
3193
+ ctx = this._getOrReturnCtx(input, ctx);
3194
+ addIssueToContext(ctx, {
3195
+ code: ZodIssueCode.invalid_string,
3196
+ validation: { endsWith: check.value },
3197
+ message: check.message
3198
+ });
3199
+ status.dirty();
3200
+ }
3201
+ } else if (check.kind === "datetime") {
3202
+ const regex = datetimeRegex(check);
3203
+ if (!regex.test(input.data)) {
3204
+ ctx = this._getOrReturnCtx(input, ctx);
3205
+ addIssueToContext(ctx, {
3206
+ code: ZodIssueCode.invalid_string,
3207
+ validation: "datetime",
3208
+ message: check.message
3209
+ });
3210
+ status.dirty();
3211
+ }
3212
+ } else if (check.kind === "date") {
3213
+ const regex = dateRegex;
3214
+ if (!regex.test(input.data)) {
3215
+ ctx = this._getOrReturnCtx(input, ctx);
3216
+ addIssueToContext(ctx, {
3217
+ code: ZodIssueCode.invalid_string,
3218
+ validation: "date",
3219
+ message: check.message
3220
+ });
3221
+ status.dirty();
3222
+ }
3223
+ } else if (check.kind === "time") {
3224
+ const regex = timeRegex(check);
3225
+ if (!regex.test(input.data)) {
3226
+ ctx = this._getOrReturnCtx(input, ctx);
3227
+ addIssueToContext(ctx, {
3228
+ code: ZodIssueCode.invalid_string,
3229
+ validation: "time",
3230
+ message: check.message
3231
+ });
3232
+ status.dirty();
3233
+ }
3234
+ } else if (check.kind === "duration") {
3235
+ if (!durationRegex.test(input.data)) {
3236
+ ctx = this._getOrReturnCtx(input, ctx);
3237
+ addIssueToContext(ctx, {
3238
+ validation: "duration",
3239
+ code: ZodIssueCode.invalid_string,
3240
+ message: check.message
3241
+ });
3242
+ status.dirty();
3243
+ }
3244
+ } else if (check.kind === "ip") {
3245
+ if (!isValidIP(input.data, check.version)) {
3246
+ ctx = this._getOrReturnCtx(input, ctx);
3247
+ addIssueToContext(ctx, {
3248
+ validation: "ip",
3249
+ code: ZodIssueCode.invalid_string,
3250
+ message: check.message
3251
+ });
3252
+ status.dirty();
3253
+ }
3254
+ } else if (check.kind === "jwt") {
3255
+ if (!isValidJWT(input.data, check.alg)) {
3256
+ ctx = this._getOrReturnCtx(input, ctx);
3257
+ addIssueToContext(ctx, {
3258
+ validation: "jwt",
3259
+ code: ZodIssueCode.invalid_string,
3260
+ message: check.message
3261
+ });
3262
+ status.dirty();
3263
+ }
3264
+ } else if (check.kind === "cidr") {
3265
+ if (!isValidCidr(input.data, check.version)) {
3266
+ ctx = this._getOrReturnCtx(input, ctx);
3267
+ addIssueToContext(ctx, {
3268
+ validation: "cidr",
3269
+ code: ZodIssueCode.invalid_string,
3270
+ message: check.message
3271
+ });
3272
+ status.dirty();
3273
+ }
3274
+ } else if (check.kind === "base64") {
3275
+ if (!base64Regex.test(input.data)) {
3276
+ ctx = this._getOrReturnCtx(input, ctx);
3277
+ addIssueToContext(ctx, {
3278
+ validation: "base64",
3279
+ code: ZodIssueCode.invalid_string,
3280
+ message: check.message
3281
+ });
3282
+ status.dirty();
3283
+ }
3284
+ } else if (check.kind === "base64url") {
3285
+ if (!base64urlRegex.test(input.data)) {
3286
+ ctx = this._getOrReturnCtx(input, ctx);
3287
+ addIssueToContext(ctx, {
3288
+ validation: "base64url",
3289
+ code: ZodIssueCode.invalid_string,
3290
+ message: check.message
3291
+ });
3292
+ status.dirty();
3293
+ }
3294
+ } else {
3295
+ util.assertNever(check);
3296
+ }
3297
+ }
3298
+ return { status: status.value, value: input.data };
3299
+ }
3300
+ _regex(regex, validation, message) {
3301
+ return this.refinement((data) => regex.test(data), {
3302
+ validation,
3303
+ code: ZodIssueCode.invalid_string,
3304
+ ...errorUtil.errToObj(message)
3305
+ });
3306
+ }
3307
+ _addCheck(check) {
3308
+ return new ZodString({
3309
+ ...this._def,
3310
+ checks: [...this._def.checks, check]
3311
+ });
3312
+ }
3313
+ email(message) {
3314
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
3315
+ }
3316
+ url(message) {
3317
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
3318
+ }
3319
+ emoji(message) {
3320
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
3321
+ }
3322
+ uuid(message) {
3323
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
3324
+ }
3325
+ nanoid(message) {
3326
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
3327
+ }
3328
+ cuid(message) {
3329
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
3330
+ }
3331
+ cuid2(message) {
3332
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
3333
+ }
3334
+ ulid(message) {
3335
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
3336
+ }
3337
+ base64(message) {
3338
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
3339
+ }
3340
+ base64url(message) {
3341
+ return this._addCheck({
3342
+ kind: "base64url",
3343
+ ...errorUtil.errToObj(message)
3344
+ });
3345
+ }
3346
+ jwt(options) {
3347
+ return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
3348
+ }
3349
+ ip(options) {
3350
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
3351
+ }
3352
+ cidr(options) {
3353
+ return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
3354
+ }
3355
+ datetime(options) {
3356
+ if (typeof options === "string") {
3357
+ return this._addCheck({
3358
+ kind: "datetime",
3359
+ precision: null,
3360
+ offset: false,
3361
+ local: false,
3362
+ message: options
3363
+ });
3364
+ }
3365
+ return this._addCheck({
3366
+ kind: "datetime",
3367
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
3368
+ offset: options?.offset ?? false,
3369
+ local: options?.local ?? false,
3370
+ ...errorUtil.errToObj(options?.message)
3371
+ });
3372
+ }
3373
+ date(message) {
3374
+ return this._addCheck({ kind: "date", message });
3375
+ }
3376
+ time(options) {
3377
+ if (typeof options === "string") {
3378
+ return this._addCheck({
3379
+ kind: "time",
3380
+ precision: null,
3381
+ message: options
3382
+ });
3383
+ }
3384
+ return this._addCheck({
3385
+ kind: "time",
3386
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
3387
+ ...errorUtil.errToObj(options?.message)
3388
+ });
3389
+ }
3390
+ duration(message) {
3391
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
3392
+ }
3393
+ regex(regex, message) {
3394
+ return this._addCheck({
3395
+ kind: "regex",
3396
+ regex,
3397
+ ...errorUtil.errToObj(message)
3398
+ });
3399
+ }
3400
+ includes(value, options) {
3401
+ return this._addCheck({
3402
+ kind: "includes",
3403
+ value,
3404
+ position: options?.position,
3405
+ ...errorUtil.errToObj(options?.message)
3406
+ });
3407
+ }
3408
+ startsWith(value, message) {
3409
+ return this._addCheck({
3410
+ kind: "startsWith",
3411
+ value,
3412
+ ...errorUtil.errToObj(message)
3413
+ });
3414
+ }
3415
+ endsWith(value, message) {
3416
+ return this._addCheck({
3417
+ kind: "endsWith",
3418
+ value,
3419
+ ...errorUtil.errToObj(message)
3420
+ });
3421
+ }
3422
+ min(minLength, message) {
3423
+ return this._addCheck({
3424
+ kind: "min",
3425
+ value: minLength,
3426
+ ...errorUtil.errToObj(message)
3427
+ });
3428
+ }
3429
+ max(maxLength, message) {
3430
+ return this._addCheck({
3431
+ kind: "max",
3432
+ value: maxLength,
3433
+ ...errorUtil.errToObj(message)
3434
+ });
3435
+ }
3436
+ length(len, message) {
3437
+ return this._addCheck({
3438
+ kind: "length",
3439
+ value: len,
3440
+ ...errorUtil.errToObj(message)
3441
+ });
3442
+ }
3443
+ nonempty(message) {
3444
+ return this.min(1, errorUtil.errToObj(message));
3445
+ }
3446
+ trim() {
3447
+ return new ZodString({
3448
+ ...this._def,
3449
+ checks: [...this._def.checks, { kind: "trim" }]
3450
+ });
3451
+ }
3452
+ toLowerCase() {
3453
+ return new ZodString({
3454
+ ...this._def,
3455
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
3456
+ });
3457
+ }
3458
+ toUpperCase() {
3459
+ return new ZodString({
3460
+ ...this._def,
3461
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
3462
+ });
3463
+ }
3464
+ get isDatetime() {
3465
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
3466
+ }
3467
+ get isDate() {
3468
+ return !!this._def.checks.find((ch) => ch.kind === "date");
3469
+ }
3470
+ get isTime() {
3471
+ return !!this._def.checks.find((ch) => ch.kind === "time");
3472
+ }
3473
+ get isDuration() {
3474
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
3475
+ }
3476
+ get isEmail() {
3477
+ return !!this._def.checks.find((ch) => ch.kind === "email");
3478
+ }
3479
+ get isURL() {
3480
+ return !!this._def.checks.find((ch) => ch.kind === "url");
3481
+ }
3482
+ get isEmoji() {
3483
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
3484
+ }
3485
+ get isUUID() {
3486
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
3487
+ }
3488
+ get isNANOID() {
3489
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
3490
+ }
3491
+ get isCUID() {
3492
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
3493
+ }
3494
+ get isCUID2() {
3495
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
3496
+ }
3497
+ get isULID() {
3498
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
3499
+ }
3500
+ get isIP() {
3501
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
3502
+ }
3503
+ get isCIDR() {
3504
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
3505
+ }
3506
+ get isBase64() {
3507
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
3508
+ }
3509
+ get isBase64url() {
3510
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
3511
+ }
3512
+ get minLength() {
3513
+ let min = null;
3514
+ for (const ch of this._def.checks) {
3515
+ if (ch.kind === "min") {
3516
+ if (min === null || ch.value > min)
3517
+ min = ch.value;
3518
+ }
3519
+ }
3520
+ return min;
3521
+ }
3522
+ get maxLength() {
3523
+ let max = null;
3524
+ for (const ch of this._def.checks) {
3525
+ if (ch.kind === "max") {
3526
+ if (max === null || ch.value < max)
3527
+ max = ch.value;
3528
+ }
3529
+ }
3530
+ return max;
3531
+ }
3532
+ }
3533
+ ZodString.create = (params) => {
3534
+ return new ZodString({
3535
+ checks: [],
3536
+ typeName: ZodFirstPartyTypeKind.ZodString,
3537
+ coerce: params?.coerce ?? false,
3538
+ ...processCreateParams(params)
3539
+ });
3540
+ };
3541
+ function floatSafeRemainder(val, step) {
3542
+ const valDecCount = (val.toString().split(".")[1] || "").length;
3543
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
3544
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
3545
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
3546
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
3547
+ return valInt % stepInt / 10 ** decCount;
3548
+ }
3549
+
3550
+ class ZodNumber extends ZodType {
3551
+ constructor() {
3552
+ super(...arguments);
3553
+ this.min = this.gte;
3554
+ this.max = this.lte;
3555
+ this.step = this.multipleOf;
3556
+ }
3557
+ _parse(input) {
3558
+ if (this._def.coerce) {
3559
+ input.data = Number(input.data);
3560
+ }
3561
+ const parsedType = this._getType(input);
3562
+ if (parsedType !== ZodParsedType.number) {
3563
+ const ctx2 = this._getOrReturnCtx(input);
3564
+ addIssueToContext(ctx2, {
3565
+ code: ZodIssueCode.invalid_type,
3566
+ expected: ZodParsedType.number,
3567
+ received: ctx2.parsedType
3568
+ });
3569
+ return INVALID;
3570
+ }
3571
+ let ctx = undefined;
3572
+ const status = new ParseStatus;
3573
+ for (const check of this._def.checks) {
3574
+ if (check.kind === "int") {
3575
+ if (!util.isInteger(input.data)) {
3576
+ ctx = this._getOrReturnCtx(input, ctx);
3577
+ addIssueToContext(ctx, {
3578
+ code: ZodIssueCode.invalid_type,
3579
+ expected: "integer",
3580
+ received: "float",
3581
+ message: check.message
3582
+ });
3583
+ status.dirty();
3584
+ }
3585
+ } else if (check.kind === "min") {
3586
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
3587
+ if (tooSmall) {
3588
+ ctx = this._getOrReturnCtx(input, ctx);
3589
+ addIssueToContext(ctx, {
3590
+ code: ZodIssueCode.too_small,
3591
+ minimum: check.value,
3592
+ type: "number",
3593
+ inclusive: check.inclusive,
3594
+ exact: false,
3595
+ message: check.message
3596
+ });
3597
+ status.dirty();
3598
+ }
3599
+ } else if (check.kind === "max") {
3600
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
3601
+ if (tooBig) {
3602
+ ctx = this._getOrReturnCtx(input, ctx);
3603
+ addIssueToContext(ctx, {
3604
+ code: ZodIssueCode.too_big,
3605
+ maximum: check.value,
3606
+ type: "number",
3607
+ inclusive: check.inclusive,
3608
+ exact: false,
3609
+ message: check.message
3610
+ });
3611
+ status.dirty();
3612
+ }
3613
+ } else if (check.kind === "multipleOf") {
3614
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
3615
+ ctx = this._getOrReturnCtx(input, ctx);
3616
+ addIssueToContext(ctx, {
3617
+ code: ZodIssueCode.not_multiple_of,
3618
+ multipleOf: check.value,
3619
+ message: check.message
3620
+ });
3621
+ status.dirty();
3622
+ }
3623
+ } else if (check.kind === "finite") {
3624
+ if (!Number.isFinite(input.data)) {
3625
+ ctx = this._getOrReturnCtx(input, ctx);
3626
+ addIssueToContext(ctx, {
3627
+ code: ZodIssueCode.not_finite,
3628
+ message: check.message
3629
+ });
3630
+ status.dirty();
3631
+ }
3632
+ } else {
3633
+ util.assertNever(check);
3634
+ }
3635
+ }
3636
+ return { status: status.value, value: input.data };
3637
+ }
3638
+ gte(value, message) {
3639
+ return this.setLimit("min", value, true, errorUtil.toString(message));
3640
+ }
3641
+ gt(value, message) {
3642
+ return this.setLimit("min", value, false, errorUtil.toString(message));
3643
+ }
3644
+ lte(value, message) {
3645
+ return this.setLimit("max", value, true, errorUtil.toString(message));
3646
+ }
3647
+ lt(value, message) {
3648
+ return this.setLimit("max", value, false, errorUtil.toString(message));
3649
+ }
3650
+ setLimit(kind, value, inclusive, message) {
3651
+ return new ZodNumber({
3652
+ ...this._def,
3653
+ checks: [
3654
+ ...this._def.checks,
3655
+ {
3656
+ kind,
3657
+ value,
3658
+ inclusive,
3659
+ message: errorUtil.toString(message)
3660
+ }
3661
+ ]
3662
+ });
3663
+ }
3664
+ _addCheck(check) {
3665
+ return new ZodNumber({
3666
+ ...this._def,
3667
+ checks: [...this._def.checks, check]
3668
+ });
3669
+ }
3670
+ int(message) {
3671
+ return this._addCheck({
3672
+ kind: "int",
3673
+ message: errorUtil.toString(message)
3674
+ });
3675
+ }
3676
+ positive(message) {
3677
+ return this._addCheck({
3678
+ kind: "min",
3679
+ value: 0,
3680
+ inclusive: false,
3681
+ message: errorUtil.toString(message)
3682
+ });
3683
+ }
3684
+ negative(message) {
3685
+ return this._addCheck({
3686
+ kind: "max",
3687
+ value: 0,
3688
+ inclusive: false,
3689
+ message: errorUtil.toString(message)
3690
+ });
3691
+ }
3692
+ nonpositive(message) {
3693
+ return this._addCheck({
3694
+ kind: "max",
3695
+ value: 0,
3696
+ inclusive: true,
3697
+ message: errorUtil.toString(message)
3698
+ });
3699
+ }
3700
+ nonnegative(message) {
3701
+ return this._addCheck({
3702
+ kind: "min",
3703
+ value: 0,
3704
+ inclusive: true,
3705
+ message: errorUtil.toString(message)
3706
+ });
3707
+ }
3708
+ multipleOf(value, message) {
3709
+ return this._addCheck({
3710
+ kind: "multipleOf",
3711
+ value,
3712
+ message: errorUtil.toString(message)
3713
+ });
3714
+ }
3715
+ finite(message) {
3716
+ return this._addCheck({
3717
+ kind: "finite",
3718
+ message: errorUtil.toString(message)
3719
+ });
3720
+ }
3721
+ safe(message) {
3722
+ return this._addCheck({
3723
+ kind: "min",
3724
+ inclusive: true,
3725
+ value: Number.MIN_SAFE_INTEGER,
3726
+ message: errorUtil.toString(message)
3727
+ })._addCheck({
3728
+ kind: "max",
3729
+ inclusive: true,
3730
+ value: Number.MAX_SAFE_INTEGER,
3731
+ message: errorUtil.toString(message)
3732
+ });
3733
+ }
3734
+ get minValue() {
3735
+ let min = null;
3736
+ for (const ch of this._def.checks) {
3737
+ if (ch.kind === "min") {
3738
+ if (min === null || ch.value > min)
3739
+ min = ch.value;
3740
+ }
3741
+ }
3742
+ return min;
3743
+ }
3744
+ get maxValue() {
3745
+ let max = null;
3746
+ for (const ch of this._def.checks) {
3747
+ if (ch.kind === "max") {
3748
+ if (max === null || ch.value < max)
3749
+ max = ch.value;
3750
+ }
3751
+ }
3752
+ return max;
3753
+ }
3754
+ get isInt() {
3755
+ return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
3756
+ }
3757
+ get isFinite() {
3758
+ let max = null;
3759
+ let min = null;
3760
+ for (const ch of this._def.checks) {
3761
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
3762
+ return true;
3763
+ } else if (ch.kind === "min") {
3764
+ if (min === null || ch.value > min)
3765
+ min = ch.value;
3766
+ } else if (ch.kind === "max") {
3767
+ if (max === null || ch.value < max)
3768
+ max = ch.value;
3769
+ }
3770
+ }
3771
+ return Number.isFinite(min) && Number.isFinite(max);
3772
+ }
3773
+ }
3774
+ ZodNumber.create = (params) => {
3775
+ return new ZodNumber({
3776
+ checks: [],
3777
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
3778
+ coerce: params?.coerce || false,
3779
+ ...processCreateParams(params)
3780
+ });
3781
+ };
3782
+
3783
+ class ZodBigInt extends ZodType {
3784
+ constructor() {
3785
+ super(...arguments);
3786
+ this.min = this.gte;
3787
+ this.max = this.lte;
3788
+ }
3789
+ _parse(input) {
3790
+ if (this._def.coerce) {
3791
+ try {
3792
+ input.data = BigInt(input.data);
3793
+ } catch {
3794
+ return this._getInvalidInput(input);
3795
+ }
3796
+ }
3797
+ const parsedType = this._getType(input);
3798
+ if (parsedType !== ZodParsedType.bigint) {
3799
+ return this._getInvalidInput(input);
3800
+ }
3801
+ let ctx = undefined;
3802
+ const status = new ParseStatus;
3803
+ for (const check of this._def.checks) {
3804
+ if (check.kind === "min") {
3805
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
3806
+ if (tooSmall) {
3807
+ ctx = this._getOrReturnCtx(input, ctx);
3808
+ addIssueToContext(ctx, {
3809
+ code: ZodIssueCode.too_small,
3810
+ type: "bigint",
3811
+ minimum: check.value,
3812
+ inclusive: check.inclusive,
3813
+ message: check.message
3814
+ });
3815
+ status.dirty();
3816
+ }
3817
+ } else if (check.kind === "max") {
3818
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
3819
+ if (tooBig) {
3820
+ ctx = this._getOrReturnCtx(input, ctx);
3821
+ addIssueToContext(ctx, {
3822
+ code: ZodIssueCode.too_big,
3823
+ type: "bigint",
3824
+ maximum: check.value,
3825
+ inclusive: check.inclusive,
3826
+ message: check.message
3827
+ });
3828
+ status.dirty();
3829
+ }
3830
+ } else if (check.kind === "multipleOf") {
3831
+ if (input.data % check.value !== BigInt(0)) {
3832
+ ctx = this._getOrReturnCtx(input, ctx);
3833
+ addIssueToContext(ctx, {
3834
+ code: ZodIssueCode.not_multiple_of,
3835
+ multipleOf: check.value,
3836
+ message: check.message
3837
+ });
3838
+ status.dirty();
3839
+ }
3840
+ } else {
3841
+ util.assertNever(check);
3842
+ }
3843
+ }
3844
+ return { status: status.value, value: input.data };
3845
+ }
3846
+ _getInvalidInput(input) {
3847
+ const ctx = this._getOrReturnCtx(input);
3848
+ addIssueToContext(ctx, {
3849
+ code: ZodIssueCode.invalid_type,
3850
+ expected: ZodParsedType.bigint,
3851
+ received: ctx.parsedType
3852
+ });
3853
+ return INVALID;
3854
+ }
3855
+ gte(value, message) {
3856
+ return this.setLimit("min", value, true, errorUtil.toString(message));
3857
+ }
3858
+ gt(value, message) {
3859
+ return this.setLimit("min", value, false, errorUtil.toString(message));
3860
+ }
3861
+ lte(value, message) {
3862
+ return this.setLimit("max", value, true, errorUtil.toString(message));
3863
+ }
3864
+ lt(value, message) {
3865
+ return this.setLimit("max", value, false, errorUtil.toString(message));
3866
+ }
3867
+ setLimit(kind, value, inclusive, message) {
3868
+ return new ZodBigInt({
3869
+ ...this._def,
3870
+ checks: [
3871
+ ...this._def.checks,
3872
+ {
3873
+ kind,
3874
+ value,
3875
+ inclusive,
3876
+ message: errorUtil.toString(message)
3877
+ }
3878
+ ]
3879
+ });
3880
+ }
3881
+ _addCheck(check) {
3882
+ return new ZodBigInt({
3883
+ ...this._def,
3884
+ checks: [...this._def.checks, check]
3885
+ });
3886
+ }
3887
+ positive(message) {
3888
+ return this._addCheck({
3889
+ kind: "min",
3890
+ value: BigInt(0),
3891
+ inclusive: false,
3892
+ message: errorUtil.toString(message)
3893
+ });
3894
+ }
3895
+ negative(message) {
3896
+ return this._addCheck({
3897
+ kind: "max",
3898
+ value: BigInt(0),
3899
+ inclusive: false,
3900
+ message: errorUtil.toString(message)
3901
+ });
3902
+ }
3903
+ nonpositive(message) {
3904
+ return this._addCheck({
3905
+ kind: "max",
3906
+ value: BigInt(0),
3907
+ inclusive: true,
3908
+ message: errorUtil.toString(message)
3909
+ });
3910
+ }
3911
+ nonnegative(message) {
3912
+ return this._addCheck({
3913
+ kind: "min",
3914
+ value: BigInt(0),
3915
+ inclusive: true,
3916
+ message: errorUtil.toString(message)
3917
+ });
3918
+ }
3919
+ multipleOf(value, message) {
3920
+ return this._addCheck({
3921
+ kind: "multipleOf",
3922
+ value,
3923
+ message: errorUtil.toString(message)
3924
+ });
3925
+ }
3926
+ get minValue() {
3927
+ let min = null;
3928
+ for (const ch of this._def.checks) {
3929
+ if (ch.kind === "min") {
3930
+ if (min === null || ch.value > min)
3931
+ min = ch.value;
3932
+ }
3933
+ }
3934
+ return min;
3935
+ }
3936
+ get maxValue() {
3937
+ let max = null;
3938
+ for (const ch of this._def.checks) {
3939
+ if (ch.kind === "max") {
3940
+ if (max === null || ch.value < max)
3941
+ max = ch.value;
3942
+ }
3943
+ }
3944
+ return max;
3945
+ }
3946
+ }
3947
+ ZodBigInt.create = (params) => {
3948
+ return new ZodBigInt({
3949
+ checks: [],
3950
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
3951
+ coerce: params?.coerce ?? false,
3952
+ ...processCreateParams(params)
3953
+ });
3954
+ };
3955
+
3956
+ class ZodBoolean extends ZodType {
3957
+ _parse(input) {
3958
+ if (this._def.coerce) {
3959
+ input.data = Boolean(input.data);
3960
+ }
3961
+ const parsedType = this._getType(input);
3962
+ if (parsedType !== ZodParsedType.boolean) {
3963
+ const ctx = this._getOrReturnCtx(input);
3964
+ addIssueToContext(ctx, {
3965
+ code: ZodIssueCode.invalid_type,
3966
+ expected: ZodParsedType.boolean,
3967
+ received: ctx.parsedType
3968
+ });
3969
+ return INVALID;
3970
+ }
3971
+ return OK(input.data);
3972
+ }
3973
+ }
3974
+ ZodBoolean.create = (params) => {
3975
+ return new ZodBoolean({
3976
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
3977
+ coerce: params?.coerce || false,
3978
+ ...processCreateParams(params)
3979
+ });
3980
+ };
3981
+
3982
+ class ZodDate extends ZodType {
3983
+ _parse(input) {
3984
+ if (this._def.coerce) {
3985
+ input.data = new Date(input.data);
3986
+ }
3987
+ const parsedType = this._getType(input);
3988
+ if (parsedType !== ZodParsedType.date) {
3989
+ const ctx2 = this._getOrReturnCtx(input);
3990
+ addIssueToContext(ctx2, {
3991
+ code: ZodIssueCode.invalid_type,
3992
+ expected: ZodParsedType.date,
3993
+ received: ctx2.parsedType
3994
+ });
3995
+ return INVALID;
3996
+ }
3997
+ if (Number.isNaN(input.data.getTime())) {
3998
+ const ctx2 = this._getOrReturnCtx(input);
3999
+ addIssueToContext(ctx2, {
4000
+ code: ZodIssueCode.invalid_date
4001
+ });
4002
+ return INVALID;
4003
+ }
4004
+ const status = new ParseStatus;
4005
+ let ctx = undefined;
4006
+ for (const check of this._def.checks) {
4007
+ if (check.kind === "min") {
4008
+ if (input.data.getTime() < check.value) {
4009
+ ctx = this._getOrReturnCtx(input, ctx);
4010
+ addIssueToContext(ctx, {
4011
+ code: ZodIssueCode.too_small,
4012
+ message: check.message,
4013
+ inclusive: true,
4014
+ exact: false,
4015
+ minimum: check.value,
4016
+ type: "date"
4017
+ });
4018
+ status.dirty();
4019
+ }
4020
+ } else if (check.kind === "max") {
4021
+ if (input.data.getTime() > check.value) {
4022
+ ctx = this._getOrReturnCtx(input, ctx);
4023
+ addIssueToContext(ctx, {
4024
+ code: ZodIssueCode.too_big,
4025
+ message: check.message,
4026
+ inclusive: true,
4027
+ exact: false,
4028
+ maximum: check.value,
4029
+ type: "date"
4030
+ });
4031
+ status.dirty();
4032
+ }
4033
+ } else {
4034
+ util.assertNever(check);
4035
+ }
4036
+ }
4037
+ return {
4038
+ status: status.value,
4039
+ value: new Date(input.data.getTime())
4040
+ };
4041
+ }
4042
+ _addCheck(check) {
4043
+ return new ZodDate({
4044
+ ...this._def,
4045
+ checks: [...this._def.checks, check]
4046
+ });
4047
+ }
4048
+ min(minDate, message) {
4049
+ return this._addCheck({
4050
+ kind: "min",
4051
+ value: minDate.getTime(),
4052
+ message: errorUtil.toString(message)
4053
+ });
4054
+ }
4055
+ max(maxDate, message) {
4056
+ return this._addCheck({
4057
+ kind: "max",
4058
+ value: maxDate.getTime(),
4059
+ message: errorUtil.toString(message)
4060
+ });
4061
+ }
4062
+ get minDate() {
4063
+ let min = null;
4064
+ for (const ch of this._def.checks) {
4065
+ if (ch.kind === "min") {
4066
+ if (min === null || ch.value > min)
4067
+ min = ch.value;
4068
+ }
4069
+ }
4070
+ return min != null ? new Date(min) : null;
4071
+ }
4072
+ get maxDate() {
4073
+ let max = null;
4074
+ for (const ch of this._def.checks) {
4075
+ if (ch.kind === "max") {
4076
+ if (max === null || ch.value < max)
4077
+ max = ch.value;
4078
+ }
4079
+ }
4080
+ return max != null ? new Date(max) : null;
4081
+ }
4082
+ }
4083
+ ZodDate.create = (params) => {
4084
+ return new ZodDate({
4085
+ checks: [],
4086
+ coerce: params?.coerce || false,
4087
+ typeName: ZodFirstPartyTypeKind.ZodDate,
4088
+ ...processCreateParams(params)
4089
+ });
4090
+ };
4091
+
4092
+ class ZodSymbol extends ZodType {
4093
+ _parse(input) {
4094
+ const parsedType = this._getType(input);
4095
+ if (parsedType !== ZodParsedType.symbol) {
4096
+ const ctx = this._getOrReturnCtx(input);
4097
+ addIssueToContext(ctx, {
4098
+ code: ZodIssueCode.invalid_type,
4099
+ expected: ZodParsedType.symbol,
4100
+ received: ctx.parsedType
4101
+ });
4102
+ return INVALID;
4103
+ }
4104
+ return OK(input.data);
4105
+ }
4106
+ }
4107
+ ZodSymbol.create = (params) => {
4108
+ return new ZodSymbol({
4109
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
4110
+ ...processCreateParams(params)
4111
+ });
4112
+ };
4113
+
4114
+ class ZodUndefined extends ZodType {
4115
+ _parse(input) {
4116
+ const parsedType = this._getType(input);
4117
+ if (parsedType !== ZodParsedType.undefined) {
4118
+ const ctx = this._getOrReturnCtx(input);
4119
+ addIssueToContext(ctx, {
4120
+ code: ZodIssueCode.invalid_type,
4121
+ expected: ZodParsedType.undefined,
4122
+ received: ctx.parsedType
4123
+ });
4124
+ return INVALID;
4125
+ }
4126
+ return OK(input.data);
4127
+ }
4128
+ }
4129
+ ZodUndefined.create = (params) => {
4130
+ return new ZodUndefined({
4131
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
4132
+ ...processCreateParams(params)
4133
+ });
4134
+ };
4135
+
4136
+ class ZodNull extends ZodType {
4137
+ _parse(input) {
4138
+ const parsedType = this._getType(input);
4139
+ if (parsedType !== ZodParsedType.null) {
4140
+ const ctx = this._getOrReturnCtx(input);
4141
+ addIssueToContext(ctx, {
4142
+ code: ZodIssueCode.invalid_type,
4143
+ expected: ZodParsedType.null,
4144
+ received: ctx.parsedType
4145
+ });
4146
+ return INVALID;
4147
+ }
4148
+ return OK(input.data);
4149
+ }
4150
+ }
4151
+ ZodNull.create = (params) => {
4152
+ return new ZodNull({
4153
+ typeName: ZodFirstPartyTypeKind.ZodNull,
4154
+ ...processCreateParams(params)
4155
+ });
4156
+ };
4157
+
4158
+ class ZodAny extends ZodType {
4159
+ constructor() {
4160
+ super(...arguments);
4161
+ this._any = true;
4162
+ }
4163
+ _parse(input) {
4164
+ return OK(input.data);
4165
+ }
4166
+ }
4167
+ ZodAny.create = (params) => {
4168
+ return new ZodAny({
4169
+ typeName: ZodFirstPartyTypeKind.ZodAny,
4170
+ ...processCreateParams(params)
4171
+ });
4172
+ };
4173
+
4174
+ class ZodUnknown extends ZodType {
4175
+ constructor() {
4176
+ super(...arguments);
4177
+ this._unknown = true;
4178
+ }
4179
+ _parse(input) {
4180
+ return OK(input.data);
4181
+ }
4182
+ }
4183
+ ZodUnknown.create = (params) => {
4184
+ return new ZodUnknown({
4185
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
4186
+ ...processCreateParams(params)
4187
+ });
4188
+ };
4189
+
4190
+ class ZodNever extends ZodType {
4191
+ _parse(input) {
4192
+ const ctx = this._getOrReturnCtx(input);
4193
+ addIssueToContext(ctx, {
4194
+ code: ZodIssueCode.invalid_type,
4195
+ expected: ZodParsedType.never,
4196
+ received: ctx.parsedType
4197
+ });
4198
+ return INVALID;
4199
+ }
4200
+ }
4201
+ ZodNever.create = (params) => {
4202
+ return new ZodNever({
4203
+ typeName: ZodFirstPartyTypeKind.ZodNever,
4204
+ ...processCreateParams(params)
4205
+ });
4206
+ };
4207
+
4208
+ class ZodVoid extends ZodType {
4209
+ _parse(input) {
4210
+ const parsedType = this._getType(input);
4211
+ if (parsedType !== ZodParsedType.undefined) {
4212
+ const ctx = this._getOrReturnCtx(input);
4213
+ addIssueToContext(ctx, {
4214
+ code: ZodIssueCode.invalid_type,
4215
+ expected: ZodParsedType.void,
4216
+ received: ctx.parsedType
4217
+ });
4218
+ return INVALID;
4219
+ }
4220
+ return OK(input.data);
4221
+ }
4222
+ }
4223
+ ZodVoid.create = (params) => {
4224
+ return new ZodVoid({
4225
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
4226
+ ...processCreateParams(params)
4227
+ });
4228
+ };
4229
+
4230
+ class ZodArray extends ZodType {
4231
+ _parse(input) {
4232
+ const { ctx, status } = this._processInputParams(input);
4233
+ const def = this._def;
4234
+ if (ctx.parsedType !== ZodParsedType.array) {
4235
+ addIssueToContext(ctx, {
4236
+ code: ZodIssueCode.invalid_type,
4237
+ expected: ZodParsedType.array,
4238
+ received: ctx.parsedType
4239
+ });
4240
+ return INVALID;
4241
+ }
4242
+ if (def.exactLength !== null) {
4243
+ const tooBig = ctx.data.length > def.exactLength.value;
4244
+ const tooSmall = ctx.data.length < def.exactLength.value;
4245
+ if (tooBig || tooSmall) {
4246
+ addIssueToContext(ctx, {
4247
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
4248
+ minimum: tooSmall ? def.exactLength.value : undefined,
4249
+ maximum: tooBig ? def.exactLength.value : undefined,
4250
+ type: "array",
4251
+ inclusive: true,
4252
+ exact: true,
4253
+ message: def.exactLength.message
4254
+ });
4255
+ status.dirty();
4256
+ }
4257
+ }
4258
+ if (def.minLength !== null) {
4259
+ if (ctx.data.length < def.minLength.value) {
4260
+ addIssueToContext(ctx, {
4261
+ code: ZodIssueCode.too_small,
4262
+ minimum: def.minLength.value,
4263
+ type: "array",
4264
+ inclusive: true,
4265
+ exact: false,
4266
+ message: def.minLength.message
4267
+ });
4268
+ status.dirty();
4269
+ }
4270
+ }
4271
+ if (def.maxLength !== null) {
4272
+ if (ctx.data.length > def.maxLength.value) {
4273
+ addIssueToContext(ctx, {
4274
+ code: ZodIssueCode.too_big,
4275
+ maximum: def.maxLength.value,
4276
+ type: "array",
4277
+ inclusive: true,
4278
+ exact: false,
4279
+ message: def.maxLength.message
4280
+ });
4281
+ status.dirty();
4282
+ }
4283
+ }
4284
+ if (ctx.common.async) {
4285
+ return Promise.all([...ctx.data].map((item, i) => {
4286
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
4287
+ })).then((result2) => {
4288
+ return ParseStatus.mergeArray(status, result2);
4289
+ });
4290
+ }
4291
+ const result = [...ctx.data].map((item, i) => {
4292
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
4293
+ });
4294
+ return ParseStatus.mergeArray(status, result);
4295
+ }
4296
+ get element() {
4297
+ return this._def.type;
4298
+ }
4299
+ min(minLength, message) {
4300
+ return new ZodArray({
4301
+ ...this._def,
4302
+ minLength: { value: minLength, message: errorUtil.toString(message) }
4303
+ });
4304
+ }
4305
+ max(maxLength, message) {
4306
+ return new ZodArray({
4307
+ ...this._def,
4308
+ maxLength: { value: maxLength, message: errorUtil.toString(message) }
4309
+ });
4310
+ }
4311
+ length(len, message) {
4312
+ return new ZodArray({
4313
+ ...this._def,
4314
+ exactLength: { value: len, message: errorUtil.toString(message) }
4315
+ });
4316
+ }
4317
+ nonempty(message) {
4318
+ return this.min(1, message);
4319
+ }
4320
+ }
4321
+ ZodArray.create = (schema, params) => {
4322
+ return new ZodArray({
4323
+ type: schema,
4324
+ minLength: null,
4325
+ maxLength: null,
4326
+ exactLength: null,
4327
+ typeName: ZodFirstPartyTypeKind.ZodArray,
4328
+ ...processCreateParams(params)
4329
+ });
4330
+ };
4331
+ function deepPartialify(schema) {
4332
+ if (schema instanceof ZodObject) {
4333
+ const newShape = {};
4334
+ for (const key in schema.shape) {
4335
+ const fieldSchema = schema.shape[key];
4336
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
4337
+ }
4338
+ return new ZodObject({
4339
+ ...schema._def,
4340
+ shape: () => newShape
4341
+ });
4342
+ } else if (schema instanceof ZodArray) {
4343
+ return new ZodArray({
4344
+ ...schema._def,
4345
+ type: deepPartialify(schema.element)
4346
+ });
4347
+ } else if (schema instanceof ZodOptional) {
4348
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
4349
+ } else if (schema instanceof ZodNullable) {
4350
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
4351
+ } else if (schema instanceof ZodTuple) {
4352
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
4353
+ } else {
4354
+ return schema;
4355
+ }
4356
+ }
4357
+
4358
+ class ZodObject extends ZodType {
4359
+ constructor() {
4360
+ super(...arguments);
4361
+ this._cached = null;
4362
+ this.nonstrict = this.passthrough;
4363
+ this.augment = this.extend;
4364
+ }
4365
+ _getCached() {
4366
+ if (this._cached !== null)
4367
+ return this._cached;
4368
+ const shape = this._def.shape();
4369
+ const keys = util.objectKeys(shape);
4370
+ this._cached = { shape, keys };
4371
+ return this._cached;
4372
+ }
4373
+ _parse(input) {
4374
+ const parsedType = this._getType(input);
4375
+ if (parsedType !== ZodParsedType.object) {
4376
+ const ctx2 = this._getOrReturnCtx(input);
4377
+ addIssueToContext(ctx2, {
4378
+ code: ZodIssueCode.invalid_type,
4379
+ expected: ZodParsedType.object,
4380
+ received: ctx2.parsedType
4381
+ });
4382
+ return INVALID;
4383
+ }
4384
+ const { status, ctx } = this._processInputParams(input);
4385
+ const { shape, keys: shapeKeys } = this._getCached();
4386
+ const extraKeys = [];
4387
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
4388
+ for (const key in ctx.data) {
4389
+ if (!shapeKeys.includes(key)) {
4390
+ extraKeys.push(key);
4391
+ }
4392
+ }
4393
+ }
4394
+ const pairs = [];
4395
+ for (const key of shapeKeys) {
4396
+ const keyValidator = shape[key];
4397
+ const value = ctx.data[key];
4398
+ pairs.push({
4399
+ key: { status: "valid", value: key },
4400
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
4401
+ alwaysSet: key in ctx.data
4402
+ });
4403
+ }
4404
+ if (this._def.catchall instanceof ZodNever) {
4405
+ const unknownKeys = this._def.unknownKeys;
4406
+ if (unknownKeys === "passthrough") {
4407
+ for (const key of extraKeys) {
4408
+ pairs.push({
4409
+ key: { status: "valid", value: key },
4410
+ value: { status: "valid", value: ctx.data[key] }
4411
+ });
4412
+ }
4413
+ } else if (unknownKeys === "strict") {
4414
+ if (extraKeys.length > 0) {
4415
+ addIssueToContext(ctx, {
4416
+ code: ZodIssueCode.unrecognized_keys,
4417
+ keys: extraKeys
4418
+ });
4419
+ status.dirty();
4420
+ }
4421
+ } else if (unknownKeys === "strip") {} else {
4422
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
4423
+ }
4424
+ } else {
4425
+ const catchall = this._def.catchall;
4426
+ for (const key of extraKeys) {
4427
+ const value = ctx.data[key];
4428
+ pairs.push({
4429
+ key: { status: "valid", value: key },
4430
+ value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
4431
+ alwaysSet: key in ctx.data
4432
+ });
4433
+ }
4434
+ }
4435
+ if (ctx.common.async) {
4436
+ return Promise.resolve().then(async () => {
4437
+ const syncPairs = [];
4438
+ for (const pair of pairs) {
4439
+ const key = await pair.key;
4440
+ const value = await pair.value;
4441
+ syncPairs.push({
4442
+ key,
4443
+ value,
4444
+ alwaysSet: pair.alwaysSet
4445
+ });
4446
+ }
4447
+ return syncPairs;
4448
+ }).then((syncPairs) => {
4449
+ return ParseStatus.mergeObjectSync(status, syncPairs);
4450
+ });
4451
+ } else {
4452
+ return ParseStatus.mergeObjectSync(status, pairs);
4453
+ }
4454
+ }
4455
+ get shape() {
4456
+ return this._def.shape();
4457
+ }
4458
+ strict(message) {
4459
+ errorUtil.errToObj;
4460
+ return new ZodObject({
4461
+ ...this._def,
4462
+ unknownKeys: "strict",
4463
+ ...message !== undefined ? {
4464
+ errorMap: (issue, ctx) => {
4465
+ const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
4466
+ if (issue.code === "unrecognized_keys")
4467
+ return {
4468
+ message: errorUtil.errToObj(message).message ?? defaultError
4469
+ };
4470
+ return {
4471
+ message: defaultError
4472
+ };
4473
+ }
4474
+ } : {}
4475
+ });
4476
+ }
4477
+ strip() {
4478
+ return new ZodObject({
4479
+ ...this._def,
4480
+ unknownKeys: "strip"
4481
+ });
4482
+ }
4483
+ passthrough() {
4484
+ return new ZodObject({
4485
+ ...this._def,
4486
+ unknownKeys: "passthrough"
4487
+ });
4488
+ }
4489
+ extend(augmentation) {
4490
+ return new ZodObject({
4491
+ ...this._def,
4492
+ shape: () => ({
4493
+ ...this._def.shape(),
4494
+ ...augmentation
4495
+ })
4496
+ });
4497
+ }
4498
+ merge(merging) {
4499
+ const merged = new ZodObject({
4500
+ unknownKeys: merging._def.unknownKeys,
4501
+ catchall: merging._def.catchall,
4502
+ shape: () => ({
4503
+ ...this._def.shape(),
4504
+ ...merging._def.shape()
4505
+ }),
4506
+ typeName: ZodFirstPartyTypeKind.ZodObject
4507
+ });
4508
+ return merged;
4509
+ }
4510
+ setKey(key, schema) {
4511
+ return this.augment({ [key]: schema });
4512
+ }
4513
+ catchall(index) {
4514
+ return new ZodObject({
4515
+ ...this._def,
4516
+ catchall: index
4517
+ });
4518
+ }
4519
+ pick(mask) {
4520
+ const shape = {};
4521
+ for (const key of util.objectKeys(mask)) {
4522
+ if (mask[key] && this.shape[key]) {
4523
+ shape[key] = this.shape[key];
4524
+ }
4525
+ }
4526
+ return new ZodObject({
4527
+ ...this._def,
4528
+ shape: () => shape
4529
+ });
4530
+ }
4531
+ omit(mask) {
4532
+ const shape = {};
4533
+ for (const key of util.objectKeys(this.shape)) {
4534
+ if (!mask[key]) {
4535
+ shape[key] = this.shape[key];
4536
+ }
4537
+ }
4538
+ return new ZodObject({
4539
+ ...this._def,
4540
+ shape: () => shape
4541
+ });
4542
+ }
4543
+ deepPartial() {
4544
+ return deepPartialify(this);
4545
+ }
4546
+ partial(mask) {
4547
+ const newShape = {};
4548
+ for (const key of util.objectKeys(this.shape)) {
4549
+ const fieldSchema = this.shape[key];
4550
+ if (mask && !mask[key]) {
4551
+ newShape[key] = fieldSchema;
4552
+ } else {
4553
+ newShape[key] = fieldSchema.optional();
4554
+ }
4555
+ }
4556
+ return new ZodObject({
4557
+ ...this._def,
4558
+ shape: () => newShape
4559
+ });
4560
+ }
4561
+ required(mask) {
4562
+ const newShape = {};
4563
+ for (const key of util.objectKeys(this.shape)) {
4564
+ if (mask && !mask[key]) {
4565
+ newShape[key] = this.shape[key];
4566
+ } else {
4567
+ const fieldSchema = this.shape[key];
4568
+ let newField = fieldSchema;
4569
+ while (newField instanceof ZodOptional) {
4570
+ newField = newField._def.innerType;
4571
+ }
4572
+ newShape[key] = newField;
4573
+ }
4574
+ }
4575
+ return new ZodObject({
4576
+ ...this._def,
4577
+ shape: () => newShape
4578
+ });
4579
+ }
4580
+ keyof() {
4581
+ return createZodEnum(util.objectKeys(this.shape));
4582
+ }
4583
+ }
4584
+ ZodObject.create = (shape, params) => {
4585
+ return new ZodObject({
4586
+ shape: () => shape,
4587
+ unknownKeys: "strip",
4588
+ catchall: ZodNever.create(),
4589
+ typeName: ZodFirstPartyTypeKind.ZodObject,
4590
+ ...processCreateParams(params)
4591
+ });
4592
+ };
4593
+ ZodObject.strictCreate = (shape, params) => {
4594
+ return new ZodObject({
4595
+ shape: () => shape,
4596
+ unknownKeys: "strict",
4597
+ catchall: ZodNever.create(),
4598
+ typeName: ZodFirstPartyTypeKind.ZodObject,
4599
+ ...processCreateParams(params)
4600
+ });
4601
+ };
4602
+ ZodObject.lazycreate = (shape, params) => {
4603
+ return new ZodObject({
4604
+ shape,
4605
+ unknownKeys: "strip",
4606
+ catchall: ZodNever.create(),
4607
+ typeName: ZodFirstPartyTypeKind.ZodObject,
4608
+ ...processCreateParams(params)
4609
+ });
4610
+ };
4611
+
4612
+ class ZodUnion extends ZodType {
4613
+ _parse(input) {
4614
+ const { ctx } = this._processInputParams(input);
4615
+ const options = this._def.options;
4616
+ function handleResults(results) {
4617
+ for (const result of results) {
4618
+ if (result.result.status === "valid") {
4619
+ return result.result;
4620
+ }
4621
+ }
4622
+ for (const result of results) {
4623
+ if (result.result.status === "dirty") {
4624
+ ctx.common.issues.push(...result.ctx.common.issues);
4625
+ return result.result;
4626
+ }
4627
+ }
4628
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
4629
+ addIssueToContext(ctx, {
4630
+ code: ZodIssueCode.invalid_union,
4631
+ unionErrors
4632
+ });
4633
+ return INVALID;
4634
+ }
4635
+ if (ctx.common.async) {
4636
+ return Promise.all(options.map(async (option) => {
4637
+ const childCtx = {
4638
+ ...ctx,
4639
+ common: {
4640
+ ...ctx.common,
4641
+ issues: []
4642
+ },
4643
+ parent: null
4644
+ };
4645
+ return {
4646
+ result: await option._parseAsync({
4647
+ data: ctx.data,
4648
+ path: ctx.path,
4649
+ parent: childCtx
4650
+ }),
4651
+ ctx: childCtx
4652
+ };
4653
+ })).then(handleResults);
4654
+ } else {
4655
+ let dirty = undefined;
4656
+ const issues = [];
4657
+ for (const option of options) {
4658
+ const childCtx = {
4659
+ ...ctx,
4660
+ common: {
4661
+ ...ctx.common,
4662
+ issues: []
4663
+ },
4664
+ parent: null
4665
+ };
4666
+ const result = option._parseSync({
4667
+ data: ctx.data,
4668
+ path: ctx.path,
4669
+ parent: childCtx
4670
+ });
4671
+ if (result.status === "valid") {
4672
+ return result;
4673
+ } else if (result.status === "dirty" && !dirty) {
4674
+ dirty = { result, ctx: childCtx };
4675
+ }
4676
+ if (childCtx.common.issues.length) {
4677
+ issues.push(childCtx.common.issues);
4678
+ }
4679
+ }
4680
+ if (dirty) {
4681
+ ctx.common.issues.push(...dirty.ctx.common.issues);
4682
+ return dirty.result;
4683
+ }
4684
+ const unionErrors = issues.map((issues2) => new ZodError(issues2));
4685
+ addIssueToContext(ctx, {
4686
+ code: ZodIssueCode.invalid_union,
4687
+ unionErrors
4688
+ });
4689
+ return INVALID;
4690
+ }
4691
+ }
4692
+ get options() {
4693
+ return this._def.options;
4694
+ }
4695
+ }
4696
+ ZodUnion.create = (types, params) => {
4697
+ return new ZodUnion({
4698
+ options: types,
4699
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
4700
+ ...processCreateParams(params)
4701
+ });
4702
+ };
4703
+ var getDiscriminator = (type) => {
4704
+ if (type instanceof ZodLazy) {
4705
+ return getDiscriminator(type.schema);
4706
+ } else if (type instanceof ZodEffects) {
4707
+ return getDiscriminator(type.innerType());
4708
+ } else if (type instanceof ZodLiteral) {
4709
+ return [type.value];
4710
+ } else if (type instanceof ZodEnum) {
4711
+ return type.options;
4712
+ } else if (type instanceof ZodNativeEnum) {
4713
+ return util.objectValues(type.enum);
4714
+ } else if (type instanceof ZodDefault) {
4715
+ return getDiscriminator(type._def.innerType);
4716
+ } else if (type instanceof ZodUndefined) {
4717
+ return [undefined];
4718
+ } else if (type instanceof ZodNull) {
4719
+ return [null];
4720
+ } else if (type instanceof ZodOptional) {
4721
+ return [undefined, ...getDiscriminator(type.unwrap())];
4722
+ } else if (type instanceof ZodNullable) {
4723
+ return [null, ...getDiscriminator(type.unwrap())];
4724
+ } else if (type instanceof ZodBranded) {
4725
+ return getDiscriminator(type.unwrap());
4726
+ } else if (type instanceof ZodReadonly) {
4727
+ return getDiscriminator(type.unwrap());
4728
+ } else if (type instanceof ZodCatch) {
4729
+ return getDiscriminator(type._def.innerType);
4730
+ } else {
4731
+ return [];
4732
+ }
4733
+ };
4734
+
4735
+ class ZodDiscriminatedUnion extends ZodType {
4736
+ _parse(input) {
4737
+ const { ctx } = this._processInputParams(input);
4738
+ if (ctx.parsedType !== ZodParsedType.object) {
4739
+ addIssueToContext(ctx, {
4740
+ code: ZodIssueCode.invalid_type,
4741
+ expected: ZodParsedType.object,
4742
+ received: ctx.parsedType
4743
+ });
4744
+ return INVALID;
4745
+ }
4746
+ const discriminator = this.discriminator;
4747
+ const discriminatorValue = ctx.data[discriminator];
4748
+ const option = this.optionsMap.get(discriminatorValue);
4749
+ if (!option) {
4750
+ addIssueToContext(ctx, {
4751
+ code: ZodIssueCode.invalid_union_discriminator,
4752
+ options: Array.from(this.optionsMap.keys()),
4753
+ path: [discriminator]
4754
+ });
4755
+ return INVALID;
4756
+ }
4757
+ if (ctx.common.async) {
4758
+ return option._parseAsync({
4759
+ data: ctx.data,
4760
+ path: ctx.path,
4761
+ parent: ctx
4762
+ });
4763
+ } else {
4764
+ return option._parseSync({
4765
+ data: ctx.data,
4766
+ path: ctx.path,
4767
+ parent: ctx
4768
+ });
4769
+ }
4770
+ }
4771
+ get discriminator() {
4772
+ return this._def.discriminator;
4773
+ }
4774
+ get options() {
4775
+ return this._def.options;
4776
+ }
4777
+ get optionsMap() {
4778
+ return this._def.optionsMap;
4779
+ }
4780
+ static create(discriminator, options, params) {
4781
+ const optionsMap = new Map;
4782
+ for (const type of options) {
4783
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
4784
+ if (!discriminatorValues.length) {
4785
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
4786
+ }
4787
+ for (const value of discriminatorValues) {
4788
+ if (optionsMap.has(value)) {
4789
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
4790
+ }
4791
+ optionsMap.set(value, type);
4792
+ }
4793
+ }
4794
+ return new ZodDiscriminatedUnion({
4795
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
4796
+ discriminator,
4797
+ options,
4798
+ optionsMap,
4799
+ ...processCreateParams(params)
4800
+ });
4801
+ }
4802
+ }
4803
+ function mergeValues(a, b) {
4804
+ const aType = getParsedType(a);
4805
+ const bType = getParsedType(b);
4806
+ if (a === b) {
4807
+ return { valid: true, data: a };
4808
+ } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
4809
+ const bKeys = util.objectKeys(b);
4810
+ const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
4811
+ const newObj = { ...a, ...b };
4812
+ for (const key of sharedKeys) {
4813
+ const sharedValue = mergeValues(a[key], b[key]);
4814
+ if (!sharedValue.valid) {
4815
+ return { valid: false };
4816
+ }
4817
+ newObj[key] = sharedValue.data;
4818
+ }
4819
+ return { valid: true, data: newObj };
4820
+ } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
4821
+ if (a.length !== b.length) {
4822
+ return { valid: false };
4823
+ }
4824
+ const newArray = [];
4825
+ for (let index = 0;index < a.length; index++) {
4826
+ const itemA = a[index];
4827
+ const itemB = b[index];
4828
+ const sharedValue = mergeValues(itemA, itemB);
4829
+ if (!sharedValue.valid) {
4830
+ return { valid: false };
4831
+ }
4832
+ newArray.push(sharedValue.data);
4833
+ }
4834
+ return { valid: true, data: newArray };
4835
+ } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
4836
+ return { valid: true, data: a };
4837
+ } else {
4838
+ return { valid: false };
4839
+ }
4840
+ }
4841
+
4842
+ class ZodIntersection extends ZodType {
4843
+ _parse(input) {
4844
+ const { status, ctx } = this._processInputParams(input);
4845
+ const handleParsed = (parsedLeft, parsedRight) => {
4846
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
4847
+ return INVALID;
4848
+ }
4849
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
4850
+ if (!merged.valid) {
4851
+ addIssueToContext(ctx, {
4852
+ code: ZodIssueCode.invalid_intersection_types
4853
+ });
4854
+ return INVALID;
4855
+ }
4856
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
4857
+ status.dirty();
4858
+ }
4859
+ return { status: status.value, value: merged.data };
4860
+ };
4861
+ if (ctx.common.async) {
4862
+ return Promise.all([
4863
+ this._def.left._parseAsync({
4864
+ data: ctx.data,
4865
+ path: ctx.path,
4866
+ parent: ctx
4867
+ }),
4868
+ this._def.right._parseAsync({
4869
+ data: ctx.data,
4870
+ path: ctx.path,
4871
+ parent: ctx
4872
+ })
4873
+ ]).then(([left, right]) => handleParsed(left, right));
4874
+ } else {
4875
+ return handleParsed(this._def.left._parseSync({
4876
+ data: ctx.data,
4877
+ path: ctx.path,
4878
+ parent: ctx
4879
+ }), this._def.right._parseSync({
4880
+ data: ctx.data,
4881
+ path: ctx.path,
4882
+ parent: ctx
4883
+ }));
4884
+ }
4885
+ }
4886
+ }
4887
+ ZodIntersection.create = (left, right, params) => {
4888
+ return new ZodIntersection({
4889
+ left,
4890
+ right,
4891
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
4892
+ ...processCreateParams(params)
4893
+ });
4894
+ };
4895
+
4896
+ class ZodTuple extends ZodType {
4897
+ _parse(input) {
4898
+ const { status, ctx } = this._processInputParams(input);
4899
+ if (ctx.parsedType !== ZodParsedType.array) {
4900
+ addIssueToContext(ctx, {
4901
+ code: ZodIssueCode.invalid_type,
4902
+ expected: ZodParsedType.array,
4903
+ received: ctx.parsedType
4904
+ });
4905
+ return INVALID;
4906
+ }
4907
+ if (ctx.data.length < this._def.items.length) {
4908
+ addIssueToContext(ctx, {
4909
+ code: ZodIssueCode.too_small,
4910
+ minimum: this._def.items.length,
4911
+ inclusive: true,
4912
+ exact: false,
4913
+ type: "array"
4914
+ });
4915
+ return INVALID;
4916
+ }
4917
+ const rest = this._def.rest;
4918
+ if (!rest && ctx.data.length > this._def.items.length) {
4919
+ addIssueToContext(ctx, {
4920
+ code: ZodIssueCode.too_big,
4921
+ maximum: this._def.items.length,
4922
+ inclusive: true,
4923
+ exact: false,
4924
+ type: "array"
4925
+ });
4926
+ status.dirty();
4927
+ }
4928
+ const items = [...ctx.data].map((item, itemIndex) => {
4929
+ const schema = this._def.items[itemIndex] || this._def.rest;
4930
+ if (!schema)
4931
+ return null;
4932
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
4933
+ }).filter((x) => !!x);
4934
+ if (ctx.common.async) {
4935
+ return Promise.all(items).then((results) => {
4936
+ return ParseStatus.mergeArray(status, results);
4937
+ });
4938
+ } else {
4939
+ return ParseStatus.mergeArray(status, items);
4940
+ }
4941
+ }
4942
+ get items() {
4943
+ return this._def.items;
4944
+ }
4945
+ rest(rest) {
4946
+ return new ZodTuple({
4947
+ ...this._def,
4948
+ rest
4949
+ });
4950
+ }
4951
+ }
4952
+ ZodTuple.create = (schemas, params) => {
4953
+ if (!Array.isArray(schemas)) {
4954
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
4955
+ }
4956
+ return new ZodTuple({
4957
+ items: schemas,
4958
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
4959
+ rest: null,
4960
+ ...processCreateParams(params)
4961
+ });
4962
+ };
4963
+
4964
+ class ZodRecord extends ZodType {
4965
+ get keySchema() {
4966
+ return this._def.keyType;
4967
+ }
4968
+ get valueSchema() {
4969
+ return this._def.valueType;
4970
+ }
4971
+ _parse(input) {
4972
+ const { status, ctx } = this._processInputParams(input);
4973
+ if (ctx.parsedType !== ZodParsedType.object) {
4974
+ addIssueToContext(ctx, {
4975
+ code: ZodIssueCode.invalid_type,
4976
+ expected: ZodParsedType.object,
4977
+ received: ctx.parsedType
4978
+ });
4979
+ return INVALID;
4980
+ }
4981
+ const pairs = [];
4982
+ const keyType = this._def.keyType;
4983
+ const valueType = this._def.valueType;
4984
+ for (const key in ctx.data) {
4985
+ pairs.push({
4986
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
4987
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
4988
+ alwaysSet: key in ctx.data
4989
+ });
4990
+ }
4991
+ if (ctx.common.async) {
4992
+ return ParseStatus.mergeObjectAsync(status, pairs);
4993
+ } else {
4994
+ return ParseStatus.mergeObjectSync(status, pairs);
4995
+ }
4996
+ }
4997
+ get element() {
4998
+ return this._def.valueType;
4999
+ }
5000
+ static create(first, second, third) {
5001
+ if (second instanceof ZodType) {
5002
+ return new ZodRecord({
5003
+ keyType: first,
5004
+ valueType: second,
5005
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
5006
+ ...processCreateParams(third)
5007
+ });
5008
+ }
5009
+ return new ZodRecord({
5010
+ keyType: ZodString.create(),
5011
+ valueType: first,
5012
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
5013
+ ...processCreateParams(second)
5014
+ });
5015
+ }
5016
+ }
5017
+
5018
+ class ZodMap extends ZodType {
5019
+ get keySchema() {
5020
+ return this._def.keyType;
5021
+ }
5022
+ get valueSchema() {
5023
+ return this._def.valueType;
5024
+ }
5025
+ _parse(input) {
5026
+ const { status, ctx } = this._processInputParams(input);
5027
+ if (ctx.parsedType !== ZodParsedType.map) {
5028
+ addIssueToContext(ctx, {
5029
+ code: ZodIssueCode.invalid_type,
5030
+ expected: ZodParsedType.map,
5031
+ received: ctx.parsedType
5032
+ });
5033
+ return INVALID;
5034
+ }
5035
+ const keyType = this._def.keyType;
5036
+ const valueType = this._def.valueType;
5037
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
5038
+ return {
5039
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
5040
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
5041
+ };
5042
+ });
5043
+ if (ctx.common.async) {
5044
+ const finalMap = new Map;
5045
+ return Promise.resolve().then(async () => {
5046
+ for (const pair of pairs) {
5047
+ const key = await pair.key;
5048
+ const value = await pair.value;
5049
+ if (key.status === "aborted" || value.status === "aborted") {
5050
+ return INVALID;
5051
+ }
5052
+ if (key.status === "dirty" || value.status === "dirty") {
5053
+ status.dirty();
5054
+ }
5055
+ finalMap.set(key.value, value.value);
5056
+ }
5057
+ return { status: status.value, value: finalMap };
5058
+ });
5059
+ } else {
5060
+ const finalMap = new Map;
5061
+ for (const pair of pairs) {
5062
+ const key = pair.key;
5063
+ const value = pair.value;
5064
+ if (key.status === "aborted" || value.status === "aborted") {
5065
+ return INVALID;
5066
+ }
5067
+ if (key.status === "dirty" || value.status === "dirty") {
5068
+ status.dirty();
5069
+ }
5070
+ finalMap.set(key.value, value.value);
5071
+ }
5072
+ return { status: status.value, value: finalMap };
5073
+ }
5074
+ }
5075
+ }
5076
+ ZodMap.create = (keyType, valueType, params) => {
5077
+ return new ZodMap({
5078
+ valueType,
5079
+ keyType,
5080
+ typeName: ZodFirstPartyTypeKind.ZodMap,
5081
+ ...processCreateParams(params)
5082
+ });
5083
+ };
5084
+
5085
+ class ZodSet extends ZodType {
5086
+ _parse(input) {
5087
+ const { status, ctx } = this._processInputParams(input);
5088
+ if (ctx.parsedType !== ZodParsedType.set) {
5089
+ addIssueToContext(ctx, {
5090
+ code: ZodIssueCode.invalid_type,
5091
+ expected: ZodParsedType.set,
5092
+ received: ctx.parsedType
5093
+ });
5094
+ return INVALID;
5095
+ }
5096
+ const def = this._def;
5097
+ if (def.minSize !== null) {
5098
+ if (ctx.data.size < def.minSize.value) {
5099
+ addIssueToContext(ctx, {
5100
+ code: ZodIssueCode.too_small,
5101
+ minimum: def.minSize.value,
5102
+ type: "set",
5103
+ inclusive: true,
5104
+ exact: false,
5105
+ message: def.minSize.message
5106
+ });
5107
+ status.dirty();
5108
+ }
5109
+ }
5110
+ if (def.maxSize !== null) {
5111
+ if (ctx.data.size > def.maxSize.value) {
5112
+ addIssueToContext(ctx, {
5113
+ code: ZodIssueCode.too_big,
5114
+ maximum: def.maxSize.value,
5115
+ type: "set",
5116
+ inclusive: true,
5117
+ exact: false,
5118
+ message: def.maxSize.message
5119
+ });
5120
+ status.dirty();
5121
+ }
5122
+ }
5123
+ const valueType = this._def.valueType;
5124
+ function finalizeSet(elements2) {
5125
+ const parsedSet = new Set;
5126
+ for (const element of elements2) {
5127
+ if (element.status === "aborted")
5128
+ return INVALID;
5129
+ if (element.status === "dirty")
5130
+ status.dirty();
5131
+ parsedSet.add(element.value);
5132
+ }
5133
+ return { status: status.value, value: parsedSet };
5134
+ }
5135
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
5136
+ if (ctx.common.async) {
5137
+ return Promise.all(elements).then((elements2) => finalizeSet(elements2));
5138
+ } else {
5139
+ return finalizeSet(elements);
5140
+ }
5141
+ }
5142
+ min(minSize, message) {
5143
+ return new ZodSet({
5144
+ ...this._def,
5145
+ minSize: { value: minSize, message: errorUtil.toString(message) }
5146
+ });
5147
+ }
5148
+ max(maxSize, message) {
5149
+ return new ZodSet({
5150
+ ...this._def,
5151
+ maxSize: { value: maxSize, message: errorUtil.toString(message) }
5152
+ });
5153
+ }
5154
+ size(size, message) {
5155
+ return this.min(size, message).max(size, message);
5156
+ }
5157
+ nonempty(message) {
5158
+ return this.min(1, message);
5159
+ }
5160
+ }
5161
+ ZodSet.create = (valueType, params) => {
5162
+ return new ZodSet({
5163
+ valueType,
5164
+ minSize: null,
5165
+ maxSize: null,
5166
+ typeName: ZodFirstPartyTypeKind.ZodSet,
5167
+ ...processCreateParams(params)
5168
+ });
5169
+ };
5170
+
5171
+ class ZodFunction extends ZodType {
5172
+ constructor() {
5173
+ super(...arguments);
5174
+ this.validate = this.implement;
5175
+ }
5176
+ _parse(input) {
5177
+ const { ctx } = this._processInputParams(input);
5178
+ if (ctx.parsedType !== ZodParsedType.function) {
5179
+ addIssueToContext(ctx, {
5180
+ code: ZodIssueCode.invalid_type,
5181
+ expected: ZodParsedType.function,
5182
+ received: ctx.parsedType
5183
+ });
5184
+ return INVALID;
5185
+ }
5186
+ function makeArgsIssue(args, error) {
5187
+ return makeIssue({
5188
+ data: args,
5189
+ path: ctx.path,
5190
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
5191
+ issueData: {
5192
+ code: ZodIssueCode.invalid_arguments,
5193
+ argumentsError: error
5194
+ }
5195
+ });
5196
+ }
5197
+ function makeReturnsIssue(returns, error) {
5198
+ return makeIssue({
5199
+ data: returns,
5200
+ path: ctx.path,
5201
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
5202
+ issueData: {
5203
+ code: ZodIssueCode.invalid_return_type,
5204
+ returnTypeError: error
5205
+ }
5206
+ });
5207
+ }
5208
+ const params = { errorMap: ctx.common.contextualErrorMap };
5209
+ const fn = ctx.data;
5210
+ if (this._def.returns instanceof ZodPromise) {
5211
+ const me = this;
5212
+ return OK(async function(...args) {
5213
+ const error = new ZodError([]);
5214
+ const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
5215
+ error.addIssue(makeArgsIssue(args, e));
5216
+ throw error;
5217
+ });
5218
+ const result = await Reflect.apply(fn, this, parsedArgs);
5219
+ const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
5220
+ error.addIssue(makeReturnsIssue(result, e));
5221
+ throw error;
5222
+ });
5223
+ return parsedReturns;
5224
+ });
5225
+ } else {
5226
+ const me = this;
5227
+ return OK(function(...args) {
5228
+ const parsedArgs = me._def.args.safeParse(args, params);
5229
+ if (!parsedArgs.success) {
5230
+ throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
5231
+ }
5232
+ const result = Reflect.apply(fn, this, parsedArgs.data);
5233
+ const parsedReturns = me._def.returns.safeParse(result, params);
5234
+ if (!parsedReturns.success) {
5235
+ throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
5236
+ }
5237
+ return parsedReturns.data;
5238
+ });
5239
+ }
5240
+ }
5241
+ parameters() {
5242
+ return this._def.args;
5243
+ }
5244
+ returnType() {
5245
+ return this._def.returns;
5246
+ }
5247
+ args(...items) {
5248
+ return new ZodFunction({
5249
+ ...this._def,
5250
+ args: ZodTuple.create(items).rest(ZodUnknown.create())
5251
+ });
5252
+ }
5253
+ returns(returnType) {
5254
+ return new ZodFunction({
5255
+ ...this._def,
5256
+ returns: returnType
5257
+ });
5258
+ }
5259
+ implement(func) {
5260
+ const validatedFunc = this.parse(func);
5261
+ return validatedFunc;
5262
+ }
5263
+ strictImplement(func) {
5264
+ const validatedFunc = this.parse(func);
5265
+ return validatedFunc;
5266
+ }
5267
+ static create(args, returns, params) {
5268
+ return new ZodFunction({
5269
+ args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
5270
+ returns: returns || ZodUnknown.create(),
5271
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
5272
+ ...processCreateParams(params)
5273
+ });
5274
+ }
5275
+ }
5276
+
5277
+ class ZodLazy extends ZodType {
5278
+ get schema() {
5279
+ return this._def.getter();
5280
+ }
5281
+ _parse(input) {
5282
+ const { ctx } = this._processInputParams(input);
5283
+ const lazySchema = this._def.getter();
5284
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
5285
+ }
5286
+ }
5287
+ ZodLazy.create = (getter, params) => {
5288
+ return new ZodLazy({
5289
+ getter,
5290
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
5291
+ ...processCreateParams(params)
5292
+ });
5293
+ };
5294
+
5295
+ class ZodLiteral extends ZodType {
5296
+ _parse(input) {
5297
+ if (input.data !== this._def.value) {
5298
+ const ctx = this._getOrReturnCtx(input);
5299
+ addIssueToContext(ctx, {
5300
+ received: ctx.data,
5301
+ code: ZodIssueCode.invalid_literal,
5302
+ expected: this._def.value
5303
+ });
5304
+ return INVALID;
5305
+ }
5306
+ return { status: "valid", value: input.data };
5307
+ }
5308
+ get value() {
5309
+ return this._def.value;
5310
+ }
5311
+ }
5312
+ ZodLiteral.create = (value, params) => {
5313
+ return new ZodLiteral({
5314
+ value,
5315
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
5316
+ ...processCreateParams(params)
5317
+ });
5318
+ };
5319
+ function createZodEnum(values, params) {
5320
+ return new ZodEnum({
5321
+ values,
5322
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
5323
+ ...processCreateParams(params)
5324
+ });
5325
+ }
5326
+
5327
+ class ZodEnum extends ZodType {
5328
+ _parse(input) {
5329
+ if (typeof input.data !== "string") {
5330
+ const ctx = this._getOrReturnCtx(input);
5331
+ const expectedValues = this._def.values;
5332
+ addIssueToContext(ctx, {
5333
+ expected: util.joinValues(expectedValues),
5334
+ received: ctx.parsedType,
5335
+ code: ZodIssueCode.invalid_type
5336
+ });
5337
+ return INVALID;
5338
+ }
5339
+ if (!this._cache) {
5340
+ this._cache = new Set(this._def.values);
5341
+ }
5342
+ if (!this._cache.has(input.data)) {
5343
+ const ctx = this._getOrReturnCtx(input);
5344
+ const expectedValues = this._def.values;
5345
+ addIssueToContext(ctx, {
5346
+ received: ctx.data,
5347
+ code: ZodIssueCode.invalid_enum_value,
5348
+ options: expectedValues
5349
+ });
5350
+ return INVALID;
5351
+ }
5352
+ return OK(input.data);
5353
+ }
5354
+ get options() {
5355
+ return this._def.values;
5356
+ }
5357
+ get enum() {
5358
+ const enumValues = {};
5359
+ for (const val of this._def.values) {
5360
+ enumValues[val] = val;
5361
+ }
5362
+ return enumValues;
5363
+ }
5364
+ get Values() {
5365
+ const enumValues = {};
5366
+ for (const val of this._def.values) {
5367
+ enumValues[val] = val;
5368
+ }
5369
+ return enumValues;
5370
+ }
5371
+ get Enum() {
5372
+ const enumValues = {};
5373
+ for (const val of this._def.values) {
5374
+ enumValues[val] = val;
5375
+ }
5376
+ return enumValues;
5377
+ }
5378
+ extract(values, newDef = this._def) {
5379
+ return ZodEnum.create(values, {
5380
+ ...this._def,
5381
+ ...newDef
5382
+ });
5383
+ }
5384
+ exclude(values, newDef = this._def) {
5385
+ return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
5386
+ ...this._def,
5387
+ ...newDef
5388
+ });
5389
+ }
5390
+ }
5391
+ ZodEnum.create = createZodEnum;
5392
+
5393
+ class ZodNativeEnum extends ZodType {
5394
+ _parse(input) {
5395
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
5396
+ const ctx = this._getOrReturnCtx(input);
5397
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
5398
+ const expectedValues = util.objectValues(nativeEnumValues);
5399
+ addIssueToContext(ctx, {
5400
+ expected: util.joinValues(expectedValues),
5401
+ received: ctx.parsedType,
5402
+ code: ZodIssueCode.invalid_type
5403
+ });
5404
+ return INVALID;
5405
+ }
5406
+ if (!this._cache) {
5407
+ this._cache = new Set(util.getValidEnumValues(this._def.values));
5408
+ }
5409
+ if (!this._cache.has(input.data)) {
5410
+ const expectedValues = util.objectValues(nativeEnumValues);
5411
+ addIssueToContext(ctx, {
5412
+ received: ctx.data,
5413
+ code: ZodIssueCode.invalid_enum_value,
5414
+ options: expectedValues
5415
+ });
5416
+ return INVALID;
5417
+ }
5418
+ return OK(input.data);
5419
+ }
5420
+ get enum() {
5421
+ return this._def.values;
5422
+ }
5423
+ }
5424
+ ZodNativeEnum.create = (values, params) => {
5425
+ return new ZodNativeEnum({
5426
+ values,
5427
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
5428
+ ...processCreateParams(params)
5429
+ });
5430
+ };
5431
+
5432
+ class ZodPromise extends ZodType {
5433
+ unwrap() {
5434
+ return this._def.type;
5435
+ }
5436
+ _parse(input) {
5437
+ const { ctx } = this._processInputParams(input);
5438
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
5439
+ addIssueToContext(ctx, {
5440
+ code: ZodIssueCode.invalid_type,
5441
+ expected: ZodParsedType.promise,
5442
+ received: ctx.parsedType
5443
+ });
5444
+ return INVALID;
5445
+ }
5446
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
5447
+ return OK(promisified.then((data) => {
5448
+ return this._def.type.parseAsync(data, {
5449
+ path: ctx.path,
5450
+ errorMap: ctx.common.contextualErrorMap
5451
+ });
5452
+ }));
5453
+ }
5454
+ }
5455
+ ZodPromise.create = (schema, params) => {
5456
+ return new ZodPromise({
5457
+ type: schema,
5458
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
5459
+ ...processCreateParams(params)
5460
+ });
5461
+ };
5462
+
5463
+ class ZodEffects extends ZodType {
5464
+ innerType() {
5465
+ return this._def.schema;
5466
+ }
5467
+ sourceType() {
5468
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
5469
+ }
5470
+ _parse(input) {
5471
+ const { status, ctx } = this._processInputParams(input);
5472
+ const effect = this._def.effect || null;
5473
+ const checkCtx = {
5474
+ addIssue: (arg) => {
5475
+ addIssueToContext(ctx, arg);
5476
+ if (arg.fatal) {
5477
+ status.abort();
5478
+ } else {
5479
+ status.dirty();
5480
+ }
5481
+ },
5482
+ get path() {
5483
+ return ctx.path;
5484
+ }
5485
+ };
5486
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
5487
+ if (effect.type === "preprocess") {
5488
+ const processed = effect.transform(ctx.data, checkCtx);
5489
+ if (ctx.common.async) {
5490
+ return Promise.resolve(processed).then(async (processed2) => {
5491
+ if (status.value === "aborted")
5492
+ return INVALID;
5493
+ const result = await this._def.schema._parseAsync({
5494
+ data: processed2,
5495
+ path: ctx.path,
5496
+ parent: ctx
5497
+ });
5498
+ if (result.status === "aborted")
5499
+ return INVALID;
5500
+ if (result.status === "dirty")
5501
+ return DIRTY(result.value);
5502
+ if (status.value === "dirty")
5503
+ return DIRTY(result.value);
5504
+ return result;
5505
+ });
5506
+ } else {
5507
+ if (status.value === "aborted")
5508
+ return INVALID;
5509
+ const result = this._def.schema._parseSync({
5510
+ data: processed,
5511
+ path: ctx.path,
5512
+ parent: ctx
5513
+ });
5514
+ if (result.status === "aborted")
5515
+ return INVALID;
5516
+ if (result.status === "dirty")
5517
+ return DIRTY(result.value);
5518
+ if (status.value === "dirty")
5519
+ return DIRTY(result.value);
5520
+ return result;
5521
+ }
5522
+ }
5523
+ if (effect.type === "refinement") {
5524
+ const executeRefinement = (acc) => {
5525
+ const result = effect.refinement(acc, checkCtx);
5526
+ if (ctx.common.async) {
5527
+ return Promise.resolve(result);
5528
+ }
5529
+ if (result instanceof Promise) {
5530
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
5531
+ }
5532
+ return acc;
5533
+ };
5534
+ if (ctx.common.async === false) {
5535
+ const inner = this._def.schema._parseSync({
5536
+ data: ctx.data,
5537
+ path: ctx.path,
5538
+ parent: ctx
5539
+ });
5540
+ if (inner.status === "aborted")
5541
+ return INVALID;
5542
+ if (inner.status === "dirty")
5543
+ status.dirty();
5544
+ executeRefinement(inner.value);
5545
+ return { status: status.value, value: inner.value };
5546
+ } else {
5547
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
5548
+ if (inner.status === "aborted")
5549
+ return INVALID;
5550
+ if (inner.status === "dirty")
5551
+ status.dirty();
5552
+ return executeRefinement(inner.value).then(() => {
5553
+ return { status: status.value, value: inner.value };
5554
+ });
5555
+ });
5556
+ }
5557
+ }
5558
+ if (effect.type === "transform") {
5559
+ if (ctx.common.async === false) {
5560
+ const base = this._def.schema._parseSync({
5561
+ data: ctx.data,
5562
+ path: ctx.path,
5563
+ parent: ctx
5564
+ });
5565
+ if (!isValid(base))
5566
+ return INVALID;
5567
+ const result = effect.transform(base.value, checkCtx);
5568
+ if (result instanceof Promise) {
5569
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
5570
+ }
5571
+ return { status: status.value, value: result };
5572
+ } else {
5573
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
5574
+ if (!isValid(base))
5575
+ return INVALID;
5576
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
5577
+ status: status.value,
5578
+ value: result
5579
+ }));
5580
+ });
5581
+ }
5582
+ }
5583
+ util.assertNever(effect);
5584
+ }
5585
+ }
5586
+ ZodEffects.create = (schema, effect, params) => {
5587
+ return new ZodEffects({
5588
+ schema,
5589
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
5590
+ effect,
5591
+ ...processCreateParams(params)
5592
+ });
5593
+ };
5594
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
5595
+ return new ZodEffects({
5596
+ schema,
5597
+ effect: { type: "preprocess", transform: preprocess },
5598
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
5599
+ ...processCreateParams(params)
5600
+ });
5601
+ };
5602
+ class ZodOptional extends ZodType {
5603
+ _parse(input) {
5604
+ const parsedType = this._getType(input);
5605
+ if (parsedType === ZodParsedType.undefined) {
5606
+ return OK(undefined);
5607
+ }
5608
+ return this._def.innerType._parse(input);
5609
+ }
5610
+ unwrap() {
5611
+ return this._def.innerType;
5612
+ }
5613
+ }
5614
+ ZodOptional.create = (type, params) => {
5615
+ return new ZodOptional({
5616
+ innerType: type,
5617
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
5618
+ ...processCreateParams(params)
5619
+ });
5620
+ };
5621
+
5622
+ class ZodNullable extends ZodType {
5623
+ _parse(input) {
5624
+ const parsedType = this._getType(input);
5625
+ if (parsedType === ZodParsedType.null) {
5626
+ return OK(null);
5627
+ }
5628
+ return this._def.innerType._parse(input);
5629
+ }
5630
+ unwrap() {
5631
+ return this._def.innerType;
5632
+ }
5633
+ }
5634
+ ZodNullable.create = (type, params) => {
5635
+ return new ZodNullable({
5636
+ innerType: type,
5637
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
5638
+ ...processCreateParams(params)
5639
+ });
5640
+ };
5641
+
5642
+ class ZodDefault extends ZodType {
5643
+ _parse(input) {
5644
+ const { ctx } = this._processInputParams(input);
5645
+ let data = ctx.data;
5646
+ if (ctx.parsedType === ZodParsedType.undefined) {
5647
+ data = this._def.defaultValue();
5648
+ }
5649
+ return this._def.innerType._parse({
5650
+ data,
5651
+ path: ctx.path,
5652
+ parent: ctx
5653
+ });
5654
+ }
5655
+ removeDefault() {
5656
+ return this._def.innerType;
5657
+ }
5658
+ }
5659
+ ZodDefault.create = (type, params) => {
5660
+ return new ZodDefault({
5661
+ innerType: type,
5662
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
5663
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
5664
+ ...processCreateParams(params)
5665
+ });
5666
+ };
5667
+
5668
+ class ZodCatch extends ZodType {
5669
+ _parse(input) {
5670
+ const { ctx } = this._processInputParams(input);
5671
+ const newCtx = {
5672
+ ...ctx,
5673
+ common: {
5674
+ ...ctx.common,
5675
+ issues: []
5676
+ }
5677
+ };
5678
+ const result = this._def.innerType._parse({
5679
+ data: newCtx.data,
5680
+ path: newCtx.path,
5681
+ parent: {
5682
+ ...newCtx
5683
+ }
5684
+ });
5685
+ if (isAsync(result)) {
5686
+ return result.then((result2) => {
5687
+ return {
5688
+ status: "valid",
5689
+ value: result2.status === "valid" ? result2.value : this._def.catchValue({
5690
+ get error() {
5691
+ return new ZodError(newCtx.common.issues);
5692
+ },
5693
+ input: newCtx.data
5694
+ })
5695
+ };
5696
+ });
5697
+ } else {
5698
+ return {
5699
+ status: "valid",
5700
+ value: result.status === "valid" ? result.value : this._def.catchValue({
5701
+ get error() {
5702
+ return new ZodError(newCtx.common.issues);
5703
+ },
5704
+ input: newCtx.data
5705
+ })
5706
+ };
5707
+ }
5708
+ }
5709
+ removeCatch() {
5710
+ return this._def.innerType;
5711
+ }
5712
+ }
5713
+ ZodCatch.create = (type, params) => {
5714
+ return new ZodCatch({
5715
+ innerType: type,
5716
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
5717
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
5718
+ ...processCreateParams(params)
5719
+ });
5720
+ };
5721
+
5722
+ class ZodNaN extends ZodType {
5723
+ _parse(input) {
5724
+ const parsedType = this._getType(input);
5725
+ if (parsedType !== ZodParsedType.nan) {
5726
+ const ctx = this._getOrReturnCtx(input);
5727
+ addIssueToContext(ctx, {
5728
+ code: ZodIssueCode.invalid_type,
5729
+ expected: ZodParsedType.nan,
5730
+ received: ctx.parsedType
5731
+ });
5732
+ return INVALID;
5733
+ }
5734
+ return { status: "valid", value: input.data };
5735
+ }
5736
+ }
5737
+ ZodNaN.create = (params) => {
5738
+ return new ZodNaN({
5739
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
5740
+ ...processCreateParams(params)
5741
+ });
5742
+ };
5743
+ var BRAND = Symbol("zod_brand");
5744
+
5745
+ class ZodBranded extends ZodType {
5746
+ _parse(input) {
5747
+ const { ctx } = this._processInputParams(input);
5748
+ const data = ctx.data;
5749
+ return this._def.type._parse({
5750
+ data,
5751
+ path: ctx.path,
5752
+ parent: ctx
5753
+ });
5754
+ }
5755
+ unwrap() {
5756
+ return this._def.type;
5757
+ }
5758
+ }
5759
+
5760
+ class ZodPipeline extends ZodType {
5761
+ _parse(input) {
5762
+ const { status, ctx } = this._processInputParams(input);
5763
+ if (ctx.common.async) {
5764
+ const handleAsync = async () => {
5765
+ const inResult = await this._def.in._parseAsync({
5766
+ data: ctx.data,
5767
+ path: ctx.path,
5768
+ parent: ctx
5769
+ });
5770
+ if (inResult.status === "aborted")
5771
+ return INVALID;
5772
+ if (inResult.status === "dirty") {
5773
+ status.dirty();
5774
+ return DIRTY(inResult.value);
5775
+ } else {
5776
+ return this._def.out._parseAsync({
5777
+ data: inResult.value,
5778
+ path: ctx.path,
5779
+ parent: ctx
5780
+ });
5781
+ }
5782
+ };
5783
+ return handleAsync();
5784
+ } else {
5785
+ const inResult = this._def.in._parseSync({
5786
+ data: ctx.data,
5787
+ path: ctx.path,
5788
+ parent: ctx
5789
+ });
5790
+ if (inResult.status === "aborted")
5791
+ return INVALID;
5792
+ if (inResult.status === "dirty") {
5793
+ status.dirty();
5794
+ return {
5795
+ status: "dirty",
5796
+ value: inResult.value
5797
+ };
5798
+ } else {
5799
+ return this._def.out._parseSync({
5800
+ data: inResult.value,
5801
+ path: ctx.path,
5802
+ parent: ctx
5803
+ });
5804
+ }
5805
+ }
5806
+ }
5807
+ static create(a, b) {
5808
+ return new ZodPipeline({
5809
+ in: a,
5810
+ out: b,
5811
+ typeName: ZodFirstPartyTypeKind.ZodPipeline
5812
+ });
5813
+ }
5814
+ }
5815
+
5816
+ class ZodReadonly extends ZodType {
5817
+ _parse(input) {
5818
+ const result = this._def.innerType._parse(input);
5819
+ const freeze = (data) => {
5820
+ if (isValid(data)) {
5821
+ data.value = Object.freeze(data.value);
5822
+ }
5823
+ return data;
5824
+ };
5825
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
5826
+ }
5827
+ unwrap() {
5828
+ return this._def.innerType;
5829
+ }
5830
+ }
5831
+ ZodReadonly.create = (type, params) => {
5832
+ return new ZodReadonly({
5833
+ innerType: type,
5834
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
5835
+ ...processCreateParams(params)
5836
+ });
5837
+ };
5838
+ function cleanParams(params, data) {
5839
+ const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
5840
+ const p2 = typeof p === "string" ? { message: p } : p;
5841
+ return p2;
5842
+ }
5843
+ function custom(check, _params = {}, fatal) {
5844
+ if (check)
5845
+ return ZodAny.create().superRefine((data, ctx) => {
5846
+ const r = check(data);
5847
+ if (r instanceof Promise) {
5848
+ return r.then((r2) => {
5849
+ if (!r2) {
5850
+ const params = cleanParams(_params, data);
5851
+ const _fatal = params.fatal ?? fatal ?? true;
5852
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
5853
+ }
5854
+ });
5855
+ }
5856
+ if (!r) {
5857
+ const params = cleanParams(_params, data);
5858
+ const _fatal = params.fatal ?? fatal ?? true;
5859
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
5860
+ }
5861
+ return;
5862
+ });
5863
+ return ZodAny.create();
5864
+ }
5865
+ var late = {
5866
+ object: ZodObject.lazycreate
5867
+ };
5868
+ var ZodFirstPartyTypeKind;
5869
+ (function(ZodFirstPartyTypeKind2) {
5870
+ ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
5871
+ ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
5872
+ ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
5873
+ ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
5874
+ ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
5875
+ ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
5876
+ ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
5877
+ ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
5878
+ ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
5879
+ ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
5880
+ ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
5881
+ ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
5882
+ ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
5883
+ ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
5884
+ ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
5885
+ ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
5886
+ ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
5887
+ ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
5888
+ ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
5889
+ ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
5890
+ ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
5891
+ ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
5892
+ ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
5893
+ ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
5894
+ ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
5895
+ ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
5896
+ ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
5897
+ ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
5898
+ ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
5899
+ ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
5900
+ ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
5901
+ ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
5902
+ ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
5903
+ ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
5904
+ ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
5905
+ ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
5906
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
5907
+ var instanceOfType = (cls, params = {
5908
+ message: `Input not instance of ${cls.name}`
5909
+ }) => custom((data) => data instanceof cls, params);
5910
+ var stringType = ZodString.create;
5911
+ var numberType = ZodNumber.create;
5912
+ var nanType = ZodNaN.create;
5913
+ var bigIntType = ZodBigInt.create;
5914
+ var booleanType = ZodBoolean.create;
5915
+ var dateType = ZodDate.create;
5916
+ var symbolType = ZodSymbol.create;
5917
+ var undefinedType = ZodUndefined.create;
5918
+ var nullType = ZodNull.create;
5919
+ var anyType = ZodAny.create;
5920
+ var unknownType = ZodUnknown.create;
5921
+ var neverType = ZodNever.create;
5922
+ var voidType = ZodVoid.create;
5923
+ var arrayType = ZodArray.create;
5924
+ var objectType = ZodObject.create;
5925
+ var strictObjectType = ZodObject.strictCreate;
5926
+ var unionType = ZodUnion.create;
5927
+ var discriminatedUnionType = ZodDiscriminatedUnion.create;
5928
+ var intersectionType = ZodIntersection.create;
5929
+ var tupleType = ZodTuple.create;
5930
+ var recordType = ZodRecord.create;
5931
+ var mapType = ZodMap.create;
5932
+ var setType = ZodSet.create;
5933
+ var functionType = ZodFunction.create;
5934
+ var lazyType = ZodLazy.create;
5935
+ var literalType = ZodLiteral.create;
5936
+ var enumType = ZodEnum.create;
5937
+ var nativeEnumType = ZodNativeEnum.create;
5938
+ var promiseType = ZodPromise.create;
5939
+ var effectsType = ZodEffects.create;
5940
+ var optionalType = ZodOptional.create;
5941
+ var nullableType = ZodNullable.create;
5942
+ var preprocessType = ZodEffects.createWithPreprocess;
5943
+ var pipelineType = ZodPipeline.create;
5944
+ var ostring = () => stringType().optional();
5945
+ var onumber = () => numberType().optional();
5946
+ var oboolean = () => booleanType().optional();
5947
+ var coerce = {
5948
+ string: (arg) => ZodString.create({ ...arg, coerce: true }),
5949
+ number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
5950
+ boolean: (arg) => ZodBoolean.create({
5951
+ ...arg,
5952
+ coerce: true
5953
+ }),
5954
+ bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
5955
+ date: (arg) => ZodDate.create({ ...arg, coerce: true })
5956
+ };
5957
+ var NEVER = INVALID;
5958
+ // src/integrations/vercel-ai.ts
5959
+ function getProviderForTool(client, toolName) {
5960
+ return client.getProviderForTool?.(toolName);
5961
+ }
5962
+ function jsonSchemaPropertyToZod(propSchema) {
5963
+ if (!propSchema || typeof propSchema !== "object") {
5964
+ return exports_external.any();
5965
+ }
5966
+ const type = propSchema.type;
5967
+ switch (type) {
5968
+ case "string":
5969
+ let stringSchema = exports_external.string();
5970
+ if (propSchema.description) {
5971
+ stringSchema = stringSchema.describe(propSchema.description);
5972
+ }
5973
+ if (propSchema.minLength !== undefined) {
5974
+ stringSchema = stringSchema.min(propSchema.minLength);
5975
+ }
5976
+ if (propSchema.maxLength !== undefined) {
5977
+ stringSchema = stringSchema.max(propSchema.maxLength);
5978
+ }
5979
+ if (propSchema.pattern) {
5980
+ stringSchema = stringSchema.regex(new RegExp(propSchema.pattern));
5981
+ }
5982
+ if (propSchema.enum) {
5983
+ return exports_external.enum(propSchema.enum);
5984
+ }
5985
+ return stringSchema;
5986
+ case "number":
5987
+ case "integer":
5988
+ let numberSchema = type === "integer" ? exports_external.number().int() : exports_external.number();
5989
+ if (propSchema.description) {
5990
+ numberSchema = numberSchema.describe(propSchema.description);
5991
+ }
5992
+ if (propSchema.minimum !== undefined) {
5993
+ numberSchema = numberSchema.min(propSchema.minimum);
5994
+ }
5995
+ if (propSchema.maximum !== undefined) {
5996
+ numberSchema = numberSchema.max(propSchema.maximum);
5997
+ }
5998
+ return numberSchema;
5999
+ case "boolean":
6000
+ let boolSchema = exports_external.boolean();
6001
+ if (propSchema.description) {
6002
+ boolSchema = boolSchema.describe(propSchema.description);
6003
+ }
6004
+ return boolSchema;
6005
+ case "array":
6006
+ let arraySchema = exports_external.array(propSchema.items ? jsonSchemaPropertyToZod(propSchema.items) : exports_external.any());
6007
+ if (propSchema.description) {
6008
+ arraySchema = arraySchema.describe(propSchema.description);
6009
+ }
6010
+ if (propSchema.minItems !== undefined) {
6011
+ arraySchema = arraySchema.min(propSchema.minItems);
6012
+ }
6013
+ if (propSchema.maxItems !== undefined) {
6014
+ arraySchema = arraySchema.max(propSchema.maxItems);
6015
+ }
6016
+ return arraySchema;
6017
+ case "object":
6018
+ if (propSchema.properties && typeof propSchema.properties === "object") {
6019
+ const shape = {};
6020
+ for (const [key, value] of Object.entries(propSchema.properties)) {
6021
+ shape[key] = jsonSchemaPropertyToZod(value);
6022
+ }
6023
+ let objSchema = exports_external.object(shape);
6024
+ if (propSchema.description) {
6025
+ objSchema = objSchema.describe(propSchema.description);
6026
+ }
6027
+ return objSchema;
6028
+ }
6029
+ return exports_external.record(exports_external.any());
6030
+ case "null":
6031
+ return exports_external.null();
6032
+ default:
6033
+ return exports_external.any();
6034
+ }
6035
+ }
6036
+ function jsonSchemaToZod(schema) {
6037
+ if (!schema || typeof schema !== "object") {
6038
+ return exports_external.object({});
6039
+ }
6040
+ if (schema.type === "None" || schema.type === null || schema.type === undefined) {
6041
+ if (schema.properties && typeof schema.properties === "object") {
6042
+ const shape = {};
6043
+ const required = schema.required || [];
6044
+ for (const [key, value] of Object.entries(schema.properties)) {
6045
+ let propSchema = jsonSchemaPropertyToZod(value);
6046
+ if (!required.includes(key)) {
6047
+ propSchema = propSchema.optional();
6048
+ }
6049
+ shape[key] = propSchema;
6050
+ }
6051
+ return exports_external.object(shape);
6052
+ }
6053
+ return exports_external.object({});
6054
+ }
6055
+ if (schema.type !== "object") {
6056
+ return exports_external.object({});
6057
+ }
6058
+ if (schema.properties && typeof schema.properties === "object") {
6059
+ const shape = {};
6060
+ const required = schema.required || [];
6061
+ for (const [key, value] of Object.entries(schema.properties)) {
6062
+ let propSchema = jsonSchemaPropertyToZod(value);
6063
+ if (!required.includes(key)) {
6064
+ propSchema = propSchema.optional();
6065
+ }
6066
+ shape[key] = propSchema;
6067
+ }
6068
+ return exports_external.object(shape);
6069
+ }
6070
+ return exports_external.object({});
1997
6071
  }
1998
6072
  function convertMCPToolToVercelAI(mcpTool, client, options) {
1999
6073
  return {
2000
6074
  description: mcpTool.description || `Execute ${mcpTool.name}`,
2001
- parameters: normalizeSchema(mcpTool.inputSchema),
6075
+ inputSchema: jsonSchemaToZod(mcpTool.inputSchema),
2002
6076
  execute: async (args) => {
2003
6077
  if (options?.providerTokens) {
2004
6078
  const provider = getProviderForTool(client, mcpTool.name);