@budibase/backend-core 3.2.14 → 3.2.17

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
@@ -2891,7 +2891,7 @@ var require_object = __commonJS({
2891
2891
  this._nodes = [];
2892
2892
  this._excludedEdges = [];
2893
2893
  this.withMutation(() => {
2894
- this.transform(function coerce(value) {
2894
+ this.transform(function coerce2(value) {
2895
2895
  if (typeof value === "string") {
2896
2896
  try {
2897
2897
  value = JSON.parse(value);
@@ -3447,10 +3447,10 @@ var require_setLocale = __commonJS({
3447
3447
  function _interopRequireDefault(obj) {
3448
3448
  return obj && obj.__esModule ? obj : { default: obj };
3449
3449
  }
3450
- function setLocale(custom) {
3451
- Object.keys(custom).forEach((type) => {
3452
- Object.keys(custom[type]).forEach((method) => {
3453
- _locale.default[type][method] = custom[type][method];
3450
+ function setLocale(custom2) {
3451
+ Object.keys(custom2).forEach((type) => {
3452
+ Object.keys(custom2[type]).forEach((method) => {
3453
+ _locale.default[type][method] = custom2[type][method];
3454
3454
  });
3455
3455
  });
3456
3456
  }
@@ -4796,15 +4796,15 @@ var require_luxon = __commonJS({
4796
4796
  var PolyDateFormatter = class {
4797
4797
  constructor(dt, intl, opts) {
4798
4798
  this.opts = opts;
4799
- let z = void 0;
4799
+ let z2 = void 0;
4800
4800
  if (dt.zone.isUniversal) {
4801
4801
  const gmtOffset = -1 * (dt.offset / 60);
4802
4802
  const offsetZ = gmtOffset >= 0 ? `Etc/GMT+${gmtOffset}` : `Etc/GMT${gmtOffset}`;
4803
4803
  if (dt.offset !== 0 && IANAZone.create(offsetZ).valid) {
4804
- z = offsetZ;
4804
+ z2 = offsetZ;
4805
4805
  this.dt = dt;
4806
4806
  } else {
4807
- z = "UTC";
4807
+ z2 = "UTC";
4808
4808
  if (opts.timeZoneName) {
4809
4809
  this.dt = dt;
4810
4810
  } else {
@@ -4815,12 +4815,12 @@ var require_luxon = __commonJS({
4815
4815
  this.dt = dt;
4816
4816
  } else {
4817
4817
  this.dt = dt;
4818
- z = dt.zone.name;
4818
+ z2 = dt.zone.name;
4819
4819
  }
4820
4820
  const intlOpts = {
4821
4821
  ...this.opts
4822
4822
  };
4823
- intlOpts.timeZone = intlOpts.timeZone || z;
4823
+ intlOpts.timeZone = intlOpts.timeZone || z2;
4824
4824
  this.dtf = getCachedDTF(intl, intlOpts);
4825
4825
  }
4826
4826
  format() {
@@ -8286,7 +8286,7 @@ var require_luxon = __commonJS({
8286
8286
  } else
8287
8287
  return false;
8288
8288
  }
8289
- var INVALID = "Invalid DateTime";
8289
+ var INVALID2 = "Invalid DateTime";
8290
8290
  var MAX_DATE = 864e13;
8291
8291
  function unsupportedZone(zone) {
8292
8292
  return new Invalid("unsupported zone", `the zone "${zone.name}" is not supported`);
@@ -9548,7 +9548,7 @@ var require_luxon = __commonJS({
9548
9548
  * @return {string}
9549
9549
  */
9550
9550
  toFormat(fmt, opts = {}) {
9551
- return this.isValid ? Formatter.create(this.loc.redefaultToEN(opts)).formatDateTimeFromString(this, fmt) : INVALID;
9551
+ return this.isValid ? Formatter.create(this.loc.redefaultToEN(opts)).formatDateTimeFromString(this, fmt) : INVALID2;
9552
9552
  }
9553
9553
  /**
9554
9554
  * Returns a localized string representing this date. Accepts the same options as the Intl.DateTimeFormat constructor and any presets defined by Luxon, such as `DateTime.DATE_FULL` or `DateTime.TIME_SIMPLE`.
@@ -9570,7 +9570,7 @@ var require_luxon = __commonJS({
9570
9570
  * @return {string}
9571
9571
  */
9572
9572
  toLocaleString(formatOpts = DATE_SHORT, opts = {}) {
9573
- return this.isValid ? Formatter.create(this.loc.clone(opts), formatOpts).formatDateTime(this) : INVALID;
9573
+ return this.isValid ? Formatter.create(this.loc.clone(opts), formatOpts).formatDateTime(this) : INVALID2;
9574
9574
  }
9575
9575
  /**
9576
9576
  * Returns an array of format "parts", meaning individual tokens along with metadata. This is allows callers to post-process individual sections of the formatted output.
@@ -9755,7 +9755,7 @@ var require_luxon = __commonJS({
9755
9755
  * @return {string}
9756
9756
  */
9757
9757
  toString() {
9758
- return this.isValid ? this.toISO() : INVALID;
9758
+ return this.isValid ? this.toISO() : INVALID2;
9759
9759
  }
9760
9760
  /**
9761
9761
  * Returns the epoch milliseconds of this DateTime. Alias of {@link DateTime#toMillis}
@@ -10621,7 +10621,7 @@ var require_expression = __commonJS({
10621
10621
  }
10622
10622
  function parseSequence(val) {
10623
10623
  var stack = [];
10624
- function handleResult(result) {
10624
+ function handleResult2(result) {
10625
10625
  if (result instanceof Array) {
10626
10626
  for (var i2 = 0, c2 = result.length; i2 < c2; i2++) {
10627
10627
  var value2 = result[i2];
@@ -10661,10 +10661,10 @@ var require_expression = __commonJS({
10661
10661
  }
10662
10662
  if (atoms.length > 1) {
10663
10663
  for (var i = 0, c = atoms.length; i < c; i++) {
10664
- handleResult(parseRepeat(atoms[i]));
10664
+ handleResult2(parseRepeat(atoms[i]));
10665
10665
  }
10666
10666
  } else {
10667
- handleResult(parseRepeat(val));
10667
+ handleResult2(parseRepeat(val));
10668
10668
  }
10669
10669
  stack.sort(CronExpression._sortCompareFn);
10670
10670
  return stack;
@@ -11572,6 +11572,11 @@ function isArraySearchOperator(value) {
11572
11572
  function isRangeSearchOperator(value) {
11573
11573
  return Object.values(RangeOperator).includes(value);
11574
11574
  }
11575
+ var EmptyFilterOption = /* @__PURE__ */ ((EmptyFilterOption2) => {
11576
+ EmptyFilterOption2["RETURN_ALL"] = "all";
11577
+ EmptyFilterOption2["RETURN_NONE"] = "none";
11578
+ return EmptyFilterOption2;
11579
+ })(EmptyFilterOption || {});
11575
11580
 
11576
11581
  // ../types/src/sdk/db.ts
11577
11582
  var isDocument = (doc) => {
@@ -11796,6 +11801,3990 @@ var BREAKDOWN_QUOTA_NAMES = [
11796
11801
  "automations" /* AUTOMATIONS */
11797
11802
  ];
11798
11803
 
11804
+ // ../types/src/api/web/pagination.ts
11805
+ var SortOrder = /* @__PURE__ */ ((SortOrder2) => {
11806
+ SortOrder2["ASCENDING"] = "ascending";
11807
+ SortOrder2["DESCENDING"] = "descending";
11808
+ return SortOrder2;
11809
+ })(SortOrder || {});
11810
+ var SortType = /* @__PURE__ */ ((SortType2) => {
11811
+ SortType2["STRING"] = "string";
11812
+ SortType2["NUMBER"] = "number";
11813
+ return SortType2;
11814
+ })(SortType || {});
11815
+
11816
+ // ../../node_modules/zod/lib/index.mjs
11817
+ var util;
11818
+ (function(util2) {
11819
+ util2.assertEqual = (val) => val;
11820
+ function assertIs(_arg) {
11821
+ }
11822
+ util2.assertIs = assertIs;
11823
+ function assertNever(_x) {
11824
+ throw new Error();
11825
+ }
11826
+ util2.assertNever = assertNever;
11827
+ util2.arrayToEnum = (items) => {
11828
+ const obj = {};
11829
+ for (const item of items) {
11830
+ obj[item] = item;
11831
+ }
11832
+ return obj;
11833
+ };
11834
+ util2.getValidEnumValues = (obj) => {
11835
+ const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
11836
+ const filtered2 = {};
11837
+ for (const k of validKeys) {
11838
+ filtered2[k] = obj[k];
11839
+ }
11840
+ return util2.objectValues(filtered2);
11841
+ };
11842
+ util2.objectValues = (obj) => {
11843
+ return util2.objectKeys(obj).map(function(e) {
11844
+ return obj[e];
11845
+ });
11846
+ };
11847
+ util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
11848
+ const keys2 = [];
11849
+ for (const key in object) {
11850
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
11851
+ keys2.push(key);
11852
+ }
11853
+ }
11854
+ return keys2;
11855
+ };
11856
+ util2.find = (arr, checker) => {
11857
+ for (const item of arr) {
11858
+ if (checker(item))
11859
+ return item;
11860
+ }
11861
+ return void 0;
11862
+ };
11863
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
11864
+ function joinValues(array, separator = " | ") {
11865
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
11866
+ }
11867
+ util2.joinValues = joinValues;
11868
+ util2.jsonStringifyReplacer = (_3, value) => {
11869
+ if (typeof value === "bigint") {
11870
+ return value.toString();
11871
+ }
11872
+ return value;
11873
+ };
11874
+ })(util || (util = {}));
11875
+ var objectUtil;
11876
+ (function(objectUtil2) {
11877
+ objectUtil2.mergeShapes = (first, second) => {
11878
+ return {
11879
+ ...first,
11880
+ ...second
11881
+ // second overwrites first
11882
+ };
11883
+ };
11884
+ })(objectUtil || (objectUtil = {}));
11885
+ var ZodParsedType = util.arrayToEnum([
11886
+ "string",
11887
+ "nan",
11888
+ "number",
11889
+ "integer",
11890
+ "float",
11891
+ "boolean",
11892
+ "date",
11893
+ "bigint",
11894
+ "symbol",
11895
+ "function",
11896
+ "undefined",
11897
+ "null",
11898
+ "array",
11899
+ "object",
11900
+ "unknown",
11901
+ "promise",
11902
+ "void",
11903
+ "never",
11904
+ "map",
11905
+ "set"
11906
+ ]);
11907
+ var getParsedType = (data) => {
11908
+ const t = typeof data;
11909
+ switch (t) {
11910
+ case "undefined":
11911
+ return ZodParsedType.undefined;
11912
+ case "string":
11913
+ return ZodParsedType.string;
11914
+ case "number":
11915
+ return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
11916
+ case "boolean":
11917
+ return ZodParsedType.boolean;
11918
+ case "function":
11919
+ return ZodParsedType.function;
11920
+ case "bigint":
11921
+ return ZodParsedType.bigint;
11922
+ case "symbol":
11923
+ return ZodParsedType.symbol;
11924
+ case "object":
11925
+ if (Array.isArray(data)) {
11926
+ return ZodParsedType.array;
11927
+ }
11928
+ if (data === null) {
11929
+ return ZodParsedType.null;
11930
+ }
11931
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
11932
+ return ZodParsedType.promise;
11933
+ }
11934
+ if (typeof Map !== "undefined" && data instanceof Map) {
11935
+ return ZodParsedType.map;
11936
+ }
11937
+ if (typeof Set !== "undefined" && data instanceof Set) {
11938
+ return ZodParsedType.set;
11939
+ }
11940
+ if (typeof Date !== "undefined" && data instanceof Date) {
11941
+ return ZodParsedType.date;
11942
+ }
11943
+ return ZodParsedType.object;
11944
+ default:
11945
+ return ZodParsedType.unknown;
11946
+ }
11947
+ };
11948
+ var ZodIssueCode = util.arrayToEnum([
11949
+ "invalid_type",
11950
+ "invalid_literal",
11951
+ "custom",
11952
+ "invalid_union",
11953
+ "invalid_union_discriminator",
11954
+ "invalid_enum_value",
11955
+ "unrecognized_keys",
11956
+ "invalid_arguments",
11957
+ "invalid_return_type",
11958
+ "invalid_date",
11959
+ "invalid_string",
11960
+ "too_small",
11961
+ "too_big",
11962
+ "invalid_intersection_types",
11963
+ "not_multiple_of",
11964
+ "not_finite"
11965
+ ]);
11966
+ var quotelessJson = (obj) => {
11967
+ const json = JSON.stringify(obj, null, 2);
11968
+ return json.replace(/"([^"]+)":/g, "$1:");
11969
+ };
11970
+ var ZodError = class _ZodError extends Error {
11971
+ constructor(issues) {
11972
+ super();
11973
+ this.issues = [];
11974
+ this.addIssue = (sub) => {
11975
+ this.issues = [...this.issues, sub];
11976
+ };
11977
+ this.addIssues = (subs = []) => {
11978
+ this.issues = [...this.issues, ...subs];
11979
+ };
11980
+ const actualProto = new.target.prototype;
11981
+ if (Object.setPrototypeOf) {
11982
+ Object.setPrototypeOf(this, actualProto);
11983
+ } else {
11984
+ this.__proto__ = actualProto;
11985
+ }
11986
+ this.name = "ZodError";
11987
+ this.issues = issues;
11988
+ }
11989
+ get errors() {
11990
+ return this.issues;
11991
+ }
11992
+ format(_mapper) {
11993
+ const mapper = _mapper || function(issue) {
11994
+ return issue.message;
11995
+ };
11996
+ const fieldErrors = { _errors: [] };
11997
+ const processError = (error) => {
11998
+ for (const issue of error.issues) {
11999
+ if (issue.code === "invalid_union") {
12000
+ issue.unionErrors.map(processError);
12001
+ } else if (issue.code === "invalid_return_type") {
12002
+ processError(issue.returnTypeError);
12003
+ } else if (issue.code === "invalid_arguments") {
12004
+ processError(issue.argumentsError);
12005
+ } else if (issue.path.length === 0) {
12006
+ fieldErrors._errors.push(mapper(issue));
12007
+ } else {
12008
+ let curr = fieldErrors;
12009
+ let i = 0;
12010
+ while (i < issue.path.length) {
12011
+ const el = issue.path[i];
12012
+ const terminal = i === issue.path.length - 1;
12013
+ if (!terminal) {
12014
+ curr[el] = curr[el] || { _errors: [] };
12015
+ } else {
12016
+ curr[el] = curr[el] || { _errors: [] };
12017
+ curr[el]._errors.push(mapper(issue));
12018
+ }
12019
+ curr = curr[el];
12020
+ i++;
12021
+ }
12022
+ }
12023
+ }
12024
+ };
12025
+ processError(this);
12026
+ return fieldErrors;
12027
+ }
12028
+ static assert(value) {
12029
+ if (!(value instanceof _ZodError)) {
12030
+ throw new Error(`Not a ZodError: ${value}`);
12031
+ }
12032
+ }
12033
+ toString() {
12034
+ return this.message;
12035
+ }
12036
+ get message() {
12037
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
12038
+ }
12039
+ get isEmpty() {
12040
+ return this.issues.length === 0;
12041
+ }
12042
+ flatten(mapper = (issue) => issue.message) {
12043
+ const fieldErrors = {};
12044
+ const formErrors = [];
12045
+ for (const sub of this.issues) {
12046
+ if (sub.path.length > 0) {
12047
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
12048
+ fieldErrors[sub.path[0]].push(mapper(sub));
12049
+ } else {
12050
+ formErrors.push(mapper(sub));
12051
+ }
12052
+ }
12053
+ return { formErrors, fieldErrors };
12054
+ }
12055
+ get formErrors() {
12056
+ return this.flatten();
12057
+ }
12058
+ };
12059
+ ZodError.create = (issues) => {
12060
+ const error = new ZodError(issues);
12061
+ return error;
12062
+ };
12063
+ var errorMap = (issue, _ctx) => {
12064
+ let message;
12065
+ switch (issue.code) {
12066
+ case ZodIssueCode.invalid_type:
12067
+ if (issue.received === ZodParsedType.undefined) {
12068
+ message = "Required";
12069
+ } else {
12070
+ message = `Expected ${issue.expected}, received ${issue.received}`;
12071
+ }
12072
+ break;
12073
+ case ZodIssueCode.invalid_literal:
12074
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
12075
+ break;
12076
+ case ZodIssueCode.unrecognized_keys:
12077
+ message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
12078
+ break;
12079
+ case ZodIssueCode.invalid_union:
12080
+ message = `Invalid input`;
12081
+ break;
12082
+ case ZodIssueCode.invalid_union_discriminator:
12083
+ message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
12084
+ break;
12085
+ case ZodIssueCode.invalid_enum_value:
12086
+ message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
12087
+ break;
12088
+ case ZodIssueCode.invalid_arguments:
12089
+ message = `Invalid function arguments`;
12090
+ break;
12091
+ case ZodIssueCode.invalid_return_type:
12092
+ message = `Invalid function return type`;
12093
+ break;
12094
+ case ZodIssueCode.invalid_date:
12095
+ message = `Invalid date`;
12096
+ break;
12097
+ case ZodIssueCode.invalid_string:
12098
+ if (typeof issue.validation === "object") {
12099
+ if ("includes" in issue.validation) {
12100
+ message = `Invalid input: must include "${issue.validation.includes}"`;
12101
+ if (typeof issue.validation.position === "number") {
12102
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
12103
+ }
12104
+ } else if ("startsWith" in issue.validation) {
12105
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
12106
+ } else if ("endsWith" in issue.validation) {
12107
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
12108
+ } else {
12109
+ util.assertNever(issue.validation);
12110
+ }
12111
+ } else if (issue.validation !== "regex") {
12112
+ message = `Invalid ${issue.validation}`;
12113
+ } else {
12114
+ message = "Invalid";
12115
+ }
12116
+ break;
12117
+ case ZodIssueCode.too_small:
12118
+ if (issue.type === "array")
12119
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
12120
+ else if (issue.type === "string")
12121
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
12122
+ else if (issue.type === "number")
12123
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
12124
+ else if (issue.type === "date")
12125
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
12126
+ else
12127
+ message = "Invalid input";
12128
+ break;
12129
+ case ZodIssueCode.too_big:
12130
+ if (issue.type === "array")
12131
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
12132
+ else if (issue.type === "string")
12133
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
12134
+ else if (issue.type === "number")
12135
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
12136
+ else if (issue.type === "bigint")
12137
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
12138
+ else if (issue.type === "date")
12139
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
12140
+ else
12141
+ message = "Invalid input";
12142
+ break;
12143
+ case ZodIssueCode.custom:
12144
+ message = `Invalid input`;
12145
+ break;
12146
+ case ZodIssueCode.invalid_intersection_types:
12147
+ message = `Intersection results could not be merged`;
12148
+ break;
12149
+ case ZodIssueCode.not_multiple_of:
12150
+ message = `Number must be a multiple of ${issue.multipleOf}`;
12151
+ break;
12152
+ case ZodIssueCode.not_finite:
12153
+ message = "Number must be finite";
12154
+ break;
12155
+ default:
12156
+ message = _ctx.defaultError;
12157
+ util.assertNever(issue);
12158
+ }
12159
+ return { message };
12160
+ };
12161
+ var overrideErrorMap = errorMap;
12162
+ function setErrorMap(map) {
12163
+ overrideErrorMap = map;
12164
+ }
12165
+ function getErrorMap() {
12166
+ return overrideErrorMap;
12167
+ }
12168
+ var makeIssue = (params2) => {
12169
+ const { data, path: path3, errorMaps, issueData } = params2;
12170
+ const fullPath = [...path3, ...issueData.path || []];
12171
+ const fullIssue = {
12172
+ ...issueData,
12173
+ path: fullPath
12174
+ };
12175
+ if (issueData.message !== void 0) {
12176
+ return {
12177
+ ...issueData,
12178
+ path: fullPath,
12179
+ message: issueData.message
12180
+ };
12181
+ }
12182
+ let errorMessage = "";
12183
+ const maps = errorMaps.filter((m) => !!m).slice().reverse();
12184
+ for (const map of maps) {
12185
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
12186
+ }
12187
+ return {
12188
+ ...issueData,
12189
+ path: fullPath,
12190
+ message: errorMessage
12191
+ };
12192
+ };
12193
+ var EMPTY_PATH = [];
12194
+ function addIssueToContext(ctx, issueData) {
12195
+ const overrideMap = getErrorMap();
12196
+ const issue = makeIssue({
12197
+ issueData,
12198
+ data: ctx.data,
12199
+ path: ctx.path,
12200
+ errorMaps: [
12201
+ ctx.common.contextualErrorMap,
12202
+ ctx.schemaErrorMap,
12203
+ overrideMap,
12204
+ overrideMap === errorMap ? void 0 : errorMap
12205
+ // then global default map
12206
+ ].filter((x) => !!x)
12207
+ });
12208
+ ctx.common.issues.push(issue);
12209
+ }
12210
+ var ParseStatus = class _ParseStatus {
12211
+ constructor() {
12212
+ this.value = "valid";
12213
+ }
12214
+ dirty() {
12215
+ if (this.value === "valid")
12216
+ this.value = "dirty";
12217
+ }
12218
+ abort() {
12219
+ if (this.value !== "aborted")
12220
+ this.value = "aborted";
12221
+ }
12222
+ static mergeArray(status, results) {
12223
+ const arrayValue = [];
12224
+ for (const s of results) {
12225
+ if (s.status === "aborted")
12226
+ return INVALID;
12227
+ if (s.status === "dirty")
12228
+ status.dirty();
12229
+ arrayValue.push(s.value);
12230
+ }
12231
+ return { status: status.value, value: arrayValue };
12232
+ }
12233
+ static async mergeObjectAsync(status, pairs) {
12234
+ const syncPairs = [];
12235
+ for (const pair of pairs) {
12236
+ const key = await pair.key;
12237
+ const value = await pair.value;
12238
+ syncPairs.push({
12239
+ key,
12240
+ value
12241
+ });
12242
+ }
12243
+ return _ParseStatus.mergeObjectSync(status, syncPairs);
12244
+ }
12245
+ static mergeObjectSync(status, pairs) {
12246
+ const finalObject = {};
12247
+ for (const pair of pairs) {
12248
+ const { key, value } = pair;
12249
+ if (key.status === "aborted")
12250
+ return INVALID;
12251
+ if (value.status === "aborted")
12252
+ return INVALID;
12253
+ if (key.status === "dirty")
12254
+ status.dirty();
12255
+ if (value.status === "dirty")
12256
+ status.dirty();
12257
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
12258
+ finalObject[key.value] = value.value;
12259
+ }
12260
+ }
12261
+ return { status: status.value, value: finalObject };
12262
+ }
12263
+ };
12264
+ var INVALID = Object.freeze({
12265
+ status: "aborted"
12266
+ });
12267
+ var DIRTY = (value) => ({ status: "dirty", value });
12268
+ var OK = (value) => ({ status: "valid", value });
12269
+ var isAborted = (x) => x.status === "aborted";
12270
+ var isDirty = (x) => x.status === "dirty";
12271
+ var isValid = (x) => x.status === "valid";
12272
+ var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
12273
+ function __classPrivateFieldGet(receiver, state, kind, f) {
12274
+ if (kind === "a" && !f)
12275
+ throw new TypeError("Private accessor was defined without a getter");
12276
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
12277
+ throw new TypeError("Cannot read private member from an object whose class did not declare it");
12278
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12279
+ }
12280
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
12281
+ if (kind === "m")
12282
+ throw new TypeError("Private method is not writable");
12283
+ if (kind === "a" && !f)
12284
+ throw new TypeError("Private accessor was defined without a setter");
12285
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
12286
+ throw new TypeError("Cannot write private member to an object whose class did not declare it");
12287
+ return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
12288
+ }
12289
+ var errorUtil;
12290
+ (function(errorUtil2) {
12291
+ errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
12292
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
12293
+ })(errorUtil || (errorUtil = {}));
12294
+ var _ZodEnum_cache;
12295
+ var _ZodNativeEnum_cache;
12296
+ var ParseInputLazyPath = class {
12297
+ constructor(parent, value, path3, key) {
12298
+ this._cachedPath = [];
12299
+ this.parent = parent;
12300
+ this.data = value;
12301
+ this._path = path3;
12302
+ this._key = key;
12303
+ }
12304
+ get path() {
12305
+ if (!this._cachedPath.length) {
12306
+ if (this._key instanceof Array) {
12307
+ this._cachedPath.push(...this._path, ...this._key);
12308
+ } else {
12309
+ this._cachedPath.push(...this._path, this._key);
12310
+ }
12311
+ }
12312
+ return this._cachedPath;
12313
+ }
12314
+ };
12315
+ var handleResult = (ctx, result) => {
12316
+ if (isValid(result)) {
12317
+ return { success: true, data: result.value };
12318
+ } else {
12319
+ if (!ctx.common.issues.length) {
12320
+ throw new Error("Validation failed but no issues detected.");
12321
+ }
12322
+ return {
12323
+ success: false,
12324
+ get error() {
12325
+ if (this._error)
12326
+ return this._error;
12327
+ const error = new ZodError(ctx.common.issues);
12328
+ this._error = error;
12329
+ return this._error;
12330
+ }
12331
+ };
12332
+ }
12333
+ };
12334
+ function processCreateParams(params2) {
12335
+ if (!params2)
12336
+ return {};
12337
+ const { errorMap: errorMap2, invalid_type_error, required_error, description } = params2;
12338
+ if (errorMap2 && (invalid_type_error || required_error)) {
12339
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
12340
+ }
12341
+ if (errorMap2)
12342
+ return { errorMap: errorMap2, description };
12343
+ const customMap = (iss, ctx) => {
12344
+ var _a, _b;
12345
+ const { message } = params2;
12346
+ if (iss.code === "invalid_enum_value") {
12347
+ return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
12348
+ }
12349
+ if (typeof ctx.data === "undefined") {
12350
+ return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
12351
+ }
12352
+ if (iss.code !== "invalid_type")
12353
+ return { message: ctx.defaultError };
12354
+ return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
12355
+ };
12356
+ return { errorMap: customMap, description };
12357
+ }
12358
+ var ZodType = class {
12359
+ constructor(def) {
12360
+ this.spa = this.safeParseAsync;
12361
+ this._def = def;
12362
+ this.parse = this.parse.bind(this);
12363
+ this.safeParse = this.safeParse.bind(this);
12364
+ this.parseAsync = this.parseAsync.bind(this);
12365
+ this.safeParseAsync = this.safeParseAsync.bind(this);
12366
+ this.spa = this.spa.bind(this);
12367
+ this.refine = this.refine.bind(this);
12368
+ this.refinement = this.refinement.bind(this);
12369
+ this.superRefine = this.superRefine.bind(this);
12370
+ this.optional = this.optional.bind(this);
12371
+ this.nullable = this.nullable.bind(this);
12372
+ this.nullish = this.nullish.bind(this);
12373
+ this.array = this.array.bind(this);
12374
+ this.promise = this.promise.bind(this);
12375
+ this.or = this.or.bind(this);
12376
+ this.and = this.and.bind(this);
12377
+ this.transform = this.transform.bind(this);
12378
+ this.brand = this.brand.bind(this);
12379
+ this.default = this.default.bind(this);
12380
+ this.catch = this.catch.bind(this);
12381
+ this.describe = this.describe.bind(this);
12382
+ this.pipe = this.pipe.bind(this);
12383
+ this.readonly = this.readonly.bind(this);
12384
+ this.isNullable = this.isNullable.bind(this);
12385
+ this.isOptional = this.isOptional.bind(this);
12386
+ }
12387
+ get description() {
12388
+ return this._def.description;
12389
+ }
12390
+ _getType(input) {
12391
+ return getParsedType(input.data);
12392
+ }
12393
+ _getOrReturnCtx(input, ctx) {
12394
+ return ctx || {
12395
+ common: input.parent.common,
12396
+ data: input.data,
12397
+ parsedType: getParsedType(input.data),
12398
+ schemaErrorMap: this._def.errorMap,
12399
+ path: input.path,
12400
+ parent: input.parent
12401
+ };
12402
+ }
12403
+ _processInputParams(input) {
12404
+ return {
12405
+ status: new ParseStatus(),
12406
+ ctx: {
12407
+ common: input.parent.common,
12408
+ data: input.data,
12409
+ parsedType: getParsedType(input.data),
12410
+ schemaErrorMap: this._def.errorMap,
12411
+ path: input.path,
12412
+ parent: input.parent
12413
+ }
12414
+ };
12415
+ }
12416
+ _parseSync(input) {
12417
+ const result = this._parse(input);
12418
+ if (isAsync(result)) {
12419
+ throw new Error("Synchronous parse encountered promise.");
12420
+ }
12421
+ return result;
12422
+ }
12423
+ _parseAsync(input) {
12424
+ const result = this._parse(input);
12425
+ return Promise.resolve(result);
12426
+ }
12427
+ parse(data, params2) {
12428
+ const result = this.safeParse(data, params2);
12429
+ if (result.success)
12430
+ return result.data;
12431
+ throw result.error;
12432
+ }
12433
+ safeParse(data, params2) {
12434
+ var _a;
12435
+ const ctx = {
12436
+ common: {
12437
+ issues: [],
12438
+ async: (_a = params2 === null || params2 === void 0 ? void 0 : params2.async) !== null && _a !== void 0 ? _a : false,
12439
+ contextualErrorMap: params2 === null || params2 === void 0 ? void 0 : params2.errorMap
12440
+ },
12441
+ path: (params2 === null || params2 === void 0 ? void 0 : params2.path) || [],
12442
+ schemaErrorMap: this._def.errorMap,
12443
+ parent: null,
12444
+ data,
12445
+ parsedType: getParsedType(data)
12446
+ };
12447
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
12448
+ return handleResult(ctx, result);
12449
+ }
12450
+ async parseAsync(data, params2) {
12451
+ const result = await this.safeParseAsync(data, params2);
12452
+ if (result.success)
12453
+ return result.data;
12454
+ throw result.error;
12455
+ }
12456
+ async safeParseAsync(data, params2) {
12457
+ const ctx = {
12458
+ common: {
12459
+ issues: [],
12460
+ contextualErrorMap: params2 === null || params2 === void 0 ? void 0 : params2.errorMap,
12461
+ async: true
12462
+ },
12463
+ path: (params2 === null || params2 === void 0 ? void 0 : params2.path) || [],
12464
+ schemaErrorMap: this._def.errorMap,
12465
+ parent: null,
12466
+ data,
12467
+ parsedType: getParsedType(data)
12468
+ };
12469
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
12470
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
12471
+ return handleResult(ctx, result);
12472
+ }
12473
+ refine(check, message) {
12474
+ const getIssueProperties = (val) => {
12475
+ if (typeof message === "string" || typeof message === "undefined") {
12476
+ return { message };
12477
+ } else if (typeof message === "function") {
12478
+ return message(val);
12479
+ } else {
12480
+ return message;
12481
+ }
12482
+ };
12483
+ return this._refinement((val, ctx) => {
12484
+ const result = check(val);
12485
+ const setError = () => ctx.addIssue({
12486
+ code: ZodIssueCode.custom,
12487
+ ...getIssueProperties(val)
12488
+ });
12489
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
12490
+ return result.then((data) => {
12491
+ if (!data) {
12492
+ setError();
12493
+ return false;
12494
+ } else {
12495
+ return true;
12496
+ }
12497
+ });
12498
+ }
12499
+ if (!result) {
12500
+ setError();
12501
+ return false;
12502
+ } else {
12503
+ return true;
12504
+ }
12505
+ });
12506
+ }
12507
+ refinement(check, refinementData) {
12508
+ return this._refinement((val, ctx) => {
12509
+ if (!check(val)) {
12510
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
12511
+ return false;
12512
+ } else {
12513
+ return true;
12514
+ }
12515
+ });
12516
+ }
12517
+ _refinement(refinement) {
12518
+ return new ZodEffects({
12519
+ schema: this,
12520
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
12521
+ effect: { type: "refinement", refinement }
12522
+ });
12523
+ }
12524
+ superRefine(refinement) {
12525
+ return this._refinement(refinement);
12526
+ }
12527
+ optional() {
12528
+ return ZodOptional.create(this, this._def);
12529
+ }
12530
+ nullable() {
12531
+ return ZodNullable.create(this, this._def);
12532
+ }
12533
+ nullish() {
12534
+ return this.nullable().optional();
12535
+ }
12536
+ array() {
12537
+ return ZodArray.create(this, this._def);
12538
+ }
12539
+ promise() {
12540
+ return ZodPromise.create(this, this._def);
12541
+ }
12542
+ or(option) {
12543
+ return ZodUnion.create([this, option], this._def);
12544
+ }
12545
+ and(incoming) {
12546
+ return ZodIntersection.create(this, incoming, this._def);
12547
+ }
12548
+ transform(transform) {
12549
+ return new ZodEffects({
12550
+ ...processCreateParams(this._def),
12551
+ schema: this,
12552
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
12553
+ effect: { type: "transform", transform }
12554
+ });
12555
+ }
12556
+ default(def) {
12557
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
12558
+ return new ZodDefault({
12559
+ ...processCreateParams(this._def),
12560
+ innerType: this,
12561
+ defaultValue: defaultValueFunc,
12562
+ typeName: ZodFirstPartyTypeKind.ZodDefault
12563
+ });
12564
+ }
12565
+ brand() {
12566
+ return new ZodBranded({
12567
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
12568
+ type: this,
12569
+ ...processCreateParams(this._def)
12570
+ });
12571
+ }
12572
+ catch(def) {
12573
+ const catchValueFunc = typeof def === "function" ? def : () => def;
12574
+ return new ZodCatch({
12575
+ ...processCreateParams(this._def),
12576
+ innerType: this,
12577
+ catchValue: catchValueFunc,
12578
+ typeName: ZodFirstPartyTypeKind.ZodCatch
12579
+ });
12580
+ }
12581
+ describe(description) {
12582
+ const This = this.constructor;
12583
+ return new This({
12584
+ ...this._def,
12585
+ description
12586
+ });
12587
+ }
12588
+ pipe(target) {
12589
+ return ZodPipeline.create(this, target);
12590
+ }
12591
+ readonly() {
12592
+ return ZodReadonly.create(this);
12593
+ }
12594
+ isOptional() {
12595
+ return this.safeParse(void 0).success;
12596
+ }
12597
+ isNullable() {
12598
+ return this.safeParse(null).success;
12599
+ }
12600
+ };
12601
+ var cuidRegex = /^c[^\s-]{8,}$/i;
12602
+ var cuid2Regex = /^[0-9a-z]+$/;
12603
+ var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
12604
+ 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;
12605
+ var nanoidRegex = /^[a-z0-9_-]{21}$/i;
12606
+ 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)?)??$/;
12607
+ var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
12608
+ var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
12609
+ var emojiRegex;
12610
+ 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])$/;
12611
+ var ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
12612
+ var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
12613
+ 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])))`;
12614
+ var dateRegex = new RegExp(`^${dateRegexSource}$`);
12615
+ function timeRegexSource(args) {
12616
+ let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
12617
+ if (args.precision) {
12618
+ regex = `${regex}\\.\\d{${args.precision}}`;
12619
+ } else if (args.precision == null) {
12620
+ regex = `${regex}(\\.\\d+)?`;
12621
+ }
12622
+ return regex;
12623
+ }
12624
+ function timeRegex(args) {
12625
+ return new RegExp(`^${timeRegexSource(args)}$`);
12626
+ }
12627
+ function datetimeRegex(args) {
12628
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
12629
+ const opts = [];
12630
+ opts.push(args.local ? `Z?` : `Z`);
12631
+ if (args.offset)
12632
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
12633
+ regex = `${regex}(${opts.join("|")})`;
12634
+ return new RegExp(`^${regex}$`);
12635
+ }
12636
+ function isValidIP(ip, version) {
12637
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
12638
+ return true;
12639
+ }
12640
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
12641
+ return true;
12642
+ }
12643
+ return false;
12644
+ }
12645
+ var ZodString = class _ZodString extends ZodType {
12646
+ _parse(input) {
12647
+ if (this._def.coerce) {
12648
+ input.data = String(input.data);
12649
+ }
12650
+ const parsedType = this._getType(input);
12651
+ if (parsedType !== ZodParsedType.string) {
12652
+ const ctx2 = this._getOrReturnCtx(input);
12653
+ addIssueToContext(ctx2, {
12654
+ code: ZodIssueCode.invalid_type,
12655
+ expected: ZodParsedType.string,
12656
+ received: ctx2.parsedType
12657
+ });
12658
+ return INVALID;
12659
+ }
12660
+ const status = new ParseStatus();
12661
+ let ctx = void 0;
12662
+ for (const check of this._def.checks) {
12663
+ if (check.kind === "min") {
12664
+ if (input.data.length < check.value) {
12665
+ ctx = this._getOrReturnCtx(input, ctx);
12666
+ addIssueToContext(ctx, {
12667
+ code: ZodIssueCode.too_small,
12668
+ minimum: check.value,
12669
+ type: "string",
12670
+ inclusive: true,
12671
+ exact: false,
12672
+ message: check.message
12673
+ });
12674
+ status.dirty();
12675
+ }
12676
+ } else if (check.kind === "max") {
12677
+ if (input.data.length > check.value) {
12678
+ ctx = this._getOrReturnCtx(input, ctx);
12679
+ addIssueToContext(ctx, {
12680
+ code: ZodIssueCode.too_big,
12681
+ maximum: check.value,
12682
+ type: "string",
12683
+ inclusive: true,
12684
+ exact: false,
12685
+ message: check.message
12686
+ });
12687
+ status.dirty();
12688
+ }
12689
+ } else if (check.kind === "length") {
12690
+ const tooBig = input.data.length > check.value;
12691
+ const tooSmall = input.data.length < check.value;
12692
+ if (tooBig || tooSmall) {
12693
+ ctx = this._getOrReturnCtx(input, ctx);
12694
+ if (tooBig) {
12695
+ addIssueToContext(ctx, {
12696
+ code: ZodIssueCode.too_big,
12697
+ maximum: check.value,
12698
+ type: "string",
12699
+ inclusive: true,
12700
+ exact: true,
12701
+ message: check.message
12702
+ });
12703
+ } else if (tooSmall) {
12704
+ addIssueToContext(ctx, {
12705
+ code: ZodIssueCode.too_small,
12706
+ minimum: check.value,
12707
+ type: "string",
12708
+ inclusive: true,
12709
+ exact: true,
12710
+ message: check.message
12711
+ });
12712
+ }
12713
+ status.dirty();
12714
+ }
12715
+ } else if (check.kind === "email") {
12716
+ if (!emailRegex.test(input.data)) {
12717
+ ctx = this._getOrReturnCtx(input, ctx);
12718
+ addIssueToContext(ctx, {
12719
+ validation: "email",
12720
+ code: ZodIssueCode.invalid_string,
12721
+ message: check.message
12722
+ });
12723
+ status.dirty();
12724
+ }
12725
+ } else if (check.kind === "emoji") {
12726
+ if (!emojiRegex) {
12727
+ emojiRegex = new RegExp(_emojiRegex, "u");
12728
+ }
12729
+ if (!emojiRegex.test(input.data)) {
12730
+ ctx = this._getOrReturnCtx(input, ctx);
12731
+ addIssueToContext(ctx, {
12732
+ validation: "emoji",
12733
+ code: ZodIssueCode.invalid_string,
12734
+ message: check.message
12735
+ });
12736
+ status.dirty();
12737
+ }
12738
+ } else if (check.kind === "uuid") {
12739
+ if (!uuidRegex.test(input.data)) {
12740
+ ctx = this._getOrReturnCtx(input, ctx);
12741
+ addIssueToContext(ctx, {
12742
+ validation: "uuid",
12743
+ code: ZodIssueCode.invalid_string,
12744
+ message: check.message
12745
+ });
12746
+ status.dirty();
12747
+ }
12748
+ } else if (check.kind === "nanoid") {
12749
+ if (!nanoidRegex.test(input.data)) {
12750
+ ctx = this._getOrReturnCtx(input, ctx);
12751
+ addIssueToContext(ctx, {
12752
+ validation: "nanoid",
12753
+ code: ZodIssueCode.invalid_string,
12754
+ message: check.message
12755
+ });
12756
+ status.dirty();
12757
+ }
12758
+ } else if (check.kind === "cuid") {
12759
+ if (!cuidRegex.test(input.data)) {
12760
+ ctx = this._getOrReturnCtx(input, ctx);
12761
+ addIssueToContext(ctx, {
12762
+ validation: "cuid",
12763
+ code: ZodIssueCode.invalid_string,
12764
+ message: check.message
12765
+ });
12766
+ status.dirty();
12767
+ }
12768
+ } else if (check.kind === "cuid2") {
12769
+ if (!cuid2Regex.test(input.data)) {
12770
+ ctx = this._getOrReturnCtx(input, ctx);
12771
+ addIssueToContext(ctx, {
12772
+ validation: "cuid2",
12773
+ code: ZodIssueCode.invalid_string,
12774
+ message: check.message
12775
+ });
12776
+ status.dirty();
12777
+ }
12778
+ } else if (check.kind === "ulid") {
12779
+ if (!ulidRegex.test(input.data)) {
12780
+ ctx = this._getOrReturnCtx(input, ctx);
12781
+ addIssueToContext(ctx, {
12782
+ validation: "ulid",
12783
+ code: ZodIssueCode.invalid_string,
12784
+ message: check.message
12785
+ });
12786
+ status.dirty();
12787
+ }
12788
+ } else if (check.kind === "url") {
12789
+ try {
12790
+ new URL(input.data);
12791
+ } catch (_a) {
12792
+ ctx = this._getOrReturnCtx(input, ctx);
12793
+ addIssueToContext(ctx, {
12794
+ validation: "url",
12795
+ code: ZodIssueCode.invalid_string,
12796
+ message: check.message
12797
+ });
12798
+ status.dirty();
12799
+ }
12800
+ } else if (check.kind === "regex") {
12801
+ check.regex.lastIndex = 0;
12802
+ const testResult = check.regex.test(input.data);
12803
+ if (!testResult) {
12804
+ ctx = this._getOrReturnCtx(input, ctx);
12805
+ addIssueToContext(ctx, {
12806
+ validation: "regex",
12807
+ code: ZodIssueCode.invalid_string,
12808
+ message: check.message
12809
+ });
12810
+ status.dirty();
12811
+ }
12812
+ } else if (check.kind === "trim") {
12813
+ input.data = input.data.trim();
12814
+ } else if (check.kind === "includes") {
12815
+ if (!input.data.includes(check.value, check.position)) {
12816
+ ctx = this._getOrReturnCtx(input, ctx);
12817
+ addIssueToContext(ctx, {
12818
+ code: ZodIssueCode.invalid_string,
12819
+ validation: { includes: check.value, position: check.position },
12820
+ message: check.message
12821
+ });
12822
+ status.dirty();
12823
+ }
12824
+ } else if (check.kind === "toLowerCase") {
12825
+ input.data = input.data.toLowerCase();
12826
+ } else if (check.kind === "toUpperCase") {
12827
+ input.data = input.data.toUpperCase();
12828
+ } else if (check.kind === "startsWith") {
12829
+ if (!input.data.startsWith(check.value)) {
12830
+ ctx = this._getOrReturnCtx(input, ctx);
12831
+ addIssueToContext(ctx, {
12832
+ code: ZodIssueCode.invalid_string,
12833
+ validation: { startsWith: check.value },
12834
+ message: check.message
12835
+ });
12836
+ status.dirty();
12837
+ }
12838
+ } else if (check.kind === "endsWith") {
12839
+ if (!input.data.endsWith(check.value)) {
12840
+ ctx = this._getOrReturnCtx(input, ctx);
12841
+ addIssueToContext(ctx, {
12842
+ code: ZodIssueCode.invalid_string,
12843
+ validation: { endsWith: check.value },
12844
+ message: check.message
12845
+ });
12846
+ status.dirty();
12847
+ }
12848
+ } else if (check.kind === "datetime") {
12849
+ const regex = datetimeRegex(check);
12850
+ if (!regex.test(input.data)) {
12851
+ ctx = this._getOrReturnCtx(input, ctx);
12852
+ addIssueToContext(ctx, {
12853
+ code: ZodIssueCode.invalid_string,
12854
+ validation: "datetime",
12855
+ message: check.message
12856
+ });
12857
+ status.dirty();
12858
+ }
12859
+ } else if (check.kind === "date") {
12860
+ const regex = dateRegex;
12861
+ if (!regex.test(input.data)) {
12862
+ ctx = this._getOrReturnCtx(input, ctx);
12863
+ addIssueToContext(ctx, {
12864
+ code: ZodIssueCode.invalid_string,
12865
+ validation: "date",
12866
+ message: check.message
12867
+ });
12868
+ status.dirty();
12869
+ }
12870
+ } else if (check.kind === "time") {
12871
+ const regex = timeRegex(check);
12872
+ if (!regex.test(input.data)) {
12873
+ ctx = this._getOrReturnCtx(input, ctx);
12874
+ addIssueToContext(ctx, {
12875
+ code: ZodIssueCode.invalid_string,
12876
+ validation: "time",
12877
+ message: check.message
12878
+ });
12879
+ status.dirty();
12880
+ }
12881
+ } else if (check.kind === "duration") {
12882
+ if (!durationRegex.test(input.data)) {
12883
+ ctx = this._getOrReturnCtx(input, ctx);
12884
+ addIssueToContext(ctx, {
12885
+ validation: "duration",
12886
+ code: ZodIssueCode.invalid_string,
12887
+ message: check.message
12888
+ });
12889
+ status.dirty();
12890
+ }
12891
+ } else if (check.kind === "ip") {
12892
+ if (!isValidIP(input.data, check.version)) {
12893
+ ctx = this._getOrReturnCtx(input, ctx);
12894
+ addIssueToContext(ctx, {
12895
+ validation: "ip",
12896
+ code: ZodIssueCode.invalid_string,
12897
+ message: check.message
12898
+ });
12899
+ status.dirty();
12900
+ }
12901
+ } else if (check.kind === "base64") {
12902
+ if (!base64Regex.test(input.data)) {
12903
+ ctx = this._getOrReturnCtx(input, ctx);
12904
+ addIssueToContext(ctx, {
12905
+ validation: "base64",
12906
+ code: ZodIssueCode.invalid_string,
12907
+ message: check.message
12908
+ });
12909
+ status.dirty();
12910
+ }
12911
+ } else {
12912
+ util.assertNever(check);
12913
+ }
12914
+ }
12915
+ return { status: status.value, value: input.data };
12916
+ }
12917
+ _regex(regex, validation, message) {
12918
+ return this.refinement((data) => regex.test(data), {
12919
+ validation,
12920
+ code: ZodIssueCode.invalid_string,
12921
+ ...errorUtil.errToObj(message)
12922
+ });
12923
+ }
12924
+ _addCheck(check) {
12925
+ return new _ZodString({
12926
+ ...this._def,
12927
+ checks: [...this._def.checks, check]
12928
+ });
12929
+ }
12930
+ email(message) {
12931
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
12932
+ }
12933
+ url(message) {
12934
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
12935
+ }
12936
+ emoji(message) {
12937
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
12938
+ }
12939
+ uuid(message) {
12940
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
12941
+ }
12942
+ nanoid(message) {
12943
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
12944
+ }
12945
+ cuid(message) {
12946
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
12947
+ }
12948
+ cuid2(message) {
12949
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
12950
+ }
12951
+ ulid(message) {
12952
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
12953
+ }
12954
+ base64(message) {
12955
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
12956
+ }
12957
+ ip(options2) {
12958
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options2) });
12959
+ }
12960
+ datetime(options2) {
12961
+ var _a, _b;
12962
+ if (typeof options2 === "string") {
12963
+ return this._addCheck({
12964
+ kind: "datetime",
12965
+ precision: null,
12966
+ offset: false,
12967
+ local: false,
12968
+ message: options2
12969
+ });
12970
+ }
12971
+ return this._addCheck({
12972
+ kind: "datetime",
12973
+ precision: typeof (options2 === null || options2 === void 0 ? void 0 : options2.precision) === "undefined" ? null : options2 === null || options2 === void 0 ? void 0 : options2.precision,
12974
+ offset: (_a = options2 === null || options2 === void 0 ? void 0 : options2.offset) !== null && _a !== void 0 ? _a : false,
12975
+ local: (_b = options2 === null || options2 === void 0 ? void 0 : options2.local) !== null && _b !== void 0 ? _b : false,
12976
+ ...errorUtil.errToObj(options2 === null || options2 === void 0 ? void 0 : options2.message)
12977
+ });
12978
+ }
12979
+ date(message) {
12980
+ return this._addCheck({ kind: "date", message });
12981
+ }
12982
+ time(options2) {
12983
+ if (typeof options2 === "string") {
12984
+ return this._addCheck({
12985
+ kind: "time",
12986
+ precision: null,
12987
+ message: options2
12988
+ });
12989
+ }
12990
+ return this._addCheck({
12991
+ kind: "time",
12992
+ precision: typeof (options2 === null || options2 === void 0 ? void 0 : options2.precision) === "undefined" ? null : options2 === null || options2 === void 0 ? void 0 : options2.precision,
12993
+ ...errorUtil.errToObj(options2 === null || options2 === void 0 ? void 0 : options2.message)
12994
+ });
12995
+ }
12996
+ duration(message) {
12997
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
12998
+ }
12999
+ regex(regex, message) {
13000
+ return this._addCheck({
13001
+ kind: "regex",
13002
+ regex,
13003
+ ...errorUtil.errToObj(message)
13004
+ });
13005
+ }
13006
+ includes(value, options2) {
13007
+ return this._addCheck({
13008
+ kind: "includes",
13009
+ value,
13010
+ position: options2 === null || options2 === void 0 ? void 0 : options2.position,
13011
+ ...errorUtil.errToObj(options2 === null || options2 === void 0 ? void 0 : options2.message)
13012
+ });
13013
+ }
13014
+ startsWith(value, message) {
13015
+ return this._addCheck({
13016
+ kind: "startsWith",
13017
+ value,
13018
+ ...errorUtil.errToObj(message)
13019
+ });
13020
+ }
13021
+ endsWith(value, message) {
13022
+ return this._addCheck({
13023
+ kind: "endsWith",
13024
+ value,
13025
+ ...errorUtil.errToObj(message)
13026
+ });
13027
+ }
13028
+ min(minLength, message) {
13029
+ return this._addCheck({
13030
+ kind: "min",
13031
+ value: minLength,
13032
+ ...errorUtil.errToObj(message)
13033
+ });
13034
+ }
13035
+ max(maxLength, message) {
13036
+ return this._addCheck({
13037
+ kind: "max",
13038
+ value: maxLength,
13039
+ ...errorUtil.errToObj(message)
13040
+ });
13041
+ }
13042
+ length(len, message) {
13043
+ return this._addCheck({
13044
+ kind: "length",
13045
+ value: len,
13046
+ ...errorUtil.errToObj(message)
13047
+ });
13048
+ }
13049
+ /**
13050
+ * @deprecated Use z.string().min(1) instead.
13051
+ * @see {@link ZodString.min}
13052
+ */
13053
+ nonempty(message) {
13054
+ return this.min(1, errorUtil.errToObj(message));
13055
+ }
13056
+ trim() {
13057
+ return new _ZodString({
13058
+ ...this._def,
13059
+ checks: [...this._def.checks, { kind: "trim" }]
13060
+ });
13061
+ }
13062
+ toLowerCase() {
13063
+ return new _ZodString({
13064
+ ...this._def,
13065
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
13066
+ });
13067
+ }
13068
+ toUpperCase() {
13069
+ return new _ZodString({
13070
+ ...this._def,
13071
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
13072
+ });
13073
+ }
13074
+ get isDatetime() {
13075
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
13076
+ }
13077
+ get isDate() {
13078
+ return !!this._def.checks.find((ch) => ch.kind === "date");
13079
+ }
13080
+ get isTime() {
13081
+ return !!this._def.checks.find((ch) => ch.kind === "time");
13082
+ }
13083
+ get isDuration() {
13084
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
13085
+ }
13086
+ get isEmail() {
13087
+ return !!this._def.checks.find((ch) => ch.kind === "email");
13088
+ }
13089
+ get isURL() {
13090
+ return !!this._def.checks.find((ch) => ch.kind === "url");
13091
+ }
13092
+ get isEmoji() {
13093
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
13094
+ }
13095
+ get isUUID() {
13096
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
13097
+ }
13098
+ get isNANOID() {
13099
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
13100
+ }
13101
+ get isCUID() {
13102
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
13103
+ }
13104
+ get isCUID2() {
13105
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
13106
+ }
13107
+ get isULID() {
13108
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
13109
+ }
13110
+ get isIP() {
13111
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
13112
+ }
13113
+ get isBase64() {
13114
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
13115
+ }
13116
+ get minLength() {
13117
+ let min = null;
13118
+ for (const ch of this._def.checks) {
13119
+ if (ch.kind === "min") {
13120
+ if (min === null || ch.value > min)
13121
+ min = ch.value;
13122
+ }
13123
+ }
13124
+ return min;
13125
+ }
13126
+ get maxLength() {
13127
+ let max = null;
13128
+ for (const ch of this._def.checks) {
13129
+ if (ch.kind === "max") {
13130
+ if (max === null || ch.value < max)
13131
+ max = ch.value;
13132
+ }
13133
+ }
13134
+ return max;
13135
+ }
13136
+ };
13137
+ ZodString.create = (params2) => {
13138
+ var _a;
13139
+ return new ZodString({
13140
+ checks: [],
13141
+ typeName: ZodFirstPartyTypeKind.ZodString,
13142
+ coerce: (_a = params2 === null || params2 === void 0 ? void 0 : params2.coerce) !== null && _a !== void 0 ? _a : false,
13143
+ ...processCreateParams(params2)
13144
+ });
13145
+ };
13146
+ function floatSafeRemainder(val, step) {
13147
+ const valDecCount = (val.toString().split(".")[1] || "").length;
13148
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
13149
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
13150
+ const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
13151
+ const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
13152
+ return valInt % stepInt / Math.pow(10, decCount);
13153
+ }
13154
+ var ZodNumber = class _ZodNumber extends ZodType {
13155
+ constructor() {
13156
+ super(...arguments);
13157
+ this.min = this.gte;
13158
+ this.max = this.lte;
13159
+ this.step = this.multipleOf;
13160
+ }
13161
+ _parse(input) {
13162
+ if (this._def.coerce) {
13163
+ input.data = Number(input.data);
13164
+ }
13165
+ const parsedType = this._getType(input);
13166
+ if (parsedType !== ZodParsedType.number) {
13167
+ const ctx2 = this._getOrReturnCtx(input);
13168
+ addIssueToContext(ctx2, {
13169
+ code: ZodIssueCode.invalid_type,
13170
+ expected: ZodParsedType.number,
13171
+ received: ctx2.parsedType
13172
+ });
13173
+ return INVALID;
13174
+ }
13175
+ let ctx = void 0;
13176
+ const status = new ParseStatus();
13177
+ for (const check of this._def.checks) {
13178
+ if (check.kind === "int") {
13179
+ if (!util.isInteger(input.data)) {
13180
+ ctx = this._getOrReturnCtx(input, ctx);
13181
+ addIssueToContext(ctx, {
13182
+ code: ZodIssueCode.invalid_type,
13183
+ expected: "integer",
13184
+ received: "float",
13185
+ message: check.message
13186
+ });
13187
+ status.dirty();
13188
+ }
13189
+ } else if (check.kind === "min") {
13190
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
13191
+ if (tooSmall) {
13192
+ ctx = this._getOrReturnCtx(input, ctx);
13193
+ addIssueToContext(ctx, {
13194
+ code: ZodIssueCode.too_small,
13195
+ minimum: check.value,
13196
+ type: "number",
13197
+ inclusive: check.inclusive,
13198
+ exact: false,
13199
+ message: check.message
13200
+ });
13201
+ status.dirty();
13202
+ }
13203
+ } else if (check.kind === "max") {
13204
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
13205
+ if (tooBig) {
13206
+ ctx = this._getOrReturnCtx(input, ctx);
13207
+ addIssueToContext(ctx, {
13208
+ code: ZodIssueCode.too_big,
13209
+ maximum: check.value,
13210
+ type: "number",
13211
+ inclusive: check.inclusive,
13212
+ exact: false,
13213
+ message: check.message
13214
+ });
13215
+ status.dirty();
13216
+ }
13217
+ } else if (check.kind === "multipleOf") {
13218
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
13219
+ ctx = this._getOrReturnCtx(input, ctx);
13220
+ addIssueToContext(ctx, {
13221
+ code: ZodIssueCode.not_multiple_of,
13222
+ multipleOf: check.value,
13223
+ message: check.message
13224
+ });
13225
+ status.dirty();
13226
+ }
13227
+ } else if (check.kind === "finite") {
13228
+ if (!Number.isFinite(input.data)) {
13229
+ ctx = this._getOrReturnCtx(input, ctx);
13230
+ addIssueToContext(ctx, {
13231
+ code: ZodIssueCode.not_finite,
13232
+ message: check.message
13233
+ });
13234
+ status.dirty();
13235
+ }
13236
+ } else {
13237
+ util.assertNever(check);
13238
+ }
13239
+ }
13240
+ return { status: status.value, value: input.data };
13241
+ }
13242
+ gte(value, message) {
13243
+ return this.setLimit("min", value, true, errorUtil.toString(message));
13244
+ }
13245
+ gt(value, message) {
13246
+ return this.setLimit("min", value, false, errorUtil.toString(message));
13247
+ }
13248
+ lte(value, message) {
13249
+ return this.setLimit("max", value, true, errorUtil.toString(message));
13250
+ }
13251
+ lt(value, message) {
13252
+ return this.setLimit("max", value, false, errorUtil.toString(message));
13253
+ }
13254
+ setLimit(kind, value, inclusive, message) {
13255
+ return new _ZodNumber({
13256
+ ...this._def,
13257
+ checks: [
13258
+ ...this._def.checks,
13259
+ {
13260
+ kind,
13261
+ value,
13262
+ inclusive,
13263
+ message: errorUtil.toString(message)
13264
+ }
13265
+ ]
13266
+ });
13267
+ }
13268
+ _addCheck(check) {
13269
+ return new _ZodNumber({
13270
+ ...this._def,
13271
+ checks: [...this._def.checks, check]
13272
+ });
13273
+ }
13274
+ int(message) {
13275
+ return this._addCheck({
13276
+ kind: "int",
13277
+ message: errorUtil.toString(message)
13278
+ });
13279
+ }
13280
+ positive(message) {
13281
+ return this._addCheck({
13282
+ kind: "min",
13283
+ value: 0,
13284
+ inclusive: false,
13285
+ message: errorUtil.toString(message)
13286
+ });
13287
+ }
13288
+ negative(message) {
13289
+ return this._addCheck({
13290
+ kind: "max",
13291
+ value: 0,
13292
+ inclusive: false,
13293
+ message: errorUtil.toString(message)
13294
+ });
13295
+ }
13296
+ nonpositive(message) {
13297
+ return this._addCheck({
13298
+ kind: "max",
13299
+ value: 0,
13300
+ inclusive: true,
13301
+ message: errorUtil.toString(message)
13302
+ });
13303
+ }
13304
+ nonnegative(message) {
13305
+ return this._addCheck({
13306
+ kind: "min",
13307
+ value: 0,
13308
+ inclusive: true,
13309
+ message: errorUtil.toString(message)
13310
+ });
13311
+ }
13312
+ multipleOf(value, message) {
13313
+ return this._addCheck({
13314
+ kind: "multipleOf",
13315
+ value,
13316
+ message: errorUtil.toString(message)
13317
+ });
13318
+ }
13319
+ finite(message) {
13320
+ return this._addCheck({
13321
+ kind: "finite",
13322
+ message: errorUtil.toString(message)
13323
+ });
13324
+ }
13325
+ safe(message) {
13326
+ return this._addCheck({
13327
+ kind: "min",
13328
+ inclusive: true,
13329
+ value: Number.MIN_SAFE_INTEGER,
13330
+ message: errorUtil.toString(message)
13331
+ })._addCheck({
13332
+ kind: "max",
13333
+ inclusive: true,
13334
+ value: Number.MAX_SAFE_INTEGER,
13335
+ message: errorUtil.toString(message)
13336
+ });
13337
+ }
13338
+ get minValue() {
13339
+ let min = null;
13340
+ for (const ch of this._def.checks) {
13341
+ if (ch.kind === "min") {
13342
+ if (min === null || ch.value > min)
13343
+ min = ch.value;
13344
+ }
13345
+ }
13346
+ return min;
13347
+ }
13348
+ get maxValue() {
13349
+ let max = null;
13350
+ for (const ch of this._def.checks) {
13351
+ if (ch.kind === "max") {
13352
+ if (max === null || ch.value < max)
13353
+ max = ch.value;
13354
+ }
13355
+ }
13356
+ return max;
13357
+ }
13358
+ get isInt() {
13359
+ return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
13360
+ }
13361
+ get isFinite() {
13362
+ let max = null, min = null;
13363
+ for (const ch of this._def.checks) {
13364
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
13365
+ return true;
13366
+ } else if (ch.kind === "min") {
13367
+ if (min === null || ch.value > min)
13368
+ min = ch.value;
13369
+ } else if (ch.kind === "max") {
13370
+ if (max === null || ch.value < max)
13371
+ max = ch.value;
13372
+ }
13373
+ }
13374
+ return Number.isFinite(min) && Number.isFinite(max);
13375
+ }
13376
+ };
13377
+ ZodNumber.create = (params2) => {
13378
+ return new ZodNumber({
13379
+ checks: [],
13380
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
13381
+ coerce: (params2 === null || params2 === void 0 ? void 0 : params2.coerce) || false,
13382
+ ...processCreateParams(params2)
13383
+ });
13384
+ };
13385
+ var ZodBigInt = class _ZodBigInt extends ZodType {
13386
+ constructor() {
13387
+ super(...arguments);
13388
+ this.min = this.gte;
13389
+ this.max = this.lte;
13390
+ }
13391
+ _parse(input) {
13392
+ if (this._def.coerce) {
13393
+ input.data = BigInt(input.data);
13394
+ }
13395
+ const parsedType = this._getType(input);
13396
+ if (parsedType !== ZodParsedType.bigint) {
13397
+ const ctx2 = this._getOrReturnCtx(input);
13398
+ addIssueToContext(ctx2, {
13399
+ code: ZodIssueCode.invalid_type,
13400
+ expected: ZodParsedType.bigint,
13401
+ received: ctx2.parsedType
13402
+ });
13403
+ return INVALID;
13404
+ }
13405
+ let ctx = void 0;
13406
+ const status = new ParseStatus();
13407
+ for (const check of this._def.checks) {
13408
+ if (check.kind === "min") {
13409
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
13410
+ if (tooSmall) {
13411
+ ctx = this._getOrReturnCtx(input, ctx);
13412
+ addIssueToContext(ctx, {
13413
+ code: ZodIssueCode.too_small,
13414
+ type: "bigint",
13415
+ minimum: check.value,
13416
+ inclusive: check.inclusive,
13417
+ message: check.message
13418
+ });
13419
+ status.dirty();
13420
+ }
13421
+ } else if (check.kind === "max") {
13422
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
13423
+ if (tooBig) {
13424
+ ctx = this._getOrReturnCtx(input, ctx);
13425
+ addIssueToContext(ctx, {
13426
+ code: ZodIssueCode.too_big,
13427
+ type: "bigint",
13428
+ maximum: check.value,
13429
+ inclusive: check.inclusive,
13430
+ message: check.message
13431
+ });
13432
+ status.dirty();
13433
+ }
13434
+ } else if (check.kind === "multipleOf") {
13435
+ if (input.data % check.value !== BigInt(0)) {
13436
+ ctx = this._getOrReturnCtx(input, ctx);
13437
+ addIssueToContext(ctx, {
13438
+ code: ZodIssueCode.not_multiple_of,
13439
+ multipleOf: check.value,
13440
+ message: check.message
13441
+ });
13442
+ status.dirty();
13443
+ }
13444
+ } else {
13445
+ util.assertNever(check);
13446
+ }
13447
+ }
13448
+ return { status: status.value, value: input.data };
13449
+ }
13450
+ gte(value, message) {
13451
+ return this.setLimit("min", value, true, errorUtil.toString(message));
13452
+ }
13453
+ gt(value, message) {
13454
+ return this.setLimit("min", value, false, errorUtil.toString(message));
13455
+ }
13456
+ lte(value, message) {
13457
+ return this.setLimit("max", value, true, errorUtil.toString(message));
13458
+ }
13459
+ lt(value, message) {
13460
+ return this.setLimit("max", value, false, errorUtil.toString(message));
13461
+ }
13462
+ setLimit(kind, value, inclusive, message) {
13463
+ return new _ZodBigInt({
13464
+ ...this._def,
13465
+ checks: [
13466
+ ...this._def.checks,
13467
+ {
13468
+ kind,
13469
+ value,
13470
+ inclusive,
13471
+ message: errorUtil.toString(message)
13472
+ }
13473
+ ]
13474
+ });
13475
+ }
13476
+ _addCheck(check) {
13477
+ return new _ZodBigInt({
13478
+ ...this._def,
13479
+ checks: [...this._def.checks, check]
13480
+ });
13481
+ }
13482
+ positive(message) {
13483
+ return this._addCheck({
13484
+ kind: "min",
13485
+ value: BigInt(0),
13486
+ inclusive: false,
13487
+ message: errorUtil.toString(message)
13488
+ });
13489
+ }
13490
+ negative(message) {
13491
+ return this._addCheck({
13492
+ kind: "max",
13493
+ value: BigInt(0),
13494
+ inclusive: false,
13495
+ message: errorUtil.toString(message)
13496
+ });
13497
+ }
13498
+ nonpositive(message) {
13499
+ return this._addCheck({
13500
+ kind: "max",
13501
+ value: BigInt(0),
13502
+ inclusive: true,
13503
+ message: errorUtil.toString(message)
13504
+ });
13505
+ }
13506
+ nonnegative(message) {
13507
+ return this._addCheck({
13508
+ kind: "min",
13509
+ value: BigInt(0),
13510
+ inclusive: true,
13511
+ message: errorUtil.toString(message)
13512
+ });
13513
+ }
13514
+ multipleOf(value, message) {
13515
+ return this._addCheck({
13516
+ kind: "multipleOf",
13517
+ value,
13518
+ message: errorUtil.toString(message)
13519
+ });
13520
+ }
13521
+ get minValue() {
13522
+ let min = null;
13523
+ for (const ch of this._def.checks) {
13524
+ if (ch.kind === "min") {
13525
+ if (min === null || ch.value > min)
13526
+ min = ch.value;
13527
+ }
13528
+ }
13529
+ return min;
13530
+ }
13531
+ get maxValue() {
13532
+ let max = null;
13533
+ for (const ch of this._def.checks) {
13534
+ if (ch.kind === "max") {
13535
+ if (max === null || ch.value < max)
13536
+ max = ch.value;
13537
+ }
13538
+ }
13539
+ return max;
13540
+ }
13541
+ };
13542
+ ZodBigInt.create = (params2) => {
13543
+ var _a;
13544
+ return new ZodBigInt({
13545
+ checks: [],
13546
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
13547
+ coerce: (_a = params2 === null || params2 === void 0 ? void 0 : params2.coerce) !== null && _a !== void 0 ? _a : false,
13548
+ ...processCreateParams(params2)
13549
+ });
13550
+ };
13551
+ var ZodBoolean = class extends ZodType {
13552
+ _parse(input) {
13553
+ if (this._def.coerce) {
13554
+ input.data = Boolean(input.data);
13555
+ }
13556
+ const parsedType = this._getType(input);
13557
+ if (parsedType !== ZodParsedType.boolean) {
13558
+ const ctx = this._getOrReturnCtx(input);
13559
+ addIssueToContext(ctx, {
13560
+ code: ZodIssueCode.invalid_type,
13561
+ expected: ZodParsedType.boolean,
13562
+ received: ctx.parsedType
13563
+ });
13564
+ return INVALID;
13565
+ }
13566
+ return OK(input.data);
13567
+ }
13568
+ };
13569
+ ZodBoolean.create = (params2) => {
13570
+ return new ZodBoolean({
13571
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
13572
+ coerce: (params2 === null || params2 === void 0 ? void 0 : params2.coerce) || false,
13573
+ ...processCreateParams(params2)
13574
+ });
13575
+ };
13576
+ var ZodDate = class _ZodDate extends ZodType {
13577
+ _parse(input) {
13578
+ if (this._def.coerce) {
13579
+ input.data = new Date(input.data);
13580
+ }
13581
+ const parsedType = this._getType(input);
13582
+ if (parsedType !== ZodParsedType.date) {
13583
+ const ctx2 = this._getOrReturnCtx(input);
13584
+ addIssueToContext(ctx2, {
13585
+ code: ZodIssueCode.invalid_type,
13586
+ expected: ZodParsedType.date,
13587
+ received: ctx2.parsedType
13588
+ });
13589
+ return INVALID;
13590
+ }
13591
+ if (isNaN(input.data.getTime())) {
13592
+ const ctx2 = this._getOrReturnCtx(input);
13593
+ addIssueToContext(ctx2, {
13594
+ code: ZodIssueCode.invalid_date
13595
+ });
13596
+ return INVALID;
13597
+ }
13598
+ const status = new ParseStatus();
13599
+ let ctx = void 0;
13600
+ for (const check of this._def.checks) {
13601
+ if (check.kind === "min") {
13602
+ if (input.data.getTime() < check.value) {
13603
+ ctx = this._getOrReturnCtx(input, ctx);
13604
+ addIssueToContext(ctx, {
13605
+ code: ZodIssueCode.too_small,
13606
+ message: check.message,
13607
+ inclusive: true,
13608
+ exact: false,
13609
+ minimum: check.value,
13610
+ type: "date"
13611
+ });
13612
+ status.dirty();
13613
+ }
13614
+ } else if (check.kind === "max") {
13615
+ if (input.data.getTime() > check.value) {
13616
+ ctx = this._getOrReturnCtx(input, ctx);
13617
+ addIssueToContext(ctx, {
13618
+ code: ZodIssueCode.too_big,
13619
+ message: check.message,
13620
+ inclusive: true,
13621
+ exact: false,
13622
+ maximum: check.value,
13623
+ type: "date"
13624
+ });
13625
+ status.dirty();
13626
+ }
13627
+ } else {
13628
+ util.assertNever(check);
13629
+ }
13630
+ }
13631
+ return {
13632
+ status: status.value,
13633
+ value: new Date(input.data.getTime())
13634
+ };
13635
+ }
13636
+ _addCheck(check) {
13637
+ return new _ZodDate({
13638
+ ...this._def,
13639
+ checks: [...this._def.checks, check]
13640
+ });
13641
+ }
13642
+ min(minDate, message) {
13643
+ return this._addCheck({
13644
+ kind: "min",
13645
+ value: minDate.getTime(),
13646
+ message: errorUtil.toString(message)
13647
+ });
13648
+ }
13649
+ max(maxDate, message) {
13650
+ return this._addCheck({
13651
+ kind: "max",
13652
+ value: maxDate.getTime(),
13653
+ message: errorUtil.toString(message)
13654
+ });
13655
+ }
13656
+ get minDate() {
13657
+ let min = null;
13658
+ for (const ch of this._def.checks) {
13659
+ if (ch.kind === "min") {
13660
+ if (min === null || ch.value > min)
13661
+ min = ch.value;
13662
+ }
13663
+ }
13664
+ return min != null ? new Date(min) : null;
13665
+ }
13666
+ get maxDate() {
13667
+ let max = null;
13668
+ for (const ch of this._def.checks) {
13669
+ if (ch.kind === "max") {
13670
+ if (max === null || ch.value < max)
13671
+ max = ch.value;
13672
+ }
13673
+ }
13674
+ return max != null ? new Date(max) : null;
13675
+ }
13676
+ };
13677
+ ZodDate.create = (params2) => {
13678
+ return new ZodDate({
13679
+ checks: [],
13680
+ coerce: (params2 === null || params2 === void 0 ? void 0 : params2.coerce) || false,
13681
+ typeName: ZodFirstPartyTypeKind.ZodDate,
13682
+ ...processCreateParams(params2)
13683
+ });
13684
+ };
13685
+ var ZodSymbol = class extends ZodType {
13686
+ _parse(input) {
13687
+ const parsedType = this._getType(input);
13688
+ if (parsedType !== ZodParsedType.symbol) {
13689
+ const ctx = this._getOrReturnCtx(input);
13690
+ addIssueToContext(ctx, {
13691
+ code: ZodIssueCode.invalid_type,
13692
+ expected: ZodParsedType.symbol,
13693
+ received: ctx.parsedType
13694
+ });
13695
+ return INVALID;
13696
+ }
13697
+ return OK(input.data);
13698
+ }
13699
+ };
13700
+ ZodSymbol.create = (params2) => {
13701
+ return new ZodSymbol({
13702
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
13703
+ ...processCreateParams(params2)
13704
+ });
13705
+ };
13706
+ var ZodUndefined = class extends ZodType {
13707
+ _parse(input) {
13708
+ const parsedType = this._getType(input);
13709
+ if (parsedType !== ZodParsedType.undefined) {
13710
+ const ctx = this._getOrReturnCtx(input);
13711
+ addIssueToContext(ctx, {
13712
+ code: ZodIssueCode.invalid_type,
13713
+ expected: ZodParsedType.undefined,
13714
+ received: ctx.parsedType
13715
+ });
13716
+ return INVALID;
13717
+ }
13718
+ return OK(input.data);
13719
+ }
13720
+ };
13721
+ ZodUndefined.create = (params2) => {
13722
+ return new ZodUndefined({
13723
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
13724
+ ...processCreateParams(params2)
13725
+ });
13726
+ };
13727
+ var ZodNull = class extends ZodType {
13728
+ _parse(input) {
13729
+ const parsedType = this._getType(input);
13730
+ if (parsedType !== ZodParsedType.null) {
13731
+ const ctx = this._getOrReturnCtx(input);
13732
+ addIssueToContext(ctx, {
13733
+ code: ZodIssueCode.invalid_type,
13734
+ expected: ZodParsedType.null,
13735
+ received: ctx.parsedType
13736
+ });
13737
+ return INVALID;
13738
+ }
13739
+ return OK(input.data);
13740
+ }
13741
+ };
13742
+ ZodNull.create = (params2) => {
13743
+ return new ZodNull({
13744
+ typeName: ZodFirstPartyTypeKind.ZodNull,
13745
+ ...processCreateParams(params2)
13746
+ });
13747
+ };
13748
+ var ZodAny = class extends ZodType {
13749
+ constructor() {
13750
+ super(...arguments);
13751
+ this._any = true;
13752
+ }
13753
+ _parse(input) {
13754
+ return OK(input.data);
13755
+ }
13756
+ };
13757
+ ZodAny.create = (params2) => {
13758
+ return new ZodAny({
13759
+ typeName: ZodFirstPartyTypeKind.ZodAny,
13760
+ ...processCreateParams(params2)
13761
+ });
13762
+ };
13763
+ var ZodUnknown = class extends ZodType {
13764
+ constructor() {
13765
+ super(...arguments);
13766
+ this._unknown = true;
13767
+ }
13768
+ _parse(input) {
13769
+ return OK(input.data);
13770
+ }
13771
+ };
13772
+ ZodUnknown.create = (params2) => {
13773
+ return new ZodUnknown({
13774
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
13775
+ ...processCreateParams(params2)
13776
+ });
13777
+ };
13778
+ var ZodNever = class extends ZodType {
13779
+ _parse(input) {
13780
+ const ctx = this._getOrReturnCtx(input);
13781
+ addIssueToContext(ctx, {
13782
+ code: ZodIssueCode.invalid_type,
13783
+ expected: ZodParsedType.never,
13784
+ received: ctx.parsedType
13785
+ });
13786
+ return INVALID;
13787
+ }
13788
+ };
13789
+ ZodNever.create = (params2) => {
13790
+ return new ZodNever({
13791
+ typeName: ZodFirstPartyTypeKind.ZodNever,
13792
+ ...processCreateParams(params2)
13793
+ });
13794
+ };
13795
+ var ZodVoid = class extends ZodType {
13796
+ _parse(input) {
13797
+ const parsedType = this._getType(input);
13798
+ if (parsedType !== ZodParsedType.undefined) {
13799
+ const ctx = this._getOrReturnCtx(input);
13800
+ addIssueToContext(ctx, {
13801
+ code: ZodIssueCode.invalid_type,
13802
+ expected: ZodParsedType.void,
13803
+ received: ctx.parsedType
13804
+ });
13805
+ return INVALID;
13806
+ }
13807
+ return OK(input.data);
13808
+ }
13809
+ };
13810
+ ZodVoid.create = (params2) => {
13811
+ return new ZodVoid({
13812
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
13813
+ ...processCreateParams(params2)
13814
+ });
13815
+ };
13816
+ var ZodArray = class _ZodArray extends ZodType {
13817
+ _parse(input) {
13818
+ const { ctx, status } = this._processInputParams(input);
13819
+ const def = this._def;
13820
+ if (ctx.parsedType !== ZodParsedType.array) {
13821
+ addIssueToContext(ctx, {
13822
+ code: ZodIssueCode.invalid_type,
13823
+ expected: ZodParsedType.array,
13824
+ received: ctx.parsedType
13825
+ });
13826
+ return INVALID;
13827
+ }
13828
+ if (def.exactLength !== null) {
13829
+ const tooBig = ctx.data.length > def.exactLength.value;
13830
+ const tooSmall = ctx.data.length < def.exactLength.value;
13831
+ if (tooBig || tooSmall) {
13832
+ addIssueToContext(ctx, {
13833
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
13834
+ minimum: tooSmall ? def.exactLength.value : void 0,
13835
+ maximum: tooBig ? def.exactLength.value : void 0,
13836
+ type: "array",
13837
+ inclusive: true,
13838
+ exact: true,
13839
+ message: def.exactLength.message
13840
+ });
13841
+ status.dirty();
13842
+ }
13843
+ }
13844
+ if (def.minLength !== null) {
13845
+ if (ctx.data.length < def.minLength.value) {
13846
+ addIssueToContext(ctx, {
13847
+ code: ZodIssueCode.too_small,
13848
+ minimum: def.minLength.value,
13849
+ type: "array",
13850
+ inclusive: true,
13851
+ exact: false,
13852
+ message: def.minLength.message
13853
+ });
13854
+ status.dirty();
13855
+ }
13856
+ }
13857
+ if (def.maxLength !== null) {
13858
+ if (ctx.data.length > def.maxLength.value) {
13859
+ addIssueToContext(ctx, {
13860
+ code: ZodIssueCode.too_big,
13861
+ maximum: def.maxLength.value,
13862
+ type: "array",
13863
+ inclusive: true,
13864
+ exact: false,
13865
+ message: def.maxLength.message
13866
+ });
13867
+ status.dirty();
13868
+ }
13869
+ }
13870
+ if (ctx.common.async) {
13871
+ return Promise.all([...ctx.data].map((item, i) => {
13872
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
13873
+ })).then((result2) => {
13874
+ return ParseStatus.mergeArray(status, result2);
13875
+ });
13876
+ }
13877
+ const result = [...ctx.data].map((item, i) => {
13878
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
13879
+ });
13880
+ return ParseStatus.mergeArray(status, result);
13881
+ }
13882
+ get element() {
13883
+ return this._def.type;
13884
+ }
13885
+ min(minLength, message) {
13886
+ return new _ZodArray({
13887
+ ...this._def,
13888
+ minLength: { value: minLength, message: errorUtil.toString(message) }
13889
+ });
13890
+ }
13891
+ max(maxLength, message) {
13892
+ return new _ZodArray({
13893
+ ...this._def,
13894
+ maxLength: { value: maxLength, message: errorUtil.toString(message) }
13895
+ });
13896
+ }
13897
+ length(len, message) {
13898
+ return new _ZodArray({
13899
+ ...this._def,
13900
+ exactLength: { value: len, message: errorUtil.toString(message) }
13901
+ });
13902
+ }
13903
+ nonempty(message) {
13904
+ return this.min(1, message);
13905
+ }
13906
+ };
13907
+ ZodArray.create = (schema, params2) => {
13908
+ return new ZodArray({
13909
+ type: schema,
13910
+ minLength: null,
13911
+ maxLength: null,
13912
+ exactLength: null,
13913
+ typeName: ZodFirstPartyTypeKind.ZodArray,
13914
+ ...processCreateParams(params2)
13915
+ });
13916
+ };
13917
+ function deepPartialify(schema) {
13918
+ if (schema instanceof ZodObject) {
13919
+ const newShape = {};
13920
+ for (const key in schema.shape) {
13921
+ const fieldSchema = schema.shape[key];
13922
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
13923
+ }
13924
+ return new ZodObject({
13925
+ ...schema._def,
13926
+ shape: () => newShape
13927
+ });
13928
+ } else if (schema instanceof ZodArray) {
13929
+ return new ZodArray({
13930
+ ...schema._def,
13931
+ type: deepPartialify(schema.element)
13932
+ });
13933
+ } else if (schema instanceof ZodOptional) {
13934
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
13935
+ } else if (schema instanceof ZodNullable) {
13936
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
13937
+ } else if (schema instanceof ZodTuple) {
13938
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
13939
+ } else {
13940
+ return schema;
13941
+ }
13942
+ }
13943
+ var ZodObject = class _ZodObject extends ZodType {
13944
+ constructor() {
13945
+ super(...arguments);
13946
+ this._cached = null;
13947
+ this.nonstrict = this.passthrough;
13948
+ this.augment = this.extend;
13949
+ }
13950
+ _getCached() {
13951
+ if (this._cached !== null)
13952
+ return this._cached;
13953
+ const shape = this._def.shape();
13954
+ const keys2 = util.objectKeys(shape);
13955
+ return this._cached = { shape, keys: keys2 };
13956
+ }
13957
+ _parse(input) {
13958
+ const parsedType = this._getType(input);
13959
+ if (parsedType !== ZodParsedType.object) {
13960
+ const ctx2 = this._getOrReturnCtx(input);
13961
+ addIssueToContext(ctx2, {
13962
+ code: ZodIssueCode.invalid_type,
13963
+ expected: ZodParsedType.object,
13964
+ received: ctx2.parsedType
13965
+ });
13966
+ return INVALID;
13967
+ }
13968
+ const { status, ctx } = this._processInputParams(input);
13969
+ const { shape, keys: shapeKeys } = this._getCached();
13970
+ const extraKeys = [];
13971
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
13972
+ for (const key in ctx.data) {
13973
+ if (!shapeKeys.includes(key)) {
13974
+ extraKeys.push(key);
13975
+ }
13976
+ }
13977
+ }
13978
+ const pairs = [];
13979
+ for (const key of shapeKeys) {
13980
+ const keyValidator = shape[key];
13981
+ const value = ctx.data[key];
13982
+ pairs.push({
13983
+ key: { status: "valid", value: key },
13984
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
13985
+ alwaysSet: key in ctx.data
13986
+ });
13987
+ }
13988
+ if (this._def.catchall instanceof ZodNever) {
13989
+ const unknownKeys = this._def.unknownKeys;
13990
+ if (unknownKeys === "passthrough") {
13991
+ for (const key of extraKeys) {
13992
+ pairs.push({
13993
+ key: { status: "valid", value: key },
13994
+ value: { status: "valid", value: ctx.data[key] }
13995
+ });
13996
+ }
13997
+ } else if (unknownKeys === "strict") {
13998
+ if (extraKeys.length > 0) {
13999
+ addIssueToContext(ctx, {
14000
+ code: ZodIssueCode.unrecognized_keys,
14001
+ keys: extraKeys
14002
+ });
14003
+ status.dirty();
14004
+ }
14005
+ } else if (unknownKeys === "strip")
14006
+ ;
14007
+ else {
14008
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
14009
+ }
14010
+ } else {
14011
+ const catchall = this._def.catchall;
14012
+ for (const key of extraKeys) {
14013
+ const value = ctx.data[key];
14014
+ pairs.push({
14015
+ key: { status: "valid", value: key },
14016
+ value: catchall._parse(
14017
+ new ParseInputLazyPath(ctx, value, ctx.path, key)
14018
+ //, ctx.child(key), value, getParsedType(value)
14019
+ ),
14020
+ alwaysSet: key in ctx.data
14021
+ });
14022
+ }
14023
+ }
14024
+ if (ctx.common.async) {
14025
+ return Promise.resolve().then(async () => {
14026
+ const syncPairs = [];
14027
+ for (const pair of pairs) {
14028
+ const key = await pair.key;
14029
+ const value = await pair.value;
14030
+ syncPairs.push({
14031
+ key,
14032
+ value,
14033
+ alwaysSet: pair.alwaysSet
14034
+ });
14035
+ }
14036
+ return syncPairs;
14037
+ }).then((syncPairs) => {
14038
+ return ParseStatus.mergeObjectSync(status, syncPairs);
14039
+ });
14040
+ } else {
14041
+ return ParseStatus.mergeObjectSync(status, pairs);
14042
+ }
14043
+ }
14044
+ get shape() {
14045
+ return this._def.shape();
14046
+ }
14047
+ strict(message) {
14048
+ errorUtil.errToObj;
14049
+ return new _ZodObject({
14050
+ ...this._def,
14051
+ unknownKeys: "strict",
14052
+ ...message !== void 0 ? {
14053
+ errorMap: (issue, ctx) => {
14054
+ var _a, _b, _c, _d;
14055
+ const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
14056
+ if (issue.code === "unrecognized_keys")
14057
+ return {
14058
+ message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError
14059
+ };
14060
+ return {
14061
+ message: defaultError
14062
+ };
14063
+ }
14064
+ } : {}
14065
+ });
14066
+ }
14067
+ strip() {
14068
+ return new _ZodObject({
14069
+ ...this._def,
14070
+ unknownKeys: "strip"
14071
+ });
14072
+ }
14073
+ passthrough() {
14074
+ return new _ZodObject({
14075
+ ...this._def,
14076
+ unknownKeys: "passthrough"
14077
+ });
14078
+ }
14079
+ // const AugmentFactory =
14080
+ // <Def extends ZodObjectDef>(def: Def) =>
14081
+ // <Augmentation extends ZodRawShape>(
14082
+ // augmentation: Augmentation
14083
+ // ): ZodObject<
14084
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
14085
+ // Def["unknownKeys"],
14086
+ // Def["catchall"]
14087
+ // > => {
14088
+ // return new ZodObject({
14089
+ // ...def,
14090
+ // shape: () => ({
14091
+ // ...def.shape(),
14092
+ // ...augmentation,
14093
+ // }),
14094
+ // }) as any;
14095
+ // };
14096
+ extend(augmentation) {
14097
+ return new _ZodObject({
14098
+ ...this._def,
14099
+ shape: () => ({
14100
+ ...this._def.shape(),
14101
+ ...augmentation
14102
+ })
14103
+ });
14104
+ }
14105
+ /**
14106
+ * Prior to zod@1.0.12 there was a bug in the
14107
+ * inferred type of merged objects. Please
14108
+ * upgrade if you are experiencing issues.
14109
+ */
14110
+ merge(merging) {
14111
+ const merged = new _ZodObject({
14112
+ unknownKeys: merging._def.unknownKeys,
14113
+ catchall: merging._def.catchall,
14114
+ shape: () => ({
14115
+ ...this._def.shape(),
14116
+ ...merging._def.shape()
14117
+ }),
14118
+ typeName: ZodFirstPartyTypeKind.ZodObject
14119
+ });
14120
+ return merged;
14121
+ }
14122
+ // merge<
14123
+ // Incoming extends AnyZodObject,
14124
+ // Augmentation extends Incoming["shape"],
14125
+ // NewOutput extends {
14126
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
14127
+ // ? Augmentation[k]["_output"]
14128
+ // : k extends keyof Output
14129
+ // ? Output[k]
14130
+ // : never;
14131
+ // },
14132
+ // NewInput extends {
14133
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
14134
+ // ? Augmentation[k]["_input"]
14135
+ // : k extends keyof Input
14136
+ // ? Input[k]
14137
+ // : never;
14138
+ // }
14139
+ // >(
14140
+ // merging: Incoming
14141
+ // ): ZodObject<
14142
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
14143
+ // Incoming["_def"]["unknownKeys"],
14144
+ // Incoming["_def"]["catchall"],
14145
+ // NewOutput,
14146
+ // NewInput
14147
+ // > {
14148
+ // const merged: any = new ZodObject({
14149
+ // unknownKeys: merging._def.unknownKeys,
14150
+ // catchall: merging._def.catchall,
14151
+ // shape: () =>
14152
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
14153
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
14154
+ // }) as any;
14155
+ // return merged;
14156
+ // }
14157
+ setKey(key, schema) {
14158
+ return this.augment({ [key]: schema });
14159
+ }
14160
+ // merge<Incoming extends AnyZodObject>(
14161
+ // merging: Incoming
14162
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
14163
+ // ZodObject<
14164
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
14165
+ // Incoming["_def"]["unknownKeys"],
14166
+ // Incoming["_def"]["catchall"]
14167
+ // > {
14168
+ // // const mergedShape = objectUtil.mergeShapes(
14169
+ // // this._def.shape(),
14170
+ // // merging._def.shape()
14171
+ // // );
14172
+ // const merged: any = new ZodObject({
14173
+ // unknownKeys: merging._def.unknownKeys,
14174
+ // catchall: merging._def.catchall,
14175
+ // shape: () =>
14176
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
14177
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
14178
+ // }) as any;
14179
+ // return merged;
14180
+ // }
14181
+ catchall(index2) {
14182
+ return new _ZodObject({
14183
+ ...this._def,
14184
+ catchall: index2
14185
+ });
14186
+ }
14187
+ pick(mask) {
14188
+ const shape = {};
14189
+ util.objectKeys(mask).forEach((key) => {
14190
+ if (mask[key] && this.shape[key]) {
14191
+ shape[key] = this.shape[key];
14192
+ }
14193
+ });
14194
+ return new _ZodObject({
14195
+ ...this._def,
14196
+ shape: () => shape
14197
+ });
14198
+ }
14199
+ omit(mask) {
14200
+ const shape = {};
14201
+ util.objectKeys(this.shape).forEach((key) => {
14202
+ if (!mask[key]) {
14203
+ shape[key] = this.shape[key];
14204
+ }
14205
+ });
14206
+ return new _ZodObject({
14207
+ ...this._def,
14208
+ shape: () => shape
14209
+ });
14210
+ }
14211
+ /**
14212
+ * @deprecated
14213
+ */
14214
+ deepPartial() {
14215
+ return deepPartialify(this);
14216
+ }
14217
+ partial(mask) {
14218
+ const newShape = {};
14219
+ util.objectKeys(this.shape).forEach((key) => {
14220
+ const fieldSchema = this.shape[key];
14221
+ if (mask && !mask[key]) {
14222
+ newShape[key] = fieldSchema;
14223
+ } else {
14224
+ newShape[key] = fieldSchema.optional();
14225
+ }
14226
+ });
14227
+ return new _ZodObject({
14228
+ ...this._def,
14229
+ shape: () => newShape
14230
+ });
14231
+ }
14232
+ required(mask) {
14233
+ const newShape = {};
14234
+ util.objectKeys(this.shape).forEach((key) => {
14235
+ if (mask && !mask[key]) {
14236
+ newShape[key] = this.shape[key];
14237
+ } else {
14238
+ const fieldSchema = this.shape[key];
14239
+ let newField = fieldSchema;
14240
+ while (newField instanceof ZodOptional) {
14241
+ newField = newField._def.innerType;
14242
+ }
14243
+ newShape[key] = newField;
14244
+ }
14245
+ });
14246
+ return new _ZodObject({
14247
+ ...this._def,
14248
+ shape: () => newShape
14249
+ });
14250
+ }
14251
+ keyof() {
14252
+ return createZodEnum(util.objectKeys(this.shape));
14253
+ }
14254
+ };
14255
+ ZodObject.create = (shape, params2) => {
14256
+ return new ZodObject({
14257
+ shape: () => shape,
14258
+ unknownKeys: "strip",
14259
+ catchall: ZodNever.create(),
14260
+ typeName: ZodFirstPartyTypeKind.ZodObject,
14261
+ ...processCreateParams(params2)
14262
+ });
14263
+ };
14264
+ ZodObject.strictCreate = (shape, params2) => {
14265
+ return new ZodObject({
14266
+ shape: () => shape,
14267
+ unknownKeys: "strict",
14268
+ catchall: ZodNever.create(),
14269
+ typeName: ZodFirstPartyTypeKind.ZodObject,
14270
+ ...processCreateParams(params2)
14271
+ });
14272
+ };
14273
+ ZodObject.lazycreate = (shape, params2) => {
14274
+ return new ZodObject({
14275
+ shape,
14276
+ unknownKeys: "strip",
14277
+ catchall: ZodNever.create(),
14278
+ typeName: ZodFirstPartyTypeKind.ZodObject,
14279
+ ...processCreateParams(params2)
14280
+ });
14281
+ };
14282
+ var ZodUnion = class extends ZodType {
14283
+ _parse(input) {
14284
+ const { ctx } = this._processInputParams(input);
14285
+ const options2 = this._def.options;
14286
+ function handleResults(results) {
14287
+ for (const result of results) {
14288
+ if (result.result.status === "valid") {
14289
+ return result.result;
14290
+ }
14291
+ }
14292
+ for (const result of results) {
14293
+ if (result.result.status === "dirty") {
14294
+ ctx.common.issues.push(...result.ctx.common.issues);
14295
+ return result.result;
14296
+ }
14297
+ }
14298
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
14299
+ addIssueToContext(ctx, {
14300
+ code: ZodIssueCode.invalid_union,
14301
+ unionErrors
14302
+ });
14303
+ return INVALID;
14304
+ }
14305
+ if (ctx.common.async) {
14306
+ return Promise.all(options2.map(async (option) => {
14307
+ const childCtx = {
14308
+ ...ctx,
14309
+ common: {
14310
+ ...ctx.common,
14311
+ issues: []
14312
+ },
14313
+ parent: null
14314
+ };
14315
+ return {
14316
+ result: await option._parseAsync({
14317
+ data: ctx.data,
14318
+ path: ctx.path,
14319
+ parent: childCtx
14320
+ }),
14321
+ ctx: childCtx
14322
+ };
14323
+ })).then(handleResults);
14324
+ } else {
14325
+ let dirty = void 0;
14326
+ const issues = [];
14327
+ for (const option of options2) {
14328
+ const childCtx = {
14329
+ ...ctx,
14330
+ common: {
14331
+ ...ctx.common,
14332
+ issues: []
14333
+ },
14334
+ parent: null
14335
+ };
14336
+ const result = option._parseSync({
14337
+ data: ctx.data,
14338
+ path: ctx.path,
14339
+ parent: childCtx
14340
+ });
14341
+ if (result.status === "valid") {
14342
+ return result;
14343
+ } else if (result.status === "dirty" && !dirty) {
14344
+ dirty = { result, ctx: childCtx };
14345
+ }
14346
+ if (childCtx.common.issues.length) {
14347
+ issues.push(childCtx.common.issues);
14348
+ }
14349
+ }
14350
+ if (dirty) {
14351
+ ctx.common.issues.push(...dirty.ctx.common.issues);
14352
+ return dirty.result;
14353
+ }
14354
+ const unionErrors = issues.map((issues2) => new ZodError(issues2));
14355
+ addIssueToContext(ctx, {
14356
+ code: ZodIssueCode.invalid_union,
14357
+ unionErrors
14358
+ });
14359
+ return INVALID;
14360
+ }
14361
+ }
14362
+ get options() {
14363
+ return this._def.options;
14364
+ }
14365
+ };
14366
+ ZodUnion.create = (types, params2) => {
14367
+ return new ZodUnion({
14368
+ options: types,
14369
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
14370
+ ...processCreateParams(params2)
14371
+ });
14372
+ };
14373
+ var getDiscriminator = (type) => {
14374
+ if (type instanceof ZodLazy) {
14375
+ return getDiscriminator(type.schema);
14376
+ } else if (type instanceof ZodEffects) {
14377
+ return getDiscriminator(type.innerType());
14378
+ } else if (type instanceof ZodLiteral) {
14379
+ return [type.value];
14380
+ } else if (type instanceof ZodEnum) {
14381
+ return type.options;
14382
+ } else if (type instanceof ZodNativeEnum) {
14383
+ return util.objectValues(type.enum);
14384
+ } else if (type instanceof ZodDefault) {
14385
+ return getDiscriminator(type._def.innerType);
14386
+ } else if (type instanceof ZodUndefined) {
14387
+ return [void 0];
14388
+ } else if (type instanceof ZodNull) {
14389
+ return [null];
14390
+ } else if (type instanceof ZodOptional) {
14391
+ return [void 0, ...getDiscriminator(type.unwrap())];
14392
+ } else if (type instanceof ZodNullable) {
14393
+ return [null, ...getDiscriminator(type.unwrap())];
14394
+ } else if (type instanceof ZodBranded) {
14395
+ return getDiscriminator(type.unwrap());
14396
+ } else if (type instanceof ZodReadonly) {
14397
+ return getDiscriminator(type.unwrap());
14398
+ } else if (type instanceof ZodCatch) {
14399
+ return getDiscriminator(type._def.innerType);
14400
+ } else {
14401
+ return [];
14402
+ }
14403
+ };
14404
+ var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
14405
+ _parse(input) {
14406
+ const { ctx } = this._processInputParams(input);
14407
+ if (ctx.parsedType !== ZodParsedType.object) {
14408
+ addIssueToContext(ctx, {
14409
+ code: ZodIssueCode.invalid_type,
14410
+ expected: ZodParsedType.object,
14411
+ received: ctx.parsedType
14412
+ });
14413
+ return INVALID;
14414
+ }
14415
+ const discriminator = this.discriminator;
14416
+ const discriminatorValue = ctx.data[discriminator];
14417
+ const option = this.optionsMap.get(discriminatorValue);
14418
+ if (!option) {
14419
+ addIssueToContext(ctx, {
14420
+ code: ZodIssueCode.invalid_union_discriminator,
14421
+ options: Array.from(this.optionsMap.keys()),
14422
+ path: [discriminator]
14423
+ });
14424
+ return INVALID;
14425
+ }
14426
+ if (ctx.common.async) {
14427
+ return option._parseAsync({
14428
+ data: ctx.data,
14429
+ path: ctx.path,
14430
+ parent: ctx
14431
+ });
14432
+ } else {
14433
+ return option._parseSync({
14434
+ data: ctx.data,
14435
+ path: ctx.path,
14436
+ parent: ctx
14437
+ });
14438
+ }
14439
+ }
14440
+ get discriminator() {
14441
+ return this._def.discriminator;
14442
+ }
14443
+ get options() {
14444
+ return this._def.options;
14445
+ }
14446
+ get optionsMap() {
14447
+ return this._def.optionsMap;
14448
+ }
14449
+ /**
14450
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
14451
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
14452
+ * have a different value for each object in the union.
14453
+ * @param discriminator the name of the discriminator property
14454
+ * @param types an array of object schemas
14455
+ * @param params
14456
+ */
14457
+ static create(discriminator, options2, params2) {
14458
+ const optionsMap = /* @__PURE__ */ new Map();
14459
+ for (const type of options2) {
14460
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
14461
+ if (!discriminatorValues.length) {
14462
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
14463
+ }
14464
+ for (const value of discriminatorValues) {
14465
+ if (optionsMap.has(value)) {
14466
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
14467
+ }
14468
+ optionsMap.set(value, type);
14469
+ }
14470
+ }
14471
+ return new _ZodDiscriminatedUnion({
14472
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
14473
+ discriminator,
14474
+ options: options2,
14475
+ optionsMap,
14476
+ ...processCreateParams(params2)
14477
+ });
14478
+ }
14479
+ };
14480
+ function mergeValues(a, b) {
14481
+ const aType = getParsedType(a);
14482
+ const bType = getParsedType(b);
14483
+ if (a === b) {
14484
+ return { valid: true, data: a };
14485
+ } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
14486
+ const bKeys = util.objectKeys(b);
14487
+ const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
14488
+ const newObj = { ...a, ...b };
14489
+ for (const key of sharedKeys) {
14490
+ const sharedValue = mergeValues(a[key], b[key]);
14491
+ if (!sharedValue.valid) {
14492
+ return { valid: false };
14493
+ }
14494
+ newObj[key] = sharedValue.data;
14495
+ }
14496
+ return { valid: true, data: newObj };
14497
+ } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
14498
+ if (a.length !== b.length) {
14499
+ return { valid: false };
14500
+ }
14501
+ const newArray = [];
14502
+ for (let index2 = 0; index2 < a.length; index2++) {
14503
+ const itemA = a[index2];
14504
+ const itemB = b[index2];
14505
+ const sharedValue = mergeValues(itemA, itemB);
14506
+ if (!sharedValue.valid) {
14507
+ return { valid: false };
14508
+ }
14509
+ newArray.push(sharedValue.data);
14510
+ }
14511
+ return { valid: true, data: newArray };
14512
+ } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
14513
+ return { valid: true, data: a };
14514
+ } else {
14515
+ return { valid: false };
14516
+ }
14517
+ }
14518
+ var ZodIntersection = class extends ZodType {
14519
+ _parse(input) {
14520
+ const { status, ctx } = this._processInputParams(input);
14521
+ const handleParsed = (parsedLeft, parsedRight) => {
14522
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
14523
+ return INVALID;
14524
+ }
14525
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
14526
+ if (!merged.valid) {
14527
+ addIssueToContext(ctx, {
14528
+ code: ZodIssueCode.invalid_intersection_types
14529
+ });
14530
+ return INVALID;
14531
+ }
14532
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
14533
+ status.dirty();
14534
+ }
14535
+ return { status: status.value, value: merged.data };
14536
+ };
14537
+ if (ctx.common.async) {
14538
+ return Promise.all([
14539
+ this._def.left._parseAsync({
14540
+ data: ctx.data,
14541
+ path: ctx.path,
14542
+ parent: ctx
14543
+ }),
14544
+ this._def.right._parseAsync({
14545
+ data: ctx.data,
14546
+ path: ctx.path,
14547
+ parent: ctx
14548
+ })
14549
+ ]).then(([left, right]) => handleParsed(left, right));
14550
+ } else {
14551
+ return handleParsed(this._def.left._parseSync({
14552
+ data: ctx.data,
14553
+ path: ctx.path,
14554
+ parent: ctx
14555
+ }), this._def.right._parseSync({
14556
+ data: ctx.data,
14557
+ path: ctx.path,
14558
+ parent: ctx
14559
+ }));
14560
+ }
14561
+ }
14562
+ };
14563
+ ZodIntersection.create = (left, right, params2) => {
14564
+ return new ZodIntersection({
14565
+ left,
14566
+ right,
14567
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
14568
+ ...processCreateParams(params2)
14569
+ });
14570
+ };
14571
+ var ZodTuple = class _ZodTuple extends ZodType {
14572
+ _parse(input) {
14573
+ const { status, ctx } = this._processInputParams(input);
14574
+ if (ctx.parsedType !== ZodParsedType.array) {
14575
+ addIssueToContext(ctx, {
14576
+ code: ZodIssueCode.invalid_type,
14577
+ expected: ZodParsedType.array,
14578
+ received: ctx.parsedType
14579
+ });
14580
+ return INVALID;
14581
+ }
14582
+ if (ctx.data.length < this._def.items.length) {
14583
+ addIssueToContext(ctx, {
14584
+ code: ZodIssueCode.too_small,
14585
+ minimum: this._def.items.length,
14586
+ inclusive: true,
14587
+ exact: false,
14588
+ type: "array"
14589
+ });
14590
+ return INVALID;
14591
+ }
14592
+ const rest = this._def.rest;
14593
+ if (!rest && ctx.data.length > this._def.items.length) {
14594
+ addIssueToContext(ctx, {
14595
+ code: ZodIssueCode.too_big,
14596
+ maximum: this._def.items.length,
14597
+ inclusive: true,
14598
+ exact: false,
14599
+ type: "array"
14600
+ });
14601
+ status.dirty();
14602
+ }
14603
+ const items = [...ctx.data].map((item, itemIndex) => {
14604
+ const schema = this._def.items[itemIndex] || this._def.rest;
14605
+ if (!schema)
14606
+ return null;
14607
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
14608
+ }).filter((x) => !!x);
14609
+ if (ctx.common.async) {
14610
+ return Promise.all(items).then((results) => {
14611
+ return ParseStatus.mergeArray(status, results);
14612
+ });
14613
+ } else {
14614
+ return ParseStatus.mergeArray(status, items);
14615
+ }
14616
+ }
14617
+ get items() {
14618
+ return this._def.items;
14619
+ }
14620
+ rest(rest) {
14621
+ return new _ZodTuple({
14622
+ ...this._def,
14623
+ rest
14624
+ });
14625
+ }
14626
+ };
14627
+ ZodTuple.create = (schemas, params2) => {
14628
+ if (!Array.isArray(schemas)) {
14629
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
14630
+ }
14631
+ return new ZodTuple({
14632
+ items: schemas,
14633
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
14634
+ rest: null,
14635
+ ...processCreateParams(params2)
14636
+ });
14637
+ };
14638
+ var ZodRecord = class _ZodRecord extends ZodType {
14639
+ get keySchema() {
14640
+ return this._def.keyType;
14641
+ }
14642
+ get valueSchema() {
14643
+ return this._def.valueType;
14644
+ }
14645
+ _parse(input) {
14646
+ const { status, ctx } = this._processInputParams(input);
14647
+ if (ctx.parsedType !== ZodParsedType.object) {
14648
+ addIssueToContext(ctx, {
14649
+ code: ZodIssueCode.invalid_type,
14650
+ expected: ZodParsedType.object,
14651
+ received: ctx.parsedType
14652
+ });
14653
+ return INVALID;
14654
+ }
14655
+ const pairs = [];
14656
+ const keyType = this._def.keyType;
14657
+ const valueType = this._def.valueType;
14658
+ for (const key in ctx.data) {
14659
+ pairs.push({
14660
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
14661
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
14662
+ alwaysSet: key in ctx.data
14663
+ });
14664
+ }
14665
+ if (ctx.common.async) {
14666
+ return ParseStatus.mergeObjectAsync(status, pairs);
14667
+ } else {
14668
+ return ParseStatus.mergeObjectSync(status, pairs);
14669
+ }
14670
+ }
14671
+ get element() {
14672
+ return this._def.valueType;
14673
+ }
14674
+ static create(first, second, third) {
14675
+ if (second instanceof ZodType) {
14676
+ return new _ZodRecord({
14677
+ keyType: first,
14678
+ valueType: second,
14679
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
14680
+ ...processCreateParams(third)
14681
+ });
14682
+ }
14683
+ return new _ZodRecord({
14684
+ keyType: ZodString.create(),
14685
+ valueType: first,
14686
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
14687
+ ...processCreateParams(second)
14688
+ });
14689
+ }
14690
+ };
14691
+ var ZodMap = class extends ZodType {
14692
+ get keySchema() {
14693
+ return this._def.keyType;
14694
+ }
14695
+ get valueSchema() {
14696
+ return this._def.valueType;
14697
+ }
14698
+ _parse(input) {
14699
+ const { status, ctx } = this._processInputParams(input);
14700
+ if (ctx.parsedType !== ZodParsedType.map) {
14701
+ addIssueToContext(ctx, {
14702
+ code: ZodIssueCode.invalid_type,
14703
+ expected: ZodParsedType.map,
14704
+ received: ctx.parsedType
14705
+ });
14706
+ return INVALID;
14707
+ }
14708
+ const keyType = this._def.keyType;
14709
+ const valueType = this._def.valueType;
14710
+ const pairs = [...ctx.data.entries()].map(([key, value], index2) => {
14711
+ return {
14712
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index2, "key"])),
14713
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index2, "value"]))
14714
+ };
14715
+ });
14716
+ if (ctx.common.async) {
14717
+ const finalMap = /* @__PURE__ */ new Map();
14718
+ return Promise.resolve().then(async () => {
14719
+ for (const pair of pairs) {
14720
+ const key = await pair.key;
14721
+ const value = await pair.value;
14722
+ if (key.status === "aborted" || value.status === "aborted") {
14723
+ return INVALID;
14724
+ }
14725
+ if (key.status === "dirty" || value.status === "dirty") {
14726
+ status.dirty();
14727
+ }
14728
+ finalMap.set(key.value, value.value);
14729
+ }
14730
+ return { status: status.value, value: finalMap };
14731
+ });
14732
+ } else {
14733
+ const finalMap = /* @__PURE__ */ new Map();
14734
+ for (const pair of pairs) {
14735
+ const key = pair.key;
14736
+ const value = pair.value;
14737
+ if (key.status === "aborted" || value.status === "aborted") {
14738
+ return INVALID;
14739
+ }
14740
+ if (key.status === "dirty" || value.status === "dirty") {
14741
+ status.dirty();
14742
+ }
14743
+ finalMap.set(key.value, value.value);
14744
+ }
14745
+ return { status: status.value, value: finalMap };
14746
+ }
14747
+ }
14748
+ };
14749
+ ZodMap.create = (keyType, valueType, params2) => {
14750
+ return new ZodMap({
14751
+ valueType,
14752
+ keyType,
14753
+ typeName: ZodFirstPartyTypeKind.ZodMap,
14754
+ ...processCreateParams(params2)
14755
+ });
14756
+ };
14757
+ var ZodSet = class _ZodSet extends ZodType {
14758
+ _parse(input) {
14759
+ const { status, ctx } = this._processInputParams(input);
14760
+ if (ctx.parsedType !== ZodParsedType.set) {
14761
+ addIssueToContext(ctx, {
14762
+ code: ZodIssueCode.invalid_type,
14763
+ expected: ZodParsedType.set,
14764
+ received: ctx.parsedType
14765
+ });
14766
+ return INVALID;
14767
+ }
14768
+ const def = this._def;
14769
+ if (def.minSize !== null) {
14770
+ if (ctx.data.size < def.minSize.value) {
14771
+ addIssueToContext(ctx, {
14772
+ code: ZodIssueCode.too_small,
14773
+ minimum: def.minSize.value,
14774
+ type: "set",
14775
+ inclusive: true,
14776
+ exact: false,
14777
+ message: def.minSize.message
14778
+ });
14779
+ status.dirty();
14780
+ }
14781
+ }
14782
+ if (def.maxSize !== null) {
14783
+ if (ctx.data.size > def.maxSize.value) {
14784
+ addIssueToContext(ctx, {
14785
+ code: ZodIssueCode.too_big,
14786
+ maximum: def.maxSize.value,
14787
+ type: "set",
14788
+ inclusive: true,
14789
+ exact: false,
14790
+ message: def.maxSize.message
14791
+ });
14792
+ status.dirty();
14793
+ }
14794
+ }
14795
+ const valueType = this._def.valueType;
14796
+ function finalizeSet(elements2) {
14797
+ const parsedSet = /* @__PURE__ */ new Set();
14798
+ for (const element of elements2) {
14799
+ if (element.status === "aborted")
14800
+ return INVALID;
14801
+ if (element.status === "dirty")
14802
+ status.dirty();
14803
+ parsedSet.add(element.value);
14804
+ }
14805
+ return { status: status.value, value: parsedSet };
14806
+ }
14807
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
14808
+ if (ctx.common.async) {
14809
+ return Promise.all(elements).then((elements2) => finalizeSet(elements2));
14810
+ } else {
14811
+ return finalizeSet(elements);
14812
+ }
14813
+ }
14814
+ min(minSize, message) {
14815
+ return new _ZodSet({
14816
+ ...this._def,
14817
+ minSize: { value: minSize, message: errorUtil.toString(message) }
14818
+ });
14819
+ }
14820
+ max(maxSize, message) {
14821
+ return new _ZodSet({
14822
+ ...this._def,
14823
+ maxSize: { value: maxSize, message: errorUtil.toString(message) }
14824
+ });
14825
+ }
14826
+ size(size, message) {
14827
+ return this.min(size, message).max(size, message);
14828
+ }
14829
+ nonempty(message) {
14830
+ return this.min(1, message);
14831
+ }
14832
+ };
14833
+ ZodSet.create = (valueType, params2) => {
14834
+ return new ZodSet({
14835
+ valueType,
14836
+ minSize: null,
14837
+ maxSize: null,
14838
+ typeName: ZodFirstPartyTypeKind.ZodSet,
14839
+ ...processCreateParams(params2)
14840
+ });
14841
+ };
14842
+ var ZodFunction = class _ZodFunction extends ZodType {
14843
+ constructor() {
14844
+ super(...arguments);
14845
+ this.validate = this.implement;
14846
+ }
14847
+ _parse(input) {
14848
+ const { ctx } = this._processInputParams(input);
14849
+ if (ctx.parsedType !== ZodParsedType.function) {
14850
+ addIssueToContext(ctx, {
14851
+ code: ZodIssueCode.invalid_type,
14852
+ expected: ZodParsedType.function,
14853
+ received: ctx.parsedType
14854
+ });
14855
+ return INVALID;
14856
+ }
14857
+ function makeArgsIssue(args, error) {
14858
+ return makeIssue({
14859
+ data: args,
14860
+ path: ctx.path,
14861
+ errorMaps: [
14862
+ ctx.common.contextualErrorMap,
14863
+ ctx.schemaErrorMap,
14864
+ getErrorMap(),
14865
+ errorMap
14866
+ ].filter((x) => !!x),
14867
+ issueData: {
14868
+ code: ZodIssueCode.invalid_arguments,
14869
+ argumentsError: error
14870
+ }
14871
+ });
14872
+ }
14873
+ function makeReturnsIssue(returns, error) {
14874
+ return makeIssue({
14875
+ data: returns,
14876
+ path: ctx.path,
14877
+ errorMaps: [
14878
+ ctx.common.contextualErrorMap,
14879
+ ctx.schemaErrorMap,
14880
+ getErrorMap(),
14881
+ errorMap
14882
+ ].filter((x) => !!x),
14883
+ issueData: {
14884
+ code: ZodIssueCode.invalid_return_type,
14885
+ returnTypeError: error
14886
+ }
14887
+ });
14888
+ }
14889
+ const params2 = { errorMap: ctx.common.contextualErrorMap };
14890
+ const fn = ctx.data;
14891
+ if (this._def.returns instanceof ZodPromise) {
14892
+ const me = this;
14893
+ return OK(async function(...args) {
14894
+ const error = new ZodError([]);
14895
+ const parsedArgs = await me._def.args.parseAsync(args, params2).catch((e) => {
14896
+ error.addIssue(makeArgsIssue(args, e));
14897
+ throw error;
14898
+ });
14899
+ const result = await Reflect.apply(fn, this, parsedArgs);
14900
+ const parsedReturns = await me._def.returns._def.type.parseAsync(result, params2).catch((e) => {
14901
+ error.addIssue(makeReturnsIssue(result, e));
14902
+ throw error;
14903
+ });
14904
+ return parsedReturns;
14905
+ });
14906
+ } else {
14907
+ const me = this;
14908
+ return OK(function(...args) {
14909
+ const parsedArgs = me._def.args.safeParse(args, params2);
14910
+ if (!parsedArgs.success) {
14911
+ throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
14912
+ }
14913
+ const result = Reflect.apply(fn, this, parsedArgs.data);
14914
+ const parsedReturns = me._def.returns.safeParse(result, params2);
14915
+ if (!parsedReturns.success) {
14916
+ throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
14917
+ }
14918
+ return parsedReturns.data;
14919
+ });
14920
+ }
14921
+ }
14922
+ parameters() {
14923
+ return this._def.args;
14924
+ }
14925
+ returnType() {
14926
+ return this._def.returns;
14927
+ }
14928
+ args(...items) {
14929
+ return new _ZodFunction({
14930
+ ...this._def,
14931
+ args: ZodTuple.create(items).rest(ZodUnknown.create())
14932
+ });
14933
+ }
14934
+ returns(returnType) {
14935
+ return new _ZodFunction({
14936
+ ...this._def,
14937
+ returns: returnType
14938
+ });
14939
+ }
14940
+ implement(func) {
14941
+ const validatedFunc = this.parse(func);
14942
+ return validatedFunc;
14943
+ }
14944
+ strictImplement(func) {
14945
+ const validatedFunc = this.parse(func);
14946
+ return validatedFunc;
14947
+ }
14948
+ static create(args, returns, params2) {
14949
+ return new _ZodFunction({
14950
+ args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
14951
+ returns: returns || ZodUnknown.create(),
14952
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
14953
+ ...processCreateParams(params2)
14954
+ });
14955
+ }
14956
+ };
14957
+ var ZodLazy = class extends ZodType {
14958
+ get schema() {
14959
+ return this._def.getter();
14960
+ }
14961
+ _parse(input) {
14962
+ const { ctx } = this._processInputParams(input);
14963
+ const lazySchema = this._def.getter();
14964
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
14965
+ }
14966
+ };
14967
+ ZodLazy.create = (getter, params2) => {
14968
+ return new ZodLazy({
14969
+ getter,
14970
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
14971
+ ...processCreateParams(params2)
14972
+ });
14973
+ };
14974
+ var ZodLiteral = class extends ZodType {
14975
+ _parse(input) {
14976
+ if (input.data !== this._def.value) {
14977
+ const ctx = this._getOrReturnCtx(input);
14978
+ addIssueToContext(ctx, {
14979
+ received: ctx.data,
14980
+ code: ZodIssueCode.invalid_literal,
14981
+ expected: this._def.value
14982
+ });
14983
+ return INVALID;
14984
+ }
14985
+ return { status: "valid", value: input.data };
14986
+ }
14987
+ get value() {
14988
+ return this._def.value;
14989
+ }
14990
+ };
14991
+ ZodLiteral.create = (value, params2) => {
14992
+ return new ZodLiteral({
14993
+ value,
14994
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
14995
+ ...processCreateParams(params2)
14996
+ });
14997
+ };
14998
+ function createZodEnum(values2, params2) {
14999
+ return new ZodEnum({
15000
+ values: values2,
15001
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
15002
+ ...processCreateParams(params2)
15003
+ });
15004
+ }
15005
+ var ZodEnum = class _ZodEnum extends ZodType {
15006
+ constructor() {
15007
+ super(...arguments);
15008
+ _ZodEnum_cache.set(this, void 0);
15009
+ }
15010
+ _parse(input) {
15011
+ if (typeof input.data !== "string") {
15012
+ const ctx = this._getOrReturnCtx(input);
15013
+ const expectedValues = this._def.values;
15014
+ addIssueToContext(ctx, {
15015
+ expected: util.joinValues(expectedValues),
15016
+ received: ctx.parsedType,
15017
+ code: ZodIssueCode.invalid_type
15018
+ });
15019
+ return INVALID;
15020
+ }
15021
+ if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f")) {
15022
+ __classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values), "f");
15023
+ }
15024
+ if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f").has(input.data)) {
15025
+ const ctx = this._getOrReturnCtx(input);
15026
+ const expectedValues = this._def.values;
15027
+ addIssueToContext(ctx, {
15028
+ received: ctx.data,
15029
+ code: ZodIssueCode.invalid_enum_value,
15030
+ options: expectedValues
15031
+ });
15032
+ return INVALID;
15033
+ }
15034
+ return OK(input.data);
15035
+ }
15036
+ get options() {
15037
+ return this._def.values;
15038
+ }
15039
+ get enum() {
15040
+ const enumValues = {};
15041
+ for (const val of this._def.values) {
15042
+ enumValues[val] = val;
15043
+ }
15044
+ return enumValues;
15045
+ }
15046
+ get Values() {
15047
+ const enumValues = {};
15048
+ for (const val of this._def.values) {
15049
+ enumValues[val] = val;
15050
+ }
15051
+ return enumValues;
15052
+ }
15053
+ get Enum() {
15054
+ const enumValues = {};
15055
+ for (const val of this._def.values) {
15056
+ enumValues[val] = val;
15057
+ }
15058
+ return enumValues;
15059
+ }
15060
+ extract(values2, newDef = this._def) {
15061
+ return _ZodEnum.create(values2, {
15062
+ ...this._def,
15063
+ ...newDef
15064
+ });
15065
+ }
15066
+ exclude(values2, newDef = this._def) {
15067
+ return _ZodEnum.create(this.options.filter((opt) => !values2.includes(opt)), {
15068
+ ...this._def,
15069
+ ...newDef
15070
+ });
15071
+ }
15072
+ };
15073
+ _ZodEnum_cache = /* @__PURE__ */ new WeakMap();
15074
+ ZodEnum.create = createZodEnum;
15075
+ var ZodNativeEnum = class extends ZodType {
15076
+ constructor() {
15077
+ super(...arguments);
15078
+ _ZodNativeEnum_cache.set(this, void 0);
15079
+ }
15080
+ _parse(input) {
15081
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
15082
+ const ctx = this._getOrReturnCtx(input);
15083
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
15084
+ const expectedValues = util.objectValues(nativeEnumValues);
15085
+ addIssueToContext(ctx, {
15086
+ expected: util.joinValues(expectedValues),
15087
+ received: ctx.parsedType,
15088
+ code: ZodIssueCode.invalid_type
15089
+ });
15090
+ return INVALID;
15091
+ }
15092
+ if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f")) {
15093
+ __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)), "f");
15094
+ }
15095
+ if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f").has(input.data)) {
15096
+ const expectedValues = util.objectValues(nativeEnumValues);
15097
+ addIssueToContext(ctx, {
15098
+ received: ctx.data,
15099
+ code: ZodIssueCode.invalid_enum_value,
15100
+ options: expectedValues
15101
+ });
15102
+ return INVALID;
15103
+ }
15104
+ return OK(input.data);
15105
+ }
15106
+ get enum() {
15107
+ return this._def.values;
15108
+ }
15109
+ };
15110
+ _ZodNativeEnum_cache = /* @__PURE__ */ new WeakMap();
15111
+ ZodNativeEnum.create = (values2, params2) => {
15112
+ return new ZodNativeEnum({
15113
+ values: values2,
15114
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
15115
+ ...processCreateParams(params2)
15116
+ });
15117
+ };
15118
+ var ZodPromise = class extends ZodType {
15119
+ unwrap() {
15120
+ return this._def.type;
15121
+ }
15122
+ _parse(input) {
15123
+ const { ctx } = this._processInputParams(input);
15124
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
15125
+ addIssueToContext(ctx, {
15126
+ code: ZodIssueCode.invalid_type,
15127
+ expected: ZodParsedType.promise,
15128
+ received: ctx.parsedType
15129
+ });
15130
+ return INVALID;
15131
+ }
15132
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
15133
+ return OK(promisified.then((data) => {
15134
+ return this._def.type.parseAsync(data, {
15135
+ path: ctx.path,
15136
+ errorMap: ctx.common.contextualErrorMap
15137
+ });
15138
+ }));
15139
+ }
15140
+ };
15141
+ ZodPromise.create = (schema, params2) => {
15142
+ return new ZodPromise({
15143
+ type: schema,
15144
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
15145
+ ...processCreateParams(params2)
15146
+ });
15147
+ };
15148
+ var ZodEffects = class extends ZodType {
15149
+ innerType() {
15150
+ return this._def.schema;
15151
+ }
15152
+ sourceType() {
15153
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
15154
+ }
15155
+ _parse(input) {
15156
+ const { status, ctx } = this._processInputParams(input);
15157
+ const effect = this._def.effect || null;
15158
+ const checkCtx = {
15159
+ addIssue: (arg) => {
15160
+ addIssueToContext(ctx, arg);
15161
+ if (arg.fatal) {
15162
+ status.abort();
15163
+ } else {
15164
+ status.dirty();
15165
+ }
15166
+ },
15167
+ get path() {
15168
+ return ctx.path;
15169
+ }
15170
+ };
15171
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
15172
+ if (effect.type === "preprocess") {
15173
+ const processed = effect.transform(ctx.data, checkCtx);
15174
+ if (ctx.common.async) {
15175
+ return Promise.resolve(processed).then(async (processed2) => {
15176
+ if (status.value === "aborted")
15177
+ return INVALID;
15178
+ const result = await this._def.schema._parseAsync({
15179
+ data: processed2,
15180
+ path: ctx.path,
15181
+ parent: ctx
15182
+ });
15183
+ if (result.status === "aborted")
15184
+ return INVALID;
15185
+ if (result.status === "dirty")
15186
+ return DIRTY(result.value);
15187
+ if (status.value === "dirty")
15188
+ return DIRTY(result.value);
15189
+ return result;
15190
+ });
15191
+ } else {
15192
+ if (status.value === "aborted")
15193
+ return INVALID;
15194
+ const result = this._def.schema._parseSync({
15195
+ data: processed,
15196
+ path: ctx.path,
15197
+ parent: ctx
15198
+ });
15199
+ if (result.status === "aborted")
15200
+ return INVALID;
15201
+ if (result.status === "dirty")
15202
+ return DIRTY(result.value);
15203
+ if (status.value === "dirty")
15204
+ return DIRTY(result.value);
15205
+ return result;
15206
+ }
15207
+ }
15208
+ if (effect.type === "refinement") {
15209
+ const executeRefinement = (acc) => {
15210
+ const result = effect.refinement(acc, checkCtx);
15211
+ if (ctx.common.async) {
15212
+ return Promise.resolve(result);
15213
+ }
15214
+ if (result instanceof Promise) {
15215
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
15216
+ }
15217
+ return acc;
15218
+ };
15219
+ if (ctx.common.async === false) {
15220
+ const inner = this._def.schema._parseSync({
15221
+ data: ctx.data,
15222
+ path: ctx.path,
15223
+ parent: ctx
15224
+ });
15225
+ if (inner.status === "aborted")
15226
+ return INVALID;
15227
+ if (inner.status === "dirty")
15228
+ status.dirty();
15229
+ executeRefinement(inner.value);
15230
+ return { status: status.value, value: inner.value };
15231
+ } else {
15232
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
15233
+ if (inner.status === "aborted")
15234
+ return INVALID;
15235
+ if (inner.status === "dirty")
15236
+ status.dirty();
15237
+ return executeRefinement(inner.value).then(() => {
15238
+ return { status: status.value, value: inner.value };
15239
+ });
15240
+ });
15241
+ }
15242
+ }
15243
+ if (effect.type === "transform") {
15244
+ if (ctx.common.async === false) {
15245
+ const base2 = this._def.schema._parseSync({
15246
+ data: ctx.data,
15247
+ path: ctx.path,
15248
+ parent: ctx
15249
+ });
15250
+ if (!isValid(base2))
15251
+ return base2;
15252
+ const result = effect.transform(base2.value, checkCtx);
15253
+ if (result instanceof Promise) {
15254
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
15255
+ }
15256
+ return { status: status.value, value: result };
15257
+ } else {
15258
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base2) => {
15259
+ if (!isValid(base2))
15260
+ return base2;
15261
+ return Promise.resolve(effect.transform(base2.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
15262
+ });
15263
+ }
15264
+ }
15265
+ util.assertNever(effect);
15266
+ }
15267
+ };
15268
+ ZodEffects.create = (schema, effect, params2) => {
15269
+ return new ZodEffects({
15270
+ schema,
15271
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
15272
+ effect,
15273
+ ...processCreateParams(params2)
15274
+ });
15275
+ };
15276
+ ZodEffects.createWithPreprocess = (preprocess, schema, params2) => {
15277
+ return new ZodEffects({
15278
+ schema,
15279
+ effect: { type: "preprocess", transform: preprocess },
15280
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
15281
+ ...processCreateParams(params2)
15282
+ });
15283
+ };
15284
+ var ZodOptional = class extends ZodType {
15285
+ _parse(input) {
15286
+ const parsedType = this._getType(input);
15287
+ if (parsedType === ZodParsedType.undefined) {
15288
+ return OK(void 0);
15289
+ }
15290
+ return this._def.innerType._parse(input);
15291
+ }
15292
+ unwrap() {
15293
+ return this._def.innerType;
15294
+ }
15295
+ };
15296
+ ZodOptional.create = (type, params2) => {
15297
+ return new ZodOptional({
15298
+ innerType: type,
15299
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
15300
+ ...processCreateParams(params2)
15301
+ });
15302
+ };
15303
+ var ZodNullable = class extends ZodType {
15304
+ _parse(input) {
15305
+ const parsedType = this._getType(input);
15306
+ if (parsedType === ZodParsedType.null) {
15307
+ return OK(null);
15308
+ }
15309
+ return this._def.innerType._parse(input);
15310
+ }
15311
+ unwrap() {
15312
+ return this._def.innerType;
15313
+ }
15314
+ };
15315
+ ZodNullable.create = (type, params2) => {
15316
+ return new ZodNullable({
15317
+ innerType: type,
15318
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
15319
+ ...processCreateParams(params2)
15320
+ });
15321
+ };
15322
+ var ZodDefault = class extends ZodType {
15323
+ _parse(input) {
15324
+ const { ctx } = this._processInputParams(input);
15325
+ let data = ctx.data;
15326
+ if (ctx.parsedType === ZodParsedType.undefined) {
15327
+ data = this._def.defaultValue();
15328
+ }
15329
+ return this._def.innerType._parse({
15330
+ data,
15331
+ path: ctx.path,
15332
+ parent: ctx
15333
+ });
15334
+ }
15335
+ removeDefault() {
15336
+ return this._def.innerType;
15337
+ }
15338
+ };
15339
+ ZodDefault.create = (type, params2) => {
15340
+ return new ZodDefault({
15341
+ innerType: type,
15342
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
15343
+ defaultValue: typeof params2.default === "function" ? params2.default : () => params2.default,
15344
+ ...processCreateParams(params2)
15345
+ });
15346
+ };
15347
+ var ZodCatch = class extends ZodType {
15348
+ _parse(input) {
15349
+ const { ctx } = this._processInputParams(input);
15350
+ const newCtx = {
15351
+ ...ctx,
15352
+ common: {
15353
+ ...ctx.common,
15354
+ issues: []
15355
+ }
15356
+ };
15357
+ const result = this._def.innerType._parse({
15358
+ data: newCtx.data,
15359
+ path: newCtx.path,
15360
+ parent: {
15361
+ ...newCtx
15362
+ }
15363
+ });
15364
+ if (isAsync(result)) {
15365
+ return result.then((result2) => {
15366
+ return {
15367
+ status: "valid",
15368
+ value: result2.status === "valid" ? result2.value : this._def.catchValue({
15369
+ get error() {
15370
+ return new ZodError(newCtx.common.issues);
15371
+ },
15372
+ input: newCtx.data
15373
+ })
15374
+ };
15375
+ });
15376
+ } else {
15377
+ return {
15378
+ status: "valid",
15379
+ value: result.status === "valid" ? result.value : this._def.catchValue({
15380
+ get error() {
15381
+ return new ZodError(newCtx.common.issues);
15382
+ },
15383
+ input: newCtx.data
15384
+ })
15385
+ };
15386
+ }
15387
+ }
15388
+ removeCatch() {
15389
+ return this._def.innerType;
15390
+ }
15391
+ };
15392
+ ZodCatch.create = (type, params2) => {
15393
+ return new ZodCatch({
15394
+ innerType: type,
15395
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
15396
+ catchValue: typeof params2.catch === "function" ? params2.catch : () => params2.catch,
15397
+ ...processCreateParams(params2)
15398
+ });
15399
+ };
15400
+ var ZodNaN = class extends ZodType {
15401
+ _parse(input) {
15402
+ const parsedType = this._getType(input);
15403
+ if (parsedType !== ZodParsedType.nan) {
15404
+ const ctx = this._getOrReturnCtx(input);
15405
+ addIssueToContext(ctx, {
15406
+ code: ZodIssueCode.invalid_type,
15407
+ expected: ZodParsedType.nan,
15408
+ received: ctx.parsedType
15409
+ });
15410
+ return INVALID;
15411
+ }
15412
+ return { status: "valid", value: input.data };
15413
+ }
15414
+ };
15415
+ ZodNaN.create = (params2) => {
15416
+ return new ZodNaN({
15417
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
15418
+ ...processCreateParams(params2)
15419
+ });
15420
+ };
15421
+ var BRAND = Symbol("zod_brand");
15422
+ var ZodBranded = class extends ZodType {
15423
+ _parse(input) {
15424
+ const { ctx } = this._processInputParams(input);
15425
+ const data = ctx.data;
15426
+ return this._def.type._parse({
15427
+ data,
15428
+ path: ctx.path,
15429
+ parent: ctx
15430
+ });
15431
+ }
15432
+ unwrap() {
15433
+ return this._def.type;
15434
+ }
15435
+ };
15436
+ var ZodPipeline = class _ZodPipeline extends ZodType {
15437
+ _parse(input) {
15438
+ const { status, ctx } = this._processInputParams(input);
15439
+ if (ctx.common.async) {
15440
+ const handleAsync = async () => {
15441
+ const inResult = await this._def.in._parseAsync({
15442
+ data: ctx.data,
15443
+ path: ctx.path,
15444
+ parent: ctx
15445
+ });
15446
+ if (inResult.status === "aborted")
15447
+ return INVALID;
15448
+ if (inResult.status === "dirty") {
15449
+ status.dirty();
15450
+ return DIRTY(inResult.value);
15451
+ } else {
15452
+ return this._def.out._parseAsync({
15453
+ data: inResult.value,
15454
+ path: ctx.path,
15455
+ parent: ctx
15456
+ });
15457
+ }
15458
+ };
15459
+ return handleAsync();
15460
+ } else {
15461
+ const inResult = this._def.in._parseSync({
15462
+ data: ctx.data,
15463
+ path: ctx.path,
15464
+ parent: ctx
15465
+ });
15466
+ if (inResult.status === "aborted")
15467
+ return INVALID;
15468
+ if (inResult.status === "dirty") {
15469
+ status.dirty();
15470
+ return {
15471
+ status: "dirty",
15472
+ value: inResult.value
15473
+ };
15474
+ } else {
15475
+ return this._def.out._parseSync({
15476
+ data: inResult.value,
15477
+ path: ctx.path,
15478
+ parent: ctx
15479
+ });
15480
+ }
15481
+ }
15482
+ }
15483
+ static create(a, b) {
15484
+ return new _ZodPipeline({
15485
+ in: a,
15486
+ out: b,
15487
+ typeName: ZodFirstPartyTypeKind.ZodPipeline
15488
+ });
15489
+ }
15490
+ };
15491
+ var ZodReadonly = class extends ZodType {
15492
+ _parse(input) {
15493
+ const result = this._def.innerType._parse(input);
15494
+ const freeze = (data) => {
15495
+ if (isValid(data)) {
15496
+ data.value = Object.freeze(data.value);
15497
+ }
15498
+ return data;
15499
+ };
15500
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
15501
+ }
15502
+ unwrap() {
15503
+ return this._def.innerType;
15504
+ }
15505
+ };
15506
+ ZodReadonly.create = (type, params2) => {
15507
+ return new ZodReadonly({
15508
+ innerType: type,
15509
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
15510
+ ...processCreateParams(params2)
15511
+ });
15512
+ };
15513
+ function custom(check, params2 = {}, fatal) {
15514
+ if (check)
15515
+ return ZodAny.create().superRefine((data, ctx) => {
15516
+ var _a, _b;
15517
+ if (!check(data)) {
15518
+ const p = typeof params2 === "function" ? params2(data) : typeof params2 === "string" ? { message: params2 } : params2;
15519
+ const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
15520
+ const p2 = typeof p === "string" ? { message: p } : p;
15521
+ ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
15522
+ }
15523
+ });
15524
+ return ZodAny.create();
15525
+ }
15526
+ var late = {
15527
+ object: ZodObject.lazycreate
15528
+ };
15529
+ var ZodFirstPartyTypeKind;
15530
+ (function(ZodFirstPartyTypeKind2) {
15531
+ ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
15532
+ ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
15533
+ ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
15534
+ ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
15535
+ ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
15536
+ ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
15537
+ ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
15538
+ ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
15539
+ ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
15540
+ ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
15541
+ ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
15542
+ ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
15543
+ ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
15544
+ ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
15545
+ ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
15546
+ ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
15547
+ ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
15548
+ ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
15549
+ ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
15550
+ ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
15551
+ ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
15552
+ ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
15553
+ ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
15554
+ ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
15555
+ ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
15556
+ ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
15557
+ ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
15558
+ ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
15559
+ ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
15560
+ ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
15561
+ ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
15562
+ ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
15563
+ ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
15564
+ ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
15565
+ ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
15566
+ ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
15567
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
15568
+ var instanceOfType = (cls, params2 = {
15569
+ message: `Input not instance of ${cls.name}`
15570
+ }) => custom((data) => data instanceof cls, params2);
15571
+ var stringType = ZodString.create;
15572
+ var numberType = ZodNumber.create;
15573
+ var nanType = ZodNaN.create;
15574
+ var bigIntType = ZodBigInt.create;
15575
+ var booleanType = ZodBoolean.create;
15576
+ var dateType = ZodDate.create;
15577
+ var symbolType = ZodSymbol.create;
15578
+ var undefinedType = ZodUndefined.create;
15579
+ var nullType = ZodNull.create;
15580
+ var anyType = ZodAny.create;
15581
+ var unknownType = ZodUnknown.create;
15582
+ var neverType = ZodNever.create;
15583
+ var voidType = ZodVoid.create;
15584
+ var arrayType = ZodArray.create;
15585
+ var objectType = ZodObject.create;
15586
+ var strictObjectType = ZodObject.strictCreate;
15587
+ var unionType = ZodUnion.create;
15588
+ var discriminatedUnionType = ZodDiscriminatedUnion.create;
15589
+ var intersectionType = ZodIntersection.create;
15590
+ var tupleType = ZodTuple.create;
15591
+ var recordType = ZodRecord.create;
15592
+ var mapType = ZodMap.create;
15593
+ var setType = ZodSet.create;
15594
+ var functionType = ZodFunction.create;
15595
+ var lazyType = ZodLazy.create;
15596
+ var literalType = ZodLiteral.create;
15597
+ var enumType = ZodEnum.create;
15598
+ var nativeEnumType = ZodNativeEnum.create;
15599
+ var promiseType = ZodPromise.create;
15600
+ var effectsType = ZodEffects.create;
15601
+ var optionalType = ZodOptional.create;
15602
+ var nullableType = ZodNullable.create;
15603
+ var preprocessType = ZodEffects.createWithPreprocess;
15604
+ var pipelineType = ZodPipeline.create;
15605
+ var ostring = () => stringType().optional();
15606
+ var onumber = () => numberType().optional();
15607
+ var oboolean = () => booleanType().optional();
15608
+ var coerce = {
15609
+ string: (arg) => ZodString.create({ ...arg, coerce: true }),
15610
+ number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
15611
+ boolean: (arg) => ZodBoolean.create({
15612
+ ...arg,
15613
+ coerce: true
15614
+ }),
15615
+ bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
15616
+ date: (arg) => ZodDate.create({ ...arg, coerce: true })
15617
+ };
15618
+ var NEVER = INVALID;
15619
+ var z = /* @__PURE__ */ Object.freeze({
15620
+ __proto__: null,
15621
+ defaultErrorMap: errorMap,
15622
+ setErrorMap,
15623
+ getErrorMap,
15624
+ makeIssue,
15625
+ EMPTY_PATH,
15626
+ addIssueToContext,
15627
+ ParseStatus,
15628
+ INVALID,
15629
+ DIRTY,
15630
+ OK,
15631
+ isAborted,
15632
+ isDirty,
15633
+ isValid,
15634
+ isAsync,
15635
+ get util() {
15636
+ return util;
15637
+ },
15638
+ get objectUtil() {
15639
+ return objectUtil;
15640
+ },
15641
+ ZodParsedType,
15642
+ getParsedType,
15643
+ ZodType,
15644
+ datetimeRegex,
15645
+ ZodString,
15646
+ ZodNumber,
15647
+ ZodBigInt,
15648
+ ZodBoolean,
15649
+ ZodDate,
15650
+ ZodSymbol,
15651
+ ZodUndefined,
15652
+ ZodNull,
15653
+ ZodAny,
15654
+ ZodUnknown,
15655
+ ZodNever,
15656
+ ZodVoid,
15657
+ ZodArray,
15658
+ ZodObject,
15659
+ ZodUnion,
15660
+ ZodDiscriminatedUnion,
15661
+ ZodIntersection,
15662
+ ZodTuple,
15663
+ ZodRecord,
15664
+ ZodMap,
15665
+ ZodSet,
15666
+ ZodFunction,
15667
+ ZodLazy,
15668
+ ZodLiteral,
15669
+ ZodEnum,
15670
+ ZodNativeEnum,
15671
+ ZodPromise,
15672
+ ZodEffects,
15673
+ ZodTransformer: ZodEffects,
15674
+ ZodOptional,
15675
+ ZodNullable,
15676
+ ZodDefault,
15677
+ ZodCatch,
15678
+ ZodNaN,
15679
+ BRAND,
15680
+ ZodBranded,
15681
+ ZodPipeline,
15682
+ ZodReadonly,
15683
+ custom,
15684
+ Schema: ZodType,
15685
+ ZodSchema: ZodType,
15686
+ late,
15687
+ get ZodFirstPartyTypeKind() {
15688
+ return ZodFirstPartyTypeKind;
15689
+ },
15690
+ coerce,
15691
+ any: anyType,
15692
+ array: arrayType,
15693
+ bigint: bigIntType,
15694
+ boolean: booleanType,
15695
+ date: dateType,
15696
+ discriminatedUnion: discriminatedUnionType,
15697
+ effect: effectsType,
15698
+ "enum": enumType,
15699
+ "function": functionType,
15700
+ "instanceof": instanceOfType,
15701
+ intersection: intersectionType,
15702
+ lazy: lazyType,
15703
+ literal: literalType,
15704
+ map: mapType,
15705
+ nan: nanType,
15706
+ nativeEnum: nativeEnumType,
15707
+ never: neverType,
15708
+ "null": nullType,
15709
+ nullable: nullableType,
15710
+ number: numberType,
15711
+ object: objectType,
15712
+ oboolean,
15713
+ onumber,
15714
+ optional: optionalType,
15715
+ ostring,
15716
+ pipeline: pipelineType,
15717
+ preprocess: preprocessType,
15718
+ promise: promiseType,
15719
+ record: recordType,
15720
+ set: setType,
15721
+ strictObject: strictObjectType,
15722
+ string: stringType,
15723
+ symbol: symbolType,
15724
+ transformer: effectsType,
15725
+ tuple: tupleType,
15726
+ "undefined": undefinedType,
15727
+ union: unionType,
15728
+ unknown: unknownType,
15729
+ "void": voidType,
15730
+ NEVER,
15731
+ ZodIssueCode,
15732
+ quotelessJson,
15733
+ ZodError
15734
+ });
15735
+
15736
+ // ../types/src/api/web/app/rows/search.ts
15737
+ var fieldKey = z.string().refine((s) => s !== "_complexIdOperator" /* COMPLEX_ID_OPERATOR */, {
15738
+ message: `Key '${"_complexIdOperator" /* COMPLEX_ID_OPERATOR */}' is not allowed`
15739
+ });
15740
+ var stringBasicFilter = z.record(fieldKey, z.string());
15741
+ var basicFilter = z.record(fieldKey, z.any());
15742
+ var arrayFilter = z.record(fieldKey, z.union([z.any().array(), z.string()]));
15743
+ var logicFilter = z.lazy(
15744
+ () => z.object({
15745
+ conditions: z.array(z.object(queryFilterValidation))
15746
+ })
15747
+ );
15748
+ var stringOrNumber = z.union([z.string(), z.number()]);
15749
+ var queryFilterValidation = {
15750
+ ["string" /* STRING */]: stringBasicFilter.optional(),
15751
+ ["fuzzy" /* FUZZY */]: stringBasicFilter.optional(),
15752
+ ["range" /* RANGE */]: z.record(
15753
+ fieldKey,
15754
+ z.union([
15755
+ z.object({ high: stringOrNumber, low: stringOrNumber }),
15756
+ z.object({ high: stringOrNumber }),
15757
+ z.object({ low: stringOrNumber })
15758
+ ])
15759
+ ).optional(),
15760
+ ["equal" /* EQUAL */]: basicFilter.optional(),
15761
+ ["notEqual" /* NOT_EQUAL */]: basicFilter.optional(),
15762
+ ["empty" /* EMPTY */]: basicFilter.optional(),
15763
+ ["notEmpty" /* NOT_EMPTY */]: basicFilter.optional(),
15764
+ ["oneOf" /* ONE_OF */]: arrayFilter.optional(),
15765
+ ["contains" /* CONTAINS */]: arrayFilter.optional(),
15766
+ ["notContains" /* NOT_CONTAINS */]: arrayFilter.optional(),
15767
+ ["containsAny" /* CONTAINS_ANY */]: arrayFilter.optional(),
15768
+ ["$and" /* AND */]: logicFilter.optional(),
15769
+ ["$or" /* OR */]: logicFilter.optional()
15770
+ };
15771
+ var searchRowRequest = z.object({
15772
+ query: z.object({
15773
+ allOr: z.boolean().optional(),
15774
+ onEmptyFilter: z.nativeEnum(EmptyFilterOption).optional(),
15775
+ ...queryFilterValidation
15776
+ }).optional(),
15777
+ paginate: z.boolean().optional(),
15778
+ bookmark: z.union([z.string(), z.number()]).nullish(),
15779
+ limit: z.number().optional(),
15780
+ sort: z.string().nullish(),
15781
+ sortOrder: z.nativeEnum(SortOrder).optional(),
15782
+ sortType: z.nativeEnum(SortType).nullish(),
15783
+ version: z.string().optional(),
15784
+ disableEscaping: z.boolean().optional(),
15785
+ countRows: z.boolean().optional()
15786
+ });
15787
+
11799
15788
  // src/constants/index.ts
11800
15789
  var constants_exports2 = {};
11801
15790
  __export(constants_exports2, {
@@ -20609,29 +24598,17 @@ var identifyInstallationGroup = async (installId, timestamp) => {
20609
24598
  await identifyGroup(group, timestamp);
20610
24599
  await identify({ ...group, id: `$${type}_${id}` }, timestamp);
20611
24600
  };
20612
- var identifyTenantGroup = async (tenantId, account, timestamp) => {
24601
+ var identifyTenantGroup = async (tenantId, hosting, timestamp) => {
20613
24602
  const id = await getEventTenantId(tenantId);
20614
24603
  const type = "tenant" /* TENANT */;
20615
24604
  const installationId = await getInstallationId();
20616
24605
  const environment2 = getDeploymentEnvironment();
20617
- let hosting;
20618
- let profession;
20619
- let companySize;
20620
- if (account) {
20621
- profession = account.profession;
20622
- companySize = account.size;
20623
- hosting = account.hosting;
20624
- } else {
20625
- hosting = getHostingFromEnv();
20626
- }
20627
24606
  const group = {
20628
24607
  id,
20629
24608
  type,
20630
24609
  hosting,
20631
24610
  environment: environment2,
20632
- installationId,
20633
- profession,
20634
- companySize
24611
+ installationId
20635
24612
  };
20636
24613
  await identifyGroup(group, timestamp);
20637
24614
  await identify({ ...group, id: `$${type}_${id}` }, timestamp);
@@ -20886,8 +24863,8 @@ var getEventKey = (event, properties) => {
20886
24863
  const tenantId = getTenantId();
20887
24864
  if (event) {
20888
24865
  eventKey2 = `${"events" /* EVENTS */}:${tenantId}:${event}`;
20889
- const custom = CUSTOM_PROPERTY_SUFFIX[event];
20890
- const suffix = custom ? custom(properties) : void 0;
24866
+ const custom2 = CUSTOM_PROPERTY_SUFFIX[event];
24867
+ const suffix = custom2 ? custom2(properties) : void 0;
20891
24868
  if (suffix) {
20892
24869
  eventKey2 = `${eventKey2}:${suffix}`;
20893
24870
  }
@@ -24027,12 +28004,14 @@ var FlagSet = class {
24027
28004
  });
24028
28005
  }
24029
28006
  };
24030
- var flags = new FlagSet({
28007
+ var flagsConfig = {
24031
28008
  ["DEFAULT_VALUES" /* DEFAULT_VALUES */]: Flag.boolean(true),
24032
28009
  ["AUTOMATION_BRANCHING" /* AUTOMATION_BRANCHING */]: Flag.boolean(true),
24033
28010
  ["AI_CUSTOM_CONFIGS" /* AI_CUSTOM_CONFIGS */]: Flag.boolean(true),
24034
- ["BUDIBASE_AI" /* BUDIBASE_AI */]: Flag.boolean(true)
24035
- });
28011
+ ["BUDIBASE_AI" /* BUDIBASE_AI */]: Flag.boolean(true),
28012
+ ["USE_ZOD_VALIDATOR" /* USE_ZOD_VALIDATOR */]: Flag.boolean(environment_default.isDev())
28013
+ };
28014
+ var flags = new FlagSet(flagsConfig);
24036
28015
 
24037
28016
  // src/features/tests/utils.ts
24038
28017
  var utils_exports6 = {};
@@ -25669,7 +29648,7 @@ function isIgnoredType(type) {
25669
29648
  const ignored = ["link" /* LINK */, "formula" /* FORMULA */, "ai" /* AI */];
25670
29649
  return ignored.indexOf(type) !== -1;
25671
29650
  }
25672
- function generateSchema(schema, table, tables, oldTable = null, renamed) {
29651
+ function generateSchema(schema, table, tables, oldTable, renamed) {
25673
29652
  let primaryKeys = table && table.primary ? table.primary : [];
25674
29653
  const columns = Object.values(table.schema);
25675
29654
  let metaCols = columns.filter((col) => col.meta);
@@ -25689,7 +29668,7 @@ function generateSchema(schema, table, tables, oldTable = null, renamed) {
25689
29668
  (col) => col.foreignKey
25690
29669
  );
25691
29670
  for (let [key, column] of Object.entries(table.schema)) {
25692
- const oldColumn = oldTable ? oldTable.schema[key] : null;
29671
+ const oldColumn = oldTable?.schema[key];
25693
29672
  if (oldColumn && oldColumn.type || columnTypeSet.includes(key) || renamed?.updated === key) {
25694
29673
  continue;
25695
29674
  }
@@ -25829,16 +29808,15 @@ var SqlTableQueryBuilder = class {
25829
29808
  * @return the operation that was found in the JSON.
25830
29809
  */
25831
29810
  _operation(json) {
25832
- return json.endpoint.operation;
29811
+ return json.operation;
25833
29812
  }
25834
29813
  _tableQuery(json) {
25835
29814
  let client = (0, import_knex.knex)({ client: this.sqlClient }).schema;
25836
- let schemaName = json?.endpoint?.schema;
25837
- if (schemaName) {
25838
- client = client.withSchema(schemaName);
29815
+ if (json?.schema) {
29816
+ client = client.withSchema(json.schema);
25839
29817
  }
25840
29818
  let query;
25841
- if (!json.table || !json.meta || !json.meta.tables) {
29819
+ if (!json.table || !json.tables) {
25842
29820
  throw new Error("Cannot execute without table being specified");
25843
29821
  }
25844
29822
  if (json.table.sourceType === "internal" /* INTERNAL */) {
@@ -25846,15 +29824,15 @@ var SqlTableQueryBuilder = class {
25846
29824
  }
25847
29825
  switch (this._operation(json)) {
25848
29826
  case "CREATE_TABLE" /* CREATE_TABLE */:
25849
- query = buildCreateTable(client, json.table, json.meta.tables);
29827
+ query = buildCreateTable(client, json.table, json.tables);
25850
29828
  break;
25851
29829
  case "UPDATE_TABLE" /* UPDATE_TABLE */:
25852
- if (!json.meta || !json.meta.table) {
29830
+ if (!json.table) {
25853
29831
  throw new Error("Must specify old table for update");
25854
29832
  }
25855
- if (this.sqlClient === "mysql2" /* MY_SQL */ && json.meta.renamed) {
29833
+ if (this.sqlClient === "mysql2" /* MY_SQL */ && json.meta?.renamed) {
25856
29834
  const updatedColumn = json.meta.renamed.updated;
25857
- const tableName = schemaName ? `\`${schemaName}\`.\`${json.table.name}\`` : `\`${json.table.name}\``;
29835
+ const tableName = json?.schema ? `\`${json.schema}\`.\`${json.table.name}\`` : `\`${json.table.name}\``;
25858
29836
  return {
25859
29837
  sql: `alter table ${tableName} rename column \`${json.meta.renamed.old}\` to \`${updatedColumn}\`;`,
25860
29838
  bindings: []
@@ -25863,14 +29841,14 @@ var SqlTableQueryBuilder = class {
25863
29841
  query = buildUpdateTable(
25864
29842
  client,
25865
29843
  json.table,
25866
- json.meta.tables,
25867
- json.meta.table,
25868
- json.meta.renamed
29844
+ json.tables,
29845
+ json.meta?.oldTable,
29846
+ json.meta?.renamed
25869
29847
  );
25870
- if (this.sqlClient === "mssql" /* MS_SQL */ && json.meta.renamed) {
29848
+ if (this.sqlClient === "mssql" /* MS_SQL */ && json.meta?.renamed) {
25871
29849
  const oldColumn = json.meta.renamed.old;
25872
29850
  const updatedColumn = json.meta.renamed.updated;
25873
- const tableName = schemaName ? `${schemaName}.${json.table.name}` : `${json.table.name}`;
29851
+ const tableName = json?.schema ? `${json.schema}.${json.table.name}` : `${json.table.name}`;
25874
29852
  const sql = getNativeSql(query);
25875
29853
  if (Array.isArray(sql)) {
25876
29854
  for (const query2 of sql) {
@@ -25981,11 +29959,11 @@ var InternalBuilder = class {
25981
29959
  this.knex = knex3;
25982
29960
  this.splitter = new filters_exports.ColumnSplitter([this.table], {
25983
29961
  aliases: this.query.tableAliases,
25984
- columnPrefix: this.query.meta.columnPrefix
29962
+ columnPrefix: this.query.meta?.columnPrefix
25985
29963
  });
25986
29964
  }
25987
29965
  get table() {
25988
- return this.query.meta.table;
29966
+ return this.query.table;
25989
29967
  }
25990
29968
  get knexClient() {
25991
29969
  return this.knex.client;
@@ -26074,8 +30052,7 @@ var InternalBuilder = class {
26074
30052
  return parts.join(".");
26075
30053
  }
26076
30054
  isFullSelectStatementRequired() {
26077
- const { meta } = this.query;
26078
- for (let column of Object.values(meta.table.schema)) {
30055
+ for (let column of Object.values(this.table.schema)) {
26079
30056
  if (this.SPECIAL_SELECT_CASES.POSTGRES_MONEY(column)) {
26080
30057
  return true;
26081
30058
  } else if (this.SPECIAL_SELECT_CASES.MSSQL_DATES(column)) {
@@ -26085,29 +30062,29 @@ var InternalBuilder = class {
26085
30062
  return false;
26086
30063
  }
26087
30064
  generateSelectStatement() {
26088
- const { meta, endpoint, resource } = this.query;
30065
+ const { table, resource } = this.query;
26089
30066
  if (!resource || !resource.fields || resource.fields.length === 0) {
26090
30067
  return "*";
26091
30068
  }
26092
- const alias = this.getTableName(endpoint.entityId);
26093
- const schema = meta.table.schema;
30069
+ const alias = this.getTableName(table);
30070
+ const schema = this.table.schema;
26094
30071
  if (!this.isFullSelectStatementRequired()) {
26095
30072
  return [this.knex.raw("??", [`${alias}.*`])];
26096
30073
  }
26097
30074
  return resource.fields.map((field) => {
26098
30075
  const parts = field.split(/\./g);
26099
- let table = void 0;
30076
+ let table2 = void 0;
26100
30077
  let column = parts[0];
26101
30078
  if (parts.length > 1) {
26102
- table = parts[0];
30079
+ table2 = parts[0];
26103
30080
  column = parts.slice(1).join(".");
26104
30081
  }
26105
- return { table, column, field };
26106
- }).filter(({ table }) => !table || table === alias).map(({ table, column, field }) => {
30082
+ return { table: table2, column, field };
30083
+ }).filter(({ table: table2 }) => !table2 || table2 === alias).map(({ table: table2, column, field }) => {
26107
30084
  const columnSchema = schema[column];
26108
30085
  if (this.SPECIAL_SELECT_CASES.POSTGRES_MONEY(columnSchema)) {
26109
30086
  return this.knex.raw(`??::money::numeric as ??`, [
26110
- this.rawQuotedIdentifier([table, column].join(".")),
30087
+ this.rawQuotedIdentifier([table2, column].join(".")),
26111
30088
  this.knex.raw(this.quote(field))
26112
30089
  ]);
26113
30090
  }
@@ -26117,8 +30094,8 @@ var InternalBuilder = class {
26117
30094
  this.knex.raw(this.quote(field))
26118
30095
  ]);
26119
30096
  }
26120
- if (table) {
26121
- return this.rawQuotedIdentifier(`${table}.${column}`);
30097
+ if (table2) {
30098
+ return this.rawQuotedIdentifier(`${table2}.${column}`);
26122
30099
  } else {
26123
30100
  return this.rawQuotedIdentifier(field);
26124
30101
  }
@@ -26249,9 +30226,8 @@ var InternalBuilder = class {
26249
30226
  return query.andWhere(`${document}.fieldName`, "=", relationship.column);
26250
30227
  }
26251
30228
  addRelationshipForFilter(query, allowEmptyRelationships2, filterKey, whereCb) {
26252
- const { relationships, endpoint, tableAliases: aliases } = this.query;
26253
- const tableName = endpoint.entityId;
26254
- const fromAlias = aliases?.[tableName] || tableName;
30229
+ const { relationships, schema, tableAliases: aliases, table } = this.query;
30230
+ const fromAlias = aliases?.[table.name] || table.name;
26255
30231
  const matches2 = (value) => filterKey.match(new RegExp(`^${value}\\.`));
26256
30232
  if (!relationships) {
26257
30233
  return query;
@@ -26278,7 +30254,7 @@ var InternalBuilder = class {
26278
30254
  const throughAlias = aliases?.[manyToMany.through] || relationship.through;
26279
30255
  let throughTable = this.tableNameWithSchema(manyToMany.through, {
26280
30256
  alias: throughAlias,
26281
- schema: endpoint.schema
30257
+ schema
26282
30258
  });
26283
30259
  subQuery = subQuery.innerJoin(throughTable, function() {
26284
30260
  this.on(
@@ -26659,22 +30635,8 @@ var InternalBuilder = class {
26659
30635
  isSqs() {
26660
30636
  return isSqs(this.table);
26661
30637
  }
26662
- getTableName(tableOrName) {
26663
- let table;
26664
- if (typeof tableOrName === "string") {
26665
- const name2 = tableOrName;
26666
- if (this.query.table?.name === name2) {
26667
- table = this.query.table;
26668
- } else if (this.query.meta.table?.name === name2) {
26669
- table = this.query.meta.table;
26670
- } else if (!this.query.meta.tables?.[name2]) {
26671
- return name2;
26672
- } else {
26673
- table = this.query.meta.tables[name2];
26674
- }
26675
- } else if (tableOrName) {
26676
- table = tableOrName;
26677
- } else {
30638
+ getTableName(table) {
30639
+ if (!table) {
26678
30640
  table = this.table;
26679
30641
  }
26680
30642
  let name = table.name;
@@ -26806,8 +30768,9 @@ var InternalBuilder = class {
26806
30768
  }
26807
30769
  return withSchema;
26808
30770
  }
26809
- buildJsonField(field) {
30771
+ buildJsonField(table, field) {
26810
30772
  const parts = field.split(".");
30773
+ let baseName = parts[parts.length - 1];
26811
30774
  let unaliased;
26812
30775
  let tableField;
26813
30776
  if (parts.length > 1) {
@@ -26818,8 +30781,15 @@ var InternalBuilder = class {
26818
30781
  unaliased = parts.join(".");
26819
30782
  tableField = unaliased;
26820
30783
  }
26821
- const separator = this.client === "oracledb" /* ORACLE */ ? " VALUE " : ",";
26822
- return this.knex.raw(`?${separator}??`, [unaliased, this.rawQuotedIdentifier(tableField)]).toString();
30784
+ if (this.query.meta?.columnPrefix) {
30785
+ baseName = baseName.replace(this.query.meta.columnPrefix, "");
30786
+ }
30787
+ let identifier = this.rawQuotedIdentifier(tableField);
30788
+ const schema = table.schema[baseName];
30789
+ if (schema && schema.type === "bigint" /* BIGINT */) {
30790
+ identifier = this.castIntToString(identifier);
30791
+ }
30792
+ return [unaliased, identifier];
26823
30793
  }
26824
30794
  maxFunctionParameters() {
26825
30795
  switch (this.client) {
@@ -26834,7 +30804,7 @@ var InternalBuilder = class {
26834
30804
  addJsonRelationships(query, fromTable, relationships) {
26835
30805
  const sqlClient = this.client;
26836
30806
  const knex3 = this.knex;
26837
- const { resource, tableAliases: aliases, endpoint, meta } = this.query;
30807
+ const { resource, tableAliases: aliases, schema, tables } = this.query;
26838
30808
  const fields = resource?.fields || [];
26839
30809
  for (let relationship of relationships) {
26840
30810
  const {
@@ -26848,11 +30818,14 @@ var InternalBuilder = class {
26848
30818
  if (!toTable || !fromTable) {
26849
30819
  continue;
26850
30820
  }
26851
- const relatedTable = meta.tables?.[toTable];
30821
+ const relatedTable = tables[toTable];
30822
+ if (!relatedTable) {
30823
+ throw new Error(`related table "${toTable}" not found in datasource`);
30824
+ }
26852
30825
  const toAlias = aliases?.[toTable] || toTable, fromAlias = aliases?.[fromTable] || fromTable, throughAlias = throughTable && aliases?.[throughTable] || throughTable;
26853
30826
  let toTableWithSchema = this.tableNameWithSchema(toTable, {
26854
30827
  alias: toAlias,
26855
- schema: endpoint.schema
30828
+ schema
26856
30829
  });
26857
30830
  const requiredFields = [
26858
30831
  ...relatedTable?.primary || [],
@@ -26866,7 +30839,13 @@ var InternalBuilder = class {
26866
30839
  0,
26867
30840
  Math.floor(this.maxFunctionParameters() / 2)
26868
30841
  );
26869
- const fieldList = relationshipFields.map((field) => this.buildJsonField(field)).join(",");
30842
+ const fieldList = relationshipFields.map(
30843
+ (field) => this.buildJsonField(relatedTable, field)
30844
+ );
30845
+ const fieldListFormatted = fieldList.map((f) => {
30846
+ const separator = this.client === "oracledb" /* ORACLE */ ? " VALUE " : ",";
30847
+ return this.knex.raw(`?${separator}??`, [f[0], f[1]]).toString();
30848
+ }).join(",");
26870
30849
  const primaryKey = `${toAlias}.${toPrimary || toKey}`;
26871
30850
  let subQuery = knex3.from(toTableWithSchema).orderBy(primaryKey);
26872
30851
  const isManyToMany = throughTable && toPrimary && fromPrimary;
@@ -26874,7 +30853,7 @@ var InternalBuilder = class {
26874
30853
  if (isManyToMany) {
26875
30854
  let throughTableWithSchema = this.tableNameWithSchema(throughTable, {
26876
30855
  alias: throughAlias,
26877
- schema: endpoint.schema
30856
+ schema
26878
30857
  });
26879
30858
  subQuery = subQuery.join(throughTableWithSchema, function() {
26880
30859
  this.on(`${toAlias}.${toPrimary}`, "=", `${throughAlias}.${toKey}`);
@@ -26896,30 +30875,36 @@ var InternalBuilder = class {
26896
30875
  case "sqlite3" /* SQL_LITE */:
26897
30876
  subQuery = this.addJoinFieldCheck(subQuery, relationship);
26898
30877
  wrapperQuery = standardWrap(
26899
- this.knex.raw(`json_group_array(json_object(${fieldList}))`)
30878
+ this.knex.raw(
30879
+ `json_group_array(json_object(${fieldListFormatted}))`
30880
+ )
26900
30881
  );
26901
30882
  break;
26902
30883
  case "pg" /* POSTGRES */:
26903
30884
  wrapperQuery = standardWrap(
26904
- this.knex.raw(`json_agg(json_build_object(${fieldList}))`)
30885
+ this.knex.raw(`json_agg(json_build_object(${fieldListFormatted}))`)
26905
30886
  );
26906
30887
  break;
26907
30888
  case "mariadb" /* MARIADB */:
26908
30889
  wrapperQuery = subQuery.select(
26909
30890
  knex3.raw(
26910
- `json_arrayagg(json_object(${fieldList}) LIMIT ${getRelationshipLimit()})`
30891
+ `json_arrayagg(json_object(${fieldListFormatted}) LIMIT ${getRelationshipLimit()})`
26911
30892
  )
26912
30893
  );
26913
30894
  break;
26914
30895
  case "mysql2" /* MY_SQL */:
26915
30896
  case "oracledb" /* ORACLE */:
26916
30897
  wrapperQuery = standardWrap(
26917
- this.knex.raw(`json_arrayagg(json_object(${fieldList}))`)
30898
+ this.knex.raw(`json_arrayagg(json_object(${fieldListFormatted}))`)
26918
30899
  );
26919
30900
  break;
26920
30901
  case "mssql" /* MS_SQL */: {
26921
- const comparatorQuery = knex3.select(`${fromAlias}.*`).from({
26922
- [fromAlias]: subQuery.select(`${toAlias}.*`).limit(getRelationshipLimit())
30902
+ const comparatorQuery = knex3.select(`*`).from({
30903
+ [fromAlias]: subQuery.select(
30904
+ fieldList.map((f) => {
30905
+ return knex3.ref(f[1]).as(f[0]);
30906
+ })
30907
+ ).limit(getRelationshipLimit())
26923
30908
  });
26924
30909
  wrapperQuery = knex3.raw(
26925
30910
  `(SELECT ?? = (${comparatorQuery} FOR JSON PATH))`,
@@ -26935,8 +30920,7 @@ var InternalBuilder = class {
26935
30920
  return query;
26936
30921
  }
26937
30922
  addJoin(query, tables, columns) {
26938
- const { tableAliases: aliases, endpoint } = this.query;
26939
- const schema = endpoint.schema;
30923
+ const { tableAliases: aliases, schema } = this.query;
26940
30924
  const toTable = tables.to, fromTable = tables.from, throughTable = tables.through;
26941
30925
  const toAlias = aliases?.[toTable] || toTable, throughAlias = throughTable && aliases?.[throughTable] || throughTable, fromAlias = aliases?.[fromTable] || fromTable;
26942
30926
  let toTableWithSchema = this.tableNameWithSchema(toTable, {
@@ -26976,16 +30960,16 @@ var InternalBuilder = class {
26976
30960
  return query;
26977
30961
  }
26978
30962
  qualifiedKnex(opts) {
26979
- let alias = this.query.tableAliases?.[this.query.endpoint.entityId];
30963
+ let alias = this.query.tableAliases?.[this.query.table.name];
26980
30964
  if (opts?.alias === false) {
26981
30965
  alias = void 0;
26982
30966
  } else if (typeof opts?.alias === "string") {
26983
30967
  alias = opts.alias;
26984
30968
  }
26985
30969
  return this.knex(
26986
- this.tableNameWithSchema(this.query.endpoint.entityId, {
30970
+ this.tableNameWithSchema(this.query.table.name, {
26987
30971
  alias,
26988
- schema: this.query.endpoint.schema
30972
+ schema: this.query.schema
26989
30973
  })
26990
30974
  );
26991
30975
  }
@@ -26997,9 +30981,7 @@ var InternalBuilder = class {
26997
30981
  let query = this.qualifiedKnex({ alias: false });
26998
30982
  const parsedBody = this.parseBody(body2);
26999
30983
  if (this.client === "oracledb" /* ORACLE */) {
27000
- for (const [column, schema] of Object.entries(
27001
- this.query.meta.table.schema
27002
- )) {
30984
+ for (const [column, schema] of Object.entries(this.query.table.schema)) {
27003
30985
  if (schema.constraints?.presence === true || schema.type === "formula" /* FORMULA */ || schema.type === "auto" /* AUTO */ || schema.type === "link" /* LINK */ || schema.type === "ai" /* AI */) {
27004
30986
  continue;
27005
30987
  }
@@ -27049,10 +31031,8 @@ var InternalBuilder = class {
27049
31031
  return query.upsert(parsedBody);
27050
31032
  }
27051
31033
  read(opts = {}) {
27052
- let { endpoint, filters, paginate, relationships } = this.query;
31034
+ let { operation, filters, paginate, relationships, table } = this.query;
27053
31035
  const { limits } = opts;
27054
- const counting = endpoint.operation === "COUNT" /* COUNT */;
27055
- const tableName = endpoint.entityId;
27056
31036
  let query = this.qualifiedKnex();
27057
31037
  let foundOffset = null;
27058
31038
  let foundLimit = limits?.query || limits?.base;
@@ -27067,7 +31047,7 @@ var InternalBuilder = class {
27067
31047
  } else if (paginate && paginate.limit) {
27068
31048
  foundLimit = paginate.limit;
27069
31049
  }
27070
- if (!counting) {
31050
+ if (operation !== "COUNT" /* COUNT */) {
27071
31051
  if (foundLimit != null) {
27072
31052
  query = query.limit(foundLimit);
27073
31053
  }
@@ -27076,25 +31056,25 @@ var InternalBuilder = class {
27076
31056
  }
27077
31057
  }
27078
31058
  const aggregations = this.query.resource?.aggregations || [];
27079
- if (counting) {
31059
+ if (operation === "COUNT" /* COUNT */) {
27080
31060
  query = this.addDistinctCount(query);
27081
31061
  } else if (aggregations.length > 0) {
27082
31062
  query = this.addAggregations(query, aggregations);
27083
31063
  } else {
27084
31064
  query = query.select(this.generateSelectStatement());
27085
31065
  }
27086
- if (!counting) {
31066
+ if (operation !== "COUNT" /* COUNT */) {
27087
31067
  query = this.addSorting(query);
27088
31068
  }
27089
31069
  query = this.addFilters(query, filters, { relationship: true });
27090
31070
  if (relationships?.length && aggregations.length === 0) {
27091
- const mainTable = this.query.tableAliases?.[this.query.endpoint.entityId] || this.query.endpoint.entityId;
31071
+ const mainTable = this.query.tableAliases?.[table.name] || table.name;
27092
31072
  const cte = this.addSorting(
27093
31073
  this.knex.with("paginated", query).select(this.generateSelectStatement()).from({
27094
31074
  [mainTable]: "paginated"
27095
31075
  })
27096
31076
  );
27097
- return this.addJsonRelationships(cte, tableName, relationships);
31077
+ return this.addJsonRelationships(cte, table.name, relationships);
27098
31078
  }
27099
31079
  return query;
27100
31080
  }
@@ -27199,28 +31179,24 @@ var SqlQueryBuilder = class extends sqlTable_default {
27199
31179
  return {};
27200
31180
  }
27201
31181
  const input = this._query({
27202
- endpoint: {
27203
- ...json.endpoint,
27204
- operation: "READ" /* READ */
27205
- },
27206
- resource: {
27207
- fields: []
27208
- },
31182
+ operation: "READ" /* READ */,
31183
+ datasource: json.datasource,
31184
+ schema: json.schema,
31185
+ table: json.table,
31186
+ tables: json.tables,
31187
+ resource: { fields: [] },
27209
31188
  filters: json.extra?.idFilter,
27210
- paginate: {
27211
- limit: 1
27212
- },
27213
- meta: json.meta
31189
+ paginate: { limit: 1 }
27214
31190
  });
27215
31191
  return queryFn(input, "READ" /* READ */);
27216
31192
  }
27217
31193
  // when creating if an ID has been inserted need to make sure
27218
31194
  // the id filter is enriched with it before trying to retrieve the row
27219
31195
  checkLookupKeys(id, json) {
27220
- if (!id || !json.meta.table || !json.meta.table.primary) {
31196
+ if (!id || !json.table.primary) {
27221
31197
  return json;
27222
31198
  }
27223
- const primaryKey = json.meta.table.primary?.[0];
31199
+ const primaryKey = json.table.primary[0];
27224
31200
  json.extra = {
27225
31201
  idFilter: {
27226
31202
  equal: {