@animaapp/anima-sdk 0.3.11 → 0.3.12

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