@rpcbase/server 0.467.0 → 0.469.0

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.
@@ -0,0 +1,3384 @@
1
+ import { loadModel } from "@rpcbase/db";
2
+ function $constructor(name, initializer2, params) {
3
+ function init(inst, def) {
4
+ if (!inst._zod) {
5
+ Object.defineProperty(inst, "_zod", {
6
+ value: {
7
+ def,
8
+ constr: _,
9
+ traits: /* @__PURE__ */ new Set()
10
+ },
11
+ enumerable: false
12
+ });
13
+ }
14
+ if (inst._zod.traits.has(name)) {
15
+ return;
16
+ }
17
+ inst._zod.traits.add(name);
18
+ initializer2(inst, def);
19
+ const proto = _.prototype;
20
+ const keys = Object.keys(proto);
21
+ for (let i = 0; i < keys.length; i++) {
22
+ const k = keys[i];
23
+ if (!(k in inst)) {
24
+ inst[k] = proto[k].bind(inst);
25
+ }
26
+ }
27
+ }
28
+ const Parent = params?.Parent ?? Object;
29
+ class Definition extends Parent {
30
+ }
31
+ Object.defineProperty(Definition, "name", { value: name });
32
+ function _(def) {
33
+ var _a2;
34
+ const inst = params?.Parent ? new Definition() : this;
35
+ init(inst, def);
36
+ (_a2 = inst._zod).deferred ?? (_a2.deferred = []);
37
+ for (const fn of inst._zod.deferred) {
38
+ fn();
39
+ }
40
+ return inst;
41
+ }
42
+ Object.defineProperty(_, "init", { value: init });
43
+ Object.defineProperty(_, Symbol.hasInstance, {
44
+ value: (inst) => {
45
+ if (params?.Parent && inst instanceof params.Parent)
46
+ return true;
47
+ return inst?._zod?.traits?.has(name);
48
+ }
49
+ });
50
+ Object.defineProperty(_, "name", { value: name });
51
+ return _;
52
+ }
53
+ class $ZodAsyncError extends Error {
54
+ constructor() {
55
+ super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
56
+ }
57
+ }
58
+ class $ZodEncodeError extends Error {
59
+ constructor(name) {
60
+ super(`Encountered unidirectional transform during encode: ${name}`);
61
+ this.name = "ZodEncodeError";
62
+ }
63
+ }
64
+ const globalConfig = {};
65
+ function config(newConfig) {
66
+ return globalConfig;
67
+ }
68
+ function getEnumValues(entries) {
69
+ const numericValues = Object.values(entries).filter((v) => typeof v === "number");
70
+ const values = Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
71
+ return values;
72
+ }
73
+ function jsonStringifyReplacer(_, value) {
74
+ if (typeof value === "bigint")
75
+ return value.toString();
76
+ return value;
77
+ }
78
+ function cached(getter) {
79
+ return {
80
+ get value() {
81
+ {
82
+ const value = getter();
83
+ Object.defineProperty(this, "value", { value });
84
+ return value;
85
+ }
86
+ }
87
+ };
88
+ }
89
+ function nullish(input) {
90
+ return input === null || input === void 0;
91
+ }
92
+ function cleanRegex(source) {
93
+ const start = source.startsWith("^") ? 1 : 0;
94
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
95
+ return source.slice(start, end);
96
+ }
97
+ function floatSafeRemainder(val, step) {
98
+ const valDecCount = (val.toString().split(".")[1] || "").length;
99
+ const stepString = step.toString();
100
+ let stepDecCount = (stepString.split(".")[1] || "").length;
101
+ if (stepDecCount === 0 && /\d?e-\d?/.test(stepString)) {
102
+ const match = stepString.match(/\d?e-(\d?)/);
103
+ if (match?.[1]) {
104
+ stepDecCount = Number.parseInt(match[1]);
105
+ }
106
+ }
107
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
108
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
109
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
110
+ return valInt % stepInt / 10 ** decCount;
111
+ }
112
+ const EVALUATING = Symbol("evaluating");
113
+ function defineLazy(object2, key, getter) {
114
+ let value = void 0;
115
+ Object.defineProperty(object2, key, {
116
+ get() {
117
+ if (value === EVALUATING) {
118
+ return void 0;
119
+ }
120
+ if (value === void 0) {
121
+ value = EVALUATING;
122
+ value = getter();
123
+ }
124
+ return value;
125
+ },
126
+ set(v) {
127
+ Object.defineProperty(object2, key, {
128
+ value: v
129
+ // configurable: true,
130
+ });
131
+ },
132
+ configurable: true
133
+ });
134
+ }
135
+ function assignProp(target, prop, value) {
136
+ Object.defineProperty(target, prop, {
137
+ value,
138
+ writable: true,
139
+ enumerable: true,
140
+ configurable: true
141
+ });
142
+ }
143
+ function mergeDefs(...defs) {
144
+ const mergedDescriptors = {};
145
+ for (const def of defs) {
146
+ const descriptors = Object.getOwnPropertyDescriptors(def);
147
+ Object.assign(mergedDescriptors, descriptors);
148
+ }
149
+ return Object.defineProperties({}, mergedDescriptors);
150
+ }
151
+ function esc(str) {
152
+ return JSON.stringify(str);
153
+ }
154
+ function slugify(input) {
155
+ return input.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
156
+ }
157
+ const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {
158
+ };
159
+ function isObject(data) {
160
+ return typeof data === "object" && data !== null && !Array.isArray(data);
161
+ }
162
+ const allowsEval = cached(() => {
163
+ if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) {
164
+ return false;
165
+ }
166
+ try {
167
+ const F = Function;
168
+ new F("");
169
+ return true;
170
+ } catch (_) {
171
+ return false;
172
+ }
173
+ });
174
+ function isPlainObject(o) {
175
+ if (isObject(o) === false)
176
+ return false;
177
+ const ctor = o.constructor;
178
+ if (ctor === void 0)
179
+ return true;
180
+ if (typeof ctor !== "function")
181
+ return true;
182
+ const prot = ctor.prototype;
183
+ if (isObject(prot) === false)
184
+ return false;
185
+ if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) {
186
+ return false;
187
+ }
188
+ return true;
189
+ }
190
+ function shallowClone(o) {
191
+ if (isPlainObject(o))
192
+ return { ...o };
193
+ if (Array.isArray(o))
194
+ return [...o];
195
+ return o;
196
+ }
197
+ const propertyKeyTypes = /* @__PURE__ */ new Set(["string", "number", "symbol"]);
198
+ function escapeRegex(str) {
199
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
200
+ }
201
+ function clone(inst, def, params) {
202
+ const cl = new inst._zod.constr(def ?? inst._zod.def);
203
+ if (!def || params?.parent)
204
+ cl._zod.parent = inst;
205
+ return cl;
206
+ }
207
+ function normalizeParams(_params) {
208
+ const params = _params;
209
+ if (!params)
210
+ return {};
211
+ if (typeof params === "string")
212
+ return { error: () => params };
213
+ if (params?.message !== void 0) {
214
+ if (params?.error !== void 0)
215
+ throw new Error("Cannot specify both `message` and `error` params");
216
+ params.error = params.message;
217
+ }
218
+ delete params.message;
219
+ if (typeof params.error === "string")
220
+ return { ...params, error: () => params.error };
221
+ return params;
222
+ }
223
+ function optionalKeys(shape) {
224
+ return Object.keys(shape).filter((k) => {
225
+ return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
226
+ });
227
+ }
228
+ const NUMBER_FORMAT_RANGES = {
229
+ safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
230
+ int32: [-2147483648, 2147483647],
231
+ uint32: [0, 4294967295],
232
+ float32: [-34028234663852886e22, 34028234663852886e22],
233
+ float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
234
+ };
235
+ function pick(schema, mask) {
236
+ const currDef = schema._zod.def;
237
+ const def = mergeDefs(schema._zod.def, {
238
+ get shape() {
239
+ const newShape = {};
240
+ for (const key in mask) {
241
+ if (!(key in currDef.shape)) {
242
+ throw new Error(`Unrecognized key: "${key}"`);
243
+ }
244
+ if (!mask[key])
245
+ continue;
246
+ newShape[key] = currDef.shape[key];
247
+ }
248
+ assignProp(this, "shape", newShape);
249
+ return newShape;
250
+ },
251
+ checks: []
252
+ });
253
+ return clone(schema, def);
254
+ }
255
+ function omit(schema, mask) {
256
+ const currDef = schema._zod.def;
257
+ const def = mergeDefs(schema._zod.def, {
258
+ get shape() {
259
+ const newShape = { ...schema._zod.def.shape };
260
+ for (const key in mask) {
261
+ if (!(key in currDef.shape)) {
262
+ throw new Error(`Unrecognized key: "${key}"`);
263
+ }
264
+ if (!mask[key])
265
+ continue;
266
+ delete newShape[key];
267
+ }
268
+ assignProp(this, "shape", newShape);
269
+ return newShape;
270
+ },
271
+ checks: []
272
+ });
273
+ return clone(schema, def);
274
+ }
275
+ function extend(schema, shape) {
276
+ if (!isPlainObject(shape)) {
277
+ throw new Error("Invalid input to extend: expected a plain object");
278
+ }
279
+ const checks = schema._zod.def.checks;
280
+ const hasChecks = checks && checks.length > 0;
281
+ if (hasChecks) {
282
+ throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");
283
+ }
284
+ const def = mergeDefs(schema._zod.def, {
285
+ get shape() {
286
+ const _shape = { ...schema._zod.def.shape, ...shape };
287
+ assignProp(this, "shape", _shape);
288
+ return _shape;
289
+ },
290
+ checks: []
291
+ });
292
+ return clone(schema, def);
293
+ }
294
+ function safeExtend(schema, shape) {
295
+ if (!isPlainObject(shape)) {
296
+ throw new Error("Invalid input to safeExtend: expected a plain object");
297
+ }
298
+ const def = {
299
+ ...schema._zod.def,
300
+ get shape() {
301
+ const _shape = { ...schema._zod.def.shape, ...shape };
302
+ assignProp(this, "shape", _shape);
303
+ return _shape;
304
+ },
305
+ checks: schema._zod.def.checks
306
+ };
307
+ return clone(schema, def);
308
+ }
309
+ function merge(a, b) {
310
+ const def = mergeDefs(a._zod.def, {
311
+ get shape() {
312
+ const _shape = { ...a._zod.def.shape, ...b._zod.def.shape };
313
+ assignProp(this, "shape", _shape);
314
+ return _shape;
315
+ },
316
+ get catchall() {
317
+ return b._zod.def.catchall;
318
+ },
319
+ checks: []
320
+ // delete existing checks
321
+ });
322
+ return clone(a, def);
323
+ }
324
+ function partial(Class, schema, mask) {
325
+ const def = mergeDefs(schema._zod.def, {
326
+ get shape() {
327
+ const oldShape = schema._zod.def.shape;
328
+ const shape = { ...oldShape };
329
+ if (mask) {
330
+ for (const key in mask) {
331
+ if (!(key in oldShape)) {
332
+ throw new Error(`Unrecognized key: "${key}"`);
333
+ }
334
+ if (!mask[key])
335
+ continue;
336
+ shape[key] = Class ? new Class({
337
+ type: "optional",
338
+ innerType: oldShape[key]
339
+ }) : oldShape[key];
340
+ }
341
+ } else {
342
+ for (const key in oldShape) {
343
+ shape[key] = Class ? new Class({
344
+ type: "optional",
345
+ innerType: oldShape[key]
346
+ }) : oldShape[key];
347
+ }
348
+ }
349
+ assignProp(this, "shape", shape);
350
+ return shape;
351
+ },
352
+ checks: []
353
+ });
354
+ return clone(schema, def);
355
+ }
356
+ function required(Class, schema, mask) {
357
+ const def = mergeDefs(schema._zod.def, {
358
+ get shape() {
359
+ const oldShape = schema._zod.def.shape;
360
+ const shape = { ...oldShape };
361
+ if (mask) {
362
+ for (const key in mask) {
363
+ if (!(key in shape)) {
364
+ throw new Error(`Unrecognized key: "${key}"`);
365
+ }
366
+ if (!mask[key])
367
+ continue;
368
+ shape[key] = new Class({
369
+ type: "nonoptional",
370
+ innerType: oldShape[key]
371
+ });
372
+ }
373
+ } else {
374
+ for (const key in oldShape) {
375
+ shape[key] = new Class({
376
+ type: "nonoptional",
377
+ innerType: oldShape[key]
378
+ });
379
+ }
380
+ }
381
+ assignProp(this, "shape", shape);
382
+ return shape;
383
+ },
384
+ checks: []
385
+ });
386
+ return clone(schema, def);
387
+ }
388
+ function aborted(x, startIndex = 0) {
389
+ if (x.aborted === true)
390
+ return true;
391
+ for (let i = startIndex; i < x.issues.length; i++) {
392
+ if (x.issues[i]?.continue !== true) {
393
+ return true;
394
+ }
395
+ }
396
+ return false;
397
+ }
398
+ function prefixIssues(path, issues) {
399
+ return issues.map((iss) => {
400
+ var _a2;
401
+ (_a2 = iss).path ?? (_a2.path = []);
402
+ iss.path.unshift(path);
403
+ return iss;
404
+ });
405
+ }
406
+ function unwrapMessage(message) {
407
+ return typeof message === "string" ? message : message?.message;
408
+ }
409
+ function finalizeIssue(iss, ctx, config2) {
410
+ const full = { ...iss, path: iss.path ?? [] };
411
+ if (!iss.message) {
412
+ const message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config2.customError?.(iss)) ?? unwrapMessage(config2.localeError?.(iss)) ?? "Invalid input";
413
+ full.message = message;
414
+ }
415
+ delete full.inst;
416
+ delete full.continue;
417
+ if (!ctx?.reportInput) {
418
+ delete full.input;
419
+ }
420
+ return full;
421
+ }
422
+ function getLengthableOrigin(input) {
423
+ if (Array.isArray(input))
424
+ return "array";
425
+ if (typeof input === "string")
426
+ return "string";
427
+ return "unknown";
428
+ }
429
+ function issue(...args) {
430
+ const [iss, input, inst] = args;
431
+ if (typeof iss === "string") {
432
+ return {
433
+ message: iss,
434
+ code: "custom",
435
+ input,
436
+ inst
437
+ };
438
+ }
439
+ return { ...iss };
440
+ }
441
+ const initializer$1 = (inst, def) => {
442
+ inst.name = "$ZodError";
443
+ Object.defineProperty(inst, "_zod", {
444
+ value: inst._zod,
445
+ enumerable: false
446
+ });
447
+ Object.defineProperty(inst, "issues", {
448
+ value: def,
449
+ enumerable: false
450
+ });
451
+ inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
452
+ Object.defineProperty(inst, "toString", {
453
+ value: () => inst.message,
454
+ enumerable: false
455
+ });
456
+ };
457
+ const $ZodError = $constructor("$ZodError", initializer$1);
458
+ const $ZodRealError = $constructor("$ZodError", initializer$1, { Parent: Error });
459
+ function flattenError(error, mapper = (issue2) => issue2.message) {
460
+ const fieldErrors = {};
461
+ const formErrors = [];
462
+ for (const sub of error.issues) {
463
+ if (sub.path.length > 0) {
464
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
465
+ fieldErrors[sub.path[0]].push(mapper(sub));
466
+ } else {
467
+ formErrors.push(mapper(sub));
468
+ }
469
+ }
470
+ return { formErrors, fieldErrors };
471
+ }
472
+ function formatError(error, mapper = (issue2) => issue2.message) {
473
+ const fieldErrors = { _errors: [] };
474
+ const processError = (error2) => {
475
+ for (const issue2 of error2.issues) {
476
+ if (issue2.code === "invalid_union" && issue2.errors.length) {
477
+ issue2.errors.map((issues) => processError({ issues }));
478
+ } else if (issue2.code === "invalid_key") {
479
+ processError({ issues: issue2.issues });
480
+ } else if (issue2.code === "invalid_element") {
481
+ processError({ issues: issue2.issues });
482
+ } else if (issue2.path.length === 0) {
483
+ fieldErrors._errors.push(mapper(issue2));
484
+ } else {
485
+ let curr = fieldErrors;
486
+ let i = 0;
487
+ while (i < issue2.path.length) {
488
+ const el = issue2.path[i];
489
+ const terminal = i === issue2.path.length - 1;
490
+ if (!terminal) {
491
+ curr[el] = curr[el] || { _errors: [] };
492
+ } else {
493
+ curr[el] = curr[el] || { _errors: [] };
494
+ curr[el]._errors.push(mapper(issue2));
495
+ }
496
+ curr = curr[el];
497
+ i++;
498
+ }
499
+ }
500
+ }
501
+ };
502
+ processError(error);
503
+ return fieldErrors;
504
+ }
505
+ const _parse = (_Err) => (schema, value, _ctx, _params) => {
506
+ const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
507
+ const result = schema._zod.run({ value, issues: [] }, ctx);
508
+ if (result instanceof Promise) {
509
+ throw new $ZodAsyncError();
510
+ }
511
+ if (result.issues.length) {
512
+ const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
513
+ captureStackTrace(e, _params?.callee);
514
+ throw e;
515
+ }
516
+ return result.value;
517
+ };
518
+ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
519
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
520
+ let result = schema._zod.run({ value, issues: [] }, ctx);
521
+ if (result instanceof Promise)
522
+ result = await result;
523
+ if (result.issues.length) {
524
+ const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
525
+ captureStackTrace(e, params?.callee);
526
+ throw e;
527
+ }
528
+ return result.value;
529
+ };
530
+ const _safeParse = (_Err) => (schema, value, _ctx) => {
531
+ const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
532
+ const result = schema._zod.run({ value, issues: [] }, ctx);
533
+ if (result instanceof Promise) {
534
+ throw new $ZodAsyncError();
535
+ }
536
+ return result.issues.length ? {
537
+ success: false,
538
+ error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
539
+ } : { success: true, data: result.value };
540
+ };
541
+ const safeParse$1 = /* @__PURE__ */ _safeParse($ZodRealError);
542
+ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
543
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
544
+ let result = schema._zod.run({ value, issues: [] }, ctx);
545
+ if (result instanceof Promise)
546
+ result = await result;
547
+ return result.issues.length ? {
548
+ success: false,
549
+ error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
550
+ } : { success: true, data: result.value };
551
+ };
552
+ const safeParseAsync$1 = /* @__PURE__ */ _safeParseAsync($ZodRealError);
553
+ const _encode = (_Err) => (schema, value, _ctx) => {
554
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
555
+ return _parse(_Err)(schema, value, ctx);
556
+ };
557
+ const _decode = (_Err) => (schema, value, _ctx) => {
558
+ return _parse(_Err)(schema, value, _ctx);
559
+ };
560
+ const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
561
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
562
+ return _parseAsync(_Err)(schema, value, ctx);
563
+ };
564
+ const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
565
+ return _parseAsync(_Err)(schema, value, _ctx);
566
+ };
567
+ const _safeEncode = (_Err) => (schema, value, _ctx) => {
568
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
569
+ return _safeParse(_Err)(schema, value, ctx);
570
+ };
571
+ const _safeDecode = (_Err) => (schema, value, _ctx) => {
572
+ return _safeParse(_Err)(schema, value, _ctx);
573
+ };
574
+ const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
575
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
576
+ return _safeParseAsync(_Err)(schema, value, ctx);
577
+ };
578
+ const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
579
+ return _safeParseAsync(_Err)(schema, value, _ctx);
580
+ };
581
+ const cuid = /^[cC][^\s-]{8,}$/;
582
+ const cuid2 = /^[0-9a-z]+$/;
583
+ const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
584
+ const xid = /^[0-9a-vA-V]{20}$/;
585
+ const ksuid = /^[A-Za-z0-9]{27}$/;
586
+ const nanoid = /^[a-zA-Z0-9_-]{21}$/;
587
+ const duration$1 = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
588
+ const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
589
+ const uuid = (version2) => {
590
+ if (!version2)
591
+ return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
592
+ return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version2}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
593
+ };
594
+ const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
595
+ const _emoji$1 = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
596
+ function emoji() {
597
+ return new RegExp(_emoji$1, "u");
598
+ }
599
+ const ipv4 = /^(?:(?: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])$/;
600
+ const ipv6 = /^(([0-9a-fA-F]{1,4}:){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}|:))$/;
601
+ const cidrv4 = /^((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])\/([0-9]|[1-2][0-9]|3[0-2])$/;
602
+ const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
603
+ const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
604
+ const base64url = /^[A-Za-z0-9_-]*$/;
605
+ const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
606
+ const dateSource = `(?:(?:\\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])))`;
607
+ const date$1 = /* @__PURE__ */ new RegExp(`^${dateSource}$`);
608
+ function timeSource(args) {
609
+ const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
610
+ const regex = typeof args.precision === "number" ? args.precision === -1 ? `${hhmm}` : args.precision === 0 ? `${hhmm}:[0-5]\\d` : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}` : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
611
+ return regex;
612
+ }
613
+ function time$1(args) {
614
+ return new RegExp(`^${timeSource(args)}$`);
615
+ }
616
+ function datetime$1(args) {
617
+ const time2 = timeSource({ precision: args.precision });
618
+ const opts = ["Z"];
619
+ if (args.local)
620
+ opts.push("");
621
+ if (args.offset)
622
+ opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
623
+ const timeRegex = `${time2}(?:${opts.join("|")})`;
624
+ return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
625
+ }
626
+ const string$1 = (params) => {
627
+ const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
628
+ return new RegExp(`^${regex}$`);
629
+ };
630
+ const integer = /^-?\d+$/;
631
+ const number$1 = /^-?\d+(?:\.\d+)?/;
632
+ const boolean$1 = /^(?:true|false)$/i;
633
+ const lowercase = /^[^A-Z]*$/;
634
+ const uppercase = /^[^a-z]*$/;
635
+ const $ZodCheck = /* @__PURE__ */ $constructor("$ZodCheck", (inst, def) => {
636
+ var _a2;
637
+ inst._zod ?? (inst._zod = {});
638
+ inst._zod.def = def;
639
+ (_a2 = inst._zod).onattach ?? (_a2.onattach = []);
640
+ });
641
+ const numericOriginMap = {
642
+ number: "number",
643
+ bigint: "bigint",
644
+ object: "date"
645
+ };
646
+ const $ZodCheckLessThan = /* @__PURE__ */ $constructor("$ZodCheckLessThan", (inst, def) => {
647
+ $ZodCheck.init(inst, def);
648
+ const origin = numericOriginMap[typeof def.value];
649
+ inst._zod.onattach.push((inst2) => {
650
+ const bag = inst2._zod.bag;
651
+ const curr = (def.inclusive ? bag.maximum : bag.exclusiveMaximum) ?? Number.POSITIVE_INFINITY;
652
+ if (def.value < curr) {
653
+ if (def.inclusive)
654
+ bag.maximum = def.value;
655
+ else
656
+ bag.exclusiveMaximum = def.value;
657
+ }
658
+ });
659
+ inst._zod.check = (payload) => {
660
+ if (def.inclusive ? payload.value <= def.value : payload.value < def.value) {
661
+ return;
662
+ }
663
+ payload.issues.push({
664
+ origin,
665
+ code: "too_big",
666
+ maximum: def.value,
667
+ input: payload.value,
668
+ inclusive: def.inclusive,
669
+ inst,
670
+ continue: !def.abort
671
+ });
672
+ };
673
+ });
674
+ const $ZodCheckGreaterThan = /* @__PURE__ */ $constructor("$ZodCheckGreaterThan", (inst, def) => {
675
+ $ZodCheck.init(inst, def);
676
+ const origin = numericOriginMap[typeof def.value];
677
+ inst._zod.onattach.push((inst2) => {
678
+ const bag = inst2._zod.bag;
679
+ const curr = (def.inclusive ? bag.minimum : bag.exclusiveMinimum) ?? Number.NEGATIVE_INFINITY;
680
+ if (def.value > curr) {
681
+ if (def.inclusive)
682
+ bag.minimum = def.value;
683
+ else
684
+ bag.exclusiveMinimum = def.value;
685
+ }
686
+ });
687
+ inst._zod.check = (payload) => {
688
+ if (def.inclusive ? payload.value >= def.value : payload.value > def.value) {
689
+ return;
690
+ }
691
+ payload.issues.push({
692
+ origin,
693
+ code: "too_small",
694
+ minimum: def.value,
695
+ input: payload.value,
696
+ inclusive: def.inclusive,
697
+ inst,
698
+ continue: !def.abort
699
+ });
700
+ };
701
+ });
702
+ const $ZodCheckMultipleOf = /* @__PURE__ */ $constructor("$ZodCheckMultipleOf", (inst, def) => {
703
+ $ZodCheck.init(inst, def);
704
+ inst._zod.onattach.push((inst2) => {
705
+ var _a2;
706
+ (_a2 = inst2._zod.bag).multipleOf ?? (_a2.multipleOf = def.value);
707
+ });
708
+ inst._zod.check = (payload) => {
709
+ if (typeof payload.value !== typeof def.value)
710
+ throw new Error("Cannot mix number and bigint in multiple_of check.");
711
+ const isMultiple = typeof payload.value === "bigint" ? payload.value % def.value === BigInt(0) : floatSafeRemainder(payload.value, def.value) === 0;
712
+ if (isMultiple)
713
+ return;
714
+ payload.issues.push({
715
+ origin: typeof payload.value,
716
+ code: "not_multiple_of",
717
+ divisor: def.value,
718
+ input: payload.value,
719
+ inst,
720
+ continue: !def.abort
721
+ });
722
+ };
723
+ });
724
+ const $ZodCheckNumberFormat = /* @__PURE__ */ $constructor("$ZodCheckNumberFormat", (inst, def) => {
725
+ $ZodCheck.init(inst, def);
726
+ def.format = def.format || "float64";
727
+ const isInt = def.format?.includes("int");
728
+ const origin = isInt ? "int" : "number";
729
+ const [minimum, maximum] = NUMBER_FORMAT_RANGES[def.format];
730
+ inst._zod.onattach.push((inst2) => {
731
+ const bag = inst2._zod.bag;
732
+ bag.format = def.format;
733
+ bag.minimum = minimum;
734
+ bag.maximum = maximum;
735
+ if (isInt)
736
+ bag.pattern = integer;
737
+ });
738
+ inst._zod.check = (payload) => {
739
+ const input = payload.value;
740
+ if (isInt) {
741
+ if (!Number.isInteger(input)) {
742
+ payload.issues.push({
743
+ expected: origin,
744
+ format: def.format,
745
+ code: "invalid_type",
746
+ continue: false,
747
+ input,
748
+ inst
749
+ });
750
+ return;
751
+ }
752
+ if (!Number.isSafeInteger(input)) {
753
+ if (input > 0) {
754
+ payload.issues.push({
755
+ input,
756
+ code: "too_big",
757
+ maximum: Number.MAX_SAFE_INTEGER,
758
+ note: "Integers must be within the safe integer range.",
759
+ inst,
760
+ origin,
761
+ continue: !def.abort
762
+ });
763
+ } else {
764
+ payload.issues.push({
765
+ input,
766
+ code: "too_small",
767
+ minimum: Number.MIN_SAFE_INTEGER,
768
+ note: "Integers must be within the safe integer range.",
769
+ inst,
770
+ origin,
771
+ continue: !def.abort
772
+ });
773
+ }
774
+ return;
775
+ }
776
+ }
777
+ if (input < minimum) {
778
+ payload.issues.push({
779
+ origin: "number",
780
+ input,
781
+ code: "too_small",
782
+ minimum,
783
+ inclusive: true,
784
+ inst,
785
+ continue: !def.abort
786
+ });
787
+ }
788
+ if (input > maximum) {
789
+ payload.issues.push({
790
+ origin: "number",
791
+ input,
792
+ code: "too_big",
793
+ maximum,
794
+ inst
795
+ });
796
+ }
797
+ };
798
+ });
799
+ const $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (inst, def) => {
800
+ var _a2;
801
+ $ZodCheck.init(inst, def);
802
+ (_a2 = inst._zod.def).when ?? (_a2.when = (payload) => {
803
+ const val = payload.value;
804
+ return !nullish(val) && val.length !== void 0;
805
+ });
806
+ inst._zod.onattach.push((inst2) => {
807
+ const curr = inst2._zod.bag.maximum ?? Number.POSITIVE_INFINITY;
808
+ if (def.maximum < curr)
809
+ inst2._zod.bag.maximum = def.maximum;
810
+ });
811
+ inst._zod.check = (payload) => {
812
+ const input = payload.value;
813
+ const length = input.length;
814
+ if (length <= def.maximum)
815
+ return;
816
+ const origin = getLengthableOrigin(input);
817
+ payload.issues.push({
818
+ origin,
819
+ code: "too_big",
820
+ maximum: def.maximum,
821
+ inclusive: true,
822
+ input,
823
+ inst,
824
+ continue: !def.abort
825
+ });
826
+ };
827
+ });
828
+ const $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (inst, def) => {
829
+ var _a2;
830
+ $ZodCheck.init(inst, def);
831
+ (_a2 = inst._zod.def).when ?? (_a2.when = (payload) => {
832
+ const val = payload.value;
833
+ return !nullish(val) && val.length !== void 0;
834
+ });
835
+ inst._zod.onattach.push((inst2) => {
836
+ const curr = inst2._zod.bag.minimum ?? Number.NEGATIVE_INFINITY;
837
+ if (def.minimum > curr)
838
+ inst2._zod.bag.minimum = def.minimum;
839
+ });
840
+ inst._zod.check = (payload) => {
841
+ const input = payload.value;
842
+ const length = input.length;
843
+ if (length >= def.minimum)
844
+ return;
845
+ const origin = getLengthableOrigin(input);
846
+ payload.issues.push({
847
+ origin,
848
+ code: "too_small",
849
+ minimum: def.minimum,
850
+ inclusive: true,
851
+ input,
852
+ inst,
853
+ continue: !def.abort
854
+ });
855
+ };
856
+ });
857
+ const $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEquals", (inst, def) => {
858
+ var _a2;
859
+ $ZodCheck.init(inst, def);
860
+ (_a2 = inst._zod.def).when ?? (_a2.when = (payload) => {
861
+ const val = payload.value;
862
+ return !nullish(val) && val.length !== void 0;
863
+ });
864
+ inst._zod.onattach.push((inst2) => {
865
+ const bag = inst2._zod.bag;
866
+ bag.minimum = def.length;
867
+ bag.maximum = def.length;
868
+ bag.length = def.length;
869
+ });
870
+ inst._zod.check = (payload) => {
871
+ const input = payload.value;
872
+ const length = input.length;
873
+ if (length === def.length)
874
+ return;
875
+ const origin = getLengthableOrigin(input);
876
+ const tooBig = length > def.length;
877
+ payload.issues.push({
878
+ origin,
879
+ ...tooBig ? { code: "too_big", maximum: def.length } : { code: "too_small", minimum: def.length },
880
+ inclusive: true,
881
+ exact: true,
882
+ input: payload.value,
883
+ inst,
884
+ continue: !def.abort
885
+ });
886
+ };
887
+ });
888
+ const $ZodCheckStringFormat = /* @__PURE__ */ $constructor("$ZodCheckStringFormat", (inst, def) => {
889
+ var _a2, _b;
890
+ $ZodCheck.init(inst, def);
891
+ inst._zod.onattach.push((inst2) => {
892
+ const bag = inst2._zod.bag;
893
+ bag.format = def.format;
894
+ if (def.pattern) {
895
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
896
+ bag.patterns.add(def.pattern);
897
+ }
898
+ });
899
+ if (def.pattern)
900
+ (_a2 = inst._zod).check ?? (_a2.check = (payload) => {
901
+ def.pattern.lastIndex = 0;
902
+ if (def.pattern.test(payload.value))
903
+ return;
904
+ payload.issues.push({
905
+ origin: "string",
906
+ code: "invalid_format",
907
+ format: def.format,
908
+ input: payload.value,
909
+ ...def.pattern ? { pattern: def.pattern.toString() } : {},
910
+ inst,
911
+ continue: !def.abort
912
+ });
913
+ });
914
+ else
915
+ (_b = inst._zod).check ?? (_b.check = () => {
916
+ });
917
+ });
918
+ const $ZodCheckRegex = /* @__PURE__ */ $constructor("$ZodCheckRegex", (inst, def) => {
919
+ $ZodCheckStringFormat.init(inst, def);
920
+ inst._zod.check = (payload) => {
921
+ def.pattern.lastIndex = 0;
922
+ if (def.pattern.test(payload.value))
923
+ return;
924
+ payload.issues.push({
925
+ origin: "string",
926
+ code: "invalid_format",
927
+ format: "regex",
928
+ input: payload.value,
929
+ pattern: def.pattern.toString(),
930
+ inst,
931
+ continue: !def.abort
932
+ });
933
+ };
934
+ });
935
+ const $ZodCheckLowerCase = /* @__PURE__ */ $constructor("$ZodCheckLowerCase", (inst, def) => {
936
+ def.pattern ?? (def.pattern = lowercase);
937
+ $ZodCheckStringFormat.init(inst, def);
938
+ });
939
+ const $ZodCheckUpperCase = /* @__PURE__ */ $constructor("$ZodCheckUpperCase", (inst, def) => {
940
+ def.pattern ?? (def.pattern = uppercase);
941
+ $ZodCheckStringFormat.init(inst, def);
942
+ });
943
+ const $ZodCheckIncludes = /* @__PURE__ */ $constructor("$ZodCheckIncludes", (inst, def) => {
944
+ $ZodCheck.init(inst, def);
945
+ const escapedRegex = escapeRegex(def.includes);
946
+ const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
947
+ def.pattern = pattern;
948
+ inst._zod.onattach.push((inst2) => {
949
+ const bag = inst2._zod.bag;
950
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
951
+ bag.patterns.add(pattern);
952
+ });
953
+ inst._zod.check = (payload) => {
954
+ if (payload.value.includes(def.includes, def.position))
955
+ return;
956
+ payload.issues.push({
957
+ origin: "string",
958
+ code: "invalid_format",
959
+ format: "includes",
960
+ includes: def.includes,
961
+ input: payload.value,
962
+ inst,
963
+ continue: !def.abort
964
+ });
965
+ };
966
+ });
967
+ const $ZodCheckStartsWith = /* @__PURE__ */ $constructor("$ZodCheckStartsWith", (inst, def) => {
968
+ $ZodCheck.init(inst, def);
969
+ const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
970
+ def.pattern ?? (def.pattern = pattern);
971
+ inst._zod.onattach.push((inst2) => {
972
+ const bag = inst2._zod.bag;
973
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
974
+ bag.patterns.add(pattern);
975
+ });
976
+ inst._zod.check = (payload) => {
977
+ if (payload.value.startsWith(def.prefix))
978
+ return;
979
+ payload.issues.push({
980
+ origin: "string",
981
+ code: "invalid_format",
982
+ format: "starts_with",
983
+ prefix: def.prefix,
984
+ input: payload.value,
985
+ inst,
986
+ continue: !def.abort
987
+ });
988
+ };
989
+ });
990
+ const $ZodCheckEndsWith = /* @__PURE__ */ $constructor("$ZodCheckEndsWith", (inst, def) => {
991
+ $ZodCheck.init(inst, def);
992
+ const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
993
+ def.pattern ?? (def.pattern = pattern);
994
+ inst._zod.onattach.push((inst2) => {
995
+ const bag = inst2._zod.bag;
996
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
997
+ bag.patterns.add(pattern);
998
+ });
999
+ inst._zod.check = (payload) => {
1000
+ if (payload.value.endsWith(def.suffix))
1001
+ return;
1002
+ payload.issues.push({
1003
+ origin: "string",
1004
+ code: "invalid_format",
1005
+ format: "ends_with",
1006
+ suffix: def.suffix,
1007
+ input: payload.value,
1008
+ inst,
1009
+ continue: !def.abort
1010
+ });
1011
+ };
1012
+ });
1013
+ const $ZodCheckOverwrite = /* @__PURE__ */ $constructor("$ZodCheckOverwrite", (inst, def) => {
1014
+ $ZodCheck.init(inst, def);
1015
+ inst._zod.check = (payload) => {
1016
+ payload.value = def.tx(payload.value);
1017
+ };
1018
+ });
1019
+ class Doc {
1020
+ constructor(args = []) {
1021
+ this.content = [];
1022
+ this.indent = 0;
1023
+ if (this)
1024
+ this.args = args;
1025
+ }
1026
+ indented(fn) {
1027
+ this.indent += 1;
1028
+ fn(this);
1029
+ this.indent -= 1;
1030
+ }
1031
+ write(arg) {
1032
+ if (typeof arg === "function") {
1033
+ arg(this, { execution: "sync" });
1034
+ arg(this, { execution: "async" });
1035
+ return;
1036
+ }
1037
+ const content = arg;
1038
+ const lines = content.split("\n").filter((x) => x);
1039
+ const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
1040
+ const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
1041
+ for (const line of dedented) {
1042
+ this.content.push(line);
1043
+ }
1044
+ }
1045
+ compile() {
1046
+ const F = Function;
1047
+ const args = this?.args;
1048
+ const content = this?.content ?? [``];
1049
+ const lines = [...content.map((x) => ` ${x}`)];
1050
+ return new F(...args, lines.join("\n"));
1051
+ }
1052
+ }
1053
+ const version = {
1054
+ major: 4,
1055
+ minor: 1,
1056
+ patch: 13
1057
+ };
1058
+ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
1059
+ var _a2;
1060
+ inst ?? (inst = {});
1061
+ inst._zod.def = def;
1062
+ inst._zod.bag = inst._zod.bag || {};
1063
+ inst._zod.version = version;
1064
+ const checks = [...inst._zod.def.checks ?? []];
1065
+ if (inst._zod.traits.has("$ZodCheck")) {
1066
+ checks.unshift(inst);
1067
+ }
1068
+ for (const ch of checks) {
1069
+ for (const fn of ch._zod.onattach) {
1070
+ fn(inst);
1071
+ }
1072
+ }
1073
+ if (checks.length === 0) {
1074
+ (_a2 = inst._zod).deferred ?? (_a2.deferred = []);
1075
+ inst._zod.deferred?.push(() => {
1076
+ inst._zod.run = inst._zod.parse;
1077
+ });
1078
+ } else {
1079
+ const runChecks = (payload, checks2, ctx) => {
1080
+ let isAborted = aborted(payload);
1081
+ let asyncResult;
1082
+ for (const ch of checks2) {
1083
+ if (ch._zod.def.when) {
1084
+ const shouldRun = ch._zod.def.when(payload);
1085
+ if (!shouldRun)
1086
+ continue;
1087
+ } else if (isAborted) {
1088
+ continue;
1089
+ }
1090
+ const currLen = payload.issues.length;
1091
+ const _ = ch._zod.check(payload);
1092
+ if (_ instanceof Promise && ctx?.async === false) {
1093
+ throw new $ZodAsyncError();
1094
+ }
1095
+ if (asyncResult || _ instanceof Promise) {
1096
+ asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
1097
+ await _;
1098
+ const nextLen = payload.issues.length;
1099
+ if (nextLen === currLen)
1100
+ return;
1101
+ if (!isAborted)
1102
+ isAborted = aborted(payload, currLen);
1103
+ });
1104
+ } else {
1105
+ const nextLen = payload.issues.length;
1106
+ if (nextLen === currLen)
1107
+ continue;
1108
+ if (!isAborted)
1109
+ isAborted = aborted(payload, currLen);
1110
+ }
1111
+ }
1112
+ if (asyncResult) {
1113
+ return asyncResult.then(() => {
1114
+ return payload;
1115
+ });
1116
+ }
1117
+ return payload;
1118
+ };
1119
+ const handleCanaryResult = (canary, payload, ctx) => {
1120
+ if (aborted(canary)) {
1121
+ canary.aborted = true;
1122
+ return canary;
1123
+ }
1124
+ const checkResult = runChecks(payload, checks, ctx);
1125
+ if (checkResult instanceof Promise) {
1126
+ if (ctx.async === false)
1127
+ throw new $ZodAsyncError();
1128
+ return checkResult.then((checkResult2) => inst._zod.parse(checkResult2, ctx));
1129
+ }
1130
+ return inst._zod.parse(checkResult, ctx);
1131
+ };
1132
+ inst._zod.run = (payload, ctx) => {
1133
+ if (ctx.skipChecks) {
1134
+ return inst._zod.parse(payload, ctx);
1135
+ }
1136
+ if (ctx.direction === "backward") {
1137
+ const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
1138
+ if (canary instanceof Promise) {
1139
+ return canary.then((canary2) => {
1140
+ return handleCanaryResult(canary2, payload, ctx);
1141
+ });
1142
+ }
1143
+ return handleCanaryResult(canary, payload, ctx);
1144
+ }
1145
+ const result = inst._zod.parse(payload, ctx);
1146
+ if (result instanceof Promise) {
1147
+ if (ctx.async === false)
1148
+ throw new $ZodAsyncError();
1149
+ return result.then((result2) => runChecks(result2, checks, ctx));
1150
+ }
1151
+ return runChecks(result, checks, ctx);
1152
+ };
1153
+ }
1154
+ inst["~standard"] = {
1155
+ validate: (value) => {
1156
+ try {
1157
+ const r = safeParse$1(inst, value);
1158
+ return r.success ? { value: r.data } : { issues: r.error?.issues };
1159
+ } catch (_) {
1160
+ return safeParseAsync$1(inst, value).then((r) => r.success ? { value: r.data } : { issues: r.error?.issues });
1161
+ }
1162
+ },
1163
+ vendor: "zod",
1164
+ version: 1
1165
+ };
1166
+ });
1167
+ const $ZodString = /* @__PURE__ */ $constructor("$ZodString", (inst, def) => {
1168
+ $ZodType.init(inst, def);
1169
+ inst._zod.pattern = [...inst?._zod.bag?.patterns ?? []].pop() ?? string$1(inst._zod.bag);
1170
+ inst._zod.parse = (payload, _) => {
1171
+ if (def.coerce)
1172
+ try {
1173
+ payload.value = String(payload.value);
1174
+ } catch (_2) {
1175
+ }
1176
+ if (typeof payload.value === "string")
1177
+ return payload;
1178
+ payload.issues.push({
1179
+ expected: "string",
1180
+ code: "invalid_type",
1181
+ input: payload.value,
1182
+ inst
1183
+ });
1184
+ return payload;
1185
+ };
1186
+ });
1187
+ const $ZodStringFormat = /* @__PURE__ */ $constructor("$ZodStringFormat", (inst, def) => {
1188
+ $ZodCheckStringFormat.init(inst, def);
1189
+ $ZodString.init(inst, def);
1190
+ });
1191
+ const $ZodGUID = /* @__PURE__ */ $constructor("$ZodGUID", (inst, def) => {
1192
+ def.pattern ?? (def.pattern = guid);
1193
+ $ZodStringFormat.init(inst, def);
1194
+ });
1195
+ const $ZodUUID = /* @__PURE__ */ $constructor("$ZodUUID", (inst, def) => {
1196
+ if (def.version) {
1197
+ const versionMap = {
1198
+ v1: 1,
1199
+ v2: 2,
1200
+ v3: 3,
1201
+ v4: 4,
1202
+ v5: 5,
1203
+ v6: 6,
1204
+ v7: 7,
1205
+ v8: 8
1206
+ };
1207
+ const v = versionMap[def.version];
1208
+ if (v === void 0)
1209
+ throw new Error(`Invalid UUID version: "${def.version}"`);
1210
+ def.pattern ?? (def.pattern = uuid(v));
1211
+ } else
1212
+ def.pattern ?? (def.pattern = uuid());
1213
+ $ZodStringFormat.init(inst, def);
1214
+ });
1215
+ const $ZodEmail = /* @__PURE__ */ $constructor("$ZodEmail", (inst, def) => {
1216
+ def.pattern ?? (def.pattern = email);
1217
+ $ZodStringFormat.init(inst, def);
1218
+ });
1219
+ const $ZodURL = /* @__PURE__ */ $constructor("$ZodURL", (inst, def) => {
1220
+ $ZodStringFormat.init(inst, def);
1221
+ inst._zod.check = (payload) => {
1222
+ try {
1223
+ const trimmed = payload.value.trim();
1224
+ const url = new URL(trimmed);
1225
+ if (def.hostname) {
1226
+ def.hostname.lastIndex = 0;
1227
+ if (!def.hostname.test(url.hostname)) {
1228
+ payload.issues.push({
1229
+ code: "invalid_format",
1230
+ format: "url",
1231
+ note: "Invalid hostname",
1232
+ pattern: def.hostname.source,
1233
+ input: payload.value,
1234
+ inst,
1235
+ continue: !def.abort
1236
+ });
1237
+ }
1238
+ }
1239
+ if (def.protocol) {
1240
+ def.protocol.lastIndex = 0;
1241
+ if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) {
1242
+ payload.issues.push({
1243
+ code: "invalid_format",
1244
+ format: "url",
1245
+ note: "Invalid protocol",
1246
+ pattern: def.protocol.source,
1247
+ input: payload.value,
1248
+ inst,
1249
+ continue: !def.abort
1250
+ });
1251
+ }
1252
+ }
1253
+ if (def.normalize) {
1254
+ payload.value = url.href;
1255
+ } else {
1256
+ payload.value = trimmed;
1257
+ }
1258
+ return;
1259
+ } catch (_) {
1260
+ payload.issues.push({
1261
+ code: "invalid_format",
1262
+ format: "url",
1263
+ input: payload.value,
1264
+ inst,
1265
+ continue: !def.abort
1266
+ });
1267
+ }
1268
+ };
1269
+ });
1270
+ const $ZodEmoji = /* @__PURE__ */ $constructor("$ZodEmoji", (inst, def) => {
1271
+ def.pattern ?? (def.pattern = emoji());
1272
+ $ZodStringFormat.init(inst, def);
1273
+ });
1274
+ const $ZodNanoID = /* @__PURE__ */ $constructor("$ZodNanoID", (inst, def) => {
1275
+ def.pattern ?? (def.pattern = nanoid);
1276
+ $ZodStringFormat.init(inst, def);
1277
+ });
1278
+ const $ZodCUID = /* @__PURE__ */ $constructor("$ZodCUID", (inst, def) => {
1279
+ def.pattern ?? (def.pattern = cuid);
1280
+ $ZodStringFormat.init(inst, def);
1281
+ });
1282
+ const $ZodCUID2 = /* @__PURE__ */ $constructor("$ZodCUID2", (inst, def) => {
1283
+ def.pattern ?? (def.pattern = cuid2);
1284
+ $ZodStringFormat.init(inst, def);
1285
+ });
1286
+ const $ZodULID = /* @__PURE__ */ $constructor("$ZodULID", (inst, def) => {
1287
+ def.pattern ?? (def.pattern = ulid);
1288
+ $ZodStringFormat.init(inst, def);
1289
+ });
1290
+ const $ZodXID = /* @__PURE__ */ $constructor("$ZodXID", (inst, def) => {
1291
+ def.pattern ?? (def.pattern = xid);
1292
+ $ZodStringFormat.init(inst, def);
1293
+ });
1294
+ const $ZodKSUID = /* @__PURE__ */ $constructor("$ZodKSUID", (inst, def) => {
1295
+ def.pattern ?? (def.pattern = ksuid);
1296
+ $ZodStringFormat.init(inst, def);
1297
+ });
1298
+ const $ZodISODateTime = /* @__PURE__ */ $constructor("$ZodISODateTime", (inst, def) => {
1299
+ def.pattern ?? (def.pattern = datetime$1(def));
1300
+ $ZodStringFormat.init(inst, def);
1301
+ });
1302
+ const $ZodISODate = /* @__PURE__ */ $constructor("$ZodISODate", (inst, def) => {
1303
+ def.pattern ?? (def.pattern = date$1);
1304
+ $ZodStringFormat.init(inst, def);
1305
+ });
1306
+ const $ZodISOTime = /* @__PURE__ */ $constructor("$ZodISOTime", (inst, def) => {
1307
+ def.pattern ?? (def.pattern = time$1(def));
1308
+ $ZodStringFormat.init(inst, def);
1309
+ });
1310
+ const $ZodISODuration = /* @__PURE__ */ $constructor("$ZodISODuration", (inst, def) => {
1311
+ def.pattern ?? (def.pattern = duration$1);
1312
+ $ZodStringFormat.init(inst, def);
1313
+ });
1314
+ const $ZodIPv4 = /* @__PURE__ */ $constructor("$ZodIPv4", (inst, def) => {
1315
+ def.pattern ?? (def.pattern = ipv4);
1316
+ $ZodStringFormat.init(inst, def);
1317
+ inst._zod.bag.format = `ipv4`;
1318
+ });
1319
+ const $ZodIPv6 = /* @__PURE__ */ $constructor("$ZodIPv6", (inst, def) => {
1320
+ def.pattern ?? (def.pattern = ipv6);
1321
+ $ZodStringFormat.init(inst, def);
1322
+ inst._zod.bag.format = `ipv6`;
1323
+ inst._zod.check = (payload) => {
1324
+ try {
1325
+ new URL(`http://[${payload.value}]`);
1326
+ } catch {
1327
+ payload.issues.push({
1328
+ code: "invalid_format",
1329
+ format: "ipv6",
1330
+ input: payload.value,
1331
+ inst,
1332
+ continue: !def.abort
1333
+ });
1334
+ }
1335
+ };
1336
+ });
1337
+ const $ZodCIDRv4 = /* @__PURE__ */ $constructor("$ZodCIDRv4", (inst, def) => {
1338
+ def.pattern ?? (def.pattern = cidrv4);
1339
+ $ZodStringFormat.init(inst, def);
1340
+ });
1341
+ const $ZodCIDRv6 = /* @__PURE__ */ $constructor("$ZodCIDRv6", (inst, def) => {
1342
+ def.pattern ?? (def.pattern = cidrv6);
1343
+ $ZodStringFormat.init(inst, def);
1344
+ inst._zod.check = (payload) => {
1345
+ const parts = payload.value.split("/");
1346
+ try {
1347
+ if (parts.length !== 2)
1348
+ throw new Error();
1349
+ const [address, prefix] = parts;
1350
+ if (!prefix)
1351
+ throw new Error();
1352
+ const prefixNum = Number(prefix);
1353
+ if (`${prefixNum}` !== prefix)
1354
+ throw new Error();
1355
+ if (prefixNum < 0 || prefixNum > 128)
1356
+ throw new Error();
1357
+ new URL(`http://[${address}]`);
1358
+ } catch {
1359
+ payload.issues.push({
1360
+ code: "invalid_format",
1361
+ format: "cidrv6",
1362
+ input: payload.value,
1363
+ inst,
1364
+ continue: !def.abort
1365
+ });
1366
+ }
1367
+ };
1368
+ });
1369
+ function isValidBase64(data) {
1370
+ if (data === "")
1371
+ return true;
1372
+ if (data.length % 4 !== 0)
1373
+ return false;
1374
+ try {
1375
+ atob(data);
1376
+ return true;
1377
+ } catch {
1378
+ return false;
1379
+ }
1380
+ }
1381
+ const $ZodBase64 = /* @__PURE__ */ $constructor("$ZodBase64", (inst, def) => {
1382
+ def.pattern ?? (def.pattern = base64);
1383
+ $ZodStringFormat.init(inst, def);
1384
+ inst._zod.bag.contentEncoding = "base64";
1385
+ inst._zod.check = (payload) => {
1386
+ if (isValidBase64(payload.value))
1387
+ return;
1388
+ payload.issues.push({
1389
+ code: "invalid_format",
1390
+ format: "base64",
1391
+ input: payload.value,
1392
+ inst,
1393
+ continue: !def.abort
1394
+ });
1395
+ };
1396
+ });
1397
+ function isValidBase64URL(data) {
1398
+ if (!base64url.test(data))
1399
+ return false;
1400
+ const base642 = data.replace(/[-_]/g, (c) => c === "-" ? "+" : "/");
1401
+ const padded = base642.padEnd(Math.ceil(base642.length / 4) * 4, "=");
1402
+ return isValidBase64(padded);
1403
+ }
1404
+ const $ZodBase64URL = /* @__PURE__ */ $constructor("$ZodBase64URL", (inst, def) => {
1405
+ def.pattern ?? (def.pattern = base64url);
1406
+ $ZodStringFormat.init(inst, def);
1407
+ inst._zod.bag.contentEncoding = "base64url";
1408
+ inst._zod.check = (payload) => {
1409
+ if (isValidBase64URL(payload.value))
1410
+ return;
1411
+ payload.issues.push({
1412
+ code: "invalid_format",
1413
+ format: "base64url",
1414
+ input: payload.value,
1415
+ inst,
1416
+ continue: !def.abort
1417
+ });
1418
+ };
1419
+ });
1420
+ const $ZodE164 = /* @__PURE__ */ $constructor("$ZodE164", (inst, def) => {
1421
+ def.pattern ?? (def.pattern = e164);
1422
+ $ZodStringFormat.init(inst, def);
1423
+ });
1424
+ function isValidJWT(token, algorithm = null) {
1425
+ try {
1426
+ const tokensParts = token.split(".");
1427
+ if (tokensParts.length !== 3)
1428
+ return false;
1429
+ const [header] = tokensParts;
1430
+ if (!header)
1431
+ return false;
1432
+ const parsedHeader = JSON.parse(atob(header));
1433
+ if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT")
1434
+ return false;
1435
+ if (!parsedHeader.alg)
1436
+ return false;
1437
+ if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm))
1438
+ return false;
1439
+ return true;
1440
+ } catch {
1441
+ return false;
1442
+ }
1443
+ }
1444
+ const $ZodJWT = /* @__PURE__ */ $constructor("$ZodJWT", (inst, def) => {
1445
+ $ZodStringFormat.init(inst, def);
1446
+ inst._zod.check = (payload) => {
1447
+ if (isValidJWT(payload.value, def.alg))
1448
+ return;
1449
+ payload.issues.push({
1450
+ code: "invalid_format",
1451
+ format: "jwt",
1452
+ input: payload.value,
1453
+ inst,
1454
+ continue: !def.abort
1455
+ });
1456
+ };
1457
+ });
1458
+ const $ZodNumber = /* @__PURE__ */ $constructor("$ZodNumber", (inst, def) => {
1459
+ $ZodType.init(inst, def);
1460
+ inst._zod.pattern = inst._zod.bag.pattern ?? number$1;
1461
+ inst._zod.parse = (payload, _ctx) => {
1462
+ if (def.coerce)
1463
+ try {
1464
+ payload.value = Number(payload.value);
1465
+ } catch (_) {
1466
+ }
1467
+ const input = payload.value;
1468
+ if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) {
1469
+ return payload;
1470
+ }
1471
+ const received = typeof input === "number" ? Number.isNaN(input) ? "NaN" : !Number.isFinite(input) ? "Infinity" : void 0 : void 0;
1472
+ payload.issues.push({
1473
+ expected: "number",
1474
+ code: "invalid_type",
1475
+ input,
1476
+ inst,
1477
+ ...received ? { received } : {}
1478
+ });
1479
+ return payload;
1480
+ };
1481
+ });
1482
+ const $ZodNumberFormat = /* @__PURE__ */ $constructor("$ZodNumberFormat", (inst, def) => {
1483
+ $ZodCheckNumberFormat.init(inst, def);
1484
+ $ZodNumber.init(inst, def);
1485
+ });
1486
+ const $ZodBoolean = /* @__PURE__ */ $constructor("$ZodBoolean", (inst, def) => {
1487
+ $ZodType.init(inst, def);
1488
+ inst._zod.pattern = boolean$1;
1489
+ inst._zod.parse = (payload, _ctx) => {
1490
+ if (def.coerce)
1491
+ try {
1492
+ payload.value = Boolean(payload.value);
1493
+ } catch (_) {
1494
+ }
1495
+ const input = payload.value;
1496
+ if (typeof input === "boolean")
1497
+ return payload;
1498
+ payload.issues.push({
1499
+ expected: "boolean",
1500
+ code: "invalid_type",
1501
+ input,
1502
+ inst
1503
+ });
1504
+ return payload;
1505
+ };
1506
+ });
1507
+ const $ZodUnknown = /* @__PURE__ */ $constructor("$ZodUnknown", (inst, def) => {
1508
+ $ZodType.init(inst, def);
1509
+ inst._zod.parse = (payload) => payload;
1510
+ });
1511
+ const $ZodNever = /* @__PURE__ */ $constructor("$ZodNever", (inst, def) => {
1512
+ $ZodType.init(inst, def);
1513
+ inst._zod.parse = (payload, _ctx) => {
1514
+ payload.issues.push({
1515
+ expected: "never",
1516
+ code: "invalid_type",
1517
+ input: payload.value,
1518
+ inst
1519
+ });
1520
+ return payload;
1521
+ };
1522
+ });
1523
+ function handleArrayResult(result, final, index) {
1524
+ if (result.issues.length) {
1525
+ final.issues.push(...prefixIssues(index, result.issues));
1526
+ }
1527
+ final.value[index] = result.value;
1528
+ }
1529
+ const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
1530
+ $ZodType.init(inst, def);
1531
+ inst._zod.parse = (payload, ctx) => {
1532
+ const input = payload.value;
1533
+ if (!Array.isArray(input)) {
1534
+ payload.issues.push({
1535
+ expected: "array",
1536
+ code: "invalid_type",
1537
+ input,
1538
+ inst
1539
+ });
1540
+ return payload;
1541
+ }
1542
+ payload.value = Array(input.length);
1543
+ const proms = [];
1544
+ for (let i = 0; i < input.length; i++) {
1545
+ const item = input[i];
1546
+ const result = def.element._zod.run({
1547
+ value: item,
1548
+ issues: []
1549
+ }, ctx);
1550
+ if (result instanceof Promise) {
1551
+ proms.push(result.then((result2) => handleArrayResult(result2, payload, i)));
1552
+ } else {
1553
+ handleArrayResult(result, payload, i);
1554
+ }
1555
+ }
1556
+ if (proms.length) {
1557
+ return Promise.all(proms).then(() => payload);
1558
+ }
1559
+ return payload;
1560
+ };
1561
+ });
1562
+ function handlePropertyResult(result, final, key, input) {
1563
+ if (result.issues.length) {
1564
+ final.issues.push(...prefixIssues(key, result.issues));
1565
+ }
1566
+ if (result.value === void 0) {
1567
+ if (key in input) {
1568
+ final.value[key] = void 0;
1569
+ }
1570
+ } else {
1571
+ final.value[key] = result.value;
1572
+ }
1573
+ }
1574
+ function normalizeDef(def) {
1575
+ const keys = Object.keys(def.shape);
1576
+ for (const k of keys) {
1577
+ if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
1578
+ throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
1579
+ }
1580
+ }
1581
+ const okeys = optionalKeys(def.shape);
1582
+ return {
1583
+ ...def,
1584
+ keys,
1585
+ keySet: new Set(keys),
1586
+ numKeys: keys.length,
1587
+ optionalKeys: new Set(okeys)
1588
+ };
1589
+ }
1590
+ function handleCatchall(proms, input, payload, ctx, def, inst) {
1591
+ const unrecognized = [];
1592
+ const keySet = def.keySet;
1593
+ const _catchall = def.catchall._zod;
1594
+ const t = _catchall.def.type;
1595
+ for (const key in input) {
1596
+ if (keySet.has(key))
1597
+ continue;
1598
+ if (t === "never") {
1599
+ unrecognized.push(key);
1600
+ continue;
1601
+ }
1602
+ const r = _catchall.run({ value: input[key], issues: [] }, ctx);
1603
+ if (r instanceof Promise) {
1604
+ proms.push(r.then((r2) => handlePropertyResult(r2, payload, key, input)));
1605
+ } else {
1606
+ handlePropertyResult(r, payload, key, input);
1607
+ }
1608
+ }
1609
+ if (unrecognized.length) {
1610
+ payload.issues.push({
1611
+ code: "unrecognized_keys",
1612
+ keys: unrecognized,
1613
+ input,
1614
+ inst
1615
+ });
1616
+ }
1617
+ if (!proms.length)
1618
+ return payload;
1619
+ return Promise.all(proms).then(() => {
1620
+ return payload;
1621
+ });
1622
+ }
1623
+ const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
1624
+ $ZodType.init(inst, def);
1625
+ const desc = Object.getOwnPropertyDescriptor(def, "shape");
1626
+ if (!desc?.get) {
1627
+ const sh = def.shape;
1628
+ Object.defineProperty(def, "shape", {
1629
+ get: () => {
1630
+ const newSh = { ...sh };
1631
+ Object.defineProperty(def, "shape", {
1632
+ value: newSh
1633
+ });
1634
+ return newSh;
1635
+ }
1636
+ });
1637
+ }
1638
+ const _normalized = cached(() => normalizeDef(def));
1639
+ defineLazy(inst._zod, "propValues", () => {
1640
+ const shape = def.shape;
1641
+ const propValues = {};
1642
+ for (const key in shape) {
1643
+ const field = shape[key]._zod;
1644
+ if (field.values) {
1645
+ propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
1646
+ for (const v of field.values)
1647
+ propValues[key].add(v);
1648
+ }
1649
+ }
1650
+ return propValues;
1651
+ });
1652
+ const isObject$1 = isObject;
1653
+ const catchall = def.catchall;
1654
+ let value;
1655
+ inst._zod.parse = (payload, ctx) => {
1656
+ value ?? (value = _normalized.value);
1657
+ const input = payload.value;
1658
+ if (!isObject$1(input)) {
1659
+ payload.issues.push({
1660
+ expected: "object",
1661
+ code: "invalid_type",
1662
+ input,
1663
+ inst
1664
+ });
1665
+ return payload;
1666
+ }
1667
+ payload.value = {};
1668
+ const proms = [];
1669
+ const shape = value.shape;
1670
+ for (const key of value.keys) {
1671
+ const el = shape[key];
1672
+ const r = el._zod.run({ value: input[key], issues: [] }, ctx);
1673
+ if (r instanceof Promise) {
1674
+ proms.push(r.then((r2) => handlePropertyResult(r2, payload, key, input)));
1675
+ } else {
1676
+ handlePropertyResult(r, payload, key, input);
1677
+ }
1678
+ }
1679
+ if (!catchall) {
1680
+ return proms.length ? Promise.all(proms).then(() => payload) : payload;
1681
+ }
1682
+ return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
1683
+ };
1684
+ });
1685
+ const $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) => {
1686
+ $ZodObject.init(inst, def);
1687
+ const superParse = inst._zod.parse;
1688
+ const _normalized = cached(() => normalizeDef(def));
1689
+ const generateFastpass = (shape) => {
1690
+ const doc = new Doc(["shape", "payload", "ctx"]);
1691
+ const normalized = _normalized.value;
1692
+ const parseStr = (key) => {
1693
+ const k = esc(key);
1694
+ return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
1695
+ };
1696
+ doc.write(`const input = payload.value;`);
1697
+ const ids = /* @__PURE__ */ Object.create(null);
1698
+ let counter = 0;
1699
+ for (const key of normalized.keys) {
1700
+ ids[key] = `key_${counter++}`;
1701
+ }
1702
+ doc.write(`const newResult = {};`);
1703
+ for (const key of normalized.keys) {
1704
+ const id = ids[key];
1705
+ const k = esc(key);
1706
+ doc.write(`const ${id} = ${parseStr(key)};`);
1707
+ doc.write(`
1708
+ if (${id}.issues.length) {
1709
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1710
+ ...iss,
1711
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
1712
+ })));
1713
+ }
1714
+
1715
+
1716
+ if (${id}.value === undefined) {
1717
+ if (${k} in input) {
1718
+ newResult[${k}] = undefined;
1719
+ }
1720
+ } else {
1721
+ newResult[${k}] = ${id}.value;
1722
+ }
1723
+
1724
+ `);
1725
+ }
1726
+ doc.write(`payload.value = newResult;`);
1727
+ doc.write(`return payload;`);
1728
+ const fn = doc.compile();
1729
+ return (payload, ctx) => fn(shape, payload, ctx);
1730
+ };
1731
+ let fastpass;
1732
+ const isObject$1 = isObject;
1733
+ const jit = !globalConfig.jitless;
1734
+ const allowsEval$1 = allowsEval;
1735
+ const fastEnabled = jit && allowsEval$1.value;
1736
+ const catchall = def.catchall;
1737
+ let value;
1738
+ inst._zod.parse = (payload, ctx) => {
1739
+ value ?? (value = _normalized.value);
1740
+ const input = payload.value;
1741
+ if (!isObject$1(input)) {
1742
+ payload.issues.push({
1743
+ expected: "object",
1744
+ code: "invalid_type",
1745
+ input,
1746
+ inst
1747
+ });
1748
+ return payload;
1749
+ }
1750
+ if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
1751
+ if (!fastpass)
1752
+ fastpass = generateFastpass(def.shape);
1753
+ payload = fastpass(payload, ctx);
1754
+ if (!catchall)
1755
+ return payload;
1756
+ return handleCatchall([], input, payload, ctx, value, inst);
1757
+ }
1758
+ return superParse(payload, ctx);
1759
+ };
1760
+ });
1761
+ function handleUnionResults(results, final, inst, ctx) {
1762
+ for (const result of results) {
1763
+ if (result.issues.length === 0) {
1764
+ final.value = result.value;
1765
+ return final;
1766
+ }
1767
+ }
1768
+ const nonaborted = results.filter((r) => !aborted(r));
1769
+ if (nonaborted.length === 1) {
1770
+ final.value = nonaborted[0].value;
1771
+ return nonaborted[0];
1772
+ }
1773
+ final.issues.push({
1774
+ code: "invalid_union",
1775
+ input: final.value,
1776
+ inst,
1777
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
1778
+ });
1779
+ return final;
1780
+ }
1781
+ const $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
1782
+ $ZodType.init(inst, def);
1783
+ defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : void 0);
1784
+ defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
1785
+ defineLazy(inst._zod, "values", () => {
1786
+ if (def.options.every((o) => o._zod.values)) {
1787
+ return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
1788
+ }
1789
+ return void 0;
1790
+ });
1791
+ defineLazy(inst._zod, "pattern", () => {
1792
+ if (def.options.every((o) => o._zod.pattern)) {
1793
+ const patterns = def.options.map((o) => o._zod.pattern);
1794
+ return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
1795
+ }
1796
+ return void 0;
1797
+ });
1798
+ const single = def.options.length === 1;
1799
+ const first = def.options[0]._zod.run;
1800
+ inst._zod.parse = (payload, ctx) => {
1801
+ if (single) {
1802
+ return first(payload, ctx);
1803
+ }
1804
+ let async = false;
1805
+ const results = [];
1806
+ for (const option of def.options) {
1807
+ const result = option._zod.run({
1808
+ value: payload.value,
1809
+ issues: []
1810
+ }, ctx);
1811
+ if (result instanceof Promise) {
1812
+ results.push(result);
1813
+ async = true;
1814
+ } else {
1815
+ if (result.issues.length === 0)
1816
+ return result;
1817
+ results.push(result);
1818
+ }
1819
+ }
1820
+ if (!async)
1821
+ return handleUnionResults(results, payload, inst, ctx);
1822
+ return Promise.all(results).then((results2) => {
1823
+ return handleUnionResults(results2, payload, inst, ctx);
1824
+ });
1825
+ };
1826
+ });
1827
+ const $ZodIntersection = /* @__PURE__ */ $constructor("$ZodIntersection", (inst, def) => {
1828
+ $ZodType.init(inst, def);
1829
+ inst._zod.parse = (payload, ctx) => {
1830
+ const input = payload.value;
1831
+ const left = def.left._zod.run({ value: input, issues: [] }, ctx);
1832
+ const right = def.right._zod.run({ value: input, issues: [] }, ctx);
1833
+ const async = left instanceof Promise || right instanceof Promise;
1834
+ if (async) {
1835
+ return Promise.all([left, right]).then(([left2, right2]) => {
1836
+ return handleIntersectionResults(payload, left2, right2);
1837
+ });
1838
+ }
1839
+ return handleIntersectionResults(payload, left, right);
1840
+ };
1841
+ });
1842
+ function mergeValues(a, b) {
1843
+ if (a === b) {
1844
+ return { valid: true, data: a };
1845
+ }
1846
+ if (a instanceof Date && b instanceof Date && +a === +b) {
1847
+ return { valid: true, data: a };
1848
+ }
1849
+ if (isPlainObject(a) && isPlainObject(b)) {
1850
+ const bKeys = Object.keys(b);
1851
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
1852
+ const newObj = { ...a, ...b };
1853
+ for (const key of sharedKeys) {
1854
+ const sharedValue = mergeValues(a[key], b[key]);
1855
+ if (!sharedValue.valid) {
1856
+ return {
1857
+ valid: false,
1858
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath]
1859
+ };
1860
+ }
1861
+ newObj[key] = sharedValue.data;
1862
+ }
1863
+ return { valid: true, data: newObj };
1864
+ }
1865
+ if (Array.isArray(a) && Array.isArray(b)) {
1866
+ if (a.length !== b.length) {
1867
+ return { valid: false, mergeErrorPath: [] };
1868
+ }
1869
+ const newArray = [];
1870
+ for (let index = 0; index < a.length; index++) {
1871
+ const itemA = a[index];
1872
+ const itemB = b[index];
1873
+ const sharedValue = mergeValues(itemA, itemB);
1874
+ if (!sharedValue.valid) {
1875
+ return {
1876
+ valid: false,
1877
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath]
1878
+ };
1879
+ }
1880
+ newArray.push(sharedValue.data);
1881
+ }
1882
+ return { valid: true, data: newArray };
1883
+ }
1884
+ return { valid: false, mergeErrorPath: [] };
1885
+ }
1886
+ function handleIntersectionResults(result, left, right) {
1887
+ if (left.issues.length) {
1888
+ result.issues.push(...left.issues);
1889
+ }
1890
+ if (right.issues.length) {
1891
+ result.issues.push(...right.issues);
1892
+ }
1893
+ if (aborted(result))
1894
+ return result;
1895
+ const merged = mergeValues(left.value, right.value);
1896
+ if (!merged.valid) {
1897
+ throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
1898
+ }
1899
+ result.value = merged.data;
1900
+ return result;
1901
+ }
1902
+ const $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
1903
+ $ZodType.init(inst, def);
1904
+ const values = getEnumValues(def.entries);
1905
+ const valuesSet = new Set(values);
1906
+ inst._zod.values = valuesSet;
1907
+ inst._zod.pattern = new RegExp(`^(${values.filter((k) => propertyKeyTypes.has(typeof k)).map((o) => typeof o === "string" ? escapeRegex(o) : o.toString()).join("|")})$`);
1908
+ inst._zod.parse = (payload, _ctx) => {
1909
+ const input = payload.value;
1910
+ if (valuesSet.has(input)) {
1911
+ return payload;
1912
+ }
1913
+ payload.issues.push({
1914
+ code: "invalid_value",
1915
+ values,
1916
+ input,
1917
+ inst
1918
+ });
1919
+ return payload;
1920
+ };
1921
+ });
1922
+ const $ZodTransform = /* @__PURE__ */ $constructor("$ZodTransform", (inst, def) => {
1923
+ $ZodType.init(inst, def);
1924
+ inst._zod.parse = (payload, ctx) => {
1925
+ if (ctx.direction === "backward") {
1926
+ throw new $ZodEncodeError(inst.constructor.name);
1927
+ }
1928
+ const _out = def.transform(payload.value, payload);
1929
+ if (ctx.async) {
1930
+ const output = _out instanceof Promise ? _out : Promise.resolve(_out);
1931
+ return output.then((output2) => {
1932
+ payload.value = output2;
1933
+ return payload;
1934
+ });
1935
+ }
1936
+ if (_out instanceof Promise) {
1937
+ throw new $ZodAsyncError();
1938
+ }
1939
+ payload.value = _out;
1940
+ return payload;
1941
+ };
1942
+ });
1943
+ function handleOptionalResult(result, input) {
1944
+ if (result.issues.length && input === void 0) {
1945
+ return { issues: [], value: void 0 };
1946
+ }
1947
+ return result;
1948
+ }
1949
+ const $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) => {
1950
+ $ZodType.init(inst, def);
1951
+ inst._zod.optin = "optional";
1952
+ inst._zod.optout = "optional";
1953
+ defineLazy(inst._zod, "values", () => {
1954
+ return def.innerType._zod.values ? /* @__PURE__ */ new Set([...def.innerType._zod.values, void 0]) : void 0;
1955
+ });
1956
+ defineLazy(inst._zod, "pattern", () => {
1957
+ const pattern = def.innerType._zod.pattern;
1958
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
1959
+ });
1960
+ inst._zod.parse = (payload, ctx) => {
1961
+ if (def.innerType._zod.optin === "optional") {
1962
+ const result = def.innerType._zod.run(payload, ctx);
1963
+ if (result instanceof Promise)
1964
+ return result.then((r) => handleOptionalResult(r, payload.value));
1965
+ return handleOptionalResult(result, payload.value);
1966
+ }
1967
+ if (payload.value === void 0) {
1968
+ return payload;
1969
+ }
1970
+ return def.innerType._zod.run(payload, ctx);
1971
+ };
1972
+ });
1973
+ const $ZodNullable = /* @__PURE__ */ $constructor("$ZodNullable", (inst, def) => {
1974
+ $ZodType.init(inst, def);
1975
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1976
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1977
+ defineLazy(inst._zod, "pattern", () => {
1978
+ const pattern = def.innerType._zod.pattern;
1979
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
1980
+ });
1981
+ defineLazy(inst._zod, "values", () => {
1982
+ return def.innerType._zod.values ? /* @__PURE__ */ new Set([...def.innerType._zod.values, null]) : void 0;
1983
+ });
1984
+ inst._zod.parse = (payload, ctx) => {
1985
+ if (payload.value === null)
1986
+ return payload;
1987
+ return def.innerType._zod.run(payload, ctx);
1988
+ };
1989
+ });
1990
+ const $ZodDefault = /* @__PURE__ */ $constructor("$ZodDefault", (inst, def) => {
1991
+ $ZodType.init(inst, def);
1992
+ inst._zod.optin = "optional";
1993
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1994
+ inst._zod.parse = (payload, ctx) => {
1995
+ if (ctx.direction === "backward") {
1996
+ return def.innerType._zod.run(payload, ctx);
1997
+ }
1998
+ if (payload.value === void 0) {
1999
+ payload.value = def.defaultValue;
2000
+ return payload;
2001
+ }
2002
+ const result = def.innerType._zod.run(payload, ctx);
2003
+ if (result instanceof Promise) {
2004
+ return result.then((result2) => handleDefaultResult(result2, def));
2005
+ }
2006
+ return handleDefaultResult(result, def);
2007
+ };
2008
+ });
2009
+ function handleDefaultResult(payload, def) {
2010
+ if (payload.value === void 0) {
2011
+ payload.value = def.defaultValue;
2012
+ }
2013
+ return payload;
2014
+ }
2015
+ const $ZodPrefault = /* @__PURE__ */ $constructor("$ZodPrefault", (inst, def) => {
2016
+ $ZodType.init(inst, def);
2017
+ inst._zod.optin = "optional";
2018
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2019
+ inst._zod.parse = (payload, ctx) => {
2020
+ if (ctx.direction === "backward") {
2021
+ return def.innerType._zod.run(payload, ctx);
2022
+ }
2023
+ if (payload.value === void 0) {
2024
+ payload.value = def.defaultValue;
2025
+ }
2026
+ return def.innerType._zod.run(payload, ctx);
2027
+ };
2028
+ });
2029
+ const $ZodNonOptional = /* @__PURE__ */ $constructor("$ZodNonOptional", (inst, def) => {
2030
+ $ZodType.init(inst, def);
2031
+ defineLazy(inst._zod, "values", () => {
2032
+ const v = def.innerType._zod.values;
2033
+ return v ? new Set([...v].filter((x) => x !== void 0)) : void 0;
2034
+ });
2035
+ inst._zod.parse = (payload, ctx) => {
2036
+ const result = def.innerType._zod.run(payload, ctx);
2037
+ if (result instanceof Promise) {
2038
+ return result.then((result2) => handleNonOptionalResult(result2, inst));
2039
+ }
2040
+ return handleNonOptionalResult(result, inst);
2041
+ };
2042
+ });
2043
+ function handleNonOptionalResult(payload, inst) {
2044
+ if (!payload.issues.length && payload.value === void 0) {
2045
+ payload.issues.push({
2046
+ code: "invalid_type",
2047
+ expected: "nonoptional",
2048
+ input: payload.value,
2049
+ inst
2050
+ });
2051
+ }
2052
+ return payload;
2053
+ }
2054
+ const $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
2055
+ $ZodType.init(inst, def);
2056
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
2057
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
2058
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2059
+ inst._zod.parse = (payload, ctx) => {
2060
+ if (ctx.direction === "backward") {
2061
+ return def.innerType._zod.run(payload, ctx);
2062
+ }
2063
+ const result = def.innerType._zod.run(payload, ctx);
2064
+ if (result instanceof Promise) {
2065
+ return result.then((result2) => {
2066
+ payload.value = result2.value;
2067
+ if (result2.issues.length) {
2068
+ payload.value = def.catchValue({
2069
+ ...payload,
2070
+ error: {
2071
+ issues: result2.issues.map((iss) => finalizeIssue(iss, ctx, config()))
2072
+ },
2073
+ input: payload.value
2074
+ });
2075
+ payload.issues = [];
2076
+ }
2077
+ return payload;
2078
+ });
2079
+ }
2080
+ payload.value = result.value;
2081
+ if (result.issues.length) {
2082
+ payload.value = def.catchValue({
2083
+ ...payload,
2084
+ error: {
2085
+ issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config()))
2086
+ },
2087
+ input: payload.value
2088
+ });
2089
+ payload.issues = [];
2090
+ }
2091
+ return payload;
2092
+ };
2093
+ });
2094
+ const $ZodPipe = /* @__PURE__ */ $constructor("$ZodPipe", (inst, def) => {
2095
+ $ZodType.init(inst, def);
2096
+ defineLazy(inst._zod, "values", () => def.in._zod.values);
2097
+ defineLazy(inst._zod, "optin", () => def.in._zod.optin);
2098
+ defineLazy(inst._zod, "optout", () => def.out._zod.optout);
2099
+ defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
2100
+ inst._zod.parse = (payload, ctx) => {
2101
+ if (ctx.direction === "backward") {
2102
+ const right = def.out._zod.run(payload, ctx);
2103
+ if (right instanceof Promise) {
2104
+ return right.then((right2) => handlePipeResult(right2, def.in, ctx));
2105
+ }
2106
+ return handlePipeResult(right, def.in, ctx);
2107
+ }
2108
+ const left = def.in._zod.run(payload, ctx);
2109
+ if (left instanceof Promise) {
2110
+ return left.then((left2) => handlePipeResult(left2, def.out, ctx));
2111
+ }
2112
+ return handlePipeResult(left, def.out, ctx);
2113
+ };
2114
+ });
2115
+ function handlePipeResult(left, next, ctx) {
2116
+ if (left.issues.length) {
2117
+ left.aborted = true;
2118
+ return left;
2119
+ }
2120
+ return next._zod.run({ value: left.value, issues: left.issues }, ctx);
2121
+ }
2122
+ const $ZodReadonly = /* @__PURE__ */ $constructor("$ZodReadonly", (inst, def) => {
2123
+ $ZodType.init(inst, def);
2124
+ defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
2125
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2126
+ defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
2127
+ defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
2128
+ inst._zod.parse = (payload, ctx) => {
2129
+ if (ctx.direction === "backward") {
2130
+ return def.innerType._zod.run(payload, ctx);
2131
+ }
2132
+ const result = def.innerType._zod.run(payload, ctx);
2133
+ if (result instanceof Promise) {
2134
+ return result.then(handleReadonlyResult);
2135
+ }
2136
+ return handleReadonlyResult(result);
2137
+ };
2138
+ });
2139
+ function handleReadonlyResult(payload) {
2140
+ payload.value = Object.freeze(payload.value);
2141
+ return payload;
2142
+ }
2143
+ const $ZodCustom = /* @__PURE__ */ $constructor("$ZodCustom", (inst, def) => {
2144
+ $ZodCheck.init(inst, def);
2145
+ $ZodType.init(inst, def);
2146
+ inst._zod.parse = (payload, _) => {
2147
+ return payload;
2148
+ };
2149
+ inst._zod.check = (payload) => {
2150
+ const input = payload.value;
2151
+ const r = def.fn(input);
2152
+ if (r instanceof Promise) {
2153
+ return r.then((r2) => handleRefineResult(r2, payload, input, inst));
2154
+ }
2155
+ handleRefineResult(r, payload, input, inst);
2156
+ return;
2157
+ };
2158
+ });
2159
+ function handleRefineResult(result, payload, input, inst) {
2160
+ if (!result) {
2161
+ const _iss = {
2162
+ code: "custom",
2163
+ input,
2164
+ inst,
2165
+ // incorporates params.error into issue reporting
2166
+ path: [...inst._zod.def.path ?? []],
2167
+ // incorporates params.error into issue reporting
2168
+ continue: !inst._zod.def.abort
2169
+ // params: inst._zod.def.params,
2170
+ };
2171
+ if (inst._zod.def.params)
2172
+ _iss.params = inst._zod.def.params;
2173
+ payload.issues.push(issue(_iss));
2174
+ }
2175
+ }
2176
+ var _a;
2177
+ class $ZodRegistry {
2178
+ constructor() {
2179
+ this._map = /* @__PURE__ */ new WeakMap();
2180
+ this._idmap = /* @__PURE__ */ new Map();
2181
+ }
2182
+ add(schema, ..._meta) {
2183
+ const meta = _meta[0];
2184
+ this._map.set(schema, meta);
2185
+ if (meta && typeof meta === "object" && "id" in meta) {
2186
+ if (this._idmap.has(meta.id)) {
2187
+ throw new Error(`ID ${meta.id} already exists in the registry`);
2188
+ }
2189
+ this._idmap.set(meta.id, schema);
2190
+ }
2191
+ return this;
2192
+ }
2193
+ clear() {
2194
+ this._map = /* @__PURE__ */ new WeakMap();
2195
+ this._idmap = /* @__PURE__ */ new Map();
2196
+ return this;
2197
+ }
2198
+ remove(schema) {
2199
+ const meta = this._map.get(schema);
2200
+ if (meta && typeof meta === "object" && "id" in meta) {
2201
+ this._idmap.delete(meta.id);
2202
+ }
2203
+ this._map.delete(schema);
2204
+ return this;
2205
+ }
2206
+ get(schema) {
2207
+ const p = schema._zod.parent;
2208
+ if (p) {
2209
+ const pm = { ...this.get(p) ?? {} };
2210
+ delete pm.id;
2211
+ const f = { ...pm, ...this._map.get(schema) };
2212
+ return Object.keys(f).length ? f : void 0;
2213
+ }
2214
+ return this._map.get(schema);
2215
+ }
2216
+ has(schema) {
2217
+ return this._map.has(schema);
2218
+ }
2219
+ }
2220
+ function registry() {
2221
+ return new $ZodRegistry();
2222
+ }
2223
+ (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
2224
+ const globalRegistry = globalThis.__zod_globalRegistry;
2225
+ function _string(Class, params) {
2226
+ return new Class({
2227
+ type: "string",
2228
+ ...normalizeParams(params)
2229
+ });
2230
+ }
2231
+ function _email(Class, params) {
2232
+ return new Class({
2233
+ type: "string",
2234
+ format: "email",
2235
+ check: "string_format",
2236
+ abort: false,
2237
+ ...normalizeParams(params)
2238
+ });
2239
+ }
2240
+ function _guid(Class, params) {
2241
+ return new Class({
2242
+ type: "string",
2243
+ format: "guid",
2244
+ check: "string_format",
2245
+ abort: false,
2246
+ ...normalizeParams(params)
2247
+ });
2248
+ }
2249
+ function _uuid(Class, params) {
2250
+ return new Class({
2251
+ type: "string",
2252
+ format: "uuid",
2253
+ check: "string_format",
2254
+ abort: false,
2255
+ ...normalizeParams(params)
2256
+ });
2257
+ }
2258
+ function _uuidv4(Class, params) {
2259
+ return new Class({
2260
+ type: "string",
2261
+ format: "uuid",
2262
+ check: "string_format",
2263
+ abort: false,
2264
+ version: "v4",
2265
+ ...normalizeParams(params)
2266
+ });
2267
+ }
2268
+ function _uuidv6(Class, params) {
2269
+ return new Class({
2270
+ type: "string",
2271
+ format: "uuid",
2272
+ check: "string_format",
2273
+ abort: false,
2274
+ version: "v6",
2275
+ ...normalizeParams(params)
2276
+ });
2277
+ }
2278
+ function _uuidv7(Class, params) {
2279
+ return new Class({
2280
+ type: "string",
2281
+ format: "uuid",
2282
+ check: "string_format",
2283
+ abort: false,
2284
+ version: "v7",
2285
+ ...normalizeParams(params)
2286
+ });
2287
+ }
2288
+ function _url(Class, params) {
2289
+ return new Class({
2290
+ type: "string",
2291
+ format: "url",
2292
+ check: "string_format",
2293
+ abort: false,
2294
+ ...normalizeParams(params)
2295
+ });
2296
+ }
2297
+ function _emoji(Class, params) {
2298
+ return new Class({
2299
+ type: "string",
2300
+ format: "emoji",
2301
+ check: "string_format",
2302
+ abort: false,
2303
+ ...normalizeParams(params)
2304
+ });
2305
+ }
2306
+ function _nanoid(Class, params) {
2307
+ return new Class({
2308
+ type: "string",
2309
+ format: "nanoid",
2310
+ check: "string_format",
2311
+ abort: false,
2312
+ ...normalizeParams(params)
2313
+ });
2314
+ }
2315
+ function _cuid(Class, params) {
2316
+ return new Class({
2317
+ type: "string",
2318
+ format: "cuid",
2319
+ check: "string_format",
2320
+ abort: false,
2321
+ ...normalizeParams(params)
2322
+ });
2323
+ }
2324
+ function _cuid2(Class, params) {
2325
+ return new Class({
2326
+ type: "string",
2327
+ format: "cuid2",
2328
+ check: "string_format",
2329
+ abort: false,
2330
+ ...normalizeParams(params)
2331
+ });
2332
+ }
2333
+ function _ulid(Class, params) {
2334
+ return new Class({
2335
+ type: "string",
2336
+ format: "ulid",
2337
+ check: "string_format",
2338
+ abort: false,
2339
+ ...normalizeParams(params)
2340
+ });
2341
+ }
2342
+ function _xid(Class, params) {
2343
+ return new Class({
2344
+ type: "string",
2345
+ format: "xid",
2346
+ check: "string_format",
2347
+ abort: false,
2348
+ ...normalizeParams(params)
2349
+ });
2350
+ }
2351
+ function _ksuid(Class, params) {
2352
+ return new Class({
2353
+ type: "string",
2354
+ format: "ksuid",
2355
+ check: "string_format",
2356
+ abort: false,
2357
+ ...normalizeParams(params)
2358
+ });
2359
+ }
2360
+ function _ipv4(Class, params) {
2361
+ return new Class({
2362
+ type: "string",
2363
+ format: "ipv4",
2364
+ check: "string_format",
2365
+ abort: false,
2366
+ ...normalizeParams(params)
2367
+ });
2368
+ }
2369
+ function _ipv6(Class, params) {
2370
+ return new Class({
2371
+ type: "string",
2372
+ format: "ipv6",
2373
+ check: "string_format",
2374
+ abort: false,
2375
+ ...normalizeParams(params)
2376
+ });
2377
+ }
2378
+ function _cidrv4(Class, params) {
2379
+ return new Class({
2380
+ type: "string",
2381
+ format: "cidrv4",
2382
+ check: "string_format",
2383
+ abort: false,
2384
+ ...normalizeParams(params)
2385
+ });
2386
+ }
2387
+ function _cidrv6(Class, params) {
2388
+ return new Class({
2389
+ type: "string",
2390
+ format: "cidrv6",
2391
+ check: "string_format",
2392
+ abort: false,
2393
+ ...normalizeParams(params)
2394
+ });
2395
+ }
2396
+ function _base64(Class, params) {
2397
+ return new Class({
2398
+ type: "string",
2399
+ format: "base64",
2400
+ check: "string_format",
2401
+ abort: false,
2402
+ ...normalizeParams(params)
2403
+ });
2404
+ }
2405
+ function _base64url(Class, params) {
2406
+ return new Class({
2407
+ type: "string",
2408
+ format: "base64url",
2409
+ check: "string_format",
2410
+ abort: false,
2411
+ ...normalizeParams(params)
2412
+ });
2413
+ }
2414
+ function _e164(Class, params) {
2415
+ return new Class({
2416
+ type: "string",
2417
+ format: "e164",
2418
+ check: "string_format",
2419
+ abort: false,
2420
+ ...normalizeParams(params)
2421
+ });
2422
+ }
2423
+ function _jwt(Class, params) {
2424
+ return new Class({
2425
+ type: "string",
2426
+ format: "jwt",
2427
+ check: "string_format",
2428
+ abort: false,
2429
+ ...normalizeParams(params)
2430
+ });
2431
+ }
2432
+ function _isoDateTime(Class, params) {
2433
+ return new Class({
2434
+ type: "string",
2435
+ format: "datetime",
2436
+ check: "string_format",
2437
+ offset: false,
2438
+ local: false,
2439
+ precision: null,
2440
+ ...normalizeParams(params)
2441
+ });
2442
+ }
2443
+ function _isoDate(Class, params) {
2444
+ return new Class({
2445
+ type: "string",
2446
+ format: "date",
2447
+ check: "string_format",
2448
+ ...normalizeParams(params)
2449
+ });
2450
+ }
2451
+ function _isoTime(Class, params) {
2452
+ return new Class({
2453
+ type: "string",
2454
+ format: "time",
2455
+ check: "string_format",
2456
+ precision: null,
2457
+ ...normalizeParams(params)
2458
+ });
2459
+ }
2460
+ function _isoDuration(Class, params) {
2461
+ return new Class({
2462
+ type: "string",
2463
+ format: "duration",
2464
+ check: "string_format",
2465
+ ...normalizeParams(params)
2466
+ });
2467
+ }
2468
+ function _number(Class, params) {
2469
+ return new Class({
2470
+ type: "number",
2471
+ checks: [],
2472
+ ...normalizeParams(params)
2473
+ });
2474
+ }
2475
+ function _int(Class, params) {
2476
+ return new Class({
2477
+ type: "number",
2478
+ check: "number_format",
2479
+ abort: false,
2480
+ format: "safeint",
2481
+ ...normalizeParams(params)
2482
+ });
2483
+ }
2484
+ function _boolean(Class, params) {
2485
+ return new Class({
2486
+ type: "boolean",
2487
+ ...normalizeParams(params)
2488
+ });
2489
+ }
2490
+ function _unknown(Class) {
2491
+ return new Class({
2492
+ type: "unknown"
2493
+ });
2494
+ }
2495
+ function _never(Class, params) {
2496
+ return new Class({
2497
+ type: "never",
2498
+ ...normalizeParams(params)
2499
+ });
2500
+ }
2501
+ function _lt(value, params) {
2502
+ return new $ZodCheckLessThan({
2503
+ check: "less_than",
2504
+ ...normalizeParams(params),
2505
+ value,
2506
+ inclusive: false
2507
+ });
2508
+ }
2509
+ function _lte(value, params) {
2510
+ return new $ZodCheckLessThan({
2511
+ check: "less_than",
2512
+ ...normalizeParams(params),
2513
+ value,
2514
+ inclusive: true
2515
+ });
2516
+ }
2517
+ function _gt(value, params) {
2518
+ return new $ZodCheckGreaterThan({
2519
+ check: "greater_than",
2520
+ ...normalizeParams(params),
2521
+ value,
2522
+ inclusive: false
2523
+ });
2524
+ }
2525
+ function _gte(value, params) {
2526
+ return new $ZodCheckGreaterThan({
2527
+ check: "greater_than",
2528
+ ...normalizeParams(params),
2529
+ value,
2530
+ inclusive: true
2531
+ });
2532
+ }
2533
+ function _multipleOf(value, params) {
2534
+ return new $ZodCheckMultipleOf({
2535
+ check: "multiple_of",
2536
+ ...normalizeParams(params),
2537
+ value
2538
+ });
2539
+ }
2540
+ function _maxLength(maximum, params) {
2541
+ const ch = new $ZodCheckMaxLength({
2542
+ check: "max_length",
2543
+ ...normalizeParams(params),
2544
+ maximum
2545
+ });
2546
+ return ch;
2547
+ }
2548
+ function _minLength(minimum, params) {
2549
+ return new $ZodCheckMinLength({
2550
+ check: "min_length",
2551
+ ...normalizeParams(params),
2552
+ minimum
2553
+ });
2554
+ }
2555
+ function _length(length, params) {
2556
+ return new $ZodCheckLengthEquals({
2557
+ check: "length_equals",
2558
+ ...normalizeParams(params),
2559
+ length
2560
+ });
2561
+ }
2562
+ function _regex(pattern, params) {
2563
+ return new $ZodCheckRegex({
2564
+ check: "string_format",
2565
+ format: "regex",
2566
+ ...normalizeParams(params),
2567
+ pattern
2568
+ });
2569
+ }
2570
+ function _lowercase(params) {
2571
+ return new $ZodCheckLowerCase({
2572
+ check: "string_format",
2573
+ format: "lowercase",
2574
+ ...normalizeParams(params)
2575
+ });
2576
+ }
2577
+ function _uppercase(params) {
2578
+ return new $ZodCheckUpperCase({
2579
+ check: "string_format",
2580
+ format: "uppercase",
2581
+ ...normalizeParams(params)
2582
+ });
2583
+ }
2584
+ function _includes(includes, params) {
2585
+ return new $ZodCheckIncludes({
2586
+ check: "string_format",
2587
+ format: "includes",
2588
+ ...normalizeParams(params),
2589
+ includes
2590
+ });
2591
+ }
2592
+ function _startsWith(prefix, params) {
2593
+ return new $ZodCheckStartsWith({
2594
+ check: "string_format",
2595
+ format: "starts_with",
2596
+ ...normalizeParams(params),
2597
+ prefix
2598
+ });
2599
+ }
2600
+ function _endsWith(suffix, params) {
2601
+ return new $ZodCheckEndsWith({
2602
+ check: "string_format",
2603
+ format: "ends_with",
2604
+ ...normalizeParams(params),
2605
+ suffix
2606
+ });
2607
+ }
2608
+ function _overwrite(tx) {
2609
+ return new $ZodCheckOverwrite({
2610
+ check: "overwrite",
2611
+ tx
2612
+ });
2613
+ }
2614
+ function _normalize(form) {
2615
+ return _overwrite((input) => input.normalize(form));
2616
+ }
2617
+ function _trim() {
2618
+ return _overwrite((input) => input.trim());
2619
+ }
2620
+ function _toLowerCase() {
2621
+ return _overwrite((input) => input.toLowerCase());
2622
+ }
2623
+ function _toUpperCase() {
2624
+ return _overwrite((input) => input.toUpperCase());
2625
+ }
2626
+ function _slugify() {
2627
+ return _overwrite((input) => slugify(input));
2628
+ }
2629
+ function _array(Class, element, params) {
2630
+ return new Class({
2631
+ type: "array",
2632
+ element,
2633
+ // get element() {
2634
+ // return element;
2635
+ // },
2636
+ ...normalizeParams(params)
2637
+ });
2638
+ }
2639
+ function _refine(Class, fn, _params) {
2640
+ const schema = new Class({
2641
+ type: "custom",
2642
+ check: "custom",
2643
+ fn,
2644
+ ...normalizeParams(_params)
2645
+ });
2646
+ return schema;
2647
+ }
2648
+ function _superRefine(fn) {
2649
+ const ch = _check((payload) => {
2650
+ payload.addIssue = (issue$1) => {
2651
+ if (typeof issue$1 === "string") {
2652
+ payload.issues.push(issue(issue$1, payload.value, ch._zod.def));
2653
+ } else {
2654
+ const _issue = issue$1;
2655
+ if (_issue.fatal)
2656
+ _issue.continue = false;
2657
+ _issue.code ?? (_issue.code = "custom");
2658
+ _issue.input ?? (_issue.input = payload.value);
2659
+ _issue.inst ?? (_issue.inst = ch);
2660
+ _issue.continue ?? (_issue.continue = !ch._zod.def.abort);
2661
+ payload.issues.push(issue(_issue));
2662
+ }
2663
+ };
2664
+ return fn(payload.value, payload);
2665
+ });
2666
+ return ch;
2667
+ }
2668
+ function _check(fn, params) {
2669
+ const ch = new $ZodCheck({
2670
+ check: "custom",
2671
+ ...normalizeParams(params)
2672
+ });
2673
+ ch._zod.check = fn;
2674
+ return ch;
2675
+ }
2676
+ const ZodISODateTime = /* @__PURE__ */ $constructor("ZodISODateTime", (inst, def) => {
2677
+ $ZodISODateTime.init(inst, def);
2678
+ ZodStringFormat.init(inst, def);
2679
+ });
2680
+ function datetime(params) {
2681
+ return _isoDateTime(ZodISODateTime, params);
2682
+ }
2683
+ const ZodISODate = /* @__PURE__ */ $constructor("ZodISODate", (inst, def) => {
2684
+ $ZodISODate.init(inst, def);
2685
+ ZodStringFormat.init(inst, def);
2686
+ });
2687
+ function date(params) {
2688
+ return _isoDate(ZodISODate, params);
2689
+ }
2690
+ const ZodISOTime = /* @__PURE__ */ $constructor("ZodISOTime", (inst, def) => {
2691
+ $ZodISOTime.init(inst, def);
2692
+ ZodStringFormat.init(inst, def);
2693
+ });
2694
+ function time(params) {
2695
+ return _isoTime(ZodISOTime, params);
2696
+ }
2697
+ const ZodISODuration = /* @__PURE__ */ $constructor("ZodISODuration", (inst, def) => {
2698
+ $ZodISODuration.init(inst, def);
2699
+ ZodStringFormat.init(inst, def);
2700
+ });
2701
+ function duration(params) {
2702
+ return _isoDuration(ZodISODuration, params);
2703
+ }
2704
+ const initializer = (inst, issues) => {
2705
+ $ZodError.init(inst, issues);
2706
+ inst.name = "ZodError";
2707
+ Object.defineProperties(inst, {
2708
+ format: {
2709
+ value: (mapper) => formatError(inst, mapper)
2710
+ // enumerable: false,
2711
+ },
2712
+ flatten: {
2713
+ value: (mapper) => flattenError(inst, mapper)
2714
+ // enumerable: false,
2715
+ },
2716
+ addIssue: {
2717
+ value: (issue2) => {
2718
+ inst.issues.push(issue2);
2719
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
2720
+ }
2721
+ // enumerable: false,
2722
+ },
2723
+ addIssues: {
2724
+ value: (issues2) => {
2725
+ inst.issues.push(...issues2);
2726
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
2727
+ }
2728
+ // enumerable: false,
2729
+ },
2730
+ isEmpty: {
2731
+ get() {
2732
+ return inst.issues.length === 0;
2733
+ }
2734
+ // enumerable: false,
2735
+ }
2736
+ });
2737
+ };
2738
+ const ZodRealError = $constructor("ZodError", initializer, {
2739
+ Parent: Error
2740
+ });
2741
+ const parse = /* @__PURE__ */ _parse(ZodRealError);
2742
+ const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
2743
+ const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
2744
+ const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
2745
+ const encode = /* @__PURE__ */ _encode(ZodRealError);
2746
+ const decode = /* @__PURE__ */ _decode(ZodRealError);
2747
+ const encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
2748
+ const decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
2749
+ const safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
2750
+ const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
2751
+ const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
2752
+ const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
2753
+ const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
2754
+ $ZodType.init(inst, def);
2755
+ inst.def = def;
2756
+ inst.type = def.type;
2757
+ Object.defineProperty(inst, "_def", { value: def });
2758
+ inst.check = (...checks) => {
2759
+ return inst.clone(mergeDefs(def, {
2760
+ checks: [
2761
+ ...def.checks ?? [],
2762
+ ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch)
2763
+ ]
2764
+ }));
2765
+ };
2766
+ inst.clone = (def2, params) => clone(inst, def2, params);
2767
+ inst.brand = () => inst;
2768
+ inst.register = ((reg, meta) => {
2769
+ reg.add(inst, meta);
2770
+ return inst;
2771
+ });
2772
+ inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
2773
+ inst.safeParse = (data, params) => safeParse(inst, data, params);
2774
+ inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
2775
+ inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
2776
+ inst.spa = inst.safeParseAsync;
2777
+ inst.encode = (data, params) => encode(inst, data, params);
2778
+ inst.decode = (data, params) => decode(inst, data, params);
2779
+ inst.encodeAsync = async (data, params) => encodeAsync(inst, data, params);
2780
+ inst.decodeAsync = async (data, params) => decodeAsync(inst, data, params);
2781
+ inst.safeEncode = (data, params) => safeEncode(inst, data, params);
2782
+ inst.safeDecode = (data, params) => safeDecode(inst, data, params);
2783
+ inst.safeEncodeAsync = async (data, params) => safeEncodeAsync(inst, data, params);
2784
+ inst.safeDecodeAsync = async (data, params) => safeDecodeAsync(inst, data, params);
2785
+ inst.refine = (check, params) => inst.check(refine(check, params));
2786
+ inst.superRefine = (refinement) => inst.check(superRefine(refinement));
2787
+ inst.overwrite = (fn) => inst.check(_overwrite(fn));
2788
+ inst.optional = () => optional(inst);
2789
+ inst.nullable = () => nullable(inst);
2790
+ inst.nullish = () => optional(nullable(inst));
2791
+ inst.nonoptional = (params) => nonoptional(inst, params);
2792
+ inst.array = () => array(inst);
2793
+ inst.or = (arg) => union([inst, arg]);
2794
+ inst.and = (arg) => intersection(inst, arg);
2795
+ inst.transform = (tx) => pipe(inst, transform(tx));
2796
+ inst.default = (def2) => _default(inst, def2);
2797
+ inst.prefault = (def2) => prefault(inst, def2);
2798
+ inst.catch = (params) => _catch(inst, params);
2799
+ inst.pipe = (target) => pipe(inst, target);
2800
+ inst.readonly = () => readonly(inst);
2801
+ inst.describe = (description) => {
2802
+ const cl = inst.clone();
2803
+ globalRegistry.add(cl, { description });
2804
+ return cl;
2805
+ };
2806
+ Object.defineProperty(inst, "description", {
2807
+ get() {
2808
+ return globalRegistry.get(inst)?.description;
2809
+ },
2810
+ configurable: true
2811
+ });
2812
+ inst.meta = (...args) => {
2813
+ if (args.length === 0) {
2814
+ return globalRegistry.get(inst);
2815
+ }
2816
+ const cl = inst.clone();
2817
+ globalRegistry.add(cl, args[0]);
2818
+ return cl;
2819
+ };
2820
+ inst.isOptional = () => inst.safeParse(void 0).success;
2821
+ inst.isNullable = () => inst.safeParse(null).success;
2822
+ return inst;
2823
+ });
2824
+ const _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
2825
+ $ZodString.init(inst, def);
2826
+ ZodType.init(inst, def);
2827
+ const bag = inst._zod.bag;
2828
+ inst.format = bag.format ?? null;
2829
+ inst.minLength = bag.minimum ?? null;
2830
+ inst.maxLength = bag.maximum ?? null;
2831
+ inst.regex = (...args) => inst.check(_regex(...args));
2832
+ inst.includes = (...args) => inst.check(_includes(...args));
2833
+ inst.startsWith = (...args) => inst.check(_startsWith(...args));
2834
+ inst.endsWith = (...args) => inst.check(_endsWith(...args));
2835
+ inst.min = (...args) => inst.check(_minLength(...args));
2836
+ inst.max = (...args) => inst.check(_maxLength(...args));
2837
+ inst.length = (...args) => inst.check(_length(...args));
2838
+ inst.nonempty = (...args) => inst.check(_minLength(1, ...args));
2839
+ inst.lowercase = (params) => inst.check(_lowercase(params));
2840
+ inst.uppercase = (params) => inst.check(_uppercase(params));
2841
+ inst.trim = () => inst.check(_trim());
2842
+ inst.normalize = (...args) => inst.check(_normalize(...args));
2843
+ inst.toLowerCase = () => inst.check(_toLowerCase());
2844
+ inst.toUpperCase = () => inst.check(_toUpperCase());
2845
+ inst.slugify = () => inst.check(_slugify());
2846
+ });
2847
+ const ZodString = /* @__PURE__ */ $constructor("ZodString", (inst, def) => {
2848
+ $ZodString.init(inst, def);
2849
+ _ZodString.init(inst, def);
2850
+ inst.email = (params) => inst.check(_email(ZodEmail, params));
2851
+ inst.url = (params) => inst.check(_url(ZodURL, params));
2852
+ inst.jwt = (params) => inst.check(_jwt(ZodJWT, params));
2853
+ inst.emoji = (params) => inst.check(_emoji(ZodEmoji, params));
2854
+ inst.guid = (params) => inst.check(_guid(ZodGUID, params));
2855
+ inst.uuid = (params) => inst.check(_uuid(ZodUUID, params));
2856
+ inst.uuidv4 = (params) => inst.check(_uuidv4(ZodUUID, params));
2857
+ inst.uuidv6 = (params) => inst.check(_uuidv6(ZodUUID, params));
2858
+ inst.uuidv7 = (params) => inst.check(_uuidv7(ZodUUID, params));
2859
+ inst.nanoid = (params) => inst.check(_nanoid(ZodNanoID, params));
2860
+ inst.guid = (params) => inst.check(_guid(ZodGUID, params));
2861
+ inst.cuid = (params) => inst.check(_cuid(ZodCUID, params));
2862
+ inst.cuid2 = (params) => inst.check(_cuid2(ZodCUID2, params));
2863
+ inst.ulid = (params) => inst.check(_ulid(ZodULID, params));
2864
+ inst.base64 = (params) => inst.check(_base64(ZodBase64, params));
2865
+ inst.base64url = (params) => inst.check(_base64url(ZodBase64URL, params));
2866
+ inst.xid = (params) => inst.check(_xid(ZodXID, params));
2867
+ inst.ksuid = (params) => inst.check(_ksuid(ZodKSUID, params));
2868
+ inst.ipv4 = (params) => inst.check(_ipv4(ZodIPv4, params));
2869
+ inst.ipv6 = (params) => inst.check(_ipv6(ZodIPv6, params));
2870
+ inst.cidrv4 = (params) => inst.check(_cidrv4(ZodCIDRv4, params));
2871
+ inst.cidrv6 = (params) => inst.check(_cidrv6(ZodCIDRv6, params));
2872
+ inst.e164 = (params) => inst.check(_e164(ZodE164, params));
2873
+ inst.datetime = (params) => inst.check(datetime(params));
2874
+ inst.date = (params) => inst.check(date(params));
2875
+ inst.time = (params) => inst.check(time(params));
2876
+ inst.duration = (params) => inst.check(duration(params));
2877
+ });
2878
+ function string(params) {
2879
+ return _string(ZodString, params);
2880
+ }
2881
+ const ZodStringFormat = /* @__PURE__ */ $constructor("ZodStringFormat", (inst, def) => {
2882
+ $ZodStringFormat.init(inst, def);
2883
+ _ZodString.init(inst, def);
2884
+ });
2885
+ const ZodEmail = /* @__PURE__ */ $constructor("ZodEmail", (inst, def) => {
2886
+ $ZodEmail.init(inst, def);
2887
+ ZodStringFormat.init(inst, def);
2888
+ });
2889
+ const ZodGUID = /* @__PURE__ */ $constructor("ZodGUID", (inst, def) => {
2890
+ $ZodGUID.init(inst, def);
2891
+ ZodStringFormat.init(inst, def);
2892
+ });
2893
+ const ZodUUID = /* @__PURE__ */ $constructor("ZodUUID", (inst, def) => {
2894
+ $ZodUUID.init(inst, def);
2895
+ ZodStringFormat.init(inst, def);
2896
+ });
2897
+ const ZodURL = /* @__PURE__ */ $constructor("ZodURL", (inst, def) => {
2898
+ $ZodURL.init(inst, def);
2899
+ ZodStringFormat.init(inst, def);
2900
+ });
2901
+ const ZodEmoji = /* @__PURE__ */ $constructor("ZodEmoji", (inst, def) => {
2902
+ $ZodEmoji.init(inst, def);
2903
+ ZodStringFormat.init(inst, def);
2904
+ });
2905
+ const ZodNanoID = /* @__PURE__ */ $constructor("ZodNanoID", (inst, def) => {
2906
+ $ZodNanoID.init(inst, def);
2907
+ ZodStringFormat.init(inst, def);
2908
+ });
2909
+ const ZodCUID = /* @__PURE__ */ $constructor("ZodCUID", (inst, def) => {
2910
+ $ZodCUID.init(inst, def);
2911
+ ZodStringFormat.init(inst, def);
2912
+ });
2913
+ const ZodCUID2 = /* @__PURE__ */ $constructor("ZodCUID2", (inst, def) => {
2914
+ $ZodCUID2.init(inst, def);
2915
+ ZodStringFormat.init(inst, def);
2916
+ });
2917
+ const ZodULID = /* @__PURE__ */ $constructor("ZodULID", (inst, def) => {
2918
+ $ZodULID.init(inst, def);
2919
+ ZodStringFormat.init(inst, def);
2920
+ });
2921
+ const ZodXID = /* @__PURE__ */ $constructor("ZodXID", (inst, def) => {
2922
+ $ZodXID.init(inst, def);
2923
+ ZodStringFormat.init(inst, def);
2924
+ });
2925
+ const ZodKSUID = /* @__PURE__ */ $constructor("ZodKSUID", (inst, def) => {
2926
+ $ZodKSUID.init(inst, def);
2927
+ ZodStringFormat.init(inst, def);
2928
+ });
2929
+ const ZodIPv4 = /* @__PURE__ */ $constructor("ZodIPv4", (inst, def) => {
2930
+ $ZodIPv4.init(inst, def);
2931
+ ZodStringFormat.init(inst, def);
2932
+ });
2933
+ const ZodIPv6 = /* @__PURE__ */ $constructor("ZodIPv6", (inst, def) => {
2934
+ $ZodIPv6.init(inst, def);
2935
+ ZodStringFormat.init(inst, def);
2936
+ });
2937
+ const ZodCIDRv4 = /* @__PURE__ */ $constructor("ZodCIDRv4", (inst, def) => {
2938
+ $ZodCIDRv4.init(inst, def);
2939
+ ZodStringFormat.init(inst, def);
2940
+ });
2941
+ const ZodCIDRv6 = /* @__PURE__ */ $constructor("ZodCIDRv6", (inst, def) => {
2942
+ $ZodCIDRv6.init(inst, def);
2943
+ ZodStringFormat.init(inst, def);
2944
+ });
2945
+ const ZodBase64 = /* @__PURE__ */ $constructor("ZodBase64", (inst, def) => {
2946
+ $ZodBase64.init(inst, def);
2947
+ ZodStringFormat.init(inst, def);
2948
+ });
2949
+ const ZodBase64URL = /* @__PURE__ */ $constructor("ZodBase64URL", (inst, def) => {
2950
+ $ZodBase64URL.init(inst, def);
2951
+ ZodStringFormat.init(inst, def);
2952
+ });
2953
+ const ZodE164 = /* @__PURE__ */ $constructor("ZodE164", (inst, def) => {
2954
+ $ZodE164.init(inst, def);
2955
+ ZodStringFormat.init(inst, def);
2956
+ });
2957
+ const ZodJWT = /* @__PURE__ */ $constructor("ZodJWT", (inst, def) => {
2958
+ $ZodJWT.init(inst, def);
2959
+ ZodStringFormat.init(inst, def);
2960
+ });
2961
+ const ZodNumber = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
2962
+ $ZodNumber.init(inst, def);
2963
+ ZodType.init(inst, def);
2964
+ inst.gt = (value, params) => inst.check(_gt(value, params));
2965
+ inst.gte = (value, params) => inst.check(_gte(value, params));
2966
+ inst.min = (value, params) => inst.check(_gte(value, params));
2967
+ inst.lt = (value, params) => inst.check(_lt(value, params));
2968
+ inst.lte = (value, params) => inst.check(_lte(value, params));
2969
+ inst.max = (value, params) => inst.check(_lte(value, params));
2970
+ inst.int = (params) => inst.check(int(params));
2971
+ inst.safe = (params) => inst.check(int(params));
2972
+ inst.positive = (params) => inst.check(_gt(0, params));
2973
+ inst.nonnegative = (params) => inst.check(_gte(0, params));
2974
+ inst.negative = (params) => inst.check(_lt(0, params));
2975
+ inst.nonpositive = (params) => inst.check(_lte(0, params));
2976
+ inst.multipleOf = (value, params) => inst.check(_multipleOf(value, params));
2977
+ inst.step = (value, params) => inst.check(_multipleOf(value, params));
2978
+ inst.finite = () => inst;
2979
+ const bag = inst._zod.bag;
2980
+ inst.minValue = Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
2981
+ inst.maxValue = Math.min(bag.maximum ?? Number.POSITIVE_INFINITY, bag.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null;
2982
+ inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? 0.5);
2983
+ inst.isFinite = true;
2984
+ inst.format = bag.format ?? null;
2985
+ });
2986
+ function number(params) {
2987
+ return _number(ZodNumber, params);
2988
+ }
2989
+ const ZodNumberFormat = /* @__PURE__ */ $constructor("ZodNumberFormat", (inst, def) => {
2990
+ $ZodNumberFormat.init(inst, def);
2991
+ ZodNumber.init(inst, def);
2992
+ });
2993
+ function int(params) {
2994
+ return _int(ZodNumberFormat, params);
2995
+ }
2996
+ const ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
2997
+ $ZodBoolean.init(inst, def);
2998
+ ZodType.init(inst, def);
2999
+ });
3000
+ function boolean(params) {
3001
+ return _boolean(ZodBoolean, params);
3002
+ }
3003
+ const ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
3004
+ $ZodUnknown.init(inst, def);
3005
+ ZodType.init(inst, def);
3006
+ });
3007
+ function unknown() {
3008
+ return _unknown(ZodUnknown);
3009
+ }
3010
+ const ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
3011
+ $ZodNever.init(inst, def);
3012
+ ZodType.init(inst, def);
3013
+ });
3014
+ function never(params) {
3015
+ return _never(ZodNever, params);
3016
+ }
3017
+ const ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
3018
+ $ZodArray.init(inst, def);
3019
+ ZodType.init(inst, def);
3020
+ inst.element = def.element;
3021
+ inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
3022
+ inst.nonempty = (params) => inst.check(_minLength(1, params));
3023
+ inst.max = (maxLength, params) => inst.check(_maxLength(maxLength, params));
3024
+ inst.length = (len, params) => inst.check(_length(len, params));
3025
+ inst.unwrap = () => inst.element;
3026
+ });
3027
+ function array(element, params) {
3028
+ return _array(ZodArray, element, params);
3029
+ }
3030
+ const ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
3031
+ $ZodObjectJIT.init(inst, def);
3032
+ ZodType.init(inst, def);
3033
+ defineLazy(inst, "shape", () => {
3034
+ return def.shape;
3035
+ });
3036
+ inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
3037
+ inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall });
3038
+ inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
3039
+ inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
3040
+ inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
3041
+ inst.strip = () => inst.clone({ ...inst._zod.def, catchall: void 0 });
3042
+ inst.extend = (incoming) => {
3043
+ return extend(inst, incoming);
3044
+ };
3045
+ inst.safeExtend = (incoming) => {
3046
+ return safeExtend(inst, incoming);
3047
+ };
3048
+ inst.merge = (other) => merge(inst, other);
3049
+ inst.pick = (mask) => pick(inst, mask);
3050
+ inst.omit = (mask) => omit(inst, mask);
3051
+ inst.partial = (...args) => partial(ZodOptional, inst, args[0]);
3052
+ inst.required = (...args) => required(ZodNonOptional, inst, args[0]);
3053
+ });
3054
+ function object(shape, params) {
3055
+ const def = {
3056
+ type: "object",
3057
+ shape: shape ?? {},
3058
+ ...normalizeParams(params)
3059
+ };
3060
+ return new ZodObject(def);
3061
+ }
3062
+ const ZodUnion = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
3063
+ $ZodUnion.init(inst, def);
3064
+ ZodType.init(inst, def);
3065
+ inst.options = def.options;
3066
+ });
3067
+ function union(options, params) {
3068
+ return new ZodUnion({
3069
+ type: "union",
3070
+ options,
3071
+ ...normalizeParams(params)
3072
+ });
3073
+ }
3074
+ const ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
3075
+ $ZodIntersection.init(inst, def);
3076
+ ZodType.init(inst, def);
3077
+ });
3078
+ function intersection(left, right) {
3079
+ return new ZodIntersection({
3080
+ type: "intersection",
3081
+ left,
3082
+ right
3083
+ });
3084
+ }
3085
+ const ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
3086
+ $ZodEnum.init(inst, def);
3087
+ ZodType.init(inst, def);
3088
+ inst.enum = def.entries;
3089
+ inst.options = Object.values(def.entries);
3090
+ const keys = new Set(Object.keys(def.entries));
3091
+ inst.extract = (values, params) => {
3092
+ const newEntries = {};
3093
+ for (const value of values) {
3094
+ if (keys.has(value)) {
3095
+ newEntries[value] = def.entries[value];
3096
+ } else
3097
+ throw new Error(`Key ${value} not found in enum`);
3098
+ }
3099
+ return new ZodEnum({
3100
+ ...def,
3101
+ checks: [],
3102
+ ...normalizeParams(params),
3103
+ entries: newEntries
3104
+ });
3105
+ };
3106
+ inst.exclude = (values, params) => {
3107
+ const newEntries = { ...def.entries };
3108
+ for (const value of values) {
3109
+ if (keys.has(value)) {
3110
+ delete newEntries[value];
3111
+ } else
3112
+ throw new Error(`Key ${value} not found in enum`);
3113
+ }
3114
+ return new ZodEnum({
3115
+ ...def,
3116
+ checks: [],
3117
+ ...normalizeParams(params),
3118
+ entries: newEntries
3119
+ });
3120
+ };
3121
+ });
3122
+ function _enum(values, params) {
3123
+ const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
3124
+ return new ZodEnum({
3125
+ type: "enum",
3126
+ entries,
3127
+ ...normalizeParams(params)
3128
+ });
3129
+ }
3130
+ const ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
3131
+ $ZodTransform.init(inst, def);
3132
+ ZodType.init(inst, def);
3133
+ inst._zod.parse = (payload, _ctx) => {
3134
+ if (_ctx.direction === "backward") {
3135
+ throw new $ZodEncodeError(inst.constructor.name);
3136
+ }
3137
+ payload.addIssue = (issue$1) => {
3138
+ if (typeof issue$1 === "string") {
3139
+ payload.issues.push(issue(issue$1, payload.value, def));
3140
+ } else {
3141
+ const _issue = issue$1;
3142
+ if (_issue.fatal)
3143
+ _issue.continue = false;
3144
+ _issue.code ?? (_issue.code = "custom");
3145
+ _issue.input ?? (_issue.input = payload.value);
3146
+ _issue.inst ?? (_issue.inst = inst);
3147
+ payload.issues.push(issue(_issue));
3148
+ }
3149
+ };
3150
+ const output = def.transform(payload.value, payload);
3151
+ if (output instanceof Promise) {
3152
+ return output.then((output2) => {
3153
+ payload.value = output2;
3154
+ return payload;
3155
+ });
3156
+ }
3157
+ payload.value = output;
3158
+ return payload;
3159
+ };
3160
+ });
3161
+ function transform(fn) {
3162
+ return new ZodTransform({
3163
+ type: "transform",
3164
+ transform: fn
3165
+ });
3166
+ }
3167
+ const ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
3168
+ $ZodOptional.init(inst, def);
3169
+ ZodType.init(inst, def);
3170
+ inst.unwrap = () => inst._zod.def.innerType;
3171
+ });
3172
+ function optional(innerType) {
3173
+ return new ZodOptional({
3174
+ type: "optional",
3175
+ innerType
3176
+ });
3177
+ }
3178
+ const ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
3179
+ $ZodNullable.init(inst, def);
3180
+ ZodType.init(inst, def);
3181
+ inst.unwrap = () => inst._zod.def.innerType;
3182
+ });
3183
+ function nullable(innerType) {
3184
+ return new ZodNullable({
3185
+ type: "nullable",
3186
+ innerType
3187
+ });
3188
+ }
3189
+ const ZodDefault = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
3190
+ $ZodDefault.init(inst, def);
3191
+ ZodType.init(inst, def);
3192
+ inst.unwrap = () => inst._zod.def.innerType;
3193
+ inst.removeDefault = inst.unwrap;
3194
+ });
3195
+ function _default(innerType, defaultValue) {
3196
+ return new ZodDefault({
3197
+ type: "default",
3198
+ innerType,
3199
+ get defaultValue() {
3200
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
3201
+ }
3202
+ });
3203
+ }
3204
+ const ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
3205
+ $ZodPrefault.init(inst, def);
3206
+ ZodType.init(inst, def);
3207
+ inst.unwrap = () => inst._zod.def.innerType;
3208
+ });
3209
+ function prefault(innerType, defaultValue) {
3210
+ return new ZodPrefault({
3211
+ type: "prefault",
3212
+ innerType,
3213
+ get defaultValue() {
3214
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
3215
+ }
3216
+ });
3217
+ }
3218
+ const ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
3219
+ $ZodNonOptional.init(inst, def);
3220
+ ZodType.init(inst, def);
3221
+ inst.unwrap = () => inst._zod.def.innerType;
3222
+ });
3223
+ function nonoptional(innerType, params) {
3224
+ return new ZodNonOptional({
3225
+ type: "nonoptional",
3226
+ innerType,
3227
+ ...normalizeParams(params)
3228
+ });
3229
+ }
3230
+ const ZodCatch = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
3231
+ $ZodCatch.init(inst, def);
3232
+ ZodType.init(inst, def);
3233
+ inst.unwrap = () => inst._zod.def.innerType;
3234
+ inst.removeCatch = inst.unwrap;
3235
+ });
3236
+ function _catch(innerType, catchValue) {
3237
+ return new ZodCatch({
3238
+ type: "catch",
3239
+ innerType,
3240
+ catchValue: typeof catchValue === "function" ? catchValue : () => catchValue
3241
+ });
3242
+ }
3243
+ const ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
3244
+ $ZodPipe.init(inst, def);
3245
+ ZodType.init(inst, def);
3246
+ inst.in = def.in;
3247
+ inst.out = def.out;
3248
+ });
3249
+ function pipe(in_, out) {
3250
+ return new ZodPipe({
3251
+ type: "pipe",
3252
+ in: in_,
3253
+ out
3254
+ // ...util.normalizeParams(params),
3255
+ });
3256
+ }
3257
+ const ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
3258
+ $ZodReadonly.init(inst, def);
3259
+ ZodType.init(inst, def);
3260
+ inst.unwrap = () => inst._zod.def.innerType;
3261
+ });
3262
+ function readonly(innerType) {
3263
+ return new ZodReadonly({
3264
+ type: "readonly",
3265
+ innerType
3266
+ });
3267
+ }
3268
+ const ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
3269
+ $ZodCustom.init(inst, def);
3270
+ ZodType.init(inst, def);
3271
+ });
3272
+ function refine(fn, _params = {}) {
3273
+ return _refine(ZodCustom, fn, _params);
3274
+ }
3275
+ function superRefine(fn) {
3276
+ return _superRefine(fn);
3277
+ }
3278
+ const Route = "/api/rb/rts/changes";
3279
+ const requestSchema = object({
3280
+ sinceSeq: number().int().min(0).default(0),
3281
+ limit: number().int().min(1).max(5e3).default(2e3),
3282
+ modelNames: array(string().min(1)).optional()
3283
+ });
3284
+ object({
3285
+ ok: boolean(),
3286
+ needsFullResync: boolean().optional(),
3287
+ earliestSeq: number().int().min(0).optional(),
3288
+ latestSeq: number().int().min(0),
3289
+ changes: array(object({
3290
+ seq: number().int().min(1),
3291
+ modelName: string().min(1),
3292
+ op: _enum(["delete", "reset_model"]),
3293
+ docId: string().optional()
3294
+ }))
3295
+ });
3296
+ const getTenantId = (ctx) => {
3297
+ const raw = ctx.req.query?.["rb-tenant-id"];
3298
+ const queryTenantId = Array.isArray(raw) ? raw[0] : raw;
3299
+ if (typeof queryTenantId === "string" && queryTenantId.trim()) return queryTenantId.trim();
3300
+ const sessionTenantId = ctx.req.session?.user?.current_tenant_id;
3301
+ if (typeof sessionTenantId === "string" && sessionTenantId.trim()) return sessionTenantId.trim();
3302
+ return null;
3303
+ };
3304
+ const ensureAuthorized = (ctx, tenantId) => {
3305
+ const userId = ctx.req.session?.user?.id;
3306
+ if (!userId) return null;
3307
+ const signedInTenants = ctx.req.session?.user?.signed_in_tenants;
3308
+ const currentTenantId = ctx.req.session?.user?.current_tenant_id;
3309
+ const hasTenantAccessFromList = Array.isArray(signedInTenants) && signedInTenants.includes(tenantId);
3310
+ const normalizedCurrentTenantId = typeof currentTenantId === "string" ? currentTenantId.trim() : "";
3311
+ const hasTenantAccessFromCurrent = Boolean(normalizedCurrentTenantId) && normalizedCurrentTenantId === tenantId;
3312
+ if (!hasTenantAccessFromList && !hasTenantAccessFromCurrent) return null;
3313
+ return userId;
3314
+ };
3315
+ const getModelCtx = (_ctx, tenantId) => ({
3316
+ req: {
3317
+ session: {
3318
+ user: {
3319
+ current_tenant_id: tenantId
3320
+ }
3321
+ }
3322
+ }
3323
+ });
3324
+ const isRtsChangeRecord = (value) => {
3325
+ if (!value || typeof value !== "object") return false;
3326
+ const obj = value;
3327
+ const isOp = obj.op === "delete" || obj.op === "reset_model";
3328
+ return typeof obj.seq === "number" && typeof obj.modelName === "string" && isOp;
3329
+ };
3330
+ const changesHandler = async (payload, ctx) => {
3331
+ const parsed = requestSchema.safeParse(payload ?? {});
3332
+ if (!parsed.success) {
3333
+ ctx.res.status(400);
3334
+ return { ok: false, latestSeq: 0, changes: [] };
3335
+ }
3336
+ const tenantId = getTenantId(ctx);
3337
+ if (!tenantId) {
3338
+ ctx.res.status(400);
3339
+ return { ok: false, latestSeq: 0, changes: [] };
3340
+ }
3341
+ const userId = ensureAuthorized(ctx, tenantId);
3342
+ if (!userId) {
3343
+ ctx.res.status(401);
3344
+ return { ok: false, latestSeq: 0, changes: [] };
3345
+ }
3346
+ const modelCtx = getModelCtx(ctx, tenantId);
3347
+ const [RtsChange, RtsCounter] = await Promise.all([
3348
+ loadModel("RtsChange", modelCtx),
3349
+ loadModel("RtsCounter", modelCtx)
3350
+ ]);
3351
+ const counter = await RtsCounter.findOne({ _id: "rts" }, { seq: 1 }).lean();
3352
+ const latestSeq = Number(counter?.seq ?? 0) || 0;
3353
+ const { sinceSeq, limit, modelNames } = parsed.data;
3354
+ const earliestSelector = {};
3355
+ if (Array.isArray(modelNames) && modelNames.length) {
3356
+ earliestSelector.modelName = { $in: modelNames };
3357
+ }
3358
+ const earliest = await RtsChange.findOne(earliestSelector, { seq: 1 }).sort({ seq: 1 }).lean();
3359
+ const earliestSeq = earliest?.seq ? Number(earliest.seq) : void 0;
3360
+ const needsFullResync = typeof earliestSeq === "number" && sinceSeq < earliestSeq - 1;
3361
+ const selector = { seq: { $gt: sinceSeq } };
3362
+ if (Array.isArray(modelNames) && modelNames.length) {
3363
+ selector.modelName = { $in: modelNames };
3364
+ }
3365
+ const changes = await RtsChange.find(selector, { _id: 0, seq: 1, modelName: 1, op: 1, docId: 1 }).sort({ seq: 1 }).limit(limit).lean();
3366
+ return {
3367
+ ok: true,
3368
+ needsFullResync: needsFullResync || void 0,
3369
+ earliestSeq,
3370
+ latestSeq,
3371
+ changes: Array.isArray(changes) ? changes.filter(isRtsChangeRecord).map((c) => ({
3372
+ seq: Number(c.seq),
3373
+ modelName: String(c.modelName),
3374
+ op: c.op,
3375
+ docId: c.docId ? String(c.docId) : void 0
3376
+ })) : []
3377
+ };
3378
+ };
3379
+ const handler = (api) => {
3380
+ api.post(Route, changesHandler);
3381
+ };
3382
+ export {
3383
+ handler as default
3384
+ };