@ray-js/robot-data-stream 0.0.14 → 0.0.15-beta.1

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 (156) hide show
  1. package/lib/mqtt/createCommonOptions.d.ts +4 -2
  2. package/lib/mqtt/createCommonOptions.js +10 -5
  3. package/lib/mqtt/hooks/useStructuredMessage.d.ts +14 -0
  4. package/lib/mqtt/hooks/useStructuredMessage.js +131 -0
  5. package/lib/mqtt/mqttProvider.d.ts +19 -1
  6. package/lib/mqtt/mqttProvider.js +69 -8
  7. package/lib/mqtt/promise.d.ts +57 -4
  8. package/lib/mqtt/promise.js +115 -36
  9. package/lib/mqtt/type/fun.d.ts +49 -0
  10. package/lib/mqtt/type/fun.js +145 -0
  11. package/lib/mqtt/type/index.d.ts +0 -7
  12. package/lib/mqtt/type/index.js +0 -1
  13. package/lib/mqtt/type/protocols/base.d.ts +5 -0
  14. package/lib/mqtt/type/protocols/base.js +32 -0
  15. package/lib/mqtt/type/protocols/carpetCleanProtocol.d.ts +8 -0
  16. package/lib/mqtt/type/protocols/carpetCleanProtocol.js +16 -0
  17. package/lib/mqtt/type/protocols/carpetProtocol.d.ts +41 -0
  18. package/lib/mqtt/type/protocols/carpetProtocol.js +202 -0
  19. package/lib/mqtt/type/protocols/devInfoProtocol.d.ts +5 -0
  20. package/lib/mqtt/type/protocols/devInfoProtocol.js +12 -0
  21. package/lib/mqtt/type/protocols/deviceModelProtocol.d.ts +8 -0
  22. package/lib/mqtt/type/protocols/deviceModelProtocol.js +34 -0
  23. package/lib/mqtt/type/protocols/furnitureModelProtocol.d.ts +10 -0
  24. package/lib/mqtt/type/protocols/furnitureModelProtocol.js +35 -0
  25. package/lib/mqtt/type/protocols/historyMapProtocol.d.ts +17 -0
  26. package/lib/mqtt/type/protocols/historyMapProtocol.js +37 -0
  27. package/lib/mqtt/type/protocols/index.d.ts +20 -0
  28. package/lib/mqtt/type/protocols/index.js +20 -0
  29. package/lib/mqtt/type/protocols/partDivisionProtocol.d.ts +8 -0
  30. package/lib/mqtt/type/protocols/partDivisionProtocol.js +12 -0
  31. package/lib/mqtt/type/protocols/partMergeProtocol.d.ts +7 -0
  32. package/lib/mqtt/type/protocols/partMergeProtocol.js +12 -0
  33. package/lib/mqtt/type/protocols/passwordProtocol.d.ts +11 -0
  34. package/lib/mqtt/type/protocols/passwordProtocol.js +25 -0
  35. package/lib/mqtt/type/protocols/quietHoursProtocol.d.ts +8 -0
  36. package/lib/mqtt/type/protocols/quietHoursProtocol.js +35 -0
  37. package/lib/mqtt/type/protocols/resetMapProtocol.d.ts +4 -0
  38. package/lib/mqtt/type/protocols/resetMapProtocol.js +1 -0
  39. package/lib/mqtt/type/protocols/roomPropertyProtocol.d.ts +14 -0
  40. package/lib/mqtt/type/protocols/roomPropertyProtocol.js +113 -0
  41. package/lib/mqtt/type/protocols/scheduleProtocol.d.ts +18 -0
  42. package/lib/mqtt/type/protocols/scheduleProtocol.js +100 -0
  43. package/lib/mqtt/type/protocols/selectRoomCleanProtocol.d.ts +8 -0
  44. package/lib/mqtt/type/protocols/selectRoomCleanProtocol.js +40 -0
  45. package/lib/mqtt/type/protocols/spotCleanProtocol.d.ts +9 -0
  46. package/lib/mqtt/type/protocols/spotCleanProtocol.js +72 -0
  47. package/lib/mqtt/type/protocols/virtualAreaProtocol.d.ts +8 -0
  48. package/lib/mqtt/type/protocols/virtualAreaProtocol.js +36 -0
  49. package/lib/mqtt/type/protocols/virtualWallProtocol.d.ts +8 -0
  50. package/lib/mqtt/type/protocols/virtualWallProtocol.js +25 -0
  51. package/lib/mqtt/type/protocols/voiceProtocol.d.ts +8 -0
  52. package/lib/mqtt/type/protocols/voiceProtocol.js +23 -0
  53. package/lib/mqtt/type/protocols/wifiMapProtocol.d.ts +8 -0
  54. package/lib/mqtt/type/protocols/wifiMapProtocol.js +14 -0
  55. package/lib/mqtt/type/protocols/zoneCleanProtocol.d.ts +8 -0
  56. package/lib/mqtt/type/protocols/zoneCleanProtocol.js +49 -0
  57. package/lib/mqtt/useCarpet.d.ts +7 -67
  58. package/lib/mqtt/useCarpet.js +101 -181
  59. package/lib/mqtt/useCarpetClean.d.ts +2 -11
  60. package/lib/mqtt/useCarpetClean.js +24 -51
  61. package/lib/mqtt/useDevInfo.d.ts +8 -6
  62. package/lib/mqtt/useDevInfo.js +44 -36
  63. package/lib/mqtt/useDeviceModel.d.ts +6 -19
  64. package/lib/mqtt/useDeviceModel.js +29 -42
  65. package/lib/mqtt/useFurnitureModel.d.ts +6 -18
  66. package/lib/mqtt/useFurnitureModel.js +29 -43
  67. package/lib/mqtt/useHistoryMap.d.ts +2 -18
  68. package/lib/mqtt/useHistoryMap.js +102 -119
  69. package/lib/mqtt/usePartDivision.d.ts +2 -9
  70. package/lib/mqtt/usePartDivision.js +48 -57
  71. package/lib/mqtt/usePartMerge.d.ts +2 -8
  72. package/lib/mqtt/usePartMerge.js +34 -49
  73. package/lib/mqtt/usePassword.d.ts +6 -13
  74. package/lib/mqtt/usePassword.js +84 -74
  75. package/lib/mqtt/useQuiteHours.d.ts +4 -37
  76. package/lib/mqtt/useQuiteHours.js +66 -100
  77. package/lib/mqtt/useResetMap.d.ts +2 -8
  78. package/lib/mqtt/useResetMap.js +27 -34
  79. package/lib/mqtt/useRoomProperty.d.ts +8 -9
  80. package/lib/mqtt/useRoomProperty.js +67 -65
  81. package/lib/mqtt/useSchedule.d.ts +3 -23
  82. package/lib/mqtt/useSchedule.js +72 -101
  83. package/lib/mqtt/useSelectRoomClean.d.ts +3 -24
  84. package/lib/mqtt/useSelectRoomClean.js +107 -133
  85. package/lib/mqtt/useSpotClean.d.ts +5 -15
  86. package/lib/mqtt/useSpotClean.js +68 -121
  87. package/lib/mqtt/useVirtualArea.d.ts +6 -17
  88. package/lib/mqtt/useVirtualArea.js +109 -119
  89. package/lib/mqtt/useVirtualWall.d.ts +2 -18
  90. package/lib/mqtt/useVirtualWall.js +69 -90
  91. package/lib/mqtt/useVoice.d.ts +2 -16
  92. package/lib/mqtt/useVoice.js +48 -68
  93. package/lib/mqtt/useWifiMap.d.ts +6 -5
  94. package/lib/mqtt/useWifiMap.js +43 -42
  95. package/lib/mqtt/useZoneClean.d.ts +2 -21
  96. package/lib/mqtt/useZoneClean.js +125 -137
  97. package/lib/myLib/zod/mini/index.d.cts +1 -0
  98. package/lib/myLib/zod/mini/index.d.ts +1 -0
  99. package/lib/myLib/zod/mini/index.js +1 -0
  100. package/lib/myLib/zod/mini/package.json +6 -0
  101. package/lib/myLib/zod/src/mini/index.d.ts +1 -0
  102. package/lib/myLib/zod/src/mini/index.js +1 -0
  103. package/lib/myLib/zod/src/v4/core/api.d.ts +306 -0
  104. package/lib/myLib/zod/src/v4/core/api.js +1256 -0
  105. package/lib/myLib/zod/src/v4/core/checks.d.ts +278 -0
  106. package/lib/myLib/zod/src/v4/core/checks.js +816 -0
  107. package/lib/myLib/zod/src/v4/core/config.d.ts +9 -0
  108. package/lib/myLib/zod/src/v4/core/config.js +5 -0
  109. package/lib/myLib/zod/src/v4/core/core.d.ts +70 -0
  110. package/lib/myLib/zod/src/v4/core/core.js +95 -0
  111. package/lib/myLib/zod/src/v4/core/doc.d.ts +14 -0
  112. package/lib/myLib/zod/src/v4/core/doc.js +42 -0
  113. package/lib/myLib/zod/src/v4/core/errors.d.ts +220 -0
  114. package/lib/myLib/zod/src/v4/core/errors.js +232 -0
  115. package/lib/myLib/zod/src/v4/core/index.d.ts +15 -0
  116. package/lib/myLib/zod/src/v4/core/index.js +15 -0
  117. package/lib/myLib/zod/src/v4/core/json-schema-generator.d.ts +65 -0
  118. package/lib/myLib/zod/src/v4/core/json-schema-generator.js +120 -0
  119. package/lib/myLib/zod/src/v4/core/json-schema-processors.d.ts +49 -0
  120. package/lib/myLib/zod/src/v4/core/json-schema-processors.js +593 -0
  121. package/lib/myLib/zod/src/v4/core/json-schema.d.ts +88 -0
  122. package/lib/myLib/zod/src/v4/core/json-schema.js +1 -0
  123. package/lib/myLib/zod/src/v4/core/parse.d.ts +49 -0
  124. package/lib/myLib/zod/src/v4/core/parse.js +147 -0
  125. package/lib/myLib/zod/src/v4/core/regexes.d.ts +78 -0
  126. package/lib/myLib/zod/src/v4/core/regexes.js +146 -0
  127. package/lib/myLib/zod/src/v4/core/registries.d.ts +35 -0
  128. package/lib/myLib/zod/src/v4/core/registries.js +51 -0
  129. package/lib/myLib/zod/src/v4/core/schemas.d.ts +1136 -0
  130. package/lib/myLib/zod/src/v4/core/schemas.js +2745 -0
  131. package/lib/myLib/zod/src/v4/core/standard-schema.d.ts +126 -0
  132. package/lib/myLib/zod/src/v4/core/standard-schema.js +1 -0
  133. package/lib/myLib/zod/src/v4/core/to-json-schema.d.ts +114 -0
  134. package/lib/myLib/zod/src/v4/core/to-json-schema.js +488 -0
  135. package/lib/myLib/zod/src/v4/core/util.d.ts +199 -0
  136. package/lib/myLib/zod/src/v4/core/util.js +656 -0
  137. package/lib/myLib/zod/src/v4/core/versions.d.ts +5 -0
  138. package/lib/myLib/zod/src/v4/core/versions.js +5 -0
  139. package/lib/myLib/zod/src/v4/core/zsf.d.ts +91 -0
  140. package/lib/myLib/zod/src/v4/core/zsf.js +1 -0
  141. package/lib/myLib/zod/src/v4/mini/checks.d.ts +1 -0
  142. package/lib/myLib/zod/src/v4/mini/checks.js +1 -0
  143. package/lib/myLib/zod/src/v4/mini/coerce.d.ts +7 -0
  144. package/lib/myLib/zod/src/v4/mini/coerce.js +27 -0
  145. package/lib/myLib/zod/src/v4/mini/external.d.ts +11 -0
  146. package/lib/myLib/zod/src/v4/mini/external.js +16 -0
  147. package/lib/myLib/zod/src/v4/mini/index.d.ts +3 -0
  148. package/lib/myLib/zod/src/v4/mini/index.js +3 -0
  149. package/lib/myLib/zod/src/v4/mini/iso.d.ts +22 -0
  150. package/lib/myLib/zod/src/v4/mini/iso.js +46 -0
  151. package/lib/myLib/zod/src/v4/mini/parse.d.ts +1 -0
  152. package/lib/myLib/zod/src/v4/mini/parse.js +1 -0
  153. package/lib/myLib/zod/src/v4/mini/schemas.js +1244 -0
  154. package/lib/utils/index.d.ts +1 -0
  155. package/lib/utils/index.js +2 -1
  156. package/package.json +5 -3
@@ -0,0 +1,2745 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import "core-js/modules/esnext.iterator.constructor.js";
3
+ import "core-js/modules/esnext.iterator.every.js";
4
+ import "core-js/modules/esnext.iterator.filter.js";
5
+ import "core-js/modules/esnext.iterator.flat-map.js";
6
+ import "core-js/modules/esnext.iterator.map.js";
7
+ import "core-js/modules/esnext.iterator.some.js";
8
+ import * as checks from "./checks.js";
9
+ import * as core from "./core.js";
10
+ import { Doc } from "./doc.js";
11
+ import { parse, parseAsync, safeParse, safeParseAsync } from "./parse.js";
12
+ import * as regexes from "./regexes.js";
13
+ import * as util from "./util.js";
14
+ import { version } from "./versions.js";
15
+
16
+ ///////////////////////////// PARSE //////////////////////////////
17
+
18
+ /** @internal */
19
+
20
+ ///////////////////////////// SCHEMAS //////////////////////////////
21
+
22
+ /** @internal */
23
+
24
+ export const $ZodType = /*@__PURE__*/core.$constructor("$ZodType", (inst, def) => {
25
+ var _inst$_zod$def$checks;
26
+ inst ??= {};
27
+ inst._zod.def = def; // set _def property
28
+ inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
29
+ inst._zod.version = version;
30
+ const checks = [...((_inst$_zod$def$checks = inst._zod.def.checks) !== null && _inst$_zod$def$checks !== void 0 ? _inst$_zod$def$checks : [])];
31
+
32
+ // if inst is itself a checks.$ZodCheck, run it as a check
33
+ if (inst._zod.traits.has("$ZodCheck")) {
34
+ checks.unshift(inst);
35
+ }
36
+ for (const ch of checks) {
37
+ for (const fn of ch._zod.onattach) {
38
+ fn(inst);
39
+ }
40
+ }
41
+ if (checks.length === 0) {
42
+ var _inst$_zod$deferred;
43
+ // deferred initializer
44
+ // inst._zod.parse is not yet defined
45
+ inst._zod.deferred ??= [];
46
+ (_inst$_zod$deferred = inst._zod.deferred) === null || _inst$_zod$deferred === void 0 || _inst$_zod$deferred.push(() => {
47
+ inst._zod.run = inst._zod.parse;
48
+ });
49
+ } else {
50
+ const runChecks = (payload, checks, ctx) => {
51
+ let isAborted = util.aborted(payload);
52
+ let asyncResult;
53
+ for (const ch of checks) {
54
+ if (ch._zod.def.when) {
55
+ const shouldRun = ch._zod.def.when(payload);
56
+ if (!shouldRun) continue;
57
+ } else if (isAborted) {
58
+ continue;
59
+ }
60
+ const currLen = payload.issues.length;
61
+ const _ = ch._zod.check(payload);
62
+ if (_ instanceof Promise && (ctx === null || ctx === void 0 ? void 0 : ctx.async) === false) {
63
+ throw new core.$ZodAsyncError();
64
+ }
65
+ if (asyncResult || _ instanceof Promise) {
66
+ var _asyncResult;
67
+ asyncResult = ((_asyncResult = asyncResult) !== null && _asyncResult !== void 0 ? _asyncResult : Promise.resolve()).then(async () => {
68
+ await _;
69
+ const nextLen = payload.issues.length;
70
+ if (nextLen === currLen) return;
71
+ if (!isAborted) isAborted = util.aborted(payload, currLen);
72
+ });
73
+ } else {
74
+ const nextLen = payload.issues.length;
75
+ if (nextLen === currLen) continue;
76
+ if (!isAborted) isAborted = util.aborted(payload, currLen);
77
+ }
78
+ }
79
+ if (asyncResult) {
80
+ return asyncResult.then(() => {
81
+ return payload;
82
+ });
83
+ }
84
+ return payload;
85
+ };
86
+ const handleCanaryResult = (canary, payload, ctx) => {
87
+ // abort if the canary is aborted
88
+ if (util.aborted(canary)) {
89
+ canary.aborted = true;
90
+ return canary;
91
+ }
92
+
93
+ // run checks first, then
94
+ const checkResult = runChecks(payload, checks, ctx);
95
+ if (checkResult instanceof Promise) {
96
+ if (ctx.async === false) throw new core.$ZodAsyncError();
97
+ return checkResult.then(checkResult => inst._zod.parse(checkResult, ctx));
98
+ }
99
+ return inst._zod.parse(checkResult, ctx);
100
+ };
101
+ inst._zod.run = (payload, ctx) => {
102
+ if (ctx.skipChecks) {
103
+ return inst._zod.parse(payload, ctx);
104
+ }
105
+ if (ctx.direction === "backward") {
106
+ // run canary
107
+ // initial pass (no checks)
108
+ const canary = inst._zod.parse({
109
+ value: payload.value,
110
+ issues: []
111
+ }, _objectSpread(_objectSpread({}, ctx), {}, {
112
+ skipChecks: true
113
+ }));
114
+ if (canary instanceof Promise) {
115
+ return canary.then(canary => {
116
+ return handleCanaryResult(canary, payload, ctx);
117
+ });
118
+ }
119
+ return handleCanaryResult(canary, payload, ctx);
120
+ }
121
+
122
+ // forward
123
+ const result = inst._zod.parse(payload, ctx);
124
+ if (result instanceof Promise) {
125
+ if (ctx.async === false) throw new core.$ZodAsyncError();
126
+ return result.then(result => runChecks(result, checks, ctx));
127
+ }
128
+ return runChecks(result, checks, ctx);
129
+ };
130
+ }
131
+
132
+ // Lazy initialize ~standard to avoid creating objects for every schema
133
+ util.defineLazy(inst, "~standard", () => ({
134
+ validate: value => {
135
+ try {
136
+ var _r$error;
137
+ const r = safeParse(inst, value);
138
+ return r.success ? {
139
+ value: r.data
140
+ } : {
141
+ issues: (_r$error = r.error) === null || _r$error === void 0 ? void 0 : _r$error.issues
142
+ };
143
+ } catch (_) {
144
+ return safeParseAsync(inst, value).then(r => {
145
+ var _r$error2;
146
+ return r.success ? {
147
+ value: r.data
148
+ } : {
149
+ issues: (_r$error2 = r.error) === null || _r$error2 === void 0 ? void 0 : _r$error2.issues
150
+ };
151
+ });
152
+ }
153
+ },
154
+ vendor: "zod",
155
+ version: 1
156
+ }));
157
+ });
158
+ export { clone } from "./util.js";
159
+
160
+ //////////////////////////////////////////
161
+ //////////////////////////////////////////
162
+ ////////// //////////
163
+ ////////// $ZodString //////////
164
+ ////////// //////////
165
+ //////////////////////////////////////////
166
+ //////////////////////////////////////////
167
+
168
+ export const $ZodString = /*@__PURE__*/core.$constructor("$ZodString", (inst, def) => {
169
+ var _pop, _inst$_zod$bag$patter, _inst$_zod$bag;
170
+ $ZodType.init(inst, def);
171
+ inst._zod.pattern = (_pop = [...((_inst$_zod$bag$patter = inst === null || inst === void 0 || (_inst$_zod$bag = inst._zod.bag) === null || _inst$_zod$bag === void 0 ? void 0 : _inst$_zod$bag.patterns) !== null && _inst$_zod$bag$patter !== void 0 ? _inst$_zod$bag$patter : [])].pop()) !== null && _pop !== void 0 ? _pop : regexes.string(inst._zod.bag);
172
+ inst._zod.parse = payload => {
173
+ if (def.coerce) try {
174
+ payload.value = String(payload.value);
175
+ } catch (_) {}
176
+ if (typeof payload.value === "string") return payload;
177
+ payload.issues.push({
178
+ expected: "string",
179
+ code: "invalid_type",
180
+ input: payload.value,
181
+ inst
182
+ });
183
+ return payload;
184
+ };
185
+ });
186
+
187
+ ////////////////////////////// ZodStringFormat //////////////////////////////
188
+
189
+ export const $ZodStringFormat = /*@__PURE__*/core.$constructor("$ZodStringFormat", (inst, def) => {
190
+ // check initialization must come first
191
+ checks.$ZodCheckStringFormat.init(inst, def);
192
+ $ZodString.init(inst, def);
193
+ });
194
+
195
+ ////////////////////////////// ZodGUID //////////////////////////////
196
+
197
+ export const $ZodGUID = /*@__PURE__*/core.$constructor("$ZodGUID", (inst, def) => {
198
+ def.pattern ??= regexes.guid;
199
+ $ZodStringFormat.init(inst, def);
200
+ });
201
+
202
+ ////////////////////////////// ZodUUID //////////////////////////////
203
+
204
+ export const $ZodUUID = /*@__PURE__*/core.$constructor("$ZodUUID", (inst, def) => {
205
+ if (def.version) {
206
+ const v = {
207
+ v1: 1,
208
+ v2: 2,
209
+ v3: 3,
210
+ v4: 4,
211
+ v5: 5,
212
+ v6: 6,
213
+ v7: 7,
214
+ v8: 8
215
+ }[def.version];
216
+ if (v === undefined) throw new Error(`Invalid UUID version: "${def.version}"`);
217
+ def.pattern ??= regexes.uuid(v);
218
+ } else def.pattern ??= regexes.uuid();
219
+ $ZodStringFormat.init(inst, def);
220
+ });
221
+
222
+ ////////////////////////////// ZodEmail //////////////////////////////
223
+
224
+ export const $ZodEmail = /*@__PURE__*/core.$constructor("$ZodEmail", (inst, def) => {
225
+ def.pattern ??= regexes.email;
226
+ $ZodStringFormat.init(inst, def);
227
+ });
228
+
229
+ ////////////////////////////// ZodURL //////////////////////////////
230
+
231
+ export const $ZodURL = /*@__PURE__*/core.$constructor("$ZodURL", (inst, def) => {
232
+ $ZodStringFormat.init(inst, def);
233
+ inst._zod.check = payload => {
234
+ try {
235
+ // Trim whitespace from input
236
+ const trimmed = payload.value.trim();
237
+ // @ts-ignore
238
+ const url = new URL(trimmed);
239
+ if (def.hostname) {
240
+ def.hostname.lastIndex = 0;
241
+ if (!def.hostname.test(url.hostname)) {
242
+ payload.issues.push({
243
+ code: "invalid_format",
244
+ format: "url",
245
+ note: "Invalid hostname",
246
+ pattern: def.hostname.source,
247
+ input: payload.value,
248
+ inst,
249
+ continue: !def.abort
250
+ });
251
+ }
252
+ }
253
+ if (def.protocol) {
254
+ def.protocol.lastIndex = 0;
255
+ if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) {
256
+ payload.issues.push({
257
+ code: "invalid_format",
258
+ format: "url",
259
+ note: "Invalid protocol",
260
+ pattern: def.protocol.source,
261
+ input: payload.value,
262
+ inst,
263
+ continue: !def.abort
264
+ });
265
+ }
266
+ }
267
+
268
+ // Set the output value based on normalize flag
269
+ if (def.normalize) {
270
+ // Use normalized URL
271
+ payload.value = url.href;
272
+ } else {
273
+ // Preserve the original input (trimmed)
274
+ payload.value = trimmed;
275
+ }
276
+ } catch (_) {
277
+ payload.issues.push({
278
+ code: "invalid_format",
279
+ format: "url",
280
+ input: payload.value,
281
+ inst,
282
+ continue: !def.abort
283
+ });
284
+ }
285
+ };
286
+ });
287
+
288
+ ////////////////////////////// ZodNanoID //////////////////////////////
289
+
290
+ export const $ZodNanoID = /*@__PURE__*/core.$constructor("$ZodNanoID", (inst, def) => {
291
+ def.pattern ??= regexes.nanoid;
292
+ $ZodStringFormat.init(inst, def);
293
+ });
294
+
295
+ ////////////////////////////// ZodCUID //////////////////////////////
296
+
297
+ export const $ZodCUID = /*@__PURE__*/core.$constructor("$ZodCUID", (inst, def) => {
298
+ def.pattern ??= regexes.cuid;
299
+ $ZodStringFormat.init(inst, def);
300
+ });
301
+
302
+ ////////////////////////////// ZodCUID2 //////////////////////////////
303
+
304
+ export const $ZodCUID2 = /*@__PURE__*/core.$constructor("$ZodCUID2", (inst, def) => {
305
+ def.pattern ??= regexes.cuid2;
306
+ $ZodStringFormat.init(inst, def);
307
+ });
308
+
309
+ ////////////////////////////// ZodULID //////////////////////////////
310
+
311
+ export const $ZodULID = /*@__PURE__*/core.$constructor("$ZodULID", (inst, def) => {
312
+ def.pattern ??= regexes.ulid;
313
+ $ZodStringFormat.init(inst, def);
314
+ });
315
+
316
+ ////////////////////////////// ZodXID //////////////////////////////
317
+
318
+ export const $ZodXID = /*@__PURE__*/core.$constructor("$ZodXID", (inst, def) => {
319
+ def.pattern ??= regexes.xid;
320
+ $ZodStringFormat.init(inst, def);
321
+ });
322
+
323
+ ////////////////////////////// ZodKSUID //////////////////////////////
324
+
325
+ export const $ZodKSUID = /*@__PURE__*/core.$constructor("$ZodKSUID", (inst, def) => {
326
+ def.pattern ??= regexes.ksuid;
327
+ $ZodStringFormat.init(inst, def);
328
+ });
329
+
330
+ ////////////////////////////// ZodISODateTime //////////////////////////////
331
+
332
+ export const $ZodISODateTime = /*@__PURE__*/core.$constructor("$ZodISODateTime", (inst, def) => {
333
+ def.pattern ??= regexes.datetime(def);
334
+ $ZodStringFormat.init(inst, def);
335
+ });
336
+
337
+ ////////////////////////////// ZodISODate //////////////////////////////
338
+
339
+ export const $ZodISODate = /*@__PURE__*/core.$constructor("$ZodISODate", (inst, def) => {
340
+ def.pattern ??= regexes.date;
341
+ $ZodStringFormat.init(inst, def);
342
+ });
343
+
344
+ ////////////////////////////// ZodISOTime //////////////////////////////
345
+
346
+ export const $ZodISOTime = /*@__PURE__*/core.$constructor("$ZodISOTime", (inst, def) => {
347
+ def.pattern ??= regexes.time(def);
348
+ $ZodStringFormat.init(inst, def);
349
+ });
350
+
351
+ ////////////////////////////// ZodISODuration //////////////////////////////
352
+
353
+ export const $ZodISODuration = /*@__PURE__*/core.$constructor("$ZodISODuration", (inst, def) => {
354
+ def.pattern ??= regexes.duration;
355
+ $ZodStringFormat.init(inst, def);
356
+ });
357
+
358
+ ////////////////////////////// ZodIPv4 //////////////////////////////
359
+
360
+ export const $ZodIPv4 = /*@__PURE__*/core.$constructor("$ZodIPv4", (inst, def) => {
361
+ def.pattern ??= regexes.ipv4;
362
+ $ZodStringFormat.init(inst, def);
363
+ inst._zod.bag.format = `ipv4`;
364
+ });
365
+
366
+ ////////////////////////////// ZodIPv6 //////////////////////////////
367
+
368
+ export const $ZodIPv6 = /*@__PURE__*/core.$constructor("$ZodIPv6", (inst, def) => {
369
+ def.pattern ??= regexes.ipv6;
370
+ $ZodStringFormat.init(inst, def);
371
+ inst._zod.bag.format = `ipv6`;
372
+ inst._zod.check = payload => {
373
+ try {
374
+ // @ts-ignore
375
+ new URL(`http://[${payload.value}]`);
376
+ // return;
377
+ } catch {
378
+ payload.issues.push({
379
+ code: "invalid_format",
380
+ format: "ipv6",
381
+ input: payload.value,
382
+ inst,
383
+ continue: !def.abort
384
+ });
385
+ }
386
+ };
387
+ });
388
+
389
+ ////////////////////////////// ZodMAC //////////////////////////////
390
+
391
+ export const $ZodMAC = /*@__PURE__*/core.$constructor("$ZodMAC", (inst, def) => {
392
+ def.pattern ??= regexes.mac(def.delimiter);
393
+ $ZodStringFormat.init(inst, def);
394
+ inst._zod.bag.format = `mac`;
395
+ });
396
+
397
+ ////////////////////////////// ZodCIDRv4 //////////////////////////////
398
+
399
+ export const $ZodCIDRv4 = /*@__PURE__*/core.$constructor("$ZodCIDRv4", (inst, def) => {
400
+ def.pattern ??= regexes.cidrv4;
401
+ $ZodStringFormat.init(inst, def);
402
+ });
403
+
404
+ ////////////////////////////// ZodCIDRv6 //////////////////////////////
405
+
406
+ export const $ZodCIDRv6 = /*@__PURE__*/core.$constructor("$ZodCIDRv6", (inst, def) => {
407
+ def.pattern ??= regexes.cidrv6; // not used for validation
408
+ $ZodStringFormat.init(inst, def);
409
+ inst._zod.check = payload => {
410
+ const parts = payload.value.split("/");
411
+ try {
412
+ if (parts.length !== 2) throw new Error();
413
+ const [address, prefix] = parts;
414
+ if (!prefix) throw new Error();
415
+ const prefixNum = Number(prefix);
416
+ if (`${prefixNum}` !== prefix) throw new Error();
417
+ if (prefixNum < 0 || prefixNum > 128) throw new Error();
418
+ // @ts-ignore
419
+ new URL(`http://[${address}]`);
420
+ } catch {
421
+ payload.issues.push({
422
+ code: "invalid_format",
423
+ format: "cidrv6",
424
+ input: payload.value,
425
+ inst,
426
+ continue: !def.abort
427
+ });
428
+ }
429
+ };
430
+ });
431
+
432
+ ////////////////////////////// ZodBase64 //////////////////////////////
433
+ export function isValidBase64(data) {
434
+ if (data === "") return true;
435
+ if (data.length % 4 !== 0) return false;
436
+ try {
437
+ // @ts-ignore
438
+ atob(data);
439
+ return true;
440
+ } catch {
441
+ return false;
442
+ }
443
+ }
444
+ export const $ZodBase64 = /*@__PURE__*/core.$constructor("$ZodBase64", (inst, def) => {
445
+ def.pattern ??= regexes.base64;
446
+ $ZodStringFormat.init(inst, def);
447
+ inst._zod.bag.contentEncoding = "base64";
448
+ inst._zod.check = payload => {
449
+ if (isValidBase64(payload.value)) return;
450
+ payload.issues.push({
451
+ code: "invalid_format",
452
+ format: "base64",
453
+ input: payload.value,
454
+ inst,
455
+ continue: !def.abort
456
+ });
457
+ };
458
+ });
459
+
460
+ ////////////////////////////// ZodBase64 //////////////////////////////
461
+ export function isValidBase64URL(data) {
462
+ if (!regexes.base64url.test(data)) return false;
463
+ const base64 = data.replace(/[-_]/g, c => c === "-" ? "+" : "/");
464
+ const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
465
+ return isValidBase64(padded);
466
+ }
467
+ export const $ZodBase64URL = /*@__PURE__*/core.$constructor("$ZodBase64URL", (inst, def) => {
468
+ def.pattern ??= regexes.base64url;
469
+ $ZodStringFormat.init(inst, def);
470
+ inst._zod.bag.contentEncoding = "base64url";
471
+ inst._zod.check = payload => {
472
+ if (isValidBase64URL(payload.value)) return;
473
+ payload.issues.push({
474
+ code: "invalid_format",
475
+ format: "base64url",
476
+ input: payload.value,
477
+ inst,
478
+ continue: !def.abort
479
+ });
480
+ };
481
+ });
482
+
483
+ ////////////////////////////// ZodE164 //////////////////////////////
484
+
485
+ export const $ZodE164 = /*@__PURE__*/core.$constructor("$ZodE164", (inst, def) => {
486
+ def.pattern ??= regexes.e164;
487
+ $ZodStringFormat.init(inst, def);
488
+ });
489
+
490
+ ////////////////////////////// ZodJWT //////////////////////////////
491
+
492
+ export function isValidJWT(token) {
493
+ let algorithm = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
494
+ try {
495
+ const tokensParts = token.split(".");
496
+ if (tokensParts.length !== 3) return false;
497
+ const [header] = tokensParts;
498
+ if (!header) return false;
499
+ // @ts-ignore
500
+ const parsedHeader = JSON.parse(atob(header));
501
+ if ("typ" in parsedHeader && (parsedHeader === null || parsedHeader === void 0 ? void 0 : parsedHeader.typ) !== "JWT") return false;
502
+ if (!parsedHeader.alg) return false;
503
+ if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm)) return false;
504
+ return true;
505
+ } catch {
506
+ return false;
507
+ }
508
+ }
509
+ export const $ZodJWT = /*@__PURE__*/core.$constructor("$ZodJWT", (inst, def) => {
510
+ $ZodStringFormat.init(inst, def);
511
+ inst._zod.check = payload => {
512
+ if (isValidJWT(payload.value, def.alg)) return;
513
+ payload.issues.push({
514
+ code: "invalid_format",
515
+ format: "jwt",
516
+ input: payload.value,
517
+ inst,
518
+ continue: !def.abort
519
+ });
520
+ };
521
+ });
522
+
523
+ ////////////////////////////// ZodCustomStringFormat //////////////////////////////
524
+
525
+ export const $ZodCustomStringFormat = /*@__PURE__*/core.$constructor("$ZodCustomStringFormat", (inst, def) => {
526
+ $ZodStringFormat.init(inst, def);
527
+ inst._zod.check = payload => {
528
+ if (def.fn(payload.value)) return;
529
+ payload.issues.push({
530
+ code: "invalid_format",
531
+ format: def.format,
532
+ input: payload.value,
533
+ inst,
534
+ continue: !def.abort
535
+ });
536
+ };
537
+ });
538
+
539
+ /////////////////////////////////////////
540
+ /////////////////////////////////////////
541
+ ////////// //////////
542
+ ////////// ZodNumber //////////
543
+ ////////// //////////
544
+ /////////////////////////////////////////
545
+ /////////////////////////////////////////
546
+
547
+ export const $ZodNumber = /*@__PURE__*/core.$constructor("$ZodNumber", (inst, def) => {
548
+ var _inst$_zod$bag$patter2;
549
+ $ZodType.init(inst, def);
550
+ inst._zod.pattern = (_inst$_zod$bag$patter2 = inst._zod.bag.pattern) !== null && _inst$_zod$bag$patter2 !== void 0 ? _inst$_zod$bag$patter2 : regexes.number;
551
+ inst._zod.parse = payload => {
552
+ if (def.coerce) try {
553
+ payload.value = Number(payload.value);
554
+ } catch (_) {}
555
+ const input = payload.value;
556
+ if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) {
557
+ return payload;
558
+ }
559
+ const received = typeof input === "number" ? Number.isNaN(input) ? "NaN" : !Number.isFinite(input) ? "Infinity" : undefined : undefined;
560
+ payload.issues.push(_objectSpread({
561
+ expected: "number",
562
+ code: "invalid_type",
563
+ input,
564
+ inst
565
+ }, received ? {
566
+ received
567
+ } : {}));
568
+ return payload;
569
+ };
570
+ });
571
+
572
+ ///////////////////////////////////////////////
573
+ ////////// ZodNumberFormat //////////
574
+ ///////////////////////////////////////////////
575
+
576
+ export const $ZodNumberFormat = /*@__PURE__*/core.$constructor("$ZodNumberFormat", (inst, def) => {
577
+ checks.$ZodCheckNumberFormat.init(inst, def);
578
+ $ZodNumber.init(inst, def); // no format checks
579
+ });
580
+
581
+ ///////////////////////////////////////////
582
+ ///////////////////////////////////////////
583
+ ////////// ///////////
584
+ ////////// $ZodBoolean //////////
585
+ ////////// ///////////
586
+ ///////////////////////////////////////////
587
+ ///////////////////////////////////////////
588
+
589
+ export const $ZodBoolean = /*@__PURE__*/core.$constructor("$ZodBoolean", (inst, def) => {
590
+ $ZodType.init(inst, def);
591
+ inst._zod.pattern = regexes.boolean;
592
+ inst._zod.parse = payload => {
593
+ if (def.coerce) try {
594
+ payload.value = Boolean(payload.value);
595
+ } catch (_) {}
596
+ const input = payload.value;
597
+ if (typeof input === "boolean") return payload;
598
+ payload.issues.push({
599
+ expected: "boolean",
600
+ code: "invalid_type",
601
+ input,
602
+ inst
603
+ });
604
+ return payload;
605
+ };
606
+ });
607
+
608
+ //////////////////////////////////////////
609
+ //////////////////////////////////////////
610
+ ////////// //////////
611
+ ////////// $ZodBigInt //////////
612
+ ////////// //////////
613
+ //////////////////////////////////////////
614
+ //////////////////////////////////////////
615
+
616
+ export const $ZodBigInt = /*@__PURE__*/core.$constructor("$ZodBigInt", (inst, def) => {
617
+ $ZodType.init(inst, def);
618
+ inst._zod.pattern = regexes.bigint;
619
+ inst._zod.parse = payload => {
620
+ if (def.coerce) try {
621
+ payload.value = BigInt(payload.value);
622
+ } catch (_) {}
623
+ if (typeof payload.value === "bigint") return payload;
624
+ payload.issues.push({
625
+ expected: "bigint",
626
+ code: "invalid_type",
627
+ input: payload.value,
628
+ inst
629
+ });
630
+ return payload;
631
+ };
632
+ });
633
+
634
+ ///////////////////////////////////////////////
635
+ ////////// ZodBigIntFormat //////////
636
+ ///////////////////////////////////////////////
637
+
638
+ export const $ZodBigIntFormat = /*@__PURE__*/core.$constructor("$ZodBigIntFormat", (inst, def) => {
639
+ checks.$ZodCheckBigIntFormat.init(inst, def);
640
+ $ZodBigInt.init(inst, def); // no format checks
641
+ });
642
+
643
+ ////////////////////////////////////////////
644
+ ////////////////////////////////////////////
645
+ ////////// //////////
646
+ ////////// $ZodSymbol //////////
647
+ ////////// //////////
648
+ ////////////////////////////////////////////
649
+ ////////////////////////////////////////////
650
+
651
+ export const $ZodSymbol = /*@__PURE__*/core.$constructor("$ZodSymbol", (inst, def) => {
652
+ $ZodType.init(inst, def);
653
+ inst._zod.parse = payload => {
654
+ const input = payload.value;
655
+ if (typeof input === "symbol") return payload;
656
+ payload.issues.push({
657
+ expected: "symbol",
658
+ code: "invalid_type",
659
+ input,
660
+ inst
661
+ });
662
+ return payload;
663
+ };
664
+ });
665
+
666
+ ////////////////////////////////////////////
667
+ ////////////////////////////////////////////
668
+ ////////// //////////
669
+ ////////// $ZodUndefined //////////
670
+ ////////// //////////
671
+ ////////////////////////////////////////////
672
+ ////////////////////////////////////////////
673
+
674
+ export const $ZodUndefined = /*@__PURE__*/core.$constructor("$ZodUndefined", (inst, def) => {
675
+ $ZodType.init(inst, def);
676
+ inst._zod.pattern = regexes.undefined;
677
+ inst._zod.values = new Set([undefined]);
678
+ inst._zod.optin = "optional";
679
+ inst._zod.optout = "optional";
680
+ inst._zod.parse = payload => {
681
+ const input = payload.value;
682
+ if (typeof input === "undefined") return payload;
683
+ payload.issues.push({
684
+ expected: "undefined",
685
+ code: "invalid_type",
686
+ input,
687
+ inst
688
+ });
689
+ return payload;
690
+ };
691
+ });
692
+
693
+ ///////////////////////////////////////
694
+ ///////////////////////////////////////
695
+ ////////// //////////
696
+ ////////// $ZodNull /////////
697
+ ////////// //////////
698
+ ///////////////////////////////////////
699
+ ///////////////////////////////////////
700
+
701
+ export const $ZodNull = /*@__PURE__*/core.$constructor("$ZodNull", (inst, def) => {
702
+ $ZodType.init(inst, def);
703
+ inst._zod.pattern = regexes.null;
704
+ inst._zod.values = new Set([null]);
705
+ inst._zod.parse = payload => {
706
+ const input = payload.value;
707
+ if (input === null) return payload;
708
+ payload.issues.push({
709
+ expected: "null",
710
+ code: "invalid_type",
711
+ input,
712
+ inst
713
+ });
714
+ return payload;
715
+ };
716
+ });
717
+
718
+ //////////////////////////////////////
719
+ //////////////////////////////////////
720
+ ////////// //////////
721
+ ////////// $ZodAny //////////
722
+ ////////// //////////
723
+ //////////////////////////////////////
724
+ //////////////////////////////////////
725
+
726
+ export const $ZodAny = /*@__PURE__*/core.$constructor("$ZodAny", (inst, def) => {
727
+ $ZodType.init(inst, def);
728
+ inst._zod.parse = payload => payload;
729
+ });
730
+
731
+ //////////////////////////////////////////
732
+ //////////////////////////////////////////
733
+ ////////// //////////
734
+ ////////// $ZodUnknown //////////
735
+ ////////// //////////
736
+ //////////////////////////////////////////
737
+ //////////////////////////////////////////
738
+
739
+ export const $ZodUnknown = /*@__PURE__*/core.$constructor("$ZodUnknown", (inst, def) => {
740
+ $ZodType.init(inst, def);
741
+ inst._zod.parse = payload => payload;
742
+ });
743
+
744
+ /////////////////////////////////////////
745
+ /////////////////////////////////////////
746
+ ////////// //////////
747
+ ////////// $ZodNever //////////
748
+ ////////// //////////
749
+ /////////////////////////////////////////
750
+ /////////////////////////////////////////
751
+
752
+ export const $ZodNever = /*@__PURE__*/core.$constructor("$ZodNever", (inst, def) => {
753
+ $ZodType.init(inst, def);
754
+ inst._zod.parse = payload => {
755
+ payload.issues.push({
756
+ expected: "never",
757
+ code: "invalid_type",
758
+ input: payload.value,
759
+ inst
760
+ });
761
+ return payload;
762
+ };
763
+ });
764
+
765
+ ////////////////////////////////////////
766
+ ////////////////////////////////////////
767
+ ////////// //////////
768
+ ////////// $ZodVoid //////////
769
+ ////////// //////////
770
+ ////////////////////////////////////////
771
+ ////////////////////////////////////////
772
+
773
+ export const $ZodVoid = /*@__PURE__*/core.$constructor("$ZodVoid", (inst, def) => {
774
+ $ZodType.init(inst, def);
775
+ inst._zod.parse = payload => {
776
+ const input = payload.value;
777
+ if (typeof input === "undefined") return payload;
778
+ payload.issues.push({
779
+ expected: "void",
780
+ code: "invalid_type",
781
+ input,
782
+ inst
783
+ });
784
+ return payload;
785
+ };
786
+ });
787
+
788
+ ///////////////////////////////////////
789
+ ///////////////////////////////////////
790
+ ////////// ////////
791
+ ////////// $ZodDate ////////
792
+ ////////// ////////
793
+ ///////////////////////////////////////
794
+ ///////////////////////////////////////
795
+
796
+ export const $ZodDate = /*@__PURE__*/core.$constructor("$ZodDate", (inst, def) => {
797
+ $ZodType.init(inst, def);
798
+ inst._zod.parse = payload => {
799
+ if (def.coerce) {
800
+ try {
801
+ payload.value = new Date(payload.value);
802
+ } catch (_err) {}
803
+ }
804
+ const input = payload.value;
805
+ const isDate = input instanceof Date;
806
+ const isValidDate = isDate && !Number.isNaN(input.getTime());
807
+ if (isValidDate) return payload;
808
+ payload.issues.push(_objectSpread(_objectSpread({
809
+ expected: "date",
810
+ code: "invalid_type",
811
+ input
812
+ }, isDate ? {
813
+ received: "Invalid Date"
814
+ } : {}), {}, {
815
+ inst
816
+ }));
817
+ return payload;
818
+ };
819
+ });
820
+
821
+ /////////////////////////////////////////
822
+ /////////////////////////////////////////
823
+ ////////// //////////
824
+ ////////// $ZodArray //////////
825
+ ////////// //////////
826
+ /////////////////////////////////////////
827
+ /////////////////////////////////////////
828
+
829
+ function handleArrayResult(result, final, index) {
830
+ if (result.issues.length) {
831
+ final.issues.push(...util.prefixIssues(index, result.issues));
832
+ }
833
+ final.value[index] = result.value;
834
+ }
835
+ export const $ZodArray = /*@__PURE__*/core.$constructor("$ZodArray", (inst, def) => {
836
+ $ZodType.init(inst, def);
837
+ inst._zod.parse = (payload, ctx) => {
838
+ const input = payload.value;
839
+ if (!Array.isArray(input)) {
840
+ payload.issues.push({
841
+ expected: "array",
842
+ code: "invalid_type",
843
+ input,
844
+ inst
845
+ });
846
+ return payload;
847
+ }
848
+ payload.value = Array(input.length);
849
+ const proms = [];
850
+ for (let i = 0; i < input.length; i++) {
851
+ const item = input[i];
852
+ const result = def.element._zod.run({
853
+ value: item,
854
+ issues: []
855
+ }, ctx);
856
+ if (result instanceof Promise) {
857
+ proms.push(result.then(result => handleArrayResult(result, payload, i)));
858
+ } else {
859
+ handleArrayResult(result, payload, i);
860
+ }
861
+ }
862
+ if (proms.length) {
863
+ return Promise.all(proms).then(() => payload);
864
+ }
865
+ return payload; //handleArrayResultsAsync(parseResults, final);
866
+ };
867
+ });
868
+
869
+ //////////////////////////////////////////
870
+ //////////////////////////////////////////
871
+ ////////// //////////
872
+ ////////// $ZodObject //////////
873
+ ////////// //////////
874
+ //////////////////////////////////////////
875
+ //////////////////////////////////////////
876
+
877
+ // experimental
878
+ // export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = keyof (T &
879
+ // Extra) extends never
880
+ // ? Record<string, never>
881
+ // : string extends keyof T
882
+ // ? util.Prettify<
883
+ // {
884
+ // [k: string]: util.IsAny<T[string]["_zod"]["output"]> extends true ? unknown : T[string]["_zod"]["output"];
885
+ // } & $InferObjectOutputNoIndex<util.OmitIndexSignature<T>, Extra>
886
+ // >
887
+ // : util.Prettify<$InferObjectOutputNoIndex<T, Extra>>;
888
+
889
+ // export type $InferObjectOutputNoIndex<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = {
890
+ // [k in keyof T as string extends k
891
+ // ? never
892
+ // : k extends string
893
+ // ? T[k] extends OptionalOutSchema
894
+ // ? never
895
+ // : k
896
+ // : never]: T[k]["_zod"]["output"];
897
+ // } & {
898
+ // [k in keyof T as string extends k
899
+ // ? never
900
+ // : k extends string
901
+ // ? T[k] extends OptionalOutSchema
902
+ // ? k
903
+ // : never
904
+ // : never]?: T[k]["_zod"]["output"];
905
+ // } & Extra;
906
+
907
+ function handlePropertyResult(result, final, key, input, isOptionalOut) {
908
+ if (result.issues.length) {
909
+ // For optional-out schemas, ignore errors on absent keys
910
+ if (isOptionalOut && !(key in input)) {
911
+ return;
912
+ }
913
+ final.issues.push(...util.prefixIssues(key, result.issues));
914
+ }
915
+ if (result.value === undefined) {
916
+ if (key in input) {
917
+ final.value[key] = undefined;
918
+ }
919
+ } else {
920
+ final.value[key] = result.value;
921
+ }
922
+ }
923
+ function normalizeDef(def) {
924
+ const keys = Object.keys(def.shape);
925
+ for (const k of keys) {
926
+ var _def$shape;
927
+ if (!((_def$shape = def.shape) !== null && _def$shape !== void 0 && (_def$shape = _def$shape[k]) !== null && _def$shape !== void 0 && (_def$shape = _def$shape._zod) !== null && _def$shape !== void 0 && (_def$shape = _def$shape.traits) !== null && _def$shape !== void 0 && _def$shape.has("$ZodType"))) {
928
+ throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
929
+ }
930
+ }
931
+ const okeys = util.optionalKeys(def.shape);
932
+ return _objectSpread(_objectSpread({}, def), {}, {
933
+ keys,
934
+ keySet: new Set(keys),
935
+ numKeys: keys.length,
936
+ optionalKeys: new Set(okeys)
937
+ });
938
+ }
939
+ function handleCatchall(proms, input, payload, ctx, def, inst) {
940
+ const unrecognized = [];
941
+ // iterate over input keys
942
+ const keySet = def.keySet;
943
+ const _catchall = def.catchall._zod;
944
+ const t = _catchall.def.type;
945
+ const isOptionalOut = _catchall.optout === "optional";
946
+ for (const key in input) {
947
+ if (keySet.has(key)) continue;
948
+ if (t === "never") {
949
+ unrecognized.push(key);
950
+ continue;
951
+ }
952
+ const r = _catchall.run({
953
+ value: input[key],
954
+ issues: []
955
+ }, ctx);
956
+ if (r instanceof Promise) {
957
+ proms.push(r.then(r => handlePropertyResult(r, payload, key, input, isOptionalOut)));
958
+ } else {
959
+ handlePropertyResult(r, payload, key, input, isOptionalOut);
960
+ }
961
+ }
962
+ if (unrecognized.length) {
963
+ payload.issues.push({
964
+ code: "unrecognized_keys",
965
+ keys: unrecognized,
966
+ input,
967
+ inst
968
+ });
969
+ }
970
+ if (!proms.length) return payload;
971
+ return Promise.all(proms).then(() => {
972
+ return payload;
973
+ });
974
+ }
975
+ export const $ZodObject = /*@__PURE__*/core.$constructor("$ZodObject", (inst, def) => {
976
+ // requires cast because technically $ZodObject doesn't extend
977
+ $ZodType.init(inst, def);
978
+ // const sh = def.shape;
979
+ const desc = Object.getOwnPropertyDescriptor(def, "shape");
980
+ if (!(desc !== null && desc !== void 0 && desc.get)) {
981
+ const sh = def.shape;
982
+ Object.defineProperty(def, "shape", {
983
+ get: () => {
984
+ const newSh = _objectSpread({}, sh);
985
+ Object.defineProperty(def, "shape", {
986
+ value: newSh
987
+ });
988
+ return newSh;
989
+ }
990
+ });
991
+ }
992
+ const _normalized = util.cached(() => normalizeDef(def));
993
+ util.defineLazy(inst._zod, "propValues", () => {
994
+ const shape = def.shape;
995
+ const propValues = {};
996
+ for (const key in shape) {
997
+ const field = shape[key]._zod;
998
+ if (field.values) {
999
+ propValues[key] ??= new Set();
1000
+ for (const v of field.values) propValues[key].add(v);
1001
+ }
1002
+ }
1003
+ return propValues;
1004
+ });
1005
+ const isObject = util.isObject;
1006
+ const catchall = def.catchall;
1007
+ let value;
1008
+ inst._zod.parse = (payload, ctx) => {
1009
+ value ??= _normalized.value;
1010
+ const input = payload.value;
1011
+ if (!isObject(input)) {
1012
+ payload.issues.push({
1013
+ expected: "object",
1014
+ code: "invalid_type",
1015
+ input,
1016
+ inst
1017
+ });
1018
+ return payload;
1019
+ }
1020
+ payload.value = {};
1021
+ const proms = [];
1022
+ const shape = value.shape;
1023
+ for (const key of value.keys) {
1024
+ const el = shape[key];
1025
+ const isOptionalOut = el._zod.optout === "optional";
1026
+ const r = el._zod.run({
1027
+ value: input[key],
1028
+ issues: []
1029
+ }, ctx);
1030
+ if (r instanceof Promise) {
1031
+ proms.push(r.then(r => handlePropertyResult(r, payload, key, input, isOptionalOut)));
1032
+ } else {
1033
+ handlePropertyResult(r, payload, key, input, isOptionalOut);
1034
+ }
1035
+ }
1036
+ if (!catchall) {
1037
+ return proms.length ? Promise.all(proms).then(() => payload) : payload;
1038
+ }
1039
+ return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
1040
+ };
1041
+ });
1042
+ export const $ZodObjectJIT = /*@__PURE__*/core.$constructor("$ZodObjectJIT", (inst, def) => {
1043
+ // requires cast because technically $ZodObject doesn't extend
1044
+ $ZodObject.init(inst, def);
1045
+ const superParse = inst._zod.parse;
1046
+ const _normalized = util.cached(() => normalizeDef(def));
1047
+ const generateFastpass = shape => {
1048
+ const doc = new Doc(["shape", "payload", "ctx"]);
1049
+ const normalized = _normalized.value;
1050
+ const parseStr = key => {
1051
+ const k = util.esc(key);
1052
+ return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
1053
+ };
1054
+ doc.write(`const input = payload.value;`);
1055
+ const ids = Object.create(null);
1056
+ let counter = 0;
1057
+ for (const key of normalized.keys) {
1058
+ ids[key] = `key_${counter++}`;
1059
+ }
1060
+
1061
+ // A: preserve key order {
1062
+ doc.write(`const newResult = {};`);
1063
+ for (const key of normalized.keys) {
1064
+ var _schema$_zod;
1065
+ const id = ids[key];
1066
+ const k = util.esc(key);
1067
+ const schema = shape[key];
1068
+ const isOptionalOut = (schema === null || schema === void 0 || (_schema$_zod = schema._zod) === null || _schema$_zod === void 0 ? void 0 : _schema$_zod.optout) === "optional";
1069
+ doc.write(`const ${id} = ${parseStr(key)};`);
1070
+ if (isOptionalOut) {
1071
+ // For optional-out schemas, ignore errors on absent keys
1072
+ doc.write(`
1073
+ if (${id}.issues.length) {
1074
+ if (${k} in input) {
1075
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1076
+ ...iss,
1077
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
1078
+ })));
1079
+ }
1080
+ }
1081
+
1082
+ if (${id}.value === undefined) {
1083
+ if (${k} in input) {
1084
+ newResult[${k}] = undefined;
1085
+ }
1086
+ } else {
1087
+ newResult[${k}] = ${id}.value;
1088
+ }
1089
+
1090
+ `);
1091
+ } else {
1092
+ doc.write(`
1093
+ if (${id}.issues.length) {
1094
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1095
+ ...iss,
1096
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
1097
+ })));
1098
+ }
1099
+
1100
+ if (${id}.value === undefined) {
1101
+ if (${k} in input) {
1102
+ newResult[${k}] = undefined;
1103
+ }
1104
+ } else {
1105
+ newResult[${k}] = ${id}.value;
1106
+ }
1107
+
1108
+ `);
1109
+ }
1110
+ }
1111
+ doc.write(`payload.value = newResult;`);
1112
+ doc.write(`return payload;`);
1113
+ const fn = doc.compile();
1114
+ return (payload, ctx) => fn(shape, payload, ctx);
1115
+ };
1116
+ let fastpass;
1117
+ const isObject = util.isObject;
1118
+ const jit = !core.globalConfig.jitless;
1119
+ const allowsEval = util.allowsEval;
1120
+ const fastEnabled = jit && allowsEval.value; // && !def.catchall;
1121
+ const catchall = def.catchall;
1122
+ let value;
1123
+ inst._zod.parse = (payload, ctx) => {
1124
+ value ??= _normalized.value;
1125
+ const input = payload.value;
1126
+ if (!isObject(input)) {
1127
+ payload.issues.push({
1128
+ expected: "object",
1129
+ code: "invalid_type",
1130
+ input,
1131
+ inst
1132
+ });
1133
+ return payload;
1134
+ }
1135
+ if (jit && fastEnabled && (ctx === null || ctx === void 0 ? void 0 : ctx.async) === false && ctx.jitless !== true) {
1136
+ // always synchronous
1137
+ if (!fastpass) fastpass = generateFastpass(def.shape);
1138
+ payload = fastpass(payload, ctx);
1139
+ if (!catchall) return payload;
1140
+ return handleCatchall([], input, payload, ctx, value, inst);
1141
+ }
1142
+ return superParse(payload, ctx);
1143
+ };
1144
+ });
1145
+
1146
+ /////////////////////////////////////////
1147
+ /////////////////////////////////////////
1148
+ ////////// ///////////
1149
+ ////////// $ZodUnion //////////
1150
+ ////////// ///////////
1151
+ /////////////////////////////////////////
1152
+ /////////////////////////////////////////
1153
+ // use generic to distribute union types
1154
+
1155
+ function handleUnionResults(results, final, inst, ctx) {
1156
+ for (const result of results) {
1157
+ if (result.issues.length === 0) {
1158
+ final.value = result.value;
1159
+ return final;
1160
+ }
1161
+ }
1162
+ const nonaborted = results.filter(r => !util.aborted(r));
1163
+ if (nonaborted.length === 1) {
1164
+ final.value = nonaborted[0].value;
1165
+ return nonaborted[0];
1166
+ }
1167
+ final.issues.push({
1168
+ code: "invalid_union",
1169
+ input: final.value,
1170
+ inst,
1171
+ errors: results.map(result => result.issues.map(iss => util.finalizeIssue(iss, ctx, core.config())))
1172
+ });
1173
+ return final;
1174
+ }
1175
+ export const $ZodUnion = /*@__PURE__*/core.$constructor("$ZodUnion", (inst, def) => {
1176
+ $ZodType.init(inst, def);
1177
+ util.defineLazy(inst._zod, "optin", () => def.options.some(o => o._zod.optin === "optional") ? "optional" : undefined);
1178
+ util.defineLazy(inst._zod, "optout", () => def.options.some(o => o._zod.optout === "optional") ? "optional" : undefined);
1179
+ util.defineLazy(inst._zod, "values", () => {
1180
+ if (def.options.every(o => o._zod.values)) {
1181
+ return new Set(def.options.flatMap(option => Array.from(option._zod.values)));
1182
+ }
1183
+ return undefined;
1184
+ });
1185
+ util.defineLazy(inst._zod, "pattern", () => {
1186
+ if (def.options.every(o => o._zod.pattern)) {
1187
+ const patterns = def.options.map(o => o._zod.pattern);
1188
+ return new RegExp(`^(${patterns.map(p => util.cleanRegex(p.source)).join("|")})$`);
1189
+ }
1190
+ return undefined;
1191
+ });
1192
+ const single = def.options.length === 1;
1193
+ const first = def.options[0]._zod.run;
1194
+ inst._zod.parse = (payload, ctx) => {
1195
+ if (single) {
1196
+ return first(payload, ctx);
1197
+ }
1198
+ let async = false;
1199
+ const results = [];
1200
+ for (const option of def.options) {
1201
+ const result = option._zod.run({
1202
+ value: payload.value,
1203
+ issues: []
1204
+ }, ctx);
1205
+ if (result instanceof Promise) {
1206
+ results.push(result);
1207
+ async = true;
1208
+ } else {
1209
+ if (result.issues.length === 0) return result;
1210
+ results.push(result);
1211
+ }
1212
+ }
1213
+ if (!async) return handleUnionResults(results, payload, inst, ctx);
1214
+ return Promise.all(results).then(results => {
1215
+ return handleUnionResults(results, payload, inst, ctx);
1216
+ });
1217
+ };
1218
+ });
1219
+ function handleExclusiveUnionResults(results, final, inst, ctx) {
1220
+ const successes = results.filter(r => r.issues.length === 0);
1221
+ if (successes.length === 1) {
1222
+ final.value = successes[0].value;
1223
+ return final;
1224
+ }
1225
+ if (successes.length === 0) {
1226
+ // No matches - same as regular union
1227
+ final.issues.push({
1228
+ code: "invalid_union",
1229
+ input: final.value,
1230
+ inst,
1231
+ errors: results.map(result => result.issues.map(iss => util.finalizeIssue(iss, ctx, core.config())))
1232
+ });
1233
+ } else {
1234
+ // Multiple matches - exclusive union failure
1235
+ final.issues.push({
1236
+ code: "invalid_union",
1237
+ input: final.value,
1238
+ inst,
1239
+ errors: [],
1240
+ inclusive: false
1241
+ });
1242
+ }
1243
+ return final;
1244
+ }
1245
+ export const $ZodXor = /*@__PURE__*/core.$constructor("$ZodXor", (inst, def) => {
1246
+ $ZodUnion.init(inst, def);
1247
+ def.inclusive = false;
1248
+ const single = def.options.length === 1;
1249
+ const first = def.options[0]._zod.run;
1250
+ inst._zod.parse = (payload, ctx) => {
1251
+ if (single) {
1252
+ return first(payload, ctx);
1253
+ }
1254
+ let async = false;
1255
+ const results = [];
1256
+ for (const option of def.options) {
1257
+ const result = option._zod.run({
1258
+ value: payload.value,
1259
+ issues: []
1260
+ }, ctx);
1261
+ if (result instanceof Promise) {
1262
+ results.push(result);
1263
+ async = true;
1264
+ } else {
1265
+ results.push(result);
1266
+ }
1267
+ }
1268
+ if (!async) return handleExclusiveUnionResults(results, payload, inst, ctx);
1269
+ return Promise.all(results).then(results => {
1270
+ return handleExclusiveUnionResults(results, payload, inst, ctx);
1271
+ });
1272
+ };
1273
+ });
1274
+
1275
+ //////////////////////////////////////////////////////
1276
+ //////////////////////////////////////////////////////
1277
+ ////////// //////////
1278
+ ////////// $ZodDiscriminatedUnion //////////
1279
+ ////////// //////////
1280
+ //////////////////////////////////////////////////////
1281
+ //////////////////////////////////////////////////////
1282
+
1283
+ export const $ZodDiscriminatedUnion = /*@__PURE__*/
1284
+ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1285
+ def.inclusive = false;
1286
+ $ZodUnion.init(inst, def);
1287
+ const _super = inst._zod.parse;
1288
+ util.defineLazy(inst._zod, "propValues", () => {
1289
+ const propValues = {};
1290
+ for (const option of def.options) {
1291
+ const pv = option._zod.propValues;
1292
+ if (!pv || Object.keys(pv).length === 0) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
1293
+ for (const [k, v] of Object.entries(pv)) {
1294
+ if (!propValues[k]) propValues[k] = new Set();
1295
+ for (const val of v) {
1296
+ propValues[k].add(val);
1297
+ }
1298
+ }
1299
+ }
1300
+ return propValues;
1301
+ });
1302
+ const disc = util.cached(() => {
1303
+ const opts = def.options;
1304
+ const map = new Map();
1305
+ for (const o of opts) {
1306
+ var _o$_zod$propValues;
1307
+ const values = (_o$_zod$propValues = o._zod.propValues) === null || _o$_zod$propValues === void 0 ? void 0 : _o$_zod$propValues[def.discriminator];
1308
+ if (!values || values.size === 0) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
1309
+ for (const v of values) {
1310
+ if (map.has(v)) {
1311
+ throw new Error(`Duplicate discriminator value "${String(v)}"`);
1312
+ }
1313
+ map.set(v, o);
1314
+ }
1315
+ }
1316
+ return map;
1317
+ });
1318
+ inst._zod.parse = (payload, ctx) => {
1319
+ const input = payload.value;
1320
+ if (!util.isObject(input)) {
1321
+ payload.issues.push({
1322
+ code: "invalid_type",
1323
+ expected: "object",
1324
+ input,
1325
+ inst
1326
+ });
1327
+ return payload;
1328
+ }
1329
+ const opt = disc.value.get(input === null || input === void 0 ? void 0 : input[def.discriminator]);
1330
+ if (opt) {
1331
+ return opt._zod.run(payload, ctx);
1332
+ }
1333
+ if (def.unionFallback) {
1334
+ return _super(payload, ctx);
1335
+ }
1336
+
1337
+ // no matching discriminator
1338
+ payload.issues.push({
1339
+ code: "invalid_union",
1340
+ errors: [],
1341
+ note: "No matching discriminator",
1342
+ discriminator: def.discriminator,
1343
+ input,
1344
+ path: [def.discriminator],
1345
+ inst
1346
+ });
1347
+ return payload;
1348
+ };
1349
+ });
1350
+
1351
+ ////////////////////////////////////////////////
1352
+ ////////////////////////////////////////////////
1353
+ ////////// //////////
1354
+ ////////// $ZodIntersection //////////
1355
+ ////////// //////////
1356
+ ////////////////////////////////////////////////
1357
+ ////////////////////////////////////////////////
1358
+
1359
+ export const $ZodIntersection = /*@__PURE__*/core.$constructor("$ZodIntersection", (inst, def) => {
1360
+ $ZodType.init(inst, def);
1361
+ inst._zod.parse = (payload, ctx) => {
1362
+ const input = payload.value;
1363
+ const left = def.left._zod.run({
1364
+ value: input,
1365
+ issues: []
1366
+ }, ctx);
1367
+ const right = def.right._zod.run({
1368
+ value: input,
1369
+ issues: []
1370
+ }, ctx);
1371
+ const async = left instanceof Promise || right instanceof Promise;
1372
+ if (async) {
1373
+ return Promise.all([left, right]).then(_ref => {
1374
+ let [left, right] = _ref;
1375
+ return handleIntersectionResults(payload, left, right);
1376
+ });
1377
+ }
1378
+ return handleIntersectionResults(payload, left, right);
1379
+ };
1380
+ });
1381
+ function mergeValues(a, b) {
1382
+ // const aType = parse.t(a);
1383
+ // const bType = parse.t(b);
1384
+
1385
+ if (a === b) {
1386
+ return {
1387
+ valid: true,
1388
+ data: a
1389
+ };
1390
+ }
1391
+ if (a instanceof Date && b instanceof Date && +a === +b) {
1392
+ return {
1393
+ valid: true,
1394
+ data: a
1395
+ };
1396
+ }
1397
+ if (util.isPlainObject(a) && util.isPlainObject(b)) {
1398
+ const bKeys = Object.keys(b);
1399
+ const sharedKeys = Object.keys(a).filter(key => bKeys.indexOf(key) !== -1);
1400
+ const newObj = _objectSpread(_objectSpread({}, a), b);
1401
+ for (const key of sharedKeys) {
1402
+ const sharedValue = mergeValues(a[key], b[key]);
1403
+ if (!sharedValue.valid) {
1404
+ return {
1405
+ valid: false,
1406
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath]
1407
+ };
1408
+ }
1409
+ newObj[key] = sharedValue.data;
1410
+ }
1411
+ return {
1412
+ valid: true,
1413
+ data: newObj
1414
+ };
1415
+ }
1416
+ if (Array.isArray(a) && Array.isArray(b)) {
1417
+ if (a.length !== b.length) {
1418
+ return {
1419
+ valid: false,
1420
+ mergeErrorPath: []
1421
+ };
1422
+ }
1423
+ const newArray = [];
1424
+ for (let index = 0; index < a.length; index++) {
1425
+ const itemA = a[index];
1426
+ const itemB = b[index];
1427
+ const sharedValue = mergeValues(itemA, itemB);
1428
+ if (!sharedValue.valid) {
1429
+ return {
1430
+ valid: false,
1431
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath]
1432
+ };
1433
+ }
1434
+ newArray.push(sharedValue.data);
1435
+ }
1436
+ return {
1437
+ valid: true,
1438
+ data: newArray
1439
+ };
1440
+ }
1441
+ return {
1442
+ valid: false,
1443
+ mergeErrorPath: []
1444
+ };
1445
+ }
1446
+ function handleIntersectionResults(result, left, right) {
1447
+ // Track which side(s) report each key as unrecognized
1448
+ const unrecKeys = new Map();
1449
+ let unrecIssue;
1450
+ for (const iss of left.issues) {
1451
+ if (iss.code === "unrecognized_keys") {
1452
+ unrecIssue ??= iss;
1453
+ for (const k of iss.keys) {
1454
+ if (!unrecKeys.has(k)) unrecKeys.set(k, {});
1455
+ unrecKeys.get(k).l = true;
1456
+ }
1457
+ } else {
1458
+ result.issues.push(iss);
1459
+ }
1460
+ }
1461
+ for (const iss of right.issues) {
1462
+ if (iss.code === "unrecognized_keys") {
1463
+ for (const k of iss.keys) {
1464
+ if (!unrecKeys.has(k)) unrecKeys.set(k, {});
1465
+ unrecKeys.get(k).r = true;
1466
+ }
1467
+ } else {
1468
+ result.issues.push(iss);
1469
+ }
1470
+ }
1471
+
1472
+ // Report only keys unrecognized by BOTH sides
1473
+ const bothKeys = [...unrecKeys].filter(_ref2 => {
1474
+ let [, f] = _ref2;
1475
+ return f.l && f.r;
1476
+ }).map(_ref3 => {
1477
+ let [k] = _ref3;
1478
+ return k;
1479
+ });
1480
+ if (bothKeys.length && unrecIssue) {
1481
+ result.issues.push(_objectSpread(_objectSpread({}, unrecIssue), {}, {
1482
+ keys: bothKeys
1483
+ }));
1484
+ }
1485
+ if (util.aborted(result)) return result;
1486
+ const merged = mergeValues(left.value, right.value);
1487
+ if (!merged.valid) {
1488
+ throw new Error(`Unmergable intersection. Error path: ` + `${JSON.stringify(merged.mergeErrorPath)}`);
1489
+ }
1490
+ result.value = merged.data;
1491
+ return result;
1492
+ }
1493
+
1494
+ /////////////////////////////////////////
1495
+ /////////////////////////////////////////
1496
+ ////////// //////////
1497
+ ////////// $ZodTuple //////////
1498
+ ////////// //////////
1499
+ /////////////////////////////////////////
1500
+ /////////////////////////////////////////
1501
+
1502
+ export const $ZodTuple = /*@__PURE__*/core.$constructor("$ZodTuple", (inst, def) => {
1503
+ $ZodType.init(inst, def);
1504
+ const items = def.items;
1505
+ inst._zod.parse = (payload, ctx) => {
1506
+ const input = payload.value;
1507
+ if (!Array.isArray(input)) {
1508
+ payload.issues.push({
1509
+ input,
1510
+ inst,
1511
+ expected: "tuple",
1512
+ code: "invalid_type"
1513
+ });
1514
+ return payload;
1515
+ }
1516
+ payload.value = [];
1517
+ const proms = [];
1518
+ const reversedIndex = [...items].reverse().findIndex(item => item._zod.optin !== "optional");
1519
+ const optStart = reversedIndex === -1 ? 0 : items.length - reversedIndex;
1520
+ if (!def.rest) {
1521
+ const tooBig = input.length > items.length;
1522
+ const tooSmall = input.length < optStart - 1;
1523
+ if (tooBig || tooSmall) {
1524
+ payload.issues.push(_objectSpread(_objectSpread({}, tooBig ? {
1525
+ code: "too_big",
1526
+ maximum: items.length,
1527
+ inclusive: true
1528
+ } : {
1529
+ code: "too_small",
1530
+ minimum: items.length
1531
+ }), {}, {
1532
+ input,
1533
+ inst,
1534
+ origin: "array"
1535
+ }));
1536
+ return payload;
1537
+ }
1538
+ }
1539
+ let i = -1;
1540
+ for (const item of items) {
1541
+ i++;
1542
+ if (i >= input.length) if (i >= optStart) continue;
1543
+ const result = item._zod.run({
1544
+ value: input[i],
1545
+ issues: []
1546
+ }, ctx);
1547
+ if (result instanceof Promise) {
1548
+ proms.push(result.then(result => handleTupleResult(result, payload, i)));
1549
+ } else {
1550
+ handleTupleResult(result, payload, i);
1551
+ }
1552
+ }
1553
+ if (def.rest) {
1554
+ const rest = input.slice(items.length);
1555
+ for (const el of rest) {
1556
+ i++;
1557
+ const result = def.rest._zod.run({
1558
+ value: el,
1559
+ issues: []
1560
+ }, ctx);
1561
+ if (result instanceof Promise) {
1562
+ proms.push(result.then(result => handleTupleResult(result, payload, i)));
1563
+ } else {
1564
+ handleTupleResult(result, payload, i);
1565
+ }
1566
+ }
1567
+ }
1568
+ if (proms.length) return Promise.all(proms).then(() => payload);
1569
+ return payload;
1570
+ };
1571
+ });
1572
+ function handleTupleResult(result, final, index) {
1573
+ if (result.issues.length) {
1574
+ final.issues.push(...util.prefixIssues(index, result.issues));
1575
+ }
1576
+ final.value[index] = result.value;
1577
+ }
1578
+
1579
+ //////////////////////////////////////////
1580
+ //////////////////////////////////////////
1581
+ ////////// //////////
1582
+ ////////// $ZodRecord //////////
1583
+ ////////// //////////
1584
+ //////////////////////////////////////////
1585
+ //////////////////////////////////////////
1586
+
1587
+ // $HasValues | $HasPattern;
1588
+
1589
+ // export type $InferZodRecordOutput<
1590
+ // Key extends $ZodRecordKey = $ZodRecordKey,
1591
+ // Value extends SomeType = $ZodType,
1592
+ // > = undefined extends Key["_zod"]["values"]
1593
+ // ? string extends core.output<Key>
1594
+ // ? Record<core.output<Key>, core.output<Value>>
1595
+ // : number extends core.output<Key>
1596
+ // ? Record<core.output<Key>, core.output<Value>>
1597
+ // : symbol extends core.output<Key>
1598
+ // ? Record<core.output<Key>, core.output<Value>>
1599
+ // : Record<core.output<Key>, core.output<Value>>
1600
+ // : Record<core.output<Key>, core.output<Value>>;
1601
+
1602
+ // export type $InferZodRecordInput<
1603
+ // Key extends $ZodRecordKey = $ZodRecordKey,
1604
+ // Value extends SomeType = $ZodType,
1605
+ // > = undefined extends Key["_zod"]["values"]
1606
+ // ? string extends core.input<Key>
1607
+ // ? Record<core.input<Key>, core.input<Value>>
1608
+ // : number extends core.input<Key>
1609
+ // ? Record<core.input<Key>, core.input<Value>>
1610
+ // : symbol extends core.input<Key>
1611
+ // ? Record<core.input<Key>, core.input<Value>>
1612
+ // : Record<core.input<Key>, core.input<Value>>
1613
+ // : Record<core.input<Key>, core.input<Value>>;
1614
+
1615
+ export const $ZodRecord = /*@__PURE__*/core.$constructor("$ZodRecord", (inst, def) => {
1616
+ $ZodType.init(inst, def);
1617
+ inst._zod.parse = (payload, ctx) => {
1618
+ const input = payload.value;
1619
+ if (!util.isPlainObject(input)) {
1620
+ payload.issues.push({
1621
+ expected: "record",
1622
+ code: "invalid_type",
1623
+ input,
1624
+ inst
1625
+ });
1626
+ return payload;
1627
+ }
1628
+ const proms = [];
1629
+ const values = def.keyType._zod.values;
1630
+ if (values) {
1631
+ payload.value = {};
1632
+ const recordKeys = new Set();
1633
+ for (const key of values) {
1634
+ if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
1635
+ recordKeys.add(typeof key === "number" ? key.toString() : key);
1636
+ const result = def.valueType._zod.run({
1637
+ value: input[key],
1638
+ issues: []
1639
+ }, ctx);
1640
+ if (result instanceof Promise) {
1641
+ proms.push(result.then(result => {
1642
+ if (result.issues.length) {
1643
+ payload.issues.push(...util.prefixIssues(key, result.issues));
1644
+ }
1645
+ payload.value[key] = result.value;
1646
+ }));
1647
+ } else {
1648
+ if (result.issues.length) {
1649
+ payload.issues.push(...util.prefixIssues(key, result.issues));
1650
+ }
1651
+ payload.value[key] = result.value;
1652
+ }
1653
+ }
1654
+ }
1655
+ let unrecognized;
1656
+ for (const key in input) {
1657
+ if (!recordKeys.has(key)) {
1658
+ var _unrecognized;
1659
+ unrecognized = (_unrecognized = unrecognized) !== null && _unrecognized !== void 0 ? _unrecognized : [];
1660
+ unrecognized.push(key);
1661
+ }
1662
+ }
1663
+ if (unrecognized && unrecognized.length > 0) {
1664
+ payload.issues.push({
1665
+ code: "unrecognized_keys",
1666
+ input,
1667
+ inst,
1668
+ keys: unrecognized
1669
+ });
1670
+ }
1671
+ } else {
1672
+ payload.value = {};
1673
+ for (const key of Reflect.ownKeys(input)) {
1674
+ if (key === "__proto__") continue;
1675
+ let keyResult = def.keyType._zod.run({
1676
+ value: key,
1677
+ issues: []
1678
+ }, ctx);
1679
+ if (keyResult instanceof Promise) {
1680
+ throw new Error("Async schemas not supported in object keys currently");
1681
+ }
1682
+
1683
+ // Numeric string fallback: if key failed with "expected number", retry with Number(key)
1684
+ const checkNumericKey = typeof key === "string" && regexes.number.test(key) && keyResult.issues.length && keyResult.issues.some(iss => iss.code === "invalid_type" && iss.expected === "number");
1685
+ if (checkNumericKey) {
1686
+ const retryResult = def.keyType._zod.run({
1687
+ value: Number(key),
1688
+ issues: []
1689
+ }, ctx);
1690
+ if (retryResult instanceof Promise) {
1691
+ throw new Error("Async schemas not supported in object keys currently");
1692
+ }
1693
+ if (retryResult.issues.length === 0) {
1694
+ keyResult = retryResult;
1695
+ }
1696
+ }
1697
+ if (keyResult.issues.length) {
1698
+ if (def.mode === "loose") {
1699
+ // Pass through unchanged
1700
+ payload.value[key] = input[key];
1701
+ } else {
1702
+ // Default "strict" behavior: error on invalid key
1703
+ payload.issues.push({
1704
+ code: "invalid_key",
1705
+ origin: "record",
1706
+ issues: keyResult.issues.map(iss => util.finalizeIssue(iss, ctx, core.config())),
1707
+ input: key,
1708
+ path: [key],
1709
+ inst
1710
+ });
1711
+ }
1712
+ continue;
1713
+ }
1714
+ const result = def.valueType._zod.run({
1715
+ value: input[key],
1716
+ issues: []
1717
+ }, ctx);
1718
+ if (result instanceof Promise) {
1719
+ proms.push(result.then(result => {
1720
+ if (result.issues.length) {
1721
+ payload.issues.push(...util.prefixIssues(key, result.issues));
1722
+ }
1723
+ payload.value[keyResult.value] = result.value;
1724
+ }));
1725
+ } else {
1726
+ if (result.issues.length) {
1727
+ payload.issues.push(...util.prefixIssues(key, result.issues));
1728
+ }
1729
+ payload.value[keyResult.value] = result.value;
1730
+ }
1731
+ }
1732
+ }
1733
+ if (proms.length) {
1734
+ return Promise.all(proms).then(() => payload);
1735
+ }
1736
+ return payload;
1737
+ };
1738
+ });
1739
+
1740
+ ///////////////////////////////////////
1741
+ ///////////////////////////////////////
1742
+ ////////// //////////
1743
+ ////////// $ZodMap //////////
1744
+ ////////// //////////
1745
+ ///////////////////////////////////////
1746
+ ///////////////////////////////////////
1747
+
1748
+ export const $ZodMap = /*@__PURE__*/core.$constructor("$ZodMap", (inst, def) => {
1749
+ $ZodType.init(inst, def);
1750
+ inst._zod.parse = (payload, ctx) => {
1751
+ const input = payload.value;
1752
+ if (!(input instanceof Map)) {
1753
+ payload.issues.push({
1754
+ expected: "map",
1755
+ code: "invalid_type",
1756
+ input,
1757
+ inst
1758
+ });
1759
+ return payload;
1760
+ }
1761
+ const proms = [];
1762
+ payload.value = new Map();
1763
+ for (const [key, value] of input) {
1764
+ const keyResult = def.keyType._zod.run({
1765
+ value: key,
1766
+ issues: []
1767
+ }, ctx);
1768
+ const valueResult = def.valueType._zod.run({
1769
+ value: value,
1770
+ issues: []
1771
+ }, ctx);
1772
+ if (keyResult instanceof Promise || valueResult instanceof Promise) {
1773
+ proms.push(Promise.all([keyResult, valueResult]).then(_ref4 => {
1774
+ let [keyResult, valueResult] = _ref4;
1775
+ handleMapResult(keyResult, valueResult, payload, key, input, inst, ctx);
1776
+ }));
1777
+ } else {
1778
+ handleMapResult(keyResult, valueResult, payload, key, input, inst, ctx);
1779
+ }
1780
+ }
1781
+ if (proms.length) return Promise.all(proms).then(() => payload);
1782
+ return payload;
1783
+ };
1784
+ });
1785
+ function handleMapResult(keyResult, valueResult, final, key, input, inst, ctx) {
1786
+ if (keyResult.issues.length) {
1787
+ if (util.propertyKeyTypes.has(typeof key)) {
1788
+ final.issues.push(...util.prefixIssues(key, keyResult.issues));
1789
+ } else {
1790
+ final.issues.push({
1791
+ code: "invalid_key",
1792
+ origin: "map",
1793
+ input,
1794
+ inst,
1795
+ issues: keyResult.issues.map(iss => util.finalizeIssue(iss, ctx, core.config()))
1796
+ });
1797
+ }
1798
+ }
1799
+ if (valueResult.issues.length) {
1800
+ if (util.propertyKeyTypes.has(typeof key)) {
1801
+ final.issues.push(...util.prefixIssues(key, valueResult.issues));
1802
+ } else {
1803
+ final.issues.push({
1804
+ origin: "map",
1805
+ code: "invalid_element",
1806
+ input,
1807
+ inst,
1808
+ key: key,
1809
+ issues: valueResult.issues.map(iss => util.finalizeIssue(iss, ctx, core.config()))
1810
+ });
1811
+ }
1812
+ }
1813
+ final.value.set(keyResult.value, valueResult.value);
1814
+ }
1815
+
1816
+ ///////////////////////////////////////
1817
+ ///////////////////////////////////////
1818
+ ////////// //////////
1819
+ ////////// $ZodSet //////////
1820
+ ////////// //////////
1821
+ ///////////////////////////////////////
1822
+ ///////////////////////////////////////
1823
+
1824
+ export const $ZodSet = /*@__PURE__*/core.$constructor("$ZodSet", (inst, def) => {
1825
+ $ZodType.init(inst, def);
1826
+ inst._zod.parse = (payload, ctx) => {
1827
+ const input = payload.value;
1828
+ if (!(input instanceof Set)) {
1829
+ payload.issues.push({
1830
+ input,
1831
+ inst,
1832
+ expected: "set",
1833
+ code: "invalid_type"
1834
+ });
1835
+ return payload;
1836
+ }
1837
+ const proms = [];
1838
+ payload.value = new Set();
1839
+ for (const item of input) {
1840
+ const result = def.valueType._zod.run({
1841
+ value: item,
1842
+ issues: []
1843
+ }, ctx);
1844
+ if (result instanceof Promise) {
1845
+ proms.push(result.then(result => handleSetResult(result, payload)));
1846
+ } else handleSetResult(result, payload);
1847
+ }
1848
+ if (proms.length) return Promise.all(proms).then(() => payload);
1849
+ return payload;
1850
+ };
1851
+ });
1852
+ function handleSetResult(result, final) {
1853
+ if (result.issues.length) {
1854
+ final.issues.push(...result.issues);
1855
+ }
1856
+ final.value.add(result.value);
1857
+ }
1858
+
1859
+ ////////////////////////////////////////
1860
+ ////////////////////////////////////////
1861
+ ////////// //////////
1862
+ ////////// $ZodEnum //////////
1863
+ ////////// //////////
1864
+ ////////////////////////////////////////
1865
+ ////////////////////////////////////////
1866
+
1867
+ export const $ZodEnum = /*@__PURE__*/core.$constructor("$ZodEnum", (inst, def) => {
1868
+ $ZodType.init(inst, def);
1869
+ const values = util.getEnumValues(def.entries);
1870
+ const valuesSet = new Set(values);
1871
+ inst._zod.values = valuesSet;
1872
+ inst._zod.pattern = new RegExp(`^(${values.filter(k => util.propertyKeyTypes.has(typeof k)).map(o => typeof o === "string" ? util.escapeRegex(o) : o.toString()).join("|")})$`);
1873
+ inst._zod.parse = payload => {
1874
+ const input = payload.value;
1875
+ if (valuesSet.has(input)) {
1876
+ return payload;
1877
+ }
1878
+ payload.issues.push({
1879
+ code: "invalid_value",
1880
+ values,
1881
+ input,
1882
+ inst
1883
+ });
1884
+ return payload;
1885
+ };
1886
+ });
1887
+
1888
+ ////////////////////////////////////////
1889
+ ////////////////////////////////////////
1890
+ ////////// //////////
1891
+ ////////// $ZodLiteral //////////
1892
+ ////////// //////////
1893
+ ////////////////////////////////////////
1894
+ ////////////////////////////////////////
1895
+
1896
+ export const $ZodLiteral = /*@__PURE__*/core.$constructor("$ZodLiteral", (inst, def) => {
1897
+ $ZodType.init(inst, def);
1898
+ if (def.values.length === 0) {
1899
+ throw new Error("Cannot create literal schema with no valid values");
1900
+ }
1901
+ const values = new Set(def.values);
1902
+ inst._zod.values = values;
1903
+ inst._zod.pattern = new RegExp(`^(${def.values.map(o => typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o)).join("|")})$`);
1904
+ inst._zod.parse = payload => {
1905
+ const input = payload.value;
1906
+ if (values.has(input)) {
1907
+ return payload;
1908
+ }
1909
+ payload.issues.push({
1910
+ code: "invalid_value",
1911
+ values: def.values,
1912
+ input,
1913
+ inst
1914
+ });
1915
+ return payload;
1916
+ };
1917
+ });
1918
+
1919
+ ////////////////////////////////////////
1920
+ ////////////////////////////////////////
1921
+ ////////// //////////
1922
+ ////////// $ZodConst //////////
1923
+ ////////// //////////
1924
+ ////////////////////////////////////////
1925
+ ////////////////////////////////////////
1926
+
1927
+ // export interface $ZodConstDef extends $ZodTypeDef {
1928
+ // type: "const";
1929
+ // value: unknown;
1930
+ // }
1931
+
1932
+ // export _interface $ZodConstInternals<T extends util.Literal = util.Literal> extends $ZodTypeInternals<T, T> {
1933
+ // _def: $ZodConstDef;
1934
+ // _values: util.PrimitiveSet;
1935
+ // _pattern: RegExp;
1936
+ // _isst: errors.$ZodIssueInvalidValue;
1937
+ // }
1938
+
1939
+ // export const $ZodConst: core.$constructor<{_zod: $ZodConstInternals}> = /*@__PURE__*/ core.$constructor("$ZodConst", (inst, def) => {
1940
+ // $ZodType.init(inst, def);
1941
+
1942
+ // if (util.primitiveTypes.has(typeof def.value) || def.value === null) {
1943
+ // inst._zod.values = new Set<util.Primitive>(def.value as any);
1944
+ // }
1945
+
1946
+ // if (util.propertyKeyTypes.has(typeof def.value)) {
1947
+ // inst._zod.pattern = new RegExp(
1948
+ // `^(${typeof def.value === "string" ? util.escapeRegex(def.value) : (def.value as any).toString()})$`
1949
+ // );
1950
+ // } else {
1951
+ // throw new Error("Const value cannot be converted to regex");
1952
+ // }
1953
+
1954
+ // inst._zod.parse = (payload, _ctx) => {
1955
+ // payload.value = def.value; // always override
1956
+ // return payload;
1957
+ // };
1958
+ // });
1959
+
1960
+ //////////////////////////////////////////
1961
+ //////////////////////////////////////////
1962
+ ////////// //////////
1963
+ ////////// $ZodFile //////////
1964
+ ////////// //////////
1965
+ //////////////////////////////////////////
1966
+ //////////////////////////////////////////
1967
+
1968
+ // provide a fallback in case the File interface isn't provided in the environment
1969
+
1970
+ /** Do not reference this directly. */
1971
+
1972
+ export const $ZodFile = /*@__PURE__*/core.$constructor("$ZodFile", (inst, def) => {
1973
+ $ZodType.init(inst, def);
1974
+ inst._zod.parse = payload => {
1975
+ const input = payload.value;
1976
+ // @ts-ignore
1977
+ if (input instanceof File) return payload;
1978
+ payload.issues.push({
1979
+ expected: "file",
1980
+ code: "invalid_type",
1981
+ input,
1982
+ inst
1983
+ });
1984
+ return payload;
1985
+ };
1986
+ });
1987
+
1988
+ //////////////////////////////////////////////
1989
+ //////////////////////////////////////////////
1990
+ ////////// //////////
1991
+ ////////// $ZodTransform //////////
1992
+ ////////// //////////
1993
+ //////////////////////////////////////////////
1994
+ //////////////////////////////////////////////
1995
+
1996
+ export const $ZodTransform = /*@__PURE__*/core.$constructor("$ZodTransform", (inst, def) => {
1997
+ $ZodType.init(inst, def);
1998
+ inst._zod.parse = (payload, ctx) => {
1999
+ if (ctx.direction === "backward") {
2000
+ throw new core.$ZodEncodeError(inst.constructor.name);
2001
+ }
2002
+ const _out = def.transform(payload.value, payload);
2003
+ if (ctx.async) {
2004
+ const output = _out instanceof Promise ? _out : Promise.resolve(_out);
2005
+ return output.then(output => {
2006
+ payload.value = output;
2007
+ return payload;
2008
+ });
2009
+ }
2010
+ if (_out instanceof Promise) {
2011
+ throw new core.$ZodAsyncError();
2012
+ }
2013
+ payload.value = _out;
2014
+ return payload;
2015
+ };
2016
+ });
2017
+
2018
+ ////////////////////////////////////////////
2019
+ ////////////////////////////////////////////
2020
+ ////////// //////////
2021
+ ////////// $ZodOptional //////////
2022
+ ////////// //////////
2023
+ ////////////////////////////////////////////
2024
+ ////////////////////////////////////////////
2025
+
2026
+ function handleOptionalResult(result, input) {
2027
+ if (result.issues.length && input === undefined) {
2028
+ return {
2029
+ issues: [],
2030
+ value: undefined
2031
+ };
2032
+ }
2033
+ return result;
2034
+ }
2035
+ export const $ZodOptional = /*@__PURE__*/core.$constructor("$ZodOptional", (inst, def) => {
2036
+ $ZodType.init(inst, def);
2037
+ inst._zod.optin = "optional";
2038
+ inst._zod.optout = "optional";
2039
+ util.defineLazy(inst._zod, "values", () => {
2040
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, undefined]) : undefined;
2041
+ });
2042
+ util.defineLazy(inst._zod, "pattern", () => {
2043
+ const pattern = def.innerType._zod.pattern;
2044
+ return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)})?$`) : undefined;
2045
+ });
2046
+ inst._zod.parse = (payload, ctx) => {
2047
+ if (def.innerType._zod.optin === "optional") {
2048
+ const result = def.innerType._zod.run(payload, ctx);
2049
+ if (result instanceof Promise) return result.then(r => handleOptionalResult(r, payload.value));
2050
+ return handleOptionalResult(result, payload.value);
2051
+ }
2052
+ if (payload.value === undefined) {
2053
+ return payload;
2054
+ }
2055
+ return def.innerType._zod.run(payload, ctx);
2056
+ };
2057
+ });
2058
+
2059
+ ////////////////////////////////////////////////
2060
+ ////////////////////////////////////////////////
2061
+ ////////// //////////
2062
+ ////////// $ZodExactOptional //////////
2063
+ ////////// //////////
2064
+ ////////////////////////////////////////////////
2065
+ ////////////////////////////////////////////////
2066
+
2067
+ // Def extends $ZodOptionalDef (no additional fields needed)
2068
+
2069
+ // Internals extends $ZodOptionalInternals but narrows output/input types (removes | undefined)
2070
+
2071
+ export const $ZodExactOptional = /*@__PURE__*/core.$constructor("$ZodExactOptional", (inst, def) => {
2072
+ // Call parent init - inherits optin/optout = "optional"
2073
+ $ZodOptional.init(inst, def);
2074
+
2075
+ // Override values/pattern to NOT add undefined
2076
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2077
+ util.defineLazy(inst._zod, "pattern", () => def.innerType._zod.pattern);
2078
+
2079
+ // Override parse to just delegate (no undefined handling)
2080
+ inst._zod.parse = (payload, ctx) => {
2081
+ return def.innerType._zod.run(payload, ctx);
2082
+ };
2083
+ });
2084
+
2085
+ ////////////////////////////////////////////
2086
+ ////////////////////////////////////////////
2087
+ ////////// //////////
2088
+ ////////// $ZodNullable //////////
2089
+ ////////// //////////
2090
+ ////////////////////////////////////////////
2091
+ ////////////////////////////////////////////
2092
+
2093
+ export const $ZodNullable = /*@__PURE__*/core.$constructor("$ZodNullable", (inst, def) => {
2094
+ $ZodType.init(inst, def);
2095
+ util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
2096
+ util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
2097
+ util.defineLazy(inst._zod, "pattern", () => {
2098
+ const pattern = def.innerType._zod.pattern;
2099
+ return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)}|null)$`) : undefined;
2100
+ });
2101
+ util.defineLazy(inst._zod, "values", () => {
2102
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
2103
+ });
2104
+ inst._zod.parse = (payload, ctx) => {
2105
+ // Forward direction (decode): allow null to pass through
2106
+ if (payload.value === null) return payload;
2107
+ return def.innerType._zod.run(payload, ctx);
2108
+ };
2109
+ });
2110
+ // );
2111
+
2112
+ ////////////////////////////////////////////
2113
+ ////////////////////////////////////////////
2114
+ ////////// //////////
2115
+ ////////// $ZodDefault //////////
2116
+ ////////// //////////
2117
+ ////////////////////////////////////////////
2118
+ ////////////////////////////////////////////
2119
+
2120
+ export const $ZodDefault = /*@__PURE__*/core.$constructor("$ZodDefault", (inst, def) => {
2121
+ $ZodType.init(inst, def);
2122
+
2123
+ // inst._zod.qin = "true";
2124
+ inst._zod.optin = "optional";
2125
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2126
+ inst._zod.parse = (payload, ctx) => {
2127
+ if (ctx.direction === "backward") {
2128
+ return def.innerType._zod.run(payload, ctx);
2129
+ }
2130
+
2131
+ // Forward direction (decode): apply defaults for undefined input
2132
+ if (payload.value === undefined) {
2133
+ payload.value = def.defaultValue;
2134
+ /**
2135
+ * $ZodDefault returns the default value immediately in forward direction.
2136
+ * It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
2137
+ return payload;
2138
+ }
2139
+ // Forward direction: continue with default handling
2140
+ const result = def.innerType._zod.run(payload, ctx);
2141
+ if (result instanceof Promise) {
2142
+ return result.then(result => handleDefaultResult(result, def));
2143
+ }
2144
+ return handleDefaultResult(result, def);
2145
+ };
2146
+ });
2147
+ function handleDefaultResult(payload, def) {
2148
+ if (payload.value === undefined) {
2149
+ payload.value = def.defaultValue;
2150
+ }
2151
+ return payload;
2152
+ }
2153
+
2154
+ ////////////////////////////////////////////
2155
+ ////////////////////////////////////////////
2156
+ ////////// //////////
2157
+ ////////// $ZodPrefault //////////
2158
+ ////////// //////////
2159
+ ////////////////////////////////////////////
2160
+ ////////////////////////////////////////////
2161
+
2162
+ export const $ZodPrefault = /*@__PURE__*/core.$constructor("$ZodPrefault", (inst, def) => {
2163
+ $ZodType.init(inst, def);
2164
+ inst._zod.optin = "optional";
2165
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2166
+ inst._zod.parse = (payload, ctx) => {
2167
+ if (ctx.direction === "backward") {
2168
+ return def.innerType._zod.run(payload, ctx);
2169
+ }
2170
+
2171
+ // Forward direction (decode): apply prefault for undefined input
2172
+ if (payload.value === undefined) {
2173
+ payload.value = def.defaultValue;
2174
+ }
2175
+ return def.innerType._zod.run(payload, ctx);
2176
+ };
2177
+ });
2178
+
2179
+ ///////////////////////////////////////////////
2180
+ ///////////////////////////////////////////////
2181
+ ////////// //////////
2182
+ ////////// $ZodNonOptional //////////
2183
+ ////////// //////////
2184
+ ///////////////////////////////////////////////
2185
+ ///////////////////////////////////////////////
2186
+
2187
+ export const $ZodNonOptional = /*@__PURE__*/core.$constructor("$ZodNonOptional", (inst, def) => {
2188
+ $ZodType.init(inst, def);
2189
+ util.defineLazy(inst._zod, "values", () => {
2190
+ const v = def.innerType._zod.values;
2191
+ return v ? new Set([...v].filter(x => x !== undefined)) : undefined;
2192
+ });
2193
+ inst._zod.parse = (payload, ctx) => {
2194
+ const result = def.innerType._zod.run(payload, ctx);
2195
+ if (result instanceof Promise) {
2196
+ return result.then(result => handleNonOptionalResult(result, inst));
2197
+ }
2198
+ return handleNonOptionalResult(result, inst);
2199
+ };
2200
+ });
2201
+ function handleNonOptionalResult(payload, inst) {
2202
+ if (!payload.issues.length && payload.value === undefined) {
2203
+ payload.issues.push({
2204
+ code: "invalid_type",
2205
+ expected: "nonoptional",
2206
+ input: payload.value,
2207
+ inst
2208
+ });
2209
+ }
2210
+ return payload;
2211
+ }
2212
+
2213
+ ////////////////////////////////////////////
2214
+ ////////////////////////////////////////////
2215
+ ////////// //////////
2216
+ ////////// $ZodCoalesce //////////
2217
+ ////////// //////////
2218
+ ////////////////////////////////////////////
2219
+ ////////////////////////////////////////////
2220
+ // export interface $ZodCoalesceDef<T extends $ZodType = $ZodType> extends $ZodTypeDef {
2221
+ // type: "coalesce";
2222
+ // innerType: T;
2223
+ // defaultValue: () => NonNullable<T['_zod']["output"]>;
2224
+ // }
2225
+
2226
+ // export _interface $ZodCoalesceInternals<T extends $ZodType = $ZodType>
2227
+ // extends $ZodTypeInternals<NonNullable<T['_zod']["output"]>, T['_zod']["input"] | undefined | null> {
2228
+ // _def: $ZodCoalesceDef<T>;
2229
+ // _isst: errors.$ZodIssueInvalidType;
2230
+ // _qin: "true";
2231
+ // }
2232
+
2233
+ // function handleCoalesceResult(payload: ParsePayload, def: $ZodCoalesceDef) {
2234
+ // payload.value ??= def.defaultValue();
2235
+ // return payload;
2236
+ // }
2237
+
2238
+ // export const $ZodCoalesce: core.$constructor<{_zod: $ZodCoalesceInternals}> = /*@__PURE__*/ core.$constructor(
2239
+ // "$ZodCoalesce",
2240
+ // (inst, def) => {
2241
+ // $ZodType.init(inst, def);
2242
+ // inst._zod.qin = "true";
2243
+ // inst._zod.parse = (payload, ctx) => {
2244
+ // const result = def.innerType._zod.run(payload, ctx);
2245
+ // if (result instanceof Promise) {
2246
+ // return result.then((result) => handleCoalesceResult(result, def));
2247
+ // }
2248
+ // return handleCoalesceResult(result, def);
2249
+ // };
2250
+ // }
2251
+ // );
2252
+
2253
+ /////////////////////////////////////////////
2254
+ /////////////////////////////////////////////
2255
+ ////////// //////////
2256
+ ////////// $ZodSuccess //////////
2257
+ ////////// //////////
2258
+ /////////////////////////////////////////////
2259
+ /////////////////////////////////////////////
2260
+
2261
+ export const $ZodSuccess = /*@__PURE__*/core.$constructor("$ZodSuccess", (inst, def) => {
2262
+ $ZodType.init(inst, def);
2263
+ inst._zod.parse = (payload, ctx) => {
2264
+ if (ctx.direction === "backward") {
2265
+ throw new core.$ZodEncodeError("ZodSuccess");
2266
+ }
2267
+ const result = def.innerType._zod.run(payload, ctx);
2268
+ if (result instanceof Promise) {
2269
+ return result.then(result => {
2270
+ payload.value = result.issues.length === 0;
2271
+ return payload;
2272
+ });
2273
+ }
2274
+ payload.value = result.issues.length === 0;
2275
+ return payload;
2276
+ };
2277
+ });
2278
+
2279
+ ////////////////////////////////////////////
2280
+ ////////////////////////////////////////////
2281
+ ////////// //////////
2282
+ ////////// $ZodCatch //////////
2283
+ ////////// //////////
2284
+ ////////////////////////////////////////////
2285
+ ////////////////////////////////////////////
2286
+
2287
+ export const $ZodCatch = /*@__PURE__*/core.$constructor("$ZodCatch", (inst, def) => {
2288
+ $ZodType.init(inst, def);
2289
+ util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
2290
+ util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
2291
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2292
+ inst._zod.parse = (payload, ctx) => {
2293
+ if (ctx.direction === "backward") {
2294
+ return def.innerType._zod.run(payload, ctx);
2295
+ }
2296
+
2297
+ // Forward direction (decode): apply catch logic
2298
+ const result = def.innerType._zod.run(payload, ctx);
2299
+ if (result instanceof Promise) {
2300
+ return result.then(result => {
2301
+ payload.value = result.value;
2302
+ if (result.issues.length) {
2303
+ payload.value = def.catchValue(_objectSpread(_objectSpread({}, payload), {}, {
2304
+ error: {
2305
+ issues: result.issues.map(iss => util.finalizeIssue(iss, ctx, core.config()))
2306
+ },
2307
+ input: payload.value
2308
+ }));
2309
+ payload.issues = [];
2310
+ }
2311
+ return payload;
2312
+ });
2313
+ }
2314
+ payload.value = result.value;
2315
+ if (result.issues.length) {
2316
+ payload.value = def.catchValue(_objectSpread(_objectSpread({}, payload), {}, {
2317
+ error: {
2318
+ issues: result.issues.map(iss => util.finalizeIssue(iss, ctx, core.config()))
2319
+ },
2320
+ input: payload.value
2321
+ }));
2322
+ payload.issues = [];
2323
+ }
2324
+ return payload;
2325
+ };
2326
+ });
2327
+
2328
+ ////////////////////////////////////////////
2329
+ ////////////////////////////////////////////
2330
+ ////////// //////////
2331
+ ////////// $ZodNaN //////////
2332
+ ////////// //////////
2333
+ ////////////////////////////////////////////
2334
+ ////////////////////////////////////////////
2335
+
2336
+ export const $ZodNaN = /*@__PURE__*/core.$constructor("$ZodNaN", (inst, def) => {
2337
+ $ZodType.init(inst, def);
2338
+ inst._zod.parse = payload => {
2339
+ if (typeof payload.value !== "number" || !Number.isNaN(payload.value)) {
2340
+ payload.issues.push({
2341
+ input: payload.value,
2342
+ inst,
2343
+ expected: "nan",
2344
+ code: "invalid_type"
2345
+ });
2346
+ return payload;
2347
+ }
2348
+ return payload;
2349
+ };
2350
+ });
2351
+
2352
+ ////////////////////////////////////////////
2353
+ ////////////////////////////////////////////
2354
+ ////////// //////////
2355
+ ////////// $ZodPipe //////////
2356
+ ////////// //////////
2357
+ ////////////////////////////////////////////
2358
+ ////////////////////////////////////////////
2359
+
2360
+ export const $ZodPipe = /*@__PURE__*/core.$constructor("$ZodPipe", (inst, def) => {
2361
+ $ZodType.init(inst, def);
2362
+ util.defineLazy(inst._zod, "values", () => def.in._zod.values);
2363
+ util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
2364
+ util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
2365
+ util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
2366
+ inst._zod.parse = (payload, ctx) => {
2367
+ if (ctx.direction === "backward") {
2368
+ const right = def.out._zod.run(payload, ctx);
2369
+ if (right instanceof Promise) {
2370
+ return right.then(right => handlePipeResult(right, def.in, ctx));
2371
+ }
2372
+ return handlePipeResult(right, def.in, ctx);
2373
+ }
2374
+ const left = def.in._zod.run(payload, ctx);
2375
+ if (left instanceof Promise) {
2376
+ return left.then(left => handlePipeResult(left, def.out, ctx));
2377
+ }
2378
+ return handlePipeResult(left, def.out, ctx);
2379
+ };
2380
+ });
2381
+ function handlePipeResult(left, next, ctx) {
2382
+ if (left.issues.length) {
2383
+ // prevent further checks
2384
+ left.aborted = true;
2385
+ return left;
2386
+ }
2387
+ return next._zod.run({
2388
+ value: left.value,
2389
+ issues: left.issues
2390
+ }, ctx);
2391
+ }
2392
+
2393
+ ////////////////////////////////////////////
2394
+ ////////////////////////////////////////////
2395
+ ////////// //////////
2396
+ ////////// $ZodCodec //////////
2397
+ ////////// //////////
2398
+ ////////////////////////////////////////////
2399
+ ////////////////////////////////////////////
2400
+
2401
+ export const $ZodCodec = /*@__PURE__*/core.$constructor("$ZodCodec", (inst, def) => {
2402
+ $ZodType.init(inst, def);
2403
+ util.defineLazy(inst._zod, "values", () => def.in._zod.values);
2404
+ util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
2405
+ util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
2406
+ util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
2407
+ inst._zod.parse = (payload, ctx) => {
2408
+ const direction = ctx.direction || "forward";
2409
+ if (direction === "forward") {
2410
+ const left = def.in._zod.run(payload, ctx);
2411
+ if (left instanceof Promise) {
2412
+ return left.then(left => handleCodecAResult(left, def, ctx));
2413
+ }
2414
+ return handleCodecAResult(left, def, ctx);
2415
+ } else {
2416
+ const right = def.out._zod.run(payload, ctx);
2417
+ if (right instanceof Promise) {
2418
+ return right.then(right => handleCodecAResult(right, def, ctx));
2419
+ }
2420
+ return handleCodecAResult(right, def, ctx);
2421
+ }
2422
+ };
2423
+ });
2424
+ function handleCodecAResult(result, def, ctx) {
2425
+ if (result.issues.length) {
2426
+ // prevent further checks
2427
+ result.aborted = true;
2428
+ return result;
2429
+ }
2430
+ const direction = ctx.direction || "forward";
2431
+ if (direction === "forward") {
2432
+ const transformed = def.transform(result.value, result);
2433
+ if (transformed instanceof Promise) {
2434
+ return transformed.then(value => handleCodecTxResult(result, value, def.out, ctx));
2435
+ }
2436
+ return handleCodecTxResult(result, transformed, def.out, ctx);
2437
+ } else {
2438
+ const transformed = def.reverseTransform(result.value, result);
2439
+ if (transformed instanceof Promise) {
2440
+ return transformed.then(value => handleCodecTxResult(result, value, def.in, ctx));
2441
+ }
2442
+ return handleCodecTxResult(result, transformed, def.in, ctx);
2443
+ }
2444
+ }
2445
+ function handleCodecTxResult(left, value, nextSchema, ctx) {
2446
+ // Check if transform added any issues
2447
+ if (left.issues.length) {
2448
+ left.aborted = true;
2449
+ return left;
2450
+ }
2451
+ return nextSchema._zod.run({
2452
+ value,
2453
+ issues: left.issues
2454
+ }, ctx);
2455
+ }
2456
+
2457
+ ////////////////////////////////////////////
2458
+ ////////////////////////////////////////////
2459
+ ////////// //////////
2460
+ ////////// $ZodReadonly //////////
2461
+ ////////// //////////
2462
+ ////////////////////////////////////////////
2463
+ ////////////////////////////////////////////
2464
+
2465
+ export const $ZodReadonly = /*@__PURE__*/core.$constructor("$ZodReadonly", (inst, def) => {
2466
+ $ZodType.init(inst, def);
2467
+ util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
2468
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2469
+ util.defineLazy(inst._zod, "optin", () => {
2470
+ var _def$innerType;
2471
+ return (_def$innerType = def.innerType) === null || _def$innerType === void 0 || (_def$innerType = _def$innerType._zod) === null || _def$innerType === void 0 ? void 0 : _def$innerType.optin;
2472
+ });
2473
+ util.defineLazy(inst._zod, "optout", () => {
2474
+ var _def$innerType2;
2475
+ return (_def$innerType2 = def.innerType) === null || _def$innerType2 === void 0 || (_def$innerType2 = _def$innerType2._zod) === null || _def$innerType2 === void 0 ? void 0 : _def$innerType2.optout;
2476
+ });
2477
+ inst._zod.parse = (payload, ctx) => {
2478
+ if (ctx.direction === "backward") {
2479
+ return def.innerType._zod.run(payload, ctx);
2480
+ }
2481
+ const result = def.innerType._zod.run(payload, ctx);
2482
+ if (result instanceof Promise) {
2483
+ return result.then(handleReadonlyResult);
2484
+ }
2485
+ return handleReadonlyResult(result);
2486
+ };
2487
+ });
2488
+ function handleReadonlyResult(payload) {
2489
+ payload.value = Object.freeze(payload.value);
2490
+ return payload;
2491
+ }
2492
+
2493
+ /////////////////////////////////////////////
2494
+ /////////////////////////////////////////////
2495
+ ////////// //////////
2496
+ ////////// $ZodTemplateLiteral //////////
2497
+ ////////// //////////
2498
+ /////////////////////////////////////////////
2499
+ /////////////////////////////////////////////
2500
+
2501
+ //string | number | boolean | null | undefined;
2502
+
2503
+ // type lkjasd = ConcatenateTupleOfStrings<["Hello", " ", "World", "!"]>; // "Hello World!"
2504
+
2505
+ export const $ZodTemplateLiteral = /*@__PURE__*/core.$constructor("$ZodTemplateLiteral", (inst, def) => {
2506
+ $ZodType.init(inst, def);
2507
+ const regexParts = [];
2508
+ for (const part of def.parts) {
2509
+ if (typeof part === "object" && part !== null) {
2510
+ // is Zod schema
2511
+ if (!part._zod.pattern) {
2512
+ // if (!source)
2513
+ throw new Error(`Invalid template literal part, no pattern found: ${[...part._zod.traits].shift()}`);
2514
+ }
2515
+ const source = part._zod.pattern instanceof RegExp ? part._zod.pattern.source : part._zod.pattern;
2516
+ if (!source) throw new Error(`Invalid template literal part: ${part._zod.traits}`);
2517
+ const start = source.startsWith("^") ? 1 : 0;
2518
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
2519
+ regexParts.push(source.slice(start, end));
2520
+ } else if (part === null || util.primitiveTypes.has(typeof part)) {
2521
+ regexParts.push(util.escapeRegex(`${part}`));
2522
+ } else {
2523
+ throw new Error(`Invalid template literal part: ${part}`);
2524
+ }
2525
+ }
2526
+ inst._zod.pattern = new RegExp(`^${regexParts.join("")}$`);
2527
+ inst._zod.parse = payload => {
2528
+ if (typeof payload.value !== "string") {
2529
+ payload.issues.push({
2530
+ input: payload.value,
2531
+ inst,
2532
+ expected: "string",
2533
+ code: "invalid_type"
2534
+ });
2535
+ return payload;
2536
+ }
2537
+ inst._zod.pattern.lastIndex = 0;
2538
+ if (!inst._zod.pattern.test(payload.value)) {
2539
+ var _def$format;
2540
+ payload.issues.push({
2541
+ input: payload.value,
2542
+ inst,
2543
+ code: "invalid_format",
2544
+ format: (_def$format = def.format) !== null && _def$format !== void 0 ? _def$format : "template_literal",
2545
+ pattern: inst._zod.pattern.source
2546
+ });
2547
+ return payload;
2548
+ }
2549
+ return payload;
2550
+ };
2551
+ });
2552
+
2553
+ //////////////////////////////////////////
2554
+ //////////////////////////////////////////
2555
+ ////////// //////////
2556
+ ////////// $ZodFunction //////////
2557
+ ////////// //////////
2558
+ //////////////////////////////////////////
2559
+ //////////////////////////////////////////
2560
+
2561
+ export const $ZodFunction = /*@__PURE__*/core.$constructor("$ZodFunction", (inst, def) => {
2562
+ $ZodType.init(inst, def);
2563
+ inst._def = def;
2564
+ inst._zod.def = def;
2565
+ inst.implement = func => {
2566
+ if (typeof func !== "function") {
2567
+ throw new Error("implement() must be called with a function");
2568
+ }
2569
+ return function () {
2570
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2571
+ args[_key] = arguments[_key];
2572
+ }
2573
+ const parsedArgs = inst._def.input ? parse(inst._def.input, args) : args;
2574
+ const result = Reflect.apply(func, this, parsedArgs);
2575
+ if (inst._def.output) {
2576
+ return parse(inst._def.output, result);
2577
+ }
2578
+ return result;
2579
+ };
2580
+ };
2581
+ inst.implementAsync = func => {
2582
+ if (typeof func !== "function") {
2583
+ throw new Error("implementAsync() must be called with a function");
2584
+ }
2585
+ return async function () {
2586
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2587
+ args[_key2] = arguments[_key2];
2588
+ }
2589
+ const parsedArgs = inst._def.input ? await parseAsync(inst._def.input, args) : args;
2590
+ const result = await Reflect.apply(func, this, parsedArgs);
2591
+ if (inst._def.output) {
2592
+ return await parseAsync(inst._def.output, result);
2593
+ }
2594
+ return result;
2595
+ };
2596
+ };
2597
+ inst._zod.parse = payload => {
2598
+ if (typeof payload.value !== "function") {
2599
+ payload.issues.push({
2600
+ code: "invalid_type",
2601
+ expected: "function",
2602
+ input: payload.value,
2603
+ inst
2604
+ });
2605
+ return payload;
2606
+ }
2607
+
2608
+ // Check if output is a promise type to determine if we should use async implementation
2609
+ const hasPromiseOutput = inst._def.output && inst._def.output._zod.def.type === "promise";
2610
+ if (hasPromiseOutput) {
2611
+ payload.value = inst.implementAsync(payload.value);
2612
+ } else {
2613
+ payload.value = inst.implement(payload.value);
2614
+ }
2615
+ return payload;
2616
+ };
2617
+ inst.input = function () {
2618
+ const F = inst.constructor;
2619
+ if (Array.isArray(arguments.length <= 0 ? undefined : arguments[0])) {
2620
+ return new F({
2621
+ type: "function",
2622
+ input: new $ZodTuple({
2623
+ type: "tuple",
2624
+ items: arguments.length <= 0 ? undefined : arguments[0],
2625
+ rest: arguments.length <= 1 ? undefined : arguments[1]
2626
+ }),
2627
+ output: inst._def.output
2628
+ });
2629
+ }
2630
+ return new F({
2631
+ type: "function",
2632
+ input: arguments.length <= 0 ? undefined : arguments[0],
2633
+ output: inst._def.output
2634
+ });
2635
+ };
2636
+ inst.output = output => {
2637
+ const F = inst.constructor;
2638
+ return new F({
2639
+ type: "function",
2640
+ input: inst._def.input,
2641
+ output
2642
+ });
2643
+ };
2644
+ return inst;
2645
+ });
2646
+
2647
+ /////////////////////////////////////////
2648
+ /////////////////////////////////////////
2649
+ ////////// //////////
2650
+ ////////// $ZodPromise //////////
2651
+ ////////// //////////
2652
+ /////////////////////////////////////////
2653
+ /////////////////////////////////////////
2654
+
2655
+ export const $ZodPromise = /*@__PURE__*/core.$constructor("$ZodPromise", (inst, def) => {
2656
+ $ZodType.init(inst, def);
2657
+ inst._zod.parse = (payload, ctx) => {
2658
+ return Promise.resolve(payload.value).then(inner => def.innerType._zod.run({
2659
+ value: inner,
2660
+ issues: []
2661
+ }, ctx));
2662
+ };
2663
+ });
2664
+
2665
+ //////////////////////////////////////////
2666
+ //////////////////////////////////////////
2667
+ ////////// //////////
2668
+ ////////// $ZodLazy //////////
2669
+ ////////// //////////
2670
+ //////////////////////////////////////////
2671
+ //////////////////////////////////////////
2672
+
2673
+ export const $ZodLazy = /*@__PURE__*/core.$constructor("$ZodLazy", (inst, def) => {
2674
+ $ZodType.init(inst, def);
2675
+
2676
+ // let _innerType!: any;
2677
+ // util.defineLazy(def, "getter", () => {
2678
+ // if (!_innerType) {
2679
+ // _innerType = def.getter();
2680
+ // }
2681
+ // return () => _innerType;
2682
+ // });
2683
+ util.defineLazy(inst._zod, "innerType", () => def.getter());
2684
+ util.defineLazy(inst._zod, "pattern", () => {
2685
+ var _inst$_zod$innerType;
2686
+ return (_inst$_zod$innerType = inst._zod.innerType) === null || _inst$_zod$innerType === void 0 || (_inst$_zod$innerType = _inst$_zod$innerType._zod) === null || _inst$_zod$innerType === void 0 ? void 0 : _inst$_zod$innerType.pattern;
2687
+ });
2688
+ util.defineLazy(inst._zod, "propValues", () => {
2689
+ var _inst$_zod$innerType2;
2690
+ return (_inst$_zod$innerType2 = inst._zod.innerType) === null || _inst$_zod$innerType2 === void 0 || (_inst$_zod$innerType2 = _inst$_zod$innerType2._zod) === null || _inst$_zod$innerType2 === void 0 ? void 0 : _inst$_zod$innerType2.propValues;
2691
+ });
2692
+ util.defineLazy(inst._zod, "optin", () => {
2693
+ var _inst$_zod$innerType$, _inst$_zod$innerType3;
2694
+ return (_inst$_zod$innerType$ = (_inst$_zod$innerType3 = inst._zod.innerType) === null || _inst$_zod$innerType3 === void 0 || (_inst$_zod$innerType3 = _inst$_zod$innerType3._zod) === null || _inst$_zod$innerType3 === void 0 ? void 0 : _inst$_zod$innerType3.optin) !== null && _inst$_zod$innerType$ !== void 0 ? _inst$_zod$innerType$ : undefined;
2695
+ });
2696
+ util.defineLazy(inst._zod, "optout", () => {
2697
+ var _inst$_zod$innerType$2, _inst$_zod$innerType4;
2698
+ return (_inst$_zod$innerType$2 = (_inst$_zod$innerType4 = inst._zod.innerType) === null || _inst$_zod$innerType4 === void 0 || (_inst$_zod$innerType4 = _inst$_zod$innerType4._zod) === null || _inst$_zod$innerType4 === void 0 ? void 0 : _inst$_zod$innerType4.optout) !== null && _inst$_zod$innerType$2 !== void 0 ? _inst$_zod$innerType$2 : undefined;
2699
+ });
2700
+ inst._zod.parse = (payload, ctx) => {
2701
+ const inner = inst._zod.innerType;
2702
+ return inner._zod.run(payload, ctx);
2703
+ };
2704
+ });
2705
+
2706
+ ////////////////////////////////////////
2707
+ ////////////////////////////////////////
2708
+ ////////// //////////
2709
+ ////////// $ZodCustom //////////
2710
+ ////////// //////////
2711
+ ////////////////////////////////////////
2712
+ ////////////////////////////////////////
2713
+
2714
+ export const $ZodCustom = /*@__PURE__*/core.$constructor("$ZodCustom", (inst, def) => {
2715
+ checks.$ZodCheck.init(inst, def);
2716
+ $ZodType.init(inst, def);
2717
+ inst._zod.parse = payload => {
2718
+ return payload;
2719
+ };
2720
+ inst._zod.check = payload => {
2721
+ const input = payload.value;
2722
+ const r = def.fn(input);
2723
+ if (r instanceof Promise) {
2724
+ return r.then(r => handleRefineResult(r, payload, input, inst));
2725
+ }
2726
+ handleRefineResult(r, payload, input, inst);
2727
+ };
2728
+ });
2729
+ function handleRefineResult(result, payload, input, inst) {
2730
+ if (!result) {
2731
+ var _inst$_zod$def$path;
2732
+ const _iss = {
2733
+ code: "custom",
2734
+ input,
2735
+ inst,
2736
+ // incorporates params.error into issue reporting
2737
+ path: [...((_inst$_zod$def$path = inst._zod.def.path) !== null && _inst$_zod$def$path !== void 0 ? _inst$_zod$def$path : [])],
2738
+ // incorporates params.error into issue reporting
2739
+ continue: !inst._zod.def.abort
2740
+ // params: inst._zod.def.params,
2741
+ };
2742
+ if (inst._zod.def.params) _iss.params = inst._zod.def.params;
2743
+ payload.issues.push(util.issue(_iss));
2744
+ }
2745
+ }