@elizaos/plugin-twitter 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,3 +1,7 @@
1
+ import {
2
+ __export
3
+ } from "./chunk-PZ5AY32C.js";
4
+
1
5
  // src/index.ts
2
6
  import {
3
7
  ChannelType as ChannelType6,
@@ -80,7 +84,7 @@ var Platform = class _Platform {
80
84
  */
81
85
  static async importPlatform() {
82
86
  if (PLATFORM_NODE) {
83
- const { platform } = await import("./node-WSVEVHDY.js");
87
+ const { platform } = await import("./node-L7ZVN5QV.js");
84
88
  return platform;
85
89
  }
86
90
  return genericPlatform;
@@ -8539,96 +8543,4188 @@ import {
8539
8543
  createUniqueUuid as createUniqueUuid5,
8540
8544
  logger as logger7
8541
8545
  } from "@elizaos/core";
8542
- var convertToCoreTweet = (tweet) => ({
8543
- id: tweet.id,
8544
- text: tweet.text,
8545
- conversationId: tweet.conversationId,
8546
- timestamp: tweet.timestamp,
8547
- userId: tweet.userId,
8548
- username: tweet.username,
8549
- name: tweet.name,
8550
- inReplyToStatusId: tweet.inReplyToStatusId,
8551
- permanentUrl: tweet.permanentUrl,
8552
- photos: tweet.photos,
8553
- hashtags: tweet.hashtags,
8554
- mentions: tweet.mentions.map((mention) => mention.username),
8555
- urls: tweet.urls,
8556
- videos: tweet.videos,
8557
- thread: tweet.thread
8546
+
8547
+ // src/environment.ts
8548
+ import { parseBooleanFromText } from "@elizaos/core";
8549
+
8550
+ // node_modules/zod/dist/esm/v3/external.js
8551
+ var external_exports = {};
8552
+ __export(external_exports, {
8553
+ BRAND: () => BRAND,
8554
+ DIRTY: () => DIRTY,
8555
+ EMPTY_PATH: () => EMPTY_PATH,
8556
+ INVALID: () => INVALID,
8557
+ NEVER: () => NEVER,
8558
+ OK: () => OK,
8559
+ ParseStatus: () => ParseStatus,
8560
+ Schema: () => ZodType,
8561
+ ZodAny: () => ZodAny,
8562
+ ZodArray: () => ZodArray,
8563
+ ZodBigInt: () => ZodBigInt,
8564
+ ZodBoolean: () => ZodBoolean,
8565
+ ZodBranded: () => ZodBranded,
8566
+ ZodCatch: () => ZodCatch,
8567
+ ZodDate: () => ZodDate,
8568
+ ZodDefault: () => ZodDefault,
8569
+ ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
8570
+ ZodEffects: () => ZodEffects,
8571
+ ZodEnum: () => ZodEnum,
8572
+ ZodError: () => ZodError,
8573
+ ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
8574
+ ZodFunction: () => ZodFunction,
8575
+ ZodIntersection: () => ZodIntersection,
8576
+ ZodIssueCode: () => ZodIssueCode,
8577
+ ZodLazy: () => ZodLazy,
8578
+ ZodLiteral: () => ZodLiteral,
8579
+ ZodMap: () => ZodMap,
8580
+ ZodNaN: () => ZodNaN,
8581
+ ZodNativeEnum: () => ZodNativeEnum,
8582
+ ZodNever: () => ZodNever,
8583
+ ZodNull: () => ZodNull,
8584
+ ZodNullable: () => ZodNullable,
8585
+ ZodNumber: () => ZodNumber,
8586
+ ZodObject: () => ZodObject,
8587
+ ZodOptional: () => ZodOptional,
8588
+ ZodParsedType: () => ZodParsedType,
8589
+ ZodPipeline: () => ZodPipeline,
8590
+ ZodPromise: () => ZodPromise,
8591
+ ZodReadonly: () => ZodReadonly,
8592
+ ZodRecord: () => ZodRecord,
8593
+ ZodSchema: () => ZodType,
8594
+ ZodSet: () => ZodSet,
8595
+ ZodString: () => ZodString,
8596
+ ZodSymbol: () => ZodSymbol,
8597
+ ZodTransformer: () => ZodEffects,
8598
+ ZodTuple: () => ZodTuple,
8599
+ ZodType: () => ZodType,
8600
+ ZodUndefined: () => ZodUndefined,
8601
+ ZodUnion: () => ZodUnion,
8602
+ ZodUnknown: () => ZodUnknown,
8603
+ ZodVoid: () => ZodVoid,
8604
+ addIssueToContext: () => addIssueToContext,
8605
+ any: () => anyType,
8606
+ array: () => arrayType,
8607
+ bigint: () => bigIntType,
8608
+ boolean: () => booleanType,
8609
+ coerce: () => coerce,
8610
+ custom: () => custom,
8611
+ date: () => dateType,
8612
+ datetimeRegex: () => datetimeRegex,
8613
+ defaultErrorMap: () => en_default,
8614
+ discriminatedUnion: () => discriminatedUnionType,
8615
+ effect: () => effectsType,
8616
+ enum: () => enumType,
8617
+ function: () => functionType,
8618
+ getErrorMap: () => getErrorMap,
8619
+ getParsedType: () => getParsedType,
8620
+ instanceof: () => instanceOfType,
8621
+ intersection: () => intersectionType,
8622
+ isAborted: () => isAborted,
8623
+ isAsync: () => isAsync,
8624
+ isDirty: () => isDirty,
8625
+ isValid: () => isValid,
8626
+ late: () => late,
8627
+ lazy: () => lazyType,
8628
+ literal: () => literalType,
8629
+ makeIssue: () => makeIssue,
8630
+ map: () => mapType,
8631
+ nan: () => nanType,
8632
+ nativeEnum: () => nativeEnumType,
8633
+ never: () => neverType,
8634
+ null: () => nullType,
8635
+ nullable: () => nullableType,
8636
+ number: () => numberType,
8637
+ object: () => objectType,
8638
+ objectUtil: () => objectUtil,
8639
+ oboolean: () => oboolean,
8640
+ onumber: () => onumber,
8641
+ optional: () => optionalType,
8642
+ ostring: () => ostring,
8643
+ pipeline: () => pipelineType,
8644
+ preprocess: () => preprocessType,
8645
+ promise: () => promiseType,
8646
+ quotelessJson: () => quotelessJson,
8647
+ record: () => recordType,
8648
+ set: () => setType,
8649
+ setErrorMap: () => setErrorMap,
8650
+ strictObject: () => strictObjectType,
8651
+ string: () => stringType,
8652
+ symbol: () => symbolType,
8653
+ transformer: () => effectsType,
8654
+ tuple: () => tupleType,
8655
+ undefined: () => undefinedType,
8656
+ union: () => unionType,
8657
+ unknown: () => unknownType,
8658
+ util: () => util,
8659
+ void: () => voidType
8558
8660
  });
8559
- var convertToCoreTweets = (tweets) => tweets.map(convertToCoreTweet);
8560
- var TwitterInteractionClient = class {
8561
- /**
8562
- * Constructor for setting up a new instance with the provided client, runtime, and state.
8563
- * @param {ClientBase} client - The client being used for communication.
8564
- * @param {IAgentRuntime} runtime - The runtime environment for the agent.
8565
- * @param {any} state - The initial state of the agent.
8566
- */
8567
- constructor(client, runtime, state) {
8568
- this.client = client;
8569
- this.runtime = runtime;
8570
- this.state = state;
8571
- this.isDryRun = this.state?.TWITTER_DRY_RUN || this.runtime.getSetting("TWITTER_DRY_RUN");
8661
+
8662
+ // node_modules/zod/dist/esm/v3/helpers/util.js
8663
+ var util;
8664
+ (function(util2) {
8665
+ util2.assertEqual = (_) => {
8666
+ };
8667
+ function assertIs(_arg) {
8572
8668
  }
8573
- /**
8574
- * Asynchronously starts the process of handling Twitter interactions on a loop.
8575
- * Uses an interval based on the 'TWITTER_POLL_INTERVAL' setting, or defaults to 2 minutes if not set.
8576
- */
8577
- async start() {
8578
- const handleTwitterInteractionsLoop = () => {
8579
- const interactionInterval = (this.state?.TWITTER_POLL_INTERVAL || this.runtime.getSetting(
8580
- "TWITTER_POLL_INTERVAL"
8581
- ) || 120) * 1e3;
8582
- this.handleTwitterInteractions();
8583
- setTimeout(handleTwitterInteractionsLoop, interactionInterval);
8669
+ util2.assertIs = assertIs;
8670
+ function assertNever(_x) {
8671
+ throw new Error();
8672
+ }
8673
+ util2.assertNever = assertNever;
8674
+ util2.arrayToEnum = (items) => {
8675
+ const obj = {};
8676
+ for (const item of items) {
8677
+ obj[item] = item;
8678
+ }
8679
+ return obj;
8680
+ };
8681
+ util2.getValidEnumValues = (obj) => {
8682
+ const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
8683
+ const filtered = {};
8684
+ for (const k of validKeys) {
8685
+ filtered[k] = obj[k];
8686
+ }
8687
+ return util2.objectValues(filtered);
8688
+ };
8689
+ util2.objectValues = (obj) => {
8690
+ return util2.objectKeys(obj).map(function(e) {
8691
+ return obj[e];
8692
+ });
8693
+ };
8694
+ util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
8695
+ const keys = [];
8696
+ for (const key in object) {
8697
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
8698
+ keys.push(key);
8699
+ }
8700
+ }
8701
+ return keys;
8702
+ };
8703
+ util2.find = (arr, checker) => {
8704
+ for (const item of arr) {
8705
+ if (checker(item))
8706
+ return item;
8707
+ }
8708
+ return void 0;
8709
+ };
8710
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
8711
+ function joinValues(array, separator = " | ") {
8712
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
8713
+ }
8714
+ util2.joinValues = joinValues;
8715
+ util2.jsonStringifyReplacer = (_, value) => {
8716
+ if (typeof value === "bigint") {
8717
+ return value.toString();
8718
+ }
8719
+ return value;
8720
+ };
8721
+ })(util || (util = {}));
8722
+ var objectUtil;
8723
+ (function(objectUtil2) {
8724
+ objectUtil2.mergeShapes = (first, second) => {
8725
+ return {
8726
+ ...first,
8727
+ ...second
8728
+ // second overwrites first
8584
8729
  };
8585
- handleTwitterInteractionsLoop();
8730
+ };
8731
+ })(objectUtil || (objectUtil = {}));
8732
+ var ZodParsedType = util.arrayToEnum([
8733
+ "string",
8734
+ "nan",
8735
+ "number",
8736
+ "integer",
8737
+ "float",
8738
+ "boolean",
8739
+ "date",
8740
+ "bigint",
8741
+ "symbol",
8742
+ "function",
8743
+ "undefined",
8744
+ "null",
8745
+ "array",
8746
+ "object",
8747
+ "unknown",
8748
+ "promise",
8749
+ "void",
8750
+ "never",
8751
+ "map",
8752
+ "set"
8753
+ ]);
8754
+ var getParsedType = (data) => {
8755
+ const t = typeof data;
8756
+ switch (t) {
8757
+ case "undefined":
8758
+ return ZodParsedType.undefined;
8759
+ case "string":
8760
+ return ZodParsedType.string;
8761
+ case "number":
8762
+ return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
8763
+ case "boolean":
8764
+ return ZodParsedType.boolean;
8765
+ case "function":
8766
+ return ZodParsedType.function;
8767
+ case "bigint":
8768
+ return ZodParsedType.bigint;
8769
+ case "symbol":
8770
+ return ZodParsedType.symbol;
8771
+ case "object":
8772
+ if (Array.isArray(data)) {
8773
+ return ZodParsedType.array;
8774
+ }
8775
+ if (data === null) {
8776
+ return ZodParsedType.null;
8777
+ }
8778
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
8779
+ return ZodParsedType.promise;
8780
+ }
8781
+ if (typeof Map !== "undefined" && data instanceof Map) {
8782
+ return ZodParsedType.map;
8783
+ }
8784
+ if (typeof Set !== "undefined" && data instanceof Set) {
8785
+ return ZodParsedType.set;
8786
+ }
8787
+ if (typeof Date !== "undefined" && data instanceof Date) {
8788
+ return ZodParsedType.date;
8789
+ }
8790
+ return ZodParsedType.object;
8791
+ default:
8792
+ return ZodParsedType.unknown;
8586
8793
  }
8587
- /**
8588
- * Asynchronously handles Twitter interactions by checking for mentions, processing tweets, and updating the last checked tweet ID.
8589
- */
8590
- async handleTwitterInteractions() {
8591
- logger7.log("Checking Twitter interactions");
8592
- const twitterUsername = this.client.profile?.username;
8593
- try {
8594
- const cursorKey = `twitter/${twitterUsername}/mention_cursor`;
8595
- const cachedCursor = await this.runtime.getCache(cursorKey);
8596
- const searchResult = await this.client.fetchSearchTweets(
8597
- `@${twitterUsername}`,
8598
- 20,
8599
- 1 /* Latest */,
8600
- String(cachedCursor)
8601
- );
8602
- const mentionCandidates = searchResult.tweets;
8603
- if (mentionCandidates.length > 0 && searchResult.previous) {
8604
- await this.runtime.setCache(cursorKey, searchResult.previous);
8605
- } else if (!searchResult.previous && !searchResult.next) {
8606
- await this.runtime.setCache(cursorKey, "");
8794
+ };
8795
+
8796
+ // node_modules/zod/dist/esm/v3/ZodError.js
8797
+ var ZodIssueCode = util.arrayToEnum([
8798
+ "invalid_type",
8799
+ "invalid_literal",
8800
+ "custom",
8801
+ "invalid_union",
8802
+ "invalid_union_discriminator",
8803
+ "invalid_enum_value",
8804
+ "unrecognized_keys",
8805
+ "invalid_arguments",
8806
+ "invalid_return_type",
8807
+ "invalid_date",
8808
+ "invalid_string",
8809
+ "too_small",
8810
+ "too_big",
8811
+ "invalid_intersection_types",
8812
+ "not_multiple_of",
8813
+ "not_finite"
8814
+ ]);
8815
+ var quotelessJson = (obj) => {
8816
+ const json = JSON.stringify(obj, null, 2);
8817
+ return json.replace(/"([^"]+)":/g, "$1:");
8818
+ };
8819
+ var ZodError = class _ZodError extends Error {
8820
+ get errors() {
8821
+ return this.issues;
8822
+ }
8823
+ constructor(issues) {
8824
+ super();
8825
+ this.issues = [];
8826
+ this.addIssue = (sub) => {
8827
+ this.issues = [...this.issues, sub];
8828
+ };
8829
+ this.addIssues = (subs = []) => {
8830
+ this.issues = [...this.issues, ...subs];
8831
+ };
8832
+ const actualProto = new.target.prototype;
8833
+ if (Object.setPrototypeOf) {
8834
+ Object.setPrototypeOf(this, actualProto);
8835
+ } else {
8836
+ this.__proto__ = actualProto;
8837
+ }
8838
+ this.name = "ZodError";
8839
+ this.issues = issues;
8840
+ }
8841
+ format(_mapper) {
8842
+ const mapper = _mapper || function(issue) {
8843
+ return issue.message;
8844
+ };
8845
+ const fieldErrors = { _errors: [] };
8846
+ const processError = (error) => {
8847
+ for (const issue of error.issues) {
8848
+ if (issue.code === "invalid_union") {
8849
+ issue.unionErrors.map(processError);
8850
+ } else if (issue.code === "invalid_return_type") {
8851
+ processError(issue.returnTypeError);
8852
+ } else if (issue.code === "invalid_arguments") {
8853
+ processError(issue.argumentsError);
8854
+ } else if (issue.path.length === 0) {
8855
+ fieldErrors._errors.push(mapper(issue));
8856
+ } else {
8857
+ let curr = fieldErrors;
8858
+ let i = 0;
8859
+ while (i < issue.path.length) {
8860
+ const el = issue.path[i];
8861
+ const terminal = i === issue.path.length - 1;
8862
+ if (!terminal) {
8863
+ curr[el] = curr[el] || { _errors: [] };
8864
+ } else {
8865
+ curr[el] = curr[el] || { _errors: [] };
8866
+ curr[el]._errors.push(mapper(issue));
8867
+ }
8868
+ curr = curr[el];
8869
+ i++;
8870
+ }
8871
+ }
8607
8872
  }
8608
- await this.processMentionTweets(mentionCandidates);
8609
- await this.client.cacheLatestCheckedTweetId();
8610
- logger7.log("Finished checking Twitter interactions");
8611
- } catch (error) {
8612
- logger7.error("Error handling Twitter interactions:", error);
8873
+ };
8874
+ processError(this);
8875
+ return fieldErrors;
8876
+ }
8877
+ static assert(value) {
8878
+ if (!(value instanceof _ZodError)) {
8879
+ throw new Error(`Not a ZodError: ${value}`);
8613
8880
  }
8614
8881
  }
8615
- /**
8616
- * Processes all incoming tweets that mention the bot.
8617
- * For each new tweet:
8618
- * - Ensures world, room, and connection exist
8619
- * - Saves the tweet as memory
8620
- * - Emits thread-related events (THREAD_CREATED / THREAD_UPDATED)
8621
- * - Delegates tweet content to `handleTweet` for reply generation
8622
- *
8623
- * Note: MENTION_RECEIVED is currently disabled (see TODO below)
8624
- */
8625
- async processMentionTweets(mentionCandidates) {
8626
- logger7.log(
8627
- "Completed checking mentioned tweets:",
8628
- mentionCandidates.length
8629
- );
8630
- let uniqueTweetCandidates = [...mentionCandidates];
8631
- uniqueTweetCandidates = uniqueTweetCandidates.sort((a, b) => a.id.localeCompare(b.id)).filter((tweet) => tweet.userId !== this.client.profile.id);
8882
+ toString() {
8883
+ return this.message;
8884
+ }
8885
+ get message() {
8886
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
8887
+ }
8888
+ get isEmpty() {
8889
+ return this.issues.length === 0;
8890
+ }
8891
+ flatten(mapper = (issue) => issue.message) {
8892
+ const fieldErrors = {};
8893
+ const formErrors = [];
8894
+ for (const sub of this.issues) {
8895
+ if (sub.path.length > 0) {
8896
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
8897
+ fieldErrors[sub.path[0]].push(mapper(sub));
8898
+ } else {
8899
+ formErrors.push(mapper(sub));
8900
+ }
8901
+ }
8902
+ return { formErrors, fieldErrors };
8903
+ }
8904
+ get formErrors() {
8905
+ return this.flatten();
8906
+ }
8907
+ };
8908
+ ZodError.create = (issues) => {
8909
+ const error = new ZodError(issues);
8910
+ return error;
8911
+ };
8912
+
8913
+ // node_modules/zod/dist/esm/v3/locales/en.js
8914
+ var errorMap = (issue, _ctx) => {
8915
+ let message;
8916
+ switch (issue.code) {
8917
+ case ZodIssueCode.invalid_type:
8918
+ if (issue.received === ZodParsedType.undefined) {
8919
+ message = "Required";
8920
+ } else {
8921
+ message = `Expected ${issue.expected}, received ${issue.received}`;
8922
+ }
8923
+ break;
8924
+ case ZodIssueCode.invalid_literal:
8925
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
8926
+ break;
8927
+ case ZodIssueCode.unrecognized_keys:
8928
+ message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
8929
+ break;
8930
+ case ZodIssueCode.invalid_union:
8931
+ message = `Invalid input`;
8932
+ break;
8933
+ case ZodIssueCode.invalid_union_discriminator:
8934
+ message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
8935
+ break;
8936
+ case ZodIssueCode.invalid_enum_value:
8937
+ message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
8938
+ break;
8939
+ case ZodIssueCode.invalid_arguments:
8940
+ message = `Invalid function arguments`;
8941
+ break;
8942
+ case ZodIssueCode.invalid_return_type:
8943
+ message = `Invalid function return type`;
8944
+ break;
8945
+ case ZodIssueCode.invalid_date:
8946
+ message = `Invalid date`;
8947
+ break;
8948
+ case ZodIssueCode.invalid_string:
8949
+ if (typeof issue.validation === "object") {
8950
+ if ("includes" in issue.validation) {
8951
+ message = `Invalid input: must include "${issue.validation.includes}"`;
8952
+ if (typeof issue.validation.position === "number") {
8953
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
8954
+ }
8955
+ } else if ("startsWith" in issue.validation) {
8956
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
8957
+ } else if ("endsWith" in issue.validation) {
8958
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
8959
+ } else {
8960
+ util.assertNever(issue.validation);
8961
+ }
8962
+ } else if (issue.validation !== "regex") {
8963
+ message = `Invalid ${issue.validation}`;
8964
+ } else {
8965
+ message = "Invalid";
8966
+ }
8967
+ break;
8968
+ case ZodIssueCode.too_small:
8969
+ if (issue.type === "array")
8970
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
8971
+ else if (issue.type === "string")
8972
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
8973
+ else if (issue.type === "number")
8974
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
8975
+ else if (issue.type === "date")
8976
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
8977
+ else
8978
+ message = "Invalid input";
8979
+ break;
8980
+ case ZodIssueCode.too_big:
8981
+ if (issue.type === "array")
8982
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
8983
+ else if (issue.type === "string")
8984
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
8985
+ else if (issue.type === "number")
8986
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
8987
+ else if (issue.type === "bigint")
8988
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
8989
+ else if (issue.type === "date")
8990
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
8991
+ else
8992
+ message = "Invalid input";
8993
+ break;
8994
+ case ZodIssueCode.custom:
8995
+ message = `Invalid input`;
8996
+ break;
8997
+ case ZodIssueCode.invalid_intersection_types:
8998
+ message = `Intersection results could not be merged`;
8999
+ break;
9000
+ case ZodIssueCode.not_multiple_of:
9001
+ message = `Number must be a multiple of ${issue.multipleOf}`;
9002
+ break;
9003
+ case ZodIssueCode.not_finite:
9004
+ message = "Number must be finite";
9005
+ break;
9006
+ default:
9007
+ message = _ctx.defaultError;
9008
+ util.assertNever(issue);
9009
+ }
9010
+ return { message };
9011
+ };
9012
+ var en_default = errorMap;
9013
+
9014
+ // node_modules/zod/dist/esm/v3/errors.js
9015
+ var overrideErrorMap = en_default;
9016
+ function setErrorMap(map) {
9017
+ overrideErrorMap = map;
9018
+ }
9019
+ function getErrorMap() {
9020
+ return overrideErrorMap;
9021
+ }
9022
+
9023
+ // node_modules/zod/dist/esm/v3/helpers/parseUtil.js
9024
+ var makeIssue = (params) => {
9025
+ const { data, path: path3, errorMaps, issueData } = params;
9026
+ const fullPath = [...path3, ...issueData.path || []];
9027
+ const fullIssue = {
9028
+ ...issueData,
9029
+ path: fullPath
9030
+ };
9031
+ if (issueData.message !== void 0) {
9032
+ return {
9033
+ ...issueData,
9034
+ path: fullPath,
9035
+ message: issueData.message
9036
+ };
9037
+ }
9038
+ let errorMessage = "";
9039
+ const maps = errorMaps.filter((m) => !!m).slice().reverse();
9040
+ for (const map of maps) {
9041
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
9042
+ }
9043
+ return {
9044
+ ...issueData,
9045
+ path: fullPath,
9046
+ message: errorMessage
9047
+ };
9048
+ };
9049
+ var EMPTY_PATH = [];
9050
+ function addIssueToContext(ctx, issueData) {
9051
+ const overrideMap = getErrorMap();
9052
+ const issue = makeIssue({
9053
+ issueData,
9054
+ data: ctx.data,
9055
+ path: ctx.path,
9056
+ errorMaps: [
9057
+ ctx.common.contextualErrorMap,
9058
+ // contextual error map is first priority
9059
+ ctx.schemaErrorMap,
9060
+ // then schema-bound map if available
9061
+ overrideMap,
9062
+ // then global override map
9063
+ overrideMap === en_default ? void 0 : en_default
9064
+ // then global default map
9065
+ ].filter((x) => !!x)
9066
+ });
9067
+ ctx.common.issues.push(issue);
9068
+ }
9069
+ var ParseStatus = class _ParseStatus {
9070
+ constructor() {
9071
+ this.value = "valid";
9072
+ }
9073
+ dirty() {
9074
+ if (this.value === "valid")
9075
+ this.value = "dirty";
9076
+ }
9077
+ abort() {
9078
+ if (this.value !== "aborted")
9079
+ this.value = "aborted";
9080
+ }
9081
+ static mergeArray(status, results) {
9082
+ const arrayValue = [];
9083
+ for (const s of results) {
9084
+ if (s.status === "aborted")
9085
+ return INVALID;
9086
+ if (s.status === "dirty")
9087
+ status.dirty();
9088
+ arrayValue.push(s.value);
9089
+ }
9090
+ return { status: status.value, value: arrayValue };
9091
+ }
9092
+ static async mergeObjectAsync(status, pairs) {
9093
+ const syncPairs = [];
9094
+ for (const pair of pairs) {
9095
+ const key = await pair.key;
9096
+ const value = await pair.value;
9097
+ syncPairs.push({
9098
+ key,
9099
+ value
9100
+ });
9101
+ }
9102
+ return _ParseStatus.mergeObjectSync(status, syncPairs);
9103
+ }
9104
+ static mergeObjectSync(status, pairs) {
9105
+ const finalObject = {};
9106
+ for (const pair of pairs) {
9107
+ const { key, value } = pair;
9108
+ if (key.status === "aborted")
9109
+ return INVALID;
9110
+ if (value.status === "aborted")
9111
+ return INVALID;
9112
+ if (key.status === "dirty")
9113
+ status.dirty();
9114
+ if (value.status === "dirty")
9115
+ status.dirty();
9116
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
9117
+ finalObject[key.value] = value.value;
9118
+ }
9119
+ }
9120
+ return { status: status.value, value: finalObject };
9121
+ }
9122
+ };
9123
+ var INVALID = Object.freeze({
9124
+ status: "aborted"
9125
+ });
9126
+ var DIRTY = (value) => ({ status: "dirty", value });
9127
+ var OK = (value) => ({ status: "valid", value });
9128
+ var isAborted = (x) => x.status === "aborted";
9129
+ var isDirty = (x) => x.status === "dirty";
9130
+ var isValid = (x) => x.status === "valid";
9131
+ var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
9132
+
9133
+ // node_modules/zod/dist/esm/v3/helpers/errorUtil.js
9134
+ var errorUtil;
9135
+ (function(errorUtil2) {
9136
+ errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
9137
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
9138
+ })(errorUtil || (errorUtil = {}));
9139
+
9140
+ // node_modules/zod/dist/esm/v3/types.js
9141
+ var ParseInputLazyPath = class {
9142
+ constructor(parent, value, path3, key) {
9143
+ this._cachedPath = [];
9144
+ this.parent = parent;
9145
+ this.data = value;
9146
+ this._path = path3;
9147
+ this._key = key;
9148
+ }
9149
+ get path() {
9150
+ if (!this._cachedPath.length) {
9151
+ if (Array.isArray(this._key)) {
9152
+ this._cachedPath.push(...this._path, ...this._key);
9153
+ } else {
9154
+ this._cachedPath.push(...this._path, this._key);
9155
+ }
9156
+ }
9157
+ return this._cachedPath;
9158
+ }
9159
+ };
9160
+ var handleResult = (ctx, result) => {
9161
+ if (isValid(result)) {
9162
+ return { success: true, data: result.value };
9163
+ } else {
9164
+ if (!ctx.common.issues.length) {
9165
+ throw new Error("Validation failed but no issues detected.");
9166
+ }
9167
+ return {
9168
+ success: false,
9169
+ get error() {
9170
+ if (this._error)
9171
+ return this._error;
9172
+ const error = new ZodError(ctx.common.issues);
9173
+ this._error = error;
9174
+ return this._error;
9175
+ }
9176
+ };
9177
+ }
9178
+ };
9179
+ function processCreateParams(params) {
9180
+ if (!params)
9181
+ return {};
9182
+ const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
9183
+ if (errorMap2 && (invalid_type_error || required_error)) {
9184
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
9185
+ }
9186
+ if (errorMap2)
9187
+ return { errorMap: errorMap2, description };
9188
+ const customMap = (iss, ctx) => {
9189
+ const { message } = params;
9190
+ if (iss.code === "invalid_enum_value") {
9191
+ return { message: message ?? ctx.defaultError };
9192
+ }
9193
+ if (typeof ctx.data === "undefined") {
9194
+ return { message: message ?? required_error ?? ctx.defaultError };
9195
+ }
9196
+ if (iss.code !== "invalid_type")
9197
+ return { message: ctx.defaultError };
9198
+ return { message: message ?? invalid_type_error ?? ctx.defaultError };
9199
+ };
9200
+ return { errorMap: customMap, description };
9201
+ }
9202
+ var ZodType = class {
9203
+ get description() {
9204
+ return this._def.description;
9205
+ }
9206
+ _getType(input) {
9207
+ return getParsedType(input.data);
9208
+ }
9209
+ _getOrReturnCtx(input, ctx) {
9210
+ return ctx || {
9211
+ common: input.parent.common,
9212
+ data: input.data,
9213
+ parsedType: getParsedType(input.data),
9214
+ schemaErrorMap: this._def.errorMap,
9215
+ path: input.path,
9216
+ parent: input.parent
9217
+ };
9218
+ }
9219
+ _processInputParams(input) {
9220
+ return {
9221
+ status: new ParseStatus(),
9222
+ ctx: {
9223
+ common: input.parent.common,
9224
+ data: input.data,
9225
+ parsedType: getParsedType(input.data),
9226
+ schemaErrorMap: this._def.errorMap,
9227
+ path: input.path,
9228
+ parent: input.parent
9229
+ }
9230
+ };
9231
+ }
9232
+ _parseSync(input) {
9233
+ const result = this._parse(input);
9234
+ if (isAsync(result)) {
9235
+ throw new Error("Synchronous parse encountered promise.");
9236
+ }
9237
+ return result;
9238
+ }
9239
+ _parseAsync(input) {
9240
+ const result = this._parse(input);
9241
+ return Promise.resolve(result);
9242
+ }
9243
+ parse(data, params) {
9244
+ const result = this.safeParse(data, params);
9245
+ if (result.success)
9246
+ return result.data;
9247
+ throw result.error;
9248
+ }
9249
+ safeParse(data, params) {
9250
+ const ctx = {
9251
+ common: {
9252
+ issues: [],
9253
+ async: params?.async ?? false,
9254
+ contextualErrorMap: params?.errorMap
9255
+ },
9256
+ path: params?.path || [],
9257
+ schemaErrorMap: this._def.errorMap,
9258
+ parent: null,
9259
+ data,
9260
+ parsedType: getParsedType(data)
9261
+ };
9262
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
9263
+ return handleResult(ctx, result);
9264
+ }
9265
+ "~validate"(data) {
9266
+ const ctx = {
9267
+ common: {
9268
+ issues: [],
9269
+ async: !!this["~standard"].async
9270
+ },
9271
+ path: [],
9272
+ schemaErrorMap: this._def.errorMap,
9273
+ parent: null,
9274
+ data,
9275
+ parsedType: getParsedType(data)
9276
+ };
9277
+ if (!this["~standard"].async) {
9278
+ try {
9279
+ const result = this._parseSync({ data, path: [], parent: ctx });
9280
+ return isValid(result) ? {
9281
+ value: result.value
9282
+ } : {
9283
+ issues: ctx.common.issues
9284
+ };
9285
+ } catch (err) {
9286
+ if (err?.message?.toLowerCase()?.includes("encountered")) {
9287
+ this["~standard"].async = true;
9288
+ }
9289
+ ctx.common = {
9290
+ issues: [],
9291
+ async: true
9292
+ };
9293
+ }
9294
+ }
9295
+ return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
9296
+ value: result.value
9297
+ } : {
9298
+ issues: ctx.common.issues
9299
+ });
9300
+ }
9301
+ async parseAsync(data, params) {
9302
+ const result = await this.safeParseAsync(data, params);
9303
+ if (result.success)
9304
+ return result.data;
9305
+ throw result.error;
9306
+ }
9307
+ async safeParseAsync(data, params) {
9308
+ const ctx = {
9309
+ common: {
9310
+ issues: [],
9311
+ contextualErrorMap: params?.errorMap,
9312
+ async: true
9313
+ },
9314
+ path: params?.path || [],
9315
+ schemaErrorMap: this._def.errorMap,
9316
+ parent: null,
9317
+ data,
9318
+ parsedType: getParsedType(data)
9319
+ };
9320
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
9321
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
9322
+ return handleResult(ctx, result);
9323
+ }
9324
+ refine(check, message) {
9325
+ const getIssueProperties = (val) => {
9326
+ if (typeof message === "string" || typeof message === "undefined") {
9327
+ return { message };
9328
+ } else if (typeof message === "function") {
9329
+ return message(val);
9330
+ } else {
9331
+ return message;
9332
+ }
9333
+ };
9334
+ return this._refinement((val, ctx) => {
9335
+ const result = check(val);
9336
+ const setError = () => ctx.addIssue({
9337
+ code: ZodIssueCode.custom,
9338
+ ...getIssueProperties(val)
9339
+ });
9340
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
9341
+ return result.then((data) => {
9342
+ if (!data) {
9343
+ setError();
9344
+ return false;
9345
+ } else {
9346
+ return true;
9347
+ }
9348
+ });
9349
+ }
9350
+ if (!result) {
9351
+ setError();
9352
+ return false;
9353
+ } else {
9354
+ return true;
9355
+ }
9356
+ });
9357
+ }
9358
+ refinement(check, refinementData) {
9359
+ return this._refinement((val, ctx) => {
9360
+ if (!check(val)) {
9361
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
9362
+ return false;
9363
+ } else {
9364
+ return true;
9365
+ }
9366
+ });
9367
+ }
9368
+ _refinement(refinement) {
9369
+ return new ZodEffects({
9370
+ schema: this,
9371
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
9372
+ effect: { type: "refinement", refinement }
9373
+ });
9374
+ }
9375
+ superRefine(refinement) {
9376
+ return this._refinement(refinement);
9377
+ }
9378
+ constructor(def) {
9379
+ this.spa = this.safeParseAsync;
9380
+ this._def = def;
9381
+ this.parse = this.parse.bind(this);
9382
+ this.safeParse = this.safeParse.bind(this);
9383
+ this.parseAsync = this.parseAsync.bind(this);
9384
+ this.safeParseAsync = this.safeParseAsync.bind(this);
9385
+ this.spa = this.spa.bind(this);
9386
+ this.refine = this.refine.bind(this);
9387
+ this.refinement = this.refinement.bind(this);
9388
+ this.superRefine = this.superRefine.bind(this);
9389
+ this.optional = this.optional.bind(this);
9390
+ this.nullable = this.nullable.bind(this);
9391
+ this.nullish = this.nullish.bind(this);
9392
+ this.array = this.array.bind(this);
9393
+ this.promise = this.promise.bind(this);
9394
+ this.or = this.or.bind(this);
9395
+ this.and = this.and.bind(this);
9396
+ this.transform = this.transform.bind(this);
9397
+ this.brand = this.brand.bind(this);
9398
+ this.default = this.default.bind(this);
9399
+ this.catch = this.catch.bind(this);
9400
+ this.describe = this.describe.bind(this);
9401
+ this.pipe = this.pipe.bind(this);
9402
+ this.readonly = this.readonly.bind(this);
9403
+ this.isNullable = this.isNullable.bind(this);
9404
+ this.isOptional = this.isOptional.bind(this);
9405
+ this["~standard"] = {
9406
+ version: 1,
9407
+ vendor: "zod",
9408
+ validate: (data) => this["~validate"](data)
9409
+ };
9410
+ }
9411
+ optional() {
9412
+ return ZodOptional.create(this, this._def);
9413
+ }
9414
+ nullable() {
9415
+ return ZodNullable.create(this, this._def);
9416
+ }
9417
+ nullish() {
9418
+ return this.nullable().optional();
9419
+ }
9420
+ array() {
9421
+ return ZodArray.create(this);
9422
+ }
9423
+ promise() {
9424
+ return ZodPromise.create(this, this._def);
9425
+ }
9426
+ or(option) {
9427
+ return ZodUnion.create([this, option], this._def);
9428
+ }
9429
+ and(incoming) {
9430
+ return ZodIntersection.create(this, incoming, this._def);
9431
+ }
9432
+ transform(transform) {
9433
+ return new ZodEffects({
9434
+ ...processCreateParams(this._def),
9435
+ schema: this,
9436
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
9437
+ effect: { type: "transform", transform }
9438
+ });
9439
+ }
9440
+ default(def) {
9441
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
9442
+ return new ZodDefault({
9443
+ ...processCreateParams(this._def),
9444
+ innerType: this,
9445
+ defaultValue: defaultValueFunc,
9446
+ typeName: ZodFirstPartyTypeKind.ZodDefault
9447
+ });
9448
+ }
9449
+ brand() {
9450
+ return new ZodBranded({
9451
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
9452
+ type: this,
9453
+ ...processCreateParams(this._def)
9454
+ });
9455
+ }
9456
+ catch(def) {
9457
+ const catchValueFunc = typeof def === "function" ? def : () => def;
9458
+ return new ZodCatch({
9459
+ ...processCreateParams(this._def),
9460
+ innerType: this,
9461
+ catchValue: catchValueFunc,
9462
+ typeName: ZodFirstPartyTypeKind.ZodCatch
9463
+ });
9464
+ }
9465
+ describe(description) {
9466
+ const This = this.constructor;
9467
+ return new This({
9468
+ ...this._def,
9469
+ description
9470
+ });
9471
+ }
9472
+ pipe(target) {
9473
+ return ZodPipeline.create(this, target);
9474
+ }
9475
+ readonly() {
9476
+ return ZodReadonly.create(this);
9477
+ }
9478
+ isOptional() {
9479
+ return this.safeParse(void 0).success;
9480
+ }
9481
+ isNullable() {
9482
+ return this.safeParse(null).success;
9483
+ }
9484
+ };
9485
+ var cuidRegex = /^c[^\s-]{8,}$/i;
9486
+ var cuid2Regex = /^[0-9a-z]+$/;
9487
+ var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
9488
+ var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
9489
+ var nanoidRegex = /^[a-z0-9_-]{21}$/i;
9490
+ var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
9491
+ var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
9492
+ var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
9493
+ var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
9494
+ var emojiRegex;
9495
+ var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
9496
+ var ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
9497
+ var ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
9498
+ var ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
9499
+ var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
9500
+ var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
9501
+ var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
9502
+ var dateRegex = new RegExp(`^${dateRegexSource}$`);
9503
+ function timeRegexSource(args) {
9504
+ let secondsRegexSource = `[0-5]\\d`;
9505
+ if (args.precision) {
9506
+ secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
9507
+ } else if (args.precision == null) {
9508
+ secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
9509
+ }
9510
+ const secondsQuantifier = args.precision ? "+" : "?";
9511
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
9512
+ }
9513
+ function timeRegex(args) {
9514
+ return new RegExp(`^${timeRegexSource(args)}$`);
9515
+ }
9516
+ function datetimeRegex(args) {
9517
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
9518
+ const opts = [];
9519
+ opts.push(args.local ? `Z?` : `Z`);
9520
+ if (args.offset)
9521
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
9522
+ regex = `${regex}(${opts.join("|")})`;
9523
+ return new RegExp(`^${regex}$`);
9524
+ }
9525
+ function isValidIP(ip, version) {
9526
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
9527
+ return true;
9528
+ }
9529
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
9530
+ return true;
9531
+ }
9532
+ return false;
9533
+ }
9534
+ function isValidJWT(jwt, alg) {
9535
+ if (!jwtRegex.test(jwt))
9536
+ return false;
9537
+ try {
9538
+ const [header] = jwt.split(".");
9539
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
9540
+ const decoded = JSON.parse(atob(base64));
9541
+ if (typeof decoded !== "object" || decoded === null)
9542
+ return false;
9543
+ if ("typ" in decoded && decoded?.typ !== "JWT")
9544
+ return false;
9545
+ if (!decoded.alg)
9546
+ return false;
9547
+ if (alg && decoded.alg !== alg)
9548
+ return false;
9549
+ return true;
9550
+ } catch {
9551
+ return false;
9552
+ }
9553
+ }
9554
+ function isValidCidr(ip, version) {
9555
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
9556
+ return true;
9557
+ }
9558
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
9559
+ return true;
9560
+ }
9561
+ return false;
9562
+ }
9563
+ var ZodString = class _ZodString extends ZodType {
9564
+ _parse(input) {
9565
+ if (this._def.coerce) {
9566
+ input.data = String(input.data);
9567
+ }
9568
+ const parsedType = this._getType(input);
9569
+ if (parsedType !== ZodParsedType.string) {
9570
+ const ctx2 = this._getOrReturnCtx(input);
9571
+ addIssueToContext(ctx2, {
9572
+ code: ZodIssueCode.invalid_type,
9573
+ expected: ZodParsedType.string,
9574
+ received: ctx2.parsedType
9575
+ });
9576
+ return INVALID;
9577
+ }
9578
+ const status = new ParseStatus();
9579
+ let ctx = void 0;
9580
+ for (const check of this._def.checks) {
9581
+ if (check.kind === "min") {
9582
+ if (input.data.length < check.value) {
9583
+ ctx = this._getOrReturnCtx(input, ctx);
9584
+ addIssueToContext(ctx, {
9585
+ code: ZodIssueCode.too_small,
9586
+ minimum: check.value,
9587
+ type: "string",
9588
+ inclusive: true,
9589
+ exact: false,
9590
+ message: check.message
9591
+ });
9592
+ status.dirty();
9593
+ }
9594
+ } else if (check.kind === "max") {
9595
+ if (input.data.length > check.value) {
9596
+ ctx = this._getOrReturnCtx(input, ctx);
9597
+ addIssueToContext(ctx, {
9598
+ code: ZodIssueCode.too_big,
9599
+ maximum: check.value,
9600
+ type: "string",
9601
+ inclusive: true,
9602
+ exact: false,
9603
+ message: check.message
9604
+ });
9605
+ status.dirty();
9606
+ }
9607
+ } else if (check.kind === "length") {
9608
+ const tooBig = input.data.length > check.value;
9609
+ const tooSmall = input.data.length < check.value;
9610
+ if (tooBig || tooSmall) {
9611
+ ctx = this._getOrReturnCtx(input, ctx);
9612
+ if (tooBig) {
9613
+ addIssueToContext(ctx, {
9614
+ code: ZodIssueCode.too_big,
9615
+ maximum: check.value,
9616
+ type: "string",
9617
+ inclusive: true,
9618
+ exact: true,
9619
+ message: check.message
9620
+ });
9621
+ } else if (tooSmall) {
9622
+ addIssueToContext(ctx, {
9623
+ code: ZodIssueCode.too_small,
9624
+ minimum: check.value,
9625
+ type: "string",
9626
+ inclusive: true,
9627
+ exact: true,
9628
+ message: check.message
9629
+ });
9630
+ }
9631
+ status.dirty();
9632
+ }
9633
+ } else if (check.kind === "email") {
9634
+ if (!emailRegex.test(input.data)) {
9635
+ ctx = this._getOrReturnCtx(input, ctx);
9636
+ addIssueToContext(ctx, {
9637
+ validation: "email",
9638
+ code: ZodIssueCode.invalid_string,
9639
+ message: check.message
9640
+ });
9641
+ status.dirty();
9642
+ }
9643
+ } else if (check.kind === "emoji") {
9644
+ if (!emojiRegex) {
9645
+ emojiRegex = new RegExp(_emojiRegex, "u");
9646
+ }
9647
+ if (!emojiRegex.test(input.data)) {
9648
+ ctx = this._getOrReturnCtx(input, ctx);
9649
+ addIssueToContext(ctx, {
9650
+ validation: "emoji",
9651
+ code: ZodIssueCode.invalid_string,
9652
+ message: check.message
9653
+ });
9654
+ status.dirty();
9655
+ }
9656
+ } else if (check.kind === "uuid") {
9657
+ if (!uuidRegex.test(input.data)) {
9658
+ ctx = this._getOrReturnCtx(input, ctx);
9659
+ addIssueToContext(ctx, {
9660
+ validation: "uuid",
9661
+ code: ZodIssueCode.invalid_string,
9662
+ message: check.message
9663
+ });
9664
+ status.dirty();
9665
+ }
9666
+ } else if (check.kind === "nanoid") {
9667
+ if (!nanoidRegex.test(input.data)) {
9668
+ ctx = this._getOrReturnCtx(input, ctx);
9669
+ addIssueToContext(ctx, {
9670
+ validation: "nanoid",
9671
+ code: ZodIssueCode.invalid_string,
9672
+ message: check.message
9673
+ });
9674
+ status.dirty();
9675
+ }
9676
+ } else if (check.kind === "cuid") {
9677
+ if (!cuidRegex.test(input.data)) {
9678
+ ctx = this._getOrReturnCtx(input, ctx);
9679
+ addIssueToContext(ctx, {
9680
+ validation: "cuid",
9681
+ code: ZodIssueCode.invalid_string,
9682
+ message: check.message
9683
+ });
9684
+ status.dirty();
9685
+ }
9686
+ } else if (check.kind === "cuid2") {
9687
+ if (!cuid2Regex.test(input.data)) {
9688
+ ctx = this._getOrReturnCtx(input, ctx);
9689
+ addIssueToContext(ctx, {
9690
+ validation: "cuid2",
9691
+ code: ZodIssueCode.invalid_string,
9692
+ message: check.message
9693
+ });
9694
+ status.dirty();
9695
+ }
9696
+ } else if (check.kind === "ulid") {
9697
+ if (!ulidRegex.test(input.data)) {
9698
+ ctx = this._getOrReturnCtx(input, ctx);
9699
+ addIssueToContext(ctx, {
9700
+ validation: "ulid",
9701
+ code: ZodIssueCode.invalid_string,
9702
+ message: check.message
9703
+ });
9704
+ status.dirty();
9705
+ }
9706
+ } else if (check.kind === "url") {
9707
+ try {
9708
+ new URL(input.data);
9709
+ } catch {
9710
+ ctx = this._getOrReturnCtx(input, ctx);
9711
+ addIssueToContext(ctx, {
9712
+ validation: "url",
9713
+ code: ZodIssueCode.invalid_string,
9714
+ message: check.message
9715
+ });
9716
+ status.dirty();
9717
+ }
9718
+ } else if (check.kind === "regex") {
9719
+ check.regex.lastIndex = 0;
9720
+ const testResult = check.regex.test(input.data);
9721
+ if (!testResult) {
9722
+ ctx = this._getOrReturnCtx(input, ctx);
9723
+ addIssueToContext(ctx, {
9724
+ validation: "regex",
9725
+ code: ZodIssueCode.invalid_string,
9726
+ message: check.message
9727
+ });
9728
+ status.dirty();
9729
+ }
9730
+ } else if (check.kind === "trim") {
9731
+ input.data = input.data.trim();
9732
+ } else if (check.kind === "includes") {
9733
+ if (!input.data.includes(check.value, check.position)) {
9734
+ ctx = this._getOrReturnCtx(input, ctx);
9735
+ addIssueToContext(ctx, {
9736
+ code: ZodIssueCode.invalid_string,
9737
+ validation: { includes: check.value, position: check.position },
9738
+ message: check.message
9739
+ });
9740
+ status.dirty();
9741
+ }
9742
+ } else if (check.kind === "toLowerCase") {
9743
+ input.data = input.data.toLowerCase();
9744
+ } else if (check.kind === "toUpperCase") {
9745
+ input.data = input.data.toUpperCase();
9746
+ } else if (check.kind === "startsWith") {
9747
+ if (!input.data.startsWith(check.value)) {
9748
+ ctx = this._getOrReturnCtx(input, ctx);
9749
+ addIssueToContext(ctx, {
9750
+ code: ZodIssueCode.invalid_string,
9751
+ validation: { startsWith: check.value },
9752
+ message: check.message
9753
+ });
9754
+ status.dirty();
9755
+ }
9756
+ } else if (check.kind === "endsWith") {
9757
+ if (!input.data.endsWith(check.value)) {
9758
+ ctx = this._getOrReturnCtx(input, ctx);
9759
+ addIssueToContext(ctx, {
9760
+ code: ZodIssueCode.invalid_string,
9761
+ validation: { endsWith: check.value },
9762
+ message: check.message
9763
+ });
9764
+ status.dirty();
9765
+ }
9766
+ } else if (check.kind === "datetime") {
9767
+ const regex = datetimeRegex(check);
9768
+ if (!regex.test(input.data)) {
9769
+ ctx = this._getOrReturnCtx(input, ctx);
9770
+ addIssueToContext(ctx, {
9771
+ code: ZodIssueCode.invalid_string,
9772
+ validation: "datetime",
9773
+ message: check.message
9774
+ });
9775
+ status.dirty();
9776
+ }
9777
+ } else if (check.kind === "date") {
9778
+ const regex = dateRegex;
9779
+ if (!regex.test(input.data)) {
9780
+ ctx = this._getOrReturnCtx(input, ctx);
9781
+ addIssueToContext(ctx, {
9782
+ code: ZodIssueCode.invalid_string,
9783
+ validation: "date",
9784
+ message: check.message
9785
+ });
9786
+ status.dirty();
9787
+ }
9788
+ } else if (check.kind === "time") {
9789
+ const regex = timeRegex(check);
9790
+ if (!regex.test(input.data)) {
9791
+ ctx = this._getOrReturnCtx(input, ctx);
9792
+ addIssueToContext(ctx, {
9793
+ code: ZodIssueCode.invalid_string,
9794
+ validation: "time",
9795
+ message: check.message
9796
+ });
9797
+ status.dirty();
9798
+ }
9799
+ } else if (check.kind === "duration") {
9800
+ if (!durationRegex.test(input.data)) {
9801
+ ctx = this._getOrReturnCtx(input, ctx);
9802
+ addIssueToContext(ctx, {
9803
+ validation: "duration",
9804
+ code: ZodIssueCode.invalid_string,
9805
+ message: check.message
9806
+ });
9807
+ status.dirty();
9808
+ }
9809
+ } else if (check.kind === "ip") {
9810
+ if (!isValidIP(input.data, check.version)) {
9811
+ ctx = this._getOrReturnCtx(input, ctx);
9812
+ addIssueToContext(ctx, {
9813
+ validation: "ip",
9814
+ code: ZodIssueCode.invalid_string,
9815
+ message: check.message
9816
+ });
9817
+ status.dirty();
9818
+ }
9819
+ } else if (check.kind === "jwt") {
9820
+ if (!isValidJWT(input.data, check.alg)) {
9821
+ ctx = this._getOrReturnCtx(input, ctx);
9822
+ addIssueToContext(ctx, {
9823
+ validation: "jwt",
9824
+ code: ZodIssueCode.invalid_string,
9825
+ message: check.message
9826
+ });
9827
+ status.dirty();
9828
+ }
9829
+ } else if (check.kind === "cidr") {
9830
+ if (!isValidCidr(input.data, check.version)) {
9831
+ ctx = this._getOrReturnCtx(input, ctx);
9832
+ addIssueToContext(ctx, {
9833
+ validation: "cidr",
9834
+ code: ZodIssueCode.invalid_string,
9835
+ message: check.message
9836
+ });
9837
+ status.dirty();
9838
+ }
9839
+ } else if (check.kind === "base64") {
9840
+ if (!base64Regex.test(input.data)) {
9841
+ ctx = this._getOrReturnCtx(input, ctx);
9842
+ addIssueToContext(ctx, {
9843
+ validation: "base64",
9844
+ code: ZodIssueCode.invalid_string,
9845
+ message: check.message
9846
+ });
9847
+ status.dirty();
9848
+ }
9849
+ } else if (check.kind === "base64url") {
9850
+ if (!base64urlRegex.test(input.data)) {
9851
+ ctx = this._getOrReturnCtx(input, ctx);
9852
+ addIssueToContext(ctx, {
9853
+ validation: "base64url",
9854
+ code: ZodIssueCode.invalid_string,
9855
+ message: check.message
9856
+ });
9857
+ status.dirty();
9858
+ }
9859
+ } else {
9860
+ util.assertNever(check);
9861
+ }
9862
+ }
9863
+ return { status: status.value, value: input.data };
9864
+ }
9865
+ _regex(regex, validation, message) {
9866
+ return this.refinement((data) => regex.test(data), {
9867
+ validation,
9868
+ code: ZodIssueCode.invalid_string,
9869
+ ...errorUtil.errToObj(message)
9870
+ });
9871
+ }
9872
+ _addCheck(check) {
9873
+ return new _ZodString({
9874
+ ...this._def,
9875
+ checks: [...this._def.checks, check]
9876
+ });
9877
+ }
9878
+ email(message) {
9879
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
9880
+ }
9881
+ url(message) {
9882
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
9883
+ }
9884
+ emoji(message) {
9885
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
9886
+ }
9887
+ uuid(message) {
9888
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
9889
+ }
9890
+ nanoid(message) {
9891
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
9892
+ }
9893
+ cuid(message) {
9894
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
9895
+ }
9896
+ cuid2(message) {
9897
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
9898
+ }
9899
+ ulid(message) {
9900
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
9901
+ }
9902
+ base64(message) {
9903
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
9904
+ }
9905
+ base64url(message) {
9906
+ return this._addCheck({
9907
+ kind: "base64url",
9908
+ ...errorUtil.errToObj(message)
9909
+ });
9910
+ }
9911
+ jwt(options) {
9912
+ return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
9913
+ }
9914
+ ip(options) {
9915
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
9916
+ }
9917
+ cidr(options) {
9918
+ return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
9919
+ }
9920
+ datetime(options) {
9921
+ if (typeof options === "string") {
9922
+ return this._addCheck({
9923
+ kind: "datetime",
9924
+ precision: null,
9925
+ offset: false,
9926
+ local: false,
9927
+ message: options
9928
+ });
9929
+ }
9930
+ return this._addCheck({
9931
+ kind: "datetime",
9932
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
9933
+ offset: options?.offset ?? false,
9934
+ local: options?.local ?? false,
9935
+ ...errorUtil.errToObj(options?.message)
9936
+ });
9937
+ }
9938
+ date(message) {
9939
+ return this._addCheck({ kind: "date", message });
9940
+ }
9941
+ time(options) {
9942
+ if (typeof options === "string") {
9943
+ return this._addCheck({
9944
+ kind: "time",
9945
+ precision: null,
9946
+ message: options
9947
+ });
9948
+ }
9949
+ return this._addCheck({
9950
+ kind: "time",
9951
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
9952
+ ...errorUtil.errToObj(options?.message)
9953
+ });
9954
+ }
9955
+ duration(message) {
9956
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
9957
+ }
9958
+ regex(regex, message) {
9959
+ return this._addCheck({
9960
+ kind: "regex",
9961
+ regex,
9962
+ ...errorUtil.errToObj(message)
9963
+ });
9964
+ }
9965
+ includes(value, options) {
9966
+ return this._addCheck({
9967
+ kind: "includes",
9968
+ value,
9969
+ position: options?.position,
9970
+ ...errorUtil.errToObj(options?.message)
9971
+ });
9972
+ }
9973
+ startsWith(value, message) {
9974
+ return this._addCheck({
9975
+ kind: "startsWith",
9976
+ value,
9977
+ ...errorUtil.errToObj(message)
9978
+ });
9979
+ }
9980
+ endsWith(value, message) {
9981
+ return this._addCheck({
9982
+ kind: "endsWith",
9983
+ value,
9984
+ ...errorUtil.errToObj(message)
9985
+ });
9986
+ }
9987
+ min(minLength, message) {
9988
+ return this._addCheck({
9989
+ kind: "min",
9990
+ value: minLength,
9991
+ ...errorUtil.errToObj(message)
9992
+ });
9993
+ }
9994
+ max(maxLength, message) {
9995
+ return this._addCheck({
9996
+ kind: "max",
9997
+ value: maxLength,
9998
+ ...errorUtil.errToObj(message)
9999
+ });
10000
+ }
10001
+ length(len, message) {
10002
+ return this._addCheck({
10003
+ kind: "length",
10004
+ value: len,
10005
+ ...errorUtil.errToObj(message)
10006
+ });
10007
+ }
10008
+ /**
10009
+ * Equivalent to `.min(1)`
10010
+ */
10011
+ nonempty(message) {
10012
+ return this.min(1, errorUtil.errToObj(message));
10013
+ }
10014
+ trim() {
10015
+ return new _ZodString({
10016
+ ...this._def,
10017
+ checks: [...this._def.checks, { kind: "trim" }]
10018
+ });
10019
+ }
10020
+ toLowerCase() {
10021
+ return new _ZodString({
10022
+ ...this._def,
10023
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
10024
+ });
10025
+ }
10026
+ toUpperCase() {
10027
+ return new _ZodString({
10028
+ ...this._def,
10029
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
10030
+ });
10031
+ }
10032
+ get isDatetime() {
10033
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
10034
+ }
10035
+ get isDate() {
10036
+ return !!this._def.checks.find((ch) => ch.kind === "date");
10037
+ }
10038
+ get isTime() {
10039
+ return !!this._def.checks.find((ch) => ch.kind === "time");
10040
+ }
10041
+ get isDuration() {
10042
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
10043
+ }
10044
+ get isEmail() {
10045
+ return !!this._def.checks.find((ch) => ch.kind === "email");
10046
+ }
10047
+ get isURL() {
10048
+ return !!this._def.checks.find((ch) => ch.kind === "url");
10049
+ }
10050
+ get isEmoji() {
10051
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
10052
+ }
10053
+ get isUUID() {
10054
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
10055
+ }
10056
+ get isNANOID() {
10057
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
10058
+ }
10059
+ get isCUID() {
10060
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
10061
+ }
10062
+ get isCUID2() {
10063
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
10064
+ }
10065
+ get isULID() {
10066
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
10067
+ }
10068
+ get isIP() {
10069
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
10070
+ }
10071
+ get isCIDR() {
10072
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
10073
+ }
10074
+ get isBase64() {
10075
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
10076
+ }
10077
+ get isBase64url() {
10078
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
10079
+ }
10080
+ get minLength() {
10081
+ let min = null;
10082
+ for (const ch of this._def.checks) {
10083
+ if (ch.kind === "min") {
10084
+ if (min === null || ch.value > min)
10085
+ min = ch.value;
10086
+ }
10087
+ }
10088
+ return min;
10089
+ }
10090
+ get maxLength() {
10091
+ let max = null;
10092
+ for (const ch of this._def.checks) {
10093
+ if (ch.kind === "max") {
10094
+ if (max === null || ch.value < max)
10095
+ max = ch.value;
10096
+ }
10097
+ }
10098
+ return max;
10099
+ }
10100
+ };
10101
+ ZodString.create = (params) => {
10102
+ return new ZodString({
10103
+ checks: [],
10104
+ typeName: ZodFirstPartyTypeKind.ZodString,
10105
+ coerce: params?.coerce ?? false,
10106
+ ...processCreateParams(params)
10107
+ });
10108
+ };
10109
+ function floatSafeRemainder(val, step) {
10110
+ const valDecCount = (val.toString().split(".")[1] || "").length;
10111
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
10112
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
10113
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
10114
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
10115
+ return valInt % stepInt / 10 ** decCount;
10116
+ }
10117
+ var ZodNumber = class _ZodNumber extends ZodType {
10118
+ constructor() {
10119
+ super(...arguments);
10120
+ this.min = this.gte;
10121
+ this.max = this.lte;
10122
+ this.step = this.multipleOf;
10123
+ }
10124
+ _parse(input) {
10125
+ if (this._def.coerce) {
10126
+ input.data = Number(input.data);
10127
+ }
10128
+ const parsedType = this._getType(input);
10129
+ if (parsedType !== ZodParsedType.number) {
10130
+ const ctx2 = this._getOrReturnCtx(input);
10131
+ addIssueToContext(ctx2, {
10132
+ code: ZodIssueCode.invalid_type,
10133
+ expected: ZodParsedType.number,
10134
+ received: ctx2.parsedType
10135
+ });
10136
+ return INVALID;
10137
+ }
10138
+ let ctx = void 0;
10139
+ const status = new ParseStatus();
10140
+ for (const check of this._def.checks) {
10141
+ if (check.kind === "int") {
10142
+ if (!util.isInteger(input.data)) {
10143
+ ctx = this._getOrReturnCtx(input, ctx);
10144
+ addIssueToContext(ctx, {
10145
+ code: ZodIssueCode.invalid_type,
10146
+ expected: "integer",
10147
+ received: "float",
10148
+ message: check.message
10149
+ });
10150
+ status.dirty();
10151
+ }
10152
+ } else if (check.kind === "min") {
10153
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
10154
+ if (tooSmall) {
10155
+ ctx = this._getOrReturnCtx(input, ctx);
10156
+ addIssueToContext(ctx, {
10157
+ code: ZodIssueCode.too_small,
10158
+ minimum: check.value,
10159
+ type: "number",
10160
+ inclusive: check.inclusive,
10161
+ exact: false,
10162
+ message: check.message
10163
+ });
10164
+ status.dirty();
10165
+ }
10166
+ } else if (check.kind === "max") {
10167
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
10168
+ if (tooBig) {
10169
+ ctx = this._getOrReturnCtx(input, ctx);
10170
+ addIssueToContext(ctx, {
10171
+ code: ZodIssueCode.too_big,
10172
+ maximum: check.value,
10173
+ type: "number",
10174
+ inclusive: check.inclusive,
10175
+ exact: false,
10176
+ message: check.message
10177
+ });
10178
+ status.dirty();
10179
+ }
10180
+ } else if (check.kind === "multipleOf") {
10181
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
10182
+ ctx = this._getOrReturnCtx(input, ctx);
10183
+ addIssueToContext(ctx, {
10184
+ code: ZodIssueCode.not_multiple_of,
10185
+ multipleOf: check.value,
10186
+ message: check.message
10187
+ });
10188
+ status.dirty();
10189
+ }
10190
+ } else if (check.kind === "finite") {
10191
+ if (!Number.isFinite(input.data)) {
10192
+ ctx = this._getOrReturnCtx(input, ctx);
10193
+ addIssueToContext(ctx, {
10194
+ code: ZodIssueCode.not_finite,
10195
+ message: check.message
10196
+ });
10197
+ status.dirty();
10198
+ }
10199
+ } else {
10200
+ util.assertNever(check);
10201
+ }
10202
+ }
10203
+ return { status: status.value, value: input.data };
10204
+ }
10205
+ gte(value, message) {
10206
+ return this.setLimit("min", value, true, errorUtil.toString(message));
10207
+ }
10208
+ gt(value, message) {
10209
+ return this.setLimit("min", value, false, errorUtil.toString(message));
10210
+ }
10211
+ lte(value, message) {
10212
+ return this.setLimit("max", value, true, errorUtil.toString(message));
10213
+ }
10214
+ lt(value, message) {
10215
+ return this.setLimit("max", value, false, errorUtil.toString(message));
10216
+ }
10217
+ setLimit(kind, value, inclusive, message) {
10218
+ return new _ZodNumber({
10219
+ ...this._def,
10220
+ checks: [
10221
+ ...this._def.checks,
10222
+ {
10223
+ kind,
10224
+ value,
10225
+ inclusive,
10226
+ message: errorUtil.toString(message)
10227
+ }
10228
+ ]
10229
+ });
10230
+ }
10231
+ _addCheck(check) {
10232
+ return new _ZodNumber({
10233
+ ...this._def,
10234
+ checks: [...this._def.checks, check]
10235
+ });
10236
+ }
10237
+ int(message) {
10238
+ return this._addCheck({
10239
+ kind: "int",
10240
+ message: errorUtil.toString(message)
10241
+ });
10242
+ }
10243
+ positive(message) {
10244
+ return this._addCheck({
10245
+ kind: "min",
10246
+ value: 0,
10247
+ inclusive: false,
10248
+ message: errorUtil.toString(message)
10249
+ });
10250
+ }
10251
+ negative(message) {
10252
+ return this._addCheck({
10253
+ kind: "max",
10254
+ value: 0,
10255
+ inclusive: false,
10256
+ message: errorUtil.toString(message)
10257
+ });
10258
+ }
10259
+ nonpositive(message) {
10260
+ return this._addCheck({
10261
+ kind: "max",
10262
+ value: 0,
10263
+ inclusive: true,
10264
+ message: errorUtil.toString(message)
10265
+ });
10266
+ }
10267
+ nonnegative(message) {
10268
+ return this._addCheck({
10269
+ kind: "min",
10270
+ value: 0,
10271
+ inclusive: true,
10272
+ message: errorUtil.toString(message)
10273
+ });
10274
+ }
10275
+ multipleOf(value, message) {
10276
+ return this._addCheck({
10277
+ kind: "multipleOf",
10278
+ value,
10279
+ message: errorUtil.toString(message)
10280
+ });
10281
+ }
10282
+ finite(message) {
10283
+ return this._addCheck({
10284
+ kind: "finite",
10285
+ message: errorUtil.toString(message)
10286
+ });
10287
+ }
10288
+ safe(message) {
10289
+ return this._addCheck({
10290
+ kind: "min",
10291
+ inclusive: true,
10292
+ value: Number.MIN_SAFE_INTEGER,
10293
+ message: errorUtil.toString(message)
10294
+ })._addCheck({
10295
+ kind: "max",
10296
+ inclusive: true,
10297
+ value: Number.MAX_SAFE_INTEGER,
10298
+ message: errorUtil.toString(message)
10299
+ });
10300
+ }
10301
+ get minValue() {
10302
+ let min = null;
10303
+ for (const ch of this._def.checks) {
10304
+ if (ch.kind === "min") {
10305
+ if (min === null || ch.value > min)
10306
+ min = ch.value;
10307
+ }
10308
+ }
10309
+ return min;
10310
+ }
10311
+ get maxValue() {
10312
+ let max = null;
10313
+ for (const ch of this._def.checks) {
10314
+ if (ch.kind === "max") {
10315
+ if (max === null || ch.value < max)
10316
+ max = ch.value;
10317
+ }
10318
+ }
10319
+ return max;
10320
+ }
10321
+ get isInt() {
10322
+ return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
10323
+ }
10324
+ get isFinite() {
10325
+ let max = null;
10326
+ let min = null;
10327
+ for (const ch of this._def.checks) {
10328
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
10329
+ return true;
10330
+ } else if (ch.kind === "min") {
10331
+ if (min === null || ch.value > min)
10332
+ min = ch.value;
10333
+ } else if (ch.kind === "max") {
10334
+ if (max === null || ch.value < max)
10335
+ max = ch.value;
10336
+ }
10337
+ }
10338
+ return Number.isFinite(min) && Number.isFinite(max);
10339
+ }
10340
+ };
10341
+ ZodNumber.create = (params) => {
10342
+ return new ZodNumber({
10343
+ checks: [],
10344
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
10345
+ coerce: params?.coerce || false,
10346
+ ...processCreateParams(params)
10347
+ });
10348
+ };
10349
+ var ZodBigInt = class _ZodBigInt extends ZodType {
10350
+ constructor() {
10351
+ super(...arguments);
10352
+ this.min = this.gte;
10353
+ this.max = this.lte;
10354
+ }
10355
+ _parse(input) {
10356
+ if (this._def.coerce) {
10357
+ try {
10358
+ input.data = BigInt(input.data);
10359
+ } catch {
10360
+ return this._getInvalidInput(input);
10361
+ }
10362
+ }
10363
+ const parsedType = this._getType(input);
10364
+ if (parsedType !== ZodParsedType.bigint) {
10365
+ return this._getInvalidInput(input);
10366
+ }
10367
+ let ctx = void 0;
10368
+ const status = new ParseStatus();
10369
+ for (const check of this._def.checks) {
10370
+ if (check.kind === "min") {
10371
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
10372
+ if (tooSmall) {
10373
+ ctx = this._getOrReturnCtx(input, ctx);
10374
+ addIssueToContext(ctx, {
10375
+ code: ZodIssueCode.too_small,
10376
+ type: "bigint",
10377
+ minimum: check.value,
10378
+ inclusive: check.inclusive,
10379
+ message: check.message
10380
+ });
10381
+ status.dirty();
10382
+ }
10383
+ } else if (check.kind === "max") {
10384
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
10385
+ if (tooBig) {
10386
+ ctx = this._getOrReturnCtx(input, ctx);
10387
+ addIssueToContext(ctx, {
10388
+ code: ZodIssueCode.too_big,
10389
+ type: "bigint",
10390
+ maximum: check.value,
10391
+ inclusive: check.inclusive,
10392
+ message: check.message
10393
+ });
10394
+ status.dirty();
10395
+ }
10396
+ } else if (check.kind === "multipleOf") {
10397
+ if (input.data % check.value !== BigInt(0)) {
10398
+ ctx = this._getOrReturnCtx(input, ctx);
10399
+ addIssueToContext(ctx, {
10400
+ code: ZodIssueCode.not_multiple_of,
10401
+ multipleOf: check.value,
10402
+ message: check.message
10403
+ });
10404
+ status.dirty();
10405
+ }
10406
+ } else {
10407
+ util.assertNever(check);
10408
+ }
10409
+ }
10410
+ return { status: status.value, value: input.data };
10411
+ }
10412
+ _getInvalidInput(input) {
10413
+ const ctx = this._getOrReturnCtx(input);
10414
+ addIssueToContext(ctx, {
10415
+ code: ZodIssueCode.invalid_type,
10416
+ expected: ZodParsedType.bigint,
10417
+ received: ctx.parsedType
10418
+ });
10419
+ return INVALID;
10420
+ }
10421
+ gte(value, message) {
10422
+ return this.setLimit("min", value, true, errorUtil.toString(message));
10423
+ }
10424
+ gt(value, message) {
10425
+ return this.setLimit("min", value, false, errorUtil.toString(message));
10426
+ }
10427
+ lte(value, message) {
10428
+ return this.setLimit("max", value, true, errorUtil.toString(message));
10429
+ }
10430
+ lt(value, message) {
10431
+ return this.setLimit("max", value, false, errorUtil.toString(message));
10432
+ }
10433
+ setLimit(kind, value, inclusive, message) {
10434
+ return new _ZodBigInt({
10435
+ ...this._def,
10436
+ checks: [
10437
+ ...this._def.checks,
10438
+ {
10439
+ kind,
10440
+ value,
10441
+ inclusive,
10442
+ message: errorUtil.toString(message)
10443
+ }
10444
+ ]
10445
+ });
10446
+ }
10447
+ _addCheck(check) {
10448
+ return new _ZodBigInt({
10449
+ ...this._def,
10450
+ checks: [...this._def.checks, check]
10451
+ });
10452
+ }
10453
+ positive(message) {
10454
+ return this._addCheck({
10455
+ kind: "min",
10456
+ value: BigInt(0),
10457
+ inclusive: false,
10458
+ message: errorUtil.toString(message)
10459
+ });
10460
+ }
10461
+ negative(message) {
10462
+ return this._addCheck({
10463
+ kind: "max",
10464
+ value: BigInt(0),
10465
+ inclusive: false,
10466
+ message: errorUtil.toString(message)
10467
+ });
10468
+ }
10469
+ nonpositive(message) {
10470
+ return this._addCheck({
10471
+ kind: "max",
10472
+ value: BigInt(0),
10473
+ inclusive: true,
10474
+ message: errorUtil.toString(message)
10475
+ });
10476
+ }
10477
+ nonnegative(message) {
10478
+ return this._addCheck({
10479
+ kind: "min",
10480
+ value: BigInt(0),
10481
+ inclusive: true,
10482
+ message: errorUtil.toString(message)
10483
+ });
10484
+ }
10485
+ multipleOf(value, message) {
10486
+ return this._addCheck({
10487
+ kind: "multipleOf",
10488
+ value,
10489
+ message: errorUtil.toString(message)
10490
+ });
10491
+ }
10492
+ get minValue() {
10493
+ let min = null;
10494
+ for (const ch of this._def.checks) {
10495
+ if (ch.kind === "min") {
10496
+ if (min === null || ch.value > min)
10497
+ min = ch.value;
10498
+ }
10499
+ }
10500
+ return min;
10501
+ }
10502
+ get maxValue() {
10503
+ let max = null;
10504
+ for (const ch of this._def.checks) {
10505
+ if (ch.kind === "max") {
10506
+ if (max === null || ch.value < max)
10507
+ max = ch.value;
10508
+ }
10509
+ }
10510
+ return max;
10511
+ }
10512
+ };
10513
+ ZodBigInt.create = (params) => {
10514
+ return new ZodBigInt({
10515
+ checks: [],
10516
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
10517
+ coerce: params?.coerce ?? false,
10518
+ ...processCreateParams(params)
10519
+ });
10520
+ };
10521
+ var ZodBoolean = class extends ZodType {
10522
+ _parse(input) {
10523
+ if (this._def.coerce) {
10524
+ input.data = Boolean(input.data);
10525
+ }
10526
+ const parsedType = this._getType(input);
10527
+ if (parsedType !== ZodParsedType.boolean) {
10528
+ const ctx = this._getOrReturnCtx(input);
10529
+ addIssueToContext(ctx, {
10530
+ code: ZodIssueCode.invalid_type,
10531
+ expected: ZodParsedType.boolean,
10532
+ received: ctx.parsedType
10533
+ });
10534
+ return INVALID;
10535
+ }
10536
+ return OK(input.data);
10537
+ }
10538
+ };
10539
+ ZodBoolean.create = (params) => {
10540
+ return new ZodBoolean({
10541
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
10542
+ coerce: params?.coerce || false,
10543
+ ...processCreateParams(params)
10544
+ });
10545
+ };
10546
+ var ZodDate = class _ZodDate extends ZodType {
10547
+ _parse(input) {
10548
+ if (this._def.coerce) {
10549
+ input.data = new Date(input.data);
10550
+ }
10551
+ const parsedType = this._getType(input);
10552
+ if (parsedType !== ZodParsedType.date) {
10553
+ const ctx2 = this._getOrReturnCtx(input);
10554
+ addIssueToContext(ctx2, {
10555
+ code: ZodIssueCode.invalid_type,
10556
+ expected: ZodParsedType.date,
10557
+ received: ctx2.parsedType
10558
+ });
10559
+ return INVALID;
10560
+ }
10561
+ if (Number.isNaN(input.data.getTime())) {
10562
+ const ctx2 = this._getOrReturnCtx(input);
10563
+ addIssueToContext(ctx2, {
10564
+ code: ZodIssueCode.invalid_date
10565
+ });
10566
+ return INVALID;
10567
+ }
10568
+ const status = new ParseStatus();
10569
+ let ctx = void 0;
10570
+ for (const check of this._def.checks) {
10571
+ if (check.kind === "min") {
10572
+ if (input.data.getTime() < check.value) {
10573
+ ctx = this._getOrReturnCtx(input, ctx);
10574
+ addIssueToContext(ctx, {
10575
+ code: ZodIssueCode.too_small,
10576
+ message: check.message,
10577
+ inclusive: true,
10578
+ exact: false,
10579
+ minimum: check.value,
10580
+ type: "date"
10581
+ });
10582
+ status.dirty();
10583
+ }
10584
+ } else if (check.kind === "max") {
10585
+ if (input.data.getTime() > check.value) {
10586
+ ctx = this._getOrReturnCtx(input, ctx);
10587
+ addIssueToContext(ctx, {
10588
+ code: ZodIssueCode.too_big,
10589
+ message: check.message,
10590
+ inclusive: true,
10591
+ exact: false,
10592
+ maximum: check.value,
10593
+ type: "date"
10594
+ });
10595
+ status.dirty();
10596
+ }
10597
+ } else {
10598
+ util.assertNever(check);
10599
+ }
10600
+ }
10601
+ return {
10602
+ status: status.value,
10603
+ value: new Date(input.data.getTime())
10604
+ };
10605
+ }
10606
+ _addCheck(check) {
10607
+ return new _ZodDate({
10608
+ ...this._def,
10609
+ checks: [...this._def.checks, check]
10610
+ });
10611
+ }
10612
+ min(minDate, message) {
10613
+ return this._addCheck({
10614
+ kind: "min",
10615
+ value: minDate.getTime(),
10616
+ message: errorUtil.toString(message)
10617
+ });
10618
+ }
10619
+ max(maxDate, message) {
10620
+ return this._addCheck({
10621
+ kind: "max",
10622
+ value: maxDate.getTime(),
10623
+ message: errorUtil.toString(message)
10624
+ });
10625
+ }
10626
+ get minDate() {
10627
+ let min = null;
10628
+ for (const ch of this._def.checks) {
10629
+ if (ch.kind === "min") {
10630
+ if (min === null || ch.value > min)
10631
+ min = ch.value;
10632
+ }
10633
+ }
10634
+ return min != null ? new Date(min) : null;
10635
+ }
10636
+ get maxDate() {
10637
+ let max = null;
10638
+ for (const ch of this._def.checks) {
10639
+ if (ch.kind === "max") {
10640
+ if (max === null || ch.value < max)
10641
+ max = ch.value;
10642
+ }
10643
+ }
10644
+ return max != null ? new Date(max) : null;
10645
+ }
10646
+ };
10647
+ ZodDate.create = (params) => {
10648
+ return new ZodDate({
10649
+ checks: [],
10650
+ coerce: params?.coerce || false,
10651
+ typeName: ZodFirstPartyTypeKind.ZodDate,
10652
+ ...processCreateParams(params)
10653
+ });
10654
+ };
10655
+ var ZodSymbol = class extends ZodType {
10656
+ _parse(input) {
10657
+ const parsedType = this._getType(input);
10658
+ if (parsedType !== ZodParsedType.symbol) {
10659
+ const ctx = this._getOrReturnCtx(input);
10660
+ addIssueToContext(ctx, {
10661
+ code: ZodIssueCode.invalid_type,
10662
+ expected: ZodParsedType.symbol,
10663
+ received: ctx.parsedType
10664
+ });
10665
+ return INVALID;
10666
+ }
10667
+ return OK(input.data);
10668
+ }
10669
+ };
10670
+ ZodSymbol.create = (params) => {
10671
+ return new ZodSymbol({
10672
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
10673
+ ...processCreateParams(params)
10674
+ });
10675
+ };
10676
+ var ZodUndefined = class extends ZodType {
10677
+ _parse(input) {
10678
+ const parsedType = this._getType(input);
10679
+ if (parsedType !== ZodParsedType.undefined) {
10680
+ const ctx = this._getOrReturnCtx(input);
10681
+ addIssueToContext(ctx, {
10682
+ code: ZodIssueCode.invalid_type,
10683
+ expected: ZodParsedType.undefined,
10684
+ received: ctx.parsedType
10685
+ });
10686
+ return INVALID;
10687
+ }
10688
+ return OK(input.data);
10689
+ }
10690
+ };
10691
+ ZodUndefined.create = (params) => {
10692
+ return new ZodUndefined({
10693
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
10694
+ ...processCreateParams(params)
10695
+ });
10696
+ };
10697
+ var ZodNull = class extends ZodType {
10698
+ _parse(input) {
10699
+ const parsedType = this._getType(input);
10700
+ if (parsedType !== ZodParsedType.null) {
10701
+ const ctx = this._getOrReturnCtx(input);
10702
+ addIssueToContext(ctx, {
10703
+ code: ZodIssueCode.invalid_type,
10704
+ expected: ZodParsedType.null,
10705
+ received: ctx.parsedType
10706
+ });
10707
+ return INVALID;
10708
+ }
10709
+ return OK(input.data);
10710
+ }
10711
+ };
10712
+ ZodNull.create = (params) => {
10713
+ return new ZodNull({
10714
+ typeName: ZodFirstPartyTypeKind.ZodNull,
10715
+ ...processCreateParams(params)
10716
+ });
10717
+ };
10718
+ var ZodAny = class extends ZodType {
10719
+ constructor() {
10720
+ super(...arguments);
10721
+ this._any = true;
10722
+ }
10723
+ _parse(input) {
10724
+ return OK(input.data);
10725
+ }
10726
+ };
10727
+ ZodAny.create = (params) => {
10728
+ return new ZodAny({
10729
+ typeName: ZodFirstPartyTypeKind.ZodAny,
10730
+ ...processCreateParams(params)
10731
+ });
10732
+ };
10733
+ var ZodUnknown = class extends ZodType {
10734
+ constructor() {
10735
+ super(...arguments);
10736
+ this._unknown = true;
10737
+ }
10738
+ _parse(input) {
10739
+ return OK(input.data);
10740
+ }
10741
+ };
10742
+ ZodUnknown.create = (params) => {
10743
+ return new ZodUnknown({
10744
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
10745
+ ...processCreateParams(params)
10746
+ });
10747
+ };
10748
+ var ZodNever = class extends ZodType {
10749
+ _parse(input) {
10750
+ const ctx = this._getOrReturnCtx(input);
10751
+ addIssueToContext(ctx, {
10752
+ code: ZodIssueCode.invalid_type,
10753
+ expected: ZodParsedType.never,
10754
+ received: ctx.parsedType
10755
+ });
10756
+ return INVALID;
10757
+ }
10758
+ };
10759
+ ZodNever.create = (params) => {
10760
+ return new ZodNever({
10761
+ typeName: ZodFirstPartyTypeKind.ZodNever,
10762
+ ...processCreateParams(params)
10763
+ });
10764
+ };
10765
+ var ZodVoid = class extends ZodType {
10766
+ _parse(input) {
10767
+ const parsedType = this._getType(input);
10768
+ if (parsedType !== ZodParsedType.undefined) {
10769
+ const ctx = this._getOrReturnCtx(input);
10770
+ addIssueToContext(ctx, {
10771
+ code: ZodIssueCode.invalid_type,
10772
+ expected: ZodParsedType.void,
10773
+ received: ctx.parsedType
10774
+ });
10775
+ return INVALID;
10776
+ }
10777
+ return OK(input.data);
10778
+ }
10779
+ };
10780
+ ZodVoid.create = (params) => {
10781
+ return new ZodVoid({
10782
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
10783
+ ...processCreateParams(params)
10784
+ });
10785
+ };
10786
+ var ZodArray = class _ZodArray extends ZodType {
10787
+ _parse(input) {
10788
+ const { ctx, status } = this._processInputParams(input);
10789
+ const def = this._def;
10790
+ if (ctx.parsedType !== ZodParsedType.array) {
10791
+ addIssueToContext(ctx, {
10792
+ code: ZodIssueCode.invalid_type,
10793
+ expected: ZodParsedType.array,
10794
+ received: ctx.parsedType
10795
+ });
10796
+ return INVALID;
10797
+ }
10798
+ if (def.exactLength !== null) {
10799
+ const tooBig = ctx.data.length > def.exactLength.value;
10800
+ const tooSmall = ctx.data.length < def.exactLength.value;
10801
+ if (tooBig || tooSmall) {
10802
+ addIssueToContext(ctx, {
10803
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
10804
+ minimum: tooSmall ? def.exactLength.value : void 0,
10805
+ maximum: tooBig ? def.exactLength.value : void 0,
10806
+ type: "array",
10807
+ inclusive: true,
10808
+ exact: true,
10809
+ message: def.exactLength.message
10810
+ });
10811
+ status.dirty();
10812
+ }
10813
+ }
10814
+ if (def.minLength !== null) {
10815
+ if (ctx.data.length < def.minLength.value) {
10816
+ addIssueToContext(ctx, {
10817
+ code: ZodIssueCode.too_small,
10818
+ minimum: def.minLength.value,
10819
+ type: "array",
10820
+ inclusive: true,
10821
+ exact: false,
10822
+ message: def.minLength.message
10823
+ });
10824
+ status.dirty();
10825
+ }
10826
+ }
10827
+ if (def.maxLength !== null) {
10828
+ if (ctx.data.length > def.maxLength.value) {
10829
+ addIssueToContext(ctx, {
10830
+ code: ZodIssueCode.too_big,
10831
+ maximum: def.maxLength.value,
10832
+ type: "array",
10833
+ inclusive: true,
10834
+ exact: false,
10835
+ message: def.maxLength.message
10836
+ });
10837
+ status.dirty();
10838
+ }
10839
+ }
10840
+ if (ctx.common.async) {
10841
+ return Promise.all([...ctx.data].map((item, i) => {
10842
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
10843
+ })).then((result2) => {
10844
+ return ParseStatus.mergeArray(status, result2);
10845
+ });
10846
+ }
10847
+ const result = [...ctx.data].map((item, i) => {
10848
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
10849
+ });
10850
+ return ParseStatus.mergeArray(status, result);
10851
+ }
10852
+ get element() {
10853
+ return this._def.type;
10854
+ }
10855
+ min(minLength, message) {
10856
+ return new _ZodArray({
10857
+ ...this._def,
10858
+ minLength: { value: minLength, message: errorUtil.toString(message) }
10859
+ });
10860
+ }
10861
+ max(maxLength, message) {
10862
+ return new _ZodArray({
10863
+ ...this._def,
10864
+ maxLength: { value: maxLength, message: errorUtil.toString(message) }
10865
+ });
10866
+ }
10867
+ length(len, message) {
10868
+ return new _ZodArray({
10869
+ ...this._def,
10870
+ exactLength: { value: len, message: errorUtil.toString(message) }
10871
+ });
10872
+ }
10873
+ nonempty(message) {
10874
+ return this.min(1, message);
10875
+ }
10876
+ };
10877
+ ZodArray.create = (schema, params) => {
10878
+ return new ZodArray({
10879
+ type: schema,
10880
+ minLength: null,
10881
+ maxLength: null,
10882
+ exactLength: null,
10883
+ typeName: ZodFirstPartyTypeKind.ZodArray,
10884
+ ...processCreateParams(params)
10885
+ });
10886
+ };
10887
+ function deepPartialify(schema) {
10888
+ if (schema instanceof ZodObject) {
10889
+ const newShape = {};
10890
+ for (const key in schema.shape) {
10891
+ const fieldSchema = schema.shape[key];
10892
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
10893
+ }
10894
+ return new ZodObject({
10895
+ ...schema._def,
10896
+ shape: () => newShape
10897
+ });
10898
+ } else if (schema instanceof ZodArray) {
10899
+ return new ZodArray({
10900
+ ...schema._def,
10901
+ type: deepPartialify(schema.element)
10902
+ });
10903
+ } else if (schema instanceof ZodOptional) {
10904
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
10905
+ } else if (schema instanceof ZodNullable) {
10906
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
10907
+ } else if (schema instanceof ZodTuple) {
10908
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
10909
+ } else {
10910
+ return schema;
10911
+ }
10912
+ }
10913
+ var ZodObject = class _ZodObject extends ZodType {
10914
+ constructor() {
10915
+ super(...arguments);
10916
+ this._cached = null;
10917
+ this.nonstrict = this.passthrough;
10918
+ this.augment = this.extend;
10919
+ }
10920
+ _getCached() {
10921
+ if (this._cached !== null)
10922
+ return this._cached;
10923
+ const shape = this._def.shape();
10924
+ const keys = util.objectKeys(shape);
10925
+ this._cached = { shape, keys };
10926
+ return this._cached;
10927
+ }
10928
+ _parse(input) {
10929
+ const parsedType = this._getType(input);
10930
+ if (parsedType !== ZodParsedType.object) {
10931
+ const ctx2 = this._getOrReturnCtx(input);
10932
+ addIssueToContext(ctx2, {
10933
+ code: ZodIssueCode.invalid_type,
10934
+ expected: ZodParsedType.object,
10935
+ received: ctx2.parsedType
10936
+ });
10937
+ return INVALID;
10938
+ }
10939
+ const { status, ctx } = this._processInputParams(input);
10940
+ const { shape, keys: shapeKeys } = this._getCached();
10941
+ const extraKeys = [];
10942
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
10943
+ for (const key in ctx.data) {
10944
+ if (!shapeKeys.includes(key)) {
10945
+ extraKeys.push(key);
10946
+ }
10947
+ }
10948
+ }
10949
+ const pairs = [];
10950
+ for (const key of shapeKeys) {
10951
+ const keyValidator = shape[key];
10952
+ const value = ctx.data[key];
10953
+ pairs.push({
10954
+ key: { status: "valid", value: key },
10955
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
10956
+ alwaysSet: key in ctx.data
10957
+ });
10958
+ }
10959
+ if (this._def.catchall instanceof ZodNever) {
10960
+ const unknownKeys = this._def.unknownKeys;
10961
+ if (unknownKeys === "passthrough") {
10962
+ for (const key of extraKeys) {
10963
+ pairs.push({
10964
+ key: { status: "valid", value: key },
10965
+ value: { status: "valid", value: ctx.data[key] }
10966
+ });
10967
+ }
10968
+ } else if (unknownKeys === "strict") {
10969
+ if (extraKeys.length > 0) {
10970
+ addIssueToContext(ctx, {
10971
+ code: ZodIssueCode.unrecognized_keys,
10972
+ keys: extraKeys
10973
+ });
10974
+ status.dirty();
10975
+ }
10976
+ } else if (unknownKeys === "strip") {
10977
+ } else {
10978
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
10979
+ }
10980
+ } else {
10981
+ const catchall = this._def.catchall;
10982
+ for (const key of extraKeys) {
10983
+ const value = ctx.data[key];
10984
+ pairs.push({
10985
+ key: { status: "valid", value: key },
10986
+ value: catchall._parse(
10987
+ new ParseInputLazyPath(ctx, value, ctx.path, key)
10988
+ //, ctx.child(key), value, getParsedType(value)
10989
+ ),
10990
+ alwaysSet: key in ctx.data
10991
+ });
10992
+ }
10993
+ }
10994
+ if (ctx.common.async) {
10995
+ return Promise.resolve().then(async () => {
10996
+ const syncPairs = [];
10997
+ for (const pair of pairs) {
10998
+ const key = await pair.key;
10999
+ const value = await pair.value;
11000
+ syncPairs.push({
11001
+ key,
11002
+ value,
11003
+ alwaysSet: pair.alwaysSet
11004
+ });
11005
+ }
11006
+ return syncPairs;
11007
+ }).then((syncPairs) => {
11008
+ return ParseStatus.mergeObjectSync(status, syncPairs);
11009
+ });
11010
+ } else {
11011
+ return ParseStatus.mergeObjectSync(status, pairs);
11012
+ }
11013
+ }
11014
+ get shape() {
11015
+ return this._def.shape();
11016
+ }
11017
+ strict(message) {
11018
+ errorUtil.errToObj;
11019
+ return new _ZodObject({
11020
+ ...this._def,
11021
+ unknownKeys: "strict",
11022
+ ...message !== void 0 ? {
11023
+ errorMap: (issue, ctx) => {
11024
+ const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
11025
+ if (issue.code === "unrecognized_keys")
11026
+ return {
11027
+ message: errorUtil.errToObj(message).message ?? defaultError
11028
+ };
11029
+ return {
11030
+ message: defaultError
11031
+ };
11032
+ }
11033
+ } : {}
11034
+ });
11035
+ }
11036
+ strip() {
11037
+ return new _ZodObject({
11038
+ ...this._def,
11039
+ unknownKeys: "strip"
11040
+ });
11041
+ }
11042
+ passthrough() {
11043
+ return new _ZodObject({
11044
+ ...this._def,
11045
+ unknownKeys: "passthrough"
11046
+ });
11047
+ }
11048
+ // const AugmentFactory =
11049
+ // <Def extends ZodObjectDef>(def: Def) =>
11050
+ // <Augmentation extends ZodRawShape>(
11051
+ // augmentation: Augmentation
11052
+ // ): ZodObject<
11053
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
11054
+ // Def["unknownKeys"],
11055
+ // Def["catchall"]
11056
+ // > => {
11057
+ // return new ZodObject({
11058
+ // ...def,
11059
+ // shape: () => ({
11060
+ // ...def.shape(),
11061
+ // ...augmentation,
11062
+ // }),
11063
+ // }) as any;
11064
+ // };
11065
+ extend(augmentation) {
11066
+ return new _ZodObject({
11067
+ ...this._def,
11068
+ shape: () => ({
11069
+ ...this._def.shape(),
11070
+ ...augmentation
11071
+ })
11072
+ });
11073
+ }
11074
+ /**
11075
+ * Prior to zod@1.0.12 there was a bug in the
11076
+ * inferred type of merged objects. Please
11077
+ * upgrade if you are experiencing issues.
11078
+ */
11079
+ merge(merging) {
11080
+ const merged = new _ZodObject({
11081
+ unknownKeys: merging._def.unknownKeys,
11082
+ catchall: merging._def.catchall,
11083
+ shape: () => ({
11084
+ ...this._def.shape(),
11085
+ ...merging._def.shape()
11086
+ }),
11087
+ typeName: ZodFirstPartyTypeKind.ZodObject
11088
+ });
11089
+ return merged;
11090
+ }
11091
+ // merge<
11092
+ // Incoming extends AnyZodObject,
11093
+ // Augmentation extends Incoming["shape"],
11094
+ // NewOutput extends {
11095
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
11096
+ // ? Augmentation[k]["_output"]
11097
+ // : k extends keyof Output
11098
+ // ? Output[k]
11099
+ // : never;
11100
+ // },
11101
+ // NewInput extends {
11102
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
11103
+ // ? Augmentation[k]["_input"]
11104
+ // : k extends keyof Input
11105
+ // ? Input[k]
11106
+ // : never;
11107
+ // }
11108
+ // >(
11109
+ // merging: Incoming
11110
+ // ): ZodObject<
11111
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
11112
+ // Incoming["_def"]["unknownKeys"],
11113
+ // Incoming["_def"]["catchall"],
11114
+ // NewOutput,
11115
+ // NewInput
11116
+ // > {
11117
+ // const merged: any = new ZodObject({
11118
+ // unknownKeys: merging._def.unknownKeys,
11119
+ // catchall: merging._def.catchall,
11120
+ // shape: () =>
11121
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
11122
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
11123
+ // }) as any;
11124
+ // return merged;
11125
+ // }
11126
+ setKey(key, schema) {
11127
+ return this.augment({ [key]: schema });
11128
+ }
11129
+ // merge<Incoming extends AnyZodObject>(
11130
+ // merging: Incoming
11131
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
11132
+ // ZodObject<
11133
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
11134
+ // Incoming["_def"]["unknownKeys"],
11135
+ // Incoming["_def"]["catchall"]
11136
+ // > {
11137
+ // // const mergedShape = objectUtil.mergeShapes(
11138
+ // // this._def.shape(),
11139
+ // // merging._def.shape()
11140
+ // // );
11141
+ // const merged: any = new ZodObject({
11142
+ // unknownKeys: merging._def.unknownKeys,
11143
+ // catchall: merging._def.catchall,
11144
+ // shape: () =>
11145
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
11146
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
11147
+ // }) as any;
11148
+ // return merged;
11149
+ // }
11150
+ catchall(index) {
11151
+ return new _ZodObject({
11152
+ ...this._def,
11153
+ catchall: index
11154
+ });
11155
+ }
11156
+ pick(mask) {
11157
+ const shape = {};
11158
+ for (const key of util.objectKeys(mask)) {
11159
+ if (mask[key] && this.shape[key]) {
11160
+ shape[key] = this.shape[key];
11161
+ }
11162
+ }
11163
+ return new _ZodObject({
11164
+ ...this._def,
11165
+ shape: () => shape
11166
+ });
11167
+ }
11168
+ omit(mask) {
11169
+ const shape = {};
11170
+ for (const key of util.objectKeys(this.shape)) {
11171
+ if (!mask[key]) {
11172
+ shape[key] = this.shape[key];
11173
+ }
11174
+ }
11175
+ return new _ZodObject({
11176
+ ...this._def,
11177
+ shape: () => shape
11178
+ });
11179
+ }
11180
+ /**
11181
+ * @deprecated
11182
+ */
11183
+ deepPartial() {
11184
+ return deepPartialify(this);
11185
+ }
11186
+ partial(mask) {
11187
+ const newShape = {};
11188
+ for (const key of util.objectKeys(this.shape)) {
11189
+ const fieldSchema = this.shape[key];
11190
+ if (mask && !mask[key]) {
11191
+ newShape[key] = fieldSchema;
11192
+ } else {
11193
+ newShape[key] = fieldSchema.optional();
11194
+ }
11195
+ }
11196
+ return new _ZodObject({
11197
+ ...this._def,
11198
+ shape: () => newShape
11199
+ });
11200
+ }
11201
+ required(mask) {
11202
+ const newShape = {};
11203
+ for (const key of util.objectKeys(this.shape)) {
11204
+ if (mask && !mask[key]) {
11205
+ newShape[key] = this.shape[key];
11206
+ } else {
11207
+ const fieldSchema = this.shape[key];
11208
+ let newField = fieldSchema;
11209
+ while (newField instanceof ZodOptional) {
11210
+ newField = newField._def.innerType;
11211
+ }
11212
+ newShape[key] = newField;
11213
+ }
11214
+ }
11215
+ return new _ZodObject({
11216
+ ...this._def,
11217
+ shape: () => newShape
11218
+ });
11219
+ }
11220
+ keyof() {
11221
+ return createZodEnum(util.objectKeys(this.shape));
11222
+ }
11223
+ };
11224
+ ZodObject.create = (shape, params) => {
11225
+ return new ZodObject({
11226
+ shape: () => shape,
11227
+ unknownKeys: "strip",
11228
+ catchall: ZodNever.create(),
11229
+ typeName: ZodFirstPartyTypeKind.ZodObject,
11230
+ ...processCreateParams(params)
11231
+ });
11232
+ };
11233
+ ZodObject.strictCreate = (shape, params) => {
11234
+ return new ZodObject({
11235
+ shape: () => shape,
11236
+ unknownKeys: "strict",
11237
+ catchall: ZodNever.create(),
11238
+ typeName: ZodFirstPartyTypeKind.ZodObject,
11239
+ ...processCreateParams(params)
11240
+ });
11241
+ };
11242
+ ZodObject.lazycreate = (shape, params) => {
11243
+ return new ZodObject({
11244
+ shape,
11245
+ unknownKeys: "strip",
11246
+ catchall: ZodNever.create(),
11247
+ typeName: ZodFirstPartyTypeKind.ZodObject,
11248
+ ...processCreateParams(params)
11249
+ });
11250
+ };
11251
+ var ZodUnion = class extends ZodType {
11252
+ _parse(input) {
11253
+ const { ctx } = this._processInputParams(input);
11254
+ const options = this._def.options;
11255
+ function handleResults(results) {
11256
+ for (const result of results) {
11257
+ if (result.result.status === "valid") {
11258
+ return result.result;
11259
+ }
11260
+ }
11261
+ for (const result of results) {
11262
+ if (result.result.status === "dirty") {
11263
+ ctx.common.issues.push(...result.ctx.common.issues);
11264
+ return result.result;
11265
+ }
11266
+ }
11267
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
11268
+ addIssueToContext(ctx, {
11269
+ code: ZodIssueCode.invalid_union,
11270
+ unionErrors
11271
+ });
11272
+ return INVALID;
11273
+ }
11274
+ if (ctx.common.async) {
11275
+ return Promise.all(options.map(async (option) => {
11276
+ const childCtx = {
11277
+ ...ctx,
11278
+ common: {
11279
+ ...ctx.common,
11280
+ issues: []
11281
+ },
11282
+ parent: null
11283
+ };
11284
+ return {
11285
+ result: await option._parseAsync({
11286
+ data: ctx.data,
11287
+ path: ctx.path,
11288
+ parent: childCtx
11289
+ }),
11290
+ ctx: childCtx
11291
+ };
11292
+ })).then(handleResults);
11293
+ } else {
11294
+ let dirty = void 0;
11295
+ const issues = [];
11296
+ for (const option of options) {
11297
+ const childCtx = {
11298
+ ...ctx,
11299
+ common: {
11300
+ ...ctx.common,
11301
+ issues: []
11302
+ },
11303
+ parent: null
11304
+ };
11305
+ const result = option._parseSync({
11306
+ data: ctx.data,
11307
+ path: ctx.path,
11308
+ parent: childCtx
11309
+ });
11310
+ if (result.status === "valid") {
11311
+ return result;
11312
+ } else if (result.status === "dirty" && !dirty) {
11313
+ dirty = { result, ctx: childCtx };
11314
+ }
11315
+ if (childCtx.common.issues.length) {
11316
+ issues.push(childCtx.common.issues);
11317
+ }
11318
+ }
11319
+ if (dirty) {
11320
+ ctx.common.issues.push(...dirty.ctx.common.issues);
11321
+ return dirty.result;
11322
+ }
11323
+ const unionErrors = issues.map((issues2) => new ZodError(issues2));
11324
+ addIssueToContext(ctx, {
11325
+ code: ZodIssueCode.invalid_union,
11326
+ unionErrors
11327
+ });
11328
+ return INVALID;
11329
+ }
11330
+ }
11331
+ get options() {
11332
+ return this._def.options;
11333
+ }
11334
+ };
11335
+ ZodUnion.create = (types, params) => {
11336
+ return new ZodUnion({
11337
+ options: types,
11338
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
11339
+ ...processCreateParams(params)
11340
+ });
11341
+ };
11342
+ var getDiscriminator = (type) => {
11343
+ if (type instanceof ZodLazy) {
11344
+ return getDiscriminator(type.schema);
11345
+ } else if (type instanceof ZodEffects) {
11346
+ return getDiscriminator(type.innerType());
11347
+ } else if (type instanceof ZodLiteral) {
11348
+ return [type.value];
11349
+ } else if (type instanceof ZodEnum) {
11350
+ return type.options;
11351
+ } else if (type instanceof ZodNativeEnum) {
11352
+ return util.objectValues(type.enum);
11353
+ } else if (type instanceof ZodDefault) {
11354
+ return getDiscriminator(type._def.innerType);
11355
+ } else if (type instanceof ZodUndefined) {
11356
+ return [void 0];
11357
+ } else if (type instanceof ZodNull) {
11358
+ return [null];
11359
+ } else if (type instanceof ZodOptional) {
11360
+ return [void 0, ...getDiscriminator(type.unwrap())];
11361
+ } else if (type instanceof ZodNullable) {
11362
+ return [null, ...getDiscriminator(type.unwrap())];
11363
+ } else if (type instanceof ZodBranded) {
11364
+ return getDiscriminator(type.unwrap());
11365
+ } else if (type instanceof ZodReadonly) {
11366
+ return getDiscriminator(type.unwrap());
11367
+ } else if (type instanceof ZodCatch) {
11368
+ return getDiscriminator(type._def.innerType);
11369
+ } else {
11370
+ return [];
11371
+ }
11372
+ };
11373
+ var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
11374
+ _parse(input) {
11375
+ const { ctx } = this._processInputParams(input);
11376
+ if (ctx.parsedType !== ZodParsedType.object) {
11377
+ addIssueToContext(ctx, {
11378
+ code: ZodIssueCode.invalid_type,
11379
+ expected: ZodParsedType.object,
11380
+ received: ctx.parsedType
11381
+ });
11382
+ return INVALID;
11383
+ }
11384
+ const discriminator = this.discriminator;
11385
+ const discriminatorValue = ctx.data[discriminator];
11386
+ const option = this.optionsMap.get(discriminatorValue);
11387
+ if (!option) {
11388
+ addIssueToContext(ctx, {
11389
+ code: ZodIssueCode.invalid_union_discriminator,
11390
+ options: Array.from(this.optionsMap.keys()),
11391
+ path: [discriminator]
11392
+ });
11393
+ return INVALID;
11394
+ }
11395
+ if (ctx.common.async) {
11396
+ return option._parseAsync({
11397
+ data: ctx.data,
11398
+ path: ctx.path,
11399
+ parent: ctx
11400
+ });
11401
+ } else {
11402
+ return option._parseSync({
11403
+ data: ctx.data,
11404
+ path: ctx.path,
11405
+ parent: ctx
11406
+ });
11407
+ }
11408
+ }
11409
+ get discriminator() {
11410
+ return this._def.discriminator;
11411
+ }
11412
+ get options() {
11413
+ return this._def.options;
11414
+ }
11415
+ get optionsMap() {
11416
+ return this._def.optionsMap;
11417
+ }
11418
+ /**
11419
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
11420
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
11421
+ * have a different value for each object in the union.
11422
+ * @param discriminator the name of the discriminator property
11423
+ * @param types an array of object schemas
11424
+ * @param params
11425
+ */
11426
+ static create(discriminator, options, params) {
11427
+ const optionsMap = /* @__PURE__ */ new Map();
11428
+ for (const type of options) {
11429
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
11430
+ if (!discriminatorValues.length) {
11431
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
11432
+ }
11433
+ for (const value of discriminatorValues) {
11434
+ if (optionsMap.has(value)) {
11435
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
11436
+ }
11437
+ optionsMap.set(value, type);
11438
+ }
11439
+ }
11440
+ return new _ZodDiscriminatedUnion({
11441
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
11442
+ discriminator,
11443
+ options,
11444
+ optionsMap,
11445
+ ...processCreateParams(params)
11446
+ });
11447
+ }
11448
+ };
11449
+ function mergeValues(a, b) {
11450
+ const aType = getParsedType(a);
11451
+ const bType = getParsedType(b);
11452
+ if (a === b) {
11453
+ return { valid: true, data: a };
11454
+ } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
11455
+ const bKeys = util.objectKeys(b);
11456
+ const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
11457
+ const newObj = { ...a, ...b };
11458
+ for (const key of sharedKeys) {
11459
+ const sharedValue = mergeValues(a[key], b[key]);
11460
+ if (!sharedValue.valid) {
11461
+ return { valid: false };
11462
+ }
11463
+ newObj[key] = sharedValue.data;
11464
+ }
11465
+ return { valid: true, data: newObj };
11466
+ } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
11467
+ if (a.length !== b.length) {
11468
+ return { valid: false };
11469
+ }
11470
+ const newArray = [];
11471
+ for (let index = 0; index < a.length; index++) {
11472
+ const itemA = a[index];
11473
+ const itemB = b[index];
11474
+ const sharedValue = mergeValues(itemA, itemB);
11475
+ if (!sharedValue.valid) {
11476
+ return { valid: false };
11477
+ }
11478
+ newArray.push(sharedValue.data);
11479
+ }
11480
+ return { valid: true, data: newArray };
11481
+ } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
11482
+ return { valid: true, data: a };
11483
+ } else {
11484
+ return { valid: false };
11485
+ }
11486
+ }
11487
+ var ZodIntersection = class extends ZodType {
11488
+ _parse(input) {
11489
+ const { status, ctx } = this._processInputParams(input);
11490
+ const handleParsed = (parsedLeft, parsedRight) => {
11491
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
11492
+ return INVALID;
11493
+ }
11494
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
11495
+ if (!merged.valid) {
11496
+ addIssueToContext(ctx, {
11497
+ code: ZodIssueCode.invalid_intersection_types
11498
+ });
11499
+ return INVALID;
11500
+ }
11501
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
11502
+ status.dirty();
11503
+ }
11504
+ return { status: status.value, value: merged.data };
11505
+ };
11506
+ if (ctx.common.async) {
11507
+ return Promise.all([
11508
+ this._def.left._parseAsync({
11509
+ data: ctx.data,
11510
+ path: ctx.path,
11511
+ parent: ctx
11512
+ }),
11513
+ this._def.right._parseAsync({
11514
+ data: ctx.data,
11515
+ path: ctx.path,
11516
+ parent: ctx
11517
+ })
11518
+ ]).then(([left, right]) => handleParsed(left, right));
11519
+ } else {
11520
+ return handleParsed(this._def.left._parseSync({
11521
+ data: ctx.data,
11522
+ path: ctx.path,
11523
+ parent: ctx
11524
+ }), this._def.right._parseSync({
11525
+ data: ctx.data,
11526
+ path: ctx.path,
11527
+ parent: ctx
11528
+ }));
11529
+ }
11530
+ }
11531
+ };
11532
+ ZodIntersection.create = (left, right, params) => {
11533
+ return new ZodIntersection({
11534
+ left,
11535
+ right,
11536
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
11537
+ ...processCreateParams(params)
11538
+ });
11539
+ };
11540
+ var ZodTuple = class _ZodTuple extends ZodType {
11541
+ _parse(input) {
11542
+ const { status, ctx } = this._processInputParams(input);
11543
+ if (ctx.parsedType !== ZodParsedType.array) {
11544
+ addIssueToContext(ctx, {
11545
+ code: ZodIssueCode.invalid_type,
11546
+ expected: ZodParsedType.array,
11547
+ received: ctx.parsedType
11548
+ });
11549
+ return INVALID;
11550
+ }
11551
+ if (ctx.data.length < this._def.items.length) {
11552
+ addIssueToContext(ctx, {
11553
+ code: ZodIssueCode.too_small,
11554
+ minimum: this._def.items.length,
11555
+ inclusive: true,
11556
+ exact: false,
11557
+ type: "array"
11558
+ });
11559
+ return INVALID;
11560
+ }
11561
+ const rest = this._def.rest;
11562
+ if (!rest && ctx.data.length > this._def.items.length) {
11563
+ addIssueToContext(ctx, {
11564
+ code: ZodIssueCode.too_big,
11565
+ maximum: this._def.items.length,
11566
+ inclusive: true,
11567
+ exact: false,
11568
+ type: "array"
11569
+ });
11570
+ status.dirty();
11571
+ }
11572
+ const items = [...ctx.data].map((item, itemIndex) => {
11573
+ const schema = this._def.items[itemIndex] || this._def.rest;
11574
+ if (!schema)
11575
+ return null;
11576
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
11577
+ }).filter((x) => !!x);
11578
+ if (ctx.common.async) {
11579
+ return Promise.all(items).then((results) => {
11580
+ return ParseStatus.mergeArray(status, results);
11581
+ });
11582
+ } else {
11583
+ return ParseStatus.mergeArray(status, items);
11584
+ }
11585
+ }
11586
+ get items() {
11587
+ return this._def.items;
11588
+ }
11589
+ rest(rest) {
11590
+ return new _ZodTuple({
11591
+ ...this._def,
11592
+ rest
11593
+ });
11594
+ }
11595
+ };
11596
+ ZodTuple.create = (schemas, params) => {
11597
+ if (!Array.isArray(schemas)) {
11598
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
11599
+ }
11600
+ return new ZodTuple({
11601
+ items: schemas,
11602
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
11603
+ rest: null,
11604
+ ...processCreateParams(params)
11605
+ });
11606
+ };
11607
+ var ZodRecord = class _ZodRecord extends ZodType {
11608
+ get keySchema() {
11609
+ return this._def.keyType;
11610
+ }
11611
+ get valueSchema() {
11612
+ return this._def.valueType;
11613
+ }
11614
+ _parse(input) {
11615
+ const { status, ctx } = this._processInputParams(input);
11616
+ if (ctx.parsedType !== ZodParsedType.object) {
11617
+ addIssueToContext(ctx, {
11618
+ code: ZodIssueCode.invalid_type,
11619
+ expected: ZodParsedType.object,
11620
+ received: ctx.parsedType
11621
+ });
11622
+ return INVALID;
11623
+ }
11624
+ const pairs = [];
11625
+ const keyType = this._def.keyType;
11626
+ const valueType = this._def.valueType;
11627
+ for (const key in ctx.data) {
11628
+ pairs.push({
11629
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
11630
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
11631
+ alwaysSet: key in ctx.data
11632
+ });
11633
+ }
11634
+ if (ctx.common.async) {
11635
+ return ParseStatus.mergeObjectAsync(status, pairs);
11636
+ } else {
11637
+ return ParseStatus.mergeObjectSync(status, pairs);
11638
+ }
11639
+ }
11640
+ get element() {
11641
+ return this._def.valueType;
11642
+ }
11643
+ static create(first, second, third) {
11644
+ if (second instanceof ZodType) {
11645
+ return new _ZodRecord({
11646
+ keyType: first,
11647
+ valueType: second,
11648
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
11649
+ ...processCreateParams(third)
11650
+ });
11651
+ }
11652
+ return new _ZodRecord({
11653
+ keyType: ZodString.create(),
11654
+ valueType: first,
11655
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
11656
+ ...processCreateParams(second)
11657
+ });
11658
+ }
11659
+ };
11660
+ var ZodMap = class extends ZodType {
11661
+ get keySchema() {
11662
+ return this._def.keyType;
11663
+ }
11664
+ get valueSchema() {
11665
+ return this._def.valueType;
11666
+ }
11667
+ _parse(input) {
11668
+ const { status, ctx } = this._processInputParams(input);
11669
+ if (ctx.parsedType !== ZodParsedType.map) {
11670
+ addIssueToContext(ctx, {
11671
+ code: ZodIssueCode.invalid_type,
11672
+ expected: ZodParsedType.map,
11673
+ received: ctx.parsedType
11674
+ });
11675
+ return INVALID;
11676
+ }
11677
+ const keyType = this._def.keyType;
11678
+ const valueType = this._def.valueType;
11679
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
11680
+ return {
11681
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
11682
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
11683
+ };
11684
+ });
11685
+ if (ctx.common.async) {
11686
+ const finalMap = /* @__PURE__ */ new Map();
11687
+ return Promise.resolve().then(async () => {
11688
+ for (const pair of pairs) {
11689
+ const key = await pair.key;
11690
+ const value = await pair.value;
11691
+ if (key.status === "aborted" || value.status === "aborted") {
11692
+ return INVALID;
11693
+ }
11694
+ if (key.status === "dirty" || value.status === "dirty") {
11695
+ status.dirty();
11696
+ }
11697
+ finalMap.set(key.value, value.value);
11698
+ }
11699
+ return { status: status.value, value: finalMap };
11700
+ });
11701
+ } else {
11702
+ const finalMap = /* @__PURE__ */ new Map();
11703
+ for (const pair of pairs) {
11704
+ const key = pair.key;
11705
+ const value = pair.value;
11706
+ if (key.status === "aborted" || value.status === "aborted") {
11707
+ return INVALID;
11708
+ }
11709
+ if (key.status === "dirty" || value.status === "dirty") {
11710
+ status.dirty();
11711
+ }
11712
+ finalMap.set(key.value, value.value);
11713
+ }
11714
+ return { status: status.value, value: finalMap };
11715
+ }
11716
+ }
11717
+ };
11718
+ ZodMap.create = (keyType, valueType, params) => {
11719
+ return new ZodMap({
11720
+ valueType,
11721
+ keyType,
11722
+ typeName: ZodFirstPartyTypeKind.ZodMap,
11723
+ ...processCreateParams(params)
11724
+ });
11725
+ };
11726
+ var ZodSet = class _ZodSet extends ZodType {
11727
+ _parse(input) {
11728
+ const { status, ctx } = this._processInputParams(input);
11729
+ if (ctx.parsedType !== ZodParsedType.set) {
11730
+ addIssueToContext(ctx, {
11731
+ code: ZodIssueCode.invalid_type,
11732
+ expected: ZodParsedType.set,
11733
+ received: ctx.parsedType
11734
+ });
11735
+ return INVALID;
11736
+ }
11737
+ const def = this._def;
11738
+ if (def.minSize !== null) {
11739
+ if (ctx.data.size < def.minSize.value) {
11740
+ addIssueToContext(ctx, {
11741
+ code: ZodIssueCode.too_small,
11742
+ minimum: def.minSize.value,
11743
+ type: "set",
11744
+ inclusive: true,
11745
+ exact: false,
11746
+ message: def.minSize.message
11747
+ });
11748
+ status.dirty();
11749
+ }
11750
+ }
11751
+ if (def.maxSize !== null) {
11752
+ if (ctx.data.size > def.maxSize.value) {
11753
+ addIssueToContext(ctx, {
11754
+ code: ZodIssueCode.too_big,
11755
+ maximum: def.maxSize.value,
11756
+ type: "set",
11757
+ inclusive: true,
11758
+ exact: false,
11759
+ message: def.maxSize.message
11760
+ });
11761
+ status.dirty();
11762
+ }
11763
+ }
11764
+ const valueType = this._def.valueType;
11765
+ function finalizeSet(elements2) {
11766
+ const parsedSet = /* @__PURE__ */ new Set();
11767
+ for (const element of elements2) {
11768
+ if (element.status === "aborted")
11769
+ return INVALID;
11770
+ if (element.status === "dirty")
11771
+ status.dirty();
11772
+ parsedSet.add(element.value);
11773
+ }
11774
+ return { status: status.value, value: parsedSet };
11775
+ }
11776
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
11777
+ if (ctx.common.async) {
11778
+ return Promise.all(elements).then((elements2) => finalizeSet(elements2));
11779
+ } else {
11780
+ return finalizeSet(elements);
11781
+ }
11782
+ }
11783
+ min(minSize, message) {
11784
+ return new _ZodSet({
11785
+ ...this._def,
11786
+ minSize: { value: minSize, message: errorUtil.toString(message) }
11787
+ });
11788
+ }
11789
+ max(maxSize, message) {
11790
+ return new _ZodSet({
11791
+ ...this._def,
11792
+ maxSize: { value: maxSize, message: errorUtil.toString(message) }
11793
+ });
11794
+ }
11795
+ size(size, message) {
11796
+ return this.min(size, message).max(size, message);
11797
+ }
11798
+ nonempty(message) {
11799
+ return this.min(1, message);
11800
+ }
11801
+ };
11802
+ ZodSet.create = (valueType, params) => {
11803
+ return new ZodSet({
11804
+ valueType,
11805
+ minSize: null,
11806
+ maxSize: null,
11807
+ typeName: ZodFirstPartyTypeKind.ZodSet,
11808
+ ...processCreateParams(params)
11809
+ });
11810
+ };
11811
+ var ZodFunction = class _ZodFunction extends ZodType {
11812
+ constructor() {
11813
+ super(...arguments);
11814
+ this.validate = this.implement;
11815
+ }
11816
+ _parse(input) {
11817
+ const { ctx } = this._processInputParams(input);
11818
+ if (ctx.parsedType !== ZodParsedType.function) {
11819
+ addIssueToContext(ctx, {
11820
+ code: ZodIssueCode.invalid_type,
11821
+ expected: ZodParsedType.function,
11822
+ received: ctx.parsedType
11823
+ });
11824
+ return INVALID;
11825
+ }
11826
+ function makeArgsIssue(args, error) {
11827
+ return makeIssue({
11828
+ data: args,
11829
+ path: ctx.path,
11830
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
11831
+ issueData: {
11832
+ code: ZodIssueCode.invalid_arguments,
11833
+ argumentsError: error
11834
+ }
11835
+ });
11836
+ }
11837
+ function makeReturnsIssue(returns, error) {
11838
+ return makeIssue({
11839
+ data: returns,
11840
+ path: ctx.path,
11841
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
11842
+ issueData: {
11843
+ code: ZodIssueCode.invalid_return_type,
11844
+ returnTypeError: error
11845
+ }
11846
+ });
11847
+ }
11848
+ const params = { errorMap: ctx.common.contextualErrorMap };
11849
+ const fn = ctx.data;
11850
+ if (this._def.returns instanceof ZodPromise) {
11851
+ const me = this;
11852
+ return OK(async function(...args) {
11853
+ const error = new ZodError([]);
11854
+ const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
11855
+ error.addIssue(makeArgsIssue(args, e));
11856
+ throw error;
11857
+ });
11858
+ const result = await Reflect.apply(fn, this, parsedArgs);
11859
+ const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
11860
+ error.addIssue(makeReturnsIssue(result, e));
11861
+ throw error;
11862
+ });
11863
+ return parsedReturns;
11864
+ });
11865
+ } else {
11866
+ const me = this;
11867
+ return OK(function(...args) {
11868
+ const parsedArgs = me._def.args.safeParse(args, params);
11869
+ if (!parsedArgs.success) {
11870
+ throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
11871
+ }
11872
+ const result = Reflect.apply(fn, this, parsedArgs.data);
11873
+ const parsedReturns = me._def.returns.safeParse(result, params);
11874
+ if (!parsedReturns.success) {
11875
+ throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
11876
+ }
11877
+ return parsedReturns.data;
11878
+ });
11879
+ }
11880
+ }
11881
+ parameters() {
11882
+ return this._def.args;
11883
+ }
11884
+ returnType() {
11885
+ return this._def.returns;
11886
+ }
11887
+ args(...items) {
11888
+ return new _ZodFunction({
11889
+ ...this._def,
11890
+ args: ZodTuple.create(items).rest(ZodUnknown.create())
11891
+ });
11892
+ }
11893
+ returns(returnType) {
11894
+ return new _ZodFunction({
11895
+ ...this._def,
11896
+ returns: returnType
11897
+ });
11898
+ }
11899
+ implement(func) {
11900
+ const validatedFunc = this.parse(func);
11901
+ return validatedFunc;
11902
+ }
11903
+ strictImplement(func) {
11904
+ const validatedFunc = this.parse(func);
11905
+ return validatedFunc;
11906
+ }
11907
+ static create(args, returns, params) {
11908
+ return new _ZodFunction({
11909
+ args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
11910
+ returns: returns || ZodUnknown.create(),
11911
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
11912
+ ...processCreateParams(params)
11913
+ });
11914
+ }
11915
+ };
11916
+ var ZodLazy = class extends ZodType {
11917
+ get schema() {
11918
+ return this._def.getter();
11919
+ }
11920
+ _parse(input) {
11921
+ const { ctx } = this._processInputParams(input);
11922
+ const lazySchema = this._def.getter();
11923
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
11924
+ }
11925
+ };
11926
+ ZodLazy.create = (getter, params) => {
11927
+ return new ZodLazy({
11928
+ getter,
11929
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
11930
+ ...processCreateParams(params)
11931
+ });
11932
+ };
11933
+ var ZodLiteral = class extends ZodType {
11934
+ _parse(input) {
11935
+ if (input.data !== this._def.value) {
11936
+ const ctx = this._getOrReturnCtx(input);
11937
+ addIssueToContext(ctx, {
11938
+ received: ctx.data,
11939
+ code: ZodIssueCode.invalid_literal,
11940
+ expected: this._def.value
11941
+ });
11942
+ return INVALID;
11943
+ }
11944
+ return { status: "valid", value: input.data };
11945
+ }
11946
+ get value() {
11947
+ return this._def.value;
11948
+ }
11949
+ };
11950
+ ZodLiteral.create = (value, params) => {
11951
+ return new ZodLiteral({
11952
+ value,
11953
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
11954
+ ...processCreateParams(params)
11955
+ });
11956
+ };
11957
+ function createZodEnum(values, params) {
11958
+ return new ZodEnum({
11959
+ values,
11960
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
11961
+ ...processCreateParams(params)
11962
+ });
11963
+ }
11964
+ var ZodEnum = class _ZodEnum extends ZodType {
11965
+ _parse(input) {
11966
+ if (typeof input.data !== "string") {
11967
+ const ctx = this._getOrReturnCtx(input);
11968
+ const expectedValues = this._def.values;
11969
+ addIssueToContext(ctx, {
11970
+ expected: util.joinValues(expectedValues),
11971
+ received: ctx.parsedType,
11972
+ code: ZodIssueCode.invalid_type
11973
+ });
11974
+ return INVALID;
11975
+ }
11976
+ if (!this._cache) {
11977
+ this._cache = new Set(this._def.values);
11978
+ }
11979
+ if (!this._cache.has(input.data)) {
11980
+ const ctx = this._getOrReturnCtx(input);
11981
+ const expectedValues = this._def.values;
11982
+ addIssueToContext(ctx, {
11983
+ received: ctx.data,
11984
+ code: ZodIssueCode.invalid_enum_value,
11985
+ options: expectedValues
11986
+ });
11987
+ return INVALID;
11988
+ }
11989
+ return OK(input.data);
11990
+ }
11991
+ get options() {
11992
+ return this._def.values;
11993
+ }
11994
+ get enum() {
11995
+ const enumValues = {};
11996
+ for (const val of this._def.values) {
11997
+ enumValues[val] = val;
11998
+ }
11999
+ return enumValues;
12000
+ }
12001
+ get Values() {
12002
+ const enumValues = {};
12003
+ for (const val of this._def.values) {
12004
+ enumValues[val] = val;
12005
+ }
12006
+ return enumValues;
12007
+ }
12008
+ get Enum() {
12009
+ const enumValues = {};
12010
+ for (const val of this._def.values) {
12011
+ enumValues[val] = val;
12012
+ }
12013
+ return enumValues;
12014
+ }
12015
+ extract(values, newDef = this._def) {
12016
+ return _ZodEnum.create(values, {
12017
+ ...this._def,
12018
+ ...newDef
12019
+ });
12020
+ }
12021
+ exclude(values, newDef = this._def) {
12022
+ return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
12023
+ ...this._def,
12024
+ ...newDef
12025
+ });
12026
+ }
12027
+ };
12028
+ ZodEnum.create = createZodEnum;
12029
+ var ZodNativeEnum = class extends ZodType {
12030
+ _parse(input) {
12031
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
12032
+ const ctx = this._getOrReturnCtx(input);
12033
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
12034
+ const expectedValues = util.objectValues(nativeEnumValues);
12035
+ addIssueToContext(ctx, {
12036
+ expected: util.joinValues(expectedValues),
12037
+ received: ctx.parsedType,
12038
+ code: ZodIssueCode.invalid_type
12039
+ });
12040
+ return INVALID;
12041
+ }
12042
+ if (!this._cache) {
12043
+ this._cache = new Set(util.getValidEnumValues(this._def.values));
12044
+ }
12045
+ if (!this._cache.has(input.data)) {
12046
+ const expectedValues = util.objectValues(nativeEnumValues);
12047
+ addIssueToContext(ctx, {
12048
+ received: ctx.data,
12049
+ code: ZodIssueCode.invalid_enum_value,
12050
+ options: expectedValues
12051
+ });
12052
+ return INVALID;
12053
+ }
12054
+ return OK(input.data);
12055
+ }
12056
+ get enum() {
12057
+ return this._def.values;
12058
+ }
12059
+ };
12060
+ ZodNativeEnum.create = (values, params) => {
12061
+ return new ZodNativeEnum({
12062
+ values,
12063
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
12064
+ ...processCreateParams(params)
12065
+ });
12066
+ };
12067
+ var ZodPromise = class extends ZodType {
12068
+ unwrap() {
12069
+ return this._def.type;
12070
+ }
12071
+ _parse(input) {
12072
+ const { ctx } = this._processInputParams(input);
12073
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
12074
+ addIssueToContext(ctx, {
12075
+ code: ZodIssueCode.invalid_type,
12076
+ expected: ZodParsedType.promise,
12077
+ received: ctx.parsedType
12078
+ });
12079
+ return INVALID;
12080
+ }
12081
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
12082
+ return OK(promisified.then((data) => {
12083
+ return this._def.type.parseAsync(data, {
12084
+ path: ctx.path,
12085
+ errorMap: ctx.common.contextualErrorMap
12086
+ });
12087
+ }));
12088
+ }
12089
+ };
12090
+ ZodPromise.create = (schema, params) => {
12091
+ return new ZodPromise({
12092
+ type: schema,
12093
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
12094
+ ...processCreateParams(params)
12095
+ });
12096
+ };
12097
+ var ZodEffects = class extends ZodType {
12098
+ innerType() {
12099
+ return this._def.schema;
12100
+ }
12101
+ sourceType() {
12102
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
12103
+ }
12104
+ _parse(input) {
12105
+ const { status, ctx } = this._processInputParams(input);
12106
+ const effect = this._def.effect || null;
12107
+ const checkCtx = {
12108
+ addIssue: (arg) => {
12109
+ addIssueToContext(ctx, arg);
12110
+ if (arg.fatal) {
12111
+ status.abort();
12112
+ } else {
12113
+ status.dirty();
12114
+ }
12115
+ },
12116
+ get path() {
12117
+ return ctx.path;
12118
+ }
12119
+ };
12120
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
12121
+ if (effect.type === "preprocess") {
12122
+ const processed = effect.transform(ctx.data, checkCtx);
12123
+ if (ctx.common.async) {
12124
+ return Promise.resolve(processed).then(async (processed2) => {
12125
+ if (status.value === "aborted")
12126
+ return INVALID;
12127
+ const result = await this._def.schema._parseAsync({
12128
+ data: processed2,
12129
+ path: ctx.path,
12130
+ parent: ctx
12131
+ });
12132
+ if (result.status === "aborted")
12133
+ return INVALID;
12134
+ if (result.status === "dirty")
12135
+ return DIRTY(result.value);
12136
+ if (status.value === "dirty")
12137
+ return DIRTY(result.value);
12138
+ return result;
12139
+ });
12140
+ } else {
12141
+ if (status.value === "aborted")
12142
+ return INVALID;
12143
+ const result = this._def.schema._parseSync({
12144
+ data: processed,
12145
+ path: ctx.path,
12146
+ parent: ctx
12147
+ });
12148
+ if (result.status === "aborted")
12149
+ return INVALID;
12150
+ if (result.status === "dirty")
12151
+ return DIRTY(result.value);
12152
+ if (status.value === "dirty")
12153
+ return DIRTY(result.value);
12154
+ return result;
12155
+ }
12156
+ }
12157
+ if (effect.type === "refinement") {
12158
+ const executeRefinement = (acc) => {
12159
+ const result = effect.refinement(acc, checkCtx);
12160
+ if (ctx.common.async) {
12161
+ return Promise.resolve(result);
12162
+ }
12163
+ if (result instanceof Promise) {
12164
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
12165
+ }
12166
+ return acc;
12167
+ };
12168
+ if (ctx.common.async === false) {
12169
+ const inner = this._def.schema._parseSync({
12170
+ data: ctx.data,
12171
+ path: ctx.path,
12172
+ parent: ctx
12173
+ });
12174
+ if (inner.status === "aborted")
12175
+ return INVALID;
12176
+ if (inner.status === "dirty")
12177
+ status.dirty();
12178
+ executeRefinement(inner.value);
12179
+ return { status: status.value, value: inner.value };
12180
+ } else {
12181
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
12182
+ if (inner.status === "aborted")
12183
+ return INVALID;
12184
+ if (inner.status === "dirty")
12185
+ status.dirty();
12186
+ return executeRefinement(inner.value).then(() => {
12187
+ return { status: status.value, value: inner.value };
12188
+ });
12189
+ });
12190
+ }
12191
+ }
12192
+ if (effect.type === "transform") {
12193
+ if (ctx.common.async === false) {
12194
+ const base = this._def.schema._parseSync({
12195
+ data: ctx.data,
12196
+ path: ctx.path,
12197
+ parent: ctx
12198
+ });
12199
+ if (!isValid(base))
12200
+ return INVALID;
12201
+ const result = effect.transform(base.value, checkCtx);
12202
+ if (result instanceof Promise) {
12203
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
12204
+ }
12205
+ return { status: status.value, value: result };
12206
+ } else {
12207
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
12208
+ if (!isValid(base))
12209
+ return INVALID;
12210
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
12211
+ status: status.value,
12212
+ value: result
12213
+ }));
12214
+ });
12215
+ }
12216
+ }
12217
+ util.assertNever(effect);
12218
+ }
12219
+ };
12220
+ ZodEffects.create = (schema, effect, params) => {
12221
+ return new ZodEffects({
12222
+ schema,
12223
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
12224
+ effect,
12225
+ ...processCreateParams(params)
12226
+ });
12227
+ };
12228
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
12229
+ return new ZodEffects({
12230
+ schema,
12231
+ effect: { type: "preprocess", transform: preprocess },
12232
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
12233
+ ...processCreateParams(params)
12234
+ });
12235
+ };
12236
+ var ZodOptional = class extends ZodType {
12237
+ _parse(input) {
12238
+ const parsedType = this._getType(input);
12239
+ if (parsedType === ZodParsedType.undefined) {
12240
+ return OK(void 0);
12241
+ }
12242
+ return this._def.innerType._parse(input);
12243
+ }
12244
+ unwrap() {
12245
+ return this._def.innerType;
12246
+ }
12247
+ };
12248
+ ZodOptional.create = (type, params) => {
12249
+ return new ZodOptional({
12250
+ innerType: type,
12251
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
12252
+ ...processCreateParams(params)
12253
+ });
12254
+ };
12255
+ var ZodNullable = class extends ZodType {
12256
+ _parse(input) {
12257
+ const parsedType = this._getType(input);
12258
+ if (parsedType === ZodParsedType.null) {
12259
+ return OK(null);
12260
+ }
12261
+ return this._def.innerType._parse(input);
12262
+ }
12263
+ unwrap() {
12264
+ return this._def.innerType;
12265
+ }
12266
+ };
12267
+ ZodNullable.create = (type, params) => {
12268
+ return new ZodNullable({
12269
+ innerType: type,
12270
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
12271
+ ...processCreateParams(params)
12272
+ });
12273
+ };
12274
+ var ZodDefault = class extends ZodType {
12275
+ _parse(input) {
12276
+ const { ctx } = this._processInputParams(input);
12277
+ let data = ctx.data;
12278
+ if (ctx.parsedType === ZodParsedType.undefined) {
12279
+ data = this._def.defaultValue();
12280
+ }
12281
+ return this._def.innerType._parse({
12282
+ data,
12283
+ path: ctx.path,
12284
+ parent: ctx
12285
+ });
12286
+ }
12287
+ removeDefault() {
12288
+ return this._def.innerType;
12289
+ }
12290
+ };
12291
+ ZodDefault.create = (type, params) => {
12292
+ return new ZodDefault({
12293
+ innerType: type,
12294
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
12295
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
12296
+ ...processCreateParams(params)
12297
+ });
12298
+ };
12299
+ var ZodCatch = class extends ZodType {
12300
+ _parse(input) {
12301
+ const { ctx } = this._processInputParams(input);
12302
+ const newCtx = {
12303
+ ...ctx,
12304
+ common: {
12305
+ ...ctx.common,
12306
+ issues: []
12307
+ }
12308
+ };
12309
+ const result = this._def.innerType._parse({
12310
+ data: newCtx.data,
12311
+ path: newCtx.path,
12312
+ parent: {
12313
+ ...newCtx
12314
+ }
12315
+ });
12316
+ if (isAsync(result)) {
12317
+ return result.then((result2) => {
12318
+ return {
12319
+ status: "valid",
12320
+ value: result2.status === "valid" ? result2.value : this._def.catchValue({
12321
+ get error() {
12322
+ return new ZodError(newCtx.common.issues);
12323
+ },
12324
+ input: newCtx.data
12325
+ })
12326
+ };
12327
+ });
12328
+ } else {
12329
+ return {
12330
+ status: "valid",
12331
+ value: result.status === "valid" ? result.value : this._def.catchValue({
12332
+ get error() {
12333
+ return new ZodError(newCtx.common.issues);
12334
+ },
12335
+ input: newCtx.data
12336
+ })
12337
+ };
12338
+ }
12339
+ }
12340
+ removeCatch() {
12341
+ return this._def.innerType;
12342
+ }
12343
+ };
12344
+ ZodCatch.create = (type, params) => {
12345
+ return new ZodCatch({
12346
+ innerType: type,
12347
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
12348
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
12349
+ ...processCreateParams(params)
12350
+ });
12351
+ };
12352
+ var ZodNaN = class extends ZodType {
12353
+ _parse(input) {
12354
+ const parsedType = this._getType(input);
12355
+ if (parsedType !== ZodParsedType.nan) {
12356
+ const ctx = this._getOrReturnCtx(input);
12357
+ addIssueToContext(ctx, {
12358
+ code: ZodIssueCode.invalid_type,
12359
+ expected: ZodParsedType.nan,
12360
+ received: ctx.parsedType
12361
+ });
12362
+ return INVALID;
12363
+ }
12364
+ return { status: "valid", value: input.data };
12365
+ }
12366
+ };
12367
+ ZodNaN.create = (params) => {
12368
+ return new ZodNaN({
12369
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
12370
+ ...processCreateParams(params)
12371
+ });
12372
+ };
12373
+ var BRAND = Symbol("zod_brand");
12374
+ var ZodBranded = class extends ZodType {
12375
+ _parse(input) {
12376
+ const { ctx } = this._processInputParams(input);
12377
+ const data = ctx.data;
12378
+ return this._def.type._parse({
12379
+ data,
12380
+ path: ctx.path,
12381
+ parent: ctx
12382
+ });
12383
+ }
12384
+ unwrap() {
12385
+ return this._def.type;
12386
+ }
12387
+ };
12388
+ var ZodPipeline = class _ZodPipeline extends ZodType {
12389
+ _parse(input) {
12390
+ const { status, ctx } = this._processInputParams(input);
12391
+ if (ctx.common.async) {
12392
+ const handleAsync = async () => {
12393
+ const inResult = await this._def.in._parseAsync({
12394
+ data: ctx.data,
12395
+ path: ctx.path,
12396
+ parent: ctx
12397
+ });
12398
+ if (inResult.status === "aborted")
12399
+ return INVALID;
12400
+ if (inResult.status === "dirty") {
12401
+ status.dirty();
12402
+ return DIRTY(inResult.value);
12403
+ } else {
12404
+ return this._def.out._parseAsync({
12405
+ data: inResult.value,
12406
+ path: ctx.path,
12407
+ parent: ctx
12408
+ });
12409
+ }
12410
+ };
12411
+ return handleAsync();
12412
+ } else {
12413
+ const inResult = this._def.in._parseSync({
12414
+ data: ctx.data,
12415
+ path: ctx.path,
12416
+ parent: ctx
12417
+ });
12418
+ if (inResult.status === "aborted")
12419
+ return INVALID;
12420
+ if (inResult.status === "dirty") {
12421
+ status.dirty();
12422
+ return {
12423
+ status: "dirty",
12424
+ value: inResult.value
12425
+ };
12426
+ } else {
12427
+ return this._def.out._parseSync({
12428
+ data: inResult.value,
12429
+ path: ctx.path,
12430
+ parent: ctx
12431
+ });
12432
+ }
12433
+ }
12434
+ }
12435
+ static create(a, b) {
12436
+ return new _ZodPipeline({
12437
+ in: a,
12438
+ out: b,
12439
+ typeName: ZodFirstPartyTypeKind.ZodPipeline
12440
+ });
12441
+ }
12442
+ };
12443
+ var ZodReadonly = class extends ZodType {
12444
+ _parse(input) {
12445
+ const result = this._def.innerType._parse(input);
12446
+ const freeze = (data) => {
12447
+ if (isValid(data)) {
12448
+ data.value = Object.freeze(data.value);
12449
+ }
12450
+ return data;
12451
+ };
12452
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
12453
+ }
12454
+ unwrap() {
12455
+ return this._def.innerType;
12456
+ }
12457
+ };
12458
+ ZodReadonly.create = (type, params) => {
12459
+ return new ZodReadonly({
12460
+ innerType: type,
12461
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
12462
+ ...processCreateParams(params)
12463
+ });
12464
+ };
12465
+ function cleanParams(params, data) {
12466
+ const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
12467
+ const p2 = typeof p === "string" ? { message: p } : p;
12468
+ return p2;
12469
+ }
12470
+ function custom(check, _params = {}, fatal) {
12471
+ if (check)
12472
+ return ZodAny.create().superRefine((data, ctx) => {
12473
+ const r = check(data);
12474
+ if (r instanceof Promise) {
12475
+ return r.then((r2) => {
12476
+ if (!r2) {
12477
+ const params = cleanParams(_params, data);
12478
+ const _fatal = params.fatal ?? fatal ?? true;
12479
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
12480
+ }
12481
+ });
12482
+ }
12483
+ if (!r) {
12484
+ const params = cleanParams(_params, data);
12485
+ const _fatal = params.fatal ?? fatal ?? true;
12486
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
12487
+ }
12488
+ return;
12489
+ });
12490
+ return ZodAny.create();
12491
+ }
12492
+ var late = {
12493
+ object: ZodObject.lazycreate
12494
+ };
12495
+ var ZodFirstPartyTypeKind;
12496
+ (function(ZodFirstPartyTypeKind2) {
12497
+ ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
12498
+ ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
12499
+ ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
12500
+ ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
12501
+ ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
12502
+ ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
12503
+ ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
12504
+ ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
12505
+ ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
12506
+ ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
12507
+ ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
12508
+ ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
12509
+ ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
12510
+ ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
12511
+ ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
12512
+ ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
12513
+ ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
12514
+ ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
12515
+ ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
12516
+ ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
12517
+ ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
12518
+ ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
12519
+ ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
12520
+ ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
12521
+ ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
12522
+ ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
12523
+ ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
12524
+ ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
12525
+ ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
12526
+ ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
12527
+ ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
12528
+ ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
12529
+ ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
12530
+ ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
12531
+ ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
12532
+ ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
12533
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
12534
+ var instanceOfType = (cls, params = {
12535
+ message: `Input not instance of ${cls.name}`
12536
+ }) => custom((data) => data instanceof cls, params);
12537
+ var stringType = ZodString.create;
12538
+ var numberType = ZodNumber.create;
12539
+ var nanType = ZodNaN.create;
12540
+ var bigIntType = ZodBigInt.create;
12541
+ var booleanType = ZodBoolean.create;
12542
+ var dateType = ZodDate.create;
12543
+ var symbolType = ZodSymbol.create;
12544
+ var undefinedType = ZodUndefined.create;
12545
+ var nullType = ZodNull.create;
12546
+ var anyType = ZodAny.create;
12547
+ var unknownType = ZodUnknown.create;
12548
+ var neverType = ZodNever.create;
12549
+ var voidType = ZodVoid.create;
12550
+ var arrayType = ZodArray.create;
12551
+ var objectType = ZodObject.create;
12552
+ var strictObjectType = ZodObject.strictCreate;
12553
+ var unionType = ZodUnion.create;
12554
+ var discriminatedUnionType = ZodDiscriminatedUnion.create;
12555
+ var intersectionType = ZodIntersection.create;
12556
+ var tupleType = ZodTuple.create;
12557
+ var recordType = ZodRecord.create;
12558
+ var mapType = ZodMap.create;
12559
+ var setType = ZodSet.create;
12560
+ var functionType = ZodFunction.create;
12561
+ var lazyType = ZodLazy.create;
12562
+ var literalType = ZodLiteral.create;
12563
+ var enumType = ZodEnum.create;
12564
+ var nativeEnumType = ZodNativeEnum.create;
12565
+ var promiseType = ZodPromise.create;
12566
+ var effectsType = ZodEffects.create;
12567
+ var optionalType = ZodOptional.create;
12568
+ var nullableType = ZodNullable.create;
12569
+ var preprocessType = ZodEffects.createWithPreprocess;
12570
+ var pipelineType = ZodPipeline.create;
12571
+ var ostring = () => stringType().optional();
12572
+ var onumber = () => numberType().optional();
12573
+ var oboolean = () => booleanType().optional();
12574
+ var coerce = {
12575
+ string: (arg) => ZodString.create({ ...arg, coerce: true }),
12576
+ number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
12577
+ boolean: (arg) => ZodBoolean.create({
12578
+ ...arg,
12579
+ coerce: true
12580
+ }),
12581
+ bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
12582
+ date: (arg) => ZodDate.create({ ...arg, coerce: true })
12583
+ };
12584
+ var NEVER = INVALID;
12585
+
12586
+ // src/environment.ts
12587
+ var twitterEnvSchema = external_exports.object({
12588
+ TWITTER_DRY_RUN: external_exports.boolean(),
12589
+ TWITTER_USERNAME: external_exports.string().min(1, "X/Twitter username is required"),
12590
+ TWITTER_PASSWORD: external_exports.string().min(1, "X/Twitter password is required"),
12591
+ TWITTER_EMAIL: external_exports.string().email("Valid X/Twitter email is required"),
12592
+ TWITTER_2FA_SECRET: external_exports.string().default(void 0),
12593
+ TWITTER_RETRY_LIMIT: external_exports.number().int(),
12594
+ TWITTER_POLL_INTERVAL: external_exports.number().int(),
12595
+ TWITTER_TARGET_USERS: external_exports.string().default(""),
12596
+ TWITTER_ENABLE_POST_GENERATION: external_exports.boolean(),
12597
+ TWITTER_POST_INTERVAL_MIN: external_exports.number().int(),
12598
+ TWITTER_POST_INTERVAL_MAX: external_exports.number().int(),
12599
+ TWITTER_POST_IMMEDIATELY: external_exports.boolean(),
12600
+ TWITTER_SPACES_ENABLE: external_exports.boolean().default(false)
12601
+ });
12602
+ function parseTargetUsers(targetUsersStr) {
12603
+ if (!targetUsersStr?.trim()) {
12604
+ return [];
12605
+ }
12606
+ return targetUsersStr.split(",").map((user) => user.trim()).filter(Boolean);
12607
+ }
12608
+ function shouldTargetUser(username, targetUsersConfig) {
12609
+ if (!targetUsersConfig?.trim()) {
12610
+ return true;
12611
+ }
12612
+ const targetUsers = parseTargetUsers(targetUsersConfig);
12613
+ if (targetUsers.includes("*")) {
12614
+ return true;
12615
+ }
12616
+ const normalizedUsername = username.toLowerCase().replace(/^@/, "");
12617
+ return targetUsers.some(
12618
+ (target) => target.toLowerCase().replace(/^@/, "") === normalizedUsername
12619
+ );
12620
+ }
12621
+
12622
+ // src/interactions.ts
12623
+ var convertToCoreTweet = (tweet) => ({
12624
+ id: tweet.id,
12625
+ text: tweet.text,
12626
+ conversationId: tweet.conversationId,
12627
+ timestamp: tweet.timestamp,
12628
+ userId: tweet.userId,
12629
+ username: tweet.username,
12630
+ name: tweet.name,
12631
+ inReplyToStatusId: tweet.inReplyToStatusId,
12632
+ permanentUrl: tweet.permanentUrl,
12633
+ photos: tweet.photos,
12634
+ hashtags: tweet.hashtags,
12635
+ mentions: tweet.mentions.map((mention) => mention.username),
12636
+ urls: tweet.urls,
12637
+ videos: tweet.videos,
12638
+ thread: tweet.thread
12639
+ });
12640
+ var convertToCoreTweets = (tweets) => tweets.map(convertToCoreTweet);
12641
+ var TwitterInteractionClient = class {
12642
+ /**
12643
+ * Constructor for setting up a new instance with the provided client, runtime, and state.
12644
+ * @param {ClientBase} client - The client being used for communication.
12645
+ * @param {IAgentRuntime} runtime - The runtime environment for the agent.
12646
+ * @param {any} state - The initial state of the agent.
12647
+ */
12648
+ constructor(client, runtime, state) {
12649
+ this.client = client;
12650
+ this.runtime = runtime;
12651
+ this.state = state;
12652
+ this.isDryRun = this.state?.TWITTER_DRY_RUN || this.runtime.getSetting("TWITTER_DRY_RUN");
12653
+ }
12654
+ /**
12655
+ * Asynchronously starts the process of handling Twitter interactions on a loop.
12656
+ * Uses an interval based on the 'TWITTER_POLL_INTERVAL' setting, or defaults to 2 minutes if not set.
12657
+ */
12658
+ async start() {
12659
+ const handleTwitterInteractionsLoop = () => {
12660
+ const interactionInterval = (this.state?.TWITTER_POLL_INTERVAL || this.runtime.getSetting(
12661
+ "TWITTER_POLL_INTERVAL"
12662
+ ) || 120) * 1e3;
12663
+ this.handleTwitterInteractions();
12664
+ setTimeout(handleTwitterInteractionsLoop, interactionInterval);
12665
+ };
12666
+ handleTwitterInteractionsLoop();
12667
+ }
12668
+ /**
12669
+ * Asynchronously handles Twitter interactions by checking for mentions, processing tweets, and updating the last checked tweet ID.
12670
+ */
12671
+ async handleTwitterInteractions() {
12672
+ logger7.log("Checking Twitter interactions");
12673
+ const twitterUsername = this.client.profile?.username;
12674
+ try {
12675
+ const cursorKey = `twitter/${twitterUsername}/mention_cursor`;
12676
+ const cachedCursor = await this.runtime.getCache(cursorKey);
12677
+ const searchResult = await this.client.fetchSearchTweets(
12678
+ `@${twitterUsername}`,
12679
+ 20,
12680
+ 1 /* Latest */,
12681
+ String(cachedCursor)
12682
+ );
12683
+ const mentionCandidates = searchResult.tweets;
12684
+ if (mentionCandidates.length > 0 && searchResult.previous) {
12685
+ await this.runtime.setCache(cursorKey, searchResult.previous);
12686
+ } else if (!searchResult.previous && !searchResult.next) {
12687
+ await this.runtime.setCache(cursorKey, "");
12688
+ }
12689
+ await this.processMentionTweets(mentionCandidates);
12690
+ await this.client.cacheLatestCheckedTweetId();
12691
+ logger7.log("Finished checking Twitter interactions");
12692
+ } catch (error) {
12693
+ logger7.error("Error handling Twitter interactions:", error);
12694
+ }
12695
+ }
12696
+ /**
12697
+ * Processes all incoming tweets that mention the bot.
12698
+ * For each new tweet:
12699
+ * - Ensures world, room, and connection exist
12700
+ * - Saves the tweet as memory
12701
+ * - Emits thread-related events (THREAD_CREATED / THREAD_UPDATED)
12702
+ * - Delegates tweet content to `handleTweet` for reply generation
12703
+ *
12704
+ * Note: MENTION_RECEIVED is currently disabled (see TODO below)
12705
+ */
12706
+ async processMentionTweets(mentionCandidates) {
12707
+ logger7.log(
12708
+ "Completed checking mentioned tweets:",
12709
+ mentionCandidates.length
12710
+ );
12711
+ let uniqueTweetCandidates = [...mentionCandidates];
12712
+ uniqueTweetCandidates = uniqueTweetCandidates.sort((a, b) => a.id.localeCompare(b.id)).filter((tweet) => tweet.userId !== this.client.profile.id);
12713
+ const targetUsersConfig = this.runtime.getSetting("TWITTER_TARGET_USERS") || "";
12714
+ if (targetUsersConfig?.trim()) {
12715
+ uniqueTweetCandidates = uniqueTweetCandidates.filter((tweet) => {
12716
+ const shouldTarget = shouldTargetUser(
12717
+ tweet.username || "",
12718
+ targetUsersConfig
12719
+ );
12720
+ if (!shouldTarget) {
12721
+ logger7.log(
12722
+ `Skipping tweet from @${tweet.username} - not in target users list`
12723
+ );
12724
+ }
12725
+ return shouldTarget;
12726
+ });
12727
+ }
8632
12728
  for (const tweet of uniqueTweetCandidates) {
8633
12729
  if (!this.client.lastCheckedTweetId || BigInt(tweet.id) > this.client.lastCheckedTweetId) {
8634
12730
  const tweetId = createUniqueUuid5(this.runtime, tweet.id);