@shopify/create-app 4.8.4 → 4.9.0
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/analytics-D5P7IMRA.js +48 -0
- package/dist/analytics-TXXYVQN7.js +40 -0
- package/dist/{chunk-ODCXYGJ2.js → chunk-23UTCSPZ.js} +14 -4
- package/dist/{chunk-QMQX3MT5.js → chunk-2UPX6QLJ.js} +6 -6
- package/dist/{chunk-FSEXIENC.js → chunk-3IJICKWH.js} +2 -2
- package/dist/chunk-5OAATCQX.js +218 -0
- package/dist/{chunk-BEUNBVME.js → chunk-A33KVF5C.js} +1 -1
- package/dist/{chunk-RJ3A4X2R.js → chunk-AJLJXEKT.js} +3093 -23
- package/dist/chunk-BBGOL4JF.js +86 -0
- package/dist/chunk-CK3T27VW.js +119 -0
- package/dist/{chunk-E43EDJOG.js → chunk-EJEHENXO.js} +3 -2
- package/dist/chunk-FKZ3NFHZ.js +7 -0
- package/dist/{chunk-2VQBQQJH.js → chunk-KZZE6H5Q.js} +51 -26
- package/dist/chunk-MHLFPQ3W.js +50 -0
- package/dist/{chunk-XZQD6FEL.js → chunk-MOB6XVGL.js} +2 -2
- package/dist/{chunk-YSB2L5XO.js → chunk-NB6X7ZFE.js} +3 -3
- package/dist/{chunk-ZOH5TKZV.js → chunk-NHN6SUTT.js} +202 -55
- package/dist/chunk-NLC4T4YS.js +1092 -0
- package/dist/{chunk-CJUIIULM.js → chunk-NW3CCDI2.js} +318 -3211
- package/dist/{chunk-U7XCB7LM.js → chunk-OG3KDO3M.js} +16 -16
- package/dist/{chunk-THSPSZ2U.js → chunk-PSP4NDSB.js} +16 -14
- package/dist/{chunk-HGTLZ6ZW.js → chunk-QNTXEHZO.js} +5 -5
- package/dist/{chunk-XPTHNPI4.js → chunk-RYTPHY47.js} +10 -10
- package/dist/{chunk-NFOBMXOQ.js → chunk-SFVOZJMO.js} +32 -10
- package/dist/chunk-SHCNJ47P.js +89 -0
- package/dist/{chunk-4ATBZZ7Q.js → chunk-SYVHC634.js} +2 -2
- package/dist/{chunk-C3J4HVUN.js → chunk-VDUAROBQ.js} +3 -2
- package/dist/command-json-schema-S3W3UW3A.js +65 -0
- package/dist/{conf-store-ZMAEEJET.js → conf-store-GW5MF5EC.js} +11 -11
- package/dist/custom-oclif-loader-MYKFWED2.js +85 -0
- package/dist/{deprecations-2ZE7F57V.js → deprecations-TJKLSMEC.js} +18 -15
- package/dist/environment-OJNKZ7ML.js +25 -0
- package/dist/environments-FLXCXEQY.js +32 -0
- package/dist/error-handler-KSSGLWAL.js +44 -0
- package/dist/{fs-ZEAP6SYM.js → fs-54TFRUFV.js} +10 -5
- package/dist/hooks/postrun.js +11 -6
- package/dist/hooks/prerun.js +6 -6
- package/dist/{http-proxy-node16-5LMQ6YXS.js → http-proxy-node16-FD2WN6JB.js} +2 -3
- package/dist/index.js +6750 -3654
- package/dist/{is-global-FYEORJBG.js → is-global-ABT2AQMZ.js} +10 -5
- package/dist/json-error-N7MI3KIX.js +104 -0
- package/dist/{lib-XCYUJYSO.js → lib-NYDMHWZM.js} +3 -4
- package/dist/{local-A2UFPWGA.js → local-BAVJFTPY.js} +11 -3
- package/dist/{metadata-WWELAOUA.js → metadata-JDWMZLO3.js} +10 -4
- package/dist/{node-package-manager-WU3OX73T.js → node-package-manager-LZQDH5RV.js} +20 -17
- package/dist/notifications-system-C4VANR5T.js +47 -0
- package/dist/os-UYRG46VD.js +24 -0
- package/dist/{output-BOE7D3BZ.js → output-WTBNQLZY.js} +12 -5
- package/dist/{path-2WA5R6GG.js → path-2KZ7FSGN.js} +2 -2
- package/dist/{prettier-SS3RRDXK.js → prettier-BNZDRHR4.js} +2 -2
- package/dist/{system-F5JGMAQ2.js → system-VYWFQ656.js} +18 -15
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/{ui-WM75TA2X.js → ui-EW2MACA7.js} +18 -15
- package/dist/{upgrade-437BKOQU.js → upgrade-TCM7RY33.js} +47 -29
- package/dist/{version-EHF3PAN2.js → version-6BXGHP54.js} +2 -2
- package/dist/version-ANERG2ID.js +36 -0
- package/oclif.manifest.json +15 -1
- package/package.json +3 -3
- package/dist/analytics-IYBTJU64.js +0 -44
- package/dist/analytics-N7RZNZ7E.js +0 -36
- package/dist/chunk-7OHJH7BF.js +0 -21
- package/dist/chunk-UPP43IHQ.js +0 -301
- package/dist/custom-oclif-loader-HTLL62HO.js +0 -54
- package/dist/environments-4UKGWAAJ.js +0 -29
- package/dist/error-handler-OPWDDXJP.js +0 -40
- package/dist/notifications-system-SQQO6LJW.js +0 -43
- package/dist/os-WN6IUS7J.js +0 -19
- package/dist/version-Q3TUYBAR.js +0 -33
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isUnitTest,
|
|
3
3
|
isVerbose
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import {
|
|
6
|
-
require_has_flag
|
|
7
|
-
} from "./chunk-7OHJH7BF.js";
|
|
4
|
+
} from "./chunk-5OAATCQX.js";
|
|
8
5
|
import {
|
|
9
6
|
isTruthy
|
|
10
7
|
} from "./chunk-HNIAZN6U.js";
|
|
8
|
+
import {
|
|
9
|
+
require_has_flag
|
|
10
|
+
} from "./chunk-23UTCSPZ.js";
|
|
11
11
|
import {
|
|
12
12
|
cwd,
|
|
13
13
|
dirname,
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
resolvePath,
|
|
20
20
|
sep,
|
|
21
21
|
sniffForPath
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-VDUAROBQ.js";
|
|
23
23
|
import {
|
|
24
24
|
require_out
|
|
25
25
|
} from "./chunk-UFLX7QDP.js";
|
|
@@ -3259,7 +3259,7 @@ var require_clone = __commonJS({
|
|
|
3259
3259
|
var require_graceful_fs = __commonJS({
|
|
3260
3260
|
"../../node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/graceful-fs.js"(exports, module) {
|
|
3261
3261
|
init_cjs_shims();
|
|
3262
|
-
var fs2 = __require("fs"), polyfills = require_polyfills(), legacy = require_legacy_streams(), clone = require_clone(),
|
|
3262
|
+
var fs2 = __require("fs"), polyfills = require_polyfills(), legacy = require_legacy_streams(), clone = require_clone(), util2 = __require("util"), gracefulQueue, previousSymbol;
|
|
3263
3263
|
typeof Symbol == "function" && typeof Symbol.for == "function" ? (gracefulQueue = /* @__PURE__ */ Symbol.for("graceful-fs.queue"), previousSymbol = /* @__PURE__ */ Symbol.for("graceful-fs.previous")) : (gracefulQueue = "___graceful-fs.queue", previousSymbol = "___graceful-fs.previous");
|
|
3264
3264
|
function noop() {
|
|
3265
3265
|
}
|
|
@@ -3271,8 +3271,8 @@ var require_graceful_fs = __commonJS({
|
|
|
3271
3271
|
});
|
|
3272
3272
|
}
|
|
3273
3273
|
var debug = noop;
|
|
3274
|
-
|
|
3275
|
-
var m =
|
|
3274
|
+
util2.debuglog ? debug = util2.debuglog("gfs4") : /\bgfs4\b/i.test(process.env.NODE_DEBUG || "") && (debug = function() {
|
|
3275
|
+
var m = util2.format.apply(util2, arguments);
|
|
3276
3276
|
m = "GFS4: " + m.split(/\n/).join(`
|
|
3277
3277
|
GFS4: `), console.error(m);
|
|
3278
3278
|
});
|
|
@@ -3675,7 +3675,7 @@ var require_stat = __commonJS({
|
|
|
3675
3675
|
"../../node_modules/.pnpm/fs-extra@11.1.0/node_modules/fs-extra/lib/util/stat.js"(exports, module) {
|
|
3676
3676
|
"use strict";
|
|
3677
3677
|
init_cjs_shims();
|
|
3678
|
-
var fs2 = require_fs(), path4 = __require("path"),
|
|
3678
|
+
var fs2 = require_fs(), path4 = __require("path"), util2 = __require("util");
|
|
3679
3679
|
function getStats(src, dest, opts) {
|
|
3680
3680
|
let statFunc = opts.dereference ? (file) => fs2.stat(file, { bigint: !0 }) : (file) => fs2.lstat(file, { bigint: !0 });
|
|
3681
3681
|
return Promise.all([
|
|
@@ -3697,7 +3697,7 @@ var require_stat = __commonJS({
|
|
|
3697
3697
|
return { srcStat, destStat };
|
|
3698
3698
|
}
|
|
3699
3699
|
function checkPaths(src, dest, funcName, opts, cb) {
|
|
3700
|
-
|
|
3700
|
+
util2.callbackify(getStats)(src, dest, opts, (err, stats) => {
|
|
3701
3701
|
if (err) return cb(err);
|
|
3702
3702
|
let { srcStat, destStat } = stats;
|
|
3703
3703
|
if (destStat) {
|
|
@@ -4734,17 +4734,17 @@ function currentProcessIsGlobal(argv = process.argv) {
|
|
|
4734
4734
|
}
|
|
4735
4735
|
}
|
|
4736
4736
|
async function installGlobalShopifyCLI(packageManager) {
|
|
4737
|
-
let { outputInfo: outputInfo2 } = await import("./output-
|
|
4737
|
+
let { outputInfo: outputInfo2 } = await import("./output-WTBNQLZY.js"), { exec } = await import("./system-VYWFQ656.js"), args = packageManager === "yarn" ? ["global", "add", "@shopify/cli@latest"] : ["install", "-g", "@shopify/cli@latest"];
|
|
4738
4738
|
outputInfo2(`Running ${packageManager} ${args.join(" ")}...`), await exec(packageManager, args, { stdio: "inherit" });
|
|
4739
4739
|
}
|
|
4740
4740
|
async function installGlobalCLIPrompt() {
|
|
4741
|
-
let { terminalSupportsPrompting } = await import("./system-
|
|
4741
|
+
let { terminalSupportsPrompting } = await import("./system-VYWFQ656.js");
|
|
4742
4742
|
if (!terminalSupportsPrompting())
|
|
4743
4743
|
return { install: !1, alreadyInstalled: !1 };
|
|
4744
|
-
let { globalCLIVersion } = await import("./version-
|
|
4744
|
+
let { globalCLIVersion } = await import("./version-ANERG2ID.js");
|
|
4745
4745
|
if (await globalCLIVersion())
|
|
4746
4746
|
return { install: !1, alreadyInstalled: !0 };
|
|
4747
|
-
let { renderSelectPrompt } = await import("./ui-
|
|
4747
|
+
let { renderSelectPrompt } = await import("./ui-EW2MACA7.js");
|
|
4748
4748
|
return { install: await renderSelectPrompt({
|
|
4749
4749
|
message: "We recommend installing Shopify CLI globally in your system. Would you like to install it now?",
|
|
4750
4750
|
choices: [
|
|
@@ -5287,6 +5287,3043 @@ function tokenItemToString(token) {
|
|
|
5287
5287
|
function appendToTokenItem(token, suffix) {
|
|
5288
5288
|
return Array.isArray(token) ? [...token, { char: suffix }] : [token, { char: suffix }];
|
|
5289
5289
|
}
|
|
5290
|
+
function tokenItemToJsonString(token) {
|
|
5291
|
+
return Array.isArray(token) ? token.map((item, index) => {
|
|
5292
|
+
let value = tokenToJsonString(item);
|
|
5293
|
+
return index !== 0 && !(typeof item != "string" && "char" in item) ? ` ${value}` : value;
|
|
5294
|
+
}).join("") : tokenToJsonString(token);
|
|
5295
|
+
}
|
|
5296
|
+
function tokenToJsonString(token) {
|
|
5297
|
+
if (typeof token == "string")
|
|
5298
|
+
return token;
|
|
5299
|
+
if ("link" in token) {
|
|
5300
|
+
let { label, url } = token.link;
|
|
5301
|
+
return label && label !== url ? `${label} (${url})` : url;
|
|
5302
|
+
}
|
|
5303
|
+
if ("list" in token) {
|
|
5304
|
+
let title = token.list.title ? tokenItemToJsonString(token.list.title).trim() : void 0, items = token.list.items.map(tokenItemToJsonString).join("; ");
|
|
5305
|
+
return title ? `${title}${items ? `: ${items}` : ""}` : items;
|
|
5306
|
+
}
|
|
5307
|
+
return tokenItemToString(token);
|
|
5308
|
+
}
|
|
5309
|
+
|
|
5310
|
+
// ../cli-kit/dist/private/node/command-event-context.js
|
|
5311
|
+
init_cjs_shims();
|
|
5312
|
+
|
|
5313
|
+
// ../cli-kit/dist/public/common/command-events.js
|
|
5314
|
+
init_cjs_shims();
|
|
5315
|
+
|
|
5316
|
+
// ../cli-kit/dist/public/common/json-output-schema.js
|
|
5317
|
+
init_cjs_shims();
|
|
5318
|
+
|
|
5319
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/index.js
|
|
5320
|
+
init_cjs_shims();
|
|
5321
|
+
|
|
5322
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
|
|
5323
|
+
var external_exports = {};
|
|
5324
|
+
__export(external_exports, {
|
|
5325
|
+
BRAND: () => BRAND,
|
|
5326
|
+
DIRTY: () => DIRTY,
|
|
5327
|
+
EMPTY_PATH: () => EMPTY_PATH,
|
|
5328
|
+
INVALID: () => INVALID,
|
|
5329
|
+
NEVER: () => NEVER,
|
|
5330
|
+
OK: () => OK,
|
|
5331
|
+
ParseStatus: () => ParseStatus,
|
|
5332
|
+
Schema: () => ZodType,
|
|
5333
|
+
ZodAny: () => ZodAny,
|
|
5334
|
+
ZodArray: () => ZodArray,
|
|
5335
|
+
ZodBigInt: () => ZodBigInt,
|
|
5336
|
+
ZodBoolean: () => ZodBoolean,
|
|
5337
|
+
ZodBranded: () => ZodBranded,
|
|
5338
|
+
ZodCatch: () => ZodCatch,
|
|
5339
|
+
ZodDate: () => ZodDate,
|
|
5340
|
+
ZodDefault: () => ZodDefault,
|
|
5341
|
+
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
5342
|
+
ZodEffects: () => ZodEffects,
|
|
5343
|
+
ZodEnum: () => ZodEnum,
|
|
5344
|
+
ZodError: () => ZodError,
|
|
5345
|
+
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
5346
|
+
ZodFunction: () => ZodFunction,
|
|
5347
|
+
ZodIntersection: () => ZodIntersection,
|
|
5348
|
+
ZodIssueCode: () => ZodIssueCode,
|
|
5349
|
+
ZodLazy: () => ZodLazy,
|
|
5350
|
+
ZodLiteral: () => ZodLiteral,
|
|
5351
|
+
ZodMap: () => ZodMap,
|
|
5352
|
+
ZodNaN: () => ZodNaN,
|
|
5353
|
+
ZodNativeEnum: () => ZodNativeEnum,
|
|
5354
|
+
ZodNever: () => ZodNever,
|
|
5355
|
+
ZodNull: () => ZodNull,
|
|
5356
|
+
ZodNullable: () => ZodNullable,
|
|
5357
|
+
ZodNumber: () => ZodNumber,
|
|
5358
|
+
ZodObject: () => ZodObject,
|
|
5359
|
+
ZodOptional: () => ZodOptional,
|
|
5360
|
+
ZodParsedType: () => ZodParsedType,
|
|
5361
|
+
ZodPipeline: () => ZodPipeline,
|
|
5362
|
+
ZodPromise: () => ZodPromise,
|
|
5363
|
+
ZodReadonly: () => ZodReadonly,
|
|
5364
|
+
ZodRecord: () => ZodRecord,
|
|
5365
|
+
ZodSchema: () => ZodType,
|
|
5366
|
+
ZodSet: () => ZodSet,
|
|
5367
|
+
ZodString: () => ZodString,
|
|
5368
|
+
ZodSymbol: () => ZodSymbol,
|
|
5369
|
+
ZodTransformer: () => ZodEffects,
|
|
5370
|
+
ZodTuple: () => ZodTuple,
|
|
5371
|
+
ZodType: () => ZodType,
|
|
5372
|
+
ZodUndefined: () => ZodUndefined,
|
|
5373
|
+
ZodUnion: () => ZodUnion,
|
|
5374
|
+
ZodUnknown: () => ZodUnknown,
|
|
5375
|
+
ZodVoid: () => ZodVoid,
|
|
5376
|
+
addIssueToContext: () => addIssueToContext,
|
|
5377
|
+
any: () => anyType,
|
|
5378
|
+
array: () => arrayType,
|
|
5379
|
+
bigint: () => bigIntType,
|
|
5380
|
+
boolean: () => booleanType,
|
|
5381
|
+
coerce: () => coerce,
|
|
5382
|
+
custom: () => custom,
|
|
5383
|
+
date: () => dateType,
|
|
5384
|
+
datetimeRegex: () => datetimeRegex,
|
|
5385
|
+
defaultErrorMap: () => en_default,
|
|
5386
|
+
discriminatedUnion: () => discriminatedUnionType,
|
|
5387
|
+
effect: () => effectsType,
|
|
5388
|
+
enum: () => enumType,
|
|
5389
|
+
function: () => functionType,
|
|
5390
|
+
getErrorMap: () => getErrorMap,
|
|
5391
|
+
getParsedType: () => getParsedType,
|
|
5392
|
+
instanceof: () => instanceOfType,
|
|
5393
|
+
intersection: () => intersectionType,
|
|
5394
|
+
isAborted: () => isAborted,
|
|
5395
|
+
isAsync: () => isAsync,
|
|
5396
|
+
isDirty: () => isDirty,
|
|
5397
|
+
isValid: () => isValid,
|
|
5398
|
+
late: () => late,
|
|
5399
|
+
lazy: () => lazyType,
|
|
5400
|
+
literal: () => literalType,
|
|
5401
|
+
makeIssue: () => makeIssue,
|
|
5402
|
+
map: () => mapType,
|
|
5403
|
+
nan: () => nanType,
|
|
5404
|
+
nativeEnum: () => nativeEnumType,
|
|
5405
|
+
never: () => neverType,
|
|
5406
|
+
null: () => nullType,
|
|
5407
|
+
nullable: () => nullableType,
|
|
5408
|
+
number: () => numberType,
|
|
5409
|
+
object: () => objectType,
|
|
5410
|
+
objectUtil: () => objectUtil,
|
|
5411
|
+
oboolean: () => oboolean,
|
|
5412
|
+
onumber: () => onumber,
|
|
5413
|
+
optional: () => optionalType,
|
|
5414
|
+
ostring: () => ostring,
|
|
5415
|
+
pipeline: () => pipelineType,
|
|
5416
|
+
preprocess: () => preprocessType,
|
|
5417
|
+
promise: () => promiseType,
|
|
5418
|
+
quotelessJson: () => quotelessJson,
|
|
5419
|
+
record: () => recordType,
|
|
5420
|
+
set: () => setType,
|
|
5421
|
+
setErrorMap: () => setErrorMap,
|
|
5422
|
+
strictObject: () => strictObjectType,
|
|
5423
|
+
string: () => stringType,
|
|
5424
|
+
symbol: () => symbolType,
|
|
5425
|
+
transformer: () => effectsType,
|
|
5426
|
+
tuple: () => tupleType,
|
|
5427
|
+
undefined: () => undefinedType,
|
|
5428
|
+
union: () => unionType,
|
|
5429
|
+
unknown: () => unknownType,
|
|
5430
|
+
util: () => util,
|
|
5431
|
+
void: () => voidType
|
|
5432
|
+
});
|
|
5433
|
+
init_cjs_shims();
|
|
5434
|
+
|
|
5435
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js
|
|
5436
|
+
init_cjs_shims();
|
|
5437
|
+
|
|
5438
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js
|
|
5439
|
+
init_cjs_shims();
|
|
5440
|
+
|
|
5441
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
|
|
5442
|
+
init_cjs_shims();
|
|
5443
|
+
|
|
5444
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
|
|
5445
|
+
init_cjs_shims();
|
|
5446
|
+
var util;
|
|
5447
|
+
(function(util2) {
|
|
5448
|
+
util2.assertEqual = (_) => {
|
|
5449
|
+
};
|
|
5450
|
+
function assertIs(_arg) {
|
|
5451
|
+
}
|
|
5452
|
+
util2.assertIs = assertIs;
|
|
5453
|
+
function assertNever(_x) {
|
|
5454
|
+
throw new Error();
|
|
5455
|
+
}
|
|
5456
|
+
util2.assertNever = assertNever, util2.arrayToEnum = (items) => {
|
|
5457
|
+
let obj = {};
|
|
5458
|
+
for (let item of items)
|
|
5459
|
+
obj[item] = item;
|
|
5460
|
+
return obj;
|
|
5461
|
+
}, util2.getValidEnumValues = (obj) => {
|
|
5462
|
+
let validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] != "number"), filtered = {};
|
|
5463
|
+
for (let k of validKeys)
|
|
5464
|
+
filtered[k] = obj[k];
|
|
5465
|
+
return util2.objectValues(filtered);
|
|
5466
|
+
}, util2.objectValues = (obj) => util2.objectKeys(obj).map(function(e) {
|
|
5467
|
+
return obj[e];
|
|
5468
|
+
}), util2.objectKeys = typeof Object.keys == "function" ? (obj) => Object.keys(obj) : (object) => {
|
|
5469
|
+
let keys = [];
|
|
5470
|
+
for (let key in object)
|
|
5471
|
+
Object.prototype.hasOwnProperty.call(object, key) && keys.push(key);
|
|
5472
|
+
return keys;
|
|
5473
|
+
}, util2.find = (arr, checker) => {
|
|
5474
|
+
for (let item of arr)
|
|
5475
|
+
if (checker(item))
|
|
5476
|
+
return item;
|
|
5477
|
+
}, util2.isInteger = typeof Number.isInteger == "function" ? (val) => Number.isInteger(val) : (val) => typeof val == "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
5478
|
+
function joinValues(array, separator = " | ") {
|
|
5479
|
+
return array.map((val) => typeof val == "string" ? `'${val}'` : val).join(separator);
|
|
5480
|
+
}
|
|
5481
|
+
util2.joinValues = joinValues, util2.jsonStringifyReplacer = (_, value) => typeof value == "bigint" ? value.toString() : value;
|
|
5482
|
+
})(util || (util = {}));
|
|
5483
|
+
var objectUtil;
|
|
5484
|
+
(function(objectUtil2) {
|
|
5485
|
+
objectUtil2.mergeShapes = (first, second) => ({
|
|
5486
|
+
...first,
|
|
5487
|
+
...second
|
|
5488
|
+
// second overwrites first
|
|
5489
|
+
});
|
|
5490
|
+
})(objectUtil || (objectUtil = {}));
|
|
5491
|
+
var ZodParsedType = util.arrayToEnum([
|
|
5492
|
+
"string",
|
|
5493
|
+
"nan",
|
|
5494
|
+
"number",
|
|
5495
|
+
"integer",
|
|
5496
|
+
"float",
|
|
5497
|
+
"boolean",
|
|
5498
|
+
"date",
|
|
5499
|
+
"bigint",
|
|
5500
|
+
"symbol",
|
|
5501
|
+
"function",
|
|
5502
|
+
"undefined",
|
|
5503
|
+
"null",
|
|
5504
|
+
"array",
|
|
5505
|
+
"object",
|
|
5506
|
+
"unknown",
|
|
5507
|
+
"promise",
|
|
5508
|
+
"void",
|
|
5509
|
+
"never",
|
|
5510
|
+
"map",
|
|
5511
|
+
"set"
|
|
5512
|
+
]), getParsedType = (data) => {
|
|
5513
|
+
switch (typeof data) {
|
|
5514
|
+
case "undefined":
|
|
5515
|
+
return ZodParsedType.undefined;
|
|
5516
|
+
case "string":
|
|
5517
|
+
return ZodParsedType.string;
|
|
5518
|
+
case "number":
|
|
5519
|
+
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
5520
|
+
case "boolean":
|
|
5521
|
+
return ZodParsedType.boolean;
|
|
5522
|
+
case "function":
|
|
5523
|
+
return ZodParsedType.function;
|
|
5524
|
+
case "bigint":
|
|
5525
|
+
return ZodParsedType.bigint;
|
|
5526
|
+
case "symbol":
|
|
5527
|
+
return ZodParsedType.symbol;
|
|
5528
|
+
case "object":
|
|
5529
|
+
return Array.isArray(data) ? ZodParsedType.array : data === null ? ZodParsedType.null : data.then && typeof data.then == "function" && data.catch && typeof data.catch == "function" ? ZodParsedType.promise : typeof Map < "u" && data instanceof Map ? ZodParsedType.map : typeof Set < "u" && data instanceof Set ? ZodParsedType.set : typeof Date < "u" && data instanceof Date ? ZodParsedType.date : ZodParsedType.object;
|
|
5530
|
+
default:
|
|
5531
|
+
return ZodParsedType.unknown;
|
|
5532
|
+
}
|
|
5533
|
+
};
|
|
5534
|
+
|
|
5535
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
|
|
5536
|
+
var ZodIssueCode = util.arrayToEnum([
|
|
5537
|
+
"invalid_type",
|
|
5538
|
+
"invalid_literal",
|
|
5539
|
+
"custom",
|
|
5540
|
+
"invalid_union",
|
|
5541
|
+
"invalid_union_discriminator",
|
|
5542
|
+
"invalid_enum_value",
|
|
5543
|
+
"unrecognized_keys",
|
|
5544
|
+
"invalid_arguments",
|
|
5545
|
+
"invalid_return_type",
|
|
5546
|
+
"invalid_date",
|
|
5547
|
+
"invalid_string",
|
|
5548
|
+
"too_small",
|
|
5549
|
+
"too_big",
|
|
5550
|
+
"invalid_intersection_types",
|
|
5551
|
+
"not_multiple_of",
|
|
5552
|
+
"not_finite"
|
|
5553
|
+
]), quotelessJson = (obj) => JSON.stringify(obj, null, 2).replace(/"([^"]+)":/g, "$1:"), ZodError = class _ZodError extends Error {
|
|
5554
|
+
get errors() {
|
|
5555
|
+
return this.issues;
|
|
5556
|
+
}
|
|
5557
|
+
constructor(issues) {
|
|
5558
|
+
super(), this.issues = [], this.addIssue = (sub) => {
|
|
5559
|
+
this.issues = [...this.issues, sub];
|
|
5560
|
+
}, this.addIssues = (subs = []) => {
|
|
5561
|
+
this.issues = [...this.issues, ...subs];
|
|
5562
|
+
};
|
|
5563
|
+
let actualProto = new.target.prototype;
|
|
5564
|
+
Object.setPrototypeOf ? Object.setPrototypeOf(this, actualProto) : this.__proto__ = actualProto, this.name = "ZodError", this.issues = issues;
|
|
5565
|
+
}
|
|
5566
|
+
format(_mapper) {
|
|
5567
|
+
let mapper = _mapper || function(issue) {
|
|
5568
|
+
return issue.message;
|
|
5569
|
+
}, fieldErrors = { _errors: [] }, processError = (error) => {
|
|
5570
|
+
for (let issue of error.issues)
|
|
5571
|
+
if (issue.code === "invalid_union")
|
|
5572
|
+
issue.unionErrors.map(processError);
|
|
5573
|
+
else if (issue.code === "invalid_return_type")
|
|
5574
|
+
processError(issue.returnTypeError);
|
|
5575
|
+
else if (issue.code === "invalid_arguments")
|
|
5576
|
+
processError(issue.argumentsError);
|
|
5577
|
+
else if (issue.path.length === 0)
|
|
5578
|
+
fieldErrors._errors.push(mapper(issue));
|
|
5579
|
+
else {
|
|
5580
|
+
let curr = fieldErrors, i = 0;
|
|
5581
|
+
for (; i < issue.path.length; ) {
|
|
5582
|
+
let el = issue.path[i];
|
|
5583
|
+
i === issue.path.length - 1 ? (curr[el] = curr[el] || { _errors: [] }, curr[el]._errors.push(mapper(issue))) : curr[el] = curr[el] || { _errors: [] }, curr = curr[el], i++;
|
|
5584
|
+
}
|
|
5585
|
+
}
|
|
5586
|
+
};
|
|
5587
|
+
return processError(this), fieldErrors;
|
|
5588
|
+
}
|
|
5589
|
+
static assert(value) {
|
|
5590
|
+
if (!(value instanceof _ZodError))
|
|
5591
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
5592
|
+
}
|
|
5593
|
+
toString() {
|
|
5594
|
+
return this.message;
|
|
5595
|
+
}
|
|
5596
|
+
get message() {
|
|
5597
|
+
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
5598
|
+
}
|
|
5599
|
+
get isEmpty() {
|
|
5600
|
+
return this.issues.length === 0;
|
|
5601
|
+
}
|
|
5602
|
+
flatten(mapper = (issue) => issue.message) {
|
|
5603
|
+
let fieldErrors = {}, formErrors = [];
|
|
5604
|
+
for (let sub of this.issues)
|
|
5605
|
+
if (sub.path.length > 0) {
|
|
5606
|
+
let firstEl = sub.path[0];
|
|
5607
|
+
fieldErrors[firstEl] = fieldErrors[firstEl] || [], fieldErrors[firstEl].push(mapper(sub));
|
|
5608
|
+
} else
|
|
5609
|
+
formErrors.push(mapper(sub));
|
|
5610
|
+
return { formErrors, fieldErrors };
|
|
5611
|
+
}
|
|
5612
|
+
get formErrors() {
|
|
5613
|
+
return this.flatten();
|
|
5614
|
+
}
|
|
5615
|
+
};
|
|
5616
|
+
ZodError.create = (issues) => new ZodError(issues);
|
|
5617
|
+
|
|
5618
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js
|
|
5619
|
+
var errorMap = (issue, _ctx) => {
|
|
5620
|
+
let message;
|
|
5621
|
+
switch (issue.code) {
|
|
5622
|
+
case ZodIssueCode.invalid_type:
|
|
5623
|
+
issue.received === ZodParsedType.undefined ? message = "Required" : message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
5624
|
+
break;
|
|
5625
|
+
case ZodIssueCode.invalid_literal:
|
|
5626
|
+
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
|
|
5627
|
+
break;
|
|
5628
|
+
case ZodIssueCode.unrecognized_keys:
|
|
5629
|
+
message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
|
|
5630
|
+
break;
|
|
5631
|
+
case ZodIssueCode.invalid_union:
|
|
5632
|
+
message = "Invalid input";
|
|
5633
|
+
break;
|
|
5634
|
+
case ZodIssueCode.invalid_union_discriminator:
|
|
5635
|
+
message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
|
|
5636
|
+
break;
|
|
5637
|
+
case ZodIssueCode.invalid_enum_value:
|
|
5638
|
+
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
5639
|
+
break;
|
|
5640
|
+
case ZodIssueCode.invalid_arguments:
|
|
5641
|
+
message = "Invalid function arguments";
|
|
5642
|
+
break;
|
|
5643
|
+
case ZodIssueCode.invalid_return_type:
|
|
5644
|
+
message = "Invalid function return type";
|
|
5645
|
+
break;
|
|
5646
|
+
case ZodIssueCode.invalid_date:
|
|
5647
|
+
message = "Invalid date";
|
|
5648
|
+
break;
|
|
5649
|
+
case ZodIssueCode.invalid_string:
|
|
5650
|
+
typeof issue.validation == "object" ? "includes" in issue.validation ? (message = `Invalid input: must include "${issue.validation.includes}"`, typeof issue.validation.position == "number" && (message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`)) : "startsWith" in issue.validation ? message = `Invalid input: must start with "${issue.validation.startsWith}"` : "endsWith" in issue.validation ? message = `Invalid input: must end with "${issue.validation.endsWith}"` : util.assertNever(issue.validation) : issue.validation !== "regex" ? message = `Invalid ${issue.validation}` : message = "Invalid";
|
|
5651
|
+
break;
|
|
5652
|
+
case ZodIssueCode.too_small:
|
|
5653
|
+
issue.type === "array" ? message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? "at least" : "more than"} ${issue.minimum} element(s)` : issue.type === "string" ? message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? "at least" : "over"} ${issue.minimum} character(s)` : issue.type === "number" ? message = `Number must be ${issue.exact ? "exactly equal to " : issue.inclusive ? "greater than or equal to " : "greater than "}${issue.minimum}` : issue.type === "bigint" ? message = `Number must be ${issue.exact ? "exactly equal to " : issue.inclusive ? "greater than or equal to " : "greater than "}${issue.minimum}` : issue.type === "date" ? message = `Date must be ${issue.exact ? "exactly equal to " : issue.inclusive ? "greater than or equal to " : "greater than "}${new Date(Number(issue.minimum))}` : message = "Invalid input";
|
|
5654
|
+
break;
|
|
5655
|
+
case ZodIssueCode.too_big:
|
|
5656
|
+
issue.type === "array" ? message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? "at most" : "less than"} ${issue.maximum} element(s)` : issue.type === "string" ? message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? "at most" : "under"} ${issue.maximum} character(s)` : issue.type === "number" ? message = `Number must be ${issue.exact ? "exactly" : issue.inclusive ? "less than or equal to" : "less than"} ${issue.maximum}` : issue.type === "bigint" ? message = `BigInt must be ${issue.exact ? "exactly" : issue.inclusive ? "less than or equal to" : "less than"} ${issue.maximum}` : issue.type === "date" ? message = `Date must be ${issue.exact ? "exactly" : issue.inclusive ? "smaller than or equal to" : "smaller than"} ${new Date(Number(issue.maximum))}` : message = "Invalid input";
|
|
5657
|
+
break;
|
|
5658
|
+
case ZodIssueCode.custom:
|
|
5659
|
+
message = "Invalid input";
|
|
5660
|
+
break;
|
|
5661
|
+
case ZodIssueCode.invalid_intersection_types:
|
|
5662
|
+
message = "Intersection results could not be merged";
|
|
5663
|
+
break;
|
|
5664
|
+
case ZodIssueCode.not_multiple_of:
|
|
5665
|
+
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
5666
|
+
break;
|
|
5667
|
+
case ZodIssueCode.not_finite:
|
|
5668
|
+
message = "Number must be finite";
|
|
5669
|
+
break;
|
|
5670
|
+
default:
|
|
5671
|
+
message = _ctx.defaultError, util.assertNever(issue);
|
|
5672
|
+
}
|
|
5673
|
+
return { message };
|
|
5674
|
+
}, en_default = errorMap;
|
|
5675
|
+
|
|
5676
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js
|
|
5677
|
+
var overrideErrorMap = en_default;
|
|
5678
|
+
function setErrorMap(map) {
|
|
5679
|
+
overrideErrorMap = map;
|
|
5680
|
+
}
|
|
5681
|
+
function getErrorMap() {
|
|
5682
|
+
return overrideErrorMap;
|
|
5683
|
+
}
|
|
5684
|
+
|
|
5685
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
|
|
5686
|
+
init_cjs_shims();
|
|
5687
|
+
var makeIssue = (params) => {
|
|
5688
|
+
let { data, path: path4, errorMaps, issueData } = params, fullPath = [...path4, ...issueData.path || []], fullIssue = {
|
|
5689
|
+
...issueData,
|
|
5690
|
+
path: fullPath
|
|
5691
|
+
};
|
|
5692
|
+
if (issueData.message !== void 0)
|
|
5693
|
+
return {
|
|
5694
|
+
...issueData,
|
|
5695
|
+
path: fullPath,
|
|
5696
|
+
message: issueData.message
|
|
5697
|
+
};
|
|
5698
|
+
let errorMessage = "", maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
5699
|
+
for (let map of maps)
|
|
5700
|
+
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
|
5701
|
+
return {
|
|
5702
|
+
...issueData,
|
|
5703
|
+
path: fullPath,
|
|
5704
|
+
message: errorMessage
|
|
5705
|
+
};
|
|
5706
|
+
}, EMPTY_PATH = [];
|
|
5707
|
+
function addIssueToContext(ctx, issueData) {
|
|
5708
|
+
let overrideMap = getErrorMap(), issue = makeIssue({
|
|
5709
|
+
issueData,
|
|
5710
|
+
data: ctx.data,
|
|
5711
|
+
path: ctx.path,
|
|
5712
|
+
errorMaps: [
|
|
5713
|
+
ctx.common.contextualErrorMap,
|
|
5714
|
+
// contextual error map is first priority
|
|
5715
|
+
ctx.schemaErrorMap,
|
|
5716
|
+
// then schema-bound map if available
|
|
5717
|
+
overrideMap,
|
|
5718
|
+
// then global override map
|
|
5719
|
+
overrideMap === en_default ? void 0 : en_default
|
|
5720
|
+
// then global default map
|
|
5721
|
+
].filter((x) => !!x)
|
|
5722
|
+
});
|
|
5723
|
+
ctx.common.issues.push(issue);
|
|
5724
|
+
}
|
|
5725
|
+
var ParseStatus = class _ParseStatus {
|
|
5726
|
+
constructor() {
|
|
5727
|
+
this.value = "valid";
|
|
5728
|
+
}
|
|
5729
|
+
dirty() {
|
|
5730
|
+
this.value === "valid" && (this.value = "dirty");
|
|
5731
|
+
}
|
|
5732
|
+
abort() {
|
|
5733
|
+
this.value !== "aborted" && (this.value = "aborted");
|
|
5734
|
+
}
|
|
5735
|
+
static mergeArray(status, results) {
|
|
5736
|
+
let arrayValue = [];
|
|
5737
|
+
for (let s of results) {
|
|
5738
|
+
if (s.status === "aborted")
|
|
5739
|
+
return INVALID;
|
|
5740
|
+
s.status === "dirty" && status.dirty(), arrayValue.push(s.value);
|
|
5741
|
+
}
|
|
5742
|
+
return { status: status.value, value: arrayValue };
|
|
5743
|
+
}
|
|
5744
|
+
static async mergeObjectAsync(status, pairs) {
|
|
5745
|
+
let syncPairs = [];
|
|
5746
|
+
for (let pair of pairs) {
|
|
5747
|
+
let key = await pair.key, value = await pair.value;
|
|
5748
|
+
syncPairs.push({
|
|
5749
|
+
key,
|
|
5750
|
+
value
|
|
5751
|
+
});
|
|
5752
|
+
}
|
|
5753
|
+
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
|
5754
|
+
}
|
|
5755
|
+
static mergeObjectSync(status, pairs) {
|
|
5756
|
+
let finalObject = {};
|
|
5757
|
+
for (let pair of pairs) {
|
|
5758
|
+
let { key, value } = pair;
|
|
5759
|
+
if (key.status === "aborted" || value.status === "aborted")
|
|
5760
|
+
return INVALID;
|
|
5761
|
+
key.status === "dirty" && status.dirty(), value.status === "dirty" && status.dirty(), key.value !== "__proto__" && (typeof value.value < "u" || pair.alwaysSet) && (finalObject[key.value] = value.value);
|
|
5762
|
+
}
|
|
5763
|
+
return { status: status.value, value: finalObject };
|
|
5764
|
+
}
|
|
5765
|
+
}, INVALID = Object.freeze({
|
|
5766
|
+
status: "aborted"
|
|
5767
|
+
}), DIRTY = (value) => ({ status: "dirty", value }), OK = (value) => ({ status: "valid", value }), isAborted = (x) => x.status === "aborted", isDirty = (x) => x.status === "dirty", isValid = (x) => x.status === "valid", isAsync = (x) => typeof Promise < "u" && x instanceof Promise;
|
|
5768
|
+
|
|
5769
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
|
|
5770
|
+
init_cjs_shims();
|
|
5771
|
+
|
|
5772
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
|
|
5773
|
+
init_cjs_shims();
|
|
5774
|
+
var errorUtil;
|
|
5775
|
+
(function(errorUtil2) {
|
|
5776
|
+
errorUtil2.errToObj = (message) => typeof message == "string" ? { message } : message || {}, errorUtil2.toString = (message) => typeof message == "string" ? message : message?.message;
|
|
5777
|
+
})(errorUtil || (errorUtil = {}));
|
|
5778
|
+
|
|
5779
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
|
|
5780
|
+
var ParseInputLazyPath = class {
|
|
5781
|
+
constructor(parent, value, path4, key) {
|
|
5782
|
+
this._cachedPath = [], this.parent = parent, this.data = value, this._path = path4, this._key = key;
|
|
5783
|
+
}
|
|
5784
|
+
get path() {
|
|
5785
|
+
return this._cachedPath.length || (Array.isArray(this._key) ? this._cachedPath.push(...this._path, ...this._key) : this._cachedPath.push(...this._path, this._key)), this._cachedPath;
|
|
5786
|
+
}
|
|
5787
|
+
}, handleResult = (ctx, result) => {
|
|
5788
|
+
if (isValid(result))
|
|
5789
|
+
return { success: !0, data: result.value };
|
|
5790
|
+
if (!ctx.common.issues.length)
|
|
5791
|
+
throw new Error("Validation failed but no issues detected.");
|
|
5792
|
+
return {
|
|
5793
|
+
success: !1,
|
|
5794
|
+
get error() {
|
|
5795
|
+
if (this._error)
|
|
5796
|
+
return this._error;
|
|
5797
|
+
let error = new ZodError(ctx.common.issues);
|
|
5798
|
+
return this._error = error, this._error;
|
|
5799
|
+
}
|
|
5800
|
+
};
|
|
5801
|
+
};
|
|
5802
|
+
function processCreateParams(params) {
|
|
5803
|
+
if (!params)
|
|
5804
|
+
return {};
|
|
5805
|
+
let { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
|
|
5806
|
+
if (errorMap2 && (invalid_type_error || required_error))
|
|
5807
|
+
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
5808
|
+
return errorMap2 ? { errorMap: errorMap2, description } : { errorMap: (iss, ctx) => {
|
|
5809
|
+
let { message } = params;
|
|
5810
|
+
return iss.code === "invalid_enum_value" ? { message: message ?? ctx.defaultError } : typeof ctx.data > "u" ? { message: message ?? required_error ?? ctx.defaultError } : iss.code !== "invalid_type" ? { message: ctx.defaultError } : { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
5811
|
+
}, description };
|
|
5812
|
+
}
|
|
5813
|
+
var ZodType = class {
|
|
5814
|
+
get description() {
|
|
5815
|
+
return this._def.description;
|
|
5816
|
+
}
|
|
5817
|
+
_getType(input) {
|
|
5818
|
+
return getParsedType(input.data);
|
|
5819
|
+
}
|
|
5820
|
+
_getOrReturnCtx(input, ctx) {
|
|
5821
|
+
return ctx || {
|
|
5822
|
+
common: input.parent.common,
|
|
5823
|
+
data: input.data,
|
|
5824
|
+
parsedType: getParsedType(input.data),
|
|
5825
|
+
schemaErrorMap: this._def.errorMap,
|
|
5826
|
+
path: input.path,
|
|
5827
|
+
parent: input.parent
|
|
5828
|
+
};
|
|
5829
|
+
}
|
|
5830
|
+
_processInputParams(input) {
|
|
5831
|
+
return {
|
|
5832
|
+
status: new ParseStatus(),
|
|
5833
|
+
ctx: {
|
|
5834
|
+
common: input.parent.common,
|
|
5835
|
+
data: input.data,
|
|
5836
|
+
parsedType: getParsedType(input.data),
|
|
5837
|
+
schemaErrorMap: this._def.errorMap,
|
|
5838
|
+
path: input.path,
|
|
5839
|
+
parent: input.parent
|
|
5840
|
+
}
|
|
5841
|
+
};
|
|
5842
|
+
}
|
|
5843
|
+
_parseSync(input) {
|
|
5844
|
+
let result = this._parse(input);
|
|
5845
|
+
if (isAsync(result))
|
|
5846
|
+
throw new Error("Synchronous parse encountered promise.");
|
|
5847
|
+
return result;
|
|
5848
|
+
}
|
|
5849
|
+
_parseAsync(input) {
|
|
5850
|
+
let result = this._parse(input);
|
|
5851
|
+
return Promise.resolve(result);
|
|
5852
|
+
}
|
|
5853
|
+
parse(data, params) {
|
|
5854
|
+
let result = this.safeParse(data, params);
|
|
5855
|
+
if (result.success)
|
|
5856
|
+
return result.data;
|
|
5857
|
+
throw result.error;
|
|
5858
|
+
}
|
|
5859
|
+
safeParse(data, params) {
|
|
5860
|
+
let ctx = {
|
|
5861
|
+
common: {
|
|
5862
|
+
issues: [],
|
|
5863
|
+
async: params?.async ?? !1,
|
|
5864
|
+
contextualErrorMap: params?.errorMap
|
|
5865
|
+
},
|
|
5866
|
+
path: params?.path || [],
|
|
5867
|
+
schemaErrorMap: this._def.errorMap,
|
|
5868
|
+
parent: null,
|
|
5869
|
+
data,
|
|
5870
|
+
parsedType: getParsedType(data)
|
|
5871
|
+
}, result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
5872
|
+
return handleResult(ctx, result);
|
|
5873
|
+
}
|
|
5874
|
+
"~validate"(data) {
|
|
5875
|
+
let ctx = {
|
|
5876
|
+
common: {
|
|
5877
|
+
issues: [],
|
|
5878
|
+
async: !!this["~standard"].async
|
|
5879
|
+
},
|
|
5880
|
+
path: [],
|
|
5881
|
+
schemaErrorMap: this._def.errorMap,
|
|
5882
|
+
parent: null,
|
|
5883
|
+
data,
|
|
5884
|
+
parsedType: getParsedType(data)
|
|
5885
|
+
};
|
|
5886
|
+
if (!this["~standard"].async)
|
|
5887
|
+
try {
|
|
5888
|
+
let result = this._parseSync({ data, path: [], parent: ctx });
|
|
5889
|
+
return isValid(result) ? {
|
|
5890
|
+
value: result.value
|
|
5891
|
+
} : {
|
|
5892
|
+
issues: ctx.common.issues
|
|
5893
|
+
};
|
|
5894
|
+
} catch (err) {
|
|
5895
|
+
err?.message?.toLowerCase()?.includes("encountered") && (this["~standard"].async = !0), ctx.common = {
|
|
5896
|
+
issues: [],
|
|
5897
|
+
async: !0
|
|
5898
|
+
};
|
|
5899
|
+
}
|
|
5900
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
5901
|
+
value: result.value
|
|
5902
|
+
} : {
|
|
5903
|
+
issues: ctx.common.issues
|
|
5904
|
+
});
|
|
5905
|
+
}
|
|
5906
|
+
async parseAsync(data, params) {
|
|
5907
|
+
let result = await this.safeParseAsync(data, params);
|
|
5908
|
+
if (result.success)
|
|
5909
|
+
return result.data;
|
|
5910
|
+
throw result.error;
|
|
5911
|
+
}
|
|
5912
|
+
async safeParseAsync(data, params) {
|
|
5913
|
+
let ctx = {
|
|
5914
|
+
common: {
|
|
5915
|
+
issues: [],
|
|
5916
|
+
contextualErrorMap: params?.errorMap,
|
|
5917
|
+
async: !0
|
|
5918
|
+
},
|
|
5919
|
+
path: params?.path || [],
|
|
5920
|
+
schemaErrorMap: this._def.errorMap,
|
|
5921
|
+
parent: null,
|
|
5922
|
+
data,
|
|
5923
|
+
parsedType: getParsedType(data)
|
|
5924
|
+
}, maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx }), result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
5925
|
+
return handleResult(ctx, result);
|
|
5926
|
+
}
|
|
5927
|
+
refine(check, message) {
|
|
5928
|
+
let getIssueProperties = (val) => typeof message == "string" || typeof message > "u" ? { message } : typeof message == "function" ? message(val) : message;
|
|
5929
|
+
return this._refinement((val, ctx) => {
|
|
5930
|
+
let result = check(val), setError = () => ctx.addIssue({
|
|
5931
|
+
code: ZodIssueCode.custom,
|
|
5932
|
+
...getIssueProperties(val)
|
|
5933
|
+
});
|
|
5934
|
+
return typeof Promise < "u" && result instanceof Promise ? result.then((data) => data ? !0 : (setError(), !1)) : result ? !0 : (setError(), !1);
|
|
5935
|
+
});
|
|
5936
|
+
}
|
|
5937
|
+
refinement(check, refinementData) {
|
|
5938
|
+
return this._refinement((val, ctx) => check(val) ? !0 : (ctx.addIssue(typeof refinementData == "function" ? refinementData(val, ctx) : refinementData), !1));
|
|
5939
|
+
}
|
|
5940
|
+
_refinement(refinement) {
|
|
5941
|
+
return new ZodEffects({
|
|
5942
|
+
schema: this,
|
|
5943
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
5944
|
+
effect: { type: "refinement", refinement }
|
|
5945
|
+
});
|
|
5946
|
+
}
|
|
5947
|
+
superRefine(refinement) {
|
|
5948
|
+
return this._refinement(refinement);
|
|
5949
|
+
}
|
|
5950
|
+
constructor(def) {
|
|
5951
|
+
this.spa = this.safeParseAsync, this._def = def, this.parse = this.parse.bind(this), this.safeParse = this.safeParse.bind(this), this.parseAsync = this.parseAsync.bind(this), this.safeParseAsync = this.safeParseAsync.bind(this), this.spa = this.spa.bind(this), this.refine = this.refine.bind(this), this.refinement = this.refinement.bind(this), this.superRefine = this.superRefine.bind(this), this.optional = this.optional.bind(this), this.nullable = this.nullable.bind(this), this.nullish = this.nullish.bind(this), this.array = this.array.bind(this), this.promise = this.promise.bind(this), this.or = this.or.bind(this), this.and = this.and.bind(this), this.transform = this.transform.bind(this), this.brand = this.brand.bind(this), this.default = this.default.bind(this), this.catch = this.catch.bind(this), this.describe = this.describe.bind(this), this.pipe = this.pipe.bind(this), this.readonly = this.readonly.bind(this), this.isNullable = this.isNullable.bind(this), this.isOptional = this.isOptional.bind(this), this["~standard"] = {
|
|
5952
|
+
version: 1,
|
|
5953
|
+
vendor: "zod",
|
|
5954
|
+
validate: (data) => this["~validate"](data)
|
|
5955
|
+
};
|
|
5956
|
+
}
|
|
5957
|
+
optional() {
|
|
5958
|
+
return ZodOptional.create(this, this._def);
|
|
5959
|
+
}
|
|
5960
|
+
nullable() {
|
|
5961
|
+
return ZodNullable.create(this, this._def);
|
|
5962
|
+
}
|
|
5963
|
+
nullish() {
|
|
5964
|
+
return this.nullable().optional();
|
|
5965
|
+
}
|
|
5966
|
+
array() {
|
|
5967
|
+
return ZodArray.create(this);
|
|
5968
|
+
}
|
|
5969
|
+
promise() {
|
|
5970
|
+
return ZodPromise.create(this, this._def);
|
|
5971
|
+
}
|
|
5972
|
+
or(option) {
|
|
5973
|
+
return ZodUnion.create([this, option], this._def);
|
|
5974
|
+
}
|
|
5975
|
+
and(incoming) {
|
|
5976
|
+
return ZodIntersection.create(this, incoming, this._def);
|
|
5977
|
+
}
|
|
5978
|
+
transform(transform) {
|
|
5979
|
+
return new ZodEffects({
|
|
5980
|
+
...processCreateParams(this._def),
|
|
5981
|
+
schema: this,
|
|
5982
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
5983
|
+
effect: { type: "transform", transform }
|
|
5984
|
+
});
|
|
5985
|
+
}
|
|
5986
|
+
default(def) {
|
|
5987
|
+
let defaultValueFunc = typeof def == "function" ? def : () => def;
|
|
5988
|
+
return new ZodDefault({
|
|
5989
|
+
...processCreateParams(this._def),
|
|
5990
|
+
innerType: this,
|
|
5991
|
+
defaultValue: defaultValueFunc,
|
|
5992
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
5993
|
+
});
|
|
5994
|
+
}
|
|
5995
|
+
brand() {
|
|
5996
|
+
return new ZodBranded({
|
|
5997
|
+
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
5998
|
+
type: this,
|
|
5999
|
+
...processCreateParams(this._def)
|
|
6000
|
+
});
|
|
6001
|
+
}
|
|
6002
|
+
catch(def) {
|
|
6003
|
+
let catchValueFunc = typeof def == "function" ? def : () => def;
|
|
6004
|
+
return new ZodCatch({
|
|
6005
|
+
...processCreateParams(this._def),
|
|
6006
|
+
innerType: this,
|
|
6007
|
+
catchValue: catchValueFunc,
|
|
6008
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
6009
|
+
});
|
|
6010
|
+
}
|
|
6011
|
+
describe(description) {
|
|
6012
|
+
let This = this.constructor;
|
|
6013
|
+
return new This({
|
|
6014
|
+
...this._def,
|
|
6015
|
+
description
|
|
6016
|
+
});
|
|
6017
|
+
}
|
|
6018
|
+
pipe(target) {
|
|
6019
|
+
return ZodPipeline.create(this, target);
|
|
6020
|
+
}
|
|
6021
|
+
readonly() {
|
|
6022
|
+
return ZodReadonly.create(this);
|
|
6023
|
+
}
|
|
6024
|
+
isOptional() {
|
|
6025
|
+
return this.safeParse(void 0).success;
|
|
6026
|
+
}
|
|
6027
|
+
isNullable() {
|
|
6028
|
+
return this.safeParse(null).success;
|
|
6029
|
+
}
|
|
6030
|
+
}, cuidRegex = /^c[^\s-]{8,}$/i, cuid2Regex = /^[0-9a-z]+$/, ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i, 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, nanoidRegex = /^[a-z0-9_-]{21}$/i, jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/, 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)?)??$/, emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i, _emojiRegex = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", emojiRegex, 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])$/, 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])$/, 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]))$/, 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])$/, base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/, base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/, 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])))", dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
6031
|
+
function timeRegexSource(args) {
|
|
6032
|
+
let secondsRegexSource = "[0-5]\\d";
|
|
6033
|
+
args.precision ? secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}` : args.precision == null && (secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`);
|
|
6034
|
+
let secondsQuantifier = args.precision ? "+" : "?";
|
|
6035
|
+
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
6036
|
+
}
|
|
6037
|
+
function timeRegex(args) {
|
|
6038
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
6039
|
+
}
|
|
6040
|
+
function datetimeRegex(args) {
|
|
6041
|
+
let regex2 = `${dateRegexSource}T${timeRegexSource(args)}`, opts = [];
|
|
6042
|
+
return opts.push(args.local ? "Z?" : "Z"), args.offset && opts.push("([+-]\\d{2}:?\\d{2})"), regex2 = `${regex2}(${opts.join("|")})`, new RegExp(`^${regex2}$`);
|
|
6043
|
+
}
|
|
6044
|
+
function isValidIP(ip, version) {
|
|
6045
|
+
return !!((version === "v4" || !version) && ipv4Regex.test(ip) || (version === "v6" || !version) && ipv6Regex.test(ip));
|
|
6046
|
+
}
|
|
6047
|
+
function isValidJWT(jwt, alg) {
|
|
6048
|
+
if (!jwtRegex.test(jwt))
|
|
6049
|
+
return !1;
|
|
6050
|
+
try {
|
|
6051
|
+
let [header] = jwt.split(".");
|
|
6052
|
+
if (!header)
|
|
6053
|
+
return !1;
|
|
6054
|
+
let base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "="), decoded = JSON.parse(atob(base64));
|
|
6055
|
+
return !(typeof decoded != "object" || decoded === null || "typ" in decoded && decoded?.typ !== "JWT" || !decoded.alg || alg && decoded.alg !== alg);
|
|
6056
|
+
} catch {
|
|
6057
|
+
return !1;
|
|
6058
|
+
}
|
|
6059
|
+
}
|
|
6060
|
+
function isValidCidr(ip, version) {
|
|
6061
|
+
return !!((version === "v4" || !version) && ipv4CidrRegex.test(ip) || (version === "v6" || !version) && ipv6CidrRegex.test(ip));
|
|
6062
|
+
}
|
|
6063
|
+
var ZodString = class _ZodString extends ZodType {
|
|
6064
|
+
_parse(input) {
|
|
6065
|
+
if (this._def.coerce && (input.data = String(input.data)), this._getType(input) !== ZodParsedType.string) {
|
|
6066
|
+
let ctx2 = this._getOrReturnCtx(input);
|
|
6067
|
+
return addIssueToContext(ctx2, {
|
|
6068
|
+
code: ZodIssueCode.invalid_type,
|
|
6069
|
+
expected: ZodParsedType.string,
|
|
6070
|
+
received: ctx2.parsedType
|
|
6071
|
+
}), INVALID;
|
|
6072
|
+
}
|
|
6073
|
+
let status = new ParseStatus(), ctx;
|
|
6074
|
+
for (let check of this._def.checks)
|
|
6075
|
+
if (check.kind === "min")
|
|
6076
|
+
input.data.length < check.value && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6077
|
+
code: ZodIssueCode.too_small,
|
|
6078
|
+
minimum: check.value,
|
|
6079
|
+
type: "string",
|
|
6080
|
+
inclusive: !0,
|
|
6081
|
+
exact: !1,
|
|
6082
|
+
message: check.message
|
|
6083
|
+
}), status.dirty());
|
|
6084
|
+
else if (check.kind === "max")
|
|
6085
|
+
input.data.length > check.value && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6086
|
+
code: ZodIssueCode.too_big,
|
|
6087
|
+
maximum: check.value,
|
|
6088
|
+
type: "string",
|
|
6089
|
+
inclusive: !0,
|
|
6090
|
+
exact: !1,
|
|
6091
|
+
message: check.message
|
|
6092
|
+
}), status.dirty());
|
|
6093
|
+
else if (check.kind === "length") {
|
|
6094
|
+
let tooBig = input.data.length > check.value, tooSmall = input.data.length < check.value;
|
|
6095
|
+
(tooBig || tooSmall) && (ctx = this._getOrReturnCtx(input, ctx), tooBig ? addIssueToContext(ctx, {
|
|
6096
|
+
code: ZodIssueCode.too_big,
|
|
6097
|
+
maximum: check.value,
|
|
6098
|
+
type: "string",
|
|
6099
|
+
inclusive: !0,
|
|
6100
|
+
exact: !0,
|
|
6101
|
+
message: check.message
|
|
6102
|
+
}) : tooSmall && addIssueToContext(ctx, {
|
|
6103
|
+
code: ZodIssueCode.too_small,
|
|
6104
|
+
minimum: check.value,
|
|
6105
|
+
type: "string",
|
|
6106
|
+
inclusive: !0,
|
|
6107
|
+
exact: !0,
|
|
6108
|
+
message: check.message
|
|
6109
|
+
}), status.dirty());
|
|
6110
|
+
} else if (check.kind === "email")
|
|
6111
|
+
emailRegex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6112
|
+
validation: "email",
|
|
6113
|
+
code: ZodIssueCode.invalid_string,
|
|
6114
|
+
message: check.message
|
|
6115
|
+
}), status.dirty());
|
|
6116
|
+
else if (check.kind === "emoji")
|
|
6117
|
+
emojiRegex || (emojiRegex = new RegExp(_emojiRegex, "u")), emojiRegex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6118
|
+
validation: "emoji",
|
|
6119
|
+
code: ZodIssueCode.invalid_string,
|
|
6120
|
+
message: check.message
|
|
6121
|
+
}), status.dirty());
|
|
6122
|
+
else if (check.kind === "uuid")
|
|
6123
|
+
uuidRegex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6124
|
+
validation: "uuid",
|
|
6125
|
+
code: ZodIssueCode.invalid_string,
|
|
6126
|
+
message: check.message
|
|
6127
|
+
}), status.dirty());
|
|
6128
|
+
else if (check.kind === "nanoid")
|
|
6129
|
+
nanoidRegex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6130
|
+
validation: "nanoid",
|
|
6131
|
+
code: ZodIssueCode.invalid_string,
|
|
6132
|
+
message: check.message
|
|
6133
|
+
}), status.dirty());
|
|
6134
|
+
else if (check.kind === "cuid")
|
|
6135
|
+
cuidRegex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6136
|
+
validation: "cuid",
|
|
6137
|
+
code: ZodIssueCode.invalid_string,
|
|
6138
|
+
message: check.message
|
|
6139
|
+
}), status.dirty());
|
|
6140
|
+
else if (check.kind === "cuid2")
|
|
6141
|
+
cuid2Regex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6142
|
+
validation: "cuid2",
|
|
6143
|
+
code: ZodIssueCode.invalid_string,
|
|
6144
|
+
message: check.message
|
|
6145
|
+
}), status.dirty());
|
|
6146
|
+
else if (check.kind === "ulid")
|
|
6147
|
+
ulidRegex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6148
|
+
validation: "ulid",
|
|
6149
|
+
code: ZodIssueCode.invalid_string,
|
|
6150
|
+
message: check.message
|
|
6151
|
+
}), status.dirty());
|
|
6152
|
+
else if (check.kind === "url")
|
|
6153
|
+
try {
|
|
6154
|
+
new URL(input.data);
|
|
6155
|
+
} catch {
|
|
6156
|
+
ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6157
|
+
validation: "url",
|
|
6158
|
+
code: ZodIssueCode.invalid_string,
|
|
6159
|
+
message: check.message
|
|
6160
|
+
}), status.dirty();
|
|
6161
|
+
}
|
|
6162
|
+
else check.kind === "regex" ? (check.regex.lastIndex = 0, check.regex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6163
|
+
validation: "regex",
|
|
6164
|
+
code: ZodIssueCode.invalid_string,
|
|
6165
|
+
message: check.message
|
|
6166
|
+
}), status.dirty())) : check.kind === "trim" ? input.data = input.data.trim() : check.kind === "includes" ? input.data.includes(check.value, check.position) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6167
|
+
code: ZodIssueCode.invalid_string,
|
|
6168
|
+
validation: { includes: check.value, position: check.position },
|
|
6169
|
+
message: check.message
|
|
6170
|
+
}), status.dirty()) : check.kind === "toLowerCase" ? input.data = input.data.toLowerCase() : check.kind === "toUpperCase" ? input.data = input.data.toUpperCase() : check.kind === "startsWith" ? input.data.startsWith(check.value) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6171
|
+
code: ZodIssueCode.invalid_string,
|
|
6172
|
+
validation: { startsWith: check.value },
|
|
6173
|
+
message: check.message
|
|
6174
|
+
}), status.dirty()) : check.kind === "endsWith" ? input.data.endsWith(check.value) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6175
|
+
code: ZodIssueCode.invalid_string,
|
|
6176
|
+
validation: { endsWith: check.value },
|
|
6177
|
+
message: check.message
|
|
6178
|
+
}), status.dirty()) : check.kind === "datetime" ? datetimeRegex(check).test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6179
|
+
code: ZodIssueCode.invalid_string,
|
|
6180
|
+
validation: "datetime",
|
|
6181
|
+
message: check.message
|
|
6182
|
+
}), status.dirty()) : check.kind === "date" ? dateRegex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6183
|
+
code: ZodIssueCode.invalid_string,
|
|
6184
|
+
validation: "date",
|
|
6185
|
+
message: check.message
|
|
6186
|
+
}), status.dirty()) : check.kind === "time" ? timeRegex(check).test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6187
|
+
code: ZodIssueCode.invalid_string,
|
|
6188
|
+
validation: "time",
|
|
6189
|
+
message: check.message
|
|
6190
|
+
}), status.dirty()) : check.kind === "duration" ? durationRegex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6191
|
+
validation: "duration",
|
|
6192
|
+
code: ZodIssueCode.invalid_string,
|
|
6193
|
+
message: check.message
|
|
6194
|
+
}), status.dirty()) : check.kind === "ip" ? isValidIP(input.data, check.version) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6195
|
+
validation: "ip",
|
|
6196
|
+
code: ZodIssueCode.invalid_string,
|
|
6197
|
+
message: check.message
|
|
6198
|
+
}), status.dirty()) : check.kind === "jwt" ? isValidJWT(input.data, check.alg) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6199
|
+
validation: "jwt",
|
|
6200
|
+
code: ZodIssueCode.invalid_string,
|
|
6201
|
+
message: check.message
|
|
6202
|
+
}), status.dirty()) : check.kind === "cidr" ? isValidCidr(input.data, check.version) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6203
|
+
validation: "cidr",
|
|
6204
|
+
code: ZodIssueCode.invalid_string,
|
|
6205
|
+
message: check.message
|
|
6206
|
+
}), status.dirty()) : check.kind === "base64" ? base64Regex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6207
|
+
validation: "base64",
|
|
6208
|
+
code: ZodIssueCode.invalid_string,
|
|
6209
|
+
message: check.message
|
|
6210
|
+
}), status.dirty()) : check.kind === "base64url" ? base64urlRegex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6211
|
+
validation: "base64url",
|
|
6212
|
+
code: ZodIssueCode.invalid_string,
|
|
6213
|
+
message: check.message
|
|
6214
|
+
}), status.dirty()) : util.assertNever(check);
|
|
6215
|
+
return { status: status.value, value: input.data };
|
|
6216
|
+
}
|
|
6217
|
+
_regex(regex2, validation, message) {
|
|
6218
|
+
return this.refinement((data) => regex2.test(data), {
|
|
6219
|
+
validation,
|
|
6220
|
+
code: ZodIssueCode.invalid_string,
|
|
6221
|
+
...errorUtil.errToObj(message)
|
|
6222
|
+
});
|
|
6223
|
+
}
|
|
6224
|
+
_addCheck(check) {
|
|
6225
|
+
return new _ZodString({
|
|
6226
|
+
...this._def,
|
|
6227
|
+
checks: [...this._def.checks, check]
|
|
6228
|
+
});
|
|
6229
|
+
}
|
|
6230
|
+
email(message) {
|
|
6231
|
+
return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
|
|
6232
|
+
}
|
|
6233
|
+
url(message) {
|
|
6234
|
+
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
|
6235
|
+
}
|
|
6236
|
+
emoji(message) {
|
|
6237
|
+
return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
|
|
6238
|
+
}
|
|
6239
|
+
uuid(message) {
|
|
6240
|
+
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
6241
|
+
}
|
|
6242
|
+
nanoid(message) {
|
|
6243
|
+
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
6244
|
+
}
|
|
6245
|
+
cuid(message) {
|
|
6246
|
+
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
6247
|
+
}
|
|
6248
|
+
cuid2(message) {
|
|
6249
|
+
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
|
6250
|
+
}
|
|
6251
|
+
ulid(message) {
|
|
6252
|
+
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
6253
|
+
}
|
|
6254
|
+
base64(message) {
|
|
6255
|
+
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
6256
|
+
}
|
|
6257
|
+
base64url(message) {
|
|
6258
|
+
return this._addCheck({
|
|
6259
|
+
kind: "base64url",
|
|
6260
|
+
...errorUtil.errToObj(message)
|
|
6261
|
+
});
|
|
6262
|
+
}
|
|
6263
|
+
jwt(options) {
|
|
6264
|
+
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
6265
|
+
}
|
|
6266
|
+
ip(options) {
|
|
6267
|
+
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
6268
|
+
}
|
|
6269
|
+
cidr(options) {
|
|
6270
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
6271
|
+
}
|
|
6272
|
+
datetime(options) {
|
|
6273
|
+
return typeof options == "string" ? this._addCheck({
|
|
6274
|
+
kind: "datetime",
|
|
6275
|
+
precision: null,
|
|
6276
|
+
offset: !1,
|
|
6277
|
+
local: !1,
|
|
6278
|
+
message: options
|
|
6279
|
+
}) : this._addCheck({
|
|
6280
|
+
kind: "datetime",
|
|
6281
|
+
precision: typeof options?.precision > "u" ? null : options?.precision,
|
|
6282
|
+
offset: options?.offset ?? !1,
|
|
6283
|
+
local: options?.local ?? !1,
|
|
6284
|
+
...errorUtil.errToObj(options?.message)
|
|
6285
|
+
});
|
|
6286
|
+
}
|
|
6287
|
+
date(message) {
|
|
6288
|
+
return this._addCheck({ kind: "date", message });
|
|
6289
|
+
}
|
|
6290
|
+
time(options) {
|
|
6291
|
+
return typeof options == "string" ? this._addCheck({
|
|
6292
|
+
kind: "time",
|
|
6293
|
+
precision: null,
|
|
6294
|
+
message: options
|
|
6295
|
+
}) : this._addCheck({
|
|
6296
|
+
kind: "time",
|
|
6297
|
+
precision: typeof options?.precision > "u" ? null : options?.precision,
|
|
6298
|
+
...errorUtil.errToObj(options?.message)
|
|
6299
|
+
});
|
|
6300
|
+
}
|
|
6301
|
+
duration(message) {
|
|
6302
|
+
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
6303
|
+
}
|
|
6304
|
+
regex(regex2, message) {
|
|
6305
|
+
return this._addCheck({
|
|
6306
|
+
kind: "regex",
|
|
6307
|
+
regex: regex2,
|
|
6308
|
+
...errorUtil.errToObj(message)
|
|
6309
|
+
});
|
|
6310
|
+
}
|
|
6311
|
+
includes(value, options) {
|
|
6312
|
+
return this._addCheck({
|
|
6313
|
+
kind: "includes",
|
|
6314
|
+
value,
|
|
6315
|
+
position: options?.position,
|
|
6316
|
+
...errorUtil.errToObj(options?.message)
|
|
6317
|
+
});
|
|
6318
|
+
}
|
|
6319
|
+
startsWith(value, message) {
|
|
6320
|
+
return this._addCheck({
|
|
6321
|
+
kind: "startsWith",
|
|
6322
|
+
value,
|
|
6323
|
+
...errorUtil.errToObj(message)
|
|
6324
|
+
});
|
|
6325
|
+
}
|
|
6326
|
+
endsWith(value, message) {
|
|
6327
|
+
return this._addCheck({
|
|
6328
|
+
kind: "endsWith",
|
|
6329
|
+
value,
|
|
6330
|
+
...errorUtil.errToObj(message)
|
|
6331
|
+
});
|
|
6332
|
+
}
|
|
6333
|
+
min(minLength, message) {
|
|
6334
|
+
return this._addCheck({
|
|
6335
|
+
kind: "min",
|
|
6336
|
+
value: minLength,
|
|
6337
|
+
...errorUtil.errToObj(message)
|
|
6338
|
+
});
|
|
6339
|
+
}
|
|
6340
|
+
max(maxLength, message) {
|
|
6341
|
+
return this._addCheck({
|
|
6342
|
+
kind: "max",
|
|
6343
|
+
value: maxLength,
|
|
6344
|
+
...errorUtil.errToObj(message)
|
|
6345
|
+
});
|
|
6346
|
+
}
|
|
6347
|
+
length(len, message) {
|
|
6348
|
+
return this._addCheck({
|
|
6349
|
+
kind: "length",
|
|
6350
|
+
value: len,
|
|
6351
|
+
...errorUtil.errToObj(message)
|
|
6352
|
+
});
|
|
6353
|
+
}
|
|
6354
|
+
/**
|
|
6355
|
+
* Equivalent to `.min(1)`
|
|
6356
|
+
*/
|
|
6357
|
+
nonempty(message) {
|
|
6358
|
+
return this.min(1, errorUtil.errToObj(message));
|
|
6359
|
+
}
|
|
6360
|
+
trim() {
|
|
6361
|
+
return new _ZodString({
|
|
6362
|
+
...this._def,
|
|
6363
|
+
checks: [...this._def.checks, { kind: "trim" }]
|
|
6364
|
+
});
|
|
6365
|
+
}
|
|
6366
|
+
toLowerCase() {
|
|
6367
|
+
return new _ZodString({
|
|
6368
|
+
...this._def,
|
|
6369
|
+
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
6370
|
+
});
|
|
6371
|
+
}
|
|
6372
|
+
toUpperCase() {
|
|
6373
|
+
return new _ZodString({
|
|
6374
|
+
...this._def,
|
|
6375
|
+
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
6376
|
+
});
|
|
6377
|
+
}
|
|
6378
|
+
get isDatetime() {
|
|
6379
|
+
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
6380
|
+
}
|
|
6381
|
+
get isDate() {
|
|
6382
|
+
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
6383
|
+
}
|
|
6384
|
+
get isTime() {
|
|
6385
|
+
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
6386
|
+
}
|
|
6387
|
+
get isDuration() {
|
|
6388
|
+
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
6389
|
+
}
|
|
6390
|
+
get isEmail() {
|
|
6391
|
+
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
6392
|
+
}
|
|
6393
|
+
get isURL() {
|
|
6394
|
+
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
6395
|
+
}
|
|
6396
|
+
get isEmoji() {
|
|
6397
|
+
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
6398
|
+
}
|
|
6399
|
+
get isUUID() {
|
|
6400
|
+
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
6401
|
+
}
|
|
6402
|
+
get isNANOID() {
|
|
6403
|
+
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
6404
|
+
}
|
|
6405
|
+
get isCUID() {
|
|
6406
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
6407
|
+
}
|
|
6408
|
+
get isCUID2() {
|
|
6409
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
6410
|
+
}
|
|
6411
|
+
get isULID() {
|
|
6412
|
+
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
6413
|
+
}
|
|
6414
|
+
get isIP() {
|
|
6415
|
+
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
6416
|
+
}
|
|
6417
|
+
get isCIDR() {
|
|
6418
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
6419
|
+
}
|
|
6420
|
+
get isBase64() {
|
|
6421
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
6422
|
+
}
|
|
6423
|
+
get isBase64url() {
|
|
6424
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
6425
|
+
}
|
|
6426
|
+
get minLength() {
|
|
6427
|
+
let min = null;
|
|
6428
|
+
for (let ch of this._def.checks)
|
|
6429
|
+
ch.kind === "min" && (min === null || ch.value > min) && (min = ch.value);
|
|
6430
|
+
return min;
|
|
6431
|
+
}
|
|
6432
|
+
get maxLength() {
|
|
6433
|
+
let max = null;
|
|
6434
|
+
for (let ch of this._def.checks)
|
|
6435
|
+
ch.kind === "max" && (max === null || ch.value < max) && (max = ch.value);
|
|
6436
|
+
return max;
|
|
6437
|
+
}
|
|
6438
|
+
};
|
|
6439
|
+
ZodString.create = (params) => new ZodString({
|
|
6440
|
+
checks: [],
|
|
6441
|
+
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
6442
|
+
coerce: params?.coerce ?? !1,
|
|
6443
|
+
...processCreateParams(params)
|
|
6444
|
+
});
|
|
6445
|
+
function floatSafeRemainder(val, step) {
|
|
6446
|
+
let valDecCount = (val.toString().split(".")[1] || "").length, stepDecCount = (step.toString().split(".")[1] || "").length, decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount, valInt = Number.parseInt(val.toFixed(decCount).replace(".", "")), stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
6447
|
+
return valInt % stepInt / 10 ** decCount;
|
|
6448
|
+
}
|
|
6449
|
+
var ZodNumber = class _ZodNumber extends ZodType {
|
|
6450
|
+
constructor() {
|
|
6451
|
+
super(...arguments), this.min = this.gte, this.max = this.lte, this.step = this.multipleOf;
|
|
6452
|
+
}
|
|
6453
|
+
_parse(input) {
|
|
6454
|
+
if (this._def.coerce && (input.data = Number(input.data)), this._getType(input) !== ZodParsedType.number) {
|
|
6455
|
+
let ctx2 = this._getOrReturnCtx(input);
|
|
6456
|
+
return addIssueToContext(ctx2, {
|
|
6457
|
+
code: ZodIssueCode.invalid_type,
|
|
6458
|
+
expected: ZodParsedType.number,
|
|
6459
|
+
received: ctx2.parsedType
|
|
6460
|
+
}), INVALID;
|
|
6461
|
+
}
|
|
6462
|
+
let ctx, status = new ParseStatus();
|
|
6463
|
+
for (let check of this._def.checks)
|
|
6464
|
+
check.kind === "int" ? util.isInteger(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6465
|
+
code: ZodIssueCode.invalid_type,
|
|
6466
|
+
expected: "integer",
|
|
6467
|
+
received: "float",
|
|
6468
|
+
message: check.message
|
|
6469
|
+
}), status.dirty()) : check.kind === "min" ? (check.inclusive ? input.data < check.value : input.data <= check.value) && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6470
|
+
code: ZodIssueCode.too_small,
|
|
6471
|
+
minimum: check.value,
|
|
6472
|
+
type: "number",
|
|
6473
|
+
inclusive: check.inclusive,
|
|
6474
|
+
exact: !1,
|
|
6475
|
+
message: check.message
|
|
6476
|
+
}), status.dirty()) : check.kind === "max" ? (check.inclusive ? input.data > check.value : input.data >= check.value) && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6477
|
+
code: ZodIssueCode.too_big,
|
|
6478
|
+
maximum: check.value,
|
|
6479
|
+
type: "number",
|
|
6480
|
+
inclusive: check.inclusive,
|
|
6481
|
+
exact: !1,
|
|
6482
|
+
message: check.message
|
|
6483
|
+
}), status.dirty()) : check.kind === "multipleOf" ? floatSafeRemainder(input.data, check.value) !== 0 && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6484
|
+
code: ZodIssueCode.not_multiple_of,
|
|
6485
|
+
multipleOf: check.value,
|
|
6486
|
+
message: check.message
|
|
6487
|
+
}), status.dirty()) : check.kind === "finite" ? Number.isFinite(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6488
|
+
code: ZodIssueCode.not_finite,
|
|
6489
|
+
message: check.message
|
|
6490
|
+
}), status.dirty()) : util.assertNever(check);
|
|
6491
|
+
return { status: status.value, value: input.data };
|
|
6492
|
+
}
|
|
6493
|
+
gte(value, message) {
|
|
6494
|
+
return this.setLimit("min", value, !0, errorUtil.toString(message));
|
|
6495
|
+
}
|
|
6496
|
+
gt(value, message) {
|
|
6497
|
+
return this.setLimit("min", value, !1, errorUtil.toString(message));
|
|
6498
|
+
}
|
|
6499
|
+
lte(value, message) {
|
|
6500
|
+
return this.setLimit("max", value, !0, errorUtil.toString(message));
|
|
6501
|
+
}
|
|
6502
|
+
lt(value, message) {
|
|
6503
|
+
return this.setLimit("max", value, !1, errorUtil.toString(message));
|
|
6504
|
+
}
|
|
6505
|
+
setLimit(kind, value, inclusive, message) {
|
|
6506
|
+
return new _ZodNumber({
|
|
6507
|
+
...this._def,
|
|
6508
|
+
checks: [
|
|
6509
|
+
...this._def.checks,
|
|
6510
|
+
{
|
|
6511
|
+
kind,
|
|
6512
|
+
value,
|
|
6513
|
+
inclusive,
|
|
6514
|
+
message: errorUtil.toString(message)
|
|
6515
|
+
}
|
|
6516
|
+
]
|
|
6517
|
+
});
|
|
6518
|
+
}
|
|
6519
|
+
_addCheck(check) {
|
|
6520
|
+
return new _ZodNumber({
|
|
6521
|
+
...this._def,
|
|
6522
|
+
checks: [...this._def.checks, check]
|
|
6523
|
+
});
|
|
6524
|
+
}
|
|
6525
|
+
int(message) {
|
|
6526
|
+
return this._addCheck({
|
|
6527
|
+
kind: "int",
|
|
6528
|
+
message: errorUtil.toString(message)
|
|
6529
|
+
});
|
|
6530
|
+
}
|
|
6531
|
+
positive(message) {
|
|
6532
|
+
return this._addCheck({
|
|
6533
|
+
kind: "min",
|
|
6534
|
+
value: 0,
|
|
6535
|
+
inclusive: !1,
|
|
6536
|
+
message: errorUtil.toString(message)
|
|
6537
|
+
});
|
|
6538
|
+
}
|
|
6539
|
+
negative(message) {
|
|
6540
|
+
return this._addCheck({
|
|
6541
|
+
kind: "max",
|
|
6542
|
+
value: 0,
|
|
6543
|
+
inclusive: !1,
|
|
6544
|
+
message: errorUtil.toString(message)
|
|
6545
|
+
});
|
|
6546
|
+
}
|
|
6547
|
+
nonpositive(message) {
|
|
6548
|
+
return this._addCheck({
|
|
6549
|
+
kind: "max",
|
|
6550
|
+
value: 0,
|
|
6551
|
+
inclusive: !0,
|
|
6552
|
+
message: errorUtil.toString(message)
|
|
6553
|
+
});
|
|
6554
|
+
}
|
|
6555
|
+
nonnegative(message) {
|
|
6556
|
+
return this._addCheck({
|
|
6557
|
+
kind: "min",
|
|
6558
|
+
value: 0,
|
|
6559
|
+
inclusive: !0,
|
|
6560
|
+
message: errorUtil.toString(message)
|
|
6561
|
+
});
|
|
6562
|
+
}
|
|
6563
|
+
multipleOf(value, message) {
|
|
6564
|
+
return this._addCheck({
|
|
6565
|
+
kind: "multipleOf",
|
|
6566
|
+
value,
|
|
6567
|
+
message: errorUtil.toString(message)
|
|
6568
|
+
});
|
|
6569
|
+
}
|
|
6570
|
+
finite(message) {
|
|
6571
|
+
return this._addCheck({
|
|
6572
|
+
kind: "finite",
|
|
6573
|
+
message: errorUtil.toString(message)
|
|
6574
|
+
});
|
|
6575
|
+
}
|
|
6576
|
+
safe(message) {
|
|
6577
|
+
return this._addCheck({
|
|
6578
|
+
kind: "min",
|
|
6579
|
+
inclusive: !0,
|
|
6580
|
+
value: Number.MIN_SAFE_INTEGER,
|
|
6581
|
+
message: errorUtil.toString(message)
|
|
6582
|
+
})._addCheck({
|
|
6583
|
+
kind: "max",
|
|
6584
|
+
inclusive: !0,
|
|
6585
|
+
value: Number.MAX_SAFE_INTEGER,
|
|
6586
|
+
message: errorUtil.toString(message)
|
|
6587
|
+
});
|
|
6588
|
+
}
|
|
6589
|
+
get minValue() {
|
|
6590
|
+
let min = null;
|
|
6591
|
+
for (let ch of this._def.checks)
|
|
6592
|
+
ch.kind === "min" && (min === null || ch.value > min) && (min = ch.value);
|
|
6593
|
+
return min;
|
|
6594
|
+
}
|
|
6595
|
+
get maxValue() {
|
|
6596
|
+
let max = null;
|
|
6597
|
+
for (let ch of this._def.checks)
|
|
6598
|
+
ch.kind === "max" && (max === null || ch.value < max) && (max = ch.value);
|
|
6599
|
+
return max;
|
|
6600
|
+
}
|
|
6601
|
+
get isInt() {
|
|
6602
|
+
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
6603
|
+
}
|
|
6604
|
+
get isFinite() {
|
|
6605
|
+
let max = null, min = null;
|
|
6606
|
+
for (let ch of this._def.checks) {
|
|
6607
|
+
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf")
|
|
6608
|
+
return !0;
|
|
6609
|
+
ch.kind === "min" ? (min === null || ch.value > min) && (min = ch.value) : ch.kind === "max" && (max === null || ch.value < max) && (max = ch.value);
|
|
6610
|
+
}
|
|
6611
|
+
return Number.isFinite(min) && Number.isFinite(max);
|
|
6612
|
+
}
|
|
6613
|
+
};
|
|
6614
|
+
ZodNumber.create = (params) => new ZodNumber({
|
|
6615
|
+
checks: [],
|
|
6616
|
+
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
6617
|
+
coerce: params?.coerce || !1,
|
|
6618
|
+
...processCreateParams(params)
|
|
6619
|
+
});
|
|
6620
|
+
var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
6621
|
+
constructor() {
|
|
6622
|
+
super(...arguments), this.min = this.gte, this.max = this.lte;
|
|
6623
|
+
}
|
|
6624
|
+
_parse(input) {
|
|
6625
|
+
if (this._def.coerce)
|
|
6626
|
+
try {
|
|
6627
|
+
input.data = BigInt(input.data);
|
|
6628
|
+
} catch {
|
|
6629
|
+
return this._getInvalidInput(input);
|
|
6630
|
+
}
|
|
6631
|
+
if (this._getType(input) !== ZodParsedType.bigint)
|
|
6632
|
+
return this._getInvalidInput(input);
|
|
6633
|
+
let ctx, status = new ParseStatus();
|
|
6634
|
+
for (let check of this._def.checks)
|
|
6635
|
+
check.kind === "min" ? (check.inclusive ? input.data < check.value : input.data <= check.value) && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6636
|
+
code: ZodIssueCode.too_small,
|
|
6637
|
+
type: "bigint",
|
|
6638
|
+
minimum: check.value,
|
|
6639
|
+
inclusive: check.inclusive,
|
|
6640
|
+
message: check.message
|
|
6641
|
+
}), status.dirty()) : check.kind === "max" ? (check.inclusive ? input.data > check.value : input.data >= check.value) && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6642
|
+
code: ZodIssueCode.too_big,
|
|
6643
|
+
type: "bigint",
|
|
6644
|
+
maximum: check.value,
|
|
6645
|
+
inclusive: check.inclusive,
|
|
6646
|
+
message: check.message
|
|
6647
|
+
}), status.dirty()) : check.kind === "multipleOf" ? input.data % check.value !== BigInt(0) && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6648
|
+
code: ZodIssueCode.not_multiple_of,
|
|
6649
|
+
multipleOf: check.value,
|
|
6650
|
+
message: check.message
|
|
6651
|
+
}), status.dirty()) : util.assertNever(check);
|
|
6652
|
+
return { status: status.value, value: input.data };
|
|
6653
|
+
}
|
|
6654
|
+
_getInvalidInput(input) {
|
|
6655
|
+
let ctx = this._getOrReturnCtx(input);
|
|
6656
|
+
return addIssueToContext(ctx, {
|
|
6657
|
+
code: ZodIssueCode.invalid_type,
|
|
6658
|
+
expected: ZodParsedType.bigint,
|
|
6659
|
+
received: ctx.parsedType
|
|
6660
|
+
}), INVALID;
|
|
6661
|
+
}
|
|
6662
|
+
gte(value, message) {
|
|
6663
|
+
return this.setLimit("min", value, !0, errorUtil.toString(message));
|
|
6664
|
+
}
|
|
6665
|
+
gt(value, message) {
|
|
6666
|
+
return this.setLimit("min", value, !1, errorUtil.toString(message));
|
|
6667
|
+
}
|
|
6668
|
+
lte(value, message) {
|
|
6669
|
+
return this.setLimit("max", value, !0, errorUtil.toString(message));
|
|
6670
|
+
}
|
|
6671
|
+
lt(value, message) {
|
|
6672
|
+
return this.setLimit("max", value, !1, errorUtil.toString(message));
|
|
6673
|
+
}
|
|
6674
|
+
setLimit(kind, value, inclusive, message) {
|
|
6675
|
+
return new _ZodBigInt({
|
|
6676
|
+
...this._def,
|
|
6677
|
+
checks: [
|
|
6678
|
+
...this._def.checks,
|
|
6679
|
+
{
|
|
6680
|
+
kind,
|
|
6681
|
+
value,
|
|
6682
|
+
inclusive,
|
|
6683
|
+
message: errorUtil.toString(message)
|
|
6684
|
+
}
|
|
6685
|
+
]
|
|
6686
|
+
});
|
|
6687
|
+
}
|
|
6688
|
+
_addCheck(check) {
|
|
6689
|
+
return new _ZodBigInt({
|
|
6690
|
+
...this._def,
|
|
6691
|
+
checks: [...this._def.checks, check]
|
|
6692
|
+
});
|
|
6693
|
+
}
|
|
6694
|
+
positive(message) {
|
|
6695
|
+
return this._addCheck({
|
|
6696
|
+
kind: "min",
|
|
6697
|
+
value: BigInt(0),
|
|
6698
|
+
inclusive: !1,
|
|
6699
|
+
message: errorUtil.toString(message)
|
|
6700
|
+
});
|
|
6701
|
+
}
|
|
6702
|
+
negative(message) {
|
|
6703
|
+
return this._addCheck({
|
|
6704
|
+
kind: "max",
|
|
6705
|
+
value: BigInt(0),
|
|
6706
|
+
inclusive: !1,
|
|
6707
|
+
message: errorUtil.toString(message)
|
|
6708
|
+
});
|
|
6709
|
+
}
|
|
6710
|
+
nonpositive(message) {
|
|
6711
|
+
return this._addCheck({
|
|
6712
|
+
kind: "max",
|
|
6713
|
+
value: BigInt(0),
|
|
6714
|
+
inclusive: !0,
|
|
6715
|
+
message: errorUtil.toString(message)
|
|
6716
|
+
});
|
|
6717
|
+
}
|
|
6718
|
+
nonnegative(message) {
|
|
6719
|
+
return this._addCheck({
|
|
6720
|
+
kind: "min",
|
|
6721
|
+
value: BigInt(0),
|
|
6722
|
+
inclusive: !0,
|
|
6723
|
+
message: errorUtil.toString(message)
|
|
6724
|
+
});
|
|
6725
|
+
}
|
|
6726
|
+
multipleOf(value, message) {
|
|
6727
|
+
return this._addCheck({
|
|
6728
|
+
kind: "multipleOf",
|
|
6729
|
+
value,
|
|
6730
|
+
message: errorUtil.toString(message)
|
|
6731
|
+
});
|
|
6732
|
+
}
|
|
6733
|
+
get minValue() {
|
|
6734
|
+
let min = null;
|
|
6735
|
+
for (let ch of this._def.checks)
|
|
6736
|
+
ch.kind === "min" && (min === null || ch.value > min) && (min = ch.value);
|
|
6737
|
+
return min;
|
|
6738
|
+
}
|
|
6739
|
+
get maxValue() {
|
|
6740
|
+
let max = null;
|
|
6741
|
+
for (let ch of this._def.checks)
|
|
6742
|
+
ch.kind === "max" && (max === null || ch.value < max) && (max = ch.value);
|
|
6743
|
+
return max;
|
|
6744
|
+
}
|
|
6745
|
+
};
|
|
6746
|
+
ZodBigInt.create = (params) => new ZodBigInt({
|
|
6747
|
+
checks: [],
|
|
6748
|
+
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
6749
|
+
coerce: params?.coerce ?? !1,
|
|
6750
|
+
...processCreateParams(params)
|
|
6751
|
+
});
|
|
6752
|
+
var ZodBoolean = class extends ZodType {
|
|
6753
|
+
_parse(input) {
|
|
6754
|
+
if (this._def.coerce && (input.data = !!input.data), this._getType(input) !== ZodParsedType.boolean) {
|
|
6755
|
+
let ctx = this._getOrReturnCtx(input);
|
|
6756
|
+
return addIssueToContext(ctx, {
|
|
6757
|
+
code: ZodIssueCode.invalid_type,
|
|
6758
|
+
expected: ZodParsedType.boolean,
|
|
6759
|
+
received: ctx.parsedType
|
|
6760
|
+
}), INVALID;
|
|
6761
|
+
}
|
|
6762
|
+
return OK(input.data);
|
|
6763
|
+
}
|
|
6764
|
+
};
|
|
6765
|
+
ZodBoolean.create = (params) => new ZodBoolean({
|
|
6766
|
+
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
6767
|
+
coerce: params?.coerce || !1,
|
|
6768
|
+
...processCreateParams(params)
|
|
6769
|
+
});
|
|
6770
|
+
var ZodDate = class _ZodDate extends ZodType {
|
|
6771
|
+
_parse(input) {
|
|
6772
|
+
if (this._def.coerce && (input.data = new Date(input.data)), this._getType(input) !== ZodParsedType.date) {
|
|
6773
|
+
let ctx2 = this._getOrReturnCtx(input);
|
|
6774
|
+
return addIssueToContext(ctx2, {
|
|
6775
|
+
code: ZodIssueCode.invalid_type,
|
|
6776
|
+
expected: ZodParsedType.date,
|
|
6777
|
+
received: ctx2.parsedType
|
|
6778
|
+
}), INVALID;
|
|
6779
|
+
}
|
|
6780
|
+
if (Number.isNaN(input.data.getTime())) {
|
|
6781
|
+
let ctx2 = this._getOrReturnCtx(input);
|
|
6782
|
+
return addIssueToContext(ctx2, {
|
|
6783
|
+
code: ZodIssueCode.invalid_date
|
|
6784
|
+
}), INVALID;
|
|
6785
|
+
}
|
|
6786
|
+
let status = new ParseStatus(), ctx;
|
|
6787
|
+
for (let check of this._def.checks)
|
|
6788
|
+
check.kind === "min" ? input.data.getTime() < check.value && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6789
|
+
code: ZodIssueCode.too_small,
|
|
6790
|
+
message: check.message,
|
|
6791
|
+
inclusive: !0,
|
|
6792
|
+
exact: !1,
|
|
6793
|
+
minimum: check.value,
|
|
6794
|
+
type: "date"
|
|
6795
|
+
}), status.dirty()) : check.kind === "max" ? input.data.getTime() > check.value && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
6796
|
+
code: ZodIssueCode.too_big,
|
|
6797
|
+
message: check.message,
|
|
6798
|
+
inclusive: !0,
|
|
6799
|
+
exact: !1,
|
|
6800
|
+
maximum: check.value,
|
|
6801
|
+
type: "date"
|
|
6802
|
+
}), status.dirty()) : util.assertNever(check);
|
|
6803
|
+
return {
|
|
6804
|
+
status: status.value,
|
|
6805
|
+
value: new Date(input.data.getTime())
|
|
6806
|
+
};
|
|
6807
|
+
}
|
|
6808
|
+
_addCheck(check) {
|
|
6809
|
+
return new _ZodDate({
|
|
6810
|
+
...this._def,
|
|
6811
|
+
checks: [...this._def.checks, check]
|
|
6812
|
+
});
|
|
6813
|
+
}
|
|
6814
|
+
min(minDate, message) {
|
|
6815
|
+
return this._addCheck({
|
|
6816
|
+
kind: "min",
|
|
6817
|
+
value: minDate.getTime(),
|
|
6818
|
+
message: errorUtil.toString(message)
|
|
6819
|
+
});
|
|
6820
|
+
}
|
|
6821
|
+
max(maxDate, message) {
|
|
6822
|
+
return this._addCheck({
|
|
6823
|
+
kind: "max",
|
|
6824
|
+
value: maxDate.getTime(),
|
|
6825
|
+
message: errorUtil.toString(message)
|
|
6826
|
+
});
|
|
6827
|
+
}
|
|
6828
|
+
get minDate() {
|
|
6829
|
+
let min = null;
|
|
6830
|
+
for (let ch of this._def.checks)
|
|
6831
|
+
ch.kind === "min" && (min === null || ch.value > min) && (min = ch.value);
|
|
6832
|
+
return min != null ? new Date(min) : null;
|
|
6833
|
+
}
|
|
6834
|
+
get maxDate() {
|
|
6835
|
+
let max = null;
|
|
6836
|
+
for (let ch of this._def.checks)
|
|
6837
|
+
ch.kind === "max" && (max === null || ch.value < max) && (max = ch.value);
|
|
6838
|
+
return max != null ? new Date(max) : null;
|
|
6839
|
+
}
|
|
6840
|
+
};
|
|
6841
|
+
ZodDate.create = (params) => new ZodDate({
|
|
6842
|
+
checks: [],
|
|
6843
|
+
coerce: params?.coerce || !1,
|
|
6844
|
+
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
6845
|
+
...processCreateParams(params)
|
|
6846
|
+
});
|
|
6847
|
+
var ZodSymbol = class extends ZodType {
|
|
6848
|
+
_parse(input) {
|
|
6849
|
+
if (this._getType(input) !== ZodParsedType.symbol) {
|
|
6850
|
+
let ctx = this._getOrReturnCtx(input);
|
|
6851
|
+
return addIssueToContext(ctx, {
|
|
6852
|
+
code: ZodIssueCode.invalid_type,
|
|
6853
|
+
expected: ZodParsedType.symbol,
|
|
6854
|
+
received: ctx.parsedType
|
|
6855
|
+
}), INVALID;
|
|
6856
|
+
}
|
|
6857
|
+
return OK(input.data);
|
|
6858
|
+
}
|
|
6859
|
+
};
|
|
6860
|
+
ZodSymbol.create = (params) => new ZodSymbol({
|
|
6861
|
+
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
6862
|
+
...processCreateParams(params)
|
|
6863
|
+
});
|
|
6864
|
+
var ZodUndefined = class extends ZodType {
|
|
6865
|
+
_parse(input) {
|
|
6866
|
+
if (this._getType(input) !== ZodParsedType.undefined) {
|
|
6867
|
+
let ctx = this._getOrReturnCtx(input);
|
|
6868
|
+
return addIssueToContext(ctx, {
|
|
6869
|
+
code: ZodIssueCode.invalid_type,
|
|
6870
|
+
expected: ZodParsedType.undefined,
|
|
6871
|
+
received: ctx.parsedType
|
|
6872
|
+
}), INVALID;
|
|
6873
|
+
}
|
|
6874
|
+
return OK(input.data);
|
|
6875
|
+
}
|
|
6876
|
+
};
|
|
6877
|
+
ZodUndefined.create = (params) => new ZodUndefined({
|
|
6878
|
+
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
6879
|
+
...processCreateParams(params)
|
|
6880
|
+
});
|
|
6881
|
+
var ZodNull = class extends ZodType {
|
|
6882
|
+
_parse(input) {
|
|
6883
|
+
if (this._getType(input) !== ZodParsedType.null) {
|
|
6884
|
+
let ctx = this._getOrReturnCtx(input);
|
|
6885
|
+
return addIssueToContext(ctx, {
|
|
6886
|
+
code: ZodIssueCode.invalid_type,
|
|
6887
|
+
expected: ZodParsedType.null,
|
|
6888
|
+
received: ctx.parsedType
|
|
6889
|
+
}), INVALID;
|
|
6890
|
+
}
|
|
6891
|
+
return OK(input.data);
|
|
6892
|
+
}
|
|
6893
|
+
};
|
|
6894
|
+
ZodNull.create = (params) => new ZodNull({
|
|
6895
|
+
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
6896
|
+
...processCreateParams(params)
|
|
6897
|
+
});
|
|
6898
|
+
var ZodAny = class extends ZodType {
|
|
6899
|
+
constructor() {
|
|
6900
|
+
super(...arguments), this._any = !0;
|
|
6901
|
+
}
|
|
6902
|
+
_parse(input) {
|
|
6903
|
+
return OK(input.data);
|
|
6904
|
+
}
|
|
6905
|
+
};
|
|
6906
|
+
ZodAny.create = (params) => new ZodAny({
|
|
6907
|
+
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
6908
|
+
...processCreateParams(params)
|
|
6909
|
+
});
|
|
6910
|
+
var ZodUnknown = class extends ZodType {
|
|
6911
|
+
constructor() {
|
|
6912
|
+
super(...arguments), this._unknown = !0;
|
|
6913
|
+
}
|
|
6914
|
+
_parse(input) {
|
|
6915
|
+
return OK(input.data);
|
|
6916
|
+
}
|
|
6917
|
+
};
|
|
6918
|
+
ZodUnknown.create = (params) => new ZodUnknown({
|
|
6919
|
+
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
6920
|
+
...processCreateParams(params)
|
|
6921
|
+
});
|
|
6922
|
+
var ZodNever = class extends ZodType {
|
|
6923
|
+
_parse(input) {
|
|
6924
|
+
let ctx = this._getOrReturnCtx(input);
|
|
6925
|
+
return addIssueToContext(ctx, {
|
|
6926
|
+
code: ZodIssueCode.invalid_type,
|
|
6927
|
+
expected: ZodParsedType.never,
|
|
6928
|
+
received: ctx.parsedType
|
|
6929
|
+
}), INVALID;
|
|
6930
|
+
}
|
|
6931
|
+
};
|
|
6932
|
+
ZodNever.create = (params) => new ZodNever({
|
|
6933
|
+
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
6934
|
+
...processCreateParams(params)
|
|
6935
|
+
});
|
|
6936
|
+
var ZodVoid = class extends ZodType {
|
|
6937
|
+
_parse(input) {
|
|
6938
|
+
if (this._getType(input) !== ZodParsedType.undefined) {
|
|
6939
|
+
let ctx = this._getOrReturnCtx(input);
|
|
6940
|
+
return addIssueToContext(ctx, {
|
|
6941
|
+
code: ZodIssueCode.invalid_type,
|
|
6942
|
+
expected: ZodParsedType.void,
|
|
6943
|
+
received: ctx.parsedType
|
|
6944
|
+
}), INVALID;
|
|
6945
|
+
}
|
|
6946
|
+
return OK(input.data);
|
|
6947
|
+
}
|
|
6948
|
+
};
|
|
6949
|
+
ZodVoid.create = (params) => new ZodVoid({
|
|
6950
|
+
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
6951
|
+
...processCreateParams(params)
|
|
6952
|
+
});
|
|
6953
|
+
var ZodArray = class _ZodArray extends ZodType {
|
|
6954
|
+
_parse(input) {
|
|
6955
|
+
let { ctx, status } = this._processInputParams(input), def = this._def;
|
|
6956
|
+
if (ctx.parsedType !== ZodParsedType.array)
|
|
6957
|
+
return addIssueToContext(ctx, {
|
|
6958
|
+
code: ZodIssueCode.invalid_type,
|
|
6959
|
+
expected: ZodParsedType.array,
|
|
6960
|
+
received: ctx.parsedType
|
|
6961
|
+
}), INVALID;
|
|
6962
|
+
if (def.exactLength !== null) {
|
|
6963
|
+
let tooBig = ctx.data.length > def.exactLength.value, tooSmall = ctx.data.length < def.exactLength.value;
|
|
6964
|
+
(tooBig || tooSmall) && (addIssueToContext(ctx, {
|
|
6965
|
+
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
6966
|
+
minimum: tooSmall ? def.exactLength.value : void 0,
|
|
6967
|
+
maximum: tooBig ? def.exactLength.value : void 0,
|
|
6968
|
+
type: "array",
|
|
6969
|
+
inclusive: !0,
|
|
6970
|
+
exact: !0,
|
|
6971
|
+
message: def.exactLength.message
|
|
6972
|
+
}), status.dirty());
|
|
6973
|
+
}
|
|
6974
|
+
if (def.minLength !== null && ctx.data.length < def.minLength.value && (addIssueToContext(ctx, {
|
|
6975
|
+
code: ZodIssueCode.too_small,
|
|
6976
|
+
minimum: def.minLength.value,
|
|
6977
|
+
type: "array",
|
|
6978
|
+
inclusive: !0,
|
|
6979
|
+
exact: !1,
|
|
6980
|
+
message: def.minLength.message
|
|
6981
|
+
}), status.dirty()), def.maxLength !== null && ctx.data.length > def.maxLength.value && (addIssueToContext(ctx, {
|
|
6982
|
+
code: ZodIssueCode.too_big,
|
|
6983
|
+
maximum: def.maxLength.value,
|
|
6984
|
+
type: "array",
|
|
6985
|
+
inclusive: !0,
|
|
6986
|
+
exact: !1,
|
|
6987
|
+
message: def.maxLength.message
|
|
6988
|
+
}), status.dirty()), ctx.common.async)
|
|
6989
|
+
return Promise.all([...ctx.data].map((item, i) => def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i)))).then((result2) => ParseStatus.mergeArray(status, result2));
|
|
6990
|
+
let result = [...ctx.data].map((item, i) => def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
6991
|
+
return ParseStatus.mergeArray(status, result);
|
|
6992
|
+
}
|
|
6993
|
+
get element() {
|
|
6994
|
+
return this._def.type;
|
|
6995
|
+
}
|
|
6996
|
+
min(minLength, message) {
|
|
6997
|
+
return new _ZodArray({
|
|
6998
|
+
...this._def,
|
|
6999
|
+
minLength: { value: minLength, message: errorUtil.toString(message) }
|
|
7000
|
+
});
|
|
7001
|
+
}
|
|
7002
|
+
max(maxLength, message) {
|
|
7003
|
+
return new _ZodArray({
|
|
7004
|
+
...this._def,
|
|
7005
|
+
maxLength: { value: maxLength, message: errorUtil.toString(message) }
|
|
7006
|
+
});
|
|
7007
|
+
}
|
|
7008
|
+
length(len, message) {
|
|
7009
|
+
return new _ZodArray({
|
|
7010
|
+
...this._def,
|
|
7011
|
+
exactLength: { value: len, message: errorUtil.toString(message) }
|
|
7012
|
+
});
|
|
7013
|
+
}
|
|
7014
|
+
nonempty(message) {
|
|
7015
|
+
return this.min(1, message);
|
|
7016
|
+
}
|
|
7017
|
+
};
|
|
7018
|
+
ZodArray.create = (schema, params) => new ZodArray({
|
|
7019
|
+
type: schema,
|
|
7020
|
+
minLength: null,
|
|
7021
|
+
maxLength: null,
|
|
7022
|
+
exactLength: null,
|
|
7023
|
+
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
7024
|
+
...processCreateParams(params)
|
|
7025
|
+
});
|
|
7026
|
+
function deepPartialify(schema) {
|
|
7027
|
+
if (schema instanceof ZodObject) {
|
|
7028
|
+
let newShape = {};
|
|
7029
|
+
for (let key in schema.shape) {
|
|
7030
|
+
let fieldSchema = schema.shape[key];
|
|
7031
|
+
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
7032
|
+
}
|
|
7033
|
+
return new ZodObject({
|
|
7034
|
+
...schema._def,
|
|
7035
|
+
shape: () => newShape
|
|
7036
|
+
});
|
|
7037
|
+
} else return schema instanceof ZodArray ? new ZodArray({
|
|
7038
|
+
...schema._def,
|
|
7039
|
+
type: deepPartialify(schema.element)
|
|
7040
|
+
}) : schema instanceof ZodOptional ? ZodOptional.create(deepPartialify(schema.unwrap())) : schema instanceof ZodNullable ? ZodNullable.create(deepPartialify(schema.unwrap())) : schema instanceof ZodTuple ? ZodTuple.create(schema.items.map((item) => deepPartialify(item))) : schema;
|
|
7041
|
+
}
|
|
7042
|
+
var ZodObject = class _ZodObject extends ZodType {
|
|
7043
|
+
constructor() {
|
|
7044
|
+
super(...arguments), this._cached = null, this.nonstrict = this.passthrough, this.augment = this.extend;
|
|
7045
|
+
}
|
|
7046
|
+
_getCached() {
|
|
7047
|
+
if (this._cached !== null)
|
|
7048
|
+
return this._cached;
|
|
7049
|
+
let shape = this._def.shape(), keys = util.objectKeys(shape);
|
|
7050
|
+
return this._cached = { shape, keys }, this._cached;
|
|
7051
|
+
}
|
|
7052
|
+
_parse(input) {
|
|
7053
|
+
if (this._getType(input) !== ZodParsedType.object) {
|
|
7054
|
+
let ctx2 = this._getOrReturnCtx(input);
|
|
7055
|
+
return addIssueToContext(ctx2, {
|
|
7056
|
+
code: ZodIssueCode.invalid_type,
|
|
7057
|
+
expected: ZodParsedType.object,
|
|
7058
|
+
received: ctx2.parsedType
|
|
7059
|
+
}), INVALID;
|
|
7060
|
+
}
|
|
7061
|
+
let { status, ctx } = this._processInputParams(input), { shape, keys: shapeKeys } = this._getCached(), extraKeys = [];
|
|
7062
|
+
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip"))
|
|
7063
|
+
for (let key in ctx.data)
|
|
7064
|
+
shapeKeys.includes(key) || extraKeys.push(key);
|
|
7065
|
+
let pairs = [];
|
|
7066
|
+
for (let key of shapeKeys) {
|
|
7067
|
+
let keyValidator = shape[key], value = ctx.data[key];
|
|
7068
|
+
pairs.push({
|
|
7069
|
+
key: { status: "valid", value: key },
|
|
7070
|
+
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
7071
|
+
alwaysSet: key in ctx.data
|
|
7072
|
+
});
|
|
7073
|
+
}
|
|
7074
|
+
if (this._def.catchall instanceof ZodNever) {
|
|
7075
|
+
let unknownKeys = this._def.unknownKeys;
|
|
7076
|
+
if (unknownKeys === "passthrough")
|
|
7077
|
+
for (let key of extraKeys)
|
|
7078
|
+
pairs.push({
|
|
7079
|
+
key: { status: "valid", value: key },
|
|
7080
|
+
value: { status: "valid", value: ctx.data[key] }
|
|
7081
|
+
});
|
|
7082
|
+
else if (unknownKeys === "strict")
|
|
7083
|
+
extraKeys.length > 0 && (addIssueToContext(ctx, {
|
|
7084
|
+
code: ZodIssueCode.unrecognized_keys,
|
|
7085
|
+
keys: extraKeys
|
|
7086
|
+
}), status.dirty());
|
|
7087
|
+
else if (unknownKeys !== "strip")
|
|
7088
|
+
throw new Error("Internal ZodObject error: invalid unknownKeys value.");
|
|
7089
|
+
} else {
|
|
7090
|
+
let catchall = this._def.catchall;
|
|
7091
|
+
for (let key of extraKeys) {
|
|
7092
|
+
let value = ctx.data[key];
|
|
7093
|
+
pairs.push({
|
|
7094
|
+
key: { status: "valid", value: key },
|
|
7095
|
+
value: catchall._parse(
|
|
7096
|
+
new ParseInputLazyPath(ctx, value, ctx.path, key)
|
|
7097
|
+
//, ctx.child(key), value, getParsedType(value)
|
|
7098
|
+
),
|
|
7099
|
+
alwaysSet: key in ctx.data
|
|
7100
|
+
});
|
|
7101
|
+
}
|
|
7102
|
+
}
|
|
7103
|
+
return ctx.common.async ? Promise.resolve().then(async () => {
|
|
7104
|
+
let syncPairs = [];
|
|
7105
|
+
for (let pair of pairs) {
|
|
7106
|
+
let key = await pair.key, value = await pair.value;
|
|
7107
|
+
syncPairs.push({
|
|
7108
|
+
key,
|
|
7109
|
+
value,
|
|
7110
|
+
alwaysSet: pair.alwaysSet
|
|
7111
|
+
});
|
|
7112
|
+
}
|
|
7113
|
+
return syncPairs;
|
|
7114
|
+
}).then((syncPairs) => ParseStatus.mergeObjectSync(status, syncPairs)) : ParseStatus.mergeObjectSync(status, pairs);
|
|
7115
|
+
}
|
|
7116
|
+
get shape() {
|
|
7117
|
+
return this._def.shape();
|
|
7118
|
+
}
|
|
7119
|
+
strict(message) {
|
|
7120
|
+
return errorUtil.errToObj, new _ZodObject({
|
|
7121
|
+
...this._def,
|
|
7122
|
+
unknownKeys: "strict",
|
|
7123
|
+
...message !== void 0 ? {
|
|
7124
|
+
errorMap: (issue, ctx) => {
|
|
7125
|
+
let defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
|
7126
|
+
return issue.code === "unrecognized_keys" ? {
|
|
7127
|
+
message: errorUtil.errToObj(message).message ?? defaultError
|
|
7128
|
+
} : {
|
|
7129
|
+
message: defaultError
|
|
7130
|
+
};
|
|
7131
|
+
}
|
|
7132
|
+
} : {}
|
|
7133
|
+
});
|
|
7134
|
+
}
|
|
7135
|
+
strip() {
|
|
7136
|
+
return new _ZodObject({
|
|
7137
|
+
...this._def,
|
|
7138
|
+
unknownKeys: "strip"
|
|
7139
|
+
});
|
|
7140
|
+
}
|
|
7141
|
+
passthrough() {
|
|
7142
|
+
return new _ZodObject({
|
|
7143
|
+
...this._def,
|
|
7144
|
+
unknownKeys: "passthrough"
|
|
7145
|
+
});
|
|
7146
|
+
}
|
|
7147
|
+
// const AugmentFactory =
|
|
7148
|
+
// <Def extends ZodObjectDef>(def: Def) =>
|
|
7149
|
+
// <Augmentation extends ZodRawShape>(
|
|
7150
|
+
// augmentation: Augmentation
|
|
7151
|
+
// ): ZodObject<
|
|
7152
|
+
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
7153
|
+
// Def["unknownKeys"],
|
|
7154
|
+
// Def["catchall"]
|
|
7155
|
+
// > => {
|
|
7156
|
+
// return new ZodObject({
|
|
7157
|
+
// ...def,
|
|
7158
|
+
// shape: () => ({
|
|
7159
|
+
// ...def.shape(),
|
|
7160
|
+
// ...augmentation,
|
|
7161
|
+
// }),
|
|
7162
|
+
// }) as any;
|
|
7163
|
+
// };
|
|
7164
|
+
extend(augmentation) {
|
|
7165
|
+
return new _ZodObject({
|
|
7166
|
+
...this._def,
|
|
7167
|
+
shape: () => ({
|
|
7168
|
+
...this._def.shape(),
|
|
7169
|
+
...augmentation
|
|
7170
|
+
})
|
|
7171
|
+
});
|
|
7172
|
+
}
|
|
7173
|
+
/**
|
|
7174
|
+
* Prior to zod@1.0.12 there was a bug in the
|
|
7175
|
+
* inferred type of merged objects. Please
|
|
7176
|
+
* upgrade if you are experiencing issues.
|
|
7177
|
+
*/
|
|
7178
|
+
merge(merging) {
|
|
7179
|
+
return new _ZodObject({
|
|
7180
|
+
unknownKeys: merging._def.unknownKeys,
|
|
7181
|
+
catchall: merging._def.catchall,
|
|
7182
|
+
shape: () => ({
|
|
7183
|
+
...this._def.shape(),
|
|
7184
|
+
...merging._def.shape()
|
|
7185
|
+
}),
|
|
7186
|
+
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
7187
|
+
});
|
|
7188
|
+
}
|
|
7189
|
+
// merge<
|
|
7190
|
+
// Incoming extends AnyZodObject,
|
|
7191
|
+
// Augmentation extends Incoming["shape"],
|
|
7192
|
+
// NewOutput extends {
|
|
7193
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
7194
|
+
// ? Augmentation[k]["_output"]
|
|
7195
|
+
// : k extends keyof Output
|
|
7196
|
+
// ? Output[k]
|
|
7197
|
+
// : never;
|
|
7198
|
+
// },
|
|
7199
|
+
// NewInput extends {
|
|
7200
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
7201
|
+
// ? Augmentation[k]["_input"]
|
|
7202
|
+
// : k extends keyof Input
|
|
7203
|
+
// ? Input[k]
|
|
7204
|
+
// : never;
|
|
7205
|
+
// }
|
|
7206
|
+
// >(
|
|
7207
|
+
// merging: Incoming
|
|
7208
|
+
// ): ZodObject<
|
|
7209
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
7210
|
+
// Incoming["_def"]["unknownKeys"],
|
|
7211
|
+
// Incoming["_def"]["catchall"],
|
|
7212
|
+
// NewOutput,
|
|
7213
|
+
// NewInput
|
|
7214
|
+
// > {
|
|
7215
|
+
// const merged: any = new ZodObject({
|
|
7216
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
7217
|
+
// catchall: merging._def.catchall,
|
|
7218
|
+
// shape: () =>
|
|
7219
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
7220
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
7221
|
+
// }) as any;
|
|
7222
|
+
// return merged;
|
|
7223
|
+
// }
|
|
7224
|
+
setKey(key, schema) {
|
|
7225
|
+
return this.augment({ [key]: schema });
|
|
7226
|
+
}
|
|
7227
|
+
// merge<Incoming extends AnyZodObject>(
|
|
7228
|
+
// merging: Incoming
|
|
7229
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
7230
|
+
// ZodObject<
|
|
7231
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
7232
|
+
// Incoming["_def"]["unknownKeys"],
|
|
7233
|
+
// Incoming["_def"]["catchall"]
|
|
7234
|
+
// > {
|
|
7235
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
|
7236
|
+
// // this._def.shape(),
|
|
7237
|
+
// // merging._def.shape()
|
|
7238
|
+
// // );
|
|
7239
|
+
// const merged: any = new ZodObject({
|
|
7240
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
7241
|
+
// catchall: merging._def.catchall,
|
|
7242
|
+
// shape: () =>
|
|
7243
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
7244
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
7245
|
+
// }) as any;
|
|
7246
|
+
// return merged;
|
|
7247
|
+
// }
|
|
7248
|
+
catchall(index) {
|
|
7249
|
+
return new _ZodObject({
|
|
7250
|
+
...this._def,
|
|
7251
|
+
catchall: index
|
|
7252
|
+
});
|
|
7253
|
+
}
|
|
7254
|
+
pick(mask) {
|
|
7255
|
+
let shape = {};
|
|
7256
|
+
for (let key of util.objectKeys(mask))
|
|
7257
|
+
mask[key] && this.shape[key] && (shape[key] = this.shape[key]);
|
|
7258
|
+
return new _ZodObject({
|
|
7259
|
+
...this._def,
|
|
7260
|
+
shape: () => shape
|
|
7261
|
+
});
|
|
7262
|
+
}
|
|
7263
|
+
omit(mask) {
|
|
7264
|
+
let shape = {};
|
|
7265
|
+
for (let key of util.objectKeys(this.shape))
|
|
7266
|
+
mask[key] || (shape[key] = this.shape[key]);
|
|
7267
|
+
return new _ZodObject({
|
|
7268
|
+
...this._def,
|
|
7269
|
+
shape: () => shape
|
|
7270
|
+
});
|
|
7271
|
+
}
|
|
7272
|
+
/**
|
|
7273
|
+
* @deprecated
|
|
7274
|
+
*/
|
|
7275
|
+
deepPartial() {
|
|
7276
|
+
return deepPartialify(this);
|
|
7277
|
+
}
|
|
7278
|
+
partial(mask) {
|
|
7279
|
+
let newShape = {};
|
|
7280
|
+
for (let key of util.objectKeys(this.shape)) {
|
|
7281
|
+
let fieldSchema = this.shape[key];
|
|
7282
|
+
mask && !mask[key] ? newShape[key] = fieldSchema : newShape[key] = fieldSchema.optional();
|
|
7283
|
+
}
|
|
7284
|
+
return new _ZodObject({
|
|
7285
|
+
...this._def,
|
|
7286
|
+
shape: () => newShape
|
|
7287
|
+
});
|
|
7288
|
+
}
|
|
7289
|
+
required(mask) {
|
|
7290
|
+
let newShape = {};
|
|
7291
|
+
for (let key of util.objectKeys(this.shape))
|
|
7292
|
+
if (mask && !mask[key])
|
|
7293
|
+
newShape[key] = this.shape[key];
|
|
7294
|
+
else {
|
|
7295
|
+
let newField = this.shape[key];
|
|
7296
|
+
for (; newField instanceof ZodOptional; )
|
|
7297
|
+
newField = newField._def.innerType;
|
|
7298
|
+
newShape[key] = newField;
|
|
7299
|
+
}
|
|
7300
|
+
return new _ZodObject({
|
|
7301
|
+
...this._def,
|
|
7302
|
+
shape: () => newShape
|
|
7303
|
+
});
|
|
7304
|
+
}
|
|
7305
|
+
keyof() {
|
|
7306
|
+
return createZodEnum(util.objectKeys(this.shape));
|
|
7307
|
+
}
|
|
7308
|
+
};
|
|
7309
|
+
ZodObject.create = (shape, params) => new ZodObject({
|
|
7310
|
+
shape: () => shape,
|
|
7311
|
+
unknownKeys: "strip",
|
|
7312
|
+
catchall: ZodNever.create(),
|
|
7313
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
7314
|
+
...processCreateParams(params)
|
|
7315
|
+
});
|
|
7316
|
+
ZodObject.strictCreate = (shape, params) => new ZodObject({
|
|
7317
|
+
shape: () => shape,
|
|
7318
|
+
unknownKeys: "strict",
|
|
7319
|
+
catchall: ZodNever.create(),
|
|
7320
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
7321
|
+
...processCreateParams(params)
|
|
7322
|
+
});
|
|
7323
|
+
ZodObject.lazycreate = (shape, params) => new ZodObject({
|
|
7324
|
+
shape,
|
|
7325
|
+
unknownKeys: "strip",
|
|
7326
|
+
catchall: ZodNever.create(),
|
|
7327
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
7328
|
+
...processCreateParams(params)
|
|
7329
|
+
});
|
|
7330
|
+
var ZodUnion = class extends ZodType {
|
|
7331
|
+
_parse(input) {
|
|
7332
|
+
let { ctx } = this._processInputParams(input), options = this._def.options;
|
|
7333
|
+
function handleResults(results) {
|
|
7334
|
+
for (let result of results)
|
|
7335
|
+
if (result.result.status === "valid")
|
|
7336
|
+
return result.result;
|
|
7337
|
+
for (let result of results)
|
|
7338
|
+
if (result.result.status === "dirty")
|
|
7339
|
+
return ctx.common.issues.push(...result.ctx.common.issues), result.result;
|
|
7340
|
+
let unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
7341
|
+
return addIssueToContext(ctx, {
|
|
7342
|
+
code: ZodIssueCode.invalid_union,
|
|
7343
|
+
unionErrors
|
|
7344
|
+
}), INVALID;
|
|
7345
|
+
}
|
|
7346
|
+
if (ctx.common.async)
|
|
7347
|
+
return Promise.all(options.map(async (option) => {
|
|
7348
|
+
let childCtx = {
|
|
7349
|
+
...ctx,
|
|
7350
|
+
common: {
|
|
7351
|
+
...ctx.common,
|
|
7352
|
+
issues: []
|
|
7353
|
+
},
|
|
7354
|
+
parent: null
|
|
7355
|
+
};
|
|
7356
|
+
return {
|
|
7357
|
+
result: await option._parseAsync({
|
|
7358
|
+
data: ctx.data,
|
|
7359
|
+
path: ctx.path,
|
|
7360
|
+
parent: childCtx
|
|
7361
|
+
}),
|
|
7362
|
+
ctx: childCtx
|
|
7363
|
+
};
|
|
7364
|
+
})).then(handleResults);
|
|
7365
|
+
{
|
|
7366
|
+
let dirty, issues = [];
|
|
7367
|
+
for (let option of options) {
|
|
7368
|
+
let childCtx = {
|
|
7369
|
+
...ctx,
|
|
7370
|
+
common: {
|
|
7371
|
+
...ctx.common,
|
|
7372
|
+
issues: []
|
|
7373
|
+
},
|
|
7374
|
+
parent: null
|
|
7375
|
+
}, result = option._parseSync({
|
|
7376
|
+
data: ctx.data,
|
|
7377
|
+
path: ctx.path,
|
|
7378
|
+
parent: childCtx
|
|
7379
|
+
});
|
|
7380
|
+
if (result.status === "valid")
|
|
7381
|
+
return result;
|
|
7382
|
+
result.status === "dirty" && !dirty && (dirty = { result, ctx: childCtx }), childCtx.common.issues.length && issues.push(childCtx.common.issues);
|
|
7383
|
+
}
|
|
7384
|
+
if (dirty)
|
|
7385
|
+
return ctx.common.issues.push(...dirty.ctx.common.issues), dirty.result;
|
|
7386
|
+
let unionErrors = issues.map((issues2) => new ZodError(issues2));
|
|
7387
|
+
return addIssueToContext(ctx, {
|
|
7388
|
+
code: ZodIssueCode.invalid_union,
|
|
7389
|
+
unionErrors
|
|
7390
|
+
}), INVALID;
|
|
7391
|
+
}
|
|
7392
|
+
}
|
|
7393
|
+
get options() {
|
|
7394
|
+
return this._def.options;
|
|
7395
|
+
}
|
|
7396
|
+
};
|
|
7397
|
+
ZodUnion.create = (types2, params) => new ZodUnion({
|
|
7398
|
+
options: types2,
|
|
7399
|
+
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
7400
|
+
...processCreateParams(params)
|
|
7401
|
+
});
|
|
7402
|
+
var getDiscriminator = (type) => type instanceof ZodLazy ? getDiscriminator(type.schema) : type instanceof ZodEffects ? getDiscriminator(type.innerType()) : type instanceof ZodLiteral ? [type.value] : type instanceof ZodEnum ? type.options : type instanceof ZodNativeEnum ? util.objectValues(type.enum) : type instanceof ZodDefault ? getDiscriminator(type._def.innerType) : type instanceof ZodUndefined ? [void 0] : type instanceof ZodNull ? [null] : type instanceof ZodOptional ? [void 0, ...getDiscriminator(type.unwrap())] : type instanceof ZodNullable ? [null, ...getDiscriminator(type.unwrap())] : type instanceof ZodBranded || type instanceof ZodReadonly ? getDiscriminator(type.unwrap()) : type instanceof ZodCatch ? getDiscriminator(type._def.innerType) : [], ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
|
7403
|
+
_parse(input) {
|
|
7404
|
+
let { ctx } = this._processInputParams(input);
|
|
7405
|
+
if (ctx.parsedType !== ZodParsedType.object)
|
|
7406
|
+
return addIssueToContext(ctx, {
|
|
7407
|
+
code: ZodIssueCode.invalid_type,
|
|
7408
|
+
expected: ZodParsedType.object,
|
|
7409
|
+
received: ctx.parsedType
|
|
7410
|
+
}), INVALID;
|
|
7411
|
+
let discriminator = this.discriminator, discriminatorValue = ctx.data[discriminator], option = this.optionsMap.get(discriminatorValue);
|
|
7412
|
+
return option ? ctx.common.async ? option._parseAsync({
|
|
7413
|
+
data: ctx.data,
|
|
7414
|
+
path: ctx.path,
|
|
7415
|
+
parent: ctx
|
|
7416
|
+
}) : option._parseSync({
|
|
7417
|
+
data: ctx.data,
|
|
7418
|
+
path: ctx.path,
|
|
7419
|
+
parent: ctx
|
|
7420
|
+
}) : (addIssueToContext(ctx, {
|
|
7421
|
+
code: ZodIssueCode.invalid_union_discriminator,
|
|
7422
|
+
options: Array.from(this.optionsMap.keys()),
|
|
7423
|
+
path: [discriminator]
|
|
7424
|
+
}), INVALID);
|
|
7425
|
+
}
|
|
7426
|
+
get discriminator() {
|
|
7427
|
+
return this._def.discriminator;
|
|
7428
|
+
}
|
|
7429
|
+
get options() {
|
|
7430
|
+
return this._def.options;
|
|
7431
|
+
}
|
|
7432
|
+
get optionsMap() {
|
|
7433
|
+
return this._def.optionsMap;
|
|
7434
|
+
}
|
|
7435
|
+
/**
|
|
7436
|
+
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
7437
|
+
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
7438
|
+
* have a different value for each object in the union.
|
|
7439
|
+
* @param discriminator the name of the discriminator property
|
|
7440
|
+
* @param types an array of object schemas
|
|
7441
|
+
* @param params
|
|
7442
|
+
*/
|
|
7443
|
+
static create(discriminator, options, params) {
|
|
7444
|
+
let optionsMap = /* @__PURE__ */ new Map();
|
|
7445
|
+
for (let type of options) {
|
|
7446
|
+
let discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
7447
|
+
if (!discriminatorValues.length)
|
|
7448
|
+
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
7449
|
+
for (let value of discriminatorValues) {
|
|
7450
|
+
if (optionsMap.has(value))
|
|
7451
|
+
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
7452
|
+
optionsMap.set(value, type);
|
|
7453
|
+
}
|
|
7454
|
+
}
|
|
7455
|
+
return new _ZodDiscriminatedUnion({
|
|
7456
|
+
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
7457
|
+
discriminator,
|
|
7458
|
+
options,
|
|
7459
|
+
optionsMap,
|
|
7460
|
+
...processCreateParams(params)
|
|
7461
|
+
});
|
|
7462
|
+
}
|
|
7463
|
+
};
|
|
7464
|
+
function mergeValues(a, b) {
|
|
7465
|
+
let aType = getParsedType(a), bType = getParsedType(b);
|
|
7466
|
+
if (a === b)
|
|
7467
|
+
return { valid: !0, data: a };
|
|
7468
|
+
if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
7469
|
+
let bKeys = util.objectKeys(b), sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1), newObj = { ...a, ...b };
|
|
7470
|
+
for (let key of sharedKeys) {
|
|
7471
|
+
let sharedValue = mergeValues(a[key], b[key]);
|
|
7472
|
+
if (!sharedValue.valid)
|
|
7473
|
+
return { valid: !1 };
|
|
7474
|
+
newObj[key] = sharedValue.data;
|
|
7475
|
+
}
|
|
7476
|
+
return { valid: !0, data: newObj };
|
|
7477
|
+
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
7478
|
+
if (a.length !== b.length)
|
|
7479
|
+
return { valid: !1 };
|
|
7480
|
+
let newArray = [];
|
|
7481
|
+
for (let index = 0; index < a.length; index++) {
|
|
7482
|
+
let itemA = a[index], itemB = b[index], sharedValue = mergeValues(itemA, itemB);
|
|
7483
|
+
if (!sharedValue.valid)
|
|
7484
|
+
return { valid: !1 };
|
|
7485
|
+
newArray.push(sharedValue.data);
|
|
7486
|
+
}
|
|
7487
|
+
return { valid: !0, data: newArray };
|
|
7488
|
+
} else return aType === ZodParsedType.date && bType === ZodParsedType.date && +a == +b ? { valid: !0, data: a } : { valid: !1 };
|
|
7489
|
+
}
|
|
7490
|
+
var ZodIntersection = class extends ZodType {
|
|
7491
|
+
_parse(input) {
|
|
7492
|
+
let { status, ctx } = this._processInputParams(input), handleParsed = (parsedLeft, parsedRight) => {
|
|
7493
|
+
if (isAborted(parsedLeft) || isAborted(parsedRight))
|
|
7494
|
+
return INVALID;
|
|
7495
|
+
let merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
7496
|
+
return merged.valid ? ((isDirty(parsedLeft) || isDirty(parsedRight)) && status.dirty(), { status: status.value, value: merged.data }) : (addIssueToContext(ctx, {
|
|
7497
|
+
code: ZodIssueCode.invalid_intersection_types
|
|
7498
|
+
}), INVALID);
|
|
7499
|
+
};
|
|
7500
|
+
return ctx.common.async ? Promise.all([
|
|
7501
|
+
this._def.left._parseAsync({
|
|
7502
|
+
data: ctx.data,
|
|
7503
|
+
path: ctx.path,
|
|
7504
|
+
parent: ctx
|
|
7505
|
+
}),
|
|
7506
|
+
this._def.right._parseAsync({
|
|
7507
|
+
data: ctx.data,
|
|
7508
|
+
path: ctx.path,
|
|
7509
|
+
parent: ctx
|
|
7510
|
+
})
|
|
7511
|
+
]).then(([left, right]) => handleParsed(left, right)) : handleParsed(this._def.left._parseSync({
|
|
7512
|
+
data: ctx.data,
|
|
7513
|
+
path: ctx.path,
|
|
7514
|
+
parent: ctx
|
|
7515
|
+
}), this._def.right._parseSync({
|
|
7516
|
+
data: ctx.data,
|
|
7517
|
+
path: ctx.path,
|
|
7518
|
+
parent: ctx
|
|
7519
|
+
}));
|
|
7520
|
+
}
|
|
7521
|
+
};
|
|
7522
|
+
ZodIntersection.create = (left, right, params) => new ZodIntersection({
|
|
7523
|
+
left,
|
|
7524
|
+
right,
|
|
7525
|
+
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
7526
|
+
...processCreateParams(params)
|
|
7527
|
+
});
|
|
7528
|
+
var ZodTuple = class _ZodTuple extends ZodType {
|
|
7529
|
+
_parse(input) {
|
|
7530
|
+
let { status, ctx } = this._processInputParams(input);
|
|
7531
|
+
if (ctx.parsedType !== ZodParsedType.array)
|
|
7532
|
+
return addIssueToContext(ctx, {
|
|
7533
|
+
code: ZodIssueCode.invalid_type,
|
|
7534
|
+
expected: ZodParsedType.array,
|
|
7535
|
+
received: ctx.parsedType
|
|
7536
|
+
}), INVALID;
|
|
7537
|
+
if (ctx.data.length < this._def.items.length)
|
|
7538
|
+
return addIssueToContext(ctx, {
|
|
7539
|
+
code: ZodIssueCode.too_small,
|
|
7540
|
+
minimum: this._def.items.length,
|
|
7541
|
+
inclusive: !0,
|
|
7542
|
+
exact: !1,
|
|
7543
|
+
type: "array"
|
|
7544
|
+
}), INVALID;
|
|
7545
|
+
!this._def.rest && ctx.data.length > this._def.items.length && (addIssueToContext(ctx, {
|
|
7546
|
+
code: ZodIssueCode.too_big,
|
|
7547
|
+
maximum: this._def.items.length,
|
|
7548
|
+
inclusive: !0,
|
|
7549
|
+
exact: !1,
|
|
7550
|
+
type: "array"
|
|
7551
|
+
}), status.dirty());
|
|
7552
|
+
let items = [...ctx.data].map((item, itemIndex) => {
|
|
7553
|
+
let schema = this._def.items[itemIndex] || this._def.rest;
|
|
7554
|
+
return schema ? schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex)) : null;
|
|
7555
|
+
}).filter((x) => !!x);
|
|
7556
|
+
return ctx.common.async ? Promise.all(items).then((results) => ParseStatus.mergeArray(status, results)) : ParseStatus.mergeArray(status, items);
|
|
7557
|
+
}
|
|
7558
|
+
get items() {
|
|
7559
|
+
return this._def.items;
|
|
7560
|
+
}
|
|
7561
|
+
rest(rest) {
|
|
7562
|
+
return new _ZodTuple({
|
|
7563
|
+
...this._def,
|
|
7564
|
+
rest
|
|
7565
|
+
});
|
|
7566
|
+
}
|
|
7567
|
+
};
|
|
7568
|
+
ZodTuple.create = (schemas, params) => {
|
|
7569
|
+
if (!Array.isArray(schemas))
|
|
7570
|
+
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
7571
|
+
return new ZodTuple({
|
|
7572
|
+
items: schemas,
|
|
7573
|
+
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
7574
|
+
rest: null,
|
|
7575
|
+
...processCreateParams(params)
|
|
7576
|
+
});
|
|
7577
|
+
};
|
|
7578
|
+
var ZodRecord = class _ZodRecord extends ZodType {
|
|
7579
|
+
get keySchema() {
|
|
7580
|
+
return this._def.keyType;
|
|
7581
|
+
}
|
|
7582
|
+
get valueSchema() {
|
|
7583
|
+
return this._def.valueType;
|
|
7584
|
+
}
|
|
7585
|
+
_parse(input) {
|
|
7586
|
+
let { status, ctx } = this._processInputParams(input);
|
|
7587
|
+
if (ctx.parsedType !== ZodParsedType.object)
|
|
7588
|
+
return addIssueToContext(ctx, {
|
|
7589
|
+
code: ZodIssueCode.invalid_type,
|
|
7590
|
+
expected: ZodParsedType.object,
|
|
7591
|
+
received: ctx.parsedType
|
|
7592
|
+
}), INVALID;
|
|
7593
|
+
let pairs = [], keyType = this._def.keyType, valueType = this._def.valueType;
|
|
7594
|
+
for (let key in ctx.data)
|
|
7595
|
+
pairs.push({
|
|
7596
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
7597
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
7598
|
+
alwaysSet: key in ctx.data
|
|
7599
|
+
});
|
|
7600
|
+
return ctx.common.async ? ParseStatus.mergeObjectAsync(status, pairs) : ParseStatus.mergeObjectSync(status, pairs);
|
|
7601
|
+
}
|
|
7602
|
+
get element() {
|
|
7603
|
+
return this._def.valueType;
|
|
7604
|
+
}
|
|
7605
|
+
static create(first, second, third) {
|
|
7606
|
+
return second instanceof ZodType ? new _ZodRecord({
|
|
7607
|
+
keyType: first,
|
|
7608
|
+
valueType: second,
|
|
7609
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
7610
|
+
...processCreateParams(third)
|
|
7611
|
+
}) : new _ZodRecord({
|
|
7612
|
+
keyType: ZodString.create(),
|
|
7613
|
+
valueType: first,
|
|
7614
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
7615
|
+
...processCreateParams(second)
|
|
7616
|
+
});
|
|
7617
|
+
}
|
|
7618
|
+
}, ZodMap = class extends ZodType {
|
|
7619
|
+
get keySchema() {
|
|
7620
|
+
return this._def.keyType;
|
|
7621
|
+
}
|
|
7622
|
+
get valueSchema() {
|
|
7623
|
+
return this._def.valueType;
|
|
7624
|
+
}
|
|
7625
|
+
_parse(input) {
|
|
7626
|
+
let { status, ctx } = this._processInputParams(input);
|
|
7627
|
+
if (ctx.parsedType !== ZodParsedType.map)
|
|
7628
|
+
return addIssueToContext(ctx, {
|
|
7629
|
+
code: ZodIssueCode.invalid_type,
|
|
7630
|
+
expected: ZodParsedType.map,
|
|
7631
|
+
received: ctx.parsedType
|
|
7632
|
+
}), INVALID;
|
|
7633
|
+
let keyType = this._def.keyType, valueType = this._def.valueType, pairs = [...ctx.data.entries()].map(([key, value], index) => ({
|
|
7634
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
7635
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
|
|
7636
|
+
}));
|
|
7637
|
+
if (ctx.common.async) {
|
|
7638
|
+
let finalMap = /* @__PURE__ */ new Map();
|
|
7639
|
+
return Promise.resolve().then(async () => {
|
|
7640
|
+
for (let pair of pairs) {
|
|
7641
|
+
let key = await pair.key, value = await pair.value;
|
|
7642
|
+
if (key.status === "aborted" || value.status === "aborted")
|
|
7643
|
+
return INVALID;
|
|
7644
|
+
(key.status === "dirty" || value.status === "dirty") && status.dirty(), finalMap.set(key.value, value.value);
|
|
7645
|
+
}
|
|
7646
|
+
return { status: status.value, value: finalMap };
|
|
7647
|
+
});
|
|
7648
|
+
} else {
|
|
7649
|
+
let finalMap = /* @__PURE__ */ new Map();
|
|
7650
|
+
for (let pair of pairs) {
|
|
7651
|
+
let key = pair.key, value = pair.value;
|
|
7652
|
+
if (key.status === "aborted" || value.status === "aborted")
|
|
7653
|
+
return INVALID;
|
|
7654
|
+
(key.status === "dirty" || value.status === "dirty") && status.dirty(), finalMap.set(key.value, value.value);
|
|
7655
|
+
}
|
|
7656
|
+
return { status: status.value, value: finalMap };
|
|
7657
|
+
}
|
|
7658
|
+
}
|
|
7659
|
+
};
|
|
7660
|
+
ZodMap.create = (keyType, valueType, params) => new ZodMap({
|
|
7661
|
+
valueType,
|
|
7662
|
+
keyType,
|
|
7663
|
+
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
7664
|
+
...processCreateParams(params)
|
|
7665
|
+
});
|
|
7666
|
+
var ZodSet = class _ZodSet extends ZodType {
|
|
7667
|
+
_parse(input) {
|
|
7668
|
+
let { status, ctx } = this._processInputParams(input);
|
|
7669
|
+
if (ctx.parsedType !== ZodParsedType.set)
|
|
7670
|
+
return addIssueToContext(ctx, {
|
|
7671
|
+
code: ZodIssueCode.invalid_type,
|
|
7672
|
+
expected: ZodParsedType.set,
|
|
7673
|
+
received: ctx.parsedType
|
|
7674
|
+
}), INVALID;
|
|
7675
|
+
let def = this._def;
|
|
7676
|
+
def.minSize !== null && ctx.data.size < def.minSize.value && (addIssueToContext(ctx, {
|
|
7677
|
+
code: ZodIssueCode.too_small,
|
|
7678
|
+
minimum: def.minSize.value,
|
|
7679
|
+
type: "set",
|
|
7680
|
+
inclusive: !0,
|
|
7681
|
+
exact: !1,
|
|
7682
|
+
message: def.minSize.message
|
|
7683
|
+
}), status.dirty()), def.maxSize !== null && ctx.data.size > def.maxSize.value && (addIssueToContext(ctx, {
|
|
7684
|
+
code: ZodIssueCode.too_big,
|
|
7685
|
+
maximum: def.maxSize.value,
|
|
7686
|
+
type: "set",
|
|
7687
|
+
inclusive: !0,
|
|
7688
|
+
exact: !1,
|
|
7689
|
+
message: def.maxSize.message
|
|
7690
|
+
}), status.dirty());
|
|
7691
|
+
let valueType = this._def.valueType;
|
|
7692
|
+
function finalizeSet(elements2) {
|
|
7693
|
+
let parsedSet = /* @__PURE__ */ new Set();
|
|
7694
|
+
for (let element of elements2) {
|
|
7695
|
+
if (element.status === "aborted")
|
|
7696
|
+
return INVALID;
|
|
7697
|
+
element.status === "dirty" && status.dirty(), parsedSet.add(element.value);
|
|
7698
|
+
}
|
|
7699
|
+
return { status: status.value, value: parsedSet };
|
|
7700
|
+
}
|
|
7701
|
+
let elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
7702
|
+
return ctx.common.async ? Promise.all(elements).then((elements2) => finalizeSet(elements2)) : finalizeSet(elements);
|
|
7703
|
+
}
|
|
7704
|
+
min(minSize, message) {
|
|
7705
|
+
return new _ZodSet({
|
|
7706
|
+
...this._def,
|
|
7707
|
+
minSize: { value: minSize, message: errorUtil.toString(message) }
|
|
7708
|
+
});
|
|
7709
|
+
}
|
|
7710
|
+
max(maxSize, message) {
|
|
7711
|
+
return new _ZodSet({
|
|
7712
|
+
...this._def,
|
|
7713
|
+
maxSize: { value: maxSize, message: errorUtil.toString(message) }
|
|
7714
|
+
});
|
|
7715
|
+
}
|
|
7716
|
+
size(size, message) {
|
|
7717
|
+
return this.min(size, message).max(size, message);
|
|
7718
|
+
}
|
|
7719
|
+
nonempty(message) {
|
|
7720
|
+
return this.min(1, message);
|
|
7721
|
+
}
|
|
7722
|
+
};
|
|
7723
|
+
ZodSet.create = (valueType, params) => new ZodSet({
|
|
7724
|
+
valueType,
|
|
7725
|
+
minSize: null,
|
|
7726
|
+
maxSize: null,
|
|
7727
|
+
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
7728
|
+
...processCreateParams(params)
|
|
7729
|
+
});
|
|
7730
|
+
var ZodFunction = class _ZodFunction extends ZodType {
|
|
7731
|
+
constructor() {
|
|
7732
|
+
super(...arguments), this.validate = this.implement;
|
|
7733
|
+
}
|
|
7734
|
+
_parse(input) {
|
|
7735
|
+
let { ctx } = this._processInputParams(input);
|
|
7736
|
+
if (ctx.parsedType !== ZodParsedType.function)
|
|
7737
|
+
return addIssueToContext(ctx, {
|
|
7738
|
+
code: ZodIssueCode.invalid_type,
|
|
7739
|
+
expected: ZodParsedType.function,
|
|
7740
|
+
received: ctx.parsedType
|
|
7741
|
+
}), INVALID;
|
|
7742
|
+
function makeArgsIssue(args, error) {
|
|
7743
|
+
return makeIssue({
|
|
7744
|
+
data: args,
|
|
7745
|
+
path: ctx.path,
|
|
7746
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
7747
|
+
issueData: {
|
|
7748
|
+
code: ZodIssueCode.invalid_arguments,
|
|
7749
|
+
argumentsError: error
|
|
7750
|
+
}
|
|
7751
|
+
});
|
|
7752
|
+
}
|
|
7753
|
+
function makeReturnsIssue(returns, error) {
|
|
7754
|
+
return makeIssue({
|
|
7755
|
+
data: returns,
|
|
7756
|
+
path: ctx.path,
|
|
7757
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
7758
|
+
issueData: {
|
|
7759
|
+
code: ZodIssueCode.invalid_return_type,
|
|
7760
|
+
returnTypeError: error
|
|
7761
|
+
}
|
|
7762
|
+
});
|
|
7763
|
+
}
|
|
7764
|
+
let params = { errorMap: ctx.common.contextualErrorMap }, fn = ctx.data;
|
|
7765
|
+
if (this._def.returns instanceof ZodPromise) {
|
|
7766
|
+
let me = this;
|
|
7767
|
+
return OK(async function(...args) {
|
|
7768
|
+
let error = new ZodError([]), parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
7769
|
+
throw error.addIssue(makeArgsIssue(args, e)), error;
|
|
7770
|
+
}), result = await Reflect.apply(fn, this, parsedArgs);
|
|
7771
|
+
return await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
7772
|
+
throw error.addIssue(makeReturnsIssue(result, e)), error;
|
|
7773
|
+
});
|
|
7774
|
+
});
|
|
7775
|
+
} else {
|
|
7776
|
+
let me = this;
|
|
7777
|
+
return OK(function(...args) {
|
|
7778
|
+
let parsedArgs = me._def.args.safeParse(args, params);
|
|
7779
|
+
if (!parsedArgs.success)
|
|
7780
|
+
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
7781
|
+
let result = Reflect.apply(fn, this, parsedArgs.data), parsedReturns = me._def.returns.safeParse(result, params);
|
|
7782
|
+
if (!parsedReturns.success)
|
|
7783
|
+
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
7784
|
+
return parsedReturns.data;
|
|
7785
|
+
});
|
|
7786
|
+
}
|
|
7787
|
+
}
|
|
7788
|
+
parameters() {
|
|
7789
|
+
return this._def.args;
|
|
7790
|
+
}
|
|
7791
|
+
returnType() {
|
|
7792
|
+
return this._def.returns;
|
|
7793
|
+
}
|
|
7794
|
+
args(...items) {
|
|
7795
|
+
return new _ZodFunction({
|
|
7796
|
+
...this._def,
|
|
7797
|
+
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
7798
|
+
});
|
|
7799
|
+
}
|
|
7800
|
+
returns(returnType) {
|
|
7801
|
+
return new _ZodFunction({
|
|
7802
|
+
...this._def,
|
|
7803
|
+
returns: returnType
|
|
7804
|
+
});
|
|
7805
|
+
}
|
|
7806
|
+
implement(func) {
|
|
7807
|
+
return this.parse(func);
|
|
7808
|
+
}
|
|
7809
|
+
strictImplement(func) {
|
|
7810
|
+
return this.parse(func);
|
|
7811
|
+
}
|
|
7812
|
+
static create(args, returns, params) {
|
|
7813
|
+
return new _ZodFunction({
|
|
7814
|
+
args: args || ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
7815
|
+
returns: returns || ZodUnknown.create(),
|
|
7816
|
+
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
7817
|
+
...processCreateParams(params)
|
|
7818
|
+
});
|
|
7819
|
+
}
|
|
7820
|
+
}, ZodLazy = class extends ZodType {
|
|
7821
|
+
get schema() {
|
|
7822
|
+
return this._def.getter();
|
|
7823
|
+
}
|
|
7824
|
+
_parse(input) {
|
|
7825
|
+
let { ctx } = this._processInputParams(input);
|
|
7826
|
+
return this._def.getter()._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
7827
|
+
}
|
|
7828
|
+
};
|
|
7829
|
+
ZodLazy.create = (getter, params) => new ZodLazy({
|
|
7830
|
+
getter,
|
|
7831
|
+
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
7832
|
+
...processCreateParams(params)
|
|
7833
|
+
});
|
|
7834
|
+
var ZodLiteral = class extends ZodType {
|
|
7835
|
+
_parse(input) {
|
|
7836
|
+
if (input.data !== this._def.value) {
|
|
7837
|
+
let ctx = this._getOrReturnCtx(input);
|
|
7838
|
+
return addIssueToContext(ctx, {
|
|
7839
|
+
received: ctx.data,
|
|
7840
|
+
code: ZodIssueCode.invalid_literal,
|
|
7841
|
+
expected: this._def.value
|
|
7842
|
+
}), INVALID;
|
|
7843
|
+
}
|
|
7844
|
+
return { status: "valid", value: input.data };
|
|
7845
|
+
}
|
|
7846
|
+
get value() {
|
|
7847
|
+
return this._def.value;
|
|
7848
|
+
}
|
|
7849
|
+
};
|
|
7850
|
+
ZodLiteral.create = (value, params) => new ZodLiteral({
|
|
7851
|
+
value,
|
|
7852
|
+
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
7853
|
+
...processCreateParams(params)
|
|
7854
|
+
});
|
|
7855
|
+
function createZodEnum(values, params) {
|
|
7856
|
+
return new ZodEnum({
|
|
7857
|
+
values,
|
|
7858
|
+
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
7859
|
+
...processCreateParams(params)
|
|
7860
|
+
});
|
|
7861
|
+
}
|
|
7862
|
+
var ZodEnum = class _ZodEnum extends ZodType {
|
|
7863
|
+
_parse(input) {
|
|
7864
|
+
if (typeof input.data != "string") {
|
|
7865
|
+
let ctx = this._getOrReturnCtx(input), expectedValues = this._def.values;
|
|
7866
|
+
return addIssueToContext(ctx, {
|
|
7867
|
+
expected: util.joinValues(expectedValues),
|
|
7868
|
+
received: ctx.parsedType,
|
|
7869
|
+
code: ZodIssueCode.invalid_type
|
|
7870
|
+
}), INVALID;
|
|
7871
|
+
}
|
|
7872
|
+
if (this._cache || (this._cache = new Set(this._def.values)), !this._cache.has(input.data)) {
|
|
7873
|
+
let ctx = this._getOrReturnCtx(input), expectedValues = this._def.values;
|
|
7874
|
+
return addIssueToContext(ctx, {
|
|
7875
|
+
received: ctx.data,
|
|
7876
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
7877
|
+
options: expectedValues
|
|
7878
|
+
}), INVALID;
|
|
7879
|
+
}
|
|
7880
|
+
return OK(input.data);
|
|
7881
|
+
}
|
|
7882
|
+
get options() {
|
|
7883
|
+
return this._def.values;
|
|
7884
|
+
}
|
|
7885
|
+
get enum() {
|
|
7886
|
+
let enumValues = {};
|
|
7887
|
+
for (let val of this._def.values)
|
|
7888
|
+
enumValues[val] = val;
|
|
7889
|
+
return enumValues;
|
|
7890
|
+
}
|
|
7891
|
+
get Values() {
|
|
7892
|
+
let enumValues = {};
|
|
7893
|
+
for (let val of this._def.values)
|
|
7894
|
+
enumValues[val] = val;
|
|
7895
|
+
return enumValues;
|
|
7896
|
+
}
|
|
7897
|
+
get Enum() {
|
|
7898
|
+
let enumValues = {};
|
|
7899
|
+
for (let val of this._def.values)
|
|
7900
|
+
enumValues[val] = val;
|
|
7901
|
+
return enumValues;
|
|
7902
|
+
}
|
|
7903
|
+
extract(values, newDef = this._def) {
|
|
7904
|
+
return _ZodEnum.create(values, {
|
|
7905
|
+
...this._def,
|
|
7906
|
+
...newDef
|
|
7907
|
+
});
|
|
7908
|
+
}
|
|
7909
|
+
exclude(values, newDef = this._def) {
|
|
7910
|
+
return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
7911
|
+
...this._def,
|
|
7912
|
+
...newDef
|
|
7913
|
+
});
|
|
7914
|
+
}
|
|
7915
|
+
};
|
|
7916
|
+
ZodEnum.create = createZodEnum;
|
|
7917
|
+
var ZodNativeEnum = class extends ZodType {
|
|
7918
|
+
_parse(input) {
|
|
7919
|
+
let nativeEnumValues = util.getValidEnumValues(this._def.values), ctx = this._getOrReturnCtx(input);
|
|
7920
|
+
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
7921
|
+
let expectedValues = util.objectValues(nativeEnumValues);
|
|
7922
|
+
return addIssueToContext(ctx, {
|
|
7923
|
+
expected: util.joinValues(expectedValues),
|
|
7924
|
+
received: ctx.parsedType,
|
|
7925
|
+
code: ZodIssueCode.invalid_type
|
|
7926
|
+
}), INVALID;
|
|
7927
|
+
}
|
|
7928
|
+
if (this._cache || (this._cache = new Set(util.getValidEnumValues(this._def.values))), !this._cache.has(input.data)) {
|
|
7929
|
+
let expectedValues = util.objectValues(nativeEnumValues);
|
|
7930
|
+
return addIssueToContext(ctx, {
|
|
7931
|
+
received: ctx.data,
|
|
7932
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
7933
|
+
options: expectedValues
|
|
7934
|
+
}), INVALID;
|
|
7935
|
+
}
|
|
7936
|
+
return OK(input.data);
|
|
7937
|
+
}
|
|
7938
|
+
get enum() {
|
|
7939
|
+
return this._def.values;
|
|
7940
|
+
}
|
|
7941
|
+
};
|
|
7942
|
+
ZodNativeEnum.create = (values, params) => new ZodNativeEnum({
|
|
7943
|
+
values,
|
|
7944
|
+
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
7945
|
+
...processCreateParams(params)
|
|
7946
|
+
});
|
|
7947
|
+
var ZodPromise = class extends ZodType {
|
|
7948
|
+
unwrap() {
|
|
7949
|
+
return this._def.type;
|
|
7950
|
+
}
|
|
7951
|
+
_parse(input) {
|
|
7952
|
+
let { ctx } = this._processInputParams(input);
|
|
7953
|
+
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === !1)
|
|
7954
|
+
return addIssueToContext(ctx, {
|
|
7955
|
+
code: ZodIssueCode.invalid_type,
|
|
7956
|
+
expected: ZodParsedType.promise,
|
|
7957
|
+
received: ctx.parsedType
|
|
7958
|
+
}), INVALID;
|
|
7959
|
+
let promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
7960
|
+
return OK(promisified.then((data) => this._def.type.parseAsync(data, {
|
|
7961
|
+
path: ctx.path,
|
|
7962
|
+
errorMap: ctx.common.contextualErrorMap
|
|
7963
|
+
})));
|
|
7964
|
+
}
|
|
7965
|
+
};
|
|
7966
|
+
ZodPromise.create = (schema, params) => new ZodPromise({
|
|
7967
|
+
type: schema,
|
|
7968
|
+
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
7969
|
+
...processCreateParams(params)
|
|
7970
|
+
});
|
|
7971
|
+
var ZodEffects = class extends ZodType {
|
|
7972
|
+
innerType() {
|
|
7973
|
+
return this._def.schema;
|
|
7974
|
+
}
|
|
7975
|
+
sourceType() {
|
|
7976
|
+
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
7977
|
+
}
|
|
7978
|
+
_parse(input) {
|
|
7979
|
+
let { status, ctx } = this._processInputParams(input), effect = this._def.effect || null, checkCtx = {
|
|
7980
|
+
addIssue: (arg) => {
|
|
7981
|
+
addIssueToContext(ctx, arg), arg.fatal ? status.abort() : status.dirty();
|
|
7982
|
+
},
|
|
7983
|
+
get path() {
|
|
7984
|
+
return ctx.path;
|
|
7985
|
+
}
|
|
7986
|
+
};
|
|
7987
|
+
if (checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx), effect.type === "preprocess") {
|
|
7988
|
+
let processed = effect.transform(ctx.data, checkCtx);
|
|
7989
|
+
if (ctx.common.async)
|
|
7990
|
+
return Promise.resolve(processed).then(async (processed2) => {
|
|
7991
|
+
if (status.value === "aborted")
|
|
7992
|
+
return INVALID;
|
|
7993
|
+
let result = await this._def.schema._parseAsync({
|
|
7994
|
+
data: processed2,
|
|
7995
|
+
path: ctx.path,
|
|
7996
|
+
parent: ctx
|
|
7997
|
+
});
|
|
7998
|
+
return result.status === "aborted" ? INVALID : result.status === "dirty" ? DIRTY(result.value) : status.value === "dirty" ? DIRTY(result.value) : result;
|
|
7999
|
+
});
|
|
8000
|
+
{
|
|
8001
|
+
if (status.value === "aborted")
|
|
8002
|
+
return INVALID;
|
|
8003
|
+
let result = this._def.schema._parseSync({
|
|
8004
|
+
data: processed,
|
|
8005
|
+
path: ctx.path,
|
|
8006
|
+
parent: ctx
|
|
8007
|
+
});
|
|
8008
|
+
return result.status === "aborted" ? INVALID : result.status === "dirty" ? DIRTY(result.value) : status.value === "dirty" ? DIRTY(result.value) : result;
|
|
8009
|
+
}
|
|
8010
|
+
}
|
|
8011
|
+
if (effect.type === "refinement") {
|
|
8012
|
+
let executeRefinement = (acc) => {
|
|
8013
|
+
let result = effect.refinement(acc, checkCtx);
|
|
8014
|
+
if (ctx.common.async)
|
|
8015
|
+
return Promise.resolve(result);
|
|
8016
|
+
if (result instanceof Promise)
|
|
8017
|
+
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
8018
|
+
return acc;
|
|
8019
|
+
};
|
|
8020
|
+
if (ctx.common.async === !1) {
|
|
8021
|
+
let inner = this._def.schema._parseSync({
|
|
8022
|
+
data: ctx.data,
|
|
8023
|
+
path: ctx.path,
|
|
8024
|
+
parent: ctx
|
|
8025
|
+
});
|
|
8026
|
+
return inner.status === "aborted" ? INVALID : (inner.status === "dirty" && status.dirty(), executeRefinement(inner.value), { status: status.value, value: inner.value });
|
|
8027
|
+
} else
|
|
8028
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => inner.status === "aborted" ? INVALID : (inner.status === "dirty" && status.dirty(), executeRefinement(inner.value).then(() => ({ status: status.value, value: inner.value }))));
|
|
8029
|
+
}
|
|
8030
|
+
if (effect.type === "transform")
|
|
8031
|
+
if (ctx.common.async === !1) {
|
|
8032
|
+
let base = this._def.schema._parseSync({
|
|
8033
|
+
data: ctx.data,
|
|
8034
|
+
path: ctx.path,
|
|
8035
|
+
parent: ctx
|
|
8036
|
+
});
|
|
8037
|
+
if (!isValid(base))
|
|
8038
|
+
return INVALID;
|
|
8039
|
+
let result = effect.transform(base.value, checkCtx);
|
|
8040
|
+
if (result instanceof Promise)
|
|
8041
|
+
throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
8042
|
+
return { status: status.value, value: result };
|
|
8043
|
+
} else
|
|
8044
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => isValid(base) ? Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
8045
|
+
status: status.value,
|
|
8046
|
+
value: result
|
|
8047
|
+
})) : INVALID);
|
|
8048
|
+
util.assertNever(effect);
|
|
8049
|
+
}
|
|
8050
|
+
};
|
|
8051
|
+
ZodEffects.create = (schema, effect, params) => new ZodEffects({
|
|
8052
|
+
schema,
|
|
8053
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
8054
|
+
effect,
|
|
8055
|
+
...processCreateParams(params)
|
|
8056
|
+
});
|
|
8057
|
+
ZodEffects.createWithPreprocess = (preprocess, schema, params) => new ZodEffects({
|
|
8058
|
+
schema,
|
|
8059
|
+
effect: { type: "preprocess", transform: preprocess },
|
|
8060
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
8061
|
+
...processCreateParams(params)
|
|
8062
|
+
});
|
|
8063
|
+
var ZodOptional = class extends ZodType {
|
|
8064
|
+
_parse(input) {
|
|
8065
|
+
return this._getType(input) === ZodParsedType.undefined ? OK(void 0) : this._def.innerType._parse(input);
|
|
8066
|
+
}
|
|
8067
|
+
unwrap() {
|
|
8068
|
+
return this._def.innerType;
|
|
8069
|
+
}
|
|
8070
|
+
};
|
|
8071
|
+
ZodOptional.create = (type, params) => new ZodOptional({
|
|
8072
|
+
innerType: type,
|
|
8073
|
+
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
8074
|
+
...processCreateParams(params)
|
|
8075
|
+
});
|
|
8076
|
+
var ZodNullable = class extends ZodType {
|
|
8077
|
+
_parse(input) {
|
|
8078
|
+
return this._getType(input) === ZodParsedType.null ? OK(null) : this._def.innerType._parse(input);
|
|
8079
|
+
}
|
|
8080
|
+
unwrap() {
|
|
8081
|
+
return this._def.innerType;
|
|
8082
|
+
}
|
|
8083
|
+
};
|
|
8084
|
+
ZodNullable.create = (type, params) => new ZodNullable({
|
|
8085
|
+
innerType: type,
|
|
8086
|
+
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
8087
|
+
...processCreateParams(params)
|
|
8088
|
+
});
|
|
8089
|
+
var ZodDefault = class extends ZodType {
|
|
8090
|
+
_parse(input) {
|
|
8091
|
+
let { ctx } = this._processInputParams(input), data = ctx.data;
|
|
8092
|
+
return ctx.parsedType === ZodParsedType.undefined && (data = this._def.defaultValue()), this._def.innerType._parse({
|
|
8093
|
+
data,
|
|
8094
|
+
path: ctx.path,
|
|
8095
|
+
parent: ctx
|
|
8096
|
+
});
|
|
8097
|
+
}
|
|
8098
|
+
removeDefault() {
|
|
8099
|
+
return this._def.innerType;
|
|
8100
|
+
}
|
|
8101
|
+
};
|
|
8102
|
+
ZodDefault.create = (type, params) => new ZodDefault({
|
|
8103
|
+
innerType: type,
|
|
8104
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
8105
|
+
defaultValue: typeof params.default == "function" ? params.default : () => params.default,
|
|
8106
|
+
...processCreateParams(params)
|
|
8107
|
+
});
|
|
8108
|
+
var ZodCatch = class extends ZodType {
|
|
8109
|
+
_parse(input) {
|
|
8110
|
+
let { ctx } = this._processInputParams(input), newCtx = {
|
|
8111
|
+
...ctx,
|
|
8112
|
+
common: {
|
|
8113
|
+
...ctx.common,
|
|
8114
|
+
issues: []
|
|
8115
|
+
}
|
|
8116
|
+
}, result = this._def.innerType._parse({
|
|
8117
|
+
data: newCtx.data,
|
|
8118
|
+
path: newCtx.path,
|
|
8119
|
+
parent: {
|
|
8120
|
+
...newCtx
|
|
8121
|
+
}
|
|
8122
|
+
});
|
|
8123
|
+
return isAsync(result) ? result.then((result2) => ({
|
|
8124
|
+
status: "valid",
|
|
8125
|
+
value: result2.status === "valid" ? result2.value : this._def.catchValue({
|
|
8126
|
+
get error() {
|
|
8127
|
+
return new ZodError(newCtx.common.issues);
|
|
8128
|
+
},
|
|
8129
|
+
input: newCtx.data
|
|
8130
|
+
})
|
|
8131
|
+
})) : {
|
|
8132
|
+
status: "valid",
|
|
8133
|
+
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
8134
|
+
get error() {
|
|
8135
|
+
return new ZodError(newCtx.common.issues);
|
|
8136
|
+
},
|
|
8137
|
+
input: newCtx.data
|
|
8138
|
+
})
|
|
8139
|
+
};
|
|
8140
|
+
}
|
|
8141
|
+
removeCatch() {
|
|
8142
|
+
return this._def.innerType;
|
|
8143
|
+
}
|
|
8144
|
+
};
|
|
8145
|
+
ZodCatch.create = (type, params) => new ZodCatch({
|
|
8146
|
+
innerType: type,
|
|
8147
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
8148
|
+
catchValue: typeof params.catch == "function" ? params.catch : () => params.catch,
|
|
8149
|
+
...processCreateParams(params)
|
|
8150
|
+
});
|
|
8151
|
+
var ZodNaN = class extends ZodType {
|
|
8152
|
+
_parse(input) {
|
|
8153
|
+
if (this._getType(input) !== ZodParsedType.nan) {
|
|
8154
|
+
let ctx = this._getOrReturnCtx(input);
|
|
8155
|
+
return addIssueToContext(ctx, {
|
|
8156
|
+
code: ZodIssueCode.invalid_type,
|
|
8157
|
+
expected: ZodParsedType.nan,
|
|
8158
|
+
received: ctx.parsedType
|
|
8159
|
+
}), INVALID;
|
|
8160
|
+
}
|
|
8161
|
+
return { status: "valid", value: input.data };
|
|
8162
|
+
}
|
|
8163
|
+
};
|
|
8164
|
+
ZodNaN.create = (params) => new ZodNaN({
|
|
8165
|
+
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
8166
|
+
...processCreateParams(params)
|
|
8167
|
+
});
|
|
8168
|
+
var BRAND = /* @__PURE__ */ Symbol("zod_brand"), ZodBranded = class extends ZodType {
|
|
8169
|
+
_parse(input) {
|
|
8170
|
+
let { ctx } = this._processInputParams(input), data = ctx.data;
|
|
8171
|
+
return this._def.type._parse({
|
|
8172
|
+
data,
|
|
8173
|
+
path: ctx.path,
|
|
8174
|
+
parent: ctx
|
|
8175
|
+
});
|
|
8176
|
+
}
|
|
8177
|
+
unwrap() {
|
|
8178
|
+
return this._def.type;
|
|
8179
|
+
}
|
|
8180
|
+
}, ZodPipeline = class _ZodPipeline extends ZodType {
|
|
8181
|
+
_parse(input) {
|
|
8182
|
+
let { status, ctx } = this._processInputParams(input);
|
|
8183
|
+
if (ctx.common.async)
|
|
8184
|
+
return (async () => {
|
|
8185
|
+
let inResult = await this._def.in._parseAsync({
|
|
8186
|
+
data: ctx.data,
|
|
8187
|
+
path: ctx.path,
|
|
8188
|
+
parent: ctx
|
|
8189
|
+
});
|
|
8190
|
+
return inResult.status === "aborted" ? INVALID : inResult.status === "dirty" ? (status.dirty(), DIRTY(inResult.value)) : this._def.out._parseAsync({
|
|
8191
|
+
data: inResult.value,
|
|
8192
|
+
path: ctx.path,
|
|
8193
|
+
parent: ctx
|
|
8194
|
+
});
|
|
8195
|
+
})();
|
|
8196
|
+
{
|
|
8197
|
+
let inResult = this._def.in._parseSync({
|
|
8198
|
+
data: ctx.data,
|
|
8199
|
+
path: ctx.path,
|
|
8200
|
+
parent: ctx
|
|
8201
|
+
});
|
|
8202
|
+
return inResult.status === "aborted" ? INVALID : inResult.status === "dirty" ? (status.dirty(), {
|
|
8203
|
+
status: "dirty",
|
|
8204
|
+
value: inResult.value
|
|
8205
|
+
}) : this._def.out._parseSync({
|
|
8206
|
+
data: inResult.value,
|
|
8207
|
+
path: ctx.path,
|
|
8208
|
+
parent: ctx
|
|
8209
|
+
});
|
|
8210
|
+
}
|
|
8211
|
+
}
|
|
8212
|
+
static create(a, b) {
|
|
8213
|
+
return new _ZodPipeline({
|
|
8214
|
+
in: a,
|
|
8215
|
+
out: b,
|
|
8216
|
+
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
8217
|
+
});
|
|
8218
|
+
}
|
|
8219
|
+
}, ZodReadonly = class extends ZodType {
|
|
8220
|
+
_parse(input) {
|
|
8221
|
+
let result = this._def.innerType._parse(input), freeze = (data) => (isValid(data) && (data.value = Object.freeze(data.value)), data);
|
|
8222
|
+
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
8223
|
+
}
|
|
8224
|
+
unwrap() {
|
|
8225
|
+
return this._def.innerType;
|
|
8226
|
+
}
|
|
8227
|
+
};
|
|
8228
|
+
ZodReadonly.create = (type, params) => new ZodReadonly({
|
|
8229
|
+
innerType: type,
|
|
8230
|
+
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
8231
|
+
...processCreateParams(params)
|
|
8232
|
+
});
|
|
8233
|
+
function cleanParams(params, data) {
|
|
8234
|
+
let p = typeof params == "function" ? params(data) : typeof params == "string" ? { message: params } : params;
|
|
8235
|
+
return typeof p == "string" ? { message: p } : p;
|
|
8236
|
+
}
|
|
8237
|
+
function custom(check, _params = {}, fatal) {
|
|
8238
|
+
return check ? ZodAny.create().superRefine((data, ctx) => {
|
|
8239
|
+
let r = check(data);
|
|
8240
|
+
if (r instanceof Promise)
|
|
8241
|
+
return r.then((r2) => {
|
|
8242
|
+
if (!r2) {
|
|
8243
|
+
let params = cleanParams(_params, data), _fatal = params.fatal ?? fatal ?? !0;
|
|
8244
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
8245
|
+
}
|
|
8246
|
+
});
|
|
8247
|
+
if (!r) {
|
|
8248
|
+
let params = cleanParams(_params, data), _fatal = params.fatal ?? fatal ?? !0;
|
|
8249
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
8250
|
+
}
|
|
8251
|
+
}) : ZodAny.create();
|
|
8252
|
+
}
|
|
8253
|
+
var late = {
|
|
8254
|
+
object: ZodObject.lazycreate
|
|
8255
|
+
}, ZodFirstPartyTypeKind;
|
|
8256
|
+
(function(ZodFirstPartyTypeKind2) {
|
|
8257
|
+
ZodFirstPartyTypeKind2.ZodString = "ZodString", ZodFirstPartyTypeKind2.ZodNumber = "ZodNumber", ZodFirstPartyTypeKind2.ZodNaN = "ZodNaN", ZodFirstPartyTypeKind2.ZodBigInt = "ZodBigInt", ZodFirstPartyTypeKind2.ZodBoolean = "ZodBoolean", ZodFirstPartyTypeKind2.ZodDate = "ZodDate", ZodFirstPartyTypeKind2.ZodSymbol = "ZodSymbol", ZodFirstPartyTypeKind2.ZodUndefined = "ZodUndefined", ZodFirstPartyTypeKind2.ZodNull = "ZodNull", ZodFirstPartyTypeKind2.ZodAny = "ZodAny", ZodFirstPartyTypeKind2.ZodUnknown = "ZodUnknown", ZodFirstPartyTypeKind2.ZodNever = "ZodNever", ZodFirstPartyTypeKind2.ZodVoid = "ZodVoid", ZodFirstPartyTypeKind2.ZodArray = "ZodArray", ZodFirstPartyTypeKind2.ZodObject = "ZodObject", ZodFirstPartyTypeKind2.ZodUnion = "ZodUnion", ZodFirstPartyTypeKind2.ZodDiscriminatedUnion = "ZodDiscriminatedUnion", ZodFirstPartyTypeKind2.ZodIntersection = "ZodIntersection", ZodFirstPartyTypeKind2.ZodTuple = "ZodTuple", ZodFirstPartyTypeKind2.ZodRecord = "ZodRecord", ZodFirstPartyTypeKind2.ZodMap = "ZodMap", ZodFirstPartyTypeKind2.ZodSet = "ZodSet", ZodFirstPartyTypeKind2.ZodFunction = "ZodFunction", ZodFirstPartyTypeKind2.ZodLazy = "ZodLazy", ZodFirstPartyTypeKind2.ZodLiteral = "ZodLiteral", ZodFirstPartyTypeKind2.ZodEnum = "ZodEnum", ZodFirstPartyTypeKind2.ZodEffects = "ZodEffects", ZodFirstPartyTypeKind2.ZodNativeEnum = "ZodNativeEnum", ZodFirstPartyTypeKind2.ZodOptional = "ZodOptional", ZodFirstPartyTypeKind2.ZodNullable = "ZodNullable", ZodFirstPartyTypeKind2.ZodDefault = "ZodDefault", ZodFirstPartyTypeKind2.ZodCatch = "ZodCatch", ZodFirstPartyTypeKind2.ZodPromise = "ZodPromise", ZodFirstPartyTypeKind2.ZodBranded = "ZodBranded", ZodFirstPartyTypeKind2.ZodPipeline = "ZodPipeline", ZodFirstPartyTypeKind2.ZodReadonly = "ZodReadonly";
|
|
8258
|
+
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
8259
|
+
var instanceOfType = (cls, params = {
|
|
8260
|
+
message: `Input not instance of ${cls.name}`
|
|
8261
|
+
}) => custom((data) => data instanceof cls, params), stringType = ZodString.create, numberType = ZodNumber.create, nanType = ZodNaN.create, bigIntType = ZodBigInt.create, booleanType = ZodBoolean.create, dateType = ZodDate.create, symbolType = ZodSymbol.create, undefinedType = ZodUndefined.create, nullType = ZodNull.create, anyType = ZodAny.create, unknownType = ZodUnknown.create, neverType = ZodNever.create, voidType = ZodVoid.create, arrayType = ZodArray.create, objectType = ZodObject.create, strictObjectType = ZodObject.strictCreate, unionType = ZodUnion.create, discriminatedUnionType = ZodDiscriminatedUnion.create, intersectionType = ZodIntersection.create, tupleType = ZodTuple.create, recordType = ZodRecord.create, mapType = ZodMap.create, setType = ZodSet.create, functionType = ZodFunction.create, lazyType = ZodLazy.create, literalType = ZodLiteral.create, enumType = ZodEnum.create, nativeEnumType = ZodNativeEnum.create, promiseType = ZodPromise.create, effectsType = ZodEffects.create, optionalType = ZodOptional.create, nullableType = ZodNullable.create, preprocessType = ZodEffects.createWithPreprocess, pipelineType = ZodPipeline.create, ostring = () => stringType().optional(), onumber = () => numberType().optional(), oboolean = () => booleanType().optional(), coerce = {
|
|
8262
|
+
string: ((arg) => ZodString.create({ ...arg, coerce: !0 })),
|
|
8263
|
+
number: ((arg) => ZodNumber.create({ ...arg, coerce: !0 })),
|
|
8264
|
+
boolean: ((arg) => ZodBoolean.create({
|
|
8265
|
+
...arg,
|
|
8266
|
+
coerce: !0
|
|
8267
|
+
})),
|
|
8268
|
+
bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: !0 })),
|
|
8269
|
+
date: ((arg) => ZodDate.create({ ...arg, coerce: !0 }))
|
|
8270
|
+
};
|
|
8271
|
+
var NEVER = INVALID;
|
|
8272
|
+
|
|
8273
|
+
// ../cli-kit/dist/public/common/json-output-schema.js
|
|
8274
|
+
var jsonOutputTimestampSchema = external_exports.string().datetime({ precision: 0 }).regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/).describe("A UTC ISO 8601 instant with whole seconds and the Z timezone marker.");
|
|
8275
|
+
function formatJsonOutputTimestamp(date) {
|
|
8276
|
+
return date.toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
8277
|
+
}
|
|
8278
|
+
|
|
8279
|
+
// ../cli-kit/dist/public/common/command-events.js
|
|
8280
|
+
var commandDiagnosticEventSchema = external_exports.object({
|
|
8281
|
+
type: external_exports.literal("diagnostic"),
|
|
8282
|
+
timestamp: jsonOutputTimestampSchema,
|
|
8283
|
+
level: external_exports.enum(["debug", "info", "warning", "error"]),
|
|
8284
|
+
message: external_exports.string(),
|
|
8285
|
+
code: external_exports.string().min(1).optional().describe("A stable diagnostic code, included only when known.")
|
|
8286
|
+
}).strict(), commandProgressEventSchema = external_exports.object({
|
|
8287
|
+
type: external_exports.literal("progress"),
|
|
8288
|
+
timestamp: jsonOutputTimestampSchema,
|
|
8289
|
+
status: external_exports.enum(["started", "updated", "retrying", "completed", "failed"]),
|
|
8290
|
+
operation: external_exports.string(),
|
|
8291
|
+
message: external_exports.string().optional(),
|
|
8292
|
+
current: external_exports.number().int().nonnegative().optional(),
|
|
8293
|
+
total: external_exports.number().int().nonnegative().optional()
|
|
8294
|
+
}).strict(), commandEventSchema = external_exports.discriminatedUnion("type", [
|
|
8295
|
+
commandDiagnosticEventSchema,
|
|
8296
|
+
commandProgressEventSchema
|
|
8297
|
+
]);
|
|
8298
|
+
function createCommandEventChannel(options = {}) {
|
|
8299
|
+
let sink = options.sink ?? (() => {
|
|
8300
|
+
}), clock = options.clock ?? (() => /* @__PURE__ */ new Date());
|
|
8301
|
+
return {
|
|
8302
|
+
emit(event, emissionOptions) {
|
|
8303
|
+
let timestamp = formatJsonOutputTimestamp(clock()), timestampedEvent = { ...event, timestamp };
|
|
8304
|
+
emissionOptions === void 0 ? sink(timestampedEvent) : sink(timestampedEvent, emissionOptions);
|
|
8305
|
+
}
|
|
8306
|
+
};
|
|
8307
|
+
}
|
|
8308
|
+
|
|
8309
|
+
// ../cli-kit/dist/private/node/command-event-context.js
|
|
8310
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8311
|
+
function runWithCommandEvents(options, execute) {
|
|
8312
|
+
return getCommandEventStorage().run({
|
|
8313
|
+
channel: createCommandEventChannel(options),
|
|
8314
|
+
outputMode: options.outputMode ?? "text"
|
|
8315
|
+
}, execute);
|
|
8316
|
+
}
|
|
8317
|
+
function emitCommandEvent(event, options) {
|
|
8318
|
+
getCommandEventStorage().getStore()?.channel.emit(event, options);
|
|
8319
|
+
}
|
|
8320
|
+
function commandEventOutputMode() {
|
|
8321
|
+
return getCommandEventStorage().getStore()?.outputMode;
|
|
8322
|
+
}
|
|
8323
|
+
function getCommandEventStorage() {
|
|
8324
|
+
let key = /* @__PURE__ */ Symbol.for("command-event-storage"), sharedGlobal = globalThis;
|
|
8325
|
+
return sharedGlobal[key] ??= new AsyncLocalStorage(), sharedGlobal[key];
|
|
8326
|
+
}
|
|
5290
8327
|
|
|
5291
8328
|
// ../cli-kit/dist/private/node/output.js
|
|
5292
8329
|
init_cjs_shims();
|
|
@@ -5298,8 +8335,7 @@ function consoleLog(message) {
|
|
|
5298
8335
|
`);
|
|
5299
8336
|
}
|
|
5300
8337
|
function consoleWarn(message) {
|
|
5301
|
-
|
|
5302
|
-
`);
|
|
8338
|
+
console.warn(withOrWithoutStyle(message));
|
|
5303
8339
|
}
|
|
5304
8340
|
function output(content, logLevel = "info", logger = consoleWarn) {
|
|
5305
8341
|
isUnitTest() && collectLog(logLevel, content);
|
|
@@ -5456,31 +8492,46 @@ var clearCollectedLogs = () => {
|
|
|
5456
8492
|
function outputResult(content) {
|
|
5457
8493
|
output(content, "info", consoleLog);
|
|
5458
8494
|
}
|
|
8495
|
+
async function flushStdout() {
|
|
8496
|
+
await new Promise((resolve, reject) => {
|
|
8497
|
+
process.stdout.write("", (error) => {
|
|
8498
|
+
error ? reject(error) : resolve();
|
|
8499
|
+
});
|
|
8500
|
+
});
|
|
8501
|
+
}
|
|
5459
8502
|
function outputInfo(content, logger = consoleWarn) {
|
|
8503
|
+
if (emitJsonDiagnostic(content, "info", logger))
|
|
8504
|
+
return;
|
|
5460
8505
|
let message = stringifyMessage(content);
|
|
5461
8506
|
isUnitTest() && collectLog("info", content), outputWhereAppropriate("info", logger, message);
|
|
5462
8507
|
}
|
|
5463
8508
|
function outputSuccess(content, logger = consoleWarn) {
|
|
8509
|
+
if (emitJsonDiagnostic(content, "info", logger))
|
|
8510
|
+
return;
|
|
5464
8511
|
let message = source_default.bold(`\u2705 Success! ${stringifyMessage(content)}.`);
|
|
5465
8512
|
isUnitTest() && collectLog("success", content), outputWhereAppropriate("info", logger, message);
|
|
5466
8513
|
}
|
|
5467
8514
|
function outputCompleted(content, logger = consoleWarn) {
|
|
8515
|
+
if (emitJsonDiagnostic(content, "info", logger))
|
|
8516
|
+
return;
|
|
5468
8517
|
let message = `${source_default.green("\u2714")} ${stringifyMessage(content)}`;
|
|
5469
8518
|
isUnitTest() && collectLog("completed", content), outputWhereAppropriate("info", logger, message);
|
|
5470
8519
|
}
|
|
5471
8520
|
function outputDebug(content, logger = consoleWarn) {
|
|
5472
|
-
if (isUnitTest() && collectLog("debug", content), !shouldOutput("debug"))
|
|
8521
|
+
if (emitJsonDiagnostic(content, "debug", logger) || (isUnitTest() && collectLog("debug", content), !shouldOutput("debug")))
|
|
5473
8522
|
return;
|
|
5474
8523
|
let message = source_default.gray(stringifyMessage(content));
|
|
5475
8524
|
outputWhereAppropriate("debug", logger, `${(/* @__PURE__ */ new Date()).toISOString()}: ${message}`);
|
|
5476
8525
|
}
|
|
5477
8526
|
function outputWarn(content, logger = consoleWarn) {
|
|
8527
|
+
if (emitJsonDiagnostic(content, "warning", logger))
|
|
8528
|
+
return;
|
|
5478
8529
|
isUnitTest() && collectLog("warn", content);
|
|
5479
8530
|
let message = source_default.yellow(stringifyMessage(content));
|
|
5480
8531
|
outputWhereAppropriate("warn", logger, message);
|
|
5481
8532
|
}
|
|
5482
8533
|
function outputNewline() {
|
|
5483
|
-
consoleWarn("");
|
|
8534
|
+
commandEventOutputMode() !== "json" && consoleWarn("");
|
|
5484
8535
|
}
|
|
5485
8536
|
function stringifyMessage(message) {
|
|
5486
8537
|
return message instanceof TokenizedString ? message.value : message;
|
|
@@ -5494,6 +8545,14 @@ function outputWhereAppropriate(logLevel, logger, message) {
|
|
|
5494
8545
|
function unstyled(message) {
|
|
5495
8546
|
return message.includes("\x1B") ? stripAnsi(message) : message;
|
|
5496
8547
|
}
|
|
8548
|
+
function emitJsonDiagnostic(content, level, logger) {
|
|
8549
|
+
if (logger !== consoleWarn || commandEventOutputMode() !== "json")
|
|
8550
|
+
return !1;
|
|
8551
|
+
if (level === "debug" && !isUnitTest() && !shouldOutput("debug"))
|
|
8552
|
+
return !0;
|
|
8553
|
+
let message = unstyled(stringifyMessage(content));
|
|
8554
|
+
return message.trim().length > 0 && emitCommandEvent({ type: "diagnostic", level, message }), !0;
|
|
8555
|
+
}
|
|
5497
8556
|
function shouldDisplayColors(_process = process) {
|
|
5498
8557
|
if (_process === process && memoizedShouldDisplayColors !== void 0)
|
|
5499
8558
|
return memoizedShouldDisplayColors;
|
|
@@ -5531,7 +8590,7 @@ function asHumanFriendlyArray(items) {
|
|
|
5531
8590
|
}
|
|
5532
8591
|
|
|
5533
8592
|
// ../cli-kit/dist/public/common/string.js
|
|
5534
|
-
var import_change_case = __toESM(require_dist15()
|
|
8593
|
+
var import_change_case = __toESM(require_dist15()), SAFE_RANDOM_BUSINESS_ADJECTIVES = [
|
|
5535
8594
|
"commercial",
|
|
5536
8595
|
"profitable",
|
|
5537
8596
|
"amortizable",
|
|
@@ -7045,8 +10104,8 @@ async function mkdir(path4) {
|
|
|
7045
10104
|
function mkdirSync(path4) {
|
|
7046
10105
|
outputDebug(outputContent`Sync-creating directory at ${outputToken.path(path4)}...`), fsMkdirSync(path4, { recursive: !0 });
|
|
7047
10106
|
}
|
|
7048
|
-
async function removeFile(path4) {
|
|
7049
|
-
outputDebug(outputContent`Removing file at ${outputToken.path(path4)}...`), await
|
|
10107
|
+
async function removeFile(path4, options = {}) {
|
|
10108
|
+
outputDebug(outputContent`Removing file at ${outputToken.path(path4)}...`), await fsRm(path4, { recursive: !0, force: !0, ...options });
|
|
7050
10109
|
}
|
|
7051
10110
|
async function renameFile(from, to) {
|
|
7052
10111
|
outputDebug(outputContent`Renaming file from ${outputToken.path(from)} to ${outputToken.path(to)}...`), await fsRename(from, to);
|
|
@@ -7315,12 +10374,22 @@ export {
|
|
|
7315
10374
|
copyDirectoryContents,
|
|
7316
10375
|
tokenItemToString,
|
|
7317
10376
|
appendToTokenItem,
|
|
10377
|
+
tokenItemToJsonString,
|
|
10378
|
+
ZodFirstPartyTypeKind,
|
|
10379
|
+
external_exports,
|
|
10380
|
+
commandDiagnosticEventSchema,
|
|
10381
|
+
commandProgressEventSchema,
|
|
10382
|
+
commandEventSchema,
|
|
10383
|
+
consoleWarn,
|
|
10384
|
+
output,
|
|
10385
|
+
runWithCommandEvents,
|
|
10386
|
+
emitCommandEvent,
|
|
10387
|
+
commandEventOutputMode,
|
|
7318
10388
|
currentProcessIsGlobal,
|
|
7319
10389
|
installGlobalShopifyCLI,
|
|
7320
10390
|
installGlobalCLIPrompt,
|
|
7321
10391
|
inferPackageManagerForGlobalCLI,
|
|
7322
10392
|
getProjectDir,
|
|
7323
|
-
output,
|
|
7324
10393
|
stripAnsi,
|
|
7325
10394
|
source_default,
|
|
7326
10395
|
ansi_escapes_default,
|
|
@@ -7334,6 +10403,7 @@ export {
|
|
|
7334
10403
|
collectLog,
|
|
7335
10404
|
clearCollectedLogs,
|
|
7336
10405
|
outputResult,
|
|
10406
|
+
flushStdout,
|
|
7337
10407
|
outputInfo,
|
|
7338
10408
|
outputSuccess,
|
|
7339
10409
|
outputCompleted,
|
|
@@ -7347,4 +10417,4 @@ export {
|
|
|
7347
10417
|
shouldDisplayColors,
|
|
7348
10418
|
formatSection
|
|
7349
10419
|
};
|
|
7350
|
-
//# sourceMappingURL=chunk-
|
|
10420
|
+
//# sourceMappingURL=chunk-AJLJXEKT.js.map
|