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