@onlive.ai/flow-client 0.0.3

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,3301 @@
1
+ var Ue = Object.defineProperty;
2
+ var Be = (n, e, t) => e in n ? Ue(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var V = (n, e, t) => Be(n, typeof e != "symbol" ? e + "" : e, t);
4
+ var b;
5
+ (function(n) {
6
+ n.assertEqual = (s) => s;
7
+ function e(s) {
8
+ }
9
+ n.assertIs = e;
10
+ function t(s) {
11
+ throw new Error();
12
+ }
13
+ n.assertNever = t, n.arrayToEnum = (s) => {
14
+ const a = {};
15
+ for (const i of s)
16
+ a[i] = i;
17
+ return a;
18
+ }, n.getValidEnumValues = (s) => {
19
+ const a = n.objectKeys(s).filter((o) => typeof s[s[o]] != "number"), i = {};
20
+ for (const o of a)
21
+ i[o] = s[o];
22
+ return n.objectValues(i);
23
+ }, n.objectValues = (s) => n.objectKeys(s).map(function(a) {
24
+ return s[a];
25
+ }), n.objectKeys = typeof Object.keys == "function" ? (s) => Object.keys(s) : (s) => {
26
+ const a = [];
27
+ for (const i in s)
28
+ Object.prototype.hasOwnProperty.call(s, i) && a.push(i);
29
+ return a;
30
+ }, n.find = (s, a) => {
31
+ for (const i of s)
32
+ if (a(i))
33
+ return i;
34
+ }, n.isInteger = typeof Number.isInteger == "function" ? (s) => Number.isInteger(s) : (s) => typeof s == "number" && isFinite(s) && Math.floor(s) === s;
35
+ function r(s, a = " | ") {
36
+ return s.map((i) => typeof i == "string" ? `'${i}'` : i).join(a);
37
+ }
38
+ n.joinValues = r, n.jsonStringifyReplacer = (s, a) => typeof a == "bigint" ? a.toString() : a;
39
+ })(b || (b = {}));
40
+ var we;
41
+ (function(n) {
42
+ n.mergeShapes = (e, t) => ({
43
+ ...e,
44
+ ...t
45
+ // second overwrites first
46
+ });
47
+ })(we || (we = {}));
48
+ const h = b.arrayToEnum([
49
+ "string",
50
+ "nan",
51
+ "number",
52
+ "integer",
53
+ "float",
54
+ "boolean",
55
+ "date",
56
+ "bigint",
57
+ "symbol",
58
+ "function",
59
+ "undefined",
60
+ "null",
61
+ "array",
62
+ "object",
63
+ "unknown",
64
+ "promise",
65
+ "void",
66
+ "never",
67
+ "map",
68
+ "set"
69
+ ]), N = (n) => {
70
+ switch (typeof n) {
71
+ case "undefined":
72
+ return h.undefined;
73
+ case "string":
74
+ return h.string;
75
+ case "number":
76
+ return isNaN(n) ? h.nan : h.number;
77
+ case "boolean":
78
+ return h.boolean;
79
+ case "function":
80
+ return h.function;
81
+ case "bigint":
82
+ return h.bigint;
83
+ case "symbol":
84
+ return h.symbol;
85
+ case "object":
86
+ return Array.isArray(n) ? h.array : n === null ? h.null : n.then && typeof n.then == "function" && n.catch && typeof n.catch == "function" ? h.promise : typeof Map < "u" && n instanceof Map ? h.map : typeof Set < "u" && n instanceof Set ? h.set : typeof Date < "u" && n instanceof Date ? h.date : h.object;
87
+ default:
88
+ return h.unknown;
89
+ }
90
+ }, c = b.arrayToEnum([
91
+ "invalid_type",
92
+ "invalid_literal",
93
+ "custom",
94
+ "invalid_union",
95
+ "invalid_union_discriminator",
96
+ "invalid_enum_value",
97
+ "unrecognized_keys",
98
+ "invalid_arguments",
99
+ "invalid_return_type",
100
+ "invalid_date",
101
+ "invalid_string",
102
+ "too_small",
103
+ "too_big",
104
+ "invalid_intersection_types",
105
+ "not_multiple_of",
106
+ "not_finite"
107
+ ]), Fe = (n) => JSON.stringify(n, null, 2).replace(/"([^"]+)":/g, "$1:");
108
+ class T extends Error {
109
+ get errors() {
110
+ return this.issues;
111
+ }
112
+ constructor(e) {
113
+ super(), this.issues = [], this.addIssue = (r) => {
114
+ this.issues = [...this.issues, r];
115
+ }, this.addIssues = (r = []) => {
116
+ this.issues = [...this.issues, ...r];
117
+ };
118
+ const t = new.target.prototype;
119
+ Object.setPrototypeOf ? Object.setPrototypeOf(this, t) : this.__proto__ = t, this.name = "ZodError", this.issues = e;
120
+ }
121
+ format(e) {
122
+ const t = e || function(a) {
123
+ return a.message;
124
+ }, r = { _errors: [] }, s = (a) => {
125
+ for (const i of a.issues)
126
+ if (i.code === "invalid_union")
127
+ i.unionErrors.map(s);
128
+ else if (i.code === "invalid_return_type")
129
+ s(i.returnTypeError);
130
+ else if (i.code === "invalid_arguments")
131
+ s(i.argumentsError);
132
+ else if (i.path.length === 0)
133
+ r._errors.push(t(i));
134
+ else {
135
+ let o = r, f = 0;
136
+ for (; f < i.path.length; ) {
137
+ const l = i.path[f];
138
+ f === i.path.length - 1 ? (o[l] = o[l] || { _errors: [] }, o[l]._errors.push(t(i))) : o[l] = o[l] || { _errors: [] }, o = o[l], f++;
139
+ }
140
+ }
141
+ };
142
+ return s(this), r;
143
+ }
144
+ static assert(e) {
145
+ if (!(e instanceof T))
146
+ throw new Error(`Not a ZodError: ${e}`);
147
+ }
148
+ toString() {
149
+ return this.message;
150
+ }
151
+ get message() {
152
+ return JSON.stringify(this.issues, b.jsonStringifyReplacer, 2);
153
+ }
154
+ get isEmpty() {
155
+ return this.issues.length === 0;
156
+ }
157
+ flatten(e = (t) => t.message) {
158
+ const t = {}, r = [];
159
+ for (const s of this.issues)
160
+ s.path.length > 0 ? (t[s.path[0]] = t[s.path[0]] || [], t[s.path[0]].push(e(s))) : r.push(e(s));
161
+ return { formErrors: r, fieldErrors: t };
162
+ }
163
+ get formErrors() {
164
+ return this.flatten();
165
+ }
166
+ }
167
+ T.create = (n) => new T(n);
168
+ const J = (n, e) => {
169
+ let t;
170
+ switch (n.code) {
171
+ case c.invalid_type:
172
+ n.received === h.undefined ? t = "Required" : t = `Expected ${n.expected}, received ${n.received}`;
173
+ break;
174
+ case c.invalid_literal:
175
+ t = `Invalid literal value, expected ${JSON.stringify(n.expected, b.jsonStringifyReplacer)}`;
176
+ break;
177
+ case c.unrecognized_keys:
178
+ t = `Unrecognized key(s) in object: ${b.joinValues(n.keys, ", ")}`;
179
+ break;
180
+ case c.invalid_union:
181
+ t = "Invalid input";
182
+ break;
183
+ case c.invalid_union_discriminator:
184
+ t = `Invalid discriminator value. Expected ${b.joinValues(n.options)}`;
185
+ break;
186
+ case c.invalid_enum_value:
187
+ t = `Invalid enum value. Expected ${b.joinValues(n.options)}, received '${n.received}'`;
188
+ break;
189
+ case c.invalid_arguments:
190
+ t = "Invalid function arguments";
191
+ break;
192
+ case c.invalid_return_type:
193
+ t = "Invalid function return type";
194
+ break;
195
+ case c.invalid_date:
196
+ t = "Invalid date";
197
+ break;
198
+ case c.invalid_string:
199
+ typeof n.validation == "object" ? "includes" in n.validation ? (t = `Invalid input: must include "${n.validation.includes}"`, typeof n.validation.position == "number" && (t = `${t} at one or more positions greater than or equal to ${n.validation.position}`)) : "startsWith" in n.validation ? t = `Invalid input: must start with "${n.validation.startsWith}"` : "endsWith" in n.validation ? t = `Invalid input: must end with "${n.validation.endsWith}"` : b.assertNever(n.validation) : n.validation !== "regex" ? t = `Invalid ${n.validation}` : t = "Invalid";
200
+ break;
201
+ case c.too_small:
202
+ n.type === "array" ? t = `Array must contain ${n.exact ? "exactly" : n.inclusive ? "at least" : "more than"} ${n.minimum} element(s)` : n.type === "string" ? t = `String must contain ${n.exact ? "exactly" : n.inclusive ? "at least" : "over"} ${n.minimum} character(s)` : n.type === "number" ? t = `Number must be ${n.exact ? "exactly equal to " : n.inclusive ? "greater than or equal to " : "greater than "}${n.minimum}` : n.type === "date" ? t = `Date must be ${n.exact ? "exactly equal to " : n.inclusive ? "greater than or equal to " : "greater than "}${new Date(Number(n.minimum))}` : t = "Invalid input";
203
+ break;
204
+ case c.too_big:
205
+ n.type === "array" ? t = `Array must contain ${n.exact ? "exactly" : n.inclusive ? "at most" : "less than"} ${n.maximum} element(s)` : n.type === "string" ? t = `String must contain ${n.exact ? "exactly" : n.inclusive ? "at most" : "under"} ${n.maximum} character(s)` : n.type === "number" ? t = `Number must be ${n.exact ? "exactly" : n.inclusive ? "less than or equal to" : "less than"} ${n.maximum}` : n.type === "bigint" ? t = `BigInt must be ${n.exact ? "exactly" : n.inclusive ? "less than or equal to" : "less than"} ${n.maximum}` : n.type === "date" ? t = `Date must be ${n.exact ? "exactly" : n.inclusive ? "smaller than or equal to" : "smaller than"} ${new Date(Number(n.maximum))}` : t = "Invalid input";
206
+ break;
207
+ case c.custom:
208
+ t = "Invalid input";
209
+ break;
210
+ case c.invalid_intersection_types:
211
+ t = "Intersection results could not be merged";
212
+ break;
213
+ case c.not_multiple_of:
214
+ t = `Number must be a multiple of ${n.multipleOf}`;
215
+ break;
216
+ case c.not_finite:
217
+ t = "Number must be finite";
218
+ break;
219
+ default:
220
+ t = e.defaultError, b.assertNever(n);
221
+ }
222
+ return { message: t };
223
+ };
224
+ let Re = J;
225
+ function qe(n) {
226
+ Re = n;
227
+ }
228
+ function fe() {
229
+ return Re;
230
+ }
231
+ const he = (n) => {
232
+ const { data: e, path: t, errorMaps: r, issueData: s } = n, a = [...t, ...s.path || []], i = {
233
+ ...s,
234
+ path: a
235
+ };
236
+ if (s.message !== void 0)
237
+ return {
238
+ ...s,
239
+ path: a,
240
+ message: s.message
241
+ };
242
+ let o = "";
243
+ const f = r.filter((l) => !!l).slice().reverse();
244
+ for (const l of f)
245
+ o = l(i, { data: e, defaultError: o }).message;
246
+ return {
247
+ ...s,
248
+ path: a,
249
+ message: o
250
+ };
251
+ }, We = [];
252
+ function u(n, e) {
253
+ const t = fe(), r = he({
254
+ issueData: e,
255
+ data: n.data,
256
+ path: n.path,
257
+ errorMaps: [
258
+ n.common.contextualErrorMap,
259
+ // contextual error map is first priority
260
+ n.schemaErrorMap,
261
+ // then schema-bound map if available
262
+ t,
263
+ // then global override map
264
+ t === J ? void 0 : J
265
+ // then global default map
266
+ ].filter((s) => !!s)
267
+ });
268
+ n.common.issues.push(r);
269
+ }
270
+ class k {
271
+ constructor() {
272
+ this.value = "valid";
273
+ }
274
+ dirty() {
275
+ this.value === "valid" && (this.value = "dirty");
276
+ }
277
+ abort() {
278
+ this.value !== "aborted" && (this.value = "aborted");
279
+ }
280
+ static mergeArray(e, t) {
281
+ const r = [];
282
+ for (const s of t) {
283
+ if (s.status === "aborted")
284
+ return y;
285
+ s.status === "dirty" && e.dirty(), r.push(s.value);
286
+ }
287
+ return { status: e.value, value: r };
288
+ }
289
+ static async mergeObjectAsync(e, t) {
290
+ const r = [];
291
+ for (const s of t) {
292
+ const a = await s.key, i = await s.value;
293
+ r.push({
294
+ key: a,
295
+ value: i
296
+ });
297
+ }
298
+ return k.mergeObjectSync(e, r);
299
+ }
300
+ static mergeObjectSync(e, t) {
301
+ const r = {};
302
+ for (const s of t) {
303
+ const { key: a, value: i } = s;
304
+ if (a.status === "aborted" || i.status === "aborted")
305
+ return y;
306
+ a.status === "dirty" && e.dirty(), i.status === "dirty" && e.dirty(), a.value !== "__proto__" && (typeof i.value < "u" || s.alwaysSet) && (r[a.value] = i.value);
307
+ }
308
+ return { status: e.value, value: r };
309
+ }
310
+ }
311
+ const y = Object.freeze({
312
+ status: "aborted"
313
+ }), q = (n) => ({ status: "dirty", value: n }), w = (n) => ({ status: "valid", value: n }), Te = (n) => n.status === "aborted", Se = (n) => n.status === "dirty", D = (n) => n.status === "valid", K = (n) => typeof Promise < "u" && n instanceof Promise;
314
+ function pe(n, e, t, r) {
315
+ if (typeof e == "function" ? n !== e || !0 : !e.has(n)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
316
+ return e.get(n);
317
+ }
318
+ function Ae(n, e, t, r, s) {
319
+ if (typeof e == "function" ? n !== e || !0 : !e.has(n)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
320
+ return e.set(n, t), t;
321
+ }
322
+ var p;
323
+ (function(n) {
324
+ n.errToObj = (e) => typeof e == "string" ? { message: e } : e || {}, n.toString = (e) => typeof e == "string" ? e : e == null ? void 0 : e.message;
325
+ })(p || (p = {}));
326
+ var G, X;
327
+ class j {
328
+ constructor(e, t, r, s) {
329
+ this._cachedPath = [], this.parent = e, this.data = t, this._path = r, this._key = s;
330
+ }
331
+ get path() {
332
+ return this._cachedPath.length || (this._key instanceof Array ? this._cachedPath.push(...this._path, ...this._key) : this._cachedPath.push(...this._path, this._key)), this._cachedPath;
333
+ }
334
+ }
335
+ const Oe = (n, e) => {
336
+ if (D(e))
337
+ return { success: !0, data: e.value };
338
+ if (!n.common.issues.length)
339
+ throw new Error("Validation failed but no issues detected.");
340
+ return {
341
+ success: !1,
342
+ get error() {
343
+ if (this._error)
344
+ return this._error;
345
+ const t = new T(n.common.issues);
346
+ return this._error = t, this._error;
347
+ }
348
+ };
349
+ };
350
+ function _(n) {
351
+ if (!n)
352
+ return {};
353
+ const { errorMap: e, invalid_type_error: t, required_error: r, description: s } = n;
354
+ if (e && (t || r))
355
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
356
+ return e ? { errorMap: e, description: s } : { errorMap: (i, o) => {
357
+ var f, l;
358
+ const { message: g } = n;
359
+ return i.code === "invalid_enum_value" ? { message: g ?? o.defaultError } : typeof o.data > "u" ? { message: (f = g ?? r) !== null && f !== void 0 ? f : o.defaultError } : i.code !== "invalid_type" ? { message: o.defaultError } : { message: (l = g ?? t) !== null && l !== void 0 ? l : o.defaultError };
360
+ }, description: s };
361
+ }
362
+ class v {
363
+ get description() {
364
+ return this._def.description;
365
+ }
366
+ _getType(e) {
367
+ return N(e.data);
368
+ }
369
+ _getOrReturnCtx(e, t) {
370
+ return t || {
371
+ common: e.parent.common,
372
+ data: e.data,
373
+ parsedType: N(e.data),
374
+ schemaErrorMap: this._def.errorMap,
375
+ path: e.path,
376
+ parent: e.parent
377
+ };
378
+ }
379
+ _processInputParams(e) {
380
+ return {
381
+ status: new k(),
382
+ ctx: {
383
+ common: e.parent.common,
384
+ data: e.data,
385
+ parsedType: N(e.data),
386
+ schemaErrorMap: this._def.errorMap,
387
+ path: e.path,
388
+ parent: e.parent
389
+ }
390
+ };
391
+ }
392
+ _parseSync(e) {
393
+ const t = this._parse(e);
394
+ if (K(t))
395
+ throw new Error("Synchronous parse encountered promise.");
396
+ return t;
397
+ }
398
+ _parseAsync(e) {
399
+ const t = this._parse(e);
400
+ return Promise.resolve(t);
401
+ }
402
+ parse(e, t) {
403
+ const r = this.safeParse(e, t);
404
+ if (r.success)
405
+ return r.data;
406
+ throw r.error;
407
+ }
408
+ safeParse(e, t) {
409
+ var r;
410
+ const s = {
411
+ common: {
412
+ issues: [],
413
+ async: (r = t == null ? void 0 : t.async) !== null && r !== void 0 ? r : !1,
414
+ contextualErrorMap: t == null ? void 0 : t.errorMap
415
+ },
416
+ path: (t == null ? void 0 : t.path) || [],
417
+ schemaErrorMap: this._def.errorMap,
418
+ parent: null,
419
+ data: e,
420
+ parsedType: N(e)
421
+ }, a = this._parseSync({ data: e, path: s.path, parent: s });
422
+ return Oe(s, a);
423
+ }
424
+ "~validate"(e) {
425
+ var t, r;
426
+ const s = {
427
+ common: {
428
+ issues: [],
429
+ async: !!this["~standard"].async
430
+ },
431
+ path: [],
432
+ schemaErrorMap: this._def.errorMap,
433
+ parent: null,
434
+ data: e,
435
+ parsedType: N(e)
436
+ };
437
+ if (!this["~standard"].async)
438
+ try {
439
+ const a = this._parseSync({ data: e, path: [], parent: s });
440
+ return D(a) ? {
441
+ value: a.value
442
+ } : {
443
+ issues: s.common.issues
444
+ };
445
+ } catch (a) {
446
+ !((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), s.common = {
447
+ issues: [],
448
+ async: !0
449
+ };
450
+ }
451
+ return this._parseAsync({ data: e, path: [], parent: s }).then((a) => D(a) ? {
452
+ value: a.value
453
+ } : {
454
+ issues: s.common.issues
455
+ });
456
+ }
457
+ async parseAsync(e, t) {
458
+ const r = await this.safeParseAsync(e, t);
459
+ if (r.success)
460
+ return r.data;
461
+ throw r.error;
462
+ }
463
+ async safeParseAsync(e, t) {
464
+ const r = {
465
+ common: {
466
+ issues: [],
467
+ contextualErrorMap: t == null ? void 0 : t.errorMap,
468
+ async: !0
469
+ },
470
+ path: (t == null ? void 0 : t.path) || [],
471
+ schemaErrorMap: this._def.errorMap,
472
+ parent: null,
473
+ data: e,
474
+ parsedType: N(e)
475
+ }, s = this._parse({ data: e, path: r.path, parent: r }), a = await (K(s) ? s : Promise.resolve(s));
476
+ return Oe(r, a);
477
+ }
478
+ refine(e, t) {
479
+ const r = (s) => typeof t == "string" || typeof t > "u" ? { message: t } : typeof t == "function" ? t(s) : t;
480
+ return this._refinement((s, a) => {
481
+ const i = e(s), o = () => a.addIssue({
482
+ code: c.custom,
483
+ ...r(s)
484
+ });
485
+ return typeof Promise < "u" && i instanceof Promise ? i.then((f) => f ? !0 : (o(), !1)) : i ? !0 : (o(), !1);
486
+ });
487
+ }
488
+ refinement(e, t) {
489
+ return this._refinement((r, s) => e(r) ? !0 : (s.addIssue(typeof t == "function" ? t(r, s) : t), !1));
490
+ }
491
+ _refinement(e) {
492
+ return new I({
493
+ schema: this,
494
+ typeName: m.ZodEffects,
495
+ effect: { type: "refinement", refinement: e }
496
+ });
497
+ }
498
+ superRefine(e) {
499
+ return this._refinement(e);
500
+ }
501
+ constructor(e) {
502
+ 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"] = {
503
+ version: 1,
504
+ vendor: "zod",
505
+ validate: (t) => this["~validate"](t)
506
+ };
507
+ }
508
+ optional() {
509
+ return O.create(this, this._def);
510
+ }
511
+ nullable() {
512
+ return P.create(this, this._def);
513
+ }
514
+ nullish() {
515
+ return this.nullable().optional();
516
+ }
517
+ array() {
518
+ return C.create(this);
519
+ }
520
+ promise() {
521
+ return Y.create(this, this._def);
522
+ }
523
+ or(e) {
524
+ return ne.create([this, e], this._def);
525
+ }
526
+ and(e) {
527
+ return re.create(this, e, this._def);
528
+ }
529
+ transform(e) {
530
+ return new I({
531
+ ..._(this._def),
532
+ schema: this,
533
+ typeName: m.ZodEffects,
534
+ effect: { type: "transform", transform: e }
535
+ });
536
+ }
537
+ default(e) {
538
+ const t = typeof e == "function" ? e : () => e;
539
+ return new de({
540
+ ..._(this._def),
541
+ innerType: this,
542
+ defaultValue: t,
543
+ typeName: m.ZodDefault
544
+ });
545
+ }
546
+ brand() {
547
+ return new Ce({
548
+ typeName: m.ZodBranded,
549
+ type: this,
550
+ ..._(this._def)
551
+ });
552
+ }
553
+ catch(e) {
554
+ const t = typeof e == "function" ? e : () => e;
555
+ return new ce({
556
+ ..._(this._def),
557
+ innerType: this,
558
+ catchValue: t,
559
+ typeName: m.ZodCatch
560
+ });
561
+ }
562
+ describe(e) {
563
+ const t = this.constructor;
564
+ return new t({
565
+ ...this._def,
566
+ description: e
567
+ });
568
+ }
569
+ pipe(e) {
570
+ return le.create(this, e);
571
+ }
572
+ readonly() {
573
+ return ue.create(this);
574
+ }
575
+ isOptional() {
576
+ return this.safeParse(void 0).success;
577
+ }
578
+ isNullable() {
579
+ return this.safeParse(null).success;
580
+ }
581
+ }
582
+ const Je = /^c[^\s-]{8,}$/i, He = /^[0-9a-z]+$/, Ye = /^[0-9A-HJKMNP-TV-Z]{26}$/i, Ge = /^[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, Xe = /^[a-z0-9_-]{21}$/i, Ke = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/, Qe = /^[-+]?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)?)??$/, et = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i, tt = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";
583
+ let xe;
584
+ const nt = /^(?:(?: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])$/, rt = /^(?:(?: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])$/, st = /^(([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]))$/, at = /^(([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])$/, it = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/, ot = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/, Ne = "((\\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])))", dt = new RegExp(`^${Ne}$`);
585
+ function Ee(n) {
586
+ let e = "([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";
587
+ return n.precision ? e = `${e}\\.\\d{${n.precision}}` : n.precision == null && (e = `${e}(\\.\\d+)?`), e;
588
+ }
589
+ function ct(n) {
590
+ return new RegExp(`^${Ee(n)}$`);
591
+ }
592
+ function $e(n) {
593
+ let e = `${Ne}T${Ee(n)}`;
594
+ const t = [];
595
+ return t.push(n.local ? "Z?" : "Z"), n.offset && t.push("([+-]\\d{2}:?\\d{2})"), e = `${e}(${t.join("|")})`, new RegExp(`^${e}$`);
596
+ }
597
+ function ut(n, e) {
598
+ return !!((e === "v4" || !e) && nt.test(n) || (e === "v6" || !e) && st.test(n));
599
+ }
600
+ function lt(n, e) {
601
+ if (!Ke.test(n))
602
+ return !1;
603
+ try {
604
+ const [t] = n.split("."), r = t.replace(/-/g, "+").replace(/_/g, "/").padEnd(t.length + (4 - t.length % 4) % 4, "="), s = JSON.parse(atob(r));
605
+ return !(typeof s != "object" || s === null || !s.typ || !s.alg || e && s.alg !== e);
606
+ } catch {
607
+ return !1;
608
+ }
609
+ }
610
+ function ft(n, e) {
611
+ return !!((e === "v4" || !e) && rt.test(n) || (e === "v6" || !e) && at.test(n));
612
+ }
613
+ class Z extends v {
614
+ _parse(e) {
615
+ if (this._def.coerce && (e.data = String(e.data)), this._getType(e) !== h.string) {
616
+ const a = this._getOrReturnCtx(e);
617
+ return u(a, {
618
+ code: c.invalid_type,
619
+ expected: h.string,
620
+ received: a.parsedType
621
+ }), y;
622
+ }
623
+ const r = new k();
624
+ let s;
625
+ for (const a of this._def.checks)
626
+ if (a.kind === "min")
627
+ e.data.length < a.value && (s = this._getOrReturnCtx(e, s), u(s, {
628
+ code: c.too_small,
629
+ minimum: a.value,
630
+ type: "string",
631
+ inclusive: !0,
632
+ exact: !1,
633
+ message: a.message
634
+ }), r.dirty());
635
+ else if (a.kind === "max")
636
+ e.data.length > a.value && (s = this._getOrReturnCtx(e, s), u(s, {
637
+ code: c.too_big,
638
+ maximum: a.value,
639
+ type: "string",
640
+ inclusive: !0,
641
+ exact: !1,
642
+ message: a.message
643
+ }), r.dirty());
644
+ else if (a.kind === "length") {
645
+ const i = e.data.length > a.value, o = e.data.length < a.value;
646
+ (i || o) && (s = this._getOrReturnCtx(e, s), i ? u(s, {
647
+ code: c.too_big,
648
+ maximum: a.value,
649
+ type: "string",
650
+ inclusive: !0,
651
+ exact: !0,
652
+ message: a.message
653
+ }) : o && u(s, {
654
+ code: c.too_small,
655
+ minimum: a.value,
656
+ type: "string",
657
+ inclusive: !0,
658
+ exact: !0,
659
+ message: a.message
660
+ }), r.dirty());
661
+ } else if (a.kind === "email")
662
+ et.test(e.data) || (s = this._getOrReturnCtx(e, s), u(s, {
663
+ validation: "email",
664
+ code: c.invalid_string,
665
+ message: a.message
666
+ }), r.dirty());
667
+ else if (a.kind === "emoji")
668
+ xe || (xe = new RegExp(tt, "u")), xe.test(e.data) || (s = this._getOrReturnCtx(e, s), u(s, {
669
+ validation: "emoji",
670
+ code: c.invalid_string,
671
+ message: a.message
672
+ }), r.dirty());
673
+ else if (a.kind === "uuid")
674
+ Ge.test(e.data) || (s = this._getOrReturnCtx(e, s), u(s, {
675
+ validation: "uuid",
676
+ code: c.invalid_string,
677
+ message: a.message
678
+ }), r.dirty());
679
+ else if (a.kind === "nanoid")
680
+ Xe.test(e.data) || (s = this._getOrReturnCtx(e, s), u(s, {
681
+ validation: "nanoid",
682
+ code: c.invalid_string,
683
+ message: a.message
684
+ }), r.dirty());
685
+ else if (a.kind === "cuid")
686
+ Je.test(e.data) || (s = this._getOrReturnCtx(e, s), u(s, {
687
+ validation: "cuid",
688
+ code: c.invalid_string,
689
+ message: a.message
690
+ }), r.dirty());
691
+ else if (a.kind === "cuid2")
692
+ He.test(e.data) || (s = this._getOrReturnCtx(e, s), u(s, {
693
+ validation: "cuid2",
694
+ code: c.invalid_string,
695
+ message: a.message
696
+ }), r.dirty());
697
+ else if (a.kind === "ulid")
698
+ Ye.test(e.data) || (s = this._getOrReturnCtx(e, s), u(s, {
699
+ validation: "ulid",
700
+ code: c.invalid_string,
701
+ message: a.message
702
+ }), r.dirty());
703
+ else if (a.kind === "url")
704
+ try {
705
+ new URL(e.data);
706
+ } catch {
707
+ s = this._getOrReturnCtx(e, s), u(s, {
708
+ validation: "url",
709
+ code: c.invalid_string,
710
+ message: a.message
711
+ }), r.dirty();
712
+ }
713
+ else a.kind === "regex" ? (a.regex.lastIndex = 0, a.regex.test(e.data) || (s = this._getOrReturnCtx(e, s), u(s, {
714
+ validation: "regex",
715
+ code: c.invalid_string,
716
+ message: a.message
717
+ }), r.dirty())) : a.kind === "trim" ? e.data = e.data.trim() : a.kind === "includes" ? e.data.includes(a.value, a.position) || (s = this._getOrReturnCtx(e, s), u(s, {
718
+ code: c.invalid_string,
719
+ validation: { includes: a.value, position: a.position },
720
+ message: a.message
721
+ }), 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) || (s = this._getOrReturnCtx(e, s), u(s, {
722
+ code: c.invalid_string,
723
+ validation: { startsWith: a.value },
724
+ message: a.message
725
+ }), r.dirty()) : a.kind === "endsWith" ? e.data.endsWith(a.value) || (s = this._getOrReturnCtx(e, s), u(s, {
726
+ code: c.invalid_string,
727
+ validation: { endsWith: a.value },
728
+ message: a.message
729
+ }), r.dirty()) : a.kind === "datetime" ? $e(a).test(e.data) || (s = this._getOrReturnCtx(e, s), u(s, {
730
+ code: c.invalid_string,
731
+ validation: "datetime",
732
+ message: a.message
733
+ }), r.dirty()) : a.kind === "date" ? dt.test(e.data) || (s = this._getOrReturnCtx(e, s), u(s, {
734
+ code: c.invalid_string,
735
+ validation: "date",
736
+ message: a.message
737
+ }), r.dirty()) : a.kind === "time" ? ct(a).test(e.data) || (s = this._getOrReturnCtx(e, s), u(s, {
738
+ code: c.invalid_string,
739
+ validation: "time",
740
+ message: a.message
741
+ }), r.dirty()) : a.kind === "duration" ? Qe.test(e.data) || (s = this._getOrReturnCtx(e, s), u(s, {
742
+ validation: "duration",
743
+ code: c.invalid_string,
744
+ message: a.message
745
+ }), r.dirty()) : a.kind === "ip" ? ut(e.data, a.version) || (s = this._getOrReturnCtx(e, s), u(s, {
746
+ validation: "ip",
747
+ code: c.invalid_string,
748
+ message: a.message
749
+ }), r.dirty()) : a.kind === "jwt" ? lt(e.data, a.alg) || (s = this._getOrReturnCtx(e, s), u(s, {
750
+ validation: "jwt",
751
+ code: c.invalid_string,
752
+ message: a.message
753
+ }), r.dirty()) : a.kind === "cidr" ? ft(e.data, a.version) || (s = this._getOrReturnCtx(e, s), u(s, {
754
+ validation: "cidr",
755
+ code: c.invalid_string,
756
+ message: a.message
757
+ }), r.dirty()) : a.kind === "base64" ? it.test(e.data) || (s = this._getOrReturnCtx(e, s), u(s, {
758
+ validation: "base64",
759
+ code: c.invalid_string,
760
+ message: a.message
761
+ }), r.dirty()) : a.kind === "base64url" ? ot.test(e.data) || (s = this._getOrReturnCtx(e, s), u(s, {
762
+ validation: "base64url",
763
+ code: c.invalid_string,
764
+ message: a.message
765
+ }), r.dirty()) : b.assertNever(a);
766
+ return { status: r.value, value: e.data };
767
+ }
768
+ _regex(e, t, r) {
769
+ return this.refinement((s) => e.test(s), {
770
+ validation: t,
771
+ code: c.invalid_string,
772
+ ...p.errToObj(r)
773
+ });
774
+ }
775
+ _addCheck(e) {
776
+ return new Z({
777
+ ...this._def,
778
+ checks: [...this._def.checks, e]
779
+ });
780
+ }
781
+ email(e) {
782
+ return this._addCheck({ kind: "email", ...p.errToObj(e) });
783
+ }
784
+ url(e) {
785
+ return this._addCheck({ kind: "url", ...p.errToObj(e) });
786
+ }
787
+ emoji(e) {
788
+ return this._addCheck({ kind: "emoji", ...p.errToObj(e) });
789
+ }
790
+ uuid(e) {
791
+ return this._addCheck({ kind: "uuid", ...p.errToObj(e) });
792
+ }
793
+ nanoid(e) {
794
+ return this._addCheck({ kind: "nanoid", ...p.errToObj(e) });
795
+ }
796
+ cuid(e) {
797
+ return this._addCheck({ kind: "cuid", ...p.errToObj(e) });
798
+ }
799
+ cuid2(e) {
800
+ return this._addCheck({ kind: "cuid2", ...p.errToObj(e) });
801
+ }
802
+ ulid(e) {
803
+ return this._addCheck({ kind: "ulid", ...p.errToObj(e) });
804
+ }
805
+ base64(e) {
806
+ return this._addCheck({ kind: "base64", ...p.errToObj(e) });
807
+ }
808
+ base64url(e) {
809
+ return this._addCheck({
810
+ kind: "base64url",
811
+ ...p.errToObj(e)
812
+ });
813
+ }
814
+ jwt(e) {
815
+ return this._addCheck({ kind: "jwt", ...p.errToObj(e) });
816
+ }
817
+ ip(e) {
818
+ return this._addCheck({ kind: "ip", ...p.errToObj(e) });
819
+ }
820
+ cidr(e) {
821
+ return this._addCheck({ kind: "cidr", ...p.errToObj(e) });
822
+ }
823
+ datetime(e) {
824
+ var t, r;
825
+ return typeof e == "string" ? this._addCheck({
826
+ kind: "datetime",
827
+ precision: null,
828
+ offset: !1,
829
+ local: !1,
830
+ message: e
831
+ }) : this._addCheck({
832
+ kind: "datetime",
833
+ precision: typeof (e == null ? void 0 : e.precision) > "u" ? null : e == null ? void 0 : e.precision,
834
+ offset: (t = e == null ? void 0 : e.offset) !== null && t !== void 0 ? t : !1,
835
+ local: (r = e == null ? void 0 : e.local) !== null && r !== void 0 ? r : !1,
836
+ ...p.errToObj(e == null ? void 0 : e.message)
837
+ });
838
+ }
839
+ date(e) {
840
+ return this._addCheck({ kind: "date", message: e });
841
+ }
842
+ time(e) {
843
+ return typeof e == "string" ? this._addCheck({
844
+ kind: "time",
845
+ precision: null,
846
+ message: e
847
+ }) : this._addCheck({
848
+ kind: "time",
849
+ precision: typeof (e == null ? void 0 : e.precision) > "u" ? null : e == null ? void 0 : e.precision,
850
+ ...p.errToObj(e == null ? void 0 : e.message)
851
+ });
852
+ }
853
+ duration(e) {
854
+ return this._addCheck({ kind: "duration", ...p.errToObj(e) });
855
+ }
856
+ regex(e, t) {
857
+ return this._addCheck({
858
+ kind: "regex",
859
+ regex: e,
860
+ ...p.errToObj(t)
861
+ });
862
+ }
863
+ includes(e, t) {
864
+ return this._addCheck({
865
+ kind: "includes",
866
+ value: e,
867
+ position: t == null ? void 0 : t.position,
868
+ ...p.errToObj(t == null ? void 0 : t.message)
869
+ });
870
+ }
871
+ startsWith(e, t) {
872
+ return this._addCheck({
873
+ kind: "startsWith",
874
+ value: e,
875
+ ...p.errToObj(t)
876
+ });
877
+ }
878
+ endsWith(e, t) {
879
+ return this._addCheck({
880
+ kind: "endsWith",
881
+ value: e,
882
+ ...p.errToObj(t)
883
+ });
884
+ }
885
+ min(e, t) {
886
+ return this._addCheck({
887
+ kind: "min",
888
+ value: e,
889
+ ...p.errToObj(t)
890
+ });
891
+ }
892
+ max(e, t) {
893
+ return this._addCheck({
894
+ kind: "max",
895
+ value: e,
896
+ ...p.errToObj(t)
897
+ });
898
+ }
899
+ length(e, t) {
900
+ return this._addCheck({
901
+ kind: "length",
902
+ value: e,
903
+ ...p.errToObj(t)
904
+ });
905
+ }
906
+ /**
907
+ * Equivalent to `.min(1)`
908
+ */
909
+ nonempty(e) {
910
+ return this.min(1, p.errToObj(e));
911
+ }
912
+ trim() {
913
+ return new Z({
914
+ ...this._def,
915
+ checks: [...this._def.checks, { kind: "trim" }]
916
+ });
917
+ }
918
+ toLowerCase() {
919
+ return new Z({
920
+ ...this._def,
921
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
922
+ });
923
+ }
924
+ toUpperCase() {
925
+ return new Z({
926
+ ...this._def,
927
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
928
+ });
929
+ }
930
+ get isDatetime() {
931
+ return !!this._def.checks.find((e) => e.kind === "datetime");
932
+ }
933
+ get isDate() {
934
+ return !!this._def.checks.find((e) => e.kind === "date");
935
+ }
936
+ get isTime() {
937
+ return !!this._def.checks.find((e) => e.kind === "time");
938
+ }
939
+ get isDuration() {
940
+ return !!this._def.checks.find((e) => e.kind === "duration");
941
+ }
942
+ get isEmail() {
943
+ return !!this._def.checks.find((e) => e.kind === "email");
944
+ }
945
+ get isURL() {
946
+ return !!this._def.checks.find((e) => e.kind === "url");
947
+ }
948
+ get isEmoji() {
949
+ return !!this._def.checks.find((e) => e.kind === "emoji");
950
+ }
951
+ get isUUID() {
952
+ return !!this._def.checks.find((e) => e.kind === "uuid");
953
+ }
954
+ get isNANOID() {
955
+ return !!this._def.checks.find((e) => e.kind === "nanoid");
956
+ }
957
+ get isCUID() {
958
+ return !!this._def.checks.find((e) => e.kind === "cuid");
959
+ }
960
+ get isCUID2() {
961
+ return !!this._def.checks.find((e) => e.kind === "cuid2");
962
+ }
963
+ get isULID() {
964
+ return !!this._def.checks.find((e) => e.kind === "ulid");
965
+ }
966
+ get isIP() {
967
+ return !!this._def.checks.find((e) => e.kind === "ip");
968
+ }
969
+ get isCIDR() {
970
+ return !!this._def.checks.find((e) => e.kind === "cidr");
971
+ }
972
+ get isBase64() {
973
+ return !!this._def.checks.find((e) => e.kind === "base64");
974
+ }
975
+ get isBase64url() {
976
+ return !!this._def.checks.find((e) => e.kind === "base64url");
977
+ }
978
+ get minLength() {
979
+ let e = null;
980
+ for (const t of this._def.checks)
981
+ t.kind === "min" && (e === null || t.value > e) && (e = t.value);
982
+ return e;
983
+ }
984
+ get maxLength() {
985
+ let e = null;
986
+ for (const t of this._def.checks)
987
+ t.kind === "max" && (e === null || t.value < e) && (e = t.value);
988
+ return e;
989
+ }
990
+ }
991
+ Z.create = (n) => {
992
+ var e;
993
+ return new Z({
994
+ checks: [],
995
+ typeName: m.ZodString,
996
+ coerce: (e = n == null ? void 0 : n.coerce) !== null && e !== void 0 ? e : !1,
997
+ ..._(n)
998
+ });
999
+ };
1000
+ function ht(n, e) {
1001
+ const t = (n.toString().split(".")[1] || "").length, r = (e.toString().split(".")[1] || "").length, s = t > r ? t : r, a = parseInt(n.toFixed(s).replace(".", "")), i = parseInt(e.toFixed(s).replace(".", ""));
1002
+ return a % i / Math.pow(10, s);
1003
+ }
1004
+ class $ extends v {
1005
+ constructor() {
1006
+ super(...arguments), this.min = this.gte, this.max = this.lte, this.step = this.multipleOf;
1007
+ }
1008
+ _parse(e) {
1009
+ if (this._def.coerce && (e.data = Number(e.data)), this._getType(e) !== h.number) {
1010
+ const a = this._getOrReturnCtx(e);
1011
+ return u(a, {
1012
+ code: c.invalid_type,
1013
+ expected: h.number,
1014
+ received: a.parsedType
1015
+ }), y;
1016
+ }
1017
+ let r;
1018
+ const s = new k();
1019
+ for (const a of this._def.checks)
1020
+ a.kind === "int" ? b.isInteger(e.data) || (r = this._getOrReturnCtx(e, r), u(r, {
1021
+ code: c.invalid_type,
1022
+ expected: "integer",
1023
+ received: "float",
1024
+ message: a.message
1025
+ }), s.dirty()) : a.kind === "min" ? (a.inclusive ? e.data < a.value : e.data <= a.value) && (r = this._getOrReturnCtx(e, r), u(r, {
1026
+ code: c.too_small,
1027
+ minimum: a.value,
1028
+ type: "number",
1029
+ inclusive: a.inclusive,
1030
+ exact: !1,
1031
+ message: a.message
1032
+ }), s.dirty()) : a.kind === "max" ? (a.inclusive ? e.data > a.value : e.data >= a.value) && (r = this._getOrReturnCtx(e, r), u(r, {
1033
+ code: c.too_big,
1034
+ maximum: a.value,
1035
+ type: "number",
1036
+ inclusive: a.inclusive,
1037
+ exact: !1,
1038
+ message: a.message
1039
+ }), s.dirty()) : a.kind === "multipleOf" ? ht(e.data, a.value) !== 0 && (r = this._getOrReturnCtx(e, r), u(r, {
1040
+ code: c.not_multiple_of,
1041
+ multipleOf: a.value,
1042
+ message: a.message
1043
+ }), s.dirty()) : a.kind === "finite" ? Number.isFinite(e.data) || (r = this._getOrReturnCtx(e, r), u(r, {
1044
+ code: c.not_finite,
1045
+ message: a.message
1046
+ }), s.dirty()) : b.assertNever(a);
1047
+ return { status: s.value, value: e.data };
1048
+ }
1049
+ gte(e, t) {
1050
+ return this.setLimit("min", e, !0, p.toString(t));
1051
+ }
1052
+ gt(e, t) {
1053
+ return this.setLimit("min", e, !1, p.toString(t));
1054
+ }
1055
+ lte(e, t) {
1056
+ return this.setLimit("max", e, !0, p.toString(t));
1057
+ }
1058
+ lt(e, t) {
1059
+ return this.setLimit("max", e, !1, p.toString(t));
1060
+ }
1061
+ setLimit(e, t, r, s) {
1062
+ return new $({
1063
+ ...this._def,
1064
+ checks: [
1065
+ ...this._def.checks,
1066
+ {
1067
+ kind: e,
1068
+ value: t,
1069
+ inclusive: r,
1070
+ message: p.toString(s)
1071
+ }
1072
+ ]
1073
+ });
1074
+ }
1075
+ _addCheck(e) {
1076
+ return new $({
1077
+ ...this._def,
1078
+ checks: [...this._def.checks, e]
1079
+ });
1080
+ }
1081
+ int(e) {
1082
+ return this._addCheck({
1083
+ kind: "int",
1084
+ message: p.toString(e)
1085
+ });
1086
+ }
1087
+ positive(e) {
1088
+ return this._addCheck({
1089
+ kind: "min",
1090
+ value: 0,
1091
+ inclusive: !1,
1092
+ message: p.toString(e)
1093
+ });
1094
+ }
1095
+ negative(e) {
1096
+ return this._addCheck({
1097
+ kind: "max",
1098
+ value: 0,
1099
+ inclusive: !1,
1100
+ message: p.toString(e)
1101
+ });
1102
+ }
1103
+ nonpositive(e) {
1104
+ return this._addCheck({
1105
+ kind: "max",
1106
+ value: 0,
1107
+ inclusive: !0,
1108
+ message: p.toString(e)
1109
+ });
1110
+ }
1111
+ nonnegative(e) {
1112
+ return this._addCheck({
1113
+ kind: "min",
1114
+ value: 0,
1115
+ inclusive: !0,
1116
+ message: p.toString(e)
1117
+ });
1118
+ }
1119
+ multipleOf(e, t) {
1120
+ return this._addCheck({
1121
+ kind: "multipleOf",
1122
+ value: e,
1123
+ message: p.toString(t)
1124
+ });
1125
+ }
1126
+ finite(e) {
1127
+ return this._addCheck({
1128
+ kind: "finite",
1129
+ message: p.toString(e)
1130
+ });
1131
+ }
1132
+ safe(e) {
1133
+ return this._addCheck({
1134
+ kind: "min",
1135
+ inclusive: !0,
1136
+ value: Number.MIN_SAFE_INTEGER,
1137
+ message: p.toString(e)
1138
+ })._addCheck({
1139
+ kind: "max",
1140
+ inclusive: !0,
1141
+ value: Number.MAX_SAFE_INTEGER,
1142
+ message: p.toString(e)
1143
+ });
1144
+ }
1145
+ get minValue() {
1146
+ let e = null;
1147
+ for (const t of this._def.checks)
1148
+ t.kind === "min" && (e === null || t.value > e) && (e = t.value);
1149
+ return e;
1150
+ }
1151
+ get maxValue() {
1152
+ let e = null;
1153
+ for (const t of this._def.checks)
1154
+ t.kind === "max" && (e === null || t.value < e) && (e = t.value);
1155
+ return e;
1156
+ }
1157
+ get isInt() {
1158
+ return !!this._def.checks.find((e) => e.kind === "int" || e.kind === "multipleOf" && b.isInteger(e.value));
1159
+ }
1160
+ get isFinite() {
1161
+ let e = null, t = null;
1162
+ for (const r of this._def.checks) {
1163
+ if (r.kind === "finite" || r.kind === "int" || r.kind === "multipleOf")
1164
+ return !0;
1165
+ r.kind === "min" ? (t === null || r.value > t) && (t = r.value) : r.kind === "max" && (e === null || r.value < e) && (e = r.value);
1166
+ }
1167
+ return Number.isFinite(t) && Number.isFinite(e);
1168
+ }
1169
+ }
1170
+ $.create = (n) => new $({
1171
+ checks: [],
1172
+ typeName: m.ZodNumber,
1173
+ coerce: (n == null ? void 0 : n.coerce) || !1,
1174
+ ..._(n)
1175
+ });
1176
+ class z extends v {
1177
+ constructor() {
1178
+ super(...arguments), this.min = this.gte, this.max = this.lte;
1179
+ }
1180
+ _parse(e) {
1181
+ if (this._def.coerce)
1182
+ try {
1183
+ e.data = BigInt(e.data);
1184
+ } catch {
1185
+ return this._getInvalidInput(e);
1186
+ }
1187
+ if (this._getType(e) !== h.bigint)
1188
+ return this._getInvalidInput(e);
1189
+ let r;
1190
+ const s = new k();
1191
+ for (const a of this._def.checks)
1192
+ a.kind === "min" ? (a.inclusive ? e.data < a.value : e.data <= a.value) && (r = this._getOrReturnCtx(e, r), u(r, {
1193
+ code: c.too_small,
1194
+ type: "bigint",
1195
+ minimum: a.value,
1196
+ inclusive: a.inclusive,
1197
+ message: a.message
1198
+ }), s.dirty()) : a.kind === "max" ? (a.inclusive ? e.data > a.value : e.data >= a.value) && (r = this._getOrReturnCtx(e, r), u(r, {
1199
+ code: c.too_big,
1200
+ type: "bigint",
1201
+ maximum: a.value,
1202
+ inclusive: a.inclusive,
1203
+ message: a.message
1204
+ }), s.dirty()) : a.kind === "multipleOf" ? e.data % a.value !== BigInt(0) && (r = this._getOrReturnCtx(e, r), u(r, {
1205
+ code: c.not_multiple_of,
1206
+ multipleOf: a.value,
1207
+ message: a.message
1208
+ }), s.dirty()) : b.assertNever(a);
1209
+ return { status: s.value, value: e.data };
1210
+ }
1211
+ _getInvalidInput(e) {
1212
+ const t = this._getOrReturnCtx(e);
1213
+ return u(t, {
1214
+ code: c.invalid_type,
1215
+ expected: h.bigint,
1216
+ received: t.parsedType
1217
+ }), y;
1218
+ }
1219
+ gte(e, t) {
1220
+ return this.setLimit("min", e, !0, p.toString(t));
1221
+ }
1222
+ gt(e, t) {
1223
+ return this.setLimit("min", e, !1, p.toString(t));
1224
+ }
1225
+ lte(e, t) {
1226
+ return this.setLimit("max", e, !0, p.toString(t));
1227
+ }
1228
+ lt(e, t) {
1229
+ return this.setLimit("max", e, !1, p.toString(t));
1230
+ }
1231
+ setLimit(e, t, r, s) {
1232
+ return new z({
1233
+ ...this._def,
1234
+ checks: [
1235
+ ...this._def.checks,
1236
+ {
1237
+ kind: e,
1238
+ value: t,
1239
+ inclusive: r,
1240
+ message: p.toString(s)
1241
+ }
1242
+ ]
1243
+ });
1244
+ }
1245
+ _addCheck(e) {
1246
+ return new z({
1247
+ ...this._def,
1248
+ checks: [...this._def.checks, e]
1249
+ });
1250
+ }
1251
+ positive(e) {
1252
+ return this._addCheck({
1253
+ kind: "min",
1254
+ value: BigInt(0),
1255
+ inclusive: !1,
1256
+ message: p.toString(e)
1257
+ });
1258
+ }
1259
+ negative(e) {
1260
+ return this._addCheck({
1261
+ kind: "max",
1262
+ value: BigInt(0),
1263
+ inclusive: !1,
1264
+ message: p.toString(e)
1265
+ });
1266
+ }
1267
+ nonpositive(e) {
1268
+ return this._addCheck({
1269
+ kind: "max",
1270
+ value: BigInt(0),
1271
+ inclusive: !0,
1272
+ message: p.toString(e)
1273
+ });
1274
+ }
1275
+ nonnegative(e) {
1276
+ return this._addCheck({
1277
+ kind: "min",
1278
+ value: BigInt(0),
1279
+ inclusive: !0,
1280
+ message: p.toString(e)
1281
+ });
1282
+ }
1283
+ multipleOf(e, t) {
1284
+ return this._addCheck({
1285
+ kind: "multipleOf",
1286
+ value: e,
1287
+ message: p.toString(t)
1288
+ });
1289
+ }
1290
+ get minValue() {
1291
+ let e = null;
1292
+ for (const t of this._def.checks)
1293
+ t.kind === "min" && (e === null || t.value > e) && (e = t.value);
1294
+ return e;
1295
+ }
1296
+ get maxValue() {
1297
+ let e = null;
1298
+ for (const t of this._def.checks)
1299
+ t.kind === "max" && (e === null || t.value < e) && (e = t.value);
1300
+ return e;
1301
+ }
1302
+ }
1303
+ z.create = (n) => {
1304
+ var e;
1305
+ return new z({
1306
+ checks: [],
1307
+ typeName: m.ZodBigInt,
1308
+ coerce: (e = n == null ? void 0 : n.coerce) !== null && e !== void 0 ? e : !1,
1309
+ ..._(n)
1310
+ });
1311
+ };
1312
+ class Q extends v {
1313
+ _parse(e) {
1314
+ if (this._def.coerce && (e.data = !!e.data), this._getType(e) !== h.boolean) {
1315
+ const r = this._getOrReturnCtx(e);
1316
+ return u(r, {
1317
+ code: c.invalid_type,
1318
+ expected: h.boolean,
1319
+ received: r.parsedType
1320
+ }), y;
1321
+ }
1322
+ return w(e.data);
1323
+ }
1324
+ }
1325
+ Q.create = (n) => new Q({
1326
+ typeName: m.ZodBoolean,
1327
+ coerce: (n == null ? void 0 : n.coerce) || !1,
1328
+ ..._(n)
1329
+ });
1330
+ class U extends v {
1331
+ _parse(e) {
1332
+ if (this._def.coerce && (e.data = new Date(e.data)), this._getType(e) !== h.date) {
1333
+ const a = this._getOrReturnCtx(e);
1334
+ return u(a, {
1335
+ code: c.invalid_type,
1336
+ expected: h.date,
1337
+ received: a.parsedType
1338
+ }), y;
1339
+ }
1340
+ if (isNaN(e.data.getTime())) {
1341
+ const a = this._getOrReturnCtx(e);
1342
+ return u(a, {
1343
+ code: c.invalid_date
1344
+ }), y;
1345
+ }
1346
+ const r = new k();
1347
+ let s;
1348
+ for (const a of this._def.checks)
1349
+ a.kind === "min" ? e.data.getTime() < a.value && (s = this._getOrReturnCtx(e, s), u(s, {
1350
+ code: c.too_small,
1351
+ message: a.message,
1352
+ inclusive: !0,
1353
+ exact: !1,
1354
+ minimum: a.value,
1355
+ type: "date"
1356
+ }), r.dirty()) : a.kind === "max" ? e.data.getTime() > a.value && (s = this._getOrReturnCtx(e, s), u(s, {
1357
+ code: c.too_big,
1358
+ message: a.message,
1359
+ inclusive: !0,
1360
+ exact: !1,
1361
+ maximum: a.value,
1362
+ type: "date"
1363
+ }), r.dirty()) : b.assertNever(a);
1364
+ return {
1365
+ status: r.value,
1366
+ value: new Date(e.data.getTime())
1367
+ };
1368
+ }
1369
+ _addCheck(e) {
1370
+ return new U({
1371
+ ...this._def,
1372
+ checks: [...this._def.checks, e]
1373
+ });
1374
+ }
1375
+ min(e, t) {
1376
+ return this._addCheck({
1377
+ kind: "min",
1378
+ value: e.getTime(),
1379
+ message: p.toString(t)
1380
+ });
1381
+ }
1382
+ max(e, t) {
1383
+ return this._addCheck({
1384
+ kind: "max",
1385
+ value: e.getTime(),
1386
+ message: p.toString(t)
1387
+ });
1388
+ }
1389
+ get minDate() {
1390
+ let e = null;
1391
+ for (const t of this._def.checks)
1392
+ t.kind === "min" && (e === null || t.value > e) && (e = t.value);
1393
+ return e != null ? new Date(e) : null;
1394
+ }
1395
+ get maxDate() {
1396
+ let e = null;
1397
+ for (const t of this._def.checks)
1398
+ t.kind === "max" && (e === null || t.value < e) && (e = t.value);
1399
+ return e != null ? new Date(e) : null;
1400
+ }
1401
+ }
1402
+ U.create = (n) => new U({
1403
+ checks: [],
1404
+ coerce: (n == null ? void 0 : n.coerce) || !1,
1405
+ typeName: m.ZodDate,
1406
+ ..._(n)
1407
+ });
1408
+ class me extends v {
1409
+ _parse(e) {
1410
+ if (this._getType(e) !== h.symbol) {
1411
+ const r = this._getOrReturnCtx(e);
1412
+ return u(r, {
1413
+ code: c.invalid_type,
1414
+ expected: h.symbol,
1415
+ received: r.parsedType
1416
+ }), y;
1417
+ }
1418
+ return w(e.data);
1419
+ }
1420
+ }
1421
+ me.create = (n) => new me({
1422
+ typeName: m.ZodSymbol,
1423
+ ..._(n)
1424
+ });
1425
+ class ee extends v {
1426
+ _parse(e) {
1427
+ if (this._getType(e) !== h.undefined) {
1428
+ const r = this._getOrReturnCtx(e);
1429
+ return u(r, {
1430
+ code: c.invalid_type,
1431
+ expected: h.undefined,
1432
+ received: r.parsedType
1433
+ }), y;
1434
+ }
1435
+ return w(e.data);
1436
+ }
1437
+ }
1438
+ ee.create = (n) => new ee({
1439
+ typeName: m.ZodUndefined,
1440
+ ..._(n)
1441
+ });
1442
+ class te extends v {
1443
+ _parse(e) {
1444
+ if (this._getType(e) !== h.null) {
1445
+ const r = this._getOrReturnCtx(e);
1446
+ return u(r, {
1447
+ code: c.invalid_type,
1448
+ expected: h.null,
1449
+ received: r.parsedType
1450
+ }), y;
1451
+ }
1452
+ return w(e.data);
1453
+ }
1454
+ }
1455
+ te.create = (n) => new te({
1456
+ typeName: m.ZodNull,
1457
+ ..._(n)
1458
+ });
1459
+ class H extends v {
1460
+ constructor() {
1461
+ super(...arguments), this._any = !0;
1462
+ }
1463
+ _parse(e) {
1464
+ return w(e.data);
1465
+ }
1466
+ }
1467
+ H.create = (n) => new H({
1468
+ typeName: m.ZodAny,
1469
+ ..._(n)
1470
+ });
1471
+ class L extends v {
1472
+ constructor() {
1473
+ super(...arguments), this._unknown = !0;
1474
+ }
1475
+ _parse(e) {
1476
+ return w(e.data);
1477
+ }
1478
+ }
1479
+ L.create = (n) => new L({
1480
+ typeName: m.ZodUnknown,
1481
+ ..._(n)
1482
+ });
1483
+ class E extends v {
1484
+ _parse(e) {
1485
+ const t = this._getOrReturnCtx(e);
1486
+ return u(t, {
1487
+ code: c.invalid_type,
1488
+ expected: h.never,
1489
+ received: t.parsedType
1490
+ }), y;
1491
+ }
1492
+ }
1493
+ E.create = (n) => new E({
1494
+ typeName: m.ZodNever,
1495
+ ..._(n)
1496
+ });
1497
+ class ye extends v {
1498
+ _parse(e) {
1499
+ if (this._getType(e) !== h.undefined) {
1500
+ const r = this._getOrReturnCtx(e);
1501
+ return u(r, {
1502
+ code: c.invalid_type,
1503
+ expected: h.void,
1504
+ received: r.parsedType
1505
+ }), y;
1506
+ }
1507
+ return w(e.data);
1508
+ }
1509
+ }
1510
+ ye.create = (n) => new ye({
1511
+ typeName: m.ZodVoid,
1512
+ ..._(n)
1513
+ });
1514
+ class C extends v {
1515
+ _parse(e) {
1516
+ const { ctx: t, status: r } = this._processInputParams(e), s = this._def;
1517
+ if (t.parsedType !== h.array)
1518
+ return u(t, {
1519
+ code: c.invalid_type,
1520
+ expected: h.array,
1521
+ received: t.parsedType
1522
+ }), y;
1523
+ if (s.exactLength !== null) {
1524
+ const i = t.data.length > s.exactLength.value, o = t.data.length < s.exactLength.value;
1525
+ (i || o) && (u(t, {
1526
+ code: i ? c.too_big : c.too_small,
1527
+ minimum: o ? s.exactLength.value : void 0,
1528
+ maximum: i ? s.exactLength.value : void 0,
1529
+ type: "array",
1530
+ inclusive: !0,
1531
+ exact: !0,
1532
+ message: s.exactLength.message
1533
+ }), r.dirty());
1534
+ }
1535
+ if (s.minLength !== null && t.data.length < s.minLength.value && (u(t, {
1536
+ code: c.too_small,
1537
+ minimum: s.minLength.value,
1538
+ type: "array",
1539
+ inclusive: !0,
1540
+ exact: !1,
1541
+ message: s.minLength.message
1542
+ }), r.dirty()), s.maxLength !== null && t.data.length > s.maxLength.value && (u(t, {
1543
+ code: c.too_big,
1544
+ maximum: s.maxLength.value,
1545
+ type: "array",
1546
+ inclusive: !0,
1547
+ exact: !1,
1548
+ message: s.maxLength.message
1549
+ }), r.dirty()), t.common.async)
1550
+ return Promise.all([...t.data].map((i, o) => s.type._parseAsync(new j(t, i, t.path, o)))).then((i) => k.mergeArray(r, i));
1551
+ const a = [...t.data].map((i, o) => s.type._parseSync(new j(t, i, t.path, o)));
1552
+ return k.mergeArray(r, a);
1553
+ }
1554
+ get element() {
1555
+ return this._def.type;
1556
+ }
1557
+ min(e, t) {
1558
+ return new C({
1559
+ ...this._def,
1560
+ minLength: { value: e, message: p.toString(t) }
1561
+ });
1562
+ }
1563
+ max(e, t) {
1564
+ return new C({
1565
+ ...this._def,
1566
+ maxLength: { value: e, message: p.toString(t) }
1567
+ });
1568
+ }
1569
+ length(e, t) {
1570
+ return new C({
1571
+ ...this._def,
1572
+ exactLength: { value: e, message: p.toString(t) }
1573
+ });
1574
+ }
1575
+ nonempty(e) {
1576
+ return this.min(1, e);
1577
+ }
1578
+ }
1579
+ C.create = (n, e) => new C({
1580
+ type: n,
1581
+ minLength: null,
1582
+ maxLength: null,
1583
+ exactLength: null,
1584
+ typeName: m.ZodArray,
1585
+ ..._(e)
1586
+ });
1587
+ function F(n) {
1588
+ if (n instanceof x) {
1589
+ const e = {};
1590
+ for (const t in n.shape) {
1591
+ const r = n.shape[t];
1592
+ e[t] = O.create(F(r));
1593
+ }
1594
+ return new x({
1595
+ ...n._def,
1596
+ shape: () => e
1597
+ });
1598
+ } else return n instanceof C ? new C({
1599
+ ...n._def,
1600
+ type: F(n.element)
1601
+ }) : n instanceof O ? O.create(F(n.unwrap())) : n instanceof P ? P.create(F(n.unwrap())) : n instanceof R ? R.create(n.items.map((e) => F(e))) : n;
1602
+ }
1603
+ class x extends v {
1604
+ constructor() {
1605
+ super(...arguments), this._cached = null, this.nonstrict = this.passthrough, this.augment = this.extend;
1606
+ }
1607
+ _getCached() {
1608
+ if (this._cached !== null)
1609
+ return this._cached;
1610
+ const e = this._def.shape(), t = b.objectKeys(e);
1611
+ return this._cached = { shape: e, keys: t };
1612
+ }
1613
+ _parse(e) {
1614
+ if (this._getType(e) !== h.object) {
1615
+ const l = this._getOrReturnCtx(e);
1616
+ return u(l, {
1617
+ code: c.invalid_type,
1618
+ expected: h.object,
1619
+ received: l.parsedType
1620
+ }), y;
1621
+ }
1622
+ const { status: r, ctx: s } = this._processInputParams(e), { shape: a, keys: i } = this._getCached(), o = [];
1623
+ if (!(this._def.catchall instanceof E && this._def.unknownKeys === "strip"))
1624
+ for (const l in s.data)
1625
+ i.includes(l) || o.push(l);
1626
+ const f = [];
1627
+ for (const l of i) {
1628
+ const g = a[l], S = s.data[l];
1629
+ f.push({
1630
+ key: { status: "valid", value: l },
1631
+ value: g._parse(new j(s, S, s.path, l)),
1632
+ alwaysSet: l in s.data
1633
+ });
1634
+ }
1635
+ if (this._def.catchall instanceof E) {
1636
+ const l = this._def.unknownKeys;
1637
+ if (l === "passthrough")
1638
+ for (const g of o)
1639
+ f.push({
1640
+ key: { status: "valid", value: g },
1641
+ value: { status: "valid", value: s.data[g] }
1642
+ });
1643
+ else if (l === "strict")
1644
+ o.length > 0 && (u(s, {
1645
+ code: c.unrecognized_keys,
1646
+ keys: o
1647
+ }), r.dirty());
1648
+ else if (l !== "strip") throw new Error("Internal ZodObject error: invalid unknownKeys value.");
1649
+ } else {
1650
+ const l = this._def.catchall;
1651
+ for (const g of o) {
1652
+ const S = s.data[g];
1653
+ f.push({
1654
+ key: { status: "valid", value: g },
1655
+ value: l._parse(
1656
+ new j(s, S, s.path, g)
1657
+ //, ctx.child(key), value, getParsedType(value)
1658
+ ),
1659
+ alwaysSet: g in s.data
1660
+ });
1661
+ }
1662
+ }
1663
+ return s.common.async ? Promise.resolve().then(async () => {
1664
+ const l = [];
1665
+ for (const g of f) {
1666
+ const S = await g.key, Ie = await g.value;
1667
+ l.push({
1668
+ key: S,
1669
+ value: Ie,
1670
+ alwaysSet: g.alwaysSet
1671
+ });
1672
+ }
1673
+ return l;
1674
+ }).then((l) => k.mergeObjectSync(r, l)) : k.mergeObjectSync(r, f);
1675
+ }
1676
+ get shape() {
1677
+ return this._def.shape();
1678
+ }
1679
+ strict(e) {
1680
+ return p.errToObj, new x({
1681
+ ...this._def,
1682
+ unknownKeys: "strict",
1683
+ ...e !== void 0 ? {
1684
+ errorMap: (t, r) => {
1685
+ var s, a, i, o;
1686
+ const f = (i = (a = (s = this._def).errorMap) === null || a === void 0 ? void 0 : a.call(s, t, r).message) !== null && i !== void 0 ? i : r.defaultError;
1687
+ return t.code === "unrecognized_keys" ? {
1688
+ message: (o = p.errToObj(e).message) !== null && o !== void 0 ? o : f
1689
+ } : {
1690
+ message: f
1691
+ };
1692
+ }
1693
+ } : {}
1694
+ });
1695
+ }
1696
+ strip() {
1697
+ return new x({
1698
+ ...this._def,
1699
+ unknownKeys: "strip"
1700
+ });
1701
+ }
1702
+ passthrough() {
1703
+ return new x({
1704
+ ...this._def,
1705
+ unknownKeys: "passthrough"
1706
+ });
1707
+ }
1708
+ // const AugmentFactory =
1709
+ // <Def extends ZodObjectDef>(def: Def) =>
1710
+ // <Augmentation extends ZodRawShape>(
1711
+ // augmentation: Augmentation
1712
+ // ): ZodObject<
1713
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
1714
+ // Def["unknownKeys"],
1715
+ // Def["catchall"]
1716
+ // > => {
1717
+ // return new ZodObject({
1718
+ // ...def,
1719
+ // shape: () => ({
1720
+ // ...def.shape(),
1721
+ // ...augmentation,
1722
+ // }),
1723
+ // }) as any;
1724
+ // };
1725
+ extend(e) {
1726
+ return new x({
1727
+ ...this._def,
1728
+ shape: () => ({
1729
+ ...this._def.shape(),
1730
+ ...e
1731
+ })
1732
+ });
1733
+ }
1734
+ /**
1735
+ * Prior to zod@1.0.12 there was a bug in the
1736
+ * inferred type of merged objects. Please
1737
+ * upgrade if you are experiencing issues.
1738
+ */
1739
+ merge(e) {
1740
+ return new x({
1741
+ unknownKeys: e._def.unknownKeys,
1742
+ catchall: e._def.catchall,
1743
+ shape: () => ({
1744
+ ...this._def.shape(),
1745
+ ...e._def.shape()
1746
+ }),
1747
+ typeName: m.ZodObject
1748
+ });
1749
+ }
1750
+ // merge<
1751
+ // Incoming extends AnyZodObject,
1752
+ // Augmentation extends Incoming["shape"],
1753
+ // NewOutput extends {
1754
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
1755
+ // ? Augmentation[k]["_output"]
1756
+ // : k extends keyof Output
1757
+ // ? Output[k]
1758
+ // : never;
1759
+ // },
1760
+ // NewInput extends {
1761
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
1762
+ // ? Augmentation[k]["_input"]
1763
+ // : k extends keyof Input
1764
+ // ? Input[k]
1765
+ // : never;
1766
+ // }
1767
+ // >(
1768
+ // merging: Incoming
1769
+ // ): ZodObject<
1770
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
1771
+ // Incoming["_def"]["unknownKeys"],
1772
+ // Incoming["_def"]["catchall"],
1773
+ // NewOutput,
1774
+ // NewInput
1775
+ // > {
1776
+ // const merged: any = new ZodObject({
1777
+ // unknownKeys: merging._def.unknownKeys,
1778
+ // catchall: merging._def.catchall,
1779
+ // shape: () =>
1780
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
1781
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
1782
+ // }) as any;
1783
+ // return merged;
1784
+ // }
1785
+ setKey(e, t) {
1786
+ return this.augment({ [e]: t });
1787
+ }
1788
+ // merge<Incoming extends AnyZodObject>(
1789
+ // merging: Incoming
1790
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
1791
+ // ZodObject<
1792
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
1793
+ // Incoming["_def"]["unknownKeys"],
1794
+ // Incoming["_def"]["catchall"]
1795
+ // > {
1796
+ // // const mergedShape = objectUtil.mergeShapes(
1797
+ // // this._def.shape(),
1798
+ // // merging._def.shape()
1799
+ // // );
1800
+ // const merged: any = new ZodObject({
1801
+ // unknownKeys: merging._def.unknownKeys,
1802
+ // catchall: merging._def.catchall,
1803
+ // shape: () =>
1804
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
1805
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
1806
+ // }) as any;
1807
+ // return merged;
1808
+ // }
1809
+ catchall(e) {
1810
+ return new x({
1811
+ ...this._def,
1812
+ catchall: e
1813
+ });
1814
+ }
1815
+ pick(e) {
1816
+ const t = {};
1817
+ return b.objectKeys(e).forEach((r) => {
1818
+ e[r] && this.shape[r] && (t[r] = this.shape[r]);
1819
+ }), new x({
1820
+ ...this._def,
1821
+ shape: () => t
1822
+ });
1823
+ }
1824
+ omit(e) {
1825
+ const t = {};
1826
+ return b.objectKeys(this.shape).forEach((r) => {
1827
+ e[r] || (t[r] = this.shape[r]);
1828
+ }), new x({
1829
+ ...this._def,
1830
+ shape: () => t
1831
+ });
1832
+ }
1833
+ /**
1834
+ * @deprecated
1835
+ */
1836
+ deepPartial() {
1837
+ return F(this);
1838
+ }
1839
+ partial(e) {
1840
+ const t = {};
1841
+ return b.objectKeys(this.shape).forEach((r) => {
1842
+ const s = this.shape[r];
1843
+ e && !e[r] ? t[r] = s : t[r] = s.optional();
1844
+ }), new x({
1845
+ ...this._def,
1846
+ shape: () => t
1847
+ });
1848
+ }
1849
+ required(e) {
1850
+ const t = {};
1851
+ return b.objectKeys(this.shape).forEach((r) => {
1852
+ if (e && !e[r])
1853
+ t[r] = this.shape[r];
1854
+ else {
1855
+ let a = this.shape[r];
1856
+ for (; a instanceof O; )
1857
+ a = a._def.innerType;
1858
+ t[r] = a;
1859
+ }
1860
+ }), new x({
1861
+ ...this._def,
1862
+ shape: () => t
1863
+ });
1864
+ }
1865
+ keyof() {
1866
+ return ze(b.objectKeys(this.shape));
1867
+ }
1868
+ }
1869
+ x.create = (n, e) => new x({
1870
+ shape: () => n,
1871
+ unknownKeys: "strip",
1872
+ catchall: E.create(),
1873
+ typeName: m.ZodObject,
1874
+ ..._(e)
1875
+ });
1876
+ x.strictCreate = (n, e) => new x({
1877
+ shape: () => n,
1878
+ unknownKeys: "strict",
1879
+ catchall: E.create(),
1880
+ typeName: m.ZodObject,
1881
+ ..._(e)
1882
+ });
1883
+ x.lazycreate = (n, e) => new x({
1884
+ shape: n,
1885
+ unknownKeys: "strip",
1886
+ catchall: E.create(),
1887
+ typeName: m.ZodObject,
1888
+ ..._(e)
1889
+ });
1890
+ class ne extends v {
1891
+ _parse(e) {
1892
+ const { ctx: t } = this._processInputParams(e), r = this._def.options;
1893
+ function s(a) {
1894
+ for (const o of a)
1895
+ if (o.result.status === "valid")
1896
+ return o.result;
1897
+ for (const o of a)
1898
+ if (o.result.status === "dirty")
1899
+ return t.common.issues.push(...o.ctx.common.issues), o.result;
1900
+ const i = a.map((o) => new T(o.ctx.common.issues));
1901
+ return u(t, {
1902
+ code: c.invalid_union,
1903
+ unionErrors: i
1904
+ }), y;
1905
+ }
1906
+ if (t.common.async)
1907
+ return Promise.all(r.map(async (a) => {
1908
+ const i = {
1909
+ ...t,
1910
+ common: {
1911
+ ...t.common,
1912
+ issues: []
1913
+ },
1914
+ parent: null
1915
+ };
1916
+ return {
1917
+ result: await a._parseAsync({
1918
+ data: t.data,
1919
+ path: t.path,
1920
+ parent: i
1921
+ }),
1922
+ ctx: i
1923
+ };
1924
+ })).then(s);
1925
+ {
1926
+ let a;
1927
+ const i = [];
1928
+ for (const f of r) {
1929
+ const l = {
1930
+ ...t,
1931
+ common: {
1932
+ ...t.common,
1933
+ issues: []
1934
+ },
1935
+ parent: null
1936
+ }, g = f._parseSync({
1937
+ data: t.data,
1938
+ path: t.path,
1939
+ parent: l
1940
+ });
1941
+ if (g.status === "valid")
1942
+ return g;
1943
+ g.status === "dirty" && !a && (a = { result: g, ctx: l }), l.common.issues.length && i.push(l.common.issues);
1944
+ }
1945
+ if (a)
1946
+ return t.common.issues.push(...a.ctx.common.issues), a.result;
1947
+ const o = i.map((f) => new T(f));
1948
+ return u(t, {
1949
+ code: c.invalid_union,
1950
+ unionErrors: o
1951
+ }), y;
1952
+ }
1953
+ }
1954
+ get options() {
1955
+ return this._def.options;
1956
+ }
1957
+ }
1958
+ ne.create = (n, e) => new ne({
1959
+ options: n,
1960
+ typeName: m.ZodUnion,
1961
+ ..._(e)
1962
+ });
1963
+ const A = (n) => n instanceof ae ? A(n.schema) : n instanceof I ? A(n.innerType()) : n instanceof ie ? [n.value] : n instanceof M ? n.options : n instanceof oe ? b.objectValues(n.enum) : n instanceof de ? A(n._def.innerType) : n instanceof ee ? [void 0] : n instanceof te ? [null] : n instanceof O ? [void 0, ...A(n.unwrap())] : n instanceof P ? [null, ...A(n.unwrap())] : n instanceof Ce || n instanceof ue ? A(n.unwrap()) : n instanceof ce ? A(n._def.innerType) : [];
1964
+ class ve extends v {
1965
+ _parse(e) {
1966
+ const { ctx: t } = this._processInputParams(e);
1967
+ if (t.parsedType !== h.object)
1968
+ return u(t, {
1969
+ code: c.invalid_type,
1970
+ expected: h.object,
1971
+ received: t.parsedType
1972
+ }), y;
1973
+ const r = this.discriminator, s = t.data[r], a = this.optionsMap.get(s);
1974
+ return a ? t.common.async ? a._parseAsync({
1975
+ data: t.data,
1976
+ path: t.path,
1977
+ parent: t
1978
+ }) : a._parseSync({
1979
+ data: t.data,
1980
+ path: t.path,
1981
+ parent: t
1982
+ }) : (u(t, {
1983
+ code: c.invalid_union_discriminator,
1984
+ options: Array.from(this.optionsMap.keys()),
1985
+ path: [r]
1986
+ }), y);
1987
+ }
1988
+ get discriminator() {
1989
+ return this._def.discriminator;
1990
+ }
1991
+ get options() {
1992
+ return this._def.options;
1993
+ }
1994
+ get optionsMap() {
1995
+ return this._def.optionsMap;
1996
+ }
1997
+ /**
1998
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
1999
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
2000
+ * have a different value for each object in the union.
2001
+ * @param discriminator the name of the discriminator property
2002
+ * @param types an array of object schemas
2003
+ * @param params
2004
+ */
2005
+ static create(e, t, r) {
2006
+ const s = /* @__PURE__ */ new Map();
2007
+ for (const a of t) {
2008
+ const i = A(a.shape[e]);
2009
+ if (!i.length)
2010
+ throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);
2011
+ for (const o of i) {
2012
+ if (s.has(o))
2013
+ throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(o)}`);
2014
+ s.set(o, a);
2015
+ }
2016
+ }
2017
+ return new ve({
2018
+ typeName: m.ZodDiscriminatedUnion,
2019
+ discriminator: e,
2020
+ options: t,
2021
+ optionsMap: s,
2022
+ ..._(r)
2023
+ });
2024
+ }
2025
+ }
2026
+ function Ze(n, e) {
2027
+ const t = N(n), r = N(e);
2028
+ if (n === e)
2029
+ return { valid: !0, data: n };
2030
+ if (t === h.object && r === h.object) {
2031
+ const s = b.objectKeys(e), a = b.objectKeys(n).filter((o) => s.indexOf(o) !== -1), i = { ...n, ...e };
2032
+ for (const o of a) {
2033
+ const f = Ze(n[o], e[o]);
2034
+ if (!f.valid)
2035
+ return { valid: !1 };
2036
+ i[o] = f.data;
2037
+ }
2038
+ return { valid: !0, data: i };
2039
+ } else if (t === h.array && r === h.array) {
2040
+ if (n.length !== e.length)
2041
+ return { valid: !1 };
2042
+ const s = [];
2043
+ for (let a = 0; a < n.length; a++) {
2044
+ const i = n[a], o = e[a], f = Ze(i, o);
2045
+ if (!f.valid)
2046
+ return { valid: !1 };
2047
+ s.push(f.data);
2048
+ }
2049
+ return { valid: !0, data: s };
2050
+ } else return t === h.date && r === h.date && +n == +e ? { valid: !0, data: n } : { valid: !1 };
2051
+ }
2052
+ class re extends v {
2053
+ _parse(e) {
2054
+ const { status: t, ctx: r } = this._processInputParams(e), s = (a, i) => {
2055
+ if (Te(a) || Te(i))
2056
+ return y;
2057
+ const o = Ze(a.value, i.value);
2058
+ return o.valid ? ((Se(a) || Se(i)) && t.dirty(), { status: t.value, value: o.data }) : (u(r, {
2059
+ code: c.invalid_intersection_types
2060
+ }), y);
2061
+ };
2062
+ return r.common.async ? Promise.all([
2063
+ this._def.left._parseAsync({
2064
+ data: r.data,
2065
+ path: r.path,
2066
+ parent: r
2067
+ }),
2068
+ this._def.right._parseAsync({
2069
+ data: r.data,
2070
+ path: r.path,
2071
+ parent: r
2072
+ })
2073
+ ]).then(([a, i]) => s(a, i)) : s(this._def.left._parseSync({
2074
+ data: r.data,
2075
+ path: r.path,
2076
+ parent: r
2077
+ }), this._def.right._parseSync({
2078
+ data: r.data,
2079
+ path: r.path,
2080
+ parent: r
2081
+ }));
2082
+ }
2083
+ }
2084
+ re.create = (n, e, t) => new re({
2085
+ left: n,
2086
+ right: e,
2087
+ typeName: m.ZodIntersection,
2088
+ ..._(t)
2089
+ });
2090
+ class R extends v {
2091
+ _parse(e) {
2092
+ const { status: t, ctx: r } = this._processInputParams(e);
2093
+ if (r.parsedType !== h.array)
2094
+ return u(r, {
2095
+ code: c.invalid_type,
2096
+ expected: h.array,
2097
+ received: r.parsedType
2098
+ }), y;
2099
+ if (r.data.length < this._def.items.length)
2100
+ return u(r, {
2101
+ code: c.too_small,
2102
+ minimum: this._def.items.length,
2103
+ inclusive: !0,
2104
+ exact: !1,
2105
+ type: "array"
2106
+ }), y;
2107
+ !this._def.rest && r.data.length > this._def.items.length && (u(r, {
2108
+ code: c.too_big,
2109
+ maximum: this._def.items.length,
2110
+ inclusive: !0,
2111
+ exact: !1,
2112
+ type: "array"
2113
+ }), t.dirty());
2114
+ const a = [...r.data].map((i, o) => {
2115
+ const f = this._def.items[o] || this._def.rest;
2116
+ return f ? f._parse(new j(r, i, r.path, o)) : null;
2117
+ }).filter((i) => !!i);
2118
+ return r.common.async ? Promise.all(a).then((i) => k.mergeArray(t, i)) : k.mergeArray(t, a);
2119
+ }
2120
+ get items() {
2121
+ return this._def.items;
2122
+ }
2123
+ rest(e) {
2124
+ return new R({
2125
+ ...this._def,
2126
+ rest: e
2127
+ });
2128
+ }
2129
+ }
2130
+ R.create = (n, e) => {
2131
+ if (!Array.isArray(n))
2132
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
2133
+ return new R({
2134
+ items: n,
2135
+ typeName: m.ZodTuple,
2136
+ rest: null,
2137
+ ..._(e)
2138
+ });
2139
+ };
2140
+ class se extends v {
2141
+ get keySchema() {
2142
+ return this._def.keyType;
2143
+ }
2144
+ get valueSchema() {
2145
+ return this._def.valueType;
2146
+ }
2147
+ _parse(e) {
2148
+ const { status: t, ctx: r } = this._processInputParams(e);
2149
+ if (r.parsedType !== h.object)
2150
+ return u(r, {
2151
+ code: c.invalid_type,
2152
+ expected: h.object,
2153
+ received: r.parsedType
2154
+ }), y;
2155
+ const s = [], a = this._def.keyType, i = this._def.valueType;
2156
+ for (const o in r.data)
2157
+ s.push({
2158
+ key: a._parse(new j(r, o, r.path, o)),
2159
+ value: i._parse(new j(r, r.data[o], r.path, o)),
2160
+ alwaysSet: o in r.data
2161
+ });
2162
+ return r.common.async ? k.mergeObjectAsync(t, s) : k.mergeObjectSync(t, s);
2163
+ }
2164
+ get element() {
2165
+ return this._def.valueType;
2166
+ }
2167
+ static create(e, t, r) {
2168
+ return t instanceof v ? new se({
2169
+ keyType: e,
2170
+ valueType: t,
2171
+ typeName: m.ZodRecord,
2172
+ ..._(r)
2173
+ }) : new se({
2174
+ keyType: Z.create(),
2175
+ valueType: e,
2176
+ typeName: m.ZodRecord,
2177
+ ..._(t)
2178
+ });
2179
+ }
2180
+ }
2181
+ class ge extends v {
2182
+ get keySchema() {
2183
+ return this._def.keyType;
2184
+ }
2185
+ get valueSchema() {
2186
+ return this._def.valueType;
2187
+ }
2188
+ _parse(e) {
2189
+ const { status: t, ctx: r } = this._processInputParams(e);
2190
+ if (r.parsedType !== h.map)
2191
+ return u(r, {
2192
+ code: c.invalid_type,
2193
+ expected: h.map,
2194
+ received: r.parsedType
2195
+ }), y;
2196
+ const s = this._def.keyType, a = this._def.valueType, i = [...r.data.entries()].map(([o, f], l) => ({
2197
+ key: s._parse(new j(r, o, r.path, [l, "key"])),
2198
+ value: a._parse(new j(r, f, r.path, [l, "value"]))
2199
+ }));
2200
+ if (r.common.async) {
2201
+ const o = /* @__PURE__ */ new Map();
2202
+ return Promise.resolve().then(async () => {
2203
+ for (const f of i) {
2204
+ const l = await f.key, g = await f.value;
2205
+ if (l.status === "aborted" || g.status === "aborted")
2206
+ return y;
2207
+ (l.status === "dirty" || g.status === "dirty") && t.dirty(), o.set(l.value, g.value);
2208
+ }
2209
+ return { status: t.value, value: o };
2210
+ });
2211
+ } else {
2212
+ const o = /* @__PURE__ */ new Map();
2213
+ for (const f of i) {
2214
+ const l = f.key, g = f.value;
2215
+ if (l.status === "aborted" || g.status === "aborted")
2216
+ return y;
2217
+ (l.status === "dirty" || g.status === "dirty") && t.dirty(), o.set(l.value, g.value);
2218
+ }
2219
+ return { status: t.value, value: o };
2220
+ }
2221
+ }
2222
+ }
2223
+ ge.create = (n, e, t) => new ge({
2224
+ valueType: e,
2225
+ keyType: n,
2226
+ typeName: m.ZodMap,
2227
+ ..._(t)
2228
+ });
2229
+ class B extends v {
2230
+ _parse(e) {
2231
+ const { status: t, ctx: r } = this._processInputParams(e);
2232
+ if (r.parsedType !== h.set)
2233
+ return u(r, {
2234
+ code: c.invalid_type,
2235
+ expected: h.set,
2236
+ received: r.parsedType
2237
+ }), y;
2238
+ const s = this._def;
2239
+ s.minSize !== null && r.data.size < s.minSize.value && (u(r, {
2240
+ code: c.too_small,
2241
+ minimum: s.minSize.value,
2242
+ type: "set",
2243
+ inclusive: !0,
2244
+ exact: !1,
2245
+ message: s.minSize.message
2246
+ }), t.dirty()), s.maxSize !== null && r.data.size > s.maxSize.value && (u(r, {
2247
+ code: c.too_big,
2248
+ maximum: s.maxSize.value,
2249
+ type: "set",
2250
+ inclusive: !0,
2251
+ exact: !1,
2252
+ message: s.maxSize.message
2253
+ }), t.dirty());
2254
+ const a = this._def.valueType;
2255
+ function i(f) {
2256
+ const l = /* @__PURE__ */ new Set();
2257
+ for (const g of f) {
2258
+ if (g.status === "aborted")
2259
+ return y;
2260
+ g.status === "dirty" && t.dirty(), l.add(g.value);
2261
+ }
2262
+ return { status: t.value, value: l };
2263
+ }
2264
+ const o = [...r.data.values()].map((f, l) => a._parse(new j(r, f, r.path, l)));
2265
+ return r.common.async ? Promise.all(o).then((f) => i(f)) : i(o);
2266
+ }
2267
+ min(e, t) {
2268
+ return new B({
2269
+ ...this._def,
2270
+ minSize: { value: e, message: p.toString(t) }
2271
+ });
2272
+ }
2273
+ max(e, t) {
2274
+ return new B({
2275
+ ...this._def,
2276
+ maxSize: { value: e, message: p.toString(t) }
2277
+ });
2278
+ }
2279
+ size(e, t) {
2280
+ return this.min(e, t).max(e, t);
2281
+ }
2282
+ nonempty(e) {
2283
+ return this.min(1, e);
2284
+ }
2285
+ }
2286
+ B.create = (n, e) => new B({
2287
+ valueType: n,
2288
+ minSize: null,
2289
+ maxSize: null,
2290
+ typeName: m.ZodSet,
2291
+ ..._(e)
2292
+ });
2293
+ class W extends v {
2294
+ constructor() {
2295
+ super(...arguments), this.validate = this.implement;
2296
+ }
2297
+ _parse(e) {
2298
+ const { ctx: t } = this._processInputParams(e);
2299
+ if (t.parsedType !== h.function)
2300
+ return u(t, {
2301
+ code: c.invalid_type,
2302
+ expected: h.function,
2303
+ received: t.parsedType
2304
+ }), y;
2305
+ function r(o, f) {
2306
+ return he({
2307
+ data: o,
2308
+ path: t.path,
2309
+ errorMaps: [
2310
+ t.common.contextualErrorMap,
2311
+ t.schemaErrorMap,
2312
+ fe(),
2313
+ J
2314
+ ].filter((l) => !!l),
2315
+ issueData: {
2316
+ code: c.invalid_arguments,
2317
+ argumentsError: f
2318
+ }
2319
+ });
2320
+ }
2321
+ function s(o, f) {
2322
+ return he({
2323
+ data: o,
2324
+ path: t.path,
2325
+ errorMaps: [
2326
+ t.common.contextualErrorMap,
2327
+ t.schemaErrorMap,
2328
+ fe(),
2329
+ J
2330
+ ].filter((l) => !!l),
2331
+ issueData: {
2332
+ code: c.invalid_return_type,
2333
+ returnTypeError: f
2334
+ }
2335
+ });
2336
+ }
2337
+ const a = { errorMap: t.common.contextualErrorMap }, i = t.data;
2338
+ if (this._def.returns instanceof Y) {
2339
+ const o = this;
2340
+ return w(async function(...f) {
2341
+ const l = new T([]), g = await o._def.args.parseAsync(f, a).catch((be) => {
2342
+ throw l.addIssue(r(f, be)), l;
2343
+ }), S = await Reflect.apply(i, this, g);
2344
+ return await o._def.returns._def.type.parseAsync(S, a).catch((be) => {
2345
+ throw l.addIssue(s(S, be)), l;
2346
+ });
2347
+ });
2348
+ } else {
2349
+ const o = this;
2350
+ return w(function(...f) {
2351
+ const l = o._def.args.safeParse(f, a);
2352
+ if (!l.success)
2353
+ throw new T([r(f, l.error)]);
2354
+ const g = Reflect.apply(i, this, l.data), S = o._def.returns.safeParse(g, a);
2355
+ if (!S.success)
2356
+ throw new T([s(g, S.error)]);
2357
+ return S.data;
2358
+ });
2359
+ }
2360
+ }
2361
+ parameters() {
2362
+ return this._def.args;
2363
+ }
2364
+ returnType() {
2365
+ return this._def.returns;
2366
+ }
2367
+ args(...e) {
2368
+ return new W({
2369
+ ...this._def,
2370
+ args: R.create(e).rest(L.create())
2371
+ });
2372
+ }
2373
+ returns(e) {
2374
+ return new W({
2375
+ ...this._def,
2376
+ returns: e
2377
+ });
2378
+ }
2379
+ implement(e) {
2380
+ return this.parse(e);
2381
+ }
2382
+ strictImplement(e) {
2383
+ return this.parse(e);
2384
+ }
2385
+ static create(e, t, r) {
2386
+ return new W({
2387
+ args: e || R.create([]).rest(L.create()),
2388
+ returns: t || L.create(),
2389
+ typeName: m.ZodFunction,
2390
+ ..._(r)
2391
+ });
2392
+ }
2393
+ }
2394
+ class ae extends v {
2395
+ get schema() {
2396
+ return this._def.getter();
2397
+ }
2398
+ _parse(e) {
2399
+ const { ctx: t } = this._processInputParams(e);
2400
+ return this._def.getter()._parse({ data: t.data, path: t.path, parent: t });
2401
+ }
2402
+ }
2403
+ ae.create = (n, e) => new ae({
2404
+ getter: n,
2405
+ typeName: m.ZodLazy,
2406
+ ..._(e)
2407
+ });
2408
+ class ie extends v {
2409
+ _parse(e) {
2410
+ if (e.data !== this._def.value) {
2411
+ const t = this._getOrReturnCtx(e);
2412
+ return u(t, {
2413
+ received: t.data,
2414
+ code: c.invalid_literal,
2415
+ expected: this._def.value
2416
+ }), y;
2417
+ }
2418
+ return { status: "valid", value: e.data };
2419
+ }
2420
+ get value() {
2421
+ return this._def.value;
2422
+ }
2423
+ }
2424
+ ie.create = (n, e) => new ie({
2425
+ value: n,
2426
+ typeName: m.ZodLiteral,
2427
+ ..._(e)
2428
+ });
2429
+ function ze(n, e) {
2430
+ return new M({
2431
+ values: n,
2432
+ typeName: m.ZodEnum,
2433
+ ..._(e)
2434
+ });
2435
+ }
2436
+ class M extends v {
2437
+ constructor() {
2438
+ super(...arguments), G.set(this, void 0);
2439
+ }
2440
+ _parse(e) {
2441
+ if (typeof e.data != "string") {
2442
+ const t = this._getOrReturnCtx(e), r = this._def.values;
2443
+ return u(t, {
2444
+ expected: b.joinValues(r),
2445
+ received: t.parsedType,
2446
+ code: c.invalid_type
2447
+ }), y;
2448
+ }
2449
+ if (pe(this, G) || Ae(this, G, new Set(this._def.values)), !pe(this, G).has(e.data)) {
2450
+ const t = this._getOrReturnCtx(e), r = this._def.values;
2451
+ return u(t, {
2452
+ received: t.data,
2453
+ code: c.invalid_enum_value,
2454
+ options: r
2455
+ }), y;
2456
+ }
2457
+ return w(e.data);
2458
+ }
2459
+ get options() {
2460
+ return this._def.values;
2461
+ }
2462
+ get enum() {
2463
+ const e = {};
2464
+ for (const t of this._def.values)
2465
+ e[t] = t;
2466
+ return e;
2467
+ }
2468
+ get Values() {
2469
+ const e = {};
2470
+ for (const t of this._def.values)
2471
+ e[t] = t;
2472
+ return e;
2473
+ }
2474
+ get Enum() {
2475
+ const e = {};
2476
+ for (const t of this._def.values)
2477
+ e[t] = t;
2478
+ return e;
2479
+ }
2480
+ extract(e, t = this._def) {
2481
+ return M.create(e, {
2482
+ ...this._def,
2483
+ ...t
2484
+ });
2485
+ }
2486
+ exclude(e, t = this._def) {
2487
+ return M.create(this.options.filter((r) => !e.includes(r)), {
2488
+ ...this._def,
2489
+ ...t
2490
+ });
2491
+ }
2492
+ }
2493
+ G = /* @__PURE__ */ new WeakMap();
2494
+ M.create = ze;
2495
+ class oe extends v {
2496
+ constructor() {
2497
+ super(...arguments), X.set(this, void 0);
2498
+ }
2499
+ _parse(e) {
2500
+ const t = b.getValidEnumValues(this._def.values), r = this._getOrReturnCtx(e);
2501
+ if (r.parsedType !== h.string && r.parsedType !== h.number) {
2502
+ const s = b.objectValues(t);
2503
+ return u(r, {
2504
+ expected: b.joinValues(s),
2505
+ received: r.parsedType,
2506
+ code: c.invalid_type
2507
+ }), y;
2508
+ }
2509
+ if (pe(this, X) || Ae(this, X, new Set(b.getValidEnumValues(this._def.values))), !pe(this, X).has(e.data)) {
2510
+ const s = b.objectValues(t);
2511
+ return u(r, {
2512
+ received: r.data,
2513
+ code: c.invalid_enum_value,
2514
+ options: s
2515
+ }), y;
2516
+ }
2517
+ return w(e.data);
2518
+ }
2519
+ get enum() {
2520
+ return this._def.values;
2521
+ }
2522
+ }
2523
+ X = /* @__PURE__ */ new WeakMap();
2524
+ oe.create = (n, e) => new oe({
2525
+ values: n,
2526
+ typeName: m.ZodNativeEnum,
2527
+ ..._(e)
2528
+ });
2529
+ class Y extends v {
2530
+ unwrap() {
2531
+ return this._def.type;
2532
+ }
2533
+ _parse(e) {
2534
+ const { ctx: t } = this._processInputParams(e);
2535
+ if (t.parsedType !== h.promise && t.common.async === !1)
2536
+ return u(t, {
2537
+ code: c.invalid_type,
2538
+ expected: h.promise,
2539
+ received: t.parsedType
2540
+ }), y;
2541
+ const r = t.parsedType === h.promise ? t.data : Promise.resolve(t.data);
2542
+ return w(r.then((s) => this._def.type.parseAsync(s, {
2543
+ path: t.path,
2544
+ errorMap: t.common.contextualErrorMap
2545
+ })));
2546
+ }
2547
+ }
2548
+ Y.create = (n, e) => new Y({
2549
+ type: n,
2550
+ typeName: m.ZodPromise,
2551
+ ..._(e)
2552
+ });
2553
+ class I extends v {
2554
+ innerType() {
2555
+ return this._def.schema;
2556
+ }
2557
+ sourceType() {
2558
+ return this._def.schema._def.typeName === m.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
2559
+ }
2560
+ _parse(e) {
2561
+ const { status: t, ctx: r } = this._processInputParams(e), s = this._def.effect || null, a = {
2562
+ addIssue: (i) => {
2563
+ u(r, i), i.fatal ? t.abort() : t.dirty();
2564
+ },
2565
+ get path() {
2566
+ return r.path;
2567
+ }
2568
+ };
2569
+ if (a.addIssue = a.addIssue.bind(a), s.type === "preprocess") {
2570
+ const i = s.transform(r.data, a);
2571
+ if (r.common.async)
2572
+ return Promise.resolve(i).then(async (o) => {
2573
+ if (t.value === "aborted")
2574
+ return y;
2575
+ const f = await this._def.schema._parseAsync({
2576
+ data: o,
2577
+ path: r.path,
2578
+ parent: r
2579
+ });
2580
+ return f.status === "aborted" ? y : f.status === "dirty" || t.value === "dirty" ? q(f.value) : f;
2581
+ });
2582
+ {
2583
+ if (t.value === "aborted")
2584
+ return y;
2585
+ const o = this._def.schema._parseSync({
2586
+ data: i,
2587
+ path: r.path,
2588
+ parent: r
2589
+ });
2590
+ return o.status === "aborted" ? y : o.status === "dirty" || t.value === "dirty" ? q(o.value) : o;
2591
+ }
2592
+ }
2593
+ if (s.type === "refinement") {
2594
+ const i = (o) => {
2595
+ const f = s.refinement(o, a);
2596
+ if (r.common.async)
2597
+ return Promise.resolve(f);
2598
+ if (f instanceof Promise)
2599
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
2600
+ return o;
2601
+ };
2602
+ if (r.common.async === !1) {
2603
+ const o = this._def.schema._parseSync({
2604
+ data: r.data,
2605
+ path: r.path,
2606
+ parent: r
2607
+ });
2608
+ return o.status === "aborted" ? y : (o.status === "dirty" && t.dirty(), i(o.value), { status: t.value, value: o.value });
2609
+ } else
2610
+ return this._def.schema._parseAsync({ data: r.data, path: r.path, parent: r }).then((o) => o.status === "aborted" ? y : (o.status === "dirty" && t.dirty(), i(o.value).then(() => ({ status: t.value, value: o.value }))));
2611
+ }
2612
+ if (s.type === "transform")
2613
+ if (r.common.async === !1) {
2614
+ const i = this._def.schema._parseSync({
2615
+ data: r.data,
2616
+ path: r.path,
2617
+ parent: r
2618
+ });
2619
+ if (!D(i))
2620
+ return i;
2621
+ const o = s.transform(i.value, a);
2622
+ if (o instanceof Promise)
2623
+ throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");
2624
+ return { status: t.value, value: o };
2625
+ } else
2626
+ return this._def.schema._parseAsync({ data: r.data, path: r.path, parent: r }).then((i) => D(i) ? Promise.resolve(s.transform(i.value, a)).then((o) => ({ status: t.value, value: o })) : i);
2627
+ b.assertNever(s);
2628
+ }
2629
+ }
2630
+ I.create = (n, e, t) => new I({
2631
+ schema: n,
2632
+ typeName: m.ZodEffects,
2633
+ effect: e,
2634
+ ..._(t)
2635
+ });
2636
+ I.createWithPreprocess = (n, e, t) => new I({
2637
+ schema: e,
2638
+ effect: { type: "preprocess", transform: n },
2639
+ typeName: m.ZodEffects,
2640
+ ..._(t)
2641
+ });
2642
+ class O extends v {
2643
+ _parse(e) {
2644
+ return this._getType(e) === h.undefined ? w(void 0) : this._def.innerType._parse(e);
2645
+ }
2646
+ unwrap() {
2647
+ return this._def.innerType;
2648
+ }
2649
+ }
2650
+ O.create = (n, e) => new O({
2651
+ innerType: n,
2652
+ typeName: m.ZodOptional,
2653
+ ..._(e)
2654
+ });
2655
+ class P extends v {
2656
+ _parse(e) {
2657
+ return this._getType(e) === h.null ? w(null) : this._def.innerType._parse(e);
2658
+ }
2659
+ unwrap() {
2660
+ return this._def.innerType;
2661
+ }
2662
+ }
2663
+ P.create = (n, e) => new P({
2664
+ innerType: n,
2665
+ typeName: m.ZodNullable,
2666
+ ..._(e)
2667
+ });
2668
+ class de extends v {
2669
+ _parse(e) {
2670
+ const { ctx: t } = this._processInputParams(e);
2671
+ let r = t.data;
2672
+ return t.parsedType === h.undefined && (r = this._def.defaultValue()), this._def.innerType._parse({
2673
+ data: r,
2674
+ path: t.path,
2675
+ parent: t
2676
+ });
2677
+ }
2678
+ removeDefault() {
2679
+ return this._def.innerType;
2680
+ }
2681
+ }
2682
+ de.create = (n, e) => new de({
2683
+ innerType: n,
2684
+ typeName: m.ZodDefault,
2685
+ defaultValue: typeof e.default == "function" ? e.default : () => e.default,
2686
+ ..._(e)
2687
+ });
2688
+ class ce extends v {
2689
+ _parse(e) {
2690
+ const { ctx: t } = this._processInputParams(e), r = {
2691
+ ...t,
2692
+ common: {
2693
+ ...t.common,
2694
+ issues: []
2695
+ }
2696
+ }, s = this._def.innerType._parse({
2697
+ data: r.data,
2698
+ path: r.path,
2699
+ parent: {
2700
+ ...r
2701
+ }
2702
+ });
2703
+ return K(s) ? s.then((a) => ({
2704
+ status: "valid",
2705
+ value: a.status === "valid" ? a.value : this._def.catchValue({
2706
+ get error() {
2707
+ return new T(r.common.issues);
2708
+ },
2709
+ input: r.data
2710
+ })
2711
+ })) : {
2712
+ status: "valid",
2713
+ value: s.status === "valid" ? s.value : this._def.catchValue({
2714
+ get error() {
2715
+ return new T(r.common.issues);
2716
+ },
2717
+ input: r.data
2718
+ })
2719
+ };
2720
+ }
2721
+ removeCatch() {
2722
+ return this._def.innerType;
2723
+ }
2724
+ }
2725
+ ce.create = (n, e) => new ce({
2726
+ innerType: n,
2727
+ typeName: m.ZodCatch,
2728
+ catchValue: typeof e.catch == "function" ? e.catch : () => e.catch,
2729
+ ..._(e)
2730
+ });
2731
+ class _e extends v {
2732
+ _parse(e) {
2733
+ if (this._getType(e) !== h.nan) {
2734
+ const r = this._getOrReturnCtx(e);
2735
+ return u(r, {
2736
+ code: c.invalid_type,
2737
+ expected: h.nan,
2738
+ received: r.parsedType
2739
+ }), y;
2740
+ }
2741
+ return { status: "valid", value: e.data };
2742
+ }
2743
+ }
2744
+ _e.create = (n) => new _e({
2745
+ typeName: m.ZodNaN,
2746
+ ..._(n)
2747
+ });
2748
+ const pt = Symbol("zod_brand");
2749
+ class Ce extends v {
2750
+ _parse(e) {
2751
+ const { ctx: t } = this._processInputParams(e), r = t.data;
2752
+ return this._def.type._parse({
2753
+ data: r,
2754
+ path: t.path,
2755
+ parent: t
2756
+ });
2757
+ }
2758
+ unwrap() {
2759
+ return this._def.type;
2760
+ }
2761
+ }
2762
+ class le extends v {
2763
+ _parse(e) {
2764
+ const { status: t, ctx: r } = this._processInputParams(e);
2765
+ if (r.common.async)
2766
+ return (async () => {
2767
+ const a = await this._def.in._parseAsync({
2768
+ data: r.data,
2769
+ path: r.path,
2770
+ parent: r
2771
+ });
2772
+ return a.status === "aborted" ? y : a.status === "dirty" ? (t.dirty(), q(a.value)) : this._def.out._parseAsync({
2773
+ data: a.value,
2774
+ path: r.path,
2775
+ parent: r
2776
+ });
2777
+ })();
2778
+ {
2779
+ const s = this._def.in._parseSync({
2780
+ data: r.data,
2781
+ path: r.path,
2782
+ parent: r
2783
+ });
2784
+ return s.status === "aborted" ? y : s.status === "dirty" ? (t.dirty(), {
2785
+ status: "dirty",
2786
+ value: s.value
2787
+ }) : this._def.out._parseSync({
2788
+ data: s.value,
2789
+ path: r.path,
2790
+ parent: r
2791
+ });
2792
+ }
2793
+ }
2794
+ static create(e, t) {
2795
+ return new le({
2796
+ in: e,
2797
+ out: t,
2798
+ typeName: m.ZodPipeline
2799
+ });
2800
+ }
2801
+ }
2802
+ class ue extends v {
2803
+ _parse(e) {
2804
+ const t = this._def.innerType._parse(e), r = (s) => (D(s) && (s.value = Object.freeze(s.value)), s);
2805
+ return K(t) ? t.then((s) => r(s)) : r(t);
2806
+ }
2807
+ unwrap() {
2808
+ return this._def.innerType;
2809
+ }
2810
+ }
2811
+ ue.create = (n, e) => new ue({
2812
+ innerType: n,
2813
+ typeName: m.ZodReadonly,
2814
+ ..._(e)
2815
+ });
2816
+ function Me(n, e = {}, t) {
2817
+ return n ? H.create().superRefine((r, s) => {
2818
+ var a, i;
2819
+ if (!n(r)) {
2820
+ const o = typeof e == "function" ? e(r) : typeof e == "string" ? { message: e } : e, f = (i = (a = o.fatal) !== null && a !== void 0 ? a : t) !== null && i !== void 0 ? i : !0, l = typeof o == "string" ? { message: o } : o;
2821
+ s.addIssue({ code: "custom", ...l, fatal: f });
2822
+ }
2823
+ }) : H.create();
2824
+ }
2825
+ const mt = {
2826
+ object: x.lazycreate
2827
+ };
2828
+ var m;
2829
+ (function(n) {
2830
+ n.ZodString = "ZodString", n.ZodNumber = "ZodNumber", n.ZodNaN = "ZodNaN", n.ZodBigInt = "ZodBigInt", n.ZodBoolean = "ZodBoolean", n.ZodDate = "ZodDate", n.ZodSymbol = "ZodSymbol", n.ZodUndefined = "ZodUndefined", n.ZodNull = "ZodNull", n.ZodAny = "ZodAny", n.ZodUnknown = "ZodUnknown", n.ZodNever = "ZodNever", n.ZodVoid = "ZodVoid", n.ZodArray = "ZodArray", n.ZodObject = "ZodObject", n.ZodUnion = "ZodUnion", n.ZodDiscriminatedUnion = "ZodDiscriminatedUnion", n.ZodIntersection = "ZodIntersection", n.ZodTuple = "ZodTuple", n.ZodRecord = "ZodRecord", n.ZodMap = "ZodMap", n.ZodSet = "ZodSet", n.ZodFunction = "ZodFunction", n.ZodLazy = "ZodLazy", n.ZodLiteral = "ZodLiteral", n.ZodEnum = "ZodEnum", n.ZodEffects = "ZodEffects", n.ZodNativeEnum = "ZodNativeEnum", n.ZodOptional = "ZodOptional", n.ZodNullable = "ZodNullable", n.ZodDefault = "ZodDefault", n.ZodCatch = "ZodCatch", n.ZodPromise = "ZodPromise", n.ZodBranded = "ZodBranded", n.ZodPipeline = "ZodPipeline", n.ZodReadonly = "ZodReadonly";
2831
+ })(m || (m = {}));
2832
+ const yt = (n, e = {
2833
+ message: `Input not instance of ${n.name}`
2834
+ }) => Me((t) => t instanceof n, e), Pe = Z.create, Ve = $.create, gt = _e.create, _t = z.create, Le = Q.create, vt = U.create, bt = me.create, xt = ee.create, kt = te.create, wt = H.create, Tt = L.create, St = E.create, Zt = ye.create, Ct = C.create, It = x.create, Ot = x.strictCreate, jt = ne.create, Rt = ve.create, At = re.create, Nt = R.create, Et = se.create, $t = ge.create, zt = B.create, Mt = W.create, Pt = ae.create, Vt = ie.create, Lt = M.create, Dt = oe.create, Ut = Y.create, je = I.create, Bt = O.create, Ft = P.create, qt = I.createWithPreprocess, Wt = le.create, Jt = () => Pe().optional(), Ht = () => Ve().optional(), Yt = () => Le().optional(), Gt = {
2835
+ string: (n) => Z.create({ ...n, coerce: !0 }),
2836
+ number: (n) => $.create({ ...n, coerce: !0 }),
2837
+ boolean: (n) => Q.create({
2838
+ ...n,
2839
+ coerce: !0
2840
+ }),
2841
+ bigint: (n) => z.create({ ...n, coerce: !0 }),
2842
+ date: (n) => U.create({ ...n, coerce: !0 })
2843
+ }, Xt = y;
2844
+ var d = /* @__PURE__ */ Object.freeze({
2845
+ __proto__: null,
2846
+ defaultErrorMap: J,
2847
+ setErrorMap: qe,
2848
+ getErrorMap: fe,
2849
+ makeIssue: he,
2850
+ EMPTY_PATH: We,
2851
+ addIssueToContext: u,
2852
+ ParseStatus: k,
2853
+ INVALID: y,
2854
+ DIRTY: q,
2855
+ OK: w,
2856
+ isAborted: Te,
2857
+ isDirty: Se,
2858
+ isValid: D,
2859
+ isAsync: K,
2860
+ get util() {
2861
+ return b;
2862
+ },
2863
+ get objectUtil() {
2864
+ return we;
2865
+ },
2866
+ ZodParsedType: h,
2867
+ getParsedType: N,
2868
+ ZodType: v,
2869
+ datetimeRegex: $e,
2870
+ ZodString: Z,
2871
+ ZodNumber: $,
2872
+ ZodBigInt: z,
2873
+ ZodBoolean: Q,
2874
+ ZodDate: U,
2875
+ ZodSymbol: me,
2876
+ ZodUndefined: ee,
2877
+ ZodNull: te,
2878
+ ZodAny: H,
2879
+ ZodUnknown: L,
2880
+ ZodNever: E,
2881
+ ZodVoid: ye,
2882
+ ZodArray: C,
2883
+ ZodObject: x,
2884
+ ZodUnion: ne,
2885
+ ZodDiscriminatedUnion: ve,
2886
+ ZodIntersection: re,
2887
+ ZodTuple: R,
2888
+ ZodRecord: se,
2889
+ ZodMap: ge,
2890
+ ZodSet: B,
2891
+ ZodFunction: W,
2892
+ ZodLazy: ae,
2893
+ ZodLiteral: ie,
2894
+ ZodEnum: M,
2895
+ ZodNativeEnum: oe,
2896
+ ZodPromise: Y,
2897
+ ZodEffects: I,
2898
+ ZodTransformer: I,
2899
+ ZodOptional: O,
2900
+ ZodNullable: P,
2901
+ ZodDefault: de,
2902
+ ZodCatch: ce,
2903
+ ZodNaN: _e,
2904
+ BRAND: pt,
2905
+ ZodBranded: Ce,
2906
+ ZodPipeline: le,
2907
+ ZodReadonly: ue,
2908
+ custom: Me,
2909
+ Schema: v,
2910
+ ZodSchema: v,
2911
+ late: mt,
2912
+ get ZodFirstPartyTypeKind() {
2913
+ return m;
2914
+ },
2915
+ coerce: Gt,
2916
+ any: wt,
2917
+ array: Ct,
2918
+ bigint: _t,
2919
+ boolean: Le,
2920
+ date: vt,
2921
+ discriminatedUnion: Rt,
2922
+ effect: je,
2923
+ enum: Lt,
2924
+ function: Mt,
2925
+ instanceof: yt,
2926
+ intersection: At,
2927
+ lazy: Pt,
2928
+ literal: Vt,
2929
+ map: $t,
2930
+ nan: gt,
2931
+ nativeEnum: Dt,
2932
+ never: St,
2933
+ null: kt,
2934
+ nullable: Ft,
2935
+ number: Ve,
2936
+ object: It,
2937
+ oboolean: Yt,
2938
+ onumber: Ht,
2939
+ optional: Bt,
2940
+ ostring: Jt,
2941
+ pipeline: Wt,
2942
+ preprocess: qt,
2943
+ promise: Ut,
2944
+ record: Et,
2945
+ set: zt,
2946
+ strictObject: Ot,
2947
+ string: Pe,
2948
+ symbol: bt,
2949
+ transformer: je,
2950
+ tuple: Nt,
2951
+ undefined: xt,
2952
+ union: jt,
2953
+ unknown: Tt,
2954
+ void: Zt,
2955
+ NEVER: Xt,
2956
+ ZodIssueCode: c,
2957
+ quotelessJson: Fe,
2958
+ ZodError: T
2959
+ });
2960
+ const Kt = d.object({
2961
+ organizationId: d.string().nonempty()
2962
+ });
2963
+ d.enum([
2964
+ "step_impression",
2965
+ "element_click",
2966
+ "form_submit",
2967
+ "form_error",
2968
+ "step_action"
2969
+ ]);
2970
+ d.object({});
2971
+ class Qt {
2972
+ constructor(e) {
2973
+ V(this, "options");
2974
+ this.options = Kt.parse(e);
2975
+ }
2976
+ /**
2977
+ * Analyzes a request and generates tracking events based on the provided trigger and options.
2978
+ *
2979
+ * @param {GetStepTrigger | { stepId?: string }} trigger - The trigger for the step, which can be either a `GetStepTrigger` or an object containing an optional `stepId`.
2980
+ * @param {GetStepOptions} options - The options for getting the step, including fields for form data.
2981
+ * @returns {Promise<EventData[]>} A promise that resolves to an array of `EventData` objects representing the tracking events.
2982
+ */
2983
+ async analyzeRequest(e, t) {
2984
+ const r = [];
2985
+ return "currentStepId" in e && (e.actionId && r.push({
2986
+ type: "element_click",
2987
+ data: {
2988
+ element_label: e.actionId,
2989
+ element_type: "button",
2990
+ step_id: e.currentStepId,
2991
+ organization_id: this.options.organizationId,
2992
+ tracker_client: "tracker@0.0.0"
2993
+ }
2994
+ }), t.fields && r.push({
2995
+ type: "form_submit",
2996
+ data: {
2997
+ form_data: t.fields,
2998
+ step_id: e.currentStepId,
2999
+ organization_id: this.options.organizationId,
3000
+ tracker_client: "tracker@0.0.0"
3001
+ }
3002
+ })), r;
3003
+ }
3004
+ /**
3005
+ * Analyzes the response based on the provided trigger and flow context, and generates tracking events.
3006
+ *
3007
+ * @param {GetStepTrigger | { stepId?: string }} trigger - The trigger for the step, which can be either a `GetStepTrigger` or an object containing an optional `stepId`.
3008
+ * @param {FlowContext} flowContext - The context of the flow, containing information about the current step and its result.
3009
+ * @returns {Promise<EventData[]>} A promise that resolves to an array of `EventData` objects representing the tracking events.
3010
+ */
3011
+ async analyzeResponse(e, t) {
3012
+ var s;
3013
+ const r = [];
3014
+ return "currentStepId" in e && (r.push({
3015
+ type: "step_impression",
3016
+ data: {
3017
+ step_id: e.currentStepId,
3018
+ organization_id: this.options.organizationId,
3019
+ tracker_client: "tracker@0.0.0"
3020
+ }
3021
+ }), (s = t.step.result) != null && s.pipelines && t.step.result.pipelines.forEach((a) => {
3022
+ r.push({
3023
+ type: "step_action",
3024
+ data: {
3025
+ action_name: a.name,
3026
+ action_data: a.data,
3027
+ step_id: e.currentStepId,
3028
+ organization_id: this.options.organizationId,
3029
+ tracker_client: "tracker@0.0.0"
3030
+ }
3031
+ });
3032
+ }), t.step.error && r.push({
3033
+ type: "form_error",
3034
+ data: {
3035
+ error_message: t.step.error.message || (t.step.error.fields ? "Invalid fields" : "Unknown error"),
3036
+ step_id: e.currentStepId,
3037
+ organization_id: this.options.organizationId,
3038
+ tracker_client: "tracker@0.0.0"
3039
+ }
3040
+ })), r;
3041
+ }
3042
+ }
3043
+ const en = d.string().nonempty(), tn = d.object({
3044
+ baseUrl: d.string().url().nonempty(),
3045
+ flowId: d.string().length(24).nonempty(),
3046
+ organizationId: d.string().uuid().nonempty(),
3047
+ lang: d.string().length(2).nonempty()
3048
+ }), ke = d.object({
3049
+ state: d.record(d.string(), d.any()).optional(),
3050
+ fields: d.record(d.string(), d.any()).optional()
3051
+ }), nn = d.object({
3052
+ currentStepId: d.string().nonempty(),
3053
+ actionId: d.string().nonempty()
3054
+ }), De = d.enum([
3055
+ "text",
3056
+ "boolean",
3057
+ "number",
3058
+ "email",
3059
+ "phone",
3060
+ "mobile_phone",
3061
+ "date",
3062
+ "time",
3063
+ "datetime",
3064
+ "password",
3065
+ "url",
3066
+ "void",
3067
+ "location",
3068
+ "availability"
3069
+ ]), rn = d.object({
3070
+ name: d.string().nonempty(),
3071
+ label: d.string().nonempty(),
3072
+ value: d.any().optional(),
3073
+ type: De,
3074
+ component: d.enum([
3075
+ "input",
3076
+ "textarea",
3077
+ "select",
3078
+ "radio",
3079
+ "checkbox",
3080
+ "switch",
3081
+ "carousel",
3082
+ "button",
3083
+ "label",
3084
+ "map",
3085
+ "calendar"
3086
+ ]).optional(),
3087
+ selectionMode: d.enum(["single", "multiple"]).optional(),
3088
+ placeholder: d.string().optional(),
3089
+ options: d.array(
3090
+ d.object({
3091
+ label: d.string().nonempty(),
3092
+ value: d.any().optional(),
3093
+ image: d.string().url().optional(),
3094
+ description: d.string().optional(),
3095
+ disabled: d.boolean().optional()
3096
+ })
3097
+ ).optional(),
3098
+ required: d.boolean().optional(),
3099
+ configuration: d.object({
3100
+ input: d.object({
3101
+ min: d.number().optional(),
3102
+ max: d.number().optional(),
3103
+ step: d.number().optional(),
3104
+ regex: d.string().refine((n) => {
3105
+ try {
3106
+ return new RegExp(n), !0;
3107
+ } catch {
3108
+ return !1;
3109
+ }
3110
+ }, "Invalid regex pattern").optional(),
3111
+ prefix: d.string().optional(),
3112
+ suffix: d.string().optional()
3113
+ }).optional(),
3114
+ map: d.object({
3115
+ apiKey: d.string().optional(),
3116
+ region: d.string().length(2).optional(),
3117
+ maxZoom: d.number().optional(),
3118
+ minZoom: d.number().optional(),
3119
+ minLocations: d.number().optional(),
3120
+ maxLocations: d.number().optional(),
3121
+ distanceUnit: d.enum(["km", "mi"]).optional(),
3122
+ search: d.object({
3123
+ placeholder: d.string().optional(),
3124
+ noResultsText: d.string().optional(),
3125
+ autocomplete: d.boolean().optional(),
3126
+ mode: d.enum(["address", "postcode"]).optional()
3127
+ }).optional(),
3128
+ distanceRange: d.object({
3129
+ initial: d.number().optional(),
3130
+ min: d.number().optional(),
3131
+ max: d.number().optional(),
3132
+ step: d.number().optional()
3133
+ }).optional(),
3134
+ mapRegion: d.object({}).optional(),
3135
+ mapPin: d.object({}).optional()
3136
+ }).optional(),
3137
+ calendar: d.object({
3138
+ time: d.object({
3139
+ format: d.enum(["12h", "24h"]).optional()
3140
+ }).optional()
3141
+ }).optional()
3142
+ }).optional(),
3143
+ dependsOn: d.array(
3144
+ d.object({
3145
+ fieldName: d.string().nonempty(),
3146
+ value: d.any().optional()
3147
+ })
3148
+ ).optional(),
3149
+ dependentBehavior: d.enum(["hidden", "disabled"]).optional()
3150
+ }), sn = d.object({
3151
+ id: d.string().nonempty(),
3152
+ type: d.enum(["submit", "forward", "link", "iCall"]),
3153
+ label: d.string().nonempty(),
3154
+ variant: d.enum(["primary", "secondary", "success", "danger", "warning", "info"]),
3155
+ url: d.string().url().optional()
3156
+ }), an = d.object({
3157
+ id: d.string().nonempty(),
3158
+ title: d.string().optional(),
3159
+ description: d.string().optional(),
3160
+ stageId: d.string().optional(),
3161
+ state: d.record(d.string(), d.any()).optional(),
3162
+ fields: d.array(rn).optional(),
3163
+ actions: d.array(sn).optional(),
3164
+ result: d.object({
3165
+ pipelines: d.array(d.object({ name: d.string(), data: d.object({}) })).optional()
3166
+ }).optional(),
3167
+ error: d.object({
3168
+ message: d.string().optional(),
3169
+ fields: d.array(
3170
+ d.object({
3171
+ name: d.string(),
3172
+ type: De,
3173
+ value: d.any(),
3174
+ error: d.string()
3175
+ })
3176
+ ).optional()
3177
+ }).optional(),
3178
+ isFinal: d.boolean().optional()
3179
+ }), on = d.object({
3180
+ id: d.string().length(24).nonempty(),
3181
+ organizationId: d.string().uuid().nonempty(),
3182
+ updatedAt: d.string().datetime().nonempty(),
3183
+ stages: d.array(
3184
+ d.object({
3185
+ id: d.string().nonempty(),
3186
+ name: d.string().nonempty()
3187
+ })
3188
+ )
3189
+ });
3190
+ d.object({
3191
+ status: d.enum(["ok", "error"]),
3192
+ step: an,
3193
+ flow: on
3194
+ });
3195
+ d.enum(["track"]);
3196
+ class cn {
3197
+ constructor(e) {
3198
+ V(this, "baseURL");
3199
+ V(this, "headers");
3200
+ V(this, "flowId");
3201
+ V(this, "eventListeners", /* @__PURE__ */ new Map());
3202
+ V(this, "trackingService");
3203
+ const t = tn.parse(e);
3204
+ this.flowId = t.flowId, this.baseURL = t.baseUrl, this.headers = new Headers({
3205
+ "Content-Type": "application/json",
3206
+ "X-Organization-Id": t.organizationId,
3207
+ "X-Lang": t.lang
3208
+ }), this.trackingService = new Qt({ organizationId: t.organizationId });
3209
+ }
3210
+ /**
3211
+ * Sends an HTTP request to the specified path and returns the response as a JSON object.
3212
+ *
3213
+ * @template T - The expected response type.
3214
+ * @param {string} path - The path to which the request is sent.
3215
+ * @param {RequestInit} [options={}] - Optional configuration for the request.
3216
+ * @returns {Promise<T>} - A promise that resolves to the response data.
3217
+ * @throws {Error} - Throws an error if the response status is not ok.
3218
+ */
3219
+ async request(e, t = {}) {
3220
+ const r = await fetch(`${this.baseURL}/${e}`, {
3221
+ ...t,
3222
+ headers: this.headers
3223
+ });
3224
+ if (!(r != null && r.ok))
3225
+ throw new Error(`HTTP error! status: ${(r == null ? void 0 : r.status) || "unknown"}`);
3226
+ return r.json();
3227
+ }
3228
+ /**
3229
+ * Initiates the first step of the flow process.
3230
+ *
3231
+ * @param {GetStepOptions} options - Optional parameters for getting the step.
3232
+ * @returns {Promise<FlowContext>} A promise that resolves to the flow context.
3233
+ */
3234
+ async firstStep(e = {}) {
3235
+ this.trackingService.analyzeRequest({}, e).then((r) => r.map((s) => this.emit("track", s)));
3236
+ const t = await this.request(`flow/${this.flowId}/first-step`, {
3237
+ method: "POST",
3238
+ body: JSON.stringify(ke.parse(e))
3239
+ });
3240
+ return this.trackingService.analyzeResponse({}, t).then((r) => r.map((s) => this.emit("track", s))), t;
3241
+ }
3242
+ /**
3243
+ * Retrieves a specific step in the flow based on the provided step ID and options.
3244
+ *
3245
+ * @param {string} stepId - The unique identifier of the step to retrieve.
3246
+ * @param {GetStepOptions} options - Optional parameters for retrieving the step.
3247
+ * @returns {Promise<FlowContext>} A promise that resolves to the FlowContext of the requested step.
3248
+ */
3249
+ async getStep(e, t = {}) {
3250
+ this.trackingService.analyzeRequest({ stepId: e }, t).then((s) => s.map((a) => this.emit("track", a)));
3251
+ const r = await this.request(
3252
+ `flow/${this.flowId}/steps/${en.parse(e)}`,
3253
+ {
3254
+ method: "POST",
3255
+ body: JSON.stringify(ke.parse(t))
3256
+ }
3257
+ );
3258
+ return this.trackingService.analyzeResponse({ stepId: e }, r).then((s) => s.map((a) => this.emit("track", a))), r;
3259
+ }
3260
+ /**
3261
+ * Proceeds to the next step in the flow based on the provided trigger and options.
3262
+ *
3263
+ * @param {GetStepTrigger} trigger - The trigger information required to determine the next step.
3264
+ * @param {GetStepOptions} options - Optional parameters to customize the step retrieval process.
3265
+ * @returns {Promise<FlowContext>} A promise that resolves to the updated flow context.
3266
+ */
3267
+ async nextStep(e, t = {}) {
3268
+ this.trackingService.analyzeRequest(e, t).then((i) => i.map((o) => this.emit("track", o)));
3269
+ const { currentStepId: r, actionId: s } = nn.parse(e), a = await this.request(
3270
+ `flow/${this.flowId}/steps/${r}/action/${s}`,
3271
+ {
3272
+ method: "POST",
3273
+ body: JSON.stringify(ke.parse(t))
3274
+ }
3275
+ );
3276
+ return this.trackingService.analyzeResponse(e, a).then((i) => i.map((o) => this.emit("track", o))), a;
3277
+ }
3278
+ /**
3279
+ * Registers an event listener for a specific event type.
3280
+ *
3281
+ * @param type - The type of event to listen for.
3282
+ * @param listener - The callback function to be invoked when the event is emitted.
3283
+ */
3284
+ on(e, t) {
3285
+ var r;
3286
+ this.eventListeners.has(e) || this.eventListeners.set(e, []), (r = this.eventListeners.get(e)) == null || r.push(t);
3287
+ }
3288
+ /**
3289
+ * Emits an event to all registered listeners for the specified event type.
3290
+ *
3291
+ * @param {EventType} eventType - The type of the event to emit.
3292
+ * @param {EventData} eventData - The data associated with the event.
3293
+ */
3294
+ emit(e, t) {
3295
+ var r;
3296
+ (r = this.eventListeners.get(e)) == null || r.forEach((s) => s(t.type, t.data));
3297
+ }
3298
+ }
3299
+ export {
3300
+ cn as FlowClient
3301
+ };