@contentful/experiences-visual-editor-react 1.5.0 → 1.5.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/renderApp.js CHANGED
@@ -34352,6 +34352,4022 @@ helpers.isText = isText;
34352
34352
 
34353
34353
  } (dist));
34354
34354
 
34355
+ var util;
34356
+ (function (util) {
34357
+ util.assertEqual = (val) => val;
34358
+ function assertIs(_arg) { }
34359
+ util.assertIs = assertIs;
34360
+ function assertNever(_x) {
34361
+ throw new Error();
34362
+ }
34363
+ util.assertNever = assertNever;
34364
+ util.arrayToEnum = (items) => {
34365
+ const obj = {};
34366
+ for (const item of items) {
34367
+ obj[item] = item;
34368
+ }
34369
+ return obj;
34370
+ };
34371
+ util.getValidEnumValues = (obj) => {
34372
+ const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
34373
+ const filtered = {};
34374
+ for (const k of validKeys) {
34375
+ filtered[k] = obj[k];
34376
+ }
34377
+ return util.objectValues(filtered);
34378
+ };
34379
+ util.objectValues = (obj) => {
34380
+ return util.objectKeys(obj).map(function (e) {
34381
+ return obj[e];
34382
+ });
34383
+ };
34384
+ util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
34385
+ ? (obj) => Object.keys(obj) // eslint-disable-line ban/ban
34386
+ : (object) => {
34387
+ const keys = [];
34388
+ for (const key in object) {
34389
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
34390
+ keys.push(key);
34391
+ }
34392
+ }
34393
+ return keys;
34394
+ };
34395
+ util.find = (arr, checker) => {
34396
+ for (const item of arr) {
34397
+ if (checker(item))
34398
+ return item;
34399
+ }
34400
+ return undefined;
34401
+ };
34402
+ util.isInteger = typeof Number.isInteger === "function"
34403
+ ? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
34404
+ : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
34405
+ function joinValues(array, separator = " | ") {
34406
+ return array
34407
+ .map((val) => (typeof val === "string" ? `'${val}'` : val))
34408
+ .join(separator);
34409
+ }
34410
+ util.joinValues = joinValues;
34411
+ util.jsonStringifyReplacer = (_, value) => {
34412
+ if (typeof value === "bigint") {
34413
+ return value.toString();
34414
+ }
34415
+ return value;
34416
+ };
34417
+ })(util || (util = {}));
34418
+ var objectUtil;
34419
+ (function (objectUtil) {
34420
+ objectUtil.mergeShapes = (first, second) => {
34421
+ return {
34422
+ ...first,
34423
+ ...second, // second overwrites first
34424
+ };
34425
+ };
34426
+ })(objectUtil || (objectUtil = {}));
34427
+ const ZodParsedType = util.arrayToEnum([
34428
+ "string",
34429
+ "nan",
34430
+ "number",
34431
+ "integer",
34432
+ "float",
34433
+ "boolean",
34434
+ "date",
34435
+ "bigint",
34436
+ "symbol",
34437
+ "function",
34438
+ "undefined",
34439
+ "null",
34440
+ "array",
34441
+ "object",
34442
+ "unknown",
34443
+ "promise",
34444
+ "void",
34445
+ "never",
34446
+ "map",
34447
+ "set",
34448
+ ]);
34449
+ const getParsedType = (data) => {
34450
+ const t = typeof data;
34451
+ switch (t) {
34452
+ case "undefined":
34453
+ return ZodParsedType.undefined;
34454
+ case "string":
34455
+ return ZodParsedType.string;
34456
+ case "number":
34457
+ return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
34458
+ case "boolean":
34459
+ return ZodParsedType.boolean;
34460
+ case "function":
34461
+ return ZodParsedType.function;
34462
+ case "bigint":
34463
+ return ZodParsedType.bigint;
34464
+ case "symbol":
34465
+ return ZodParsedType.symbol;
34466
+ case "object":
34467
+ if (Array.isArray(data)) {
34468
+ return ZodParsedType.array;
34469
+ }
34470
+ if (data === null) {
34471
+ return ZodParsedType.null;
34472
+ }
34473
+ if (data.then &&
34474
+ typeof data.then === "function" &&
34475
+ data.catch &&
34476
+ typeof data.catch === "function") {
34477
+ return ZodParsedType.promise;
34478
+ }
34479
+ if (typeof Map !== "undefined" && data instanceof Map) {
34480
+ return ZodParsedType.map;
34481
+ }
34482
+ if (typeof Set !== "undefined" && data instanceof Set) {
34483
+ return ZodParsedType.set;
34484
+ }
34485
+ if (typeof Date !== "undefined" && data instanceof Date) {
34486
+ return ZodParsedType.date;
34487
+ }
34488
+ return ZodParsedType.object;
34489
+ default:
34490
+ return ZodParsedType.unknown;
34491
+ }
34492
+ };
34493
+
34494
+ const ZodIssueCode = util.arrayToEnum([
34495
+ "invalid_type",
34496
+ "invalid_literal",
34497
+ "custom",
34498
+ "invalid_union",
34499
+ "invalid_union_discriminator",
34500
+ "invalid_enum_value",
34501
+ "unrecognized_keys",
34502
+ "invalid_arguments",
34503
+ "invalid_return_type",
34504
+ "invalid_date",
34505
+ "invalid_string",
34506
+ "too_small",
34507
+ "too_big",
34508
+ "invalid_intersection_types",
34509
+ "not_multiple_of",
34510
+ "not_finite",
34511
+ ]);
34512
+ const quotelessJson = (obj) => {
34513
+ const json = JSON.stringify(obj, null, 2);
34514
+ return json.replace(/"([^"]+)":/g, "$1:");
34515
+ };
34516
+ class ZodError extends Error {
34517
+ constructor(issues) {
34518
+ super();
34519
+ this.issues = [];
34520
+ this.addIssue = (sub) => {
34521
+ this.issues = [...this.issues, sub];
34522
+ };
34523
+ this.addIssues = (subs = []) => {
34524
+ this.issues = [...this.issues, ...subs];
34525
+ };
34526
+ const actualProto = new.target.prototype;
34527
+ if (Object.setPrototypeOf) {
34528
+ // eslint-disable-next-line ban/ban
34529
+ Object.setPrototypeOf(this, actualProto);
34530
+ }
34531
+ else {
34532
+ this.__proto__ = actualProto;
34533
+ }
34534
+ this.name = "ZodError";
34535
+ this.issues = issues;
34536
+ }
34537
+ get errors() {
34538
+ return this.issues;
34539
+ }
34540
+ format(_mapper) {
34541
+ const mapper = _mapper ||
34542
+ function (issue) {
34543
+ return issue.message;
34544
+ };
34545
+ const fieldErrors = { _errors: [] };
34546
+ const processError = (error) => {
34547
+ for (const issue of error.issues) {
34548
+ if (issue.code === "invalid_union") {
34549
+ issue.unionErrors.map(processError);
34550
+ }
34551
+ else if (issue.code === "invalid_return_type") {
34552
+ processError(issue.returnTypeError);
34553
+ }
34554
+ else if (issue.code === "invalid_arguments") {
34555
+ processError(issue.argumentsError);
34556
+ }
34557
+ else if (issue.path.length === 0) {
34558
+ fieldErrors._errors.push(mapper(issue));
34559
+ }
34560
+ else {
34561
+ let curr = fieldErrors;
34562
+ let i = 0;
34563
+ while (i < issue.path.length) {
34564
+ const el = issue.path[i];
34565
+ const terminal = i === issue.path.length - 1;
34566
+ if (!terminal) {
34567
+ curr[el] = curr[el] || { _errors: [] };
34568
+ // if (typeof el === "string") {
34569
+ // curr[el] = curr[el] || { _errors: [] };
34570
+ // } else if (typeof el === "number") {
34571
+ // const errorArray: any = [];
34572
+ // errorArray._errors = [];
34573
+ // curr[el] = curr[el] || errorArray;
34574
+ // }
34575
+ }
34576
+ else {
34577
+ curr[el] = curr[el] || { _errors: [] };
34578
+ curr[el]._errors.push(mapper(issue));
34579
+ }
34580
+ curr = curr[el];
34581
+ i++;
34582
+ }
34583
+ }
34584
+ }
34585
+ };
34586
+ processError(this);
34587
+ return fieldErrors;
34588
+ }
34589
+ toString() {
34590
+ return this.message;
34591
+ }
34592
+ get message() {
34593
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
34594
+ }
34595
+ get isEmpty() {
34596
+ return this.issues.length === 0;
34597
+ }
34598
+ flatten(mapper = (issue) => issue.message) {
34599
+ const fieldErrors = {};
34600
+ const formErrors = [];
34601
+ for (const sub of this.issues) {
34602
+ if (sub.path.length > 0) {
34603
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
34604
+ fieldErrors[sub.path[0]].push(mapper(sub));
34605
+ }
34606
+ else {
34607
+ formErrors.push(mapper(sub));
34608
+ }
34609
+ }
34610
+ return { formErrors, fieldErrors };
34611
+ }
34612
+ get formErrors() {
34613
+ return this.flatten();
34614
+ }
34615
+ }
34616
+ ZodError.create = (issues) => {
34617
+ const error = new ZodError(issues);
34618
+ return error;
34619
+ };
34620
+
34621
+ const errorMap = (issue, _ctx) => {
34622
+ let message;
34623
+ switch (issue.code) {
34624
+ case ZodIssueCode.invalid_type:
34625
+ if (issue.received === ZodParsedType.undefined) {
34626
+ message = "Required";
34627
+ }
34628
+ else {
34629
+ message = `Expected ${issue.expected}, received ${issue.received}`;
34630
+ }
34631
+ break;
34632
+ case ZodIssueCode.invalid_literal:
34633
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
34634
+ break;
34635
+ case ZodIssueCode.unrecognized_keys:
34636
+ message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
34637
+ break;
34638
+ case ZodIssueCode.invalid_union:
34639
+ message = `Invalid input`;
34640
+ break;
34641
+ case ZodIssueCode.invalid_union_discriminator:
34642
+ message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
34643
+ break;
34644
+ case ZodIssueCode.invalid_enum_value:
34645
+ message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
34646
+ break;
34647
+ case ZodIssueCode.invalid_arguments:
34648
+ message = `Invalid function arguments`;
34649
+ break;
34650
+ case ZodIssueCode.invalid_return_type:
34651
+ message = `Invalid function return type`;
34652
+ break;
34653
+ case ZodIssueCode.invalid_date:
34654
+ message = `Invalid date`;
34655
+ break;
34656
+ case ZodIssueCode.invalid_string:
34657
+ if (typeof issue.validation === "object") {
34658
+ if ("includes" in issue.validation) {
34659
+ message = `Invalid input: must include "${issue.validation.includes}"`;
34660
+ if (typeof issue.validation.position === "number") {
34661
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
34662
+ }
34663
+ }
34664
+ else if ("startsWith" in issue.validation) {
34665
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
34666
+ }
34667
+ else if ("endsWith" in issue.validation) {
34668
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
34669
+ }
34670
+ else {
34671
+ util.assertNever(issue.validation);
34672
+ }
34673
+ }
34674
+ else if (issue.validation !== "regex") {
34675
+ message = `Invalid ${issue.validation}`;
34676
+ }
34677
+ else {
34678
+ message = "Invalid";
34679
+ }
34680
+ break;
34681
+ case ZodIssueCode.too_small:
34682
+ if (issue.type === "array")
34683
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
34684
+ else if (issue.type === "string")
34685
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
34686
+ else if (issue.type === "number")
34687
+ message = `Number must be ${issue.exact
34688
+ ? `exactly equal to `
34689
+ : issue.inclusive
34690
+ ? `greater than or equal to `
34691
+ : `greater than `}${issue.minimum}`;
34692
+ else if (issue.type === "date")
34693
+ message = `Date must be ${issue.exact
34694
+ ? `exactly equal to `
34695
+ : issue.inclusive
34696
+ ? `greater than or equal to `
34697
+ : `greater than `}${new Date(Number(issue.minimum))}`;
34698
+ else
34699
+ message = "Invalid input";
34700
+ break;
34701
+ case ZodIssueCode.too_big:
34702
+ if (issue.type === "array")
34703
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
34704
+ else if (issue.type === "string")
34705
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
34706
+ else if (issue.type === "number")
34707
+ message = `Number must be ${issue.exact
34708
+ ? `exactly`
34709
+ : issue.inclusive
34710
+ ? `less than or equal to`
34711
+ : `less than`} ${issue.maximum}`;
34712
+ else if (issue.type === "bigint")
34713
+ message = `BigInt must be ${issue.exact
34714
+ ? `exactly`
34715
+ : issue.inclusive
34716
+ ? `less than or equal to`
34717
+ : `less than`} ${issue.maximum}`;
34718
+ else if (issue.type === "date")
34719
+ message = `Date must be ${issue.exact
34720
+ ? `exactly`
34721
+ : issue.inclusive
34722
+ ? `smaller than or equal to`
34723
+ : `smaller than`} ${new Date(Number(issue.maximum))}`;
34724
+ else
34725
+ message = "Invalid input";
34726
+ break;
34727
+ case ZodIssueCode.custom:
34728
+ message = `Invalid input`;
34729
+ break;
34730
+ case ZodIssueCode.invalid_intersection_types:
34731
+ message = `Intersection results could not be merged`;
34732
+ break;
34733
+ case ZodIssueCode.not_multiple_of:
34734
+ message = `Number must be a multiple of ${issue.multipleOf}`;
34735
+ break;
34736
+ case ZodIssueCode.not_finite:
34737
+ message = "Number must be finite";
34738
+ break;
34739
+ default:
34740
+ message = _ctx.defaultError;
34741
+ util.assertNever(issue);
34742
+ }
34743
+ return { message };
34744
+ };
34745
+
34746
+ let overrideErrorMap = errorMap;
34747
+ function setErrorMap(map) {
34748
+ overrideErrorMap = map;
34749
+ }
34750
+ function getErrorMap() {
34751
+ return overrideErrorMap;
34752
+ }
34753
+
34754
+ const makeIssue = (params) => {
34755
+ const { data, path, errorMaps, issueData } = params;
34756
+ const fullPath = [...path, ...(issueData.path || [])];
34757
+ const fullIssue = {
34758
+ ...issueData,
34759
+ path: fullPath,
34760
+ };
34761
+ let errorMessage = "";
34762
+ const maps = errorMaps
34763
+ .filter((m) => !!m)
34764
+ .slice()
34765
+ .reverse();
34766
+ for (const map of maps) {
34767
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
34768
+ }
34769
+ return {
34770
+ ...issueData,
34771
+ path: fullPath,
34772
+ message: issueData.message || errorMessage,
34773
+ };
34774
+ };
34775
+ const EMPTY_PATH = [];
34776
+ function addIssueToContext(ctx, issueData) {
34777
+ const issue = makeIssue({
34778
+ issueData: issueData,
34779
+ data: ctx.data,
34780
+ path: ctx.path,
34781
+ errorMaps: [
34782
+ ctx.common.contextualErrorMap,
34783
+ ctx.schemaErrorMap,
34784
+ getErrorMap(),
34785
+ errorMap, // then global default map
34786
+ ].filter((x) => !!x),
34787
+ });
34788
+ ctx.common.issues.push(issue);
34789
+ }
34790
+ class ParseStatus {
34791
+ constructor() {
34792
+ this.value = "valid";
34793
+ }
34794
+ dirty() {
34795
+ if (this.value === "valid")
34796
+ this.value = "dirty";
34797
+ }
34798
+ abort() {
34799
+ if (this.value !== "aborted")
34800
+ this.value = "aborted";
34801
+ }
34802
+ static mergeArray(status, results) {
34803
+ const arrayValue = [];
34804
+ for (const s of results) {
34805
+ if (s.status === "aborted")
34806
+ return INVALID;
34807
+ if (s.status === "dirty")
34808
+ status.dirty();
34809
+ arrayValue.push(s.value);
34810
+ }
34811
+ return { status: status.value, value: arrayValue };
34812
+ }
34813
+ static async mergeObjectAsync(status, pairs) {
34814
+ const syncPairs = [];
34815
+ for (const pair of pairs) {
34816
+ syncPairs.push({
34817
+ key: await pair.key,
34818
+ value: await pair.value,
34819
+ });
34820
+ }
34821
+ return ParseStatus.mergeObjectSync(status, syncPairs);
34822
+ }
34823
+ static mergeObjectSync(status, pairs) {
34824
+ const finalObject = {};
34825
+ for (const pair of pairs) {
34826
+ const { key, value } = pair;
34827
+ if (key.status === "aborted")
34828
+ return INVALID;
34829
+ if (value.status === "aborted")
34830
+ return INVALID;
34831
+ if (key.status === "dirty")
34832
+ status.dirty();
34833
+ if (value.status === "dirty")
34834
+ status.dirty();
34835
+ if (key.value !== "__proto__" &&
34836
+ (typeof value.value !== "undefined" || pair.alwaysSet)) {
34837
+ finalObject[key.value] = value.value;
34838
+ }
34839
+ }
34840
+ return { status: status.value, value: finalObject };
34841
+ }
34842
+ }
34843
+ const INVALID = Object.freeze({
34844
+ status: "aborted",
34845
+ });
34846
+ const DIRTY = (value) => ({ status: "dirty", value });
34847
+ const OK = (value) => ({ status: "valid", value });
34848
+ const isAborted = (x) => x.status === "aborted";
34849
+ const isDirty = (x) => x.status === "dirty";
34850
+ const isValid = (x) => x.status === "valid";
34851
+ const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
34852
+
34853
+ var errorUtil;
34854
+ (function (errorUtil) {
34855
+ errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
34856
+ errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
34857
+ })(errorUtil || (errorUtil = {}));
34858
+
34859
+ class ParseInputLazyPath {
34860
+ constructor(parent, value, path, key) {
34861
+ this._cachedPath = [];
34862
+ this.parent = parent;
34863
+ this.data = value;
34864
+ this._path = path;
34865
+ this._key = key;
34866
+ }
34867
+ get path() {
34868
+ if (!this._cachedPath.length) {
34869
+ if (this._key instanceof Array) {
34870
+ this._cachedPath.push(...this._path, ...this._key);
34871
+ }
34872
+ else {
34873
+ this._cachedPath.push(...this._path, this._key);
34874
+ }
34875
+ }
34876
+ return this._cachedPath;
34877
+ }
34878
+ }
34879
+ const handleResult = (ctx, result) => {
34880
+ if (isValid(result)) {
34881
+ return { success: true, data: result.value };
34882
+ }
34883
+ else {
34884
+ if (!ctx.common.issues.length) {
34885
+ throw new Error("Validation failed but no issues detected.");
34886
+ }
34887
+ return {
34888
+ success: false,
34889
+ get error() {
34890
+ if (this._error)
34891
+ return this._error;
34892
+ const error = new ZodError(ctx.common.issues);
34893
+ this._error = error;
34894
+ return this._error;
34895
+ },
34896
+ };
34897
+ }
34898
+ };
34899
+ function processCreateParams(params) {
34900
+ if (!params)
34901
+ return {};
34902
+ const { errorMap, invalid_type_error, required_error, description } = params;
34903
+ if (errorMap && (invalid_type_error || required_error)) {
34904
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
34905
+ }
34906
+ if (errorMap)
34907
+ return { errorMap: errorMap, description };
34908
+ const customMap = (iss, ctx) => {
34909
+ if (iss.code !== "invalid_type")
34910
+ return { message: ctx.defaultError };
34911
+ if (typeof ctx.data === "undefined") {
34912
+ return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError };
34913
+ }
34914
+ return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError };
34915
+ };
34916
+ return { errorMap: customMap, description };
34917
+ }
34918
+ class ZodType {
34919
+ constructor(def) {
34920
+ /** Alias of safeParseAsync */
34921
+ this.spa = this.safeParseAsync;
34922
+ this._def = def;
34923
+ this.parse = this.parse.bind(this);
34924
+ this.safeParse = this.safeParse.bind(this);
34925
+ this.parseAsync = this.parseAsync.bind(this);
34926
+ this.safeParseAsync = this.safeParseAsync.bind(this);
34927
+ this.spa = this.spa.bind(this);
34928
+ this.refine = this.refine.bind(this);
34929
+ this.refinement = this.refinement.bind(this);
34930
+ this.superRefine = this.superRefine.bind(this);
34931
+ this.optional = this.optional.bind(this);
34932
+ this.nullable = this.nullable.bind(this);
34933
+ this.nullish = this.nullish.bind(this);
34934
+ this.array = this.array.bind(this);
34935
+ this.promise = this.promise.bind(this);
34936
+ this.or = this.or.bind(this);
34937
+ this.and = this.and.bind(this);
34938
+ this.transform = this.transform.bind(this);
34939
+ this.brand = this.brand.bind(this);
34940
+ this.default = this.default.bind(this);
34941
+ this.catch = this.catch.bind(this);
34942
+ this.describe = this.describe.bind(this);
34943
+ this.pipe = this.pipe.bind(this);
34944
+ this.readonly = this.readonly.bind(this);
34945
+ this.isNullable = this.isNullable.bind(this);
34946
+ this.isOptional = this.isOptional.bind(this);
34947
+ }
34948
+ get description() {
34949
+ return this._def.description;
34950
+ }
34951
+ _getType(input) {
34952
+ return getParsedType(input.data);
34953
+ }
34954
+ _getOrReturnCtx(input, ctx) {
34955
+ return (ctx || {
34956
+ common: input.parent.common,
34957
+ data: input.data,
34958
+ parsedType: getParsedType(input.data),
34959
+ schemaErrorMap: this._def.errorMap,
34960
+ path: input.path,
34961
+ parent: input.parent,
34962
+ });
34963
+ }
34964
+ _processInputParams(input) {
34965
+ return {
34966
+ status: new ParseStatus(),
34967
+ ctx: {
34968
+ common: input.parent.common,
34969
+ data: input.data,
34970
+ parsedType: getParsedType(input.data),
34971
+ schemaErrorMap: this._def.errorMap,
34972
+ path: input.path,
34973
+ parent: input.parent,
34974
+ },
34975
+ };
34976
+ }
34977
+ _parseSync(input) {
34978
+ const result = this._parse(input);
34979
+ if (isAsync(result)) {
34980
+ throw new Error("Synchronous parse encountered promise.");
34981
+ }
34982
+ return result;
34983
+ }
34984
+ _parseAsync(input) {
34985
+ const result = this._parse(input);
34986
+ return Promise.resolve(result);
34987
+ }
34988
+ parse(data, params) {
34989
+ const result = this.safeParse(data, params);
34990
+ if (result.success)
34991
+ return result.data;
34992
+ throw result.error;
34993
+ }
34994
+ safeParse(data, params) {
34995
+ var _a;
34996
+ const ctx = {
34997
+ common: {
34998
+ issues: [],
34999
+ async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
35000
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
35001
+ },
35002
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
35003
+ schemaErrorMap: this._def.errorMap,
35004
+ parent: null,
35005
+ data,
35006
+ parsedType: getParsedType(data),
35007
+ };
35008
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
35009
+ return handleResult(ctx, result);
35010
+ }
35011
+ async parseAsync(data, params) {
35012
+ const result = await this.safeParseAsync(data, params);
35013
+ if (result.success)
35014
+ return result.data;
35015
+ throw result.error;
35016
+ }
35017
+ async safeParseAsync(data, params) {
35018
+ const ctx = {
35019
+ common: {
35020
+ issues: [],
35021
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
35022
+ async: true,
35023
+ },
35024
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
35025
+ schemaErrorMap: this._def.errorMap,
35026
+ parent: null,
35027
+ data,
35028
+ parsedType: getParsedType(data),
35029
+ };
35030
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
35031
+ const result = await (isAsync(maybeAsyncResult)
35032
+ ? maybeAsyncResult
35033
+ : Promise.resolve(maybeAsyncResult));
35034
+ return handleResult(ctx, result);
35035
+ }
35036
+ refine(check, message) {
35037
+ const getIssueProperties = (val) => {
35038
+ if (typeof message === "string" || typeof message === "undefined") {
35039
+ return { message };
35040
+ }
35041
+ else if (typeof message === "function") {
35042
+ return message(val);
35043
+ }
35044
+ else {
35045
+ return message;
35046
+ }
35047
+ };
35048
+ return this._refinement((val, ctx) => {
35049
+ const result = check(val);
35050
+ const setError = () => ctx.addIssue({
35051
+ code: ZodIssueCode.custom,
35052
+ ...getIssueProperties(val),
35053
+ });
35054
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
35055
+ return result.then((data) => {
35056
+ if (!data) {
35057
+ setError();
35058
+ return false;
35059
+ }
35060
+ else {
35061
+ return true;
35062
+ }
35063
+ });
35064
+ }
35065
+ if (!result) {
35066
+ setError();
35067
+ return false;
35068
+ }
35069
+ else {
35070
+ return true;
35071
+ }
35072
+ });
35073
+ }
35074
+ refinement(check, refinementData) {
35075
+ return this._refinement((val, ctx) => {
35076
+ if (!check(val)) {
35077
+ ctx.addIssue(typeof refinementData === "function"
35078
+ ? refinementData(val, ctx)
35079
+ : refinementData);
35080
+ return false;
35081
+ }
35082
+ else {
35083
+ return true;
35084
+ }
35085
+ });
35086
+ }
35087
+ _refinement(refinement) {
35088
+ return new ZodEffects({
35089
+ schema: this,
35090
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
35091
+ effect: { type: "refinement", refinement },
35092
+ });
35093
+ }
35094
+ superRefine(refinement) {
35095
+ return this._refinement(refinement);
35096
+ }
35097
+ optional() {
35098
+ return ZodOptional.create(this, this._def);
35099
+ }
35100
+ nullable() {
35101
+ return ZodNullable.create(this, this._def);
35102
+ }
35103
+ nullish() {
35104
+ return this.nullable().optional();
35105
+ }
35106
+ array() {
35107
+ return ZodArray.create(this, this._def);
35108
+ }
35109
+ promise() {
35110
+ return ZodPromise.create(this, this._def);
35111
+ }
35112
+ or(option) {
35113
+ return ZodUnion.create([this, option], this._def);
35114
+ }
35115
+ and(incoming) {
35116
+ return ZodIntersection.create(this, incoming, this._def);
35117
+ }
35118
+ transform(transform) {
35119
+ return new ZodEffects({
35120
+ ...processCreateParams(this._def),
35121
+ schema: this,
35122
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
35123
+ effect: { type: "transform", transform },
35124
+ });
35125
+ }
35126
+ default(def) {
35127
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
35128
+ return new ZodDefault({
35129
+ ...processCreateParams(this._def),
35130
+ innerType: this,
35131
+ defaultValue: defaultValueFunc,
35132
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
35133
+ });
35134
+ }
35135
+ brand() {
35136
+ return new ZodBranded({
35137
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
35138
+ type: this,
35139
+ ...processCreateParams(this._def),
35140
+ });
35141
+ }
35142
+ catch(def) {
35143
+ const catchValueFunc = typeof def === "function" ? def : () => def;
35144
+ return new ZodCatch({
35145
+ ...processCreateParams(this._def),
35146
+ innerType: this,
35147
+ catchValue: catchValueFunc,
35148
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
35149
+ });
35150
+ }
35151
+ describe(description) {
35152
+ const This = this.constructor;
35153
+ return new This({
35154
+ ...this._def,
35155
+ description,
35156
+ });
35157
+ }
35158
+ pipe(target) {
35159
+ return ZodPipeline.create(this, target);
35160
+ }
35161
+ readonly() {
35162
+ return ZodReadonly.create(this);
35163
+ }
35164
+ isOptional() {
35165
+ return this.safeParse(undefined).success;
35166
+ }
35167
+ isNullable() {
35168
+ return this.safeParse(null).success;
35169
+ }
35170
+ }
35171
+ const cuidRegex = /^c[^\s-]{8,}$/i;
35172
+ const cuid2Regex = /^[a-z][a-z0-9]*$/;
35173
+ const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
35174
+ // const uuidRegex =
35175
+ // /^([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;
35176
+ 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;
35177
+ // from https://stackoverflow.com/a/46181/1550155
35178
+ // old version: too slow, didn't support unicode
35179
+ // 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;
35180
+ //old email regex
35181
+ // const emailRegex = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@((?!-)([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{1,})[^-<>()[\].,;:\s@"]$/i;
35182
+ // eslint-disable-next-line
35183
+ // const emailRegex =
35184
+ // /^(([^<>()[\]\\.,;:\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,})+))$/;
35185
+ // const emailRegex =
35186
+ // /^[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])?)*$/;
35187
+ // const emailRegex =
35188
+ // /^(?:[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;
35189
+ const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
35190
+ // const emailRegex =
35191
+ // /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
35192
+ // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
35193
+ const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
35194
+ let emojiRegex;
35195
+ const ipv4Regex = /^(((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}))$/;
35196
+ const ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
35197
+ // Adapted from https://stackoverflow.com/a/3143231
35198
+ const datetimeRegex = (args) => {
35199
+ if (args.precision) {
35200
+ if (args.offset) {
35201
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
35202
+ }
35203
+ else {
35204
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
35205
+ }
35206
+ }
35207
+ else if (args.precision === 0) {
35208
+ if (args.offset) {
35209
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
35210
+ }
35211
+ else {
35212
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
35213
+ }
35214
+ }
35215
+ else {
35216
+ if (args.offset) {
35217
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
35218
+ }
35219
+ else {
35220
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
35221
+ }
35222
+ }
35223
+ };
35224
+ function isValidIP(ip, version) {
35225
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
35226
+ return true;
35227
+ }
35228
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
35229
+ return true;
35230
+ }
35231
+ return false;
35232
+ }
35233
+ class ZodString extends ZodType {
35234
+ _parse(input) {
35235
+ if (this._def.coerce) {
35236
+ input.data = String(input.data);
35237
+ }
35238
+ const parsedType = this._getType(input);
35239
+ if (parsedType !== ZodParsedType.string) {
35240
+ const ctx = this._getOrReturnCtx(input);
35241
+ addIssueToContext(ctx, {
35242
+ code: ZodIssueCode.invalid_type,
35243
+ expected: ZodParsedType.string,
35244
+ received: ctx.parsedType,
35245
+ }
35246
+ //
35247
+ );
35248
+ return INVALID;
35249
+ }
35250
+ const status = new ParseStatus();
35251
+ let ctx = undefined;
35252
+ for (const check of this._def.checks) {
35253
+ if (check.kind === "min") {
35254
+ if (input.data.length < check.value) {
35255
+ ctx = this._getOrReturnCtx(input, ctx);
35256
+ addIssueToContext(ctx, {
35257
+ code: ZodIssueCode.too_small,
35258
+ minimum: check.value,
35259
+ type: "string",
35260
+ inclusive: true,
35261
+ exact: false,
35262
+ message: check.message,
35263
+ });
35264
+ status.dirty();
35265
+ }
35266
+ }
35267
+ else if (check.kind === "max") {
35268
+ if (input.data.length > check.value) {
35269
+ ctx = this._getOrReturnCtx(input, ctx);
35270
+ addIssueToContext(ctx, {
35271
+ code: ZodIssueCode.too_big,
35272
+ maximum: check.value,
35273
+ type: "string",
35274
+ inclusive: true,
35275
+ exact: false,
35276
+ message: check.message,
35277
+ });
35278
+ status.dirty();
35279
+ }
35280
+ }
35281
+ else if (check.kind === "length") {
35282
+ const tooBig = input.data.length > check.value;
35283
+ const tooSmall = input.data.length < check.value;
35284
+ if (tooBig || tooSmall) {
35285
+ ctx = this._getOrReturnCtx(input, ctx);
35286
+ if (tooBig) {
35287
+ addIssueToContext(ctx, {
35288
+ code: ZodIssueCode.too_big,
35289
+ maximum: check.value,
35290
+ type: "string",
35291
+ inclusive: true,
35292
+ exact: true,
35293
+ message: check.message,
35294
+ });
35295
+ }
35296
+ else if (tooSmall) {
35297
+ addIssueToContext(ctx, {
35298
+ code: ZodIssueCode.too_small,
35299
+ minimum: check.value,
35300
+ type: "string",
35301
+ inclusive: true,
35302
+ exact: true,
35303
+ message: check.message,
35304
+ });
35305
+ }
35306
+ status.dirty();
35307
+ }
35308
+ }
35309
+ else if (check.kind === "email") {
35310
+ if (!emailRegex.test(input.data)) {
35311
+ ctx = this._getOrReturnCtx(input, ctx);
35312
+ addIssueToContext(ctx, {
35313
+ validation: "email",
35314
+ code: ZodIssueCode.invalid_string,
35315
+ message: check.message,
35316
+ });
35317
+ status.dirty();
35318
+ }
35319
+ }
35320
+ else if (check.kind === "emoji") {
35321
+ if (!emojiRegex) {
35322
+ emojiRegex = new RegExp(_emojiRegex, "u");
35323
+ }
35324
+ if (!emojiRegex.test(input.data)) {
35325
+ ctx = this._getOrReturnCtx(input, ctx);
35326
+ addIssueToContext(ctx, {
35327
+ validation: "emoji",
35328
+ code: ZodIssueCode.invalid_string,
35329
+ message: check.message,
35330
+ });
35331
+ status.dirty();
35332
+ }
35333
+ }
35334
+ else if (check.kind === "uuid") {
35335
+ if (!uuidRegex.test(input.data)) {
35336
+ ctx = this._getOrReturnCtx(input, ctx);
35337
+ addIssueToContext(ctx, {
35338
+ validation: "uuid",
35339
+ code: ZodIssueCode.invalid_string,
35340
+ message: check.message,
35341
+ });
35342
+ status.dirty();
35343
+ }
35344
+ }
35345
+ else if (check.kind === "cuid") {
35346
+ if (!cuidRegex.test(input.data)) {
35347
+ ctx = this._getOrReturnCtx(input, ctx);
35348
+ addIssueToContext(ctx, {
35349
+ validation: "cuid",
35350
+ code: ZodIssueCode.invalid_string,
35351
+ message: check.message,
35352
+ });
35353
+ status.dirty();
35354
+ }
35355
+ }
35356
+ else if (check.kind === "cuid2") {
35357
+ if (!cuid2Regex.test(input.data)) {
35358
+ ctx = this._getOrReturnCtx(input, ctx);
35359
+ addIssueToContext(ctx, {
35360
+ validation: "cuid2",
35361
+ code: ZodIssueCode.invalid_string,
35362
+ message: check.message,
35363
+ });
35364
+ status.dirty();
35365
+ }
35366
+ }
35367
+ else if (check.kind === "ulid") {
35368
+ if (!ulidRegex.test(input.data)) {
35369
+ ctx = this._getOrReturnCtx(input, ctx);
35370
+ addIssueToContext(ctx, {
35371
+ validation: "ulid",
35372
+ code: ZodIssueCode.invalid_string,
35373
+ message: check.message,
35374
+ });
35375
+ status.dirty();
35376
+ }
35377
+ }
35378
+ else if (check.kind === "url") {
35379
+ try {
35380
+ new URL(input.data);
35381
+ }
35382
+ catch (_a) {
35383
+ ctx = this._getOrReturnCtx(input, ctx);
35384
+ addIssueToContext(ctx, {
35385
+ validation: "url",
35386
+ code: ZodIssueCode.invalid_string,
35387
+ message: check.message,
35388
+ });
35389
+ status.dirty();
35390
+ }
35391
+ }
35392
+ else if (check.kind === "regex") {
35393
+ check.regex.lastIndex = 0;
35394
+ const testResult = check.regex.test(input.data);
35395
+ if (!testResult) {
35396
+ ctx = this._getOrReturnCtx(input, ctx);
35397
+ addIssueToContext(ctx, {
35398
+ validation: "regex",
35399
+ code: ZodIssueCode.invalid_string,
35400
+ message: check.message,
35401
+ });
35402
+ status.dirty();
35403
+ }
35404
+ }
35405
+ else if (check.kind === "trim") {
35406
+ input.data = input.data.trim();
35407
+ }
35408
+ else if (check.kind === "includes") {
35409
+ if (!input.data.includes(check.value, check.position)) {
35410
+ ctx = this._getOrReturnCtx(input, ctx);
35411
+ addIssueToContext(ctx, {
35412
+ code: ZodIssueCode.invalid_string,
35413
+ validation: { includes: check.value, position: check.position },
35414
+ message: check.message,
35415
+ });
35416
+ status.dirty();
35417
+ }
35418
+ }
35419
+ else if (check.kind === "toLowerCase") {
35420
+ input.data = input.data.toLowerCase();
35421
+ }
35422
+ else if (check.kind === "toUpperCase") {
35423
+ input.data = input.data.toUpperCase();
35424
+ }
35425
+ else if (check.kind === "startsWith") {
35426
+ if (!input.data.startsWith(check.value)) {
35427
+ ctx = this._getOrReturnCtx(input, ctx);
35428
+ addIssueToContext(ctx, {
35429
+ code: ZodIssueCode.invalid_string,
35430
+ validation: { startsWith: check.value },
35431
+ message: check.message,
35432
+ });
35433
+ status.dirty();
35434
+ }
35435
+ }
35436
+ else if (check.kind === "endsWith") {
35437
+ if (!input.data.endsWith(check.value)) {
35438
+ ctx = this._getOrReturnCtx(input, ctx);
35439
+ addIssueToContext(ctx, {
35440
+ code: ZodIssueCode.invalid_string,
35441
+ validation: { endsWith: check.value },
35442
+ message: check.message,
35443
+ });
35444
+ status.dirty();
35445
+ }
35446
+ }
35447
+ else if (check.kind === "datetime") {
35448
+ const regex = datetimeRegex(check);
35449
+ if (!regex.test(input.data)) {
35450
+ ctx = this._getOrReturnCtx(input, ctx);
35451
+ addIssueToContext(ctx, {
35452
+ code: ZodIssueCode.invalid_string,
35453
+ validation: "datetime",
35454
+ message: check.message,
35455
+ });
35456
+ status.dirty();
35457
+ }
35458
+ }
35459
+ else if (check.kind === "ip") {
35460
+ if (!isValidIP(input.data, check.version)) {
35461
+ ctx = this._getOrReturnCtx(input, ctx);
35462
+ addIssueToContext(ctx, {
35463
+ validation: "ip",
35464
+ code: ZodIssueCode.invalid_string,
35465
+ message: check.message,
35466
+ });
35467
+ status.dirty();
35468
+ }
35469
+ }
35470
+ else {
35471
+ util.assertNever(check);
35472
+ }
35473
+ }
35474
+ return { status: status.value, value: input.data };
35475
+ }
35476
+ _regex(regex, validation, message) {
35477
+ return this.refinement((data) => regex.test(data), {
35478
+ validation,
35479
+ code: ZodIssueCode.invalid_string,
35480
+ ...errorUtil.errToObj(message),
35481
+ });
35482
+ }
35483
+ _addCheck(check) {
35484
+ return new ZodString({
35485
+ ...this._def,
35486
+ checks: [...this._def.checks, check],
35487
+ });
35488
+ }
35489
+ email(message) {
35490
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
35491
+ }
35492
+ url(message) {
35493
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
35494
+ }
35495
+ emoji(message) {
35496
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
35497
+ }
35498
+ uuid(message) {
35499
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
35500
+ }
35501
+ cuid(message) {
35502
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
35503
+ }
35504
+ cuid2(message) {
35505
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
35506
+ }
35507
+ ulid(message) {
35508
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
35509
+ }
35510
+ ip(options) {
35511
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
35512
+ }
35513
+ datetime(options) {
35514
+ var _a;
35515
+ if (typeof options === "string") {
35516
+ return this._addCheck({
35517
+ kind: "datetime",
35518
+ precision: null,
35519
+ offset: false,
35520
+ message: options,
35521
+ });
35522
+ }
35523
+ return this._addCheck({
35524
+ kind: "datetime",
35525
+ precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
35526
+ offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
35527
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
35528
+ });
35529
+ }
35530
+ regex(regex, message) {
35531
+ return this._addCheck({
35532
+ kind: "regex",
35533
+ regex: regex,
35534
+ ...errorUtil.errToObj(message),
35535
+ });
35536
+ }
35537
+ includes(value, options) {
35538
+ return this._addCheck({
35539
+ kind: "includes",
35540
+ value: value,
35541
+ position: options === null || options === void 0 ? void 0 : options.position,
35542
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
35543
+ });
35544
+ }
35545
+ startsWith(value, message) {
35546
+ return this._addCheck({
35547
+ kind: "startsWith",
35548
+ value: value,
35549
+ ...errorUtil.errToObj(message),
35550
+ });
35551
+ }
35552
+ endsWith(value, message) {
35553
+ return this._addCheck({
35554
+ kind: "endsWith",
35555
+ value: value,
35556
+ ...errorUtil.errToObj(message),
35557
+ });
35558
+ }
35559
+ min(minLength, message) {
35560
+ return this._addCheck({
35561
+ kind: "min",
35562
+ value: minLength,
35563
+ ...errorUtil.errToObj(message),
35564
+ });
35565
+ }
35566
+ max(maxLength, message) {
35567
+ return this._addCheck({
35568
+ kind: "max",
35569
+ value: maxLength,
35570
+ ...errorUtil.errToObj(message),
35571
+ });
35572
+ }
35573
+ length(len, message) {
35574
+ return this._addCheck({
35575
+ kind: "length",
35576
+ value: len,
35577
+ ...errorUtil.errToObj(message),
35578
+ });
35579
+ }
35580
+ /**
35581
+ * @deprecated Use z.string().min(1) instead.
35582
+ * @see {@link ZodString.min}
35583
+ */
35584
+ nonempty(message) {
35585
+ return this.min(1, errorUtil.errToObj(message));
35586
+ }
35587
+ trim() {
35588
+ return new ZodString({
35589
+ ...this._def,
35590
+ checks: [...this._def.checks, { kind: "trim" }],
35591
+ });
35592
+ }
35593
+ toLowerCase() {
35594
+ return new ZodString({
35595
+ ...this._def,
35596
+ checks: [...this._def.checks, { kind: "toLowerCase" }],
35597
+ });
35598
+ }
35599
+ toUpperCase() {
35600
+ return new ZodString({
35601
+ ...this._def,
35602
+ checks: [...this._def.checks, { kind: "toUpperCase" }],
35603
+ });
35604
+ }
35605
+ get isDatetime() {
35606
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
35607
+ }
35608
+ get isEmail() {
35609
+ return !!this._def.checks.find((ch) => ch.kind === "email");
35610
+ }
35611
+ get isURL() {
35612
+ return !!this._def.checks.find((ch) => ch.kind === "url");
35613
+ }
35614
+ get isEmoji() {
35615
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
35616
+ }
35617
+ get isUUID() {
35618
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
35619
+ }
35620
+ get isCUID() {
35621
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
35622
+ }
35623
+ get isCUID2() {
35624
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
35625
+ }
35626
+ get isULID() {
35627
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
35628
+ }
35629
+ get isIP() {
35630
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
35631
+ }
35632
+ get minLength() {
35633
+ let min = null;
35634
+ for (const ch of this._def.checks) {
35635
+ if (ch.kind === "min") {
35636
+ if (min === null || ch.value > min)
35637
+ min = ch.value;
35638
+ }
35639
+ }
35640
+ return min;
35641
+ }
35642
+ get maxLength() {
35643
+ let max = null;
35644
+ for (const ch of this._def.checks) {
35645
+ if (ch.kind === "max") {
35646
+ if (max === null || ch.value < max)
35647
+ max = ch.value;
35648
+ }
35649
+ }
35650
+ return max;
35651
+ }
35652
+ }
35653
+ ZodString.create = (params) => {
35654
+ var _a;
35655
+ return new ZodString({
35656
+ checks: [],
35657
+ typeName: ZodFirstPartyTypeKind.ZodString,
35658
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
35659
+ ...processCreateParams(params),
35660
+ });
35661
+ };
35662
+ // https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
35663
+ function floatSafeRemainder(val, step) {
35664
+ const valDecCount = (val.toString().split(".")[1] || "").length;
35665
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
35666
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
35667
+ const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
35668
+ const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
35669
+ return (valInt % stepInt) / Math.pow(10, decCount);
35670
+ }
35671
+ class ZodNumber extends ZodType {
35672
+ constructor() {
35673
+ super(...arguments);
35674
+ this.min = this.gte;
35675
+ this.max = this.lte;
35676
+ this.step = this.multipleOf;
35677
+ }
35678
+ _parse(input) {
35679
+ if (this._def.coerce) {
35680
+ input.data = Number(input.data);
35681
+ }
35682
+ const parsedType = this._getType(input);
35683
+ if (parsedType !== ZodParsedType.number) {
35684
+ const ctx = this._getOrReturnCtx(input);
35685
+ addIssueToContext(ctx, {
35686
+ code: ZodIssueCode.invalid_type,
35687
+ expected: ZodParsedType.number,
35688
+ received: ctx.parsedType,
35689
+ });
35690
+ return INVALID;
35691
+ }
35692
+ let ctx = undefined;
35693
+ const status = new ParseStatus();
35694
+ for (const check of this._def.checks) {
35695
+ if (check.kind === "int") {
35696
+ if (!util.isInteger(input.data)) {
35697
+ ctx = this._getOrReturnCtx(input, ctx);
35698
+ addIssueToContext(ctx, {
35699
+ code: ZodIssueCode.invalid_type,
35700
+ expected: "integer",
35701
+ received: "float",
35702
+ message: check.message,
35703
+ });
35704
+ status.dirty();
35705
+ }
35706
+ }
35707
+ else if (check.kind === "min") {
35708
+ const tooSmall = check.inclusive
35709
+ ? input.data < check.value
35710
+ : input.data <= check.value;
35711
+ if (tooSmall) {
35712
+ ctx = this._getOrReturnCtx(input, ctx);
35713
+ addIssueToContext(ctx, {
35714
+ code: ZodIssueCode.too_small,
35715
+ minimum: check.value,
35716
+ type: "number",
35717
+ inclusive: check.inclusive,
35718
+ exact: false,
35719
+ message: check.message,
35720
+ });
35721
+ status.dirty();
35722
+ }
35723
+ }
35724
+ else if (check.kind === "max") {
35725
+ const tooBig = check.inclusive
35726
+ ? input.data > check.value
35727
+ : input.data >= check.value;
35728
+ if (tooBig) {
35729
+ ctx = this._getOrReturnCtx(input, ctx);
35730
+ addIssueToContext(ctx, {
35731
+ code: ZodIssueCode.too_big,
35732
+ maximum: check.value,
35733
+ type: "number",
35734
+ inclusive: check.inclusive,
35735
+ exact: false,
35736
+ message: check.message,
35737
+ });
35738
+ status.dirty();
35739
+ }
35740
+ }
35741
+ else if (check.kind === "multipleOf") {
35742
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
35743
+ ctx = this._getOrReturnCtx(input, ctx);
35744
+ addIssueToContext(ctx, {
35745
+ code: ZodIssueCode.not_multiple_of,
35746
+ multipleOf: check.value,
35747
+ message: check.message,
35748
+ });
35749
+ status.dirty();
35750
+ }
35751
+ }
35752
+ else if (check.kind === "finite") {
35753
+ if (!Number.isFinite(input.data)) {
35754
+ ctx = this._getOrReturnCtx(input, ctx);
35755
+ addIssueToContext(ctx, {
35756
+ code: ZodIssueCode.not_finite,
35757
+ message: check.message,
35758
+ });
35759
+ status.dirty();
35760
+ }
35761
+ }
35762
+ else {
35763
+ util.assertNever(check);
35764
+ }
35765
+ }
35766
+ return { status: status.value, value: input.data };
35767
+ }
35768
+ gte(value, message) {
35769
+ return this.setLimit("min", value, true, errorUtil.toString(message));
35770
+ }
35771
+ gt(value, message) {
35772
+ return this.setLimit("min", value, false, errorUtil.toString(message));
35773
+ }
35774
+ lte(value, message) {
35775
+ return this.setLimit("max", value, true, errorUtil.toString(message));
35776
+ }
35777
+ lt(value, message) {
35778
+ return this.setLimit("max", value, false, errorUtil.toString(message));
35779
+ }
35780
+ setLimit(kind, value, inclusive, message) {
35781
+ return new ZodNumber({
35782
+ ...this._def,
35783
+ checks: [
35784
+ ...this._def.checks,
35785
+ {
35786
+ kind,
35787
+ value,
35788
+ inclusive,
35789
+ message: errorUtil.toString(message),
35790
+ },
35791
+ ],
35792
+ });
35793
+ }
35794
+ _addCheck(check) {
35795
+ return new ZodNumber({
35796
+ ...this._def,
35797
+ checks: [...this._def.checks, check],
35798
+ });
35799
+ }
35800
+ int(message) {
35801
+ return this._addCheck({
35802
+ kind: "int",
35803
+ message: errorUtil.toString(message),
35804
+ });
35805
+ }
35806
+ positive(message) {
35807
+ return this._addCheck({
35808
+ kind: "min",
35809
+ value: 0,
35810
+ inclusive: false,
35811
+ message: errorUtil.toString(message),
35812
+ });
35813
+ }
35814
+ negative(message) {
35815
+ return this._addCheck({
35816
+ kind: "max",
35817
+ value: 0,
35818
+ inclusive: false,
35819
+ message: errorUtil.toString(message),
35820
+ });
35821
+ }
35822
+ nonpositive(message) {
35823
+ return this._addCheck({
35824
+ kind: "max",
35825
+ value: 0,
35826
+ inclusive: true,
35827
+ message: errorUtil.toString(message),
35828
+ });
35829
+ }
35830
+ nonnegative(message) {
35831
+ return this._addCheck({
35832
+ kind: "min",
35833
+ value: 0,
35834
+ inclusive: true,
35835
+ message: errorUtil.toString(message),
35836
+ });
35837
+ }
35838
+ multipleOf(value, message) {
35839
+ return this._addCheck({
35840
+ kind: "multipleOf",
35841
+ value: value,
35842
+ message: errorUtil.toString(message),
35843
+ });
35844
+ }
35845
+ finite(message) {
35846
+ return this._addCheck({
35847
+ kind: "finite",
35848
+ message: errorUtil.toString(message),
35849
+ });
35850
+ }
35851
+ safe(message) {
35852
+ return this._addCheck({
35853
+ kind: "min",
35854
+ inclusive: true,
35855
+ value: Number.MIN_SAFE_INTEGER,
35856
+ message: errorUtil.toString(message),
35857
+ })._addCheck({
35858
+ kind: "max",
35859
+ inclusive: true,
35860
+ value: Number.MAX_SAFE_INTEGER,
35861
+ message: errorUtil.toString(message),
35862
+ });
35863
+ }
35864
+ get minValue() {
35865
+ let min = null;
35866
+ for (const ch of this._def.checks) {
35867
+ if (ch.kind === "min") {
35868
+ if (min === null || ch.value > min)
35869
+ min = ch.value;
35870
+ }
35871
+ }
35872
+ return min;
35873
+ }
35874
+ get maxValue() {
35875
+ let max = null;
35876
+ for (const ch of this._def.checks) {
35877
+ if (ch.kind === "max") {
35878
+ if (max === null || ch.value < max)
35879
+ max = ch.value;
35880
+ }
35881
+ }
35882
+ return max;
35883
+ }
35884
+ get isInt() {
35885
+ return !!this._def.checks.find((ch) => ch.kind === "int" ||
35886
+ (ch.kind === "multipleOf" && util.isInteger(ch.value)));
35887
+ }
35888
+ get isFinite() {
35889
+ let max = null, min = null;
35890
+ for (const ch of this._def.checks) {
35891
+ if (ch.kind === "finite" ||
35892
+ ch.kind === "int" ||
35893
+ ch.kind === "multipleOf") {
35894
+ return true;
35895
+ }
35896
+ else if (ch.kind === "min") {
35897
+ if (min === null || ch.value > min)
35898
+ min = ch.value;
35899
+ }
35900
+ else if (ch.kind === "max") {
35901
+ if (max === null || ch.value < max)
35902
+ max = ch.value;
35903
+ }
35904
+ }
35905
+ return Number.isFinite(min) && Number.isFinite(max);
35906
+ }
35907
+ }
35908
+ ZodNumber.create = (params) => {
35909
+ return new ZodNumber({
35910
+ checks: [],
35911
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
35912
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
35913
+ ...processCreateParams(params),
35914
+ });
35915
+ };
35916
+ class ZodBigInt extends ZodType {
35917
+ constructor() {
35918
+ super(...arguments);
35919
+ this.min = this.gte;
35920
+ this.max = this.lte;
35921
+ }
35922
+ _parse(input) {
35923
+ if (this._def.coerce) {
35924
+ input.data = BigInt(input.data);
35925
+ }
35926
+ const parsedType = this._getType(input);
35927
+ if (parsedType !== ZodParsedType.bigint) {
35928
+ const ctx = this._getOrReturnCtx(input);
35929
+ addIssueToContext(ctx, {
35930
+ code: ZodIssueCode.invalid_type,
35931
+ expected: ZodParsedType.bigint,
35932
+ received: ctx.parsedType,
35933
+ });
35934
+ return INVALID;
35935
+ }
35936
+ let ctx = undefined;
35937
+ const status = new ParseStatus();
35938
+ for (const check of this._def.checks) {
35939
+ if (check.kind === "min") {
35940
+ const tooSmall = check.inclusive
35941
+ ? input.data < check.value
35942
+ : input.data <= check.value;
35943
+ if (tooSmall) {
35944
+ ctx = this._getOrReturnCtx(input, ctx);
35945
+ addIssueToContext(ctx, {
35946
+ code: ZodIssueCode.too_small,
35947
+ type: "bigint",
35948
+ minimum: check.value,
35949
+ inclusive: check.inclusive,
35950
+ message: check.message,
35951
+ });
35952
+ status.dirty();
35953
+ }
35954
+ }
35955
+ else if (check.kind === "max") {
35956
+ const tooBig = check.inclusive
35957
+ ? input.data > check.value
35958
+ : input.data >= check.value;
35959
+ if (tooBig) {
35960
+ ctx = this._getOrReturnCtx(input, ctx);
35961
+ addIssueToContext(ctx, {
35962
+ code: ZodIssueCode.too_big,
35963
+ type: "bigint",
35964
+ maximum: check.value,
35965
+ inclusive: check.inclusive,
35966
+ message: check.message,
35967
+ });
35968
+ status.dirty();
35969
+ }
35970
+ }
35971
+ else if (check.kind === "multipleOf") {
35972
+ if (input.data % check.value !== BigInt(0)) {
35973
+ ctx = this._getOrReturnCtx(input, ctx);
35974
+ addIssueToContext(ctx, {
35975
+ code: ZodIssueCode.not_multiple_of,
35976
+ multipleOf: check.value,
35977
+ message: check.message,
35978
+ });
35979
+ status.dirty();
35980
+ }
35981
+ }
35982
+ else {
35983
+ util.assertNever(check);
35984
+ }
35985
+ }
35986
+ return { status: status.value, value: input.data };
35987
+ }
35988
+ gte(value, message) {
35989
+ return this.setLimit("min", value, true, errorUtil.toString(message));
35990
+ }
35991
+ gt(value, message) {
35992
+ return this.setLimit("min", value, false, errorUtil.toString(message));
35993
+ }
35994
+ lte(value, message) {
35995
+ return this.setLimit("max", value, true, errorUtil.toString(message));
35996
+ }
35997
+ lt(value, message) {
35998
+ return this.setLimit("max", value, false, errorUtil.toString(message));
35999
+ }
36000
+ setLimit(kind, value, inclusive, message) {
36001
+ return new ZodBigInt({
36002
+ ...this._def,
36003
+ checks: [
36004
+ ...this._def.checks,
36005
+ {
36006
+ kind,
36007
+ value,
36008
+ inclusive,
36009
+ message: errorUtil.toString(message),
36010
+ },
36011
+ ],
36012
+ });
36013
+ }
36014
+ _addCheck(check) {
36015
+ return new ZodBigInt({
36016
+ ...this._def,
36017
+ checks: [...this._def.checks, check],
36018
+ });
36019
+ }
36020
+ positive(message) {
36021
+ return this._addCheck({
36022
+ kind: "min",
36023
+ value: BigInt(0),
36024
+ inclusive: false,
36025
+ message: errorUtil.toString(message),
36026
+ });
36027
+ }
36028
+ negative(message) {
36029
+ return this._addCheck({
36030
+ kind: "max",
36031
+ value: BigInt(0),
36032
+ inclusive: false,
36033
+ message: errorUtil.toString(message),
36034
+ });
36035
+ }
36036
+ nonpositive(message) {
36037
+ return this._addCheck({
36038
+ kind: "max",
36039
+ value: BigInt(0),
36040
+ inclusive: true,
36041
+ message: errorUtil.toString(message),
36042
+ });
36043
+ }
36044
+ nonnegative(message) {
36045
+ return this._addCheck({
36046
+ kind: "min",
36047
+ value: BigInt(0),
36048
+ inclusive: true,
36049
+ message: errorUtil.toString(message),
36050
+ });
36051
+ }
36052
+ multipleOf(value, message) {
36053
+ return this._addCheck({
36054
+ kind: "multipleOf",
36055
+ value,
36056
+ message: errorUtil.toString(message),
36057
+ });
36058
+ }
36059
+ get minValue() {
36060
+ let min = null;
36061
+ for (const ch of this._def.checks) {
36062
+ if (ch.kind === "min") {
36063
+ if (min === null || ch.value > min)
36064
+ min = ch.value;
36065
+ }
36066
+ }
36067
+ return min;
36068
+ }
36069
+ get maxValue() {
36070
+ let max = null;
36071
+ for (const ch of this._def.checks) {
36072
+ if (ch.kind === "max") {
36073
+ if (max === null || ch.value < max)
36074
+ max = ch.value;
36075
+ }
36076
+ }
36077
+ return max;
36078
+ }
36079
+ }
36080
+ ZodBigInt.create = (params) => {
36081
+ var _a;
36082
+ return new ZodBigInt({
36083
+ checks: [],
36084
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
36085
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
36086
+ ...processCreateParams(params),
36087
+ });
36088
+ };
36089
+ class ZodBoolean extends ZodType {
36090
+ _parse(input) {
36091
+ if (this._def.coerce) {
36092
+ input.data = Boolean(input.data);
36093
+ }
36094
+ const parsedType = this._getType(input);
36095
+ if (parsedType !== ZodParsedType.boolean) {
36096
+ const ctx = this._getOrReturnCtx(input);
36097
+ addIssueToContext(ctx, {
36098
+ code: ZodIssueCode.invalid_type,
36099
+ expected: ZodParsedType.boolean,
36100
+ received: ctx.parsedType,
36101
+ });
36102
+ return INVALID;
36103
+ }
36104
+ return OK(input.data);
36105
+ }
36106
+ }
36107
+ ZodBoolean.create = (params) => {
36108
+ return new ZodBoolean({
36109
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
36110
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
36111
+ ...processCreateParams(params),
36112
+ });
36113
+ };
36114
+ class ZodDate extends ZodType {
36115
+ _parse(input) {
36116
+ if (this._def.coerce) {
36117
+ input.data = new Date(input.data);
36118
+ }
36119
+ const parsedType = this._getType(input);
36120
+ if (parsedType !== ZodParsedType.date) {
36121
+ const ctx = this._getOrReturnCtx(input);
36122
+ addIssueToContext(ctx, {
36123
+ code: ZodIssueCode.invalid_type,
36124
+ expected: ZodParsedType.date,
36125
+ received: ctx.parsedType,
36126
+ });
36127
+ return INVALID;
36128
+ }
36129
+ if (isNaN(input.data.getTime())) {
36130
+ const ctx = this._getOrReturnCtx(input);
36131
+ addIssueToContext(ctx, {
36132
+ code: ZodIssueCode.invalid_date,
36133
+ });
36134
+ return INVALID;
36135
+ }
36136
+ const status = new ParseStatus();
36137
+ let ctx = undefined;
36138
+ for (const check of this._def.checks) {
36139
+ if (check.kind === "min") {
36140
+ if (input.data.getTime() < check.value) {
36141
+ ctx = this._getOrReturnCtx(input, ctx);
36142
+ addIssueToContext(ctx, {
36143
+ code: ZodIssueCode.too_small,
36144
+ message: check.message,
36145
+ inclusive: true,
36146
+ exact: false,
36147
+ minimum: check.value,
36148
+ type: "date",
36149
+ });
36150
+ status.dirty();
36151
+ }
36152
+ }
36153
+ else if (check.kind === "max") {
36154
+ if (input.data.getTime() > check.value) {
36155
+ ctx = this._getOrReturnCtx(input, ctx);
36156
+ addIssueToContext(ctx, {
36157
+ code: ZodIssueCode.too_big,
36158
+ message: check.message,
36159
+ inclusive: true,
36160
+ exact: false,
36161
+ maximum: check.value,
36162
+ type: "date",
36163
+ });
36164
+ status.dirty();
36165
+ }
36166
+ }
36167
+ else {
36168
+ util.assertNever(check);
36169
+ }
36170
+ }
36171
+ return {
36172
+ status: status.value,
36173
+ value: new Date(input.data.getTime()),
36174
+ };
36175
+ }
36176
+ _addCheck(check) {
36177
+ return new ZodDate({
36178
+ ...this._def,
36179
+ checks: [...this._def.checks, check],
36180
+ });
36181
+ }
36182
+ min(minDate, message) {
36183
+ return this._addCheck({
36184
+ kind: "min",
36185
+ value: minDate.getTime(),
36186
+ message: errorUtil.toString(message),
36187
+ });
36188
+ }
36189
+ max(maxDate, message) {
36190
+ return this._addCheck({
36191
+ kind: "max",
36192
+ value: maxDate.getTime(),
36193
+ message: errorUtil.toString(message),
36194
+ });
36195
+ }
36196
+ get minDate() {
36197
+ let min = null;
36198
+ for (const ch of this._def.checks) {
36199
+ if (ch.kind === "min") {
36200
+ if (min === null || ch.value > min)
36201
+ min = ch.value;
36202
+ }
36203
+ }
36204
+ return min != null ? new Date(min) : null;
36205
+ }
36206
+ get maxDate() {
36207
+ let max = null;
36208
+ for (const ch of this._def.checks) {
36209
+ if (ch.kind === "max") {
36210
+ if (max === null || ch.value < max)
36211
+ max = ch.value;
36212
+ }
36213
+ }
36214
+ return max != null ? new Date(max) : null;
36215
+ }
36216
+ }
36217
+ ZodDate.create = (params) => {
36218
+ return new ZodDate({
36219
+ checks: [],
36220
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
36221
+ typeName: ZodFirstPartyTypeKind.ZodDate,
36222
+ ...processCreateParams(params),
36223
+ });
36224
+ };
36225
+ class ZodSymbol extends ZodType {
36226
+ _parse(input) {
36227
+ const parsedType = this._getType(input);
36228
+ if (parsedType !== ZodParsedType.symbol) {
36229
+ const ctx = this._getOrReturnCtx(input);
36230
+ addIssueToContext(ctx, {
36231
+ code: ZodIssueCode.invalid_type,
36232
+ expected: ZodParsedType.symbol,
36233
+ received: ctx.parsedType,
36234
+ });
36235
+ return INVALID;
36236
+ }
36237
+ return OK(input.data);
36238
+ }
36239
+ }
36240
+ ZodSymbol.create = (params) => {
36241
+ return new ZodSymbol({
36242
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
36243
+ ...processCreateParams(params),
36244
+ });
36245
+ };
36246
+ class ZodUndefined extends ZodType {
36247
+ _parse(input) {
36248
+ const parsedType = this._getType(input);
36249
+ if (parsedType !== ZodParsedType.undefined) {
36250
+ const ctx = this._getOrReturnCtx(input);
36251
+ addIssueToContext(ctx, {
36252
+ code: ZodIssueCode.invalid_type,
36253
+ expected: ZodParsedType.undefined,
36254
+ received: ctx.parsedType,
36255
+ });
36256
+ return INVALID;
36257
+ }
36258
+ return OK(input.data);
36259
+ }
36260
+ }
36261
+ ZodUndefined.create = (params) => {
36262
+ return new ZodUndefined({
36263
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
36264
+ ...processCreateParams(params),
36265
+ });
36266
+ };
36267
+ class ZodNull extends ZodType {
36268
+ _parse(input) {
36269
+ const parsedType = this._getType(input);
36270
+ if (parsedType !== ZodParsedType.null) {
36271
+ const ctx = this._getOrReturnCtx(input);
36272
+ addIssueToContext(ctx, {
36273
+ code: ZodIssueCode.invalid_type,
36274
+ expected: ZodParsedType.null,
36275
+ received: ctx.parsedType,
36276
+ });
36277
+ return INVALID;
36278
+ }
36279
+ return OK(input.data);
36280
+ }
36281
+ }
36282
+ ZodNull.create = (params) => {
36283
+ return new ZodNull({
36284
+ typeName: ZodFirstPartyTypeKind.ZodNull,
36285
+ ...processCreateParams(params),
36286
+ });
36287
+ };
36288
+ class ZodAny extends ZodType {
36289
+ constructor() {
36290
+ super(...arguments);
36291
+ // to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
36292
+ this._any = true;
36293
+ }
36294
+ _parse(input) {
36295
+ return OK(input.data);
36296
+ }
36297
+ }
36298
+ ZodAny.create = (params) => {
36299
+ return new ZodAny({
36300
+ typeName: ZodFirstPartyTypeKind.ZodAny,
36301
+ ...processCreateParams(params),
36302
+ });
36303
+ };
36304
+ class ZodUnknown extends ZodType {
36305
+ constructor() {
36306
+ super(...arguments);
36307
+ // required
36308
+ this._unknown = true;
36309
+ }
36310
+ _parse(input) {
36311
+ return OK(input.data);
36312
+ }
36313
+ }
36314
+ ZodUnknown.create = (params) => {
36315
+ return new ZodUnknown({
36316
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
36317
+ ...processCreateParams(params),
36318
+ });
36319
+ };
36320
+ class ZodNever extends ZodType {
36321
+ _parse(input) {
36322
+ const ctx = this._getOrReturnCtx(input);
36323
+ addIssueToContext(ctx, {
36324
+ code: ZodIssueCode.invalid_type,
36325
+ expected: ZodParsedType.never,
36326
+ received: ctx.parsedType,
36327
+ });
36328
+ return INVALID;
36329
+ }
36330
+ }
36331
+ ZodNever.create = (params) => {
36332
+ return new ZodNever({
36333
+ typeName: ZodFirstPartyTypeKind.ZodNever,
36334
+ ...processCreateParams(params),
36335
+ });
36336
+ };
36337
+ class ZodVoid extends ZodType {
36338
+ _parse(input) {
36339
+ const parsedType = this._getType(input);
36340
+ if (parsedType !== ZodParsedType.undefined) {
36341
+ const ctx = this._getOrReturnCtx(input);
36342
+ addIssueToContext(ctx, {
36343
+ code: ZodIssueCode.invalid_type,
36344
+ expected: ZodParsedType.void,
36345
+ received: ctx.parsedType,
36346
+ });
36347
+ return INVALID;
36348
+ }
36349
+ return OK(input.data);
36350
+ }
36351
+ }
36352
+ ZodVoid.create = (params) => {
36353
+ return new ZodVoid({
36354
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
36355
+ ...processCreateParams(params),
36356
+ });
36357
+ };
36358
+ class ZodArray extends ZodType {
36359
+ _parse(input) {
36360
+ const { ctx, status } = this._processInputParams(input);
36361
+ const def = this._def;
36362
+ if (ctx.parsedType !== ZodParsedType.array) {
36363
+ addIssueToContext(ctx, {
36364
+ code: ZodIssueCode.invalid_type,
36365
+ expected: ZodParsedType.array,
36366
+ received: ctx.parsedType,
36367
+ });
36368
+ return INVALID;
36369
+ }
36370
+ if (def.exactLength !== null) {
36371
+ const tooBig = ctx.data.length > def.exactLength.value;
36372
+ const tooSmall = ctx.data.length < def.exactLength.value;
36373
+ if (tooBig || tooSmall) {
36374
+ addIssueToContext(ctx, {
36375
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
36376
+ minimum: (tooSmall ? def.exactLength.value : undefined),
36377
+ maximum: (tooBig ? def.exactLength.value : undefined),
36378
+ type: "array",
36379
+ inclusive: true,
36380
+ exact: true,
36381
+ message: def.exactLength.message,
36382
+ });
36383
+ status.dirty();
36384
+ }
36385
+ }
36386
+ if (def.minLength !== null) {
36387
+ if (ctx.data.length < def.minLength.value) {
36388
+ addIssueToContext(ctx, {
36389
+ code: ZodIssueCode.too_small,
36390
+ minimum: def.minLength.value,
36391
+ type: "array",
36392
+ inclusive: true,
36393
+ exact: false,
36394
+ message: def.minLength.message,
36395
+ });
36396
+ status.dirty();
36397
+ }
36398
+ }
36399
+ if (def.maxLength !== null) {
36400
+ if (ctx.data.length > def.maxLength.value) {
36401
+ addIssueToContext(ctx, {
36402
+ code: ZodIssueCode.too_big,
36403
+ maximum: def.maxLength.value,
36404
+ type: "array",
36405
+ inclusive: true,
36406
+ exact: false,
36407
+ message: def.maxLength.message,
36408
+ });
36409
+ status.dirty();
36410
+ }
36411
+ }
36412
+ if (ctx.common.async) {
36413
+ return Promise.all([...ctx.data].map((item, i) => {
36414
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
36415
+ })).then((result) => {
36416
+ return ParseStatus.mergeArray(status, result);
36417
+ });
36418
+ }
36419
+ const result = [...ctx.data].map((item, i) => {
36420
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
36421
+ });
36422
+ return ParseStatus.mergeArray(status, result);
36423
+ }
36424
+ get element() {
36425
+ return this._def.type;
36426
+ }
36427
+ min(minLength, message) {
36428
+ return new ZodArray({
36429
+ ...this._def,
36430
+ minLength: { value: minLength, message: errorUtil.toString(message) },
36431
+ });
36432
+ }
36433
+ max(maxLength, message) {
36434
+ return new ZodArray({
36435
+ ...this._def,
36436
+ maxLength: { value: maxLength, message: errorUtil.toString(message) },
36437
+ });
36438
+ }
36439
+ length(len, message) {
36440
+ return new ZodArray({
36441
+ ...this._def,
36442
+ exactLength: { value: len, message: errorUtil.toString(message) },
36443
+ });
36444
+ }
36445
+ nonempty(message) {
36446
+ return this.min(1, message);
36447
+ }
36448
+ }
36449
+ ZodArray.create = (schema, params) => {
36450
+ return new ZodArray({
36451
+ type: schema,
36452
+ minLength: null,
36453
+ maxLength: null,
36454
+ exactLength: null,
36455
+ typeName: ZodFirstPartyTypeKind.ZodArray,
36456
+ ...processCreateParams(params),
36457
+ });
36458
+ };
36459
+ function deepPartialify(schema) {
36460
+ if (schema instanceof ZodObject) {
36461
+ const newShape = {};
36462
+ for (const key in schema.shape) {
36463
+ const fieldSchema = schema.shape[key];
36464
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
36465
+ }
36466
+ return new ZodObject({
36467
+ ...schema._def,
36468
+ shape: () => newShape,
36469
+ });
36470
+ }
36471
+ else if (schema instanceof ZodArray) {
36472
+ return new ZodArray({
36473
+ ...schema._def,
36474
+ type: deepPartialify(schema.element),
36475
+ });
36476
+ }
36477
+ else if (schema instanceof ZodOptional) {
36478
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
36479
+ }
36480
+ else if (schema instanceof ZodNullable) {
36481
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
36482
+ }
36483
+ else if (schema instanceof ZodTuple) {
36484
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
36485
+ }
36486
+ else {
36487
+ return schema;
36488
+ }
36489
+ }
36490
+ class ZodObject extends ZodType {
36491
+ constructor() {
36492
+ super(...arguments);
36493
+ this._cached = null;
36494
+ /**
36495
+ * @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
36496
+ * If you want to pass through unknown properties, use `.passthrough()` instead.
36497
+ */
36498
+ this.nonstrict = this.passthrough;
36499
+ // extend<
36500
+ // Augmentation extends ZodRawShape,
36501
+ // NewOutput extends util.flatten<{
36502
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
36503
+ // ? Augmentation[k]["_output"]
36504
+ // : k extends keyof Output
36505
+ // ? Output[k]
36506
+ // : never;
36507
+ // }>,
36508
+ // NewInput extends util.flatten<{
36509
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
36510
+ // ? Augmentation[k]["_input"]
36511
+ // : k extends keyof Input
36512
+ // ? Input[k]
36513
+ // : never;
36514
+ // }>
36515
+ // >(
36516
+ // augmentation: Augmentation
36517
+ // ): ZodObject<
36518
+ // extendShape<T, Augmentation>,
36519
+ // UnknownKeys,
36520
+ // Catchall,
36521
+ // NewOutput,
36522
+ // NewInput
36523
+ // > {
36524
+ // return new ZodObject({
36525
+ // ...this._def,
36526
+ // shape: () => ({
36527
+ // ...this._def.shape(),
36528
+ // ...augmentation,
36529
+ // }),
36530
+ // }) as any;
36531
+ // }
36532
+ /**
36533
+ * @deprecated Use `.extend` instead
36534
+ * */
36535
+ this.augment = this.extend;
36536
+ }
36537
+ _getCached() {
36538
+ if (this._cached !== null)
36539
+ return this._cached;
36540
+ const shape = this._def.shape();
36541
+ const keys = util.objectKeys(shape);
36542
+ return (this._cached = { shape, keys });
36543
+ }
36544
+ _parse(input) {
36545
+ const parsedType = this._getType(input);
36546
+ if (parsedType !== ZodParsedType.object) {
36547
+ const ctx = this._getOrReturnCtx(input);
36548
+ addIssueToContext(ctx, {
36549
+ code: ZodIssueCode.invalid_type,
36550
+ expected: ZodParsedType.object,
36551
+ received: ctx.parsedType,
36552
+ });
36553
+ return INVALID;
36554
+ }
36555
+ const { status, ctx } = this._processInputParams(input);
36556
+ const { shape, keys: shapeKeys } = this._getCached();
36557
+ const extraKeys = [];
36558
+ if (!(this._def.catchall instanceof ZodNever &&
36559
+ this._def.unknownKeys === "strip")) {
36560
+ for (const key in ctx.data) {
36561
+ if (!shapeKeys.includes(key)) {
36562
+ extraKeys.push(key);
36563
+ }
36564
+ }
36565
+ }
36566
+ const pairs = [];
36567
+ for (const key of shapeKeys) {
36568
+ const keyValidator = shape[key];
36569
+ const value = ctx.data[key];
36570
+ pairs.push({
36571
+ key: { status: "valid", value: key },
36572
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
36573
+ alwaysSet: key in ctx.data,
36574
+ });
36575
+ }
36576
+ if (this._def.catchall instanceof ZodNever) {
36577
+ const unknownKeys = this._def.unknownKeys;
36578
+ if (unknownKeys === "passthrough") {
36579
+ for (const key of extraKeys) {
36580
+ pairs.push({
36581
+ key: { status: "valid", value: key },
36582
+ value: { status: "valid", value: ctx.data[key] },
36583
+ });
36584
+ }
36585
+ }
36586
+ else if (unknownKeys === "strict") {
36587
+ if (extraKeys.length > 0) {
36588
+ addIssueToContext(ctx, {
36589
+ code: ZodIssueCode.unrecognized_keys,
36590
+ keys: extraKeys,
36591
+ });
36592
+ status.dirty();
36593
+ }
36594
+ }
36595
+ else if (unknownKeys === "strip") ;
36596
+ else {
36597
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
36598
+ }
36599
+ }
36600
+ else {
36601
+ // run catchall validation
36602
+ const catchall = this._def.catchall;
36603
+ for (const key of extraKeys) {
36604
+ const value = ctx.data[key];
36605
+ pairs.push({
36606
+ key: { status: "valid", value: key },
36607
+ value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key) //, ctx.child(key), value, getParsedType(value)
36608
+ ),
36609
+ alwaysSet: key in ctx.data,
36610
+ });
36611
+ }
36612
+ }
36613
+ if (ctx.common.async) {
36614
+ return Promise.resolve()
36615
+ .then(async () => {
36616
+ const syncPairs = [];
36617
+ for (const pair of pairs) {
36618
+ const key = await pair.key;
36619
+ syncPairs.push({
36620
+ key,
36621
+ value: await pair.value,
36622
+ alwaysSet: pair.alwaysSet,
36623
+ });
36624
+ }
36625
+ return syncPairs;
36626
+ })
36627
+ .then((syncPairs) => {
36628
+ return ParseStatus.mergeObjectSync(status, syncPairs);
36629
+ });
36630
+ }
36631
+ else {
36632
+ return ParseStatus.mergeObjectSync(status, pairs);
36633
+ }
36634
+ }
36635
+ get shape() {
36636
+ return this._def.shape();
36637
+ }
36638
+ strict(message) {
36639
+ errorUtil.errToObj;
36640
+ return new ZodObject({
36641
+ ...this._def,
36642
+ unknownKeys: "strict",
36643
+ ...(message !== undefined
36644
+ ? {
36645
+ errorMap: (issue, ctx) => {
36646
+ var _a, _b, _c, _d;
36647
+ 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;
36648
+ if (issue.code === "unrecognized_keys")
36649
+ return {
36650
+ message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
36651
+ };
36652
+ return {
36653
+ message: defaultError,
36654
+ };
36655
+ },
36656
+ }
36657
+ : {}),
36658
+ });
36659
+ }
36660
+ strip() {
36661
+ return new ZodObject({
36662
+ ...this._def,
36663
+ unknownKeys: "strip",
36664
+ });
36665
+ }
36666
+ passthrough() {
36667
+ return new ZodObject({
36668
+ ...this._def,
36669
+ unknownKeys: "passthrough",
36670
+ });
36671
+ }
36672
+ // const AugmentFactory =
36673
+ // <Def extends ZodObjectDef>(def: Def) =>
36674
+ // <Augmentation extends ZodRawShape>(
36675
+ // augmentation: Augmentation
36676
+ // ): ZodObject<
36677
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
36678
+ // Def["unknownKeys"],
36679
+ // Def["catchall"]
36680
+ // > => {
36681
+ // return new ZodObject({
36682
+ // ...def,
36683
+ // shape: () => ({
36684
+ // ...def.shape(),
36685
+ // ...augmentation,
36686
+ // }),
36687
+ // }) as any;
36688
+ // };
36689
+ extend(augmentation) {
36690
+ return new ZodObject({
36691
+ ...this._def,
36692
+ shape: () => ({
36693
+ ...this._def.shape(),
36694
+ ...augmentation,
36695
+ }),
36696
+ });
36697
+ }
36698
+ /**
36699
+ * Prior to zod@1.0.12 there was a bug in the
36700
+ * inferred type of merged objects. Please
36701
+ * upgrade if you are experiencing issues.
36702
+ */
36703
+ merge(merging) {
36704
+ const merged = new ZodObject({
36705
+ unknownKeys: merging._def.unknownKeys,
36706
+ catchall: merging._def.catchall,
36707
+ shape: () => ({
36708
+ ...this._def.shape(),
36709
+ ...merging._def.shape(),
36710
+ }),
36711
+ typeName: ZodFirstPartyTypeKind.ZodObject,
36712
+ });
36713
+ return merged;
36714
+ }
36715
+ // merge<
36716
+ // Incoming extends AnyZodObject,
36717
+ // Augmentation extends Incoming["shape"],
36718
+ // NewOutput extends {
36719
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
36720
+ // ? Augmentation[k]["_output"]
36721
+ // : k extends keyof Output
36722
+ // ? Output[k]
36723
+ // : never;
36724
+ // },
36725
+ // NewInput extends {
36726
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
36727
+ // ? Augmentation[k]["_input"]
36728
+ // : k extends keyof Input
36729
+ // ? Input[k]
36730
+ // : never;
36731
+ // }
36732
+ // >(
36733
+ // merging: Incoming
36734
+ // ): ZodObject<
36735
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
36736
+ // Incoming["_def"]["unknownKeys"],
36737
+ // Incoming["_def"]["catchall"],
36738
+ // NewOutput,
36739
+ // NewInput
36740
+ // > {
36741
+ // const merged: any = new ZodObject({
36742
+ // unknownKeys: merging._def.unknownKeys,
36743
+ // catchall: merging._def.catchall,
36744
+ // shape: () =>
36745
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
36746
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
36747
+ // }) as any;
36748
+ // return merged;
36749
+ // }
36750
+ setKey(key, schema) {
36751
+ return this.augment({ [key]: schema });
36752
+ }
36753
+ // merge<Incoming extends AnyZodObject>(
36754
+ // merging: Incoming
36755
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
36756
+ // ZodObject<
36757
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
36758
+ // Incoming["_def"]["unknownKeys"],
36759
+ // Incoming["_def"]["catchall"]
36760
+ // > {
36761
+ // // const mergedShape = objectUtil.mergeShapes(
36762
+ // // this._def.shape(),
36763
+ // // merging._def.shape()
36764
+ // // );
36765
+ // const merged: any = new ZodObject({
36766
+ // unknownKeys: merging._def.unknownKeys,
36767
+ // catchall: merging._def.catchall,
36768
+ // shape: () =>
36769
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
36770
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
36771
+ // }) as any;
36772
+ // return merged;
36773
+ // }
36774
+ catchall(index) {
36775
+ return new ZodObject({
36776
+ ...this._def,
36777
+ catchall: index,
36778
+ });
36779
+ }
36780
+ pick(mask) {
36781
+ const shape = {};
36782
+ util.objectKeys(mask).forEach((key) => {
36783
+ if (mask[key] && this.shape[key]) {
36784
+ shape[key] = this.shape[key];
36785
+ }
36786
+ });
36787
+ return new ZodObject({
36788
+ ...this._def,
36789
+ shape: () => shape,
36790
+ });
36791
+ }
36792
+ omit(mask) {
36793
+ const shape = {};
36794
+ util.objectKeys(this.shape).forEach((key) => {
36795
+ if (!mask[key]) {
36796
+ shape[key] = this.shape[key];
36797
+ }
36798
+ });
36799
+ return new ZodObject({
36800
+ ...this._def,
36801
+ shape: () => shape,
36802
+ });
36803
+ }
36804
+ /**
36805
+ * @deprecated
36806
+ */
36807
+ deepPartial() {
36808
+ return deepPartialify(this);
36809
+ }
36810
+ partial(mask) {
36811
+ const newShape = {};
36812
+ util.objectKeys(this.shape).forEach((key) => {
36813
+ const fieldSchema = this.shape[key];
36814
+ if (mask && !mask[key]) {
36815
+ newShape[key] = fieldSchema;
36816
+ }
36817
+ else {
36818
+ newShape[key] = fieldSchema.optional();
36819
+ }
36820
+ });
36821
+ return new ZodObject({
36822
+ ...this._def,
36823
+ shape: () => newShape,
36824
+ });
36825
+ }
36826
+ required(mask) {
36827
+ const newShape = {};
36828
+ util.objectKeys(this.shape).forEach((key) => {
36829
+ if (mask && !mask[key]) {
36830
+ newShape[key] = this.shape[key];
36831
+ }
36832
+ else {
36833
+ const fieldSchema = this.shape[key];
36834
+ let newField = fieldSchema;
36835
+ while (newField instanceof ZodOptional) {
36836
+ newField = newField._def.innerType;
36837
+ }
36838
+ newShape[key] = newField;
36839
+ }
36840
+ });
36841
+ return new ZodObject({
36842
+ ...this._def,
36843
+ shape: () => newShape,
36844
+ });
36845
+ }
36846
+ keyof() {
36847
+ return createZodEnum(util.objectKeys(this.shape));
36848
+ }
36849
+ }
36850
+ ZodObject.create = (shape, params) => {
36851
+ return new ZodObject({
36852
+ shape: () => shape,
36853
+ unknownKeys: "strip",
36854
+ catchall: ZodNever.create(),
36855
+ typeName: ZodFirstPartyTypeKind.ZodObject,
36856
+ ...processCreateParams(params),
36857
+ });
36858
+ };
36859
+ ZodObject.strictCreate = (shape, params) => {
36860
+ return new ZodObject({
36861
+ shape: () => shape,
36862
+ unknownKeys: "strict",
36863
+ catchall: ZodNever.create(),
36864
+ typeName: ZodFirstPartyTypeKind.ZodObject,
36865
+ ...processCreateParams(params),
36866
+ });
36867
+ };
36868
+ ZodObject.lazycreate = (shape, params) => {
36869
+ return new ZodObject({
36870
+ shape,
36871
+ unknownKeys: "strip",
36872
+ catchall: ZodNever.create(),
36873
+ typeName: ZodFirstPartyTypeKind.ZodObject,
36874
+ ...processCreateParams(params),
36875
+ });
36876
+ };
36877
+ class ZodUnion extends ZodType {
36878
+ _parse(input) {
36879
+ const { ctx } = this._processInputParams(input);
36880
+ const options = this._def.options;
36881
+ function handleResults(results) {
36882
+ // return first issue-free validation if it exists
36883
+ for (const result of results) {
36884
+ if (result.result.status === "valid") {
36885
+ return result.result;
36886
+ }
36887
+ }
36888
+ for (const result of results) {
36889
+ if (result.result.status === "dirty") {
36890
+ // add issues from dirty option
36891
+ ctx.common.issues.push(...result.ctx.common.issues);
36892
+ return result.result;
36893
+ }
36894
+ }
36895
+ // return invalid
36896
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
36897
+ addIssueToContext(ctx, {
36898
+ code: ZodIssueCode.invalid_union,
36899
+ unionErrors,
36900
+ });
36901
+ return INVALID;
36902
+ }
36903
+ if (ctx.common.async) {
36904
+ return Promise.all(options.map(async (option) => {
36905
+ const childCtx = {
36906
+ ...ctx,
36907
+ common: {
36908
+ ...ctx.common,
36909
+ issues: [],
36910
+ },
36911
+ parent: null,
36912
+ };
36913
+ return {
36914
+ result: await option._parseAsync({
36915
+ data: ctx.data,
36916
+ path: ctx.path,
36917
+ parent: childCtx,
36918
+ }),
36919
+ ctx: childCtx,
36920
+ };
36921
+ })).then(handleResults);
36922
+ }
36923
+ else {
36924
+ let dirty = undefined;
36925
+ const issues = [];
36926
+ for (const option of options) {
36927
+ const childCtx = {
36928
+ ...ctx,
36929
+ common: {
36930
+ ...ctx.common,
36931
+ issues: [],
36932
+ },
36933
+ parent: null,
36934
+ };
36935
+ const result = option._parseSync({
36936
+ data: ctx.data,
36937
+ path: ctx.path,
36938
+ parent: childCtx,
36939
+ });
36940
+ if (result.status === "valid") {
36941
+ return result;
36942
+ }
36943
+ else if (result.status === "dirty" && !dirty) {
36944
+ dirty = { result, ctx: childCtx };
36945
+ }
36946
+ if (childCtx.common.issues.length) {
36947
+ issues.push(childCtx.common.issues);
36948
+ }
36949
+ }
36950
+ if (dirty) {
36951
+ ctx.common.issues.push(...dirty.ctx.common.issues);
36952
+ return dirty.result;
36953
+ }
36954
+ const unionErrors = issues.map((issues) => new ZodError(issues));
36955
+ addIssueToContext(ctx, {
36956
+ code: ZodIssueCode.invalid_union,
36957
+ unionErrors,
36958
+ });
36959
+ return INVALID;
36960
+ }
36961
+ }
36962
+ get options() {
36963
+ return this._def.options;
36964
+ }
36965
+ }
36966
+ ZodUnion.create = (types, params) => {
36967
+ return new ZodUnion({
36968
+ options: types,
36969
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
36970
+ ...processCreateParams(params),
36971
+ });
36972
+ };
36973
+ /////////////////////////////////////////////////////
36974
+ /////////////////////////////////////////////////////
36975
+ ////////// //////////
36976
+ ////////// ZodDiscriminatedUnion //////////
36977
+ ////////// //////////
36978
+ /////////////////////////////////////////////////////
36979
+ /////////////////////////////////////////////////////
36980
+ const getDiscriminator = (type) => {
36981
+ if (type instanceof ZodLazy) {
36982
+ return getDiscriminator(type.schema);
36983
+ }
36984
+ else if (type instanceof ZodEffects) {
36985
+ return getDiscriminator(type.innerType());
36986
+ }
36987
+ else if (type instanceof ZodLiteral) {
36988
+ return [type.value];
36989
+ }
36990
+ else if (type instanceof ZodEnum) {
36991
+ return type.options;
36992
+ }
36993
+ else if (type instanceof ZodNativeEnum) {
36994
+ // eslint-disable-next-line ban/ban
36995
+ return Object.keys(type.enum);
36996
+ }
36997
+ else if (type instanceof ZodDefault) {
36998
+ return getDiscriminator(type._def.innerType);
36999
+ }
37000
+ else if (type instanceof ZodUndefined) {
37001
+ return [undefined];
37002
+ }
37003
+ else if (type instanceof ZodNull) {
37004
+ return [null];
37005
+ }
37006
+ else {
37007
+ return null;
37008
+ }
37009
+ };
37010
+ class ZodDiscriminatedUnion extends ZodType {
37011
+ _parse(input) {
37012
+ const { ctx } = this._processInputParams(input);
37013
+ if (ctx.parsedType !== ZodParsedType.object) {
37014
+ addIssueToContext(ctx, {
37015
+ code: ZodIssueCode.invalid_type,
37016
+ expected: ZodParsedType.object,
37017
+ received: ctx.parsedType,
37018
+ });
37019
+ return INVALID;
37020
+ }
37021
+ const discriminator = this.discriminator;
37022
+ const discriminatorValue = ctx.data[discriminator];
37023
+ const option = this.optionsMap.get(discriminatorValue);
37024
+ if (!option) {
37025
+ addIssueToContext(ctx, {
37026
+ code: ZodIssueCode.invalid_union_discriminator,
37027
+ options: Array.from(this.optionsMap.keys()),
37028
+ path: [discriminator],
37029
+ });
37030
+ return INVALID;
37031
+ }
37032
+ if (ctx.common.async) {
37033
+ return option._parseAsync({
37034
+ data: ctx.data,
37035
+ path: ctx.path,
37036
+ parent: ctx,
37037
+ });
37038
+ }
37039
+ else {
37040
+ return option._parseSync({
37041
+ data: ctx.data,
37042
+ path: ctx.path,
37043
+ parent: ctx,
37044
+ });
37045
+ }
37046
+ }
37047
+ get discriminator() {
37048
+ return this._def.discriminator;
37049
+ }
37050
+ get options() {
37051
+ return this._def.options;
37052
+ }
37053
+ get optionsMap() {
37054
+ return this._def.optionsMap;
37055
+ }
37056
+ /**
37057
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
37058
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
37059
+ * have a different value for each object in the union.
37060
+ * @param discriminator the name of the discriminator property
37061
+ * @param types an array of object schemas
37062
+ * @param params
37063
+ */
37064
+ static create(discriminator, options, params) {
37065
+ // Get all the valid discriminator values
37066
+ const optionsMap = new Map();
37067
+ // try {
37068
+ for (const type of options) {
37069
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
37070
+ if (!discriminatorValues) {
37071
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
37072
+ }
37073
+ for (const value of discriminatorValues) {
37074
+ if (optionsMap.has(value)) {
37075
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
37076
+ }
37077
+ optionsMap.set(value, type);
37078
+ }
37079
+ }
37080
+ return new ZodDiscriminatedUnion({
37081
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
37082
+ discriminator,
37083
+ options,
37084
+ optionsMap,
37085
+ ...processCreateParams(params),
37086
+ });
37087
+ }
37088
+ }
37089
+ function mergeValues(a, b) {
37090
+ const aType = getParsedType(a);
37091
+ const bType = getParsedType(b);
37092
+ if (a === b) {
37093
+ return { valid: true, data: a };
37094
+ }
37095
+ else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
37096
+ const bKeys = util.objectKeys(b);
37097
+ const sharedKeys = util
37098
+ .objectKeys(a)
37099
+ .filter((key) => bKeys.indexOf(key) !== -1);
37100
+ const newObj = { ...a, ...b };
37101
+ for (const key of sharedKeys) {
37102
+ const sharedValue = mergeValues(a[key], b[key]);
37103
+ if (!sharedValue.valid) {
37104
+ return { valid: false };
37105
+ }
37106
+ newObj[key] = sharedValue.data;
37107
+ }
37108
+ return { valid: true, data: newObj };
37109
+ }
37110
+ else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
37111
+ if (a.length !== b.length) {
37112
+ return { valid: false };
37113
+ }
37114
+ const newArray = [];
37115
+ for (let index = 0; index < a.length; index++) {
37116
+ const itemA = a[index];
37117
+ const itemB = b[index];
37118
+ const sharedValue = mergeValues(itemA, itemB);
37119
+ if (!sharedValue.valid) {
37120
+ return { valid: false };
37121
+ }
37122
+ newArray.push(sharedValue.data);
37123
+ }
37124
+ return { valid: true, data: newArray };
37125
+ }
37126
+ else if (aType === ZodParsedType.date &&
37127
+ bType === ZodParsedType.date &&
37128
+ +a === +b) {
37129
+ return { valid: true, data: a };
37130
+ }
37131
+ else {
37132
+ return { valid: false };
37133
+ }
37134
+ }
37135
+ class ZodIntersection extends ZodType {
37136
+ _parse(input) {
37137
+ const { status, ctx } = this._processInputParams(input);
37138
+ const handleParsed = (parsedLeft, parsedRight) => {
37139
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
37140
+ return INVALID;
37141
+ }
37142
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
37143
+ if (!merged.valid) {
37144
+ addIssueToContext(ctx, {
37145
+ code: ZodIssueCode.invalid_intersection_types,
37146
+ });
37147
+ return INVALID;
37148
+ }
37149
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
37150
+ status.dirty();
37151
+ }
37152
+ return { status: status.value, value: merged.data };
37153
+ };
37154
+ if (ctx.common.async) {
37155
+ return Promise.all([
37156
+ this._def.left._parseAsync({
37157
+ data: ctx.data,
37158
+ path: ctx.path,
37159
+ parent: ctx,
37160
+ }),
37161
+ this._def.right._parseAsync({
37162
+ data: ctx.data,
37163
+ path: ctx.path,
37164
+ parent: ctx,
37165
+ }),
37166
+ ]).then(([left, right]) => handleParsed(left, right));
37167
+ }
37168
+ else {
37169
+ return handleParsed(this._def.left._parseSync({
37170
+ data: ctx.data,
37171
+ path: ctx.path,
37172
+ parent: ctx,
37173
+ }), this._def.right._parseSync({
37174
+ data: ctx.data,
37175
+ path: ctx.path,
37176
+ parent: ctx,
37177
+ }));
37178
+ }
37179
+ }
37180
+ }
37181
+ ZodIntersection.create = (left, right, params) => {
37182
+ return new ZodIntersection({
37183
+ left: left,
37184
+ right: right,
37185
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
37186
+ ...processCreateParams(params),
37187
+ });
37188
+ };
37189
+ class ZodTuple extends ZodType {
37190
+ _parse(input) {
37191
+ const { status, ctx } = this._processInputParams(input);
37192
+ if (ctx.parsedType !== ZodParsedType.array) {
37193
+ addIssueToContext(ctx, {
37194
+ code: ZodIssueCode.invalid_type,
37195
+ expected: ZodParsedType.array,
37196
+ received: ctx.parsedType,
37197
+ });
37198
+ return INVALID;
37199
+ }
37200
+ if (ctx.data.length < this._def.items.length) {
37201
+ addIssueToContext(ctx, {
37202
+ code: ZodIssueCode.too_small,
37203
+ minimum: this._def.items.length,
37204
+ inclusive: true,
37205
+ exact: false,
37206
+ type: "array",
37207
+ });
37208
+ return INVALID;
37209
+ }
37210
+ const rest = this._def.rest;
37211
+ if (!rest && ctx.data.length > this._def.items.length) {
37212
+ addIssueToContext(ctx, {
37213
+ code: ZodIssueCode.too_big,
37214
+ maximum: this._def.items.length,
37215
+ inclusive: true,
37216
+ exact: false,
37217
+ type: "array",
37218
+ });
37219
+ status.dirty();
37220
+ }
37221
+ const items = [...ctx.data]
37222
+ .map((item, itemIndex) => {
37223
+ const schema = this._def.items[itemIndex] || this._def.rest;
37224
+ if (!schema)
37225
+ return null;
37226
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
37227
+ })
37228
+ .filter((x) => !!x); // filter nulls
37229
+ if (ctx.common.async) {
37230
+ return Promise.all(items).then((results) => {
37231
+ return ParseStatus.mergeArray(status, results);
37232
+ });
37233
+ }
37234
+ else {
37235
+ return ParseStatus.mergeArray(status, items);
37236
+ }
37237
+ }
37238
+ get items() {
37239
+ return this._def.items;
37240
+ }
37241
+ rest(rest) {
37242
+ return new ZodTuple({
37243
+ ...this._def,
37244
+ rest,
37245
+ });
37246
+ }
37247
+ }
37248
+ ZodTuple.create = (schemas, params) => {
37249
+ if (!Array.isArray(schemas)) {
37250
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
37251
+ }
37252
+ return new ZodTuple({
37253
+ items: schemas,
37254
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
37255
+ rest: null,
37256
+ ...processCreateParams(params),
37257
+ });
37258
+ };
37259
+ class ZodRecord extends ZodType {
37260
+ get keySchema() {
37261
+ return this._def.keyType;
37262
+ }
37263
+ get valueSchema() {
37264
+ return this._def.valueType;
37265
+ }
37266
+ _parse(input) {
37267
+ const { status, ctx } = this._processInputParams(input);
37268
+ if (ctx.parsedType !== ZodParsedType.object) {
37269
+ addIssueToContext(ctx, {
37270
+ code: ZodIssueCode.invalid_type,
37271
+ expected: ZodParsedType.object,
37272
+ received: ctx.parsedType,
37273
+ });
37274
+ return INVALID;
37275
+ }
37276
+ const pairs = [];
37277
+ const keyType = this._def.keyType;
37278
+ const valueType = this._def.valueType;
37279
+ for (const key in ctx.data) {
37280
+ pairs.push({
37281
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
37282
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
37283
+ });
37284
+ }
37285
+ if (ctx.common.async) {
37286
+ return ParseStatus.mergeObjectAsync(status, pairs);
37287
+ }
37288
+ else {
37289
+ return ParseStatus.mergeObjectSync(status, pairs);
37290
+ }
37291
+ }
37292
+ get element() {
37293
+ return this._def.valueType;
37294
+ }
37295
+ static create(first, second, third) {
37296
+ if (second instanceof ZodType) {
37297
+ return new ZodRecord({
37298
+ keyType: first,
37299
+ valueType: second,
37300
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
37301
+ ...processCreateParams(third),
37302
+ });
37303
+ }
37304
+ return new ZodRecord({
37305
+ keyType: ZodString.create(),
37306
+ valueType: first,
37307
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
37308
+ ...processCreateParams(second),
37309
+ });
37310
+ }
37311
+ }
37312
+ class ZodMap extends ZodType {
37313
+ get keySchema() {
37314
+ return this._def.keyType;
37315
+ }
37316
+ get valueSchema() {
37317
+ return this._def.valueType;
37318
+ }
37319
+ _parse(input) {
37320
+ const { status, ctx } = this._processInputParams(input);
37321
+ if (ctx.parsedType !== ZodParsedType.map) {
37322
+ addIssueToContext(ctx, {
37323
+ code: ZodIssueCode.invalid_type,
37324
+ expected: ZodParsedType.map,
37325
+ received: ctx.parsedType,
37326
+ });
37327
+ return INVALID;
37328
+ }
37329
+ const keyType = this._def.keyType;
37330
+ const valueType = this._def.valueType;
37331
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
37332
+ return {
37333
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
37334
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"])),
37335
+ };
37336
+ });
37337
+ if (ctx.common.async) {
37338
+ const finalMap = new Map();
37339
+ return Promise.resolve().then(async () => {
37340
+ for (const pair of pairs) {
37341
+ const key = await pair.key;
37342
+ const value = await pair.value;
37343
+ if (key.status === "aborted" || value.status === "aborted") {
37344
+ return INVALID;
37345
+ }
37346
+ if (key.status === "dirty" || value.status === "dirty") {
37347
+ status.dirty();
37348
+ }
37349
+ finalMap.set(key.value, value.value);
37350
+ }
37351
+ return { status: status.value, value: finalMap };
37352
+ });
37353
+ }
37354
+ else {
37355
+ const finalMap = new Map();
37356
+ for (const pair of pairs) {
37357
+ const key = pair.key;
37358
+ const value = pair.value;
37359
+ if (key.status === "aborted" || value.status === "aborted") {
37360
+ return INVALID;
37361
+ }
37362
+ if (key.status === "dirty" || value.status === "dirty") {
37363
+ status.dirty();
37364
+ }
37365
+ finalMap.set(key.value, value.value);
37366
+ }
37367
+ return { status: status.value, value: finalMap };
37368
+ }
37369
+ }
37370
+ }
37371
+ ZodMap.create = (keyType, valueType, params) => {
37372
+ return new ZodMap({
37373
+ valueType,
37374
+ keyType,
37375
+ typeName: ZodFirstPartyTypeKind.ZodMap,
37376
+ ...processCreateParams(params),
37377
+ });
37378
+ };
37379
+ class ZodSet extends ZodType {
37380
+ _parse(input) {
37381
+ const { status, ctx } = this._processInputParams(input);
37382
+ if (ctx.parsedType !== ZodParsedType.set) {
37383
+ addIssueToContext(ctx, {
37384
+ code: ZodIssueCode.invalid_type,
37385
+ expected: ZodParsedType.set,
37386
+ received: ctx.parsedType,
37387
+ });
37388
+ return INVALID;
37389
+ }
37390
+ const def = this._def;
37391
+ if (def.minSize !== null) {
37392
+ if (ctx.data.size < def.minSize.value) {
37393
+ addIssueToContext(ctx, {
37394
+ code: ZodIssueCode.too_small,
37395
+ minimum: def.minSize.value,
37396
+ type: "set",
37397
+ inclusive: true,
37398
+ exact: false,
37399
+ message: def.minSize.message,
37400
+ });
37401
+ status.dirty();
37402
+ }
37403
+ }
37404
+ if (def.maxSize !== null) {
37405
+ if (ctx.data.size > def.maxSize.value) {
37406
+ addIssueToContext(ctx, {
37407
+ code: ZodIssueCode.too_big,
37408
+ maximum: def.maxSize.value,
37409
+ type: "set",
37410
+ inclusive: true,
37411
+ exact: false,
37412
+ message: def.maxSize.message,
37413
+ });
37414
+ status.dirty();
37415
+ }
37416
+ }
37417
+ const valueType = this._def.valueType;
37418
+ function finalizeSet(elements) {
37419
+ const parsedSet = new Set();
37420
+ for (const element of elements) {
37421
+ if (element.status === "aborted")
37422
+ return INVALID;
37423
+ if (element.status === "dirty")
37424
+ status.dirty();
37425
+ parsedSet.add(element.value);
37426
+ }
37427
+ return { status: status.value, value: parsedSet };
37428
+ }
37429
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
37430
+ if (ctx.common.async) {
37431
+ return Promise.all(elements).then((elements) => finalizeSet(elements));
37432
+ }
37433
+ else {
37434
+ return finalizeSet(elements);
37435
+ }
37436
+ }
37437
+ min(minSize, message) {
37438
+ return new ZodSet({
37439
+ ...this._def,
37440
+ minSize: { value: minSize, message: errorUtil.toString(message) },
37441
+ });
37442
+ }
37443
+ max(maxSize, message) {
37444
+ return new ZodSet({
37445
+ ...this._def,
37446
+ maxSize: { value: maxSize, message: errorUtil.toString(message) },
37447
+ });
37448
+ }
37449
+ size(size, message) {
37450
+ return this.min(size, message).max(size, message);
37451
+ }
37452
+ nonempty(message) {
37453
+ return this.min(1, message);
37454
+ }
37455
+ }
37456
+ ZodSet.create = (valueType, params) => {
37457
+ return new ZodSet({
37458
+ valueType,
37459
+ minSize: null,
37460
+ maxSize: null,
37461
+ typeName: ZodFirstPartyTypeKind.ZodSet,
37462
+ ...processCreateParams(params),
37463
+ });
37464
+ };
37465
+ class ZodFunction extends ZodType {
37466
+ constructor() {
37467
+ super(...arguments);
37468
+ this.validate = this.implement;
37469
+ }
37470
+ _parse(input) {
37471
+ const { ctx } = this._processInputParams(input);
37472
+ if (ctx.parsedType !== ZodParsedType.function) {
37473
+ addIssueToContext(ctx, {
37474
+ code: ZodIssueCode.invalid_type,
37475
+ expected: ZodParsedType.function,
37476
+ received: ctx.parsedType,
37477
+ });
37478
+ return INVALID;
37479
+ }
37480
+ function makeArgsIssue(args, error) {
37481
+ return makeIssue({
37482
+ data: args,
37483
+ path: ctx.path,
37484
+ errorMaps: [
37485
+ ctx.common.contextualErrorMap,
37486
+ ctx.schemaErrorMap,
37487
+ getErrorMap(),
37488
+ errorMap,
37489
+ ].filter((x) => !!x),
37490
+ issueData: {
37491
+ code: ZodIssueCode.invalid_arguments,
37492
+ argumentsError: error,
37493
+ },
37494
+ });
37495
+ }
37496
+ function makeReturnsIssue(returns, error) {
37497
+ return makeIssue({
37498
+ data: returns,
37499
+ path: ctx.path,
37500
+ errorMaps: [
37501
+ ctx.common.contextualErrorMap,
37502
+ ctx.schemaErrorMap,
37503
+ getErrorMap(),
37504
+ errorMap,
37505
+ ].filter((x) => !!x),
37506
+ issueData: {
37507
+ code: ZodIssueCode.invalid_return_type,
37508
+ returnTypeError: error,
37509
+ },
37510
+ });
37511
+ }
37512
+ const params = { errorMap: ctx.common.contextualErrorMap };
37513
+ const fn = ctx.data;
37514
+ if (this._def.returns instanceof ZodPromise) {
37515
+ // Would love a way to avoid disabling this rule, but we need
37516
+ // an alias (using an arrow function was what caused 2651).
37517
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
37518
+ const me = this;
37519
+ return OK(async function (...args) {
37520
+ const error = new ZodError([]);
37521
+ const parsedArgs = await me._def.args
37522
+ .parseAsync(args, params)
37523
+ .catch((e) => {
37524
+ error.addIssue(makeArgsIssue(args, e));
37525
+ throw error;
37526
+ });
37527
+ const result = await Reflect.apply(fn, this, parsedArgs);
37528
+ const parsedReturns = await me._def.returns._def.type
37529
+ .parseAsync(result, params)
37530
+ .catch((e) => {
37531
+ error.addIssue(makeReturnsIssue(result, e));
37532
+ throw error;
37533
+ });
37534
+ return parsedReturns;
37535
+ });
37536
+ }
37537
+ else {
37538
+ // Would love a way to avoid disabling this rule, but we need
37539
+ // an alias (using an arrow function was what caused 2651).
37540
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
37541
+ const me = this;
37542
+ return OK(function (...args) {
37543
+ const parsedArgs = me._def.args.safeParse(args, params);
37544
+ if (!parsedArgs.success) {
37545
+ throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
37546
+ }
37547
+ const result = Reflect.apply(fn, this, parsedArgs.data);
37548
+ const parsedReturns = me._def.returns.safeParse(result, params);
37549
+ if (!parsedReturns.success) {
37550
+ throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
37551
+ }
37552
+ return parsedReturns.data;
37553
+ });
37554
+ }
37555
+ }
37556
+ parameters() {
37557
+ return this._def.args;
37558
+ }
37559
+ returnType() {
37560
+ return this._def.returns;
37561
+ }
37562
+ args(...items) {
37563
+ return new ZodFunction({
37564
+ ...this._def,
37565
+ args: ZodTuple.create(items).rest(ZodUnknown.create()),
37566
+ });
37567
+ }
37568
+ returns(returnType) {
37569
+ return new ZodFunction({
37570
+ ...this._def,
37571
+ returns: returnType,
37572
+ });
37573
+ }
37574
+ implement(func) {
37575
+ const validatedFunc = this.parse(func);
37576
+ return validatedFunc;
37577
+ }
37578
+ strictImplement(func) {
37579
+ const validatedFunc = this.parse(func);
37580
+ return validatedFunc;
37581
+ }
37582
+ static create(args, returns, params) {
37583
+ return new ZodFunction({
37584
+ args: (args
37585
+ ? args
37586
+ : ZodTuple.create([]).rest(ZodUnknown.create())),
37587
+ returns: returns || ZodUnknown.create(),
37588
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
37589
+ ...processCreateParams(params),
37590
+ });
37591
+ }
37592
+ }
37593
+ class ZodLazy extends ZodType {
37594
+ get schema() {
37595
+ return this._def.getter();
37596
+ }
37597
+ _parse(input) {
37598
+ const { ctx } = this._processInputParams(input);
37599
+ const lazySchema = this._def.getter();
37600
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
37601
+ }
37602
+ }
37603
+ ZodLazy.create = (getter, params) => {
37604
+ return new ZodLazy({
37605
+ getter: getter,
37606
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
37607
+ ...processCreateParams(params),
37608
+ });
37609
+ };
37610
+ class ZodLiteral extends ZodType {
37611
+ _parse(input) {
37612
+ if (input.data !== this._def.value) {
37613
+ const ctx = this._getOrReturnCtx(input);
37614
+ addIssueToContext(ctx, {
37615
+ received: ctx.data,
37616
+ code: ZodIssueCode.invalid_literal,
37617
+ expected: this._def.value,
37618
+ });
37619
+ return INVALID;
37620
+ }
37621
+ return { status: "valid", value: input.data };
37622
+ }
37623
+ get value() {
37624
+ return this._def.value;
37625
+ }
37626
+ }
37627
+ ZodLiteral.create = (value, params) => {
37628
+ return new ZodLiteral({
37629
+ value: value,
37630
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
37631
+ ...processCreateParams(params),
37632
+ });
37633
+ };
37634
+ function createZodEnum(values, params) {
37635
+ return new ZodEnum({
37636
+ values,
37637
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
37638
+ ...processCreateParams(params),
37639
+ });
37640
+ }
37641
+ class ZodEnum extends ZodType {
37642
+ _parse(input) {
37643
+ if (typeof input.data !== "string") {
37644
+ const ctx = this._getOrReturnCtx(input);
37645
+ const expectedValues = this._def.values;
37646
+ addIssueToContext(ctx, {
37647
+ expected: util.joinValues(expectedValues),
37648
+ received: ctx.parsedType,
37649
+ code: ZodIssueCode.invalid_type,
37650
+ });
37651
+ return INVALID;
37652
+ }
37653
+ if (this._def.values.indexOf(input.data) === -1) {
37654
+ const ctx = this._getOrReturnCtx(input);
37655
+ const expectedValues = this._def.values;
37656
+ addIssueToContext(ctx, {
37657
+ received: ctx.data,
37658
+ code: ZodIssueCode.invalid_enum_value,
37659
+ options: expectedValues,
37660
+ });
37661
+ return INVALID;
37662
+ }
37663
+ return OK(input.data);
37664
+ }
37665
+ get options() {
37666
+ return this._def.values;
37667
+ }
37668
+ get enum() {
37669
+ const enumValues = {};
37670
+ for (const val of this._def.values) {
37671
+ enumValues[val] = val;
37672
+ }
37673
+ return enumValues;
37674
+ }
37675
+ get Values() {
37676
+ const enumValues = {};
37677
+ for (const val of this._def.values) {
37678
+ enumValues[val] = val;
37679
+ }
37680
+ return enumValues;
37681
+ }
37682
+ get Enum() {
37683
+ const enumValues = {};
37684
+ for (const val of this._def.values) {
37685
+ enumValues[val] = val;
37686
+ }
37687
+ return enumValues;
37688
+ }
37689
+ extract(values) {
37690
+ return ZodEnum.create(values);
37691
+ }
37692
+ exclude(values) {
37693
+ return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
37694
+ }
37695
+ }
37696
+ ZodEnum.create = createZodEnum;
37697
+ class ZodNativeEnum extends ZodType {
37698
+ _parse(input) {
37699
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
37700
+ const ctx = this._getOrReturnCtx(input);
37701
+ if (ctx.parsedType !== ZodParsedType.string &&
37702
+ ctx.parsedType !== ZodParsedType.number) {
37703
+ const expectedValues = util.objectValues(nativeEnumValues);
37704
+ addIssueToContext(ctx, {
37705
+ expected: util.joinValues(expectedValues),
37706
+ received: ctx.parsedType,
37707
+ code: ZodIssueCode.invalid_type,
37708
+ });
37709
+ return INVALID;
37710
+ }
37711
+ if (nativeEnumValues.indexOf(input.data) === -1) {
37712
+ const expectedValues = util.objectValues(nativeEnumValues);
37713
+ addIssueToContext(ctx, {
37714
+ received: ctx.data,
37715
+ code: ZodIssueCode.invalid_enum_value,
37716
+ options: expectedValues,
37717
+ });
37718
+ return INVALID;
37719
+ }
37720
+ return OK(input.data);
37721
+ }
37722
+ get enum() {
37723
+ return this._def.values;
37724
+ }
37725
+ }
37726
+ ZodNativeEnum.create = (values, params) => {
37727
+ return new ZodNativeEnum({
37728
+ values: values,
37729
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
37730
+ ...processCreateParams(params),
37731
+ });
37732
+ };
37733
+ class ZodPromise extends ZodType {
37734
+ unwrap() {
37735
+ return this._def.type;
37736
+ }
37737
+ _parse(input) {
37738
+ const { ctx } = this._processInputParams(input);
37739
+ if (ctx.parsedType !== ZodParsedType.promise &&
37740
+ ctx.common.async === false) {
37741
+ addIssueToContext(ctx, {
37742
+ code: ZodIssueCode.invalid_type,
37743
+ expected: ZodParsedType.promise,
37744
+ received: ctx.parsedType,
37745
+ });
37746
+ return INVALID;
37747
+ }
37748
+ const promisified = ctx.parsedType === ZodParsedType.promise
37749
+ ? ctx.data
37750
+ : Promise.resolve(ctx.data);
37751
+ return OK(promisified.then((data) => {
37752
+ return this._def.type.parseAsync(data, {
37753
+ path: ctx.path,
37754
+ errorMap: ctx.common.contextualErrorMap,
37755
+ });
37756
+ }));
37757
+ }
37758
+ }
37759
+ ZodPromise.create = (schema, params) => {
37760
+ return new ZodPromise({
37761
+ type: schema,
37762
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
37763
+ ...processCreateParams(params),
37764
+ });
37765
+ };
37766
+ class ZodEffects extends ZodType {
37767
+ innerType() {
37768
+ return this._def.schema;
37769
+ }
37770
+ sourceType() {
37771
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects
37772
+ ? this._def.schema.sourceType()
37773
+ : this._def.schema;
37774
+ }
37775
+ _parse(input) {
37776
+ const { status, ctx } = this._processInputParams(input);
37777
+ const effect = this._def.effect || null;
37778
+ const checkCtx = {
37779
+ addIssue: (arg) => {
37780
+ addIssueToContext(ctx, arg);
37781
+ if (arg.fatal) {
37782
+ status.abort();
37783
+ }
37784
+ else {
37785
+ status.dirty();
37786
+ }
37787
+ },
37788
+ get path() {
37789
+ return ctx.path;
37790
+ },
37791
+ };
37792
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
37793
+ if (effect.type === "preprocess") {
37794
+ const processed = effect.transform(ctx.data, checkCtx);
37795
+ if (ctx.common.issues.length) {
37796
+ return {
37797
+ status: "dirty",
37798
+ value: ctx.data,
37799
+ };
37800
+ }
37801
+ if (ctx.common.async) {
37802
+ return Promise.resolve(processed).then((processed) => {
37803
+ return this._def.schema._parseAsync({
37804
+ data: processed,
37805
+ path: ctx.path,
37806
+ parent: ctx,
37807
+ });
37808
+ });
37809
+ }
37810
+ else {
37811
+ return this._def.schema._parseSync({
37812
+ data: processed,
37813
+ path: ctx.path,
37814
+ parent: ctx,
37815
+ });
37816
+ }
37817
+ }
37818
+ if (effect.type === "refinement") {
37819
+ const executeRefinement = (acc
37820
+ // effect: RefinementEffect<any>
37821
+ ) => {
37822
+ const result = effect.refinement(acc, checkCtx);
37823
+ if (ctx.common.async) {
37824
+ return Promise.resolve(result);
37825
+ }
37826
+ if (result instanceof Promise) {
37827
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
37828
+ }
37829
+ return acc;
37830
+ };
37831
+ if (ctx.common.async === false) {
37832
+ const inner = this._def.schema._parseSync({
37833
+ data: ctx.data,
37834
+ path: ctx.path,
37835
+ parent: ctx,
37836
+ });
37837
+ if (inner.status === "aborted")
37838
+ return INVALID;
37839
+ if (inner.status === "dirty")
37840
+ status.dirty();
37841
+ // return value is ignored
37842
+ executeRefinement(inner.value);
37843
+ return { status: status.value, value: inner.value };
37844
+ }
37845
+ else {
37846
+ return this._def.schema
37847
+ ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
37848
+ .then((inner) => {
37849
+ if (inner.status === "aborted")
37850
+ return INVALID;
37851
+ if (inner.status === "dirty")
37852
+ status.dirty();
37853
+ return executeRefinement(inner.value).then(() => {
37854
+ return { status: status.value, value: inner.value };
37855
+ });
37856
+ });
37857
+ }
37858
+ }
37859
+ if (effect.type === "transform") {
37860
+ if (ctx.common.async === false) {
37861
+ const base = this._def.schema._parseSync({
37862
+ data: ctx.data,
37863
+ path: ctx.path,
37864
+ parent: ctx,
37865
+ });
37866
+ if (!isValid(base))
37867
+ return base;
37868
+ const result = effect.transform(base.value, checkCtx);
37869
+ if (result instanceof Promise) {
37870
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
37871
+ }
37872
+ return { status: status.value, value: result };
37873
+ }
37874
+ else {
37875
+ return this._def.schema
37876
+ ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
37877
+ .then((base) => {
37878
+ if (!isValid(base))
37879
+ return base;
37880
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
37881
+ });
37882
+ }
37883
+ }
37884
+ util.assertNever(effect);
37885
+ }
37886
+ }
37887
+ ZodEffects.create = (schema, effect, params) => {
37888
+ return new ZodEffects({
37889
+ schema,
37890
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
37891
+ effect,
37892
+ ...processCreateParams(params),
37893
+ });
37894
+ };
37895
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
37896
+ return new ZodEffects({
37897
+ schema,
37898
+ effect: { type: "preprocess", transform: preprocess },
37899
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
37900
+ ...processCreateParams(params),
37901
+ });
37902
+ };
37903
+ class ZodOptional extends ZodType {
37904
+ _parse(input) {
37905
+ const parsedType = this._getType(input);
37906
+ if (parsedType === ZodParsedType.undefined) {
37907
+ return OK(undefined);
37908
+ }
37909
+ return this._def.innerType._parse(input);
37910
+ }
37911
+ unwrap() {
37912
+ return this._def.innerType;
37913
+ }
37914
+ }
37915
+ ZodOptional.create = (type, params) => {
37916
+ return new ZodOptional({
37917
+ innerType: type,
37918
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
37919
+ ...processCreateParams(params),
37920
+ });
37921
+ };
37922
+ class ZodNullable extends ZodType {
37923
+ _parse(input) {
37924
+ const parsedType = this._getType(input);
37925
+ if (parsedType === ZodParsedType.null) {
37926
+ return OK(null);
37927
+ }
37928
+ return this._def.innerType._parse(input);
37929
+ }
37930
+ unwrap() {
37931
+ return this._def.innerType;
37932
+ }
37933
+ }
37934
+ ZodNullable.create = (type, params) => {
37935
+ return new ZodNullable({
37936
+ innerType: type,
37937
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
37938
+ ...processCreateParams(params),
37939
+ });
37940
+ };
37941
+ class ZodDefault extends ZodType {
37942
+ _parse(input) {
37943
+ const { ctx } = this._processInputParams(input);
37944
+ let data = ctx.data;
37945
+ if (ctx.parsedType === ZodParsedType.undefined) {
37946
+ data = this._def.defaultValue();
37947
+ }
37948
+ return this._def.innerType._parse({
37949
+ data,
37950
+ path: ctx.path,
37951
+ parent: ctx,
37952
+ });
37953
+ }
37954
+ removeDefault() {
37955
+ return this._def.innerType;
37956
+ }
37957
+ }
37958
+ ZodDefault.create = (type, params) => {
37959
+ return new ZodDefault({
37960
+ innerType: type,
37961
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
37962
+ defaultValue: typeof params.default === "function"
37963
+ ? params.default
37964
+ : () => params.default,
37965
+ ...processCreateParams(params),
37966
+ });
37967
+ };
37968
+ class ZodCatch extends ZodType {
37969
+ _parse(input) {
37970
+ const { ctx } = this._processInputParams(input);
37971
+ // newCtx is used to not collect issues from inner types in ctx
37972
+ const newCtx = {
37973
+ ...ctx,
37974
+ common: {
37975
+ ...ctx.common,
37976
+ issues: [],
37977
+ },
37978
+ };
37979
+ const result = this._def.innerType._parse({
37980
+ data: newCtx.data,
37981
+ path: newCtx.path,
37982
+ parent: {
37983
+ ...newCtx,
37984
+ },
37985
+ });
37986
+ if (isAsync(result)) {
37987
+ return result.then((result) => {
37988
+ return {
37989
+ status: "valid",
37990
+ value: result.status === "valid"
37991
+ ? result.value
37992
+ : this._def.catchValue({
37993
+ get error() {
37994
+ return new ZodError(newCtx.common.issues);
37995
+ },
37996
+ input: newCtx.data,
37997
+ }),
37998
+ };
37999
+ });
38000
+ }
38001
+ else {
38002
+ return {
38003
+ status: "valid",
38004
+ value: result.status === "valid"
38005
+ ? result.value
38006
+ : this._def.catchValue({
38007
+ get error() {
38008
+ return new ZodError(newCtx.common.issues);
38009
+ },
38010
+ input: newCtx.data,
38011
+ }),
38012
+ };
38013
+ }
38014
+ }
38015
+ removeCatch() {
38016
+ return this._def.innerType;
38017
+ }
38018
+ }
38019
+ ZodCatch.create = (type, params) => {
38020
+ return new ZodCatch({
38021
+ innerType: type,
38022
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
38023
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
38024
+ ...processCreateParams(params),
38025
+ });
38026
+ };
38027
+ class ZodNaN extends ZodType {
38028
+ _parse(input) {
38029
+ const parsedType = this._getType(input);
38030
+ if (parsedType !== ZodParsedType.nan) {
38031
+ const ctx = this._getOrReturnCtx(input);
38032
+ addIssueToContext(ctx, {
38033
+ code: ZodIssueCode.invalid_type,
38034
+ expected: ZodParsedType.nan,
38035
+ received: ctx.parsedType,
38036
+ });
38037
+ return INVALID;
38038
+ }
38039
+ return { status: "valid", value: input.data };
38040
+ }
38041
+ }
38042
+ ZodNaN.create = (params) => {
38043
+ return new ZodNaN({
38044
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
38045
+ ...processCreateParams(params),
38046
+ });
38047
+ };
38048
+ const BRAND = Symbol("zod_brand");
38049
+ class ZodBranded extends ZodType {
38050
+ _parse(input) {
38051
+ const { ctx } = this._processInputParams(input);
38052
+ const data = ctx.data;
38053
+ return this._def.type._parse({
38054
+ data,
38055
+ path: ctx.path,
38056
+ parent: ctx,
38057
+ });
38058
+ }
38059
+ unwrap() {
38060
+ return this._def.type;
38061
+ }
38062
+ }
38063
+ class ZodPipeline extends ZodType {
38064
+ _parse(input) {
38065
+ const { status, ctx } = this._processInputParams(input);
38066
+ if (ctx.common.async) {
38067
+ const handleAsync = async () => {
38068
+ const inResult = await this._def.in._parseAsync({
38069
+ data: ctx.data,
38070
+ path: ctx.path,
38071
+ parent: ctx,
38072
+ });
38073
+ if (inResult.status === "aborted")
38074
+ return INVALID;
38075
+ if (inResult.status === "dirty") {
38076
+ status.dirty();
38077
+ return DIRTY(inResult.value);
38078
+ }
38079
+ else {
38080
+ return this._def.out._parseAsync({
38081
+ data: inResult.value,
38082
+ path: ctx.path,
38083
+ parent: ctx,
38084
+ });
38085
+ }
38086
+ };
38087
+ return handleAsync();
38088
+ }
38089
+ else {
38090
+ const inResult = this._def.in._parseSync({
38091
+ data: ctx.data,
38092
+ path: ctx.path,
38093
+ parent: ctx,
38094
+ });
38095
+ if (inResult.status === "aborted")
38096
+ return INVALID;
38097
+ if (inResult.status === "dirty") {
38098
+ status.dirty();
38099
+ return {
38100
+ status: "dirty",
38101
+ value: inResult.value,
38102
+ };
38103
+ }
38104
+ else {
38105
+ return this._def.out._parseSync({
38106
+ data: inResult.value,
38107
+ path: ctx.path,
38108
+ parent: ctx,
38109
+ });
38110
+ }
38111
+ }
38112
+ }
38113
+ static create(a, b) {
38114
+ return new ZodPipeline({
38115
+ in: a,
38116
+ out: b,
38117
+ typeName: ZodFirstPartyTypeKind.ZodPipeline,
38118
+ });
38119
+ }
38120
+ }
38121
+ class ZodReadonly extends ZodType {
38122
+ _parse(input) {
38123
+ const result = this._def.innerType._parse(input);
38124
+ if (isValid(result)) {
38125
+ result.value = Object.freeze(result.value);
38126
+ }
38127
+ return result;
38128
+ }
38129
+ }
38130
+ ZodReadonly.create = (type, params) => {
38131
+ return new ZodReadonly({
38132
+ innerType: type,
38133
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
38134
+ ...processCreateParams(params),
38135
+ });
38136
+ };
38137
+ const custom = (check, params = {},
38138
+ /**
38139
+ * @deprecated
38140
+ *
38141
+ * Pass `fatal` into the params object instead:
38142
+ *
38143
+ * ```ts
38144
+ * z.string().custom((val) => val.length > 5, { fatal: false })
38145
+ * ```
38146
+ *
38147
+ */
38148
+ fatal) => {
38149
+ if (check)
38150
+ return ZodAny.create().superRefine((data, ctx) => {
38151
+ var _a, _b;
38152
+ if (!check(data)) {
38153
+ const p = typeof params === "function"
38154
+ ? params(data)
38155
+ : typeof params === "string"
38156
+ ? { message: params }
38157
+ : params;
38158
+ const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
38159
+ const p2 = typeof p === "string" ? { message: p } : p;
38160
+ ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
38161
+ }
38162
+ });
38163
+ return ZodAny.create();
38164
+ };
38165
+ const late = {
38166
+ object: ZodObject.lazycreate,
38167
+ };
38168
+ var ZodFirstPartyTypeKind;
38169
+ (function (ZodFirstPartyTypeKind) {
38170
+ ZodFirstPartyTypeKind["ZodString"] = "ZodString";
38171
+ ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
38172
+ ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
38173
+ ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
38174
+ ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
38175
+ ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
38176
+ ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
38177
+ ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
38178
+ ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
38179
+ ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
38180
+ ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
38181
+ ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
38182
+ ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
38183
+ ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
38184
+ ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
38185
+ ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
38186
+ ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
38187
+ ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
38188
+ ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
38189
+ ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
38190
+ ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
38191
+ ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
38192
+ ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
38193
+ ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
38194
+ ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
38195
+ ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
38196
+ ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
38197
+ ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
38198
+ ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
38199
+ ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
38200
+ ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
38201
+ ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
38202
+ ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
38203
+ ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
38204
+ ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
38205
+ ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
38206
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
38207
+ const instanceOfType = (
38208
+ // const instanceOfType = <T extends new (...args: any[]) => any>(
38209
+ cls, params = {
38210
+ message: `Input not instance of ${cls.name}`,
38211
+ }) => custom((data) => data instanceof cls, params);
38212
+ const stringType = ZodString.create;
38213
+ const numberType = ZodNumber.create;
38214
+ const nanType = ZodNaN.create;
38215
+ const bigIntType = ZodBigInt.create;
38216
+ const booleanType = ZodBoolean.create;
38217
+ const dateType = ZodDate.create;
38218
+ const symbolType = ZodSymbol.create;
38219
+ const undefinedType = ZodUndefined.create;
38220
+ const nullType = ZodNull.create;
38221
+ const anyType = ZodAny.create;
38222
+ const unknownType = ZodUnknown.create;
38223
+ const neverType = ZodNever.create;
38224
+ const voidType = ZodVoid.create;
38225
+ const arrayType = ZodArray.create;
38226
+ const objectType = ZodObject.create;
38227
+ const strictObjectType = ZodObject.strictCreate;
38228
+ const unionType = ZodUnion.create;
38229
+ const discriminatedUnionType = ZodDiscriminatedUnion.create;
38230
+ const intersectionType = ZodIntersection.create;
38231
+ const tupleType = ZodTuple.create;
38232
+ const recordType = ZodRecord.create;
38233
+ const mapType = ZodMap.create;
38234
+ const setType = ZodSet.create;
38235
+ const functionType = ZodFunction.create;
38236
+ const lazyType = ZodLazy.create;
38237
+ const literalType = ZodLiteral.create;
38238
+ const enumType = ZodEnum.create;
38239
+ const nativeEnumType = ZodNativeEnum.create;
38240
+ const promiseType = ZodPromise.create;
38241
+ const effectsType = ZodEffects.create;
38242
+ const optionalType = ZodOptional.create;
38243
+ const nullableType = ZodNullable.create;
38244
+ const preprocessType = ZodEffects.createWithPreprocess;
38245
+ const pipelineType = ZodPipeline.create;
38246
+ const ostring = () => stringType().optional();
38247
+ const onumber = () => numberType().optional();
38248
+ const oboolean = () => booleanType().optional();
38249
+ const coerce = {
38250
+ string: ((arg) => ZodString.create({ ...arg, coerce: true })),
38251
+ number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
38252
+ boolean: ((arg) => ZodBoolean.create({
38253
+ ...arg,
38254
+ coerce: true,
38255
+ })),
38256
+ bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
38257
+ date: ((arg) => ZodDate.create({ ...arg, coerce: true })),
38258
+ };
38259
+ const NEVER = INVALID;
38260
+
38261
+ var z = /*#__PURE__*/Object.freeze({
38262
+ __proto__: null,
38263
+ defaultErrorMap: errorMap,
38264
+ setErrorMap: setErrorMap,
38265
+ getErrorMap: getErrorMap,
38266
+ makeIssue: makeIssue,
38267
+ EMPTY_PATH: EMPTY_PATH,
38268
+ addIssueToContext: addIssueToContext,
38269
+ ParseStatus: ParseStatus,
38270
+ INVALID: INVALID,
38271
+ DIRTY: DIRTY,
38272
+ OK: OK,
38273
+ isAborted: isAborted,
38274
+ isDirty: isDirty,
38275
+ isValid: isValid,
38276
+ isAsync: isAsync,
38277
+ get util () { return util; },
38278
+ get objectUtil () { return objectUtil; },
38279
+ ZodParsedType: ZodParsedType,
38280
+ getParsedType: getParsedType,
38281
+ ZodType: ZodType,
38282
+ ZodString: ZodString,
38283
+ ZodNumber: ZodNumber,
38284
+ ZodBigInt: ZodBigInt,
38285
+ ZodBoolean: ZodBoolean,
38286
+ ZodDate: ZodDate,
38287
+ ZodSymbol: ZodSymbol,
38288
+ ZodUndefined: ZodUndefined,
38289
+ ZodNull: ZodNull,
38290
+ ZodAny: ZodAny,
38291
+ ZodUnknown: ZodUnknown,
38292
+ ZodNever: ZodNever,
38293
+ ZodVoid: ZodVoid,
38294
+ ZodArray: ZodArray,
38295
+ ZodObject: ZodObject,
38296
+ ZodUnion: ZodUnion,
38297
+ ZodDiscriminatedUnion: ZodDiscriminatedUnion,
38298
+ ZodIntersection: ZodIntersection,
38299
+ ZodTuple: ZodTuple,
38300
+ ZodRecord: ZodRecord,
38301
+ ZodMap: ZodMap,
38302
+ ZodSet: ZodSet,
38303
+ ZodFunction: ZodFunction,
38304
+ ZodLazy: ZodLazy,
38305
+ ZodLiteral: ZodLiteral,
38306
+ ZodEnum: ZodEnum,
38307
+ ZodNativeEnum: ZodNativeEnum,
38308
+ ZodPromise: ZodPromise,
38309
+ ZodEffects: ZodEffects,
38310
+ ZodTransformer: ZodEffects,
38311
+ ZodOptional: ZodOptional,
38312
+ ZodNullable: ZodNullable,
38313
+ ZodDefault: ZodDefault,
38314
+ ZodCatch: ZodCatch,
38315
+ ZodNaN: ZodNaN,
38316
+ BRAND: BRAND,
38317
+ ZodBranded: ZodBranded,
38318
+ ZodPipeline: ZodPipeline,
38319
+ ZodReadonly: ZodReadonly,
38320
+ custom: custom,
38321
+ Schema: ZodType,
38322
+ ZodSchema: ZodType,
38323
+ late: late,
38324
+ get ZodFirstPartyTypeKind () { return ZodFirstPartyTypeKind; },
38325
+ coerce: coerce,
38326
+ any: anyType,
38327
+ array: arrayType,
38328
+ bigint: bigIntType,
38329
+ boolean: booleanType,
38330
+ date: dateType,
38331
+ discriminatedUnion: discriminatedUnionType,
38332
+ effect: effectsType,
38333
+ 'enum': enumType,
38334
+ 'function': functionType,
38335
+ 'instanceof': instanceOfType,
38336
+ intersection: intersectionType,
38337
+ lazy: lazyType,
38338
+ literal: literalType,
38339
+ map: mapType,
38340
+ nan: nanType,
38341
+ nativeEnum: nativeEnumType,
38342
+ never: neverType,
38343
+ 'null': nullType,
38344
+ nullable: nullableType,
38345
+ number: numberType,
38346
+ object: objectType,
38347
+ oboolean: oboolean,
38348
+ onumber: onumber,
38349
+ optional: optionalType,
38350
+ ostring: ostring,
38351
+ pipeline: pipelineType,
38352
+ preprocess: preprocessType,
38353
+ promise: promiseType,
38354
+ record: recordType,
38355
+ set: setType,
38356
+ strictObject: strictObjectType,
38357
+ string: stringType,
38358
+ symbol: symbolType,
38359
+ transformer: effectsType,
38360
+ tuple: tupleType,
38361
+ 'undefined': undefinedType,
38362
+ union: unionType,
38363
+ unknown: unknownType,
38364
+ 'void': voidType,
38365
+ NEVER: NEVER,
38366
+ ZodIssueCode: ZodIssueCode,
38367
+ quotelessJson: quotelessJson,
38368
+ ZodError: ZodError
38369
+ });
38370
+
34355
38371
  /** Detect free variable `global` from Node.js. */
34356
38372
  var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
34357
38373
 
@@ -38862,6 +42878,236 @@ const resolveSimpleDesignToken = (templateString, variableName) => {
38862
42878
  return '0px';
38863
42879
  };
38864
42880
 
42881
+ // If more than one version is supported, use z.union
42882
+ const SchemaVersions = z.literal('2023-09-28');
42883
+ // Keep deprecated versions here just for reference
42884
+ z.union([
42885
+ z.literal('2023-08-23'),
42886
+ z.literal('2023-07-26'),
42887
+ z.literal('2023-06-27'),
42888
+ ]);
42889
+
42890
+ const DefinitionPropertyTypeSchema = z.enum([
42891
+ 'Text',
42892
+ 'RichText',
42893
+ 'Number',
42894
+ 'Date',
42895
+ 'Boolean',
42896
+ 'Location',
42897
+ 'Media',
42898
+ 'Object',
42899
+ 'Hyperlink',
42900
+ ]);
42901
+ const DefinitionPropertyKeySchema = z
42902
+ .string()
42903
+ .regex(/^[a-zA-Z0-9-_]{1,32}$/, { message: 'Property needs to match: /^[a-zA-Z0-9-_]{1,32}$/' });
42904
+ z.object({
42905
+ id: DefinitionPropertyKeySchema,
42906
+ variables: z.record(DefinitionPropertyKeySchema, z.object({
42907
+ // TODO - extend with definition of validations and defaultValue
42908
+ displayName: z.string().optional(),
42909
+ type: DefinitionPropertyTypeSchema,
42910
+ description: z.string().optional(),
42911
+ group: z.string().optional(),
42912
+ })),
42913
+ });
42914
+
42915
+ const uuidKeySchema = z
42916
+ .string()
42917
+ .regex(/^[a-zA-Z0-9-_]{1,21}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,21}$/' });
42918
+ /**
42919
+ * Property keys for imported components have a limit of 32 characters (to be implemented) while
42920
+ * property keys for patterns have a limit of 54 characters (<32-char-variabl-name>_<21-char-nanoid-id>).
42921
+ * Because we cannot distinguish between the two in the componentTree, we will use the larger limit for both.
42922
+ */
42923
+ const propertyKeySchema = z
42924
+ .string()
42925
+ .regex(/^[a-zA-Z0-9-_]{1,54}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,54}$/' });
42926
+ const DataSourceSchema = z.record(uuidKeySchema, z.object({
42927
+ sys: z.object({
42928
+ type: z.literal('Link'),
42929
+ id: z.string(),
42930
+ linkType: z.enum(['Entry', 'Asset']),
42931
+ }),
42932
+ }));
42933
+ const PrimitiveValueSchema = z.union([
42934
+ z.string(),
42935
+ z.boolean(),
42936
+ z.number(),
42937
+ z.record(z.any(), z.any()),
42938
+ z.undefined(),
42939
+ ]);
42940
+ const ValuesByBreakpointSchema = z.record(z.lazy(() => PrimitiveValueSchema));
42941
+ const DesignValueSchema = z
42942
+ .object({
42943
+ type: z.literal('DesignValue'),
42944
+ valuesByBreakpoint: ValuesByBreakpointSchema,
42945
+ })
42946
+ .strict();
42947
+ const BoundValueSchema = z
42948
+ .object({
42949
+ type: z.literal('BoundValue'),
42950
+ path: z.string(),
42951
+ })
42952
+ .strict();
42953
+ const HyperlinkValueSchema = z
42954
+ .object({
42955
+ type: z.literal('HyperlinkValue'),
42956
+ linkTargetKey: z.string(),
42957
+ overrides: z.object({}).optional(),
42958
+ })
42959
+ .strict();
42960
+ const UnboundValueSchema = z
42961
+ .object({
42962
+ type: z.literal('UnboundValue'),
42963
+ key: z.string(),
42964
+ })
42965
+ .strict();
42966
+ const ComponentValueSchema = z
42967
+ .object({
42968
+ type: z.literal('ComponentValue'),
42969
+ key: z.string(),
42970
+ })
42971
+ .strict();
42972
+ const ComponentPropertyValueSchema = z.discriminatedUnion('type', [
42973
+ DesignValueSchema,
42974
+ BoundValueSchema,
42975
+ UnboundValueSchema,
42976
+ HyperlinkValueSchema,
42977
+ ComponentValueSchema,
42978
+ ]);
42979
+ const BreakpointSchema = z
42980
+ .object({
42981
+ id: propertyKeySchema,
42982
+ query: z.string().regex(/^\*$|^<[0-9*]+px$/),
42983
+ previewSize: z.string(),
42984
+ displayName: z.string(),
42985
+ displayIconUrl: z.string().optional(),
42986
+ })
42987
+ .strict();
42988
+ const UnboundValuesSchema = z.record(uuidKeySchema, z.object({
42989
+ value: PrimitiveValueSchema,
42990
+ }));
42991
+ // Use helper schema to define a recursive schema with its type correctly below
42992
+ const BaseComponentTreeNodeSchema = z.object({
42993
+ definitionId: DefinitionPropertyKeySchema,
42994
+ displayName: z.string().optional(),
42995
+ slotId: z.string().optional(),
42996
+ variables: z.record(propertyKeySchema, ComponentPropertyValueSchema),
42997
+ });
42998
+ const ComponentTreeNodeSchema = BaseComponentTreeNodeSchema.extend({
42999
+ children: z.lazy(() => ComponentTreeNodeSchema.array()),
43000
+ });
43001
+ const ComponentSettingsSchema = z.object({
43002
+ variableDefinitions: z.record(z.string().regex(/^[a-zA-Z0-9-_]{1,54}$/), // Here the key is <variableName>_<nanoidId> so we need to allow for a longer length
43003
+ z.object({
43004
+ displayName: z.string().optional(),
43005
+ type: DefinitionPropertyTypeSchema,
43006
+ defaultValue: PrimitiveValueSchema.or(ComponentPropertyValueSchema).optional(),
43007
+ description: z.string().optional(),
43008
+ group: z.string().optional(),
43009
+ validations: z
43010
+ .object({
43011
+ required: z.boolean().optional(),
43012
+ format: z.literal('URL').optional(),
43013
+ in: z
43014
+ .array(z.object({
43015
+ value: z.union([z.string(), z.number()]),
43016
+ displayName: z.string().optional(),
43017
+ }))
43018
+ .optional(),
43019
+ })
43020
+ .optional(),
43021
+ })),
43022
+ });
43023
+ const UsedComponentsSchema = z.array(z.object({
43024
+ sys: z.object({
43025
+ type: z.literal('Link'),
43026
+ id: z.string(),
43027
+ linkType: z.literal('Entry'),
43028
+ }),
43029
+ }));
43030
+ const breakpointsRefinement = (value, ctx) => {
43031
+ if (!value.length || value[0].query !== '*') {
43032
+ ctx.addIssue({
43033
+ code: z.ZodIssueCode.custom,
43034
+ message: `The first breakpoint should include the following attributes: { "query": "*" }`,
43035
+ });
43036
+ }
43037
+ const hasDuplicateIds = value.some((currentBreakpoint, currentBreakpointIndex) => {
43038
+ // check if the current breakpoint id is found in the rest of the array
43039
+ const breakpointIndex = value.findIndex((breakpoint) => breakpoint.id === currentBreakpoint.id);
43040
+ return breakpointIndex !== currentBreakpointIndex;
43041
+ });
43042
+ if (hasDuplicateIds) {
43043
+ ctx.addIssue({
43044
+ code: z.ZodIssueCode.custom,
43045
+ message: `Breakpoint IDs must be unique`,
43046
+ });
43047
+ }
43048
+ // Extract the queries boundary by removing the special characters around it
43049
+ const queries = value.map((bp) => bp.query === '*' ? bp.query : parseInt(bp.query.replace(/px|<|>/, '')));
43050
+ // sort updates queries array in place so we need to create a copy
43051
+ const originalQueries = [...queries];
43052
+ queries.sort((q1, q2) => {
43053
+ if (q1 === '*') {
43054
+ return -1;
43055
+ }
43056
+ if (q2 === '*') {
43057
+ return 1;
43058
+ }
43059
+ return q1 > q2 ? -1 : 1;
43060
+ });
43061
+ if (originalQueries.join('') !== queries.join('')) {
43062
+ ctx.addIssue({
43063
+ code: z.ZodIssueCode.custom,
43064
+ message: `Breakpoints should be ordered from largest to smallest pixel value`,
43065
+ });
43066
+ }
43067
+ };
43068
+ const componentSettingsRefinement = (value, ctx) => {
43069
+ const { componentSettings, usedComponents } = value;
43070
+ if (!componentSettings || !usedComponents) {
43071
+ return;
43072
+ }
43073
+ const localeKey = Object.keys(componentSettings ?? {})[0];
43074
+ if (componentSettings[localeKey] !== undefined && usedComponents[localeKey] !== undefined) {
43075
+ ctx.addIssue({
43076
+ code: z.ZodIssueCode.custom,
43077
+ message: `'componentSettings' field cannot be used in conjunction with 'usedComponents' field`,
43078
+ path: ['componentSettings', localeKey],
43079
+ });
43080
+ }
43081
+ };
43082
+ const ComponentTreeSchema = z
43083
+ .object({
43084
+ breakpoints: z.array(BreakpointSchema).superRefine(breakpointsRefinement),
43085
+ children: z.array(ComponentTreeNodeSchema),
43086
+ schemaVersion: SchemaVersions,
43087
+ })
43088
+ .strict();
43089
+ const localeWrapper = (fieldSchema) => z.record(z.string(), fieldSchema);
43090
+ z
43091
+ .object({
43092
+ componentTree: localeWrapper(ComponentTreeSchema),
43093
+ dataSource: localeWrapper(DataSourceSchema),
43094
+ unboundValues: localeWrapper(UnboundValuesSchema),
43095
+ usedComponents: localeWrapper(UsedComponentsSchema).optional(),
43096
+ componentSettings: localeWrapper(ComponentSettingsSchema).optional(),
43097
+ })
43098
+ .superRefine(componentSettingsRefinement);
43099
+
43100
+ var CodeNames;
43101
+ (function (CodeNames) {
43102
+ CodeNames["Type"] = "type";
43103
+ CodeNames["Required"] = "required";
43104
+ CodeNames["Unexpected"] = "unexpected";
43105
+ CodeNames["Regex"] = "regex";
43106
+ CodeNames["In"] = "in";
43107
+ CodeNames["Size"] = "size";
43108
+ CodeNames["Custom"] = "custom";
43109
+ })(CodeNames || (CodeNames = {}));
43110
+
38865
43111
  const MEDIA_QUERY_REGEXP = /(<|>)(\d{1,})(px|cm|mm|in|pt|pc)$/;
38866
43112
  const toCSSMediaQuery = ({ query }) => {
38867
43113
  if (query === '*')
@@ -50029,6 +54275,7 @@ const SCROLL_STATES = {
50029
54275
  const OUTGOING_EVENTS = {
50030
54276
  Connected: 'connected',
50031
54277
  DesignTokens: 'registerDesignTokens',
54278
+ RegisteredBreakpoints: 'registeredBreakpoints',
50032
54279
  HoveredSection: 'hoveredSection',
50033
54280
  MouseMove: 'mouseMove',
50034
54281
  NewHoveredElement: 'newHoveredElement',
@@ -50575,7 +54822,7 @@ function getStyle$2(style, snapshot) {
50575
54822
  transitionDuration: `0.001s`,
50576
54823
  };
50577
54824
  }
50578
- const DraggableComponent = ({ children, id, index, isAssemblyBlock = false, isSelected = false, onClick = () => null, onMouseOver = () => null, coordinates, userIsDragging, style, wrapperProps, isContainer, blockId, isDragDisabled = false, placeholder, definition, ...rest }) => {
54825
+ const DraggableComponent = ({ children, id, index, isAssemblyBlock = false, isSelected = false, onClick = () => null, onMouseOver = () => null, coordinates, userIsDragging, style, wrapperProps, isContainer, blockId, isDragDisabled = false, placeholder, definition, displayName, ...rest }) => {
50579
54826
  const ref = reactExports.useRef(null);
50580
54827
  const setDomRect = useDraggedItemStore((state) => state.setDomRect);
50581
54828
  const isHoveredComponent = useDraggedItemStore((state) => state.hoveredComponentId === id);
@@ -50603,7 +54850,7 @@ const DraggableComponent = ({ children, id, index, isAssemblyBlock = false, isSe
50603
54850
  e.stopPropagation();
50604
54851
  setDomRect(e.currentTarget.getBoundingClientRect());
50605
54852
  }, onMouseOver: onMouseOver, onClick: onClick },
50606
- React.createElement(Tooltip, { id: id, coordinates: coordinates, isAssemblyBlock: isAssemblyBlock, isContainer: isContainer, label: definition.name || 'No label specified' }),
54853
+ React.createElement(Tooltip, { id: id, coordinates: coordinates, isAssemblyBlock: isAssemblyBlock, isContainer: isContainer, label: displayName || definition.name || 'No label specified' }),
50607
54854
  React.createElement(Placeholder, { ...placeholder, id: id }),
50608
54855
  children))));
50609
54856
  };
@@ -51772,7 +56019,7 @@ const useComponent = ({ node: rawNode, resolveDesignValue, renderDropzone, userI
51772
56019
  * component.
51773
56020
  */
51774
56021
  const DraggableChildComponent = (props) => {
51775
- const { elementToRender, id, index, isAssemblyBlock = false, isSelected = false, onClick = () => null, onMouseOver = () => null, coordinates, userIsDragging, style, isContainer, blockId, isDragDisabled = false, wrapperProps, definition, } = props;
56022
+ const { elementToRender, id, index, isAssemblyBlock = false, isSelected = false, onClick = () => null, onMouseOver = () => null, coordinates, userIsDragging, style, isContainer, blockId, isDragDisabled = false, wrapperProps, definition, displayName, } = props;
51776
56023
  const isHoveredComponent = useDraggedItemStore((state) => state.hoveredComponentId === id);
51777
56024
  return (React.createElement(PublicDraggable, { key: id, draggableId: id, index: index, isDragDisabled: isDragDisabled }, (provided, snapshot) => elementToRender({
51778
56025
  ['data-ctfl-draggable-id']: id,
@@ -51794,7 +56041,7 @@ const DraggableChildComponent = (props) => {
51794
56041
  },
51795
56042
  onClick,
51796
56043
  onMouseOver,
51797
- Tooltip: (React.createElement(Tooltip, { id: id, coordinates: coordinates, isAssemblyBlock: isAssemblyBlock, isContainer: isContainer, label: definition.name || 'No label specified' })),
56044
+ Tooltip: (React.createElement(Tooltip, { id: id, coordinates: coordinates, isAssemblyBlock: isAssemblyBlock, isContainer: isContainer, label: displayName || definition.name || 'No label specified' })),
51798
56045
  })));
51799
56046
  };
51800
56047
 
@@ -53022,6 +57269,7 @@ const EditorBlock = ({ node: rawNode, resolveDesignValue, renderDropzone, index,
53022
57269
  userIsDragging,
53023
57270
  });
53024
57271
  const coordinates = useSelectedInstanceCoordinates({ node });
57272
+ const displayName = node.data.displayName;
53025
57273
  const isContainer = node.data.blockId === CONTENTFUL_COMPONENTS.container.id;
53026
57274
  const isSingleColumn = node.data.blockId === CONTENTFUL_COMPONENTS.singleColumn.id;
53027
57275
  const isAssemblyBlock = node.type === ASSEMBLY_BLOCK_NODE_TYPE;
@@ -53054,9 +57302,9 @@ const EditorBlock = ({ node: rawNode, resolveDesignValue, renderDropzone, index,
53054
57302
  });
53055
57303
  };
53056
57304
  if (isSingleColumn) {
53057
- return (React.createElement(DraggableChildComponent, { elementToRender: elementToRender, id: componentId, index: index, isAssemblyBlock: isAssembly || isAssemblyBlock, isDragDisabled: true, isSelected: selectedNodeId === componentId, userIsDragging: userIsDragging, isContainer: isContainer, blockId: node.data.blockId, coordinates: coordinates, wrapperProps: wrapperProps, onClick: onClick, onMouseOver: onMouseOver, definition: definition }));
57305
+ return (React.createElement(DraggableChildComponent, { elementToRender: elementToRender, id: componentId, index: index, isAssemblyBlock: isAssembly || isAssemblyBlock, isDragDisabled: true, isSelected: selectedNodeId === componentId, userIsDragging: userIsDragging, isContainer: isContainer, blockId: node.data.blockId, coordinates: coordinates, wrapperProps: wrapperProps, onClick: onClick, onMouseOver: onMouseOver, definition: definition, displayName: displayName }));
53058
57306
  }
53059
- return (React.createElement(DraggableComponent, { placeholder: placeholder, definition: definition, id: componentId, index: index, isAssemblyBlock: isAssembly || isAssemblyBlock, isDragDisabled: isAssemblyBlock, isSelected: selectedNodeId === componentId, userIsDragging: userIsDragging, isContainer: isContainer, blockId: node.data.blockId, coordinates: coordinates, wrapperProps: wrapperProps, onClick: onClick, onMouseOver: onMouseOver },
57307
+ return (React.createElement(DraggableComponent, { placeholder: placeholder, definition: definition, id: componentId, index: index, isAssemblyBlock: isAssembly || isAssemblyBlock, isDragDisabled: isAssemblyBlock, isSelected: selectedNodeId === componentId, userIsDragging: userIsDragging, isContainer: isContainer, blockId: node.data.blockId, coordinates: coordinates, wrapperProps: wrapperProps, onClick: onClick, onMouseOver: onMouseOver, displayName: displayName },
53060
57308
  elementToRender(),
53061
57309
  isStructureComponent && userIsDragging && (React.createElement(Hitboxes, { parentZoneId: zoneId, zoneId: componentId, isEmptyZone: isEmptyZone }))));
53062
57310
  };