@columnus/shared 0.1.47

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