storybook 10.1.0-alpha.10 → 10.1.0-alpha.11
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/_browser-chunks/Color-FTG7SQDA.js +1097 -0
- package/dist/_browser-chunks/WithTooltip-LMROHDUP.js +1651 -0
- package/dist/_browser-chunks/chunk-2FRVAXCZ.js +7 -0
- package/dist/_browser-chunks/chunk-3IAH5M2U.js +171 -0
- package/dist/_browser-chunks/chunk-3OXGAGBE.js +779 -0
- package/dist/_browser-chunks/{chunk-TMDZCWME.js → chunk-3PJE6VLG.js} +1 -3
- package/dist/_browser-chunks/{chunk-VAMFPZY3.js → chunk-45UGUKRX.js} +2 -7
- package/dist/_browser-chunks/chunk-6XWLIJQL.js +11 -0
- package/dist/_browser-chunks/{chunk-FDWKXLBI.js → chunk-74YHFU5B.js} +44 -109
- package/dist/_browser-chunks/{chunk-MM7DTO55.js → chunk-A242L54C.js} +10 -16
- package/dist/_browser-chunks/chunk-AIOS4NGK.js +252 -0
- package/dist/_browser-chunks/chunk-AS2HQEYC.js +14 -0
- package/dist/_browser-chunks/chunk-AXG2BOBL.js +836 -0
- package/dist/_browser-chunks/chunk-BE2DAXKJ.js +2966 -0
- package/dist/_browser-chunks/{chunk-MH6AXFXB.js → chunk-CHUV5WSW.js} +0 -5
- package/dist/_browser-chunks/chunk-EBHB6RPS.js +61 -0
- package/dist/_browser-chunks/chunk-EUVGDK4H.js +93 -0
- package/dist/_browser-chunks/chunk-EZSQOHRI.js +18 -0
- package/dist/_browser-chunks/{chunk-CADGRH3P.js → chunk-FNXWN6IK.js} +3 -8
- package/dist/_browser-chunks/chunk-GFLS4VP3.js +64 -0
- package/dist/_browser-chunks/{chunk-L2D73C6Z.js → chunk-H6XK3RSC.js} +13 -21
- package/dist/_browser-chunks/chunk-IPA5A322.js +71 -0
- package/dist/_browser-chunks/chunk-JP7NCOJX.js +37 -0
- package/dist/_browser-chunks/chunk-KJHJLCBK.js +11 -0
- package/dist/_browser-chunks/{chunk-QMY4G4R2.js → chunk-L4RMQ7D7.js} +17 -64
- package/dist/_browser-chunks/{chunk-AB7OOPUX.js → chunk-QKODTO7K.js} +0 -5
- package/dist/_browser-chunks/chunk-RP5RXKFU.js +2491 -0
- package/dist/_browser-chunks/chunk-SL75JR6Y.js +9 -0
- package/dist/_browser-chunks/chunk-UD6FQLAF.js +1481 -0
- package/dist/_browser-chunks/chunk-VYJQ7RU5.js +2853 -0
- package/dist/_browser-chunks/chunk-WJYERY3R.js +136 -0
- package/dist/_browser-chunks/chunk-WXP2XJ3O.js +950 -0
- package/dist/_browser-chunks/chunk-X3DUQ5RA.js +47 -0
- package/dist/_browser-chunks/chunk-XJNX76GA.js +85 -0
- package/dist/_browser-chunks/{chunk-F4Q6SGTB.js → chunk-YKE5S47A.js} +177 -399
- package/dist/_browser-chunks/{chunk-SN4J4IQ3.js → chunk-ZUWEVLDX.js} +1 -7
- package/dist/_browser-chunks/{formatter-OMEEQ6HG.js → formatter-QJ4M4OGQ.js} +4 -9
- package/dist/_browser-chunks/{syntaxhighlighter-RJZASWHL.js → syntaxhighlighter-WKBQ5RC7.js} +704 -1848
- package/dist/_node-chunks/{builder-manager-HA7CYFCK.js → builder-manager-PMPHOSM2.js} +475 -1013
- package/dist/_node-chunks/camelcase-K3IOOFQW.js +18 -0
- package/dist/_node-chunks/{chunk-X4XU27M6.js → chunk-32NE3UE3.js} +15 -24
- package/dist/_node-chunks/chunk-4GZCFQFG.js +58 -0
- package/dist/_node-chunks/chunk-5QK5MSOI.js +943 -0
- package/dist/_node-chunks/{chunk-VPR5IBMG.js → chunk-6ZOLETQK.js} +8 -10
- package/dist/_node-chunks/chunk-7I22Y76Z.js +1047 -0
- package/dist/_node-chunks/chunk-AKTRSR3O.js +72 -0
- package/dist/_node-chunks/chunk-BBOP3XCK.js +119 -0
- package/dist/_node-chunks/chunk-C2GQVDWI.js +34 -0
- package/dist/_node-chunks/{chunk-ZHSCUGNP.js → chunk-GG2WQZSG.js} +3799 -7849
- package/dist/_node-chunks/chunk-GQJOWVVR.js +3214 -0
- package/dist/_node-chunks/chunk-JCRM2YVK.js +3009 -0
- package/dist/_node-chunks/chunk-KK4AT5F3.js +1029 -0
- package/dist/_node-chunks/chunk-L7MYXJUM.js +1114 -0
- package/dist/_node-chunks/{chunk-F3XOPI6H.js → chunk-LCZO45L7.js} +469 -983
- package/dist/_node-chunks/chunk-LR3QITDI.js +209 -0
- package/dist/_node-chunks/chunk-LXG4DK35.js +3171 -0
- package/dist/_node-chunks/chunk-MJ3WOS6F.js +37 -0
- package/dist/_node-chunks/chunk-PHOZWZZO.js +61 -0
- package/dist/_node-chunks/chunk-QECOQWRJ.js +936 -0
- package/dist/_node-chunks/chunk-QH4V5YDB.js +20 -0
- package/dist/_node-chunks/chunk-R6HWGZWD.js +26 -0
- package/dist/_node-chunks/chunk-SPQXMU2Q.js +759 -0
- package/dist/_node-chunks/chunk-TXZY6V6O.js +1564 -0
- package/dist/_node-chunks/chunk-UGDPX5LE.js +756 -0
- package/dist/_node-chunks/chunk-UY26MQLT.js +603 -0
- package/dist/_node-chunks/chunk-WK3EMYK6.js +61 -0
- package/dist/_node-chunks/{chunk-OVXB5GGT.js → chunk-WLHMN7AP.js} +292 -688
- package/dist/_node-chunks/chunk-XGVLB4UJ.js +54 -0
- package/dist/_node-chunks/{chunk-RMHAL25C.js → chunk-YHRFI6BE.js} +87 -227
- package/dist/_node-chunks/chunk-YK4KVMFW.js +18 -0
- package/dist/_node-chunks/chunk-ZZALGOA6.js +4523 -0
- package/dist/_node-chunks/chunk-ZZPBSYA5.js +301 -0
- package/dist/_node-chunks/chunk-ZZSRFAC6.js +45571 -0
- package/dist/_node-chunks/dist-4DWOCZUD.js +121 -0
- package/dist/_node-chunks/globby-AAARUKEU.js +3452 -0
- package/dist/_node-chunks/lib-HEUKGL62.js +366 -0
- package/dist/_node-chunks/mdx-N42X6CFJ-DCVRPS6N.js +14329 -0
- package/dist/_node-chunks/p-limit-F5ZKJ6WZ.js +116 -0
- package/dist/_node-chunks/plugin-7YY7JXCH.js +123 -0
- package/dist/_node-chunks/{plugin-6ZPCS4LI.js → plugin-SZP3CW6W.js} +36 -56
- package/dist/_node-chunks/webpack-inject-mocker-runtime-plugin-TGKNDPO6.js +46623 -0
- package/dist/_node-chunks/webpack-mock-plugin-LNTZZFBE.js +92 -0
- package/dist/actions/decorator.js +21 -42
- package/dist/actions/index.js +3 -3
- package/dist/babel/index.d.ts +671 -335
- package/dist/babel/index.js +11 -11
- package/dist/bin/core.js +592 -1546
- package/dist/bin/dispatcher.js +26 -37
- package/dist/bin/loader.js +23 -34
- package/dist/channels/index.js +98 -234
- package/dist/cli/index.js +1951 -5308
- package/dist/client-logger/index.js +31 -61
- package/dist/common/index.js +20 -20
- package/dist/components/index.js +4211 -8586
- package/dist/core-events/index.js +2 -66
- package/dist/core-server/index.js +3054 -7290
- package/dist/core-server/presets/common-manager.css +2 -2
- package/dist/core-server/presets/common-manager.js +1806 -3427
- package/dist/core-server/presets/common-override-preset.js +31 -60
- package/dist/core-server/presets/common-preset.js +434 -924
- package/dist/core-server/presets/webpack/loaders/storybook-mock-transform-loader.js +15 -19
- package/dist/core-server/presets/webpack/loaders/webpack-automock-loader.js +12 -17
- package/dist/csf/index.js +534 -1179
- package/dist/csf-tools/index.js +9 -9
- package/dist/docs-tools/index.js +6 -6
- package/dist/highlight/index.js +2 -2
- package/dist/instrumenter/index.js +199 -415
- package/dist/manager/globals-runtime.js +24150 -47364
- package/dist/manager/globals.js +2 -3
- package/dist/manager/runtime.js +3961 -8373
- package/dist/manager-api/index.js +1231 -2425
- package/dist/manager-errors.d.ts +3 -0
- package/dist/manager-errors.js +3 -3
- package/dist/node-logger/index.js +1253 -2601
- package/dist/preview/globals.js +2 -3
- package/dist/preview/runtime.js +10364 -21990
- package/dist/preview-api/index.d.ts +67 -68
- package/dist/preview-api/index.js +13 -13
- package/dist/preview-errors.d.ts +3 -0
- package/dist/preview-errors.js +4 -4
- package/dist/router/index.js +347 -899
- package/dist/server-errors.d.ts +3 -0
- package/dist/server-errors.js +10 -10
- package/dist/telemetry/index.js +24 -24
- package/dist/test/index.js +5860 -11645
- package/dist/theming/create.js +4 -4
- package/dist/theming/index.d.ts +3363 -2597
- package/dist/theming/index.js +490 -1086
- package/dist/types/index.js +2 -11
- package/dist/viewport/index.js +3 -3
- package/package.json +5 -5
- package/dist/_browser-chunks/Color-FQNEU7YS.js +0 -1695
- package/dist/_browser-chunks/WithTooltip-6NHN2GXF.js +0 -2343
- package/dist/_browser-chunks/chunk-6A7OIVEL.js +0 -66
- package/dist/_browser-chunks/chunk-AW46NMGV.js +0 -1308
- package/dist/_browser-chunks/chunk-B4A3ADP3.js +0 -3816
- package/dist/_browser-chunks/chunk-FSBVR7H5.js +0 -106
- package/dist/_browser-chunks/chunk-FUOHXXZT.js +0 -23
- package/dist/_browser-chunks/chunk-GTKOCWCT.js +0 -17
- package/dist/_browser-chunks/chunk-HHW4FUMO.js +0 -12
- package/dist/_browser-chunks/chunk-JVSKG4YS.js +0 -4052
- package/dist/_browser-chunks/chunk-LASUB7TL.js +0 -76
- package/dist/_browser-chunks/chunk-LYCSRYYR.js +0 -101
- package/dist/_browser-chunks/chunk-NVV6MIOE.js +0 -243
- package/dist/_browser-chunks/chunk-OBXWFEPB.js +0 -852
- package/dist/_browser-chunks/chunk-OPCDBBL3.js +0 -48
- package/dist/_browser-chunks/chunk-PB6FZ3WE.js +0 -130
- package/dist/_browser-chunks/chunk-RW5PKMWM.js +0 -4182
- package/dist/_browser-chunks/chunk-SYS437NN.js +0 -122
- package/dist/_browser-chunks/chunk-U46RQHA4.js +0 -12
- package/dist/_browser-chunks/chunk-UTNZYD2N.js +0 -311
- package/dist/_browser-chunks/chunk-VUAFL5XK.js +0 -20
- package/dist/_browser-chunks/chunk-XDGMHOV7.js +0 -2197
- package/dist/_browser-chunks/chunk-XW6KSYKF.js +0 -16
- package/dist/_browser-chunks/chunk-Y3M7TW6K.js +0 -1041
- package/dist/_browser-chunks/chunk-ZNRFDIVA.js +0 -233
- package/dist/_node-chunks/camelcase-QALD4XFE.js +0 -18
- package/dist/_node-chunks/chunk-2XY53ALL.js +0 -420
- package/dist/_node-chunks/chunk-3CBQMG2A.js +0 -6712
- package/dist/_node-chunks/chunk-3WDAPZYQ.js +0 -28
- package/dist/_node-chunks/chunk-4ZB555EJ.js +0 -697
- package/dist/_node-chunks/chunk-52DXKXY3.js +0 -4272
- package/dist/_node-chunks/chunk-5OVB4A6F.js +0 -69
- package/dist/_node-chunks/chunk-AGHGNXGH.js +0 -18
- package/dist/_node-chunks/chunk-B23X5ZCK.js +0 -1531
- package/dist/_node-chunks/chunk-B2DAHWJK.js +0 -220
- package/dist/_node-chunks/chunk-CC4PW5MJ.js +0 -34
- package/dist/_node-chunks/chunk-D7NIZELR.js +0 -2256
- package/dist/_node-chunks/chunk-DO5Q3H4L.js +0 -1250
- package/dist/_node-chunks/chunk-ECK7WVFX.js +0 -304
- package/dist/_node-chunks/chunk-EUH3NHXA.js +0 -79
- package/dist/_node-chunks/chunk-FOQHPHCV.js +0 -1657
- package/dist/_node-chunks/chunk-G6EL47NS.js +0 -111
- package/dist/_node-chunks/chunk-GFLS4TJB.js +0 -90
- package/dist/_node-chunks/chunk-J3XZKWHE.js +0 -1586
- package/dist/_node-chunks/chunk-LE63EHJ5.js +0 -1518
- package/dist/_node-chunks/chunk-M47XA42S.js +0 -4741
- package/dist/_node-chunks/chunk-OOI74AL3.js +0 -61
- package/dist/_node-chunks/chunk-PRJHT3GJ.js +0 -61
- package/dist/_node-chunks/chunk-Q52PVUSU.js +0 -101
- package/dist/_node-chunks/chunk-SDCF5RNN.js +0 -1198
- package/dist/_node-chunks/chunk-UJ5SJ23M.js +0 -5029
- package/dist/_node-chunks/chunk-UPHK4ETU.js +0 -64658
- package/dist/_node-chunks/chunk-V7VURIPB.js +0 -1544
- package/dist/_node-chunks/dist-6TXHNR5C.js +0 -175
- package/dist/_node-chunks/globby-PBTV6PX6.js +0 -5222
- package/dist/_node-chunks/lib-4RTDZVGX.js +0 -518
- package/dist/_node-chunks/mdx-N42X6CFJ-COWEH7KR.js +0 -22017
- package/dist/_node-chunks/p-limit-PBVZQOFY.js +0 -168
- package/dist/_node-chunks/plugin-EOZKYZAG.js +0 -159
- package/dist/_node-chunks/webpack-inject-mocker-runtime-plugin-35HMSMR5.js +0 -69102
- package/dist/_node-chunks/webpack-mock-plugin-GT3MA5E2.js +0 -124
|
@@ -0,0 +1,3009 @@
|
|
|
1
|
+
import CJS_COMPAT_NODE_URL_843v2rliy1 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_843v2rliy1 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_843v2rliy1 from "node:module";
|
|
4
|
+
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_843v2rliy1.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_843v2rliy1.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_843v2rliy1.createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
// ------------------------------------------------------------
|
|
10
|
+
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
+
// ------------------------------------------------------------
|
|
12
|
+
import {
|
|
13
|
+
require_dist
|
|
14
|
+
} from "./chunk-PHOZWZZO.js";
|
|
15
|
+
import {
|
|
16
|
+
__export,
|
|
17
|
+
__toESM
|
|
18
|
+
} from "./chunk-XGVLB4UJ.js";
|
|
19
|
+
|
|
20
|
+
// src/cli/globalSettings.ts
|
|
21
|
+
var import_ts_dedent = __toESM(require_dist(), 1);
|
|
22
|
+
import fs from "node:fs/promises";
|
|
23
|
+
import { homedir } from "node:os";
|
|
24
|
+
import { dirname, join } from "node:path";
|
|
25
|
+
|
|
26
|
+
// ../node_modules/zod/v3/external.js
|
|
27
|
+
var external_exports = {};
|
|
28
|
+
__export(external_exports, {
|
|
29
|
+
BRAND: () => BRAND,
|
|
30
|
+
DIRTY: () => DIRTY,
|
|
31
|
+
EMPTY_PATH: () => EMPTY_PATH,
|
|
32
|
+
INVALID: () => INVALID,
|
|
33
|
+
NEVER: () => NEVER,
|
|
34
|
+
OK: () => OK,
|
|
35
|
+
ParseStatus: () => ParseStatus,
|
|
36
|
+
Schema: () => ZodType,
|
|
37
|
+
ZodAny: () => ZodAny,
|
|
38
|
+
ZodArray: () => ZodArray,
|
|
39
|
+
ZodBigInt: () => ZodBigInt,
|
|
40
|
+
ZodBoolean: () => ZodBoolean,
|
|
41
|
+
ZodBranded: () => ZodBranded,
|
|
42
|
+
ZodCatch: () => ZodCatch,
|
|
43
|
+
ZodDate: () => ZodDate,
|
|
44
|
+
ZodDefault: () => ZodDefault,
|
|
45
|
+
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
46
|
+
ZodEffects: () => ZodEffects,
|
|
47
|
+
ZodEnum: () => ZodEnum,
|
|
48
|
+
ZodError: () => ZodError,
|
|
49
|
+
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
50
|
+
ZodFunction: () => ZodFunction,
|
|
51
|
+
ZodIntersection: () => ZodIntersection,
|
|
52
|
+
ZodIssueCode: () => ZodIssueCode,
|
|
53
|
+
ZodLazy: () => ZodLazy,
|
|
54
|
+
ZodLiteral: () => ZodLiteral,
|
|
55
|
+
ZodMap: () => ZodMap,
|
|
56
|
+
ZodNaN: () => ZodNaN,
|
|
57
|
+
ZodNativeEnum: () => ZodNativeEnum,
|
|
58
|
+
ZodNever: () => ZodNever,
|
|
59
|
+
ZodNull: () => ZodNull,
|
|
60
|
+
ZodNullable: () => ZodNullable,
|
|
61
|
+
ZodNumber: () => ZodNumber,
|
|
62
|
+
ZodObject: () => ZodObject,
|
|
63
|
+
ZodOptional: () => ZodOptional,
|
|
64
|
+
ZodParsedType: () => ZodParsedType,
|
|
65
|
+
ZodPipeline: () => ZodPipeline,
|
|
66
|
+
ZodPromise: () => ZodPromise,
|
|
67
|
+
ZodReadonly: () => ZodReadonly,
|
|
68
|
+
ZodRecord: () => ZodRecord,
|
|
69
|
+
ZodSchema: () => ZodType,
|
|
70
|
+
ZodSet: () => ZodSet,
|
|
71
|
+
ZodString: () => ZodString,
|
|
72
|
+
ZodSymbol: () => ZodSymbol,
|
|
73
|
+
ZodTransformer: () => ZodEffects,
|
|
74
|
+
ZodTuple: () => ZodTuple,
|
|
75
|
+
ZodType: () => ZodType,
|
|
76
|
+
ZodUndefined: () => ZodUndefined,
|
|
77
|
+
ZodUnion: () => ZodUnion,
|
|
78
|
+
ZodUnknown: () => ZodUnknown,
|
|
79
|
+
ZodVoid: () => ZodVoid,
|
|
80
|
+
addIssueToContext: () => addIssueToContext,
|
|
81
|
+
any: () => anyType,
|
|
82
|
+
array: () => arrayType,
|
|
83
|
+
bigint: () => bigIntType,
|
|
84
|
+
boolean: () => booleanType,
|
|
85
|
+
coerce: () => coerce,
|
|
86
|
+
custom: () => custom,
|
|
87
|
+
date: () => dateType,
|
|
88
|
+
datetimeRegex: () => datetimeRegex,
|
|
89
|
+
defaultErrorMap: () => en_default,
|
|
90
|
+
discriminatedUnion: () => discriminatedUnionType,
|
|
91
|
+
effect: () => effectsType,
|
|
92
|
+
enum: () => enumType,
|
|
93
|
+
function: () => functionType,
|
|
94
|
+
getErrorMap: () => getErrorMap,
|
|
95
|
+
getParsedType: () => getParsedType,
|
|
96
|
+
instanceof: () => instanceOfType,
|
|
97
|
+
intersection: () => intersectionType,
|
|
98
|
+
isAborted: () => isAborted,
|
|
99
|
+
isAsync: () => isAsync,
|
|
100
|
+
isDirty: () => isDirty,
|
|
101
|
+
isValid: () => isValid,
|
|
102
|
+
late: () => late,
|
|
103
|
+
lazy: () => lazyType,
|
|
104
|
+
literal: () => literalType,
|
|
105
|
+
makeIssue: () => makeIssue,
|
|
106
|
+
map: () => mapType,
|
|
107
|
+
nan: () => nanType,
|
|
108
|
+
nativeEnum: () => nativeEnumType,
|
|
109
|
+
never: () => neverType,
|
|
110
|
+
null: () => nullType,
|
|
111
|
+
nullable: () => nullableType,
|
|
112
|
+
number: () => numberType,
|
|
113
|
+
object: () => objectType,
|
|
114
|
+
objectUtil: () => objectUtil,
|
|
115
|
+
oboolean: () => oboolean,
|
|
116
|
+
onumber: () => onumber,
|
|
117
|
+
optional: () => optionalType,
|
|
118
|
+
ostring: () => ostring,
|
|
119
|
+
pipeline: () => pipelineType,
|
|
120
|
+
preprocess: () => preprocessType,
|
|
121
|
+
promise: () => promiseType,
|
|
122
|
+
quotelessJson: () => quotelessJson,
|
|
123
|
+
record: () => recordType,
|
|
124
|
+
set: () => setType,
|
|
125
|
+
setErrorMap: () => setErrorMap,
|
|
126
|
+
strictObject: () => strictObjectType,
|
|
127
|
+
string: () => stringType,
|
|
128
|
+
symbol: () => symbolType,
|
|
129
|
+
transformer: () => effectsType,
|
|
130
|
+
tuple: () => tupleType,
|
|
131
|
+
undefined: () => undefinedType,
|
|
132
|
+
union: () => unionType,
|
|
133
|
+
unknown: () => unknownType,
|
|
134
|
+
util: () => util,
|
|
135
|
+
void: () => voidType
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// ../node_modules/zod/v3/helpers/util.js
|
|
139
|
+
var util;
|
|
140
|
+
(function(util2) {
|
|
141
|
+
util2.assertEqual = (_) => {
|
|
142
|
+
};
|
|
143
|
+
function assertIs(_arg) {
|
|
144
|
+
}
|
|
145
|
+
util2.assertIs = assertIs;
|
|
146
|
+
function assertNever(_x) {
|
|
147
|
+
throw new Error();
|
|
148
|
+
}
|
|
149
|
+
util2.assertNever = assertNever, util2.arrayToEnum = (items) => {
|
|
150
|
+
let obj = {};
|
|
151
|
+
for (let item of items)
|
|
152
|
+
obj[item] = item;
|
|
153
|
+
return obj;
|
|
154
|
+
}, util2.getValidEnumValues = (obj) => {
|
|
155
|
+
let validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] != "number"), filtered = {};
|
|
156
|
+
for (let k of validKeys)
|
|
157
|
+
filtered[k] = obj[k];
|
|
158
|
+
return util2.objectValues(filtered);
|
|
159
|
+
}, util2.objectValues = (obj) => util2.objectKeys(obj).map(function(e) {
|
|
160
|
+
return obj[e];
|
|
161
|
+
}), util2.objectKeys = typeof Object.keys == "function" ? (obj) => Object.keys(obj) : (object) => {
|
|
162
|
+
let keys = [];
|
|
163
|
+
for (let key in object)
|
|
164
|
+
Object.prototype.hasOwnProperty.call(object, key) && keys.push(key);
|
|
165
|
+
return keys;
|
|
166
|
+
}, util2.find = (arr, checker) => {
|
|
167
|
+
for (let item of arr)
|
|
168
|
+
if (checker(item))
|
|
169
|
+
return item;
|
|
170
|
+
}, util2.isInteger = typeof Number.isInteger == "function" ? (val) => Number.isInteger(val) : (val) => typeof val == "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
171
|
+
function joinValues(array, separator = " | ") {
|
|
172
|
+
return array.map((val) => typeof val == "string" ? `'${val}'` : val).join(separator);
|
|
173
|
+
}
|
|
174
|
+
util2.joinValues = joinValues, util2.jsonStringifyReplacer = (_, value) => typeof value == "bigint" ? value.toString() : value;
|
|
175
|
+
})(util || (util = {}));
|
|
176
|
+
var objectUtil;
|
|
177
|
+
(function(objectUtil2) {
|
|
178
|
+
objectUtil2.mergeShapes = (first, second) => ({
|
|
179
|
+
...first,
|
|
180
|
+
...second
|
|
181
|
+
// second overwrites first
|
|
182
|
+
});
|
|
183
|
+
})(objectUtil || (objectUtil = {}));
|
|
184
|
+
var ZodParsedType = util.arrayToEnum([
|
|
185
|
+
"string",
|
|
186
|
+
"nan",
|
|
187
|
+
"number",
|
|
188
|
+
"integer",
|
|
189
|
+
"float",
|
|
190
|
+
"boolean",
|
|
191
|
+
"date",
|
|
192
|
+
"bigint",
|
|
193
|
+
"symbol",
|
|
194
|
+
"function",
|
|
195
|
+
"undefined",
|
|
196
|
+
"null",
|
|
197
|
+
"array",
|
|
198
|
+
"object",
|
|
199
|
+
"unknown",
|
|
200
|
+
"promise",
|
|
201
|
+
"void",
|
|
202
|
+
"never",
|
|
203
|
+
"map",
|
|
204
|
+
"set"
|
|
205
|
+
]), getParsedType = (data) => {
|
|
206
|
+
switch (typeof data) {
|
|
207
|
+
case "undefined":
|
|
208
|
+
return ZodParsedType.undefined;
|
|
209
|
+
case "string":
|
|
210
|
+
return ZodParsedType.string;
|
|
211
|
+
case "number":
|
|
212
|
+
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
213
|
+
case "boolean":
|
|
214
|
+
return ZodParsedType.boolean;
|
|
215
|
+
case "function":
|
|
216
|
+
return ZodParsedType.function;
|
|
217
|
+
case "bigint":
|
|
218
|
+
return ZodParsedType.bigint;
|
|
219
|
+
case "symbol":
|
|
220
|
+
return ZodParsedType.symbol;
|
|
221
|
+
case "object":
|
|
222
|
+
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;
|
|
223
|
+
default:
|
|
224
|
+
return ZodParsedType.unknown;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// ../node_modules/zod/v3/ZodError.js
|
|
229
|
+
var ZodIssueCode = util.arrayToEnum([
|
|
230
|
+
"invalid_type",
|
|
231
|
+
"invalid_literal",
|
|
232
|
+
"custom",
|
|
233
|
+
"invalid_union",
|
|
234
|
+
"invalid_union_discriminator",
|
|
235
|
+
"invalid_enum_value",
|
|
236
|
+
"unrecognized_keys",
|
|
237
|
+
"invalid_arguments",
|
|
238
|
+
"invalid_return_type",
|
|
239
|
+
"invalid_date",
|
|
240
|
+
"invalid_string",
|
|
241
|
+
"too_small",
|
|
242
|
+
"too_big",
|
|
243
|
+
"invalid_intersection_types",
|
|
244
|
+
"not_multiple_of",
|
|
245
|
+
"not_finite"
|
|
246
|
+
]), quotelessJson = (obj) => JSON.stringify(obj, null, 2).replace(/"([^"]+)":/g, "$1:"), ZodError = class _ZodError extends Error {
|
|
247
|
+
get errors() {
|
|
248
|
+
return this.issues;
|
|
249
|
+
}
|
|
250
|
+
constructor(issues) {
|
|
251
|
+
super(), this.issues = [], this.addIssue = (sub) => {
|
|
252
|
+
this.issues = [...this.issues, sub];
|
|
253
|
+
}, this.addIssues = (subs = []) => {
|
|
254
|
+
this.issues = [...this.issues, ...subs];
|
|
255
|
+
};
|
|
256
|
+
let actualProto = new.target.prototype;
|
|
257
|
+
Object.setPrototypeOf ? Object.setPrototypeOf(this, actualProto) : this.__proto__ = actualProto, this.name = "ZodError", this.issues = issues;
|
|
258
|
+
}
|
|
259
|
+
format(_mapper) {
|
|
260
|
+
let mapper = _mapper || function(issue) {
|
|
261
|
+
return issue.message;
|
|
262
|
+
}, fieldErrors = { _errors: [] }, processError = (error) => {
|
|
263
|
+
for (let issue of error.issues)
|
|
264
|
+
if (issue.code === "invalid_union")
|
|
265
|
+
issue.unionErrors.map(processError);
|
|
266
|
+
else if (issue.code === "invalid_return_type")
|
|
267
|
+
processError(issue.returnTypeError);
|
|
268
|
+
else if (issue.code === "invalid_arguments")
|
|
269
|
+
processError(issue.argumentsError);
|
|
270
|
+
else if (issue.path.length === 0)
|
|
271
|
+
fieldErrors._errors.push(mapper(issue));
|
|
272
|
+
else {
|
|
273
|
+
let curr = fieldErrors, i = 0;
|
|
274
|
+
for (; i < issue.path.length; ) {
|
|
275
|
+
let el = issue.path[i];
|
|
276
|
+
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++;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
return processError(this), fieldErrors;
|
|
281
|
+
}
|
|
282
|
+
static assert(value) {
|
|
283
|
+
if (!(value instanceof _ZodError))
|
|
284
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
285
|
+
}
|
|
286
|
+
toString() {
|
|
287
|
+
return this.message;
|
|
288
|
+
}
|
|
289
|
+
get message() {
|
|
290
|
+
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
291
|
+
}
|
|
292
|
+
get isEmpty() {
|
|
293
|
+
return this.issues.length === 0;
|
|
294
|
+
}
|
|
295
|
+
flatten(mapper = (issue) => issue.message) {
|
|
296
|
+
let fieldErrors = {}, formErrors = [];
|
|
297
|
+
for (let sub of this.issues)
|
|
298
|
+
if (sub.path.length > 0) {
|
|
299
|
+
let firstEl = sub.path[0];
|
|
300
|
+
fieldErrors[firstEl] = fieldErrors[firstEl] || [], fieldErrors[firstEl].push(mapper(sub));
|
|
301
|
+
} else
|
|
302
|
+
formErrors.push(mapper(sub));
|
|
303
|
+
return { formErrors, fieldErrors };
|
|
304
|
+
}
|
|
305
|
+
get formErrors() {
|
|
306
|
+
return this.flatten();
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
ZodError.create = (issues) => new ZodError(issues);
|
|
310
|
+
|
|
311
|
+
// ../node_modules/zod/v3/locales/en.js
|
|
312
|
+
var errorMap = (issue, _ctx) => {
|
|
313
|
+
let message;
|
|
314
|
+
switch (issue.code) {
|
|
315
|
+
case ZodIssueCode.invalid_type:
|
|
316
|
+
issue.received === ZodParsedType.undefined ? message = "Required" : message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
317
|
+
break;
|
|
318
|
+
case ZodIssueCode.invalid_literal:
|
|
319
|
+
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
|
|
320
|
+
break;
|
|
321
|
+
case ZodIssueCode.unrecognized_keys:
|
|
322
|
+
message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
|
|
323
|
+
break;
|
|
324
|
+
case ZodIssueCode.invalid_union:
|
|
325
|
+
message = "Invalid input";
|
|
326
|
+
break;
|
|
327
|
+
case ZodIssueCode.invalid_union_discriminator:
|
|
328
|
+
message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
|
|
329
|
+
break;
|
|
330
|
+
case ZodIssueCode.invalid_enum_value:
|
|
331
|
+
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
332
|
+
break;
|
|
333
|
+
case ZodIssueCode.invalid_arguments:
|
|
334
|
+
message = "Invalid function arguments";
|
|
335
|
+
break;
|
|
336
|
+
case ZodIssueCode.invalid_return_type:
|
|
337
|
+
message = "Invalid function return type";
|
|
338
|
+
break;
|
|
339
|
+
case ZodIssueCode.invalid_date:
|
|
340
|
+
message = "Invalid date";
|
|
341
|
+
break;
|
|
342
|
+
case ZodIssueCode.invalid_string:
|
|
343
|
+
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";
|
|
344
|
+
break;
|
|
345
|
+
case ZodIssueCode.too_small:
|
|
346
|
+
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";
|
|
347
|
+
break;
|
|
348
|
+
case ZodIssueCode.too_big:
|
|
349
|
+
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";
|
|
350
|
+
break;
|
|
351
|
+
case ZodIssueCode.custom:
|
|
352
|
+
message = "Invalid input";
|
|
353
|
+
break;
|
|
354
|
+
case ZodIssueCode.invalid_intersection_types:
|
|
355
|
+
message = "Intersection results could not be merged";
|
|
356
|
+
break;
|
|
357
|
+
case ZodIssueCode.not_multiple_of:
|
|
358
|
+
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
359
|
+
break;
|
|
360
|
+
case ZodIssueCode.not_finite:
|
|
361
|
+
message = "Number must be finite";
|
|
362
|
+
break;
|
|
363
|
+
default:
|
|
364
|
+
message = _ctx.defaultError, util.assertNever(issue);
|
|
365
|
+
}
|
|
366
|
+
return { message };
|
|
367
|
+
}, en_default = errorMap;
|
|
368
|
+
|
|
369
|
+
// ../node_modules/zod/v3/errors.js
|
|
370
|
+
var overrideErrorMap = en_default;
|
|
371
|
+
function setErrorMap(map) {
|
|
372
|
+
overrideErrorMap = map;
|
|
373
|
+
}
|
|
374
|
+
function getErrorMap() {
|
|
375
|
+
return overrideErrorMap;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// ../node_modules/zod/v3/helpers/parseUtil.js
|
|
379
|
+
var makeIssue = (params) => {
|
|
380
|
+
let { data, path, errorMaps, issueData } = params, fullPath = [...path, ...issueData.path || []], fullIssue = {
|
|
381
|
+
...issueData,
|
|
382
|
+
path: fullPath
|
|
383
|
+
};
|
|
384
|
+
if (issueData.message !== void 0)
|
|
385
|
+
return {
|
|
386
|
+
...issueData,
|
|
387
|
+
path: fullPath,
|
|
388
|
+
message: issueData.message
|
|
389
|
+
};
|
|
390
|
+
let errorMessage = "", maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
391
|
+
for (let map of maps)
|
|
392
|
+
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
|
393
|
+
return {
|
|
394
|
+
...issueData,
|
|
395
|
+
path: fullPath,
|
|
396
|
+
message: errorMessage
|
|
397
|
+
};
|
|
398
|
+
}, EMPTY_PATH = [];
|
|
399
|
+
function addIssueToContext(ctx, issueData) {
|
|
400
|
+
let overrideMap = getErrorMap(), issue = makeIssue({
|
|
401
|
+
issueData,
|
|
402
|
+
data: ctx.data,
|
|
403
|
+
path: ctx.path,
|
|
404
|
+
errorMaps: [
|
|
405
|
+
ctx.common.contextualErrorMap,
|
|
406
|
+
// contextual error map is first priority
|
|
407
|
+
ctx.schemaErrorMap,
|
|
408
|
+
// then schema-bound map if available
|
|
409
|
+
overrideMap,
|
|
410
|
+
// then global override map
|
|
411
|
+
overrideMap === en_default ? void 0 : en_default
|
|
412
|
+
// then global default map
|
|
413
|
+
].filter((x) => !!x)
|
|
414
|
+
});
|
|
415
|
+
ctx.common.issues.push(issue);
|
|
416
|
+
}
|
|
417
|
+
var ParseStatus = class _ParseStatus {
|
|
418
|
+
constructor() {
|
|
419
|
+
this.value = "valid";
|
|
420
|
+
}
|
|
421
|
+
dirty() {
|
|
422
|
+
this.value === "valid" && (this.value = "dirty");
|
|
423
|
+
}
|
|
424
|
+
abort() {
|
|
425
|
+
this.value !== "aborted" && (this.value = "aborted");
|
|
426
|
+
}
|
|
427
|
+
static mergeArray(status, results) {
|
|
428
|
+
let arrayValue = [];
|
|
429
|
+
for (let s of results) {
|
|
430
|
+
if (s.status === "aborted")
|
|
431
|
+
return INVALID;
|
|
432
|
+
s.status === "dirty" && status.dirty(), arrayValue.push(s.value);
|
|
433
|
+
}
|
|
434
|
+
return { status: status.value, value: arrayValue };
|
|
435
|
+
}
|
|
436
|
+
static async mergeObjectAsync(status, pairs) {
|
|
437
|
+
let syncPairs = [];
|
|
438
|
+
for (let pair of pairs) {
|
|
439
|
+
let key = await pair.key, value = await pair.value;
|
|
440
|
+
syncPairs.push({
|
|
441
|
+
key,
|
|
442
|
+
value
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
|
446
|
+
}
|
|
447
|
+
static mergeObjectSync(status, pairs) {
|
|
448
|
+
let finalObject = {};
|
|
449
|
+
for (let pair of pairs) {
|
|
450
|
+
let { key, value } = pair;
|
|
451
|
+
if (key.status === "aborted" || value.status === "aborted")
|
|
452
|
+
return INVALID;
|
|
453
|
+
key.status === "dirty" && status.dirty(), value.status === "dirty" && status.dirty(), key.value !== "__proto__" && (typeof value.value < "u" || pair.alwaysSet) && (finalObject[key.value] = value.value);
|
|
454
|
+
}
|
|
455
|
+
return { status: status.value, value: finalObject };
|
|
456
|
+
}
|
|
457
|
+
}, INVALID = Object.freeze({
|
|
458
|
+
status: "aborted"
|
|
459
|
+
}), 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;
|
|
460
|
+
|
|
461
|
+
// ../node_modules/zod/v3/helpers/errorUtil.js
|
|
462
|
+
var errorUtil;
|
|
463
|
+
(function(errorUtil2) {
|
|
464
|
+
errorUtil2.errToObj = (message) => typeof message == "string" ? { message } : message || {}, errorUtil2.toString = (message) => typeof message == "string" ? message : message?.message;
|
|
465
|
+
})(errorUtil || (errorUtil = {}));
|
|
466
|
+
|
|
467
|
+
// ../node_modules/zod/v3/types.js
|
|
468
|
+
var ParseInputLazyPath = class {
|
|
469
|
+
constructor(parent, value, path, key) {
|
|
470
|
+
this._cachedPath = [], this.parent = parent, this.data = value, this._path = path, this._key = key;
|
|
471
|
+
}
|
|
472
|
+
get path() {
|
|
473
|
+
return this._cachedPath.length || (Array.isArray(this._key) ? this._cachedPath.push(...this._path, ...this._key) : this._cachedPath.push(...this._path, this._key)), this._cachedPath;
|
|
474
|
+
}
|
|
475
|
+
}, handleResult = (ctx, result) => {
|
|
476
|
+
if (isValid(result))
|
|
477
|
+
return { success: !0, data: result.value };
|
|
478
|
+
if (!ctx.common.issues.length)
|
|
479
|
+
throw new Error("Validation failed but no issues detected.");
|
|
480
|
+
return {
|
|
481
|
+
success: !1,
|
|
482
|
+
get error() {
|
|
483
|
+
if (this._error)
|
|
484
|
+
return this._error;
|
|
485
|
+
let error = new ZodError(ctx.common.issues);
|
|
486
|
+
return this._error = error, this._error;
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
};
|
|
490
|
+
function processCreateParams(params) {
|
|
491
|
+
if (!params)
|
|
492
|
+
return {};
|
|
493
|
+
let { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
|
|
494
|
+
if (errorMap2 && (invalid_type_error || required_error))
|
|
495
|
+
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
496
|
+
return errorMap2 ? { errorMap: errorMap2, description } : { errorMap: (iss, ctx) => {
|
|
497
|
+
let { message } = params;
|
|
498
|
+
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 };
|
|
499
|
+
}, description };
|
|
500
|
+
}
|
|
501
|
+
var ZodType = class {
|
|
502
|
+
get description() {
|
|
503
|
+
return this._def.description;
|
|
504
|
+
}
|
|
505
|
+
_getType(input) {
|
|
506
|
+
return getParsedType(input.data);
|
|
507
|
+
}
|
|
508
|
+
_getOrReturnCtx(input, ctx) {
|
|
509
|
+
return ctx || {
|
|
510
|
+
common: input.parent.common,
|
|
511
|
+
data: input.data,
|
|
512
|
+
parsedType: getParsedType(input.data),
|
|
513
|
+
schemaErrorMap: this._def.errorMap,
|
|
514
|
+
path: input.path,
|
|
515
|
+
parent: input.parent
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
_processInputParams(input) {
|
|
519
|
+
return {
|
|
520
|
+
status: new ParseStatus(),
|
|
521
|
+
ctx: {
|
|
522
|
+
common: input.parent.common,
|
|
523
|
+
data: input.data,
|
|
524
|
+
parsedType: getParsedType(input.data),
|
|
525
|
+
schemaErrorMap: this._def.errorMap,
|
|
526
|
+
path: input.path,
|
|
527
|
+
parent: input.parent
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
_parseSync(input) {
|
|
532
|
+
let result = this._parse(input);
|
|
533
|
+
if (isAsync(result))
|
|
534
|
+
throw new Error("Synchronous parse encountered promise.");
|
|
535
|
+
return result;
|
|
536
|
+
}
|
|
537
|
+
_parseAsync(input) {
|
|
538
|
+
let result = this._parse(input);
|
|
539
|
+
return Promise.resolve(result);
|
|
540
|
+
}
|
|
541
|
+
parse(data, params) {
|
|
542
|
+
let result = this.safeParse(data, params);
|
|
543
|
+
if (result.success)
|
|
544
|
+
return result.data;
|
|
545
|
+
throw result.error;
|
|
546
|
+
}
|
|
547
|
+
safeParse(data, params) {
|
|
548
|
+
let ctx = {
|
|
549
|
+
common: {
|
|
550
|
+
issues: [],
|
|
551
|
+
async: params?.async ?? !1,
|
|
552
|
+
contextualErrorMap: params?.errorMap
|
|
553
|
+
},
|
|
554
|
+
path: params?.path || [],
|
|
555
|
+
schemaErrorMap: this._def.errorMap,
|
|
556
|
+
parent: null,
|
|
557
|
+
data,
|
|
558
|
+
parsedType: getParsedType(data)
|
|
559
|
+
}, result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
560
|
+
return handleResult(ctx, result);
|
|
561
|
+
}
|
|
562
|
+
"~validate"(data) {
|
|
563
|
+
let ctx = {
|
|
564
|
+
common: {
|
|
565
|
+
issues: [],
|
|
566
|
+
async: !!this["~standard"].async
|
|
567
|
+
},
|
|
568
|
+
path: [],
|
|
569
|
+
schemaErrorMap: this._def.errorMap,
|
|
570
|
+
parent: null,
|
|
571
|
+
data,
|
|
572
|
+
parsedType: getParsedType(data)
|
|
573
|
+
};
|
|
574
|
+
if (!this["~standard"].async)
|
|
575
|
+
try {
|
|
576
|
+
let result = this._parseSync({ data, path: [], parent: ctx });
|
|
577
|
+
return isValid(result) ? {
|
|
578
|
+
value: result.value
|
|
579
|
+
} : {
|
|
580
|
+
issues: ctx.common.issues
|
|
581
|
+
};
|
|
582
|
+
} catch (err) {
|
|
583
|
+
err?.message?.toLowerCase()?.includes("encountered") && (this["~standard"].async = !0), ctx.common = {
|
|
584
|
+
issues: [],
|
|
585
|
+
async: !0
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
589
|
+
value: result.value
|
|
590
|
+
} : {
|
|
591
|
+
issues: ctx.common.issues
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
async parseAsync(data, params) {
|
|
595
|
+
let result = await this.safeParseAsync(data, params);
|
|
596
|
+
if (result.success)
|
|
597
|
+
return result.data;
|
|
598
|
+
throw result.error;
|
|
599
|
+
}
|
|
600
|
+
async safeParseAsync(data, params) {
|
|
601
|
+
let ctx = {
|
|
602
|
+
common: {
|
|
603
|
+
issues: [],
|
|
604
|
+
contextualErrorMap: params?.errorMap,
|
|
605
|
+
async: !0
|
|
606
|
+
},
|
|
607
|
+
path: params?.path || [],
|
|
608
|
+
schemaErrorMap: this._def.errorMap,
|
|
609
|
+
parent: null,
|
|
610
|
+
data,
|
|
611
|
+
parsedType: getParsedType(data)
|
|
612
|
+
}, maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx }), result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
613
|
+
return handleResult(ctx, result);
|
|
614
|
+
}
|
|
615
|
+
refine(check, message) {
|
|
616
|
+
let getIssueProperties = (val) => typeof message == "string" || typeof message > "u" ? { message } : typeof message == "function" ? message(val) : message;
|
|
617
|
+
return this._refinement((val, ctx) => {
|
|
618
|
+
let result = check(val), setError = () => ctx.addIssue({
|
|
619
|
+
code: ZodIssueCode.custom,
|
|
620
|
+
...getIssueProperties(val)
|
|
621
|
+
});
|
|
622
|
+
return typeof Promise < "u" && result instanceof Promise ? result.then((data) => data ? !0 : (setError(), !1)) : result ? !0 : (setError(), !1);
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
refinement(check, refinementData) {
|
|
626
|
+
return this._refinement((val, ctx) => check(val) ? !0 : (ctx.addIssue(typeof refinementData == "function" ? refinementData(val, ctx) : refinementData), !1));
|
|
627
|
+
}
|
|
628
|
+
_refinement(refinement) {
|
|
629
|
+
return new ZodEffects({
|
|
630
|
+
schema: this,
|
|
631
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
632
|
+
effect: { type: "refinement", refinement }
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
superRefine(refinement) {
|
|
636
|
+
return this._refinement(refinement);
|
|
637
|
+
}
|
|
638
|
+
constructor(def) {
|
|
639
|
+
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"] = {
|
|
640
|
+
version: 1,
|
|
641
|
+
vendor: "zod",
|
|
642
|
+
validate: (data) => this["~validate"](data)
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
optional() {
|
|
646
|
+
return ZodOptional.create(this, this._def);
|
|
647
|
+
}
|
|
648
|
+
nullable() {
|
|
649
|
+
return ZodNullable.create(this, this._def);
|
|
650
|
+
}
|
|
651
|
+
nullish() {
|
|
652
|
+
return this.nullable().optional();
|
|
653
|
+
}
|
|
654
|
+
array() {
|
|
655
|
+
return ZodArray.create(this);
|
|
656
|
+
}
|
|
657
|
+
promise() {
|
|
658
|
+
return ZodPromise.create(this, this._def);
|
|
659
|
+
}
|
|
660
|
+
or(option) {
|
|
661
|
+
return ZodUnion.create([this, option], this._def);
|
|
662
|
+
}
|
|
663
|
+
and(incoming) {
|
|
664
|
+
return ZodIntersection.create(this, incoming, this._def);
|
|
665
|
+
}
|
|
666
|
+
transform(transform) {
|
|
667
|
+
return new ZodEffects({
|
|
668
|
+
...processCreateParams(this._def),
|
|
669
|
+
schema: this,
|
|
670
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
671
|
+
effect: { type: "transform", transform }
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
default(def) {
|
|
675
|
+
let defaultValueFunc = typeof def == "function" ? def : () => def;
|
|
676
|
+
return new ZodDefault({
|
|
677
|
+
...processCreateParams(this._def),
|
|
678
|
+
innerType: this,
|
|
679
|
+
defaultValue: defaultValueFunc,
|
|
680
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
brand() {
|
|
684
|
+
return new ZodBranded({
|
|
685
|
+
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
686
|
+
type: this,
|
|
687
|
+
...processCreateParams(this._def)
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
catch(def) {
|
|
691
|
+
let catchValueFunc = typeof def == "function" ? def : () => def;
|
|
692
|
+
return new ZodCatch({
|
|
693
|
+
...processCreateParams(this._def),
|
|
694
|
+
innerType: this,
|
|
695
|
+
catchValue: catchValueFunc,
|
|
696
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
describe(description) {
|
|
700
|
+
let This = this.constructor;
|
|
701
|
+
return new This({
|
|
702
|
+
...this._def,
|
|
703
|
+
description
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
pipe(target) {
|
|
707
|
+
return ZodPipeline.create(this, target);
|
|
708
|
+
}
|
|
709
|
+
readonly() {
|
|
710
|
+
return ZodReadonly.create(this);
|
|
711
|
+
}
|
|
712
|
+
isOptional() {
|
|
713
|
+
return this.safeParse(void 0).success;
|
|
714
|
+
}
|
|
715
|
+
isNullable() {
|
|
716
|
+
return this.safeParse(null).success;
|
|
717
|
+
}
|
|
718
|
+
}, 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}$`);
|
|
719
|
+
function timeRegexSource(args) {
|
|
720
|
+
let secondsRegexSource = "[0-5]\\d";
|
|
721
|
+
args.precision ? secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}` : args.precision == null && (secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`);
|
|
722
|
+
let secondsQuantifier = args.precision ? "+" : "?";
|
|
723
|
+
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
724
|
+
}
|
|
725
|
+
function timeRegex(args) {
|
|
726
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
727
|
+
}
|
|
728
|
+
function datetimeRegex(args) {
|
|
729
|
+
let regex = `${dateRegexSource}T${timeRegexSource(args)}`, opts = [];
|
|
730
|
+
return opts.push(args.local ? "Z?" : "Z"), args.offset && opts.push("([+-]\\d{2}:?\\d{2})"), regex = `${regex}(${opts.join("|")})`, new RegExp(`^${regex}$`);
|
|
731
|
+
}
|
|
732
|
+
function isValidIP(ip, version) {
|
|
733
|
+
return !!((version === "v4" || !version) && ipv4Regex.test(ip) || (version === "v6" || !version) && ipv6Regex.test(ip));
|
|
734
|
+
}
|
|
735
|
+
function isValidJWT(jwt, alg) {
|
|
736
|
+
if (!jwtRegex.test(jwt))
|
|
737
|
+
return !1;
|
|
738
|
+
try {
|
|
739
|
+
let [header] = jwt.split(".");
|
|
740
|
+
if (!header)
|
|
741
|
+
return !1;
|
|
742
|
+
let base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "="), decoded = JSON.parse(atob(base64));
|
|
743
|
+
return !(typeof decoded != "object" || decoded === null || "typ" in decoded && decoded?.typ !== "JWT" || !decoded.alg || alg && decoded.alg !== alg);
|
|
744
|
+
} catch {
|
|
745
|
+
return !1;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
function isValidCidr(ip, version) {
|
|
749
|
+
return !!((version === "v4" || !version) && ipv4CidrRegex.test(ip) || (version === "v6" || !version) && ipv6CidrRegex.test(ip));
|
|
750
|
+
}
|
|
751
|
+
var ZodString = class _ZodString extends ZodType {
|
|
752
|
+
_parse(input) {
|
|
753
|
+
if (this._def.coerce && (input.data = String(input.data)), this._getType(input) !== ZodParsedType.string) {
|
|
754
|
+
let ctx2 = this._getOrReturnCtx(input);
|
|
755
|
+
return addIssueToContext(ctx2, {
|
|
756
|
+
code: ZodIssueCode.invalid_type,
|
|
757
|
+
expected: ZodParsedType.string,
|
|
758
|
+
received: ctx2.parsedType
|
|
759
|
+
}), INVALID;
|
|
760
|
+
}
|
|
761
|
+
let status = new ParseStatus(), ctx;
|
|
762
|
+
for (let check of this._def.checks)
|
|
763
|
+
if (check.kind === "min")
|
|
764
|
+
input.data.length < check.value && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
765
|
+
code: ZodIssueCode.too_small,
|
|
766
|
+
minimum: check.value,
|
|
767
|
+
type: "string",
|
|
768
|
+
inclusive: !0,
|
|
769
|
+
exact: !1,
|
|
770
|
+
message: check.message
|
|
771
|
+
}), status.dirty());
|
|
772
|
+
else if (check.kind === "max")
|
|
773
|
+
input.data.length > check.value && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
774
|
+
code: ZodIssueCode.too_big,
|
|
775
|
+
maximum: check.value,
|
|
776
|
+
type: "string",
|
|
777
|
+
inclusive: !0,
|
|
778
|
+
exact: !1,
|
|
779
|
+
message: check.message
|
|
780
|
+
}), status.dirty());
|
|
781
|
+
else if (check.kind === "length") {
|
|
782
|
+
let tooBig = input.data.length > check.value, tooSmall = input.data.length < check.value;
|
|
783
|
+
(tooBig || tooSmall) && (ctx = this._getOrReturnCtx(input, ctx), tooBig ? addIssueToContext(ctx, {
|
|
784
|
+
code: ZodIssueCode.too_big,
|
|
785
|
+
maximum: check.value,
|
|
786
|
+
type: "string",
|
|
787
|
+
inclusive: !0,
|
|
788
|
+
exact: !0,
|
|
789
|
+
message: check.message
|
|
790
|
+
}) : tooSmall && addIssueToContext(ctx, {
|
|
791
|
+
code: ZodIssueCode.too_small,
|
|
792
|
+
minimum: check.value,
|
|
793
|
+
type: "string",
|
|
794
|
+
inclusive: !0,
|
|
795
|
+
exact: !0,
|
|
796
|
+
message: check.message
|
|
797
|
+
}), status.dirty());
|
|
798
|
+
} else if (check.kind === "email")
|
|
799
|
+
emailRegex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
800
|
+
validation: "email",
|
|
801
|
+
code: ZodIssueCode.invalid_string,
|
|
802
|
+
message: check.message
|
|
803
|
+
}), status.dirty());
|
|
804
|
+
else if (check.kind === "emoji")
|
|
805
|
+
emojiRegex || (emojiRegex = new RegExp(_emojiRegex, "u")), emojiRegex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
806
|
+
validation: "emoji",
|
|
807
|
+
code: ZodIssueCode.invalid_string,
|
|
808
|
+
message: check.message
|
|
809
|
+
}), status.dirty());
|
|
810
|
+
else if (check.kind === "uuid")
|
|
811
|
+
uuidRegex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
812
|
+
validation: "uuid",
|
|
813
|
+
code: ZodIssueCode.invalid_string,
|
|
814
|
+
message: check.message
|
|
815
|
+
}), status.dirty());
|
|
816
|
+
else if (check.kind === "nanoid")
|
|
817
|
+
nanoidRegex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
818
|
+
validation: "nanoid",
|
|
819
|
+
code: ZodIssueCode.invalid_string,
|
|
820
|
+
message: check.message
|
|
821
|
+
}), status.dirty());
|
|
822
|
+
else if (check.kind === "cuid")
|
|
823
|
+
cuidRegex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
824
|
+
validation: "cuid",
|
|
825
|
+
code: ZodIssueCode.invalid_string,
|
|
826
|
+
message: check.message
|
|
827
|
+
}), status.dirty());
|
|
828
|
+
else if (check.kind === "cuid2")
|
|
829
|
+
cuid2Regex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
830
|
+
validation: "cuid2",
|
|
831
|
+
code: ZodIssueCode.invalid_string,
|
|
832
|
+
message: check.message
|
|
833
|
+
}), status.dirty());
|
|
834
|
+
else if (check.kind === "ulid")
|
|
835
|
+
ulidRegex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
836
|
+
validation: "ulid",
|
|
837
|
+
code: ZodIssueCode.invalid_string,
|
|
838
|
+
message: check.message
|
|
839
|
+
}), status.dirty());
|
|
840
|
+
else if (check.kind === "url")
|
|
841
|
+
try {
|
|
842
|
+
new URL(input.data);
|
|
843
|
+
} catch {
|
|
844
|
+
ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
845
|
+
validation: "url",
|
|
846
|
+
code: ZodIssueCode.invalid_string,
|
|
847
|
+
message: check.message
|
|
848
|
+
}), status.dirty();
|
|
849
|
+
}
|
|
850
|
+
else check.kind === "regex" ? (check.regex.lastIndex = 0, check.regex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
851
|
+
validation: "regex",
|
|
852
|
+
code: ZodIssueCode.invalid_string,
|
|
853
|
+
message: check.message
|
|
854
|
+
}), 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, {
|
|
855
|
+
code: ZodIssueCode.invalid_string,
|
|
856
|
+
validation: { includes: check.value, position: check.position },
|
|
857
|
+
message: check.message
|
|
858
|
+
}), 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, {
|
|
859
|
+
code: ZodIssueCode.invalid_string,
|
|
860
|
+
validation: { startsWith: check.value },
|
|
861
|
+
message: check.message
|
|
862
|
+
}), status.dirty()) : check.kind === "endsWith" ? input.data.endsWith(check.value) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
863
|
+
code: ZodIssueCode.invalid_string,
|
|
864
|
+
validation: { endsWith: check.value },
|
|
865
|
+
message: check.message
|
|
866
|
+
}), status.dirty()) : check.kind === "datetime" ? datetimeRegex(check).test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
867
|
+
code: ZodIssueCode.invalid_string,
|
|
868
|
+
validation: "datetime",
|
|
869
|
+
message: check.message
|
|
870
|
+
}), status.dirty()) : check.kind === "date" ? dateRegex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
871
|
+
code: ZodIssueCode.invalid_string,
|
|
872
|
+
validation: "date",
|
|
873
|
+
message: check.message
|
|
874
|
+
}), status.dirty()) : check.kind === "time" ? timeRegex(check).test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
875
|
+
code: ZodIssueCode.invalid_string,
|
|
876
|
+
validation: "time",
|
|
877
|
+
message: check.message
|
|
878
|
+
}), status.dirty()) : check.kind === "duration" ? durationRegex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
879
|
+
validation: "duration",
|
|
880
|
+
code: ZodIssueCode.invalid_string,
|
|
881
|
+
message: check.message
|
|
882
|
+
}), status.dirty()) : check.kind === "ip" ? isValidIP(input.data, check.version) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
883
|
+
validation: "ip",
|
|
884
|
+
code: ZodIssueCode.invalid_string,
|
|
885
|
+
message: check.message
|
|
886
|
+
}), status.dirty()) : check.kind === "jwt" ? isValidJWT(input.data, check.alg) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
887
|
+
validation: "jwt",
|
|
888
|
+
code: ZodIssueCode.invalid_string,
|
|
889
|
+
message: check.message
|
|
890
|
+
}), status.dirty()) : check.kind === "cidr" ? isValidCidr(input.data, check.version) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
891
|
+
validation: "cidr",
|
|
892
|
+
code: ZodIssueCode.invalid_string,
|
|
893
|
+
message: check.message
|
|
894
|
+
}), status.dirty()) : check.kind === "base64" ? base64Regex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
895
|
+
validation: "base64",
|
|
896
|
+
code: ZodIssueCode.invalid_string,
|
|
897
|
+
message: check.message
|
|
898
|
+
}), status.dirty()) : check.kind === "base64url" ? base64urlRegex.test(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
899
|
+
validation: "base64url",
|
|
900
|
+
code: ZodIssueCode.invalid_string,
|
|
901
|
+
message: check.message
|
|
902
|
+
}), status.dirty()) : util.assertNever(check);
|
|
903
|
+
return { status: status.value, value: input.data };
|
|
904
|
+
}
|
|
905
|
+
_regex(regex, validation, message) {
|
|
906
|
+
return this.refinement((data) => regex.test(data), {
|
|
907
|
+
validation,
|
|
908
|
+
code: ZodIssueCode.invalid_string,
|
|
909
|
+
...errorUtil.errToObj(message)
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
_addCheck(check) {
|
|
913
|
+
return new _ZodString({
|
|
914
|
+
...this._def,
|
|
915
|
+
checks: [...this._def.checks, check]
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
email(message) {
|
|
919
|
+
return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
|
|
920
|
+
}
|
|
921
|
+
url(message) {
|
|
922
|
+
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
|
923
|
+
}
|
|
924
|
+
emoji(message) {
|
|
925
|
+
return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
|
|
926
|
+
}
|
|
927
|
+
uuid(message) {
|
|
928
|
+
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
929
|
+
}
|
|
930
|
+
nanoid(message) {
|
|
931
|
+
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
932
|
+
}
|
|
933
|
+
cuid(message) {
|
|
934
|
+
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
935
|
+
}
|
|
936
|
+
cuid2(message) {
|
|
937
|
+
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
|
938
|
+
}
|
|
939
|
+
ulid(message) {
|
|
940
|
+
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
941
|
+
}
|
|
942
|
+
base64(message) {
|
|
943
|
+
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
944
|
+
}
|
|
945
|
+
base64url(message) {
|
|
946
|
+
return this._addCheck({
|
|
947
|
+
kind: "base64url",
|
|
948
|
+
...errorUtil.errToObj(message)
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
jwt(options) {
|
|
952
|
+
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
953
|
+
}
|
|
954
|
+
ip(options) {
|
|
955
|
+
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
956
|
+
}
|
|
957
|
+
cidr(options) {
|
|
958
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
959
|
+
}
|
|
960
|
+
datetime(options) {
|
|
961
|
+
return typeof options == "string" ? this._addCheck({
|
|
962
|
+
kind: "datetime",
|
|
963
|
+
precision: null,
|
|
964
|
+
offset: !1,
|
|
965
|
+
local: !1,
|
|
966
|
+
message: options
|
|
967
|
+
}) : this._addCheck({
|
|
968
|
+
kind: "datetime",
|
|
969
|
+
precision: typeof options?.precision > "u" ? null : options?.precision,
|
|
970
|
+
offset: options?.offset ?? !1,
|
|
971
|
+
local: options?.local ?? !1,
|
|
972
|
+
...errorUtil.errToObj(options?.message)
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
date(message) {
|
|
976
|
+
return this._addCheck({ kind: "date", message });
|
|
977
|
+
}
|
|
978
|
+
time(options) {
|
|
979
|
+
return typeof options == "string" ? this._addCheck({
|
|
980
|
+
kind: "time",
|
|
981
|
+
precision: null,
|
|
982
|
+
message: options
|
|
983
|
+
}) : this._addCheck({
|
|
984
|
+
kind: "time",
|
|
985
|
+
precision: typeof options?.precision > "u" ? null : options?.precision,
|
|
986
|
+
...errorUtil.errToObj(options?.message)
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
duration(message) {
|
|
990
|
+
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
991
|
+
}
|
|
992
|
+
regex(regex, message) {
|
|
993
|
+
return this._addCheck({
|
|
994
|
+
kind: "regex",
|
|
995
|
+
regex,
|
|
996
|
+
...errorUtil.errToObj(message)
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
includes(value, options) {
|
|
1000
|
+
return this._addCheck({
|
|
1001
|
+
kind: "includes",
|
|
1002
|
+
value,
|
|
1003
|
+
position: options?.position,
|
|
1004
|
+
...errorUtil.errToObj(options?.message)
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
startsWith(value, message) {
|
|
1008
|
+
return this._addCheck({
|
|
1009
|
+
kind: "startsWith",
|
|
1010
|
+
value,
|
|
1011
|
+
...errorUtil.errToObj(message)
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
endsWith(value, message) {
|
|
1015
|
+
return this._addCheck({
|
|
1016
|
+
kind: "endsWith",
|
|
1017
|
+
value,
|
|
1018
|
+
...errorUtil.errToObj(message)
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
min(minLength, message) {
|
|
1022
|
+
return this._addCheck({
|
|
1023
|
+
kind: "min",
|
|
1024
|
+
value: minLength,
|
|
1025
|
+
...errorUtil.errToObj(message)
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
max(maxLength, message) {
|
|
1029
|
+
return this._addCheck({
|
|
1030
|
+
kind: "max",
|
|
1031
|
+
value: maxLength,
|
|
1032
|
+
...errorUtil.errToObj(message)
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
length(len, message) {
|
|
1036
|
+
return this._addCheck({
|
|
1037
|
+
kind: "length",
|
|
1038
|
+
value: len,
|
|
1039
|
+
...errorUtil.errToObj(message)
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Equivalent to `.min(1)`
|
|
1044
|
+
*/
|
|
1045
|
+
nonempty(message) {
|
|
1046
|
+
return this.min(1, errorUtil.errToObj(message));
|
|
1047
|
+
}
|
|
1048
|
+
trim() {
|
|
1049
|
+
return new _ZodString({
|
|
1050
|
+
...this._def,
|
|
1051
|
+
checks: [...this._def.checks, { kind: "trim" }]
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
toLowerCase() {
|
|
1055
|
+
return new _ZodString({
|
|
1056
|
+
...this._def,
|
|
1057
|
+
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
toUpperCase() {
|
|
1061
|
+
return new _ZodString({
|
|
1062
|
+
...this._def,
|
|
1063
|
+
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
get isDatetime() {
|
|
1067
|
+
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
1068
|
+
}
|
|
1069
|
+
get isDate() {
|
|
1070
|
+
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
1071
|
+
}
|
|
1072
|
+
get isTime() {
|
|
1073
|
+
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
1074
|
+
}
|
|
1075
|
+
get isDuration() {
|
|
1076
|
+
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
1077
|
+
}
|
|
1078
|
+
get isEmail() {
|
|
1079
|
+
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
1080
|
+
}
|
|
1081
|
+
get isURL() {
|
|
1082
|
+
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
1083
|
+
}
|
|
1084
|
+
get isEmoji() {
|
|
1085
|
+
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
1086
|
+
}
|
|
1087
|
+
get isUUID() {
|
|
1088
|
+
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
1089
|
+
}
|
|
1090
|
+
get isNANOID() {
|
|
1091
|
+
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
1092
|
+
}
|
|
1093
|
+
get isCUID() {
|
|
1094
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
1095
|
+
}
|
|
1096
|
+
get isCUID2() {
|
|
1097
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
1098
|
+
}
|
|
1099
|
+
get isULID() {
|
|
1100
|
+
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
1101
|
+
}
|
|
1102
|
+
get isIP() {
|
|
1103
|
+
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1104
|
+
}
|
|
1105
|
+
get isCIDR() {
|
|
1106
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1107
|
+
}
|
|
1108
|
+
get isBase64() {
|
|
1109
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1110
|
+
}
|
|
1111
|
+
get isBase64url() {
|
|
1112
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1113
|
+
}
|
|
1114
|
+
get minLength() {
|
|
1115
|
+
let min = null;
|
|
1116
|
+
for (let ch of this._def.checks)
|
|
1117
|
+
ch.kind === "min" && (min === null || ch.value > min) && (min = ch.value);
|
|
1118
|
+
return min;
|
|
1119
|
+
}
|
|
1120
|
+
get maxLength() {
|
|
1121
|
+
let max = null;
|
|
1122
|
+
for (let ch of this._def.checks)
|
|
1123
|
+
ch.kind === "max" && (max === null || ch.value < max) && (max = ch.value);
|
|
1124
|
+
return max;
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
ZodString.create = (params) => new ZodString({
|
|
1128
|
+
checks: [],
|
|
1129
|
+
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
1130
|
+
coerce: params?.coerce ?? !1,
|
|
1131
|
+
...processCreateParams(params)
|
|
1132
|
+
});
|
|
1133
|
+
function floatSafeRemainder(val, step) {
|
|
1134
|
+
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(".", ""));
|
|
1135
|
+
return valInt % stepInt / 10 ** decCount;
|
|
1136
|
+
}
|
|
1137
|
+
var ZodNumber = class _ZodNumber extends ZodType {
|
|
1138
|
+
constructor() {
|
|
1139
|
+
super(...arguments), this.min = this.gte, this.max = this.lte, this.step = this.multipleOf;
|
|
1140
|
+
}
|
|
1141
|
+
_parse(input) {
|
|
1142
|
+
if (this._def.coerce && (input.data = Number(input.data)), this._getType(input) !== ZodParsedType.number) {
|
|
1143
|
+
let ctx2 = this._getOrReturnCtx(input);
|
|
1144
|
+
return addIssueToContext(ctx2, {
|
|
1145
|
+
code: ZodIssueCode.invalid_type,
|
|
1146
|
+
expected: ZodParsedType.number,
|
|
1147
|
+
received: ctx2.parsedType
|
|
1148
|
+
}), INVALID;
|
|
1149
|
+
}
|
|
1150
|
+
let ctx, status = new ParseStatus();
|
|
1151
|
+
for (let check of this._def.checks)
|
|
1152
|
+
check.kind === "int" ? util.isInteger(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
1153
|
+
code: ZodIssueCode.invalid_type,
|
|
1154
|
+
expected: "integer",
|
|
1155
|
+
received: "float",
|
|
1156
|
+
message: check.message
|
|
1157
|
+
}), status.dirty()) : check.kind === "min" ? (check.inclusive ? input.data < check.value : input.data <= check.value) && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
1158
|
+
code: ZodIssueCode.too_small,
|
|
1159
|
+
minimum: check.value,
|
|
1160
|
+
type: "number",
|
|
1161
|
+
inclusive: check.inclusive,
|
|
1162
|
+
exact: !1,
|
|
1163
|
+
message: check.message
|
|
1164
|
+
}), status.dirty()) : check.kind === "max" ? (check.inclusive ? input.data > check.value : input.data >= check.value) && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
1165
|
+
code: ZodIssueCode.too_big,
|
|
1166
|
+
maximum: check.value,
|
|
1167
|
+
type: "number",
|
|
1168
|
+
inclusive: check.inclusive,
|
|
1169
|
+
exact: !1,
|
|
1170
|
+
message: check.message
|
|
1171
|
+
}), status.dirty()) : check.kind === "multipleOf" ? floatSafeRemainder(input.data, check.value) !== 0 && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
1172
|
+
code: ZodIssueCode.not_multiple_of,
|
|
1173
|
+
multipleOf: check.value,
|
|
1174
|
+
message: check.message
|
|
1175
|
+
}), status.dirty()) : check.kind === "finite" ? Number.isFinite(input.data) || (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
1176
|
+
code: ZodIssueCode.not_finite,
|
|
1177
|
+
message: check.message
|
|
1178
|
+
}), status.dirty()) : util.assertNever(check);
|
|
1179
|
+
return { status: status.value, value: input.data };
|
|
1180
|
+
}
|
|
1181
|
+
gte(value, message) {
|
|
1182
|
+
return this.setLimit("min", value, !0, errorUtil.toString(message));
|
|
1183
|
+
}
|
|
1184
|
+
gt(value, message) {
|
|
1185
|
+
return this.setLimit("min", value, !1, errorUtil.toString(message));
|
|
1186
|
+
}
|
|
1187
|
+
lte(value, message) {
|
|
1188
|
+
return this.setLimit("max", value, !0, errorUtil.toString(message));
|
|
1189
|
+
}
|
|
1190
|
+
lt(value, message) {
|
|
1191
|
+
return this.setLimit("max", value, !1, errorUtil.toString(message));
|
|
1192
|
+
}
|
|
1193
|
+
setLimit(kind, value, inclusive, message) {
|
|
1194
|
+
return new _ZodNumber({
|
|
1195
|
+
...this._def,
|
|
1196
|
+
checks: [
|
|
1197
|
+
...this._def.checks,
|
|
1198
|
+
{
|
|
1199
|
+
kind,
|
|
1200
|
+
value,
|
|
1201
|
+
inclusive,
|
|
1202
|
+
message: errorUtil.toString(message)
|
|
1203
|
+
}
|
|
1204
|
+
]
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1207
|
+
_addCheck(check) {
|
|
1208
|
+
return new _ZodNumber({
|
|
1209
|
+
...this._def,
|
|
1210
|
+
checks: [...this._def.checks, check]
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
1213
|
+
int(message) {
|
|
1214
|
+
return this._addCheck({
|
|
1215
|
+
kind: "int",
|
|
1216
|
+
message: errorUtil.toString(message)
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
positive(message) {
|
|
1220
|
+
return this._addCheck({
|
|
1221
|
+
kind: "min",
|
|
1222
|
+
value: 0,
|
|
1223
|
+
inclusive: !1,
|
|
1224
|
+
message: errorUtil.toString(message)
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
negative(message) {
|
|
1228
|
+
return this._addCheck({
|
|
1229
|
+
kind: "max",
|
|
1230
|
+
value: 0,
|
|
1231
|
+
inclusive: !1,
|
|
1232
|
+
message: errorUtil.toString(message)
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
nonpositive(message) {
|
|
1236
|
+
return this._addCheck({
|
|
1237
|
+
kind: "max",
|
|
1238
|
+
value: 0,
|
|
1239
|
+
inclusive: !0,
|
|
1240
|
+
message: errorUtil.toString(message)
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
nonnegative(message) {
|
|
1244
|
+
return this._addCheck({
|
|
1245
|
+
kind: "min",
|
|
1246
|
+
value: 0,
|
|
1247
|
+
inclusive: !0,
|
|
1248
|
+
message: errorUtil.toString(message)
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
multipleOf(value, message) {
|
|
1252
|
+
return this._addCheck({
|
|
1253
|
+
kind: "multipleOf",
|
|
1254
|
+
value,
|
|
1255
|
+
message: errorUtil.toString(message)
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
finite(message) {
|
|
1259
|
+
return this._addCheck({
|
|
1260
|
+
kind: "finite",
|
|
1261
|
+
message: errorUtil.toString(message)
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
safe(message) {
|
|
1265
|
+
return this._addCheck({
|
|
1266
|
+
kind: "min",
|
|
1267
|
+
inclusive: !0,
|
|
1268
|
+
value: Number.MIN_SAFE_INTEGER,
|
|
1269
|
+
message: errorUtil.toString(message)
|
|
1270
|
+
})._addCheck({
|
|
1271
|
+
kind: "max",
|
|
1272
|
+
inclusive: !0,
|
|
1273
|
+
value: Number.MAX_SAFE_INTEGER,
|
|
1274
|
+
message: errorUtil.toString(message)
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
get minValue() {
|
|
1278
|
+
let min = null;
|
|
1279
|
+
for (let ch of this._def.checks)
|
|
1280
|
+
ch.kind === "min" && (min === null || ch.value > min) && (min = ch.value);
|
|
1281
|
+
return min;
|
|
1282
|
+
}
|
|
1283
|
+
get maxValue() {
|
|
1284
|
+
let max = null;
|
|
1285
|
+
for (let ch of this._def.checks)
|
|
1286
|
+
ch.kind === "max" && (max === null || ch.value < max) && (max = ch.value);
|
|
1287
|
+
return max;
|
|
1288
|
+
}
|
|
1289
|
+
get isInt() {
|
|
1290
|
+
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
1291
|
+
}
|
|
1292
|
+
get isFinite() {
|
|
1293
|
+
let max = null, min = null;
|
|
1294
|
+
for (let ch of this._def.checks) {
|
|
1295
|
+
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf")
|
|
1296
|
+
return !0;
|
|
1297
|
+
ch.kind === "min" ? (min === null || ch.value > min) && (min = ch.value) : ch.kind === "max" && (max === null || ch.value < max) && (max = ch.value);
|
|
1298
|
+
}
|
|
1299
|
+
return Number.isFinite(min) && Number.isFinite(max);
|
|
1300
|
+
}
|
|
1301
|
+
};
|
|
1302
|
+
ZodNumber.create = (params) => new ZodNumber({
|
|
1303
|
+
checks: [],
|
|
1304
|
+
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
1305
|
+
coerce: params?.coerce || !1,
|
|
1306
|
+
...processCreateParams(params)
|
|
1307
|
+
});
|
|
1308
|
+
var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
1309
|
+
constructor() {
|
|
1310
|
+
super(...arguments), this.min = this.gte, this.max = this.lte;
|
|
1311
|
+
}
|
|
1312
|
+
_parse(input) {
|
|
1313
|
+
if (this._def.coerce)
|
|
1314
|
+
try {
|
|
1315
|
+
input.data = BigInt(input.data);
|
|
1316
|
+
} catch {
|
|
1317
|
+
return this._getInvalidInput(input);
|
|
1318
|
+
}
|
|
1319
|
+
if (this._getType(input) !== ZodParsedType.bigint)
|
|
1320
|
+
return this._getInvalidInput(input);
|
|
1321
|
+
let ctx, status = new ParseStatus();
|
|
1322
|
+
for (let check of this._def.checks)
|
|
1323
|
+
check.kind === "min" ? (check.inclusive ? input.data < check.value : input.data <= check.value) && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
1324
|
+
code: ZodIssueCode.too_small,
|
|
1325
|
+
type: "bigint",
|
|
1326
|
+
minimum: check.value,
|
|
1327
|
+
inclusive: check.inclusive,
|
|
1328
|
+
message: check.message
|
|
1329
|
+
}), status.dirty()) : check.kind === "max" ? (check.inclusive ? input.data > check.value : input.data >= check.value) && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
1330
|
+
code: ZodIssueCode.too_big,
|
|
1331
|
+
type: "bigint",
|
|
1332
|
+
maximum: check.value,
|
|
1333
|
+
inclusive: check.inclusive,
|
|
1334
|
+
message: check.message
|
|
1335
|
+
}), status.dirty()) : check.kind === "multipleOf" ? input.data % check.value !== BigInt(0) && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
1336
|
+
code: ZodIssueCode.not_multiple_of,
|
|
1337
|
+
multipleOf: check.value,
|
|
1338
|
+
message: check.message
|
|
1339
|
+
}), status.dirty()) : util.assertNever(check);
|
|
1340
|
+
return { status: status.value, value: input.data };
|
|
1341
|
+
}
|
|
1342
|
+
_getInvalidInput(input) {
|
|
1343
|
+
let ctx = this._getOrReturnCtx(input);
|
|
1344
|
+
return addIssueToContext(ctx, {
|
|
1345
|
+
code: ZodIssueCode.invalid_type,
|
|
1346
|
+
expected: ZodParsedType.bigint,
|
|
1347
|
+
received: ctx.parsedType
|
|
1348
|
+
}), INVALID;
|
|
1349
|
+
}
|
|
1350
|
+
gte(value, message) {
|
|
1351
|
+
return this.setLimit("min", value, !0, errorUtil.toString(message));
|
|
1352
|
+
}
|
|
1353
|
+
gt(value, message) {
|
|
1354
|
+
return this.setLimit("min", value, !1, errorUtil.toString(message));
|
|
1355
|
+
}
|
|
1356
|
+
lte(value, message) {
|
|
1357
|
+
return this.setLimit("max", value, !0, errorUtil.toString(message));
|
|
1358
|
+
}
|
|
1359
|
+
lt(value, message) {
|
|
1360
|
+
return this.setLimit("max", value, !1, errorUtil.toString(message));
|
|
1361
|
+
}
|
|
1362
|
+
setLimit(kind, value, inclusive, message) {
|
|
1363
|
+
return new _ZodBigInt({
|
|
1364
|
+
...this._def,
|
|
1365
|
+
checks: [
|
|
1366
|
+
...this._def.checks,
|
|
1367
|
+
{
|
|
1368
|
+
kind,
|
|
1369
|
+
value,
|
|
1370
|
+
inclusive,
|
|
1371
|
+
message: errorUtil.toString(message)
|
|
1372
|
+
}
|
|
1373
|
+
]
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1376
|
+
_addCheck(check) {
|
|
1377
|
+
return new _ZodBigInt({
|
|
1378
|
+
...this._def,
|
|
1379
|
+
checks: [...this._def.checks, check]
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
positive(message) {
|
|
1383
|
+
return this._addCheck({
|
|
1384
|
+
kind: "min",
|
|
1385
|
+
value: BigInt(0),
|
|
1386
|
+
inclusive: !1,
|
|
1387
|
+
message: errorUtil.toString(message)
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
negative(message) {
|
|
1391
|
+
return this._addCheck({
|
|
1392
|
+
kind: "max",
|
|
1393
|
+
value: BigInt(0),
|
|
1394
|
+
inclusive: !1,
|
|
1395
|
+
message: errorUtil.toString(message)
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
nonpositive(message) {
|
|
1399
|
+
return this._addCheck({
|
|
1400
|
+
kind: "max",
|
|
1401
|
+
value: BigInt(0),
|
|
1402
|
+
inclusive: !0,
|
|
1403
|
+
message: errorUtil.toString(message)
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
nonnegative(message) {
|
|
1407
|
+
return this._addCheck({
|
|
1408
|
+
kind: "min",
|
|
1409
|
+
value: BigInt(0),
|
|
1410
|
+
inclusive: !0,
|
|
1411
|
+
message: errorUtil.toString(message)
|
|
1412
|
+
});
|
|
1413
|
+
}
|
|
1414
|
+
multipleOf(value, message) {
|
|
1415
|
+
return this._addCheck({
|
|
1416
|
+
kind: "multipleOf",
|
|
1417
|
+
value,
|
|
1418
|
+
message: errorUtil.toString(message)
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
get minValue() {
|
|
1422
|
+
let min = null;
|
|
1423
|
+
for (let ch of this._def.checks)
|
|
1424
|
+
ch.kind === "min" && (min === null || ch.value > min) && (min = ch.value);
|
|
1425
|
+
return min;
|
|
1426
|
+
}
|
|
1427
|
+
get maxValue() {
|
|
1428
|
+
let max = null;
|
|
1429
|
+
for (let ch of this._def.checks)
|
|
1430
|
+
ch.kind === "max" && (max === null || ch.value < max) && (max = ch.value);
|
|
1431
|
+
return max;
|
|
1432
|
+
}
|
|
1433
|
+
};
|
|
1434
|
+
ZodBigInt.create = (params) => new ZodBigInt({
|
|
1435
|
+
checks: [],
|
|
1436
|
+
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
1437
|
+
coerce: params?.coerce ?? !1,
|
|
1438
|
+
...processCreateParams(params)
|
|
1439
|
+
});
|
|
1440
|
+
var ZodBoolean = class extends ZodType {
|
|
1441
|
+
_parse(input) {
|
|
1442
|
+
if (this._def.coerce && (input.data = !!input.data), this._getType(input) !== ZodParsedType.boolean) {
|
|
1443
|
+
let ctx = this._getOrReturnCtx(input);
|
|
1444
|
+
return addIssueToContext(ctx, {
|
|
1445
|
+
code: ZodIssueCode.invalid_type,
|
|
1446
|
+
expected: ZodParsedType.boolean,
|
|
1447
|
+
received: ctx.parsedType
|
|
1448
|
+
}), INVALID;
|
|
1449
|
+
}
|
|
1450
|
+
return OK(input.data);
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
ZodBoolean.create = (params) => new ZodBoolean({
|
|
1454
|
+
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
1455
|
+
coerce: params?.coerce || !1,
|
|
1456
|
+
...processCreateParams(params)
|
|
1457
|
+
});
|
|
1458
|
+
var ZodDate = class _ZodDate extends ZodType {
|
|
1459
|
+
_parse(input) {
|
|
1460
|
+
if (this._def.coerce && (input.data = new Date(input.data)), this._getType(input) !== ZodParsedType.date) {
|
|
1461
|
+
let ctx2 = this._getOrReturnCtx(input);
|
|
1462
|
+
return addIssueToContext(ctx2, {
|
|
1463
|
+
code: ZodIssueCode.invalid_type,
|
|
1464
|
+
expected: ZodParsedType.date,
|
|
1465
|
+
received: ctx2.parsedType
|
|
1466
|
+
}), INVALID;
|
|
1467
|
+
}
|
|
1468
|
+
if (Number.isNaN(input.data.getTime())) {
|
|
1469
|
+
let ctx2 = this._getOrReturnCtx(input);
|
|
1470
|
+
return addIssueToContext(ctx2, {
|
|
1471
|
+
code: ZodIssueCode.invalid_date
|
|
1472
|
+
}), INVALID;
|
|
1473
|
+
}
|
|
1474
|
+
let status = new ParseStatus(), ctx;
|
|
1475
|
+
for (let check of this._def.checks)
|
|
1476
|
+
check.kind === "min" ? input.data.getTime() < check.value && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
1477
|
+
code: ZodIssueCode.too_small,
|
|
1478
|
+
message: check.message,
|
|
1479
|
+
inclusive: !0,
|
|
1480
|
+
exact: !1,
|
|
1481
|
+
minimum: check.value,
|
|
1482
|
+
type: "date"
|
|
1483
|
+
}), status.dirty()) : check.kind === "max" ? input.data.getTime() > check.value && (ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
|
|
1484
|
+
code: ZodIssueCode.too_big,
|
|
1485
|
+
message: check.message,
|
|
1486
|
+
inclusive: !0,
|
|
1487
|
+
exact: !1,
|
|
1488
|
+
maximum: check.value,
|
|
1489
|
+
type: "date"
|
|
1490
|
+
}), status.dirty()) : util.assertNever(check);
|
|
1491
|
+
return {
|
|
1492
|
+
status: status.value,
|
|
1493
|
+
value: new Date(input.data.getTime())
|
|
1494
|
+
};
|
|
1495
|
+
}
|
|
1496
|
+
_addCheck(check) {
|
|
1497
|
+
return new _ZodDate({
|
|
1498
|
+
...this._def,
|
|
1499
|
+
checks: [...this._def.checks, check]
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
min(minDate, message) {
|
|
1503
|
+
return this._addCheck({
|
|
1504
|
+
kind: "min",
|
|
1505
|
+
value: minDate.getTime(),
|
|
1506
|
+
message: errorUtil.toString(message)
|
|
1507
|
+
});
|
|
1508
|
+
}
|
|
1509
|
+
max(maxDate, message) {
|
|
1510
|
+
return this._addCheck({
|
|
1511
|
+
kind: "max",
|
|
1512
|
+
value: maxDate.getTime(),
|
|
1513
|
+
message: errorUtil.toString(message)
|
|
1514
|
+
});
|
|
1515
|
+
}
|
|
1516
|
+
get minDate() {
|
|
1517
|
+
let min = null;
|
|
1518
|
+
for (let ch of this._def.checks)
|
|
1519
|
+
ch.kind === "min" && (min === null || ch.value > min) && (min = ch.value);
|
|
1520
|
+
return min != null ? new Date(min) : null;
|
|
1521
|
+
}
|
|
1522
|
+
get maxDate() {
|
|
1523
|
+
let max = null;
|
|
1524
|
+
for (let ch of this._def.checks)
|
|
1525
|
+
ch.kind === "max" && (max === null || ch.value < max) && (max = ch.value);
|
|
1526
|
+
return max != null ? new Date(max) : null;
|
|
1527
|
+
}
|
|
1528
|
+
};
|
|
1529
|
+
ZodDate.create = (params) => new ZodDate({
|
|
1530
|
+
checks: [],
|
|
1531
|
+
coerce: params?.coerce || !1,
|
|
1532
|
+
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
1533
|
+
...processCreateParams(params)
|
|
1534
|
+
});
|
|
1535
|
+
var ZodSymbol = class extends ZodType {
|
|
1536
|
+
_parse(input) {
|
|
1537
|
+
if (this._getType(input) !== ZodParsedType.symbol) {
|
|
1538
|
+
let ctx = this._getOrReturnCtx(input);
|
|
1539
|
+
return addIssueToContext(ctx, {
|
|
1540
|
+
code: ZodIssueCode.invalid_type,
|
|
1541
|
+
expected: ZodParsedType.symbol,
|
|
1542
|
+
received: ctx.parsedType
|
|
1543
|
+
}), INVALID;
|
|
1544
|
+
}
|
|
1545
|
+
return OK(input.data);
|
|
1546
|
+
}
|
|
1547
|
+
};
|
|
1548
|
+
ZodSymbol.create = (params) => new ZodSymbol({
|
|
1549
|
+
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
1550
|
+
...processCreateParams(params)
|
|
1551
|
+
});
|
|
1552
|
+
var ZodUndefined = class extends ZodType {
|
|
1553
|
+
_parse(input) {
|
|
1554
|
+
if (this._getType(input) !== ZodParsedType.undefined) {
|
|
1555
|
+
let ctx = this._getOrReturnCtx(input);
|
|
1556
|
+
return addIssueToContext(ctx, {
|
|
1557
|
+
code: ZodIssueCode.invalid_type,
|
|
1558
|
+
expected: ZodParsedType.undefined,
|
|
1559
|
+
received: ctx.parsedType
|
|
1560
|
+
}), INVALID;
|
|
1561
|
+
}
|
|
1562
|
+
return OK(input.data);
|
|
1563
|
+
}
|
|
1564
|
+
};
|
|
1565
|
+
ZodUndefined.create = (params) => new ZodUndefined({
|
|
1566
|
+
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
1567
|
+
...processCreateParams(params)
|
|
1568
|
+
});
|
|
1569
|
+
var ZodNull = class extends ZodType {
|
|
1570
|
+
_parse(input) {
|
|
1571
|
+
if (this._getType(input) !== ZodParsedType.null) {
|
|
1572
|
+
let ctx = this._getOrReturnCtx(input);
|
|
1573
|
+
return addIssueToContext(ctx, {
|
|
1574
|
+
code: ZodIssueCode.invalid_type,
|
|
1575
|
+
expected: ZodParsedType.null,
|
|
1576
|
+
received: ctx.parsedType
|
|
1577
|
+
}), INVALID;
|
|
1578
|
+
}
|
|
1579
|
+
return OK(input.data);
|
|
1580
|
+
}
|
|
1581
|
+
};
|
|
1582
|
+
ZodNull.create = (params) => new ZodNull({
|
|
1583
|
+
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
1584
|
+
...processCreateParams(params)
|
|
1585
|
+
});
|
|
1586
|
+
var ZodAny = class extends ZodType {
|
|
1587
|
+
constructor() {
|
|
1588
|
+
super(...arguments), this._any = !0;
|
|
1589
|
+
}
|
|
1590
|
+
_parse(input) {
|
|
1591
|
+
return OK(input.data);
|
|
1592
|
+
}
|
|
1593
|
+
};
|
|
1594
|
+
ZodAny.create = (params) => new ZodAny({
|
|
1595
|
+
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
1596
|
+
...processCreateParams(params)
|
|
1597
|
+
});
|
|
1598
|
+
var ZodUnknown = class extends ZodType {
|
|
1599
|
+
constructor() {
|
|
1600
|
+
super(...arguments), this._unknown = !0;
|
|
1601
|
+
}
|
|
1602
|
+
_parse(input) {
|
|
1603
|
+
return OK(input.data);
|
|
1604
|
+
}
|
|
1605
|
+
};
|
|
1606
|
+
ZodUnknown.create = (params) => new ZodUnknown({
|
|
1607
|
+
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
1608
|
+
...processCreateParams(params)
|
|
1609
|
+
});
|
|
1610
|
+
var ZodNever = class extends ZodType {
|
|
1611
|
+
_parse(input) {
|
|
1612
|
+
let ctx = this._getOrReturnCtx(input);
|
|
1613
|
+
return addIssueToContext(ctx, {
|
|
1614
|
+
code: ZodIssueCode.invalid_type,
|
|
1615
|
+
expected: ZodParsedType.never,
|
|
1616
|
+
received: ctx.parsedType
|
|
1617
|
+
}), INVALID;
|
|
1618
|
+
}
|
|
1619
|
+
};
|
|
1620
|
+
ZodNever.create = (params) => new ZodNever({
|
|
1621
|
+
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
1622
|
+
...processCreateParams(params)
|
|
1623
|
+
});
|
|
1624
|
+
var ZodVoid = class extends ZodType {
|
|
1625
|
+
_parse(input) {
|
|
1626
|
+
if (this._getType(input) !== ZodParsedType.undefined) {
|
|
1627
|
+
let ctx = this._getOrReturnCtx(input);
|
|
1628
|
+
return addIssueToContext(ctx, {
|
|
1629
|
+
code: ZodIssueCode.invalid_type,
|
|
1630
|
+
expected: ZodParsedType.void,
|
|
1631
|
+
received: ctx.parsedType
|
|
1632
|
+
}), INVALID;
|
|
1633
|
+
}
|
|
1634
|
+
return OK(input.data);
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
ZodVoid.create = (params) => new ZodVoid({
|
|
1638
|
+
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
1639
|
+
...processCreateParams(params)
|
|
1640
|
+
});
|
|
1641
|
+
var ZodArray = class _ZodArray extends ZodType {
|
|
1642
|
+
_parse(input) {
|
|
1643
|
+
let { ctx, status } = this._processInputParams(input), def = this._def;
|
|
1644
|
+
if (ctx.parsedType !== ZodParsedType.array)
|
|
1645
|
+
return addIssueToContext(ctx, {
|
|
1646
|
+
code: ZodIssueCode.invalid_type,
|
|
1647
|
+
expected: ZodParsedType.array,
|
|
1648
|
+
received: ctx.parsedType
|
|
1649
|
+
}), INVALID;
|
|
1650
|
+
if (def.exactLength !== null) {
|
|
1651
|
+
let tooBig = ctx.data.length > def.exactLength.value, tooSmall = ctx.data.length < def.exactLength.value;
|
|
1652
|
+
(tooBig || tooSmall) && (addIssueToContext(ctx, {
|
|
1653
|
+
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
1654
|
+
minimum: tooSmall ? def.exactLength.value : void 0,
|
|
1655
|
+
maximum: tooBig ? def.exactLength.value : void 0,
|
|
1656
|
+
type: "array",
|
|
1657
|
+
inclusive: !0,
|
|
1658
|
+
exact: !0,
|
|
1659
|
+
message: def.exactLength.message
|
|
1660
|
+
}), status.dirty());
|
|
1661
|
+
}
|
|
1662
|
+
if (def.minLength !== null && ctx.data.length < def.minLength.value && (addIssueToContext(ctx, {
|
|
1663
|
+
code: ZodIssueCode.too_small,
|
|
1664
|
+
minimum: def.minLength.value,
|
|
1665
|
+
type: "array",
|
|
1666
|
+
inclusive: !0,
|
|
1667
|
+
exact: !1,
|
|
1668
|
+
message: def.minLength.message
|
|
1669
|
+
}), status.dirty()), def.maxLength !== null && ctx.data.length > def.maxLength.value && (addIssueToContext(ctx, {
|
|
1670
|
+
code: ZodIssueCode.too_big,
|
|
1671
|
+
maximum: def.maxLength.value,
|
|
1672
|
+
type: "array",
|
|
1673
|
+
inclusive: !0,
|
|
1674
|
+
exact: !1,
|
|
1675
|
+
message: def.maxLength.message
|
|
1676
|
+
}), status.dirty()), ctx.common.async)
|
|
1677
|
+
return Promise.all([...ctx.data].map((item, i) => def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i)))).then((result2) => ParseStatus.mergeArray(status, result2));
|
|
1678
|
+
let result = [...ctx.data].map((item, i) => def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
1679
|
+
return ParseStatus.mergeArray(status, result);
|
|
1680
|
+
}
|
|
1681
|
+
get element() {
|
|
1682
|
+
return this._def.type;
|
|
1683
|
+
}
|
|
1684
|
+
min(minLength, message) {
|
|
1685
|
+
return new _ZodArray({
|
|
1686
|
+
...this._def,
|
|
1687
|
+
minLength: { value: minLength, message: errorUtil.toString(message) }
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
max(maxLength, message) {
|
|
1691
|
+
return new _ZodArray({
|
|
1692
|
+
...this._def,
|
|
1693
|
+
maxLength: { value: maxLength, message: errorUtil.toString(message) }
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
length(len, message) {
|
|
1697
|
+
return new _ZodArray({
|
|
1698
|
+
...this._def,
|
|
1699
|
+
exactLength: { value: len, message: errorUtil.toString(message) }
|
|
1700
|
+
});
|
|
1701
|
+
}
|
|
1702
|
+
nonempty(message) {
|
|
1703
|
+
return this.min(1, message);
|
|
1704
|
+
}
|
|
1705
|
+
};
|
|
1706
|
+
ZodArray.create = (schema, params) => new ZodArray({
|
|
1707
|
+
type: schema,
|
|
1708
|
+
minLength: null,
|
|
1709
|
+
maxLength: null,
|
|
1710
|
+
exactLength: null,
|
|
1711
|
+
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
1712
|
+
...processCreateParams(params)
|
|
1713
|
+
});
|
|
1714
|
+
function deepPartialify(schema) {
|
|
1715
|
+
if (schema instanceof ZodObject) {
|
|
1716
|
+
let newShape = {};
|
|
1717
|
+
for (let key in schema.shape) {
|
|
1718
|
+
let fieldSchema = schema.shape[key];
|
|
1719
|
+
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
1720
|
+
}
|
|
1721
|
+
return new ZodObject({
|
|
1722
|
+
...schema._def,
|
|
1723
|
+
shape: () => newShape
|
|
1724
|
+
});
|
|
1725
|
+
} else return schema instanceof ZodArray ? new ZodArray({
|
|
1726
|
+
...schema._def,
|
|
1727
|
+
type: deepPartialify(schema.element)
|
|
1728
|
+
}) : 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;
|
|
1729
|
+
}
|
|
1730
|
+
var ZodObject = class _ZodObject extends ZodType {
|
|
1731
|
+
constructor() {
|
|
1732
|
+
super(...arguments), this._cached = null, this.nonstrict = this.passthrough, this.augment = this.extend;
|
|
1733
|
+
}
|
|
1734
|
+
_getCached() {
|
|
1735
|
+
if (this._cached !== null)
|
|
1736
|
+
return this._cached;
|
|
1737
|
+
let shape = this._def.shape(), keys = util.objectKeys(shape);
|
|
1738
|
+
return this._cached = { shape, keys }, this._cached;
|
|
1739
|
+
}
|
|
1740
|
+
_parse(input) {
|
|
1741
|
+
if (this._getType(input) !== ZodParsedType.object) {
|
|
1742
|
+
let ctx2 = this._getOrReturnCtx(input);
|
|
1743
|
+
return addIssueToContext(ctx2, {
|
|
1744
|
+
code: ZodIssueCode.invalid_type,
|
|
1745
|
+
expected: ZodParsedType.object,
|
|
1746
|
+
received: ctx2.parsedType
|
|
1747
|
+
}), INVALID;
|
|
1748
|
+
}
|
|
1749
|
+
let { status, ctx } = this._processInputParams(input), { shape, keys: shapeKeys } = this._getCached(), extraKeys = [];
|
|
1750
|
+
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip"))
|
|
1751
|
+
for (let key in ctx.data)
|
|
1752
|
+
shapeKeys.includes(key) || extraKeys.push(key);
|
|
1753
|
+
let pairs = [];
|
|
1754
|
+
for (let key of shapeKeys) {
|
|
1755
|
+
let keyValidator = shape[key], value = ctx.data[key];
|
|
1756
|
+
pairs.push({
|
|
1757
|
+
key: { status: "valid", value: key },
|
|
1758
|
+
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
1759
|
+
alwaysSet: key in ctx.data
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
if (this._def.catchall instanceof ZodNever) {
|
|
1763
|
+
let unknownKeys = this._def.unknownKeys;
|
|
1764
|
+
if (unknownKeys === "passthrough")
|
|
1765
|
+
for (let key of extraKeys)
|
|
1766
|
+
pairs.push({
|
|
1767
|
+
key: { status: "valid", value: key },
|
|
1768
|
+
value: { status: "valid", value: ctx.data[key] }
|
|
1769
|
+
});
|
|
1770
|
+
else if (unknownKeys === "strict")
|
|
1771
|
+
extraKeys.length > 0 && (addIssueToContext(ctx, {
|
|
1772
|
+
code: ZodIssueCode.unrecognized_keys,
|
|
1773
|
+
keys: extraKeys
|
|
1774
|
+
}), status.dirty());
|
|
1775
|
+
else if (unknownKeys !== "strip")
|
|
1776
|
+
throw new Error("Internal ZodObject error: invalid unknownKeys value.");
|
|
1777
|
+
} else {
|
|
1778
|
+
let catchall = this._def.catchall;
|
|
1779
|
+
for (let key of extraKeys) {
|
|
1780
|
+
let value = ctx.data[key];
|
|
1781
|
+
pairs.push({
|
|
1782
|
+
key: { status: "valid", value: key },
|
|
1783
|
+
value: catchall._parse(
|
|
1784
|
+
new ParseInputLazyPath(ctx, value, ctx.path, key)
|
|
1785
|
+
//, ctx.child(key), value, getParsedType(value)
|
|
1786
|
+
),
|
|
1787
|
+
alwaysSet: key in ctx.data
|
|
1788
|
+
});
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
return ctx.common.async ? Promise.resolve().then(async () => {
|
|
1792
|
+
let syncPairs = [];
|
|
1793
|
+
for (let pair of pairs) {
|
|
1794
|
+
let key = await pair.key, value = await pair.value;
|
|
1795
|
+
syncPairs.push({
|
|
1796
|
+
key,
|
|
1797
|
+
value,
|
|
1798
|
+
alwaysSet: pair.alwaysSet
|
|
1799
|
+
});
|
|
1800
|
+
}
|
|
1801
|
+
return syncPairs;
|
|
1802
|
+
}).then((syncPairs) => ParseStatus.mergeObjectSync(status, syncPairs)) : ParseStatus.mergeObjectSync(status, pairs);
|
|
1803
|
+
}
|
|
1804
|
+
get shape() {
|
|
1805
|
+
return this._def.shape();
|
|
1806
|
+
}
|
|
1807
|
+
strict(message) {
|
|
1808
|
+
return errorUtil.errToObj, new _ZodObject({
|
|
1809
|
+
...this._def,
|
|
1810
|
+
unknownKeys: "strict",
|
|
1811
|
+
...message !== void 0 ? {
|
|
1812
|
+
errorMap: (issue, ctx) => {
|
|
1813
|
+
let defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
|
1814
|
+
return issue.code === "unrecognized_keys" ? {
|
|
1815
|
+
message: errorUtil.errToObj(message).message ?? defaultError
|
|
1816
|
+
} : {
|
|
1817
|
+
message: defaultError
|
|
1818
|
+
};
|
|
1819
|
+
}
|
|
1820
|
+
} : {}
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1823
|
+
strip() {
|
|
1824
|
+
return new _ZodObject({
|
|
1825
|
+
...this._def,
|
|
1826
|
+
unknownKeys: "strip"
|
|
1827
|
+
});
|
|
1828
|
+
}
|
|
1829
|
+
passthrough() {
|
|
1830
|
+
return new _ZodObject({
|
|
1831
|
+
...this._def,
|
|
1832
|
+
unknownKeys: "passthrough"
|
|
1833
|
+
});
|
|
1834
|
+
}
|
|
1835
|
+
// const AugmentFactory =
|
|
1836
|
+
// <Def extends ZodObjectDef>(def: Def) =>
|
|
1837
|
+
// <Augmentation extends ZodRawShape>(
|
|
1838
|
+
// augmentation: Augmentation
|
|
1839
|
+
// ): ZodObject<
|
|
1840
|
+
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
1841
|
+
// Def["unknownKeys"],
|
|
1842
|
+
// Def["catchall"]
|
|
1843
|
+
// > => {
|
|
1844
|
+
// return new ZodObject({
|
|
1845
|
+
// ...def,
|
|
1846
|
+
// shape: () => ({
|
|
1847
|
+
// ...def.shape(),
|
|
1848
|
+
// ...augmentation,
|
|
1849
|
+
// }),
|
|
1850
|
+
// }) as any;
|
|
1851
|
+
// };
|
|
1852
|
+
extend(augmentation) {
|
|
1853
|
+
return new _ZodObject({
|
|
1854
|
+
...this._def,
|
|
1855
|
+
shape: () => ({
|
|
1856
|
+
...this._def.shape(),
|
|
1857
|
+
...augmentation
|
|
1858
|
+
})
|
|
1859
|
+
});
|
|
1860
|
+
}
|
|
1861
|
+
/**
|
|
1862
|
+
* Prior to zod@1.0.12 there was a bug in the
|
|
1863
|
+
* inferred type of merged objects. Please
|
|
1864
|
+
* upgrade if you are experiencing issues.
|
|
1865
|
+
*/
|
|
1866
|
+
merge(merging) {
|
|
1867
|
+
return new _ZodObject({
|
|
1868
|
+
unknownKeys: merging._def.unknownKeys,
|
|
1869
|
+
catchall: merging._def.catchall,
|
|
1870
|
+
shape: () => ({
|
|
1871
|
+
...this._def.shape(),
|
|
1872
|
+
...merging._def.shape()
|
|
1873
|
+
}),
|
|
1874
|
+
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
1875
|
+
});
|
|
1876
|
+
}
|
|
1877
|
+
// merge<
|
|
1878
|
+
// Incoming extends AnyZodObject,
|
|
1879
|
+
// Augmentation extends Incoming["shape"],
|
|
1880
|
+
// NewOutput extends {
|
|
1881
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
1882
|
+
// ? Augmentation[k]["_output"]
|
|
1883
|
+
// : k extends keyof Output
|
|
1884
|
+
// ? Output[k]
|
|
1885
|
+
// : never;
|
|
1886
|
+
// },
|
|
1887
|
+
// NewInput extends {
|
|
1888
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
1889
|
+
// ? Augmentation[k]["_input"]
|
|
1890
|
+
// : k extends keyof Input
|
|
1891
|
+
// ? Input[k]
|
|
1892
|
+
// : never;
|
|
1893
|
+
// }
|
|
1894
|
+
// >(
|
|
1895
|
+
// merging: Incoming
|
|
1896
|
+
// ): ZodObject<
|
|
1897
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
1898
|
+
// Incoming["_def"]["unknownKeys"],
|
|
1899
|
+
// Incoming["_def"]["catchall"],
|
|
1900
|
+
// NewOutput,
|
|
1901
|
+
// NewInput
|
|
1902
|
+
// > {
|
|
1903
|
+
// const merged: any = new ZodObject({
|
|
1904
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
1905
|
+
// catchall: merging._def.catchall,
|
|
1906
|
+
// shape: () =>
|
|
1907
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
1908
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
1909
|
+
// }) as any;
|
|
1910
|
+
// return merged;
|
|
1911
|
+
// }
|
|
1912
|
+
setKey(key, schema) {
|
|
1913
|
+
return this.augment({ [key]: schema });
|
|
1914
|
+
}
|
|
1915
|
+
// merge<Incoming extends AnyZodObject>(
|
|
1916
|
+
// merging: Incoming
|
|
1917
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
1918
|
+
// ZodObject<
|
|
1919
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
1920
|
+
// Incoming["_def"]["unknownKeys"],
|
|
1921
|
+
// Incoming["_def"]["catchall"]
|
|
1922
|
+
// > {
|
|
1923
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
|
1924
|
+
// // this._def.shape(),
|
|
1925
|
+
// // merging._def.shape()
|
|
1926
|
+
// // );
|
|
1927
|
+
// const merged: any = new ZodObject({
|
|
1928
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
1929
|
+
// catchall: merging._def.catchall,
|
|
1930
|
+
// shape: () =>
|
|
1931
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
1932
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
1933
|
+
// }) as any;
|
|
1934
|
+
// return merged;
|
|
1935
|
+
// }
|
|
1936
|
+
catchall(index) {
|
|
1937
|
+
return new _ZodObject({
|
|
1938
|
+
...this._def,
|
|
1939
|
+
catchall: index
|
|
1940
|
+
});
|
|
1941
|
+
}
|
|
1942
|
+
pick(mask) {
|
|
1943
|
+
let shape = {};
|
|
1944
|
+
for (let key of util.objectKeys(mask))
|
|
1945
|
+
mask[key] && this.shape[key] && (shape[key] = this.shape[key]);
|
|
1946
|
+
return new _ZodObject({
|
|
1947
|
+
...this._def,
|
|
1948
|
+
shape: () => shape
|
|
1949
|
+
});
|
|
1950
|
+
}
|
|
1951
|
+
omit(mask) {
|
|
1952
|
+
let shape = {};
|
|
1953
|
+
for (let key of util.objectKeys(this.shape))
|
|
1954
|
+
mask[key] || (shape[key] = this.shape[key]);
|
|
1955
|
+
return new _ZodObject({
|
|
1956
|
+
...this._def,
|
|
1957
|
+
shape: () => shape
|
|
1958
|
+
});
|
|
1959
|
+
}
|
|
1960
|
+
/**
|
|
1961
|
+
* @deprecated
|
|
1962
|
+
*/
|
|
1963
|
+
deepPartial() {
|
|
1964
|
+
return deepPartialify(this);
|
|
1965
|
+
}
|
|
1966
|
+
partial(mask) {
|
|
1967
|
+
let newShape = {};
|
|
1968
|
+
for (let key of util.objectKeys(this.shape)) {
|
|
1969
|
+
let fieldSchema = this.shape[key];
|
|
1970
|
+
mask && !mask[key] ? newShape[key] = fieldSchema : newShape[key] = fieldSchema.optional();
|
|
1971
|
+
}
|
|
1972
|
+
return new _ZodObject({
|
|
1973
|
+
...this._def,
|
|
1974
|
+
shape: () => newShape
|
|
1975
|
+
});
|
|
1976
|
+
}
|
|
1977
|
+
required(mask) {
|
|
1978
|
+
let newShape = {};
|
|
1979
|
+
for (let key of util.objectKeys(this.shape))
|
|
1980
|
+
if (mask && !mask[key])
|
|
1981
|
+
newShape[key] = this.shape[key];
|
|
1982
|
+
else {
|
|
1983
|
+
let newField = this.shape[key];
|
|
1984
|
+
for (; newField instanceof ZodOptional; )
|
|
1985
|
+
newField = newField._def.innerType;
|
|
1986
|
+
newShape[key] = newField;
|
|
1987
|
+
}
|
|
1988
|
+
return new _ZodObject({
|
|
1989
|
+
...this._def,
|
|
1990
|
+
shape: () => newShape
|
|
1991
|
+
});
|
|
1992
|
+
}
|
|
1993
|
+
keyof() {
|
|
1994
|
+
return createZodEnum(util.objectKeys(this.shape));
|
|
1995
|
+
}
|
|
1996
|
+
};
|
|
1997
|
+
ZodObject.create = (shape, params) => new ZodObject({
|
|
1998
|
+
shape: () => shape,
|
|
1999
|
+
unknownKeys: "strip",
|
|
2000
|
+
catchall: ZodNever.create(),
|
|
2001
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2002
|
+
...processCreateParams(params)
|
|
2003
|
+
});
|
|
2004
|
+
ZodObject.strictCreate = (shape, params) => new ZodObject({
|
|
2005
|
+
shape: () => shape,
|
|
2006
|
+
unknownKeys: "strict",
|
|
2007
|
+
catchall: ZodNever.create(),
|
|
2008
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2009
|
+
...processCreateParams(params)
|
|
2010
|
+
});
|
|
2011
|
+
ZodObject.lazycreate = (shape, params) => new ZodObject({
|
|
2012
|
+
shape,
|
|
2013
|
+
unknownKeys: "strip",
|
|
2014
|
+
catchall: ZodNever.create(),
|
|
2015
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2016
|
+
...processCreateParams(params)
|
|
2017
|
+
});
|
|
2018
|
+
var ZodUnion = class extends ZodType {
|
|
2019
|
+
_parse(input) {
|
|
2020
|
+
let { ctx } = this._processInputParams(input), options = this._def.options;
|
|
2021
|
+
function handleResults(results) {
|
|
2022
|
+
for (let result of results)
|
|
2023
|
+
if (result.result.status === "valid")
|
|
2024
|
+
return result.result;
|
|
2025
|
+
for (let result of results)
|
|
2026
|
+
if (result.result.status === "dirty")
|
|
2027
|
+
return ctx.common.issues.push(...result.ctx.common.issues), result.result;
|
|
2028
|
+
let unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
2029
|
+
return addIssueToContext(ctx, {
|
|
2030
|
+
code: ZodIssueCode.invalid_union,
|
|
2031
|
+
unionErrors
|
|
2032
|
+
}), INVALID;
|
|
2033
|
+
}
|
|
2034
|
+
if (ctx.common.async)
|
|
2035
|
+
return Promise.all(options.map(async (option) => {
|
|
2036
|
+
let childCtx = {
|
|
2037
|
+
...ctx,
|
|
2038
|
+
common: {
|
|
2039
|
+
...ctx.common,
|
|
2040
|
+
issues: []
|
|
2041
|
+
},
|
|
2042
|
+
parent: null
|
|
2043
|
+
};
|
|
2044
|
+
return {
|
|
2045
|
+
result: await option._parseAsync({
|
|
2046
|
+
data: ctx.data,
|
|
2047
|
+
path: ctx.path,
|
|
2048
|
+
parent: childCtx
|
|
2049
|
+
}),
|
|
2050
|
+
ctx: childCtx
|
|
2051
|
+
};
|
|
2052
|
+
})).then(handleResults);
|
|
2053
|
+
{
|
|
2054
|
+
let dirty, issues = [];
|
|
2055
|
+
for (let option of options) {
|
|
2056
|
+
let childCtx = {
|
|
2057
|
+
...ctx,
|
|
2058
|
+
common: {
|
|
2059
|
+
...ctx.common,
|
|
2060
|
+
issues: []
|
|
2061
|
+
},
|
|
2062
|
+
parent: null
|
|
2063
|
+
}, result = option._parseSync({
|
|
2064
|
+
data: ctx.data,
|
|
2065
|
+
path: ctx.path,
|
|
2066
|
+
parent: childCtx
|
|
2067
|
+
});
|
|
2068
|
+
if (result.status === "valid")
|
|
2069
|
+
return result;
|
|
2070
|
+
result.status === "dirty" && !dirty && (dirty = { result, ctx: childCtx }), childCtx.common.issues.length && issues.push(childCtx.common.issues);
|
|
2071
|
+
}
|
|
2072
|
+
if (dirty)
|
|
2073
|
+
return ctx.common.issues.push(...dirty.ctx.common.issues), dirty.result;
|
|
2074
|
+
let unionErrors = issues.map((issues2) => new ZodError(issues2));
|
|
2075
|
+
return addIssueToContext(ctx, {
|
|
2076
|
+
code: ZodIssueCode.invalid_union,
|
|
2077
|
+
unionErrors
|
|
2078
|
+
}), INVALID;
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
get options() {
|
|
2082
|
+
return this._def.options;
|
|
2083
|
+
}
|
|
2084
|
+
};
|
|
2085
|
+
ZodUnion.create = (types, params) => new ZodUnion({
|
|
2086
|
+
options: types,
|
|
2087
|
+
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
2088
|
+
...processCreateParams(params)
|
|
2089
|
+
});
|
|
2090
|
+
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 {
|
|
2091
|
+
_parse(input) {
|
|
2092
|
+
let { ctx } = this._processInputParams(input);
|
|
2093
|
+
if (ctx.parsedType !== ZodParsedType.object)
|
|
2094
|
+
return addIssueToContext(ctx, {
|
|
2095
|
+
code: ZodIssueCode.invalid_type,
|
|
2096
|
+
expected: ZodParsedType.object,
|
|
2097
|
+
received: ctx.parsedType
|
|
2098
|
+
}), INVALID;
|
|
2099
|
+
let discriminator = this.discriminator, discriminatorValue = ctx.data[discriminator], option = this.optionsMap.get(discriminatorValue);
|
|
2100
|
+
return option ? ctx.common.async ? option._parseAsync({
|
|
2101
|
+
data: ctx.data,
|
|
2102
|
+
path: ctx.path,
|
|
2103
|
+
parent: ctx
|
|
2104
|
+
}) : option._parseSync({
|
|
2105
|
+
data: ctx.data,
|
|
2106
|
+
path: ctx.path,
|
|
2107
|
+
parent: ctx
|
|
2108
|
+
}) : (addIssueToContext(ctx, {
|
|
2109
|
+
code: ZodIssueCode.invalid_union_discriminator,
|
|
2110
|
+
options: Array.from(this.optionsMap.keys()),
|
|
2111
|
+
path: [discriminator]
|
|
2112
|
+
}), INVALID);
|
|
2113
|
+
}
|
|
2114
|
+
get discriminator() {
|
|
2115
|
+
return this._def.discriminator;
|
|
2116
|
+
}
|
|
2117
|
+
get options() {
|
|
2118
|
+
return this._def.options;
|
|
2119
|
+
}
|
|
2120
|
+
get optionsMap() {
|
|
2121
|
+
return this._def.optionsMap;
|
|
2122
|
+
}
|
|
2123
|
+
/**
|
|
2124
|
+
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
2125
|
+
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
2126
|
+
* have a different value for each object in the union.
|
|
2127
|
+
* @param discriminator the name of the discriminator property
|
|
2128
|
+
* @param types an array of object schemas
|
|
2129
|
+
* @param params
|
|
2130
|
+
*/
|
|
2131
|
+
static create(discriminator, options, params) {
|
|
2132
|
+
let optionsMap = /* @__PURE__ */ new Map();
|
|
2133
|
+
for (let type of options) {
|
|
2134
|
+
let discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
2135
|
+
if (!discriminatorValues.length)
|
|
2136
|
+
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
2137
|
+
for (let value of discriminatorValues) {
|
|
2138
|
+
if (optionsMap.has(value))
|
|
2139
|
+
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
2140
|
+
optionsMap.set(value, type);
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
return new _ZodDiscriminatedUnion({
|
|
2144
|
+
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
2145
|
+
discriminator,
|
|
2146
|
+
options,
|
|
2147
|
+
optionsMap,
|
|
2148
|
+
...processCreateParams(params)
|
|
2149
|
+
});
|
|
2150
|
+
}
|
|
2151
|
+
};
|
|
2152
|
+
function mergeValues(a, b) {
|
|
2153
|
+
let aType = getParsedType(a), bType = getParsedType(b);
|
|
2154
|
+
if (a === b)
|
|
2155
|
+
return { valid: !0, data: a };
|
|
2156
|
+
if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
2157
|
+
let bKeys = util.objectKeys(b), sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1), newObj = { ...a, ...b };
|
|
2158
|
+
for (let key of sharedKeys) {
|
|
2159
|
+
let sharedValue = mergeValues(a[key], b[key]);
|
|
2160
|
+
if (!sharedValue.valid)
|
|
2161
|
+
return { valid: !1 };
|
|
2162
|
+
newObj[key] = sharedValue.data;
|
|
2163
|
+
}
|
|
2164
|
+
return { valid: !0, data: newObj };
|
|
2165
|
+
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
2166
|
+
if (a.length !== b.length)
|
|
2167
|
+
return { valid: !1 };
|
|
2168
|
+
let newArray = [];
|
|
2169
|
+
for (let index = 0; index < a.length; index++) {
|
|
2170
|
+
let itemA = a[index], itemB = b[index], sharedValue = mergeValues(itemA, itemB);
|
|
2171
|
+
if (!sharedValue.valid)
|
|
2172
|
+
return { valid: !1 };
|
|
2173
|
+
newArray.push(sharedValue.data);
|
|
2174
|
+
}
|
|
2175
|
+
return { valid: !0, data: newArray };
|
|
2176
|
+
} else return aType === ZodParsedType.date && bType === ZodParsedType.date && +a == +b ? { valid: !0, data: a } : { valid: !1 };
|
|
2177
|
+
}
|
|
2178
|
+
var ZodIntersection = class extends ZodType {
|
|
2179
|
+
_parse(input) {
|
|
2180
|
+
let { status, ctx } = this._processInputParams(input), handleParsed = (parsedLeft, parsedRight) => {
|
|
2181
|
+
if (isAborted(parsedLeft) || isAborted(parsedRight))
|
|
2182
|
+
return INVALID;
|
|
2183
|
+
let merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
2184
|
+
return merged.valid ? ((isDirty(parsedLeft) || isDirty(parsedRight)) && status.dirty(), { status: status.value, value: merged.data }) : (addIssueToContext(ctx, {
|
|
2185
|
+
code: ZodIssueCode.invalid_intersection_types
|
|
2186
|
+
}), INVALID);
|
|
2187
|
+
};
|
|
2188
|
+
return ctx.common.async ? Promise.all([
|
|
2189
|
+
this._def.left._parseAsync({
|
|
2190
|
+
data: ctx.data,
|
|
2191
|
+
path: ctx.path,
|
|
2192
|
+
parent: ctx
|
|
2193
|
+
}),
|
|
2194
|
+
this._def.right._parseAsync({
|
|
2195
|
+
data: ctx.data,
|
|
2196
|
+
path: ctx.path,
|
|
2197
|
+
parent: ctx
|
|
2198
|
+
})
|
|
2199
|
+
]).then(([left, right]) => handleParsed(left, right)) : handleParsed(this._def.left._parseSync({
|
|
2200
|
+
data: ctx.data,
|
|
2201
|
+
path: ctx.path,
|
|
2202
|
+
parent: ctx
|
|
2203
|
+
}), this._def.right._parseSync({
|
|
2204
|
+
data: ctx.data,
|
|
2205
|
+
path: ctx.path,
|
|
2206
|
+
parent: ctx
|
|
2207
|
+
}));
|
|
2208
|
+
}
|
|
2209
|
+
};
|
|
2210
|
+
ZodIntersection.create = (left, right, params) => new ZodIntersection({
|
|
2211
|
+
left,
|
|
2212
|
+
right,
|
|
2213
|
+
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
2214
|
+
...processCreateParams(params)
|
|
2215
|
+
});
|
|
2216
|
+
var ZodTuple = class _ZodTuple extends ZodType {
|
|
2217
|
+
_parse(input) {
|
|
2218
|
+
let { status, ctx } = this._processInputParams(input);
|
|
2219
|
+
if (ctx.parsedType !== ZodParsedType.array)
|
|
2220
|
+
return addIssueToContext(ctx, {
|
|
2221
|
+
code: ZodIssueCode.invalid_type,
|
|
2222
|
+
expected: ZodParsedType.array,
|
|
2223
|
+
received: ctx.parsedType
|
|
2224
|
+
}), INVALID;
|
|
2225
|
+
if (ctx.data.length < this._def.items.length)
|
|
2226
|
+
return addIssueToContext(ctx, {
|
|
2227
|
+
code: ZodIssueCode.too_small,
|
|
2228
|
+
minimum: this._def.items.length,
|
|
2229
|
+
inclusive: !0,
|
|
2230
|
+
exact: !1,
|
|
2231
|
+
type: "array"
|
|
2232
|
+
}), INVALID;
|
|
2233
|
+
!this._def.rest && ctx.data.length > this._def.items.length && (addIssueToContext(ctx, {
|
|
2234
|
+
code: ZodIssueCode.too_big,
|
|
2235
|
+
maximum: this._def.items.length,
|
|
2236
|
+
inclusive: !0,
|
|
2237
|
+
exact: !1,
|
|
2238
|
+
type: "array"
|
|
2239
|
+
}), status.dirty());
|
|
2240
|
+
let items = [...ctx.data].map((item, itemIndex) => {
|
|
2241
|
+
let schema = this._def.items[itemIndex] || this._def.rest;
|
|
2242
|
+
return schema ? schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex)) : null;
|
|
2243
|
+
}).filter((x) => !!x);
|
|
2244
|
+
return ctx.common.async ? Promise.all(items).then((results) => ParseStatus.mergeArray(status, results)) : ParseStatus.mergeArray(status, items);
|
|
2245
|
+
}
|
|
2246
|
+
get items() {
|
|
2247
|
+
return this._def.items;
|
|
2248
|
+
}
|
|
2249
|
+
rest(rest) {
|
|
2250
|
+
return new _ZodTuple({
|
|
2251
|
+
...this._def,
|
|
2252
|
+
rest
|
|
2253
|
+
});
|
|
2254
|
+
}
|
|
2255
|
+
};
|
|
2256
|
+
ZodTuple.create = (schemas, params) => {
|
|
2257
|
+
if (!Array.isArray(schemas))
|
|
2258
|
+
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
2259
|
+
return new ZodTuple({
|
|
2260
|
+
items: schemas,
|
|
2261
|
+
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
2262
|
+
rest: null,
|
|
2263
|
+
...processCreateParams(params)
|
|
2264
|
+
});
|
|
2265
|
+
};
|
|
2266
|
+
var ZodRecord = class _ZodRecord extends ZodType {
|
|
2267
|
+
get keySchema() {
|
|
2268
|
+
return this._def.keyType;
|
|
2269
|
+
}
|
|
2270
|
+
get valueSchema() {
|
|
2271
|
+
return this._def.valueType;
|
|
2272
|
+
}
|
|
2273
|
+
_parse(input) {
|
|
2274
|
+
let { status, ctx } = this._processInputParams(input);
|
|
2275
|
+
if (ctx.parsedType !== ZodParsedType.object)
|
|
2276
|
+
return addIssueToContext(ctx, {
|
|
2277
|
+
code: ZodIssueCode.invalid_type,
|
|
2278
|
+
expected: ZodParsedType.object,
|
|
2279
|
+
received: ctx.parsedType
|
|
2280
|
+
}), INVALID;
|
|
2281
|
+
let pairs = [], keyType = this._def.keyType, valueType = this._def.valueType;
|
|
2282
|
+
for (let key in ctx.data)
|
|
2283
|
+
pairs.push({
|
|
2284
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
2285
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
2286
|
+
alwaysSet: key in ctx.data
|
|
2287
|
+
});
|
|
2288
|
+
return ctx.common.async ? ParseStatus.mergeObjectAsync(status, pairs) : ParseStatus.mergeObjectSync(status, pairs);
|
|
2289
|
+
}
|
|
2290
|
+
get element() {
|
|
2291
|
+
return this._def.valueType;
|
|
2292
|
+
}
|
|
2293
|
+
static create(first, second, third) {
|
|
2294
|
+
return second instanceof ZodType ? new _ZodRecord({
|
|
2295
|
+
keyType: first,
|
|
2296
|
+
valueType: second,
|
|
2297
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
2298
|
+
...processCreateParams(third)
|
|
2299
|
+
}) : new _ZodRecord({
|
|
2300
|
+
keyType: ZodString.create(),
|
|
2301
|
+
valueType: first,
|
|
2302
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
2303
|
+
...processCreateParams(second)
|
|
2304
|
+
});
|
|
2305
|
+
}
|
|
2306
|
+
}, ZodMap = class extends ZodType {
|
|
2307
|
+
get keySchema() {
|
|
2308
|
+
return this._def.keyType;
|
|
2309
|
+
}
|
|
2310
|
+
get valueSchema() {
|
|
2311
|
+
return this._def.valueType;
|
|
2312
|
+
}
|
|
2313
|
+
_parse(input) {
|
|
2314
|
+
let { status, ctx } = this._processInputParams(input);
|
|
2315
|
+
if (ctx.parsedType !== ZodParsedType.map)
|
|
2316
|
+
return addIssueToContext(ctx, {
|
|
2317
|
+
code: ZodIssueCode.invalid_type,
|
|
2318
|
+
expected: ZodParsedType.map,
|
|
2319
|
+
received: ctx.parsedType
|
|
2320
|
+
}), INVALID;
|
|
2321
|
+
let keyType = this._def.keyType, valueType = this._def.valueType, pairs = [...ctx.data.entries()].map(([key, value], index) => ({
|
|
2322
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
2323
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
|
|
2324
|
+
}));
|
|
2325
|
+
if (ctx.common.async) {
|
|
2326
|
+
let finalMap = /* @__PURE__ */ new Map();
|
|
2327
|
+
return Promise.resolve().then(async () => {
|
|
2328
|
+
for (let pair of pairs) {
|
|
2329
|
+
let key = await pair.key, value = await pair.value;
|
|
2330
|
+
if (key.status === "aborted" || value.status === "aborted")
|
|
2331
|
+
return INVALID;
|
|
2332
|
+
(key.status === "dirty" || value.status === "dirty") && status.dirty(), finalMap.set(key.value, value.value);
|
|
2333
|
+
}
|
|
2334
|
+
return { status: status.value, value: finalMap };
|
|
2335
|
+
});
|
|
2336
|
+
} else {
|
|
2337
|
+
let finalMap = /* @__PURE__ */ new Map();
|
|
2338
|
+
for (let pair of pairs) {
|
|
2339
|
+
let key = pair.key, value = pair.value;
|
|
2340
|
+
if (key.status === "aborted" || value.status === "aborted")
|
|
2341
|
+
return INVALID;
|
|
2342
|
+
(key.status === "dirty" || value.status === "dirty") && status.dirty(), finalMap.set(key.value, value.value);
|
|
2343
|
+
}
|
|
2344
|
+
return { status: status.value, value: finalMap };
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
};
|
|
2348
|
+
ZodMap.create = (keyType, valueType, params) => new ZodMap({
|
|
2349
|
+
valueType,
|
|
2350
|
+
keyType,
|
|
2351
|
+
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
2352
|
+
...processCreateParams(params)
|
|
2353
|
+
});
|
|
2354
|
+
var ZodSet = class _ZodSet extends ZodType {
|
|
2355
|
+
_parse(input) {
|
|
2356
|
+
let { status, ctx } = this._processInputParams(input);
|
|
2357
|
+
if (ctx.parsedType !== ZodParsedType.set)
|
|
2358
|
+
return addIssueToContext(ctx, {
|
|
2359
|
+
code: ZodIssueCode.invalid_type,
|
|
2360
|
+
expected: ZodParsedType.set,
|
|
2361
|
+
received: ctx.parsedType
|
|
2362
|
+
}), INVALID;
|
|
2363
|
+
let def = this._def;
|
|
2364
|
+
def.minSize !== null && ctx.data.size < def.minSize.value && (addIssueToContext(ctx, {
|
|
2365
|
+
code: ZodIssueCode.too_small,
|
|
2366
|
+
minimum: def.minSize.value,
|
|
2367
|
+
type: "set",
|
|
2368
|
+
inclusive: !0,
|
|
2369
|
+
exact: !1,
|
|
2370
|
+
message: def.minSize.message
|
|
2371
|
+
}), status.dirty()), def.maxSize !== null && ctx.data.size > def.maxSize.value && (addIssueToContext(ctx, {
|
|
2372
|
+
code: ZodIssueCode.too_big,
|
|
2373
|
+
maximum: def.maxSize.value,
|
|
2374
|
+
type: "set",
|
|
2375
|
+
inclusive: !0,
|
|
2376
|
+
exact: !1,
|
|
2377
|
+
message: def.maxSize.message
|
|
2378
|
+
}), status.dirty());
|
|
2379
|
+
let valueType = this._def.valueType;
|
|
2380
|
+
function finalizeSet(elements2) {
|
|
2381
|
+
let parsedSet = /* @__PURE__ */ new Set();
|
|
2382
|
+
for (let element of elements2) {
|
|
2383
|
+
if (element.status === "aborted")
|
|
2384
|
+
return INVALID;
|
|
2385
|
+
element.status === "dirty" && status.dirty(), parsedSet.add(element.value);
|
|
2386
|
+
}
|
|
2387
|
+
return { status: status.value, value: parsedSet };
|
|
2388
|
+
}
|
|
2389
|
+
let elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
2390
|
+
return ctx.common.async ? Promise.all(elements).then((elements2) => finalizeSet(elements2)) : finalizeSet(elements);
|
|
2391
|
+
}
|
|
2392
|
+
min(minSize, message) {
|
|
2393
|
+
return new _ZodSet({
|
|
2394
|
+
...this._def,
|
|
2395
|
+
minSize: { value: minSize, message: errorUtil.toString(message) }
|
|
2396
|
+
});
|
|
2397
|
+
}
|
|
2398
|
+
max(maxSize, message) {
|
|
2399
|
+
return new _ZodSet({
|
|
2400
|
+
...this._def,
|
|
2401
|
+
maxSize: { value: maxSize, message: errorUtil.toString(message) }
|
|
2402
|
+
});
|
|
2403
|
+
}
|
|
2404
|
+
size(size, message) {
|
|
2405
|
+
return this.min(size, message).max(size, message);
|
|
2406
|
+
}
|
|
2407
|
+
nonempty(message) {
|
|
2408
|
+
return this.min(1, message);
|
|
2409
|
+
}
|
|
2410
|
+
};
|
|
2411
|
+
ZodSet.create = (valueType, params) => new ZodSet({
|
|
2412
|
+
valueType,
|
|
2413
|
+
minSize: null,
|
|
2414
|
+
maxSize: null,
|
|
2415
|
+
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
2416
|
+
...processCreateParams(params)
|
|
2417
|
+
});
|
|
2418
|
+
var ZodFunction = class _ZodFunction extends ZodType {
|
|
2419
|
+
constructor() {
|
|
2420
|
+
super(...arguments), this.validate = this.implement;
|
|
2421
|
+
}
|
|
2422
|
+
_parse(input) {
|
|
2423
|
+
let { ctx } = this._processInputParams(input);
|
|
2424
|
+
if (ctx.parsedType !== ZodParsedType.function)
|
|
2425
|
+
return addIssueToContext(ctx, {
|
|
2426
|
+
code: ZodIssueCode.invalid_type,
|
|
2427
|
+
expected: ZodParsedType.function,
|
|
2428
|
+
received: ctx.parsedType
|
|
2429
|
+
}), INVALID;
|
|
2430
|
+
function makeArgsIssue(args, error) {
|
|
2431
|
+
return makeIssue({
|
|
2432
|
+
data: args,
|
|
2433
|
+
path: ctx.path,
|
|
2434
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
2435
|
+
issueData: {
|
|
2436
|
+
code: ZodIssueCode.invalid_arguments,
|
|
2437
|
+
argumentsError: error
|
|
2438
|
+
}
|
|
2439
|
+
});
|
|
2440
|
+
}
|
|
2441
|
+
function makeReturnsIssue(returns, error) {
|
|
2442
|
+
return makeIssue({
|
|
2443
|
+
data: returns,
|
|
2444
|
+
path: ctx.path,
|
|
2445
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
2446
|
+
issueData: {
|
|
2447
|
+
code: ZodIssueCode.invalid_return_type,
|
|
2448
|
+
returnTypeError: error
|
|
2449
|
+
}
|
|
2450
|
+
});
|
|
2451
|
+
}
|
|
2452
|
+
let params = { errorMap: ctx.common.contextualErrorMap }, fn = ctx.data;
|
|
2453
|
+
if (this._def.returns instanceof ZodPromise) {
|
|
2454
|
+
let me = this;
|
|
2455
|
+
return OK(async function(...args) {
|
|
2456
|
+
let error = new ZodError([]), parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
2457
|
+
throw error.addIssue(makeArgsIssue(args, e)), error;
|
|
2458
|
+
}), result = await Reflect.apply(fn, this, parsedArgs);
|
|
2459
|
+
return await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
2460
|
+
throw error.addIssue(makeReturnsIssue(result, e)), error;
|
|
2461
|
+
});
|
|
2462
|
+
});
|
|
2463
|
+
} else {
|
|
2464
|
+
let me = this;
|
|
2465
|
+
return OK(function(...args) {
|
|
2466
|
+
let parsedArgs = me._def.args.safeParse(args, params);
|
|
2467
|
+
if (!parsedArgs.success)
|
|
2468
|
+
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
2469
|
+
let result = Reflect.apply(fn, this, parsedArgs.data), parsedReturns = me._def.returns.safeParse(result, params);
|
|
2470
|
+
if (!parsedReturns.success)
|
|
2471
|
+
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
2472
|
+
return parsedReturns.data;
|
|
2473
|
+
});
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
parameters() {
|
|
2477
|
+
return this._def.args;
|
|
2478
|
+
}
|
|
2479
|
+
returnType() {
|
|
2480
|
+
return this._def.returns;
|
|
2481
|
+
}
|
|
2482
|
+
args(...items) {
|
|
2483
|
+
return new _ZodFunction({
|
|
2484
|
+
...this._def,
|
|
2485
|
+
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
2486
|
+
});
|
|
2487
|
+
}
|
|
2488
|
+
returns(returnType) {
|
|
2489
|
+
return new _ZodFunction({
|
|
2490
|
+
...this._def,
|
|
2491
|
+
returns: returnType
|
|
2492
|
+
});
|
|
2493
|
+
}
|
|
2494
|
+
implement(func) {
|
|
2495
|
+
return this.parse(func);
|
|
2496
|
+
}
|
|
2497
|
+
strictImplement(func) {
|
|
2498
|
+
return this.parse(func);
|
|
2499
|
+
}
|
|
2500
|
+
static create(args, returns, params) {
|
|
2501
|
+
return new _ZodFunction({
|
|
2502
|
+
args: args || ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
2503
|
+
returns: returns || ZodUnknown.create(),
|
|
2504
|
+
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
2505
|
+
...processCreateParams(params)
|
|
2506
|
+
});
|
|
2507
|
+
}
|
|
2508
|
+
}, ZodLazy = class extends ZodType {
|
|
2509
|
+
get schema() {
|
|
2510
|
+
return this._def.getter();
|
|
2511
|
+
}
|
|
2512
|
+
_parse(input) {
|
|
2513
|
+
let { ctx } = this._processInputParams(input);
|
|
2514
|
+
return this._def.getter()._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
2515
|
+
}
|
|
2516
|
+
};
|
|
2517
|
+
ZodLazy.create = (getter, params) => new ZodLazy({
|
|
2518
|
+
getter,
|
|
2519
|
+
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
2520
|
+
...processCreateParams(params)
|
|
2521
|
+
});
|
|
2522
|
+
var ZodLiteral = class extends ZodType {
|
|
2523
|
+
_parse(input) {
|
|
2524
|
+
if (input.data !== this._def.value) {
|
|
2525
|
+
let ctx = this._getOrReturnCtx(input);
|
|
2526
|
+
return addIssueToContext(ctx, {
|
|
2527
|
+
received: ctx.data,
|
|
2528
|
+
code: ZodIssueCode.invalid_literal,
|
|
2529
|
+
expected: this._def.value
|
|
2530
|
+
}), INVALID;
|
|
2531
|
+
}
|
|
2532
|
+
return { status: "valid", value: input.data };
|
|
2533
|
+
}
|
|
2534
|
+
get value() {
|
|
2535
|
+
return this._def.value;
|
|
2536
|
+
}
|
|
2537
|
+
};
|
|
2538
|
+
ZodLiteral.create = (value, params) => new ZodLiteral({
|
|
2539
|
+
value,
|
|
2540
|
+
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
2541
|
+
...processCreateParams(params)
|
|
2542
|
+
});
|
|
2543
|
+
function createZodEnum(values, params) {
|
|
2544
|
+
return new ZodEnum({
|
|
2545
|
+
values,
|
|
2546
|
+
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
2547
|
+
...processCreateParams(params)
|
|
2548
|
+
});
|
|
2549
|
+
}
|
|
2550
|
+
var ZodEnum = class _ZodEnum extends ZodType {
|
|
2551
|
+
_parse(input) {
|
|
2552
|
+
if (typeof input.data != "string") {
|
|
2553
|
+
let ctx = this._getOrReturnCtx(input), expectedValues = this._def.values;
|
|
2554
|
+
return addIssueToContext(ctx, {
|
|
2555
|
+
expected: util.joinValues(expectedValues),
|
|
2556
|
+
received: ctx.parsedType,
|
|
2557
|
+
code: ZodIssueCode.invalid_type
|
|
2558
|
+
}), INVALID;
|
|
2559
|
+
}
|
|
2560
|
+
if (this._cache || (this._cache = new Set(this._def.values)), !this._cache.has(input.data)) {
|
|
2561
|
+
let ctx = this._getOrReturnCtx(input), expectedValues = this._def.values;
|
|
2562
|
+
return addIssueToContext(ctx, {
|
|
2563
|
+
received: ctx.data,
|
|
2564
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
2565
|
+
options: expectedValues
|
|
2566
|
+
}), INVALID;
|
|
2567
|
+
}
|
|
2568
|
+
return OK(input.data);
|
|
2569
|
+
}
|
|
2570
|
+
get options() {
|
|
2571
|
+
return this._def.values;
|
|
2572
|
+
}
|
|
2573
|
+
get enum() {
|
|
2574
|
+
let enumValues = {};
|
|
2575
|
+
for (let val of this._def.values)
|
|
2576
|
+
enumValues[val] = val;
|
|
2577
|
+
return enumValues;
|
|
2578
|
+
}
|
|
2579
|
+
get Values() {
|
|
2580
|
+
let enumValues = {};
|
|
2581
|
+
for (let val of this._def.values)
|
|
2582
|
+
enumValues[val] = val;
|
|
2583
|
+
return enumValues;
|
|
2584
|
+
}
|
|
2585
|
+
get Enum() {
|
|
2586
|
+
let enumValues = {};
|
|
2587
|
+
for (let val of this._def.values)
|
|
2588
|
+
enumValues[val] = val;
|
|
2589
|
+
return enumValues;
|
|
2590
|
+
}
|
|
2591
|
+
extract(values, newDef = this._def) {
|
|
2592
|
+
return _ZodEnum.create(values, {
|
|
2593
|
+
...this._def,
|
|
2594
|
+
...newDef
|
|
2595
|
+
});
|
|
2596
|
+
}
|
|
2597
|
+
exclude(values, newDef = this._def) {
|
|
2598
|
+
return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
2599
|
+
...this._def,
|
|
2600
|
+
...newDef
|
|
2601
|
+
});
|
|
2602
|
+
}
|
|
2603
|
+
};
|
|
2604
|
+
ZodEnum.create = createZodEnum;
|
|
2605
|
+
var ZodNativeEnum = class extends ZodType {
|
|
2606
|
+
_parse(input) {
|
|
2607
|
+
let nativeEnumValues = util.getValidEnumValues(this._def.values), ctx = this._getOrReturnCtx(input);
|
|
2608
|
+
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
2609
|
+
let expectedValues = util.objectValues(nativeEnumValues);
|
|
2610
|
+
return addIssueToContext(ctx, {
|
|
2611
|
+
expected: util.joinValues(expectedValues),
|
|
2612
|
+
received: ctx.parsedType,
|
|
2613
|
+
code: ZodIssueCode.invalid_type
|
|
2614
|
+
}), INVALID;
|
|
2615
|
+
}
|
|
2616
|
+
if (this._cache || (this._cache = new Set(util.getValidEnumValues(this._def.values))), !this._cache.has(input.data)) {
|
|
2617
|
+
let expectedValues = util.objectValues(nativeEnumValues);
|
|
2618
|
+
return addIssueToContext(ctx, {
|
|
2619
|
+
received: ctx.data,
|
|
2620
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
2621
|
+
options: expectedValues
|
|
2622
|
+
}), INVALID;
|
|
2623
|
+
}
|
|
2624
|
+
return OK(input.data);
|
|
2625
|
+
}
|
|
2626
|
+
get enum() {
|
|
2627
|
+
return this._def.values;
|
|
2628
|
+
}
|
|
2629
|
+
};
|
|
2630
|
+
ZodNativeEnum.create = (values, params) => new ZodNativeEnum({
|
|
2631
|
+
values,
|
|
2632
|
+
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
2633
|
+
...processCreateParams(params)
|
|
2634
|
+
});
|
|
2635
|
+
var ZodPromise = class extends ZodType {
|
|
2636
|
+
unwrap() {
|
|
2637
|
+
return this._def.type;
|
|
2638
|
+
}
|
|
2639
|
+
_parse(input) {
|
|
2640
|
+
let { ctx } = this._processInputParams(input);
|
|
2641
|
+
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === !1)
|
|
2642
|
+
return addIssueToContext(ctx, {
|
|
2643
|
+
code: ZodIssueCode.invalid_type,
|
|
2644
|
+
expected: ZodParsedType.promise,
|
|
2645
|
+
received: ctx.parsedType
|
|
2646
|
+
}), INVALID;
|
|
2647
|
+
let promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
2648
|
+
return OK(promisified.then((data) => this._def.type.parseAsync(data, {
|
|
2649
|
+
path: ctx.path,
|
|
2650
|
+
errorMap: ctx.common.contextualErrorMap
|
|
2651
|
+
})));
|
|
2652
|
+
}
|
|
2653
|
+
};
|
|
2654
|
+
ZodPromise.create = (schema, params) => new ZodPromise({
|
|
2655
|
+
type: schema,
|
|
2656
|
+
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
2657
|
+
...processCreateParams(params)
|
|
2658
|
+
});
|
|
2659
|
+
var ZodEffects = class extends ZodType {
|
|
2660
|
+
innerType() {
|
|
2661
|
+
return this._def.schema;
|
|
2662
|
+
}
|
|
2663
|
+
sourceType() {
|
|
2664
|
+
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
2665
|
+
}
|
|
2666
|
+
_parse(input) {
|
|
2667
|
+
let { status, ctx } = this._processInputParams(input), effect = this._def.effect || null, checkCtx = {
|
|
2668
|
+
addIssue: (arg) => {
|
|
2669
|
+
addIssueToContext(ctx, arg), arg.fatal ? status.abort() : status.dirty();
|
|
2670
|
+
},
|
|
2671
|
+
get path() {
|
|
2672
|
+
return ctx.path;
|
|
2673
|
+
}
|
|
2674
|
+
};
|
|
2675
|
+
if (checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx), effect.type === "preprocess") {
|
|
2676
|
+
let processed = effect.transform(ctx.data, checkCtx);
|
|
2677
|
+
if (ctx.common.async)
|
|
2678
|
+
return Promise.resolve(processed).then(async (processed2) => {
|
|
2679
|
+
if (status.value === "aborted")
|
|
2680
|
+
return INVALID;
|
|
2681
|
+
let result = await this._def.schema._parseAsync({
|
|
2682
|
+
data: processed2,
|
|
2683
|
+
path: ctx.path,
|
|
2684
|
+
parent: ctx
|
|
2685
|
+
});
|
|
2686
|
+
return result.status === "aborted" ? INVALID : result.status === "dirty" ? DIRTY(result.value) : status.value === "dirty" ? DIRTY(result.value) : result;
|
|
2687
|
+
});
|
|
2688
|
+
{
|
|
2689
|
+
if (status.value === "aborted")
|
|
2690
|
+
return INVALID;
|
|
2691
|
+
let result = this._def.schema._parseSync({
|
|
2692
|
+
data: processed,
|
|
2693
|
+
path: ctx.path,
|
|
2694
|
+
parent: ctx
|
|
2695
|
+
});
|
|
2696
|
+
return result.status === "aborted" ? INVALID : result.status === "dirty" ? DIRTY(result.value) : status.value === "dirty" ? DIRTY(result.value) : result;
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
if (effect.type === "refinement") {
|
|
2700
|
+
let executeRefinement = (acc) => {
|
|
2701
|
+
let result = effect.refinement(acc, checkCtx);
|
|
2702
|
+
if (ctx.common.async)
|
|
2703
|
+
return Promise.resolve(result);
|
|
2704
|
+
if (result instanceof Promise)
|
|
2705
|
+
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
2706
|
+
return acc;
|
|
2707
|
+
};
|
|
2708
|
+
if (ctx.common.async === !1) {
|
|
2709
|
+
let inner = this._def.schema._parseSync({
|
|
2710
|
+
data: ctx.data,
|
|
2711
|
+
path: ctx.path,
|
|
2712
|
+
parent: ctx
|
|
2713
|
+
});
|
|
2714
|
+
return inner.status === "aborted" ? INVALID : (inner.status === "dirty" && status.dirty(), executeRefinement(inner.value), { status: status.value, value: inner.value });
|
|
2715
|
+
} else
|
|
2716
|
+
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 }))));
|
|
2717
|
+
}
|
|
2718
|
+
if (effect.type === "transform")
|
|
2719
|
+
if (ctx.common.async === !1) {
|
|
2720
|
+
let base = this._def.schema._parseSync({
|
|
2721
|
+
data: ctx.data,
|
|
2722
|
+
path: ctx.path,
|
|
2723
|
+
parent: ctx
|
|
2724
|
+
});
|
|
2725
|
+
if (!isValid(base))
|
|
2726
|
+
return INVALID;
|
|
2727
|
+
let result = effect.transform(base.value, checkCtx);
|
|
2728
|
+
if (result instanceof Promise)
|
|
2729
|
+
throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
2730
|
+
return { status: status.value, value: result };
|
|
2731
|
+
} else
|
|
2732
|
+
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) => ({
|
|
2733
|
+
status: status.value,
|
|
2734
|
+
value: result
|
|
2735
|
+
})) : INVALID);
|
|
2736
|
+
util.assertNever(effect);
|
|
2737
|
+
}
|
|
2738
|
+
};
|
|
2739
|
+
ZodEffects.create = (schema, effect, params) => new ZodEffects({
|
|
2740
|
+
schema,
|
|
2741
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
2742
|
+
effect,
|
|
2743
|
+
...processCreateParams(params)
|
|
2744
|
+
});
|
|
2745
|
+
ZodEffects.createWithPreprocess = (preprocess, schema, params) => new ZodEffects({
|
|
2746
|
+
schema,
|
|
2747
|
+
effect: { type: "preprocess", transform: preprocess },
|
|
2748
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
2749
|
+
...processCreateParams(params)
|
|
2750
|
+
});
|
|
2751
|
+
var ZodOptional = class extends ZodType {
|
|
2752
|
+
_parse(input) {
|
|
2753
|
+
return this._getType(input) === ZodParsedType.undefined ? OK(void 0) : this._def.innerType._parse(input);
|
|
2754
|
+
}
|
|
2755
|
+
unwrap() {
|
|
2756
|
+
return this._def.innerType;
|
|
2757
|
+
}
|
|
2758
|
+
};
|
|
2759
|
+
ZodOptional.create = (type, params) => new ZodOptional({
|
|
2760
|
+
innerType: type,
|
|
2761
|
+
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
2762
|
+
...processCreateParams(params)
|
|
2763
|
+
});
|
|
2764
|
+
var ZodNullable = class extends ZodType {
|
|
2765
|
+
_parse(input) {
|
|
2766
|
+
return this._getType(input) === ZodParsedType.null ? OK(null) : this._def.innerType._parse(input);
|
|
2767
|
+
}
|
|
2768
|
+
unwrap() {
|
|
2769
|
+
return this._def.innerType;
|
|
2770
|
+
}
|
|
2771
|
+
};
|
|
2772
|
+
ZodNullable.create = (type, params) => new ZodNullable({
|
|
2773
|
+
innerType: type,
|
|
2774
|
+
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
2775
|
+
...processCreateParams(params)
|
|
2776
|
+
});
|
|
2777
|
+
var ZodDefault = class extends ZodType {
|
|
2778
|
+
_parse(input) {
|
|
2779
|
+
let { ctx } = this._processInputParams(input), data = ctx.data;
|
|
2780
|
+
return ctx.parsedType === ZodParsedType.undefined && (data = this._def.defaultValue()), this._def.innerType._parse({
|
|
2781
|
+
data,
|
|
2782
|
+
path: ctx.path,
|
|
2783
|
+
parent: ctx
|
|
2784
|
+
});
|
|
2785
|
+
}
|
|
2786
|
+
removeDefault() {
|
|
2787
|
+
return this._def.innerType;
|
|
2788
|
+
}
|
|
2789
|
+
};
|
|
2790
|
+
ZodDefault.create = (type, params) => new ZodDefault({
|
|
2791
|
+
innerType: type,
|
|
2792
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
2793
|
+
defaultValue: typeof params.default == "function" ? params.default : () => params.default,
|
|
2794
|
+
...processCreateParams(params)
|
|
2795
|
+
});
|
|
2796
|
+
var ZodCatch = class extends ZodType {
|
|
2797
|
+
_parse(input) {
|
|
2798
|
+
let { ctx } = this._processInputParams(input), newCtx = {
|
|
2799
|
+
...ctx,
|
|
2800
|
+
common: {
|
|
2801
|
+
...ctx.common,
|
|
2802
|
+
issues: []
|
|
2803
|
+
}
|
|
2804
|
+
}, result = this._def.innerType._parse({
|
|
2805
|
+
data: newCtx.data,
|
|
2806
|
+
path: newCtx.path,
|
|
2807
|
+
parent: {
|
|
2808
|
+
...newCtx
|
|
2809
|
+
}
|
|
2810
|
+
});
|
|
2811
|
+
return isAsync(result) ? result.then((result2) => ({
|
|
2812
|
+
status: "valid",
|
|
2813
|
+
value: result2.status === "valid" ? result2.value : this._def.catchValue({
|
|
2814
|
+
get error() {
|
|
2815
|
+
return new ZodError(newCtx.common.issues);
|
|
2816
|
+
},
|
|
2817
|
+
input: newCtx.data
|
|
2818
|
+
})
|
|
2819
|
+
})) : {
|
|
2820
|
+
status: "valid",
|
|
2821
|
+
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
2822
|
+
get error() {
|
|
2823
|
+
return new ZodError(newCtx.common.issues);
|
|
2824
|
+
},
|
|
2825
|
+
input: newCtx.data
|
|
2826
|
+
})
|
|
2827
|
+
};
|
|
2828
|
+
}
|
|
2829
|
+
removeCatch() {
|
|
2830
|
+
return this._def.innerType;
|
|
2831
|
+
}
|
|
2832
|
+
};
|
|
2833
|
+
ZodCatch.create = (type, params) => new ZodCatch({
|
|
2834
|
+
innerType: type,
|
|
2835
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
2836
|
+
catchValue: typeof params.catch == "function" ? params.catch : () => params.catch,
|
|
2837
|
+
...processCreateParams(params)
|
|
2838
|
+
});
|
|
2839
|
+
var ZodNaN = class extends ZodType {
|
|
2840
|
+
_parse(input) {
|
|
2841
|
+
if (this._getType(input) !== ZodParsedType.nan) {
|
|
2842
|
+
let ctx = this._getOrReturnCtx(input);
|
|
2843
|
+
return addIssueToContext(ctx, {
|
|
2844
|
+
code: ZodIssueCode.invalid_type,
|
|
2845
|
+
expected: ZodParsedType.nan,
|
|
2846
|
+
received: ctx.parsedType
|
|
2847
|
+
}), INVALID;
|
|
2848
|
+
}
|
|
2849
|
+
return { status: "valid", value: input.data };
|
|
2850
|
+
}
|
|
2851
|
+
};
|
|
2852
|
+
ZodNaN.create = (params) => new ZodNaN({
|
|
2853
|
+
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
2854
|
+
...processCreateParams(params)
|
|
2855
|
+
});
|
|
2856
|
+
var BRAND = Symbol("zod_brand"), ZodBranded = class extends ZodType {
|
|
2857
|
+
_parse(input) {
|
|
2858
|
+
let { ctx } = this._processInputParams(input), data = ctx.data;
|
|
2859
|
+
return this._def.type._parse({
|
|
2860
|
+
data,
|
|
2861
|
+
path: ctx.path,
|
|
2862
|
+
parent: ctx
|
|
2863
|
+
});
|
|
2864
|
+
}
|
|
2865
|
+
unwrap() {
|
|
2866
|
+
return this._def.type;
|
|
2867
|
+
}
|
|
2868
|
+
}, ZodPipeline = class _ZodPipeline extends ZodType {
|
|
2869
|
+
_parse(input) {
|
|
2870
|
+
let { status, ctx } = this._processInputParams(input);
|
|
2871
|
+
if (ctx.common.async)
|
|
2872
|
+
return (async () => {
|
|
2873
|
+
let inResult = await this._def.in._parseAsync({
|
|
2874
|
+
data: ctx.data,
|
|
2875
|
+
path: ctx.path,
|
|
2876
|
+
parent: ctx
|
|
2877
|
+
});
|
|
2878
|
+
return inResult.status === "aborted" ? INVALID : inResult.status === "dirty" ? (status.dirty(), DIRTY(inResult.value)) : this._def.out._parseAsync({
|
|
2879
|
+
data: inResult.value,
|
|
2880
|
+
path: ctx.path,
|
|
2881
|
+
parent: ctx
|
|
2882
|
+
});
|
|
2883
|
+
})();
|
|
2884
|
+
{
|
|
2885
|
+
let inResult = this._def.in._parseSync({
|
|
2886
|
+
data: ctx.data,
|
|
2887
|
+
path: ctx.path,
|
|
2888
|
+
parent: ctx
|
|
2889
|
+
});
|
|
2890
|
+
return inResult.status === "aborted" ? INVALID : inResult.status === "dirty" ? (status.dirty(), {
|
|
2891
|
+
status: "dirty",
|
|
2892
|
+
value: inResult.value
|
|
2893
|
+
}) : this._def.out._parseSync({
|
|
2894
|
+
data: inResult.value,
|
|
2895
|
+
path: ctx.path,
|
|
2896
|
+
parent: ctx
|
|
2897
|
+
});
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
static create(a, b) {
|
|
2901
|
+
return new _ZodPipeline({
|
|
2902
|
+
in: a,
|
|
2903
|
+
out: b,
|
|
2904
|
+
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
2905
|
+
});
|
|
2906
|
+
}
|
|
2907
|
+
}, ZodReadonly = class extends ZodType {
|
|
2908
|
+
_parse(input) {
|
|
2909
|
+
let result = this._def.innerType._parse(input), freeze = (data) => (isValid(data) && (data.value = Object.freeze(data.value)), data);
|
|
2910
|
+
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
2911
|
+
}
|
|
2912
|
+
unwrap() {
|
|
2913
|
+
return this._def.innerType;
|
|
2914
|
+
}
|
|
2915
|
+
};
|
|
2916
|
+
ZodReadonly.create = (type, params) => new ZodReadonly({
|
|
2917
|
+
innerType: type,
|
|
2918
|
+
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
2919
|
+
...processCreateParams(params)
|
|
2920
|
+
});
|
|
2921
|
+
function cleanParams(params, data) {
|
|
2922
|
+
let p = typeof params == "function" ? params(data) : typeof params == "string" ? { message: params } : params;
|
|
2923
|
+
return typeof p == "string" ? { message: p } : p;
|
|
2924
|
+
}
|
|
2925
|
+
function custom(check, _params = {}, fatal) {
|
|
2926
|
+
return check ? ZodAny.create().superRefine((data, ctx) => {
|
|
2927
|
+
let r = check(data);
|
|
2928
|
+
if (r instanceof Promise)
|
|
2929
|
+
return r.then((r2) => {
|
|
2930
|
+
if (!r2) {
|
|
2931
|
+
let params = cleanParams(_params, data), _fatal = params.fatal ?? fatal ?? !0;
|
|
2932
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
2933
|
+
}
|
|
2934
|
+
});
|
|
2935
|
+
if (!r) {
|
|
2936
|
+
let params = cleanParams(_params, data), _fatal = params.fatal ?? fatal ?? !0;
|
|
2937
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
2938
|
+
}
|
|
2939
|
+
}) : ZodAny.create();
|
|
2940
|
+
}
|
|
2941
|
+
var late = {
|
|
2942
|
+
object: ZodObject.lazycreate
|
|
2943
|
+
}, ZodFirstPartyTypeKind;
|
|
2944
|
+
(function(ZodFirstPartyTypeKind2) {
|
|
2945
|
+
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";
|
|
2946
|
+
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
2947
|
+
var instanceOfType = (cls, params = {
|
|
2948
|
+
message: `Input not instance of ${cls.name}`
|
|
2949
|
+
}) => 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 = {
|
|
2950
|
+
string: ((arg) => ZodString.create({ ...arg, coerce: !0 })),
|
|
2951
|
+
number: ((arg) => ZodNumber.create({ ...arg, coerce: !0 })),
|
|
2952
|
+
boolean: ((arg) => ZodBoolean.create({
|
|
2953
|
+
...arg,
|
|
2954
|
+
coerce: !0
|
|
2955
|
+
})),
|
|
2956
|
+
bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: !0 })),
|
|
2957
|
+
date: ((arg) => ZodDate.create({ ...arg, coerce: !0 }))
|
|
2958
|
+
};
|
|
2959
|
+
var NEVER = INVALID;
|
|
2960
|
+
|
|
2961
|
+
// src/cli/globalSettings.ts
|
|
2962
|
+
var DEFAULT_SETTINGS_PATH = join(homedir(), ".storybook", "settings.json"), VERSION = 1, userSettingSchema = external_exports.object({
|
|
2963
|
+
version: external_exports.number(),
|
|
2964
|
+
// NOTE: every key (and subkey) below must be optional, for forwards compatibility reasons
|
|
2965
|
+
// (we can remove keys once they are deprecated)
|
|
2966
|
+
userSince: external_exports.number().optional(),
|
|
2967
|
+
init: external_exports.object({ skipOnboarding: external_exports.boolean().optional() }).optional()
|
|
2968
|
+
}), settings;
|
|
2969
|
+
async function globalSettings(filePath = DEFAULT_SETTINGS_PATH) {
|
|
2970
|
+
if (settings)
|
|
2971
|
+
return settings;
|
|
2972
|
+
try {
|
|
2973
|
+
let content = await fs.readFile(filePath, "utf8"), settingsValue = userSettingSchema.parse(JSON.parse(content));
|
|
2974
|
+
settings = new Settings(filePath, settingsValue);
|
|
2975
|
+
} catch {
|
|
2976
|
+
settings = new Settings(filePath, { version: VERSION, userSince: Date.now() }), await settings.save();
|
|
2977
|
+
}
|
|
2978
|
+
return settings;
|
|
2979
|
+
}
|
|
2980
|
+
function _clearGlobalSettings() {
|
|
2981
|
+
settings = void 0;
|
|
2982
|
+
}
|
|
2983
|
+
var Settings = class {
|
|
2984
|
+
/**
|
|
2985
|
+
* Create a new Settings instance
|
|
2986
|
+
*
|
|
2987
|
+
* @param filePath Path to the JSON settings file
|
|
2988
|
+
* @param value Loaded value of settings
|
|
2989
|
+
*/
|
|
2990
|
+
constructor(filePath, value) {
|
|
2991
|
+
this.filePath = filePath, this.value = value;
|
|
2992
|
+
}
|
|
2993
|
+
/** Save settings to the file */
|
|
2994
|
+
async save() {
|
|
2995
|
+
try {
|
|
2996
|
+
await fs.mkdir(dirname(this.filePath), { recursive: !0 }), await fs.writeFile(this.filePath, JSON.stringify(this.value, null, 2));
|
|
2997
|
+
} catch (err) {
|
|
2998
|
+
console.warn(import_ts_dedent.dedent`
|
|
2999
|
+
Unable to save global settings file to ${this.filePath}
|
|
3000
|
+
${err && `Reason: ${err.message ?? err}`}`);
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
};
|
|
3004
|
+
|
|
3005
|
+
export {
|
|
3006
|
+
globalSettings,
|
|
3007
|
+
_clearGlobalSettings,
|
|
3008
|
+
Settings
|
|
3009
|
+
};
|