@fluent.xyz/connect 0.6.3 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4781 @@
1
+ import { parseAbi, defineChain, formatUnits, isAddress, parseUnits } from 'viem';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __export = (target, all) => {
5
+ for (var name in all)
6
+ __defProp(target, name, { get: all[name], enumerable: true });
7
+ };
8
+
9
+ // ../registry/data/chains/fluent-mainnet.json
10
+ var fluent_mainnet_default = {
11
+ id: "fluent-mainnet",
12
+ name: "Fluent Mainnet",
13
+ chainId: 25363,
14
+ testnet: false,
15
+ nativeCurrency: {
16
+ name: "Ether",
17
+ symbol: "ETH",
18
+ decimals: 18
19
+ },
20
+ rpcUrls: {
21
+ default: {
22
+ http: [
23
+ "https://rpc.fluent.xyz/"
24
+ ]
25
+ }
26
+ },
27
+ blockExplorers: {
28
+ default: {
29
+ name: "Fluentscan",
30
+ url: "https://fluentscan.xyz"
31
+ }
32
+ },
33
+ infoURL: "https://docs.fluent.xyz/",
34
+ parent: {
35
+ type: "L2",
36
+ chainId: 1,
37
+ bridgeUrl: "https://portal.fluent.xyz/"
38
+ },
39
+ contracts: {
40
+ fluentBridge: {
41
+ address: "0x9CAcf613fC29015893728563f423fD26dCdB8Ddc"
42
+ },
43
+ nativeGateway: {
44
+ address: "0x8976Ca4E0c8467097Da675399fB7DB454a1b56dd"
45
+ },
46
+ erc20Gateway: {
47
+ address: "0xFD4C62647A34FF6d6802092F5fbe176099223B61"
48
+ },
49
+ wethGateway: {
50
+ address: "0x1e1f5Df9D48e8E88C037e9255a769e77c9fe587b"
51
+ }
52
+ }
53
+ };
54
+
55
+ // ../registry/data/chains/fluent-testnet.json
56
+ var fluent_testnet_default = {
57
+ id: "fluent-testnet",
58
+ name: "Fluent Testnet",
59
+ chainId: 20994,
60
+ testnet: true,
61
+ nativeCurrency: {
62
+ name: "Ether",
63
+ symbol: "ETH",
64
+ decimals: 18
65
+ },
66
+ rpcUrls: {
67
+ default: {
68
+ http: [
69
+ "https://rpc.testnet.fluent.xyz/"
70
+ ],
71
+ webSocket: [
72
+ "wss://rpc.testnet.fluent.xyz/ws"
73
+ ]
74
+ }
75
+ },
76
+ blockExplorers: {
77
+ default: {
78
+ name: "Fluentscan Testnet",
79
+ url: "https://testnet.fluentscan.xyz"
80
+ }
81
+ },
82
+ infoURL: "https://docs.fluent.xyz/",
83
+ faucets: [
84
+ "https://testnet.fluent.xyz/dev-portal"
85
+ ],
86
+ parent: {
87
+ type: "L2",
88
+ chainId: 11155111,
89
+ bridgeUrl: "https://portal.fluent.xyz/"
90
+ },
91
+ contracts: {
92
+ fluentBridge: {
93
+ address: "0x9CAcf613fC29015893728563f423fD26dCdB8Ddc"
94
+ },
95
+ universalTokenFactory: {
96
+ address: "0x4c64F50F9CbeE440f8c4ea6147517018D680AE6c",
97
+ implementation: "0x4bc7ef271d5659025c2A88B149BD1da019570538"
98
+ },
99
+ paymentGateway: {
100
+ address: "0xdC9BF18a1c307ce1A84e2775C7645e57eB373CD4",
101
+ implementation: "0xdE0079364f24045Fa144CaE722055709d8547b4d"
102
+ },
103
+ peggedTokenPrecompile: {
104
+ address: "0x0000000000000000000000000000000000520008"
105
+ },
106
+ nativeGateway: {
107
+ address: "0x8976Ca4E0c8467097Da675399fB7DB454a1b56dd"
108
+ },
109
+ erc20Gateway: {
110
+ address: "0xFD4C62647A34FF6d6802092F5fbe176099223B61"
111
+ },
112
+ wethGateway: {
113
+ address: "0x9C2baa1d32466aceC1AdDD98AA047fB7B6D55622"
114
+ }
115
+ }
116
+ };
117
+
118
+ // ../registry/data/l1/ethereum.json
119
+ var ethereum_default = {
120
+ id: "ethereum",
121
+ name: "Ethereum",
122
+ chainId: 1,
123
+ testnet: false,
124
+ nativeCurrency: {
125
+ name: "Ether",
126
+ symbol: "ETH",
127
+ decimals: 18
128
+ },
129
+ rpcUrls: {
130
+ default: {
131
+ http: [
132
+ "https://ethereum-rpc.publicnode.com",
133
+ "https://eth.llamarpc.com",
134
+ "https://eth.drpc.org"
135
+ ]
136
+ }
137
+ },
138
+ blockExplorers: {
139
+ default: {
140
+ name: "Etherscan",
141
+ url: "https://etherscan.io"
142
+ }
143
+ },
144
+ pairedL2: "fluent-mainnet",
145
+ contracts: {
146
+ fluentBridge: {
147
+ address: "0x9CAcf613fC29015893728563f423fD26dCdB8Ddc"
148
+ },
149
+ nativeGateway: {
150
+ address: "0x8976Ca4E0c8467097Da675399fB7DB454a1b56dd"
151
+ },
152
+ erc20Gateway: {
153
+ address: "0xFD4C62647A34FF6d6802092F5fbe176099223B61"
154
+ },
155
+ wethGateway: {
156
+ address: "0x1e1f5Df9D48e8E88C037e9255a769e77c9fe587b"
157
+ },
158
+ fastPathPortal: {
159
+ address: "0xD925C84b55E4e44a53749fF5F2a5A13F63D128fd"
160
+ },
161
+ swapFacility: {
162
+ address: "0xb6807116b3b1b321a390594e31ecd6e0076f6278"
163
+ }
164
+ }
165
+ };
166
+
167
+ // ../registry/data/l1/sepolia.json
168
+ var sepolia_default = {
169
+ id: "sepolia",
170
+ name: "Sepolia",
171
+ chainId: 11155111,
172
+ testnet: true,
173
+ nativeCurrency: {
174
+ name: "Ether",
175
+ symbol: "ETH",
176
+ decimals: 18
177
+ },
178
+ rpcUrls: {
179
+ default: {
180
+ http: [
181
+ "https://ethereum-sepolia-rpc.publicnode.com"
182
+ ]
183
+ }
184
+ },
185
+ blockExplorers: {
186
+ default: {
187
+ name: "Etherscan",
188
+ url: "https://sepolia.etherscan.io"
189
+ }
190
+ },
191
+ pairedL2: "fluent-testnet",
192
+ contracts: {
193
+ fluentBridge: {
194
+ address: "0x9CAcf613fC29015893728563f423fD26dCdB8Ddc"
195
+ },
196
+ erc20TokenFactory: {
197
+ address: "0x299647D9CCB041CC7B24334132Ce40bAe782307B",
198
+ implementation: "0xAcc5dbf44ED0720A58247c91A60825bbC44770a9"
199
+ },
200
+ upgradeableBeacon: {
201
+ address: "0x89C1066323dBb4a0fC8a23343EC2966579cc0877"
202
+ },
203
+ erc20PeggedTokenImplementation: {
204
+ address: "0xe2963EC5EE91C5EF911Ea5993135C72b7ce6CA2e"
205
+ },
206
+ paymentGateway: {
207
+ address: "0x8a2b6627fFbd481907b23070Faf5a33C596A1b9f",
208
+ implementation: "0x246f6AA064F607AEb76208BcF7948212F0894ceA"
209
+ },
210
+ mockERC20: {
211
+ address: "0x39f86A7d19f1bF090EbBaF6BFAbB900c5CF48DB8"
212
+ },
213
+ nativeGateway: {
214
+ address: "0x8976Ca4E0c8467097Da675399fB7DB454a1b56dd"
215
+ },
216
+ erc20Gateway: {
217
+ address: "0xFD4C62647A34FF6d6802092F5fbe176099223B61"
218
+ },
219
+ wethGateway: {
220
+ address: "0x9C2baa1d32466aceC1AdDD98AA047fB7B6D55622"
221
+ }
222
+ }
223
+ };
224
+
225
+ // ../registry/data/apps/fluent-bridge.json
226
+ var fluent_bridge_default = {
227
+ id: "fluent-bridge",
228
+ name: "Fluent Bridge",
229
+ category: "bridge",
230
+ description: "L1 <-> L2 asset bridge (Ethereum <-> Fluent)",
231
+ docs: "https://github.com/fluentlabs-xyz/solidity-contracts/blob/main/docs/Addresses.md",
232
+ deployments: {
233
+ "1": {
234
+ contract: "fluentBridge",
235
+ address: "0x9CAcf613fC29015893728563f423fD26dCdB8Ddc"
236
+ },
237
+ "11155111": {
238
+ contract: "fluentBridge",
239
+ address: "0x9CAcf613fC29015893728563f423fD26dCdB8Ddc"
240
+ },
241
+ "20994": {
242
+ contract: "fluentBridge",
243
+ address: "0x9CAcf613fC29015893728563f423fD26dCdB8Ddc"
244
+ },
245
+ "25363": {
246
+ contract: "fluentBridge",
247
+ address: "0x9CAcf613fC29015893728563f423fD26dCdB8Ddc"
248
+ }
249
+ }
250
+ };
251
+
252
+ // ../registry/data/integrations/zerodev.json
253
+ var zerodev_default = {
254
+ id: "zerodev",
255
+ name: "ZeroDev",
256
+ description: "ERC-4337 smart accounts and gas sponsorship for Fluent (enabled on testnet and mainnet in the ZeroDev dashboard)",
257
+ docs: "https://docs.zerodev.app",
258
+ dashboard: "https://dashboard.zerodev.app",
259
+ rpcUrlTemplate: "https://rpc.zerodev.app/api/v3/{projectId}/chain/{chainId}",
260
+ supportedFluentChains: [
261
+ {
262
+ fluentChainId: "fluent-testnet",
263
+ chainId: 20994
264
+ },
265
+ {
266
+ fluentChainId: "fluent-mainnet",
267
+ chainId: 25363
268
+ }
269
+ ],
270
+ privy: {
271
+ docs: "https://docs.privy.io",
272
+ embeddedWalletCreateOnLogin: "users-without-wallets"
273
+ }
274
+ };
275
+
276
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
277
+ var external_exports = {};
278
+ __export(external_exports, {
279
+ BRAND: () => BRAND,
280
+ DIRTY: () => DIRTY,
281
+ EMPTY_PATH: () => EMPTY_PATH,
282
+ INVALID: () => INVALID,
283
+ NEVER: () => NEVER,
284
+ OK: () => OK,
285
+ ParseStatus: () => ParseStatus,
286
+ Schema: () => ZodType,
287
+ ZodAny: () => ZodAny,
288
+ ZodArray: () => ZodArray,
289
+ ZodBigInt: () => ZodBigInt,
290
+ ZodBoolean: () => ZodBoolean,
291
+ ZodBranded: () => ZodBranded,
292
+ ZodCatch: () => ZodCatch,
293
+ ZodDate: () => ZodDate,
294
+ ZodDefault: () => ZodDefault,
295
+ ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
296
+ ZodEffects: () => ZodEffects,
297
+ ZodEnum: () => ZodEnum,
298
+ ZodError: () => ZodError,
299
+ ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
300
+ ZodFunction: () => ZodFunction,
301
+ ZodIntersection: () => ZodIntersection,
302
+ ZodIssueCode: () => ZodIssueCode,
303
+ ZodLazy: () => ZodLazy,
304
+ ZodLiteral: () => ZodLiteral,
305
+ ZodMap: () => ZodMap,
306
+ ZodNaN: () => ZodNaN,
307
+ ZodNativeEnum: () => ZodNativeEnum,
308
+ ZodNever: () => ZodNever,
309
+ ZodNull: () => ZodNull,
310
+ ZodNullable: () => ZodNullable,
311
+ ZodNumber: () => ZodNumber,
312
+ ZodObject: () => ZodObject,
313
+ ZodOptional: () => ZodOptional,
314
+ ZodParsedType: () => ZodParsedType,
315
+ ZodPipeline: () => ZodPipeline,
316
+ ZodPromise: () => ZodPromise,
317
+ ZodReadonly: () => ZodReadonly,
318
+ ZodRecord: () => ZodRecord,
319
+ ZodSchema: () => ZodType,
320
+ ZodSet: () => ZodSet,
321
+ ZodString: () => ZodString,
322
+ ZodSymbol: () => ZodSymbol,
323
+ ZodTransformer: () => ZodEffects,
324
+ ZodTuple: () => ZodTuple,
325
+ ZodType: () => ZodType,
326
+ ZodUndefined: () => ZodUndefined,
327
+ ZodUnion: () => ZodUnion,
328
+ ZodUnknown: () => ZodUnknown,
329
+ ZodVoid: () => ZodVoid,
330
+ addIssueToContext: () => addIssueToContext,
331
+ any: () => anyType,
332
+ array: () => arrayType,
333
+ bigint: () => bigIntType,
334
+ boolean: () => booleanType,
335
+ coerce: () => coerce,
336
+ custom: () => custom,
337
+ date: () => dateType,
338
+ datetimeRegex: () => datetimeRegex,
339
+ defaultErrorMap: () => en_default,
340
+ discriminatedUnion: () => discriminatedUnionType,
341
+ effect: () => effectsType,
342
+ enum: () => enumType,
343
+ function: () => functionType,
344
+ getErrorMap: () => getErrorMap,
345
+ getParsedType: () => getParsedType,
346
+ instanceof: () => instanceOfType,
347
+ intersection: () => intersectionType,
348
+ isAborted: () => isAborted,
349
+ isAsync: () => isAsync,
350
+ isDirty: () => isDirty,
351
+ isValid: () => isValid,
352
+ late: () => late,
353
+ lazy: () => lazyType,
354
+ literal: () => literalType,
355
+ makeIssue: () => makeIssue,
356
+ map: () => mapType,
357
+ nan: () => nanType,
358
+ nativeEnum: () => nativeEnumType,
359
+ never: () => neverType,
360
+ null: () => nullType,
361
+ nullable: () => nullableType,
362
+ number: () => numberType,
363
+ object: () => objectType,
364
+ objectUtil: () => objectUtil,
365
+ oboolean: () => oboolean,
366
+ onumber: () => onumber,
367
+ optional: () => optionalType,
368
+ ostring: () => ostring,
369
+ pipeline: () => pipelineType,
370
+ preprocess: () => preprocessType,
371
+ promise: () => promiseType,
372
+ quotelessJson: () => quotelessJson,
373
+ record: () => recordType,
374
+ set: () => setType,
375
+ setErrorMap: () => setErrorMap,
376
+ strictObject: () => strictObjectType,
377
+ string: () => stringType,
378
+ symbol: () => symbolType,
379
+ transformer: () => effectsType,
380
+ tuple: () => tupleType,
381
+ undefined: () => undefinedType,
382
+ union: () => unionType,
383
+ unknown: () => unknownType,
384
+ util: () => util,
385
+ void: () => voidType
386
+ });
387
+
388
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
389
+ var util;
390
+ (function(util2) {
391
+ util2.assertEqual = (_) => {
392
+ };
393
+ function assertIs(_arg) {
394
+ }
395
+ util2.assertIs = assertIs;
396
+ function assertNever(_x) {
397
+ throw new Error();
398
+ }
399
+ util2.assertNever = assertNever;
400
+ util2.arrayToEnum = (items) => {
401
+ const obj = {};
402
+ for (const item of items) {
403
+ obj[item] = item;
404
+ }
405
+ return obj;
406
+ };
407
+ util2.getValidEnumValues = (obj) => {
408
+ const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
409
+ const filtered = {};
410
+ for (const k of validKeys) {
411
+ filtered[k] = obj[k];
412
+ }
413
+ return util2.objectValues(filtered);
414
+ };
415
+ util2.objectValues = (obj) => {
416
+ return util2.objectKeys(obj).map(function(e) {
417
+ return obj[e];
418
+ });
419
+ };
420
+ util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
421
+ const keys = [];
422
+ for (const key in object) {
423
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
424
+ keys.push(key);
425
+ }
426
+ }
427
+ return keys;
428
+ };
429
+ util2.find = (arr, checker) => {
430
+ for (const item of arr) {
431
+ if (checker(item))
432
+ return item;
433
+ }
434
+ return void 0;
435
+ };
436
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
437
+ function joinValues(array, separator = " | ") {
438
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
439
+ }
440
+ util2.joinValues = joinValues;
441
+ util2.jsonStringifyReplacer = (_, value) => {
442
+ if (typeof value === "bigint") {
443
+ return value.toString();
444
+ }
445
+ return value;
446
+ };
447
+ })(util || (util = {}));
448
+ var objectUtil;
449
+ (function(objectUtil2) {
450
+ objectUtil2.mergeShapes = (first, second) => {
451
+ return {
452
+ ...first,
453
+ ...second
454
+ // second overwrites first
455
+ };
456
+ };
457
+ })(objectUtil || (objectUtil = {}));
458
+ var ZodParsedType = util.arrayToEnum([
459
+ "string",
460
+ "nan",
461
+ "number",
462
+ "integer",
463
+ "float",
464
+ "boolean",
465
+ "date",
466
+ "bigint",
467
+ "symbol",
468
+ "function",
469
+ "undefined",
470
+ "null",
471
+ "array",
472
+ "object",
473
+ "unknown",
474
+ "promise",
475
+ "void",
476
+ "never",
477
+ "map",
478
+ "set"
479
+ ]);
480
+ var getParsedType = (data) => {
481
+ const t = typeof data;
482
+ switch (t) {
483
+ case "undefined":
484
+ return ZodParsedType.undefined;
485
+ case "string":
486
+ return ZodParsedType.string;
487
+ case "number":
488
+ return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
489
+ case "boolean":
490
+ return ZodParsedType.boolean;
491
+ case "function":
492
+ return ZodParsedType.function;
493
+ case "bigint":
494
+ return ZodParsedType.bigint;
495
+ case "symbol":
496
+ return ZodParsedType.symbol;
497
+ case "object":
498
+ if (Array.isArray(data)) {
499
+ return ZodParsedType.array;
500
+ }
501
+ if (data === null) {
502
+ return ZodParsedType.null;
503
+ }
504
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
505
+ return ZodParsedType.promise;
506
+ }
507
+ if (typeof Map !== "undefined" && data instanceof Map) {
508
+ return ZodParsedType.map;
509
+ }
510
+ if (typeof Set !== "undefined" && data instanceof Set) {
511
+ return ZodParsedType.set;
512
+ }
513
+ if (typeof Date !== "undefined" && data instanceof Date) {
514
+ return ZodParsedType.date;
515
+ }
516
+ return ZodParsedType.object;
517
+ default:
518
+ return ZodParsedType.unknown;
519
+ }
520
+ };
521
+
522
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
523
+ var ZodIssueCode = util.arrayToEnum([
524
+ "invalid_type",
525
+ "invalid_literal",
526
+ "custom",
527
+ "invalid_union",
528
+ "invalid_union_discriminator",
529
+ "invalid_enum_value",
530
+ "unrecognized_keys",
531
+ "invalid_arguments",
532
+ "invalid_return_type",
533
+ "invalid_date",
534
+ "invalid_string",
535
+ "too_small",
536
+ "too_big",
537
+ "invalid_intersection_types",
538
+ "not_multiple_of",
539
+ "not_finite"
540
+ ]);
541
+ var quotelessJson = (obj) => {
542
+ const json = JSON.stringify(obj, null, 2);
543
+ return json.replace(/"([^"]+)":/g, "$1:");
544
+ };
545
+ var ZodError = class _ZodError extends Error {
546
+ get errors() {
547
+ return this.issues;
548
+ }
549
+ constructor(issues) {
550
+ super();
551
+ this.issues = [];
552
+ this.addIssue = (sub) => {
553
+ this.issues = [...this.issues, sub];
554
+ };
555
+ this.addIssues = (subs = []) => {
556
+ this.issues = [...this.issues, ...subs];
557
+ };
558
+ const actualProto = new.target.prototype;
559
+ if (Object.setPrototypeOf) {
560
+ Object.setPrototypeOf(this, actualProto);
561
+ } else {
562
+ this.__proto__ = actualProto;
563
+ }
564
+ this.name = "ZodError";
565
+ this.issues = issues;
566
+ }
567
+ format(_mapper) {
568
+ const mapper = _mapper || function(issue) {
569
+ return issue.message;
570
+ };
571
+ const fieldErrors = { _errors: [] };
572
+ const processError = (error) => {
573
+ for (const issue of error.issues) {
574
+ if (issue.code === "invalid_union") {
575
+ issue.unionErrors.map(processError);
576
+ } else if (issue.code === "invalid_return_type") {
577
+ processError(issue.returnTypeError);
578
+ } else if (issue.code === "invalid_arguments") {
579
+ processError(issue.argumentsError);
580
+ } else if (issue.path.length === 0) {
581
+ fieldErrors._errors.push(mapper(issue));
582
+ } else {
583
+ let curr = fieldErrors;
584
+ let i = 0;
585
+ while (i < issue.path.length) {
586
+ const el = issue.path[i];
587
+ const terminal = i === issue.path.length - 1;
588
+ if (!terminal) {
589
+ curr[el] = curr[el] || { _errors: [] };
590
+ } else {
591
+ curr[el] = curr[el] || { _errors: [] };
592
+ curr[el]._errors.push(mapper(issue));
593
+ }
594
+ curr = curr[el];
595
+ i++;
596
+ }
597
+ }
598
+ }
599
+ };
600
+ processError(this);
601
+ return fieldErrors;
602
+ }
603
+ static assert(value) {
604
+ if (!(value instanceof _ZodError)) {
605
+ throw new Error(`Not a ZodError: ${value}`);
606
+ }
607
+ }
608
+ toString() {
609
+ return this.message;
610
+ }
611
+ get message() {
612
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
613
+ }
614
+ get isEmpty() {
615
+ return this.issues.length === 0;
616
+ }
617
+ flatten(mapper = (issue) => issue.message) {
618
+ const fieldErrors = {};
619
+ const formErrors = [];
620
+ for (const sub of this.issues) {
621
+ if (sub.path.length > 0) {
622
+ const firstEl = sub.path[0];
623
+ fieldErrors[firstEl] = fieldErrors[firstEl] || [];
624
+ fieldErrors[firstEl].push(mapper(sub));
625
+ } else {
626
+ formErrors.push(mapper(sub));
627
+ }
628
+ }
629
+ return { formErrors, fieldErrors };
630
+ }
631
+ get formErrors() {
632
+ return this.flatten();
633
+ }
634
+ };
635
+ ZodError.create = (issues) => {
636
+ const error = new ZodError(issues);
637
+ return error;
638
+ };
639
+
640
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js
641
+ var errorMap = (issue, _ctx) => {
642
+ let message;
643
+ switch (issue.code) {
644
+ case ZodIssueCode.invalid_type:
645
+ if (issue.received === ZodParsedType.undefined) {
646
+ message = "Required";
647
+ } else {
648
+ message = `Expected ${issue.expected}, received ${issue.received}`;
649
+ }
650
+ break;
651
+ case ZodIssueCode.invalid_literal:
652
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
653
+ break;
654
+ case ZodIssueCode.unrecognized_keys:
655
+ message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
656
+ break;
657
+ case ZodIssueCode.invalid_union:
658
+ message = `Invalid input`;
659
+ break;
660
+ case ZodIssueCode.invalid_union_discriminator:
661
+ message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
662
+ break;
663
+ case ZodIssueCode.invalid_enum_value:
664
+ message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
665
+ break;
666
+ case ZodIssueCode.invalid_arguments:
667
+ message = `Invalid function arguments`;
668
+ break;
669
+ case ZodIssueCode.invalid_return_type:
670
+ message = `Invalid function return type`;
671
+ break;
672
+ case ZodIssueCode.invalid_date:
673
+ message = `Invalid date`;
674
+ break;
675
+ case ZodIssueCode.invalid_string:
676
+ if (typeof issue.validation === "object") {
677
+ if ("includes" in issue.validation) {
678
+ message = `Invalid input: must include "${issue.validation.includes}"`;
679
+ if (typeof issue.validation.position === "number") {
680
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
681
+ }
682
+ } else if ("startsWith" in issue.validation) {
683
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
684
+ } else if ("endsWith" in issue.validation) {
685
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
686
+ } else {
687
+ util.assertNever(issue.validation);
688
+ }
689
+ } else if (issue.validation !== "regex") {
690
+ message = `Invalid ${issue.validation}`;
691
+ } else {
692
+ message = "Invalid";
693
+ }
694
+ break;
695
+ case ZodIssueCode.too_small:
696
+ if (issue.type === "array")
697
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
698
+ else if (issue.type === "string")
699
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
700
+ else if (issue.type === "number")
701
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
702
+ else if (issue.type === "bigint")
703
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
704
+ else if (issue.type === "date")
705
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
706
+ else
707
+ message = "Invalid input";
708
+ break;
709
+ case ZodIssueCode.too_big:
710
+ if (issue.type === "array")
711
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
712
+ else if (issue.type === "string")
713
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
714
+ else if (issue.type === "number")
715
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
716
+ else if (issue.type === "bigint")
717
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
718
+ else if (issue.type === "date")
719
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
720
+ else
721
+ message = "Invalid input";
722
+ break;
723
+ case ZodIssueCode.custom:
724
+ message = `Invalid input`;
725
+ break;
726
+ case ZodIssueCode.invalid_intersection_types:
727
+ message = `Intersection results could not be merged`;
728
+ break;
729
+ case ZodIssueCode.not_multiple_of:
730
+ message = `Number must be a multiple of ${issue.multipleOf}`;
731
+ break;
732
+ case ZodIssueCode.not_finite:
733
+ message = "Number must be finite";
734
+ break;
735
+ default:
736
+ message = _ctx.defaultError;
737
+ util.assertNever(issue);
738
+ }
739
+ return { message };
740
+ };
741
+ var en_default = errorMap;
742
+
743
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js
744
+ var overrideErrorMap = en_default;
745
+ function setErrorMap(map) {
746
+ overrideErrorMap = map;
747
+ }
748
+ function getErrorMap() {
749
+ return overrideErrorMap;
750
+ }
751
+
752
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
753
+ var makeIssue = (params) => {
754
+ const { data, path, errorMaps, issueData } = params;
755
+ const fullPath = [...path, ...issueData.path || []];
756
+ const fullIssue = {
757
+ ...issueData,
758
+ path: fullPath
759
+ };
760
+ if (issueData.message !== void 0) {
761
+ return {
762
+ ...issueData,
763
+ path: fullPath,
764
+ message: issueData.message
765
+ };
766
+ }
767
+ let errorMessage2 = "";
768
+ const maps = errorMaps.filter((m) => !!m).slice().reverse();
769
+ for (const map of maps) {
770
+ errorMessage2 = map(fullIssue, { data, defaultError: errorMessage2 }).message;
771
+ }
772
+ return {
773
+ ...issueData,
774
+ path: fullPath,
775
+ message: errorMessage2
776
+ };
777
+ };
778
+ var EMPTY_PATH = [];
779
+ function addIssueToContext(ctx, issueData) {
780
+ const overrideMap = getErrorMap();
781
+ const issue = makeIssue({
782
+ issueData,
783
+ data: ctx.data,
784
+ path: ctx.path,
785
+ errorMaps: [
786
+ ctx.common.contextualErrorMap,
787
+ // contextual error map is first priority
788
+ ctx.schemaErrorMap,
789
+ // then schema-bound map if available
790
+ overrideMap,
791
+ // then global override map
792
+ overrideMap === en_default ? void 0 : en_default
793
+ // then global default map
794
+ ].filter((x) => !!x)
795
+ });
796
+ ctx.common.issues.push(issue);
797
+ }
798
+ var ParseStatus = class _ParseStatus {
799
+ constructor() {
800
+ this.value = "valid";
801
+ }
802
+ dirty() {
803
+ if (this.value === "valid")
804
+ this.value = "dirty";
805
+ }
806
+ abort() {
807
+ if (this.value !== "aborted")
808
+ this.value = "aborted";
809
+ }
810
+ static mergeArray(status, results) {
811
+ const arrayValue = [];
812
+ for (const s of results) {
813
+ if (s.status === "aborted")
814
+ return INVALID;
815
+ if (s.status === "dirty")
816
+ status.dirty();
817
+ arrayValue.push(s.value);
818
+ }
819
+ return { status: status.value, value: arrayValue };
820
+ }
821
+ static async mergeObjectAsync(status, pairs) {
822
+ const syncPairs = [];
823
+ for (const pair of pairs) {
824
+ const key = await pair.key;
825
+ const value = await pair.value;
826
+ syncPairs.push({
827
+ key,
828
+ value
829
+ });
830
+ }
831
+ return _ParseStatus.mergeObjectSync(status, syncPairs);
832
+ }
833
+ static mergeObjectSync(status, pairs) {
834
+ const finalObject = {};
835
+ for (const pair of pairs) {
836
+ const { key, value } = pair;
837
+ if (key.status === "aborted")
838
+ return INVALID;
839
+ if (value.status === "aborted")
840
+ return INVALID;
841
+ if (key.status === "dirty")
842
+ status.dirty();
843
+ if (value.status === "dirty")
844
+ status.dirty();
845
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
846
+ finalObject[key.value] = value.value;
847
+ }
848
+ }
849
+ return { status: status.value, value: finalObject };
850
+ }
851
+ };
852
+ var INVALID = Object.freeze({
853
+ status: "aborted"
854
+ });
855
+ var DIRTY = (value) => ({ status: "dirty", value });
856
+ var OK = (value) => ({ status: "valid", value });
857
+ var isAborted = (x) => x.status === "aborted";
858
+ var isDirty = (x) => x.status === "dirty";
859
+ var isValid = (x) => x.status === "valid";
860
+ var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
861
+
862
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
863
+ var errorUtil;
864
+ (function(errorUtil2) {
865
+ errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
866
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
867
+ })(errorUtil || (errorUtil = {}));
868
+
869
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
870
+ var ParseInputLazyPath = class {
871
+ constructor(parent, value, path, key) {
872
+ this._cachedPath = [];
873
+ this.parent = parent;
874
+ this.data = value;
875
+ this._path = path;
876
+ this._key = key;
877
+ }
878
+ get path() {
879
+ if (!this._cachedPath.length) {
880
+ if (Array.isArray(this._key)) {
881
+ this._cachedPath.push(...this._path, ...this._key);
882
+ } else {
883
+ this._cachedPath.push(...this._path, this._key);
884
+ }
885
+ }
886
+ return this._cachedPath;
887
+ }
888
+ };
889
+ var handleResult = (ctx, result) => {
890
+ if (isValid(result)) {
891
+ return { success: true, data: result.value };
892
+ } else {
893
+ if (!ctx.common.issues.length) {
894
+ throw new Error("Validation failed but no issues detected.");
895
+ }
896
+ return {
897
+ success: false,
898
+ get error() {
899
+ if (this._error)
900
+ return this._error;
901
+ const error = new ZodError(ctx.common.issues);
902
+ this._error = error;
903
+ return this._error;
904
+ }
905
+ };
906
+ }
907
+ };
908
+ function processCreateParams(params) {
909
+ if (!params)
910
+ return {};
911
+ const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
912
+ if (errorMap2 && (invalid_type_error || required_error)) {
913
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
914
+ }
915
+ if (errorMap2)
916
+ return { errorMap: errorMap2, description };
917
+ const customMap = (iss, ctx) => {
918
+ const { message } = params;
919
+ if (iss.code === "invalid_enum_value") {
920
+ return { message: message ?? ctx.defaultError };
921
+ }
922
+ if (typeof ctx.data === "undefined") {
923
+ return { message: message ?? required_error ?? ctx.defaultError };
924
+ }
925
+ if (iss.code !== "invalid_type")
926
+ return { message: ctx.defaultError };
927
+ return { message: message ?? invalid_type_error ?? ctx.defaultError };
928
+ };
929
+ return { errorMap: customMap, description };
930
+ }
931
+ var ZodType = class {
932
+ get description() {
933
+ return this._def.description;
934
+ }
935
+ _getType(input) {
936
+ return getParsedType(input.data);
937
+ }
938
+ _getOrReturnCtx(input, ctx) {
939
+ return ctx || {
940
+ common: input.parent.common,
941
+ data: input.data,
942
+ parsedType: getParsedType(input.data),
943
+ schemaErrorMap: this._def.errorMap,
944
+ path: input.path,
945
+ parent: input.parent
946
+ };
947
+ }
948
+ _processInputParams(input) {
949
+ return {
950
+ status: new ParseStatus(),
951
+ ctx: {
952
+ common: input.parent.common,
953
+ data: input.data,
954
+ parsedType: getParsedType(input.data),
955
+ schemaErrorMap: this._def.errorMap,
956
+ path: input.path,
957
+ parent: input.parent
958
+ }
959
+ };
960
+ }
961
+ _parseSync(input) {
962
+ const result = this._parse(input);
963
+ if (isAsync(result)) {
964
+ throw new Error("Synchronous parse encountered promise.");
965
+ }
966
+ return result;
967
+ }
968
+ _parseAsync(input) {
969
+ const result = this._parse(input);
970
+ return Promise.resolve(result);
971
+ }
972
+ parse(data, params) {
973
+ const result = this.safeParse(data, params);
974
+ if (result.success)
975
+ return result.data;
976
+ throw result.error;
977
+ }
978
+ safeParse(data, params) {
979
+ const ctx = {
980
+ common: {
981
+ issues: [],
982
+ async: params?.async ?? false,
983
+ contextualErrorMap: params?.errorMap
984
+ },
985
+ path: params?.path || [],
986
+ schemaErrorMap: this._def.errorMap,
987
+ parent: null,
988
+ data,
989
+ parsedType: getParsedType(data)
990
+ };
991
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
992
+ return handleResult(ctx, result);
993
+ }
994
+ "~validate"(data) {
995
+ const ctx = {
996
+ common: {
997
+ issues: [],
998
+ async: !!this["~standard"].async
999
+ },
1000
+ path: [],
1001
+ schemaErrorMap: this._def.errorMap,
1002
+ parent: null,
1003
+ data,
1004
+ parsedType: getParsedType(data)
1005
+ };
1006
+ if (!this["~standard"].async) {
1007
+ try {
1008
+ const result = this._parseSync({ data, path: [], parent: ctx });
1009
+ return isValid(result) ? {
1010
+ value: result.value
1011
+ } : {
1012
+ issues: ctx.common.issues
1013
+ };
1014
+ } catch (err) {
1015
+ if (err?.message?.toLowerCase()?.includes("encountered")) {
1016
+ this["~standard"].async = true;
1017
+ }
1018
+ ctx.common = {
1019
+ issues: [],
1020
+ async: true
1021
+ };
1022
+ }
1023
+ }
1024
+ return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
1025
+ value: result.value
1026
+ } : {
1027
+ issues: ctx.common.issues
1028
+ });
1029
+ }
1030
+ async parseAsync(data, params) {
1031
+ const result = await this.safeParseAsync(data, params);
1032
+ if (result.success)
1033
+ return result.data;
1034
+ throw result.error;
1035
+ }
1036
+ async safeParseAsync(data, params) {
1037
+ const ctx = {
1038
+ common: {
1039
+ issues: [],
1040
+ contextualErrorMap: params?.errorMap,
1041
+ async: true
1042
+ },
1043
+ path: params?.path || [],
1044
+ schemaErrorMap: this._def.errorMap,
1045
+ parent: null,
1046
+ data,
1047
+ parsedType: getParsedType(data)
1048
+ };
1049
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
1050
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
1051
+ return handleResult(ctx, result);
1052
+ }
1053
+ refine(check, message) {
1054
+ const getIssueProperties = (val) => {
1055
+ if (typeof message === "string" || typeof message === "undefined") {
1056
+ return { message };
1057
+ } else if (typeof message === "function") {
1058
+ return message(val);
1059
+ } else {
1060
+ return message;
1061
+ }
1062
+ };
1063
+ return this._refinement((val, ctx) => {
1064
+ const result = check(val);
1065
+ const setError = () => ctx.addIssue({
1066
+ code: ZodIssueCode.custom,
1067
+ ...getIssueProperties(val)
1068
+ });
1069
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
1070
+ return result.then((data) => {
1071
+ if (!data) {
1072
+ setError();
1073
+ return false;
1074
+ } else {
1075
+ return true;
1076
+ }
1077
+ });
1078
+ }
1079
+ if (!result) {
1080
+ setError();
1081
+ return false;
1082
+ } else {
1083
+ return true;
1084
+ }
1085
+ });
1086
+ }
1087
+ refinement(check, refinementData) {
1088
+ return this._refinement((val, ctx) => {
1089
+ if (!check(val)) {
1090
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
1091
+ return false;
1092
+ } else {
1093
+ return true;
1094
+ }
1095
+ });
1096
+ }
1097
+ _refinement(refinement) {
1098
+ return new ZodEffects({
1099
+ schema: this,
1100
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
1101
+ effect: { type: "refinement", refinement }
1102
+ });
1103
+ }
1104
+ superRefine(refinement) {
1105
+ return this._refinement(refinement);
1106
+ }
1107
+ constructor(def) {
1108
+ this.spa = this.safeParseAsync;
1109
+ this._def = def;
1110
+ this.parse = this.parse.bind(this);
1111
+ this.safeParse = this.safeParse.bind(this);
1112
+ this.parseAsync = this.parseAsync.bind(this);
1113
+ this.safeParseAsync = this.safeParseAsync.bind(this);
1114
+ this.spa = this.spa.bind(this);
1115
+ this.refine = this.refine.bind(this);
1116
+ this.refinement = this.refinement.bind(this);
1117
+ this.superRefine = this.superRefine.bind(this);
1118
+ this.optional = this.optional.bind(this);
1119
+ this.nullable = this.nullable.bind(this);
1120
+ this.nullish = this.nullish.bind(this);
1121
+ this.array = this.array.bind(this);
1122
+ this.promise = this.promise.bind(this);
1123
+ this.or = this.or.bind(this);
1124
+ this.and = this.and.bind(this);
1125
+ this.transform = this.transform.bind(this);
1126
+ this.brand = this.brand.bind(this);
1127
+ this.default = this.default.bind(this);
1128
+ this.catch = this.catch.bind(this);
1129
+ this.describe = this.describe.bind(this);
1130
+ this.pipe = this.pipe.bind(this);
1131
+ this.readonly = this.readonly.bind(this);
1132
+ this.isNullable = this.isNullable.bind(this);
1133
+ this.isOptional = this.isOptional.bind(this);
1134
+ this["~standard"] = {
1135
+ version: 1,
1136
+ vendor: "zod",
1137
+ validate: (data) => this["~validate"](data)
1138
+ };
1139
+ }
1140
+ optional() {
1141
+ return ZodOptional.create(this, this._def);
1142
+ }
1143
+ nullable() {
1144
+ return ZodNullable.create(this, this._def);
1145
+ }
1146
+ nullish() {
1147
+ return this.nullable().optional();
1148
+ }
1149
+ array() {
1150
+ return ZodArray.create(this);
1151
+ }
1152
+ promise() {
1153
+ return ZodPromise.create(this, this._def);
1154
+ }
1155
+ or(option) {
1156
+ return ZodUnion.create([this, option], this._def);
1157
+ }
1158
+ and(incoming) {
1159
+ return ZodIntersection.create(this, incoming, this._def);
1160
+ }
1161
+ transform(transform) {
1162
+ return new ZodEffects({
1163
+ ...processCreateParams(this._def),
1164
+ schema: this,
1165
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
1166
+ effect: { type: "transform", transform }
1167
+ });
1168
+ }
1169
+ default(def) {
1170
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
1171
+ return new ZodDefault({
1172
+ ...processCreateParams(this._def),
1173
+ innerType: this,
1174
+ defaultValue: defaultValueFunc,
1175
+ typeName: ZodFirstPartyTypeKind.ZodDefault
1176
+ });
1177
+ }
1178
+ brand() {
1179
+ return new ZodBranded({
1180
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
1181
+ type: this,
1182
+ ...processCreateParams(this._def)
1183
+ });
1184
+ }
1185
+ catch(def) {
1186
+ const catchValueFunc = typeof def === "function" ? def : () => def;
1187
+ return new ZodCatch({
1188
+ ...processCreateParams(this._def),
1189
+ innerType: this,
1190
+ catchValue: catchValueFunc,
1191
+ typeName: ZodFirstPartyTypeKind.ZodCatch
1192
+ });
1193
+ }
1194
+ describe(description) {
1195
+ const This = this.constructor;
1196
+ return new This({
1197
+ ...this._def,
1198
+ description
1199
+ });
1200
+ }
1201
+ pipe(target) {
1202
+ return ZodPipeline.create(this, target);
1203
+ }
1204
+ readonly() {
1205
+ return ZodReadonly.create(this);
1206
+ }
1207
+ isOptional() {
1208
+ return this.safeParse(void 0).success;
1209
+ }
1210
+ isNullable() {
1211
+ return this.safeParse(null).success;
1212
+ }
1213
+ };
1214
+ var cuidRegex = /^c[^\s-]{8,}$/i;
1215
+ var cuid2Regex = /^[0-9a-z]+$/;
1216
+ var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
1217
+ var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
1218
+ var nanoidRegex = /^[a-z0-9_-]{21}$/i;
1219
+ var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
1220
+ var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
1221
+ var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
1222
+ var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
1223
+ var emojiRegex;
1224
+ var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
1225
+ var ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
1226
+ var ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
1227
+ var ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
1228
+ var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
1229
+ var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
1230
+ var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
1231
+ var dateRegex = new RegExp(`^${dateRegexSource}$`);
1232
+ function timeRegexSource(args) {
1233
+ let secondsRegexSource = `[0-5]\\d`;
1234
+ if (args.precision) {
1235
+ secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
1236
+ } else if (args.precision == null) {
1237
+ secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
1238
+ }
1239
+ const secondsQuantifier = args.precision ? "+" : "?";
1240
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
1241
+ }
1242
+ function timeRegex(args) {
1243
+ return new RegExp(`^${timeRegexSource(args)}$`);
1244
+ }
1245
+ function datetimeRegex(args) {
1246
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
1247
+ const opts = [];
1248
+ opts.push(args.local ? `Z?` : `Z`);
1249
+ if (args.offset)
1250
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
1251
+ regex = `${regex}(${opts.join("|")})`;
1252
+ return new RegExp(`^${regex}$`);
1253
+ }
1254
+ function isValidIP(ip, version) {
1255
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
1256
+ return true;
1257
+ }
1258
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
1259
+ return true;
1260
+ }
1261
+ return false;
1262
+ }
1263
+ function isValidJWT(jwt, alg) {
1264
+ if (!jwtRegex.test(jwt))
1265
+ return false;
1266
+ try {
1267
+ const [header] = jwt.split(".");
1268
+ if (!header)
1269
+ return false;
1270
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
1271
+ const decoded = JSON.parse(atob(base64));
1272
+ if (typeof decoded !== "object" || decoded === null)
1273
+ return false;
1274
+ if ("typ" in decoded && decoded?.typ !== "JWT")
1275
+ return false;
1276
+ if (!decoded.alg)
1277
+ return false;
1278
+ if (alg && decoded.alg !== alg)
1279
+ return false;
1280
+ return true;
1281
+ } catch {
1282
+ return false;
1283
+ }
1284
+ }
1285
+ function isValidCidr(ip, version) {
1286
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
1287
+ return true;
1288
+ }
1289
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
1290
+ return true;
1291
+ }
1292
+ return false;
1293
+ }
1294
+ var ZodString = class _ZodString extends ZodType {
1295
+ _parse(input) {
1296
+ if (this._def.coerce) {
1297
+ input.data = String(input.data);
1298
+ }
1299
+ const parsedType = this._getType(input);
1300
+ if (parsedType !== ZodParsedType.string) {
1301
+ const ctx2 = this._getOrReturnCtx(input);
1302
+ addIssueToContext(ctx2, {
1303
+ code: ZodIssueCode.invalid_type,
1304
+ expected: ZodParsedType.string,
1305
+ received: ctx2.parsedType
1306
+ });
1307
+ return INVALID;
1308
+ }
1309
+ const status = new ParseStatus();
1310
+ let ctx = void 0;
1311
+ for (const check of this._def.checks) {
1312
+ if (check.kind === "min") {
1313
+ if (input.data.length < check.value) {
1314
+ ctx = this._getOrReturnCtx(input, ctx);
1315
+ addIssueToContext(ctx, {
1316
+ code: ZodIssueCode.too_small,
1317
+ minimum: check.value,
1318
+ type: "string",
1319
+ inclusive: true,
1320
+ exact: false,
1321
+ message: check.message
1322
+ });
1323
+ status.dirty();
1324
+ }
1325
+ } else if (check.kind === "max") {
1326
+ if (input.data.length > check.value) {
1327
+ ctx = this._getOrReturnCtx(input, ctx);
1328
+ addIssueToContext(ctx, {
1329
+ code: ZodIssueCode.too_big,
1330
+ maximum: check.value,
1331
+ type: "string",
1332
+ inclusive: true,
1333
+ exact: false,
1334
+ message: check.message
1335
+ });
1336
+ status.dirty();
1337
+ }
1338
+ } else if (check.kind === "length") {
1339
+ const tooBig = input.data.length > check.value;
1340
+ const tooSmall = input.data.length < check.value;
1341
+ if (tooBig || tooSmall) {
1342
+ ctx = this._getOrReturnCtx(input, ctx);
1343
+ if (tooBig) {
1344
+ addIssueToContext(ctx, {
1345
+ code: ZodIssueCode.too_big,
1346
+ maximum: check.value,
1347
+ type: "string",
1348
+ inclusive: true,
1349
+ exact: true,
1350
+ message: check.message
1351
+ });
1352
+ } else if (tooSmall) {
1353
+ addIssueToContext(ctx, {
1354
+ code: ZodIssueCode.too_small,
1355
+ minimum: check.value,
1356
+ type: "string",
1357
+ inclusive: true,
1358
+ exact: true,
1359
+ message: check.message
1360
+ });
1361
+ }
1362
+ status.dirty();
1363
+ }
1364
+ } else if (check.kind === "email") {
1365
+ if (!emailRegex.test(input.data)) {
1366
+ ctx = this._getOrReturnCtx(input, ctx);
1367
+ addIssueToContext(ctx, {
1368
+ validation: "email",
1369
+ code: ZodIssueCode.invalid_string,
1370
+ message: check.message
1371
+ });
1372
+ status.dirty();
1373
+ }
1374
+ } else if (check.kind === "emoji") {
1375
+ if (!emojiRegex) {
1376
+ emojiRegex = new RegExp(_emojiRegex, "u");
1377
+ }
1378
+ if (!emojiRegex.test(input.data)) {
1379
+ ctx = this._getOrReturnCtx(input, ctx);
1380
+ addIssueToContext(ctx, {
1381
+ validation: "emoji",
1382
+ code: ZodIssueCode.invalid_string,
1383
+ message: check.message
1384
+ });
1385
+ status.dirty();
1386
+ }
1387
+ } else if (check.kind === "uuid") {
1388
+ if (!uuidRegex.test(input.data)) {
1389
+ ctx = this._getOrReturnCtx(input, ctx);
1390
+ addIssueToContext(ctx, {
1391
+ validation: "uuid",
1392
+ code: ZodIssueCode.invalid_string,
1393
+ message: check.message
1394
+ });
1395
+ status.dirty();
1396
+ }
1397
+ } else if (check.kind === "nanoid") {
1398
+ if (!nanoidRegex.test(input.data)) {
1399
+ ctx = this._getOrReturnCtx(input, ctx);
1400
+ addIssueToContext(ctx, {
1401
+ validation: "nanoid",
1402
+ code: ZodIssueCode.invalid_string,
1403
+ message: check.message
1404
+ });
1405
+ status.dirty();
1406
+ }
1407
+ } else if (check.kind === "cuid") {
1408
+ if (!cuidRegex.test(input.data)) {
1409
+ ctx = this._getOrReturnCtx(input, ctx);
1410
+ addIssueToContext(ctx, {
1411
+ validation: "cuid",
1412
+ code: ZodIssueCode.invalid_string,
1413
+ message: check.message
1414
+ });
1415
+ status.dirty();
1416
+ }
1417
+ } else if (check.kind === "cuid2") {
1418
+ if (!cuid2Regex.test(input.data)) {
1419
+ ctx = this._getOrReturnCtx(input, ctx);
1420
+ addIssueToContext(ctx, {
1421
+ validation: "cuid2",
1422
+ code: ZodIssueCode.invalid_string,
1423
+ message: check.message
1424
+ });
1425
+ status.dirty();
1426
+ }
1427
+ } else if (check.kind === "ulid") {
1428
+ if (!ulidRegex.test(input.data)) {
1429
+ ctx = this._getOrReturnCtx(input, ctx);
1430
+ addIssueToContext(ctx, {
1431
+ validation: "ulid",
1432
+ code: ZodIssueCode.invalid_string,
1433
+ message: check.message
1434
+ });
1435
+ status.dirty();
1436
+ }
1437
+ } else if (check.kind === "url") {
1438
+ try {
1439
+ new URL(input.data);
1440
+ } catch {
1441
+ ctx = this._getOrReturnCtx(input, ctx);
1442
+ addIssueToContext(ctx, {
1443
+ validation: "url",
1444
+ code: ZodIssueCode.invalid_string,
1445
+ message: check.message
1446
+ });
1447
+ status.dirty();
1448
+ }
1449
+ } else if (check.kind === "regex") {
1450
+ check.regex.lastIndex = 0;
1451
+ const testResult = check.regex.test(input.data);
1452
+ if (!testResult) {
1453
+ ctx = this._getOrReturnCtx(input, ctx);
1454
+ addIssueToContext(ctx, {
1455
+ validation: "regex",
1456
+ code: ZodIssueCode.invalid_string,
1457
+ message: check.message
1458
+ });
1459
+ status.dirty();
1460
+ }
1461
+ } else if (check.kind === "trim") {
1462
+ input.data = input.data.trim();
1463
+ } else if (check.kind === "includes") {
1464
+ if (!input.data.includes(check.value, check.position)) {
1465
+ ctx = this._getOrReturnCtx(input, ctx);
1466
+ addIssueToContext(ctx, {
1467
+ code: ZodIssueCode.invalid_string,
1468
+ validation: { includes: check.value, position: check.position },
1469
+ message: check.message
1470
+ });
1471
+ status.dirty();
1472
+ }
1473
+ } else if (check.kind === "toLowerCase") {
1474
+ input.data = input.data.toLowerCase();
1475
+ } else if (check.kind === "toUpperCase") {
1476
+ input.data = input.data.toUpperCase();
1477
+ } else if (check.kind === "startsWith") {
1478
+ if (!input.data.startsWith(check.value)) {
1479
+ ctx = this._getOrReturnCtx(input, ctx);
1480
+ addIssueToContext(ctx, {
1481
+ code: ZodIssueCode.invalid_string,
1482
+ validation: { startsWith: check.value },
1483
+ message: check.message
1484
+ });
1485
+ status.dirty();
1486
+ }
1487
+ } else if (check.kind === "endsWith") {
1488
+ if (!input.data.endsWith(check.value)) {
1489
+ ctx = this._getOrReturnCtx(input, ctx);
1490
+ addIssueToContext(ctx, {
1491
+ code: ZodIssueCode.invalid_string,
1492
+ validation: { endsWith: check.value },
1493
+ message: check.message
1494
+ });
1495
+ status.dirty();
1496
+ }
1497
+ } else if (check.kind === "datetime") {
1498
+ const regex = datetimeRegex(check);
1499
+ if (!regex.test(input.data)) {
1500
+ ctx = this._getOrReturnCtx(input, ctx);
1501
+ addIssueToContext(ctx, {
1502
+ code: ZodIssueCode.invalid_string,
1503
+ validation: "datetime",
1504
+ message: check.message
1505
+ });
1506
+ status.dirty();
1507
+ }
1508
+ } else if (check.kind === "date") {
1509
+ const regex = dateRegex;
1510
+ if (!regex.test(input.data)) {
1511
+ ctx = this._getOrReturnCtx(input, ctx);
1512
+ addIssueToContext(ctx, {
1513
+ code: ZodIssueCode.invalid_string,
1514
+ validation: "date",
1515
+ message: check.message
1516
+ });
1517
+ status.dirty();
1518
+ }
1519
+ } else if (check.kind === "time") {
1520
+ const regex = timeRegex(check);
1521
+ if (!regex.test(input.data)) {
1522
+ ctx = this._getOrReturnCtx(input, ctx);
1523
+ addIssueToContext(ctx, {
1524
+ code: ZodIssueCode.invalid_string,
1525
+ validation: "time",
1526
+ message: check.message
1527
+ });
1528
+ status.dirty();
1529
+ }
1530
+ } else if (check.kind === "duration") {
1531
+ if (!durationRegex.test(input.data)) {
1532
+ ctx = this._getOrReturnCtx(input, ctx);
1533
+ addIssueToContext(ctx, {
1534
+ validation: "duration",
1535
+ code: ZodIssueCode.invalid_string,
1536
+ message: check.message
1537
+ });
1538
+ status.dirty();
1539
+ }
1540
+ } else if (check.kind === "ip") {
1541
+ if (!isValidIP(input.data, check.version)) {
1542
+ ctx = this._getOrReturnCtx(input, ctx);
1543
+ addIssueToContext(ctx, {
1544
+ validation: "ip",
1545
+ code: ZodIssueCode.invalid_string,
1546
+ message: check.message
1547
+ });
1548
+ status.dirty();
1549
+ }
1550
+ } else if (check.kind === "jwt") {
1551
+ if (!isValidJWT(input.data, check.alg)) {
1552
+ ctx = this._getOrReturnCtx(input, ctx);
1553
+ addIssueToContext(ctx, {
1554
+ validation: "jwt",
1555
+ code: ZodIssueCode.invalid_string,
1556
+ message: check.message
1557
+ });
1558
+ status.dirty();
1559
+ }
1560
+ } else if (check.kind === "cidr") {
1561
+ if (!isValidCidr(input.data, check.version)) {
1562
+ ctx = this._getOrReturnCtx(input, ctx);
1563
+ addIssueToContext(ctx, {
1564
+ validation: "cidr",
1565
+ code: ZodIssueCode.invalid_string,
1566
+ message: check.message
1567
+ });
1568
+ status.dirty();
1569
+ }
1570
+ } else if (check.kind === "base64") {
1571
+ if (!base64Regex.test(input.data)) {
1572
+ ctx = this._getOrReturnCtx(input, ctx);
1573
+ addIssueToContext(ctx, {
1574
+ validation: "base64",
1575
+ code: ZodIssueCode.invalid_string,
1576
+ message: check.message
1577
+ });
1578
+ status.dirty();
1579
+ }
1580
+ } else if (check.kind === "base64url") {
1581
+ if (!base64urlRegex.test(input.data)) {
1582
+ ctx = this._getOrReturnCtx(input, ctx);
1583
+ addIssueToContext(ctx, {
1584
+ validation: "base64url",
1585
+ code: ZodIssueCode.invalid_string,
1586
+ message: check.message
1587
+ });
1588
+ status.dirty();
1589
+ }
1590
+ } else {
1591
+ util.assertNever(check);
1592
+ }
1593
+ }
1594
+ return { status: status.value, value: input.data };
1595
+ }
1596
+ _regex(regex, validation, message) {
1597
+ return this.refinement((data) => regex.test(data), {
1598
+ validation,
1599
+ code: ZodIssueCode.invalid_string,
1600
+ ...errorUtil.errToObj(message)
1601
+ });
1602
+ }
1603
+ _addCheck(check) {
1604
+ return new _ZodString({
1605
+ ...this._def,
1606
+ checks: [...this._def.checks, check]
1607
+ });
1608
+ }
1609
+ email(message) {
1610
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
1611
+ }
1612
+ url(message) {
1613
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
1614
+ }
1615
+ emoji(message) {
1616
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
1617
+ }
1618
+ uuid(message) {
1619
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
1620
+ }
1621
+ nanoid(message) {
1622
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
1623
+ }
1624
+ cuid(message) {
1625
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
1626
+ }
1627
+ cuid2(message) {
1628
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
1629
+ }
1630
+ ulid(message) {
1631
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
1632
+ }
1633
+ base64(message) {
1634
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
1635
+ }
1636
+ base64url(message) {
1637
+ return this._addCheck({
1638
+ kind: "base64url",
1639
+ ...errorUtil.errToObj(message)
1640
+ });
1641
+ }
1642
+ jwt(options) {
1643
+ return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
1644
+ }
1645
+ ip(options) {
1646
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
1647
+ }
1648
+ cidr(options) {
1649
+ return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
1650
+ }
1651
+ datetime(options) {
1652
+ if (typeof options === "string") {
1653
+ return this._addCheck({
1654
+ kind: "datetime",
1655
+ precision: null,
1656
+ offset: false,
1657
+ local: false,
1658
+ message: options
1659
+ });
1660
+ }
1661
+ return this._addCheck({
1662
+ kind: "datetime",
1663
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1664
+ offset: options?.offset ?? false,
1665
+ local: options?.local ?? false,
1666
+ ...errorUtil.errToObj(options?.message)
1667
+ });
1668
+ }
1669
+ date(message) {
1670
+ return this._addCheck({ kind: "date", message });
1671
+ }
1672
+ time(options) {
1673
+ if (typeof options === "string") {
1674
+ return this._addCheck({
1675
+ kind: "time",
1676
+ precision: null,
1677
+ message: options
1678
+ });
1679
+ }
1680
+ return this._addCheck({
1681
+ kind: "time",
1682
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1683
+ ...errorUtil.errToObj(options?.message)
1684
+ });
1685
+ }
1686
+ duration(message) {
1687
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
1688
+ }
1689
+ regex(regex, message) {
1690
+ return this._addCheck({
1691
+ kind: "regex",
1692
+ regex,
1693
+ ...errorUtil.errToObj(message)
1694
+ });
1695
+ }
1696
+ includes(value, options) {
1697
+ return this._addCheck({
1698
+ kind: "includes",
1699
+ value,
1700
+ position: options?.position,
1701
+ ...errorUtil.errToObj(options?.message)
1702
+ });
1703
+ }
1704
+ startsWith(value, message) {
1705
+ return this._addCheck({
1706
+ kind: "startsWith",
1707
+ value,
1708
+ ...errorUtil.errToObj(message)
1709
+ });
1710
+ }
1711
+ endsWith(value, message) {
1712
+ return this._addCheck({
1713
+ kind: "endsWith",
1714
+ value,
1715
+ ...errorUtil.errToObj(message)
1716
+ });
1717
+ }
1718
+ min(minLength, message) {
1719
+ return this._addCheck({
1720
+ kind: "min",
1721
+ value: minLength,
1722
+ ...errorUtil.errToObj(message)
1723
+ });
1724
+ }
1725
+ max(maxLength, message) {
1726
+ return this._addCheck({
1727
+ kind: "max",
1728
+ value: maxLength,
1729
+ ...errorUtil.errToObj(message)
1730
+ });
1731
+ }
1732
+ length(len, message) {
1733
+ return this._addCheck({
1734
+ kind: "length",
1735
+ value: len,
1736
+ ...errorUtil.errToObj(message)
1737
+ });
1738
+ }
1739
+ /**
1740
+ * Equivalent to `.min(1)`
1741
+ */
1742
+ nonempty(message) {
1743
+ return this.min(1, errorUtil.errToObj(message));
1744
+ }
1745
+ trim() {
1746
+ return new _ZodString({
1747
+ ...this._def,
1748
+ checks: [...this._def.checks, { kind: "trim" }]
1749
+ });
1750
+ }
1751
+ toLowerCase() {
1752
+ return new _ZodString({
1753
+ ...this._def,
1754
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
1755
+ });
1756
+ }
1757
+ toUpperCase() {
1758
+ return new _ZodString({
1759
+ ...this._def,
1760
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
1761
+ });
1762
+ }
1763
+ get isDatetime() {
1764
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
1765
+ }
1766
+ get isDate() {
1767
+ return !!this._def.checks.find((ch) => ch.kind === "date");
1768
+ }
1769
+ get isTime() {
1770
+ return !!this._def.checks.find((ch) => ch.kind === "time");
1771
+ }
1772
+ get isDuration() {
1773
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
1774
+ }
1775
+ get isEmail() {
1776
+ return !!this._def.checks.find((ch) => ch.kind === "email");
1777
+ }
1778
+ get isURL() {
1779
+ return !!this._def.checks.find((ch) => ch.kind === "url");
1780
+ }
1781
+ get isEmoji() {
1782
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
1783
+ }
1784
+ get isUUID() {
1785
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
1786
+ }
1787
+ get isNANOID() {
1788
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
1789
+ }
1790
+ get isCUID() {
1791
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
1792
+ }
1793
+ get isCUID2() {
1794
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
1795
+ }
1796
+ get isULID() {
1797
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
1798
+ }
1799
+ get isIP() {
1800
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
1801
+ }
1802
+ get isCIDR() {
1803
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
1804
+ }
1805
+ get isBase64() {
1806
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
1807
+ }
1808
+ get isBase64url() {
1809
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
1810
+ }
1811
+ get minLength() {
1812
+ let min = null;
1813
+ for (const ch of this._def.checks) {
1814
+ if (ch.kind === "min") {
1815
+ if (min === null || ch.value > min)
1816
+ min = ch.value;
1817
+ }
1818
+ }
1819
+ return min;
1820
+ }
1821
+ get maxLength() {
1822
+ let max = null;
1823
+ for (const ch of this._def.checks) {
1824
+ if (ch.kind === "max") {
1825
+ if (max === null || ch.value < max)
1826
+ max = ch.value;
1827
+ }
1828
+ }
1829
+ return max;
1830
+ }
1831
+ };
1832
+ ZodString.create = (params) => {
1833
+ return new ZodString({
1834
+ checks: [],
1835
+ typeName: ZodFirstPartyTypeKind.ZodString,
1836
+ coerce: params?.coerce ?? false,
1837
+ ...processCreateParams(params)
1838
+ });
1839
+ };
1840
+ function floatSafeRemainder(val, step) {
1841
+ const valDecCount = (val.toString().split(".")[1] || "").length;
1842
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
1843
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1844
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
1845
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
1846
+ return valInt % stepInt / 10 ** decCount;
1847
+ }
1848
+ var ZodNumber = class _ZodNumber extends ZodType {
1849
+ constructor() {
1850
+ super(...arguments);
1851
+ this.min = this.gte;
1852
+ this.max = this.lte;
1853
+ this.step = this.multipleOf;
1854
+ }
1855
+ _parse(input) {
1856
+ if (this._def.coerce) {
1857
+ input.data = Number(input.data);
1858
+ }
1859
+ const parsedType = this._getType(input);
1860
+ if (parsedType !== ZodParsedType.number) {
1861
+ const ctx2 = this._getOrReturnCtx(input);
1862
+ addIssueToContext(ctx2, {
1863
+ code: ZodIssueCode.invalid_type,
1864
+ expected: ZodParsedType.number,
1865
+ received: ctx2.parsedType
1866
+ });
1867
+ return INVALID;
1868
+ }
1869
+ let ctx = void 0;
1870
+ const status = new ParseStatus();
1871
+ for (const check of this._def.checks) {
1872
+ if (check.kind === "int") {
1873
+ if (!util.isInteger(input.data)) {
1874
+ ctx = this._getOrReturnCtx(input, ctx);
1875
+ addIssueToContext(ctx, {
1876
+ code: ZodIssueCode.invalid_type,
1877
+ expected: "integer",
1878
+ received: "float",
1879
+ message: check.message
1880
+ });
1881
+ status.dirty();
1882
+ }
1883
+ } else if (check.kind === "min") {
1884
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1885
+ if (tooSmall) {
1886
+ ctx = this._getOrReturnCtx(input, ctx);
1887
+ addIssueToContext(ctx, {
1888
+ code: ZodIssueCode.too_small,
1889
+ minimum: check.value,
1890
+ type: "number",
1891
+ inclusive: check.inclusive,
1892
+ exact: false,
1893
+ message: check.message
1894
+ });
1895
+ status.dirty();
1896
+ }
1897
+ } else if (check.kind === "max") {
1898
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1899
+ if (tooBig) {
1900
+ ctx = this._getOrReturnCtx(input, ctx);
1901
+ addIssueToContext(ctx, {
1902
+ code: ZodIssueCode.too_big,
1903
+ maximum: check.value,
1904
+ type: "number",
1905
+ inclusive: check.inclusive,
1906
+ exact: false,
1907
+ message: check.message
1908
+ });
1909
+ status.dirty();
1910
+ }
1911
+ } else if (check.kind === "multipleOf") {
1912
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
1913
+ ctx = this._getOrReturnCtx(input, ctx);
1914
+ addIssueToContext(ctx, {
1915
+ code: ZodIssueCode.not_multiple_of,
1916
+ multipleOf: check.value,
1917
+ message: check.message
1918
+ });
1919
+ status.dirty();
1920
+ }
1921
+ } else if (check.kind === "finite") {
1922
+ if (!Number.isFinite(input.data)) {
1923
+ ctx = this._getOrReturnCtx(input, ctx);
1924
+ addIssueToContext(ctx, {
1925
+ code: ZodIssueCode.not_finite,
1926
+ message: check.message
1927
+ });
1928
+ status.dirty();
1929
+ }
1930
+ } else {
1931
+ util.assertNever(check);
1932
+ }
1933
+ }
1934
+ return { status: status.value, value: input.data };
1935
+ }
1936
+ gte(value, message) {
1937
+ return this.setLimit("min", value, true, errorUtil.toString(message));
1938
+ }
1939
+ gt(value, message) {
1940
+ return this.setLimit("min", value, false, errorUtil.toString(message));
1941
+ }
1942
+ lte(value, message) {
1943
+ return this.setLimit("max", value, true, errorUtil.toString(message));
1944
+ }
1945
+ lt(value, message) {
1946
+ return this.setLimit("max", value, false, errorUtil.toString(message));
1947
+ }
1948
+ setLimit(kind, value, inclusive, message) {
1949
+ return new _ZodNumber({
1950
+ ...this._def,
1951
+ checks: [
1952
+ ...this._def.checks,
1953
+ {
1954
+ kind,
1955
+ value,
1956
+ inclusive,
1957
+ message: errorUtil.toString(message)
1958
+ }
1959
+ ]
1960
+ });
1961
+ }
1962
+ _addCheck(check) {
1963
+ return new _ZodNumber({
1964
+ ...this._def,
1965
+ checks: [...this._def.checks, check]
1966
+ });
1967
+ }
1968
+ int(message) {
1969
+ return this._addCheck({
1970
+ kind: "int",
1971
+ message: errorUtil.toString(message)
1972
+ });
1973
+ }
1974
+ positive(message) {
1975
+ return this._addCheck({
1976
+ kind: "min",
1977
+ value: 0,
1978
+ inclusive: false,
1979
+ message: errorUtil.toString(message)
1980
+ });
1981
+ }
1982
+ negative(message) {
1983
+ return this._addCheck({
1984
+ kind: "max",
1985
+ value: 0,
1986
+ inclusive: false,
1987
+ message: errorUtil.toString(message)
1988
+ });
1989
+ }
1990
+ nonpositive(message) {
1991
+ return this._addCheck({
1992
+ kind: "max",
1993
+ value: 0,
1994
+ inclusive: true,
1995
+ message: errorUtil.toString(message)
1996
+ });
1997
+ }
1998
+ nonnegative(message) {
1999
+ return this._addCheck({
2000
+ kind: "min",
2001
+ value: 0,
2002
+ inclusive: true,
2003
+ message: errorUtil.toString(message)
2004
+ });
2005
+ }
2006
+ multipleOf(value, message) {
2007
+ return this._addCheck({
2008
+ kind: "multipleOf",
2009
+ value,
2010
+ message: errorUtil.toString(message)
2011
+ });
2012
+ }
2013
+ finite(message) {
2014
+ return this._addCheck({
2015
+ kind: "finite",
2016
+ message: errorUtil.toString(message)
2017
+ });
2018
+ }
2019
+ safe(message) {
2020
+ return this._addCheck({
2021
+ kind: "min",
2022
+ inclusive: true,
2023
+ value: Number.MIN_SAFE_INTEGER,
2024
+ message: errorUtil.toString(message)
2025
+ })._addCheck({
2026
+ kind: "max",
2027
+ inclusive: true,
2028
+ value: Number.MAX_SAFE_INTEGER,
2029
+ message: errorUtil.toString(message)
2030
+ });
2031
+ }
2032
+ get minValue() {
2033
+ let min = null;
2034
+ for (const ch of this._def.checks) {
2035
+ if (ch.kind === "min") {
2036
+ if (min === null || ch.value > min)
2037
+ min = ch.value;
2038
+ }
2039
+ }
2040
+ return min;
2041
+ }
2042
+ get maxValue() {
2043
+ let max = null;
2044
+ for (const ch of this._def.checks) {
2045
+ if (ch.kind === "max") {
2046
+ if (max === null || ch.value < max)
2047
+ max = ch.value;
2048
+ }
2049
+ }
2050
+ return max;
2051
+ }
2052
+ get isInt() {
2053
+ return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
2054
+ }
2055
+ get isFinite() {
2056
+ let max = null;
2057
+ let min = null;
2058
+ for (const ch of this._def.checks) {
2059
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
2060
+ return true;
2061
+ } else if (ch.kind === "min") {
2062
+ if (min === null || ch.value > min)
2063
+ min = ch.value;
2064
+ } else if (ch.kind === "max") {
2065
+ if (max === null || ch.value < max)
2066
+ max = ch.value;
2067
+ }
2068
+ }
2069
+ return Number.isFinite(min) && Number.isFinite(max);
2070
+ }
2071
+ };
2072
+ ZodNumber.create = (params) => {
2073
+ return new ZodNumber({
2074
+ checks: [],
2075
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
2076
+ coerce: params?.coerce || false,
2077
+ ...processCreateParams(params)
2078
+ });
2079
+ };
2080
+ var ZodBigInt = class _ZodBigInt extends ZodType {
2081
+ constructor() {
2082
+ super(...arguments);
2083
+ this.min = this.gte;
2084
+ this.max = this.lte;
2085
+ }
2086
+ _parse(input) {
2087
+ if (this._def.coerce) {
2088
+ try {
2089
+ input.data = BigInt(input.data);
2090
+ } catch {
2091
+ return this._getInvalidInput(input);
2092
+ }
2093
+ }
2094
+ const parsedType = this._getType(input);
2095
+ if (parsedType !== ZodParsedType.bigint) {
2096
+ return this._getInvalidInput(input);
2097
+ }
2098
+ let ctx = void 0;
2099
+ const status = new ParseStatus();
2100
+ for (const check of this._def.checks) {
2101
+ if (check.kind === "min") {
2102
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
2103
+ if (tooSmall) {
2104
+ ctx = this._getOrReturnCtx(input, ctx);
2105
+ addIssueToContext(ctx, {
2106
+ code: ZodIssueCode.too_small,
2107
+ type: "bigint",
2108
+ minimum: check.value,
2109
+ inclusive: check.inclusive,
2110
+ message: check.message
2111
+ });
2112
+ status.dirty();
2113
+ }
2114
+ } else if (check.kind === "max") {
2115
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
2116
+ if (tooBig) {
2117
+ ctx = this._getOrReturnCtx(input, ctx);
2118
+ addIssueToContext(ctx, {
2119
+ code: ZodIssueCode.too_big,
2120
+ type: "bigint",
2121
+ maximum: check.value,
2122
+ inclusive: check.inclusive,
2123
+ message: check.message
2124
+ });
2125
+ status.dirty();
2126
+ }
2127
+ } else if (check.kind === "multipleOf") {
2128
+ if (input.data % check.value !== BigInt(0)) {
2129
+ ctx = this._getOrReturnCtx(input, ctx);
2130
+ addIssueToContext(ctx, {
2131
+ code: ZodIssueCode.not_multiple_of,
2132
+ multipleOf: check.value,
2133
+ message: check.message
2134
+ });
2135
+ status.dirty();
2136
+ }
2137
+ } else {
2138
+ util.assertNever(check);
2139
+ }
2140
+ }
2141
+ return { status: status.value, value: input.data };
2142
+ }
2143
+ _getInvalidInput(input) {
2144
+ const ctx = this._getOrReturnCtx(input);
2145
+ addIssueToContext(ctx, {
2146
+ code: ZodIssueCode.invalid_type,
2147
+ expected: ZodParsedType.bigint,
2148
+ received: ctx.parsedType
2149
+ });
2150
+ return INVALID;
2151
+ }
2152
+ gte(value, message) {
2153
+ return this.setLimit("min", value, true, errorUtil.toString(message));
2154
+ }
2155
+ gt(value, message) {
2156
+ return this.setLimit("min", value, false, errorUtil.toString(message));
2157
+ }
2158
+ lte(value, message) {
2159
+ return this.setLimit("max", value, true, errorUtil.toString(message));
2160
+ }
2161
+ lt(value, message) {
2162
+ return this.setLimit("max", value, false, errorUtil.toString(message));
2163
+ }
2164
+ setLimit(kind, value, inclusive, message) {
2165
+ return new _ZodBigInt({
2166
+ ...this._def,
2167
+ checks: [
2168
+ ...this._def.checks,
2169
+ {
2170
+ kind,
2171
+ value,
2172
+ inclusive,
2173
+ message: errorUtil.toString(message)
2174
+ }
2175
+ ]
2176
+ });
2177
+ }
2178
+ _addCheck(check) {
2179
+ return new _ZodBigInt({
2180
+ ...this._def,
2181
+ checks: [...this._def.checks, check]
2182
+ });
2183
+ }
2184
+ positive(message) {
2185
+ return this._addCheck({
2186
+ kind: "min",
2187
+ value: BigInt(0),
2188
+ inclusive: false,
2189
+ message: errorUtil.toString(message)
2190
+ });
2191
+ }
2192
+ negative(message) {
2193
+ return this._addCheck({
2194
+ kind: "max",
2195
+ value: BigInt(0),
2196
+ inclusive: false,
2197
+ message: errorUtil.toString(message)
2198
+ });
2199
+ }
2200
+ nonpositive(message) {
2201
+ return this._addCheck({
2202
+ kind: "max",
2203
+ value: BigInt(0),
2204
+ inclusive: true,
2205
+ message: errorUtil.toString(message)
2206
+ });
2207
+ }
2208
+ nonnegative(message) {
2209
+ return this._addCheck({
2210
+ kind: "min",
2211
+ value: BigInt(0),
2212
+ inclusive: true,
2213
+ message: errorUtil.toString(message)
2214
+ });
2215
+ }
2216
+ multipleOf(value, message) {
2217
+ return this._addCheck({
2218
+ kind: "multipleOf",
2219
+ value,
2220
+ message: errorUtil.toString(message)
2221
+ });
2222
+ }
2223
+ get minValue() {
2224
+ let min = null;
2225
+ for (const ch of this._def.checks) {
2226
+ if (ch.kind === "min") {
2227
+ if (min === null || ch.value > min)
2228
+ min = ch.value;
2229
+ }
2230
+ }
2231
+ return min;
2232
+ }
2233
+ get maxValue() {
2234
+ let max = null;
2235
+ for (const ch of this._def.checks) {
2236
+ if (ch.kind === "max") {
2237
+ if (max === null || ch.value < max)
2238
+ max = ch.value;
2239
+ }
2240
+ }
2241
+ return max;
2242
+ }
2243
+ };
2244
+ ZodBigInt.create = (params) => {
2245
+ return new ZodBigInt({
2246
+ checks: [],
2247
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
2248
+ coerce: params?.coerce ?? false,
2249
+ ...processCreateParams(params)
2250
+ });
2251
+ };
2252
+ var ZodBoolean = class extends ZodType {
2253
+ _parse(input) {
2254
+ if (this._def.coerce) {
2255
+ input.data = Boolean(input.data);
2256
+ }
2257
+ const parsedType = this._getType(input);
2258
+ if (parsedType !== ZodParsedType.boolean) {
2259
+ const ctx = this._getOrReturnCtx(input);
2260
+ addIssueToContext(ctx, {
2261
+ code: ZodIssueCode.invalid_type,
2262
+ expected: ZodParsedType.boolean,
2263
+ received: ctx.parsedType
2264
+ });
2265
+ return INVALID;
2266
+ }
2267
+ return OK(input.data);
2268
+ }
2269
+ };
2270
+ ZodBoolean.create = (params) => {
2271
+ return new ZodBoolean({
2272
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
2273
+ coerce: params?.coerce || false,
2274
+ ...processCreateParams(params)
2275
+ });
2276
+ };
2277
+ var ZodDate = class _ZodDate extends ZodType {
2278
+ _parse(input) {
2279
+ if (this._def.coerce) {
2280
+ input.data = new Date(input.data);
2281
+ }
2282
+ const parsedType = this._getType(input);
2283
+ if (parsedType !== ZodParsedType.date) {
2284
+ const ctx2 = this._getOrReturnCtx(input);
2285
+ addIssueToContext(ctx2, {
2286
+ code: ZodIssueCode.invalid_type,
2287
+ expected: ZodParsedType.date,
2288
+ received: ctx2.parsedType
2289
+ });
2290
+ return INVALID;
2291
+ }
2292
+ if (Number.isNaN(input.data.getTime())) {
2293
+ const ctx2 = this._getOrReturnCtx(input);
2294
+ addIssueToContext(ctx2, {
2295
+ code: ZodIssueCode.invalid_date
2296
+ });
2297
+ return INVALID;
2298
+ }
2299
+ const status = new ParseStatus();
2300
+ let ctx = void 0;
2301
+ for (const check of this._def.checks) {
2302
+ if (check.kind === "min") {
2303
+ if (input.data.getTime() < check.value) {
2304
+ ctx = this._getOrReturnCtx(input, ctx);
2305
+ addIssueToContext(ctx, {
2306
+ code: ZodIssueCode.too_small,
2307
+ message: check.message,
2308
+ inclusive: true,
2309
+ exact: false,
2310
+ minimum: check.value,
2311
+ type: "date"
2312
+ });
2313
+ status.dirty();
2314
+ }
2315
+ } else if (check.kind === "max") {
2316
+ if (input.data.getTime() > check.value) {
2317
+ ctx = this._getOrReturnCtx(input, ctx);
2318
+ addIssueToContext(ctx, {
2319
+ code: ZodIssueCode.too_big,
2320
+ message: check.message,
2321
+ inclusive: true,
2322
+ exact: false,
2323
+ maximum: check.value,
2324
+ type: "date"
2325
+ });
2326
+ status.dirty();
2327
+ }
2328
+ } else {
2329
+ util.assertNever(check);
2330
+ }
2331
+ }
2332
+ return {
2333
+ status: status.value,
2334
+ value: new Date(input.data.getTime())
2335
+ };
2336
+ }
2337
+ _addCheck(check) {
2338
+ return new _ZodDate({
2339
+ ...this._def,
2340
+ checks: [...this._def.checks, check]
2341
+ });
2342
+ }
2343
+ min(minDate, message) {
2344
+ return this._addCheck({
2345
+ kind: "min",
2346
+ value: minDate.getTime(),
2347
+ message: errorUtil.toString(message)
2348
+ });
2349
+ }
2350
+ max(maxDate, message) {
2351
+ return this._addCheck({
2352
+ kind: "max",
2353
+ value: maxDate.getTime(),
2354
+ message: errorUtil.toString(message)
2355
+ });
2356
+ }
2357
+ get minDate() {
2358
+ let min = null;
2359
+ for (const ch of this._def.checks) {
2360
+ if (ch.kind === "min") {
2361
+ if (min === null || ch.value > min)
2362
+ min = ch.value;
2363
+ }
2364
+ }
2365
+ return min != null ? new Date(min) : null;
2366
+ }
2367
+ get maxDate() {
2368
+ let max = null;
2369
+ for (const ch of this._def.checks) {
2370
+ if (ch.kind === "max") {
2371
+ if (max === null || ch.value < max)
2372
+ max = ch.value;
2373
+ }
2374
+ }
2375
+ return max != null ? new Date(max) : null;
2376
+ }
2377
+ };
2378
+ ZodDate.create = (params) => {
2379
+ return new ZodDate({
2380
+ checks: [],
2381
+ coerce: params?.coerce || false,
2382
+ typeName: ZodFirstPartyTypeKind.ZodDate,
2383
+ ...processCreateParams(params)
2384
+ });
2385
+ };
2386
+ var ZodSymbol = class extends ZodType {
2387
+ _parse(input) {
2388
+ const parsedType = this._getType(input);
2389
+ if (parsedType !== ZodParsedType.symbol) {
2390
+ const ctx = this._getOrReturnCtx(input);
2391
+ addIssueToContext(ctx, {
2392
+ code: ZodIssueCode.invalid_type,
2393
+ expected: ZodParsedType.symbol,
2394
+ received: ctx.parsedType
2395
+ });
2396
+ return INVALID;
2397
+ }
2398
+ return OK(input.data);
2399
+ }
2400
+ };
2401
+ ZodSymbol.create = (params) => {
2402
+ return new ZodSymbol({
2403
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
2404
+ ...processCreateParams(params)
2405
+ });
2406
+ };
2407
+ var ZodUndefined = class extends ZodType {
2408
+ _parse(input) {
2409
+ const parsedType = this._getType(input);
2410
+ if (parsedType !== ZodParsedType.undefined) {
2411
+ const ctx = this._getOrReturnCtx(input);
2412
+ addIssueToContext(ctx, {
2413
+ code: ZodIssueCode.invalid_type,
2414
+ expected: ZodParsedType.undefined,
2415
+ received: ctx.parsedType
2416
+ });
2417
+ return INVALID;
2418
+ }
2419
+ return OK(input.data);
2420
+ }
2421
+ };
2422
+ ZodUndefined.create = (params) => {
2423
+ return new ZodUndefined({
2424
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
2425
+ ...processCreateParams(params)
2426
+ });
2427
+ };
2428
+ var ZodNull = class extends ZodType {
2429
+ _parse(input) {
2430
+ const parsedType = this._getType(input);
2431
+ if (parsedType !== ZodParsedType.null) {
2432
+ const ctx = this._getOrReturnCtx(input);
2433
+ addIssueToContext(ctx, {
2434
+ code: ZodIssueCode.invalid_type,
2435
+ expected: ZodParsedType.null,
2436
+ received: ctx.parsedType
2437
+ });
2438
+ return INVALID;
2439
+ }
2440
+ return OK(input.data);
2441
+ }
2442
+ };
2443
+ ZodNull.create = (params) => {
2444
+ return new ZodNull({
2445
+ typeName: ZodFirstPartyTypeKind.ZodNull,
2446
+ ...processCreateParams(params)
2447
+ });
2448
+ };
2449
+ var ZodAny = class extends ZodType {
2450
+ constructor() {
2451
+ super(...arguments);
2452
+ this._any = true;
2453
+ }
2454
+ _parse(input) {
2455
+ return OK(input.data);
2456
+ }
2457
+ };
2458
+ ZodAny.create = (params) => {
2459
+ return new ZodAny({
2460
+ typeName: ZodFirstPartyTypeKind.ZodAny,
2461
+ ...processCreateParams(params)
2462
+ });
2463
+ };
2464
+ var ZodUnknown = class extends ZodType {
2465
+ constructor() {
2466
+ super(...arguments);
2467
+ this._unknown = true;
2468
+ }
2469
+ _parse(input) {
2470
+ return OK(input.data);
2471
+ }
2472
+ };
2473
+ ZodUnknown.create = (params) => {
2474
+ return new ZodUnknown({
2475
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
2476
+ ...processCreateParams(params)
2477
+ });
2478
+ };
2479
+ var ZodNever = class extends ZodType {
2480
+ _parse(input) {
2481
+ const ctx = this._getOrReturnCtx(input);
2482
+ addIssueToContext(ctx, {
2483
+ code: ZodIssueCode.invalid_type,
2484
+ expected: ZodParsedType.never,
2485
+ received: ctx.parsedType
2486
+ });
2487
+ return INVALID;
2488
+ }
2489
+ };
2490
+ ZodNever.create = (params) => {
2491
+ return new ZodNever({
2492
+ typeName: ZodFirstPartyTypeKind.ZodNever,
2493
+ ...processCreateParams(params)
2494
+ });
2495
+ };
2496
+ var ZodVoid = class extends ZodType {
2497
+ _parse(input) {
2498
+ const parsedType = this._getType(input);
2499
+ if (parsedType !== ZodParsedType.undefined) {
2500
+ const ctx = this._getOrReturnCtx(input);
2501
+ addIssueToContext(ctx, {
2502
+ code: ZodIssueCode.invalid_type,
2503
+ expected: ZodParsedType.void,
2504
+ received: ctx.parsedType
2505
+ });
2506
+ return INVALID;
2507
+ }
2508
+ return OK(input.data);
2509
+ }
2510
+ };
2511
+ ZodVoid.create = (params) => {
2512
+ return new ZodVoid({
2513
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
2514
+ ...processCreateParams(params)
2515
+ });
2516
+ };
2517
+ var ZodArray = class _ZodArray extends ZodType {
2518
+ _parse(input) {
2519
+ const { ctx, status } = this._processInputParams(input);
2520
+ const def = this._def;
2521
+ if (ctx.parsedType !== ZodParsedType.array) {
2522
+ addIssueToContext(ctx, {
2523
+ code: ZodIssueCode.invalid_type,
2524
+ expected: ZodParsedType.array,
2525
+ received: ctx.parsedType
2526
+ });
2527
+ return INVALID;
2528
+ }
2529
+ if (def.exactLength !== null) {
2530
+ const tooBig = ctx.data.length > def.exactLength.value;
2531
+ const tooSmall = ctx.data.length < def.exactLength.value;
2532
+ if (tooBig || tooSmall) {
2533
+ addIssueToContext(ctx, {
2534
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
2535
+ minimum: tooSmall ? def.exactLength.value : void 0,
2536
+ maximum: tooBig ? def.exactLength.value : void 0,
2537
+ type: "array",
2538
+ inclusive: true,
2539
+ exact: true,
2540
+ message: def.exactLength.message
2541
+ });
2542
+ status.dirty();
2543
+ }
2544
+ }
2545
+ if (def.minLength !== null) {
2546
+ if (ctx.data.length < def.minLength.value) {
2547
+ addIssueToContext(ctx, {
2548
+ code: ZodIssueCode.too_small,
2549
+ minimum: def.minLength.value,
2550
+ type: "array",
2551
+ inclusive: true,
2552
+ exact: false,
2553
+ message: def.minLength.message
2554
+ });
2555
+ status.dirty();
2556
+ }
2557
+ }
2558
+ if (def.maxLength !== null) {
2559
+ if (ctx.data.length > def.maxLength.value) {
2560
+ addIssueToContext(ctx, {
2561
+ code: ZodIssueCode.too_big,
2562
+ maximum: def.maxLength.value,
2563
+ type: "array",
2564
+ inclusive: true,
2565
+ exact: false,
2566
+ message: def.maxLength.message
2567
+ });
2568
+ status.dirty();
2569
+ }
2570
+ }
2571
+ if (ctx.common.async) {
2572
+ return Promise.all([...ctx.data].map((item, i) => {
2573
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2574
+ })).then((result2) => {
2575
+ return ParseStatus.mergeArray(status, result2);
2576
+ });
2577
+ }
2578
+ const result = [...ctx.data].map((item, i) => {
2579
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2580
+ });
2581
+ return ParseStatus.mergeArray(status, result);
2582
+ }
2583
+ get element() {
2584
+ return this._def.type;
2585
+ }
2586
+ min(minLength, message) {
2587
+ return new _ZodArray({
2588
+ ...this._def,
2589
+ minLength: { value: minLength, message: errorUtil.toString(message) }
2590
+ });
2591
+ }
2592
+ max(maxLength, message) {
2593
+ return new _ZodArray({
2594
+ ...this._def,
2595
+ maxLength: { value: maxLength, message: errorUtil.toString(message) }
2596
+ });
2597
+ }
2598
+ length(len, message) {
2599
+ return new _ZodArray({
2600
+ ...this._def,
2601
+ exactLength: { value: len, message: errorUtil.toString(message) }
2602
+ });
2603
+ }
2604
+ nonempty(message) {
2605
+ return this.min(1, message);
2606
+ }
2607
+ };
2608
+ ZodArray.create = (schema, params) => {
2609
+ return new ZodArray({
2610
+ type: schema,
2611
+ minLength: null,
2612
+ maxLength: null,
2613
+ exactLength: null,
2614
+ typeName: ZodFirstPartyTypeKind.ZodArray,
2615
+ ...processCreateParams(params)
2616
+ });
2617
+ };
2618
+ function deepPartialify(schema) {
2619
+ if (schema instanceof ZodObject) {
2620
+ const newShape = {};
2621
+ for (const key in schema.shape) {
2622
+ const fieldSchema = schema.shape[key];
2623
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
2624
+ }
2625
+ return new ZodObject({
2626
+ ...schema._def,
2627
+ shape: () => newShape
2628
+ });
2629
+ } else if (schema instanceof ZodArray) {
2630
+ return new ZodArray({
2631
+ ...schema._def,
2632
+ type: deepPartialify(schema.element)
2633
+ });
2634
+ } else if (schema instanceof ZodOptional) {
2635
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
2636
+ } else if (schema instanceof ZodNullable) {
2637
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
2638
+ } else if (schema instanceof ZodTuple) {
2639
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
2640
+ } else {
2641
+ return schema;
2642
+ }
2643
+ }
2644
+ var ZodObject = class _ZodObject extends ZodType {
2645
+ constructor() {
2646
+ super(...arguments);
2647
+ this._cached = null;
2648
+ this.nonstrict = this.passthrough;
2649
+ this.augment = this.extend;
2650
+ }
2651
+ _getCached() {
2652
+ if (this._cached !== null)
2653
+ return this._cached;
2654
+ const shape = this._def.shape();
2655
+ const keys = util.objectKeys(shape);
2656
+ this._cached = { shape, keys };
2657
+ return this._cached;
2658
+ }
2659
+ _parse(input) {
2660
+ const parsedType = this._getType(input);
2661
+ if (parsedType !== ZodParsedType.object) {
2662
+ const ctx2 = this._getOrReturnCtx(input);
2663
+ addIssueToContext(ctx2, {
2664
+ code: ZodIssueCode.invalid_type,
2665
+ expected: ZodParsedType.object,
2666
+ received: ctx2.parsedType
2667
+ });
2668
+ return INVALID;
2669
+ }
2670
+ const { status, ctx } = this._processInputParams(input);
2671
+ const { shape, keys: shapeKeys } = this._getCached();
2672
+ const extraKeys = [];
2673
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
2674
+ for (const key in ctx.data) {
2675
+ if (!shapeKeys.includes(key)) {
2676
+ extraKeys.push(key);
2677
+ }
2678
+ }
2679
+ }
2680
+ const pairs = [];
2681
+ for (const key of shapeKeys) {
2682
+ const keyValidator = shape[key];
2683
+ const value = ctx.data[key];
2684
+ pairs.push({
2685
+ key: { status: "valid", value: key },
2686
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
2687
+ alwaysSet: key in ctx.data
2688
+ });
2689
+ }
2690
+ if (this._def.catchall instanceof ZodNever) {
2691
+ const unknownKeys = this._def.unknownKeys;
2692
+ if (unknownKeys === "passthrough") {
2693
+ for (const key of extraKeys) {
2694
+ pairs.push({
2695
+ key: { status: "valid", value: key },
2696
+ value: { status: "valid", value: ctx.data[key] }
2697
+ });
2698
+ }
2699
+ } else if (unknownKeys === "strict") {
2700
+ if (extraKeys.length > 0) {
2701
+ addIssueToContext(ctx, {
2702
+ code: ZodIssueCode.unrecognized_keys,
2703
+ keys: extraKeys
2704
+ });
2705
+ status.dirty();
2706
+ }
2707
+ } else if (unknownKeys === "strip") ; else {
2708
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
2709
+ }
2710
+ } else {
2711
+ const catchall = this._def.catchall;
2712
+ for (const key of extraKeys) {
2713
+ const value = ctx.data[key];
2714
+ pairs.push({
2715
+ key: { status: "valid", value: key },
2716
+ value: catchall._parse(
2717
+ new ParseInputLazyPath(ctx, value, ctx.path, key)
2718
+ //, ctx.child(key), value, getParsedType(value)
2719
+ ),
2720
+ alwaysSet: key in ctx.data
2721
+ });
2722
+ }
2723
+ }
2724
+ if (ctx.common.async) {
2725
+ return Promise.resolve().then(async () => {
2726
+ const syncPairs = [];
2727
+ for (const pair of pairs) {
2728
+ const key = await pair.key;
2729
+ const value = await pair.value;
2730
+ syncPairs.push({
2731
+ key,
2732
+ value,
2733
+ alwaysSet: pair.alwaysSet
2734
+ });
2735
+ }
2736
+ return syncPairs;
2737
+ }).then((syncPairs) => {
2738
+ return ParseStatus.mergeObjectSync(status, syncPairs);
2739
+ });
2740
+ } else {
2741
+ return ParseStatus.mergeObjectSync(status, pairs);
2742
+ }
2743
+ }
2744
+ get shape() {
2745
+ return this._def.shape();
2746
+ }
2747
+ strict(message) {
2748
+ errorUtil.errToObj;
2749
+ return new _ZodObject({
2750
+ ...this._def,
2751
+ unknownKeys: "strict",
2752
+ ...message !== void 0 ? {
2753
+ errorMap: (issue, ctx) => {
2754
+ const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
2755
+ if (issue.code === "unrecognized_keys")
2756
+ return {
2757
+ message: errorUtil.errToObj(message).message ?? defaultError
2758
+ };
2759
+ return {
2760
+ message: defaultError
2761
+ };
2762
+ }
2763
+ } : {}
2764
+ });
2765
+ }
2766
+ strip() {
2767
+ return new _ZodObject({
2768
+ ...this._def,
2769
+ unknownKeys: "strip"
2770
+ });
2771
+ }
2772
+ passthrough() {
2773
+ return new _ZodObject({
2774
+ ...this._def,
2775
+ unknownKeys: "passthrough"
2776
+ });
2777
+ }
2778
+ // const AugmentFactory =
2779
+ // <Def extends ZodObjectDef>(def: Def) =>
2780
+ // <Augmentation extends ZodRawShape>(
2781
+ // augmentation: Augmentation
2782
+ // ): ZodObject<
2783
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
2784
+ // Def["unknownKeys"],
2785
+ // Def["catchall"]
2786
+ // > => {
2787
+ // return new ZodObject({
2788
+ // ...def,
2789
+ // shape: () => ({
2790
+ // ...def.shape(),
2791
+ // ...augmentation,
2792
+ // }),
2793
+ // }) as any;
2794
+ // };
2795
+ extend(augmentation) {
2796
+ return new _ZodObject({
2797
+ ...this._def,
2798
+ shape: () => ({
2799
+ ...this._def.shape(),
2800
+ ...augmentation
2801
+ })
2802
+ });
2803
+ }
2804
+ /**
2805
+ * Prior to zod@1.0.12 there was a bug in the
2806
+ * inferred type of merged objects. Please
2807
+ * upgrade if you are experiencing issues.
2808
+ */
2809
+ merge(merging) {
2810
+ const merged = new _ZodObject({
2811
+ unknownKeys: merging._def.unknownKeys,
2812
+ catchall: merging._def.catchall,
2813
+ shape: () => ({
2814
+ ...this._def.shape(),
2815
+ ...merging._def.shape()
2816
+ }),
2817
+ typeName: ZodFirstPartyTypeKind.ZodObject
2818
+ });
2819
+ return merged;
2820
+ }
2821
+ // merge<
2822
+ // Incoming extends AnyZodObject,
2823
+ // Augmentation extends Incoming["shape"],
2824
+ // NewOutput extends {
2825
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
2826
+ // ? Augmentation[k]["_output"]
2827
+ // : k extends keyof Output
2828
+ // ? Output[k]
2829
+ // : never;
2830
+ // },
2831
+ // NewInput extends {
2832
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
2833
+ // ? Augmentation[k]["_input"]
2834
+ // : k extends keyof Input
2835
+ // ? Input[k]
2836
+ // : never;
2837
+ // }
2838
+ // >(
2839
+ // merging: Incoming
2840
+ // ): ZodObject<
2841
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2842
+ // Incoming["_def"]["unknownKeys"],
2843
+ // Incoming["_def"]["catchall"],
2844
+ // NewOutput,
2845
+ // NewInput
2846
+ // > {
2847
+ // const merged: any = new ZodObject({
2848
+ // unknownKeys: merging._def.unknownKeys,
2849
+ // catchall: merging._def.catchall,
2850
+ // shape: () =>
2851
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2852
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
2853
+ // }) as any;
2854
+ // return merged;
2855
+ // }
2856
+ setKey(key, schema) {
2857
+ return this.augment({ [key]: schema });
2858
+ }
2859
+ // merge<Incoming extends AnyZodObject>(
2860
+ // merging: Incoming
2861
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
2862
+ // ZodObject<
2863
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2864
+ // Incoming["_def"]["unknownKeys"],
2865
+ // Incoming["_def"]["catchall"]
2866
+ // > {
2867
+ // // const mergedShape = objectUtil.mergeShapes(
2868
+ // // this._def.shape(),
2869
+ // // merging._def.shape()
2870
+ // // );
2871
+ // const merged: any = new ZodObject({
2872
+ // unknownKeys: merging._def.unknownKeys,
2873
+ // catchall: merging._def.catchall,
2874
+ // shape: () =>
2875
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2876
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
2877
+ // }) as any;
2878
+ // return merged;
2879
+ // }
2880
+ catchall(index) {
2881
+ return new _ZodObject({
2882
+ ...this._def,
2883
+ catchall: index
2884
+ });
2885
+ }
2886
+ pick(mask) {
2887
+ const shape = {};
2888
+ for (const key of util.objectKeys(mask)) {
2889
+ if (mask[key] && this.shape[key]) {
2890
+ shape[key] = this.shape[key];
2891
+ }
2892
+ }
2893
+ return new _ZodObject({
2894
+ ...this._def,
2895
+ shape: () => shape
2896
+ });
2897
+ }
2898
+ omit(mask) {
2899
+ const shape = {};
2900
+ for (const key of util.objectKeys(this.shape)) {
2901
+ if (!mask[key]) {
2902
+ shape[key] = this.shape[key];
2903
+ }
2904
+ }
2905
+ return new _ZodObject({
2906
+ ...this._def,
2907
+ shape: () => shape
2908
+ });
2909
+ }
2910
+ /**
2911
+ * @deprecated
2912
+ */
2913
+ deepPartial() {
2914
+ return deepPartialify(this);
2915
+ }
2916
+ partial(mask) {
2917
+ const newShape = {};
2918
+ for (const key of util.objectKeys(this.shape)) {
2919
+ const fieldSchema = this.shape[key];
2920
+ if (mask && !mask[key]) {
2921
+ newShape[key] = fieldSchema;
2922
+ } else {
2923
+ newShape[key] = fieldSchema.optional();
2924
+ }
2925
+ }
2926
+ return new _ZodObject({
2927
+ ...this._def,
2928
+ shape: () => newShape
2929
+ });
2930
+ }
2931
+ required(mask) {
2932
+ const newShape = {};
2933
+ for (const key of util.objectKeys(this.shape)) {
2934
+ if (mask && !mask[key]) {
2935
+ newShape[key] = this.shape[key];
2936
+ } else {
2937
+ const fieldSchema = this.shape[key];
2938
+ let newField = fieldSchema;
2939
+ while (newField instanceof ZodOptional) {
2940
+ newField = newField._def.innerType;
2941
+ }
2942
+ newShape[key] = newField;
2943
+ }
2944
+ }
2945
+ return new _ZodObject({
2946
+ ...this._def,
2947
+ shape: () => newShape
2948
+ });
2949
+ }
2950
+ keyof() {
2951
+ return createZodEnum(util.objectKeys(this.shape));
2952
+ }
2953
+ };
2954
+ ZodObject.create = (shape, params) => {
2955
+ return new ZodObject({
2956
+ shape: () => shape,
2957
+ unknownKeys: "strip",
2958
+ catchall: ZodNever.create(),
2959
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2960
+ ...processCreateParams(params)
2961
+ });
2962
+ };
2963
+ ZodObject.strictCreate = (shape, params) => {
2964
+ return new ZodObject({
2965
+ shape: () => shape,
2966
+ unknownKeys: "strict",
2967
+ catchall: ZodNever.create(),
2968
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2969
+ ...processCreateParams(params)
2970
+ });
2971
+ };
2972
+ ZodObject.lazycreate = (shape, params) => {
2973
+ return new ZodObject({
2974
+ shape,
2975
+ unknownKeys: "strip",
2976
+ catchall: ZodNever.create(),
2977
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2978
+ ...processCreateParams(params)
2979
+ });
2980
+ };
2981
+ var ZodUnion = class extends ZodType {
2982
+ _parse(input) {
2983
+ const { ctx } = this._processInputParams(input);
2984
+ const options = this._def.options;
2985
+ function handleResults(results) {
2986
+ for (const result of results) {
2987
+ if (result.result.status === "valid") {
2988
+ return result.result;
2989
+ }
2990
+ }
2991
+ for (const result of results) {
2992
+ if (result.result.status === "dirty") {
2993
+ ctx.common.issues.push(...result.ctx.common.issues);
2994
+ return result.result;
2995
+ }
2996
+ }
2997
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
2998
+ addIssueToContext(ctx, {
2999
+ code: ZodIssueCode.invalid_union,
3000
+ unionErrors
3001
+ });
3002
+ return INVALID;
3003
+ }
3004
+ if (ctx.common.async) {
3005
+ return Promise.all(options.map(async (option) => {
3006
+ const childCtx = {
3007
+ ...ctx,
3008
+ common: {
3009
+ ...ctx.common,
3010
+ issues: []
3011
+ },
3012
+ parent: null
3013
+ };
3014
+ return {
3015
+ result: await option._parseAsync({
3016
+ data: ctx.data,
3017
+ path: ctx.path,
3018
+ parent: childCtx
3019
+ }),
3020
+ ctx: childCtx
3021
+ };
3022
+ })).then(handleResults);
3023
+ } else {
3024
+ let dirty = void 0;
3025
+ const issues = [];
3026
+ for (const option of options) {
3027
+ const childCtx = {
3028
+ ...ctx,
3029
+ common: {
3030
+ ...ctx.common,
3031
+ issues: []
3032
+ },
3033
+ parent: null
3034
+ };
3035
+ const result = option._parseSync({
3036
+ data: ctx.data,
3037
+ path: ctx.path,
3038
+ parent: childCtx
3039
+ });
3040
+ if (result.status === "valid") {
3041
+ return result;
3042
+ } else if (result.status === "dirty" && !dirty) {
3043
+ dirty = { result, ctx: childCtx };
3044
+ }
3045
+ if (childCtx.common.issues.length) {
3046
+ issues.push(childCtx.common.issues);
3047
+ }
3048
+ }
3049
+ if (dirty) {
3050
+ ctx.common.issues.push(...dirty.ctx.common.issues);
3051
+ return dirty.result;
3052
+ }
3053
+ const unionErrors = issues.map((issues2) => new ZodError(issues2));
3054
+ addIssueToContext(ctx, {
3055
+ code: ZodIssueCode.invalid_union,
3056
+ unionErrors
3057
+ });
3058
+ return INVALID;
3059
+ }
3060
+ }
3061
+ get options() {
3062
+ return this._def.options;
3063
+ }
3064
+ };
3065
+ ZodUnion.create = (types, params) => {
3066
+ return new ZodUnion({
3067
+ options: types,
3068
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
3069
+ ...processCreateParams(params)
3070
+ });
3071
+ };
3072
+ var getDiscriminator = (type) => {
3073
+ if (type instanceof ZodLazy) {
3074
+ return getDiscriminator(type.schema);
3075
+ } else if (type instanceof ZodEffects) {
3076
+ return getDiscriminator(type.innerType());
3077
+ } else if (type instanceof ZodLiteral) {
3078
+ return [type.value];
3079
+ } else if (type instanceof ZodEnum) {
3080
+ return type.options;
3081
+ } else if (type instanceof ZodNativeEnum) {
3082
+ return util.objectValues(type.enum);
3083
+ } else if (type instanceof ZodDefault) {
3084
+ return getDiscriminator(type._def.innerType);
3085
+ } else if (type instanceof ZodUndefined) {
3086
+ return [void 0];
3087
+ } else if (type instanceof ZodNull) {
3088
+ return [null];
3089
+ } else if (type instanceof ZodOptional) {
3090
+ return [void 0, ...getDiscriminator(type.unwrap())];
3091
+ } else if (type instanceof ZodNullable) {
3092
+ return [null, ...getDiscriminator(type.unwrap())];
3093
+ } else if (type instanceof ZodBranded) {
3094
+ return getDiscriminator(type.unwrap());
3095
+ } else if (type instanceof ZodReadonly) {
3096
+ return getDiscriminator(type.unwrap());
3097
+ } else if (type instanceof ZodCatch) {
3098
+ return getDiscriminator(type._def.innerType);
3099
+ } else {
3100
+ return [];
3101
+ }
3102
+ };
3103
+ var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
3104
+ _parse(input) {
3105
+ const { ctx } = this._processInputParams(input);
3106
+ if (ctx.parsedType !== ZodParsedType.object) {
3107
+ addIssueToContext(ctx, {
3108
+ code: ZodIssueCode.invalid_type,
3109
+ expected: ZodParsedType.object,
3110
+ received: ctx.parsedType
3111
+ });
3112
+ return INVALID;
3113
+ }
3114
+ const discriminator = this.discriminator;
3115
+ const discriminatorValue = ctx.data[discriminator];
3116
+ const option = this.optionsMap.get(discriminatorValue);
3117
+ if (!option) {
3118
+ addIssueToContext(ctx, {
3119
+ code: ZodIssueCode.invalid_union_discriminator,
3120
+ options: Array.from(this.optionsMap.keys()),
3121
+ path: [discriminator]
3122
+ });
3123
+ return INVALID;
3124
+ }
3125
+ if (ctx.common.async) {
3126
+ return option._parseAsync({
3127
+ data: ctx.data,
3128
+ path: ctx.path,
3129
+ parent: ctx
3130
+ });
3131
+ } else {
3132
+ return option._parseSync({
3133
+ data: ctx.data,
3134
+ path: ctx.path,
3135
+ parent: ctx
3136
+ });
3137
+ }
3138
+ }
3139
+ get discriminator() {
3140
+ return this._def.discriminator;
3141
+ }
3142
+ get options() {
3143
+ return this._def.options;
3144
+ }
3145
+ get optionsMap() {
3146
+ return this._def.optionsMap;
3147
+ }
3148
+ /**
3149
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
3150
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
3151
+ * have a different value for each object in the union.
3152
+ * @param discriminator the name of the discriminator property
3153
+ * @param types an array of object schemas
3154
+ * @param params
3155
+ */
3156
+ static create(discriminator, options, params) {
3157
+ const optionsMap = /* @__PURE__ */ new Map();
3158
+ for (const type of options) {
3159
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
3160
+ if (!discriminatorValues.length) {
3161
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
3162
+ }
3163
+ for (const value of discriminatorValues) {
3164
+ if (optionsMap.has(value)) {
3165
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
3166
+ }
3167
+ optionsMap.set(value, type);
3168
+ }
3169
+ }
3170
+ return new _ZodDiscriminatedUnion({
3171
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
3172
+ discriminator,
3173
+ options,
3174
+ optionsMap,
3175
+ ...processCreateParams(params)
3176
+ });
3177
+ }
3178
+ };
3179
+ function mergeValues(a, b) {
3180
+ const aType = getParsedType(a);
3181
+ const bType = getParsedType(b);
3182
+ if (a === b) {
3183
+ return { valid: true, data: a };
3184
+ } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
3185
+ const bKeys = util.objectKeys(b);
3186
+ const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
3187
+ const newObj = { ...a, ...b };
3188
+ for (const key of sharedKeys) {
3189
+ const sharedValue = mergeValues(a[key], b[key]);
3190
+ if (!sharedValue.valid) {
3191
+ return { valid: false };
3192
+ }
3193
+ newObj[key] = sharedValue.data;
3194
+ }
3195
+ return { valid: true, data: newObj };
3196
+ } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
3197
+ if (a.length !== b.length) {
3198
+ return { valid: false };
3199
+ }
3200
+ const newArray = [];
3201
+ for (let index = 0; index < a.length; index++) {
3202
+ const itemA = a[index];
3203
+ const itemB = b[index];
3204
+ const sharedValue = mergeValues(itemA, itemB);
3205
+ if (!sharedValue.valid) {
3206
+ return { valid: false };
3207
+ }
3208
+ newArray.push(sharedValue.data);
3209
+ }
3210
+ return { valid: true, data: newArray };
3211
+ } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
3212
+ return { valid: true, data: a };
3213
+ } else {
3214
+ return { valid: false };
3215
+ }
3216
+ }
3217
+ var ZodIntersection = class extends ZodType {
3218
+ _parse(input) {
3219
+ const { status, ctx } = this._processInputParams(input);
3220
+ const handleParsed = (parsedLeft, parsedRight) => {
3221
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
3222
+ return INVALID;
3223
+ }
3224
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
3225
+ if (!merged.valid) {
3226
+ addIssueToContext(ctx, {
3227
+ code: ZodIssueCode.invalid_intersection_types
3228
+ });
3229
+ return INVALID;
3230
+ }
3231
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
3232
+ status.dirty();
3233
+ }
3234
+ return { status: status.value, value: merged.data };
3235
+ };
3236
+ if (ctx.common.async) {
3237
+ return Promise.all([
3238
+ this._def.left._parseAsync({
3239
+ data: ctx.data,
3240
+ path: ctx.path,
3241
+ parent: ctx
3242
+ }),
3243
+ this._def.right._parseAsync({
3244
+ data: ctx.data,
3245
+ path: ctx.path,
3246
+ parent: ctx
3247
+ })
3248
+ ]).then(([left, right]) => handleParsed(left, right));
3249
+ } else {
3250
+ return handleParsed(this._def.left._parseSync({
3251
+ data: ctx.data,
3252
+ path: ctx.path,
3253
+ parent: ctx
3254
+ }), this._def.right._parseSync({
3255
+ data: ctx.data,
3256
+ path: ctx.path,
3257
+ parent: ctx
3258
+ }));
3259
+ }
3260
+ }
3261
+ };
3262
+ ZodIntersection.create = (left, right, params) => {
3263
+ return new ZodIntersection({
3264
+ left,
3265
+ right,
3266
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
3267
+ ...processCreateParams(params)
3268
+ });
3269
+ };
3270
+ var ZodTuple = class _ZodTuple extends ZodType {
3271
+ _parse(input) {
3272
+ const { status, ctx } = this._processInputParams(input);
3273
+ if (ctx.parsedType !== ZodParsedType.array) {
3274
+ addIssueToContext(ctx, {
3275
+ code: ZodIssueCode.invalid_type,
3276
+ expected: ZodParsedType.array,
3277
+ received: ctx.parsedType
3278
+ });
3279
+ return INVALID;
3280
+ }
3281
+ if (ctx.data.length < this._def.items.length) {
3282
+ addIssueToContext(ctx, {
3283
+ code: ZodIssueCode.too_small,
3284
+ minimum: this._def.items.length,
3285
+ inclusive: true,
3286
+ exact: false,
3287
+ type: "array"
3288
+ });
3289
+ return INVALID;
3290
+ }
3291
+ const rest = this._def.rest;
3292
+ if (!rest && ctx.data.length > this._def.items.length) {
3293
+ addIssueToContext(ctx, {
3294
+ code: ZodIssueCode.too_big,
3295
+ maximum: this._def.items.length,
3296
+ inclusive: true,
3297
+ exact: false,
3298
+ type: "array"
3299
+ });
3300
+ status.dirty();
3301
+ }
3302
+ const items = [...ctx.data].map((item, itemIndex) => {
3303
+ const schema = this._def.items[itemIndex] || this._def.rest;
3304
+ if (!schema)
3305
+ return null;
3306
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
3307
+ }).filter((x) => !!x);
3308
+ if (ctx.common.async) {
3309
+ return Promise.all(items).then((results) => {
3310
+ return ParseStatus.mergeArray(status, results);
3311
+ });
3312
+ } else {
3313
+ return ParseStatus.mergeArray(status, items);
3314
+ }
3315
+ }
3316
+ get items() {
3317
+ return this._def.items;
3318
+ }
3319
+ rest(rest) {
3320
+ return new _ZodTuple({
3321
+ ...this._def,
3322
+ rest
3323
+ });
3324
+ }
3325
+ };
3326
+ ZodTuple.create = (schemas, params) => {
3327
+ if (!Array.isArray(schemas)) {
3328
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
3329
+ }
3330
+ return new ZodTuple({
3331
+ items: schemas,
3332
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
3333
+ rest: null,
3334
+ ...processCreateParams(params)
3335
+ });
3336
+ };
3337
+ var ZodRecord = class _ZodRecord extends ZodType {
3338
+ get keySchema() {
3339
+ return this._def.keyType;
3340
+ }
3341
+ get valueSchema() {
3342
+ return this._def.valueType;
3343
+ }
3344
+ _parse(input) {
3345
+ const { status, ctx } = this._processInputParams(input);
3346
+ if (ctx.parsedType !== ZodParsedType.object) {
3347
+ addIssueToContext(ctx, {
3348
+ code: ZodIssueCode.invalid_type,
3349
+ expected: ZodParsedType.object,
3350
+ received: ctx.parsedType
3351
+ });
3352
+ return INVALID;
3353
+ }
3354
+ const pairs = [];
3355
+ const keyType = this._def.keyType;
3356
+ const valueType = this._def.valueType;
3357
+ for (const key in ctx.data) {
3358
+ pairs.push({
3359
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
3360
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
3361
+ alwaysSet: key in ctx.data
3362
+ });
3363
+ }
3364
+ if (ctx.common.async) {
3365
+ return ParseStatus.mergeObjectAsync(status, pairs);
3366
+ } else {
3367
+ return ParseStatus.mergeObjectSync(status, pairs);
3368
+ }
3369
+ }
3370
+ get element() {
3371
+ return this._def.valueType;
3372
+ }
3373
+ static create(first, second, third) {
3374
+ if (second instanceof ZodType) {
3375
+ return new _ZodRecord({
3376
+ keyType: first,
3377
+ valueType: second,
3378
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
3379
+ ...processCreateParams(third)
3380
+ });
3381
+ }
3382
+ return new _ZodRecord({
3383
+ keyType: ZodString.create(),
3384
+ valueType: first,
3385
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
3386
+ ...processCreateParams(second)
3387
+ });
3388
+ }
3389
+ };
3390
+ var ZodMap = class extends ZodType {
3391
+ get keySchema() {
3392
+ return this._def.keyType;
3393
+ }
3394
+ get valueSchema() {
3395
+ return this._def.valueType;
3396
+ }
3397
+ _parse(input) {
3398
+ const { status, ctx } = this._processInputParams(input);
3399
+ if (ctx.parsedType !== ZodParsedType.map) {
3400
+ addIssueToContext(ctx, {
3401
+ code: ZodIssueCode.invalid_type,
3402
+ expected: ZodParsedType.map,
3403
+ received: ctx.parsedType
3404
+ });
3405
+ return INVALID;
3406
+ }
3407
+ const keyType = this._def.keyType;
3408
+ const valueType = this._def.valueType;
3409
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
3410
+ return {
3411
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
3412
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
3413
+ };
3414
+ });
3415
+ if (ctx.common.async) {
3416
+ const finalMap = /* @__PURE__ */ new Map();
3417
+ return Promise.resolve().then(async () => {
3418
+ for (const pair of pairs) {
3419
+ const key = await pair.key;
3420
+ const value = await pair.value;
3421
+ if (key.status === "aborted" || value.status === "aborted") {
3422
+ return INVALID;
3423
+ }
3424
+ if (key.status === "dirty" || value.status === "dirty") {
3425
+ status.dirty();
3426
+ }
3427
+ finalMap.set(key.value, value.value);
3428
+ }
3429
+ return { status: status.value, value: finalMap };
3430
+ });
3431
+ } else {
3432
+ const finalMap = /* @__PURE__ */ new Map();
3433
+ for (const pair of pairs) {
3434
+ const key = pair.key;
3435
+ const value = pair.value;
3436
+ if (key.status === "aborted" || value.status === "aborted") {
3437
+ return INVALID;
3438
+ }
3439
+ if (key.status === "dirty" || value.status === "dirty") {
3440
+ status.dirty();
3441
+ }
3442
+ finalMap.set(key.value, value.value);
3443
+ }
3444
+ return { status: status.value, value: finalMap };
3445
+ }
3446
+ }
3447
+ };
3448
+ ZodMap.create = (keyType, valueType, params) => {
3449
+ return new ZodMap({
3450
+ valueType,
3451
+ keyType,
3452
+ typeName: ZodFirstPartyTypeKind.ZodMap,
3453
+ ...processCreateParams(params)
3454
+ });
3455
+ };
3456
+ var ZodSet = class _ZodSet extends ZodType {
3457
+ _parse(input) {
3458
+ const { status, ctx } = this._processInputParams(input);
3459
+ if (ctx.parsedType !== ZodParsedType.set) {
3460
+ addIssueToContext(ctx, {
3461
+ code: ZodIssueCode.invalid_type,
3462
+ expected: ZodParsedType.set,
3463
+ received: ctx.parsedType
3464
+ });
3465
+ return INVALID;
3466
+ }
3467
+ const def = this._def;
3468
+ if (def.minSize !== null) {
3469
+ if (ctx.data.size < def.minSize.value) {
3470
+ addIssueToContext(ctx, {
3471
+ code: ZodIssueCode.too_small,
3472
+ minimum: def.minSize.value,
3473
+ type: "set",
3474
+ inclusive: true,
3475
+ exact: false,
3476
+ message: def.minSize.message
3477
+ });
3478
+ status.dirty();
3479
+ }
3480
+ }
3481
+ if (def.maxSize !== null) {
3482
+ if (ctx.data.size > def.maxSize.value) {
3483
+ addIssueToContext(ctx, {
3484
+ code: ZodIssueCode.too_big,
3485
+ maximum: def.maxSize.value,
3486
+ type: "set",
3487
+ inclusive: true,
3488
+ exact: false,
3489
+ message: def.maxSize.message
3490
+ });
3491
+ status.dirty();
3492
+ }
3493
+ }
3494
+ const valueType = this._def.valueType;
3495
+ function finalizeSet(elements2) {
3496
+ const parsedSet = /* @__PURE__ */ new Set();
3497
+ for (const element of elements2) {
3498
+ if (element.status === "aborted")
3499
+ return INVALID;
3500
+ if (element.status === "dirty")
3501
+ status.dirty();
3502
+ parsedSet.add(element.value);
3503
+ }
3504
+ return { status: status.value, value: parsedSet };
3505
+ }
3506
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
3507
+ if (ctx.common.async) {
3508
+ return Promise.all(elements).then((elements2) => finalizeSet(elements2));
3509
+ } else {
3510
+ return finalizeSet(elements);
3511
+ }
3512
+ }
3513
+ min(minSize, message) {
3514
+ return new _ZodSet({
3515
+ ...this._def,
3516
+ minSize: { value: minSize, message: errorUtil.toString(message) }
3517
+ });
3518
+ }
3519
+ max(maxSize, message) {
3520
+ return new _ZodSet({
3521
+ ...this._def,
3522
+ maxSize: { value: maxSize, message: errorUtil.toString(message) }
3523
+ });
3524
+ }
3525
+ size(size, message) {
3526
+ return this.min(size, message).max(size, message);
3527
+ }
3528
+ nonempty(message) {
3529
+ return this.min(1, message);
3530
+ }
3531
+ };
3532
+ ZodSet.create = (valueType, params) => {
3533
+ return new ZodSet({
3534
+ valueType,
3535
+ minSize: null,
3536
+ maxSize: null,
3537
+ typeName: ZodFirstPartyTypeKind.ZodSet,
3538
+ ...processCreateParams(params)
3539
+ });
3540
+ };
3541
+ var ZodFunction = class _ZodFunction extends ZodType {
3542
+ constructor() {
3543
+ super(...arguments);
3544
+ this.validate = this.implement;
3545
+ }
3546
+ _parse(input) {
3547
+ const { ctx } = this._processInputParams(input);
3548
+ if (ctx.parsedType !== ZodParsedType.function) {
3549
+ addIssueToContext(ctx, {
3550
+ code: ZodIssueCode.invalid_type,
3551
+ expected: ZodParsedType.function,
3552
+ received: ctx.parsedType
3553
+ });
3554
+ return INVALID;
3555
+ }
3556
+ function makeArgsIssue(args, error) {
3557
+ return makeIssue({
3558
+ data: args,
3559
+ path: ctx.path,
3560
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
3561
+ issueData: {
3562
+ code: ZodIssueCode.invalid_arguments,
3563
+ argumentsError: error
3564
+ }
3565
+ });
3566
+ }
3567
+ function makeReturnsIssue(returns, error) {
3568
+ return makeIssue({
3569
+ data: returns,
3570
+ path: ctx.path,
3571
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
3572
+ issueData: {
3573
+ code: ZodIssueCode.invalid_return_type,
3574
+ returnTypeError: error
3575
+ }
3576
+ });
3577
+ }
3578
+ const params = { errorMap: ctx.common.contextualErrorMap };
3579
+ const fn = ctx.data;
3580
+ if (this._def.returns instanceof ZodPromise) {
3581
+ const me = this;
3582
+ return OK(async function(...args) {
3583
+ const error = new ZodError([]);
3584
+ const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
3585
+ error.addIssue(makeArgsIssue(args, e));
3586
+ throw error;
3587
+ });
3588
+ const result = await Reflect.apply(fn, this, parsedArgs);
3589
+ const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
3590
+ error.addIssue(makeReturnsIssue(result, e));
3591
+ throw error;
3592
+ });
3593
+ return parsedReturns;
3594
+ });
3595
+ } else {
3596
+ const me = this;
3597
+ return OK(function(...args) {
3598
+ const parsedArgs = me._def.args.safeParse(args, params);
3599
+ if (!parsedArgs.success) {
3600
+ throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
3601
+ }
3602
+ const result = Reflect.apply(fn, this, parsedArgs.data);
3603
+ const parsedReturns = me._def.returns.safeParse(result, params);
3604
+ if (!parsedReturns.success) {
3605
+ throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
3606
+ }
3607
+ return parsedReturns.data;
3608
+ });
3609
+ }
3610
+ }
3611
+ parameters() {
3612
+ return this._def.args;
3613
+ }
3614
+ returnType() {
3615
+ return this._def.returns;
3616
+ }
3617
+ args(...items) {
3618
+ return new _ZodFunction({
3619
+ ...this._def,
3620
+ args: ZodTuple.create(items).rest(ZodUnknown.create())
3621
+ });
3622
+ }
3623
+ returns(returnType) {
3624
+ return new _ZodFunction({
3625
+ ...this._def,
3626
+ returns: returnType
3627
+ });
3628
+ }
3629
+ implement(func) {
3630
+ const validatedFunc = this.parse(func);
3631
+ return validatedFunc;
3632
+ }
3633
+ strictImplement(func) {
3634
+ const validatedFunc = this.parse(func);
3635
+ return validatedFunc;
3636
+ }
3637
+ static create(args, returns, params) {
3638
+ return new _ZodFunction({
3639
+ args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
3640
+ returns: returns || ZodUnknown.create(),
3641
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
3642
+ ...processCreateParams(params)
3643
+ });
3644
+ }
3645
+ };
3646
+ var ZodLazy = class extends ZodType {
3647
+ get schema() {
3648
+ return this._def.getter();
3649
+ }
3650
+ _parse(input) {
3651
+ const { ctx } = this._processInputParams(input);
3652
+ const lazySchema = this._def.getter();
3653
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
3654
+ }
3655
+ };
3656
+ ZodLazy.create = (getter, params) => {
3657
+ return new ZodLazy({
3658
+ getter,
3659
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
3660
+ ...processCreateParams(params)
3661
+ });
3662
+ };
3663
+ var ZodLiteral = class extends ZodType {
3664
+ _parse(input) {
3665
+ if (input.data !== this._def.value) {
3666
+ const ctx = this._getOrReturnCtx(input);
3667
+ addIssueToContext(ctx, {
3668
+ received: ctx.data,
3669
+ code: ZodIssueCode.invalid_literal,
3670
+ expected: this._def.value
3671
+ });
3672
+ return INVALID;
3673
+ }
3674
+ return { status: "valid", value: input.data };
3675
+ }
3676
+ get value() {
3677
+ return this._def.value;
3678
+ }
3679
+ };
3680
+ ZodLiteral.create = (value, params) => {
3681
+ return new ZodLiteral({
3682
+ value,
3683
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
3684
+ ...processCreateParams(params)
3685
+ });
3686
+ };
3687
+ function createZodEnum(values, params) {
3688
+ return new ZodEnum({
3689
+ values,
3690
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
3691
+ ...processCreateParams(params)
3692
+ });
3693
+ }
3694
+ var ZodEnum = class _ZodEnum extends ZodType {
3695
+ _parse(input) {
3696
+ if (typeof input.data !== "string") {
3697
+ const ctx = this._getOrReturnCtx(input);
3698
+ const expectedValues = this._def.values;
3699
+ addIssueToContext(ctx, {
3700
+ expected: util.joinValues(expectedValues),
3701
+ received: ctx.parsedType,
3702
+ code: ZodIssueCode.invalid_type
3703
+ });
3704
+ return INVALID;
3705
+ }
3706
+ if (!this._cache) {
3707
+ this._cache = new Set(this._def.values);
3708
+ }
3709
+ if (!this._cache.has(input.data)) {
3710
+ const ctx = this._getOrReturnCtx(input);
3711
+ const expectedValues = this._def.values;
3712
+ addIssueToContext(ctx, {
3713
+ received: ctx.data,
3714
+ code: ZodIssueCode.invalid_enum_value,
3715
+ options: expectedValues
3716
+ });
3717
+ return INVALID;
3718
+ }
3719
+ return OK(input.data);
3720
+ }
3721
+ get options() {
3722
+ return this._def.values;
3723
+ }
3724
+ get enum() {
3725
+ const enumValues = {};
3726
+ for (const val of this._def.values) {
3727
+ enumValues[val] = val;
3728
+ }
3729
+ return enumValues;
3730
+ }
3731
+ get Values() {
3732
+ const enumValues = {};
3733
+ for (const val of this._def.values) {
3734
+ enumValues[val] = val;
3735
+ }
3736
+ return enumValues;
3737
+ }
3738
+ get Enum() {
3739
+ const enumValues = {};
3740
+ for (const val of this._def.values) {
3741
+ enumValues[val] = val;
3742
+ }
3743
+ return enumValues;
3744
+ }
3745
+ extract(values, newDef = this._def) {
3746
+ return _ZodEnum.create(values, {
3747
+ ...this._def,
3748
+ ...newDef
3749
+ });
3750
+ }
3751
+ exclude(values, newDef = this._def) {
3752
+ return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
3753
+ ...this._def,
3754
+ ...newDef
3755
+ });
3756
+ }
3757
+ };
3758
+ ZodEnum.create = createZodEnum;
3759
+ var ZodNativeEnum = class extends ZodType {
3760
+ _parse(input) {
3761
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
3762
+ const ctx = this._getOrReturnCtx(input);
3763
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
3764
+ const expectedValues = util.objectValues(nativeEnumValues);
3765
+ addIssueToContext(ctx, {
3766
+ expected: util.joinValues(expectedValues),
3767
+ received: ctx.parsedType,
3768
+ code: ZodIssueCode.invalid_type
3769
+ });
3770
+ return INVALID;
3771
+ }
3772
+ if (!this._cache) {
3773
+ this._cache = new Set(util.getValidEnumValues(this._def.values));
3774
+ }
3775
+ if (!this._cache.has(input.data)) {
3776
+ const expectedValues = util.objectValues(nativeEnumValues);
3777
+ addIssueToContext(ctx, {
3778
+ received: ctx.data,
3779
+ code: ZodIssueCode.invalid_enum_value,
3780
+ options: expectedValues
3781
+ });
3782
+ return INVALID;
3783
+ }
3784
+ return OK(input.data);
3785
+ }
3786
+ get enum() {
3787
+ return this._def.values;
3788
+ }
3789
+ };
3790
+ ZodNativeEnum.create = (values, params) => {
3791
+ return new ZodNativeEnum({
3792
+ values,
3793
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
3794
+ ...processCreateParams(params)
3795
+ });
3796
+ };
3797
+ var ZodPromise = class extends ZodType {
3798
+ unwrap() {
3799
+ return this._def.type;
3800
+ }
3801
+ _parse(input) {
3802
+ const { ctx } = this._processInputParams(input);
3803
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
3804
+ addIssueToContext(ctx, {
3805
+ code: ZodIssueCode.invalid_type,
3806
+ expected: ZodParsedType.promise,
3807
+ received: ctx.parsedType
3808
+ });
3809
+ return INVALID;
3810
+ }
3811
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
3812
+ return OK(promisified.then((data) => {
3813
+ return this._def.type.parseAsync(data, {
3814
+ path: ctx.path,
3815
+ errorMap: ctx.common.contextualErrorMap
3816
+ });
3817
+ }));
3818
+ }
3819
+ };
3820
+ ZodPromise.create = (schema, params) => {
3821
+ return new ZodPromise({
3822
+ type: schema,
3823
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
3824
+ ...processCreateParams(params)
3825
+ });
3826
+ };
3827
+ var ZodEffects = class extends ZodType {
3828
+ innerType() {
3829
+ return this._def.schema;
3830
+ }
3831
+ sourceType() {
3832
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
3833
+ }
3834
+ _parse(input) {
3835
+ const { status, ctx } = this._processInputParams(input);
3836
+ const effect = this._def.effect || null;
3837
+ const checkCtx = {
3838
+ addIssue: (arg) => {
3839
+ addIssueToContext(ctx, arg);
3840
+ if (arg.fatal) {
3841
+ status.abort();
3842
+ } else {
3843
+ status.dirty();
3844
+ }
3845
+ },
3846
+ get path() {
3847
+ return ctx.path;
3848
+ }
3849
+ };
3850
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3851
+ if (effect.type === "preprocess") {
3852
+ const processed = effect.transform(ctx.data, checkCtx);
3853
+ if (ctx.common.async) {
3854
+ return Promise.resolve(processed).then(async (processed2) => {
3855
+ if (status.value === "aborted")
3856
+ return INVALID;
3857
+ const result = await this._def.schema._parseAsync({
3858
+ data: processed2,
3859
+ path: ctx.path,
3860
+ parent: ctx
3861
+ });
3862
+ if (result.status === "aborted")
3863
+ return INVALID;
3864
+ if (result.status === "dirty")
3865
+ return DIRTY(result.value);
3866
+ if (status.value === "dirty")
3867
+ return DIRTY(result.value);
3868
+ return result;
3869
+ });
3870
+ } else {
3871
+ if (status.value === "aborted")
3872
+ return INVALID;
3873
+ const result = this._def.schema._parseSync({
3874
+ data: processed,
3875
+ path: ctx.path,
3876
+ parent: ctx
3877
+ });
3878
+ if (result.status === "aborted")
3879
+ return INVALID;
3880
+ if (result.status === "dirty")
3881
+ return DIRTY(result.value);
3882
+ if (status.value === "dirty")
3883
+ return DIRTY(result.value);
3884
+ return result;
3885
+ }
3886
+ }
3887
+ if (effect.type === "refinement") {
3888
+ const executeRefinement = (acc) => {
3889
+ const result = effect.refinement(acc, checkCtx);
3890
+ if (ctx.common.async) {
3891
+ return Promise.resolve(result);
3892
+ }
3893
+ if (result instanceof Promise) {
3894
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
3895
+ }
3896
+ return acc;
3897
+ };
3898
+ if (ctx.common.async === false) {
3899
+ const inner = this._def.schema._parseSync({
3900
+ data: ctx.data,
3901
+ path: ctx.path,
3902
+ parent: ctx
3903
+ });
3904
+ if (inner.status === "aborted")
3905
+ return INVALID;
3906
+ if (inner.status === "dirty")
3907
+ status.dirty();
3908
+ executeRefinement(inner.value);
3909
+ return { status: status.value, value: inner.value };
3910
+ } else {
3911
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
3912
+ if (inner.status === "aborted")
3913
+ return INVALID;
3914
+ if (inner.status === "dirty")
3915
+ status.dirty();
3916
+ return executeRefinement(inner.value).then(() => {
3917
+ return { status: status.value, value: inner.value };
3918
+ });
3919
+ });
3920
+ }
3921
+ }
3922
+ if (effect.type === "transform") {
3923
+ if (ctx.common.async === false) {
3924
+ const base = this._def.schema._parseSync({
3925
+ data: ctx.data,
3926
+ path: ctx.path,
3927
+ parent: ctx
3928
+ });
3929
+ if (!isValid(base))
3930
+ return INVALID;
3931
+ const result = effect.transform(base.value, checkCtx);
3932
+ if (result instanceof Promise) {
3933
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
3934
+ }
3935
+ return { status: status.value, value: result };
3936
+ } else {
3937
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
3938
+ if (!isValid(base))
3939
+ return INVALID;
3940
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
3941
+ status: status.value,
3942
+ value: result
3943
+ }));
3944
+ });
3945
+ }
3946
+ }
3947
+ util.assertNever(effect);
3948
+ }
3949
+ };
3950
+ ZodEffects.create = (schema, effect, params) => {
3951
+ return new ZodEffects({
3952
+ schema,
3953
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3954
+ effect,
3955
+ ...processCreateParams(params)
3956
+ });
3957
+ };
3958
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
3959
+ return new ZodEffects({
3960
+ schema,
3961
+ effect: { type: "preprocess", transform: preprocess },
3962
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3963
+ ...processCreateParams(params)
3964
+ });
3965
+ };
3966
+ var ZodOptional = class extends ZodType {
3967
+ _parse(input) {
3968
+ const parsedType = this._getType(input);
3969
+ if (parsedType === ZodParsedType.undefined) {
3970
+ return OK(void 0);
3971
+ }
3972
+ return this._def.innerType._parse(input);
3973
+ }
3974
+ unwrap() {
3975
+ return this._def.innerType;
3976
+ }
3977
+ };
3978
+ ZodOptional.create = (type, params) => {
3979
+ return new ZodOptional({
3980
+ innerType: type,
3981
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
3982
+ ...processCreateParams(params)
3983
+ });
3984
+ };
3985
+ var ZodNullable = class extends ZodType {
3986
+ _parse(input) {
3987
+ const parsedType = this._getType(input);
3988
+ if (parsedType === ZodParsedType.null) {
3989
+ return OK(null);
3990
+ }
3991
+ return this._def.innerType._parse(input);
3992
+ }
3993
+ unwrap() {
3994
+ return this._def.innerType;
3995
+ }
3996
+ };
3997
+ ZodNullable.create = (type, params) => {
3998
+ return new ZodNullable({
3999
+ innerType: type,
4000
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
4001
+ ...processCreateParams(params)
4002
+ });
4003
+ };
4004
+ var ZodDefault = class extends ZodType {
4005
+ _parse(input) {
4006
+ const { ctx } = this._processInputParams(input);
4007
+ let data = ctx.data;
4008
+ if (ctx.parsedType === ZodParsedType.undefined) {
4009
+ data = this._def.defaultValue();
4010
+ }
4011
+ return this._def.innerType._parse({
4012
+ data,
4013
+ path: ctx.path,
4014
+ parent: ctx
4015
+ });
4016
+ }
4017
+ removeDefault() {
4018
+ return this._def.innerType;
4019
+ }
4020
+ };
4021
+ ZodDefault.create = (type, params) => {
4022
+ return new ZodDefault({
4023
+ innerType: type,
4024
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
4025
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
4026
+ ...processCreateParams(params)
4027
+ });
4028
+ };
4029
+ var ZodCatch = class extends ZodType {
4030
+ _parse(input) {
4031
+ const { ctx } = this._processInputParams(input);
4032
+ const newCtx = {
4033
+ ...ctx,
4034
+ common: {
4035
+ ...ctx.common,
4036
+ issues: []
4037
+ }
4038
+ };
4039
+ const result = this._def.innerType._parse({
4040
+ data: newCtx.data,
4041
+ path: newCtx.path,
4042
+ parent: {
4043
+ ...newCtx
4044
+ }
4045
+ });
4046
+ if (isAsync(result)) {
4047
+ return result.then((result2) => {
4048
+ return {
4049
+ status: "valid",
4050
+ value: result2.status === "valid" ? result2.value : this._def.catchValue({
4051
+ get error() {
4052
+ return new ZodError(newCtx.common.issues);
4053
+ },
4054
+ input: newCtx.data
4055
+ })
4056
+ };
4057
+ });
4058
+ } else {
4059
+ return {
4060
+ status: "valid",
4061
+ value: result.status === "valid" ? result.value : this._def.catchValue({
4062
+ get error() {
4063
+ return new ZodError(newCtx.common.issues);
4064
+ },
4065
+ input: newCtx.data
4066
+ })
4067
+ };
4068
+ }
4069
+ }
4070
+ removeCatch() {
4071
+ return this._def.innerType;
4072
+ }
4073
+ };
4074
+ ZodCatch.create = (type, params) => {
4075
+ return new ZodCatch({
4076
+ innerType: type,
4077
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
4078
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
4079
+ ...processCreateParams(params)
4080
+ });
4081
+ };
4082
+ var ZodNaN = class extends ZodType {
4083
+ _parse(input) {
4084
+ const parsedType = this._getType(input);
4085
+ if (parsedType !== ZodParsedType.nan) {
4086
+ const ctx = this._getOrReturnCtx(input);
4087
+ addIssueToContext(ctx, {
4088
+ code: ZodIssueCode.invalid_type,
4089
+ expected: ZodParsedType.nan,
4090
+ received: ctx.parsedType
4091
+ });
4092
+ return INVALID;
4093
+ }
4094
+ return { status: "valid", value: input.data };
4095
+ }
4096
+ };
4097
+ ZodNaN.create = (params) => {
4098
+ return new ZodNaN({
4099
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
4100
+ ...processCreateParams(params)
4101
+ });
4102
+ };
4103
+ var BRAND = /* @__PURE__ */ Symbol("zod_brand");
4104
+ var ZodBranded = class extends ZodType {
4105
+ _parse(input) {
4106
+ const { ctx } = this._processInputParams(input);
4107
+ const data = ctx.data;
4108
+ return this._def.type._parse({
4109
+ data,
4110
+ path: ctx.path,
4111
+ parent: ctx
4112
+ });
4113
+ }
4114
+ unwrap() {
4115
+ return this._def.type;
4116
+ }
4117
+ };
4118
+ var ZodPipeline = class _ZodPipeline extends ZodType {
4119
+ _parse(input) {
4120
+ const { status, ctx } = this._processInputParams(input);
4121
+ if (ctx.common.async) {
4122
+ const handleAsync = async () => {
4123
+ const inResult = await this._def.in._parseAsync({
4124
+ data: ctx.data,
4125
+ path: ctx.path,
4126
+ parent: ctx
4127
+ });
4128
+ if (inResult.status === "aborted")
4129
+ return INVALID;
4130
+ if (inResult.status === "dirty") {
4131
+ status.dirty();
4132
+ return DIRTY(inResult.value);
4133
+ } else {
4134
+ return this._def.out._parseAsync({
4135
+ data: inResult.value,
4136
+ path: ctx.path,
4137
+ parent: ctx
4138
+ });
4139
+ }
4140
+ };
4141
+ return handleAsync();
4142
+ } else {
4143
+ const inResult = this._def.in._parseSync({
4144
+ data: ctx.data,
4145
+ path: ctx.path,
4146
+ parent: ctx
4147
+ });
4148
+ if (inResult.status === "aborted")
4149
+ return INVALID;
4150
+ if (inResult.status === "dirty") {
4151
+ status.dirty();
4152
+ return {
4153
+ status: "dirty",
4154
+ value: inResult.value
4155
+ };
4156
+ } else {
4157
+ return this._def.out._parseSync({
4158
+ data: inResult.value,
4159
+ path: ctx.path,
4160
+ parent: ctx
4161
+ });
4162
+ }
4163
+ }
4164
+ }
4165
+ static create(a, b) {
4166
+ return new _ZodPipeline({
4167
+ in: a,
4168
+ out: b,
4169
+ typeName: ZodFirstPartyTypeKind.ZodPipeline
4170
+ });
4171
+ }
4172
+ };
4173
+ var ZodReadonly = class extends ZodType {
4174
+ _parse(input) {
4175
+ const result = this._def.innerType._parse(input);
4176
+ const freeze = (data) => {
4177
+ if (isValid(data)) {
4178
+ data.value = Object.freeze(data.value);
4179
+ }
4180
+ return data;
4181
+ };
4182
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
4183
+ }
4184
+ unwrap() {
4185
+ return this._def.innerType;
4186
+ }
4187
+ };
4188
+ ZodReadonly.create = (type, params) => {
4189
+ return new ZodReadonly({
4190
+ innerType: type,
4191
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
4192
+ ...processCreateParams(params)
4193
+ });
4194
+ };
4195
+ function cleanParams(params, data) {
4196
+ const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
4197
+ const p2 = typeof p === "string" ? { message: p } : p;
4198
+ return p2;
4199
+ }
4200
+ function custom(check, _params = {}, fatal) {
4201
+ if (check)
4202
+ return ZodAny.create().superRefine((data, ctx) => {
4203
+ const r = check(data);
4204
+ if (r instanceof Promise) {
4205
+ return r.then((r2) => {
4206
+ if (!r2) {
4207
+ const params = cleanParams(_params, data);
4208
+ const _fatal = params.fatal ?? fatal ?? true;
4209
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
4210
+ }
4211
+ });
4212
+ }
4213
+ if (!r) {
4214
+ const params = cleanParams(_params, data);
4215
+ const _fatal = params.fatal ?? fatal ?? true;
4216
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
4217
+ }
4218
+ return;
4219
+ });
4220
+ return ZodAny.create();
4221
+ }
4222
+ var late = {
4223
+ object: ZodObject.lazycreate
4224
+ };
4225
+ var ZodFirstPartyTypeKind;
4226
+ (function(ZodFirstPartyTypeKind2) {
4227
+ ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
4228
+ ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
4229
+ ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
4230
+ ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
4231
+ ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
4232
+ ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
4233
+ ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
4234
+ ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
4235
+ ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
4236
+ ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
4237
+ ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
4238
+ ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
4239
+ ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
4240
+ ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
4241
+ ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
4242
+ ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
4243
+ ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
4244
+ ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
4245
+ ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
4246
+ ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
4247
+ ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
4248
+ ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
4249
+ ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
4250
+ ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
4251
+ ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
4252
+ ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
4253
+ ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
4254
+ ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
4255
+ ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
4256
+ ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
4257
+ ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
4258
+ ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
4259
+ ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
4260
+ ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
4261
+ ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
4262
+ ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
4263
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
4264
+ var instanceOfType = (cls, params = {
4265
+ message: `Input not instance of ${cls.name}`
4266
+ }) => custom((data) => data instanceof cls, params);
4267
+ var stringType = ZodString.create;
4268
+ var numberType = ZodNumber.create;
4269
+ var nanType = ZodNaN.create;
4270
+ var bigIntType = ZodBigInt.create;
4271
+ var booleanType = ZodBoolean.create;
4272
+ var dateType = ZodDate.create;
4273
+ var symbolType = ZodSymbol.create;
4274
+ var undefinedType = ZodUndefined.create;
4275
+ var nullType = ZodNull.create;
4276
+ var anyType = ZodAny.create;
4277
+ var unknownType = ZodUnknown.create;
4278
+ var neverType = ZodNever.create;
4279
+ var voidType = ZodVoid.create;
4280
+ var arrayType = ZodArray.create;
4281
+ var objectType = ZodObject.create;
4282
+ var strictObjectType = ZodObject.strictCreate;
4283
+ var unionType = ZodUnion.create;
4284
+ var discriminatedUnionType = ZodDiscriminatedUnion.create;
4285
+ var intersectionType = ZodIntersection.create;
4286
+ var tupleType = ZodTuple.create;
4287
+ var recordType = ZodRecord.create;
4288
+ var mapType = ZodMap.create;
4289
+ var setType = ZodSet.create;
4290
+ var functionType = ZodFunction.create;
4291
+ var lazyType = ZodLazy.create;
4292
+ var literalType = ZodLiteral.create;
4293
+ var enumType = ZodEnum.create;
4294
+ var nativeEnumType = ZodNativeEnum.create;
4295
+ var promiseType = ZodPromise.create;
4296
+ var effectsType = ZodEffects.create;
4297
+ var optionalType = ZodOptional.create;
4298
+ var nullableType = ZodNullable.create;
4299
+ var preprocessType = ZodEffects.createWithPreprocess;
4300
+ var pipelineType = ZodPipeline.create;
4301
+ var ostring = () => stringType().optional();
4302
+ var onumber = () => numberType().optional();
4303
+ var oboolean = () => booleanType().optional();
4304
+ var coerce = {
4305
+ string: ((arg) => ZodString.create({ ...arg, coerce: true })),
4306
+ number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
4307
+ boolean: ((arg) => ZodBoolean.create({
4308
+ ...arg,
4309
+ coerce: true
4310
+ })),
4311
+ bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
4312
+ date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
4313
+ };
4314
+ var NEVER = INVALID;
4315
+
4316
+ // ../registry/src/schema.ts
4317
+ var addressSchema = external_exports.string().regex(/^0x[a-fA-F0-9]{40}$/, "Invalid checksummed or hex address");
4318
+ var contractEntrySchema = external_exports.object({
4319
+ address: addressSchema,
4320
+ implementation: addressSchema.optional()
4321
+ });
4322
+ var fluentChainSchema = external_exports.object({
4323
+ id: external_exports.string(),
4324
+ name: external_exports.string(),
4325
+ chainId: external_exports.number().int().positive(),
4326
+ testnet: external_exports.boolean(),
4327
+ nativeCurrency: external_exports.object({
4328
+ name: external_exports.string(),
4329
+ symbol: external_exports.string(),
4330
+ decimals: external_exports.number().int()
4331
+ }),
4332
+ rpcUrls: external_exports.object({
4333
+ default: external_exports.object({
4334
+ http: external_exports.array(external_exports.string().url()),
4335
+ webSocket: external_exports.array(external_exports.string().url()).optional()
4336
+ })
4337
+ }),
4338
+ blockExplorers: external_exports.object({
4339
+ default: external_exports.object({
4340
+ name: external_exports.string(),
4341
+ url: external_exports.string().url()
4342
+ })
4343
+ }),
4344
+ infoURL: external_exports.string().url(),
4345
+ faucets: external_exports.array(external_exports.string().url()).optional(),
4346
+ parent: external_exports.object({
4347
+ type: external_exports.literal("L2"),
4348
+ chainId: external_exports.number().int().positive(),
4349
+ bridgeUrl: external_exports.string().url()
4350
+ }).optional(),
4351
+ contracts: external_exports.object({
4352
+ fluentBridge: contractEntrySchema.optional(),
4353
+ // Gateways are what a bridge transfer actually calls; the bridge contract
4354
+ // itself only prices the message (`getSentMessageFee`).
4355
+ nativeGateway: contractEntrySchema.optional(),
4356
+ erc20Gateway: contractEntrySchema.optional(),
4357
+ wethGateway: contractEntrySchema.optional(),
4358
+ universalTokenFactory: contractEntrySchema.optional(),
4359
+ paymentGateway: contractEntrySchema.optional(),
4360
+ peggedTokenPrecompile: external_exports.object({ address: addressSchema }).optional()
4361
+ }).optional()
4362
+ });
4363
+ var l1ChainSchema = external_exports.object({
4364
+ id: external_exports.string(),
4365
+ name: external_exports.string(),
4366
+ chainId: external_exports.number().int().positive(),
4367
+ testnet: external_exports.boolean(),
4368
+ nativeCurrency: external_exports.object({
4369
+ name: external_exports.string(),
4370
+ symbol: external_exports.string(),
4371
+ decimals: external_exports.number().int()
4372
+ }),
4373
+ rpcUrls: external_exports.object({
4374
+ default: external_exports.object({
4375
+ http: external_exports.array(external_exports.string().url())
4376
+ })
4377
+ }),
4378
+ blockExplorers: external_exports.object({
4379
+ default: external_exports.object({
4380
+ name: external_exports.string(),
4381
+ url: external_exports.string().url()
4382
+ })
4383
+ }),
4384
+ pairedL2: external_exports.string().optional(),
4385
+ contracts: external_exports.record(external_exports.string(), contractEntrySchema).optional()
4386
+ });
4387
+ var appSchema = external_exports.object({
4388
+ id: external_exports.string(),
4389
+ name: external_exports.string(),
4390
+ category: external_exports.string(),
4391
+ description: external_exports.string().optional(),
4392
+ docs: external_exports.string().url().optional(),
4393
+ deployments: external_exports.record(external_exports.string(), external_exports.object({
4394
+ contract: external_exports.string(),
4395
+ address: addressSchema
4396
+ }))
4397
+ });
4398
+ var zerodevIntegrationSchema = external_exports.object({
4399
+ id: external_exports.literal("zerodev"),
4400
+ name: external_exports.string(),
4401
+ description: external_exports.string(),
4402
+ docs: external_exports.string().url(),
4403
+ dashboard: external_exports.string().url(),
4404
+ rpcUrlTemplate: external_exports.string(),
4405
+ supportedFluentChains: external_exports.array(
4406
+ external_exports.object({
4407
+ fluentChainId: external_exports.string(),
4408
+ chainId: external_exports.number().int().positive()
4409
+ })
4410
+ ),
4411
+ privy: external_exports.object({
4412
+ docs: external_exports.string().url(),
4413
+ embeddedWalletCreateOnLogin: external_exports.string()
4414
+ })
4415
+ });
4416
+
4417
+ // ../registry/src/data.ts
4418
+ function parse(schema, value) {
4419
+ return schema.parse(value);
4420
+ }
4421
+ var fluentChains = {
4422
+ testnet: parse(fluentChainSchema, fluent_testnet_default),
4423
+ mainnet: parse(fluentChainSchema, fluent_mainnet_default)
4424
+ };
4425
+ var l1Chains = {
4426
+ ethereum: parse(l1ChainSchema, ethereum_default),
4427
+ sepolia: parse(l1ChainSchema, sepolia_default)
4428
+ };
4429
+ ({
4430
+ fluentBridge: parse(appSchema, fluent_bridge_default)
4431
+ });
4432
+ var integrations = {
4433
+ zerodev: parse(zerodevIntegrationSchema, zerodev_default)
4434
+ };
4435
+ integrations.zerodev.supportedFluentChains.map(
4436
+ (c) => c.chainId
4437
+ );
4438
+ function toContract(entry) {
4439
+ return { address: entry.address };
4440
+ }
4441
+ function fluentDefinitionToViemChain(definition) {
4442
+ const contracts = definition.contracts;
4443
+ const viemContracts = {};
4444
+ if (contracts?.fluentBridge) {
4445
+ viemContracts.fluentBridge = toContract(contracts.fluentBridge);
4446
+ }
4447
+ if (contracts?.universalTokenFactory) {
4448
+ viemContracts.universalTokenFactory = toContract(
4449
+ contracts.universalTokenFactory
4450
+ );
4451
+ }
4452
+ if (contracts?.paymentGateway) {
4453
+ viemContracts.paymentGateway = toContract(contracts.paymentGateway);
4454
+ }
4455
+ if (contracts?.peggedTokenPrecompile) {
4456
+ viemContracts.peggedTokenPrecompile = toContract(
4457
+ contracts.peggedTokenPrecompile
4458
+ );
4459
+ }
4460
+ return defineChain({
4461
+ id: definition.chainId,
4462
+ name: definition.name,
4463
+ nativeCurrency: definition.nativeCurrency,
4464
+ rpcUrls: definition.rpcUrls,
4465
+ blockExplorers: definition.blockExplorers,
4466
+ testnet: definition.testnet,
4467
+ contracts: Object.keys(viemContracts).length > 0 ? viemContracts : void 0,
4468
+ sourceId: definition.parent?.chainId
4469
+ });
4470
+ }
4471
+ function l1DefinitionToViemChain(definition) {
4472
+ const bridge = definition.contracts?.fluentBridge;
4473
+ const viemContracts = bridge ? { fluentBridge: toContract(bridge) } : void 0;
4474
+ return defineChain({
4475
+ id: definition.chainId,
4476
+ name: definition.name,
4477
+ nativeCurrency: definition.nativeCurrency,
4478
+ rpcUrls: definition.rpcUrls,
4479
+ blockExplorers: definition.blockExplorers,
4480
+ testnet: definition.testnet,
4481
+ contracts: viemContracts
4482
+ });
4483
+ }
4484
+
4485
+ // ../connect-sdk/src/chains.ts
4486
+ var fluentTestnet = fluentDefinitionToViemChain(fluentChains.testnet);
4487
+ var fluentMainnet = fluentDefinitionToViemChain(fluentChains.mainnet);
4488
+ l1DefinitionToViemChain(l1Chains.sepolia);
4489
+ function isFluentNativeToken(token) {
4490
+ return token.native === true;
4491
+ }
4492
+ function fluentTokenIdentity(token) {
4493
+ const target = isFluentNativeToken(token) ? "native" : token.address?.toLowerCase() ?? "unknown";
4494
+ return `${token.chainId}:${target}`;
4495
+ }
4496
+ var fluentTestnetTokenDefaults = {
4497
+ ETH: {
4498
+ chainId: 20994,
4499
+ symbol: "ETH",
4500
+ name: "Ether",
4501
+ decimals: 18,
4502
+ native: true,
4503
+ gasPriority: 3
4504
+ },
4505
+ USDnr: {
4506
+ chainId: 20994,
4507
+ symbol: "USDnr",
4508
+ name: "USDnr",
4509
+ decimals: 6,
4510
+ address: "0x279a6DC6354374473f6f3CFB3999e6C2e146f8a1",
4511
+ gasPriority: 2
4512
+ },
4513
+ BLEND: {
4514
+ chainId: 20994,
4515
+ symbol: "BLEND",
4516
+ name: "Mock Blend",
4517
+ decimals: 18,
4518
+ address: "0x83Fed707A8dDDC2535aE591CF19fB6C91D542D8E",
4519
+ gasPriority: 1
4520
+ }
4521
+ };
4522
+ var fluentMainnetTokenDefaults = {
4523
+ ETH: {
4524
+ chainId: 25363,
4525
+ symbol: "ETH",
4526
+ name: "Ether",
4527
+ decimals: 18,
4528
+ native: true,
4529
+ gasPriority: 3
4530
+ },
4531
+ USDnr: {
4532
+ chainId: 25363,
4533
+ symbol: "USDnr",
4534
+ name: "USDnr",
4535
+ // `decimals()` on 0xD48e… returns 6, as it does on the testnet USDnr.
4536
+ decimals: 6,
4537
+ address: "0xD48e565561416dE59DA1050ED70b8d75e8eF28f9",
4538
+ gasPriority: 2
4539
+ },
4540
+ BLEND: {
4541
+ chainId: 25363,
4542
+ symbol: "BLEND",
4543
+ name: "Fluent",
4544
+ decimals: 18,
4545
+ address: "0x1385b8f55a84f2bda13eed4099d29eae03d553b2",
4546
+ gasPriority: 1
4547
+ }
4548
+ };
4549
+ function getFluentTokenDefaultsForNetwork(network) {
4550
+ switch (network) {
4551
+ case "mainnet":
4552
+ return fluentMainnetTokenDefaults;
4553
+ default:
4554
+ return fluentTestnetTokenDefaults;
4555
+ }
4556
+ }
4557
+ new Set(
4558
+ [
4559
+ ...Object.values(fluentTestnetTokenDefaults),
4560
+ ...Object.values(fluentMainnetTokenDefaults)
4561
+ ].map(fluentTokenIdentity)
4562
+ );
4563
+ function sortFluentGasTokens(tokens) {
4564
+ return tokens.filter((token) => token.gasPriority !== void 0).sort((left, right) => left.gasPriority - right.gasPriority);
4565
+ }
4566
+ var displayTokensByNetwork = {
4567
+ testnet: Object.freeze(Object.values(fluentTestnetTokenDefaults)),
4568
+ mainnet: Object.freeze(Object.values(fluentMainnetTokenDefaults))
4569
+ };
4570
+ ({
4571
+ testnet: Object.freeze(sortFluentGasTokens(displayTokensByNetwork.testnet)),
4572
+ mainnet: Object.freeze(sortFluentGasTokens(displayTokensByNetwork.mainnet))
4573
+ });
4574
+ function getFluentDefaultWidgetDisplayTokens(network) {
4575
+ return displayTokensByNetwork[network];
4576
+ }
4577
+ var balanceOfAbi = [
4578
+ {
4579
+ type: "function",
4580
+ name: "balanceOf",
4581
+ stateMutability: "view",
4582
+ inputs: [{ name: "account", type: "address" }],
4583
+ outputs: [{ name: "", type: "uint256" }]
4584
+ }
4585
+ ];
4586
+ async function readFluentTokenBalances(params) {
4587
+ return Promise.all(
4588
+ params.tokens.map(async (token) => {
4589
+ const native = isFluentNativeToken(token);
4590
+ if (!native && !token.address) {
4591
+ return {
4592
+ ...token,
4593
+ raw: null,
4594
+ formatted: null,
4595
+ status: "not-configured"
4596
+ };
4597
+ }
4598
+ try {
4599
+ const raw = native ? await params.client.getBalance({ address: params.account }) : await params.client.readContract({
4600
+ address: token.address,
4601
+ abi: balanceOfAbi,
4602
+ functionName: "balanceOf",
4603
+ args: [params.account]
4604
+ });
4605
+ return {
4606
+ ...token,
4607
+ raw,
4608
+ formatted: formatUnits(raw, token.decimals),
4609
+ status: "ready"
4610
+ };
4611
+ } catch (error) {
4612
+ return {
4613
+ ...token,
4614
+ raw: null,
4615
+ formatted: null,
4616
+ status: "error",
4617
+ error: error instanceof Error ? error.message : "Balance read failed"
4618
+ };
4619
+ }
4620
+ })
4621
+ );
4622
+ }
4623
+
4624
+ // ../connect-sdk/src/families.ts
4625
+ function withoutTrailingSlash(value) {
4626
+ return value.replace(/\/+$/, "");
4627
+ }
4628
+ async function errorMessage(response) {
4629
+ const body = await response.text().catch(() => "");
4630
+ const parsed = body ? (() => {
4631
+ try {
4632
+ return JSON.parse(body);
4633
+ } catch {
4634
+ return null;
4635
+ }
4636
+ })() : null;
4637
+ return (parsed?.error ?? parsed?.message ?? body.trim()) || `Request failed with ${response.status}`;
4638
+ }
4639
+ function createFluentFamiliesClient(config) {
4640
+ const fetcher = config.fetch ?? globalThis.fetch;
4641
+ const baseUrl = withoutTrailingSlash(config.baseUrl);
4642
+ return {
4643
+ async getFamilies(privyId) {
4644
+ const normalizedPrivyId = privyId.trim();
4645
+ if (!normalizedPrivyId) {
4646
+ throw new Error("Privy ID is required");
4647
+ }
4648
+ const endpoint = new URL(`${baseUrl}/profile/families/`);
4649
+ endpoint.searchParams.set("privy_id", normalizedPrivyId);
4650
+ const response = await fetcher(endpoint.toString());
4651
+ if (!response.ok) {
4652
+ throw new Error(await errorMessage(response));
4653
+ }
4654
+ const result = await response.json();
4655
+ return {
4656
+ xHandle: result.x_handle,
4657
+ families: result.families
4658
+ };
4659
+ }
4660
+ };
4661
+ }
4662
+ var AMOUNT_SHAPE = /^\d*(\.\d*)?$/;
4663
+ var ADDRESS_SHAPE = /^0x[0-9a-fA-F]{40}$/;
4664
+ var fluentTransferAbi = parseAbi([
4665
+ "function transfer(address to, uint256 amount) returns (bool)"
4666
+ ]);
4667
+ function parseFluentTransferRecipient(params) {
4668
+ const trimmed = params.input.trim();
4669
+ if (!trimmed) return { status: "empty" };
4670
+ if (!ADDRESS_SHAPE.test(trimmed)) {
4671
+ return {
4672
+ status: "rejected",
4673
+ message: "That\u2019s not a valid Fluent address. It should start with 0x."
4674
+ };
4675
+ }
4676
+ if (!isAddress(trimmed)) {
4677
+ return {
4678
+ status: "rejected",
4679
+ message: "This address fails its checksum. Check it for a typo."
4680
+ };
4681
+ }
4682
+ const lowercased = trimmed.toLowerCase();
4683
+ if (params.self && params.self.toLowerCase() === lowercased) {
4684
+ return { status: "rejected", message: "This is the address you are sending from." };
4685
+ }
4686
+ if (params.contracts?.has(lowercased)) {
4687
+ return {
4688
+ status: "rejected",
4689
+ message: "This is a token's contract address, not a wallet. Tokens sent there are lost."
4690
+ };
4691
+ }
4692
+ return { status: "ok", address: trimmed };
4693
+ }
4694
+ function parseFluentTransferAmount(params) {
4695
+ const trimmed = params.input.trim();
4696
+ if (!trimmed) return { status: "empty" };
4697
+ if (trimmed.includes(",")) {
4698
+ return { status: "rejected", message: "Use a dot for the decimal point." };
4699
+ }
4700
+ if (!AMOUNT_SHAPE.test(trimmed) || !/\d/.test(trimmed)) {
4701
+ return { status: "rejected", message: "Enter the amount as a number, like 12.5." };
4702
+ }
4703
+ const fraction = trimmed.split(".")[1] ?? "";
4704
+ if (fraction.length > params.decimals) {
4705
+ return {
4706
+ status: "rejected",
4707
+ message: params.decimals === 0 ? `${params.symbol} cannot be split \u2014 enter a whole number.` : `${params.symbol} has ${params.decimals} decimals. Use at most that many.`
4708
+ };
4709
+ }
4710
+ const raw = parseUnits(trimmed, params.decimals);
4711
+ if (raw === 0n) {
4712
+ return { status: "rejected", message: "Enter an amount greater than 0." };
4713
+ }
4714
+ if (raw > params.balance) {
4715
+ return { status: "rejected", message: `Amount exceeds your ${params.symbol} balance.` };
4716
+ }
4717
+ return { status: "ok", raw };
4718
+ }
4719
+ function buildFluentTransferCall(params) {
4720
+ const { token, to, amount } = params;
4721
+ const label = `Send ${token.symbol}`;
4722
+ if (isFluentNativeToken(token)) {
4723
+ return { id: "fluent-send-token", label, to, value: amount, data: "0x" };
4724
+ }
4725
+ if (!token.address) {
4726
+ throw new Error(`${token.symbol} has no contract address on this network`);
4727
+ }
4728
+ return {
4729
+ id: "fluent-send-token",
4730
+ label,
4731
+ to: token.address,
4732
+ abi: fluentTransferAbi,
4733
+ method: "transfer",
4734
+ args: [to, amount]
4735
+ };
4736
+ }
4737
+
4738
+ // src/core/network.ts
4739
+ var FLUENT_NETWORK_ALIASES = {
4740
+ testnet: "testnet",
4741
+ mainnet: "mainnet",
4742
+ development: "testnet",
4743
+ dev: "testnet",
4744
+ production: "mainnet",
4745
+ prod: "mainnet"
4746
+ };
4747
+ function normalizeFluentWidgetNetwork(value) {
4748
+ if (!value) return void 0;
4749
+ return FLUENT_NETWORK_ALIASES[value.trim().toLowerCase()];
4750
+ }
4751
+ function isFaucetNetwork(network) {
4752
+ return network === "testnet";
4753
+ }
4754
+ function getFluentChainForNetwork(network) {
4755
+ switch (network) {
4756
+ case "mainnet":
4757
+ return fluentMainnet;
4758
+ default:
4759
+ return fluentTestnet;
4760
+ }
4761
+ }
4762
+ function getFluentExplorerBaseUrl(network) {
4763
+ return getFluentChainForNetwork(network).blockExplorers?.default.url;
4764
+ }
4765
+
4766
+ // src/utils/buildFluentBridgeUrl.ts
4767
+ function buildFluentBridgeUrl(bridgeUrl, recipient) {
4768
+ if (!recipient) return bridgeUrl;
4769
+ try {
4770
+ const url = new URL(bridgeUrl);
4771
+ url.searchParams.set("recipient", recipient);
4772
+ return url.toString();
4773
+ } catch {
4774
+ const join = bridgeUrl.includes("?") ? "&" : "?";
4775
+ return `${bridgeUrl}${join}recipient=${encodeURIComponent(recipient)}`;
4776
+ }
4777
+ }
4778
+
4779
+ export { buildFluentBridgeUrl, buildFluentTransferCall, createFluentFamiliesClient, fluentMainnetTokenDefaults, fluentTestnetTokenDefaults, fluentTokenIdentity, fluentTransferAbi, getFluentDefaultWidgetDisplayTokens, getFluentExplorerBaseUrl, getFluentTokenDefaultsForNetwork, isFaucetNetwork, isFluentNativeToken, normalizeFluentWidgetNetwork, parseFluentTransferAmount, parseFluentTransferRecipient, readFluentTokenBalances };
4780
+ //# sourceMappingURL=internal.js.map
4781
+ //# sourceMappingURL=internal.js.map