@mappedin/dynamic-focus 6.0.1-beta.53 → 6.0.1-beta.54

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/lib/esm/index.js CHANGED
@@ -1,8 +1,12 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, { get: all[name], enumerable: true });
6
+ };
3
7
 
4
8
  // <define:process>
5
- var define_process_default = { env: { npm_package_version: "6.0.1-beta.53" } };
9
+ var define_process_default = { env: { npm_package_version: "6.0.1-beta.54" } };
6
10
 
7
11
  // src/dynamic-focus.ts
8
12
  import { Floor as Floor3 } from "@mappedin/mappedin-js";
@@ -5954,341 +5958,4415 @@ var PubSub = class {
5954
5958
  // ../packages/common/color.ts
5955
5959
  var X11_COLOR_NAMES_SET = new Set(Object.keys(Color.NAMES));
5956
5960
 
5957
- // src/building.ts
5958
- import { Facade, Floor, FloorStack } from "@mappedin/mappedin-js";
5959
- var Building = class {
5960
- static {
5961
- __name(this, "Building");
5962
- }
5963
- __type = "building";
5964
- #floorStack;
5965
- #floorsById = /* @__PURE__ */ new Map();
5966
- #floorsByElevation = /* @__PURE__ */ new Map();
5967
- #floorsByElevationSorted = [];
5968
- #mapView;
5969
- #spacesByAltitude;
5970
- #animationInProgress;
5971
- defaultFloor;
5972
- activeFloor;
5973
- excluded = false;
5974
- constructor(floorStack, mapView) {
5975
- this.#floorStack = floorStack;
5976
- this.#floorsById = new Map(floorStack.floors.map((floor) => [floor.id, floor]));
5977
- this.#floorsByElevation = new Map(floorStack.floors.map((floor) => [floor.elevation, floor]));
5978
- this.#floorsByElevationSorted = Array.from(this.#floorsByElevation.values()).sort(
5979
- (a, b) => a.elevation - b.elevation
5980
- );
5981
- this.defaultFloor = floorStack.defaultFloor;
5982
- this.activeFloor = this.defaultFloor;
5983
- this.#mapView = mapView;
5984
- }
5985
- get id() {
5986
- return this.#floorStack.id;
5987
- }
5988
- get name() {
5989
- return this.#floorStack.name;
5990
- }
5991
- get floors() {
5992
- return this.#floorStack.floors;
5993
- }
5994
- get floorStack() {
5995
- return this.#floorStack;
5996
- }
5997
- get facade() {
5998
- return this.#floorStack.facade;
5999
- }
6000
- get isCurrentFloorStack() {
6001
- return this.id === this.#mapView.currentFloorStack.id;
6002
- }
6003
- get isIndoor() {
6004
- const state = this.#mapView.getState(this.facade);
6005
- return this.isCurrentFloorStack || state?.visible === false && state?.opacity === 0;
6006
- }
6007
- get canSetFloor() {
6008
- return this.isIndoor || !this.excluded;
5961
+ // ../../node_modules/.pnpm/zod@3.25.51/node_modules/zod/dist/esm/v3/external.js
5962
+ var external_exports = {};
5963
+ __export(external_exports, {
5964
+ BRAND: () => BRAND,
5965
+ DIRTY: () => DIRTY,
5966
+ EMPTY_PATH: () => EMPTY_PATH,
5967
+ INVALID: () => INVALID,
5968
+ NEVER: () => NEVER,
5969
+ OK: () => OK,
5970
+ ParseStatus: () => ParseStatus,
5971
+ Schema: () => ZodType,
5972
+ ZodAny: () => ZodAny,
5973
+ ZodArray: () => ZodArray,
5974
+ ZodBigInt: () => ZodBigInt,
5975
+ ZodBoolean: () => ZodBoolean,
5976
+ ZodBranded: () => ZodBranded,
5977
+ ZodCatch: () => ZodCatch,
5978
+ ZodDate: () => ZodDate,
5979
+ ZodDefault: () => ZodDefault,
5980
+ ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
5981
+ ZodEffects: () => ZodEffects,
5982
+ ZodEnum: () => ZodEnum,
5983
+ ZodError: () => ZodError,
5984
+ ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
5985
+ ZodFunction: () => ZodFunction,
5986
+ ZodIntersection: () => ZodIntersection,
5987
+ ZodIssueCode: () => ZodIssueCode,
5988
+ ZodLazy: () => ZodLazy,
5989
+ ZodLiteral: () => ZodLiteral,
5990
+ ZodMap: () => ZodMap,
5991
+ ZodNaN: () => ZodNaN,
5992
+ ZodNativeEnum: () => ZodNativeEnum,
5993
+ ZodNever: () => ZodNever,
5994
+ ZodNull: () => ZodNull,
5995
+ ZodNullable: () => ZodNullable,
5996
+ ZodNumber: () => ZodNumber,
5997
+ ZodObject: () => ZodObject,
5998
+ ZodOptional: () => ZodOptional,
5999
+ ZodParsedType: () => ZodParsedType,
6000
+ ZodPipeline: () => ZodPipeline,
6001
+ ZodPromise: () => ZodPromise,
6002
+ ZodReadonly: () => ZodReadonly,
6003
+ ZodRecord: () => ZodRecord,
6004
+ ZodSchema: () => ZodType,
6005
+ ZodSet: () => ZodSet,
6006
+ ZodString: () => ZodString,
6007
+ ZodSymbol: () => ZodSymbol,
6008
+ ZodTransformer: () => ZodEffects,
6009
+ ZodTuple: () => ZodTuple,
6010
+ ZodType: () => ZodType,
6011
+ ZodUndefined: () => ZodUndefined,
6012
+ ZodUnion: () => ZodUnion,
6013
+ ZodUnknown: () => ZodUnknown,
6014
+ ZodVoid: () => ZodVoid,
6015
+ addIssueToContext: () => addIssueToContext,
6016
+ any: () => anyType,
6017
+ array: () => arrayType,
6018
+ bigint: () => bigIntType,
6019
+ boolean: () => booleanType,
6020
+ coerce: () => coerce,
6021
+ custom: () => custom,
6022
+ date: () => dateType,
6023
+ datetimeRegex: () => datetimeRegex,
6024
+ defaultErrorMap: () => en_default,
6025
+ discriminatedUnion: () => discriminatedUnionType,
6026
+ effect: () => effectsType,
6027
+ enum: () => enumType,
6028
+ function: () => functionType,
6029
+ getErrorMap: () => getErrorMap,
6030
+ getParsedType: () => getParsedType,
6031
+ instanceof: () => instanceOfType,
6032
+ intersection: () => intersectionType,
6033
+ isAborted: () => isAborted,
6034
+ isAsync: () => isAsync,
6035
+ isDirty: () => isDirty,
6036
+ isValid: () => isValid,
6037
+ late: () => late,
6038
+ lazy: () => lazyType,
6039
+ literal: () => literalType,
6040
+ makeIssue: () => makeIssue,
6041
+ map: () => mapType,
6042
+ nan: () => nanType,
6043
+ nativeEnum: () => nativeEnumType,
6044
+ never: () => neverType,
6045
+ null: () => nullType,
6046
+ nullable: () => nullableType,
6047
+ number: () => numberType,
6048
+ object: () => objectType,
6049
+ objectUtil: () => objectUtil,
6050
+ oboolean: () => oboolean,
6051
+ onumber: () => onumber,
6052
+ optional: () => optionalType,
6053
+ ostring: () => ostring,
6054
+ pipeline: () => pipelineType,
6055
+ preprocess: () => preprocessType,
6056
+ promise: () => promiseType,
6057
+ quotelessJson: () => quotelessJson,
6058
+ record: () => recordType,
6059
+ set: () => setType,
6060
+ setErrorMap: () => setErrorMap,
6061
+ strictObject: () => strictObjectType,
6062
+ string: () => stringType,
6063
+ symbol: () => symbolType,
6064
+ transformer: () => effectsType,
6065
+ tuple: () => tupleType,
6066
+ undefined: () => undefinedType,
6067
+ union: () => unionType,
6068
+ unknown: () => unknownType,
6069
+ util: () => util,
6070
+ void: () => voidType
6071
+ });
6072
+
6073
+ // ../../node_modules/.pnpm/zod@3.25.51/node_modules/zod/dist/esm/v3/helpers/util.js
6074
+ var util;
6075
+ (function(util2) {
6076
+ util2.assertEqual = (_) => {
6077
+ };
6078
+ function assertIs(_arg) {
6009
6079
  }
6010
- #maxElevation;
6011
- get maxElevation() {
6012
- if (this.#maxElevation == null) {
6013
- this.#maxElevation = Math.max(...this.#floorsByElevation.keys());
6014
- }
6015
- return this.#maxElevation;
6080
+ __name(assertIs, "assertIs");
6081
+ util2.assertIs = assertIs;
6082
+ function assertNever(_x2) {
6083
+ throw new Error();
6016
6084
  }
6017
- #minElevation;
6018
- get minElevation() {
6019
- if (this.#minElevation == null) {
6020
- this.#minElevation = Math.min(...this.#floorsByElevation.keys());
6085
+ __name(assertNever, "assertNever");
6086
+ util2.assertNever = assertNever;
6087
+ util2.arrayToEnum = (items) => {
6088
+ const obj = {};
6089
+ for (const item of items) {
6090
+ obj[item] = item;
6021
6091
  }
6022
- return this.#minElevation;
6023
- }
6024
- has(f) {
6025
- if (Floor.is(f)) {
6026
- return this.#floorsById.has(f.id);
6092
+ return obj;
6093
+ };
6094
+ util2.getValidEnumValues = (obj) => {
6095
+ const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
6096
+ const filtered = {};
6097
+ for (const k of validKeys) {
6098
+ filtered[k] = obj[k];
6027
6099
  }
6028
- if (FloorStack.is(f)) {
6029
- return f.id === this.#floorStack.id;
6100
+ return util2.objectValues(filtered);
6101
+ };
6102
+ util2.objectValues = (obj) => {
6103
+ return util2.objectKeys(obj).map(function(e) {
6104
+ return obj[e];
6105
+ });
6106
+ };
6107
+ util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
6108
+ const keys = [];
6109
+ for (const key in object) {
6110
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
6111
+ keys.push(key);
6112
+ }
6030
6113
  }
6031
- if (Facade.is(f)) {
6032
- return f.id === this.facade.id;
6114
+ return keys;
6115
+ };
6116
+ util2.find = (arr, checker) => {
6117
+ for (const item of arr) {
6118
+ if (checker(item))
6119
+ return item;
6033
6120
  }
6034
- return false;
6035
- }
6036
- get aboveGroundFloors() {
6037
- return this.#floorsByElevationSorted.filter((floor) => floor.elevation >= 0);
6121
+ return void 0;
6122
+ };
6123
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
6124
+ function joinValues(array, separator = " | ") {
6125
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
6038
6126
  }
6039
- expandFacade() {
6040
- if (!this.#mapView.options.multiFloorView?.enabled || !this.facade || this.facade.__type !== "facade" || this.facade.spaces.length < 1) {
6041
- return;
6127
+ __name(joinValues, "joinValues");
6128
+ util2.joinValues = joinValues;
6129
+ util2.jsonStringifyReplacer = (_, value) => {
6130
+ if (typeof value === "bigint") {
6131
+ return value.toString();
6042
6132
  }
6043
- const footprintHeight = this.#mapView.options.multiFloorView.floorHeight ?? 10;
6044
- if (!this.#spacesByAltitude) {
6045
- this.#spacesByAltitude = /* @__PURE__ */ new Map();
6046
- for (const space of this.facade.spaces) {
6047
- const state = this.#mapView.getState(space);
6048
- const altitude = state?.altitude ?? 0;
6049
- const height = state?.height ?? 0;
6050
- if (!this.#spacesByAltitude.has(altitude)) {
6051
- this.#spacesByAltitude.set(altitude, []);
6052
- }
6053
- this.#spacesByAltitude.get(altitude).push({
6054
- space,
6055
- originalAltitude: altitude,
6056
- originalHeight: height
6057
- });
6133
+ return value;
6134
+ };
6135
+ })(util || (util = {}));
6136
+ var objectUtil;
6137
+ (function(objectUtil2) {
6138
+ objectUtil2.mergeShapes = (first, second) => {
6139
+ return {
6140
+ ...first,
6141
+ ...second
6142
+ // second overwrites first
6143
+ };
6144
+ };
6145
+ })(objectUtil || (objectUtil = {}));
6146
+ var ZodParsedType = util.arrayToEnum([
6147
+ "string",
6148
+ "nan",
6149
+ "number",
6150
+ "integer",
6151
+ "float",
6152
+ "boolean",
6153
+ "date",
6154
+ "bigint",
6155
+ "symbol",
6156
+ "function",
6157
+ "undefined",
6158
+ "null",
6159
+ "array",
6160
+ "object",
6161
+ "unknown",
6162
+ "promise",
6163
+ "void",
6164
+ "never",
6165
+ "map",
6166
+ "set"
6167
+ ]);
6168
+ var getParsedType = /* @__PURE__ */ __name((data) => {
6169
+ const t = typeof data;
6170
+ switch (t) {
6171
+ case "undefined":
6172
+ return ZodParsedType.undefined;
6173
+ case "string":
6174
+ return ZodParsedType.string;
6175
+ case "number":
6176
+ return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
6177
+ case "boolean":
6178
+ return ZodParsedType.boolean;
6179
+ case "function":
6180
+ return ZodParsedType.function;
6181
+ case "bigint":
6182
+ return ZodParsedType.bigint;
6183
+ case "symbol":
6184
+ return ZodParsedType.symbol;
6185
+ case "object":
6186
+ if (Array.isArray(data)) {
6187
+ return ZodParsedType.array;
6058
6188
  }
6059
- }
6060
- const altitudeKeys = Array.from(this.#spacesByAltitude.keys()).sort((a, b) => a - b);
6061
- const isSingleAltitude = altitudeKeys.length === 1;
6062
- const heightToUse = isSingleAltitude ? footprintHeight * (this.aboveGroundFloors.length - 1) : footprintHeight;
6063
- let currentAltitude = 0;
6064
- altitudeKeys.forEach((originalAltitude) => {
6065
- const spaceData = this.#spacesByAltitude.get(originalAltitude);
6066
- for (const { space } of spaceData) {
6067
- this.#mapView.updateState(space, {
6068
- height: isSingleAltitude ? heightToUse : footprintHeight,
6069
- altitude: currentAltitude
6070
- });
6189
+ if (data === null) {
6190
+ return ZodParsedType.null;
6071
6191
  }
6072
- if (!isSingleAltitude) {
6073
- currentAltitude += footprintHeight;
6192
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
6193
+ return ZodParsedType.promise;
6074
6194
  }
6075
- });
6076
- }
6077
- collapseFacade() {
6078
- if (!this.#spacesByAltitude) {
6079
- return;
6080
- }
6081
- for (const spaceDataArray of this.#spacesByAltitude.values()) {
6082
- for (const { space, originalAltitude, originalHeight } of spaceDataArray) {
6083
- this.#mapView.updateState(space, {
6084
- height: originalHeight,
6085
- altitude: originalAltitude
6086
- });
6195
+ if (typeof Map !== "undefined" && data instanceof Map) {
6196
+ return ZodParsedType.map;
6087
6197
  }
6088
- }
6089
- this.#spacesByAltitude = void 0;
6090
- }
6091
- getFloorByElevation(elevation) {
6092
- return this.#floorsByElevation.get(elevation);
6093
- }
6094
- getNearestFloorByElevation(targetElevation) {
6095
- const exactMatch = this.getFloorByElevation(targetElevation);
6096
- if (exactMatch) {
6097
- return exactMatch;
6098
- }
6099
- if (targetElevation >= 0) {
6100
- if (targetElevation > this.maxElevation) {
6101
- return this.#floorsByElevationSorted[this.#floorsByElevationSorted.length - 1];
6198
+ if (typeof Set !== "undefined" && data instanceof Set) {
6199
+ return ZodParsedType.set;
6102
6200
  }
6103
- for (let i = this.#floorsByElevationSorted.length - 1; i >= 0; i--) {
6104
- const floor = this.#floorsByElevationSorted[i];
6105
- if (floor.elevation <= targetElevation) {
6106
- return floor;
6107
- }
6201
+ if (typeof Date !== "undefined" && data instanceof Date) {
6202
+ return ZodParsedType.date;
6108
6203
  }
6204
+ return ZodParsedType.object;
6205
+ default:
6206
+ return ZodParsedType.unknown;
6207
+ }
6208
+ }, "getParsedType");
6209
+
6210
+ // ../../node_modules/.pnpm/zod@3.25.51/node_modules/zod/dist/esm/v3/ZodError.js
6211
+ var ZodIssueCode = util.arrayToEnum([
6212
+ "invalid_type",
6213
+ "invalid_literal",
6214
+ "custom",
6215
+ "invalid_union",
6216
+ "invalid_union_discriminator",
6217
+ "invalid_enum_value",
6218
+ "unrecognized_keys",
6219
+ "invalid_arguments",
6220
+ "invalid_return_type",
6221
+ "invalid_date",
6222
+ "invalid_string",
6223
+ "too_small",
6224
+ "too_big",
6225
+ "invalid_intersection_types",
6226
+ "not_multiple_of",
6227
+ "not_finite"
6228
+ ]);
6229
+ var quotelessJson = /* @__PURE__ */ __name((obj) => {
6230
+ const json = JSON.stringify(obj, null, 2);
6231
+ return json.replace(/"([^"]+)":/g, "$1:");
6232
+ }, "quotelessJson");
6233
+ var ZodError = class _ZodError extends Error {
6234
+ static {
6235
+ __name(this, "ZodError");
6236
+ }
6237
+ get errors() {
6238
+ return this.issues;
6239
+ }
6240
+ constructor(issues) {
6241
+ super();
6242
+ this.issues = [];
6243
+ this.addIssue = (sub) => {
6244
+ this.issues = [...this.issues, sub];
6245
+ };
6246
+ this.addIssues = (subs = []) => {
6247
+ this.issues = [...this.issues, ...subs];
6248
+ };
6249
+ const actualProto = new.target.prototype;
6250
+ if (Object.setPrototypeOf) {
6251
+ Object.setPrototypeOf(this, actualProto);
6109
6252
  } else {
6110
- if (targetElevation < this.minElevation) {
6111
- return this.#floorsByElevationSorted[0];
6112
- }
6113
- for (const floor of this.#floorsByElevationSorted) {
6114
- if (floor.elevation >= targetElevation) {
6115
- return floor;
6253
+ this.__proto__ = actualProto;
6254
+ }
6255
+ this.name = "ZodError";
6256
+ this.issues = issues;
6257
+ }
6258
+ format(_mapper) {
6259
+ const mapper = _mapper || function(issue) {
6260
+ return issue.message;
6261
+ };
6262
+ const fieldErrors = { _errors: [] };
6263
+ const processError = /* @__PURE__ */ __name((error) => {
6264
+ for (const issue of error.issues) {
6265
+ if (issue.code === "invalid_union") {
6266
+ issue.unionErrors.map(processError);
6267
+ } else if (issue.code === "invalid_return_type") {
6268
+ processError(issue.returnTypeError);
6269
+ } else if (issue.code === "invalid_arguments") {
6270
+ processError(issue.argumentsError);
6271
+ } else if (issue.path.length === 0) {
6272
+ fieldErrors._errors.push(mapper(issue));
6273
+ } else {
6274
+ let curr = fieldErrors;
6275
+ let i = 0;
6276
+ while (i < issue.path.length) {
6277
+ const el = issue.path[i];
6278
+ const terminal = i === issue.path.length - 1;
6279
+ if (!terminal) {
6280
+ curr[el] = curr[el] || { _errors: [] };
6281
+ } else {
6282
+ curr[el] = curr[el] || { _errors: [] };
6283
+ curr[el]._errors.push(mapper(issue));
6284
+ }
6285
+ curr = curr[el];
6286
+ i++;
6287
+ }
6116
6288
  }
6117
6289
  }
6290
+ }, "processError");
6291
+ processError(this);
6292
+ return fieldErrors;
6293
+ }
6294
+ static assert(value) {
6295
+ if (!(value instanceof _ZodError)) {
6296
+ throw new Error(`Not a ZodError: ${value}`);
6118
6297
  }
6119
- return void 0;
6120
6298
  }
6121
- getHighestFloor() {
6122
- return this.#floorsByElevationSorted[this.#floorsByElevationSorted.length - 1];
6299
+ toString() {
6300
+ return this.message;
6123
6301
  }
6124
- cancelAnimation() {
6125
- if (this.#animationInProgress) {
6126
- this.#animationInProgress.animation.cancel();
6127
- this.#animationInProgress = void 0;
6128
- }
6302
+ get message() {
6303
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
6129
6304
  }
6130
- async animateFacade(newState, options = { duration: 150 }) {
6131
- const currentState = this.#animationInProgress?.state || this.#mapView.getState(this.facade);
6132
- if (!currentState || !newState || currentState?.opacity === newState.opacity && currentState?.visible === newState.visible) {
6133
- return { result: "completed" };
6134
- }
6135
- this.cancelAnimation();
6136
- const { opacity, visible } = newState;
6137
- this.#mapView.updateState(this.facade, {
6138
- visible: true
6139
- });
6140
- if (opacity !== void 0) {
6141
- this.#animationInProgress = {
6142
- animation: this.#mapView.animateState(
6143
- this.facade,
6144
- {
6145
- opacity
6146
- },
6147
- {
6148
- duration: options.duration
6149
- }
6150
- ),
6151
- state: newState
6152
- };
6153
- const result = await this.#animationInProgress.animation;
6154
- this.#animationInProgress = void 0;
6155
- if (result.result === "cancelled") {
6156
- return result;
6305
+ get isEmpty() {
6306
+ return this.issues.length === 0;
6307
+ }
6308
+ flatten(mapper = (issue) => issue.message) {
6309
+ const fieldErrors = {};
6310
+ const formErrors = [];
6311
+ for (const sub of this.issues) {
6312
+ if (sub.path.length > 0) {
6313
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
6314
+ fieldErrors[sub.path[0]].push(mapper(sub));
6315
+ } else {
6316
+ formErrors.push(mapper(sub));
6157
6317
  }
6158
6318
  }
6159
- if (visible === false) {
6160
- this.#mapView.updateState(this.facade, {
6161
- visible
6162
- });
6163
- }
6164
- return { result: "completed" };
6319
+ return { formErrors, fieldErrors };
6165
6320
  }
6166
- destroy() {
6167
- this.cancelAnimation();
6168
- this.#floorStack.floors.forEach((floor) => {
6169
- this.#mapView.updateState(floor, {
6170
- visible: floor.id === this.#mapView.currentFloor.id
6171
- });
6172
- });
6173
- if (!this.has(this.#mapView.currentFloor)) {
6174
- this.#mapView.updateState(this.facade, {
6175
- visible: true,
6176
- opacity: 1
6177
- });
6178
- }
6321
+ get formErrors() {
6322
+ return this.flatten();
6179
6323
  }
6180
6324
  };
6325
+ ZodError.create = (issues) => {
6326
+ const error = new ZodError(issues);
6327
+ return error;
6328
+ };
6181
6329
 
6182
- // ../mappedin-js/src/api-geojson/multi-floor.ts
6183
- function getMultiFloorState(floors, currentFloor, floorHeight, floorIdsInNavigation) {
6184
- const state = {
6185
- outdoorOpacity: 1,
6186
- floorStates: []
6187
- };
6188
- const sortedFloors = floors.sort((f1, f2) => f1.elevation - f2.elevation);
6189
- const minElevation = Math.min(0, sortedFloors[0].elevation);
6190
- const maxElevation = sortedFloors[sortedFloors.length - 1].elevation;
6191
- let gapStartElevation;
6192
- let gapEndElevation;
6193
- for (let i = minElevation; i <= maxElevation; i++) {
6194
- const floor = sortedFloors.find((f) => f.elevation === i);
6195
- if (floor == null) {
6196
- if (i >= 0) {
6197
- if (gapStartElevation == null) {
6198
- gapStartElevation = i;
6199
- } else {
6200
- gapEndElevation = i;
6201
- }
6202
- }
6203
- continue;
6204
- }
6205
- let footprintAltitude = 0;
6206
- let footprintHeight = i < 0 ? Math.abs(floor.elevation) * floorHeight : floorHeight;
6207
- let shouldShowFootprint = false;
6208
- if (gapStartElevation === 0 && gapEndElevation != null) {
6209
- const expansionHeight = floorHeight * gapEndElevation;
6210
- footprintAltitude = -expansionHeight;
6211
- footprintHeight = expansionHeight;
6212
- shouldShowFootprint = true;
6213
- } else if (gapStartElevation != null && gapEndElevation != null) {
6214
- const startElevation = gapStartElevation;
6215
- const lastFloor = floors.find((f) => f.elevation === startElevation - 1);
6216
- const lastFloorState = state.floorStates.find((s) => s.floor === lastFloor);
6217
- if (lastFloorState) {
6218
- const expansionHeight = floorHeight * (gapEndElevation - gapStartElevation + 2);
6219
- lastFloorState.state.footprint = {
6220
- ...lastFloorState.state.footprint,
6221
- altitude: 0,
6222
- height: expansionHeight,
6223
- visible: true
6224
- };
6225
- }
6226
- }
6227
- gapStartElevation = void 0;
6228
- gapEndElevation = void 0;
6229
- const currentFloorState = {
6230
- floor,
6231
- state: {
6232
- type: "floor",
6233
- visible: false,
6234
- geometry: {
6235
- visible: false
6236
- },
6237
- labels: {
6238
- enabled: false
6239
- },
6240
- markers: {
6241
- enabled: false
6242
- },
6243
- footprint: {
6244
- visible: false
6245
- },
6246
- occlusion: {
6247
- enabled: false
6248
- }
6330
+ // ../../node_modules/.pnpm/zod@3.25.51/node_modules/zod/dist/esm/v3/locales/en.js
6331
+ var errorMap = /* @__PURE__ */ __name((issue, _ctx) => {
6332
+ let message;
6333
+ switch (issue.code) {
6334
+ case ZodIssueCode.invalid_type:
6335
+ if (issue.received === ZodParsedType.undefined) {
6336
+ message = "Required";
6337
+ } else {
6338
+ message = `Expected ${issue.expected}, received ${issue.received}`;
6249
6339
  }
6250
- };
6251
- state.floorStates.push(currentFloorState);
6252
- if (floor.id === currentFloor.id) {
6253
- currentFloorState.state.visible = true;
6254
- currentFloorState.state.geometry.visible = true;
6255
- currentFloorState.state.labels.enabled = true;
6256
- currentFloorState.state.markers.enabled = true;
6257
- currentFloorState.state.occlusion.enabled = true;
6258
- if (floor.elevation < 0 || shouldShowFootprint) {
6259
- if (floor.elevation < 0) {
6260
- state.outdoorOpacity = 0.2;
6340
+ break;
6341
+ case ZodIssueCode.invalid_literal:
6342
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
6343
+ break;
6344
+ case ZodIssueCode.unrecognized_keys:
6345
+ message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
6346
+ break;
6347
+ case ZodIssueCode.invalid_union:
6348
+ message = `Invalid input`;
6349
+ break;
6350
+ case ZodIssueCode.invalid_union_discriminator:
6351
+ message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
6352
+ break;
6353
+ case ZodIssueCode.invalid_enum_value:
6354
+ message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
6355
+ break;
6356
+ case ZodIssueCode.invalid_arguments:
6357
+ message = `Invalid function arguments`;
6358
+ break;
6359
+ case ZodIssueCode.invalid_return_type:
6360
+ message = `Invalid function return type`;
6361
+ break;
6362
+ case ZodIssueCode.invalid_date:
6363
+ message = `Invalid date`;
6364
+ break;
6365
+ case ZodIssueCode.invalid_string:
6366
+ if (typeof issue.validation === "object") {
6367
+ if ("includes" in issue.validation) {
6368
+ message = `Invalid input: must include "${issue.validation.includes}"`;
6369
+ if (typeof issue.validation.position === "number") {
6370
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
6371
+ }
6372
+ } else if ("startsWith" in issue.validation) {
6373
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
6374
+ } else if ("endsWith" in issue.validation) {
6375
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
6376
+ } else {
6377
+ util.assertNever(issue.validation);
6261
6378
  }
6262
- currentFloorState.state.footprint.height = footprintHeight;
6263
- currentFloorState.state.footprint.altitude = footprintAltitude;
6264
- currentFloorState.state.footprint.visible = true;
6265
- }
6266
- } else if (floorIdsInNavigation.includes(floor.id) && floor.elevation < currentFloor.elevation) {
6267
- currentFloorState.state.visible = true;
6268
- currentFloorState.state.geometry.visible = true;
6269
- currentFloorState.state.markers.enabled = true;
6270
- currentFloorState.state.occlusion.enabled = true;
6271
- currentFloorState.state.footprint.visible = true;
6272
- if (floor.elevation < 0) {
6273
- currentFloorState.state.footprint.height = footprintHeight;
6274
- currentFloorState.state.footprint.altitude = footprintAltitude;
6275
- state.outdoorOpacity = 0.2;
6379
+ } else if (issue.validation !== "regex") {
6380
+ message = `Invalid ${issue.validation}`;
6276
6381
  } else {
6277
- currentFloorState.state.footprint.height = footprintHeight;
6278
- currentFloorState.state.footprint.altitude = footprintAltitude;
6382
+ message = "Invalid";
6279
6383
  }
6280
- } else if (currentFloor.elevation > 0 && floor.elevation < currentFloor.elevation && floor.elevation >= 0) {
6281
- currentFloorState.state.visible = true;
6282
- currentFloorState.state.footprint.visible = true;
6283
- currentFloorState.state.footprint.height = floorHeight;
6284
- currentFloorState.state.footprint.altitude = footprintAltitude;
6285
- }
6286
- }
6287
- return state;
6288
- }
6289
- __name(getMultiFloorState, "getMultiFloorState");
6384
+ break;
6385
+ case ZodIssueCode.too_small:
6386
+ if (issue.type === "array")
6387
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
6388
+ else if (issue.type === "string")
6389
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
6390
+ else if (issue.type === "number")
6391
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
6392
+ else if (issue.type === "date")
6393
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
6394
+ else
6395
+ message = "Invalid input";
6396
+ break;
6397
+ case ZodIssueCode.too_big:
6398
+ if (issue.type === "array")
6399
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
6400
+ else if (issue.type === "string")
6401
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
6402
+ else if (issue.type === "number")
6403
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
6404
+ else if (issue.type === "bigint")
6405
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
6406
+ else if (issue.type === "date")
6407
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
6408
+ else
6409
+ message = "Invalid input";
6410
+ break;
6411
+ case ZodIssueCode.custom:
6412
+ message = `Invalid input`;
6413
+ break;
6414
+ case ZodIssueCode.invalid_intersection_types:
6415
+ message = `Intersection results could not be merged`;
6416
+ break;
6417
+ case ZodIssueCode.not_multiple_of:
6418
+ message = `Number must be a multiple of ${issue.multipleOf}`;
6419
+ break;
6420
+ case ZodIssueCode.not_finite:
6421
+ message = "Number must be finite";
6422
+ break;
6423
+ default:
6424
+ message = _ctx.defaultError;
6425
+ util.assertNever(issue);
6426
+ }
6427
+ return { message };
6428
+ }, "errorMap");
6429
+ var en_default = errorMap;
6430
+
6431
+ // ../../node_modules/.pnpm/zod@3.25.51/node_modules/zod/dist/esm/v3/errors.js
6432
+ var overrideErrorMap = en_default;
6433
+ function setErrorMap(map) {
6434
+ overrideErrorMap = map;
6435
+ }
6436
+ __name(setErrorMap, "setErrorMap");
6437
+ function getErrorMap() {
6438
+ return overrideErrorMap;
6439
+ }
6440
+ __name(getErrorMap, "getErrorMap");
6441
+
6442
+ // ../../node_modules/.pnpm/zod@3.25.51/node_modules/zod/dist/esm/v3/helpers/parseUtil.js
6443
+ var makeIssue = /* @__PURE__ */ __name((params) => {
6444
+ const { data, path, errorMaps, issueData } = params;
6445
+ const fullPath = [...path, ...issueData.path || []];
6446
+ const fullIssue = {
6447
+ ...issueData,
6448
+ path: fullPath
6449
+ };
6450
+ if (issueData.message !== void 0) {
6451
+ return {
6452
+ ...issueData,
6453
+ path: fullPath,
6454
+ message: issueData.message
6455
+ };
6456
+ }
6457
+ let errorMessage = "";
6458
+ const maps = errorMaps.filter((m) => !!m).slice().reverse();
6459
+ for (const map of maps) {
6460
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
6461
+ }
6462
+ return {
6463
+ ...issueData,
6464
+ path: fullPath,
6465
+ message: errorMessage
6466
+ };
6467
+ }, "makeIssue");
6468
+ var EMPTY_PATH = [];
6469
+ function addIssueToContext(ctx, issueData) {
6470
+ const overrideMap = getErrorMap();
6471
+ const issue = makeIssue({
6472
+ issueData,
6473
+ data: ctx.data,
6474
+ path: ctx.path,
6475
+ errorMaps: [
6476
+ ctx.common.contextualErrorMap,
6477
+ // contextual error map is first priority
6478
+ ctx.schemaErrorMap,
6479
+ // then schema-bound map if available
6480
+ overrideMap,
6481
+ // then global override map
6482
+ overrideMap === en_default ? void 0 : en_default
6483
+ // then global default map
6484
+ ].filter((x) => !!x)
6485
+ });
6486
+ ctx.common.issues.push(issue);
6487
+ }
6488
+ __name(addIssueToContext, "addIssueToContext");
6489
+ var ParseStatus = class _ParseStatus {
6490
+ static {
6491
+ __name(this, "ParseStatus");
6492
+ }
6493
+ constructor() {
6494
+ this.value = "valid";
6495
+ }
6496
+ dirty() {
6497
+ if (this.value === "valid")
6498
+ this.value = "dirty";
6499
+ }
6500
+ abort() {
6501
+ if (this.value !== "aborted")
6502
+ this.value = "aborted";
6503
+ }
6504
+ static mergeArray(status, results) {
6505
+ const arrayValue = [];
6506
+ for (const s of results) {
6507
+ if (s.status === "aborted")
6508
+ return INVALID;
6509
+ if (s.status === "dirty")
6510
+ status.dirty();
6511
+ arrayValue.push(s.value);
6512
+ }
6513
+ return { status: status.value, value: arrayValue };
6514
+ }
6515
+ static async mergeObjectAsync(status, pairs) {
6516
+ const syncPairs = [];
6517
+ for (const pair of pairs) {
6518
+ const key = await pair.key;
6519
+ const value = await pair.value;
6520
+ syncPairs.push({
6521
+ key,
6522
+ value
6523
+ });
6524
+ }
6525
+ return _ParseStatus.mergeObjectSync(status, syncPairs);
6526
+ }
6527
+ static mergeObjectSync(status, pairs) {
6528
+ const finalObject = {};
6529
+ for (const pair of pairs) {
6530
+ const { key, value } = pair;
6531
+ if (key.status === "aborted")
6532
+ return INVALID;
6533
+ if (value.status === "aborted")
6534
+ return INVALID;
6535
+ if (key.status === "dirty")
6536
+ status.dirty();
6537
+ if (value.status === "dirty")
6538
+ status.dirty();
6539
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
6540
+ finalObject[key.value] = value.value;
6541
+ }
6542
+ }
6543
+ return { status: status.value, value: finalObject };
6544
+ }
6545
+ };
6546
+ var INVALID = Object.freeze({
6547
+ status: "aborted"
6548
+ });
6549
+ var DIRTY = /* @__PURE__ */ __name((value) => ({ status: "dirty", value }), "DIRTY");
6550
+ var OK = /* @__PURE__ */ __name((value) => ({ status: "valid", value }), "OK");
6551
+ var isAborted = /* @__PURE__ */ __name((x) => x.status === "aborted", "isAborted");
6552
+ var isDirty = /* @__PURE__ */ __name((x) => x.status === "dirty", "isDirty");
6553
+ var isValid = /* @__PURE__ */ __name((x) => x.status === "valid", "isValid");
6554
+ var isAsync = /* @__PURE__ */ __name((x) => typeof Promise !== "undefined" && x instanceof Promise, "isAsync");
6555
+
6556
+ // ../../node_modules/.pnpm/zod@3.25.51/node_modules/zod/dist/esm/v3/helpers/errorUtil.js
6557
+ var errorUtil;
6558
+ (function(errorUtil2) {
6559
+ errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
6560
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
6561
+ })(errorUtil || (errorUtil = {}));
6562
+
6563
+ // ../../node_modules/.pnpm/zod@3.25.51/node_modules/zod/dist/esm/v3/types.js
6564
+ var ParseInputLazyPath = class {
6565
+ static {
6566
+ __name(this, "ParseInputLazyPath");
6567
+ }
6568
+ constructor(parent, value, path, key) {
6569
+ this._cachedPath = [];
6570
+ this.parent = parent;
6571
+ this.data = value;
6572
+ this._path = path;
6573
+ this._key = key;
6574
+ }
6575
+ get path() {
6576
+ if (!this._cachedPath.length) {
6577
+ if (Array.isArray(this._key)) {
6578
+ this._cachedPath.push(...this._path, ...this._key);
6579
+ } else {
6580
+ this._cachedPath.push(...this._path, this._key);
6581
+ }
6582
+ }
6583
+ return this._cachedPath;
6584
+ }
6585
+ };
6586
+ var handleResult = /* @__PURE__ */ __name((ctx, result) => {
6587
+ if (isValid(result)) {
6588
+ return { success: true, data: result.value };
6589
+ } else {
6590
+ if (!ctx.common.issues.length) {
6591
+ throw new Error("Validation failed but no issues detected.");
6592
+ }
6593
+ return {
6594
+ success: false,
6595
+ get error() {
6596
+ if (this._error)
6597
+ return this._error;
6598
+ const error = new ZodError(ctx.common.issues);
6599
+ this._error = error;
6600
+ return this._error;
6601
+ }
6602
+ };
6603
+ }
6604
+ }, "handleResult");
6605
+ function processCreateParams(params) {
6606
+ if (!params)
6607
+ return {};
6608
+ const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
6609
+ if (errorMap2 && (invalid_type_error || required_error)) {
6610
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
6611
+ }
6612
+ if (errorMap2)
6613
+ return { errorMap: errorMap2, description };
6614
+ const customMap = /* @__PURE__ */ __name((iss, ctx) => {
6615
+ const { message } = params;
6616
+ if (iss.code === "invalid_enum_value") {
6617
+ return { message: message ?? ctx.defaultError };
6618
+ }
6619
+ if (typeof ctx.data === "undefined") {
6620
+ return { message: message ?? required_error ?? ctx.defaultError };
6621
+ }
6622
+ if (iss.code !== "invalid_type")
6623
+ return { message: ctx.defaultError };
6624
+ return { message: message ?? invalid_type_error ?? ctx.defaultError };
6625
+ }, "customMap");
6626
+ return { errorMap: customMap, description };
6627
+ }
6628
+ __name(processCreateParams, "processCreateParams");
6629
+ var ZodType = class {
6630
+ static {
6631
+ __name(this, "ZodType");
6632
+ }
6633
+ get description() {
6634
+ return this._def.description;
6635
+ }
6636
+ _getType(input) {
6637
+ return getParsedType(input.data);
6638
+ }
6639
+ _getOrReturnCtx(input, ctx) {
6640
+ return ctx || {
6641
+ common: input.parent.common,
6642
+ data: input.data,
6643
+ parsedType: getParsedType(input.data),
6644
+ schemaErrorMap: this._def.errorMap,
6645
+ path: input.path,
6646
+ parent: input.parent
6647
+ };
6648
+ }
6649
+ _processInputParams(input) {
6650
+ return {
6651
+ status: new ParseStatus(),
6652
+ ctx: {
6653
+ common: input.parent.common,
6654
+ data: input.data,
6655
+ parsedType: getParsedType(input.data),
6656
+ schemaErrorMap: this._def.errorMap,
6657
+ path: input.path,
6658
+ parent: input.parent
6659
+ }
6660
+ };
6661
+ }
6662
+ _parseSync(input) {
6663
+ const result = this._parse(input);
6664
+ if (isAsync(result)) {
6665
+ throw new Error("Synchronous parse encountered promise.");
6666
+ }
6667
+ return result;
6668
+ }
6669
+ _parseAsync(input) {
6670
+ const result = this._parse(input);
6671
+ return Promise.resolve(result);
6672
+ }
6673
+ parse(data, params) {
6674
+ const result = this.safeParse(data, params);
6675
+ if (result.success)
6676
+ return result.data;
6677
+ throw result.error;
6678
+ }
6679
+ safeParse(data, params) {
6680
+ const ctx = {
6681
+ common: {
6682
+ issues: [],
6683
+ async: params?.async ?? false,
6684
+ contextualErrorMap: params?.errorMap
6685
+ },
6686
+ path: params?.path || [],
6687
+ schemaErrorMap: this._def.errorMap,
6688
+ parent: null,
6689
+ data,
6690
+ parsedType: getParsedType(data)
6691
+ };
6692
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
6693
+ return handleResult(ctx, result);
6694
+ }
6695
+ "~validate"(data) {
6696
+ const ctx = {
6697
+ common: {
6698
+ issues: [],
6699
+ async: !!this["~standard"].async
6700
+ },
6701
+ path: [],
6702
+ schemaErrorMap: this._def.errorMap,
6703
+ parent: null,
6704
+ data,
6705
+ parsedType: getParsedType(data)
6706
+ };
6707
+ if (!this["~standard"].async) {
6708
+ try {
6709
+ const result = this._parseSync({ data, path: [], parent: ctx });
6710
+ return isValid(result) ? {
6711
+ value: result.value
6712
+ } : {
6713
+ issues: ctx.common.issues
6714
+ };
6715
+ } catch (err) {
6716
+ if (err?.message?.toLowerCase()?.includes("encountered")) {
6717
+ this["~standard"].async = true;
6718
+ }
6719
+ ctx.common = {
6720
+ issues: [],
6721
+ async: true
6722
+ };
6723
+ }
6724
+ }
6725
+ return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
6726
+ value: result.value
6727
+ } : {
6728
+ issues: ctx.common.issues
6729
+ });
6730
+ }
6731
+ async parseAsync(data, params) {
6732
+ const result = await this.safeParseAsync(data, params);
6733
+ if (result.success)
6734
+ return result.data;
6735
+ throw result.error;
6736
+ }
6737
+ async safeParseAsync(data, params) {
6738
+ const ctx = {
6739
+ common: {
6740
+ issues: [],
6741
+ contextualErrorMap: params?.errorMap,
6742
+ async: true
6743
+ },
6744
+ path: params?.path || [],
6745
+ schemaErrorMap: this._def.errorMap,
6746
+ parent: null,
6747
+ data,
6748
+ parsedType: getParsedType(data)
6749
+ };
6750
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
6751
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
6752
+ return handleResult(ctx, result);
6753
+ }
6754
+ refine(check, message) {
6755
+ const getIssueProperties = /* @__PURE__ */ __name((val) => {
6756
+ if (typeof message === "string" || typeof message === "undefined") {
6757
+ return { message };
6758
+ } else if (typeof message === "function") {
6759
+ return message(val);
6760
+ } else {
6761
+ return message;
6762
+ }
6763
+ }, "getIssueProperties");
6764
+ return this._refinement((val, ctx) => {
6765
+ const result = check(val);
6766
+ const setError = /* @__PURE__ */ __name(() => ctx.addIssue({
6767
+ code: ZodIssueCode.custom,
6768
+ ...getIssueProperties(val)
6769
+ }), "setError");
6770
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
6771
+ return result.then((data) => {
6772
+ if (!data) {
6773
+ setError();
6774
+ return false;
6775
+ } else {
6776
+ return true;
6777
+ }
6778
+ });
6779
+ }
6780
+ if (!result) {
6781
+ setError();
6782
+ return false;
6783
+ } else {
6784
+ return true;
6785
+ }
6786
+ });
6787
+ }
6788
+ refinement(check, refinementData) {
6789
+ return this._refinement((val, ctx) => {
6790
+ if (!check(val)) {
6791
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
6792
+ return false;
6793
+ } else {
6794
+ return true;
6795
+ }
6796
+ });
6797
+ }
6798
+ _refinement(refinement) {
6799
+ return new ZodEffects({
6800
+ schema: this,
6801
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
6802
+ effect: { type: "refinement", refinement }
6803
+ });
6804
+ }
6805
+ superRefine(refinement) {
6806
+ return this._refinement(refinement);
6807
+ }
6808
+ constructor(def) {
6809
+ this.spa = this.safeParseAsync;
6810
+ this._def = def;
6811
+ this.parse = this.parse.bind(this);
6812
+ this.safeParse = this.safeParse.bind(this);
6813
+ this.parseAsync = this.parseAsync.bind(this);
6814
+ this.safeParseAsync = this.safeParseAsync.bind(this);
6815
+ this.spa = this.spa.bind(this);
6816
+ this.refine = this.refine.bind(this);
6817
+ this.refinement = this.refinement.bind(this);
6818
+ this.superRefine = this.superRefine.bind(this);
6819
+ this.optional = this.optional.bind(this);
6820
+ this.nullable = this.nullable.bind(this);
6821
+ this.nullish = this.nullish.bind(this);
6822
+ this.array = this.array.bind(this);
6823
+ this.promise = this.promise.bind(this);
6824
+ this.or = this.or.bind(this);
6825
+ this.and = this.and.bind(this);
6826
+ this.transform = this.transform.bind(this);
6827
+ this.brand = this.brand.bind(this);
6828
+ this.default = this.default.bind(this);
6829
+ this.catch = this.catch.bind(this);
6830
+ this.describe = this.describe.bind(this);
6831
+ this.pipe = this.pipe.bind(this);
6832
+ this.readonly = this.readonly.bind(this);
6833
+ this.isNullable = this.isNullable.bind(this);
6834
+ this.isOptional = this.isOptional.bind(this);
6835
+ this["~standard"] = {
6836
+ version: 1,
6837
+ vendor: "zod",
6838
+ validate: /* @__PURE__ */ __name((data) => this["~validate"](data), "validate")
6839
+ };
6840
+ }
6841
+ optional() {
6842
+ return ZodOptional.create(this, this._def);
6843
+ }
6844
+ nullable() {
6845
+ return ZodNullable.create(this, this._def);
6846
+ }
6847
+ nullish() {
6848
+ return this.nullable().optional();
6849
+ }
6850
+ array() {
6851
+ return ZodArray.create(this);
6852
+ }
6853
+ promise() {
6854
+ return ZodPromise.create(this, this._def);
6855
+ }
6856
+ or(option) {
6857
+ return ZodUnion.create([this, option], this._def);
6858
+ }
6859
+ and(incoming) {
6860
+ return ZodIntersection.create(this, incoming, this._def);
6861
+ }
6862
+ transform(transform) {
6863
+ return new ZodEffects({
6864
+ ...processCreateParams(this._def),
6865
+ schema: this,
6866
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
6867
+ effect: { type: "transform", transform }
6868
+ });
6869
+ }
6870
+ default(def) {
6871
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
6872
+ return new ZodDefault({
6873
+ ...processCreateParams(this._def),
6874
+ innerType: this,
6875
+ defaultValue: defaultValueFunc,
6876
+ typeName: ZodFirstPartyTypeKind.ZodDefault
6877
+ });
6878
+ }
6879
+ brand() {
6880
+ return new ZodBranded({
6881
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
6882
+ type: this,
6883
+ ...processCreateParams(this._def)
6884
+ });
6885
+ }
6886
+ catch(def) {
6887
+ const catchValueFunc = typeof def === "function" ? def : () => def;
6888
+ return new ZodCatch({
6889
+ ...processCreateParams(this._def),
6890
+ innerType: this,
6891
+ catchValue: catchValueFunc,
6892
+ typeName: ZodFirstPartyTypeKind.ZodCatch
6893
+ });
6894
+ }
6895
+ describe(description) {
6896
+ const This = this.constructor;
6897
+ return new This({
6898
+ ...this._def,
6899
+ description
6900
+ });
6901
+ }
6902
+ pipe(target) {
6903
+ return ZodPipeline.create(this, target);
6904
+ }
6905
+ readonly() {
6906
+ return ZodReadonly.create(this);
6907
+ }
6908
+ isOptional() {
6909
+ return this.safeParse(void 0).success;
6910
+ }
6911
+ isNullable() {
6912
+ return this.safeParse(null).success;
6913
+ }
6914
+ };
6915
+ var cuidRegex = /^c[^\s-]{8,}$/i;
6916
+ var cuid2Regex = /^[0-9a-z]+$/;
6917
+ var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
6918
+ 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;
6919
+ var nanoidRegex = /^[a-z0-9_-]{21}$/i;
6920
+ var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
6921
+ 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)?)??$/;
6922
+ var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
6923
+ var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
6924
+ var emojiRegex;
6925
+ 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])$/;
6926
+ var ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
6927
+ var ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
6928
+ var ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
6929
+ var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
6930
+ var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
6931
+ 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])))`;
6932
+ var dateRegex = new RegExp(`^${dateRegexSource}$`);
6933
+ function timeRegexSource(args) {
6934
+ let secondsRegexSource = `[0-5]\\d`;
6935
+ if (args.precision) {
6936
+ secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
6937
+ } else if (args.precision == null) {
6938
+ secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
6939
+ }
6940
+ const secondsQuantifier = args.precision ? "+" : "?";
6941
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
6942
+ }
6943
+ __name(timeRegexSource, "timeRegexSource");
6944
+ function timeRegex(args) {
6945
+ return new RegExp(`^${timeRegexSource(args)}$`);
6946
+ }
6947
+ __name(timeRegex, "timeRegex");
6948
+ function datetimeRegex(args) {
6949
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
6950
+ const opts = [];
6951
+ opts.push(args.local ? `Z?` : `Z`);
6952
+ if (args.offset)
6953
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
6954
+ regex = `${regex}(${opts.join("|")})`;
6955
+ return new RegExp(`^${regex}$`);
6956
+ }
6957
+ __name(datetimeRegex, "datetimeRegex");
6958
+ function isValidIP(ip, version) {
6959
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
6960
+ return true;
6961
+ }
6962
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
6963
+ return true;
6964
+ }
6965
+ return false;
6966
+ }
6967
+ __name(isValidIP, "isValidIP");
6968
+ function isValidJWT(jwt, alg) {
6969
+ if (!jwtRegex.test(jwt))
6970
+ return false;
6971
+ try {
6972
+ const [header] = jwt.split(".");
6973
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
6974
+ const decoded = JSON.parse(atob(base64));
6975
+ if (typeof decoded !== "object" || decoded === null)
6976
+ return false;
6977
+ if ("typ" in decoded && decoded?.typ !== "JWT")
6978
+ return false;
6979
+ if (!decoded.alg)
6980
+ return false;
6981
+ if (alg && decoded.alg !== alg)
6982
+ return false;
6983
+ return true;
6984
+ } catch {
6985
+ return false;
6986
+ }
6987
+ }
6988
+ __name(isValidJWT, "isValidJWT");
6989
+ function isValidCidr(ip, version) {
6990
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
6991
+ return true;
6992
+ }
6993
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
6994
+ return true;
6995
+ }
6996
+ return false;
6997
+ }
6998
+ __name(isValidCidr, "isValidCidr");
6999
+ var ZodString = class _ZodString extends ZodType {
7000
+ static {
7001
+ __name(this, "ZodString");
7002
+ }
7003
+ _parse(input) {
7004
+ if (this._def.coerce) {
7005
+ input.data = String(input.data);
7006
+ }
7007
+ const parsedType = this._getType(input);
7008
+ if (parsedType !== ZodParsedType.string) {
7009
+ const ctx2 = this._getOrReturnCtx(input);
7010
+ addIssueToContext(ctx2, {
7011
+ code: ZodIssueCode.invalid_type,
7012
+ expected: ZodParsedType.string,
7013
+ received: ctx2.parsedType
7014
+ });
7015
+ return INVALID;
7016
+ }
7017
+ const status = new ParseStatus();
7018
+ let ctx = void 0;
7019
+ for (const check of this._def.checks) {
7020
+ if (check.kind === "min") {
7021
+ if (input.data.length < check.value) {
7022
+ ctx = this._getOrReturnCtx(input, ctx);
7023
+ addIssueToContext(ctx, {
7024
+ code: ZodIssueCode.too_small,
7025
+ minimum: check.value,
7026
+ type: "string",
7027
+ inclusive: true,
7028
+ exact: false,
7029
+ message: check.message
7030
+ });
7031
+ status.dirty();
7032
+ }
7033
+ } else if (check.kind === "max") {
7034
+ if (input.data.length > check.value) {
7035
+ ctx = this._getOrReturnCtx(input, ctx);
7036
+ addIssueToContext(ctx, {
7037
+ code: ZodIssueCode.too_big,
7038
+ maximum: check.value,
7039
+ type: "string",
7040
+ inclusive: true,
7041
+ exact: false,
7042
+ message: check.message
7043
+ });
7044
+ status.dirty();
7045
+ }
7046
+ } else if (check.kind === "length") {
7047
+ const tooBig = input.data.length > check.value;
7048
+ const tooSmall = input.data.length < check.value;
7049
+ if (tooBig || tooSmall) {
7050
+ ctx = this._getOrReturnCtx(input, ctx);
7051
+ if (tooBig) {
7052
+ addIssueToContext(ctx, {
7053
+ code: ZodIssueCode.too_big,
7054
+ maximum: check.value,
7055
+ type: "string",
7056
+ inclusive: true,
7057
+ exact: true,
7058
+ message: check.message
7059
+ });
7060
+ } else if (tooSmall) {
7061
+ addIssueToContext(ctx, {
7062
+ code: ZodIssueCode.too_small,
7063
+ minimum: check.value,
7064
+ type: "string",
7065
+ inclusive: true,
7066
+ exact: true,
7067
+ message: check.message
7068
+ });
7069
+ }
7070
+ status.dirty();
7071
+ }
7072
+ } else if (check.kind === "email") {
7073
+ if (!emailRegex.test(input.data)) {
7074
+ ctx = this._getOrReturnCtx(input, ctx);
7075
+ addIssueToContext(ctx, {
7076
+ validation: "email",
7077
+ code: ZodIssueCode.invalid_string,
7078
+ message: check.message
7079
+ });
7080
+ status.dirty();
7081
+ }
7082
+ } else if (check.kind === "emoji") {
7083
+ if (!emojiRegex) {
7084
+ emojiRegex = new RegExp(_emojiRegex, "u");
7085
+ }
7086
+ if (!emojiRegex.test(input.data)) {
7087
+ ctx = this._getOrReturnCtx(input, ctx);
7088
+ addIssueToContext(ctx, {
7089
+ validation: "emoji",
7090
+ code: ZodIssueCode.invalid_string,
7091
+ message: check.message
7092
+ });
7093
+ status.dirty();
7094
+ }
7095
+ } else if (check.kind === "uuid") {
7096
+ if (!uuidRegex.test(input.data)) {
7097
+ ctx = this._getOrReturnCtx(input, ctx);
7098
+ addIssueToContext(ctx, {
7099
+ validation: "uuid",
7100
+ code: ZodIssueCode.invalid_string,
7101
+ message: check.message
7102
+ });
7103
+ status.dirty();
7104
+ }
7105
+ } else if (check.kind === "nanoid") {
7106
+ if (!nanoidRegex.test(input.data)) {
7107
+ ctx = this._getOrReturnCtx(input, ctx);
7108
+ addIssueToContext(ctx, {
7109
+ validation: "nanoid",
7110
+ code: ZodIssueCode.invalid_string,
7111
+ message: check.message
7112
+ });
7113
+ status.dirty();
7114
+ }
7115
+ } else if (check.kind === "cuid") {
7116
+ if (!cuidRegex.test(input.data)) {
7117
+ ctx = this._getOrReturnCtx(input, ctx);
7118
+ addIssueToContext(ctx, {
7119
+ validation: "cuid",
7120
+ code: ZodIssueCode.invalid_string,
7121
+ message: check.message
7122
+ });
7123
+ status.dirty();
7124
+ }
7125
+ } else if (check.kind === "cuid2") {
7126
+ if (!cuid2Regex.test(input.data)) {
7127
+ ctx = this._getOrReturnCtx(input, ctx);
7128
+ addIssueToContext(ctx, {
7129
+ validation: "cuid2",
7130
+ code: ZodIssueCode.invalid_string,
7131
+ message: check.message
7132
+ });
7133
+ status.dirty();
7134
+ }
7135
+ } else if (check.kind === "ulid") {
7136
+ if (!ulidRegex.test(input.data)) {
7137
+ ctx = this._getOrReturnCtx(input, ctx);
7138
+ addIssueToContext(ctx, {
7139
+ validation: "ulid",
7140
+ code: ZodIssueCode.invalid_string,
7141
+ message: check.message
7142
+ });
7143
+ status.dirty();
7144
+ }
7145
+ } else if (check.kind === "url") {
7146
+ try {
7147
+ new URL(input.data);
7148
+ } catch {
7149
+ ctx = this._getOrReturnCtx(input, ctx);
7150
+ addIssueToContext(ctx, {
7151
+ validation: "url",
7152
+ code: ZodIssueCode.invalid_string,
7153
+ message: check.message
7154
+ });
7155
+ status.dirty();
7156
+ }
7157
+ } else if (check.kind === "regex") {
7158
+ check.regex.lastIndex = 0;
7159
+ const testResult = check.regex.test(input.data);
7160
+ if (!testResult) {
7161
+ ctx = this._getOrReturnCtx(input, ctx);
7162
+ addIssueToContext(ctx, {
7163
+ validation: "regex",
7164
+ code: ZodIssueCode.invalid_string,
7165
+ message: check.message
7166
+ });
7167
+ status.dirty();
7168
+ }
7169
+ } else if (check.kind === "trim") {
7170
+ input.data = input.data.trim();
7171
+ } else if (check.kind === "includes") {
7172
+ if (!input.data.includes(check.value, check.position)) {
7173
+ ctx = this._getOrReturnCtx(input, ctx);
7174
+ addIssueToContext(ctx, {
7175
+ code: ZodIssueCode.invalid_string,
7176
+ validation: { includes: check.value, position: check.position },
7177
+ message: check.message
7178
+ });
7179
+ status.dirty();
7180
+ }
7181
+ } else if (check.kind === "toLowerCase") {
7182
+ input.data = input.data.toLowerCase();
7183
+ } else if (check.kind === "toUpperCase") {
7184
+ input.data = input.data.toUpperCase();
7185
+ } else if (check.kind === "startsWith") {
7186
+ if (!input.data.startsWith(check.value)) {
7187
+ ctx = this._getOrReturnCtx(input, ctx);
7188
+ addIssueToContext(ctx, {
7189
+ code: ZodIssueCode.invalid_string,
7190
+ validation: { startsWith: check.value },
7191
+ message: check.message
7192
+ });
7193
+ status.dirty();
7194
+ }
7195
+ } else if (check.kind === "endsWith") {
7196
+ if (!input.data.endsWith(check.value)) {
7197
+ ctx = this._getOrReturnCtx(input, ctx);
7198
+ addIssueToContext(ctx, {
7199
+ code: ZodIssueCode.invalid_string,
7200
+ validation: { endsWith: check.value },
7201
+ message: check.message
7202
+ });
7203
+ status.dirty();
7204
+ }
7205
+ } else if (check.kind === "datetime") {
7206
+ const regex = datetimeRegex(check);
7207
+ if (!regex.test(input.data)) {
7208
+ ctx = this._getOrReturnCtx(input, ctx);
7209
+ addIssueToContext(ctx, {
7210
+ code: ZodIssueCode.invalid_string,
7211
+ validation: "datetime",
7212
+ message: check.message
7213
+ });
7214
+ status.dirty();
7215
+ }
7216
+ } else if (check.kind === "date") {
7217
+ const regex = dateRegex;
7218
+ if (!regex.test(input.data)) {
7219
+ ctx = this._getOrReturnCtx(input, ctx);
7220
+ addIssueToContext(ctx, {
7221
+ code: ZodIssueCode.invalid_string,
7222
+ validation: "date",
7223
+ message: check.message
7224
+ });
7225
+ status.dirty();
7226
+ }
7227
+ } else if (check.kind === "time") {
7228
+ const regex = timeRegex(check);
7229
+ if (!regex.test(input.data)) {
7230
+ ctx = this._getOrReturnCtx(input, ctx);
7231
+ addIssueToContext(ctx, {
7232
+ code: ZodIssueCode.invalid_string,
7233
+ validation: "time",
7234
+ message: check.message
7235
+ });
7236
+ status.dirty();
7237
+ }
7238
+ } else if (check.kind === "duration") {
7239
+ if (!durationRegex.test(input.data)) {
7240
+ ctx = this._getOrReturnCtx(input, ctx);
7241
+ addIssueToContext(ctx, {
7242
+ validation: "duration",
7243
+ code: ZodIssueCode.invalid_string,
7244
+ message: check.message
7245
+ });
7246
+ status.dirty();
7247
+ }
7248
+ } else if (check.kind === "ip") {
7249
+ if (!isValidIP(input.data, check.version)) {
7250
+ ctx = this._getOrReturnCtx(input, ctx);
7251
+ addIssueToContext(ctx, {
7252
+ validation: "ip",
7253
+ code: ZodIssueCode.invalid_string,
7254
+ message: check.message
7255
+ });
7256
+ status.dirty();
7257
+ }
7258
+ } else if (check.kind === "jwt") {
7259
+ if (!isValidJWT(input.data, check.alg)) {
7260
+ ctx = this._getOrReturnCtx(input, ctx);
7261
+ addIssueToContext(ctx, {
7262
+ validation: "jwt",
7263
+ code: ZodIssueCode.invalid_string,
7264
+ message: check.message
7265
+ });
7266
+ status.dirty();
7267
+ }
7268
+ } else if (check.kind === "cidr") {
7269
+ if (!isValidCidr(input.data, check.version)) {
7270
+ ctx = this._getOrReturnCtx(input, ctx);
7271
+ addIssueToContext(ctx, {
7272
+ validation: "cidr",
7273
+ code: ZodIssueCode.invalid_string,
7274
+ message: check.message
7275
+ });
7276
+ status.dirty();
7277
+ }
7278
+ } else if (check.kind === "base64") {
7279
+ if (!base64Regex.test(input.data)) {
7280
+ ctx = this._getOrReturnCtx(input, ctx);
7281
+ addIssueToContext(ctx, {
7282
+ validation: "base64",
7283
+ code: ZodIssueCode.invalid_string,
7284
+ message: check.message
7285
+ });
7286
+ status.dirty();
7287
+ }
7288
+ } else if (check.kind === "base64url") {
7289
+ if (!base64urlRegex.test(input.data)) {
7290
+ ctx = this._getOrReturnCtx(input, ctx);
7291
+ addIssueToContext(ctx, {
7292
+ validation: "base64url",
7293
+ code: ZodIssueCode.invalid_string,
7294
+ message: check.message
7295
+ });
7296
+ status.dirty();
7297
+ }
7298
+ } else {
7299
+ util.assertNever(check);
7300
+ }
7301
+ }
7302
+ return { status: status.value, value: input.data };
7303
+ }
7304
+ _regex(regex, validation, message) {
7305
+ return this.refinement((data) => regex.test(data), {
7306
+ validation,
7307
+ code: ZodIssueCode.invalid_string,
7308
+ ...errorUtil.errToObj(message)
7309
+ });
7310
+ }
7311
+ _addCheck(check) {
7312
+ return new _ZodString({
7313
+ ...this._def,
7314
+ checks: [...this._def.checks, check]
7315
+ });
7316
+ }
7317
+ email(message) {
7318
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
7319
+ }
7320
+ url(message) {
7321
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
7322
+ }
7323
+ emoji(message) {
7324
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
7325
+ }
7326
+ uuid(message) {
7327
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
7328
+ }
7329
+ nanoid(message) {
7330
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
7331
+ }
7332
+ cuid(message) {
7333
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
7334
+ }
7335
+ cuid2(message) {
7336
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
7337
+ }
7338
+ ulid(message) {
7339
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
7340
+ }
7341
+ base64(message) {
7342
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
7343
+ }
7344
+ base64url(message) {
7345
+ return this._addCheck({
7346
+ kind: "base64url",
7347
+ ...errorUtil.errToObj(message)
7348
+ });
7349
+ }
7350
+ jwt(options) {
7351
+ return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
7352
+ }
7353
+ ip(options) {
7354
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
7355
+ }
7356
+ cidr(options) {
7357
+ return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
7358
+ }
7359
+ datetime(options) {
7360
+ if (typeof options === "string") {
7361
+ return this._addCheck({
7362
+ kind: "datetime",
7363
+ precision: null,
7364
+ offset: false,
7365
+ local: false,
7366
+ message: options
7367
+ });
7368
+ }
7369
+ return this._addCheck({
7370
+ kind: "datetime",
7371
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
7372
+ offset: options?.offset ?? false,
7373
+ local: options?.local ?? false,
7374
+ ...errorUtil.errToObj(options?.message)
7375
+ });
7376
+ }
7377
+ date(message) {
7378
+ return this._addCheck({ kind: "date", message });
7379
+ }
7380
+ time(options) {
7381
+ if (typeof options === "string") {
7382
+ return this._addCheck({
7383
+ kind: "time",
7384
+ precision: null,
7385
+ message: options
7386
+ });
7387
+ }
7388
+ return this._addCheck({
7389
+ kind: "time",
7390
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
7391
+ ...errorUtil.errToObj(options?.message)
7392
+ });
7393
+ }
7394
+ duration(message) {
7395
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
7396
+ }
7397
+ regex(regex, message) {
7398
+ return this._addCheck({
7399
+ kind: "regex",
7400
+ regex,
7401
+ ...errorUtil.errToObj(message)
7402
+ });
7403
+ }
7404
+ includes(value, options) {
7405
+ return this._addCheck({
7406
+ kind: "includes",
7407
+ value,
7408
+ position: options?.position,
7409
+ ...errorUtil.errToObj(options?.message)
7410
+ });
7411
+ }
7412
+ startsWith(value, message) {
7413
+ return this._addCheck({
7414
+ kind: "startsWith",
7415
+ value,
7416
+ ...errorUtil.errToObj(message)
7417
+ });
7418
+ }
7419
+ endsWith(value, message) {
7420
+ return this._addCheck({
7421
+ kind: "endsWith",
7422
+ value,
7423
+ ...errorUtil.errToObj(message)
7424
+ });
7425
+ }
7426
+ min(minLength, message) {
7427
+ return this._addCheck({
7428
+ kind: "min",
7429
+ value: minLength,
7430
+ ...errorUtil.errToObj(message)
7431
+ });
7432
+ }
7433
+ max(maxLength, message) {
7434
+ return this._addCheck({
7435
+ kind: "max",
7436
+ value: maxLength,
7437
+ ...errorUtil.errToObj(message)
7438
+ });
7439
+ }
7440
+ length(len, message) {
7441
+ return this._addCheck({
7442
+ kind: "length",
7443
+ value: len,
7444
+ ...errorUtil.errToObj(message)
7445
+ });
7446
+ }
7447
+ /**
7448
+ * Equivalent to `.min(1)`
7449
+ */
7450
+ nonempty(message) {
7451
+ return this.min(1, errorUtil.errToObj(message));
7452
+ }
7453
+ trim() {
7454
+ return new _ZodString({
7455
+ ...this._def,
7456
+ checks: [...this._def.checks, { kind: "trim" }]
7457
+ });
7458
+ }
7459
+ toLowerCase() {
7460
+ return new _ZodString({
7461
+ ...this._def,
7462
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
7463
+ });
7464
+ }
7465
+ toUpperCase() {
7466
+ return new _ZodString({
7467
+ ...this._def,
7468
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
7469
+ });
7470
+ }
7471
+ get isDatetime() {
7472
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
7473
+ }
7474
+ get isDate() {
7475
+ return !!this._def.checks.find((ch) => ch.kind === "date");
7476
+ }
7477
+ get isTime() {
7478
+ return !!this._def.checks.find((ch) => ch.kind === "time");
7479
+ }
7480
+ get isDuration() {
7481
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
7482
+ }
7483
+ get isEmail() {
7484
+ return !!this._def.checks.find((ch) => ch.kind === "email");
7485
+ }
7486
+ get isURL() {
7487
+ return !!this._def.checks.find((ch) => ch.kind === "url");
7488
+ }
7489
+ get isEmoji() {
7490
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
7491
+ }
7492
+ get isUUID() {
7493
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
7494
+ }
7495
+ get isNANOID() {
7496
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
7497
+ }
7498
+ get isCUID() {
7499
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
7500
+ }
7501
+ get isCUID2() {
7502
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
7503
+ }
7504
+ get isULID() {
7505
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
7506
+ }
7507
+ get isIP() {
7508
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
7509
+ }
7510
+ get isCIDR() {
7511
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
7512
+ }
7513
+ get isBase64() {
7514
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
7515
+ }
7516
+ get isBase64url() {
7517
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
7518
+ }
7519
+ get minLength() {
7520
+ let min = null;
7521
+ for (const ch of this._def.checks) {
7522
+ if (ch.kind === "min") {
7523
+ if (min === null || ch.value > min)
7524
+ min = ch.value;
7525
+ }
7526
+ }
7527
+ return min;
7528
+ }
7529
+ get maxLength() {
7530
+ let max = null;
7531
+ for (const ch of this._def.checks) {
7532
+ if (ch.kind === "max") {
7533
+ if (max === null || ch.value < max)
7534
+ max = ch.value;
7535
+ }
7536
+ }
7537
+ return max;
7538
+ }
7539
+ };
7540
+ ZodString.create = (params) => {
7541
+ return new ZodString({
7542
+ checks: [],
7543
+ typeName: ZodFirstPartyTypeKind.ZodString,
7544
+ coerce: params?.coerce ?? false,
7545
+ ...processCreateParams(params)
7546
+ });
7547
+ };
7548
+ function floatSafeRemainder(val, step) {
7549
+ const valDecCount = (val.toString().split(".")[1] || "").length;
7550
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
7551
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
7552
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
7553
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
7554
+ return valInt % stepInt / 10 ** decCount;
7555
+ }
7556
+ __name(floatSafeRemainder, "floatSafeRemainder");
7557
+ var ZodNumber = class _ZodNumber extends ZodType {
7558
+ static {
7559
+ __name(this, "ZodNumber");
7560
+ }
7561
+ constructor() {
7562
+ super(...arguments);
7563
+ this.min = this.gte;
7564
+ this.max = this.lte;
7565
+ this.step = this.multipleOf;
7566
+ }
7567
+ _parse(input) {
7568
+ if (this._def.coerce) {
7569
+ input.data = Number(input.data);
7570
+ }
7571
+ const parsedType = this._getType(input);
7572
+ if (parsedType !== ZodParsedType.number) {
7573
+ const ctx2 = this._getOrReturnCtx(input);
7574
+ addIssueToContext(ctx2, {
7575
+ code: ZodIssueCode.invalid_type,
7576
+ expected: ZodParsedType.number,
7577
+ received: ctx2.parsedType
7578
+ });
7579
+ return INVALID;
7580
+ }
7581
+ let ctx = void 0;
7582
+ const status = new ParseStatus();
7583
+ for (const check of this._def.checks) {
7584
+ if (check.kind === "int") {
7585
+ if (!util.isInteger(input.data)) {
7586
+ ctx = this._getOrReturnCtx(input, ctx);
7587
+ addIssueToContext(ctx, {
7588
+ code: ZodIssueCode.invalid_type,
7589
+ expected: "integer",
7590
+ received: "float",
7591
+ message: check.message
7592
+ });
7593
+ status.dirty();
7594
+ }
7595
+ } else if (check.kind === "min") {
7596
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
7597
+ if (tooSmall) {
7598
+ ctx = this._getOrReturnCtx(input, ctx);
7599
+ addIssueToContext(ctx, {
7600
+ code: ZodIssueCode.too_small,
7601
+ minimum: check.value,
7602
+ type: "number",
7603
+ inclusive: check.inclusive,
7604
+ exact: false,
7605
+ message: check.message
7606
+ });
7607
+ status.dirty();
7608
+ }
7609
+ } else if (check.kind === "max") {
7610
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
7611
+ if (tooBig) {
7612
+ ctx = this._getOrReturnCtx(input, ctx);
7613
+ addIssueToContext(ctx, {
7614
+ code: ZodIssueCode.too_big,
7615
+ maximum: check.value,
7616
+ type: "number",
7617
+ inclusive: check.inclusive,
7618
+ exact: false,
7619
+ message: check.message
7620
+ });
7621
+ status.dirty();
7622
+ }
7623
+ } else if (check.kind === "multipleOf") {
7624
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
7625
+ ctx = this._getOrReturnCtx(input, ctx);
7626
+ addIssueToContext(ctx, {
7627
+ code: ZodIssueCode.not_multiple_of,
7628
+ multipleOf: check.value,
7629
+ message: check.message
7630
+ });
7631
+ status.dirty();
7632
+ }
7633
+ } else if (check.kind === "finite") {
7634
+ if (!Number.isFinite(input.data)) {
7635
+ ctx = this._getOrReturnCtx(input, ctx);
7636
+ addIssueToContext(ctx, {
7637
+ code: ZodIssueCode.not_finite,
7638
+ message: check.message
7639
+ });
7640
+ status.dirty();
7641
+ }
7642
+ } else {
7643
+ util.assertNever(check);
7644
+ }
7645
+ }
7646
+ return { status: status.value, value: input.data };
7647
+ }
7648
+ gte(value, message) {
7649
+ return this.setLimit("min", value, true, errorUtil.toString(message));
7650
+ }
7651
+ gt(value, message) {
7652
+ return this.setLimit("min", value, false, errorUtil.toString(message));
7653
+ }
7654
+ lte(value, message) {
7655
+ return this.setLimit("max", value, true, errorUtil.toString(message));
7656
+ }
7657
+ lt(value, message) {
7658
+ return this.setLimit("max", value, false, errorUtil.toString(message));
7659
+ }
7660
+ setLimit(kind, value, inclusive, message) {
7661
+ return new _ZodNumber({
7662
+ ...this._def,
7663
+ checks: [
7664
+ ...this._def.checks,
7665
+ {
7666
+ kind,
7667
+ value,
7668
+ inclusive,
7669
+ message: errorUtil.toString(message)
7670
+ }
7671
+ ]
7672
+ });
7673
+ }
7674
+ _addCheck(check) {
7675
+ return new _ZodNumber({
7676
+ ...this._def,
7677
+ checks: [...this._def.checks, check]
7678
+ });
7679
+ }
7680
+ int(message) {
7681
+ return this._addCheck({
7682
+ kind: "int",
7683
+ message: errorUtil.toString(message)
7684
+ });
7685
+ }
7686
+ positive(message) {
7687
+ return this._addCheck({
7688
+ kind: "min",
7689
+ value: 0,
7690
+ inclusive: false,
7691
+ message: errorUtil.toString(message)
7692
+ });
7693
+ }
7694
+ negative(message) {
7695
+ return this._addCheck({
7696
+ kind: "max",
7697
+ value: 0,
7698
+ inclusive: false,
7699
+ message: errorUtil.toString(message)
7700
+ });
7701
+ }
7702
+ nonpositive(message) {
7703
+ return this._addCheck({
7704
+ kind: "max",
7705
+ value: 0,
7706
+ inclusive: true,
7707
+ message: errorUtil.toString(message)
7708
+ });
7709
+ }
7710
+ nonnegative(message) {
7711
+ return this._addCheck({
7712
+ kind: "min",
7713
+ value: 0,
7714
+ inclusive: true,
7715
+ message: errorUtil.toString(message)
7716
+ });
7717
+ }
7718
+ multipleOf(value, message) {
7719
+ return this._addCheck({
7720
+ kind: "multipleOf",
7721
+ value,
7722
+ message: errorUtil.toString(message)
7723
+ });
7724
+ }
7725
+ finite(message) {
7726
+ return this._addCheck({
7727
+ kind: "finite",
7728
+ message: errorUtil.toString(message)
7729
+ });
7730
+ }
7731
+ safe(message) {
7732
+ return this._addCheck({
7733
+ kind: "min",
7734
+ inclusive: true,
7735
+ value: Number.MIN_SAFE_INTEGER,
7736
+ message: errorUtil.toString(message)
7737
+ })._addCheck({
7738
+ kind: "max",
7739
+ inclusive: true,
7740
+ value: Number.MAX_SAFE_INTEGER,
7741
+ message: errorUtil.toString(message)
7742
+ });
7743
+ }
7744
+ get minValue() {
7745
+ let min = null;
7746
+ for (const ch of this._def.checks) {
7747
+ if (ch.kind === "min") {
7748
+ if (min === null || ch.value > min)
7749
+ min = ch.value;
7750
+ }
7751
+ }
7752
+ return min;
7753
+ }
7754
+ get maxValue() {
7755
+ let max = null;
7756
+ for (const ch of this._def.checks) {
7757
+ if (ch.kind === "max") {
7758
+ if (max === null || ch.value < max)
7759
+ max = ch.value;
7760
+ }
7761
+ }
7762
+ return max;
7763
+ }
7764
+ get isInt() {
7765
+ return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
7766
+ }
7767
+ get isFinite() {
7768
+ let max = null;
7769
+ let min = null;
7770
+ for (const ch of this._def.checks) {
7771
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
7772
+ return true;
7773
+ } else if (ch.kind === "min") {
7774
+ if (min === null || ch.value > min)
7775
+ min = ch.value;
7776
+ } else if (ch.kind === "max") {
7777
+ if (max === null || ch.value < max)
7778
+ max = ch.value;
7779
+ }
7780
+ }
7781
+ return Number.isFinite(min) && Number.isFinite(max);
7782
+ }
7783
+ };
7784
+ ZodNumber.create = (params) => {
7785
+ return new ZodNumber({
7786
+ checks: [],
7787
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
7788
+ coerce: params?.coerce || false,
7789
+ ...processCreateParams(params)
7790
+ });
7791
+ };
7792
+ var ZodBigInt = class _ZodBigInt extends ZodType {
7793
+ static {
7794
+ __name(this, "ZodBigInt");
7795
+ }
7796
+ constructor() {
7797
+ super(...arguments);
7798
+ this.min = this.gte;
7799
+ this.max = this.lte;
7800
+ }
7801
+ _parse(input) {
7802
+ if (this._def.coerce) {
7803
+ try {
7804
+ input.data = BigInt(input.data);
7805
+ } catch {
7806
+ return this._getInvalidInput(input);
7807
+ }
7808
+ }
7809
+ const parsedType = this._getType(input);
7810
+ if (parsedType !== ZodParsedType.bigint) {
7811
+ return this._getInvalidInput(input);
7812
+ }
7813
+ let ctx = void 0;
7814
+ const status = new ParseStatus();
7815
+ for (const check of this._def.checks) {
7816
+ if (check.kind === "min") {
7817
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
7818
+ if (tooSmall) {
7819
+ ctx = this._getOrReturnCtx(input, ctx);
7820
+ addIssueToContext(ctx, {
7821
+ code: ZodIssueCode.too_small,
7822
+ type: "bigint",
7823
+ minimum: check.value,
7824
+ inclusive: check.inclusive,
7825
+ message: check.message
7826
+ });
7827
+ status.dirty();
7828
+ }
7829
+ } else if (check.kind === "max") {
7830
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
7831
+ if (tooBig) {
7832
+ ctx = this._getOrReturnCtx(input, ctx);
7833
+ addIssueToContext(ctx, {
7834
+ code: ZodIssueCode.too_big,
7835
+ type: "bigint",
7836
+ maximum: check.value,
7837
+ inclusive: check.inclusive,
7838
+ message: check.message
7839
+ });
7840
+ status.dirty();
7841
+ }
7842
+ } else if (check.kind === "multipleOf") {
7843
+ if (input.data % check.value !== BigInt(0)) {
7844
+ ctx = this._getOrReturnCtx(input, ctx);
7845
+ addIssueToContext(ctx, {
7846
+ code: ZodIssueCode.not_multiple_of,
7847
+ multipleOf: check.value,
7848
+ message: check.message
7849
+ });
7850
+ status.dirty();
7851
+ }
7852
+ } else {
7853
+ util.assertNever(check);
7854
+ }
7855
+ }
7856
+ return { status: status.value, value: input.data };
7857
+ }
7858
+ _getInvalidInput(input) {
7859
+ const ctx = this._getOrReturnCtx(input);
7860
+ addIssueToContext(ctx, {
7861
+ code: ZodIssueCode.invalid_type,
7862
+ expected: ZodParsedType.bigint,
7863
+ received: ctx.parsedType
7864
+ });
7865
+ return INVALID;
7866
+ }
7867
+ gte(value, message) {
7868
+ return this.setLimit("min", value, true, errorUtil.toString(message));
7869
+ }
7870
+ gt(value, message) {
7871
+ return this.setLimit("min", value, false, errorUtil.toString(message));
7872
+ }
7873
+ lte(value, message) {
7874
+ return this.setLimit("max", value, true, errorUtil.toString(message));
7875
+ }
7876
+ lt(value, message) {
7877
+ return this.setLimit("max", value, false, errorUtil.toString(message));
7878
+ }
7879
+ setLimit(kind, value, inclusive, message) {
7880
+ return new _ZodBigInt({
7881
+ ...this._def,
7882
+ checks: [
7883
+ ...this._def.checks,
7884
+ {
7885
+ kind,
7886
+ value,
7887
+ inclusive,
7888
+ message: errorUtil.toString(message)
7889
+ }
7890
+ ]
7891
+ });
7892
+ }
7893
+ _addCheck(check) {
7894
+ return new _ZodBigInt({
7895
+ ...this._def,
7896
+ checks: [...this._def.checks, check]
7897
+ });
7898
+ }
7899
+ positive(message) {
7900
+ return this._addCheck({
7901
+ kind: "min",
7902
+ value: BigInt(0),
7903
+ inclusive: false,
7904
+ message: errorUtil.toString(message)
7905
+ });
7906
+ }
7907
+ negative(message) {
7908
+ return this._addCheck({
7909
+ kind: "max",
7910
+ value: BigInt(0),
7911
+ inclusive: false,
7912
+ message: errorUtil.toString(message)
7913
+ });
7914
+ }
7915
+ nonpositive(message) {
7916
+ return this._addCheck({
7917
+ kind: "max",
7918
+ value: BigInt(0),
7919
+ inclusive: true,
7920
+ message: errorUtil.toString(message)
7921
+ });
7922
+ }
7923
+ nonnegative(message) {
7924
+ return this._addCheck({
7925
+ kind: "min",
7926
+ value: BigInt(0),
7927
+ inclusive: true,
7928
+ message: errorUtil.toString(message)
7929
+ });
7930
+ }
7931
+ multipleOf(value, message) {
7932
+ return this._addCheck({
7933
+ kind: "multipleOf",
7934
+ value,
7935
+ message: errorUtil.toString(message)
7936
+ });
7937
+ }
7938
+ get minValue() {
7939
+ let min = null;
7940
+ for (const ch of this._def.checks) {
7941
+ if (ch.kind === "min") {
7942
+ if (min === null || ch.value > min)
7943
+ min = ch.value;
7944
+ }
7945
+ }
7946
+ return min;
7947
+ }
7948
+ get maxValue() {
7949
+ let max = null;
7950
+ for (const ch of this._def.checks) {
7951
+ if (ch.kind === "max") {
7952
+ if (max === null || ch.value < max)
7953
+ max = ch.value;
7954
+ }
7955
+ }
7956
+ return max;
7957
+ }
7958
+ };
7959
+ ZodBigInt.create = (params) => {
7960
+ return new ZodBigInt({
7961
+ checks: [],
7962
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
7963
+ coerce: params?.coerce ?? false,
7964
+ ...processCreateParams(params)
7965
+ });
7966
+ };
7967
+ var ZodBoolean = class extends ZodType {
7968
+ static {
7969
+ __name(this, "ZodBoolean");
7970
+ }
7971
+ _parse(input) {
7972
+ if (this._def.coerce) {
7973
+ input.data = Boolean(input.data);
7974
+ }
7975
+ const parsedType = this._getType(input);
7976
+ if (parsedType !== ZodParsedType.boolean) {
7977
+ const ctx = this._getOrReturnCtx(input);
7978
+ addIssueToContext(ctx, {
7979
+ code: ZodIssueCode.invalid_type,
7980
+ expected: ZodParsedType.boolean,
7981
+ received: ctx.parsedType
7982
+ });
7983
+ return INVALID;
7984
+ }
7985
+ return OK(input.data);
7986
+ }
7987
+ };
7988
+ ZodBoolean.create = (params) => {
7989
+ return new ZodBoolean({
7990
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
7991
+ coerce: params?.coerce || false,
7992
+ ...processCreateParams(params)
7993
+ });
7994
+ };
7995
+ var ZodDate = class _ZodDate extends ZodType {
7996
+ static {
7997
+ __name(this, "ZodDate");
7998
+ }
7999
+ _parse(input) {
8000
+ if (this._def.coerce) {
8001
+ input.data = new Date(input.data);
8002
+ }
8003
+ const parsedType = this._getType(input);
8004
+ if (parsedType !== ZodParsedType.date) {
8005
+ const ctx2 = this._getOrReturnCtx(input);
8006
+ addIssueToContext(ctx2, {
8007
+ code: ZodIssueCode.invalid_type,
8008
+ expected: ZodParsedType.date,
8009
+ received: ctx2.parsedType
8010
+ });
8011
+ return INVALID;
8012
+ }
8013
+ if (Number.isNaN(input.data.getTime())) {
8014
+ const ctx2 = this._getOrReturnCtx(input);
8015
+ addIssueToContext(ctx2, {
8016
+ code: ZodIssueCode.invalid_date
8017
+ });
8018
+ return INVALID;
8019
+ }
8020
+ const status = new ParseStatus();
8021
+ let ctx = void 0;
8022
+ for (const check of this._def.checks) {
8023
+ if (check.kind === "min") {
8024
+ if (input.data.getTime() < check.value) {
8025
+ ctx = this._getOrReturnCtx(input, ctx);
8026
+ addIssueToContext(ctx, {
8027
+ code: ZodIssueCode.too_small,
8028
+ message: check.message,
8029
+ inclusive: true,
8030
+ exact: false,
8031
+ minimum: check.value,
8032
+ type: "date"
8033
+ });
8034
+ status.dirty();
8035
+ }
8036
+ } else if (check.kind === "max") {
8037
+ if (input.data.getTime() > check.value) {
8038
+ ctx = this._getOrReturnCtx(input, ctx);
8039
+ addIssueToContext(ctx, {
8040
+ code: ZodIssueCode.too_big,
8041
+ message: check.message,
8042
+ inclusive: true,
8043
+ exact: false,
8044
+ maximum: check.value,
8045
+ type: "date"
8046
+ });
8047
+ status.dirty();
8048
+ }
8049
+ } else {
8050
+ util.assertNever(check);
8051
+ }
8052
+ }
8053
+ return {
8054
+ status: status.value,
8055
+ value: new Date(input.data.getTime())
8056
+ };
8057
+ }
8058
+ _addCheck(check) {
8059
+ return new _ZodDate({
8060
+ ...this._def,
8061
+ checks: [...this._def.checks, check]
8062
+ });
8063
+ }
8064
+ min(minDate, message) {
8065
+ return this._addCheck({
8066
+ kind: "min",
8067
+ value: minDate.getTime(),
8068
+ message: errorUtil.toString(message)
8069
+ });
8070
+ }
8071
+ max(maxDate, message) {
8072
+ return this._addCheck({
8073
+ kind: "max",
8074
+ value: maxDate.getTime(),
8075
+ message: errorUtil.toString(message)
8076
+ });
8077
+ }
8078
+ get minDate() {
8079
+ let min = null;
8080
+ for (const ch of this._def.checks) {
8081
+ if (ch.kind === "min") {
8082
+ if (min === null || ch.value > min)
8083
+ min = ch.value;
8084
+ }
8085
+ }
8086
+ return min != null ? new Date(min) : null;
8087
+ }
8088
+ get maxDate() {
8089
+ let max = null;
8090
+ for (const ch of this._def.checks) {
8091
+ if (ch.kind === "max") {
8092
+ if (max === null || ch.value < max)
8093
+ max = ch.value;
8094
+ }
8095
+ }
8096
+ return max != null ? new Date(max) : null;
8097
+ }
8098
+ };
8099
+ ZodDate.create = (params) => {
8100
+ return new ZodDate({
8101
+ checks: [],
8102
+ coerce: params?.coerce || false,
8103
+ typeName: ZodFirstPartyTypeKind.ZodDate,
8104
+ ...processCreateParams(params)
8105
+ });
8106
+ };
8107
+ var ZodSymbol = class extends ZodType {
8108
+ static {
8109
+ __name(this, "ZodSymbol");
8110
+ }
8111
+ _parse(input) {
8112
+ const parsedType = this._getType(input);
8113
+ if (parsedType !== ZodParsedType.symbol) {
8114
+ const ctx = this._getOrReturnCtx(input);
8115
+ addIssueToContext(ctx, {
8116
+ code: ZodIssueCode.invalid_type,
8117
+ expected: ZodParsedType.symbol,
8118
+ received: ctx.parsedType
8119
+ });
8120
+ return INVALID;
8121
+ }
8122
+ return OK(input.data);
8123
+ }
8124
+ };
8125
+ ZodSymbol.create = (params) => {
8126
+ return new ZodSymbol({
8127
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
8128
+ ...processCreateParams(params)
8129
+ });
8130
+ };
8131
+ var ZodUndefined = class extends ZodType {
8132
+ static {
8133
+ __name(this, "ZodUndefined");
8134
+ }
8135
+ _parse(input) {
8136
+ const parsedType = this._getType(input);
8137
+ if (parsedType !== ZodParsedType.undefined) {
8138
+ const ctx = this._getOrReturnCtx(input);
8139
+ addIssueToContext(ctx, {
8140
+ code: ZodIssueCode.invalid_type,
8141
+ expected: ZodParsedType.undefined,
8142
+ received: ctx.parsedType
8143
+ });
8144
+ return INVALID;
8145
+ }
8146
+ return OK(input.data);
8147
+ }
8148
+ };
8149
+ ZodUndefined.create = (params) => {
8150
+ return new ZodUndefined({
8151
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
8152
+ ...processCreateParams(params)
8153
+ });
8154
+ };
8155
+ var ZodNull = class extends ZodType {
8156
+ static {
8157
+ __name(this, "ZodNull");
8158
+ }
8159
+ _parse(input) {
8160
+ const parsedType = this._getType(input);
8161
+ if (parsedType !== ZodParsedType.null) {
8162
+ const ctx = this._getOrReturnCtx(input);
8163
+ addIssueToContext(ctx, {
8164
+ code: ZodIssueCode.invalid_type,
8165
+ expected: ZodParsedType.null,
8166
+ received: ctx.parsedType
8167
+ });
8168
+ return INVALID;
8169
+ }
8170
+ return OK(input.data);
8171
+ }
8172
+ };
8173
+ ZodNull.create = (params) => {
8174
+ return new ZodNull({
8175
+ typeName: ZodFirstPartyTypeKind.ZodNull,
8176
+ ...processCreateParams(params)
8177
+ });
8178
+ };
8179
+ var ZodAny = class extends ZodType {
8180
+ static {
8181
+ __name(this, "ZodAny");
8182
+ }
8183
+ constructor() {
8184
+ super(...arguments);
8185
+ this._any = true;
8186
+ }
8187
+ _parse(input) {
8188
+ return OK(input.data);
8189
+ }
8190
+ };
8191
+ ZodAny.create = (params) => {
8192
+ return new ZodAny({
8193
+ typeName: ZodFirstPartyTypeKind.ZodAny,
8194
+ ...processCreateParams(params)
8195
+ });
8196
+ };
8197
+ var ZodUnknown = class extends ZodType {
8198
+ static {
8199
+ __name(this, "ZodUnknown");
8200
+ }
8201
+ constructor() {
8202
+ super(...arguments);
8203
+ this._unknown = true;
8204
+ }
8205
+ _parse(input) {
8206
+ return OK(input.data);
8207
+ }
8208
+ };
8209
+ ZodUnknown.create = (params) => {
8210
+ return new ZodUnknown({
8211
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
8212
+ ...processCreateParams(params)
8213
+ });
8214
+ };
8215
+ var ZodNever = class extends ZodType {
8216
+ static {
8217
+ __name(this, "ZodNever");
8218
+ }
8219
+ _parse(input) {
8220
+ const ctx = this._getOrReturnCtx(input);
8221
+ addIssueToContext(ctx, {
8222
+ code: ZodIssueCode.invalid_type,
8223
+ expected: ZodParsedType.never,
8224
+ received: ctx.parsedType
8225
+ });
8226
+ return INVALID;
8227
+ }
8228
+ };
8229
+ ZodNever.create = (params) => {
8230
+ return new ZodNever({
8231
+ typeName: ZodFirstPartyTypeKind.ZodNever,
8232
+ ...processCreateParams(params)
8233
+ });
8234
+ };
8235
+ var ZodVoid = class extends ZodType {
8236
+ static {
8237
+ __name(this, "ZodVoid");
8238
+ }
8239
+ _parse(input) {
8240
+ const parsedType = this._getType(input);
8241
+ if (parsedType !== ZodParsedType.undefined) {
8242
+ const ctx = this._getOrReturnCtx(input);
8243
+ addIssueToContext(ctx, {
8244
+ code: ZodIssueCode.invalid_type,
8245
+ expected: ZodParsedType.void,
8246
+ received: ctx.parsedType
8247
+ });
8248
+ return INVALID;
8249
+ }
8250
+ return OK(input.data);
8251
+ }
8252
+ };
8253
+ ZodVoid.create = (params) => {
8254
+ return new ZodVoid({
8255
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
8256
+ ...processCreateParams(params)
8257
+ });
8258
+ };
8259
+ var ZodArray = class _ZodArray extends ZodType {
8260
+ static {
8261
+ __name(this, "ZodArray");
8262
+ }
8263
+ _parse(input) {
8264
+ const { ctx, status } = this._processInputParams(input);
8265
+ const def = this._def;
8266
+ if (ctx.parsedType !== ZodParsedType.array) {
8267
+ addIssueToContext(ctx, {
8268
+ code: ZodIssueCode.invalid_type,
8269
+ expected: ZodParsedType.array,
8270
+ received: ctx.parsedType
8271
+ });
8272
+ return INVALID;
8273
+ }
8274
+ if (def.exactLength !== null) {
8275
+ const tooBig = ctx.data.length > def.exactLength.value;
8276
+ const tooSmall = ctx.data.length < def.exactLength.value;
8277
+ if (tooBig || tooSmall) {
8278
+ addIssueToContext(ctx, {
8279
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
8280
+ minimum: tooSmall ? def.exactLength.value : void 0,
8281
+ maximum: tooBig ? def.exactLength.value : void 0,
8282
+ type: "array",
8283
+ inclusive: true,
8284
+ exact: true,
8285
+ message: def.exactLength.message
8286
+ });
8287
+ status.dirty();
8288
+ }
8289
+ }
8290
+ if (def.minLength !== null) {
8291
+ if (ctx.data.length < def.minLength.value) {
8292
+ addIssueToContext(ctx, {
8293
+ code: ZodIssueCode.too_small,
8294
+ minimum: def.minLength.value,
8295
+ type: "array",
8296
+ inclusive: true,
8297
+ exact: false,
8298
+ message: def.minLength.message
8299
+ });
8300
+ status.dirty();
8301
+ }
8302
+ }
8303
+ if (def.maxLength !== null) {
8304
+ if (ctx.data.length > def.maxLength.value) {
8305
+ addIssueToContext(ctx, {
8306
+ code: ZodIssueCode.too_big,
8307
+ maximum: def.maxLength.value,
8308
+ type: "array",
8309
+ inclusive: true,
8310
+ exact: false,
8311
+ message: def.maxLength.message
8312
+ });
8313
+ status.dirty();
8314
+ }
8315
+ }
8316
+ if (ctx.common.async) {
8317
+ return Promise.all([...ctx.data].map((item, i) => {
8318
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
8319
+ })).then((result2) => {
8320
+ return ParseStatus.mergeArray(status, result2);
8321
+ });
8322
+ }
8323
+ const result = [...ctx.data].map((item, i) => {
8324
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
8325
+ });
8326
+ return ParseStatus.mergeArray(status, result);
8327
+ }
8328
+ get element() {
8329
+ return this._def.type;
8330
+ }
8331
+ min(minLength, message) {
8332
+ return new _ZodArray({
8333
+ ...this._def,
8334
+ minLength: { value: minLength, message: errorUtil.toString(message) }
8335
+ });
8336
+ }
8337
+ max(maxLength, message) {
8338
+ return new _ZodArray({
8339
+ ...this._def,
8340
+ maxLength: { value: maxLength, message: errorUtil.toString(message) }
8341
+ });
8342
+ }
8343
+ length(len, message) {
8344
+ return new _ZodArray({
8345
+ ...this._def,
8346
+ exactLength: { value: len, message: errorUtil.toString(message) }
8347
+ });
8348
+ }
8349
+ nonempty(message) {
8350
+ return this.min(1, message);
8351
+ }
8352
+ };
8353
+ ZodArray.create = (schema, params) => {
8354
+ return new ZodArray({
8355
+ type: schema,
8356
+ minLength: null,
8357
+ maxLength: null,
8358
+ exactLength: null,
8359
+ typeName: ZodFirstPartyTypeKind.ZodArray,
8360
+ ...processCreateParams(params)
8361
+ });
8362
+ };
8363
+ function deepPartialify(schema) {
8364
+ if (schema instanceof ZodObject) {
8365
+ const newShape = {};
8366
+ for (const key in schema.shape) {
8367
+ const fieldSchema = schema.shape[key];
8368
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
8369
+ }
8370
+ return new ZodObject({
8371
+ ...schema._def,
8372
+ shape: /* @__PURE__ */ __name(() => newShape, "shape")
8373
+ });
8374
+ } else if (schema instanceof ZodArray) {
8375
+ return new ZodArray({
8376
+ ...schema._def,
8377
+ type: deepPartialify(schema.element)
8378
+ });
8379
+ } else if (schema instanceof ZodOptional) {
8380
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
8381
+ } else if (schema instanceof ZodNullable) {
8382
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
8383
+ } else if (schema instanceof ZodTuple) {
8384
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
8385
+ } else {
8386
+ return schema;
8387
+ }
8388
+ }
8389
+ __name(deepPartialify, "deepPartialify");
8390
+ var ZodObject = class _ZodObject extends ZodType {
8391
+ static {
8392
+ __name(this, "ZodObject");
8393
+ }
8394
+ constructor() {
8395
+ super(...arguments);
8396
+ this._cached = null;
8397
+ this.nonstrict = this.passthrough;
8398
+ this.augment = this.extend;
8399
+ }
8400
+ _getCached() {
8401
+ if (this._cached !== null)
8402
+ return this._cached;
8403
+ const shape = this._def.shape();
8404
+ const keys = util.objectKeys(shape);
8405
+ this._cached = { shape, keys };
8406
+ return this._cached;
8407
+ }
8408
+ _parse(input) {
8409
+ const parsedType = this._getType(input);
8410
+ if (parsedType !== ZodParsedType.object) {
8411
+ const ctx2 = this._getOrReturnCtx(input);
8412
+ addIssueToContext(ctx2, {
8413
+ code: ZodIssueCode.invalid_type,
8414
+ expected: ZodParsedType.object,
8415
+ received: ctx2.parsedType
8416
+ });
8417
+ return INVALID;
8418
+ }
8419
+ const { status, ctx } = this._processInputParams(input);
8420
+ const { shape, keys: shapeKeys } = this._getCached();
8421
+ const extraKeys = [];
8422
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
8423
+ for (const key in ctx.data) {
8424
+ if (!shapeKeys.includes(key)) {
8425
+ extraKeys.push(key);
8426
+ }
8427
+ }
8428
+ }
8429
+ const pairs = [];
8430
+ for (const key of shapeKeys) {
8431
+ const keyValidator = shape[key];
8432
+ const value = ctx.data[key];
8433
+ pairs.push({
8434
+ key: { status: "valid", value: key },
8435
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
8436
+ alwaysSet: key in ctx.data
8437
+ });
8438
+ }
8439
+ if (this._def.catchall instanceof ZodNever) {
8440
+ const unknownKeys = this._def.unknownKeys;
8441
+ if (unknownKeys === "passthrough") {
8442
+ for (const key of extraKeys) {
8443
+ pairs.push({
8444
+ key: { status: "valid", value: key },
8445
+ value: { status: "valid", value: ctx.data[key] }
8446
+ });
8447
+ }
8448
+ } else if (unknownKeys === "strict") {
8449
+ if (extraKeys.length > 0) {
8450
+ addIssueToContext(ctx, {
8451
+ code: ZodIssueCode.unrecognized_keys,
8452
+ keys: extraKeys
8453
+ });
8454
+ status.dirty();
8455
+ }
8456
+ } else if (unknownKeys === "strip") {
8457
+ } else {
8458
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
8459
+ }
8460
+ } else {
8461
+ const catchall = this._def.catchall;
8462
+ for (const key of extraKeys) {
8463
+ const value = ctx.data[key];
8464
+ pairs.push({
8465
+ key: { status: "valid", value: key },
8466
+ value: catchall._parse(
8467
+ new ParseInputLazyPath(ctx, value, ctx.path, key)
8468
+ //, ctx.child(key), value, getParsedType(value)
8469
+ ),
8470
+ alwaysSet: key in ctx.data
8471
+ });
8472
+ }
8473
+ }
8474
+ if (ctx.common.async) {
8475
+ return Promise.resolve().then(async () => {
8476
+ const syncPairs = [];
8477
+ for (const pair of pairs) {
8478
+ const key = await pair.key;
8479
+ const value = await pair.value;
8480
+ syncPairs.push({
8481
+ key,
8482
+ value,
8483
+ alwaysSet: pair.alwaysSet
8484
+ });
8485
+ }
8486
+ return syncPairs;
8487
+ }).then((syncPairs) => {
8488
+ return ParseStatus.mergeObjectSync(status, syncPairs);
8489
+ });
8490
+ } else {
8491
+ return ParseStatus.mergeObjectSync(status, pairs);
8492
+ }
8493
+ }
8494
+ get shape() {
8495
+ return this._def.shape();
8496
+ }
8497
+ strict(message) {
8498
+ errorUtil.errToObj;
8499
+ return new _ZodObject({
8500
+ ...this._def,
8501
+ unknownKeys: "strict",
8502
+ ...message !== void 0 ? {
8503
+ errorMap: /* @__PURE__ */ __name((issue, ctx) => {
8504
+ const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
8505
+ if (issue.code === "unrecognized_keys")
8506
+ return {
8507
+ message: errorUtil.errToObj(message).message ?? defaultError
8508
+ };
8509
+ return {
8510
+ message: defaultError
8511
+ };
8512
+ }, "errorMap")
8513
+ } : {}
8514
+ });
8515
+ }
8516
+ strip() {
8517
+ return new _ZodObject({
8518
+ ...this._def,
8519
+ unknownKeys: "strip"
8520
+ });
8521
+ }
8522
+ passthrough() {
8523
+ return new _ZodObject({
8524
+ ...this._def,
8525
+ unknownKeys: "passthrough"
8526
+ });
8527
+ }
8528
+ // const AugmentFactory =
8529
+ // <Def extends ZodObjectDef>(def: Def) =>
8530
+ // <Augmentation extends ZodRawShape>(
8531
+ // augmentation: Augmentation
8532
+ // ): ZodObject<
8533
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
8534
+ // Def["unknownKeys"],
8535
+ // Def["catchall"]
8536
+ // > => {
8537
+ // return new ZodObject({
8538
+ // ...def,
8539
+ // shape: () => ({
8540
+ // ...def.shape(),
8541
+ // ...augmentation,
8542
+ // }),
8543
+ // }) as any;
8544
+ // };
8545
+ extend(augmentation) {
8546
+ return new _ZodObject({
8547
+ ...this._def,
8548
+ shape: /* @__PURE__ */ __name(() => ({
8549
+ ...this._def.shape(),
8550
+ ...augmentation
8551
+ }), "shape")
8552
+ });
8553
+ }
8554
+ /**
8555
+ * Prior to zod@1.0.12 there was a bug in the
8556
+ * inferred type of merged objects. Please
8557
+ * upgrade if you are experiencing issues.
8558
+ */
8559
+ merge(merging) {
8560
+ const merged = new _ZodObject({
8561
+ unknownKeys: merging._def.unknownKeys,
8562
+ catchall: merging._def.catchall,
8563
+ shape: /* @__PURE__ */ __name(() => ({
8564
+ ...this._def.shape(),
8565
+ ...merging._def.shape()
8566
+ }), "shape"),
8567
+ typeName: ZodFirstPartyTypeKind.ZodObject
8568
+ });
8569
+ return merged;
8570
+ }
8571
+ // merge<
8572
+ // Incoming extends AnyZodObject,
8573
+ // Augmentation extends Incoming["shape"],
8574
+ // NewOutput extends {
8575
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
8576
+ // ? Augmentation[k]["_output"]
8577
+ // : k extends keyof Output
8578
+ // ? Output[k]
8579
+ // : never;
8580
+ // },
8581
+ // NewInput extends {
8582
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
8583
+ // ? Augmentation[k]["_input"]
8584
+ // : k extends keyof Input
8585
+ // ? Input[k]
8586
+ // : never;
8587
+ // }
8588
+ // >(
8589
+ // merging: Incoming
8590
+ // ): ZodObject<
8591
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
8592
+ // Incoming["_def"]["unknownKeys"],
8593
+ // Incoming["_def"]["catchall"],
8594
+ // NewOutput,
8595
+ // NewInput
8596
+ // > {
8597
+ // const merged: any = new ZodObject({
8598
+ // unknownKeys: merging._def.unknownKeys,
8599
+ // catchall: merging._def.catchall,
8600
+ // shape: () =>
8601
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
8602
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
8603
+ // }) as any;
8604
+ // return merged;
8605
+ // }
8606
+ setKey(key, schema) {
8607
+ return this.augment({ [key]: schema });
8608
+ }
8609
+ // merge<Incoming extends AnyZodObject>(
8610
+ // merging: Incoming
8611
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
8612
+ // ZodObject<
8613
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
8614
+ // Incoming["_def"]["unknownKeys"],
8615
+ // Incoming["_def"]["catchall"]
8616
+ // > {
8617
+ // // const mergedShape = objectUtil.mergeShapes(
8618
+ // // this._def.shape(),
8619
+ // // merging._def.shape()
8620
+ // // );
8621
+ // const merged: any = new ZodObject({
8622
+ // unknownKeys: merging._def.unknownKeys,
8623
+ // catchall: merging._def.catchall,
8624
+ // shape: () =>
8625
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
8626
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
8627
+ // }) as any;
8628
+ // return merged;
8629
+ // }
8630
+ catchall(index) {
8631
+ return new _ZodObject({
8632
+ ...this._def,
8633
+ catchall: index
8634
+ });
8635
+ }
8636
+ pick(mask) {
8637
+ const shape = {};
8638
+ for (const key of util.objectKeys(mask)) {
8639
+ if (mask[key] && this.shape[key]) {
8640
+ shape[key] = this.shape[key];
8641
+ }
8642
+ }
8643
+ return new _ZodObject({
8644
+ ...this._def,
8645
+ shape: /* @__PURE__ */ __name(() => shape, "shape")
8646
+ });
8647
+ }
8648
+ omit(mask) {
8649
+ const shape = {};
8650
+ for (const key of util.objectKeys(this.shape)) {
8651
+ if (!mask[key]) {
8652
+ shape[key] = this.shape[key];
8653
+ }
8654
+ }
8655
+ return new _ZodObject({
8656
+ ...this._def,
8657
+ shape: /* @__PURE__ */ __name(() => shape, "shape")
8658
+ });
8659
+ }
8660
+ /**
8661
+ * @deprecated
8662
+ */
8663
+ deepPartial() {
8664
+ return deepPartialify(this);
8665
+ }
8666
+ partial(mask) {
8667
+ const newShape = {};
8668
+ for (const key of util.objectKeys(this.shape)) {
8669
+ const fieldSchema = this.shape[key];
8670
+ if (mask && !mask[key]) {
8671
+ newShape[key] = fieldSchema;
8672
+ } else {
8673
+ newShape[key] = fieldSchema.optional();
8674
+ }
8675
+ }
8676
+ return new _ZodObject({
8677
+ ...this._def,
8678
+ shape: /* @__PURE__ */ __name(() => newShape, "shape")
8679
+ });
8680
+ }
8681
+ required(mask) {
8682
+ const newShape = {};
8683
+ for (const key of util.objectKeys(this.shape)) {
8684
+ if (mask && !mask[key]) {
8685
+ newShape[key] = this.shape[key];
8686
+ } else {
8687
+ const fieldSchema = this.shape[key];
8688
+ let newField = fieldSchema;
8689
+ while (newField instanceof ZodOptional) {
8690
+ newField = newField._def.innerType;
8691
+ }
8692
+ newShape[key] = newField;
8693
+ }
8694
+ }
8695
+ return new _ZodObject({
8696
+ ...this._def,
8697
+ shape: /* @__PURE__ */ __name(() => newShape, "shape")
8698
+ });
8699
+ }
8700
+ keyof() {
8701
+ return createZodEnum(util.objectKeys(this.shape));
8702
+ }
8703
+ };
8704
+ ZodObject.create = (shape, params) => {
8705
+ return new ZodObject({
8706
+ shape: /* @__PURE__ */ __name(() => shape, "shape"),
8707
+ unknownKeys: "strip",
8708
+ catchall: ZodNever.create(),
8709
+ typeName: ZodFirstPartyTypeKind.ZodObject,
8710
+ ...processCreateParams(params)
8711
+ });
8712
+ };
8713
+ ZodObject.strictCreate = (shape, params) => {
8714
+ return new ZodObject({
8715
+ shape: /* @__PURE__ */ __name(() => shape, "shape"),
8716
+ unknownKeys: "strict",
8717
+ catchall: ZodNever.create(),
8718
+ typeName: ZodFirstPartyTypeKind.ZodObject,
8719
+ ...processCreateParams(params)
8720
+ });
8721
+ };
8722
+ ZodObject.lazycreate = (shape, params) => {
8723
+ return new ZodObject({
8724
+ shape,
8725
+ unknownKeys: "strip",
8726
+ catchall: ZodNever.create(),
8727
+ typeName: ZodFirstPartyTypeKind.ZodObject,
8728
+ ...processCreateParams(params)
8729
+ });
8730
+ };
8731
+ var ZodUnion = class extends ZodType {
8732
+ static {
8733
+ __name(this, "ZodUnion");
8734
+ }
8735
+ _parse(input) {
8736
+ const { ctx } = this._processInputParams(input);
8737
+ const options = this._def.options;
8738
+ function handleResults(results) {
8739
+ for (const result of results) {
8740
+ if (result.result.status === "valid") {
8741
+ return result.result;
8742
+ }
8743
+ }
8744
+ for (const result of results) {
8745
+ if (result.result.status === "dirty") {
8746
+ ctx.common.issues.push(...result.ctx.common.issues);
8747
+ return result.result;
8748
+ }
8749
+ }
8750
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
8751
+ addIssueToContext(ctx, {
8752
+ code: ZodIssueCode.invalid_union,
8753
+ unionErrors
8754
+ });
8755
+ return INVALID;
8756
+ }
8757
+ __name(handleResults, "handleResults");
8758
+ if (ctx.common.async) {
8759
+ return Promise.all(options.map(async (option) => {
8760
+ const childCtx = {
8761
+ ...ctx,
8762
+ common: {
8763
+ ...ctx.common,
8764
+ issues: []
8765
+ },
8766
+ parent: null
8767
+ };
8768
+ return {
8769
+ result: await option._parseAsync({
8770
+ data: ctx.data,
8771
+ path: ctx.path,
8772
+ parent: childCtx
8773
+ }),
8774
+ ctx: childCtx
8775
+ };
8776
+ })).then(handleResults);
8777
+ } else {
8778
+ let dirty = void 0;
8779
+ const issues = [];
8780
+ for (const option of options) {
8781
+ const childCtx = {
8782
+ ...ctx,
8783
+ common: {
8784
+ ...ctx.common,
8785
+ issues: []
8786
+ },
8787
+ parent: null
8788
+ };
8789
+ const result = option._parseSync({
8790
+ data: ctx.data,
8791
+ path: ctx.path,
8792
+ parent: childCtx
8793
+ });
8794
+ if (result.status === "valid") {
8795
+ return result;
8796
+ } else if (result.status === "dirty" && !dirty) {
8797
+ dirty = { result, ctx: childCtx };
8798
+ }
8799
+ if (childCtx.common.issues.length) {
8800
+ issues.push(childCtx.common.issues);
8801
+ }
8802
+ }
8803
+ if (dirty) {
8804
+ ctx.common.issues.push(...dirty.ctx.common.issues);
8805
+ return dirty.result;
8806
+ }
8807
+ const unionErrors = issues.map((issues2) => new ZodError(issues2));
8808
+ addIssueToContext(ctx, {
8809
+ code: ZodIssueCode.invalid_union,
8810
+ unionErrors
8811
+ });
8812
+ return INVALID;
8813
+ }
8814
+ }
8815
+ get options() {
8816
+ return this._def.options;
8817
+ }
8818
+ };
8819
+ ZodUnion.create = (types, params) => {
8820
+ return new ZodUnion({
8821
+ options: types,
8822
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
8823
+ ...processCreateParams(params)
8824
+ });
8825
+ };
8826
+ var getDiscriminator = /* @__PURE__ */ __name((type) => {
8827
+ if (type instanceof ZodLazy) {
8828
+ return getDiscriminator(type.schema);
8829
+ } else if (type instanceof ZodEffects) {
8830
+ return getDiscriminator(type.innerType());
8831
+ } else if (type instanceof ZodLiteral) {
8832
+ return [type.value];
8833
+ } else if (type instanceof ZodEnum) {
8834
+ return type.options;
8835
+ } else if (type instanceof ZodNativeEnum) {
8836
+ return util.objectValues(type.enum);
8837
+ } else if (type instanceof ZodDefault) {
8838
+ return getDiscriminator(type._def.innerType);
8839
+ } else if (type instanceof ZodUndefined) {
8840
+ return [void 0];
8841
+ } else if (type instanceof ZodNull) {
8842
+ return [null];
8843
+ } else if (type instanceof ZodOptional) {
8844
+ return [void 0, ...getDiscriminator(type.unwrap())];
8845
+ } else if (type instanceof ZodNullable) {
8846
+ return [null, ...getDiscriminator(type.unwrap())];
8847
+ } else if (type instanceof ZodBranded) {
8848
+ return getDiscriminator(type.unwrap());
8849
+ } else if (type instanceof ZodReadonly) {
8850
+ return getDiscriminator(type.unwrap());
8851
+ } else if (type instanceof ZodCatch) {
8852
+ return getDiscriminator(type._def.innerType);
8853
+ } else {
8854
+ return [];
8855
+ }
8856
+ }, "getDiscriminator");
8857
+ var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
8858
+ static {
8859
+ __name(this, "ZodDiscriminatedUnion");
8860
+ }
8861
+ _parse(input) {
8862
+ const { ctx } = this._processInputParams(input);
8863
+ if (ctx.parsedType !== ZodParsedType.object) {
8864
+ addIssueToContext(ctx, {
8865
+ code: ZodIssueCode.invalid_type,
8866
+ expected: ZodParsedType.object,
8867
+ received: ctx.parsedType
8868
+ });
8869
+ return INVALID;
8870
+ }
8871
+ const discriminator = this.discriminator;
8872
+ const discriminatorValue = ctx.data[discriminator];
8873
+ const option = this.optionsMap.get(discriminatorValue);
8874
+ if (!option) {
8875
+ addIssueToContext(ctx, {
8876
+ code: ZodIssueCode.invalid_union_discriminator,
8877
+ options: Array.from(this.optionsMap.keys()),
8878
+ path: [discriminator]
8879
+ });
8880
+ return INVALID;
8881
+ }
8882
+ if (ctx.common.async) {
8883
+ return option._parseAsync({
8884
+ data: ctx.data,
8885
+ path: ctx.path,
8886
+ parent: ctx
8887
+ });
8888
+ } else {
8889
+ return option._parseSync({
8890
+ data: ctx.data,
8891
+ path: ctx.path,
8892
+ parent: ctx
8893
+ });
8894
+ }
8895
+ }
8896
+ get discriminator() {
8897
+ return this._def.discriminator;
8898
+ }
8899
+ get options() {
8900
+ return this._def.options;
8901
+ }
8902
+ get optionsMap() {
8903
+ return this._def.optionsMap;
8904
+ }
8905
+ /**
8906
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
8907
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
8908
+ * have a different value for each object in the union.
8909
+ * @param discriminator the name of the discriminator property
8910
+ * @param types an array of object schemas
8911
+ * @param params
8912
+ */
8913
+ static create(discriminator, options, params) {
8914
+ const optionsMap = /* @__PURE__ */ new Map();
8915
+ for (const type of options) {
8916
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
8917
+ if (!discriminatorValues.length) {
8918
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
8919
+ }
8920
+ for (const value of discriminatorValues) {
8921
+ if (optionsMap.has(value)) {
8922
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
8923
+ }
8924
+ optionsMap.set(value, type);
8925
+ }
8926
+ }
8927
+ return new _ZodDiscriminatedUnion({
8928
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
8929
+ discriminator,
8930
+ options,
8931
+ optionsMap,
8932
+ ...processCreateParams(params)
8933
+ });
8934
+ }
8935
+ };
8936
+ function mergeValues(a, b) {
8937
+ const aType = getParsedType(a);
8938
+ const bType = getParsedType(b);
8939
+ if (a === b) {
8940
+ return { valid: true, data: a };
8941
+ } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
8942
+ const bKeys = util.objectKeys(b);
8943
+ const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
8944
+ const newObj = { ...a, ...b };
8945
+ for (const key of sharedKeys) {
8946
+ const sharedValue = mergeValues(a[key], b[key]);
8947
+ if (!sharedValue.valid) {
8948
+ return { valid: false };
8949
+ }
8950
+ newObj[key] = sharedValue.data;
8951
+ }
8952
+ return { valid: true, data: newObj };
8953
+ } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
8954
+ if (a.length !== b.length) {
8955
+ return { valid: false };
8956
+ }
8957
+ const newArray = [];
8958
+ for (let index = 0; index < a.length; index++) {
8959
+ const itemA = a[index];
8960
+ const itemB = b[index];
8961
+ const sharedValue = mergeValues(itemA, itemB);
8962
+ if (!sharedValue.valid) {
8963
+ return { valid: false };
8964
+ }
8965
+ newArray.push(sharedValue.data);
8966
+ }
8967
+ return { valid: true, data: newArray };
8968
+ } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
8969
+ return { valid: true, data: a };
8970
+ } else {
8971
+ return { valid: false };
8972
+ }
8973
+ }
8974
+ __name(mergeValues, "mergeValues");
8975
+ var ZodIntersection = class extends ZodType {
8976
+ static {
8977
+ __name(this, "ZodIntersection");
8978
+ }
8979
+ _parse(input) {
8980
+ const { status, ctx } = this._processInputParams(input);
8981
+ const handleParsed = /* @__PURE__ */ __name((parsedLeft, parsedRight) => {
8982
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
8983
+ return INVALID;
8984
+ }
8985
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
8986
+ if (!merged.valid) {
8987
+ addIssueToContext(ctx, {
8988
+ code: ZodIssueCode.invalid_intersection_types
8989
+ });
8990
+ return INVALID;
8991
+ }
8992
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
8993
+ status.dirty();
8994
+ }
8995
+ return { status: status.value, value: merged.data };
8996
+ }, "handleParsed");
8997
+ if (ctx.common.async) {
8998
+ return Promise.all([
8999
+ this._def.left._parseAsync({
9000
+ data: ctx.data,
9001
+ path: ctx.path,
9002
+ parent: ctx
9003
+ }),
9004
+ this._def.right._parseAsync({
9005
+ data: ctx.data,
9006
+ path: ctx.path,
9007
+ parent: ctx
9008
+ })
9009
+ ]).then(([left, right]) => handleParsed(left, right));
9010
+ } else {
9011
+ return handleParsed(this._def.left._parseSync({
9012
+ data: ctx.data,
9013
+ path: ctx.path,
9014
+ parent: ctx
9015
+ }), this._def.right._parseSync({
9016
+ data: ctx.data,
9017
+ path: ctx.path,
9018
+ parent: ctx
9019
+ }));
9020
+ }
9021
+ }
9022
+ };
9023
+ ZodIntersection.create = (left, right, params) => {
9024
+ return new ZodIntersection({
9025
+ left,
9026
+ right,
9027
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
9028
+ ...processCreateParams(params)
9029
+ });
9030
+ };
9031
+ var ZodTuple = class _ZodTuple extends ZodType {
9032
+ static {
9033
+ __name(this, "ZodTuple");
9034
+ }
9035
+ _parse(input) {
9036
+ const { status, ctx } = this._processInputParams(input);
9037
+ if (ctx.parsedType !== ZodParsedType.array) {
9038
+ addIssueToContext(ctx, {
9039
+ code: ZodIssueCode.invalid_type,
9040
+ expected: ZodParsedType.array,
9041
+ received: ctx.parsedType
9042
+ });
9043
+ return INVALID;
9044
+ }
9045
+ if (ctx.data.length < this._def.items.length) {
9046
+ addIssueToContext(ctx, {
9047
+ code: ZodIssueCode.too_small,
9048
+ minimum: this._def.items.length,
9049
+ inclusive: true,
9050
+ exact: false,
9051
+ type: "array"
9052
+ });
9053
+ return INVALID;
9054
+ }
9055
+ const rest = this._def.rest;
9056
+ if (!rest && ctx.data.length > this._def.items.length) {
9057
+ addIssueToContext(ctx, {
9058
+ code: ZodIssueCode.too_big,
9059
+ maximum: this._def.items.length,
9060
+ inclusive: true,
9061
+ exact: false,
9062
+ type: "array"
9063
+ });
9064
+ status.dirty();
9065
+ }
9066
+ const items = [...ctx.data].map((item, itemIndex) => {
9067
+ const schema = this._def.items[itemIndex] || this._def.rest;
9068
+ if (!schema)
9069
+ return null;
9070
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
9071
+ }).filter((x) => !!x);
9072
+ if (ctx.common.async) {
9073
+ return Promise.all(items).then((results) => {
9074
+ return ParseStatus.mergeArray(status, results);
9075
+ });
9076
+ } else {
9077
+ return ParseStatus.mergeArray(status, items);
9078
+ }
9079
+ }
9080
+ get items() {
9081
+ return this._def.items;
9082
+ }
9083
+ rest(rest) {
9084
+ return new _ZodTuple({
9085
+ ...this._def,
9086
+ rest
9087
+ });
9088
+ }
9089
+ };
9090
+ ZodTuple.create = (schemas, params) => {
9091
+ if (!Array.isArray(schemas)) {
9092
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
9093
+ }
9094
+ return new ZodTuple({
9095
+ items: schemas,
9096
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
9097
+ rest: null,
9098
+ ...processCreateParams(params)
9099
+ });
9100
+ };
9101
+ var ZodRecord = class _ZodRecord extends ZodType {
9102
+ static {
9103
+ __name(this, "ZodRecord");
9104
+ }
9105
+ get keySchema() {
9106
+ return this._def.keyType;
9107
+ }
9108
+ get valueSchema() {
9109
+ return this._def.valueType;
9110
+ }
9111
+ _parse(input) {
9112
+ const { status, ctx } = this._processInputParams(input);
9113
+ if (ctx.parsedType !== ZodParsedType.object) {
9114
+ addIssueToContext(ctx, {
9115
+ code: ZodIssueCode.invalid_type,
9116
+ expected: ZodParsedType.object,
9117
+ received: ctx.parsedType
9118
+ });
9119
+ return INVALID;
9120
+ }
9121
+ const pairs = [];
9122
+ const keyType = this._def.keyType;
9123
+ const valueType = this._def.valueType;
9124
+ for (const key in ctx.data) {
9125
+ pairs.push({
9126
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
9127
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
9128
+ alwaysSet: key in ctx.data
9129
+ });
9130
+ }
9131
+ if (ctx.common.async) {
9132
+ return ParseStatus.mergeObjectAsync(status, pairs);
9133
+ } else {
9134
+ return ParseStatus.mergeObjectSync(status, pairs);
9135
+ }
9136
+ }
9137
+ get element() {
9138
+ return this._def.valueType;
9139
+ }
9140
+ static create(first, second, third) {
9141
+ if (second instanceof ZodType) {
9142
+ return new _ZodRecord({
9143
+ keyType: first,
9144
+ valueType: second,
9145
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
9146
+ ...processCreateParams(third)
9147
+ });
9148
+ }
9149
+ return new _ZodRecord({
9150
+ keyType: ZodString.create(),
9151
+ valueType: first,
9152
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
9153
+ ...processCreateParams(second)
9154
+ });
9155
+ }
9156
+ };
9157
+ var ZodMap = class extends ZodType {
9158
+ static {
9159
+ __name(this, "ZodMap");
9160
+ }
9161
+ get keySchema() {
9162
+ return this._def.keyType;
9163
+ }
9164
+ get valueSchema() {
9165
+ return this._def.valueType;
9166
+ }
9167
+ _parse(input) {
9168
+ const { status, ctx } = this._processInputParams(input);
9169
+ if (ctx.parsedType !== ZodParsedType.map) {
9170
+ addIssueToContext(ctx, {
9171
+ code: ZodIssueCode.invalid_type,
9172
+ expected: ZodParsedType.map,
9173
+ received: ctx.parsedType
9174
+ });
9175
+ return INVALID;
9176
+ }
9177
+ const keyType = this._def.keyType;
9178
+ const valueType = this._def.valueType;
9179
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
9180
+ return {
9181
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
9182
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
9183
+ };
9184
+ });
9185
+ if (ctx.common.async) {
9186
+ const finalMap = /* @__PURE__ */ new Map();
9187
+ return Promise.resolve().then(async () => {
9188
+ for (const pair of pairs) {
9189
+ const key = await pair.key;
9190
+ const value = await pair.value;
9191
+ if (key.status === "aborted" || value.status === "aborted") {
9192
+ return INVALID;
9193
+ }
9194
+ if (key.status === "dirty" || value.status === "dirty") {
9195
+ status.dirty();
9196
+ }
9197
+ finalMap.set(key.value, value.value);
9198
+ }
9199
+ return { status: status.value, value: finalMap };
9200
+ });
9201
+ } else {
9202
+ const finalMap = /* @__PURE__ */ new Map();
9203
+ for (const pair of pairs) {
9204
+ const key = pair.key;
9205
+ const value = pair.value;
9206
+ if (key.status === "aborted" || value.status === "aborted") {
9207
+ return INVALID;
9208
+ }
9209
+ if (key.status === "dirty" || value.status === "dirty") {
9210
+ status.dirty();
9211
+ }
9212
+ finalMap.set(key.value, value.value);
9213
+ }
9214
+ return { status: status.value, value: finalMap };
9215
+ }
9216
+ }
9217
+ };
9218
+ ZodMap.create = (keyType, valueType, params) => {
9219
+ return new ZodMap({
9220
+ valueType,
9221
+ keyType,
9222
+ typeName: ZodFirstPartyTypeKind.ZodMap,
9223
+ ...processCreateParams(params)
9224
+ });
9225
+ };
9226
+ var ZodSet = class _ZodSet extends ZodType {
9227
+ static {
9228
+ __name(this, "ZodSet");
9229
+ }
9230
+ _parse(input) {
9231
+ const { status, ctx } = this._processInputParams(input);
9232
+ if (ctx.parsedType !== ZodParsedType.set) {
9233
+ addIssueToContext(ctx, {
9234
+ code: ZodIssueCode.invalid_type,
9235
+ expected: ZodParsedType.set,
9236
+ received: ctx.parsedType
9237
+ });
9238
+ return INVALID;
9239
+ }
9240
+ const def = this._def;
9241
+ if (def.minSize !== null) {
9242
+ if (ctx.data.size < def.minSize.value) {
9243
+ addIssueToContext(ctx, {
9244
+ code: ZodIssueCode.too_small,
9245
+ minimum: def.minSize.value,
9246
+ type: "set",
9247
+ inclusive: true,
9248
+ exact: false,
9249
+ message: def.minSize.message
9250
+ });
9251
+ status.dirty();
9252
+ }
9253
+ }
9254
+ if (def.maxSize !== null) {
9255
+ if (ctx.data.size > def.maxSize.value) {
9256
+ addIssueToContext(ctx, {
9257
+ code: ZodIssueCode.too_big,
9258
+ maximum: def.maxSize.value,
9259
+ type: "set",
9260
+ inclusive: true,
9261
+ exact: false,
9262
+ message: def.maxSize.message
9263
+ });
9264
+ status.dirty();
9265
+ }
9266
+ }
9267
+ const valueType = this._def.valueType;
9268
+ function finalizeSet(elements2) {
9269
+ const parsedSet = /* @__PURE__ */ new Set();
9270
+ for (const element of elements2) {
9271
+ if (element.status === "aborted")
9272
+ return INVALID;
9273
+ if (element.status === "dirty")
9274
+ status.dirty();
9275
+ parsedSet.add(element.value);
9276
+ }
9277
+ return { status: status.value, value: parsedSet };
9278
+ }
9279
+ __name(finalizeSet, "finalizeSet");
9280
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
9281
+ if (ctx.common.async) {
9282
+ return Promise.all(elements).then((elements2) => finalizeSet(elements2));
9283
+ } else {
9284
+ return finalizeSet(elements);
9285
+ }
9286
+ }
9287
+ min(minSize, message) {
9288
+ return new _ZodSet({
9289
+ ...this._def,
9290
+ minSize: { value: minSize, message: errorUtil.toString(message) }
9291
+ });
9292
+ }
9293
+ max(maxSize, message) {
9294
+ return new _ZodSet({
9295
+ ...this._def,
9296
+ maxSize: { value: maxSize, message: errorUtil.toString(message) }
9297
+ });
9298
+ }
9299
+ size(size, message) {
9300
+ return this.min(size, message).max(size, message);
9301
+ }
9302
+ nonempty(message) {
9303
+ return this.min(1, message);
9304
+ }
9305
+ };
9306
+ ZodSet.create = (valueType, params) => {
9307
+ return new ZodSet({
9308
+ valueType,
9309
+ minSize: null,
9310
+ maxSize: null,
9311
+ typeName: ZodFirstPartyTypeKind.ZodSet,
9312
+ ...processCreateParams(params)
9313
+ });
9314
+ };
9315
+ var ZodFunction = class _ZodFunction extends ZodType {
9316
+ static {
9317
+ __name(this, "ZodFunction");
9318
+ }
9319
+ constructor() {
9320
+ super(...arguments);
9321
+ this.validate = this.implement;
9322
+ }
9323
+ _parse(input) {
9324
+ const { ctx } = this._processInputParams(input);
9325
+ if (ctx.parsedType !== ZodParsedType.function) {
9326
+ addIssueToContext(ctx, {
9327
+ code: ZodIssueCode.invalid_type,
9328
+ expected: ZodParsedType.function,
9329
+ received: ctx.parsedType
9330
+ });
9331
+ return INVALID;
9332
+ }
9333
+ function makeArgsIssue(args, error) {
9334
+ return makeIssue({
9335
+ data: args,
9336
+ path: ctx.path,
9337
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
9338
+ issueData: {
9339
+ code: ZodIssueCode.invalid_arguments,
9340
+ argumentsError: error
9341
+ }
9342
+ });
9343
+ }
9344
+ __name(makeArgsIssue, "makeArgsIssue");
9345
+ function makeReturnsIssue(returns, error) {
9346
+ return makeIssue({
9347
+ data: returns,
9348
+ path: ctx.path,
9349
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
9350
+ issueData: {
9351
+ code: ZodIssueCode.invalid_return_type,
9352
+ returnTypeError: error
9353
+ }
9354
+ });
9355
+ }
9356
+ __name(makeReturnsIssue, "makeReturnsIssue");
9357
+ const params = { errorMap: ctx.common.contextualErrorMap };
9358
+ const fn = ctx.data;
9359
+ if (this._def.returns instanceof ZodPromise) {
9360
+ const me = this;
9361
+ return OK(async function(...args) {
9362
+ const error = new ZodError([]);
9363
+ const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
9364
+ error.addIssue(makeArgsIssue(args, e));
9365
+ throw error;
9366
+ });
9367
+ const result = await Reflect.apply(fn, this, parsedArgs);
9368
+ const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
9369
+ error.addIssue(makeReturnsIssue(result, e));
9370
+ throw error;
9371
+ });
9372
+ return parsedReturns;
9373
+ });
9374
+ } else {
9375
+ const me = this;
9376
+ return OK(function(...args) {
9377
+ const parsedArgs = me._def.args.safeParse(args, params);
9378
+ if (!parsedArgs.success) {
9379
+ throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
9380
+ }
9381
+ const result = Reflect.apply(fn, this, parsedArgs.data);
9382
+ const parsedReturns = me._def.returns.safeParse(result, params);
9383
+ if (!parsedReturns.success) {
9384
+ throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
9385
+ }
9386
+ return parsedReturns.data;
9387
+ });
9388
+ }
9389
+ }
9390
+ parameters() {
9391
+ return this._def.args;
9392
+ }
9393
+ returnType() {
9394
+ return this._def.returns;
9395
+ }
9396
+ args(...items) {
9397
+ return new _ZodFunction({
9398
+ ...this._def,
9399
+ args: ZodTuple.create(items).rest(ZodUnknown.create())
9400
+ });
9401
+ }
9402
+ returns(returnType) {
9403
+ return new _ZodFunction({
9404
+ ...this._def,
9405
+ returns: returnType
9406
+ });
9407
+ }
9408
+ implement(func) {
9409
+ const validatedFunc = this.parse(func);
9410
+ return validatedFunc;
9411
+ }
9412
+ strictImplement(func) {
9413
+ const validatedFunc = this.parse(func);
9414
+ return validatedFunc;
9415
+ }
9416
+ static create(args, returns, params) {
9417
+ return new _ZodFunction({
9418
+ args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
9419
+ returns: returns || ZodUnknown.create(),
9420
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
9421
+ ...processCreateParams(params)
9422
+ });
9423
+ }
9424
+ };
9425
+ var ZodLazy = class extends ZodType {
9426
+ static {
9427
+ __name(this, "ZodLazy");
9428
+ }
9429
+ get schema() {
9430
+ return this._def.getter();
9431
+ }
9432
+ _parse(input) {
9433
+ const { ctx } = this._processInputParams(input);
9434
+ const lazySchema = this._def.getter();
9435
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
9436
+ }
9437
+ };
9438
+ ZodLazy.create = (getter, params) => {
9439
+ return new ZodLazy({
9440
+ getter,
9441
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
9442
+ ...processCreateParams(params)
9443
+ });
9444
+ };
9445
+ var ZodLiteral = class extends ZodType {
9446
+ static {
9447
+ __name(this, "ZodLiteral");
9448
+ }
9449
+ _parse(input) {
9450
+ if (input.data !== this._def.value) {
9451
+ const ctx = this._getOrReturnCtx(input);
9452
+ addIssueToContext(ctx, {
9453
+ received: ctx.data,
9454
+ code: ZodIssueCode.invalid_literal,
9455
+ expected: this._def.value
9456
+ });
9457
+ return INVALID;
9458
+ }
9459
+ return { status: "valid", value: input.data };
9460
+ }
9461
+ get value() {
9462
+ return this._def.value;
9463
+ }
9464
+ };
9465
+ ZodLiteral.create = (value, params) => {
9466
+ return new ZodLiteral({
9467
+ value,
9468
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
9469
+ ...processCreateParams(params)
9470
+ });
9471
+ };
9472
+ function createZodEnum(values, params) {
9473
+ return new ZodEnum({
9474
+ values,
9475
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
9476
+ ...processCreateParams(params)
9477
+ });
9478
+ }
9479
+ __name(createZodEnum, "createZodEnum");
9480
+ var ZodEnum = class _ZodEnum extends ZodType {
9481
+ static {
9482
+ __name(this, "ZodEnum");
9483
+ }
9484
+ _parse(input) {
9485
+ if (typeof input.data !== "string") {
9486
+ const ctx = this._getOrReturnCtx(input);
9487
+ const expectedValues = this._def.values;
9488
+ addIssueToContext(ctx, {
9489
+ expected: util.joinValues(expectedValues),
9490
+ received: ctx.parsedType,
9491
+ code: ZodIssueCode.invalid_type
9492
+ });
9493
+ return INVALID;
9494
+ }
9495
+ if (!this._cache) {
9496
+ this._cache = new Set(this._def.values);
9497
+ }
9498
+ if (!this._cache.has(input.data)) {
9499
+ const ctx = this._getOrReturnCtx(input);
9500
+ const expectedValues = this._def.values;
9501
+ addIssueToContext(ctx, {
9502
+ received: ctx.data,
9503
+ code: ZodIssueCode.invalid_enum_value,
9504
+ options: expectedValues
9505
+ });
9506
+ return INVALID;
9507
+ }
9508
+ return OK(input.data);
9509
+ }
9510
+ get options() {
9511
+ return this._def.values;
9512
+ }
9513
+ get enum() {
9514
+ const enumValues = {};
9515
+ for (const val of this._def.values) {
9516
+ enumValues[val] = val;
9517
+ }
9518
+ return enumValues;
9519
+ }
9520
+ get Values() {
9521
+ const enumValues = {};
9522
+ for (const val of this._def.values) {
9523
+ enumValues[val] = val;
9524
+ }
9525
+ return enumValues;
9526
+ }
9527
+ get Enum() {
9528
+ const enumValues = {};
9529
+ for (const val of this._def.values) {
9530
+ enumValues[val] = val;
9531
+ }
9532
+ return enumValues;
9533
+ }
9534
+ extract(values, newDef = this._def) {
9535
+ return _ZodEnum.create(values, {
9536
+ ...this._def,
9537
+ ...newDef
9538
+ });
9539
+ }
9540
+ exclude(values, newDef = this._def) {
9541
+ return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
9542
+ ...this._def,
9543
+ ...newDef
9544
+ });
9545
+ }
9546
+ };
9547
+ ZodEnum.create = createZodEnum;
9548
+ var ZodNativeEnum = class extends ZodType {
9549
+ static {
9550
+ __name(this, "ZodNativeEnum");
9551
+ }
9552
+ _parse(input) {
9553
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
9554
+ const ctx = this._getOrReturnCtx(input);
9555
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
9556
+ const expectedValues = util.objectValues(nativeEnumValues);
9557
+ addIssueToContext(ctx, {
9558
+ expected: util.joinValues(expectedValues),
9559
+ received: ctx.parsedType,
9560
+ code: ZodIssueCode.invalid_type
9561
+ });
9562
+ return INVALID;
9563
+ }
9564
+ if (!this._cache) {
9565
+ this._cache = new Set(util.getValidEnumValues(this._def.values));
9566
+ }
9567
+ if (!this._cache.has(input.data)) {
9568
+ const expectedValues = util.objectValues(nativeEnumValues);
9569
+ addIssueToContext(ctx, {
9570
+ received: ctx.data,
9571
+ code: ZodIssueCode.invalid_enum_value,
9572
+ options: expectedValues
9573
+ });
9574
+ return INVALID;
9575
+ }
9576
+ return OK(input.data);
9577
+ }
9578
+ get enum() {
9579
+ return this._def.values;
9580
+ }
9581
+ };
9582
+ ZodNativeEnum.create = (values, params) => {
9583
+ return new ZodNativeEnum({
9584
+ values,
9585
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
9586
+ ...processCreateParams(params)
9587
+ });
9588
+ };
9589
+ var ZodPromise = class extends ZodType {
9590
+ static {
9591
+ __name(this, "ZodPromise");
9592
+ }
9593
+ unwrap() {
9594
+ return this._def.type;
9595
+ }
9596
+ _parse(input) {
9597
+ const { ctx } = this._processInputParams(input);
9598
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
9599
+ addIssueToContext(ctx, {
9600
+ code: ZodIssueCode.invalid_type,
9601
+ expected: ZodParsedType.promise,
9602
+ received: ctx.parsedType
9603
+ });
9604
+ return INVALID;
9605
+ }
9606
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
9607
+ return OK(promisified.then((data) => {
9608
+ return this._def.type.parseAsync(data, {
9609
+ path: ctx.path,
9610
+ errorMap: ctx.common.contextualErrorMap
9611
+ });
9612
+ }));
9613
+ }
9614
+ };
9615
+ ZodPromise.create = (schema, params) => {
9616
+ return new ZodPromise({
9617
+ type: schema,
9618
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
9619
+ ...processCreateParams(params)
9620
+ });
9621
+ };
9622
+ var ZodEffects = class extends ZodType {
9623
+ static {
9624
+ __name(this, "ZodEffects");
9625
+ }
9626
+ innerType() {
9627
+ return this._def.schema;
9628
+ }
9629
+ sourceType() {
9630
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
9631
+ }
9632
+ _parse(input) {
9633
+ const { status, ctx } = this._processInputParams(input);
9634
+ const effect = this._def.effect || null;
9635
+ const checkCtx = {
9636
+ addIssue: /* @__PURE__ */ __name((arg) => {
9637
+ addIssueToContext(ctx, arg);
9638
+ if (arg.fatal) {
9639
+ status.abort();
9640
+ } else {
9641
+ status.dirty();
9642
+ }
9643
+ }, "addIssue"),
9644
+ get path() {
9645
+ return ctx.path;
9646
+ }
9647
+ };
9648
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
9649
+ if (effect.type === "preprocess") {
9650
+ const processed = effect.transform(ctx.data, checkCtx);
9651
+ if (ctx.common.async) {
9652
+ return Promise.resolve(processed).then(async (processed2) => {
9653
+ if (status.value === "aborted")
9654
+ return INVALID;
9655
+ const result = await this._def.schema._parseAsync({
9656
+ data: processed2,
9657
+ path: ctx.path,
9658
+ parent: ctx
9659
+ });
9660
+ if (result.status === "aborted")
9661
+ return INVALID;
9662
+ if (result.status === "dirty")
9663
+ return DIRTY(result.value);
9664
+ if (status.value === "dirty")
9665
+ return DIRTY(result.value);
9666
+ return result;
9667
+ });
9668
+ } else {
9669
+ if (status.value === "aborted")
9670
+ return INVALID;
9671
+ const result = this._def.schema._parseSync({
9672
+ data: processed,
9673
+ path: ctx.path,
9674
+ parent: ctx
9675
+ });
9676
+ if (result.status === "aborted")
9677
+ return INVALID;
9678
+ if (result.status === "dirty")
9679
+ return DIRTY(result.value);
9680
+ if (status.value === "dirty")
9681
+ return DIRTY(result.value);
9682
+ return result;
9683
+ }
9684
+ }
9685
+ if (effect.type === "refinement") {
9686
+ const executeRefinement = /* @__PURE__ */ __name((acc) => {
9687
+ const result = effect.refinement(acc, checkCtx);
9688
+ if (ctx.common.async) {
9689
+ return Promise.resolve(result);
9690
+ }
9691
+ if (result instanceof Promise) {
9692
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
9693
+ }
9694
+ return acc;
9695
+ }, "executeRefinement");
9696
+ if (ctx.common.async === false) {
9697
+ const inner = this._def.schema._parseSync({
9698
+ data: ctx.data,
9699
+ path: ctx.path,
9700
+ parent: ctx
9701
+ });
9702
+ if (inner.status === "aborted")
9703
+ return INVALID;
9704
+ if (inner.status === "dirty")
9705
+ status.dirty();
9706
+ executeRefinement(inner.value);
9707
+ return { status: status.value, value: inner.value };
9708
+ } else {
9709
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
9710
+ if (inner.status === "aborted")
9711
+ return INVALID;
9712
+ if (inner.status === "dirty")
9713
+ status.dirty();
9714
+ return executeRefinement(inner.value).then(() => {
9715
+ return { status: status.value, value: inner.value };
9716
+ });
9717
+ });
9718
+ }
9719
+ }
9720
+ if (effect.type === "transform") {
9721
+ if (ctx.common.async === false) {
9722
+ const base = this._def.schema._parseSync({
9723
+ data: ctx.data,
9724
+ path: ctx.path,
9725
+ parent: ctx
9726
+ });
9727
+ if (!isValid(base))
9728
+ return INVALID;
9729
+ const result = effect.transform(base.value, checkCtx);
9730
+ if (result instanceof Promise) {
9731
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
9732
+ }
9733
+ return { status: status.value, value: result };
9734
+ } else {
9735
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
9736
+ if (!isValid(base))
9737
+ return INVALID;
9738
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
9739
+ status: status.value,
9740
+ value: result
9741
+ }));
9742
+ });
9743
+ }
9744
+ }
9745
+ util.assertNever(effect);
9746
+ }
9747
+ };
9748
+ ZodEffects.create = (schema, effect, params) => {
9749
+ return new ZodEffects({
9750
+ schema,
9751
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
9752
+ effect,
9753
+ ...processCreateParams(params)
9754
+ });
9755
+ };
9756
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
9757
+ return new ZodEffects({
9758
+ schema,
9759
+ effect: { type: "preprocess", transform: preprocess },
9760
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
9761
+ ...processCreateParams(params)
9762
+ });
9763
+ };
9764
+ var ZodOptional = class extends ZodType {
9765
+ static {
9766
+ __name(this, "ZodOptional");
9767
+ }
9768
+ _parse(input) {
9769
+ const parsedType = this._getType(input);
9770
+ if (parsedType === ZodParsedType.undefined) {
9771
+ return OK(void 0);
9772
+ }
9773
+ return this._def.innerType._parse(input);
9774
+ }
9775
+ unwrap() {
9776
+ return this._def.innerType;
9777
+ }
9778
+ };
9779
+ ZodOptional.create = (type, params) => {
9780
+ return new ZodOptional({
9781
+ innerType: type,
9782
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
9783
+ ...processCreateParams(params)
9784
+ });
9785
+ };
9786
+ var ZodNullable = class extends ZodType {
9787
+ static {
9788
+ __name(this, "ZodNullable");
9789
+ }
9790
+ _parse(input) {
9791
+ const parsedType = this._getType(input);
9792
+ if (parsedType === ZodParsedType.null) {
9793
+ return OK(null);
9794
+ }
9795
+ return this._def.innerType._parse(input);
9796
+ }
9797
+ unwrap() {
9798
+ return this._def.innerType;
9799
+ }
9800
+ };
9801
+ ZodNullable.create = (type, params) => {
9802
+ return new ZodNullable({
9803
+ innerType: type,
9804
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
9805
+ ...processCreateParams(params)
9806
+ });
9807
+ };
9808
+ var ZodDefault = class extends ZodType {
9809
+ static {
9810
+ __name(this, "ZodDefault");
9811
+ }
9812
+ _parse(input) {
9813
+ const { ctx } = this._processInputParams(input);
9814
+ let data = ctx.data;
9815
+ if (ctx.parsedType === ZodParsedType.undefined) {
9816
+ data = this._def.defaultValue();
9817
+ }
9818
+ return this._def.innerType._parse({
9819
+ data,
9820
+ path: ctx.path,
9821
+ parent: ctx
9822
+ });
9823
+ }
9824
+ removeDefault() {
9825
+ return this._def.innerType;
9826
+ }
9827
+ };
9828
+ ZodDefault.create = (type, params) => {
9829
+ return new ZodDefault({
9830
+ innerType: type,
9831
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
9832
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
9833
+ ...processCreateParams(params)
9834
+ });
9835
+ };
9836
+ var ZodCatch = class extends ZodType {
9837
+ static {
9838
+ __name(this, "ZodCatch");
9839
+ }
9840
+ _parse(input) {
9841
+ const { ctx } = this._processInputParams(input);
9842
+ const newCtx = {
9843
+ ...ctx,
9844
+ common: {
9845
+ ...ctx.common,
9846
+ issues: []
9847
+ }
9848
+ };
9849
+ const result = this._def.innerType._parse({
9850
+ data: newCtx.data,
9851
+ path: newCtx.path,
9852
+ parent: {
9853
+ ...newCtx
9854
+ }
9855
+ });
9856
+ if (isAsync(result)) {
9857
+ return result.then((result2) => {
9858
+ return {
9859
+ status: "valid",
9860
+ value: result2.status === "valid" ? result2.value : this._def.catchValue({
9861
+ get error() {
9862
+ return new ZodError(newCtx.common.issues);
9863
+ },
9864
+ input: newCtx.data
9865
+ })
9866
+ };
9867
+ });
9868
+ } else {
9869
+ return {
9870
+ status: "valid",
9871
+ value: result.status === "valid" ? result.value : this._def.catchValue({
9872
+ get error() {
9873
+ return new ZodError(newCtx.common.issues);
9874
+ },
9875
+ input: newCtx.data
9876
+ })
9877
+ };
9878
+ }
9879
+ }
9880
+ removeCatch() {
9881
+ return this._def.innerType;
9882
+ }
9883
+ };
9884
+ ZodCatch.create = (type, params) => {
9885
+ return new ZodCatch({
9886
+ innerType: type,
9887
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
9888
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
9889
+ ...processCreateParams(params)
9890
+ });
9891
+ };
9892
+ var ZodNaN = class extends ZodType {
9893
+ static {
9894
+ __name(this, "ZodNaN");
9895
+ }
9896
+ _parse(input) {
9897
+ const parsedType = this._getType(input);
9898
+ if (parsedType !== ZodParsedType.nan) {
9899
+ const ctx = this._getOrReturnCtx(input);
9900
+ addIssueToContext(ctx, {
9901
+ code: ZodIssueCode.invalid_type,
9902
+ expected: ZodParsedType.nan,
9903
+ received: ctx.parsedType
9904
+ });
9905
+ return INVALID;
9906
+ }
9907
+ return { status: "valid", value: input.data };
9908
+ }
9909
+ };
9910
+ ZodNaN.create = (params) => {
9911
+ return new ZodNaN({
9912
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
9913
+ ...processCreateParams(params)
9914
+ });
9915
+ };
9916
+ var BRAND = Symbol("zod_brand");
9917
+ var ZodBranded = class extends ZodType {
9918
+ static {
9919
+ __name(this, "ZodBranded");
9920
+ }
9921
+ _parse(input) {
9922
+ const { ctx } = this._processInputParams(input);
9923
+ const data = ctx.data;
9924
+ return this._def.type._parse({
9925
+ data,
9926
+ path: ctx.path,
9927
+ parent: ctx
9928
+ });
9929
+ }
9930
+ unwrap() {
9931
+ return this._def.type;
9932
+ }
9933
+ };
9934
+ var ZodPipeline = class _ZodPipeline extends ZodType {
9935
+ static {
9936
+ __name(this, "ZodPipeline");
9937
+ }
9938
+ _parse(input) {
9939
+ const { status, ctx } = this._processInputParams(input);
9940
+ if (ctx.common.async) {
9941
+ const handleAsync = /* @__PURE__ */ __name(async () => {
9942
+ const inResult = await this._def.in._parseAsync({
9943
+ data: ctx.data,
9944
+ path: ctx.path,
9945
+ parent: ctx
9946
+ });
9947
+ if (inResult.status === "aborted")
9948
+ return INVALID;
9949
+ if (inResult.status === "dirty") {
9950
+ status.dirty();
9951
+ return DIRTY(inResult.value);
9952
+ } else {
9953
+ return this._def.out._parseAsync({
9954
+ data: inResult.value,
9955
+ path: ctx.path,
9956
+ parent: ctx
9957
+ });
9958
+ }
9959
+ }, "handleAsync");
9960
+ return handleAsync();
9961
+ } else {
9962
+ const inResult = this._def.in._parseSync({
9963
+ data: ctx.data,
9964
+ path: ctx.path,
9965
+ parent: ctx
9966
+ });
9967
+ if (inResult.status === "aborted")
9968
+ return INVALID;
9969
+ if (inResult.status === "dirty") {
9970
+ status.dirty();
9971
+ return {
9972
+ status: "dirty",
9973
+ value: inResult.value
9974
+ };
9975
+ } else {
9976
+ return this._def.out._parseSync({
9977
+ data: inResult.value,
9978
+ path: ctx.path,
9979
+ parent: ctx
9980
+ });
9981
+ }
9982
+ }
9983
+ }
9984
+ static create(a, b) {
9985
+ return new _ZodPipeline({
9986
+ in: a,
9987
+ out: b,
9988
+ typeName: ZodFirstPartyTypeKind.ZodPipeline
9989
+ });
9990
+ }
9991
+ };
9992
+ var ZodReadonly = class extends ZodType {
9993
+ static {
9994
+ __name(this, "ZodReadonly");
9995
+ }
9996
+ _parse(input) {
9997
+ const result = this._def.innerType._parse(input);
9998
+ const freeze = /* @__PURE__ */ __name((data) => {
9999
+ if (isValid(data)) {
10000
+ data.value = Object.freeze(data.value);
10001
+ }
10002
+ return data;
10003
+ }, "freeze");
10004
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
10005
+ }
10006
+ unwrap() {
10007
+ return this._def.innerType;
10008
+ }
10009
+ };
10010
+ ZodReadonly.create = (type, params) => {
10011
+ return new ZodReadonly({
10012
+ innerType: type,
10013
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
10014
+ ...processCreateParams(params)
10015
+ });
10016
+ };
10017
+ function cleanParams(params, data) {
10018
+ const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
10019
+ const p2 = typeof p === "string" ? { message: p } : p;
10020
+ return p2;
10021
+ }
10022
+ __name(cleanParams, "cleanParams");
10023
+ function custom(check, _params = {}, fatal) {
10024
+ if (check)
10025
+ return ZodAny.create().superRefine((data, ctx) => {
10026
+ const r = check(data);
10027
+ if (r instanceof Promise) {
10028
+ return r.then((r2) => {
10029
+ if (!r2) {
10030
+ const params = cleanParams(_params, data);
10031
+ const _fatal = params.fatal ?? fatal ?? true;
10032
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
10033
+ }
10034
+ });
10035
+ }
10036
+ if (!r) {
10037
+ const params = cleanParams(_params, data);
10038
+ const _fatal = params.fatal ?? fatal ?? true;
10039
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
10040
+ }
10041
+ return;
10042
+ });
10043
+ return ZodAny.create();
10044
+ }
10045
+ __name(custom, "custom");
10046
+ var late = {
10047
+ object: ZodObject.lazycreate
10048
+ };
10049
+ var ZodFirstPartyTypeKind;
10050
+ (function(ZodFirstPartyTypeKind2) {
10051
+ ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
10052
+ ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
10053
+ ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
10054
+ ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
10055
+ ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
10056
+ ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
10057
+ ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
10058
+ ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
10059
+ ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
10060
+ ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
10061
+ ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
10062
+ ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
10063
+ ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
10064
+ ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
10065
+ ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
10066
+ ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
10067
+ ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
10068
+ ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
10069
+ ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
10070
+ ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
10071
+ ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
10072
+ ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
10073
+ ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
10074
+ ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
10075
+ ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
10076
+ ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
10077
+ ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
10078
+ ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
10079
+ ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
10080
+ ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
10081
+ ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
10082
+ ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
10083
+ ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
10084
+ ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
10085
+ ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
10086
+ ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
10087
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
10088
+ var instanceOfType = /* @__PURE__ */ __name((cls, params = {
10089
+ message: `Input not instance of ${cls.name}`
10090
+ }) => custom((data) => data instanceof cls, params), "instanceOfType");
10091
+ var stringType = ZodString.create;
10092
+ var numberType = ZodNumber.create;
10093
+ var nanType = ZodNaN.create;
10094
+ var bigIntType = ZodBigInt.create;
10095
+ var booleanType = ZodBoolean.create;
10096
+ var dateType = ZodDate.create;
10097
+ var symbolType = ZodSymbol.create;
10098
+ var undefinedType = ZodUndefined.create;
10099
+ var nullType = ZodNull.create;
10100
+ var anyType = ZodAny.create;
10101
+ var unknownType = ZodUnknown.create;
10102
+ var neverType = ZodNever.create;
10103
+ var voidType = ZodVoid.create;
10104
+ var arrayType = ZodArray.create;
10105
+ var objectType = ZodObject.create;
10106
+ var strictObjectType = ZodObject.strictCreate;
10107
+ var unionType = ZodUnion.create;
10108
+ var discriminatedUnionType = ZodDiscriminatedUnion.create;
10109
+ var intersectionType = ZodIntersection.create;
10110
+ var tupleType = ZodTuple.create;
10111
+ var recordType = ZodRecord.create;
10112
+ var mapType = ZodMap.create;
10113
+ var setType = ZodSet.create;
10114
+ var functionType = ZodFunction.create;
10115
+ var lazyType = ZodLazy.create;
10116
+ var literalType = ZodLiteral.create;
10117
+ var enumType = ZodEnum.create;
10118
+ var nativeEnumType = ZodNativeEnum.create;
10119
+ var promiseType = ZodPromise.create;
10120
+ var effectsType = ZodEffects.create;
10121
+ var optionalType = ZodOptional.create;
10122
+ var nullableType = ZodNullable.create;
10123
+ var preprocessType = ZodEffects.createWithPreprocess;
10124
+ var pipelineType = ZodPipeline.create;
10125
+ var ostring = /* @__PURE__ */ __name(() => stringType().optional(), "ostring");
10126
+ var onumber = /* @__PURE__ */ __name(() => numberType().optional(), "onumber");
10127
+ var oboolean = /* @__PURE__ */ __name(() => booleanType().optional(), "oboolean");
10128
+ var coerce = {
10129
+ string: /* @__PURE__ */ __name((arg) => ZodString.create({ ...arg, coerce: true }), "string"),
10130
+ number: /* @__PURE__ */ __name((arg) => ZodNumber.create({ ...arg, coerce: true }), "number"),
10131
+ boolean: /* @__PURE__ */ __name((arg) => ZodBoolean.create({
10132
+ ...arg,
10133
+ coerce: true
10134
+ }), "boolean"),
10135
+ bigint: /* @__PURE__ */ __name((arg) => ZodBigInt.create({ ...arg, coerce: true }), "bigint"),
10136
+ date: /* @__PURE__ */ __name((arg) => ZodDate.create({ ...arg, coerce: true }), "date")
10137
+ };
10138
+ var NEVER = INVALID;
10139
+
10140
+ // ../packages/common/interpolate.ts
10141
+ var easingCurveSchema = external_exports.enum(["ease-in", "ease-out", "ease-in-out", "linear"]);
10142
+
10143
+ // src/building.ts
10144
+ import { Facade, Floor, FloorStack } from "@mappedin/mappedin-js";
10145
+ var Building = class {
10146
+ static {
10147
+ __name(this, "Building");
10148
+ }
10149
+ __type = "building";
10150
+ #floorStack;
10151
+ #floorsById = /* @__PURE__ */ new Map();
10152
+ #floorsByElevation = /* @__PURE__ */ new Map();
10153
+ #floorsByElevationSorted = [];
10154
+ #mapView;
10155
+ #spacesByAltitude;
10156
+ #animationInProgress;
10157
+ defaultFloor;
10158
+ activeFloor;
10159
+ excluded = false;
10160
+ constructor(floorStack, mapView) {
10161
+ this.#floorStack = floorStack;
10162
+ this.#floorsById = new Map(floorStack.floors.map((floor) => [floor.id, floor]));
10163
+ this.#floorsByElevation = new Map(floorStack.floors.map((floor) => [floor.elevation, floor]));
10164
+ this.#floorsByElevationSorted = Array.from(this.#floorsByElevation.values()).sort(
10165
+ (a, b) => a.elevation - b.elevation
10166
+ );
10167
+ this.defaultFloor = floorStack.defaultFloor;
10168
+ this.activeFloor = this.defaultFloor;
10169
+ this.#mapView = mapView;
10170
+ }
10171
+ get id() {
10172
+ return this.#floorStack.id;
10173
+ }
10174
+ get name() {
10175
+ return this.#floorStack.name;
10176
+ }
10177
+ get floors() {
10178
+ return this.#floorStack.floors;
10179
+ }
10180
+ get floorStack() {
10181
+ return this.#floorStack;
10182
+ }
10183
+ get facade() {
10184
+ return this.#floorStack.facade;
10185
+ }
10186
+ get isCurrentFloorStack() {
10187
+ return this.id === this.#mapView.currentFloorStack.id;
10188
+ }
10189
+ get isIndoor() {
10190
+ const state = this.#mapView.getState(this.facade);
10191
+ return this.isCurrentFloorStack || state?.visible === false && state?.opacity === 0;
10192
+ }
10193
+ get canSetFloor() {
10194
+ return this.isIndoor || !this.excluded;
10195
+ }
10196
+ #maxElevation;
10197
+ get maxElevation() {
10198
+ if (this.#maxElevation == null) {
10199
+ this.#maxElevation = Math.max(...this.#floorsByElevation.keys());
10200
+ }
10201
+ return this.#maxElevation;
10202
+ }
10203
+ #minElevation;
10204
+ get minElevation() {
10205
+ if (this.#minElevation == null) {
10206
+ this.#minElevation = Math.min(...this.#floorsByElevation.keys());
10207
+ }
10208
+ return this.#minElevation;
10209
+ }
10210
+ has(f) {
10211
+ if (Floor.is(f)) {
10212
+ return this.#floorsById.has(f.id);
10213
+ }
10214
+ if (FloorStack.is(f)) {
10215
+ return f.id === this.#floorStack.id;
10216
+ }
10217
+ if (Facade.is(f)) {
10218
+ return f.id === this.facade.id;
10219
+ }
10220
+ return false;
10221
+ }
10222
+ get aboveGroundFloors() {
10223
+ return this.#floorsByElevationSorted.filter((floor) => floor.elevation >= 0);
10224
+ }
10225
+ expandFacade() {
10226
+ if (!this.#mapView.options.multiFloorView?.enabled || !this.facade || this.facade.__type !== "facade" || this.facade.spaces.length < 1) {
10227
+ return;
10228
+ }
10229
+ const footprintHeight = this.#mapView.options.multiFloorView.floorGap ?? 10;
10230
+ if (!this.#spacesByAltitude) {
10231
+ this.#spacesByAltitude = /* @__PURE__ */ new Map();
10232
+ for (const space of this.facade.spaces) {
10233
+ const state = this.#mapView.getState(space);
10234
+ const altitude = state?.altitude ?? 0;
10235
+ const height = state?.height ?? 0;
10236
+ if (!this.#spacesByAltitude.has(altitude)) {
10237
+ this.#spacesByAltitude.set(altitude, []);
10238
+ }
10239
+ this.#spacesByAltitude.get(altitude).push({
10240
+ space,
10241
+ originalAltitude: altitude,
10242
+ originalHeight: height
10243
+ });
10244
+ }
10245
+ }
10246
+ const altitudeKeys = Array.from(this.#spacesByAltitude.keys()).sort((a, b) => a - b);
10247
+ const isSingleAltitude = altitudeKeys.length === 1;
10248
+ const heightToUse = isSingleAltitude ? footprintHeight * (this.aboveGroundFloors.length - 1) : footprintHeight;
10249
+ let currentAltitude = 0;
10250
+ altitudeKeys.forEach((originalAltitude) => {
10251
+ const spaceData = this.#spacesByAltitude.get(originalAltitude);
10252
+ for (const { space } of spaceData) {
10253
+ this.#mapView.updateState(space, {
10254
+ height: isSingleAltitude ? heightToUse : footprintHeight,
10255
+ altitude: currentAltitude
10256
+ });
10257
+ }
10258
+ if (!isSingleAltitude) {
10259
+ currentAltitude += footprintHeight;
10260
+ }
10261
+ });
10262
+ }
10263
+ collapseFacade() {
10264
+ if (!this.#spacesByAltitude) {
10265
+ return;
10266
+ }
10267
+ for (const spaceDataArray of this.#spacesByAltitude.values()) {
10268
+ for (const { space, originalAltitude, originalHeight } of spaceDataArray) {
10269
+ this.#mapView.updateState(space, {
10270
+ height: originalHeight,
10271
+ altitude: originalAltitude
10272
+ });
10273
+ }
10274
+ }
10275
+ this.#spacesByAltitude = void 0;
10276
+ }
10277
+ getFloorByElevation(elevation) {
10278
+ return this.#floorsByElevation.get(elevation);
10279
+ }
10280
+ getNearestFloorByElevation(targetElevation) {
10281
+ const exactMatch = this.getFloorByElevation(targetElevation);
10282
+ if (exactMatch) {
10283
+ return exactMatch;
10284
+ }
10285
+ if (targetElevation >= 0) {
10286
+ if (targetElevation > this.maxElevation) {
10287
+ return this.#floorsByElevationSorted[this.#floorsByElevationSorted.length - 1];
10288
+ }
10289
+ for (let i = this.#floorsByElevationSorted.length - 1; i >= 0; i--) {
10290
+ const floor = this.#floorsByElevationSorted[i];
10291
+ if (floor.elevation <= targetElevation) {
10292
+ return floor;
10293
+ }
10294
+ }
10295
+ } else {
10296
+ if (targetElevation < this.minElevation) {
10297
+ return this.#floorsByElevationSorted[0];
10298
+ }
10299
+ for (const floor of this.#floorsByElevationSorted) {
10300
+ if (floor.elevation >= targetElevation) {
10301
+ return floor;
10302
+ }
10303
+ }
10304
+ }
10305
+ return void 0;
10306
+ }
10307
+ getHighestFloor() {
10308
+ return this.#floorsByElevationSorted[this.#floorsByElevationSorted.length - 1];
10309
+ }
10310
+ cancelAnimation() {
10311
+ if (this.#animationInProgress) {
10312
+ this.#animationInProgress.animation.cancel();
10313
+ this.#animationInProgress = void 0;
10314
+ }
10315
+ }
10316
+ async animateFacade(newState, options = { duration: 150 }) {
10317
+ const currentState = this.#animationInProgress?.state || this.#mapView.getState(this.facade);
10318
+ if (!currentState || !newState || currentState?.opacity === newState.opacity && currentState?.visible === newState.visible) {
10319
+ return { result: "completed" };
10320
+ }
10321
+ this.cancelAnimation();
10322
+ const { opacity, visible } = newState;
10323
+ this.#mapView.updateState(this.facade, {
10324
+ visible: true
10325
+ });
10326
+ if (opacity !== void 0) {
10327
+ this.#animationInProgress = {
10328
+ animation: this.#mapView.animateState(
10329
+ this.facade,
10330
+ {
10331
+ opacity
10332
+ },
10333
+ {
10334
+ duration: options.duration
10335
+ }
10336
+ ),
10337
+ state: newState
10338
+ };
10339
+ const result = await this.#animationInProgress.animation;
10340
+ this.#animationInProgress = void 0;
10341
+ if (result.result === "cancelled") {
10342
+ return result;
10343
+ }
10344
+ }
10345
+ if (visible === false) {
10346
+ this.#mapView.updateState(this.facade, {
10347
+ visible
10348
+ });
10349
+ }
10350
+ return { result: "completed" };
10351
+ }
10352
+ destroy() {
10353
+ this.cancelAnimation();
10354
+ this.#floorStack.floors.forEach((floor) => {
10355
+ this.#mapView.updateState(floor, {
10356
+ visible: floor.id === this.#mapView.currentFloor.id
10357
+ });
10358
+ });
10359
+ if (!this.has(this.#mapView.currentFloor)) {
10360
+ this.#mapView.updateState(this.facade, {
10361
+ visible: true,
10362
+ opacity: 1
10363
+ });
10364
+ }
10365
+ }
10366
+ };
6290
10367
 
6291
10368
  // src/dynamic-focus-scene.ts
10369
+ import { getMultiFloorState } from "@mappedin/mappedin-js";
6292
10370
  function getZoomState(zoomLevel, indoorThreshold, outdoorThreshold) {
6293
10371
  if (zoomLevel >= indoorThreshold) {
6294
10372
  return "in-range";
@@ -6401,7 +10479,7 @@ function getBuildingStates(buildings, inViewSet, currentFloor, zoomState, mode,
6401
10479
  const floorStackState = multiFloorView.enabled ? getMultiFloorState(
6402
10480
  building.floors,
6403
10481
  floorToShow || building.activeFloor,
6404
- multiFloorView.floorHeight,
10482
+ multiFloorView.floorGap,
6405
10483
  floorIdsInNavigation
6406
10484
  ) : getSingleBuildingState(building.floorStack, floorToShow || building.activeFloor, showIndoor);
6407
10485
  const facadeState = getFacadeState(building.facade, showIndoor);
@@ -6920,9 +10998,9 @@ var DynamicFocus = class {
6920
10998
  await this.#applyBuildingStates(newFloor);
6921
10999
  this.#pubsub.publish("focus", { facades: this.focusedFacades });
6922
11000
  }
6923
- if (this.#mapView.options.multiFloorView != null && this.#mapView.options.multiFloorView?.enabled && this.#mapView.options.multiFloorView?.updateCameraElevationOnFloorChange && this.#mapView.Camera.elevation !== this.#floorElevation * (this.#mapView.options.multiFloorView.floorHeight ?? 0)) {
11001
+ if (this.#mapView.options.multiFloorView != null && this.#mapView.options.multiFloorView?.enabled && this.#mapView.options.multiFloorView?.updateCameraElevationOnFloorChange && this.#mapView.Camera.elevation !== this.#floorElevation * (this.#mapView.options.multiFloorView.floorGap ?? 0)) {
6924
11002
  this.#mapView.Camera.animateElevation(
6925
- this.#floorElevation * (this.#mapView.options.multiFloorView.floorHeight ?? 0),
11003
+ this.#floorElevation * (this.#mapView.options.multiFloorView.floorGap ?? 0),
6926
11004
  {
6927
11005
  duration: 750,
6928
11006
  easing: "ease-in-out"