@embeddable.com/sdk-core 3.1.8 → 3.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.esm.js +299 -70
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +299 -70
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
- package/src/push.ts +2 -2
package/lib/index.esm.js
CHANGED
|
@@ -231,6 +231,11 @@ let ZodError$1 = class ZodError extends Error {
|
|
|
231
231
|
processError(this);
|
|
232
232
|
return fieldErrors;
|
|
233
233
|
}
|
|
234
|
+
static assert(value) {
|
|
235
|
+
if (!(value instanceof ZodError)) {
|
|
236
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
234
239
|
toString() {
|
|
235
240
|
return this.message;
|
|
236
241
|
}
|
|
@@ -262,6 +267,11 @@ ZodError$1.create = (issues) => {
|
|
|
262
267
|
const error = new ZodError$1(issues);
|
|
263
268
|
return error;
|
|
264
269
|
};
|
|
270
|
+
|
|
271
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
272
|
+
var e = new Error(message);
|
|
273
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
274
|
+
};
|
|
265
275
|
|
|
266
276
|
var errorUtil$1;
|
|
267
277
|
(function (errorUtil) {
|
|
@@ -719,6 +729,11 @@ class ZodError extends Error {
|
|
|
719
729
|
processError(this);
|
|
720
730
|
return fieldErrors;
|
|
721
731
|
}
|
|
732
|
+
static assert(value) {
|
|
733
|
+
if (!(value instanceof ZodError)) {
|
|
734
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
722
737
|
toString() {
|
|
723
738
|
return this.message;
|
|
724
739
|
}
|
|
@@ -891,6 +906,13 @@ const makeIssue = (params) => {
|
|
|
891
906
|
...issueData,
|
|
892
907
|
path: fullPath,
|
|
893
908
|
};
|
|
909
|
+
if (issueData.message !== undefined) {
|
|
910
|
+
return {
|
|
911
|
+
...issueData,
|
|
912
|
+
path: fullPath,
|
|
913
|
+
message: issueData.message,
|
|
914
|
+
};
|
|
915
|
+
}
|
|
894
916
|
let errorMessage = "";
|
|
895
917
|
const maps = errorMaps
|
|
896
918
|
.filter((m) => !!m)
|
|
@@ -902,11 +924,12 @@ const makeIssue = (params) => {
|
|
|
902
924
|
return {
|
|
903
925
|
...issueData,
|
|
904
926
|
path: fullPath,
|
|
905
|
-
message:
|
|
927
|
+
message: errorMessage,
|
|
906
928
|
};
|
|
907
929
|
};
|
|
908
930
|
const EMPTY_PATH = [];
|
|
909
931
|
function addIssueToContext(ctx, issueData) {
|
|
932
|
+
const overrideMap = getErrorMap();
|
|
910
933
|
const issue = makeIssue({
|
|
911
934
|
issueData: issueData,
|
|
912
935
|
data: ctx.data,
|
|
@@ -914,8 +937,8 @@ function addIssueToContext(ctx, issueData) {
|
|
|
914
937
|
errorMaps: [
|
|
915
938
|
ctx.common.contextualErrorMap,
|
|
916
939
|
ctx.schemaErrorMap,
|
|
917
|
-
|
|
918
|
-
errorMap, // then global default map
|
|
940
|
+
overrideMap,
|
|
941
|
+
overrideMap === errorMap ? undefined : errorMap, // then global default map
|
|
919
942
|
].filter((x) => !!x),
|
|
920
943
|
});
|
|
921
944
|
ctx.common.issues.push(issue);
|
|
@@ -946,9 +969,11 @@ class ParseStatus {
|
|
|
946
969
|
static async mergeObjectAsync(status, pairs) {
|
|
947
970
|
const syncPairs = [];
|
|
948
971
|
for (const pair of pairs) {
|
|
972
|
+
const key = await pair.key;
|
|
973
|
+
const value = await pair.value;
|
|
949
974
|
syncPairs.push({
|
|
950
|
-
key
|
|
951
|
-
value
|
|
975
|
+
key,
|
|
976
|
+
value,
|
|
952
977
|
});
|
|
953
978
|
}
|
|
954
979
|
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
@@ -983,12 +1008,46 @@ const isDirty = (x) => x.status === "dirty";
|
|
|
983
1008
|
const isValid = (x) => x.status === "valid";
|
|
984
1009
|
const isAsync$1 = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
985
1010
|
|
|
1011
|
+
/******************************************************************************
|
|
1012
|
+
Copyright (c) Microsoft Corporation.
|
|
1013
|
+
|
|
1014
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
1015
|
+
purpose with or without fee is hereby granted.
|
|
1016
|
+
|
|
1017
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
1018
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
1019
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
1020
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
1021
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
1022
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
1023
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
1024
|
+
***************************************************************************** */
|
|
1025
|
+
|
|
1026
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
1027
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
1028
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
1029
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
1033
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
1034
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
1035
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
1036
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
1040
|
+
var e = new Error(message);
|
|
1041
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1042
|
+
};
|
|
1043
|
+
|
|
986
1044
|
var errorUtil;
|
|
987
1045
|
(function (errorUtil) {
|
|
988
1046
|
errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
989
1047
|
errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
990
1048
|
})(errorUtil || (errorUtil = {}));
|
|
991
1049
|
|
|
1050
|
+
var _ZodEnum_cache, _ZodNativeEnum_cache;
|
|
992
1051
|
class ParseInputLazyPath {
|
|
993
1052
|
constructor(parent, value, path, key) {
|
|
994
1053
|
this._cachedPath = [];
|
|
@@ -1039,12 +1098,17 @@ function processCreateParams(params) {
|
|
|
1039
1098
|
if (errorMap)
|
|
1040
1099
|
return { errorMap: errorMap, description };
|
|
1041
1100
|
const customMap = (iss, ctx) => {
|
|
1042
|
-
|
|
1043
|
-
|
|
1101
|
+
var _a, _b;
|
|
1102
|
+
const { message } = params;
|
|
1103
|
+
if (iss.code === "invalid_enum_value") {
|
|
1104
|
+
return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
|
|
1105
|
+
}
|
|
1044
1106
|
if (typeof ctx.data === "undefined") {
|
|
1045
|
-
return { message:
|
|
1107
|
+
return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
|
|
1046
1108
|
}
|
|
1047
|
-
|
|
1109
|
+
if (iss.code !== "invalid_type")
|
|
1110
|
+
return { message: ctx.defaultError };
|
|
1111
|
+
return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
|
|
1048
1112
|
};
|
|
1049
1113
|
return { errorMap: customMap, description };
|
|
1050
1114
|
}
|
|
@@ -1302,11 +1366,13 @@ class ZodType {
|
|
|
1302
1366
|
}
|
|
1303
1367
|
}
|
|
1304
1368
|
const cuidRegex = /^c[^\s-]{8,}$/i;
|
|
1305
|
-
const cuid2Regex = /^[
|
|
1369
|
+
const cuid2Regex = /^[0-9a-z]+$/;
|
|
1306
1370
|
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
|
|
1307
1371
|
// const uuidRegex =
|
|
1308
1372
|
// /^([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;
|
|
1309
1373
|
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;
|
|
1374
|
+
const nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
1375
|
+
const durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
|
1310
1376
|
// from https://stackoverflow.com/a/46181/1550155
|
|
1311
1377
|
// old version: too slow, didn't support unicode
|
|
1312
1378
|
// 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;
|
|
@@ -1319,41 +1385,48 @@ const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-
|
|
|
1319
1385
|
// /^[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])?)*$/;
|
|
1320
1386
|
// const emailRegex =
|
|
1321
1387
|
// /^(?:[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;
|
|
1322
|
-
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_
|
|
1388
|
+
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
1323
1389
|
// const emailRegex =
|
|
1324
1390
|
// /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
|
|
1325
1391
|
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
|
1326
1392
|
const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
1327
1393
|
let emojiRegex;
|
|
1328
|
-
|
|
1394
|
+
// faster, simpler, safer
|
|
1395
|
+
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
1329
1396
|
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})))$/;
|
|
1330
|
-
//
|
|
1331
|
-
const
|
|
1397
|
+
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
1398
|
+
const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
1399
|
+
// simple
|
|
1400
|
+
// const dateRegexSource = `\\d{4}-\\d{2}-\\d{2}`;
|
|
1401
|
+
// no leap year validation
|
|
1402
|
+
// const dateRegexSource = `\\d{4}-((0[13578]|10|12)-31|(0[13-9]|1[0-2])-30|(0[1-9]|1[0-2])-(0[1-9]|1\\d|2\\d))`;
|
|
1403
|
+
// with leap year validation
|
|
1404
|
+
const dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
1405
|
+
const dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
1406
|
+
function timeRegexSource(args) {
|
|
1407
|
+
// let regex = `\\d{2}:\\d{2}:\\d{2}`;
|
|
1408
|
+
let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
|
|
1332
1409
|
if (args.precision) {
|
|
1333
|
-
|
|
1334
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
1335
|
-
}
|
|
1336
|
-
else {
|
|
1337
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
else if (args.precision === 0) {
|
|
1341
|
-
if (args.offset) {
|
|
1342
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
1343
|
-
}
|
|
1344
|
-
else {
|
|
1345
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
|
|
1346
|
-
}
|
|
1410
|
+
regex = `${regex}\\.\\d{${args.precision}}`;
|
|
1347
1411
|
}
|
|
1348
|
-
else {
|
|
1349
|
-
|
|
1350
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
1351
|
-
}
|
|
1352
|
-
else {
|
|
1353
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
|
|
1354
|
-
}
|
|
1412
|
+
else if (args.precision == null) {
|
|
1413
|
+
regex = `${regex}(\\.\\d+)?`;
|
|
1355
1414
|
}
|
|
1356
|
-
|
|
1415
|
+
return regex;
|
|
1416
|
+
}
|
|
1417
|
+
function timeRegex(args) {
|
|
1418
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
1419
|
+
}
|
|
1420
|
+
// Adapted from https://stackoverflow.com/a/3143231
|
|
1421
|
+
function datetimeRegex(args) {
|
|
1422
|
+
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
1423
|
+
const opts = [];
|
|
1424
|
+
opts.push(args.local ? `Z?` : `Z`);
|
|
1425
|
+
if (args.offset)
|
|
1426
|
+
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
1427
|
+
regex = `${regex}(${opts.join("|")})`;
|
|
1428
|
+
return new RegExp(`^${regex}$`);
|
|
1429
|
+
}
|
|
1357
1430
|
function isValidIP(ip, version) {
|
|
1358
1431
|
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
1359
1432
|
return true;
|
|
@@ -1375,9 +1448,7 @@ class ZodString extends ZodType {
|
|
|
1375
1448
|
code: ZodIssueCode.invalid_type,
|
|
1376
1449
|
expected: ZodParsedType.string,
|
|
1377
1450
|
received: ctx.parsedType,
|
|
1378
|
-
}
|
|
1379
|
-
//
|
|
1380
|
-
);
|
|
1451
|
+
});
|
|
1381
1452
|
return INVALID;
|
|
1382
1453
|
}
|
|
1383
1454
|
const status = new ParseStatus();
|
|
@@ -1475,6 +1546,17 @@ class ZodString extends ZodType {
|
|
|
1475
1546
|
status.dirty();
|
|
1476
1547
|
}
|
|
1477
1548
|
}
|
|
1549
|
+
else if (check.kind === "nanoid") {
|
|
1550
|
+
if (!nanoidRegex.test(input.data)) {
|
|
1551
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1552
|
+
addIssueToContext(ctx, {
|
|
1553
|
+
validation: "nanoid",
|
|
1554
|
+
code: ZodIssueCode.invalid_string,
|
|
1555
|
+
message: check.message,
|
|
1556
|
+
});
|
|
1557
|
+
status.dirty();
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1478
1560
|
else if (check.kind === "cuid") {
|
|
1479
1561
|
if (!cuidRegex.test(input.data)) {
|
|
1480
1562
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -1589,6 +1671,41 @@ class ZodString extends ZodType {
|
|
|
1589
1671
|
status.dirty();
|
|
1590
1672
|
}
|
|
1591
1673
|
}
|
|
1674
|
+
else if (check.kind === "date") {
|
|
1675
|
+
const regex = dateRegex;
|
|
1676
|
+
if (!regex.test(input.data)) {
|
|
1677
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1678
|
+
addIssueToContext(ctx, {
|
|
1679
|
+
code: ZodIssueCode.invalid_string,
|
|
1680
|
+
validation: "date",
|
|
1681
|
+
message: check.message,
|
|
1682
|
+
});
|
|
1683
|
+
status.dirty();
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
else if (check.kind === "time") {
|
|
1687
|
+
const regex = timeRegex(check);
|
|
1688
|
+
if (!regex.test(input.data)) {
|
|
1689
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1690
|
+
addIssueToContext(ctx, {
|
|
1691
|
+
code: ZodIssueCode.invalid_string,
|
|
1692
|
+
validation: "time",
|
|
1693
|
+
message: check.message,
|
|
1694
|
+
});
|
|
1695
|
+
status.dirty();
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
else if (check.kind === "duration") {
|
|
1699
|
+
if (!durationRegex.test(input.data)) {
|
|
1700
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1701
|
+
addIssueToContext(ctx, {
|
|
1702
|
+
validation: "duration",
|
|
1703
|
+
code: ZodIssueCode.invalid_string,
|
|
1704
|
+
message: check.message,
|
|
1705
|
+
});
|
|
1706
|
+
status.dirty();
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1592
1709
|
else if (check.kind === "ip") {
|
|
1593
1710
|
if (!isValidIP(input.data, check.version)) {
|
|
1594
1711
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -1600,6 +1717,17 @@ class ZodString extends ZodType {
|
|
|
1600
1717
|
status.dirty();
|
|
1601
1718
|
}
|
|
1602
1719
|
}
|
|
1720
|
+
else if (check.kind === "base64") {
|
|
1721
|
+
if (!base64Regex.test(input.data)) {
|
|
1722
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1723
|
+
addIssueToContext(ctx, {
|
|
1724
|
+
validation: "base64",
|
|
1725
|
+
code: ZodIssueCode.invalid_string,
|
|
1726
|
+
message: check.message,
|
|
1727
|
+
});
|
|
1728
|
+
status.dirty();
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1603
1731
|
else {
|
|
1604
1732
|
util$7.assertNever(check);
|
|
1605
1733
|
}
|
|
@@ -1631,6 +1759,9 @@ class ZodString extends ZodType {
|
|
|
1631
1759
|
uuid(message) {
|
|
1632
1760
|
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
1633
1761
|
}
|
|
1762
|
+
nanoid(message) {
|
|
1763
|
+
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
1764
|
+
}
|
|
1634
1765
|
cuid(message) {
|
|
1635
1766
|
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
1636
1767
|
}
|
|
@@ -1640,16 +1771,20 @@ class ZodString extends ZodType {
|
|
|
1640
1771
|
ulid(message) {
|
|
1641
1772
|
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
1642
1773
|
}
|
|
1774
|
+
base64(message) {
|
|
1775
|
+
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1776
|
+
}
|
|
1643
1777
|
ip(options) {
|
|
1644
1778
|
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
1645
1779
|
}
|
|
1646
1780
|
datetime(options) {
|
|
1647
|
-
var _a;
|
|
1781
|
+
var _a, _b;
|
|
1648
1782
|
if (typeof options === "string") {
|
|
1649
1783
|
return this._addCheck({
|
|
1650
1784
|
kind: "datetime",
|
|
1651
1785
|
precision: null,
|
|
1652
1786
|
offset: false,
|
|
1787
|
+
local: false,
|
|
1653
1788
|
message: options,
|
|
1654
1789
|
});
|
|
1655
1790
|
}
|
|
@@ -1657,9 +1792,30 @@ class ZodString extends ZodType {
|
|
|
1657
1792
|
kind: "datetime",
|
|
1658
1793
|
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
|
1659
1794
|
offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
|
|
1795
|
+
local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
|
|
1660
1796
|
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
|
|
1661
1797
|
});
|
|
1662
1798
|
}
|
|
1799
|
+
date(message) {
|
|
1800
|
+
return this._addCheck({ kind: "date", message });
|
|
1801
|
+
}
|
|
1802
|
+
time(options) {
|
|
1803
|
+
if (typeof options === "string") {
|
|
1804
|
+
return this._addCheck({
|
|
1805
|
+
kind: "time",
|
|
1806
|
+
precision: null,
|
|
1807
|
+
message: options,
|
|
1808
|
+
});
|
|
1809
|
+
}
|
|
1810
|
+
return this._addCheck({
|
|
1811
|
+
kind: "time",
|
|
1812
|
+
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
|
1813
|
+
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
|
|
1814
|
+
});
|
|
1815
|
+
}
|
|
1816
|
+
duration(message) {
|
|
1817
|
+
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
1818
|
+
}
|
|
1663
1819
|
regex(regex, message) {
|
|
1664
1820
|
return this._addCheck({
|
|
1665
1821
|
kind: "regex",
|
|
@@ -1738,6 +1894,15 @@ class ZodString extends ZodType {
|
|
|
1738
1894
|
get isDatetime() {
|
|
1739
1895
|
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
1740
1896
|
}
|
|
1897
|
+
get isDate() {
|
|
1898
|
+
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
1899
|
+
}
|
|
1900
|
+
get isTime() {
|
|
1901
|
+
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
1902
|
+
}
|
|
1903
|
+
get isDuration() {
|
|
1904
|
+
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
1905
|
+
}
|
|
1741
1906
|
get isEmail() {
|
|
1742
1907
|
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
1743
1908
|
}
|
|
@@ -1750,6 +1915,9 @@ class ZodString extends ZodType {
|
|
|
1750
1915
|
get isUUID() {
|
|
1751
1916
|
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
1752
1917
|
}
|
|
1918
|
+
get isNANOID() {
|
|
1919
|
+
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
1920
|
+
}
|
|
1753
1921
|
get isCUID() {
|
|
1754
1922
|
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
1755
1923
|
}
|
|
@@ -1762,6 +1930,9 @@ class ZodString extends ZodType {
|
|
|
1762
1930
|
get isIP() {
|
|
1763
1931
|
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1764
1932
|
}
|
|
1933
|
+
get isBase64() {
|
|
1934
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1935
|
+
}
|
|
1765
1936
|
get minLength() {
|
|
1766
1937
|
let min = null;
|
|
1767
1938
|
for (const ch of this._def.checks) {
|
|
@@ -2749,9 +2920,10 @@ class ZodObject extends ZodType {
|
|
|
2749
2920
|
const syncPairs = [];
|
|
2750
2921
|
for (const pair of pairs) {
|
|
2751
2922
|
const key = await pair.key;
|
|
2923
|
+
const value = await pair.value;
|
|
2752
2924
|
syncPairs.push({
|
|
2753
2925
|
key,
|
|
2754
|
-
value
|
|
2926
|
+
value,
|
|
2755
2927
|
alwaysSet: pair.alwaysSet,
|
|
2756
2928
|
});
|
|
2757
2929
|
}
|
|
@@ -3125,7 +3297,7 @@ const getDiscriminator = (type) => {
|
|
|
3125
3297
|
}
|
|
3126
3298
|
else if (type instanceof ZodNativeEnum) {
|
|
3127
3299
|
// eslint-disable-next-line ban/ban
|
|
3128
|
-
return
|
|
3300
|
+
return util$7.objectValues(type.enum);
|
|
3129
3301
|
}
|
|
3130
3302
|
else if (type instanceof ZodDefault) {
|
|
3131
3303
|
return getDiscriminator(type._def.innerType);
|
|
@@ -3136,8 +3308,23 @@ const getDiscriminator = (type) => {
|
|
|
3136
3308
|
else if (type instanceof ZodNull) {
|
|
3137
3309
|
return [null];
|
|
3138
3310
|
}
|
|
3311
|
+
else if (type instanceof ZodOptional) {
|
|
3312
|
+
return [undefined, ...getDiscriminator(type.unwrap())];
|
|
3313
|
+
}
|
|
3314
|
+
else if (type instanceof ZodNullable) {
|
|
3315
|
+
return [null, ...getDiscriminator(type.unwrap())];
|
|
3316
|
+
}
|
|
3317
|
+
else if (type instanceof ZodBranded) {
|
|
3318
|
+
return getDiscriminator(type.unwrap());
|
|
3319
|
+
}
|
|
3320
|
+
else if (type instanceof ZodReadonly) {
|
|
3321
|
+
return getDiscriminator(type.unwrap());
|
|
3322
|
+
}
|
|
3323
|
+
else if (type instanceof ZodCatch) {
|
|
3324
|
+
return getDiscriminator(type._def.innerType);
|
|
3325
|
+
}
|
|
3139
3326
|
else {
|
|
3140
|
-
return
|
|
3327
|
+
return [];
|
|
3141
3328
|
}
|
|
3142
3329
|
};
|
|
3143
3330
|
class ZodDiscriminatedUnion extends ZodType {
|
|
@@ -3200,7 +3387,7 @@ class ZodDiscriminatedUnion extends ZodType {
|
|
|
3200
3387
|
// try {
|
|
3201
3388
|
for (const type of options) {
|
|
3202
3389
|
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
3203
|
-
if (!discriminatorValues) {
|
|
3390
|
+
if (!discriminatorValues.length) {
|
|
3204
3391
|
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
3205
3392
|
}
|
|
3206
3393
|
for (const value of discriminatorValues) {
|
|
@@ -3413,6 +3600,7 @@ class ZodRecord extends ZodType {
|
|
|
3413
3600
|
pairs.push({
|
|
3414
3601
|
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
3415
3602
|
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
3603
|
+
alwaysSet: key in ctx.data,
|
|
3416
3604
|
});
|
|
3417
3605
|
}
|
|
3418
3606
|
if (ctx.common.async) {
|
|
@@ -3772,6 +3960,10 @@ function createZodEnum(values, params) {
|
|
|
3772
3960
|
});
|
|
3773
3961
|
}
|
|
3774
3962
|
class ZodEnum extends ZodType {
|
|
3963
|
+
constructor() {
|
|
3964
|
+
super(...arguments);
|
|
3965
|
+
_ZodEnum_cache.set(this, void 0);
|
|
3966
|
+
}
|
|
3775
3967
|
_parse(input) {
|
|
3776
3968
|
if (typeof input.data !== "string") {
|
|
3777
3969
|
const ctx = this._getOrReturnCtx(input);
|
|
@@ -3783,7 +3975,10 @@ class ZodEnum extends ZodType {
|
|
|
3783
3975
|
});
|
|
3784
3976
|
return INVALID;
|
|
3785
3977
|
}
|
|
3786
|
-
if (this
|
|
3978
|
+
if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f")) {
|
|
3979
|
+
__classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values), "f");
|
|
3980
|
+
}
|
|
3981
|
+
if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f").has(input.data)) {
|
|
3787
3982
|
const ctx = this._getOrReturnCtx(input);
|
|
3788
3983
|
const expectedValues = this._def.values;
|
|
3789
3984
|
addIssueToContext(ctx, {
|
|
@@ -3819,15 +4014,26 @@ class ZodEnum extends ZodType {
|
|
|
3819
4014
|
}
|
|
3820
4015
|
return enumValues;
|
|
3821
4016
|
}
|
|
3822
|
-
extract(values) {
|
|
3823
|
-
return ZodEnum.create(values
|
|
4017
|
+
extract(values, newDef = this._def) {
|
|
4018
|
+
return ZodEnum.create(values, {
|
|
4019
|
+
...this._def,
|
|
4020
|
+
...newDef,
|
|
4021
|
+
});
|
|
3824
4022
|
}
|
|
3825
|
-
exclude(values) {
|
|
3826
|
-
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt))
|
|
4023
|
+
exclude(values, newDef = this._def) {
|
|
4024
|
+
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
4025
|
+
...this._def,
|
|
4026
|
+
...newDef,
|
|
4027
|
+
});
|
|
3827
4028
|
}
|
|
3828
4029
|
}
|
|
4030
|
+
_ZodEnum_cache = new WeakMap();
|
|
3829
4031
|
ZodEnum.create = createZodEnum;
|
|
3830
4032
|
class ZodNativeEnum extends ZodType {
|
|
4033
|
+
constructor() {
|
|
4034
|
+
super(...arguments);
|
|
4035
|
+
_ZodNativeEnum_cache.set(this, void 0);
|
|
4036
|
+
}
|
|
3831
4037
|
_parse(input) {
|
|
3832
4038
|
const nativeEnumValues = util$7.getValidEnumValues(this._def.values);
|
|
3833
4039
|
const ctx = this._getOrReturnCtx(input);
|
|
@@ -3841,7 +4047,10 @@ class ZodNativeEnum extends ZodType {
|
|
|
3841
4047
|
});
|
|
3842
4048
|
return INVALID;
|
|
3843
4049
|
}
|
|
3844
|
-
if (
|
|
4050
|
+
if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f")) {
|
|
4051
|
+
__classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util$7.getValidEnumValues(this._def.values)), "f");
|
|
4052
|
+
}
|
|
4053
|
+
if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f").has(input.data)) {
|
|
3845
4054
|
const expectedValues = util$7.objectValues(nativeEnumValues);
|
|
3846
4055
|
addIssueToContext(ctx, {
|
|
3847
4056
|
received: ctx.data,
|
|
@@ -3856,6 +4065,7 @@ class ZodNativeEnum extends ZodType {
|
|
|
3856
4065
|
return this._def.values;
|
|
3857
4066
|
}
|
|
3858
4067
|
}
|
|
4068
|
+
_ZodNativeEnum_cache = new WeakMap();
|
|
3859
4069
|
ZodNativeEnum.create = (values, params) => {
|
|
3860
4070
|
return new ZodNativeEnum({
|
|
3861
4071
|
values: values,
|
|
@@ -3925,33 +4135,43 @@ class ZodEffects extends ZodType {
|
|
|
3925
4135
|
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
3926
4136
|
if (effect.type === "preprocess") {
|
|
3927
4137
|
const processed = effect.transform(ctx.data, checkCtx);
|
|
3928
|
-
if (ctx.common.issues.length) {
|
|
3929
|
-
return {
|
|
3930
|
-
status: "dirty",
|
|
3931
|
-
value: ctx.data,
|
|
3932
|
-
};
|
|
3933
|
-
}
|
|
3934
4138
|
if (ctx.common.async) {
|
|
3935
|
-
return Promise.resolve(processed).then((processed) => {
|
|
3936
|
-
|
|
4139
|
+
return Promise.resolve(processed).then(async (processed) => {
|
|
4140
|
+
if (status.value === "aborted")
|
|
4141
|
+
return INVALID;
|
|
4142
|
+
const result = await this._def.schema._parseAsync({
|
|
3937
4143
|
data: processed,
|
|
3938
4144
|
path: ctx.path,
|
|
3939
4145
|
parent: ctx,
|
|
3940
4146
|
});
|
|
4147
|
+
if (result.status === "aborted")
|
|
4148
|
+
return INVALID;
|
|
4149
|
+
if (result.status === "dirty")
|
|
4150
|
+
return DIRTY(result.value);
|
|
4151
|
+
if (status.value === "dirty")
|
|
4152
|
+
return DIRTY(result.value);
|
|
4153
|
+
return result;
|
|
3941
4154
|
});
|
|
3942
4155
|
}
|
|
3943
4156
|
else {
|
|
3944
|
-
|
|
4157
|
+
if (status.value === "aborted")
|
|
4158
|
+
return INVALID;
|
|
4159
|
+
const result = this._def.schema._parseSync({
|
|
3945
4160
|
data: processed,
|
|
3946
4161
|
path: ctx.path,
|
|
3947
4162
|
parent: ctx,
|
|
3948
4163
|
});
|
|
4164
|
+
if (result.status === "aborted")
|
|
4165
|
+
return INVALID;
|
|
4166
|
+
if (result.status === "dirty")
|
|
4167
|
+
return DIRTY(result.value);
|
|
4168
|
+
if (status.value === "dirty")
|
|
4169
|
+
return DIRTY(result.value);
|
|
4170
|
+
return result;
|
|
3949
4171
|
}
|
|
3950
4172
|
}
|
|
3951
4173
|
if (effect.type === "refinement") {
|
|
3952
|
-
const executeRefinement = (acc
|
|
3953
|
-
// effect: RefinementEffect<any>
|
|
3954
|
-
) => {
|
|
4174
|
+
const executeRefinement = (acc) => {
|
|
3955
4175
|
const result = effect.refinement(acc, checkCtx);
|
|
3956
4176
|
if (ctx.common.async) {
|
|
3957
4177
|
return Promise.resolve(result);
|
|
@@ -4254,10 +4474,18 @@ class ZodPipeline extends ZodType {
|
|
|
4254
4474
|
class ZodReadonly extends ZodType {
|
|
4255
4475
|
_parse(input) {
|
|
4256
4476
|
const result = this._def.innerType._parse(input);
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4477
|
+
const freeze = (data) => {
|
|
4478
|
+
if (isValid(data)) {
|
|
4479
|
+
data.value = Object.freeze(data.value);
|
|
4480
|
+
}
|
|
4481
|
+
return data;
|
|
4482
|
+
};
|
|
4483
|
+
return isAsync$1(result)
|
|
4484
|
+
? result.then((data) => freeze(data))
|
|
4485
|
+
: freeze(result);
|
|
4486
|
+
}
|
|
4487
|
+
unwrap() {
|
|
4488
|
+
return this._def.innerType;
|
|
4261
4489
|
}
|
|
4262
4490
|
}
|
|
4263
4491
|
ZodReadonly.create = (type, params) => {
|
|
@@ -4267,7 +4495,7 @@ ZodReadonly.create = (type, params) => {
|
|
|
4267
4495
|
...processCreateParams(params),
|
|
4268
4496
|
});
|
|
4269
4497
|
};
|
|
4270
|
-
|
|
4498
|
+
function custom(check, params = {},
|
|
4271
4499
|
/**
|
|
4272
4500
|
* @deprecated
|
|
4273
4501
|
*
|
|
@@ -4278,7 +4506,7 @@ const custom = (check, params = {},
|
|
|
4278
4506
|
* ```
|
|
4279
4507
|
*
|
|
4280
4508
|
*/
|
|
4281
|
-
fatal)
|
|
4509
|
+
fatal) {
|
|
4282
4510
|
if (check)
|
|
4283
4511
|
return ZodAny.create().superRefine((data, ctx) => {
|
|
4284
4512
|
var _a, _b;
|
|
@@ -4294,7 +4522,7 @@ fatal) => {
|
|
|
4294
4522
|
}
|
|
4295
4523
|
});
|
|
4296
4524
|
return ZodAny.create();
|
|
4297
|
-
}
|
|
4525
|
+
}
|
|
4298
4526
|
const late = {
|
|
4299
4527
|
object: ZodObject.lazycreate,
|
|
4300
4528
|
};
|
|
@@ -4412,6 +4640,7 @@ var z = /*#__PURE__*/Object.freeze({
|
|
|
4412
4640
|
ZodParsedType: ZodParsedType,
|
|
4413
4641
|
getParsedType: getParsedType,
|
|
4414
4642
|
ZodType: ZodType,
|
|
4643
|
+
datetimeRegex: datetimeRegex,
|
|
4415
4644
|
ZodString: ZodString,
|
|
4416
4645
|
ZodNumber: ZodNumber,
|
|
4417
4646
|
ZodBigInt: ZodBigInt,
|
|
@@ -20135,13 +20364,13 @@ var push = async () => {
|
|
|
20135
20364
|
checkNodeVersion();
|
|
20136
20365
|
ora$1 = (await oraP$1).default;
|
|
20137
20366
|
const config = await provideConfig();
|
|
20138
|
-
const token = await verify(config);
|
|
20139
20367
|
if (process.argv.includes("--api-key") || process.argv.includes("-k")) {
|
|
20140
20368
|
spinnerPushing = ora$1("Using API key...").start();
|
|
20141
20369
|
await pushByApiKey(config, spinnerPushing);
|
|
20142
20370
|
spinnerPushing.succeed("Published using API key");
|
|
20143
20371
|
return;
|
|
20144
20372
|
}
|
|
20373
|
+
const token = await verify(config);
|
|
20145
20374
|
const { workspaceId, name: workspaceName } = await selectWorkspace(config, token);
|
|
20146
20375
|
const workspacePreviewUrl = `${config.previewBaseUrl}/workspace/${workspaceId}`;
|
|
20147
20376
|
await buildArchive(config);
|