@kokimoki/app 1.10.2 → 1.11.1

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.
@@ -486,7 +486,7 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
486
486
  var eventsExports = events.exports;
487
487
  var EventEmitter$1 = /*@__PURE__*/getDefaultExportFromCjs(eventsExports);
488
488
 
489
- const KOKIMOKI_APP_VERSION = "1.10.2";
489
+ const KOKIMOKI_APP_VERSION = "1.11.1";
490
490
 
491
491
  /**
492
492
  * Utility module to work with key-value stores.
@@ -11398,15 +11398,13 @@ var RoomSubscriptionMode;
11398
11398
 
11399
11399
  class KokimokiStore {
11400
11400
  roomName;
11401
- schema;
11402
11401
  defaultValue;
11403
11402
  mode;
11404
11403
  doc;
11405
11404
  proxy;
11406
11405
  docRoot;
11407
- constructor(roomName, schema, defaultValue, mode = RoomSubscriptionMode.ReadWrite) {
11406
+ constructor(roomName, defaultValue, mode = RoomSubscriptionMode.ReadWrite) {
11408
11407
  this.roomName = roomName;
11409
- this.schema = schema;
11410
11408
  this.defaultValue = defaultValue;
11411
11409
  this.mode = mode;
11412
11410
  // Construct Y doc
@@ -11596,4424 +11594,12 @@ class RoomSubscription {
11596
11594
  }
11597
11595
  }
11598
11596
 
11599
- var util$1;
11600
- (function (util) {
11601
- util.assertEqual = (val) => val;
11602
- function assertIs(_arg) { }
11603
- util.assertIs = assertIs;
11604
- function assertNever(_x) {
11605
- throw new Error();
11606
- }
11607
- util.assertNever = assertNever;
11608
- util.arrayToEnum = (items) => {
11609
- const obj = {};
11610
- for (const item of items) {
11611
- obj[item] = item;
11612
- }
11613
- return obj;
11614
- };
11615
- util.getValidEnumValues = (obj) => {
11616
- const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
11617
- const filtered = {};
11618
- for (const k of validKeys) {
11619
- filtered[k] = obj[k];
11620
- }
11621
- return util.objectValues(filtered);
11622
- };
11623
- util.objectValues = (obj) => {
11624
- return util.objectKeys(obj).map(function (e) {
11625
- return obj[e];
11626
- });
11627
- };
11628
- util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
11629
- ? (obj) => Object.keys(obj) // eslint-disable-line ban/ban
11630
- : (object) => {
11631
- const keys = [];
11632
- for (const key in object) {
11633
- if (Object.prototype.hasOwnProperty.call(object, key)) {
11634
- keys.push(key);
11635
- }
11636
- }
11637
- return keys;
11638
- };
11639
- util.find = (arr, checker) => {
11640
- for (const item of arr) {
11641
- if (checker(item))
11642
- return item;
11643
- }
11644
- return undefined;
11645
- };
11646
- util.isInteger = typeof Number.isInteger === "function"
11647
- ? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
11648
- : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
11649
- function joinValues(array, separator = " | ") {
11650
- return array
11651
- .map((val) => (typeof val === "string" ? `'${val}'` : val))
11652
- .join(separator);
11653
- }
11654
- util.joinValues = joinValues;
11655
- util.jsonStringifyReplacer = (_, value) => {
11656
- if (typeof value === "bigint") {
11657
- return value.toString();
11658
- }
11659
- return value;
11660
- };
11661
- })(util$1 || (util$1 = {}));
11662
- var objectUtil;
11663
- (function (objectUtil) {
11664
- objectUtil.mergeShapes = (first, second) => {
11665
- return {
11666
- ...first,
11667
- ...second, // second overwrites first
11668
- };
11669
- };
11670
- })(objectUtil || (objectUtil = {}));
11671
- const ZodParsedType = util$1.arrayToEnum([
11672
- "string",
11673
- "nan",
11674
- "number",
11675
- "integer",
11676
- "float",
11677
- "boolean",
11678
- "date",
11679
- "bigint",
11680
- "symbol",
11681
- "function",
11682
- "undefined",
11683
- "null",
11684
- "array",
11685
- "object",
11686
- "unknown",
11687
- "promise",
11688
- "void",
11689
- "never",
11690
- "map",
11691
- "set",
11692
- ]);
11693
- const getParsedType = (data) => {
11694
- const t = typeof data;
11695
- switch (t) {
11696
- case "undefined":
11697
- return ZodParsedType.undefined;
11698
- case "string":
11699
- return ZodParsedType.string;
11700
- case "number":
11701
- return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
11702
- case "boolean":
11703
- return ZodParsedType.boolean;
11704
- case "function":
11705
- return ZodParsedType.function;
11706
- case "bigint":
11707
- return ZodParsedType.bigint;
11708
- case "symbol":
11709
- return ZodParsedType.symbol;
11710
- case "object":
11711
- if (Array.isArray(data)) {
11712
- return ZodParsedType.array;
11713
- }
11714
- if (data === null) {
11715
- return ZodParsedType.null;
11716
- }
11717
- if (data.then &&
11718
- typeof data.then === "function" &&
11719
- data.catch &&
11720
- typeof data.catch === "function") {
11721
- return ZodParsedType.promise;
11722
- }
11723
- if (typeof Map !== "undefined" && data instanceof Map) {
11724
- return ZodParsedType.map;
11725
- }
11726
- if (typeof Set !== "undefined" && data instanceof Set) {
11727
- return ZodParsedType.set;
11728
- }
11729
- if (typeof Date !== "undefined" && data instanceof Date) {
11730
- return ZodParsedType.date;
11731
- }
11732
- return ZodParsedType.object;
11733
- default:
11734
- return ZodParsedType.unknown;
11735
- }
11736
- };
11737
-
11738
- const ZodIssueCode = util$1.arrayToEnum([
11739
- "invalid_type",
11740
- "invalid_literal",
11741
- "custom",
11742
- "invalid_union",
11743
- "invalid_union_discriminator",
11744
- "invalid_enum_value",
11745
- "unrecognized_keys",
11746
- "invalid_arguments",
11747
- "invalid_return_type",
11748
- "invalid_date",
11749
- "invalid_string",
11750
- "too_small",
11751
- "too_big",
11752
- "invalid_intersection_types",
11753
- "not_multiple_of",
11754
- "not_finite",
11755
- ]);
11756
- const quotelessJson = (obj) => {
11757
- const json = JSON.stringify(obj, null, 2);
11758
- return json.replace(/"([^"]+)":/g, "$1:");
11759
- };
11760
- class ZodError extends Error {
11761
- get errors() {
11762
- return this.issues;
11763
- }
11764
- constructor(issues) {
11765
- super();
11766
- this.issues = [];
11767
- this.addIssue = (sub) => {
11768
- this.issues = [...this.issues, sub];
11769
- };
11770
- this.addIssues = (subs = []) => {
11771
- this.issues = [...this.issues, ...subs];
11772
- };
11773
- const actualProto = new.target.prototype;
11774
- if (Object.setPrototypeOf) {
11775
- // eslint-disable-next-line ban/ban
11776
- Object.setPrototypeOf(this, actualProto);
11777
- }
11778
- else {
11779
- this.__proto__ = actualProto;
11780
- }
11781
- this.name = "ZodError";
11782
- this.issues = issues;
11783
- }
11784
- format(_mapper) {
11785
- const mapper = _mapper ||
11786
- function (issue) {
11787
- return issue.message;
11788
- };
11789
- const fieldErrors = { _errors: [] };
11790
- const processError = (error) => {
11791
- for (const issue of error.issues) {
11792
- if (issue.code === "invalid_union") {
11793
- issue.unionErrors.map(processError);
11794
- }
11795
- else if (issue.code === "invalid_return_type") {
11796
- processError(issue.returnTypeError);
11797
- }
11798
- else if (issue.code === "invalid_arguments") {
11799
- processError(issue.argumentsError);
11800
- }
11801
- else if (issue.path.length === 0) {
11802
- fieldErrors._errors.push(mapper(issue));
11803
- }
11804
- else {
11805
- let curr = fieldErrors;
11806
- let i = 0;
11807
- while (i < issue.path.length) {
11808
- const el = issue.path[i];
11809
- const terminal = i === issue.path.length - 1;
11810
- if (!terminal) {
11811
- curr[el] = curr[el] || { _errors: [] };
11812
- // if (typeof el === "string") {
11813
- // curr[el] = curr[el] || { _errors: [] };
11814
- // } else if (typeof el === "number") {
11815
- // const errorArray: any = [];
11816
- // errorArray._errors = [];
11817
- // curr[el] = curr[el] || errorArray;
11818
- // }
11819
- }
11820
- else {
11821
- curr[el] = curr[el] || { _errors: [] };
11822
- curr[el]._errors.push(mapper(issue));
11823
- }
11824
- curr = curr[el];
11825
- i++;
11826
- }
11827
- }
11828
- }
11829
- };
11830
- processError(this);
11831
- return fieldErrors;
11832
- }
11833
- static assert(value) {
11834
- if (!(value instanceof ZodError)) {
11835
- throw new Error(`Not a ZodError: ${value}`);
11836
- }
11837
- }
11838
- toString() {
11839
- return this.message;
11840
- }
11841
- get message() {
11842
- return JSON.stringify(this.issues, util$1.jsonStringifyReplacer, 2);
11843
- }
11844
- get isEmpty() {
11845
- return this.issues.length === 0;
11846
- }
11847
- flatten(mapper = (issue) => issue.message) {
11848
- const fieldErrors = {};
11849
- const formErrors = [];
11850
- for (const sub of this.issues) {
11851
- if (sub.path.length > 0) {
11852
- fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
11853
- fieldErrors[sub.path[0]].push(mapper(sub));
11854
- }
11855
- else {
11856
- formErrors.push(mapper(sub));
11857
- }
11858
- }
11859
- return { formErrors, fieldErrors };
11860
- }
11861
- get formErrors() {
11862
- return this.flatten();
11863
- }
11864
- }
11865
- ZodError.create = (issues) => {
11866
- const error = new ZodError(issues);
11867
- return error;
11868
- };
11869
-
11870
- const errorMap = (issue, _ctx) => {
11871
- let message;
11872
- switch (issue.code) {
11873
- case ZodIssueCode.invalid_type:
11874
- if (issue.received === ZodParsedType.undefined) {
11875
- message = "Required";
11876
- }
11877
- else {
11878
- message = `Expected ${issue.expected}, received ${issue.received}`;
11879
- }
11880
- break;
11881
- case ZodIssueCode.invalid_literal:
11882
- message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util$1.jsonStringifyReplacer)}`;
11883
- break;
11884
- case ZodIssueCode.unrecognized_keys:
11885
- message = `Unrecognized key(s) in object: ${util$1.joinValues(issue.keys, ", ")}`;
11886
- break;
11887
- case ZodIssueCode.invalid_union:
11888
- message = `Invalid input`;
11889
- break;
11890
- case ZodIssueCode.invalid_union_discriminator:
11891
- message = `Invalid discriminator value. Expected ${util$1.joinValues(issue.options)}`;
11892
- break;
11893
- case ZodIssueCode.invalid_enum_value:
11894
- message = `Invalid enum value. Expected ${util$1.joinValues(issue.options)}, received '${issue.received}'`;
11895
- break;
11896
- case ZodIssueCode.invalid_arguments:
11897
- message = `Invalid function arguments`;
11898
- break;
11899
- case ZodIssueCode.invalid_return_type:
11900
- message = `Invalid function return type`;
11901
- break;
11902
- case ZodIssueCode.invalid_date:
11903
- message = `Invalid date`;
11904
- break;
11905
- case ZodIssueCode.invalid_string:
11906
- if (typeof issue.validation === "object") {
11907
- if ("includes" in issue.validation) {
11908
- message = `Invalid input: must include "${issue.validation.includes}"`;
11909
- if (typeof issue.validation.position === "number") {
11910
- message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
11911
- }
11912
- }
11913
- else if ("startsWith" in issue.validation) {
11914
- message = `Invalid input: must start with "${issue.validation.startsWith}"`;
11915
- }
11916
- else if ("endsWith" in issue.validation) {
11917
- message = `Invalid input: must end with "${issue.validation.endsWith}"`;
11918
- }
11919
- else {
11920
- util$1.assertNever(issue.validation);
11921
- }
11922
- }
11923
- else if (issue.validation !== "regex") {
11924
- message = `Invalid ${issue.validation}`;
11925
- }
11926
- else {
11927
- message = "Invalid";
11928
- }
11929
- break;
11930
- case ZodIssueCode.too_small:
11931
- if (issue.type === "array")
11932
- message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
11933
- else if (issue.type === "string")
11934
- message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
11935
- else if (issue.type === "number")
11936
- message = `Number must be ${issue.exact
11937
- ? `exactly equal to `
11938
- : issue.inclusive
11939
- ? `greater than or equal to `
11940
- : `greater than `}${issue.minimum}`;
11941
- else if (issue.type === "date")
11942
- message = `Date must be ${issue.exact
11943
- ? `exactly equal to `
11944
- : issue.inclusive
11945
- ? `greater than or equal to `
11946
- : `greater than `}${new Date(Number(issue.minimum))}`;
11947
- else
11948
- message = "Invalid input";
11949
- break;
11950
- case ZodIssueCode.too_big:
11951
- if (issue.type === "array")
11952
- message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
11953
- else if (issue.type === "string")
11954
- message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
11955
- else if (issue.type === "number")
11956
- message = `Number must be ${issue.exact
11957
- ? `exactly`
11958
- : issue.inclusive
11959
- ? `less than or equal to`
11960
- : `less than`} ${issue.maximum}`;
11961
- else if (issue.type === "bigint")
11962
- message = `BigInt must be ${issue.exact
11963
- ? `exactly`
11964
- : issue.inclusive
11965
- ? `less than or equal to`
11966
- : `less than`} ${issue.maximum}`;
11967
- else if (issue.type === "date")
11968
- message = `Date must be ${issue.exact
11969
- ? `exactly`
11970
- : issue.inclusive
11971
- ? `smaller than or equal to`
11972
- : `smaller than`} ${new Date(Number(issue.maximum))}`;
11973
- else
11974
- message = "Invalid input";
11975
- break;
11976
- case ZodIssueCode.custom:
11977
- message = `Invalid input`;
11978
- break;
11979
- case ZodIssueCode.invalid_intersection_types:
11980
- message = `Intersection results could not be merged`;
11981
- break;
11982
- case ZodIssueCode.not_multiple_of:
11983
- message = `Number must be a multiple of ${issue.multipleOf}`;
11984
- break;
11985
- case ZodIssueCode.not_finite:
11986
- message = "Number must be finite";
11987
- break;
11988
- default:
11989
- message = _ctx.defaultError;
11990
- util$1.assertNever(issue);
11991
- }
11992
- return { message };
11993
- };
11994
-
11995
- let overrideErrorMap = errorMap;
11996
- function setErrorMap(map) {
11997
- overrideErrorMap = map;
11998
- }
11999
- function getErrorMap() {
12000
- return overrideErrorMap;
12001
- }
12002
-
12003
- const makeIssue = (params) => {
12004
- const { data, path, errorMaps, issueData } = params;
12005
- const fullPath = [...path, ...(issueData.path || [])];
12006
- const fullIssue = {
12007
- ...issueData,
12008
- path: fullPath,
12009
- };
12010
- if (issueData.message !== undefined) {
12011
- return {
12012
- ...issueData,
12013
- path: fullPath,
12014
- message: issueData.message,
12015
- };
12016
- }
12017
- let errorMessage = "";
12018
- const maps = errorMaps
12019
- .filter((m) => !!m)
12020
- .slice()
12021
- .reverse();
12022
- for (const map of maps) {
12023
- errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
12024
- }
12025
- return {
12026
- ...issueData,
12027
- path: fullPath,
12028
- message: errorMessage,
12029
- };
12030
- };
12031
- const EMPTY_PATH = [];
12032
- function addIssueToContext(ctx, issueData) {
12033
- const overrideMap = getErrorMap();
12034
- const issue = makeIssue({
12035
- issueData: issueData,
12036
- data: ctx.data,
12037
- path: ctx.path,
12038
- errorMaps: [
12039
- ctx.common.contextualErrorMap, // contextual error map is first priority
12040
- ctx.schemaErrorMap, // then schema-bound map if available
12041
- overrideMap, // then global override map
12042
- overrideMap === errorMap ? undefined : errorMap, // then global default map
12043
- ].filter((x) => !!x),
12044
- });
12045
- ctx.common.issues.push(issue);
12046
- }
12047
- class ParseStatus {
12048
- constructor() {
12049
- this.value = "valid";
12050
- }
12051
- dirty() {
12052
- if (this.value === "valid")
12053
- this.value = "dirty";
12054
- }
12055
- abort() {
12056
- if (this.value !== "aborted")
12057
- this.value = "aborted";
12058
- }
12059
- static mergeArray(status, results) {
12060
- const arrayValue = [];
12061
- for (const s of results) {
12062
- if (s.status === "aborted")
12063
- return INVALID;
12064
- if (s.status === "dirty")
12065
- status.dirty();
12066
- arrayValue.push(s.value);
12067
- }
12068
- return { status: status.value, value: arrayValue };
12069
- }
12070
- static async mergeObjectAsync(status, pairs) {
12071
- const syncPairs = [];
12072
- for (const pair of pairs) {
12073
- const key = await pair.key;
12074
- const value = await pair.value;
12075
- syncPairs.push({
12076
- key,
12077
- value,
12078
- });
12079
- }
12080
- return ParseStatus.mergeObjectSync(status, syncPairs);
12081
- }
12082
- static mergeObjectSync(status, pairs) {
12083
- const finalObject = {};
12084
- for (const pair of pairs) {
12085
- const { key, value } = pair;
12086
- if (key.status === "aborted")
12087
- return INVALID;
12088
- if (value.status === "aborted")
12089
- return INVALID;
12090
- if (key.status === "dirty")
12091
- status.dirty();
12092
- if (value.status === "dirty")
12093
- status.dirty();
12094
- if (key.value !== "__proto__" &&
12095
- (typeof value.value !== "undefined" || pair.alwaysSet)) {
12096
- finalObject[key.value] = value.value;
12097
- }
12098
- }
12099
- return { status: status.value, value: finalObject };
12100
- }
12101
- }
12102
- const INVALID = Object.freeze({
12103
- status: "aborted",
12104
- });
12105
- const DIRTY = (value) => ({ status: "dirty", value });
12106
- const OK = (value) => ({ status: "valid", value });
12107
- const isAborted = (x) => x.status === "aborted";
12108
- const isDirty = (x) => x.status === "dirty";
12109
- const isValid = (x) => x.status === "valid";
12110
- const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
12111
-
12112
- /******************************************************************************
12113
- Copyright (c) Microsoft Corporation.
12114
-
12115
- Permission to use, copy, modify, and/or distribute this software for any
12116
- purpose with or without fee is hereby granted.
12117
-
12118
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12119
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12120
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12121
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12122
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12123
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
12124
- PERFORMANCE OF THIS SOFTWARE.
12125
- ***************************************************************************** */
12126
-
12127
- function __classPrivateFieldGet(receiver, state, kind, f) {
12128
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
12129
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
12130
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12131
- }
12132
-
12133
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
12134
- if (kind === "m") throw new TypeError("Private method is not writable");
12135
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
12136
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
12137
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12138
- }
12139
-
12140
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
12141
- var e = new Error(message);
12142
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
12143
- };
12144
-
12145
- var errorUtil;
12146
- (function (errorUtil) {
12147
- errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
12148
- errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
12149
- })(errorUtil || (errorUtil = {}));
12150
-
12151
- var _ZodEnum_cache, _ZodNativeEnum_cache;
12152
- class ParseInputLazyPath {
12153
- constructor(parent, value, path, key) {
12154
- this._cachedPath = [];
12155
- this.parent = parent;
12156
- this.data = value;
12157
- this._path = path;
12158
- this._key = key;
12159
- }
12160
- get path() {
12161
- if (!this._cachedPath.length) {
12162
- if (this._key instanceof Array) {
12163
- this._cachedPath.push(...this._path, ...this._key);
12164
- }
12165
- else {
12166
- this._cachedPath.push(...this._path, this._key);
12167
- }
12168
- }
12169
- return this._cachedPath;
12170
- }
12171
- }
12172
- const handleResult = (ctx, result) => {
12173
- if (isValid(result)) {
12174
- return { success: true, data: result.value };
12175
- }
12176
- else {
12177
- if (!ctx.common.issues.length) {
12178
- throw new Error("Validation failed but no issues detected.");
12179
- }
12180
- return {
12181
- success: false,
12182
- get error() {
12183
- if (this._error)
12184
- return this._error;
12185
- const error = new ZodError(ctx.common.issues);
12186
- this._error = error;
12187
- return this._error;
12188
- },
12189
- };
12190
- }
12191
- };
12192
- function processCreateParams(params) {
12193
- if (!params)
12194
- return {};
12195
- const { errorMap, invalid_type_error, required_error, description } = params;
12196
- if (errorMap && (invalid_type_error || required_error)) {
12197
- throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
12198
- }
12199
- if (errorMap)
12200
- return { errorMap: errorMap, description };
12201
- const customMap = (iss, ctx) => {
12202
- var _a, _b;
12203
- const { message } = params;
12204
- if (iss.code === "invalid_enum_value") {
12205
- return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
12206
- }
12207
- if (typeof ctx.data === "undefined") {
12208
- return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
12209
- }
12210
- if (iss.code !== "invalid_type")
12211
- return { message: ctx.defaultError };
12212
- return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
12213
- };
12214
- return { errorMap: customMap, description };
12215
- }
12216
- class ZodType {
12217
- get description() {
12218
- return this._def.description;
12219
- }
12220
- _getType(input) {
12221
- return getParsedType(input.data);
12222
- }
12223
- _getOrReturnCtx(input, ctx) {
12224
- return (ctx || {
12225
- common: input.parent.common,
12226
- data: input.data,
12227
- parsedType: getParsedType(input.data),
12228
- schemaErrorMap: this._def.errorMap,
12229
- path: input.path,
12230
- parent: input.parent,
12231
- });
12232
- }
12233
- _processInputParams(input) {
12234
- return {
12235
- status: new ParseStatus(),
12236
- ctx: {
12237
- common: input.parent.common,
12238
- data: input.data,
12239
- parsedType: getParsedType(input.data),
12240
- schemaErrorMap: this._def.errorMap,
12241
- path: input.path,
12242
- parent: input.parent,
12243
- },
12244
- };
12245
- }
12246
- _parseSync(input) {
12247
- const result = this._parse(input);
12248
- if (isAsync(result)) {
12249
- throw new Error("Synchronous parse encountered promise.");
12250
- }
12251
- return result;
12252
- }
12253
- _parseAsync(input) {
12254
- const result = this._parse(input);
12255
- return Promise.resolve(result);
12256
- }
12257
- parse(data, params) {
12258
- const result = this.safeParse(data, params);
12259
- if (result.success)
12260
- return result.data;
12261
- throw result.error;
12262
- }
12263
- safeParse(data, params) {
12264
- var _a;
12265
- const ctx = {
12266
- common: {
12267
- issues: [],
12268
- async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
12269
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
12270
- },
12271
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
12272
- schemaErrorMap: this._def.errorMap,
12273
- parent: null,
12274
- data,
12275
- parsedType: getParsedType(data),
12276
- };
12277
- const result = this._parseSync({ data, path: ctx.path, parent: ctx });
12278
- return handleResult(ctx, result);
12279
- }
12280
- "~validate"(data) {
12281
- var _a, _b;
12282
- const ctx = {
12283
- common: {
12284
- issues: [],
12285
- async: !!this["~standard"].async,
12286
- },
12287
- path: [],
12288
- schemaErrorMap: this._def.errorMap,
12289
- parent: null,
12290
- data,
12291
- parsedType: getParsedType(data),
12292
- };
12293
- if (!this["~standard"].async) {
12294
- try {
12295
- const result = this._parseSync({ data, path: [], parent: ctx });
12296
- return isValid(result)
12297
- ? {
12298
- value: result.value,
12299
- }
12300
- : {
12301
- issues: ctx.common.issues,
12302
- };
12303
- }
12304
- catch (err) {
12305
- if ((_b = (_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes("encountered")) {
12306
- this["~standard"].async = true;
12307
- }
12308
- ctx.common = {
12309
- issues: [],
12310
- async: true,
12311
- };
12312
- }
12313
- }
12314
- return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result)
12315
- ? {
12316
- value: result.value,
12317
- }
12318
- : {
12319
- issues: ctx.common.issues,
12320
- });
12321
- }
12322
- async parseAsync(data, params) {
12323
- const result = await this.safeParseAsync(data, params);
12324
- if (result.success)
12325
- return result.data;
12326
- throw result.error;
12327
- }
12328
- async safeParseAsync(data, params) {
12329
- const ctx = {
12330
- common: {
12331
- issues: [],
12332
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
12333
- async: true,
12334
- },
12335
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
12336
- schemaErrorMap: this._def.errorMap,
12337
- parent: null,
12338
- data,
12339
- parsedType: getParsedType(data),
12340
- };
12341
- const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
12342
- const result = await (isAsync(maybeAsyncResult)
12343
- ? maybeAsyncResult
12344
- : Promise.resolve(maybeAsyncResult));
12345
- return handleResult(ctx, result);
12346
- }
12347
- refine(check, message) {
12348
- const getIssueProperties = (val) => {
12349
- if (typeof message === "string" || typeof message === "undefined") {
12350
- return { message };
12351
- }
12352
- else if (typeof message === "function") {
12353
- return message(val);
12354
- }
12355
- else {
12356
- return message;
12357
- }
12358
- };
12359
- return this._refinement((val, ctx) => {
12360
- const result = check(val);
12361
- const setError = () => ctx.addIssue({
12362
- code: ZodIssueCode.custom,
12363
- ...getIssueProperties(val),
12364
- });
12365
- if (typeof Promise !== "undefined" && result instanceof Promise) {
12366
- return result.then((data) => {
12367
- if (!data) {
12368
- setError();
12369
- return false;
12370
- }
12371
- else {
12372
- return true;
12373
- }
12374
- });
12375
- }
12376
- if (!result) {
12377
- setError();
12378
- return false;
12379
- }
12380
- else {
12381
- return true;
12382
- }
12383
- });
12384
- }
12385
- refinement(check, refinementData) {
12386
- return this._refinement((val, ctx) => {
12387
- if (!check(val)) {
12388
- ctx.addIssue(typeof refinementData === "function"
12389
- ? refinementData(val, ctx)
12390
- : refinementData);
12391
- return false;
12392
- }
12393
- else {
12394
- return true;
12395
- }
12396
- });
12397
- }
12398
- _refinement(refinement) {
12399
- return new ZodEffects({
12400
- schema: this,
12401
- typeName: ZodFirstPartyTypeKind.ZodEffects,
12402
- effect: { type: "refinement", refinement },
12403
- });
12404
- }
12405
- superRefine(refinement) {
12406
- return this._refinement(refinement);
12407
- }
12408
- constructor(def) {
12409
- /** Alias of safeParseAsync */
12410
- this.spa = this.safeParseAsync;
12411
- this._def = def;
12412
- this.parse = this.parse.bind(this);
12413
- this.safeParse = this.safeParse.bind(this);
12414
- this.parseAsync = this.parseAsync.bind(this);
12415
- this.safeParseAsync = this.safeParseAsync.bind(this);
12416
- this.spa = this.spa.bind(this);
12417
- this.refine = this.refine.bind(this);
12418
- this.refinement = this.refinement.bind(this);
12419
- this.superRefine = this.superRefine.bind(this);
12420
- this.optional = this.optional.bind(this);
12421
- this.nullable = this.nullable.bind(this);
12422
- this.nullish = this.nullish.bind(this);
12423
- this.array = this.array.bind(this);
12424
- this.promise = this.promise.bind(this);
12425
- this.or = this.or.bind(this);
12426
- this.and = this.and.bind(this);
12427
- this.transform = this.transform.bind(this);
12428
- this.brand = this.brand.bind(this);
12429
- this.default = this.default.bind(this);
12430
- this.catch = this.catch.bind(this);
12431
- this.describe = this.describe.bind(this);
12432
- this.pipe = this.pipe.bind(this);
12433
- this.readonly = this.readonly.bind(this);
12434
- this.isNullable = this.isNullable.bind(this);
12435
- this.isOptional = this.isOptional.bind(this);
12436
- this["~standard"] = {
12437
- version: 1,
12438
- vendor: "zod",
12439
- validate: (data) => this["~validate"](data),
12440
- };
12441
- }
12442
- optional() {
12443
- return ZodOptional.create(this, this._def);
12444
- }
12445
- nullable() {
12446
- return ZodNullable.create(this, this._def);
12447
- }
12448
- nullish() {
12449
- return this.nullable().optional();
12450
- }
12451
- array() {
12452
- return ZodArray.create(this);
12453
- }
12454
- promise() {
12455
- return ZodPromise.create(this, this._def);
12456
- }
12457
- or(option) {
12458
- return ZodUnion.create([this, option], this._def);
12459
- }
12460
- and(incoming) {
12461
- return ZodIntersection.create(this, incoming, this._def);
12462
- }
12463
- transform(transform) {
12464
- return new ZodEffects({
12465
- ...processCreateParams(this._def),
12466
- schema: this,
12467
- typeName: ZodFirstPartyTypeKind.ZodEffects,
12468
- effect: { type: "transform", transform },
12469
- });
12470
- }
12471
- default(def) {
12472
- const defaultValueFunc = typeof def === "function" ? def : () => def;
12473
- return new ZodDefault({
12474
- ...processCreateParams(this._def),
12475
- innerType: this,
12476
- defaultValue: defaultValueFunc,
12477
- typeName: ZodFirstPartyTypeKind.ZodDefault,
12478
- });
12479
- }
12480
- brand() {
12481
- return new ZodBranded({
12482
- typeName: ZodFirstPartyTypeKind.ZodBranded,
12483
- type: this,
12484
- ...processCreateParams(this._def),
12485
- });
12486
- }
12487
- catch(def) {
12488
- const catchValueFunc = typeof def === "function" ? def : () => def;
12489
- return new ZodCatch({
12490
- ...processCreateParams(this._def),
12491
- innerType: this,
12492
- catchValue: catchValueFunc,
12493
- typeName: ZodFirstPartyTypeKind.ZodCatch,
12494
- });
12495
- }
12496
- describe(description) {
12497
- const This = this.constructor;
12498
- return new This({
12499
- ...this._def,
12500
- description,
12501
- });
12502
- }
12503
- pipe(target) {
12504
- return ZodPipeline.create(this, target);
12505
- }
12506
- readonly() {
12507
- return ZodReadonly.create(this);
12508
- }
12509
- isOptional() {
12510
- return this.safeParse(undefined).success;
12511
- }
12512
- isNullable() {
12513
- return this.safeParse(null).success;
12514
- }
12515
- }
12516
- const cuidRegex = /^c[^\s-]{8,}$/i;
12517
- const cuid2Regex = /^[0-9a-z]+$/;
12518
- const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
12519
- // const uuidRegex =
12520
- // /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
12521
- const 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;
12522
- const nanoidRegex = /^[a-z0-9_-]{21}$/i;
12523
- const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
12524
- const 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)?)??$/;
12525
- // from https://stackoverflow.com/a/46181/1550155
12526
- // old version: too slow, didn't support unicode
12527
- // const emailRegex = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
12528
- //old email regex
12529
- // const emailRegex = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@((?!-)([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{1,})[^-<>()[\].,;:\s@"]$/i;
12530
- // eslint-disable-next-line
12531
- // const emailRegex =
12532
- // /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\])|(\[IPv6:(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))\])|([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*(\.[A-Za-z]{2,})+))$/;
12533
- // const emailRegex =
12534
- // /^[a-zA-Z0-9\.\!\#\$\%\&\'\*\+\/\=\?\^\_\`\{\|\}\~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
12535
- // const emailRegex =
12536
- // /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
12537
- const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
12538
- // const emailRegex =
12539
- // /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
12540
- // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
12541
- const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
12542
- let emojiRegex;
12543
- // faster, simpler, safer
12544
- const 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])$/;
12545
- const 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])$/;
12546
- // const ipv6Regex =
12547
- // /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
12548
- const 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]))$/;
12549
- const 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])$/;
12550
- // https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
12551
- const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
12552
- // https://base64.guru/standards/base64url
12553
- const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
12554
- // simple
12555
- // const dateRegexSource = `\\d{4}-\\d{2}-\\d{2}`;
12556
- // no leap year validation
12557
- // const dateRegexSource = `\\d{4}-((0[13578]|10|12)-31|(0[13-9]|1[0-2])-30|(0[1-9]|1[0-2])-(0[1-9]|1\\d|2\\d))`;
12558
- // with leap year validation
12559
- const 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])))`;
12560
- const dateRegex = new RegExp(`^${dateRegexSource}$`);
12561
- function timeRegexSource(args) {
12562
- // let regex = `\\d{2}:\\d{2}:\\d{2}`;
12563
- let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
12564
- if (args.precision) {
12565
- regex = `${regex}\\.\\d{${args.precision}}`;
12566
- }
12567
- else if (args.precision == null) {
12568
- regex = `${regex}(\\.\\d+)?`;
12569
- }
12570
- return regex;
12571
- }
12572
- function timeRegex(args) {
12573
- return new RegExp(`^${timeRegexSource(args)}$`);
12574
- }
12575
- // Adapted from https://stackoverflow.com/a/3143231
12576
- function datetimeRegex(args) {
12577
- let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
12578
- const opts = [];
12579
- opts.push(args.local ? `Z?` : `Z`);
12580
- if (args.offset)
12581
- opts.push(`([+-]\\d{2}:?\\d{2})`);
12582
- regex = `${regex}(${opts.join("|")})`;
12583
- return new RegExp(`^${regex}$`);
12584
- }
12585
- function isValidIP(ip, version) {
12586
- if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
12587
- return true;
12588
- }
12589
- if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
12590
- return true;
12591
- }
12592
- return false;
12593
- }
12594
- function isValidJWT(jwt, alg) {
12595
- if (!jwtRegex.test(jwt))
12596
- return false;
12597
- try {
12598
- const [header] = jwt.split(".");
12599
- // Convert base64url to base64
12600
- const base64 = header
12601
- .replace(/-/g, "+")
12602
- .replace(/_/g, "/")
12603
- .padEnd(header.length + ((4 - (header.length % 4)) % 4), "=");
12604
- const decoded = JSON.parse(atob(base64));
12605
- if (typeof decoded !== "object" || decoded === null)
12606
- return false;
12607
- if (!decoded.typ || !decoded.alg)
12608
- return false;
12609
- if (alg && decoded.alg !== alg)
12610
- return false;
12611
- return true;
12612
- }
12613
- catch (_a) {
12614
- return false;
12615
- }
12616
- }
12617
- function isValidCidr(ip, version) {
12618
- if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
12619
- return true;
12620
- }
12621
- if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
12622
- return true;
12623
- }
12624
- return false;
12625
- }
12626
- class ZodString extends ZodType {
12627
- _parse(input) {
12628
- if (this._def.coerce) {
12629
- input.data = String(input.data);
12630
- }
12631
- const parsedType = this._getType(input);
12632
- if (parsedType !== ZodParsedType.string) {
12633
- const ctx = this._getOrReturnCtx(input);
12634
- addIssueToContext(ctx, {
12635
- code: ZodIssueCode.invalid_type,
12636
- expected: ZodParsedType.string,
12637
- received: ctx.parsedType,
12638
- });
12639
- return INVALID;
12640
- }
12641
- const status = new ParseStatus();
12642
- let ctx = undefined;
12643
- for (const check of this._def.checks) {
12644
- if (check.kind === "min") {
12645
- if (input.data.length < check.value) {
12646
- ctx = this._getOrReturnCtx(input, ctx);
12647
- addIssueToContext(ctx, {
12648
- code: ZodIssueCode.too_small,
12649
- minimum: check.value,
12650
- type: "string",
12651
- inclusive: true,
12652
- exact: false,
12653
- message: check.message,
12654
- });
12655
- status.dirty();
12656
- }
12657
- }
12658
- else if (check.kind === "max") {
12659
- if (input.data.length > check.value) {
12660
- ctx = this._getOrReturnCtx(input, ctx);
12661
- addIssueToContext(ctx, {
12662
- code: ZodIssueCode.too_big,
12663
- maximum: check.value,
12664
- type: "string",
12665
- inclusive: true,
12666
- exact: false,
12667
- message: check.message,
12668
- });
12669
- status.dirty();
12670
- }
12671
- }
12672
- else if (check.kind === "length") {
12673
- const tooBig = input.data.length > check.value;
12674
- const tooSmall = input.data.length < check.value;
12675
- if (tooBig || tooSmall) {
12676
- ctx = this._getOrReturnCtx(input, ctx);
12677
- if (tooBig) {
12678
- addIssueToContext(ctx, {
12679
- code: ZodIssueCode.too_big,
12680
- maximum: check.value,
12681
- type: "string",
12682
- inclusive: true,
12683
- exact: true,
12684
- message: check.message,
12685
- });
12686
- }
12687
- else if (tooSmall) {
12688
- addIssueToContext(ctx, {
12689
- code: ZodIssueCode.too_small,
12690
- minimum: check.value,
12691
- type: "string",
12692
- inclusive: true,
12693
- exact: true,
12694
- message: check.message,
12695
- });
12696
- }
12697
- status.dirty();
12698
- }
12699
- }
12700
- else if (check.kind === "email") {
12701
- if (!emailRegex.test(input.data)) {
12702
- ctx = this._getOrReturnCtx(input, ctx);
12703
- addIssueToContext(ctx, {
12704
- validation: "email",
12705
- code: ZodIssueCode.invalid_string,
12706
- message: check.message,
12707
- });
12708
- status.dirty();
12709
- }
12710
- }
12711
- else if (check.kind === "emoji") {
12712
- if (!emojiRegex) {
12713
- emojiRegex = new RegExp(_emojiRegex, "u");
12714
- }
12715
- if (!emojiRegex.test(input.data)) {
12716
- ctx = this._getOrReturnCtx(input, ctx);
12717
- addIssueToContext(ctx, {
12718
- validation: "emoji",
12719
- code: ZodIssueCode.invalid_string,
12720
- message: check.message,
12721
- });
12722
- status.dirty();
12723
- }
12724
- }
12725
- else if (check.kind === "uuid") {
12726
- if (!uuidRegex.test(input.data)) {
12727
- ctx = this._getOrReturnCtx(input, ctx);
12728
- addIssueToContext(ctx, {
12729
- validation: "uuid",
12730
- code: ZodIssueCode.invalid_string,
12731
- message: check.message,
12732
- });
12733
- status.dirty();
12734
- }
12735
- }
12736
- else if (check.kind === "nanoid") {
12737
- if (!nanoidRegex.test(input.data)) {
12738
- ctx = this._getOrReturnCtx(input, ctx);
12739
- addIssueToContext(ctx, {
12740
- validation: "nanoid",
12741
- code: ZodIssueCode.invalid_string,
12742
- message: check.message,
12743
- });
12744
- status.dirty();
12745
- }
12746
- }
12747
- else if (check.kind === "cuid") {
12748
- if (!cuidRegex.test(input.data)) {
12749
- ctx = this._getOrReturnCtx(input, ctx);
12750
- addIssueToContext(ctx, {
12751
- validation: "cuid",
12752
- code: ZodIssueCode.invalid_string,
12753
- message: check.message,
12754
- });
12755
- status.dirty();
12756
- }
12757
- }
12758
- else if (check.kind === "cuid2") {
12759
- if (!cuid2Regex.test(input.data)) {
12760
- ctx = this._getOrReturnCtx(input, ctx);
12761
- addIssueToContext(ctx, {
12762
- validation: "cuid2",
12763
- code: ZodIssueCode.invalid_string,
12764
- message: check.message,
12765
- });
12766
- status.dirty();
12767
- }
12768
- }
12769
- else if (check.kind === "ulid") {
12770
- if (!ulidRegex.test(input.data)) {
12771
- ctx = this._getOrReturnCtx(input, ctx);
12772
- addIssueToContext(ctx, {
12773
- validation: "ulid",
12774
- code: ZodIssueCode.invalid_string,
12775
- message: check.message,
12776
- });
12777
- status.dirty();
12778
- }
12779
- }
12780
- else if (check.kind === "url") {
12781
- try {
12782
- new URL(input.data);
12783
- }
12784
- catch (_a) {
12785
- ctx = this._getOrReturnCtx(input, ctx);
12786
- addIssueToContext(ctx, {
12787
- validation: "url",
12788
- code: ZodIssueCode.invalid_string,
12789
- message: check.message,
12790
- });
12791
- status.dirty();
12792
- }
12793
- }
12794
- else if (check.kind === "regex") {
12795
- check.regex.lastIndex = 0;
12796
- const testResult = check.regex.test(input.data);
12797
- if (!testResult) {
12798
- ctx = this._getOrReturnCtx(input, ctx);
12799
- addIssueToContext(ctx, {
12800
- validation: "regex",
12801
- code: ZodIssueCode.invalid_string,
12802
- message: check.message,
12803
- });
12804
- status.dirty();
12805
- }
12806
- }
12807
- else if (check.kind === "trim") {
12808
- input.data = input.data.trim();
12809
- }
12810
- else if (check.kind === "includes") {
12811
- if (!input.data.includes(check.value, check.position)) {
12812
- ctx = this._getOrReturnCtx(input, ctx);
12813
- addIssueToContext(ctx, {
12814
- code: ZodIssueCode.invalid_string,
12815
- validation: { includes: check.value, position: check.position },
12816
- message: check.message,
12817
- });
12818
- status.dirty();
12819
- }
12820
- }
12821
- else if (check.kind === "toLowerCase") {
12822
- input.data = input.data.toLowerCase();
12823
- }
12824
- else if (check.kind === "toUpperCase") {
12825
- input.data = input.data.toUpperCase();
12826
- }
12827
- else if (check.kind === "startsWith") {
12828
- if (!input.data.startsWith(check.value)) {
12829
- ctx = this._getOrReturnCtx(input, ctx);
12830
- addIssueToContext(ctx, {
12831
- code: ZodIssueCode.invalid_string,
12832
- validation: { startsWith: check.value },
12833
- message: check.message,
12834
- });
12835
- status.dirty();
12836
- }
12837
- }
12838
- else if (check.kind === "endsWith") {
12839
- if (!input.data.endsWith(check.value)) {
12840
- ctx = this._getOrReturnCtx(input, ctx);
12841
- addIssueToContext(ctx, {
12842
- code: ZodIssueCode.invalid_string,
12843
- validation: { endsWith: check.value },
12844
- message: check.message,
12845
- });
12846
- status.dirty();
12847
- }
12848
- }
12849
- else if (check.kind === "datetime") {
12850
- const regex = datetimeRegex(check);
12851
- if (!regex.test(input.data)) {
12852
- ctx = this._getOrReturnCtx(input, ctx);
12853
- addIssueToContext(ctx, {
12854
- code: ZodIssueCode.invalid_string,
12855
- validation: "datetime",
12856
- message: check.message,
12857
- });
12858
- status.dirty();
12859
- }
12860
- }
12861
- else if (check.kind === "date") {
12862
- const regex = dateRegex;
12863
- if (!regex.test(input.data)) {
12864
- ctx = this._getOrReturnCtx(input, ctx);
12865
- addIssueToContext(ctx, {
12866
- code: ZodIssueCode.invalid_string,
12867
- validation: "date",
12868
- message: check.message,
12869
- });
12870
- status.dirty();
12871
- }
12872
- }
12873
- else if (check.kind === "time") {
12874
- const regex = timeRegex(check);
12875
- if (!regex.test(input.data)) {
12876
- ctx = this._getOrReturnCtx(input, ctx);
12877
- addIssueToContext(ctx, {
12878
- code: ZodIssueCode.invalid_string,
12879
- validation: "time",
12880
- message: check.message,
12881
- });
12882
- status.dirty();
12883
- }
12884
- }
12885
- else if (check.kind === "duration") {
12886
- if (!durationRegex.test(input.data)) {
12887
- ctx = this._getOrReturnCtx(input, ctx);
12888
- addIssueToContext(ctx, {
12889
- validation: "duration",
12890
- code: ZodIssueCode.invalid_string,
12891
- message: check.message,
12892
- });
12893
- status.dirty();
12894
- }
12895
- }
12896
- else if (check.kind === "ip") {
12897
- if (!isValidIP(input.data, check.version)) {
12898
- ctx = this._getOrReturnCtx(input, ctx);
12899
- addIssueToContext(ctx, {
12900
- validation: "ip",
12901
- code: ZodIssueCode.invalid_string,
12902
- message: check.message,
12903
- });
12904
- status.dirty();
12905
- }
12906
- }
12907
- else if (check.kind === "jwt") {
12908
- if (!isValidJWT(input.data, check.alg)) {
12909
- ctx = this._getOrReturnCtx(input, ctx);
12910
- addIssueToContext(ctx, {
12911
- validation: "jwt",
12912
- code: ZodIssueCode.invalid_string,
12913
- message: check.message,
12914
- });
12915
- status.dirty();
12916
- }
12917
- }
12918
- else if (check.kind === "cidr") {
12919
- if (!isValidCidr(input.data, check.version)) {
12920
- ctx = this._getOrReturnCtx(input, ctx);
12921
- addIssueToContext(ctx, {
12922
- validation: "cidr",
12923
- code: ZodIssueCode.invalid_string,
12924
- message: check.message,
12925
- });
12926
- status.dirty();
12927
- }
12928
- }
12929
- else if (check.kind === "base64") {
12930
- if (!base64Regex.test(input.data)) {
12931
- ctx = this._getOrReturnCtx(input, ctx);
12932
- addIssueToContext(ctx, {
12933
- validation: "base64",
12934
- code: ZodIssueCode.invalid_string,
12935
- message: check.message,
12936
- });
12937
- status.dirty();
12938
- }
12939
- }
12940
- else if (check.kind === "base64url") {
12941
- if (!base64urlRegex.test(input.data)) {
12942
- ctx = this._getOrReturnCtx(input, ctx);
12943
- addIssueToContext(ctx, {
12944
- validation: "base64url",
12945
- code: ZodIssueCode.invalid_string,
12946
- message: check.message,
12947
- });
12948
- status.dirty();
12949
- }
12950
- }
12951
- else {
12952
- util$1.assertNever(check);
12953
- }
12954
- }
12955
- return { status: status.value, value: input.data };
12956
- }
12957
- _regex(regex, validation, message) {
12958
- return this.refinement((data) => regex.test(data), {
12959
- validation,
12960
- code: ZodIssueCode.invalid_string,
12961
- ...errorUtil.errToObj(message),
12962
- });
12963
- }
12964
- _addCheck(check) {
12965
- return new ZodString({
12966
- ...this._def,
12967
- checks: [...this._def.checks, check],
12968
- });
12969
- }
12970
- email(message) {
12971
- return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
12972
- }
12973
- url(message) {
12974
- return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
12975
- }
12976
- emoji(message) {
12977
- return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
12978
- }
12979
- uuid(message) {
12980
- return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
12981
- }
12982
- nanoid(message) {
12983
- return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
12984
- }
12985
- cuid(message) {
12986
- return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
12987
- }
12988
- cuid2(message) {
12989
- return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
12990
- }
12991
- ulid(message) {
12992
- return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
12993
- }
12994
- base64(message) {
12995
- return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
12996
- }
12997
- base64url(message) {
12998
- // base64url encoding is a modification of base64 that can safely be used in URLs and filenames
12999
- return this._addCheck({
13000
- kind: "base64url",
13001
- ...errorUtil.errToObj(message),
13002
- });
13003
- }
13004
- jwt(options) {
13005
- return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
13006
- }
13007
- ip(options) {
13008
- return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
13009
- }
13010
- cidr(options) {
13011
- return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
13012
- }
13013
- datetime(options) {
13014
- var _a, _b;
13015
- if (typeof options === "string") {
13016
- return this._addCheck({
13017
- kind: "datetime",
13018
- precision: null,
13019
- offset: false,
13020
- local: false,
13021
- message: options,
13022
- });
13023
- }
13024
- return this._addCheck({
13025
- kind: "datetime",
13026
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
13027
- offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
13028
- local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
13029
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
13030
- });
13031
- }
13032
- date(message) {
13033
- return this._addCheck({ kind: "date", message });
13034
- }
13035
- time(options) {
13036
- if (typeof options === "string") {
13037
- return this._addCheck({
13038
- kind: "time",
13039
- precision: null,
13040
- message: options,
13041
- });
13042
- }
13043
- return this._addCheck({
13044
- kind: "time",
13045
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
13046
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
13047
- });
13048
- }
13049
- duration(message) {
13050
- return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
13051
- }
13052
- regex(regex, message) {
13053
- return this._addCheck({
13054
- kind: "regex",
13055
- regex: regex,
13056
- ...errorUtil.errToObj(message),
13057
- });
13058
- }
13059
- includes(value, options) {
13060
- return this._addCheck({
13061
- kind: "includes",
13062
- value: value,
13063
- position: options === null || options === void 0 ? void 0 : options.position,
13064
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
13065
- });
13066
- }
13067
- startsWith(value, message) {
13068
- return this._addCheck({
13069
- kind: "startsWith",
13070
- value: value,
13071
- ...errorUtil.errToObj(message),
13072
- });
13073
- }
13074
- endsWith(value, message) {
13075
- return this._addCheck({
13076
- kind: "endsWith",
13077
- value: value,
13078
- ...errorUtil.errToObj(message),
13079
- });
13080
- }
13081
- min(minLength, message) {
13082
- return this._addCheck({
13083
- kind: "min",
13084
- value: minLength,
13085
- ...errorUtil.errToObj(message),
13086
- });
13087
- }
13088
- max(maxLength, message) {
13089
- return this._addCheck({
13090
- kind: "max",
13091
- value: maxLength,
13092
- ...errorUtil.errToObj(message),
13093
- });
13094
- }
13095
- length(len, message) {
13096
- return this._addCheck({
13097
- kind: "length",
13098
- value: len,
13099
- ...errorUtil.errToObj(message),
13100
- });
13101
- }
13102
- /**
13103
- * Equivalent to `.min(1)`
13104
- */
13105
- nonempty(message) {
13106
- return this.min(1, errorUtil.errToObj(message));
13107
- }
13108
- trim() {
13109
- return new ZodString({
13110
- ...this._def,
13111
- checks: [...this._def.checks, { kind: "trim" }],
13112
- });
13113
- }
13114
- toLowerCase() {
13115
- return new ZodString({
13116
- ...this._def,
13117
- checks: [...this._def.checks, { kind: "toLowerCase" }],
13118
- });
13119
- }
13120
- toUpperCase() {
13121
- return new ZodString({
13122
- ...this._def,
13123
- checks: [...this._def.checks, { kind: "toUpperCase" }],
13124
- });
13125
- }
13126
- get isDatetime() {
13127
- return !!this._def.checks.find((ch) => ch.kind === "datetime");
13128
- }
13129
- get isDate() {
13130
- return !!this._def.checks.find((ch) => ch.kind === "date");
13131
- }
13132
- get isTime() {
13133
- return !!this._def.checks.find((ch) => ch.kind === "time");
13134
- }
13135
- get isDuration() {
13136
- return !!this._def.checks.find((ch) => ch.kind === "duration");
13137
- }
13138
- get isEmail() {
13139
- return !!this._def.checks.find((ch) => ch.kind === "email");
13140
- }
13141
- get isURL() {
13142
- return !!this._def.checks.find((ch) => ch.kind === "url");
13143
- }
13144
- get isEmoji() {
13145
- return !!this._def.checks.find((ch) => ch.kind === "emoji");
13146
- }
13147
- get isUUID() {
13148
- return !!this._def.checks.find((ch) => ch.kind === "uuid");
13149
- }
13150
- get isNANOID() {
13151
- return !!this._def.checks.find((ch) => ch.kind === "nanoid");
13152
- }
13153
- get isCUID() {
13154
- return !!this._def.checks.find((ch) => ch.kind === "cuid");
13155
- }
13156
- get isCUID2() {
13157
- return !!this._def.checks.find((ch) => ch.kind === "cuid2");
13158
- }
13159
- get isULID() {
13160
- return !!this._def.checks.find((ch) => ch.kind === "ulid");
13161
- }
13162
- get isIP() {
13163
- return !!this._def.checks.find((ch) => ch.kind === "ip");
13164
- }
13165
- get isCIDR() {
13166
- return !!this._def.checks.find((ch) => ch.kind === "cidr");
13167
- }
13168
- get isBase64() {
13169
- return !!this._def.checks.find((ch) => ch.kind === "base64");
13170
- }
13171
- get isBase64url() {
13172
- // base64url encoding is a modification of base64 that can safely be used in URLs and filenames
13173
- return !!this._def.checks.find((ch) => ch.kind === "base64url");
13174
- }
13175
- get minLength() {
13176
- let min = null;
13177
- for (const ch of this._def.checks) {
13178
- if (ch.kind === "min") {
13179
- if (min === null || ch.value > min)
13180
- min = ch.value;
13181
- }
13182
- }
13183
- return min;
13184
- }
13185
- get maxLength() {
13186
- let max = null;
13187
- for (const ch of this._def.checks) {
13188
- if (ch.kind === "max") {
13189
- if (max === null || ch.value < max)
13190
- max = ch.value;
13191
- }
13192
- }
13193
- return max;
13194
- }
13195
- }
13196
- ZodString.create = (params) => {
13197
- var _a;
13198
- return new ZodString({
13199
- checks: [],
13200
- typeName: ZodFirstPartyTypeKind.ZodString,
13201
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
13202
- ...processCreateParams(params),
13203
- });
13204
- };
13205
- // https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
13206
- function floatSafeRemainder(val, step) {
13207
- const valDecCount = (val.toString().split(".")[1] || "").length;
13208
- const stepDecCount = (step.toString().split(".")[1] || "").length;
13209
- const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
13210
- const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
13211
- const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
13212
- return (valInt % stepInt) / Math.pow(10, decCount);
13213
- }
13214
- class ZodNumber extends ZodType {
13215
- constructor() {
13216
- super(...arguments);
13217
- this.min = this.gte;
13218
- this.max = this.lte;
13219
- this.step = this.multipleOf;
13220
- }
13221
- _parse(input) {
13222
- if (this._def.coerce) {
13223
- input.data = Number(input.data);
13224
- }
13225
- const parsedType = this._getType(input);
13226
- if (parsedType !== ZodParsedType.number) {
13227
- const ctx = this._getOrReturnCtx(input);
13228
- addIssueToContext(ctx, {
13229
- code: ZodIssueCode.invalid_type,
13230
- expected: ZodParsedType.number,
13231
- received: ctx.parsedType,
13232
- });
13233
- return INVALID;
13234
- }
13235
- let ctx = undefined;
13236
- const status = new ParseStatus();
13237
- for (const check of this._def.checks) {
13238
- if (check.kind === "int") {
13239
- if (!util$1.isInteger(input.data)) {
13240
- ctx = this._getOrReturnCtx(input, ctx);
13241
- addIssueToContext(ctx, {
13242
- code: ZodIssueCode.invalid_type,
13243
- expected: "integer",
13244
- received: "float",
13245
- message: check.message,
13246
- });
13247
- status.dirty();
13248
- }
13249
- }
13250
- else if (check.kind === "min") {
13251
- const tooSmall = check.inclusive
13252
- ? input.data < check.value
13253
- : input.data <= check.value;
13254
- if (tooSmall) {
13255
- ctx = this._getOrReturnCtx(input, ctx);
13256
- addIssueToContext(ctx, {
13257
- code: ZodIssueCode.too_small,
13258
- minimum: check.value,
13259
- type: "number",
13260
- inclusive: check.inclusive,
13261
- exact: false,
13262
- message: check.message,
13263
- });
13264
- status.dirty();
13265
- }
13266
- }
13267
- else if (check.kind === "max") {
13268
- const tooBig = check.inclusive
13269
- ? input.data > check.value
13270
- : input.data >= check.value;
13271
- if (tooBig) {
13272
- ctx = this._getOrReturnCtx(input, ctx);
13273
- addIssueToContext(ctx, {
13274
- code: ZodIssueCode.too_big,
13275
- maximum: check.value,
13276
- type: "number",
13277
- inclusive: check.inclusive,
13278
- exact: false,
13279
- message: check.message,
13280
- });
13281
- status.dirty();
13282
- }
13283
- }
13284
- else if (check.kind === "multipleOf") {
13285
- if (floatSafeRemainder(input.data, check.value) !== 0) {
13286
- ctx = this._getOrReturnCtx(input, ctx);
13287
- addIssueToContext(ctx, {
13288
- code: ZodIssueCode.not_multiple_of,
13289
- multipleOf: check.value,
13290
- message: check.message,
13291
- });
13292
- status.dirty();
13293
- }
13294
- }
13295
- else if (check.kind === "finite") {
13296
- if (!Number.isFinite(input.data)) {
13297
- ctx = this._getOrReturnCtx(input, ctx);
13298
- addIssueToContext(ctx, {
13299
- code: ZodIssueCode.not_finite,
13300
- message: check.message,
13301
- });
13302
- status.dirty();
13303
- }
13304
- }
13305
- else {
13306
- util$1.assertNever(check);
13307
- }
13308
- }
13309
- return { status: status.value, value: input.data };
13310
- }
13311
- gte(value, message) {
13312
- return this.setLimit("min", value, true, errorUtil.toString(message));
13313
- }
13314
- gt(value, message) {
13315
- return this.setLimit("min", value, false, errorUtil.toString(message));
13316
- }
13317
- lte(value, message) {
13318
- return this.setLimit("max", value, true, errorUtil.toString(message));
13319
- }
13320
- lt(value, message) {
13321
- return this.setLimit("max", value, false, errorUtil.toString(message));
13322
- }
13323
- setLimit(kind, value, inclusive, message) {
13324
- return new ZodNumber({
13325
- ...this._def,
13326
- checks: [
13327
- ...this._def.checks,
13328
- {
13329
- kind,
13330
- value,
13331
- inclusive,
13332
- message: errorUtil.toString(message),
13333
- },
13334
- ],
13335
- });
13336
- }
13337
- _addCheck(check) {
13338
- return new ZodNumber({
13339
- ...this._def,
13340
- checks: [...this._def.checks, check],
13341
- });
13342
- }
13343
- int(message) {
13344
- return this._addCheck({
13345
- kind: "int",
13346
- message: errorUtil.toString(message),
13347
- });
13348
- }
13349
- positive(message) {
13350
- return this._addCheck({
13351
- kind: "min",
13352
- value: 0,
13353
- inclusive: false,
13354
- message: errorUtil.toString(message),
13355
- });
13356
- }
13357
- negative(message) {
13358
- return this._addCheck({
13359
- kind: "max",
13360
- value: 0,
13361
- inclusive: false,
13362
- message: errorUtil.toString(message),
13363
- });
13364
- }
13365
- nonpositive(message) {
13366
- return this._addCheck({
13367
- kind: "max",
13368
- value: 0,
13369
- inclusive: true,
13370
- message: errorUtil.toString(message),
13371
- });
13372
- }
13373
- nonnegative(message) {
13374
- return this._addCheck({
13375
- kind: "min",
13376
- value: 0,
13377
- inclusive: true,
13378
- message: errorUtil.toString(message),
13379
- });
13380
- }
13381
- multipleOf(value, message) {
13382
- return this._addCheck({
13383
- kind: "multipleOf",
13384
- value: value,
13385
- message: errorUtil.toString(message),
13386
- });
13387
- }
13388
- finite(message) {
13389
- return this._addCheck({
13390
- kind: "finite",
13391
- message: errorUtil.toString(message),
13392
- });
13393
- }
13394
- safe(message) {
13395
- return this._addCheck({
13396
- kind: "min",
13397
- inclusive: true,
13398
- value: Number.MIN_SAFE_INTEGER,
13399
- message: errorUtil.toString(message),
13400
- })._addCheck({
13401
- kind: "max",
13402
- inclusive: true,
13403
- value: Number.MAX_SAFE_INTEGER,
13404
- message: errorUtil.toString(message),
13405
- });
13406
- }
13407
- get minValue() {
13408
- let min = null;
13409
- for (const ch of this._def.checks) {
13410
- if (ch.kind === "min") {
13411
- if (min === null || ch.value > min)
13412
- min = ch.value;
13413
- }
13414
- }
13415
- return min;
13416
- }
13417
- get maxValue() {
13418
- let max = null;
13419
- for (const ch of this._def.checks) {
13420
- if (ch.kind === "max") {
13421
- if (max === null || ch.value < max)
13422
- max = ch.value;
13423
- }
13424
- }
13425
- return max;
13426
- }
13427
- get isInt() {
13428
- return !!this._def.checks.find((ch) => ch.kind === "int" ||
13429
- (ch.kind === "multipleOf" && util$1.isInteger(ch.value)));
13430
- }
13431
- get isFinite() {
13432
- let max = null, min = null;
13433
- for (const ch of this._def.checks) {
13434
- if (ch.kind === "finite" ||
13435
- ch.kind === "int" ||
13436
- ch.kind === "multipleOf") {
13437
- return true;
13438
- }
13439
- else if (ch.kind === "min") {
13440
- if (min === null || ch.value > min)
13441
- min = ch.value;
13442
- }
13443
- else if (ch.kind === "max") {
13444
- if (max === null || ch.value < max)
13445
- max = ch.value;
13446
- }
13447
- }
13448
- return Number.isFinite(min) && Number.isFinite(max);
13449
- }
13450
- }
13451
- ZodNumber.create = (params) => {
13452
- return new ZodNumber({
13453
- checks: [],
13454
- typeName: ZodFirstPartyTypeKind.ZodNumber,
13455
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
13456
- ...processCreateParams(params),
13457
- });
13458
- };
13459
- class ZodBigInt extends ZodType {
13460
- constructor() {
13461
- super(...arguments);
13462
- this.min = this.gte;
13463
- this.max = this.lte;
13464
- }
13465
- _parse(input) {
13466
- if (this._def.coerce) {
13467
- try {
13468
- input.data = BigInt(input.data);
13469
- }
13470
- catch (_a) {
13471
- return this._getInvalidInput(input);
13472
- }
13473
- }
13474
- const parsedType = this._getType(input);
13475
- if (parsedType !== ZodParsedType.bigint) {
13476
- return this._getInvalidInput(input);
13477
- }
13478
- let ctx = undefined;
13479
- const status = new ParseStatus();
13480
- for (const check of this._def.checks) {
13481
- if (check.kind === "min") {
13482
- const tooSmall = check.inclusive
13483
- ? input.data < check.value
13484
- : input.data <= check.value;
13485
- if (tooSmall) {
13486
- ctx = this._getOrReturnCtx(input, ctx);
13487
- addIssueToContext(ctx, {
13488
- code: ZodIssueCode.too_small,
13489
- type: "bigint",
13490
- minimum: check.value,
13491
- inclusive: check.inclusive,
13492
- message: check.message,
13493
- });
13494
- status.dirty();
13495
- }
13496
- }
13497
- else if (check.kind === "max") {
13498
- const tooBig = check.inclusive
13499
- ? input.data > check.value
13500
- : input.data >= check.value;
13501
- if (tooBig) {
13502
- ctx = this._getOrReturnCtx(input, ctx);
13503
- addIssueToContext(ctx, {
13504
- code: ZodIssueCode.too_big,
13505
- type: "bigint",
13506
- maximum: check.value,
13507
- inclusive: check.inclusive,
13508
- message: check.message,
13509
- });
13510
- status.dirty();
13511
- }
13512
- }
13513
- else if (check.kind === "multipleOf") {
13514
- if (input.data % check.value !== BigInt(0)) {
13515
- ctx = this._getOrReturnCtx(input, ctx);
13516
- addIssueToContext(ctx, {
13517
- code: ZodIssueCode.not_multiple_of,
13518
- multipleOf: check.value,
13519
- message: check.message,
13520
- });
13521
- status.dirty();
13522
- }
13523
- }
13524
- else {
13525
- util$1.assertNever(check);
13526
- }
13527
- }
13528
- return { status: status.value, value: input.data };
13529
- }
13530
- _getInvalidInput(input) {
13531
- const ctx = this._getOrReturnCtx(input);
13532
- addIssueToContext(ctx, {
13533
- code: ZodIssueCode.invalid_type,
13534
- expected: ZodParsedType.bigint,
13535
- received: ctx.parsedType,
13536
- });
13537
- return INVALID;
13538
- }
13539
- gte(value, message) {
13540
- return this.setLimit("min", value, true, errorUtil.toString(message));
13541
- }
13542
- gt(value, message) {
13543
- return this.setLimit("min", value, false, errorUtil.toString(message));
13544
- }
13545
- lte(value, message) {
13546
- return this.setLimit("max", value, true, errorUtil.toString(message));
13547
- }
13548
- lt(value, message) {
13549
- return this.setLimit("max", value, false, errorUtil.toString(message));
13550
- }
13551
- setLimit(kind, value, inclusive, message) {
13552
- return new ZodBigInt({
13553
- ...this._def,
13554
- checks: [
13555
- ...this._def.checks,
13556
- {
13557
- kind,
13558
- value,
13559
- inclusive,
13560
- message: errorUtil.toString(message),
13561
- },
13562
- ],
13563
- });
13564
- }
13565
- _addCheck(check) {
13566
- return new ZodBigInt({
13567
- ...this._def,
13568
- checks: [...this._def.checks, check],
13569
- });
13570
- }
13571
- positive(message) {
13572
- return this._addCheck({
13573
- kind: "min",
13574
- value: BigInt(0),
13575
- inclusive: false,
13576
- message: errorUtil.toString(message),
13577
- });
13578
- }
13579
- negative(message) {
13580
- return this._addCheck({
13581
- kind: "max",
13582
- value: BigInt(0),
13583
- inclusive: false,
13584
- message: errorUtil.toString(message),
13585
- });
13586
- }
13587
- nonpositive(message) {
13588
- return this._addCheck({
13589
- kind: "max",
13590
- value: BigInt(0),
13591
- inclusive: true,
13592
- message: errorUtil.toString(message),
13593
- });
13594
- }
13595
- nonnegative(message) {
13596
- return this._addCheck({
13597
- kind: "min",
13598
- value: BigInt(0),
13599
- inclusive: true,
13600
- message: errorUtil.toString(message),
13601
- });
13602
- }
13603
- multipleOf(value, message) {
13604
- return this._addCheck({
13605
- kind: "multipleOf",
13606
- value,
13607
- message: errorUtil.toString(message),
13608
- });
13609
- }
13610
- get minValue() {
13611
- let min = null;
13612
- for (const ch of this._def.checks) {
13613
- if (ch.kind === "min") {
13614
- if (min === null || ch.value > min)
13615
- min = ch.value;
13616
- }
13617
- }
13618
- return min;
13619
- }
13620
- get maxValue() {
13621
- let max = null;
13622
- for (const ch of this._def.checks) {
13623
- if (ch.kind === "max") {
13624
- if (max === null || ch.value < max)
13625
- max = ch.value;
13626
- }
13627
- }
13628
- return max;
13629
- }
13630
- }
13631
- ZodBigInt.create = (params) => {
13632
- var _a;
13633
- return new ZodBigInt({
13634
- checks: [],
13635
- typeName: ZodFirstPartyTypeKind.ZodBigInt,
13636
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
13637
- ...processCreateParams(params),
13638
- });
13639
- };
13640
- class ZodBoolean extends ZodType {
13641
- _parse(input) {
13642
- if (this._def.coerce) {
13643
- input.data = Boolean(input.data);
13644
- }
13645
- const parsedType = this._getType(input);
13646
- if (parsedType !== ZodParsedType.boolean) {
13647
- const ctx = this._getOrReturnCtx(input);
13648
- addIssueToContext(ctx, {
13649
- code: ZodIssueCode.invalid_type,
13650
- expected: ZodParsedType.boolean,
13651
- received: ctx.parsedType,
13652
- });
13653
- return INVALID;
13654
- }
13655
- return OK(input.data);
13656
- }
13657
- }
13658
- ZodBoolean.create = (params) => {
13659
- return new ZodBoolean({
13660
- typeName: ZodFirstPartyTypeKind.ZodBoolean,
13661
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
13662
- ...processCreateParams(params),
13663
- });
13664
- };
13665
- class ZodDate extends ZodType {
13666
- _parse(input) {
13667
- if (this._def.coerce) {
13668
- input.data = new Date(input.data);
13669
- }
13670
- const parsedType = this._getType(input);
13671
- if (parsedType !== ZodParsedType.date) {
13672
- const ctx = this._getOrReturnCtx(input);
13673
- addIssueToContext(ctx, {
13674
- code: ZodIssueCode.invalid_type,
13675
- expected: ZodParsedType.date,
13676
- received: ctx.parsedType,
13677
- });
13678
- return INVALID;
13679
- }
13680
- if (isNaN(input.data.getTime())) {
13681
- const ctx = this._getOrReturnCtx(input);
13682
- addIssueToContext(ctx, {
13683
- code: ZodIssueCode.invalid_date,
13684
- });
13685
- return INVALID;
13686
- }
13687
- const status = new ParseStatus();
13688
- let ctx = undefined;
13689
- for (const check of this._def.checks) {
13690
- if (check.kind === "min") {
13691
- if (input.data.getTime() < check.value) {
13692
- ctx = this._getOrReturnCtx(input, ctx);
13693
- addIssueToContext(ctx, {
13694
- code: ZodIssueCode.too_small,
13695
- message: check.message,
13696
- inclusive: true,
13697
- exact: false,
13698
- minimum: check.value,
13699
- type: "date",
13700
- });
13701
- status.dirty();
13702
- }
13703
- }
13704
- else if (check.kind === "max") {
13705
- if (input.data.getTime() > check.value) {
13706
- ctx = this._getOrReturnCtx(input, ctx);
13707
- addIssueToContext(ctx, {
13708
- code: ZodIssueCode.too_big,
13709
- message: check.message,
13710
- inclusive: true,
13711
- exact: false,
13712
- maximum: check.value,
13713
- type: "date",
13714
- });
13715
- status.dirty();
13716
- }
13717
- }
13718
- else {
13719
- util$1.assertNever(check);
13720
- }
13721
- }
13722
- return {
13723
- status: status.value,
13724
- value: new Date(input.data.getTime()),
13725
- };
13726
- }
13727
- _addCheck(check) {
13728
- return new ZodDate({
13729
- ...this._def,
13730
- checks: [...this._def.checks, check],
13731
- });
13732
- }
13733
- min(minDate, message) {
13734
- return this._addCheck({
13735
- kind: "min",
13736
- value: minDate.getTime(),
13737
- message: errorUtil.toString(message),
13738
- });
13739
- }
13740
- max(maxDate, message) {
13741
- return this._addCheck({
13742
- kind: "max",
13743
- value: maxDate.getTime(),
13744
- message: errorUtil.toString(message),
13745
- });
13746
- }
13747
- get minDate() {
13748
- let min = null;
13749
- for (const ch of this._def.checks) {
13750
- if (ch.kind === "min") {
13751
- if (min === null || ch.value > min)
13752
- min = ch.value;
13753
- }
13754
- }
13755
- return min != null ? new Date(min) : null;
13756
- }
13757
- get maxDate() {
13758
- let max = null;
13759
- for (const ch of this._def.checks) {
13760
- if (ch.kind === "max") {
13761
- if (max === null || ch.value < max)
13762
- max = ch.value;
13763
- }
13764
- }
13765
- return max != null ? new Date(max) : null;
13766
- }
13767
- }
13768
- ZodDate.create = (params) => {
13769
- return new ZodDate({
13770
- checks: [],
13771
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
13772
- typeName: ZodFirstPartyTypeKind.ZodDate,
13773
- ...processCreateParams(params),
13774
- });
13775
- };
13776
- class ZodSymbol extends ZodType {
13777
- _parse(input) {
13778
- const parsedType = this._getType(input);
13779
- if (parsedType !== ZodParsedType.symbol) {
13780
- const ctx = this._getOrReturnCtx(input);
13781
- addIssueToContext(ctx, {
13782
- code: ZodIssueCode.invalid_type,
13783
- expected: ZodParsedType.symbol,
13784
- received: ctx.parsedType,
13785
- });
13786
- return INVALID;
13787
- }
13788
- return OK(input.data);
13789
- }
13790
- }
13791
- ZodSymbol.create = (params) => {
13792
- return new ZodSymbol({
13793
- typeName: ZodFirstPartyTypeKind.ZodSymbol,
13794
- ...processCreateParams(params),
13795
- });
13796
- };
13797
- class ZodUndefined extends ZodType {
13798
- _parse(input) {
13799
- const parsedType = this._getType(input);
13800
- if (parsedType !== ZodParsedType.undefined) {
13801
- const ctx = this._getOrReturnCtx(input);
13802
- addIssueToContext(ctx, {
13803
- code: ZodIssueCode.invalid_type,
13804
- expected: ZodParsedType.undefined,
13805
- received: ctx.parsedType,
13806
- });
13807
- return INVALID;
13808
- }
13809
- return OK(input.data);
13810
- }
13811
- }
13812
- ZodUndefined.create = (params) => {
13813
- return new ZodUndefined({
13814
- typeName: ZodFirstPartyTypeKind.ZodUndefined,
13815
- ...processCreateParams(params),
13816
- });
13817
- };
13818
- class ZodNull extends ZodType {
13819
- _parse(input) {
13820
- const parsedType = this._getType(input);
13821
- if (parsedType !== ZodParsedType.null) {
13822
- const ctx = this._getOrReturnCtx(input);
13823
- addIssueToContext(ctx, {
13824
- code: ZodIssueCode.invalid_type,
13825
- expected: ZodParsedType.null,
13826
- received: ctx.parsedType,
13827
- });
13828
- return INVALID;
13829
- }
13830
- return OK(input.data);
13831
- }
13832
- }
13833
- ZodNull.create = (params) => {
13834
- return new ZodNull({
13835
- typeName: ZodFirstPartyTypeKind.ZodNull,
13836
- ...processCreateParams(params),
13837
- });
13838
- };
13839
- class ZodAny extends ZodType {
13840
- constructor() {
13841
- super(...arguments);
13842
- // to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
13843
- this._any = true;
13844
- }
13845
- _parse(input) {
13846
- return OK(input.data);
13847
- }
13848
- }
13849
- ZodAny.create = (params) => {
13850
- return new ZodAny({
13851
- typeName: ZodFirstPartyTypeKind.ZodAny,
13852
- ...processCreateParams(params),
13853
- });
13854
- };
13855
- class ZodUnknown extends ZodType {
13856
- constructor() {
13857
- super(...arguments);
13858
- // required
13859
- this._unknown = true;
13860
- }
13861
- _parse(input) {
13862
- return OK(input.data);
13863
- }
13864
- }
13865
- ZodUnknown.create = (params) => {
13866
- return new ZodUnknown({
13867
- typeName: ZodFirstPartyTypeKind.ZodUnknown,
13868
- ...processCreateParams(params),
13869
- });
13870
- };
13871
- class ZodNever extends ZodType {
13872
- _parse(input) {
13873
- const ctx = this._getOrReturnCtx(input);
13874
- addIssueToContext(ctx, {
13875
- code: ZodIssueCode.invalid_type,
13876
- expected: ZodParsedType.never,
13877
- received: ctx.parsedType,
13878
- });
13879
- return INVALID;
13880
- }
13881
- }
13882
- ZodNever.create = (params) => {
13883
- return new ZodNever({
13884
- typeName: ZodFirstPartyTypeKind.ZodNever,
13885
- ...processCreateParams(params),
13886
- });
13887
- };
13888
- class ZodVoid extends ZodType {
13889
- _parse(input) {
13890
- const parsedType = this._getType(input);
13891
- if (parsedType !== ZodParsedType.undefined) {
13892
- const ctx = this._getOrReturnCtx(input);
13893
- addIssueToContext(ctx, {
13894
- code: ZodIssueCode.invalid_type,
13895
- expected: ZodParsedType.void,
13896
- received: ctx.parsedType,
13897
- });
13898
- return INVALID;
13899
- }
13900
- return OK(input.data);
13901
- }
13902
- }
13903
- ZodVoid.create = (params) => {
13904
- return new ZodVoid({
13905
- typeName: ZodFirstPartyTypeKind.ZodVoid,
13906
- ...processCreateParams(params),
13907
- });
13908
- };
13909
- class ZodArray extends ZodType {
13910
- _parse(input) {
13911
- const { ctx, status } = this._processInputParams(input);
13912
- const def = this._def;
13913
- if (ctx.parsedType !== ZodParsedType.array) {
13914
- addIssueToContext(ctx, {
13915
- code: ZodIssueCode.invalid_type,
13916
- expected: ZodParsedType.array,
13917
- received: ctx.parsedType,
13918
- });
13919
- return INVALID;
13920
- }
13921
- if (def.exactLength !== null) {
13922
- const tooBig = ctx.data.length > def.exactLength.value;
13923
- const tooSmall = ctx.data.length < def.exactLength.value;
13924
- if (tooBig || tooSmall) {
13925
- addIssueToContext(ctx, {
13926
- code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
13927
- minimum: (tooSmall ? def.exactLength.value : undefined),
13928
- maximum: (tooBig ? def.exactLength.value : undefined),
13929
- type: "array",
13930
- inclusive: true,
13931
- exact: true,
13932
- message: def.exactLength.message,
13933
- });
13934
- status.dirty();
13935
- }
13936
- }
13937
- if (def.minLength !== null) {
13938
- if (ctx.data.length < def.minLength.value) {
13939
- addIssueToContext(ctx, {
13940
- code: ZodIssueCode.too_small,
13941
- minimum: def.minLength.value,
13942
- type: "array",
13943
- inclusive: true,
13944
- exact: false,
13945
- message: def.minLength.message,
13946
- });
13947
- status.dirty();
13948
- }
13949
- }
13950
- if (def.maxLength !== null) {
13951
- if (ctx.data.length > def.maxLength.value) {
13952
- addIssueToContext(ctx, {
13953
- code: ZodIssueCode.too_big,
13954
- maximum: def.maxLength.value,
13955
- type: "array",
13956
- inclusive: true,
13957
- exact: false,
13958
- message: def.maxLength.message,
13959
- });
13960
- status.dirty();
13961
- }
13962
- }
13963
- if (ctx.common.async) {
13964
- return Promise.all([...ctx.data].map((item, i) => {
13965
- return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
13966
- })).then((result) => {
13967
- return ParseStatus.mergeArray(status, result);
13968
- });
13969
- }
13970
- const result = [...ctx.data].map((item, i) => {
13971
- return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
13972
- });
13973
- return ParseStatus.mergeArray(status, result);
13974
- }
13975
- get element() {
13976
- return this._def.type;
13977
- }
13978
- min(minLength, message) {
13979
- return new ZodArray({
13980
- ...this._def,
13981
- minLength: { value: minLength, message: errorUtil.toString(message) },
13982
- });
13983
- }
13984
- max(maxLength, message) {
13985
- return new ZodArray({
13986
- ...this._def,
13987
- maxLength: { value: maxLength, message: errorUtil.toString(message) },
13988
- });
13989
- }
13990
- length(len, message) {
13991
- return new ZodArray({
13992
- ...this._def,
13993
- exactLength: { value: len, message: errorUtil.toString(message) },
13994
- });
13995
- }
13996
- nonempty(message) {
13997
- return this.min(1, message);
13998
- }
13999
- }
14000
- ZodArray.create = (schema, params) => {
14001
- return new ZodArray({
14002
- type: schema,
14003
- minLength: null,
14004
- maxLength: null,
14005
- exactLength: null,
14006
- typeName: ZodFirstPartyTypeKind.ZodArray,
14007
- ...processCreateParams(params),
14008
- });
14009
- };
14010
- function deepPartialify(schema) {
14011
- if (schema instanceof ZodObject) {
14012
- const newShape = {};
14013
- for (const key in schema.shape) {
14014
- const fieldSchema = schema.shape[key];
14015
- newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
14016
- }
14017
- return new ZodObject({
14018
- ...schema._def,
14019
- shape: () => newShape,
14020
- });
14021
- }
14022
- else if (schema instanceof ZodArray) {
14023
- return new ZodArray({
14024
- ...schema._def,
14025
- type: deepPartialify(schema.element),
14026
- });
14027
- }
14028
- else if (schema instanceof ZodOptional) {
14029
- return ZodOptional.create(deepPartialify(schema.unwrap()));
14030
- }
14031
- else if (schema instanceof ZodNullable) {
14032
- return ZodNullable.create(deepPartialify(schema.unwrap()));
14033
- }
14034
- else if (schema instanceof ZodTuple) {
14035
- return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
14036
- }
14037
- else {
14038
- return schema;
14039
- }
14040
- }
14041
- class ZodObject extends ZodType {
14042
- constructor() {
14043
- super(...arguments);
14044
- this._cached = null;
14045
- /**
14046
- * @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
14047
- * If you want to pass through unknown properties, use `.passthrough()` instead.
14048
- */
14049
- this.nonstrict = this.passthrough;
14050
- // extend<
14051
- // Augmentation extends ZodRawShape,
14052
- // NewOutput extends util.flatten<{
14053
- // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
14054
- // ? Augmentation[k]["_output"]
14055
- // : k extends keyof Output
14056
- // ? Output[k]
14057
- // : never;
14058
- // }>,
14059
- // NewInput extends util.flatten<{
14060
- // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
14061
- // ? Augmentation[k]["_input"]
14062
- // : k extends keyof Input
14063
- // ? Input[k]
14064
- // : never;
14065
- // }>
14066
- // >(
14067
- // augmentation: Augmentation
14068
- // ): ZodObject<
14069
- // extendShape<T, Augmentation>,
14070
- // UnknownKeys,
14071
- // Catchall,
14072
- // NewOutput,
14073
- // NewInput
14074
- // > {
14075
- // return new ZodObject({
14076
- // ...this._def,
14077
- // shape: () => ({
14078
- // ...this._def.shape(),
14079
- // ...augmentation,
14080
- // }),
14081
- // }) as any;
14082
- // }
14083
- /**
14084
- * @deprecated Use `.extend` instead
14085
- * */
14086
- this.augment = this.extend;
14087
- }
14088
- _getCached() {
14089
- if (this._cached !== null)
14090
- return this._cached;
14091
- const shape = this._def.shape();
14092
- const keys = util$1.objectKeys(shape);
14093
- return (this._cached = { shape, keys });
14094
- }
14095
- _parse(input) {
14096
- const parsedType = this._getType(input);
14097
- if (parsedType !== ZodParsedType.object) {
14098
- const ctx = this._getOrReturnCtx(input);
14099
- addIssueToContext(ctx, {
14100
- code: ZodIssueCode.invalid_type,
14101
- expected: ZodParsedType.object,
14102
- received: ctx.parsedType,
14103
- });
14104
- return INVALID;
14105
- }
14106
- const { status, ctx } = this._processInputParams(input);
14107
- const { shape, keys: shapeKeys } = this._getCached();
14108
- const extraKeys = [];
14109
- if (!(this._def.catchall instanceof ZodNever &&
14110
- this._def.unknownKeys === "strip")) {
14111
- for (const key in ctx.data) {
14112
- if (!shapeKeys.includes(key)) {
14113
- extraKeys.push(key);
14114
- }
14115
- }
14116
- }
14117
- const pairs = [];
14118
- for (const key of shapeKeys) {
14119
- const keyValidator = shape[key];
14120
- const value = ctx.data[key];
14121
- pairs.push({
14122
- key: { status: "valid", value: key },
14123
- value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
14124
- alwaysSet: key in ctx.data,
14125
- });
14126
- }
14127
- if (this._def.catchall instanceof ZodNever) {
14128
- const unknownKeys = this._def.unknownKeys;
14129
- if (unknownKeys === "passthrough") {
14130
- for (const key of extraKeys) {
14131
- pairs.push({
14132
- key: { status: "valid", value: key },
14133
- value: { status: "valid", value: ctx.data[key] },
14134
- });
14135
- }
14136
- }
14137
- else if (unknownKeys === "strict") {
14138
- if (extraKeys.length > 0) {
14139
- addIssueToContext(ctx, {
14140
- code: ZodIssueCode.unrecognized_keys,
14141
- keys: extraKeys,
14142
- });
14143
- status.dirty();
14144
- }
14145
- }
14146
- else if (unknownKeys === "strip") ;
14147
- else {
14148
- throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
14149
- }
14150
- }
14151
- else {
14152
- // run catchall validation
14153
- const catchall = this._def.catchall;
14154
- for (const key of extraKeys) {
14155
- const value = ctx.data[key];
14156
- pairs.push({
14157
- key: { status: "valid", value: key },
14158
- value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key) //, ctx.child(key), value, getParsedType(value)
14159
- ),
14160
- alwaysSet: key in ctx.data,
14161
- });
14162
- }
14163
- }
14164
- if (ctx.common.async) {
14165
- return Promise.resolve()
14166
- .then(async () => {
14167
- const syncPairs = [];
14168
- for (const pair of pairs) {
14169
- const key = await pair.key;
14170
- const value = await pair.value;
14171
- syncPairs.push({
14172
- key,
14173
- value,
14174
- alwaysSet: pair.alwaysSet,
14175
- });
14176
- }
14177
- return syncPairs;
14178
- })
14179
- .then((syncPairs) => {
14180
- return ParseStatus.mergeObjectSync(status, syncPairs);
14181
- });
14182
- }
14183
- else {
14184
- return ParseStatus.mergeObjectSync(status, pairs);
14185
- }
14186
- }
14187
- get shape() {
14188
- return this._def.shape();
14189
- }
14190
- strict(message) {
14191
- errorUtil.errToObj;
14192
- return new ZodObject({
14193
- ...this._def,
14194
- unknownKeys: "strict",
14195
- ...(message !== undefined
14196
- ? {
14197
- errorMap: (issue, ctx) => {
14198
- var _a, _b, _c, _d;
14199
- const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
14200
- if (issue.code === "unrecognized_keys")
14201
- return {
14202
- message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
14203
- };
14204
- return {
14205
- message: defaultError,
14206
- };
14207
- },
14208
- }
14209
- : {}),
14210
- });
14211
- }
14212
- strip() {
14213
- return new ZodObject({
14214
- ...this._def,
14215
- unknownKeys: "strip",
14216
- });
14217
- }
14218
- passthrough() {
14219
- return new ZodObject({
14220
- ...this._def,
14221
- unknownKeys: "passthrough",
14222
- });
14223
- }
14224
- // const AugmentFactory =
14225
- // <Def extends ZodObjectDef>(def: Def) =>
14226
- // <Augmentation extends ZodRawShape>(
14227
- // augmentation: Augmentation
14228
- // ): ZodObject<
14229
- // extendShape<ReturnType<Def["shape"]>, Augmentation>,
14230
- // Def["unknownKeys"],
14231
- // Def["catchall"]
14232
- // > => {
14233
- // return new ZodObject({
14234
- // ...def,
14235
- // shape: () => ({
14236
- // ...def.shape(),
14237
- // ...augmentation,
14238
- // }),
14239
- // }) as any;
14240
- // };
14241
- extend(augmentation) {
14242
- return new ZodObject({
14243
- ...this._def,
14244
- shape: () => ({
14245
- ...this._def.shape(),
14246
- ...augmentation,
14247
- }),
14248
- });
14249
- }
14250
- /**
14251
- * Prior to zod@1.0.12 there was a bug in the
14252
- * inferred type of merged objects. Please
14253
- * upgrade if you are experiencing issues.
14254
- */
14255
- merge(merging) {
14256
- const merged = new ZodObject({
14257
- unknownKeys: merging._def.unknownKeys,
14258
- catchall: merging._def.catchall,
14259
- shape: () => ({
14260
- ...this._def.shape(),
14261
- ...merging._def.shape(),
14262
- }),
14263
- typeName: ZodFirstPartyTypeKind.ZodObject,
14264
- });
14265
- return merged;
14266
- }
14267
- // merge<
14268
- // Incoming extends AnyZodObject,
14269
- // Augmentation extends Incoming["shape"],
14270
- // NewOutput extends {
14271
- // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
14272
- // ? Augmentation[k]["_output"]
14273
- // : k extends keyof Output
14274
- // ? Output[k]
14275
- // : never;
14276
- // },
14277
- // NewInput extends {
14278
- // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
14279
- // ? Augmentation[k]["_input"]
14280
- // : k extends keyof Input
14281
- // ? Input[k]
14282
- // : never;
14283
- // }
14284
- // >(
14285
- // merging: Incoming
14286
- // ): ZodObject<
14287
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
14288
- // Incoming["_def"]["unknownKeys"],
14289
- // Incoming["_def"]["catchall"],
14290
- // NewOutput,
14291
- // NewInput
14292
- // > {
14293
- // const merged: any = new ZodObject({
14294
- // unknownKeys: merging._def.unknownKeys,
14295
- // catchall: merging._def.catchall,
14296
- // shape: () =>
14297
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
14298
- // typeName: ZodFirstPartyTypeKind.ZodObject,
14299
- // }) as any;
14300
- // return merged;
14301
- // }
14302
- setKey(key, schema) {
14303
- return this.augment({ [key]: schema });
14304
- }
14305
- // merge<Incoming extends AnyZodObject>(
14306
- // merging: Incoming
14307
- // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
14308
- // ZodObject<
14309
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
14310
- // Incoming["_def"]["unknownKeys"],
14311
- // Incoming["_def"]["catchall"]
14312
- // > {
14313
- // // const mergedShape = objectUtil.mergeShapes(
14314
- // // this._def.shape(),
14315
- // // merging._def.shape()
14316
- // // );
14317
- // const merged: any = new ZodObject({
14318
- // unknownKeys: merging._def.unknownKeys,
14319
- // catchall: merging._def.catchall,
14320
- // shape: () =>
14321
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
14322
- // typeName: ZodFirstPartyTypeKind.ZodObject,
14323
- // }) as any;
14324
- // return merged;
14325
- // }
14326
- catchall(index) {
14327
- return new ZodObject({
14328
- ...this._def,
14329
- catchall: index,
14330
- });
14331
- }
14332
- pick(mask) {
14333
- const shape = {};
14334
- util$1.objectKeys(mask).forEach((key) => {
14335
- if (mask[key] && this.shape[key]) {
14336
- shape[key] = this.shape[key];
14337
- }
14338
- });
14339
- return new ZodObject({
14340
- ...this._def,
14341
- shape: () => shape,
14342
- });
14343
- }
14344
- omit(mask) {
14345
- const shape = {};
14346
- util$1.objectKeys(this.shape).forEach((key) => {
14347
- if (!mask[key]) {
14348
- shape[key] = this.shape[key];
14349
- }
14350
- });
14351
- return new ZodObject({
14352
- ...this._def,
14353
- shape: () => shape,
14354
- });
14355
- }
14356
- /**
14357
- * @deprecated
14358
- */
14359
- deepPartial() {
14360
- return deepPartialify(this);
14361
- }
14362
- partial(mask) {
14363
- const newShape = {};
14364
- util$1.objectKeys(this.shape).forEach((key) => {
14365
- const fieldSchema = this.shape[key];
14366
- if (mask && !mask[key]) {
14367
- newShape[key] = fieldSchema;
14368
- }
14369
- else {
14370
- newShape[key] = fieldSchema.optional();
14371
- }
14372
- });
14373
- return new ZodObject({
14374
- ...this._def,
14375
- shape: () => newShape,
14376
- });
14377
- }
14378
- required(mask) {
14379
- const newShape = {};
14380
- util$1.objectKeys(this.shape).forEach((key) => {
14381
- if (mask && !mask[key]) {
14382
- newShape[key] = this.shape[key];
14383
- }
14384
- else {
14385
- const fieldSchema = this.shape[key];
14386
- let newField = fieldSchema;
14387
- while (newField instanceof ZodOptional) {
14388
- newField = newField._def.innerType;
14389
- }
14390
- newShape[key] = newField;
14391
- }
14392
- });
14393
- return new ZodObject({
14394
- ...this._def,
14395
- shape: () => newShape,
14396
- });
14397
- }
14398
- keyof() {
14399
- return createZodEnum(util$1.objectKeys(this.shape));
14400
- }
14401
- }
14402
- ZodObject.create = (shape, params) => {
14403
- return new ZodObject({
14404
- shape: () => shape,
14405
- unknownKeys: "strip",
14406
- catchall: ZodNever.create(),
14407
- typeName: ZodFirstPartyTypeKind.ZodObject,
14408
- ...processCreateParams(params),
14409
- });
14410
- };
14411
- ZodObject.strictCreate = (shape, params) => {
14412
- return new ZodObject({
14413
- shape: () => shape,
14414
- unknownKeys: "strict",
14415
- catchall: ZodNever.create(),
14416
- typeName: ZodFirstPartyTypeKind.ZodObject,
14417
- ...processCreateParams(params),
14418
- });
14419
- };
14420
- ZodObject.lazycreate = (shape, params) => {
14421
- return new ZodObject({
14422
- shape,
14423
- unknownKeys: "strip",
14424
- catchall: ZodNever.create(),
14425
- typeName: ZodFirstPartyTypeKind.ZodObject,
14426
- ...processCreateParams(params),
14427
- });
14428
- };
14429
- class ZodUnion extends ZodType {
14430
- _parse(input) {
14431
- const { ctx } = this._processInputParams(input);
14432
- const options = this._def.options;
14433
- function handleResults(results) {
14434
- // return first issue-free validation if it exists
14435
- for (const result of results) {
14436
- if (result.result.status === "valid") {
14437
- return result.result;
14438
- }
14439
- }
14440
- for (const result of results) {
14441
- if (result.result.status === "dirty") {
14442
- // add issues from dirty option
14443
- ctx.common.issues.push(...result.ctx.common.issues);
14444
- return result.result;
14445
- }
14446
- }
14447
- // return invalid
14448
- const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
14449
- addIssueToContext(ctx, {
14450
- code: ZodIssueCode.invalid_union,
14451
- unionErrors,
14452
- });
14453
- return INVALID;
14454
- }
14455
- if (ctx.common.async) {
14456
- return Promise.all(options.map(async (option) => {
14457
- const childCtx = {
14458
- ...ctx,
14459
- common: {
14460
- ...ctx.common,
14461
- issues: [],
14462
- },
14463
- parent: null,
14464
- };
14465
- return {
14466
- result: await option._parseAsync({
14467
- data: ctx.data,
14468
- path: ctx.path,
14469
- parent: childCtx,
14470
- }),
14471
- ctx: childCtx,
14472
- };
14473
- })).then(handleResults);
14474
- }
14475
- else {
14476
- let dirty = undefined;
14477
- const issues = [];
14478
- for (const option of options) {
14479
- const childCtx = {
14480
- ...ctx,
14481
- common: {
14482
- ...ctx.common,
14483
- issues: [],
14484
- },
14485
- parent: null,
14486
- };
14487
- const result = option._parseSync({
14488
- data: ctx.data,
14489
- path: ctx.path,
14490
- parent: childCtx,
14491
- });
14492
- if (result.status === "valid") {
14493
- return result;
14494
- }
14495
- else if (result.status === "dirty" && !dirty) {
14496
- dirty = { result, ctx: childCtx };
14497
- }
14498
- if (childCtx.common.issues.length) {
14499
- issues.push(childCtx.common.issues);
14500
- }
14501
- }
14502
- if (dirty) {
14503
- ctx.common.issues.push(...dirty.ctx.common.issues);
14504
- return dirty.result;
14505
- }
14506
- const unionErrors = issues.map((issues) => new ZodError(issues));
14507
- addIssueToContext(ctx, {
14508
- code: ZodIssueCode.invalid_union,
14509
- unionErrors,
14510
- });
14511
- return INVALID;
14512
- }
14513
- }
14514
- get options() {
14515
- return this._def.options;
14516
- }
14517
- }
14518
- ZodUnion.create = (types, params) => {
14519
- return new ZodUnion({
14520
- options: types,
14521
- typeName: ZodFirstPartyTypeKind.ZodUnion,
14522
- ...processCreateParams(params),
14523
- });
14524
- };
14525
- /////////////////////////////////////////////////////
14526
- /////////////////////////////////////////////////////
14527
- ////////// //////////
14528
- ////////// ZodDiscriminatedUnion //////////
14529
- ////////// //////////
14530
- /////////////////////////////////////////////////////
14531
- /////////////////////////////////////////////////////
14532
- const getDiscriminator = (type) => {
14533
- if (type instanceof ZodLazy) {
14534
- return getDiscriminator(type.schema);
14535
- }
14536
- else if (type instanceof ZodEffects) {
14537
- return getDiscriminator(type.innerType());
14538
- }
14539
- else if (type instanceof ZodLiteral) {
14540
- return [type.value];
14541
- }
14542
- else if (type instanceof ZodEnum) {
14543
- return type.options;
14544
- }
14545
- else if (type instanceof ZodNativeEnum) {
14546
- // eslint-disable-next-line ban/ban
14547
- return util$1.objectValues(type.enum);
14548
- }
14549
- else if (type instanceof ZodDefault) {
14550
- return getDiscriminator(type._def.innerType);
14551
- }
14552
- else if (type instanceof ZodUndefined) {
14553
- return [undefined];
14554
- }
14555
- else if (type instanceof ZodNull) {
14556
- return [null];
14557
- }
14558
- else if (type instanceof ZodOptional) {
14559
- return [undefined, ...getDiscriminator(type.unwrap())];
14560
- }
14561
- else if (type instanceof ZodNullable) {
14562
- return [null, ...getDiscriminator(type.unwrap())];
14563
- }
14564
- else if (type instanceof ZodBranded) {
14565
- return getDiscriminator(type.unwrap());
14566
- }
14567
- else if (type instanceof ZodReadonly) {
14568
- return getDiscriminator(type.unwrap());
14569
- }
14570
- else if (type instanceof ZodCatch) {
14571
- return getDiscriminator(type._def.innerType);
14572
- }
14573
- else {
14574
- return [];
14575
- }
14576
- };
14577
- class ZodDiscriminatedUnion extends ZodType {
14578
- _parse(input) {
14579
- const { ctx } = this._processInputParams(input);
14580
- if (ctx.parsedType !== ZodParsedType.object) {
14581
- addIssueToContext(ctx, {
14582
- code: ZodIssueCode.invalid_type,
14583
- expected: ZodParsedType.object,
14584
- received: ctx.parsedType,
14585
- });
14586
- return INVALID;
14587
- }
14588
- const discriminator = this.discriminator;
14589
- const discriminatorValue = ctx.data[discriminator];
14590
- const option = this.optionsMap.get(discriminatorValue);
14591
- if (!option) {
14592
- addIssueToContext(ctx, {
14593
- code: ZodIssueCode.invalid_union_discriminator,
14594
- options: Array.from(this.optionsMap.keys()),
14595
- path: [discriminator],
14596
- });
14597
- return INVALID;
14598
- }
14599
- if (ctx.common.async) {
14600
- return option._parseAsync({
14601
- data: ctx.data,
14602
- path: ctx.path,
14603
- parent: ctx,
14604
- });
14605
- }
14606
- else {
14607
- return option._parseSync({
14608
- data: ctx.data,
14609
- path: ctx.path,
14610
- parent: ctx,
14611
- });
14612
- }
14613
- }
14614
- get discriminator() {
14615
- return this._def.discriminator;
14616
- }
14617
- get options() {
14618
- return this._def.options;
14619
- }
14620
- get optionsMap() {
14621
- return this._def.optionsMap;
14622
- }
14623
- /**
14624
- * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
14625
- * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
14626
- * have a different value for each object in the union.
14627
- * @param discriminator the name of the discriminator property
14628
- * @param types an array of object schemas
14629
- * @param params
14630
- */
14631
- static create(discriminator, options, params) {
14632
- // Get all the valid discriminator values
14633
- const optionsMap = new Map();
14634
- // try {
14635
- for (const type of options) {
14636
- const discriminatorValues = getDiscriminator(type.shape[discriminator]);
14637
- if (!discriminatorValues.length) {
14638
- throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
14639
- }
14640
- for (const value of discriminatorValues) {
14641
- if (optionsMap.has(value)) {
14642
- throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
14643
- }
14644
- optionsMap.set(value, type);
14645
- }
14646
- }
14647
- return new ZodDiscriminatedUnion({
14648
- typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
14649
- discriminator,
14650
- options,
14651
- optionsMap,
14652
- ...processCreateParams(params),
14653
- });
14654
- }
14655
- }
14656
- function mergeValues(a, b) {
14657
- const aType = getParsedType(a);
14658
- const bType = getParsedType(b);
14659
- if (a === b) {
14660
- return { valid: true, data: a };
14661
- }
14662
- else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
14663
- const bKeys = util$1.objectKeys(b);
14664
- const sharedKeys = util$1
14665
- .objectKeys(a)
14666
- .filter((key) => bKeys.indexOf(key) !== -1);
14667
- const newObj = { ...a, ...b };
14668
- for (const key of sharedKeys) {
14669
- const sharedValue = mergeValues(a[key], b[key]);
14670
- if (!sharedValue.valid) {
14671
- return { valid: false };
14672
- }
14673
- newObj[key] = sharedValue.data;
14674
- }
14675
- return { valid: true, data: newObj };
14676
- }
14677
- else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
14678
- if (a.length !== b.length) {
14679
- return { valid: false };
14680
- }
14681
- const newArray = [];
14682
- for (let index = 0; index < a.length; index++) {
14683
- const itemA = a[index];
14684
- const itemB = b[index];
14685
- const sharedValue = mergeValues(itemA, itemB);
14686
- if (!sharedValue.valid) {
14687
- return { valid: false };
14688
- }
14689
- newArray.push(sharedValue.data);
14690
- }
14691
- return { valid: true, data: newArray };
14692
- }
14693
- else if (aType === ZodParsedType.date &&
14694
- bType === ZodParsedType.date &&
14695
- +a === +b) {
14696
- return { valid: true, data: a };
14697
- }
14698
- else {
14699
- return { valid: false };
14700
- }
14701
- }
14702
- class ZodIntersection extends ZodType {
14703
- _parse(input) {
14704
- const { status, ctx } = this._processInputParams(input);
14705
- const handleParsed = (parsedLeft, parsedRight) => {
14706
- if (isAborted(parsedLeft) || isAborted(parsedRight)) {
14707
- return INVALID;
14708
- }
14709
- const merged = mergeValues(parsedLeft.value, parsedRight.value);
14710
- if (!merged.valid) {
14711
- addIssueToContext(ctx, {
14712
- code: ZodIssueCode.invalid_intersection_types,
14713
- });
14714
- return INVALID;
14715
- }
14716
- if (isDirty(parsedLeft) || isDirty(parsedRight)) {
14717
- status.dirty();
14718
- }
14719
- return { status: status.value, value: merged.data };
14720
- };
14721
- if (ctx.common.async) {
14722
- return Promise.all([
14723
- this._def.left._parseAsync({
14724
- data: ctx.data,
14725
- path: ctx.path,
14726
- parent: ctx,
14727
- }),
14728
- this._def.right._parseAsync({
14729
- data: ctx.data,
14730
- path: ctx.path,
14731
- parent: ctx,
14732
- }),
14733
- ]).then(([left, right]) => handleParsed(left, right));
14734
- }
14735
- else {
14736
- return handleParsed(this._def.left._parseSync({
14737
- data: ctx.data,
14738
- path: ctx.path,
14739
- parent: ctx,
14740
- }), this._def.right._parseSync({
14741
- data: ctx.data,
14742
- path: ctx.path,
14743
- parent: ctx,
14744
- }));
14745
- }
14746
- }
14747
- }
14748
- ZodIntersection.create = (left, right, params) => {
14749
- return new ZodIntersection({
14750
- left: left,
14751
- right: right,
14752
- typeName: ZodFirstPartyTypeKind.ZodIntersection,
14753
- ...processCreateParams(params),
14754
- });
14755
- };
14756
- class ZodTuple extends ZodType {
14757
- _parse(input) {
14758
- const { status, ctx } = this._processInputParams(input);
14759
- if (ctx.parsedType !== ZodParsedType.array) {
14760
- addIssueToContext(ctx, {
14761
- code: ZodIssueCode.invalid_type,
14762
- expected: ZodParsedType.array,
14763
- received: ctx.parsedType,
14764
- });
14765
- return INVALID;
14766
- }
14767
- if (ctx.data.length < this._def.items.length) {
14768
- addIssueToContext(ctx, {
14769
- code: ZodIssueCode.too_small,
14770
- minimum: this._def.items.length,
14771
- inclusive: true,
14772
- exact: false,
14773
- type: "array",
14774
- });
14775
- return INVALID;
14776
- }
14777
- const rest = this._def.rest;
14778
- if (!rest && ctx.data.length > this._def.items.length) {
14779
- addIssueToContext(ctx, {
14780
- code: ZodIssueCode.too_big,
14781
- maximum: this._def.items.length,
14782
- inclusive: true,
14783
- exact: false,
14784
- type: "array",
14785
- });
14786
- status.dirty();
14787
- }
14788
- const items = [...ctx.data]
14789
- .map((item, itemIndex) => {
14790
- const schema = this._def.items[itemIndex] || this._def.rest;
14791
- if (!schema)
14792
- return null;
14793
- return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
14794
- })
14795
- .filter((x) => !!x); // filter nulls
14796
- if (ctx.common.async) {
14797
- return Promise.all(items).then((results) => {
14798
- return ParseStatus.mergeArray(status, results);
14799
- });
14800
- }
14801
- else {
14802
- return ParseStatus.mergeArray(status, items);
14803
- }
14804
- }
14805
- get items() {
14806
- return this._def.items;
14807
- }
14808
- rest(rest) {
14809
- return new ZodTuple({
14810
- ...this._def,
14811
- rest,
14812
- });
14813
- }
14814
- }
14815
- ZodTuple.create = (schemas, params) => {
14816
- if (!Array.isArray(schemas)) {
14817
- throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
14818
- }
14819
- return new ZodTuple({
14820
- items: schemas,
14821
- typeName: ZodFirstPartyTypeKind.ZodTuple,
14822
- rest: null,
14823
- ...processCreateParams(params),
14824
- });
14825
- };
14826
- class ZodRecord extends ZodType {
14827
- get keySchema() {
14828
- return this._def.keyType;
14829
- }
14830
- get valueSchema() {
14831
- return this._def.valueType;
14832
- }
14833
- _parse(input) {
14834
- const { status, ctx } = this._processInputParams(input);
14835
- if (ctx.parsedType !== ZodParsedType.object) {
14836
- addIssueToContext(ctx, {
14837
- code: ZodIssueCode.invalid_type,
14838
- expected: ZodParsedType.object,
14839
- received: ctx.parsedType,
14840
- });
14841
- return INVALID;
14842
- }
14843
- const pairs = [];
14844
- const keyType = this._def.keyType;
14845
- const valueType = this._def.valueType;
14846
- for (const key in ctx.data) {
14847
- pairs.push({
14848
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
14849
- value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
14850
- alwaysSet: key in ctx.data,
14851
- });
14852
- }
14853
- if (ctx.common.async) {
14854
- return ParseStatus.mergeObjectAsync(status, pairs);
14855
- }
14856
- else {
14857
- return ParseStatus.mergeObjectSync(status, pairs);
14858
- }
14859
- }
14860
- get element() {
14861
- return this._def.valueType;
14862
- }
14863
- static create(first, second, third) {
14864
- if (second instanceof ZodType) {
14865
- return new ZodRecord({
14866
- keyType: first,
14867
- valueType: second,
14868
- typeName: ZodFirstPartyTypeKind.ZodRecord,
14869
- ...processCreateParams(third),
14870
- });
14871
- }
14872
- return new ZodRecord({
14873
- keyType: ZodString.create(),
14874
- valueType: first,
14875
- typeName: ZodFirstPartyTypeKind.ZodRecord,
14876
- ...processCreateParams(second),
14877
- });
14878
- }
14879
- }
14880
- class ZodMap extends ZodType {
14881
- get keySchema() {
14882
- return this._def.keyType;
14883
- }
14884
- get valueSchema() {
14885
- return this._def.valueType;
14886
- }
14887
- _parse(input) {
14888
- const { status, ctx } = this._processInputParams(input);
14889
- if (ctx.parsedType !== ZodParsedType.map) {
14890
- addIssueToContext(ctx, {
14891
- code: ZodIssueCode.invalid_type,
14892
- expected: ZodParsedType.map,
14893
- received: ctx.parsedType,
14894
- });
14895
- return INVALID;
14896
- }
14897
- const keyType = this._def.keyType;
14898
- const valueType = this._def.valueType;
14899
- const pairs = [...ctx.data.entries()].map(([key, value], index) => {
14900
- return {
14901
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
14902
- value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"])),
14903
- };
14904
- });
14905
- if (ctx.common.async) {
14906
- const finalMap = new Map();
14907
- return Promise.resolve().then(async () => {
14908
- for (const pair of pairs) {
14909
- const key = await pair.key;
14910
- const value = await pair.value;
14911
- if (key.status === "aborted" || value.status === "aborted") {
14912
- return INVALID;
14913
- }
14914
- if (key.status === "dirty" || value.status === "dirty") {
14915
- status.dirty();
14916
- }
14917
- finalMap.set(key.value, value.value);
14918
- }
14919
- return { status: status.value, value: finalMap };
14920
- });
14921
- }
14922
- else {
14923
- const finalMap = new Map();
14924
- for (const pair of pairs) {
14925
- const key = pair.key;
14926
- const value = pair.value;
14927
- if (key.status === "aborted" || value.status === "aborted") {
14928
- return INVALID;
14929
- }
14930
- if (key.status === "dirty" || value.status === "dirty") {
14931
- status.dirty();
14932
- }
14933
- finalMap.set(key.value, value.value);
14934
- }
14935
- return { status: status.value, value: finalMap };
14936
- }
14937
- }
14938
- }
14939
- ZodMap.create = (keyType, valueType, params) => {
14940
- return new ZodMap({
14941
- valueType,
14942
- keyType,
14943
- typeName: ZodFirstPartyTypeKind.ZodMap,
14944
- ...processCreateParams(params),
14945
- });
14946
- };
14947
- class ZodSet extends ZodType {
14948
- _parse(input) {
14949
- const { status, ctx } = this._processInputParams(input);
14950
- if (ctx.parsedType !== ZodParsedType.set) {
14951
- addIssueToContext(ctx, {
14952
- code: ZodIssueCode.invalid_type,
14953
- expected: ZodParsedType.set,
14954
- received: ctx.parsedType,
14955
- });
14956
- return INVALID;
14957
- }
14958
- const def = this._def;
14959
- if (def.minSize !== null) {
14960
- if (ctx.data.size < def.minSize.value) {
14961
- addIssueToContext(ctx, {
14962
- code: ZodIssueCode.too_small,
14963
- minimum: def.minSize.value,
14964
- type: "set",
14965
- inclusive: true,
14966
- exact: false,
14967
- message: def.minSize.message,
14968
- });
14969
- status.dirty();
14970
- }
14971
- }
14972
- if (def.maxSize !== null) {
14973
- if (ctx.data.size > def.maxSize.value) {
14974
- addIssueToContext(ctx, {
14975
- code: ZodIssueCode.too_big,
14976
- maximum: def.maxSize.value,
14977
- type: "set",
14978
- inclusive: true,
14979
- exact: false,
14980
- message: def.maxSize.message,
14981
- });
14982
- status.dirty();
14983
- }
14984
- }
14985
- const valueType = this._def.valueType;
14986
- function finalizeSet(elements) {
14987
- const parsedSet = new Set();
14988
- for (const element of elements) {
14989
- if (element.status === "aborted")
14990
- return INVALID;
14991
- if (element.status === "dirty")
14992
- status.dirty();
14993
- parsedSet.add(element.value);
14994
- }
14995
- return { status: status.value, value: parsedSet };
14996
- }
14997
- const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
14998
- if (ctx.common.async) {
14999
- return Promise.all(elements).then((elements) => finalizeSet(elements));
15000
- }
15001
- else {
15002
- return finalizeSet(elements);
15003
- }
15004
- }
15005
- min(minSize, message) {
15006
- return new ZodSet({
15007
- ...this._def,
15008
- minSize: { value: minSize, message: errorUtil.toString(message) },
15009
- });
15010
- }
15011
- max(maxSize, message) {
15012
- return new ZodSet({
15013
- ...this._def,
15014
- maxSize: { value: maxSize, message: errorUtil.toString(message) },
15015
- });
15016
- }
15017
- size(size, message) {
15018
- return this.min(size, message).max(size, message);
15019
- }
15020
- nonempty(message) {
15021
- return this.min(1, message);
15022
- }
15023
- }
15024
- ZodSet.create = (valueType, params) => {
15025
- return new ZodSet({
15026
- valueType,
15027
- minSize: null,
15028
- maxSize: null,
15029
- typeName: ZodFirstPartyTypeKind.ZodSet,
15030
- ...processCreateParams(params),
15031
- });
15032
- };
15033
- class ZodFunction extends ZodType {
15034
- constructor() {
15035
- super(...arguments);
15036
- this.validate = this.implement;
15037
- }
15038
- _parse(input) {
15039
- const { ctx } = this._processInputParams(input);
15040
- if (ctx.parsedType !== ZodParsedType.function) {
15041
- addIssueToContext(ctx, {
15042
- code: ZodIssueCode.invalid_type,
15043
- expected: ZodParsedType.function,
15044
- received: ctx.parsedType,
15045
- });
15046
- return INVALID;
15047
- }
15048
- function makeArgsIssue(args, error) {
15049
- return makeIssue({
15050
- data: args,
15051
- path: ctx.path,
15052
- errorMaps: [
15053
- ctx.common.contextualErrorMap,
15054
- ctx.schemaErrorMap,
15055
- getErrorMap(),
15056
- errorMap,
15057
- ].filter((x) => !!x),
15058
- issueData: {
15059
- code: ZodIssueCode.invalid_arguments,
15060
- argumentsError: error,
15061
- },
15062
- });
15063
- }
15064
- function makeReturnsIssue(returns, error) {
15065
- return makeIssue({
15066
- data: returns,
15067
- path: ctx.path,
15068
- errorMaps: [
15069
- ctx.common.contextualErrorMap,
15070
- ctx.schemaErrorMap,
15071
- getErrorMap(),
15072
- errorMap,
15073
- ].filter((x) => !!x),
15074
- issueData: {
15075
- code: ZodIssueCode.invalid_return_type,
15076
- returnTypeError: error,
15077
- },
15078
- });
15079
- }
15080
- const params = { errorMap: ctx.common.contextualErrorMap };
15081
- const fn = ctx.data;
15082
- if (this._def.returns instanceof ZodPromise) {
15083
- // Would love a way to avoid disabling this rule, but we need
15084
- // an alias (using an arrow function was what caused 2651).
15085
- // eslint-disable-next-line @typescript-eslint/no-this-alias
15086
- const me = this;
15087
- return OK(async function (...args) {
15088
- const error = new ZodError([]);
15089
- const parsedArgs = await me._def.args
15090
- .parseAsync(args, params)
15091
- .catch((e) => {
15092
- error.addIssue(makeArgsIssue(args, e));
15093
- throw error;
15094
- });
15095
- const result = await Reflect.apply(fn, this, parsedArgs);
15096
- const parsedReturns = await me._def.returns._def.type
15097
- .parseAsync(result, params)
15098
- .catch((e) => {
15099
- error.addIssue(makeReturnsIssue(result, e));
15100
- throw error;
15101
- });
15102
- return parsedReturns;
15103
- });
15104
- }
15105
- else {
15106
- // Would love a way to avoid disabling this rule, but we need
15107
- // an alias (using an arrow function was what caused 2651).
15108
- // eslint-disable-next-line @typescript-eslint/no-this-alias
15109
- const me = this;
15110
- return OK(function (...args) {
15111
- const parsedArgs = me._def.args.safeParse(args, params);
15112
- if (!parsedArgs.success) {
15113
- throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
15114
- }
15115
- const result = Reflect.apply(fn, this, parsedArgs.data);
15116
- const parsedReturns = me._def.returns.safeParse(result, params);
15117
- if (!parsedReturns.success) {
15118
- throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
15119
- }
15120
- return parsedReturns.data;
15121
- });
15122
- }
15123
- }
15124
- parameters() {
15125
- return this._def.args;
15126
- }
15127
- returnType() {
15128
- return this._def.returns;
15129
- }
15130
- args(...items) {
15131
- return new ZodFunction({
15132
- ...this._def,
15133
- args: ZodTuple.create(items).rest(ZodUnknown.create()),
15134
- });
15135
- }
15136
- returns(returnType) {
15137
- return new ZodFunction({
15138
- ...this._def,
15139
- returns: returnType,
15140
- });
15141
- }
15142
- implement(func) {
15143
- const validatedFunc = this.parse(func);
15144
- return validatedFunc;
15145
- }
15146
- strictImplement(func) {
15147
- const validatedFunc = this.parse(func);
15148
- return validatedFunc;
15149
- }
15150
- static create(args, returns, params) {
15151
- return new ZodFunction({
15152
- args: (args
15153
- ? args
15154
- : ZodTuple.create([]).rest(ZodUnknown.create())),
15155
- returns: returns || ZodUnknown.create(),
15156
- typeName: ZodFirstPartyTypeKind.ZodFunction,
15157
- ...processCreateParams(params),
15158
- });
15159
- }
15160
- }
15161
- class ZodLazy extends ZodType {
15162
- get schema() {
15163
- return this._def.getter();
15164
- }
15165
- _parse(input) {
15166
- const { ctx } = this._processInputParams(input);
15167
- const lazySchema = this._def.getter();
15168
- return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
15169
- }
15170
- }
15171
- ZodLazy.create = (getter, params) => {
15172
- return new ZodLazy({
15173
- getter: getter,
15174
- typeName: ZodFirstPartyTypeKind.ZodLazy,
15175
- ...processCreateParams(params),
15176
- });
15177
- };
15178
- class ZodLiteral extends ZodType {
15179
- _parse(input) {
15180
- if (input.data !== this._def.value) {
15181
- const ctx = this._getOrReturnCtx(input);
15182
- addIssueToContext(ctx, {
15183
- received: ctx.data,
15184
- code: ZodIssueCode.invalid_literal,
15185
- expected: this._def.value,
15186
- });
15187
- return INVALID;
15188
- }
15189
- return { status: "valid", value: input.data };
15190
- }
15191
- get value() {
15192
- return this._def.value;
15193
- }
15194
- }
15195
- ZodLiteral.create = (value, params) => {
15196
- return new ZodLiteral({
15197
- value: value,
15198
- typeName: ZodFirstPartyTypeKind.ZodLiteral,
15199
- ...processCreateParams(params),
15200
- });
15201
- };
15202
- function createZodEnum(values, params) {
15203
- return new ZodEnum({
15204
- values,
15205
- typeName: ZodFirstPartyTypeKind.ZodEnum,
15206
- ...processCreateParams(params),
15207
- });
15208
- }
15209
- class ZodEnum extends ZodType {
15210
- constructor() {
15211
- super(...arguments);
15212
- _ZodEnum_cache.set(this, void 0);
15213
- }
15214
- _parse(input) {
15215
- if (typeof input.data !== "string") {
15216
- const ctx = this._getOrReturnCtx(input);
15217
- const expectedValues = this._def.values;
15218
- addIssueToContext(ctx, {
15219
- expected: util$1.joinValues(expectedValues),
15220
- received: ctx.parsedType,
15221
- code: ZodIssueCode.invalid_type,
15222
- });
15223
- return INVALID;
15224
- }
15225
- if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f")) {
15226
- __classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values), "f");
15227
- }
15228
- if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f").has(input.data)) {
15229
- const ctx = this._getOrReturnCtx(input);
15230
- const expectedValues = this._def.values;
15231
- addIssueToContext(ctx, {
15232
- received: ctx.data,
15233
- code: ZodIssueCode.invalid_enum_value,
15234
- options: expectedValues,
15235
- });
15236
- return INVALID;
15237
- }
15238
- return OK(input.data);
15239
- }
15240
- get options() {
15241
- return this._def.values;
15242
- }
15243
- get enum() {
15244
- const enumValues = {};
15245
- for (const val of this._def.values) {
15246
- enumValues[val] = val;
15247
- }
15248
- return enumValues;
15249
- }
15250
- get Values() {
15251
- const enumValues = {};
15252
- for (const val of this._def.values) {
15253
- enumValues[val] = val;
15254
- }
15255
- return enumValues;
15256
- }
15257
- get Enum() {
15258
- const enumValues = {};
15259
- for (const val of this._def.values) {
15260
- enumValues[val] = val;
15261
- }
15262
- return enumValues;
15263
- }
15264
- extract(values, newDef = this._def) {
15265
- return ZodEnum.create(values, {
15266
- ...this._def,
15267
- ...newDef,
15268
- });
15269
- }
15270
- exclude(values, newDef = this._def) {
15271
- return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
15272
- ...this._def,
15273
- ...newDef,
15274
- });
15275
- }
15276
- }
15277
- _ZodEnum_cache = new WeakMap();
15278
- ZodEnum.create = createZodEnum;
15279
- class ZodNativeEnum extends ZodType {
15280
- constructor() {
15281
- super(...arguments);
15282
- _ZodNativeEnum_cache.set(this, void 0);
15283
- }
15284
- _parse(input) {
15285
- const nativeEnumValues = util$1.getValidEnumValues(this._def.values);
15286
- const ctx = this._getOrReturnCtx(input);
15287
- if (ctx.parsedType !== ZodParsedType.string &&
15288
- ctx.parsedType !== ZodParsedType.number) {
15289
- const expectedValues = util$1.objectValues(nativeEnumValues);
15290
- addIssueToContext(ctx, {
15291
- expected: util$1.joinValues(expectedValues),
15292
- received: ctx.parsedType,
15293
- code: ZodIssueCode.invalid_type,
15294
- });
15295
- return INVALID;
15296
- }
15297
- if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f")) {
15298
- __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util$1.getValidEnumValues(this._def.values)), "f");
15299
- }
15300
- if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f").has(input.data)) {
15301
- const expectedValues = util$1.objectValues(nativeEnumValues);
15302
- addIssueToContext(ctx, {
15303
- received: ctx.data,
15304
- code: ZodIssueCode.invalid_enum_value,
15305
- options: expectedValues,
15306
- });
15307
- return INVALID;
15308
- }
15309
- return OK(input.data);
15310
- }
15311
- get enum() {
15312
- return this._def.values;
15313
- }
15314
- }
15315
- _ZodNativeEnum_cache = new WeakMap();
15316
- ZodNativeEnum.create = (values, params) => {
15317
- return new ZodNativeEnum({
15318
- values: values,
15319
- typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
15320
- ...processCreateParams(params),
15321
- });
15322
- };
15323
- class ZodPromise extends ZodType {
15324
- unwrap() {
15325
- return this._def.type;
15326
- }
15327
- _parse(input) {
15328
- const { ctx } = this._processInputParams(input);
15329
- if (ctx.parsedType !== ZodParsedType.promise &&
15330
- ctx.common.async === false) {
15331
- addIssueToContext(ctx, {
15332
- code: ZodIssueCode.invalid_type,
15333
- expected: ZodParsedType.promise,
15334
- received: ctx.parsedType,
15335
- });
15336
- return INVALID;
15337
- }
15338
- const promisified = ctx.parsedType === ZodParsedType.promise
15339
- ? ctx.data
15340
- : Promise.resolve(ctx.data);
15341
- return OK(promisified.then((data) => {
15342
- return this._def.type.parseAsync(data, {
15343
- path: ctx.path,
15344
- errorMap: ctx.common.contextualErrorMap,
15345
- });
15346
- }));
15347
- }
15348
- }
15349
- ZodPromise.create = (schema, params) => {
15350
- return new ZodPromise({
15351
- type: schema,
15352
- typeName: ZodFirstPartyTypeKind.ZodPromise,
15353
- ...processCreateParams(params),
15354
- });
15355
- };
15356
- class ZodEffects extends ZodType {
15357
- innerType() {
15358
- return this._def.schema;
15359
- }
15360
- sourceType() {
15361
- return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects
15362
- ? this._def.schema.sourceType()
15363
- : this._def.schema;
15364
- }
15365
- _parse(input) {
15366
- const { status, ctx } = this._processInputParams(input);
15367
- const effect = this._def.effect || null;
15368
- const checkCtx = {
15369
- addIssue: (arg) => {
15370
- addIssueToContext(ctx, arg);
15371
- if (arg.fatal) {
15372
- status.abort();
15373
- }
15374
- else {
15375
- status.dirty();
15376
- }
15377
- },
15378
- get path() {
15379
- return ctx.path;
15380
- },
15381
- };
15382
- checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
15383
- if (effect.type === "preprocess") {
15384
- const processed = effect.transform(ctx.data, checkCtx);
15385
- if (ctx.common.async) {
15386
- return Promise.resolve(processed).then(async (processed) => {
15387
- if (status.value === "aborted")
15388
- return INVALID;
15389
- const result = await this._def.schema._parseAsync({
15390
- data: processed,
15391
- path: ctx.path,
15392
- parent: ctx,
15393
- });
15394
- if (result.status === "aborted")
15395
- return INVALID;
15396
- if (result.status === "dirty")
15397
- return DIRTY(result.value);
15398
- if (status.value === "dirty")
15399
- return DIRTY(result.value);
15400
- return result;
15401
- });
15402
- }
15403
- else {
15404
- if (status.value === "aborted")
15405
- return INVALID;
15406
- const result = this._def.schema._parseSync({
15407
- data: processed,
15408
- path: ctx.path,
15409
- parent: ctx,
15410
- });
15411
- if (result.status === "aborted")
15412
- return INVALID;
15413
- if (result.status === "dirty")
15414
- return DIRTY(result.value);
15415
- if (status.value === "dirty")
15416
- return DIRTY(result.value);
15417
- return result;
15418
- }
15419
- }
15420
- if (effect.type === "refinement") {
15421
- const executeRefinement = (acc) => {
15422
- const result = effect.refinement(acc, checkCtx);
15423
- if (ctx.common.async) {
15424
- return Promise.resolve(result);
15425
- }
15426
- if (result instanceof Promise) {
15427
- throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
15428
- }
15429
- return acc;
15430
- };
15431
- if (ctx.common.async === false) {
15432
- const inner = this._def.schema._parseSync({
15433
- data: ctx.data,
15434
- path: ctx.path,
15435
- parent: ctx,
15436
- });
15437
- if (inner.status === "aborted")
15438
- return INVALID;
15439
- if (inner.status === "dirty")
15440
- status.dirty();
15441
- // return value is ignored
15442
- executeRefinement(inner.value);
15443
- return { status: status.value, value: inner.value };
15444
- }
15445
- else {
15446
- return this._def.schema
15447
- ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
15448
- .then((inner) => {
15449
- if (inner.status === "aborted")
15450
- return INVALID;
15451
- if (inner.status === "dirty")
15452
- status.dirty();
15453
- return executeRefinement(inner.value).then(() => {
15454
- return { status: status.value, value: inner.value };
15455
- });
15456
- });
15457
- }
15458
- }
15459
- if (effect.type === "transform") {
15460
- if (ctx.common.async === false) {
15461
- const base = this._def.schema._parseSync({
15462
- data: ctx.data,
15463
- path: ctx.path,
15464
- parent: ctx,
15465
- });
15466
- if (!isValid(base))
15467
- return base;
15468
- const result = effect.transform(base.value, checkCtx);
15469
- if (result instanceof Promise) {
15470
- throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
15471
- }
15472
- return { status: status.value, value: result };
15473
- }
15474
- else {
15475
- return this._def.schema
15476
- ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
15477
- .then((base) => {
15478
- if (!isValid(base))
15479
- return base;
15480
- return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
15481
- });
15482
- }
15483
- }
15484
- util$1.assertNever(effect);
15485
- }
15486
- }
15487
- ZodEffects.create = (schema, effect, params) => {
15488
- return new ZodEffects({
15489
- schema,
15490
- typeName: ZodFirstPartyTypeKind.ZodEffects,
15491
- effect,
15492
- ...processCreateParams(params),
15493
- });
15494
- };
15495
- ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
15496
- return new ZodEffects({
15497
- schema,
15498
- effect: { type: "preprocess", transform: preprocess },
15499
- typeName: ZodFirstPartyTypeKind.ZodEffects,
15500
- ...processCreateParams(params),
15501
- });
15502
- };
15503
- class ZodOptional extends ZodType {
15504
- _parse(input) {
15505
- const parsedType = this._getType(input);
15506
- if (parsedType === ZodParsedType.undefined) {
15507
- return OK(undefined);
15508
- }
15509
- return this._def.innerType._parse(input);
15510
- }
15511
- unwrap() {
15512
- return this._def.innerType;
15513
- }
15514
- }
15515
- ZodOptional.create = (type, params) => {
15516
- return new ZodOptional({
15517
- innerType: type,
15518
- typeName: ZodFirstPartyTypeKind.ZodOptional,
15519
- ...processCreateParams(params),
15520
- });
15521
- };
15522
- class ZodNullable extends ZodType {
15523
- _parse(input) {
15524
- const parsedType = this._getType(input);
15525
- if (parsedType === ZodParsedType.null) {
15526
- return OK(null);
15527
- }
15528
- return this._def.innerType._parse(input);
15529
- }
15530
- unwrap() {
15531
- return this._def.innerType;
15532
- }
15533
- }
15534
- ZodNullable.create = (type, params) => {
15535
- return new ZodNullable({
15536
- innerType: type,
15537
- typeName: ZodFirstPartyTypeKind.ZodNullable,
15538
- ...processCreateParams(params),
15539
- });
15540
- };
15541
- class ZodDefault extends ZodType {
15542
- _parse(input) {
15543
- const { ctx } = this._processInputParams(input);
15544
- let data = ctx.data;
15545
- if (ctx.parsedType === ZodParsedType.undefined) {
15546
- data = this._def.defaultValue();
15547
- }
15548
- return this._def.innerType._parse({
15549
- data,
15550
- path: ctx.path,
15551
- parent: ctx,
15552
- });
15553
- }
15554
- removeDefault() {
15555
- return this._def.innerType;
15556
- }
15557
- }
15558
- ZodDefault.create = (type, params) => {
15559
- return new ZodDefault({
15560
- innerType: type,
15561
- typeName: ZodFirstPartyTypeKind.ZodDefault,
15562
- defaultValue: typeof params.default === "function"
15563
- ? params.default
15564
- : () => params.default,
15565
- ...processCreateParams(params),
15566
- });
15567
- };
15568
- class ZodCatch extends ZodType {
15569
- _parse(input) {
15570
- const { ctx } = this._processInputParams(input);
15571
- // newCtx is used to not collect issues from inner types in ctx
15572
- const newCtx = {
15573
- ...ctx,
15574
- common: {
15575
- ...ctx.common,
15576
- issues: [],
15577
- },
15578
- };
15579
- const result = this._def.innerType._parse({
15580
- data: newCtx.data,
15581
- path: newCtx.path,
15582
- parent: {
15583
- ...newCtx,
15584
- },
15585
- });
15586
- if (isAsync(result)) {
15587
- return result.then((result) => {
15588
- return {
15589
- status: "valid",
15590
- value: result.status === "valid"
15591
- ? result.value
15592
- : this._def.catchValue({
15593
- get error() {
15594
- return new ZodError(newCtx.common.issues);
15595
- },
15596
- input: newCtx.data,
15597
- }),
15598
- };
15599
- });
15600
- }
15601
- else {
15602
- return {
15603
- status: "valid",
15604
- value: result.status === "valid"
15605
- ? result.value
15606
- : this._def.catchValue({
15607
- get error() {
15608
- return new ZodError(newCtx.common.issues);
15609
- },
15610
- input: newCtx.data,
15611
- }),
15612
- };
15613
- }
15614
- }
15615
- removeCatch() {
15616
- return this._def.innerType;
15617
- }
15618
- }
15619
- ZodCatch.create = (type, params) => {
15620
- return new ZodCatch({
15621
- innerType: type,
15622
- typeName: ZodFirstPartyTypeKind.ZodCatch,
15623
- catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
15624
- ...processCreateParams(params),
15625
- });
15626
- };
15627
- class ZodNaN extends ZodType {
15628
- _parse(input) {
15629
- const parsedType = this._getType(input);
15630
- if (parsedType !== ZodParsedType.nan) {
15631
- const ctx = this._getOrReturnCtx(input);
15632
- addIssueToContext(ctx, {
15633
- code: ZodIssueCode.invalid_type,
15634
- expected: ZodParsedType.nan,
15635
- received: ctx.parsedType,
15636
- });
15637
- return INVALID;
15638
- }
15639
- return { status: "valid", value: input.data };
15640
- }
15641
- }
15642
- ZodNaN.create = (params) => {
15643
- return new ZodNaN({
15644
- typeName: ZodFirstPartyTypeKind.ZodNaN,
15645
- ...processCreateParams(params),
15646
- });
15647
- };
15648
- const BRAND = Symbol("zod_brand");
15649
- class ZodBranded extends ZodType {
15650
- _parse(input) {
15651
- const { ctx } = this._processInputParams(input);
15652
- const data = ctx.data;
15653
- return this._def.type._parse({
15654
- data,
15655
- path: ctx.path,
15656
- parent: ctx,
15657
- });
15658
- }
15659
- unwrap() {
15660
- return this._def.type;
15661
- }
15662
- }
15663
- class ZodPipeline extends ZodType {
15664
- _parse(input) {
15665
- const { status, ctx } = this._processInputParams(input);
15666
- if (ctx.common.async) {
15667
- const handleAsync = async () => {
15668
- const inResult = await this._def.in._parseAsync({
15669
- data: ctx.data,
15670
- path: ctx.path,
15671
- parent: ctx,
15672
- });
15673
- if (inResult.status === "aborted")
15674
- return INVALID;
15675
- if (inResult.status === "dirty") {
15676
- status.dirty();
15677
- return DIRTY(inResult.value);
15678
- }
15679
- else {
15680
- return this._def.out._parseAsync({
15681
- data: inResult.value,
15682
- path: ctx.path,
15683
- parent: ctx,
15684
- });
15685
- }
15686
- };
15687
- return handleAsync();
15688
- }
15689
- else {
15690
- const inResult = this._def.in._parseSync({
15691
- data: ctx.data,
15692
- path: ctx.path,
15693
- parent: ctx,
15694
- });
15695
- if (inResult.status === "aborted")
15696
- return INVALID;
15697
- if (inResult.status === "dirty") {
15698
- status.dirty();
15699
- return {
15700
- status: "dirty",
15701
- value: inResult.value,
15702
- };
15703
- }
15704
- else {
15705
- return this._def.out._parseSync({
15706
- data: inResult.value,
15707
- path: ctx.path,
15708
- parent: ctx,
15709
- });
15710
- }
15711
- }
15712
- }
15713
- static create(a, b) {
15714
- return new ZodPipeline({
15715
- in: a,
15716
- out: b,
15717
- typeName: ZodFirstPartyTypeKind.ZodPipeline,
15718
- });
15719
- }
15720
- }
15721
- class ZodReadonly extends ZodType {
15722
- _parse(input) {
15723
- const result = this._def.innerType._parse(input);
15724
- const freeze = (data) => {
15725
- if (isValid(data)) {
15726
- data.value = Object.freeze(data.value);
15727
- }
15728
- return data;
15729
- };
15730
- return isAsync(result)
15731
- ? result.then((data) => freeze(data))
15732
- : freeze(result);
15733
- }
15734
- unwrap() {
15735
- return this._def.innerType;
15736
- }
15737
- }
15738
- ZodReadonly.create = (type, params) => {
15739
- return new ZodReadonly({
15740
- innerType: type,
15741
- typeName: ZodFirstPartyTypeKind.ZodReadonly,
15742
- ...processCreateParams(params),
15743
- });
15744
- };
15745
- ////////////////////////////////////////
15746
- ////////////////////////////////////////
15747
- ////////// //////////
15748
- ////////// z.custom //////////
15749
- ////////// //////////
15750
- ////////////////////////////////////////
15751
- ////////////////////////////////////////
15752
- function cleanParams(params, data) {
15753
- const p = typeof params === "function"
15754
- ? params(data)
15755
- : typeof params === "string"
15756
- ? { message: params }
15757
- : params;
15758
- const p2 = typeof p === "string" ? { message: p } : p;
15759
- return p2;
15760
- }
15761
- function custom(check, _params = {},
15762
- /**
15763
- * @deprecated
15764
- *
15765
- * Pass `fatal` into the params object instead:
15766
- *
15767
- * ```ts
15768
- * z.string().custom((val) => val.length > 5, { fatal: false })
15769
- * ```
15770
- *
15771
- */
15772
- fatal) {
15773
- if (check)
15774
- return ZodAny.create().superRefine((data, ctx) => {
15775
- var _a, _b;
15776
- const r = check(data);
15777
- if (r instanceof Promise) {
15778
- return r.then((r) => {
15779
- var _a, _b;
15780
- if (!r) {
15781
- const params = cleanParams(_params, data);
15782
- const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
15783
- ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
15784
- }
15785
- });
15786
- }
15787
- if (!r) {
15788
- const params = cleanParams(_params, data);
15789
- const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
15790
- ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
15791
- }
15792
- return;
15793
- });
15794
- return ZodAny.create();
15795
- }
15796
- const late = {
15797
- object: ZodObject.lazycreate,
15798
- };
15799
- var ZodFirstPartyTypeKind;
15800
- (function (ZodFirstPartyTypeKind) {
15801
- ZodFirstPartyTypeKind["ZodString"] = "ZodString";
15802
- ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
15803
- ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
15804
- ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
15805
- ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
15806
- ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
15807
- ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
15808
- ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
15809
- ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
15810
- ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
15811
- ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
15812
- ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
15813
- ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
15814
- ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
15815
- ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
15816
- ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
15817
- ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
15818
- ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
15819
- ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
15820
- ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
15821
- ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
15822
- ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
15823
- ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
15824
- ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
15825
- ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
15826
- ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
15827
- ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
15828
- ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
15829
- ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
15830
- ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
15831
- ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
15832
- ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
15833
- ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
15834
- ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
15835
- ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
15836
- ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
15837
- })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
15838
- const instanceOfType = (
15839
- // const instanceOfType = <T extends new (...args: any[]) => any>(
15840
- cls, params = {
15841
- message: `Input not instance of ${cls.name}`,
15842
- }) => custom((data) => data instanceof cls, params);
15843
- const stringType = ZodString.create;
15844
- const numberType = ZodNumber.create;
15845
- const nanType = ZodNaN.create;
15846
- const bigIntType = ZodBigInt.create;
15847
- const booleanType = ZodBoolean.create;
15848
- const dateType = ZodDate.create;
15849
- const symbolType = ZodSymbol.create;
15850
- const undefinedType = ZodUndefined.create;
15851
- const nullType = ZodNull.create;
15852
- const anyType = ZodAny.create;
15853
- const unknownType = ZodUnknown.create;
15854
- const neverType = ZodNever.create;
15855
- const voidType = ZodVoid.create;
15856
- const arrayType = ZodArray.create;
15857
- const objectType = ZodObject.create;
15858
- const strictObjectType = ZodObject.strictCreate;
15859
- const unionType = ZodUnion.create;
15860
- const discriminatedUnionType = ZodDiscriminatedUnion.create;
15861
- const intersectionType = ZodIntersection.create;
15862
- const tupleType = ZodTuple.create;
15863
- const recordType = ZodRecord.create;
15864
- const mapType = ZodMap.create;
15865
- const setType = ZodSet.create;
15866
- const functionType = ZodFunction.create;
15867
- const lazyType = ZodLazy.create;
15868
- const literalType = ZodLiteral.create;
15869
- const enumType = ZodEnum.create;
15870
- const nativeEnumType = ZodNativeEnum.create;
15871
- const promiseType = ZodPromise.create;
15872
- const effectsType = ZodEffects.create;
15873
- const optionalType = ZodOptional.create;
15874
- const nullableType = ZodNullable.create;
15875
- const preprocessType = ZodEffects.createWithPreprocess;
15876
- const pipelineType = ZodPipeline.create;
15877
- const ostring = () => stringType().optional();
15878
- const onumber = () => numberType().optional();
15879
- const oboolean = () => booleanType().optional();
15880
- const coerce = {
15881
- string: ((arg) => ZodString.create({ ...arg, coerce: true })),
15882
- number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
15883
- boolean: ((arg) => ZodBoolean.create({
15884
- ...arg,
15885
- coerce: true,
15886
- })),
15887
- bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
15888
- date: ((arg) => ZodDate.create({ ...arg, coerce: true })),
15889
- };
15890
- const NEVER = INVALID;
15891
-
15892
- var z = /*#__PURE__*/Object.freeze({
15893
- __proto__: null,
15894
- defaultErrorMap: errorMap,
15895
- setErrorMap: setErrorMap,
15896
- getErrorMap: getErrorMap,
15897
- makeIssue: makeIssue,
15898
- EMPTY_PATH: EMPTY_PATH,
15899
- addIssueToContext: addIssueToContext,
15900
- ParseStatus: ParseStatus,
15901
- INVALID: INVALID,
15902
- DIRTY: DIRTY,
15903
- OK: OK,
15904
- isAborted: isAborted,
15905
- isDirty: isDirty,
15906
- isValid: isValid,
15907
- isAsync: isAsync,
15908
- get util () { return util$1; },
15909
- get objectUtil () { return objectUtil; },
15910
- ZodParsedType: ZodParsedType,
15911
- getParsedType: getParsedType,
15912
- ZodType: ZodType,
15913
- datetimeRegex: datetimeRegex,
15914
- ZodString: ZodString,
15915
- ZodNumber: ZodNumber,
15916
- ZodBigInt: ZodBigInt,
15917
- ZodBoolean: ZodBoolean,
15918
- ZodDate: ZodDate,
15919
- ZodSymbol: ZodSymbol,
15920
- ZodUndefined: ZodUndefined,
15921
- ZodNull: ZodNull,
15922
- ZodAny: ZodAny,
15923
- ZodUnknown: ZodUnknown,
15924
- ZodNever: ZodNever,
15925
- ZodVoid: ZodVoid,
15926
- ZodArray: ZodArray,
15927
- ZodObject: ZodObject,
15928
- ZodUnion: ZodUnion,
15929
- ZodDiscriminatedUnion: ZodDiscriminatedUnion,
15930
- ZodIntersection: ZodIntersection,
15931
- ZodTuple: ZodTuple,
15932
- ZodRecord: ZodRecord,
15933
- ZodMap: ZodMap,
15934
- ZodSet: ZodSet,
15935
- ZodFunction: ZodFunction,
15936
- ZodLazy: ZodLazy,
15937
- ZodLiteral: ZodLiteral,
15938
- ZodEnum: ZodEnum,
15939
- ZodNativeEnum: ZodNativeEnum,
15940
- ZodPromise: ZodPromise,
15941
- ZodEffects: ZodEffects,
15942
- ZodTransformer: ZodEffects,
15943
- ZodOptional: ZodOptional,
15944
- ZodNullable: ZodNullable,
15945
- ZodDefault: ZodDefault,
15946
- ZodCatch: ZodCatch,
15947
- ZodNaN: ZodNaN,
15948
- BRAND: BRAND,
15949
- ZodBranded: ZodBranded,
15950
- ZodPipeline: ZodPipeline,
15951
- ZodReadonly: ZodReadonly,
15952
- custom: custom,
15953
- Schema: ZodType,
15954
- ZodSchema: ZodType,
15955
- late: late,
15956
- get ZodFirstPartyTypeKind () { return ZodFirstPartyTypeKind; },
15957
- coerce: coerce,
15958
- any: anyType,
15959
- array: arrayType,
15960
- bigint: bigIntType,
15961
- boolean: booleanType,
15962
- date: dateType,
15963
- discriminatedUnion: discriminatedUnionType,
15964
- effect: effectsType,
15965
- 'enum': enumType,
15966
- 'function': functionType,
15967
- 'instanceof': instanceOfType,
15968
- intersection: intersectionType,
15969
- lazy: lazyType,
15970
- literal: literalType,
15971
- map: mapType,
15972
- nan: nanType,
15973
- nativeEnum: nativeEnumType,
15974
- never: neverType,
15975
- 'null': nullType,
15976
- nullable: nullableType,
15977
- number: numberType,
15978
- object: objectType,
15979
- oboolean: oboolean,
15980
- onumber: onumber,
15981
- optional: optionalType,
15982
- ostring: ostring,
15983
- pipeline: pipelineType,
15984
- preprocess: preprocessType,
15985
- promise: promiseType,
15986
- record: recordType,
15987
- set: setType,
15988
- strictObject: strictObjectType,
15989
- string: stringType,
15990
- symbol: symbolType,
15991
- transformer: effectsType,
15992
- tuple: tupleType,
15993
- 'undefined': undefinedType,
15994
- union: unionType,
15995
- unknown: unknownType,
15996
- 'void': voidType,
15997
- NEVER: NEVER,
15998
- ZodIssueCode: ZodIssueCode,
15999
- quotelessJson: quotelessJson,
16000
- ZodError: ZodError
16001
- });
16002
-
16003
11597
  class KokimokiAwareness extends KokimokiStore {
16004
- dataSchema;
16005
11598
  _data;
16006
11599
  _pingInterval = null;
16007
11600
  _kmClients = new Set();
16008
- constructor(roomName, dataSchema, _data, mode = RoomSubscriptionMode.ReadWrite, pingTimeout = 3000) {
16009
- super(`/a/${roomName}`,
16010
- // @ts-ignore
16011
- z.record(z.string(), z.object({
16012
- clientId: z.string(),
16013
- lastPing: z.number(),
16014
- data: dataSchema,
16015
- })), {}, mode);
16016
- this.dataSchema = dataSchema;
11601
+ constructor(roomName, _data, mode = RoomSubscriptionMode.ReadWrite, pingTimeout = 3000) {
11602
+ super(`/a/${roomName}`, {}, mode);
16017
11603
  this._data = _data;
16018
11604
  this._pingInterval = setInterval(async () => {
16019
11605
  const kmClients = Array.from(this._kmClients);
@@ -18620,8 +14206,8 @@ class KokimokiLocalStore extends KokimokiStore {
18620
14206
  }
18621
14207
  return this._stateKey;
18622
14208
  }
18623
- constructor(localRoomName, schema, defaultState) {
18624
- super(`/l/${localRoomName}`, schema, defaultState, RoomSubscriptionMode.ReadWrite);
14209
+ constructor(localRoomName, defaultState) {
14210
+ super(`/l/${localRoomName}`, defaultState, RoomSubscriptionMode.ReadWrite);
18625
14211
  this.localRoomName = localRoomName;
18626
14212
  // Synchronize doc changes to local storage
18627
14213
  // TODO: maybe do not serialize full state every time
@@ -19206,8 +14792,8 @@ class KokimokiClient extends EventEmitter$1 {
19206
14792
  }
19207
14793
  /** Initializers */
19208
14794
  // store
19209
- store(name, schema, defaultState, autoJoin = true) {
19210
- const store = new KokimokiStore(name, schema, defaultState);
14795
+ store(name, defaultState, autoJoin = true) {
14796
+ const store = new KokimokiStore(name, defaultState);
19211
14797
  if (autoJoin) {
19212
14798
  this.join(store)
19213
14799
  .then(() => { })
@@ -19216,8 +14802,8 @@ class KokimokiClient extends EventEmitter$1 {
19216
14802
  return store;
19217
14803
  }
19218
14804
  // local store
19219
- localStore(name, schema, defaultState) {
19220
- const store = new KokimokiLocalStore(name, schema, defaultState);
14805
+ localStore(name, defaultState) {
14806
+ const store = new KokimokiLocalStore(name, defaultState);
19221
14807
  this.join(store)
19222
14808
  .then(() => { })
19223
14809
  .catch(() => { });
@@ -19239,8 +14825,8 @@ class KokimokiClient extends EventEmitter$1 {
19239
14825
  // return queue;
19240
14826
  // }
19241
14827
  // awareness
19242
- awareness(name, dataSchema, initialData, autoJoin = true) {
19243
- const awareness = new KokimokiAwareness(name, dataSchema, initialData);
14828
+ awareness(name, initialData, autoJoin = true) {
14829
+ const awareness = new KokimokiAwareness(name, initialData);
19244
14830
  if (autoJoin) {
19245
14831
  this.join(awareness)
19246
14832
  .then(() => { })