@economic/agents 0.0.1-alpha.22 → 0.0.1-alpha.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { AIChatAgent as AIChatAgent$1 } from "@cloudflare/ai-chat";
2
2
  import { Output, convertToModelMessages, generateText, jsonSchema, stepCountIs, tool } from "ai";
3
+ import { callable } from "agents";
3
4
  //#region src/features/skills/index.ts
4
5
  /** Creates the `skill_state` table in DO SQLite if it does not exist yet. */
5
6
  function ensureSkillTable(sql) {
@@ -368,3348 +369,6 @@ function extractMessageText(msg) {
368
369
  if (!msg?.parts) return "";
369
370
  return msg.parts.filter((p) => p.type === "text").map((p) => p.text).join(" ").trim();
370
371
  }
371
- Object.freeze({ status: "aborted" });
372
- function $constructor(name, initializer, params) {
373
- function init(inst, def) {
374
- if (!inst._zod) Object.defineProperty(inst, "_zod", {
375
- value: {
376
- def,
377
- constr: _,
378
- traits: /* @__PURE__ */ new Set()
379
- },
380
- enumerable: false
381
- });
382
- if (inst._zod.traits.has(name)) return;
383
- inst._zod.traits.add(name);
384
- initializer(inst, def);
385
- const proto = _.prototype;
386
- const keys = Object.keys(proto);
387
- for (let i = 0; i < keys.length; i++) {
388
- const k = keys[i];
389
- if (!(k in inst)) inst[k] = proto[k].bind(inst);
390
- }
391
- }
392
- const Parent = params?.Parent ?? Object;
393
- class Definition extends Parent {}
394
- Object.defineProperty(Definition, "name", { value: name });
395
- function _(def) {
396
- var _a;
397
- const inst = params?.Parent ? new Definition() : this;
398
- init(inst, def);
399
- (_a = inst._zod).deferred ?? (_a.deferred = []);
400
- for (const fn of inst._zod.deferred) fn();
401
- return inst;
402
- }
403
- Object.defineProperty(_, "init", { value: init });
404
- Object.defineProperty(_, Symbol.hasInstance, { value: (inst) => {
405
- if (params?.Parent && inst instanceof params.Parent) return true;
406
- return inst?._zod?.traits?.has(name);
407
- } });
408
- Object.defineProperty(_, "name", { value: name });
409
- return _;
410
- }
411
- var $ZodAsyncError = class extends Error {
412
- constructor() {
413
- super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
414
- }
415
- };
416
- var $ZodEncodeError = class extends Error {
417
- constructor(name) {
418
- super(`Encountered unidirectional transform during encode: ${name}`);
419
- this.name = "ZodEncodeError";
420
- }
421
- };
422
- const globalConfig = {};
423
- function config(newConfig) {
424
- if (newConfig) Object.assign(globalConfig, newConfig);
425
- return globalConfig;
426
- }
427
- //#endregion
428
- //#region ../../node_modules/zod/v4/core/util.js
429
- function getEnumValues(entries) {
430
- const numericValues = Object.values(entries).filter((v) => typeof v === "number");
431
- return Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
432
- }
433
- function jsonStringifyReplacer(_, value) {
434
- if (typeof value === "bigint") return value.toString();
435
- return value;
436
- }
437
- function cached(getter) {
438
- return { get value() {
439
- {
440
- const value = getter();
441
- Object.defineProperty(this, "value", { value });
442
- return value;
443
- }
444
- throw new Error("cached value already set");
445
- } };
446
- }
447
- function nullish(input) {
448
- return input === null || input === void 0;
449
- }
450
- function cleanRegex(source) {
451
- const start = source.startsWith("^") ? 1 : 0;
452
- const end = source.endsWith("$") ? source.length - 1 : source.length;
453
- return source.slice(start, end);
454
- }
455
- const EVALUATING = Symbol("evaluating");
456
- function defineLazy(object, key, getter) {
457
- let value = void 0;
458
- Object.defineProperty(object, key, {
459
- get() {
460
- if (value === EVALUATING) return;
461
- if (value === void 0) {
462
- value = EVALUATING;
463
- value = getter();
464
- }
465
- return value;
466
- },
467
- set(v) {
468
- Object.defineProperty(object, key, { value: v });
469
- },
470
- configurable: true
471
- });
472
- }
473
- function assignProp(target, prop, value) {
474
- Object.defineProperty(target, prop, {
475
- value,
476
- writable: true,
477
- enumerable: true,
478
- configurable: true
479
- });
480
- }
481
- function mergeDefs(...defs) {
482
- const mergedDescriptors = {};
483
- for (const def of defs) {
484
- const descriptors = Object.getOwnPropertyDescriptors(def);
485
- Object.assign(mergedDescriptors, descriptors);
486
- }
487
- return Object.defineProperties({}, mergedDescriptors);
488
- }
489
- function esc(str) {
490
- return JSON.stringify(str);
491
- }
492
- function slugify(input) {
493
- return input.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
494
- }
495
- const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
496
- function isObject(data) {
497
- return typeof data === "object" && data !== null && !Array.isArray(data);
498
- }
499
- const allowsEval = cached(() => {
500
- if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) return false;
501
- try {
502
- new Function("");
503
- return true;
504
- } catch (_) {
505
- return false;
506
- }
507
- });
508
- function isPlainObject(o) {
509
- if (isObject(o) === false) return false;
510
- const ctor = o.constructor;
511
- if (ctor === void 0) return true;
512
- if (typeof ctor !== "function") return true;
513
- const prot = ctor.prototype;
514
- if (isObject(prot) === false) return false;
515
- if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) return false;
516
- return true;
517
- }
518
- function shallowClone(o) {
519
- if (isPlainObject(o)) return { ...o };
520
- if (Array.isArray(o)) return [...o];
521
- return o;
522
- }
523
- const propertyKeyTypes = new Set([
524
- "string",
525
- "number",
526
- "symbol"
527
- ]);
528
- function escapeRegex(str) {
529
- return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
530
- }
531
- function clone(inst, def, params) {
532
- const cl = new inst._zod.constr(def ?? inst._zod.def);
533
- if (!def || params?.parent) cl._zod.parent = inst;
534
- return cl;
535
- }
536
- function normalizeParams(_params) {
537
- const params = _params;
538
- if (!params) return {};
539
- if (typeof params === "string") return { error: () => params };
540
- if (params?.message !== void 0) {
541
- if (params?.error !== void 0) throw new Error("Cannot specify both `message` and `error` params");
542
- params.error = params.message;
543
- }
544
- delete params.message;
545
- if (typeof params.error === "string") return {
546
- ...params,
547
- error: () => params.error
548
- };
549
- return params;
550
- }
551
- function optionalKeys(shape) {
552
- return Object.keys(shape).filter((k) => {
553
- return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
554
- });
555
- }
556
- Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, -Number.MAX_VALUE, Number.MAX_VALUE;
557
- function pick(schema, mask) {
558
- const currDef = schema._zod.def;
559
- const checks = currDef.checks;
560
- if (checks && checks.length > 0) throw new Error(".pick() cannot be used on object schemas containing refinements");
561
- return clone(schema, mergeDefs(schema._zod.def, {
562
- get shape() {
563
- const newShape = {};
564
- for (const key in mask) {
565
- if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
566
- if (!mask[key]) continue;
567
- newShape[key] = currDef.shape[key];
568
- }
569
- assignProp(this, "shape", newShape);
570
- return newShape;
571
- },
572
- checks: []
573
- }));
574
- }
575
- function omit(schema, mask) {
576
- const currDef = schema._zod.def;
577
- const checks = currDef.checks;
578
- if (checks && checks.length > 0) throw new Error(".omit() cannot be used on object schemas containing refinements");
579
- return clone(schema, mergeDefs(schema._zod.def, {
580
- get shape() {
581
- const newShape = { ...schema._zod.def.shape };
582
- for (const key in mask) {
583
- if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
584
- if (!mask[key]) continue;
585
- delete newShape[key];
586
- }
587
- assignProp(this, "shape", newShape);
588
- return newShape;
589
- },
590
- checks: []
591
- }));
592
- }
593
- function extend(schema, shape) {
594
- if (!isPlainObject(shape)) throw new Error("Invalid input to extend: expected a plain object");
595
- const checks = schema._zod.def.checks;
596
- if (checks && checks.length > 0) {
597
- const existingShape = schema._zod.def.shape;
598
- for (const key in shape) if (Object.getOwnPropertyDescriptor(existingShape, key) !== void 0) throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
599
- }
600
- return clone(schema, mergeDefs(schema._zod.def, { get shape() {
601
- const _shape = {
602
- ...schema._zod.def.shape,
603
- ...shape
604
- };
605
- assignProp(this, "shape", _shape);
606
- return _shape;
607
- } }));
608
- }
609
- function safeExtend(schema, shape) {
610
- if (!isPlainObject(shape)) throw new Error("Invalid input to safeExtend: expected a plain object");
611
- return clone(schema, mergeDefs(schema._zod.def, { get shape() {
612
- const _shape = {
613
- ...schema._zod.def.shape,
614
- ...shape
615
- };
616
- assignProp(this, "shape", _shape);
617
- return _shape;
618
- } }));
619
- }
620
- function merge(a, b) {
621
- return clone(a, mergeDefs(a._zod.def, {
622
- get shape() {
623
- const _shape = {
624
- ...a._zod.def.shape,
625
- ...b._zod.def.shape
626
- };
627
- assignProp(this, "shape", _shape);
628
- return _shape;
629
- },
630
- get catchall() {
631
- return b._zod.def.catchall;
632
- },
633
- checks: []
634
- }));
635
- }
636
- function partial(Class, schema, mask) {
637
- const checks = schema._zod.def.checks;
638
- if (checks && checks.length > 0) throw new Error(".partial() cannot be used on object schemas containing refinements");
639
- return clone(schema, mergeDefs(schema._zod.def, {
640
- get shape() {
641
- const oldShape = schema._zod.def.shape;
642
- const shape = { ...oldShape };
643
- if (mask) for (const key in mask) {
644
- if (!(key in oldShape)) throw new Error(`Unrecognized key: "${key}"`);
645
- if (!mask[key]) continue;
646
- shape[key] = Class ? new Class({
647
- type: "optional",
648
- innerType: oldShape[key]
649
- }) : oldShape[key];
650
- }
651
- else for (const key in oldShape) shape[key] = Class ? new Class({
652
- type: "optional",
653
- innerType: oldShape[key]
654
- }) : oldShape[key];
655
- assignProp(this, "shape", shape);
656
- return shape;
657
- },
658
- checks: []
659
- }));
660
- }
661
- function required(Class, schema, mask) {
662
- return clone(schema, mergeDefs(schema._zod.def, { get shape() {
663
- const oldShape = schema._zod.def.shape;
664
- const shape = { ...oldShape };
665
- if (mask) for (const key in mask) {
666
- if (!(key in shape)) throw new Error(`Unrecognized key: "${key}"`);
667
- if (!mask[key]) continue;
668
- shape[key] = new Class({
669
- type: "nonoptional",
670
- innerType: oldShape[key]
671
- });
672
- }
673
- else for (const key in oldShape) shape[key] = new Class({
674
- type: "nonoptional",
675
- innerType: oldShape[key]
676
- });
677
- assignProp(this, "shape", shape);
678
- return shape;
679
- } }));
680
- }
681
- function aborted(x, startIndex = 0) {
682
- if (x.aborted === true) return true;
683
- for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue !== true) return true;
684
- return false;
685
- }
686
- function prefixIssues(path, issues) {
687
- return issues.map((iss) => {
688
- var _a;
689
- (_a = iss).path ?? (_a.path = []);
690
- iss.path.unshift(path);
691
- return iss;
692
- });
693
- }
694
- function unwrapMessage(message) {
695
- return typeof message === "string" ? message : message?.message;
696
- }
697
- function finalizeIssue(iss, ctx, config) {
698
- const full = {
699
- ...iss,
700
- path: iss.path ?? []
701
- };
702
- if (!iss.message) full.message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config.customError?.(iss)) ?? unwrapMessage(config.localeError?.(iss)) ?? "Invalid input";
703
- delete full.inst;
704
- delete full.continue;
705
- if (!ctx?.reportInput) delete full.input;
706
- return full;
707
- }
708
- function getLengthableOrigin(input) {
709
- if (Array.isArray(input)) return "array";
710
- if (typeof input === "string") return "string";
711
- return "unknown";
712
- }
713
- function issue(...args) {
714
- const [iss, input, inst] = args;
715
- if (typeof iss === "string") return {
716
- message: iss,
717
- code: "custom",
718
- input,
719
- inst
720
- };
721
- return { ...iss };
722
- }
723
- //#endregion
724
- //#region ../../node_modules/zod/v4/core/errors.js
725
- const initializer$1 = (inst, def) => {
726
- inst.name = "$ZodError";
727
- Object.defineProperty(inst, "_zod", {
728
- value: inst._zod,
729
- enumerable: false
730
- });
731
- Object.defineProperty(inst, "issues", {
732
- value: def,
733
- enumerable: false
734
- });
735
- inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
736
- Object.defineProperty(inst, "toString", {
737
- value: () => inst.message,
738
- enumerable: false
739
- });
740
- };
741
- const $ZodError = $constructor("$ZodError", initializer$1);
742
- const $ZodRealError = $constructor("$ZodError", initializer$1, { Parent: Error });
743
- function flattenError(error, mapper = (issue) => issue.message) {
744
- const fieldErrors = {};
745
- const formErrors = [];
746
- for (const sub of error.issues) if (sub.path.length > 0) {
747
- fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
748
- fieldErrors[sub.path[0]].push(mapper(sub));
749
- } else formErrors.push(mapper(sub));
750
- return {
751
- formErrors,
752
- fieldErrors
753
- };
754
- }
755
- function formatError(error, mapper = (issue) => issue.message) {
756
- const fieldErrors = { _errors: [] };
757
- const processError = (error) => {
758
- for (const issue of error.issues) if (issue.code === "invalid_union" && issue.errors.length) issue.errors.map((issues) => processError({ issues }));
759
- else if (issue.code === "invalid_key") processError({ issues: issue.issues });
760
- else if (issue.code === "invalid_element") processError({ issues: issue.issues });
761
- else if (issue.path.length === 0) fieldErrors._errors.push(mapper(issue));
762
- else {
763
- let curr = fieldErrors;
764
- let i = 0;
765
- while (i < issue.path.length) {
766
- const el = issue.path[i];
767
- if (!(i === issue.path.length - 1)) curr[el] = curr[el] || { _errors: [] };
768
- else {
769
- curr[el] = curr[el] || { _errors: [] };
770
- curr[el]._errors.push(mapper(issue));
771
- }
772
- curr = curr[el];
773
- i++;
774
- }
775
- }
776
- };
777
- processError(error);
778
- return fieldErrors;
779
- }
780
- //#endregion
781
- //#region ../../node_modules/zod/v4/core/parse.js
782
- const _parse = (_Err) => (schema, value, _ctx, _params) => {
783
- const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
784
- const result = schema._zod.run({
785
- value,
786
- issues: []
787
- }, ctx);
788
- if (result instanceof Promise) throw new $ZodAsyncError();
789
- if (result.issues.length) {
790
- const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
791
- captureStackTrace(e, _params?.callee);
792
- throw e;
793
- }
794
- return result.value;
795
- };
796
- const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
797
- const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
798
- let result = schema._zod.run({
799
- value,
800
- issues: []
801
- }, ctx);
802
- if (result instanceof Promise) result = await result;
803
- if (result.issues.length) {
804
- const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
805
- captureStackTrace(e, params?.callee);
806
- throw e;
807
- }
808
- return result.value;
809
- };
810
- const _safeParse = (_Err) => (schema, value, _ctx) => {
811
- const ctx = _ctx ? {
812
- ..._ctx,
813
- async: false
814
- } : { async: false };
815
- const result = schema._zod.run({
816
- value,
817
- issues: []
818
- }, ctx);
819
- if (result instanceof Promise) throw new $ZodAsyncError();
820
- return result.issues.length ? {
821
- success: false,
822
- error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
823
- } : {
824
- success: true,
825
- data: result.value
826
- };
827
- };
828
- const safeParse$1 = /* @__PURE__ */ _safeParse($ZodRealError);
829
- const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
830
- const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
831
- let result = schema._zod.run({
832
- value,
833
- issues: []
834
- }, ctx);
835
- if (result instanceof Promise) result = await result;
836
- return result.issues.length ? {
837
- success: false,
838
- error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
839
- } : {
840
- success: true,
841
- data: result.value
842
- };
843
- };
844
- const safeParseAsync$1 = /* @__PURE__ */ _safeParseAsync($ZodRealError);
845
- const _encode = (_Err) => (schema, value, _ctx) => {
846
- const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
847
- return _parse(_Err)(schema, value, ctx);
848
- };
849
- const _decode = (_Err) => (schema, value, _ctx) => {
850
- return _parse(_Err)(schema, value, _ctx);
851
- };
852
- const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
853
- const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
854
- return _parseAsync(_Err)(schema, value, ctx);
855
- };
856
- const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
857
- return _parseAsync(_Err)(schema, value, _ctx);
858
- };
859
- const _safeEncode = (_Err) => (schema, value, _ctx) => {
860
- const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
861
- return _safeParse(_Err)(schema, value, ctx);
862
- };
863
- const _safeDecode = (_Err) => (schema, value, _ctx) => {
864
- return _safeParse(_Err)(schema, value, _ctx);
865
- };
866
- const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
867
- const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
868
- return _safeParseAsync(_Err)(schema, value, ctx);
869
- };
870
- const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
871
- return _safeParseAsync(_Err)(schema, value, _ctx);
872
- };
873
- //#endregion
874
- //#region ../../node_modules/zod/v4/core/regexes.js
875
- const cuid = /^[cC][^\s-]{8,}$/;
876
- const cuid2 = /^[0-9a-z]+$/;
877
- const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
878
- const xid = /^[0-9a-vA-V]{20}$/;
879
- const ksuid = /^[A-Za-z0-9]{27}$/;
880
- const nanoid = /^[a-zA-Z0-9_-]{21}$/;
881
- /** ISO 8601-1 duration regex. Does not support the 8601-2 extensions like negative durations or fractional/negative components. */
882
- 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)?)?)$/;
883
- /** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
884
- 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})$/;
885
- /** Returns a regex for validating an RFC 9562/4122 UUID.
886
- *
887
- * @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
888
- const uuid = (version) => {
889
- if (!version) 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)$/;
890
- return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
891
- };
892
- /** Practical email validation */
893
- const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
894
- const _emoji$1 = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
895
- function emoji() {
896
- return new RegExp(_emoji$1, "u");
897
- }
898
- 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])$/;
899
- 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}|:))$/;
900
- 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])$/;
901
- 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])$/;
902
- const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
903
- const base64url = /^[A-Za-z0-9_-]*$/;
904
- const e164 = /^\+[1-9]\d{6,14}$/;
905
- 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])))`;
906
- const date$1 = /* @__PURE__ */ new RegExp(`^${dateSource}$`);
907
- function timeSource(args) {
908
- const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
909
- return 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+)?)?`;
910
- }
911
- function time$1(args) {
912
- return new RegExp(`^${timeSource(args)}$`);
913
- }
914
- function datetime$1(args) {
915
- const time = timeSource({ precision: args.precision });
916
- const opts = ["Z"];
917
- if (args.local) opts.push("");
918
- if (args.offset) opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
919
- const timeRegex = `${time}(?:${opts.join("|")})`;
920
- return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
921
- }
922
- const string$1 = (params) => {
923
- const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
924
- return new RegExp(`^${regex}$`);
925
- };
926
- const lowercase = /^[^A-Z]*$/;
927
- const uppercase = /^[^a-z]*$/;
928
- //#endregion
929
- //#region ../../node_modules/zod/v4/core/checks.js
930
- const $ZodCheck = /* @__PURE__ */ $constructor("$ZodCheck", (inst, def) => {
931
- var _a;
932
- inst._zod ?? (inst._zod = {});
933
- inst._zod.def = def;
934
- (_a = inst._zod).onattach ?? (_a.onattach = []);
935
- });
936
- const $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (inst, def) => {
937
- var _a;
938
- $ZodCheck.init(inst, def);
939
- (_a = inst._zod.def).when ?? (_a.when = (payload) => {
940
- const val = payload.value;
941
- return !nullish(val) && val.length !== void 0;
942
- });
943
- inst._zod.onattach.push((inst) => {
944
- const curr = inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY;
945
- if (def.maximum < curr) inst._zod.bag.maximum = def.maximum;
946
- });
947
- inst._zod.check = (payload) => {
948
- const input = payload.value;
949
- if (input.length <= def.maximum) return;
950
- const origin = getLengthableOrigin(input);
951
- payload.issues.push({
952
- origin,
953
- code: "too_big",
954
- maximum: def.maximum,
955
- inclusive: true,
956
- input,
957
- inst,
958
- continue: !def.abort
959
- });
960
- };
961
- });
962
- const $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (inst, def) => {
963
- var _a;
964
- $ZodCheck.init(inst, def);
965
- (_a = inst._zod.def).when ?? (_a.when = (payload) => {
966
- const val = payload.value;
967
- return !nullish(val) && val.length !== void 0;
968
- });
969
- inst._zod.onattach.push((inst) => {
970
- const curr = inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY;
971
- if (def.minimum > curr) inst._zod.bag.minimum = def.minimum;
972
- });
973
- inst._zod.check = (payload) => {
974
- const input = payload.value;
975
- if (input.length >= def.minimum) return;
976
- const origin = getLengthableOrigin(input);
977
- payload.issues.push({
978
- origin,
979
- code: "too_small",
980
- minimum: def.minimum,
981
- inclusive: true,
982
- input,
983
- inst,
984
- continue: !def.abort
985
- });
986
- };
987
- });
988
- const $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEquals", (inst, def) => {
989
- var _a;
990
- $ZodCheck.init(inst, def);
991
- (_a = inst._zod.def).when ?? (_a.when = (payload) => {
992
- const val = payload.value;
993
- return !nullish(val) && val.length !== void 0;
994
- });
995
- inst._zod.onattach.push((inst) => {
996
- const bag = inst._zod.bag;
997
- bag.minimum = def.length;
998
- bag.maximum = def.length;
999
- bag.length = def.length;
1000
- });
1001
- inst._zod.check = (payload) => {
1002
- const input = payload.value;
1003
- const length = input.length;
1004
- if (length === def.length) return;
1005
- const origin = getLengthableOrigin(input);
1006
- const tooBig = length > def.length;
1007
- payload.issues.push({
1008
- origin,
1009
- ...tooBig ? {
1010
- code: "too_big",
1011
- maximum: def.length
1012
- } : {
1013
- code: "too_small",
1014
- minimum: def.length
1015
- },
1016
- inclusive: true,
1017
- exact: true,
1018
- input: payload.value,
1019
- inst,
1020
- continue: !def.abort
1021
- });
1022
- };
1023
- });
1024
- const $ZodCheckStringFormat = /* @__PURE__ */ $constructor("$ZodCheckStringFormat", (inst, def) => {
1025
- var _a, _b;
1026
- $ZodCheck.init(inst, def);
1027
- inst._zod.onattach.push((inst) => {
1028
- const bag = inst._zod.bag;
1029
- bag.format = def.format;
1030
- if (def.pattern) {
1031
- bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
1032
- bag.patterns.add(def.pattern);
1033
- }
1034
- });
1035
- if (def.pattern) (_a = inst._zod).check ?? (_a.check = (payload) => {
1036
- def.pattern.lastIndex = 0;
1037
- if (def.pattern.test(payload.value)) return;
1038
- payload.issues.push({
1039
- origin: "string",
1040
- code: "invalid_format",
1041
- format: def.format,
1042
- input: payload.value,
1043
- ...def.pattern ? { pattern: def.pattern.toString() } : {},
1044
- inst,
1045
- continue: !def.abort
1046
- });
1047
- });
1048
- else (_b = inst._zod).check ?? (_b.check = () => {});
1049
- });
1050
- const $ZodCheckRegex = /* @__PURE__ */ $constructor("$ZodCheckRegex", (inst, def) => {
1051
- $ZodCheckStringFormat.init(inst, def);
1052
- inst._zod.check = (payload) => {
1053
- def.pattern.lastIndex = 0;
1054
- if (def.pattern.test(payload.value)) return;
1055
- payload.issues.push({
1056
- origin: "string",
1057
- code: "invalid_format",
1058
- format: "regex",
1059
- input: payload.value,
1060
- pattern: def.pattern.toString(),
1061
- inst,
1062
- continue: !def.abort
1063
- });
1064
- };
1065
- });
1066
- const $ZodCheckLowerCase = /* @__PURE__ */ $constructor("$ZodCheckLowerCase", (inst, def) => {
1067
- def.pattern ?? (def.pattern = lowercase);
1068
- $ZodCheckStringFormat.init(inst, def);
1069
- });
1070
- const $ZodCheckUpperCase = /* @__PURE__ */ $constructor("$ZodCheckUpperCase", (inst, def) => {
1071
- def.pattern ?? (def.pattern = uppercase);
1072
- $ZodCheckStringFormat.init(inst, def);
1073
- });
1074
- const $ZodCheckIncludes = /* @__PURE__ */ $constructor("$ZodCheckIncludes", (inst, def) => {
1075
- $ZodCheck.init(inst, def);
1076
- const escapedRegex = escapeRegex(def.includes);
1077
- const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
1078
- def.pattern = pattern;
1079
- inst._zod.onattach.push((inst) => {
1080
- const bag = inst._zod.bag;
1081
- bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
1082
- bag.patterns.add(pattern);
1083
- });
1084
- inst._zod.check = (payload) => {
1085
- if (payload.value.includes(def.includes, def.position)) return;
1086
- payload.issues.push({
1087
- origin: "string",
1088
- code: "invalid_format",
1089
- format: "includes",
1090
- includes: def.includes,
1091
- input: payload.value,
1092
- inst,
1093
- continue: !def.abort
1094
- });
1095
- };
1096
- });
1097
- const $ZodCheckStartsWith = /* @__PURE__ */ $constructor("$ZodCheckStartsWith", (inst, def) => {
1098
- $ZodCheck.init(inst, def);
1099
- const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
1100
- def.pattern ?? (def.pattern = pattern);
1101
- inst._zod.onattach.push((inst) => {
1102
- const bag = inst._zod.bag;
1103
- bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
1104
- bag.patterns.add(pattern);
1105
- });
1106
- inst._zod.check = (payload) => {
1107
- if (payload.value.startsWith(def.prefix)) return;
1108
- payload.issues.push({
1109
- origin: "string",
1110
- code: "invalid_format",
1111
- format: "starts_with",
1112
- prefix: def.prefix,
1113
- input: payload.value,
1114
- inst,
1115
- continue: !def.abort
1116
- });
1117
- };
1118
- });
1119
- const $ZodCheckEndsWith = /* @__PURE__ */ $constructor("$ZodCheckEndsWith", (inst, def) => {
1120
- $ZodCheck.init(inst, def);
1121
- const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
1122
- def.pattern ?? (def.pattern = pattern);
1123
- inst._zod.onattach.push((inst) => {
1124
- const bag = inst._zod.bag;
1125
- bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
1126
- bag.patterns.add(pattern);
1127
- });
1128
- inst._zod.check = (payload) => {
1129
- if (payload.value.endsWith(def.suffix)) return;
1130
- payload.issues.push({
1131
- origin: "string",
1132
- code: "invalid_format",
1133
- format: "ends_with",
1134
- suffix: def.suffix,
1135
- input: payload.value,
1136
- inst,
1137
- continue: !def.abort
1138
- });
1139
- };
1140
- });
1141
- const $ZodCheckOverwrite = /* @__PURE__ */ $constructor("$ZodCheckOverwrite", (inst, def) => {
1142
- $ZodCheck.init(inst, def);
1143
- inst._zod.check = (payload) => {
1144
- payload.value = def.tx(payload.value);
1145
- };
1146
- });
1147
- //#endregion
1148
- //#region ../../node_modules/zod/v4/core/doc.js
1149
- var Doc = class {
1150
- constructor(args = []) {
1151
- this.content = [];
1152
- this.indent = 0;
1153
- if (this) this.args = args;
1154
- }
1155
- indented(fn) {
1156
- this.indent += 1;
1157
- fn(this);
1158
- this.indent -= 1;
1159
- }
1160
- write(arg) {
1161
- if (typeof arg === "function") {
1162
- arg(this, { execution: "sync" });
1163
- arg(this, { execution: "async" });
1164
- return;
1165
- }
1166
- const lines = arg.split("\n").filter((x) => x);
1167
- const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
1168
- const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
1169
- for (const line of dedented) this.content.push(line);
1170
- }
1171
- compile() {
1172
- const F = Function;
1173
- const args = this?.args;
1174
- const lines = [...(this?.content ?? [``]).map((x) => ` ${x}`)];
1175
- return new F(...args, lines.join("\n"));
1176
- }
1177
- };
1178
- //#endregion
1179
- //#region ../../node_modules/zod/v4/core/versions.js
1180
- const version = {
1181
- major: 4,
1182
- minor: 3,
1183
- patch: 6
1184
- };
1185
- //#endregion
1186
- //#region ../../node_modules/zod/v4/core/schemas.js
1187
- const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
1188
- var _a;
1189
- inst ?? (inst = {});
1190
- inst._zod.def = def;
1191
- inst._zod.bag = inst._zod.bag || {};
1192
- inst._zod.version = version;
1193
- const checks = [...inst._zod.def.checks ?? []];
1194
- if (inst._zod.traits.has("$ZodCheck")) checks.unshift(inst);
1195
- for (const ch of checks) for (const fn of ch._zod.onattach) fn(inst);
1196
- if (checks.length === 0) {
1197
- (_a = inst._zod).deferred ?? (_a.deferred = []);
1198
- inst._zod.deferred?.push(() => {
1199
- inst._zod.run = inst._zod.parse;
1200
- });
1201
- } else {
1202
- const runChecks = (payload, checks, ctx) => {
1203
- let isAborted = aborted(payload);
1204
- let asyncResult;
1205
- for (const ch of checks) {
1206
- if (ch._zod.def.when) {
1207
- if (!ch._zod.def.when(payload)) continue;
1208
- } else if (isAborted) continue;
1209
- const currLen = payload.issues.length;
1210
- const _ = ch._zod.check(payload);
1211
- if (_ instanceof Promise && ctx?.async === false) throw new $ZodAsyncError();
1212
- if (asyncResult || _ instanceof Promise) asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
1213
- await _;
1214
- if (payload.issues.length === currLen) return;
1215
- if (!isAborted) isAborted = aborted(payload, currLen);
1216
- });
1217
- else {
1218
- if (payload.issues.length === currLen) continue;
1219
- if (!isAborted) isAborted = aborted(payload, currLen);
1220
- }
1221
- }
1222
- if (asyncResult) return asyncResult.then(() => {
1223
- return payload;
1224
- });
1225
- return payload;
1226
- };
1227
- const handleCanaryResult = (canary, payload, ctx) => {
1228
- if (aborted(canary)) {
1229
- canary.aborted = true;
1230
- return canary;
1231
- }
1232
- const checkResult = runChecks(payload, checks, ctx);
1233
- if (checkResult instanceof Promise) {
1234
- if (ctx.async === false) throw new $ZodAsyncError();
1235
- return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
1236
- }
1237
- return inst._zod.parse(checkResult, ctx);
1238
- };
1239
- inst._zod.run = (payload, ctx) => {
1240
- if (ctx.skipChecks) return inst._zod.parse(payload, ctx);
1241
- if (ctx.direction === "backward") {
1242
- const canary = inst._zod.parse({
1243
- value: payload.value,
1244
- issues: []
1245
- }, {
1246
- ...ctx,
1247
- skipChecks: true
1248
- });
1249
- if (canary instanceof Promise) return canary.then((canary) => {
1250
- return handleCanaryResult(canary, payload, ctx);
1251
- });
1252
- return handleCanaryResult(canary, payload, ctx);
1253
- }
1254
- const result = inst._zod.parse(payload, ctx);
1255
- if (result instanceof Promise) {
1256
- if (ctx.async === false) throw new $ZodAsyncError();
1257
- return result.then((result) => runChecks(result, checks, ctx));
1258
- }
1259
- return runChecks(result, checks, ctx);
1260
- };
1261
- }
1262
- defineLazy(inst, "~standard", () => ({
1263
- validate: (value) => {
1264
- try {
1265
- const r = safeParse$1(inst, value);
1266
- return r.success ? { value: r.data } : { issues: r.error?.issues };
1267
- } catch (_) {
1268
- return safeParseAsync$1(inst, value).then((r) => r.success ? { value: r.data } : { issues: r.error?.issues });
1269
- }
1270
- },
1271
- vendor: "zod",
1272
- version: 1
1273
- }));
1274
- });
1275
- const $ZodString = /* @__PURE__ */ $constructor("$ZodString", (inst, def) => {
1276
- $ZodType.init(inst, def);
1277
- inst._zod.pattern = [...inst?._zod.bag?.patterns ?? []].pop() ?? string$1(inst._zod.bag);
1278
- inst._zod.parse = (payload, _) => {
1279
- if (def.coerce) try {
1280
- payload.value = String(payload.value);
1281
- } catch (_) {}
1282
- if (typeof payload.value === "string") return payload;
1283
- payload.issues.push({
1284
- expected: "string",
1285
- code: "invalid_type",
1286
- input: payload.value,
1287
- inst
1288
- });
1289
- return payload;
1290
- };
1291
- });
1292
- const $ZodStringFormat = /* @__PURE__ */ $constructor("$ZodStringFormat", (inst, def) => {
1293
- $ZodCheckStringFormat.init(inst, def);
1294
- $ZodString.init(inst, def);
1295
- });
1296
- const $ZodGUID = /* @__PURE__ */ $constructor("$ZodGUID", (inst, def) => {
1297
- def.pattern ?? (def.pattern = guid);
1298
- $ZodStringFormat.init(inst, def);
1299
- });
1300
- const $ZodUUID = /* @__PURE__ */ $constructor("$ZodUUID", (inst, def) => {
1301
- if (def.version) {
1302
- const v = {
1303
- v1: 1,
1304
- v2: 2,
1305
- v3: 3,
1306
- v4: 4,
1307
- v5: 5,
1308
- v6: 6,
1309
- v7: 7,
1310
- v8: 8
1311
- }[def.version];
1312
- if (v === void 0) throw new Error(`Invalid UUID version: "${def.version}"`);
1313
- def.pattern ?? (def.pattern = uuid(v));
1314
- } else def.pattern ?? (def.pattern = uuid());
1315
- $ZodStringFormat.init(inst, def);
1316
- });
1317
- const $ZodEmail = /* @__PURE__ */ $constructor("$ZodEmail", (inst, def) => {
1318
- def.pattern ?? (def.pattern = email);
1319
- $ZodStringFormat.init(inst, def);
1320
- });
1321
- const $ZodURL = /* @__PURE__ */ $constructor("$ZodURL", (inst, def) => {
1322
- $ZodStringFormat.init(inst, def);
1323
- inst._zod.check = (payload) => {
1324
- try {
1325
- const trimmed = payload.value.trim();
1326
- const url = new URL(trimmed);
1327
- if (def.hostname) {
1328
- def.hostname.lastIndex = 0;
1329
- if (!def.hostname.test(url.hostname)) payload.issues.push({
1330
- code: "invalid_format",
1331
- format: "url",
1332
- note: "Invalid hostname",
1333
- pattern: def.hostname.source,
1334
- input: payload.value,
1335
- inst,
1336
- continue: !def.abort
1337
- });
1338
- }
1339
- if (def.protocol) {
1340
- def.protocol.lastIndex = 0;
1341
- if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) payload.issues.push({
1342
- code: "invalid_format",
1343
- format: "url",
1344
- note: "Invalid protocol",
1345
- pattern: def.protocol.source,
1346
- input: payload.value,
1347
- inst,
1348
- continue: !def.abort
1349
- });
1350
- }
1351
- if (def.normalize) payload.value = url.href;
1352
- else payload.value = trimmed;
1353
- return;
1354
- } catch (_) {
1355
- payload.issues.push({
1356
- code: "invalid_format",
1357
- format: "url",
1358
- input: payload.value,
1359
- inst,
1360
- continue: !def.abort
1361
- });
1362
- }
1363
- };
1364
- });
1365
- const $ZodEmoji = /* @__PURE__ */ $constructor("$ZodEmoji", (inst, def) => {
1366
- def.pattern ?? (def.pattern = emoji());
1367
- $ZodStringFormat.init(inst, def);
1368
- });
1369
- const $ZodNanoID = /* @__PURE__ */ $constructor("$ZodNanoID", (inst, def) => {
1370
- def.pattern ?? (def.pattern = nanoid);
1371
- $ZodStringFormat.init(inst, def);
1372
- });
1373
- const $ZodCUID = /* @__PURE__ */ $constructor("$ZodCUID", (inst, def) => {
1374
- def.pattern ?? (def.pattern = cuid);
1375
- $ZodStringFormat.init(inst, def);
1376
- });
1377
- const $ZodCUID2 = /* @__PURE__ */ $constructor("$ZodCUID2", (inst, def) => {
1378
- def.pattern ?? (def.pattern = cuid2);
1379
- $ZodStringFormat.init(inst, def);
1380
- });
1381
- const $ZodULID = /* @__PURE__ */ $constructor("$ZodULID", (inst, def) => {
1382
- def.pattern ?? (def.pattern = ulid);
1383
- $ZodStringFormat.init(inst, def);
1384
- });
1385
- const $ZodXID = /* @__PURE__ */ $constructor("$ZodXID", (inst, def) => {
1386
- def.pattern ?? (def.pattern = xid);
1387
- $ZodStringFormat.init(inst, def);
1388
- });
1389
- const $ZodKSUID = /* @__PURE__ */ $constructor("$ZodKSUID", (inst, def) => {
1390
- def.pattern ?? (def.pattern = ksuid);
1391
- $ZodStringFormat.init(inst, def);
1392
- });
1393
- const $ZodISODateTime = /* @__PURE__ */ $constructor("$ZodISODateTime", (inst, def) => {
1394
- def.pattern ?? (def.pattern = datetime$1(def));
1395
- $ZodStringFormat.init(inst, def);
1396
- });
1397
- const $ZodISODate = /* @__PURE__ */ $constructor("$ZodISODate", (inst, def) => {
1398
- def.pattern ?? (def.pattern = date$1);
1399
- $ZodStringFormat.init(inst, def);
1400
- });
1401
- const $ZodISOTime = /* @__PURE__ */ $constructor("$ZodISOTime", (inst, def) => {
1402
- def.pattern ?? (def.pattern = time$1(def));
1403
- $ZodStringFormat.init(inst, def);
1404
- });
1405
- const $ZodISODuration = /* @__PURE__ */ $constructor("$ZodISODuration", (inst, def) => {
1406
- def.pattern ?? (def.pattern = duration$1);
1407
- $ZodStringFormat.init(inst, def);
1408
- });
1409
- const $ZodIPv4 = /* @__PURE__ */ $constructor("$ZodIPv4", (inst, def) => {
1410
- def.pattern ?? (def.pattern = ipv4);
1411
- $ZodStringFormat.init(inst, def);
1412
- inst._zod.bag.format = `ipv4`;
1413
- });
1414
- const $ZodIPv6 = /* @__PURE__ */ $constructor("$ZodIPv6", (inst, def) => {
1415
- def.pattern ?? (def.pattern = ipv6);
1416
- $ZodStringFormat.init(inst, def);
1417
- inst._zod.bag.format = `ipv6`;
1418
- inst._zod.check = (payload) => {
1419
- try {
1420
- new URL(`http://[${payload.value}]`);
1421
- } catch {
1422
- payload.issues.push({
1423
- code: "invalid_format",
1424
- format: "ipv6",
1425
- input: payload.value,
1426
- inst,
1427
- continue: !def.abort
1428
- });
1429
- }
1430
- };
1431
- });
1432
- const $ZodCIDRv4 = /* @__PURE__ */ $constructor("$ZodCIDRv4", (inst, def) => {
1433
- def.pattern ?? (def.pattern = cidrv4);
1434
- $ZodStringFormat.init(inst, def);
1435
- });
1436
- const $ZodCIDRv6 = /* @__PURE__ */ $constructor("$ZodCIDRv6", (inst, def) => {
1437
- def.pattern ?? (def.pattern = cidrv6);
1438
- $ZodStringFormat.init(inst, def);
1439
- inst._zod.check = (payload) => {
1440
- const parts = payload.value.split("/");
1441
- try {
1442
- if (parts.length !== 2) throw new Error();
1443
- const [address, prefix] = parts;
1444
- if (!prefix) throw new Error();
1445
- const prefixNum = Number(prefix);
1446
- if (`${prefixNum}` !== prefix) throw new Error();
1447
- if (prefixNum < 0 || prefixNum > 128) throw new Error();
1448
- new URL(`http://[${address}]`);
1449
- } catch {
1450
- payload.issues.push({
1451
- code: "invalid_format",
1452
- format: "cidrv6",
1453
- input: payload.value,
1454
- inst,
1455
- continue: !def.abort
1456
- });
1457
- }
1458
- };
1459
- });
1460
- function isValidBase64(data) {
1461
- if (data === "") return true;
1462
- if (data.length % 4 !== 0) return false;
1463
- try {
1464
- atob(data);
1465
- return true;
1466
- } catch {
1467
- return false;
1468
- }
1469
- }
1470
- const $ZodBase64 = /* @__PURE__ */ $constructor("$ZodBase64", (inst, def) => {
1471
- def.pattern ?? (def.pattern = base64);
1472
- $ZodStringFormat.init(inst, def);
1473
- inst._zod.bag.contentEncoding = "base64";
1474
- inst._zod.check = (payload) => {
1475
- if (isValidBase64(payload.value)) return;
1476
- payload.issues.push({
1477
- code: "invalid_format",
1478
- format: "base64",
1479
- input: payload.value,
1480
- inst,
1481
- continue: !def.abort
1482
- });
1483
- };
1484
- });
1485
- function isValidBase64URL(data) {
1486
- if (!base64url.test(data)) return false;
1487
- const base64 = data.replace(/[-_]/g, (c) => c === "-" ? "+" : "/");
1488
- return isValidBase64(base64.padEnd(Math.ceil(base64.length / 4) * 4, "="));
1489
- }
1490
- const $ZodBase64URL = /* @__PURE__ */ $constructor("$ZodBase64URL", (inst, def) => {
1491
- def.pattern ?? (def.pattern = base64url);
1492
- $ZodStringFormat.init(inst, def);
1493
- inst._zod.bag.contentEncoding = "base64url";
1494
- inst._zod.check = (payload) => {
1495
- if (isValidBase64URL(payload.value)) return;
1496
- payload.issues.push({
1497
- code: "invalid_format",
1498
- format: "base64url",
1499
- input: payload.value,
1500
- inst,
1501
- continue: !def.abort
1502
- });
1503
- };
1504
- });
1505
- const $ZodE164 = /* @__PURE__ */ $constructor("$ZodE164", (inst, def) => {
1506
- def.pattern ?? (def.pattern = e164);
1507
- $ZodStringFormat.init(inst, def);
1508
- });
1509
- function isValidJWT(token, algorithm = null) {
1510
- try {
1511
- const tokensParts = token.split(".");
1512
- if (tokensParts.length !== 3) return false;
1513
- const [header] = tokensParts;
1514
- if (!header) return false;
1515
- const parsedHeader = JSON.parse(atob(header));
1516
- if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT") return false;
1517
- if (!parsedHeader.alg) return false;
1518
- if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm)) return false;
1519
- return true;
1520
- } catch {
1521
- return false;
1522
- }
1523
- }
1524
- const $ZodJWT = /* @__PURE__ */ $constructor("$ZodJWT", (inst, def) => {
1525
- $ZodStringFormat.init(inst, def);
1526
- inst._zod.check = (payload) => {
1527
- if (isValidJWT(payload.value, def.alg)) return;
1528
- payload.issues.push({
1529
- code: "invalid_format",
1530
- format: "jwt",
1531
- input: payload.value,
1532
- inst,
1533
- continue: !def.abort
1534
- });
1535
- };
1536
- });
1537
- const $ZodUnknown = /* @__PURE__ */ $constructor("$ZodUnknown", (inst, def) => {
1538
- $ZodType.init(inst, def);
1539
- inst._zod.parse = (payload) => payload;
1540
- });
1541
- const $ZodNever = /* @__PURE__ */ $constructor("$ZodNever", (inst, def) => {
1542
- $ZodType.init(inst, def);
1543
- inst._zod.parse = (payload, _ctx) => {
1544
- payload.issues.push({
1545
- expected: "never",
1546
- code: "invalid_type",
1547
- input: payload.value,
1548
- inst
1549
- });
1550
- return payload;
1551
- };
1552
- });
1553
- function handleArrayResult(result, final, index) {
1554
- if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
1555
- final.value[index] = result.value;
1556
- }
1557
- const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
1558
- $ZodType.init(inst, def);
1559
- inst._zod.parse = (payload, ctx) => {
1560
- const input = payload.value;
1561
- if (!Array.isArray(input)) {
1562
- payload.issues.push({
1563
- expected: "array",
1564
- code: "invalid_type",
1565
- input,
1566
- inst
1567
- });
1568
- return payload;
1569
- }
1570
- payload.value = Array(input.length);
1571
- const proms = [];
1572
- for (let i = 0; i < input.length; i++) {
1573
- const item = input[i];
1574
- const result = def.element._zod.run({
1575
- value: item,
1576
- issues: []
1577
- }, ctx);
1578
- if (result instanceof Promise) proms.push(result.then((result) => handleArrayResult(result, payload, i)));
1579
- else handleArrayResult(result, payload, i);
1580
- }
1581
- if (proms.length) return Promise.all(proms).then(() => payload);
1582
- return payload;
1583
- };
1584
- });
1585
- function handlePropertyResult(result, final, key, input, isOptionalOut) {
1586
- if (result.issues.length) {
1587
- if (isOptionalOut && !(key in input)) return;
1588
- final.issues.push(...prefixIssues(key, result.issues));
1589
- }
1590
- if (result.value === void 0) {
1591
- if (key in input) final.value[key] = void 0;
1592
- } else final.value[key] = result.value;
1593
- }
1594
- function normalizeDef(def) {
1595
- const keys = Object.keys(def.shape);
1596
- for (const k of keys) if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
1597
- const okeys = optionalKeys(def.shape);
1598
- return {
1599
- ...def,
1600
- keys,
1601
- keySet: new Set(keys),
1602
- numKeys: keys.length,
1603
- optionalKeys: new Set(okeys)
1604
- };
1605
- }
1606
- function handleCatchall(proms, input, payload, ctx, def, inst) {
1607
- const unrecognized = [];
1608
- const keySet = def.keySet;
1609
- const _catchall = def.catchall._zod;
1610
- const t = _catchall.def.type;
1611
- const isOptionalOut = _catchall.optout === "optional";
1612
- for (const key in input) {
1613
- if (keySet.has(key)) continue;
1614
- if (t === "never") {
1615
- unrecognized.push(key);
1616
- continue;
1617
- }
1618
- const r = _catchall.run({
1619
- value: input[key],
1620
- issues: []
1621
- }, ctx);
1622
- if (r instanceof Promise) proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
1623
- else handlePropertyResult(r, payload, key, input, isOptionalOut);
1624
- }
1625
- if (unrecognized.length) payload.issues.push({
1626
- code: "unrecognized_keys",
1627
- keys: unrecognized,
1628
- input,
1629
- inst
1630
- });
1631
- if (!proms.length) return payload;
1632
- return Promise.all(proms).then(() => {
1633
- return payload;
1634
- });
1635
- }
1636
- const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
1637
- $ZodType.init(inst, def);
1638
- if (!Object.getOwnPropertyDescriptor(def, "shape")?.get) {
1639
- const sh = def.shape;
1640
- Object.defineProperty(def, "shape", { get: () => {
1641
- const newSh = { ...sh };
1642
- Object.defineProperty(def, "shape", { value: newSh });
1643
- return newSh;
1644
- } });
1645
- }
1646
- const _normalized = cached(() => normalizeDef(def));
1647
- defineLazy(inst._zod, "propValues", () => {
1648
- const shape = def.shape;
1649
- const propValues = {};
1650
- for (const key in shape) {
1651
- const field = shape[key]._zod;
1652
- if (field.values) {
1653
- propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
1654
- for (const v of field.values) propValues[key].add(v);
1655
- }
1656
- }
1657
- return propValues;
1658
- });
1659
- const isObject$2 = isObject;
1660
- const catchall = def.catchall;
1661
- let value;
1662
- inst._zod.parse = (payload, ctx) => {
1663
- value ?? (value = _normalized.value);
1664
- const input = payload.value;
1665
- if (!isObject$2(input)) {
1666
- payload.issues.push({
1667
- expected: "object",
1668
- code: "invalid_type",
1669
- input,
1670
- inst
1671
- });
1672
- return payload;
1673
- }
1674
- payload.value = {};
1675
- const proms = [];
1676
- const shape = value.shape;
1677
- for (const key of value.keys) {
1678
- const el = shape[key];
1679
- const isOptionalOut = el._zod.optout === "optional";
1680
- const r = el._zod.run({
1681
- value: input[key],
1682
- issues: []
1683
- }, ctx);
1684
- if (r instanceof Promise) proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
1685
- else handlePropertyResult(r, payload, key, input, isOptionalOut);
1686
- }
1687
- if (!catchall) return proms.length ? Promise.all(proms).then(() => payload) : payload;
1688
- return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
1689
- };
1690
- });
1691
- const $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) => {
1692
- $ZodObject.init(inst, def);
1693
- const superParse = inst._zod.parse;
1694
- const _normalized = cached(() => normalizeDef(def));
1695
- const generateFastpass = (shape) => {
1696
- const doc = new Doc([
1697
- "shape",
1698
- "payload",
1699
- "ctx"
1700
- ]);
1701
- const normalized = _normalized.value;
1702
- const parseStr = (key) => {
1703
- const k = esc(key);
1704
- return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
1705
- };
1706
- doc.write(`const input = payload.value;`);
1707
- const ids = Object.create(null);
1708
- let counter = 0;
1709
- for (const key of normalized.keys) ids[key] = `key_${counter++}`;
1710
- doc.write(`const newResult = {};`);
1711
- for (const key of normalized.keys) {
1712
- const id = ids[key];
1713
- const k = esc(key);
1714
- const isOptionalOut = shape[key]?._zod?.optout === "optional";
1715
- doc.write(`const ${id} = ${parseStr(key)};`);
1716
- if (isOptionalOut) doc.write(`
1717
- if (${id}.issues.length) {
1718
- if (${k} in input) {
1719
- payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1720
- ...iss,
1721
- path: iss.path ? [${k}, ...iss.path] : [${k}]
1722
- })));
1723
- }
1724
- }
1725
-
1726
- if (${id}.value === undefined) {
1727
- if (${k} in input) {
1728
- newResult[${k}] = undefined;
1729
- }
1730
- } else {
1731
- newResult[${k}] = ${id}.value;
1732
- }
1733
-
1734
- `);
1735
- else doc.write(`
1736
- if (${id}.issues.length) {
1737
- payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1738
- ...iss,
1739
- path: iss.path ? [${k}, ...iss.path] : [${k}]
1740
- })));
1741
- }
1742
-
1743
- if (${id}.value === undefined) {
1744
- if (${k} in input) {
1745
- newResult[${k}] = undefined;
1746
- }
1747
- } else {
1748
- newResult[${k}] = ${id}.value;
1749
- }
1750
-
1751
- `);
1752
- }
1753
- doc.write(`payload.value = newResult;`);
1754
- doc.write(`return payload;`);
1755
- const fn = doc.compile();
1756
- return (payload, ctx) => fn(shape, payload, ctx);
1757
- };
1758
- let fastpass;
1759
- const isObject$1 = isObject;
1760
- const jit = !globalConfig.jitless;
1761
- const fastEnabled = jit && allowsEval.value;
1762
- const catchall = def.catchall;
1763
- let value;
1764
- inst._zod.parse = (payload, ctx) => {
1765
- value ?? (value = _normalized.value);
1766
- const input = payload.value;
1767
- if (!isObject$1(input)) {
1768
- payload.issues.push({
1769
- expected: "object",
1770
- code: "invalid_type",
1771
- input,
1772
- inst
1773
- });
1774
- return payload;
1775
- }
1776
- if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
1777
- if (!fastpass) fastpass = generateFastpass(def.shape);
1778
- payload = fastpass(payload, ctx);
1779
- if (!catchall) return payload;
1780
- return handleCatchall([], input, payload, ctx, value, inst);
1781
- }
1782
- return superParse(payload, ctx);
1783
- };
1784
- });
1785
- function handleUnionResults(results, final, inst, ctx) {
1786
- for (const result of results) if (result.issues.length === 0) {
1787
- final.value = result.value;
1788
- return final;
1789
- }
1790
- const nonaborted = results.filter((r) => !aborted(r));
1791
- if (nonaborted.length === 1) {
1792
- final.value = nonaborted[0].value;
1793
- return nonaborted[0];
1794
- }
1795
- final.issues.push({
1796
- code: "invalid_union",
1797
- input: final.value,
1798
- inst,
1799
- errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
1800
- });
1801
- return final;
1802
- }
1803
- const $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
1804
- $ZodType.init(inst, def);
1805
- defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : void 0);
1806
- defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
1807
- defineLazy(inst._zod, "values", () => {
1808
- if (def.options.every((o) => o._zod.values)) return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
1809
- });
1810
- defineLazy(inst._zod, "pattern", () => {
1811
- if (def.options.every((o) => o._zod.pattern)) {
1812
- const patterns = def.options.map((o) => o._zod.pattern);
1813
- return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
1814
- }
1815
- });
1816
- const single = def.options.length === 1;
1817
- const first = def.options[0]._zod.run;
1818
- inst._zod.parse = (payload, ctx) => {
1819
- if (single) return first(payload, ctx);
1820
- let async = false;
1821
- const results = [];
1822
- for (const option of def.options) {
1823
- const result = option._zod.run({
1824
- value: payload.value,
1825
- issues: []
1826
- }, ctx);
1827
- if (result instanceof Promise) {
1828
- results.push(result);
1829
- async = true;
1830
- } else {
1831
- if (result.issues.length === 0) return result;
1832
- results.push(result);
1833
- }
1834
- }
1835
- if (!async) return handleUnionResults(results, payload, inst, ctx);
1836
- return Promise.all(results).then((results) => {
1837
- return handleUnionResults(results, payload, inst, ctx);
1838
- });
1839
- };
1840
- });
1841
- const $ZodIntersection = /* @__PURE__ */ $constructor("$ZodIntersection", (inst, def) => {
1842
- $ZodType.init(inst, def);
1843
- inst._zod.parse = (payload, ctx) => {
1844
- const input = payload.value;
1845
- const left = def.left._zod.run({
1846
- value: input,
1847
- issues: []
1848
- }, ctx);
1849
- const right = def.right._zod.run({
1850
- value: input,
1851
- issues: []
1852
- }, ctx);
1853
- if (left instanceof Promise || right instanceof Promise) return Promise.all([left, right]).then(([left, right]) => {
1854
- return handleIntersectionResults(payload, left, right);
1855
- });
1856
- return handleIntersectionResults(payload, left, right);
1857
- };
1858
- });
1859
- function mergeValues(a, b) {
1860
- if (a === b) return {
1861
- valid: true,
1862
- data: a
1863
- };
1864
- if (a instanceof Date && b instanceof Date && +a === +b) return {
1865
- valid: true,
1866
- data: a
1867
- };
1868
- if (isPlainObject(a) && isPlainObject(b)) {
1869
- const bKeys = Object.keys(b);
1870
- const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
1871
- const newObj = {
1872
- ...a,
1873
- ...b
1874
- };
1875
- for (const key of sharedKeys) {
1876
- const sharedValue = mergeValues(a[key], b[key]);
1877
- if (!sharedValue.valid) return {
1878
- valid: false,
1879
- mergeErrorPath: [key, ...sharedValue.mergeErrorPath]
1880
- };
1881
- newObj[key] = sharedValue.data;
1882
- }
1883
- return {
1884
- valid: true,
1885
- data: newObj
1886
- };
1887
- }
1888
- if (Array.isArray(a) && Array.isArray(b)) {
1889
- if (a.length !== b.length) return {
1890
- valid: false,
1891
- mergeErrorPath: []
1892
- };
1893
- const newArray = [];
1894
- for (let index = 0; index < a.length; index++) {
1895
- const itemA = a[index];
1896
- const itemB = b[index];
1897
- const sharedValue = mergeValues(itemA, itemB);
1898
- if (!sharedValue.valid) return {
1899
- valid: false,
1900
- mergeErrorPath: [index, ...sharedValue.mergeErrorPath]
1901
- };
1902
- newArray.push(sharedValue.data);
1903
- }
1904
- return {
1905
- valid: true,
1906
- data: newArray
1907
- };
1908
- }
1909
- return {
1910
- valid: false,
1911
- mergeErrorPath: []
1912
- };
1913
- }
1914
- function handleIntersectionResults(result, left, right) {
1915
- const unrecKeys = /* @__PURE__ */ new Map();
1916
- let unrecIssue;
1917
- for (const iss of left.issues) if (iss.code === "unrecognized_keys") {
1918
- unrecIssue ?? (unrecIssue = iss);
1919
- for (const k of iss.keys) {
1920
- if (!unrecKeys.has(k)) unrecKeys.set(k, {});
1921
- unrecKeys.get(k).l = true;
1922
- }
1923
- } else result.issues.push(iss);
1924
- for (const iss of right.issues) if (iss.code === "unrecognized_keys") for (const k of iss.keys) {
1925
- if (!unrecKeys.has(k)) unrecKeys.set(k, {});
1926
- unrecKeys.get(k).r = true;
1927
- }
1928
- else result.issues.push(iss);
1929
- const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
1930
- if (bothKeys.length && unrecIssue) result.issues.push({
1931
- ...unrecIssue,
1932
- keys: bothKeys
1933
- });
1934
- if (aborted(result)) return result;
1935
- const merged = mergeValues(left.value, right.value);
1936
- if (!merged.valid) throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
1937
- result.value = merged.data;
1938
- return result;
1939
- }
1940
- const $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
1941
- $ZodType.init(inst, def);
1942
- const values = getEnumValues(def.entries);
1943
- const valuesSet = new Set(values);
1944
- inst._zod.values = valuesSet;
1945
- inst._zod.pattern = new RegExp(`^(${values.filter((k) => propertyKeyTypes.has(typeof k)).map((o) => typeof o === "string" ? escapeRegex(o) : o.toString()).join("|")})$`);
1946
- inst._zod.parse = (payload, _ctx) => {
1947
- const input = payload.value;
1948
- if (valuesSet.has(input)) return payload;
1949
- payload.issues.push({
1950
- code: "invalid_value",
1951
- values,
1952
- input,
1953
- inst
1954
- });
1955
- return payload;
1956
- };
1957
- });
1958
- const $ZodTransform = /* @__PURE__ */ $constructor("$ZodTransform", (inst, def) => {
1959
- $ZodType.init(inst, def);
1960
- inst._zod.parse = (payload, ctx) => {
1961
- if (ctx.direction === "backward") throw new $ZodEncodeError(inst.constructor.name);
1962
- const _out = def.transform(payload.value, payload);
1963
- if (ctx.async) return (_out instanceof Promise ? _out : Promise.resolve(_out)).then((output) => {
1964
- payload.value = output;
1965
- return payload;
1966
- });
1967
- if (_out instanceof Promise) throw new $ZodAsyncError();
1968
- payload.value = _out;
1969
- return payload;
1970
- };
1971
- });
1972
- function handleOptionalResult(result, input) {
1973
- if (result.issues.length && input === void 0) return {
1974
- issues: [],
1975
- value: void 0
1976
- };
1977
- return result;
1978
- }
1979
- const $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) => {
1980
- $ZodType.init(inst, def);
1981
- inst._zod.optin = "optional";
1982
- inst._zod.optout = "optional";
1983
- defineLazy(inst._zod, "values", () => {
1984
- return def.innerType._zod.values ? new Set([...def.innerType._zod.values, void 0]) : void 0;
1985
- });
1986
- defineLazy(inst._zod, "pattern", () => {
1987
- const pattern = def.innerType._zod.pattern;
1988
- return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
1989
- });
1990
- inst._zod.parse = (payload, ctx) => {
1991
- if (def.innerType._zod.optin === "optional") {
1992
- const result = def.innerType._zod.run(payload, ctx);
1993
- if (result instanceof Promise) return result.then((r) => handleOptionalResult(r, payload.value));
1994
- return handleOptionalResult(result, payload.value);
1995
- }
1996
- if (payload.value === void 0) return payload;
1997
- return def.innerType._zod.run(payload, ctx);
1998
- };
1999
- });
2000
- const $ZodExactOptional = /* @__PURE__ */ $constructor("$ZodExactOptional", (inst, def) => {
2001
- $ZodOptional.init(inst, def);
2002
- defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2003
- defineLazy(inst._zod, "pattern", () => def.innerType._zod.pattern);
2004
- inst._zod.parse = (payload, ctx) => {
2005
- return def.innerType._zod.run(payload, ctx);
2006
- };
2007
- });
2008
- const $ZodNullable = /* @__PURE__ */ $constructor("$ZodNullable", (inst, def) => {
2009
- $ZodType.init(inst, def);
2010
- defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
2011
- defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
2012
- defineLazy(inst._zod, "pattern", () => {
2013
- const pattern = def.innerType._zod.pattern;
2014
- return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
2015
- });
2016
- defineLazy(inst._zod, "values", () => {
2017
- return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : void 0;
2018
- });
2019
- inst._zod.parse = (payload, ctx) => {
2020
- if (payload.value === null) return payload;
2021
- return def.innerType._zod.run(payload, ctx);
2022
- };
2023
- });
2024
- const $ZodDefault = /* @__PURE__ */ $constructor("$ZodDefault", (inst, def) => {
2025
- $ZodType.init(inst, def);
2026
- inst._zod.optin = "optional";
2027
- defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2028
- inst._zod.parse = (payload, ctx) => {
2029
- if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
2030
- if (payload.value === void 0) {
2031
- payload.value = def.defaultValue;
2032
- /**
2033
- * $ZodDefault returns the default value immediately in forward direction.
2034
- * It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
2035
- return payload;
2036
- }
2037
- const result = def.innerType._zod.run(payload, ctx);
2038
- if (result instanceof Promise) return result.then((result) => handleDefaultResult(result, def));
2039
- return handleDefaultResult(result, def);
2040
- };
2041
- });
2042
- function handleDefaultResult(payload, def) {
2043
- if (payload.value === void 0) payload.value = def.defaultValue;
2044
- return payload;
2045
- }
2046
- const $ZodPrefault = /* @__PURE__ */ $constructor("$ZodPrefault", (inst, def) => {
2047
- $ZodType.init(inst, def);
2048
- inst._zod.optin = "optional";
2049
- defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2050
- inst._zod.parse = (payload, ctx) => {
2051
- if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
2052
- if (payload.value === void 0) payload.value = def.defaultValue;
2053
- return def.innerType._zod.run(payload, ctx);
2054
- };
2055
- });
2056
- const $ZodNonOptional = /* @__PURE__ */ $constructor("$ZodNonOptional", (inst, def) => {
2057
- $ZodType.init(inst, def);
2058
- defineLazy(inst._zod, "values", () => {
2059
- const v = def.innerType._zod.values;
2060
- return v ? new Set([...v].filter((x) => x !== void 0)) : void 0;
2061
- });
2062
- inst._zod.parse = (payload, ctx) => {
2063
- const result = def.innerType._zod.run(payload, ctx);
2064
- if (result instanceof Promise) return result.then((result) => handleNonOptionalResult(result, inst));
2065
- return handleNonOptionalResult(result, inst);
2066
- };
2067
- });
2068
- function handleNonOptionalResult(payload, inst) {
2069
- if (!payload.issues.length && payload.value === void 0) payload.issues.push({
2070
- code: "invalid_type",
2071
- expected: "nonoptional",
2072
- input: payload.value,
2073
- inst
2074
- });
2075
- return payload;
2076
- }
2077
- const $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
2078
- $ZodType.init(inst, def);
2079
- defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
2080
- defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
2081
- defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2082
- inst._zod.parse = (payload, ctx) => {
2083
- if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
2084
- const result = def.innerType._zod.run(payload, ctx);
2085
- if (result instanceof Promise) return result.then((result) => {
2086
- payload.value = result.value;
2087
- if (result.issues.length) {
2088
- payload.value = def.catchValue({
2089
- ...payload,
2090
- error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
2091
- input: payload.value
2092
- });
2093
- payload.issues = [];
2094
- }
2095
- return payload;
2096
- });
2097
- payload.value = result.value;
2098
- if (result.issues.length) {
2099
- payload.value = def.catchValue({
2100
- ...payload,
2101
- error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
2102
- input: payload.value
2103
- });
2104
- payload.issues = [];
2105
- }
2106
- return payload;
2107
- };
2108
- });
2109
- const $ZodPipe = /* @__PURE__ */ $constructor("$ZodPipe", (inst, def) => {
2110
- $ZodType.init(inst, def);
2111
- defineLazy(inst._zod, "values", () => def.in._zod.values);
2112
- defineLazy(inst._zod, "optin", () => def.in._zod.optin);
2113
- defineLazy(inst._zod, "optout", () => def.out._zod.optout);
2114
- defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
2115
- inst._zod.parse = (payload, ctx) => {
2116
- if (ctx.direction === "backward") {
2117
- const right = def.out._zod.run(payload, ctx);
2118
- if (right instanceof Promise) return right.then((right) => handlePipeResult(right, def.in, ctx));
2119
- return handlePipeResult(right, def.in, ctx);
2120
- }
2121
- const left = def.in._zod.run(payload, ctx);
2122
- if (left instanceof Promise) return left.then((left) => handlePipeResult(left, def.out, ctx));
2123
- return handlePipeResult(left, def.out, ctx);
2124
- };
2125
- });
2126
- function handlePipeResult(left, next, ctx) {
2127
- if (left.issues.length) {
2128
- left.aborted = true;
2129
- return left;
2130
- }
2131
- return next._zod.run({
2132
- value: left.value,
2133
- issues: left.issues
2134
- }, ctx);
2135
- }
2136
- const $ZodReadonly = /* @__PURE__ */ $constructor("$ZodReadonly", (inst, def) => {
2137
- $ZodType.init(inst, def);
2138
- defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
2139
- defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2140
- defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
2141
- defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
2142
- inst._zod.parse = (payload, ctx) => {
2143
- if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
2144
- const result = def.innerType._zod.run(payload, ctx);
2145
- if (result instanceof Promise) return result.then(handleReadonlyResult);
2146
- return handleReadonlyResult(result);
2147
- };
2148
- });
2149
- function handleReadonlyResult(payload) {
2150
- payload.value = Object.freeze(payload.value);
2151
- return payload;
2152
- }
2153
- const $ZodCustom = /* @__PURE__ */ $constructor("$ZodCustom", (inst, def) => {
2154
- $ZodCheck.init(inst, def);
2155
- $ZodType.init(inst, def);
2156
- inst._zod.parse = (payload, _) => {
2157
- return payload;
2158
- };
2159
- inst._zod.check = (payload) => {
2160
- const input = payload.value;
2161
- const r = def.fn(input);
2162
- if (r instanceof Promise) return r.then((r) => handleRefineResult(r, payload, input, inst));
2163
- handleRefineResult(r, payload, input, inst);
2164
- };
2165
- });
2166
- function handleRefineResult(result, payload, input, inst) {
2167
- if (!result) {
2168
- const _iss = {
2169
- code: "custom",
2170
- input,
2171
- inst,
2172
- path: [...inst._zod.def.path ?? []],
2173
- continue: !inst._zod.def.abort
2174
- };
2175
- if (inst._zod.def.params) _iss.params = inst._zod.def.params;
2176
- payload.issues.push(issue(_iss));
2177
- }
2178
- }
2179
- //#endregion
2180
- //#region ../../node_modules/zod/v4/core/registries.js
2181
- var _a;
2182
- var $ZodRegistry = class {
2183
- constructor() {
2184
- this._map = /* @__PURE__ */ new WeakMap();
2185
- this._idmap = /* @__PURE__ */ new Map();
2186
- }
2187
- add(schema, ..._meta) {
2188
- const meta = _meta[0];
2189
- this._map.set(schema, meta);
2190
- if (meta && typeof meta === "object" && "id" in meta) this._idmap.set(meta.id, schema);
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) this._idmap.delete(meta.id);
2201
- this._map.delete(schema);
2202
- return this;
2203
- }
2204
- get(schema) {
2205
- const p = schema._zod.parent;
2206
- if (p) {
2207
- const pm = { ...this.get(p) ?? {} };
2208
- delete pm.id;
2209
- const f = {
2210
- ...pm,
2211
- ...this._map.get(schema)
2212
- };
2213
- return Object.keys(f).length ? f : void 0;
2214
- }
2215
- return this._map.get(schema);
2216
- }
2217
- has(schema) {
2218
- return this._map.has(schema);
2219
- }
2220
- };
2221
- function registry() {
2222
- return new $ZodRegistry();
2223
- }
2224
- (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
2225
- const globalRegistry = globalThis.__zod_globalRegistry;
2226
- //#endregion
2227
- //#region ../../node_modules/zod/v4/core/api.js
2228
- /* @__NO_SIDE_EFFECTS__ */
2229
- function _string(Class, params) {
2230
- return new Class({
2231
- type: "string",
2232
- ...normalizeParams(params)
2233
- });
2234
- }
2235
- /* @__NO_SIDE_EFFECTS__ */
2236
- function _email(Class, params) {
2237
- return new Class({
2238
- type: "string",
2239
- format: "email",
2240
- check: "string_format",
2241
- abort: false,
2242
- ...normalizeParams(params)
2243
- });
2244
- }
2245
- /* @__NO_SIDE_EFFECTS__ */
2246
- function _guid(Class, params) {
2247
- return new Class({
2248
- type: "string",
2249
- format: "guid",
2250
- check: "string_format",
2251
- abort: false,
2252
- ...normalizeParams(params)
2253
- });
2254
- }
2255
- /* @__NO_SIDE_EFFECTS__ */
2256
- function _uuid(Class, params) {
2257
- return new Class({
2258
- type: "string",
2259
- format: "uuid",
2260
- check: "string_format",
2261
- abort: false,
2262
- ...normalizeParams(params)
2263
- });
2264
- }
2265
- /* @__NO_SIDE_EFFECTS__ */
2266
- function _uuidv4(Class, params) {
2267
- return new Class({
2268
- type: "string",
2269
- format: "uuid",
2270
- check: "string_format",
2271
- abort: false,
2272
- version: "v4",
2273
- ...normalizeParams(params)
2274
- });
2275
- }
2276
- /* @__NO_SIDE_EFFECTS__ */
2277
- function _uuidv6(Class, params) {
2278
- return new Class({
2279
- type: "string",
2280
- format: "uuid",
2281
- check: "string_format",
2282
- abort: false,
2283
- version: "v6",
2284
- ...normalizeParams(params)
2285
- });
2286
- }
2287
- /* @__NO_SIDE_EFFECTS__ */
2288
- function _uuidv7(Class, params) {
2289
- return new Class({
2290
- type: "string",
2291
- format: "uuid",
2292
- check: "string_format",
2293
- abort: false,
2294
- version: "v7",
2295
- ...normalizeParams(params)
2296
- });
2297
- }
2298
- /* @__NO_SIDE_EFFECTS__ */
2299
- function _url(Class, params) {
2300
- return new Class({
2301
- type: "string",
2302
- format: "url",
2303
- check: "string_format",
2304
- abort: false,
2305
- ...normalizeParams(params)
2306
- });
2307
- }
2308
- /* @__NO_SIDE_EFFECTS__ */
2309
- function _emoji(Class, params) {
2310
- return new Class({
2311
- type: "string",
2312
- format: "emoji",
2313
- check: "string_format",
2314
- abort: false,
2315
- ...normalizeParams(params)
2316
- });
2317
- }
2318
- /* @__NO_SIDE_EFFECTS__ */
2319
- function _nanoid(Class, params) {
2320
- return new Class({
2321
- type: "string",
2322
- format: "nanoid",
2323
- check: "string_format",
2324
- abort: false,
2325
- ...normalizeParams(params)
2326
- });
2327
- }
2328
- /* @__NO_SIDE_EFFECTS__ */
2329
- function _cuid(Class, params) {
2330
- return new Class({
2331
- type: "string",
2332
- format: "cuid",
2333
- check: "string_format",
2334
- abort: false,
2335
- ...normalizeParams(params)
2336
- });
2337
- }
2338
- /* @__NO_SIDE_EFFECTS__ */
2339
- function _cuid2(Class, params) {
2340
- return new Class({
2341
- type: "string",
2342
- format: "cuid2",
2343
- check: "string_format",
2344
- abort: false,
2345
- ...normalizeParams(params)
2346
- });
2347
- }
2348
- /* @__NO_SIDE_EFFECTS__ */
2349
- function _ulid(Class, params) {
2350
- return new Class({
2351
- type: "string",
2352
- format: "ulid",
2353
- check: "string_format",
2354
- abort: false,
2355
- ...normalizeParams(params)
2356
- });
2357
- }
2358
- /* @__NO_SIDE_EFFECTS__ */
2359
- function _xid(Class, params) {
2360
- return new Class({
2361
- type: "string",
2362
- format: "xid",
2363
- check: "string_format",
2364
- abort: false,
2365
- ...normalizeParams(params)
2366
- });
2367
- }
2368
- /* @__NO_SIDE_EFFECTS__ */
2369
- function _ksuid(Class, params) {
2370
- return new Class({
2371
- type: "string",
2372
- format: "ksuid",
2373
- check: "string_format",
2374
- abort: false,
2375
- ...normalizeParams(params)
2376
- });
2377
- }
2378
- /* @__NO_SIDE_EFFECTS__ */
2379
- function _ipv4(Class, params) {
2380
- return new Class({
2381
- type: "string",
2382
- format: "ipv4",
2383
- check: "string_format",
2384
- abort: false,
2385
- ...normalizeParams(params)
2386
- });
2387
- }
2388
- /* @__NO_SIDE_EFFECTS__ */
2389
- function _ipv6(Class, params) {
2390
- return new Class({
2391
- type: "string",
2392
- format: "ipv6",
2393
- check: "string_format",
2394
- abort: false,
2395
- ...normalizeParams(params)
2396
- });
2397
- }
2398
- /* @__NO_SIDE_EFFECTS__ */
2399
- function _cidrv4(Class, params) {
2400
- return new Class({
2401
- type: "string",
2402
- format: "cidrv4",
2403
- check: "string_format",
2404
- abort: false,
2405
- ...normalizeParams(params)
2406
- });
2407
- }
2408
- /* @__NO_SIDE_EFFECTS__ */
2409
- function _cidrv6(Class, params) {
2410
- return new Class({
2411
- type: "string",
2412
- format: "cidrv6",
2413
- check: "string_format",
2414
- abort: false,
2415
- ...normalizeParams(params)
2416
- });
2417
- }
2418
- /* @__NO_SIDE_EFFECTS__ */
2419
- function _base64(Class, params) {
2420
- return new Class({
2421
- type: "string",
2422
- format: "base64",
2423
- check: "string_format",
2424
- abort: false,
2425
- ...normalizeParams(params)
2426
- });
2427
- }
2428
- /* @__NO_SIDE_EFFECTS__ */
2429
- function _base64url(Class, params) {
2430
- return new Class({
2431
- type: "string",
2432
- format: "base64url",
2433
- check: "string_format",
2434
- abort: false,
2435
- ...normalizeParams(params)
2436
- });
2437
- }
2438
- /* @__NO_SIDE_EFFECTS__ */
2439
- function _e164(Class, params) {
2440
- return new Class({
2441
- type: "string",
2442
- format: "e164",
2443
- check: "string_format",
2444
- abort: false,
2445
- ...normalizeParams(params)
2446
- });
2447
- }
2448
- /* @__NO_SIDE_EFFECTS__ */
2449
- function _jwt(Class, params) {
2450
- return new Class({
2451
- type: "string",
2452
- format: "jwt",
2453
- check: "string_format",
2454
- abort: false,
2455
- ...normalizeParams(params)
2456
- });
2457
- }
2458
- /* @__NO_SIDE_EFFECTS__ */
2459
- function _isoDateTime(Class, params) {
2460
- return new Class({
2461
- type: "string",
2462
- format: "datetime",
2463
- check: "string_format",
2464
- offset: false,
2465
- local: false,
2466
- precision: null,
2467
- ...normalizeParams(params)
2468
- });
2469
- }
2470
- /* @__NO_SIDE_EFFECTS__ */
2471
- function _isoDate(Class, params) {
2472
- return new Class({
2473
- type: "string",
2474
- format: "date",
2475
- check: "string_format",
2476
- ...normalizeParams(params)
2477
- });
2478
- }
2479
- /* @__NO_SIDE_EFFECTS__ */
2480
- function _isoTime(Class, params) {
2481
- return new Class({
2482
- type: "string",
2483
- format: "time",
2484
- check: "string_format",
2485
- precision: null,
2486
- ...normalizeParams(params)
2487
- });
2488
- }
2489
- /* @__NO_SIDE_EFFECTS__ */
2490
- function _isoDuration(Class, params) {
2491
- return new Class({
2492
- type: "string",
2493
- format: "duration",
2494
- check: "string_format",
2495
- ...normalizeParams(params)
2496
- });
2497
- }
2498
- /* @__NO_SIDE_EFFECTS__ */
2499
- function _unknown(Class) {
2500
- return new Class({ type: "unknown" });
2501
- }
2502
- /* @__NO_SIDE_EFFECTS__ */
2503
- function _never(Class, params) {
2504
- return new Class({
2505
- type: "never",
2506
- ...normalizeParams(params)
2507
- });
2508
- }
2509
- /* @__NO_SIDE_EFFECTS__ */
2510
- function _maxLength(maximum, params) {
2511
- return new $ZodCheckMaxLength({
2512
- check: "max_length",
2513
- ...normalizeParams(params),
2514
- maximum
2515
- });
2516
- }
2517
- /* @__NO_SIDE_EFFECTS__ */
2518
- function _minLength(minimum, params) {
2519
- return new $ZodCheckMinLength({
2520
- check: "min_length",
2521
- ...normalizeParams(params),
2522
- minimum
2523
- });
2524
- }
2525
- /* @__NO_SIDE_EFFECTS__ */
2526
- function _length(length, params) {
2527
- return new $ZodCheckLengthEquals({
2528
- check: "length_equals",
2529
- ...normalizeParams(params),
2530
- length
2531
- });
2532
- }
2533
- /* @__NO_SIDE_EFFECTS__ */
2534
- function _regex(pattern, params) {
2535
- return new $ZodCheckRegex({
2536
- check: "string_format",
2537
- format: "regex",
2538
- ...normalizeParams(params),
2539
- pattern
2540
- });
2541
- }
2542
- /* @__NO_SIDE_EFFECTS__ */
2543
- function _lowercase(params) {
2544
- return new $ZodCheckLowerCase({
2545
- check: "string_format",
2546
- format: "lowercase",
2547
- ...normalizeParams(params)
2548
- });
2549
- }
2550
- /* @__NO_SIDE_EFFECTS__ */
2551
- function _uppercase(params) {
2552
- return new $ZodCheckUpperCase({
2553
- check: "string_format",
2554
- format: "uppercase",
2555
- ...normalizeParams(params)
2556
- });
2557
- }
2558
- /* @__NO_SIDE_EFFECTS__ */
2559
- function _includes(includes, params) {
2560
- return new $ZodCheckIncludes({
2561
- check: "string_format",
2562
- format: "includes",
2563
- ...normalizeParams(params),
2564
- includes
2565
- });
2566
- }
2567
- /* @__NO_SIDE_EFFECTS__ */
2568
- function _startsWith(prefix, params) {
2569
- return new $ZodCheckStartsWith({
2570
- check: "string_format",
2571
- format: "starts_with",
2572
- ...normalizeParams(params),
2573
- prefix
2574
- });
2575
- }
2576
- /* @__NO_SIDE_EFFECTS__ */
2577
- function _endsWith(suffix, params) {
2578
- return new $ZodCheckEndsWith({
2579
- check: "string_format",
2580
- format: "ends_with",
2581
- ...normalizeParams(params),
2582
- suffix
2583
- });
2584
- }
2585
- /* @__NO_SIDE_EFFECTS__ */
2586
- function _overwrite(tx) {
2587
- return new $ZodCheckOverwrite({
2588
- check: "overwrite",
2589
- tx
2590
- });
2591
- }
2592
- /* @__NO_SIDE_EFFECTS__ */
2593
- function _normalize(form) {
2594
- return /* @__PURE__ */ _overwrite((input) => input.normalize(form));
2595
- }
2596
- /* @__NO_SIDE_EFFECTS__ */
2597
- function _trim() {
2598
- return /* @__PURE__ */ _overwrite((input) => input.trim());
2599
- }
2600
- /* @__NO_SIDE_EFFECTS__ */
2601
- function _toLowerCase() {
2602
- return /* @__PURE__ */ _overwrite((input) => input.toLowerCase());
2603
- }
2604
- /* @__NO_SIDE_EFFECTS__ */
2605
- function _toUpperCase() {
2606
- return /* @__PURE__ */ _overwrite((input) => input.toUpperCase());
2607
- }
2608
- /* @__NO_SIDE_EFFECTS__ */
2609
- function _slugify() {
2610
- return /* @__PURE__ */ _overwrite((input) => slugify(input));
2611
- }
2612
- /* @__NO_SIDE_EFFECTS__ */
2613
- function _array(Class, element, params) {
2614
- return new Class({
2615
- type: "array",
2616
- element,
2617
- ...normalizeParams(params)
2618
- });
2619
- }
2620
- /* @__NO_SIDE_EFFECTS__ */
2621
- function _refine(Class, fn, _params) {
2622
- return new Class({
2623
- type: "custom",
2624
- check: "custom",
2625
- fn,
2626
- ...normalizeParams(_params)
2627
- });
2628
- }
2629
- /* @__NO_SIDE_EFFECTS__ */
2630
- function _superRefine(fn) {
2631
- const ch = /* @__PURE__ */ _check((payload) => {
2632
- payload.addIssue = (issue$2) => {
2633
- if (typeof issue$2 === "string") payload.issues.push(issue(issue$2, payload.value, ch._zod.def));
2634
- else {
2635
- const _issue = issue$2;
2636
- if (_issue.fatal) _issue.continue = false;
2637
- _issue.code ?? (_issue.code = "custom");
2638
- _issue.input ?? (_issue.input = payload.value);
2639
- _issue.inst ?? (_issue.inst = ch);
2640
- _issue.continue ?? (_issue.continue = !ch._zod.def.abort);
2641
- payload.issues.push(issue(_issue));
2642
- }
2643
- };
2644
- return fn(payload.value, payload);
2645
- });
2646
- return ch;
2647
- }
2648
- /* @__NO_SIDE_EFFECTS__ */
2649
- function _check(fn, params) {
2650
- const ch = new $ZodCheck({
2651
- check: "custom",
2652
- ...normalizeParams(params)
2653
- });
2654
- ch._zod.check = fn;
2655
- return ch;
2656
- }
2657
- //#endregion
2658
- //#region ../../node_modules/zod/v4/core/to-json-schema.js
2659
- function initializeContext(params) {
2660
- let target = params?.target ?? "draft-2020-12";
2661
- if (target === "draft-4") target = "draft-04";
2662
- if (target === "draft-7") target = "draft-07";
2663
- return {
2664
- processors: params.processors ?? {},
2665
- metadataRegistry: params?.metadata ?? globalRegistry,
2666
- target,
2667
- unrepresentable: params?.unrepresentable ?? "throw",
2668
- override: params?.override ?? (() => {}),
2669
- io: params?.io ?? "output",
2670
- counter: 0,
2671
- seen: /* @__PURE__ */ new Map(),
2672
- cycles: params?.cycles ?? "ref",
2673
- reused: params?.reused ?? "inline",
2674
- external: params?.external ?? void 0
2675
- };
2676
- }
2677
- function process(schema, ctx, _params = {
2678
- path: [],
2679
- schemaPath: []
2680
- }) {
2681
- var _a;
2682
- const def = schema._zod.def;
2683
- const seen = ctx.seen.get(schema);
2684
- if (seen) {
2685
- seen.count++;
2686
- if (_params.schemaPath.includes(schema)) seen.cycle = _params.path;
2687
- return seen.schema;
2688
- }
2689
- const result = {
2690
- schema: {},
2691
- count: 1,
2692
- cycle: void 0,
2693
- path: _params.path
2694
- };
2695
- ctx.seen.set(schema, result);
2696
- const overrideSchema = schema._zod.toJSONSchema?.();
2697
- if (overrideSchema) result.schema = overrideSchema;
2698
- else {
2699
- const params = {
2700
- ..._params,
2701
- schemaPath: [..._params.schemaPath, schema],
2702
- path: _params.path
2703
- };
2704
- if (schema._zod.processJSONSchema) schema._zod.processJSONSchema(ctx, result.schema, params);
2705
- else {
2706
- const _json = result.schema;
2707
- const processor = ctx.processors[def.type];
2708
- if (!processor) throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
2709
- processor(schema, ctx, _json, params);
2710
- }
2711
- const parent = schema._zod.parent;
2712
- if (parent) {
2713
- if (!result.ref) result.ref = parent;
2714
- process(parent, ctx, params);
2715
- ctx.seen.get(parent).isParent = true;
2716
- }
2717
- }
2718
- const meta = ctx.metadataRegistry.get(schema);
2719
- if (meta) Object.assign(result.schema, meta);
2720
- if (ctx.io === "input" && isTransforming(schema)) {
2721
- delete result.schema.examples;
2722
- delete result.schema.default;
2723
- }
2724
- if (ctx.io === "input" && result.schema._prefault) (_a = result.schema).default ?? (_a.default = result.schema._prefault);
2725
- delete result.schema._prefault;
2726
- return ctx.seen.get(schema).schema;
2727
- }
2728
- function extractDefs(ctx, schema) {
2729
- const root = ctx.seen.get(schema);
2730
- if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
2731
- const idToSchema = /* @__PURE__ */ new Map();
2732
- for (const entry of ctx.seen.entries()) {
2733
- const id = ctx.metadataRegistry.get(entry[0])?.id;
2734
- if (id) {
2735
- const existing = idToSchema.get(id);
2736
- if (existing && existing !== entry[0]) throw new Error(`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
2737
- idToSchema.set(id, entry[0]);
2738
- }
2739
- }
2740
- const makeURI = (entry) => {
2741
- const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
2742
- if (ctx.external) {
2743
- const externalId = ctx.external.registry.get(entry[0])?.id;
2744
- const uriGenerator = ctx.external.uri ?? ((id) => id);
2745
- if (externalId) return { ref: uriGenerator(externalId) };
2746
- const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
2747
- entry[1].defId = id;
2748
- return {
2749
- defId: id,
2750
- ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}`
2751
- };
2752
- }
2753
- if (entry[1] === root) return { ref: "#" };
2754
- const defUriPrefix = `#/${defsSegment}/`;
2755
- const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
2756
- return {
2757
- defId,
2758
- ref: defUriPrefix + defId
2759
- };
2760
- };
2761
- const extractToDef = (entry) => {
2762
- if (entry[1].schema.$ref) return;
2763
- const seen = entry[1];
2764
- const { ref, defId } = makeURI(entry);
2765
- seen.def = { ...seen.schema };
2766
- if (defId) seen.defId = defId;
2767
- const schema = seen.schema;
2768
- for (const key in schema) delete schema[key];
2769
- schema.$ref = ref;
2770
- };
2771
- if (ctx.cycles === "throw") for (const entry of ctx.seen.entries()) {
2772
- const seen = entry[1];
2773
- if (seen.cycle) throw new Error(`Cycle detected: #/${seen.cycle?.join("/")}/<root>
2774
-
2775
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
2776
- }
2777
- for (const entry of ctx.seen.entries()) {
2778
- const seen = entry[1];
2779
- if (schema === entry[0]) {
2780
- extractToDef(entry);
2781
- continue;
2782
- }
2783
- if (ctx.external) {
2784
- const ext = ctx.external.registry.get(entry[0])?.id;
2785
- if (schema !== entry[0] && ext) {
2786
- extractToDef(entry);
2787
- continue;
2788
- }
2789
- }
2790
- if (ctx.metadataRegistry.get(entry[0])?.id) {
2791
- extractToDef(entry);
2792
- continue;
2793
- }
2794
- if (seen.cycle) {
2795
- extractToDef(entry);
2796
- continue;
2797
- }
2798
- if (seen.count > 1) {
2799
- if (ctx.reused === "ref") {
2800
- extractToDef(entry);
2801
- continue;
2802
- }
2803
- }
2804
- }
2805
- }
2806
- function finalize(ctx, schema) {
2807
- const root = ctx.seen.get(schema);
2808
- if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
2809
- const flattenRef = (zodSchema) => {
2810
- const seen = ctx.seen.get(zodSchema);
2811
- if (seen.ref === null) return;
2812
- const schema = seen.def ?? seen.schema;
2813
- const _cached = { ...schema };
2814
- const ref = seen.ref;
2815
- seen.ref = null;
2816
- if (ref) {
2817
- flattenRef(ref);
2818
- const refSeen = ctx.seen.get(ref);
2819
- const refSchema = refSeen.schema;
2820
- if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
2821
- schema.allOf = schema.allOf ?? [];
2822
- schema.allOf.push(refSchema);
2823
- } else Object.assign(schema, refSchema);
2824
- Object.assign(schema, _cached);
2825
- if (zodSchema._zod.parent === ref) for (const key in schema) {
2826
- if (key === "$ref" || key === "allOf") continue;
2827
- if (!(key in _cached)) delete schema[key];
2828
- }
2829
- if (refSchema.$ref && refSeen.def) for (const key in schema) {
2830
- if (key === "$ref" || key === "allOf") continue;
2831
- if (key in refSeen.def && JSON.stringify(schema[key]) === JSON.stringify(refSeen.def[key])) delete schema[key];
2832
- }
2833
- }
2834
- const parent = zodSchema._zod.parent;
2835
- if (parent && parent !== ref) {
2836
- flattenRef(parent);
2837
- const parentSeen = ctx.seen.get(parent);
2838
- if (parentSeen?.schema.$ref) {
2839
- schema.$ref = parentSeen.schema.$ref;
2840
- if (parentSeen.def) for (const key in schema) {
2841
- if (key === "$ref" || key === "allOf") continue;
2842
- if (key in parentSeen.def && JSON.stringify(schema[key]) === JSON.stringify(parentSeen.def[key])) delete schema[key];
2843
- }
2844
- }
2845
- }
2846
- ctx.override({
2847
- zodSchema,
2848
- jsonSchema: schema,
2849
- path: seen.path ?? []
2850
- });
2851
- };
2852
- for (const entry of [...ctx.seen.entries()].reverse()) flattenRef(entry[0]);
2853
- const result = {};
2854
- if (ctx.target === "draft-2020-12") result.$schema = "https://json-schema.org/draft/2020-12/schema";
2855
- else if (ctx.target === "draft-07") result.$schema = "http://json-schema.org/draft-07/schema#";
2856
- else if (ctx.target === "draft-04") result.$schema = "http://json-schema.org/draft-04/schema#";
2857
- else if (ctx.target === "openapi-3.0") {}
2858
- if (ctx.external?.uri) {
2859
- const id = ctx.external.registry.get(schema)?.id;
2860
- if (!id) throw new Error("Schema is missing an `id` property");
2861
- result.$id = ctx.external.uri(id);
2862
- }
2863
- Object.assign(result, root.def ?? root.schema);
2864
- const defs = ctx.external?.defs ?? {};
2865
- for (const entry of ctx.seen.entries()) {
2866
- const seen = entry[1];
2867
- if (seen.def && seen.defId) defs[seen.defId] = seen.def;
2868
- }
2869
- if (ctx.external) {} else if (Object.keys(defs).length > 0) if (ctx.target === "draft-2020-12") result.$defs = defs;
2870
- else result.definitions = defs;
2871
- try {
2872
- const finalized = JSON.parse(JSON.stringify(result));
2873
- Object.defineProperty(finalized, "~standard", {
2874
- value: {
2875
- ...schema["~standard"],
2876
- jsonSchema: {
2877
- input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
2878
- output: createStandardJSONSchemaMethod(schema, "output", ctx.processors)
2879
- }
2880
- },
2881
- enumerable: false,
2882
- writable: false
2883
- });
2884
- return finalized;
2885
- } catch (_err) {
2886
- throw new Error("Error converting schema to JSON.");
2887
- }
2888
- }
2889
- function isTransforming(_schema, _ctx) {
2890
- const ctx = _ctx ?? { seen: /* @__PURE__ */ new Set() };
2891
- if (ctx.seen.has(_schema)) return false;
2892
- ctx.seen.add(_schema);
2893
- const def = _schema._zod.def;
2894
- if (def.type === "transform") return true;
2895
- if (def.type === "array") return isTransforming(def.element, ctx);
2896
- if (def.type === "set") return isTransforming(def.valueType, ctx);
2897
- if (def.type === "lazy") return isTransforming(def.getter(), ctx);
2898
- if (def.type === "promise" || def.type === "optional" || def.type === "nonoptional" || def.type === "nullable" || def.type === "readonly" || def.type === "default" || def.type === "prefault") return isTransforming(def.innerType, ctx);
2899
- if (def.type === "intersection") return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
2900
- if (def.type === "record" || def.type === "map") return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
2901
- if (def.type === "pipe") return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
2902
- if (def.type === "object") {
2903
- for (const key in def.shape) if (isTransforming(def.shape[key], ctx)) return true;
2904
- return false;
2905
- }
2906
- if (def.type === "union") {
2907
- for (const option of def.options) if (isTransforming(option, ctx)) return true;
2908
- return false;
2909
- }
2910
- if (def.type === "tuple") {
2911
- for (const item of def.items) if (isTransforming(item, ctx)) return true;
2912
- if (def.rest && isTransforming(def.rest, ctx)) return true;
2913
- return false;
2914
- }
2915
- return false;
2916
- }
2917
- /**
2918
- * Creates a toJSONSchema method for a schema instance.
2919
- * This encapsulates the logic of initializing context, processing, extracting defs, and finalizing.
2920
- */
2921
- const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
2922
- const ctx = initializeContext({
2923
- ...params,
2924
- processors
2925
- });
2926
- process(schema, ctx);
2927
- extractDefs(ctx, schema);
2928
- return finalize(ctx, schema);
2929
- };
2930
- const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
2931
- const { libraryOptions, target } = params ?? {};
2932
- const ctx = initializeContext({
2933
- ...libraryOptions ?? {},
2934
- target,
2935
- io,
2936
- processors
2937
- });
2938
- process(schema, ctx);
2939
- extractDefs(ctx, schema);
2940
- return finalize(ctx, schema);
2941
- };
2942
- //#endregion
2943
- //#region ../../node_modules/zod/v4/core/json-schema-processors.js
2944
- const formatMap = {
2945
- guid: "uuid",
2946
- url: "uri",
2947
- datetime: "date-time",
2948
- json_string: "json-string",
2949
- regex: ""
2950
- };
2951
- const stringProcessor = (schema, ctx, _json, _params) => {
2952
- const json = _json;
2953
- json.type = "string";
2954
- const { minimum, maximum, format, patterns, contentEncoding } = schema._zod.bag;
2955
- if (typeof minimum === "number") json.minLength = minimum;
2956
- if (typeof maximum === "number") json.maxLength = maximum;
2957
- if (format) {
2958
- json.format = formatMap[format] ?? format;
2959
- if (json.format === "") delete json.format;
2960
- if (format === "time") delete json.format;
2961
- }
2962
- if (contentEncoding) json.contentEncoding = contentEncoding;
2963
- if (patterns && patterns.size > 0) {
2964
- const regexes = [...patterns];
2965
- if (regexes.length === 1) json.pattern = regexes[0].source;
2966
- else if (regexes.length > 1) json.allOf = [...regexes.map((regex) => ({
2967
- ...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
2968
- pattern: regex.source
2969
- }))];
2970
- }
2971
- };
2972
- const neverProcessor = (_schema, _ctx, json, _params) => {
2973
- json.not = {};
2974
- };
2975
- const unknownProcessor = (_schema, _ctx, _json, _params) => {};
2976
- const enumProcessor = (schema, _ctx, json, _params) => {
2977
- const def = schema._zod.def;
2978
- const values = getEnumValues(def.entries);
2979
- if (values.every((v) => typeof v === "number")) json.type = "number";
2980
- if (values.every((v) => typeof v === "string")) json.type = "string";
2981
- json.enum = values;
2982
- };
2983
- const customProcessor = (_schema, ctx, _json, _params) => {
2984
- if (ctx.unrepresentable === "throw") throw new Error("Custom types cannot be represented in JSON Schema");
2985
- };
2986
- const transformProcessor = (_schema, ctx, _json, _params) => {
2987
- if (ctx.unrepresentable === "throw") throw new Error("Transforms cannot be represented in JSON Schema");
2988
- };
2989
- const arrayProcessor = (schema, ctx, _json, params) => {
2990
- const json = _json;
2991
- const def = schema._zod.def;
2992
- const { minimum, maximum } = schema._zod.bag;
2993
- if (typeof minimum === "number") json.minItems = minimum;
2994
- if (typeof maximum === "number") json.maxItems = maximum;
2995
- json.type = "array";
2996
- json.items = process(def.element, ctx, {
2997
- ...params,
2998
- path: [...params.path, "items"]
2999
- });
3000
- };
3001
- const objectProcessor = (schema, ctx, _json, params) => {
3002
- const json = _json;
3003
- const def = schema._zod.def;
3004
- json.type = "object";
3005
- json.properties = {};
3006
- const shape = def.shape;
3007
- for (const key in shape) json.properties[key] = process(shape[key], ctx, {
3008
- ...params,
3009
- path: [
3010
- ...params.path,
3011
- "properties",
3012
- key
3013
- ]
3014
- });
3015
- const allKeys = new Set(Object.keys(shape));
3016
- const requiredKeys = new Set([...allKeys].filter((key) => {
3017
- const v = def.shape[key]._zod;
3018
- if (ctx.io === "input") return v.optin === void 0;
3019
- else return v.optout === void 0;
3020
- }));
3021
- if (requiredKeys.size > 0) json.required = Array.from(requiredKeys);
3022
- if (def.catchall?._zod.def.type === "never") json.additionalProperties = false;
3023
- else if (!def.catchall) {
3024
- if (ctx.io === "output") json.additionalProperties = false;
3025
- } else if (def.catchall) json.additionalProperties = process(def.catchall, ctx, {
3026
- ...params,
3027
- path: [...params.path, "additionalProperties"]
3028
- });
3029
- };
3030
- const unionProcessor = (schema, ctx, json, params) => {
3031
- const def = schema._zod.def;
3032
- const isExclusive = def.inclusive === false;
3033
- const options = def.options.map((x, i) => process(x, ctx, {
3034
- ...params,
3035
- path: [
3036
- ...params.path,
3037
- isExclusive ? "oneOf" : "anyOf",
3038
- i
3039
- ]
3040
- }));
3041
- if (isExclusive) json.oneOf = options;
3042
- else json.anyOf = options;
3043
- };
3044
- const intersectionProcessor = (schema, ctx, json, params) => {
3045
- const def = schema._zod.def;
3046
- const a = process(def.left, ctx, {
3047
- ...params,
3048
- path: [
3049
- ...params.path,
3050
- "allOf",
3051
- 0
3052
- ]
3053
- });
3054
- const b = process(def.right, ctx, {
3055
- ...params,
3056
- path: [
3057
- ...params.path,
3058
- "allOf",
3059
- 1
3060
- ]
3061
- });
3062
- const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
3063
- json.allOf = [...isSimpleIntersection(a) ? a.allOf : [a], ...isSimpleIntersection(b) ? b.allOf : [b]];
3064
- };
3065
- const nullableProcessor = (schema, ctx, json, params) => {
3066
- const def = schema._zod.def;
3067
- const inner = process(def.innerType, ctx, params);
3068
- const seen = ctx.seen.get(schema);
3069
- if (ctx.target === "openapi-3.0") {
3070
- seen.ref = def.innerType;
3071
- json.nullable = true;
3072
- } else json.anyOf = [inner, { type: "null" }];
3073
- };
3074
- const nonoptionalProcessor = (schema, ctx, _json, params) => {
3075
- const def = schema._zod.def;
3076
- process(def.innerType, ctx, params);
3077
- const seen = ctx.seen.get(schema);
3078
- seen.ref = def.innerType;
3079
- };
3080
- const defaultProcessor = (schema, ctx, json, params) => {
3081
- const def = schema._zod.def;
3082
- process(def.innerType, ctx, params);
3083
- const seen = ctx.seen.get(schema);
3084
- seen.ref = def.innerType;
3085
- json.default = JSON.parse(JSON.stringify(def.defaultValue));
3086
- };
3087
- const prefaultProcessor = (schema, ctx, json, params) => {
3088
- const def = schema._zod.def;
3089
- process(def.innerType, ctx, params);
3090
- const seen = ctx.seen.get(schema);
3091
- seen.ref = def.innerType;
3092
- if (ctx.io === "input") json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
3093
- };
3094
- const catchProcessor = (schema, ctx, json, params) => {
3095
- const def = schema._zod.def;
3096
- process(def.innerType, ctx, params);
3097
- const seen = ctx.seen.get(schema);
3098
- seen.ref = def.innerType;
3099
- let catchValue;
3100
- try {
3101
- catchValue = def.catchValue(void 0);
3102
- } catch {
3103
- throw new Error("Dynamic catch values are not supported in JSON Schema");
3104
- }
3105
- json.default = catchValue;
3106
- };
3107
- const pipeProcessor = (schema, ctx, _json, params) => {
3108
- const def = schema._zod.def;
3109
- const innerType = ctx.io === "input" ? def.in._zod.def.type === "transform" ? def.out : def.in : def.out;
3110
- process(innerType, ctx, params);
3111
- const seen = ctx.seen.get(schema);
3112
- seen.ref = innerType;
3113
- };
3114
- const readonlyProcessor = (schema, ctx, json, params) => {
3115
- const def = schema._zod.def;
3116
- process(def.innerType, ctx, params);
3117
- const seen = ctx.seen.get(schema);
3118
- seen.ref = def.innerType;
3119
- json.readOnly = true;
3120
- };
3121
- const optionalProcessor = (schema, ctx, _json, params) => {
3122
- const def = schema._zod.def;
3123
- process(def.innerType, ctx, params);
3124
- const seen = ctx.seen.get(schema);
3125
- seen.ref = def.innerType;
3126
- };
3127
- //#endregion
3128
- //#region ../../node_modules/zod/v4/classic/iso.js
3129
- const ZodISODateTime = /* @__PURE__ */ $constructor("ZodISODateTime", (inst, def) => {
3130
- $ZodISODateTime.init(inst, def);
3131
- ZodStringFormat.init(inst, def);
3132
- });
3133
- function datetime(params) {
3134
- return /* @__PURE__ */ _isoDateTime(ZodISODateTime, params);
3135
- }
3136
- const ZodISODate = /* @__PURE__ */ $constructor("ZodISODate", (inst, def) => {
3137
- $ZodISODate.init(inst, def);
3138
- ZodStringFormat.init(inst, def);
3139
- });
3140
- function date(params) {
3141
- return /* @__PURE__ */ _isoDate(ZodISODate, params);
3142
- }
3143
- const ZodISOTime = /* @__PURE__ */ $constructor("ZodISOTime", (inst, def) => {
3144
- $ZodISOTime.init(inst, def);
3145
- ZodStringFormat.init(inst, def);
3146
- });
3147
- function time(params) {
3148
- return /* @__PURE__ */ _isoTime(ZodISOTime, params);
3149
- }
3150
- const ZodISODuration = /* @__PURE__ */ $constructor("ZodISODuration", (inst, def) => {
3151
- $ZodISODuration.init(inst, def);
3152
- ZodStringFormat.init(inst, def);
3153
- });
3154
- function duration(params) {
3155
- return /* @__PURE__ */ _isoDuration(ZodISODuration, params);
3156
- }
3157
- //#endregion
3158
- //#region ../../node_modules/zod/v4/classic/errors.js
3159
- const initializer = (inst, issues) => {
3160
- $ZodError.init(inst, issues);
3161
- inst.name = "ZodError";
3162
- Object.defineProperties(inst, {
3163
- format: { value: (mapper) => formatError(inst, mapper) },
3164
- flatten: { value: (mapper) => flattenError(inst, mapper) },
3165
- addIssue: { value: (issue) => {
3166
- inst.issues.push(issue);
3167
- inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
3168
- } },
3169
- addIssues: { value: (issues) => {
3170
- inst.issues.push(...issues);
3171
- inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
3172
- } },
3173
- isEmpty: { get() {
3174
- return inst.issues.length === 0;
3175
- } }
3176
- });
3177
- };
3178
- $constructor("ZodError", initializer);
3179
- const ZodRealError = $constructor("ZodError", initializer, { Parent: Error });
3180
- //#endregion
3181
- //#region ../../node_modules/zod/v4/classic/parse.js
3182
- const parse = /* @__PURE__ */ _parse(ZodRealError);
3183
- const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
3184
- const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
3185
- const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
3186
- const encode = /* @__PURE__ */ _encode(ZodRealError);
3187
- const decode = /* @__PURE__ */ _decode(ZodRealError);
3188
- const encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
3189
- const decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
3190
- const safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
3191
- const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
3192
- const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
3193
- const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
3194
- //#endregion
3195
- //#region ../../node_modules/zod/v4/classic/schemas.js
3196
- const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
3197
- $ZodType.init(inst, def);
3198
- Object.assign(inst["~standard"], { jsonSchema: {
3199
- input: createStandardJSONSchemaMethod(inst, "input"),
3200
- output: createStandardJSONSchemaMethod(inst, "output")
3201
- } });
3202
- inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
3203
- inst.def = def;
3204
- inst.type = def.type;
3205
- Object.defineProperty(inst, "_def", { value: def });
3206
- inst.check = (...checks) => {
3207
- return inst.clone(mergeDefs(def, { checks: [...def.checks ?? [], ...checks.map((ch) => typeof ch === "function" ? { _zod: {
3208
- check: ch,
3209
- def: { check: "custom" },
3210
- onattach: []
3211
- } } : ch)] }), { parent: true });
3212
- };
3213
- inst.with = inst.check;
3214
- inst.clone = (def, params) => clone(inst, def, params);
3215
- inst.brand = () => inst;
3216
- inst.register = ((reg, meta) => {
3217
- reg.add(inst, meta);
3218
- return inst;
3219
- });
3220
- inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
3221
- inst.safeParse = (data, params) => safeParse(inst, data, params);
3222
- inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
3223
- inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
3224
- inst.spa = inst.safeParseAsync;
3225
- inst.encode = (data, params) => encode(inst, data, params);
3226
- inst.decode = (data, params) => decode(inst, data, params);
3227
- inst.encodeAsync = async (data, params) => encodeAsync(inst, data, params);
3228
- inst.decodeAsync = async (data, params) => decodeAsync(inst, data, params);
3229
- inst.safeEncode = (data, params) => safeEncode(inst, data, params);
3230
- inst.safeDecode = (data, params) => safeDecode(inst, data, params);
3231
- inst.safeEncodeAsync = async (data, params) => safeEncodeAsync(inst, data, params);
3232
- inst.safeDecodeAsync = async (data, params) => safeDecodeAsync(inst, data, params);
3233
- inst.refine = (check, params) => inst.check(refine(check, params));
3234
- inst.superRefine = (refinement) => inst.check(superRefine(refinement));
3235
- inst.overwrite = (fn) => inst.check(/* @__PURE__ */ _overwrite(fn));
3236
- inst.optional = () => optional(inst);
3237
- inst.exactOptional = () => exactOptional(inst);
3238
- inst.nullable = () => nullable(inst);
3239
- inst.nullish = () => optional(nullable(inst));
3240
- inst.nonoptional = (params) => nonoptional(inst, params);
3241
- inst.array = () => array(inst);
3242
- inst.or = (arg) => union([inst, arg]);
3243
- inst.and = (arg) => intersection(inst, arg);
3244
- inst.transform = (tx) => pipe(inst, transform(tx));
3245
- inst.default = (def) => _default(inst, def);
3246
- inst.prefault = (def) => prefault(inst, def);
3247
- inst.catch = (params) => _catch(inst, params);
3248
- inst.pipe = (target) => pipe(inst, target);
3249
- inst.readonly = () => readonly(inst);
3250
- inst.describe = (description) => {
3251
- const cl = inst.clone();
3252
- globalRegistry.add(cl, { description });
3253
- return cl;
3254
- };
3255
- Object.defineProperty(inst, "description", {
3256
- get() {
3257
- return globalRegistry.get(inst)?.description;
3258
- },
3259
- configurable: true
3260
- });
3261
- inst.meta = (...args) => {
3262
- if (args.length === 0) return globalRegistry.get(inst);
3263
- const cl = inst.clone();
3264
- globalRegistry.add(cl, args[0]);
3265
- return cl;
3266
- };
3267
- inst.isOptional = () => inst.safeParse(void 0).success;
3268
- inst.isNullable = () => inst.safeParse(null).success;
3269
- inst.apply = (fn) => fn(inst);
3270
- return inst;
3271
- });
3272
- /** @internal */
3273
- const _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
3274
- $ZodString.init(inst, def);
3275
- ZodType.init(inst, def);
3276
- inst._zod.processJSONSchema = (ctx, json, params) => stringProcessor(inst, ctx, json, params);
3277
- const bag = inst._zod.bag;
3278
- inst.format = bag.format ?? null;
3279
- inst.minLength = bag.minimum ?? null;
3280
- inst.maxLength = bag.maximum ?? null;
3281
- inst.regex = (...args) => inst.check(/* @__PURE__ */ _regex(...args));
3282
- inst.includes = (...args) => inst.check(/* @__PURE__ */ _includes(...args));
3283
- inst.startsWith = (...args) => inst.check(/* @__PURE__ */ _startsWith(...args));
3284
- inst.endsWith = (...args) => inst.check(/* @__PURE__ */ _endsWith(...args));
3285
- inst.min = (...args) => inst.check(/* @__PURE__ */ _minLength(...args));
3286
- inst.max = (...args) => inst.check(/* @__PURE__ */ _maxLength(...args));
3287
- inst.length = (...args) => inst.check(/* @__PURE__ */ _length(...args));
3288
- inst.nonempty = (...args) => inst.check(/* @__PURE__ */ _minLength(1, ...args));
3289
- inst.lowercase = (params) => inst.check(/* @__PURE__ */ _lowercase(params));
3290
- inst.uppercase = (params) => inst.check(/* @__PURE__ */ _uppercase(params));
3291
- inst.trim = () => inst.check(/* @__PURE__ */ _trim());
3292
- inst.normalize = (...args) => inst.check(/* @__PURE__ */ _normalize(...args));
3293
- inst.toLowerCase = () => inst.check(/* @__PURE__ */ _toLowerCase());
3294
- inst.toUpperCase = () => inst.check(/* @__PURE__ */ _toUpperCase());
3295
- inst.slugify = () => inst.check(/* @__PURE__ */ _slugify());
3296
- });
3297
- const ZodString = /* @__PURE__ */ $constructor("ZodString", (inst, def) => {
3298
- $ZodString.init(inst, def);
3299
- _ZodString.init(inst, def);
3300
- inst.email = (params) => inst.check(/* @__PURE__ */ _email(ZodEmail, params));
3301
- inst.url = (params) => inst.check(/* @__PURE__ */ _url(ZodURL, params));
3302
- inst.jwt = (params) => inst.check(/* @__PURE__ */ _jwt(ZodJWT, params));
3303
- inst.emoji = (params) => inst.check(/* @__PURE__ */ _emoji(ZodEmoji, params));
3304
- inst.guid = (params) => inst.check(/* @__PURE__ */ _guid(ZodGUID, params));
3305
- inst.uuid = (params) => inst.check(/* @__PURE__ */ _uuid(ZodUUID, params));
3306
- inst.uuidv4 = (params) => inst.check(/* @__PURE__ */ _uuidv4(ZodUUID, params));
3307
- inst.uuidv6 = (params) => inst.check(/* @__PURE__ */ _uuidv6(ZodUUID, params));
3308
- inst.uuidv7 = (params) => inst.check(/* @__PURE__ */ _uuidv7(ZodUUID, params));
3309
- inst.nanoid = (params) => inst.check(/* @__PURE__ */ _nanoid(ZodNanoID, params));
3310
- inst.guid = (params) => inst.check(/* @__PURE__ */ _guid(ZodGUID, params));
3311
- inst.cuid = (params) => inst.check(/* @__PURE__ */ _cuid(ZodCUID, params));
3312
- inst.cuid2 = (params) => inst.check(/* @__PURE__ */ _cuid2(ZodCUID2, params));
3313
- inst.ulid = (params) => inst.check(/* @__PURE__ */ _ulid(ZodULID, params));
3314
- inst.base64 = (params) => inst.check(/* @__PURE__ */ _base64(ZodBase64, params));
3315
- inst.base64url = (params) => inst.check(/* @__PURE__ */ _base64url(ZodBase64URL, params));
3316
- inst.xid = (params) => inst.check(/* @__PURE__ */ _xid(ZodXID, params));
3317
- inst.ksuid = (params) => inst.check(/* @__PURE__ */ _ksuid(ZodKSUID, params));
3318
- inst.ipv4 = (params) => inst.check(/* @__PURE__ */ _ipv4(ZodIPv4, params));
3319
- inst.ipv6 = (params) => inst.check(/* @__PURE__ */ _ipv6(ZodIPv6, params));
3320
- inst.cidrv4 = (params) => inst.check(/* @__PURE__ */ _cidrv4(ZodCIDRv4, params));
3321
- inst.cidrv6 = (params) => inst.check(/* @__PURE__ */ _cidrv6(ZodCIDRv6, params));
3322
- inst.e164 = (params) => inst.check(/* @__PURE__ */ _e164(ZodE164, params));
3323
- inst.datetime = (params) => inst.check(datetime(params));
3324
- inst.date = (params) => inst.check(date(params));
3325
- inst.time = (params) => inst.check(time(params));
3326
- inst.duration = (params) => inst.check(duration(params));
3327
- });
3328
- function string(params) {
3329
- return /* @__PURE__ */ _string(ZodString, params);
3330
- }
3331
- const ZodStringFormat = /* @__PURE__ */ $constructor("ZodStringFormat", (inst, def) => {
3332
- $ZodStringFormat.init(inst, def);
3333
- _ZodString.init(inst, def);
3334
- });
3335
- const ZodEmail = /* @__PURE__ */ $constructor("ZodEmail", (inst, def) => {
3336
- $ZodEmail.init(inst, def);
3337
- ZodStringFormat.init(inst, def);
3338
- });
3339
- const ZodGUID = /* @__PURE__ */ $constructor("ZodGUID", (inst, def) => {
3340
- $ZodGUID.init(inst, def);
3341
- ZodStringFormat.init(inst, def);
3342
- });
3343
- const ZodUUID = /* @__PURE__ */ $constructor("ZodUUID", (inst, def) => {
3344
- $ZodUUID.init(inst, def);
3345
- ZodStringFormat.init(inst, def);
3346
- });
3347
- const ZodURL = /* @__PURE__ */ $constructor("ZodURL", (inst, def) => {
3348
- $ZodURL.init(inst, def);
3349
- ZodStringFormat.init(inst, def);
3350
- });
3351
- const ZodEmoji = /* @__PURE__ */ $constructor("ZodEmoji", (inst, def) => {
3352
- $ZodEmoji.init(inst, def);
3353
- ZodStringFormat.init(inst, def);
3354
- });
3355
- const ZodNanoID = /* @__PURE__ */ $constructor("ZodNanoID", (inst, def) => {
3356
- $ZodNanoID.init(inst, def);
3357
- ZodStringFormat.init(inst, def);
3358
- });
3359
- const ZodCUID = /* @__PURE__ */ $constructor("ZodCUID", (inst, def) => {
3360
- $ZodCUID.init(inst, def);
3361
- ZodStringFormat.init(inst, def);
3362
- });
3363
- const ZodCUID2 = /* @__PURE__ */ $constructor("ZodCUID2", (inst, def) => {
3364
- $ZodCUID2.init(inst, def);
3365
- ZodStringFormat.init(inst, def);
3366
- });
3367
- const ZodULID = /* @__PURE__ */ $constructor("ZodULID", (inst, def) => {
3368
- $ZodULID.init(inst, def);
3369
- ZodStringFormat.init(inst, def);
3370
- });
3371
- const ZodXID = /* @__PURE__ */ $constructor("ZodXID", (inst, def) => {
3372
- $ZodXID.init(inst, def);
3373
- ZodStringFormat.init(inst, def);
3374
- });
3375
- const ZodKSUID = /* @__PURE__ */ $constructor("ZodKSUID", (inst, def) => {
3376
- $ZodKSUID.init(inst, def);
3377
- ZodStringFormat.init(inst, def);
3378
- });
3379
- const ZodIPv4 = /* @__PURE__ */ $constructor("ZodIPv4", (inst, def) => {
3380
- $ZodIPv4.init(inst, def);
3381
- ZodStringFormat.init(inst, def);
3382
- });
3383
- const ZodIPv6 = /* @__PURE__ */ $constructor("ZodIPv6", (inst, def) => {
3384
- $ZodIPv6.init(inst, def);
3385
- ZodStringFormat.init(inst, def);
3386
- });
3387
- const ZodCIDRv4 = /* @__PURE__ */ $constructor("ZodCIDRv4", (inst, def) => {
3388
- $ZodCIDRv4.init(inst, def);
3389
- ZodStringFormat.init(inst, def);
3390
- });
3391
- const ZodCIDRv6 = /* @__PURE__ */ $constructor("ZodCIDRv6", (inst, def) => {
3392
- $ZodCIDRv6.init(inst, def);
3393
- ZodStringFormat.init(inst, def);
3394
- });
3395
- const ZodBase64 = /* @__PURE__ */ $constructor("ZodBase64", (inst, def) => {
3396
- $ZodBase64.init(inst, def);
3397
- ZodStringFormat.init(inst, def);
3398
- });
3399
- const ZodBase64URL = /* @__PURE__ */ $constructor("ZodBase64URL", (inst, def) => {
3400
- $ZodBase64URL.init(inst, def);
3401
- ZodStringFormat.init(inst, def);
3402
- });
3403
- const ZodE164 = /* @__PURE__ */ $constructor("ZodE164", (inst, def) => {
3404
- $ZodE164.init(inst, def);
3405
- ZodStringFormat.init(inst, def);
3406
- });
3407
- const ZodJWT = /* @__PURE__ */ $constructor("ZodJWT", (inst, def) => {
3408
- $ZodJWT.init(inst, def);
3409
- ZodStringFormat.init(inst, def);
3410
- });
3411
- const ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
3412
- $ZodUnknown.init(inst, def);
3413
- ZodType.init(inst, def);
3414
- inst._zod.processJSONSchema = (ctx, json, params) => unknownProcessor(inst, ctx, json, params);
3415
- });
3416
- function unknown() {
3417
- return /* @__PURE__ */ _unknown(ZodUnknown);
3418
- }
3419
- const ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
3420
- $ZodNever.init(inst, def);
3421
- ZodType.init(inst, def);
3422
- inst._zod.processJSONSchema = (ctx, json, params) => neverProcessor(inst, ctx, json, params);
3423
- });
3424
- function never(params) {
3425
- return /* @__PURE__ */ _never(ZodNever, params);
3426
- }
3427
- const ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
3428
- $ZodArray.init(inst, def);
3429
- ZodType.init(inst, def);
3430
- inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
3431
- inst.element = def.element;
3432
- inst.min = (minLength, params) => inst.check(/* @__PURE__ */ _minLength(minLength, params));
3433
- inst.nonempty = (params) => inst.check(/* @__PURE__ */ _minLength(1, params));
3434
- inst.max = (maxLength, params) => inst.check(/* @__PURE__ */ _maxLength(maxLength, params));
3435
- inst.length = (len, params) => inst.check(/* @__PURE__ */ _length(len, params));
3436
- inst.unwrap = () => inst.element;
3437
- });
3438
- function array(element, params) {
3439
- return /* @__PURE__ */ _array(ZodArray, element, params);
3440
- }
3441
- const ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
3442
- $ZodObjectJIT.init(inst, def);
3443
- ZodType.init(inst, def);
3444
- inst._zod.processJSONSchema = (ctx, json, params) => objectProcessor(inst, ctx, json, params);
3445
- defineLazy(inst, "shape", () => {
3446
- return def.shape;
3447
- });
3448
- inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
3449
- inst.catchall = (catchall) => inst.clone({
3450
- ...inst._zod.def,
3451
- catchall
3452
- });
3453
- inst.passthrough = () => inst.clone({
3454
- ...inst._zod.def,
3455
- catchall: unknown()
3456
- });
3457
- inst.loose = () => inst.clone({
3458
- ...inst._zod.def,
3459
- catchall: unknown()
3460
- });
3461
- inst.strict = () => inst.clone({
3462
- ...inst._zod.def,
3463
- catchall: never()
3464
- });
3465
- inst.strip = () => inst.clone({
3466
- ...inst._zod.def,
3467
- catchall: void 0
3468
- });
3469
- inst.extend = (incoming) => {
3470
- return extend(inst, incoming);
3471
- };
3472
- inst.safeExtend = (incoming) => {
3473
- return safeExtend(inst, incoming);
3474
- };
3475
- inst.merge = (other) => merge(inst, other);
3476
- inst.pick = (mask) => pick(inst, mask);
3477
- inst.omit = (mask) => omit(inst, mask);
3478
- inst.partial = (...args) => partial(ZodOptional, inst, args[0]);
3479
- inst.required = (...args) => required(ZodNonOptional, inst, args[0]);
3480
- });
3481
- function object(shape, params) {
3482
- return new ZodObject({
3483
- type: "object",
3484
- shape: shape ?? {},
3485
- ...normalizeParams(params)
3486
- });
3487
- }
3488
- const ZodUnion = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
3489
- $ZodUnion.init(inst, def);
3490
- ZodType.init(inst, def);
3491
- inst._zod.processJSONSchema = (ctx, json, params) => unionProcessor(inst, ctx, json, params);
3492
- inst.options = def.options;
3493
- });
3494
- function union(options, params) {
3495
- return new ZodUnion({
3496
- type: "union",
3497
- options,
3498
- ...normalizeParams(params)
3499
- });
3500
- }
3501
- const ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
3502
- $ZodIntersection.init(inst, def);
3503
- ZodType.init(inst, def);
3504
- inst._zod.processJSONSchema = (ctx, json, params) => intersectionProcessor(inst, ctx, json, params);
3505
- });
3506
- function intersection(left, right) {
3507
- return new ZodIntersection({
3508
- type: "intersection",
3509
- left,
3510
- right
3511
- });
3512
- }
3513
- const ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
3514
- $ZodEnum.init(inst, def);
3515
- ZodType.init(inst, def);
3516
- inst._zod.processJSONSchema = (ctx, json, params) => enumProcessor(inst, ctx, json, params);
3517
- inst.enum = def.entries;
3518
- inst.options = Object.values(def.entries);
3519
- const keys = new Set(Object.keys(def.entries));
3520
- inst.extract = (values, params) => {
3521
- const newEntries = {};
3522
- for (const value of values) if (keys.has(value)) newEntries[value] = def.entries[value];
3523
- else throw new Error(`Key ${value} not found in enum`);
3524
- return new ZodEnum({
3525
- ...def,
3526
- checks: [],
3527
- ...normalizeParams(params),
3528
- entries: newEntries
3529
- });
3530
- };
3531
- inst.exclude = (values, params) => {
3532
- const newEntries = { ...def.entries };
3533
- for (const value of values) if (keys.has(value)) delete newEntries[value];
3534
- else throw new Error(`Key ${value} not found in enum`);
3535
- return new ZodEnum({
3536
- ...def,
3537
- checks: [],
3538
- ...normalizeParams(params),
3539
- entries: newEntries
3540
- });
3541
- };
3542
- });
3543
- function _enum(values, params) {
3544
- return new ZodEnum({
3545
- type: "enum",
3546
- entries: Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values,
3547
- ...normalizeParams(params)
3548
- });
3549
- }
3550
- const ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
3551
- $ZodTransform.init(inst, def);
3552
- ZodType.init(inst, def);
3553
- inst._zod.processJSONSchema = (ctx, json, params) => transformProcessor(inst, ctx, json, params);
3554
- inst._zod.parse = (payload, _ctx) => {
3555
- if (_ctx.direction === "backward") throw new $ZodEncodeError(inst.constructor.name);
3556
- payload.addIssue = (issue$1) => {
3557
- if (typeof issue$1 === "string") payload.issues.push(issue(issue$1, payload.value, def));
3558
- else {
3559
- const _issue = issue$1;
3560
- if (_issue.fatal) _issue.continue = false;
3561
- _issue.code ?? (_issue.code = "custom");
3562
- _issue.input ?? (_issue.input = payload.value);
3563
- _issue.inst ?? (_issue.inst = inst);
3564
- payload.issues.push(issue(_issue));
3565
- }
3566
- };
3567
- const output = def.transform(payload.value, payload);
3568
- if (output instanceof Promise) return output.then((output) => {
3569
- payload.value = output;
3570
- return payload;
3571
- });
3572
- payload.value = output;
3573
- return payload;
3574
- };
3575
- });
3576
- function transform(fn) {
3577
- return new ZodTransform({
3578
- type: "transform",
3579
- transform: fn
3580
- });
3581
- }
3582
- const ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
3583
- $ZodOptional.init(inst, def);
3584
- ZodType.init(inst, def);
3585
- inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
3586
- inst.unwrap = () => inst._zod.def.innerType;
3587
- });
3588
- function optional(innerType) {
3589
- return new ZodOptional({
3590
- type: "optional",
3591
- innerType
3592
- });
3593
- }
3594
- const ZodExactOptional = /* @__PURE__ */ $constructor("ZodExactOptional", (inst, def) => {
3595
- $ZodExactOptional.init(inst, def);
3596
- ZodType.init(inst, def);
3597
- inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
3598
- inst.unwrap = () => inst._zod.def.innerType;
3599
- });
3600
- function exactOptional(innerType) {
3601
- return new ZodExactOptional({
3602
- type: "optional",
3603
- innerType
3604
- });
3605
- }
3606
- const ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
3607
- $ZodNullable.init(inst, def);
3608
- ZodType.init(inst, def);
3609
- inst._zod.processJSONSchema = (ctx, json, params) => nullableProcessor(inst, ctx, json, params);
3610
- inst.unwrap = () => inst._zod.def.innerType;
3611
- });
3612
- function nullable(innerType) {
3613
- return new ZodNullable({
3614
- type: "nullable",
3615
- innerType
3616
- });
3617
- }
3618
- const ZodDefault = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
3619
- $ZodDefault.init(inst, def);
3620
- ZodType.init(inst, def);
3621
- inst._zod.processJSONSchema = (ctx, json, params) => defaultProcessor(inst, ctx, json, params);
3622
- inst.unwrap = () => inst._zod.def.innerType;
3623
- inst.removeDefault = inst.unwrap;
3624
- });
3625
- function _default(innerType, defaultValue) {
3626
- return new ZodDefault({
3627
- type: "default",
3628
- innerType,
3629
- get defaultValue() {
3630
- return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
3631
- }
3632
- });
3633
- }
3634
- const ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
3635
- $ZodPrefault.init(inst, def);
3636
- ZodType.init(inst, def);
3637
- inst._zod.processJSONSchema = (ctx, json, params) => prefaultProcessor(inst, ctx, json, params);
3638
- inst.unwrap = () => inst._zod.def.innerType;
3639
- });
3640
- function prefault(innerType, defaultValue) {
3641
- return new ZodPrefault({
3642
- type: "prefault",
3643
- innerType,
3644
- get defaultValue() {
3645
- return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
3646
- }
3647
- });
3648
- }
3649
- const ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
3650
- $ZodNonOptional.init(inst, def);
3651
- ZodType.init(inst, def);
3652
- inst._zod.processJSONSchema = (ctx, json, params) => nonoptionalProcessor(inst, ctx, json, params);
3653
- inst.unwrap = () => inst._zod.def.innerType;
3654
- });
3655
- function nonoptional(innerType, params) {
3656
- return new ZodNonOptional({
3657
- type: "nonoptional",
3658
- innerType,
3659
- ...normalizeParams(params)
3660
- });
3661
- }
3662
- const ZodCatch = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
3663
- $ZodCatch.init(inst, def);
3664
- ZodType.init(inst, def);
3665
- inst._zod.processJSONSchema = (ctx, json, params) => catchProcessor(inst, ctx, json, params);
3666
- inst.unwrap = () => inst._zod.def.innerType;
3667
- inst.removeCatch = inst.unwrap;
3668
- });
3669
- function _catch(innerType, catchValue) {
3670
- return new ZodCatch({
3671
- type: "catch",
3672
- innerType,
3673
- catchValue: typeof catchValue === "function" ? catchValue : () => catchValue
3674
- });
3675
- }
3676
- const ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
3677
- $ZodPipe.init(inst, def);
3678
- ZodType.init(inst, def);
3679
- inst._zod.processJSONSchema = (ctx, json, params) => pipeProcessor(inst, ctx, json, params);
3680
- inst.in = def.in;
3681
- inst.out = def.out;
3682
- });
3683
- function pipe(in_, out) {
3684
- return new ZodPipe({
3685
- type: "pipe",
3686
- in: in_,
3687
- out
3688
- });
3689
- }
3690
- const ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
3691
- $ZodReadonly.init(inst, def);
3692
- ZodType.init(inst, def);
3693
- inst._zod.processJSONSchema = (ctx, json, params) => readonlyProcessor(inst, ctx, json, params);
3694
- inst.unwrap = () => inst._zod.def.innerType;
3695
- });
3696
- function readonly(innerType) {
3697
- return new ZodReadonly({
3698
- type: "readonly",
3699
- innerType
3700
- });
3701
- }
3702
- const ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
3703
- $ZodCustom.init(inst, def);
3704
- ZodType.init(inst, def);
3705
- inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx, json, params);
3706
- });
3707
- function refine(fn, _params = {}) {
3708
- return /* @__PURE__ */ _refine(ZodCustom, fn, _params);
3709
- }
3710
- function superRefine(fn) {
3711
- return /* @__PURE__ */ _superRefine(fn);
3712
- }
3713
372
  //#endregion
3714
373
  //#region src/features/conversations/index.ts
3715
374
  /**
@@ -3738,6 +397,13 @@ async function getConversationSummary(db, durableObjectId) {
3738
397
  return await db.prepare(`SELECT title, summary FROM conversations WHERE durable_object_id = ?`).bind(durableObjectId).first() ?? null;
3739
398
  }
3740
399
  /**
400
+ * Returns all conversations for a user, ordered by most recent.
401
+ */
402
+ async function getConversations(db, userId) {
403
+ const { results } = await db.prepare(`SELECT * FROM conversations WHERE user_id = ? ORDER BY updated_at DESC`).bind(userId).all();
404
+ return results;
405
+ }
406
+ /**
3741
407
  * Writes a generated `title` and `summary` back to the `conversations` row.
3742
408
  */
3743
409
  async function updateConversationSummary(db, durableObjectId, title, summary) {
@@ -3759,9 +425,19 @@ async function generateTitleAndSummary(messages, model, existingSummary) {
3759
425
  const previousContext = existingSummary ? `Previous summary: ${existingSummary}\n\nMost recent messages:` : "Conversation:";
3760
426
  const { output } = await generateText({
3761
427
  model,
3762
- output: Output.object({ schema: object({
3763
- title: string().describe("Short title for the conversation, max 8 words"),
3764
- summary: string().describe("2-3 sentence summary. If the conversation direction has changed from the previous summary, reflect the new direction.")
428
+ output: Output.object({ schema: jsonSchema({
429
+ type: "object",
430
+ properties: {
431
+ title: {
432
+ type: "string",
433
+ description: "Short title for the conversation, max 8 words"
434
+ },
435
+ summary: {
436
+ type: "string",
437
+ description: "2-3 sentence summary. If the conversation direction has changed from the previous summary, reflect the new direction."
438
+ }
439
+ },
440
+ required: ["title", "summary"]
3765
441
  }) }),
3766
442
  prompt: `${previousContext}\n\n${formatMessagesForSummary(recentMessages)}`
3767
443
  });
@@ -3797,21 +473,21 @@ async function generateConversationSummary(db, durableObjectId, messages, model)
3797
473
  */
3798
474
  var AIChatAgent = class extends AIChatAgent$1 {
3799
475
  /**
3800
- * Composed user identifier extracted from `options.body.userId` during
3801
- * `buildLLMParams`. Expected format: `{agreementNumber}_{userId}`, e.g. `148583_matt`.
3802
- * Undefined if the client did not include `userId` in the request body.
476
+ * Composed user identifier extracted from the query params on the initial connection.
477
+ * Expected format: `{agreementNumber}_{userId}`, e.g. `148583_matt`.
478
+ * Undefined if the client did not include `userId`.
3803
479
  */
3804
480
  _userId;
3805
481
  /**
3806
482
  * Resolves the D1 database binding and userId required for all D1 writes.
3807
483
  * Returns null and silently no-ops if AGENT_DB is not bound.
3808
- * Returns null and logs an error if userId is missing from the request body.
484
+ * Returns null and logs an error if userId is missing.
3809
485
  */
3810
486
  resolveD1Context() {
3811
487
  const db = this.env.AGENT_DB;
3812
488
  if (!db) return null;
3813
489
  if (!this._userId) {
3814
- console.error("[AIChatAgent] Logging & conversation tracking skipped: userId not set on request body");
490
+ console.error("[AIChatAgent] Logging & conversation tracking skipped: userId not provided in connection query params");
3815
491
  return null;
3816
492
  }
3817
493
  return {
@@ -3819,6 +495,23 @@ var AIChatAgent = class extends AIChatAgent$1 {
3819
495
  userId: this._userId
3820
496
  };
3821
497
  }
498
+ async onConnect(connection, ctx) {
499
+ super.onConnect(connection, ctx);
500
+ const userId = new URL(ctx.request.url).searchParams.get("userId");
501
+ if (!userId) {
502
+ connection.close(3e3, "userId query parameter is required");
503
+ return;
504
+ }
505
+ this._userId = userId;
506
+ }
507
+ /**
508
+ * Returns all conversations for the current user.
509
+ */
510
+ @callable() async getConversations() {
511
+ const context = this.resolveD1Context();
512
+ if (!context) return;
513
+ return getConversations(context.db, context.userId);
514
+ }
3822
515
  /**
3823
516
  * Writes an audit event to D1 if `AGENT_DB` is bound on the environment,
3824
517
  * otherwise silently does nothing.
@@ -3883,8 +576,6 @@ var AIChatAgent = class extends AIChatAgent$1 {
3883
576
  * ```
3884
577
  */
3885
578
  async buildLLMParams(config) {
3886
- const body = config.options?.body;
3887
- this._userId = typeof body?.userId === "string" ? body.userId : void 0;
3888
579
  const maxMessagesBeforeCompaction = "maxMessagesBeforeCompaction" in config ? config.maxMessagesBeforeCompaction : 15;
3889
580
  const onFinishWithErrorLogging = async (result) => {
3890
581
  if (result.finishReason !== "stop" && result.finishReason !== "tool-calls") await this.log("turn error", { finishReason: result.finishReason });
@@ -3949,44 +640,4 @@ var AIChatAgent = class extends AIChatAgent$1 {
3949
640
  }
3950
641
  };
3951
642
  //#endregion
3952
- //#region src/decorators/guard.ts
3953
- /**
3954
- * Method decorator (TypeScript 5+ stage-3) that runs `guardFn` with the second
3955
- * argument's `body` (the chat request body). If `guardFn` returns a
3956
- * {@link Response}, that value is returned and the original method is not called.
3957
- *
3958
- * Intended for `onChatMessage(onFinish, options?)` on subclasses of
3959
- * `AIChatAgent`; `options` is read as `{ body?: TBody }`.
3960
- *
3961
- * @param guardFn - Called with `options?.body` (cast to `TBody`) before the method body.
3962
- *
3963
- * @example
3964
- * ```ts
3965
- * interface RequestBody { token: string }
3966
- *
3967
- * const requireToken: GuardFn<RequestBody> = async (body) => {
3968
- * if (!await isValidToken(body?.token)) {
3969
- * return new Response("Unauthorized", { status: 401 });
3970
- * }
3971
- * };
3972
- *
3973
- * class MyAgent extends AIChatAgent<Env> {
3974
- * @guard(requireToken)
3975
- * async onChatMessage(onFinish, options) {
3976
- * // ...
3977
- * }
3978
- * }
3979
- * ```
3980
- */
3981
- function guard(guardFn) {
3982
- return function(target, _context) {
3983
- return async function(...args) {
3984
- const options = args[1];
3985
- const result = await guardFn(options?.body ?? {});
3986
- if (result instanceof Response) return result;
3987
- return target.apply(this, args);
3988
- };
3989
- };
3990
- }
3991
- //#endregion
3992
- export { AIChatAgent, buildLLMParams, guard };
643
+ export { AIChatAgent, buildLLMParams };