@columnus/shared 0.1.59 → 0.1.60

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