@rhei-team/rhei 1.0.0-beta.0

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