@pushary/agent-hooks 1.9.62 → 1.9.63

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