@embeddable.com/sdk-core 3.2.0-next.9 → 3.2.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/bin/embeddable +1 -1
- package/configs/tsconfig.json +4 -11
- package/lib/defineConfig.d.ts +5 -2
- package/lib/index.esm.js +470 -88
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +470 -88
- package/lib/index.js.map +1 -1
- package/lib/push.d.ts +5 -0
- package/lib/utils.d.ts +7 -0
- package/loader/custom-esm-loader.mjs +1 -1
- package/package.json +3 -3
- package/src/buildTypes.ts +5 -0
- package/src/cleanup.ts +40 -8
- package/src/defineConfig.ts +25 -1
- package/src/entryPoint.js +12 -0
- package/src/generate.ts +17 -0
- package/src/prepare.ts +2 -0
- package/src/push.ts +103 -13
- package/src/utils.ts +22 -0
- package/src/validate.ts +30 -4
- package/templates/component.tsx.template +17 -1
- package/lib/entryPoint.d.ts +0 -1
- package/src/entryPoint.ts +0 -18
package/lib/index.esm.js
CHANGED
|
@@ -4,7 +4,9 @@ import * as path$1 from 'node:path';
|
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import * as vite from 'vite';
|
|
6
6
|
import 'node:child_process';
|
|
7
|
+
import * as crypto from 'node:crypto';
|
|
7
8
|
import * as fs$2 from 'node:fs';
|
|
9
|
+
import { existsSync } from 'node:fs';
|
|
8
10
|
import { createNodeLogger, createNodeSys } from '@stencil/core/sys/node';
|
|
9
11
|
import { loadConfig, createCompiler } from '@stencil/core/compiler';
|
|
10
12
|
import * as YAML from 'yaml';
|
|
@@ -230,6 +232,11 @@ let ZodError$1 = class ZodError extends Error {
|
|
|
230
232
|
processError(this);
|
|
231
233
|
return fieldErrors;
|
|
232
234
|
}
|
|
235
|
+
static assert(value) {
|
|
236
|
+
if (!(value instanceof ZodError)) {
|
|
237
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
233
240
|
toString() {
|
|
234
241
|
return this.message;
|
|
235
242
|
}
|
|
@@ -261,6 +268,11 @@ ZodError$1.create = (issues) => {
|
|
|
261
268
|
const error = new ZodError$1(issues);
|
|
262
269
|
return error;
|
|
263
270
|
};
|
|
271
|
+
|
|
272
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
273
|
+
var e = new Error(message);
|
|
274
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
275
|
+
};
|
|
264
276
|
|
|
265
277
|
var errorUtil$1;
|
|
266
278
|
(function (errorUtil) {
|
|
@@ -336,6 +348,20 @@ const formatErrorPath = (path) => {
|
|
|
336
348
|
return formatted;
|
|
337
349
|
};
|
|
338
350
|
|
|
351
|
+
/**
|
|
352
|
+
* Get the hash of the content string. It returns the first 5 characters of the hash
|
|
353
|
+
* Example: getContentHash("Hello World")
|
|
354
|
+
* @param contentString The content string to hash
|
|
355
|
+
* @returns
|
|
356
|
+
*/
|
|
357
|
+
const getContentHash = (contentString) => {
|
|
358
|
+
return crypto
|
|
359
|
+
.createHash("md5")
|
|
360
|
+
.update(contentString)
|
|
361
|
+
.digest("hex")
|
|
362
|
+
.substring(0, 5);
|
|
363
|
+
};
|
|
364
|
+
|
|
339
365
|
const oraP$4 = import('ora');
|
|
340
366
|
const EMB_TYPE_FILE_REGEX = /^(.*)\.type\.emb\.[jt]s$/;
|
|
341
367
|
const EMB_OPTIONS_FILE_REGEX = /^(.*)\.options\.emb\.[jt]s$/;
|
|
@@ -368,6 +394,11 @@ async function build$1(ctx) {
|
|
|
368
394
|
formats: ["es"],
|
|
369
395
|
fileName: "embeddable-types",
|
|
370
396
|
},
|
|
397
|
+
rollupOptions: {
|
|
398
|
+
output: {
|
|
399
|
+
entryFileNames: "embeddable-types-[hash].js",
|
|
400
|
+
},
|
|
401
|
+
},
|
|
371
402
|
outDir: ctx.client.buildDir,
|
|
372
403
|
},
|
|
373
404
|
});
|
|
@@ -384,6 +415,8 @@ var prepare = async (ctx) => {
|
|
|
384
415
|
async function removeIfExists(ctx) {
|
|
385
416
|
if (fs$2.existsSync(ctx.client.buildDir))
|
|
386
417
|
await fs$1.rm(ctx.client.buildDir, { recursive: true });
|
|
418
|
+
if (fs$2.existsSync(ctx.client.tmpDir))
|
|
419
|
+
await fs$1.rm(ctx.client.tmpDir, { recursive: true });
|
|
387
420
|
}
|
|
388
421
|
async function copyStencilConfigsToClient(ctx) {
|
|
389
422
|
await fs$1.cp(ctx.core.configsDir, ctx.client.buildDir, { recursive: true });
|
|
@@ -421,12 +454,14 @@ async function runStencil(ctx) {
|
|
|
421
454
|
const logger = ((_a = ctx.dev) === null || _a === void 0 ? void 0 : _a.logger) || createNodeLogger({ process });
|
|
422
455
|
const sys = ((_b = ctx.dev) === null || _b === void 0 ? void 0 : _b.sys) || createNodeSys({ process });
|
|
423
456
|
const devMode = !!ctx.dev;
|
|
457
|
+
const isWindows = process.platform === "win32";
|
|
424
458
|
const validated = await loadConfig({
|
|
425
459
|
initTsConfig: true,
|
|
426
460
|
logger,
|
|
427
461
|
sys,
|
|
428
462
|
config: {
|
|
429
463
|
devMode,
|
|
464
|
+
maxConcurrentWorkers: isWindows ? 0 : 8, // workers break on windows
|
|
430
465
|
rootDir: ctx.client.buildDir,
|
|
431
466
|
configPath: path$1.resolve(ctx.client.buildDir, "stencil.config.ts"),
|
|
432
467
|
tsconfig: path$1.resolve(ctx.client.buildDir, "tsconfig.json"),
|
|
@@ -441,6 +476,11 @@ async function runStencil(ctx) {
|
|
|
441
476
|
});
|
|
442
477
|
const compiler = await createCompiler(validated.config);
|
|
443
478
|
await compiler.build();
|
|
479
|
+
const entryFilePath = path$1.resolve(ctx.client.stencilBuild, "embeddable-wrapper.esm.js");
|
|
480
|
+
const entryFileContent = await fs$1.readFile(entryFilePath, "utf8");
|
|
481
|
+
const fileHash = getContentHash(entryFileContent);
|
|
482
|
+
const newFileName = `embeddable-wrapper.esm-${fileHash}.js`;
|
|
483
|
+
await fs$1.rename(entryFilePath, path$1.resolve(ctx.client.stencilBuild, newFileName));
|
|
444
484
|
await compiler.destroy();
|
|
445
485
|
process.chdir(ctx.client.rootDir);
|
|
446
486
|
}
|
|
@@ -470,10 +510,28 @@ var cleanup = async (ctx) => {
|
|
|
470
510
|
await moveBuildTOBuildDir(ctx);
|
|
471
511
|
};
|
|
472
512
|
async function extractBuild(ctx) {
|
|
513
|
+
const [[, stencilWrapperFilePath]] = await findFiles(ctx.client.stencilBuild, /embeddable-wrapper.esm-[a-z0-9]+\.js/);
|
|
514
|
+
const stencilWrapperFileName = path$1.basename(stencilWrapperFilePath);
|
|
473
515
|
await fs$1.rename(path$1.resolve(ctx.client.buildDir, ctx.client.stencilBuild), ctx.client.tmpDir);
|
|
474
|
-
await
|
|
475
|
-
|
|
476
|
-
await fs$1.rename(
|
|
516
|
+
const [[, typesFilePath]] = await findFiles(ctx.client.buildDir, /embeddable-types-[a-z0-9]+\.js/);
|
|
517
|
+
const typesFileName = path$1.basename(typesFilePath);
|
|
518
|
+
await fs$1.rename(typesFilePath, path$1.join(ctx.client.tmpDir, typesFileName));
|
|
519
|
+
const [[, metaFilePath]] = await findFiles(ctx.client.buildDir, /embeddable-components-meta-[a-z0-9]+\.js/);
|
|
520
|
+
const metaFileName = path$1.basename(metaFilePath);
|
|
521
|
+
await fs$1.rename(metaFilePath, path$1.join(ctx.client.tmpDir, metaFileName));
|
|
522
|
+
const [[, editorsMetaFilePath]] = await findFiles(ctx.client.buildDir, /embeddable-editors-meta-[a-z0-9]+\.js/);
|
|
523
|
+
const editorsMetaFileName = path$1.basename(editorsMetaFilePath);
|
|
524
|
+
await fs$1.rename(editorsMetaFilePath, path$1.join(ctx.client.tmpDir, editorsMetaFileName));
|
|
525
|
+
// write manifest file with files with hash
|
|
526
|
+
const manifest = {
|
|
527
|
+
entryFiles: {
|
|
528
|
+
"embeddable-types.js": typesFileName,
|
|
529
|
+
"embeddable-components-meta.js": metaFileName,
|
|
530
|
+
"embeddable-editors-meta.js": editorsMetaFileName,
|
|
531
|
+
"embeddable-wrapper.esm.js": stencilWrapperFileName,
|
|
532
|
+
},
|
|
533
|
+
};
|
|
534
|
+
await fs$1.writeFile(path$1.join(ctx.client.tmpDir, "embeddable-manifest.json"), JSON.stringify(manifest));
|
|
477
535
|
}
|
|
478
536
|
async function removeObsoleteDir(dir) {
|
|
479
537
|
await fs$1.rm(dir, { recursive: true });
|
|
@@ -716,6 +774,11 @@ class ZodError extends Error {
|
|
|
716
774
|
processError(this);
|
|
717
775
|
return fieldErrors;
|
|
718
776
|
}
|
|
777
|
+
static assert(value) {
|
|
778
|
+
if (!(value instanceof ZodError)) {
|
|
779
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
719
782
|
toString() {
|
|
720
783
|
return this.message;
|
|
721
784
|
}
|
|
@@ -888,6 +951,13 @@ const makeIssue = (params) => {
|
|
|
888
951
|
...issueData,
|
|
889
952
|
path: fullPath,
|
|
890
953
|
};
|
|
954
|
+
if (issueData.message !== undefined) {
|
|
955
|
+
return {
|
|
956
|
+
...issueData,
|
|
957
|
+
path: fullPath,
|
|
958
|
+
message: issueData.message,
|
|
959
|
+
};
|
|
960
|
+
}
|
|
891
961
|
let errorMessage = "";
|
|
892
962
|
const maps = errorMaps
|
|
893
963
|
.filter((m) => !!m)
|
|
@@ -899,11 +969,12 @@ const makeIssue = (params) => {
|
|
|
899
969
|
return {
|
|
900
970
|
...issueData,
|
|
901
971
|
path: fullPath,
|
|
902
|
-
message:
|
|
972
|
+
message: errorMessage,
|
|
903
973
|
};
|
|
904
974
|
};
|
|
905
975
|
const EMPTY_PATH = [];
|
|
906
976
|
function addIssueToContext(ctx, issueData) {
|
|
977
|
+
const overrideMap = getErrorMap();
|
|
907
978
|
const issue = makeIssue({
|
|
908
979
|
issueData: issueData,
|
|
909
980
|
data: ctx.data,
|
|
@@ -911,8 +982,8 @@ function addIssueToContext(ctx, issueData) {
|
|
|
911
982
|
errorMaps: [
|
|
912
983
|
ctx.common.contextualErrorMap,
|
|
913
984
|
ctx.schemaErrorMap,
|
|
914
|
-
|
|
915
|
-
errorMap, // then global default map
|
|
985
|
+
overrideMap,
|
|
986
|
+
overrideMap === errorMap ? undefined : errorMap, // then global default map
|
|
916
987
|
].filter((x) => !!x),
|
|
917
988
|
});
|
|
918
989
|
ctx.common.issues.push(issue);
|
|
@@ -943,9 +1014,11 @@ class ParseStatus {
|
|
|
943
1014
|
static async mergeObjectAsync(status, pairs) {
|
|
944
1015
|
const syncPairs = [];
|
|
945
1016
|
for (const pair of pairs) {
|
|
1017
|
+
const key = await pair.key;
|
|
1018
|
+
const value = await pair.value;
|
|
946
1019
|
syncPairs.push({
|
|
947
|
-
key
|
|
948
|
-
value
|
|
1020
|
+
key,
|
|
1021
|
+
value,
|
|
949
1022
|
});
|
|
950
1023
|
}
|
|
951
1024
|
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
@@ -980,12 +1053,46 @@ const isDirty = (x) => x.status === "dirty";
|
|
|
980
1053
|
const isValid = (x) => x.status === "valid";
|
|
981
1054
|
const isAsync$1 = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
982
1055
|
|
|
1056
|
+
/******************************************************************************
|
|
1057
|
+
Copyright (c) Microsoft Corporation.
|
|
1058
|
+
|
|
1059
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
1060
|
+
purpose with or without fee is hereby granted.
|
|
1061
|
+
|
|
1062
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
1063
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
1064
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
1065
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
1066
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
1067
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
1068
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
1069
|
+
***************************************************************************** */
|
|
1070
|
+
|
|
1071
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
1072
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
1073
|
+
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");
|
|
1074
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
1078
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
1079
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
1080
|
+
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");
|
|
1081
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
1085
|
+
var e = new Error(message);
|
|
1086
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1087
|
+
};
|
|
1088
|
+
|
|
983
1089
|
var errorUtil;
|
|
984
1090
|
(function (errorUtil) {
|
|
985
1091
|
errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
986
1092
|
errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
987
1093
|
})(errorUtil || (errorUtil = {}));
|
|
988
1094
|
|
|
1095
|
+
var _ZodEnum_cache, _ZodNativeEnum_cache;
|
|
989
1096
|
class ParseInputLazyPath {
|
|
990
1097
|
constructor(parent, value, path, key) {
|
|
991
1098
|
this._cachedPath = [];
|
|
@@ -1036,12 +1143,17 @@ function processCreateParams(params) {
|
|
|
1036
1143
|
if (errorMap)
|
|
1037
1144
|
return { errorMap: errorMap, description };
|
|
1038
1145
|
const customMap = (iss, ctx) => {
|
|
1039
|
-
|
|
1040
|
-
|
|
1146
|
+
var _a, _b;
|
|
1147
|
+
const { message } = params;
|
|
1148
|
+
if (iss.code === "invalid_enum_value") {
|
|
1149
|
+
return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
|
|
1150
|
+
}
|
|
1041
1151
|
if (typeof ctx.data === "undefined") {
|
|
1042
|
-
return { message:
|
|
1152
|
+
return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
|
|
1043
1153
|
}
|
|
1044
|
-
|
|
1154
|
+
if (iss.code !== "invalid_type")
|
|
1155
|
+
return { message: ctx.defaultError };
|
|
1156
|
+
return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
|
|
1045
1157
|
};
|
|
1046
1158
|
return { errorMap: customMap, description };
|
|
1047
1159
|
}
|
|
@@ -1299,11 +1411,13 @@ class ZodType {
|
|
|
1299
1411
|
}
|
|
1300
1412
|
}
|
|
1301
1413
|
const cuidRegex = /^c[^\s-]{8,}$/i;
|
|
1302
|
-
const cuid2Regex = /^[
|
|
1414
|
+
const cuid2Regex = /^[0-9a-z]+$/;
|
|
1303
1415
|
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
|
|
1304
1416
|
// const uuidRegex =
|
|
1305
1417
|
// /^([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;
|
|
1306
1418
|
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;
|
|
1419
|
+
const nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
1420
|
+
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)?)??$/;
|
|
1307
1421
|
// from https://stackoverflow.com/a/46181/1550155
|
|
1308
1422
|
// old version: too slow, didn't support unicode
|
|
1309
1423
|
// 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;
|
|
@@ -1316,41 +1430,48 @@ const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-
|
|
|
1316
1430
|
// /^[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])?)*$/;
|
|
1317
1431
|
// const emailRegex =
|
|
1318
1432
|
// /^(?:[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;
|
|
1319
|
-
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_
|
|
1433
|
+
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
1320
1434
|
// const emailRegex =
|
|
1321
1435
|
// /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
|
|
1322
1436
|
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
|
1323
1437
|
const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
1324
1438
|
let emojiRegex;
|
|
1325
|
-
|
|
1439
|
+
// faster, simpler, safer
|
|
1440
|
+
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])$/;
|
|
1326
1441
|
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})))$/;
|
|
1327
|
-
//
|
|
1328
|
-
const
|
|
1442
|
+
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
1443
|
+
const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
1444
|
+
// simple
|
|
1445
|
+
// const dateRegexSource = `\\d{4}-\\d{2}-\\d{2}`;
|
|
1446
|
+
// no leap year validation
|
|
1447
|
+
// 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))`;
|
|
1448
|
+
// with leap year validation
|
|
1449
|
+
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])))`;
|
|
1450
|
+
const dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
1451
|
+
function timeRegexSource(args) {
|
|
1452
|
+
// let regex = `\\d{2}:\\d{2}:\\d{2}`;
|
|
1453
|
+
let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
|
|
1329
1454
|
if (args.precision) {
|
|
1330
|
-
|
|
1331
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
1332
|
-
}
|
|
1333
|
-
else {
|
|
1334
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
else if (args.precision === 0) {
|
|
1338
|
-
if (args.offset) {
|
|
1339
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
1340
|
-
}
|
|
1341
|
-
else {
|
|
1342
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
|
|
1343
|
-
}
|
|
1455
|
+
regex = `${regex}\\.\\d{${args.precision}}`;
|
|
1344
1456
|
}
|
|
1345
|
-
else {
|
|
1346
|
-
|
|
1347
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
1348
|
-
}
|
|
1349
|
-
else {
|
|
1350
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
|
|
1351
|
-
}
|
|
1457
|
+
else if (args.precision == null) {
|
|
1458
|
+
regex = `${regex}(\\.\\d+)?`;
|
|
1352
1459
|
}
|
|
1353
|
-
|
|
1460
|
+
return regex;
|
|
1461
|
+
}
|
|
1462
|
+
function timeRegex(args) {
|
|
1463
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
1464
|
+
}
|
|
1465
|
+
// Adapted from https://stackoverflow.com/a/3143231
|
|
1466
|
+
function datetimeRegex(args) {
|
|
1467
|
+
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
1468
|
+
const opts = [];
|
|
1469
|
+
opts.push(args.local ? `Z?` : `Z`);
|
|
1470
|
+
if (args.offset)
|
|
1471
|
+
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
1472
|
+
regex = `${regex}(${opts.join("|")})`;
|
|
1473
|
+
return new RegExp(`^${regex}$`);
|
|
1474
|
+
}
|
|
1354
1475
|
function isValidIP(ip, version) {
|
|
1355
1476
|
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
1356
1477
|
return true;
|
|
@@ -1372,9 +1493,7 @@ class ZodString extends ZodType {
|
|
|
1372
1493
|
code: ZodIssueCode.invalid_type,
|
|
1373
1494
|
expected: ZodParsedType.string,
|
|
1374
1495
|
received: ctx.parsedType,
|
|
1375
|
-
}
|
|
1376
|
-
//
|
|
1377
|
-
);
|
|
1496
|
+
});
|
|
1378
1497
|
return INVALID;
|
|
1379
1498
|
}
|
|
1380
1499
|
const status = new ParseStatus();
|
|
@@ -1472,6 +1591,17 @@ class ZodString extends ZodType {
|
|
|
1472
1591
|
status.dirty();
|
|
1473
1592
|
}
|
|
1474
1593
|
}
|
|
1594
|
+
else if (check.kind === "nanoid") {
|
|
1595
|
+
if (!nanoidRegex.test(input.data)) {
|
|
1596
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1597
|
+
addIssueToContext(ctx, {
|
|
1598
|
+
validation: "nanoid",
|
|
1599
|
+
code: ZodIssueCode.invalid_string,
|
|
1600
|
+
message: check.message,
|
|
1601
|
+
});
|
|
1602
|
+
status.dirty();
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1475
1605
|
else if (check.kind === "cuid") {
|
|
1476
1606
|
if (!cuidRegex.test(input.data)) {
|
|
1477
1607
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -1586,6 +1716,41 @@ class ZodString extends ZodType {
|
|
|
1586
1716
|
status.dirty();
|
|
1587
1717
|
}
|
|
1588
1718
|
}
|
|
1719
|
+
else if (check.kind === "date") {
|
|
1720
|
+
const regex = dateRegex;
|
|
1721
|
+
if (!regex.test(input.data)) {
|
|
1722
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1723
|
+
addIssueToContext(ctx, {
|
|
1724
|
+
code: ZodIssueCode.invalid_string,
|
|
1725
|
+
validation: "date",
|
|
1726
|
+
message: check.message,
|
|
1727
|
+
});
|
|
1728
|
+
status.dirty();
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
else if (check.kind === "time") {
|
|
1732
|
+
const regex = timeRegex(check);
|
|
1733
|
+
if (!regex.test(input.data)) {
|
|
1734
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1735
|
+
addIssueToContext(ctx, {
|
|
1736
|
+
code: ZodIssueCode.invalid_string,
|
|
1737
|
+
validation: "time",
|
|
1738
|
+
message: check.message,
|
|
1739
|
+
});
|
|
1740
|
+
status.dirty();
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
else if (check.kind === "duration") {
|
|
1744
|
+
if (!durationRegex.test(input.data)) {
|
|
1745
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1746
|
+
addIssueToContext(ctx, {
|
|
1747
|
+
validation: "duration",
|
|
1748
|
+
code: ZodIssueCode.invalid_string,
|
|
1749
|
+
message: check.message,
|
|
1750
|
+
});
|
|
1751
|
+
status.dirty();
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1589
1754
|
else if (check.kind === "ip") {
|
|
1590
1755
|
if (!isValidIP(input.data, check.version)) {
|
|
1591
1756
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -1597,6 +1762,17 @@ class ZodString extends ZodType {
|
|
|
1597
1762
|
status.dirty();
|
|
1598
1763
|
}
|
|
1599
1764
|
}
|
|
1765
|
+
else if (check.kind === "base64") {
|
|
1766
|
+
if (!base64Regex.test(input.data)) {
|
|
1767
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1768
|
+
addIssueToContext(ctx, {
|
|
1769
|
+
validation: "base64",
|
|
1770
|
+
code: ZodIssueCode.invalid_string,
|
|
1771
|
+
message: check.message,
|
|
1772
|
+
});
|
|
1773
|
+
status.dirty();
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1600
1776
|
else {
|
|
1601
1777
|
util$7.assertNever(check);
|
|
1602
1778
|
}
|
|
@@ -1628,6 +1804,9 @@ class ZodString extends ZodType {
|
|
|
1628
1804
|
uuid(message) {
|
|
1629
1805
|
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
1630
1806
|
}
|
|
1807
|
+
nanoid(message) {
|
|
1808
|
+
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
1809
|
+
}
|
|
1631
1810
|
cuid(message) {
|
|
1632
1811
|
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
1633
1812
|
}
|
|
@@ -1637,16 +1816,20 @@ class ZodString extends ZodType {
|
|
|
1637
1816
|
ulid(message) {
|
|
1638
1817
|
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
1639
1818
|
}
|
|
1819
|
+
base64(message) {
|
|
1820
|
+
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1821
|
+
}
|
|
1640
1822
|
ip(options) {
|
|
1641
1823
|
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
1642
1824
|
}
|
|
1643
1825
|
datetime(options) {
|
|
1644
|
-
var _a;
|
|
1826
|
+
var _a, _b;
|
|
1645
1827
|
if (typeof options === "string") {
|
|
1646
1828
|
return this._addCheck({
|
|
1647
1829
|
kind: "datetime",
|
|
1648
1830
|
precision: null,
|
|
1649
1831
|
offset: false,
|
|
1832
|
+
local: false,
|
|
1650
1833
|
message: options,
|
|
1651
1834
|
});
|
|
1652
1835
|
}
|
|
@@ -1654,9 +1837,30 @@ class ZodString extends ZodType {
|
|
|
1654
1837
|
kind: "datetime",
|
|
1655
1838
|
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
|
1656
1839
|
offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
|
|
1840
|
+
local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
|
|
1657
1841
|
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
|
|
1658
1842
|
});
|
|
1659
1843
|
}
|
|
1844
|
+
date(message) {
|
|
1845
|
+
return this._addCheck({ kind: "date", message });
|
|
1846
|
+
}
|
|
1847
|
+
time(options) {
|
|
1848
|
+
if (typeof options === "string") {
|
|
1849
|
+
return this._addCheck({
|
|
1850
|
+
kind: "time",
|
|
1851
|
+
precision: null,
|
|
1852
|
+
message: options,
|
|
1853
|
+
});
|
|
1854
|
+
}
|
|
1855
|
+
return this._addCheck({
|
|
1856
|
+
kind: "time",
|
|
1857
|
+
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
|
1858
|
+
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
|
|
1859
|
+
});
|
|
1860
|
+
}
|
|
1861
|
+
duration(message) {
|
|
1862
|
+
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
1863
|
+
}
|
|
1660
1864
|
regex(regex, message) {
|
|
1661
1865
|
return this._addCheck({
|
|
1662
1866
|
kind: "regex",
|
|
@@ -1735,6 +1939,15 @@ class ZodString extends ZodType {
|
|
|
1735
1939
|
get isDatetime() {
|
|
1736
1940
|
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
1737
1941
|
}
|
|
1942
|
+
get isDate() {
|
|
1943
|
+
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
1944
|
+
}
|
|
1945
|
+
get isTime() {
|
|
1946
|
+
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
1947
|
+
}
|
|
1948
|
+
get isDuration() {
|
|
1949
|
+
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
1950
|
+
}
|
|
1738
1951
|
get isEmail() {
|
|
1739
1952
|
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
1740
1953
|
}
|
|
@@ -1747,6 +1960,9 @@ class ZodString extends ZodType {
|
|
|
1747
1960
|
get isUUID() {
|
|
1748
1961
|
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
1749
1962
|
}
|
|
1963
|
+
get isNANOID() {
|
|
1964
|
+
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
1965
|
+
}
|
|
1750
1966
|
get isCUID() {
|
|
1751
1967
|
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
1752
1968
|
}
|
|
@@ -1759,6 +1975,9 @@ class ZodString extends ZodType {
|
|
|
1759
1975
|
get isIP() {
|
|
1760
1976
|
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1761
1977
|
}
|
|
1978
|
+
get isBase64() {
|
|
1979
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1980
|
+
}
|
|
1762
1981
|
get minLength() {
|
|
1763
1982
|
let min = null;
|
|
1764
1983
|
for (const ch of this._def.checks) {
|
|
@@ -2746,9 +2965,10 @@ class ZodObject extends ZodType {
|
|
|
2746
2965
|
const syncPairs = [];
|
|
2747
2966
|
for (const pair of pairs) {
|
|
2748
2967
|
const key = await pair.key;
|
|
2968
|
+
const value = await pair.value;
|
|
2749
2969
|
syncPairs.push({
|
|
2750
2970
|
key,
|
|
2751
|
-
value
|
|
2971
|
+
value,
|
|
2752
2972
|
alwaysSet: pair.alwaysSet,
|
|
2753
2973
|
});
|
|
2754
2974
|
}
|
|
@@ -3122,7 +3342,7 @@ const getDiscriminator = (type) => {
|
|
|
3122
3342
|
}
|
|
3123
3343
|
else if (type instanceof ZodNativeEnum) {
|
|
3124
3344
|
// eslint-disable-next-line ban/ban
|
|
3125
|
-
return
|
|
3345
|
+
return util$7.objectValues(type.enum);
|
|
3126
3346
|
}
|
|
3127
3347
|
else if (type instanceof ZodDefault) {
|
|
3128
3348
|
return getDiscriminator(type._def.innerType);
|
|
@@ -3133,8 +3353,23 @@ const getDiscriminator = (type) => {
|
|
|
3133
3353
|
else if (type instanceof ZodNull) {
|
|
3134
3354
|
return [null];
|
|
3135
3355
|
}
|
|
3356
|
+
else if (type instanceof ZodOptional) {
|
|
3357
|
+
return [undefined, ...getDiscriminator(type.unwrap())];
|
|
3358
|
+
}
|
|
3359
|
+
else if (type instanceof ZodNullable) {
|
|
3360
|
+
return [null, ...getDiscriminator(type.unwrap())];
|
|
3361
|
+
}
|
|
3362
|
+
else if (type instanceof ZodBranded) {
|
|
3363
|
+
return getDiscriminator(type.unwrap());
|
|
3364
|
+
}
|
|
3365
|
+
else if (type instanceof ZodReadonly) {
|
|
3366
|
+
return getDiscriminator(type.unwrap());
|
|
3367
|
+
}
|
|
3368
|
+
else if (type instanceof ZodCatch) {
|
|
3369
|
+
return getDiscriminator(type._def.innerType);
|
|
3370
|
+
}
|
|
3136
3371
|
else {
|
|
3137
|
-
return
|
|
3372
|
+
return [];
|
|
3138
3373
|
}
|
|
3139
3374
|
};
|
|
3140
3375
|
class ZodDiscriminatedUnion extends ZodType {
|
|
@@ -3197,7 +3432,7 @@ class ZodDiscriminatedUnion extends ZodType {
|
|
|
3197
3432
|
// try {
|
|
3198
3433
|
for (const type of options) {
|
|
3199
3434
|
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
3200
|
-
if (!discriminatorValues) {
|
|
3435
|
+
if (!discriminatorValues.length) {
|
|
3201
3436
|
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
3202
3437
|
}
|
|
3203
3438
|
for (const value of discriminatorValues) {
|
|
@@ -3410,6 +3645,7 @@ class ZodRecord extends ZodType {
|
|
|
3410
3645
|
pairs.push({
|
|
3411
3646
|
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
3412
3647
|
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
3648
|
+
alwaysSet: key in ctx.data,
|
|
3413
3649
|
});
|
|
3414
3650
|
}
|
|
3415
3651
|
if (ctx.common.async) {
|
|
@@ -3769,6 +4005,10 @@ function createZodEnum(values, params) {
|
|
|
3769
4005
|
});
|
|
3770
4006
|
}
|
|
3771
4007
|
class ZodEnum extends ZodType {
|
|
4008
|
+
constructor() {
|
|
4009
|
+
super(...arguments);
|
|
4010
|
+
_ZodEnum_cache.set(this, void 0);
|
|
4011
|
+
}
|
|
3772
4012
|
_parse(input) {
|
|
3773
4013
|
if (typeof input.data !== "string") {
|
|
3774
4014
|
const ctx = this._getOrReturnCtx(input);
|
|
@@ -3780,7 +4020,10 @@ class ZodEnum extends ZodType {
|
|
|
3780
4020
|
});
|
|
3781
4021
|
return INVALID;
|
|
3782
4022
|
}
|
|
3783
|
-
if (this
|
|
4023
|
+
if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f")) {
|
|
4024
|
+
__classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values), "f");
|
|
4025
|
+
}
|
|
4026
|
+
if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f").has(input.data)) {
|
|
3784
4027
|
const ctx = this._getOrReturnCtx(input);
|
|
3785
4028
|
const expectedValues = this._def.values;
|
|
3786
4029
|
addIssueToContext(ctx, {
|
|
@@ -3816,15 +4059,26 @@ class ZodEnum extends ZodType {
|
|
|
3816
4059
|
}
|
|
3817
4060
|
return enumValues;
|
|
3818
4061
|
}
|
|
3819
|
-
extract(values) {
|
|
3820
|
-
return ZodEnum.create(values
|
|
4062
|
+
extract(values, newDef = this._def) {
|
|
4063
|
+
return ZodEnum.create(values, {
|
|
4064
|
+
...this._def,
|
|
4065
|
+
...newDef,
|
|
4066
|
+
});
|
|
3821
4067
|
}
|
|
3822
|
-
exclude(values) {
|
|
3823
|
-
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt))
|
|
4068
|
+
exclude(values, newDef = this._def) {
|
|
4069
|
+
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
4070
|
+
...this._def,
|
|
4071
|
+
...newDef,
|
|
4072
|
+
});
|
|
3824
4073
|
}
|
|
3825
4074
|
}
|
|
4075
|
+
_ZodEnum_cache = new WeakMap();
|
|
3826
4076
|
ZodEnum.create = createZodEnum;
|
|
3827
4077
|
class ZodNativeEnum extends ZodType {
|
|
4078
|
+
constructor() {
|
|
4079
|
+
super(...arguments);
|
|
4080
|
+
_ZodNativeEnum_cache.set(this, void 0);
|
|
4081
|
+
}
|
|
3828
4082
|
_parse(input) {
|
|
3829
4083
|
const nativeEnumValues = util$7.getValidEnumValues(this._def.values);
|
|
3830
4084
|
const ctx = this._getOrReturnCtx(input);
|
|
@@ -3838,7 +4092,10 @@ class ZodNativeEnum extends ZodType {
|
|
|
3838
4092
|
});
|
|
3839
4093
|
return INVALID;
|
|
3840
4094
|
}
|
|
3841
|
-
if (
|
|
4095
|
+
if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f")) {
|
|
4096
|
+
__classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util$7.getValidEnumValues(this._def.values)), "f");
|
|
4097
|
+
}
|
|
4098
|
+
if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f").has(input.data)) {
|
|
3842
4099
|
const expectedValues = util$7.objectValues(nativeEnumValues);
|
|
3843
4100
|
addIssueToContext(ctx, {
|
|
3844
4101
|
received: ctx.data,
|
|
@@ -3853,6 +4110,7 @@ class ZodNativeEnum extends ZodType {
|
|
|
3853
4110
|
return this._def.values;
|
|
3854
4111
|
}
|
|
3855
4112
|
}
|
|
4113
|
+
_ZodNativeEnum_cache = new WeakMap();
|
|
3856
4114
|
ZodNativeEnum.create = (values, params) => {
|
|
3857
4115
|
return new ZodNativeEnum({
|
|
3858
4116
|
values: values,
|
|
@@ -3922,33 +4180,43 @@ class ZodEffects extends ZodType {
|
|
|
3922
4180
|
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
3923
4181
|
if (effect.type === "preprocess") {
|
|
3924
4182
|
const processed = effect.transform(ctx.data, checkCtx);
|
|
3925
|
-
if (ctx.common.issues.length) {
|
|
3926
|
-
return {
|
|
3927
|
-
status: "dirty",
|
|
3928
|
-
value: ctx.data,
|
|
3929
|
-
};
|
|
3930
|
-
}
|
|
3931
4183
|
if (ctx.common.async) {
|
|
3932
|
-
return Promise.resolve(processed).then((processed) => {
|
|
3933
|
-
|
|
4184
|
+
return Promise.resolve(processed).then(async (processed) => {
|
|
4185
|
+
if (status.value === "aborted")
|
|
4186
|
+
return INVALID;
|
|
4187
|
+
const result = await this._def.schema._parseAsync({
|
|
3934
4188
|
data: processed,
|
|
3935
4189
|
path: ctx.path,
|
|
3936
4190
|
parent: ctx,
|
|
3937
4191
|
});
|
|
4192
|
+
if (result.status === "aborted")
|
|
4193
|
+
return INVALID;
|
|
4194
|
+
if (result.status === "dirty")
|
|
4195
|
+
return DIRTY(result.value);
|
|
4196
|
+
if (status.value === "dirty")
|
|
4197
|
+
return DIRTY(result.value);
|
|
4198
|
+
return result;
|
|
3938
4199
|
});
|
|
3939
4200
|
}
|
|
3940
4201
|
else {
|
|
3941
|
-
|
|
4202
|
+
if (status.value === "aborted")
|
|
4203
|
+
return INVALID;
|
|
4204
|
+
const result = this._def.schema._parseSync({
|
|
3942
4205
|
data: processed,
|
|
3943
4206
|
path: ctx.path,
|
|
3944
4207
|
parent: ctx,
|
|
3945
4208
|
});
|
|
4209
|
+
if (result.status === "aborted")
|
|
4210
|
+
return INVALID;
|
|
4211
|
+
if (result.status === "dirty")
|
|
4212
|
+
return DIRTY(result.value);
|
|
4213
|
+
if (status.value === "dirty")
|
|
4214
|
+
return DIRTY(result.value);
|
|
4215
|
+
return result;
|
|
3946
4216
|
}
|
|
3947
4217
|
}
|
|
3948
4218
|
if (effect.type === "refinement") {
|
|
3949
|
-
const executeRefinement = (acc
|
|
3950
|
-
// effect: RefinementEffect<any>
|
|
3951
|
-
) => {
|
|
4219
|
+
const executeRefinement = (acc) => {
|
|
3952
4220
|
const result = effect.refinement(acc, checkCtx);
|
|
3953
4221
|
if (ctx.common.async) {
|
|
3954
4222
|
return Promise.resolve(result);
|
|
@@ -4251,10 +4519,18 @@ class ZodPipeline extends ZodType {
|
|
|
4251
4519
|
class ZodReadonly extends ZodType {
|
|
4252
4520
|
_parse(input) {
|
|
4253
4521
|
const result = this._def.innerType._parse(input);
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4522
|
+
const freeze = (data) => {
|
|
4523
|
+
if (isValid(data)) {
|
|
4524
|
+
data.value = Object.freeze(data.value);
|
|
4525
|
+
}
|
|
4526
|
+
return data;
|
|
4527
|
+
};
|
|
4528
|
+
return isAsync$1(result)
|
|
4529
|
+
? result.then((data) => freeze(data))
|
|
4530
|
+
: freeze(result);
|
|
4531
|
+
}
|
|
4532
|
+
unwrap() {
|
|
4533
|
+
return this._def.innerType;
|
|
4258
4534
|
}
|
|
4259
4535
|
}
|
|
4260
4536
|
ZodReadonly.create = (type, params) => {
|
|
@@ -4264,7 +4540,7 @@ ZodReadonly.create = (type, params) => {
|
|
|
4264
4540
|
...processCreateParams(params),
|
|
4265
4541
|
});
|
|
4266
4542
|
};
|
|
4267
|
-
|
|
4543
|
+
function custom(check, params = {},
|
|
4268
4544
|
/**
|
|
4269
4545
|
* @deprecated
|
|
4270
4546
|
*
|
|
@@ -4275,7 +4551,7 @@ const custom = (check, params = {},
|
|
|
4275
4551
|
* ```
|
|
4276
4552
|
*
|
|
4277
4553
|
*/
|
|
4278
|
-
fatal)
|
|
4554
|
+
fatal) {
|
|
4279
4555
|
if (check)
|
|
4280
4556
|
return ZodAny.create().superRefine((data, ctx) => {
|
|
4281
4557
|
var _a, _b;
|
|
@@ -4291,7 +4567,7 @@ fatal) => {
|
|
|
4291
4567
|
}
|
|
4292
4568
|
});
|
|
4293
4569
|
return ZodAny.create();
|
|
4294
|
-
}
|
|
4570
|
+
}
|
|
4295
4571
|
const late = {
|
|
4296
4572
|
object: ZodObject.lazycreate,
|
|
4297
4573
|
};
|
|
@@ -4409,6 +4685,7 @@ var z = /*#__PURE__*/Object.freeze({
|
|
|
4409
4685
|
ZodParsedType: ZodParsedType,
|
|
4410
4686
|
getParsedType: getParsedType,
|
|
4411
4687
|
ZodType: ZodType,
|
|
4688
|
+
datetimeRegex: datetimeRegex,
|
|
4412
4689
|
ZodString: ZodString,
|
|
4413
4690
|
ZodNumber: ZodNumber,
|
|
4414
4691
|
ZodBigInt: ZodBigInt,
|
|
@@ -4513,7 +4790,7 @@ var validate = async (ctx, exitIfInvalid = true) => {
|
|
|
4513
4790
|
const ora = (await import('ora')).default;
|
|
4514
4791
|
const spinnerValidate = ora("Data model validation...").start();
|
|
4515
4792
|
const filesList = await findFiles(ctx.client.srcDir, CUBE_YAML_FILE_REGEX);
|
|
4516
|
-
const securityContextFilesList = await findFiles(ctx.client.srcDir, SECURITY_CONTEXT_FILE_REGEX);
|
|
4793
|
+
const securityContextFilesList = await findFiles(ctx.client.modelsSrc || ctx.client.srcDir, SECURITY_CONTEXT_FILE_REGEX);
|
|
4517
4794
|
const dataModelErrors = await dataModelsValidation(filesList);
|
|
4518
4795
|
if (dataModelErrors.length) {
|
|
4519
4796
|
spinnerValidate.fail("One or more cube.yaml files are invalid:");
|
|
@@ -4538,9 +4815,18 @@ async function dataModelsValidation(filesList) {
|
|
|
4538
4815
|
for (const [_, filePath] of filesList) {
|
|
4539
4816
|
const fileContentRaw = await fs$1.readFile(filePath, "utf8");
|
|
4540
4817
|
const cube = YAML.parse(fileContentRaw);
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4818
|
+
if (!(cube === null || cube === void 0 ? void 0 : cube.cubes) && !(cube === null || cube === void 0 ? void 0 : cube.views)) {
|
|
4819
|
+
return [`${filePath}: At least one cubes or views must be defined`];
|
|
4820
|
+
}
|
|
4821
|
+
const cubeModelSafeParse = cubeModelSchema.safeParse(cube);
|
|
4822
|
+
const viewModelSafeParse = viewModelSchema.safeParse(cube);
|
|
4823
|
+
if (cube.cubes && !cubeModelSafeParse.success) {
|
|
4824
|
+
errorFormatter(cubeModelSafeParse.error.issues).forEach((error) => {
|
|
4825
|
+
errors.push(`${filePath}: ${error}`);
|
|
4826
|
+
});
|
|
4827
|
+
}
|
|
4828
|
+
if (cube.views && !viewModelSafeParse.success) {
|
|
4829
|
+
errorFormatter(viewModelSafeParse.error.issues).forEach((error) => {
|
|
4544
4830
|
errors.push(`${filePath}: ${error}`);
|
|
4545
4831
|
});
|
|
4546
4832
|
}
|
|
@@ -4619,6 +4905,19 @@ const cubeModelSchema = z
|
|
|
4619
4905
|
message: "At least one measure or dimension must be defined",
|
|
4620
4906
|
path: ["cubes"],
|
|
4621
4907
|
});
|
|
4908
|
+
const viewModelSchema = z.object({
|
|
4909
|
+
views: z
|
|
4910
|
+
.object({
|
|
4911
|
+
name: z.string(),
|
|
4912
|
+
cubes: z
|
|
4913
|
+
.object({
|
|
4914
|
+
join_path: z.string(),
|
|
4915
|
+
})
|
|
4916
|
+
.array(),
|
|
4917
|
+
})
|
|
4918
|
+
.array()
|
|
4919
|
+
.min(1),
|
|
4920
|
+
});
|
|
4622
4921
|
const securityContextSchema = z.array(z.object({
|
|
4623
4922
|
name: z.string(),
|
|
4624
4923
|
securityContext: z.object({}), // can be any object
|
|
@@ -19975,6 +20274,25 @@ const checkNodeVersion = async () => {
|
|
|
19975
20274
|
process.exit(1);
|
|
19976
20275
|
}
|
|
19977
20276
|
};
|
|
20277
|
+
/**
|
|
20278
|
+
* Get the value of a process argument by key
|
|
20279
|
+
* Example: getArgumentByKey("--email") or getArgumentByKey(["--email", "-e"])
|
|
20280
|
+
* @param key The key to search for in the process arguments
|
|
20281
|
+
* @returns
|
|
20282
|
+
*/
|
|
20283
|
+
const getArgumentByKey = (key) => {
|
|
20284
|
+
if (Array.isArray(key)) {
|
|
20285
|
+
for (const k of key) {
|
|
20286
|
+
if (process.argv.includes(k)) {
|
|
20287
|
+
const index = process.argv.indexOf(k);
|
|
20288
|
+
return index !== -1 ? process.argv[index + 1] : undefined;
|
|
20289
|
+
}
|
|
20290
|
+
}
|
|
20291
|
+
return undefined;
|
|
20292
|
+
}
|
|
20293
|
+
const index = process.argv.indexOf(key);
|
|
20294
|
+
return index !== -1 ? process.argv[index + 1] : undefined;
|
|
20295
|
+
};
|
|
19978
20296
|
|
|
19979
20297
|
var build = async () => {
|
|
19980
20298
|
try {
|
|
@@ -20085,29 +20403,58 @@ const inquirerSelect = import('@inquirer/select');
|
|
|
20085
20403
|
const YAML_OR_JS_FILES = /^(.*)\.(cube|sc)\.(ya?ml|js)$/;
|
|
20086
20404
|
let ora$1;
|
|
20087
20405
|
var push = async () => {
|
|
20088
|
-
var _a;
|
|
20406
|
+
var _a, _b;
|
|
20089
20407
|
let spinnerPushing;
|
|
20090
20408
|
try {
|
|
20091
20409
|
checkNodeVersion();
|
|
20092
20410
|
ora$1 = (await oraP$1).default;
|
|
20093
20411
|
const config = await provideConfig();
|
|
20412
|
+
if (process.argv.includes("--api-key") || process.argv.includes("-k")) {
|
|
20413
|
+
spinnerPushing = ora$1("Using API key...").start();
|
|
20414
|
+
await pushByApiKey(config, spinnerPushing);
|
|
20415
|
+
spinnerPushing.succeed("Published using API key");
|
|
20416
|
+
return;
|
|
20417
|
+
}
|
|
20094
20418
|
const token = await verify(config);
|
|
20095
20419
|
const { workspaceId, name: workspaceName } = await selectWorkspace(config, token);
|
|
20096
|
-
const
|
|
20097
|
-
|
|
20098
|
-
|
|
20099
|
-
spinnerArchive.succeed("Bundling completed");
|
|
20100
|
-
spinnerPushing = ora$1(`Publishing to ${workspaceName} using ${config.pushBaseUrl}...`).start();
|
|
20420
|
+
const workspacePreviewUrl = `${config.previewBaseUrl}/workspace/${workspaceId}`;
|
|
20421
|
+
await buildArchive(config);
|
|
20422
|
+
spinnerPushing = ora$1(`Publishing to ${workspaceName} using ${workspacePreviewUrl}...`).start();
|
|
20101
20423
|
await sendBuild(config, { workspaceId, token });
|
|
20102
|
-
spinnerPushing.succeed(`Published to ${workspaceName} using ${
|
|
20424
|
+
spinnerPushing.succeed(`Published to ${workspaceName} using ${workspacePreviewUrl}`);
|
|
20103
20425
|
}
|
|
20104
20426
|
catch (error) {
|
|
20105
20427
|
spinnerPushing === null || spinnerPushing === void 0 ? void 0 : spinnerPushing.fail("Publishing failed");
|
|
20106
|
-
|
|
20428
|
+
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.statusText) === "Unauthorized") {
|
|
20429
|
+
console.error("Unauthorized. Please check your credentials.");
|
|
20430
|
+
}
|
|
20431
|
+
else {
|
|
20432
|
+
console.error(((_b = error.response) === null || _b === void 0 ? void 0 : _b.data) || (error === null || error === void 0 ? void 0 : error.message) || error);
|
|
20433
|
+
}
|
|
20107
20434
|
await reportErrorToRollbar(error);
|
|
20108
20435
|
process.exit(1);
|
|
20109
20436
|
}
|
|
20110
20437
|
};
|
|
20438
|
+
async function pushByApiKey(config, spinner) {
|
|
20439
|
+
const apiKey = getArgumentByKey(["--api-key", "-k"]);
|
|
20440
|
+
if (!apiKey) {
|
|
20441
|
+
spinner.fail("No API key provided");
|
|
20442
|
+
process.exit(1);
|
|
20443
|
+
}
|
|
20444
|
+
const email = getArgumentByKey(["--email", "-e"]);
|
|
20445
|
+
if (!email || !/\S+@\S+\.\S+/.test(email)) {
|
|
20446
|
+
spinner.fail("Invalid email provided. Please provide a valid email using --email (-e) flag");
|
|
20447
|
+
process.exit(1);
|
|
20448
|
+
}
|
|
20449
|
+
// message is optional
|
|
20450
|
+
const message = getArgumentByKey(["--message", "-m"]);
|
|
20451
|
+
await buildArchive(config);
|
|
20452
|
+
return sendBuildByApiKey(config, {
|
|
20453
|
+
apiKey,
|
|
20454
|
+
email,
|
|
20455
|
+
message,
|
|
20456
|
+
});
|
|
20457
|
+
}
|
|
20111
20458
|
async function selectWorkspace(ctx, token) {
|
|
20112
20459
|
const workspaceSpinner = ora$1({
|
|
20113
20460
|
text: `Fetching workspaces using ${ctx.pushBaseUrl}...`,
|
|
@@ -20153,6 +20500,12 @@ async function verify(ctx) {
|
|
|
20153
20500
|
}
|
|
20154
20501
|
return token;
|
|
20155
20502
|
}
|
|
20503
|
+
async function buildArchive(config) {
|
|
20504
|
+
const spinnerArchive = ora$1("Building...").start();
|
|
20505
|
+
const filesList = await findFiles(config.client.modelsSrc || config.client.srcDir, YAML_OR_JS_FILES);
|
|
20506
|
+
await archive(config, filesList);
|
|
20507
|
+
return spinnerArchive.succeed("Bundling completed");
|
|
20508
|
+
}
|
|
20156
20509
|
async function archive(ctx, yamlFiles, includeBuild = true) {
|
|
20157
20510
|
const output = fs$2.createWriteStream(ctx.client.archiveFile);
|
|
20158
20511
|
const _archiver = archiver.create("zip", {
|
|
@@ -20173,13 +20526,30 @@ async function archive(ctx, yamlFiles, includeBuild = true) {
|
|
|
20173
20526
|
output.on("close", resolve);
|
|
20174
20527
|
});
|
|
20175
20528
|
}
|
|
20529
|
+
async function sendBuildByApiKey(ctx, { apiKey, email, message }) {
|
|
20530
|
+
var _a;
|
|
20531
|
+
const { FormData, Blob } = await import('formdata-node');
|
|
20532
|
+
const { fileFromPath } = await Promise.resolve().then(function () { return fileFromPath$1; });
|
|
20533
|
+
const file = await fileFromPath(ctx.client.archiveFile, "embeddable-build.zip");
|
|
20534
|
+
const form = new FormData();
|
|
20535
|
+
form.set("file", file, "embeddable-build.zip");
|
|
20536
|
+
const metadataBlob = new Blob([JSON.stringify({ authorEmail: email, description: message })], { type: "application/json" });
|
|
20537
|
+
form.set("metadata", metadataBlob, "metadata.json");
|
|
20538
|
+
const response = await uploadFile(form, `${ctx.pushBaseUrl}/api/v1/bundle/upload`, apiKey);
|
|
20539
|
+
await fs$1.rm(ctx.client.archiveFile);
|
|
20540
|
+
return { bundleId: (_a = response.data) === null || _a === void 0 ? void 0 : _a.bundleId, email, message };
|
|
20541
|
+
}
|
|
20176
20542
|
async function sendBuild(ctx, { workspaceId, token }) {
|
|
20177
20543
|
const { FormData } = await import('formdata-node');
|
|
20178
20544
|
const { fileFromPath } = await Promise.resolve().then(function () { return fileFromPath$1; });
|
|
20179
20545
|
const file = await fileFromPath(ctx.client.archiveFile, "embeddable-build.zip");
|
|
20180
20546
|
const form = new FormData();
|
|
20181
20547
|
form.set("file", file, "embeddable-build.zip");
|
|
20182
|
-
await
|
|
20548
|
+
await uploadFile(form, `${ctx.pushBaseUrl}/bundle/${workspaceId}/upload`, token);
|
|
20549
|
+
await fs$1.rm(ctx.client.archiveFile);
|
|
20550
|
+
}
|
|
20551
|
+
async function uploadFile(formData, url, token) {
|
|
20552
|
+
return axios.post(url, formData, {
|
|
20183
20553
|
headers: {
|
|
20184
20554
|
"Content-Type": "multipart/form-data",
|
|
20185
20555
|
Authorization: `Bearer ${token}`,
|
|
@@ -20187,7 +20557,6 @@ async function sendBuild(ctx, { workspaceId, token }) {
|
|
|
20187
20557
|
maxContentLength: Infinity,
|
|
20188
20558
|
maxBodyLength: Infinity,
|
|
20189
20559
|
});
|
|
20190
|
-
await fs$1.rm(ctx.client.archiveFile);
|
|
20191
20560
|
}
|
|
20192
20561
|
async function getWorkspaces(ctx, token, workspaceSpinner) {
|
|
20193
20562
|
var _a;
|
|
@@ -20394,9 +20763,21 @@ const getPreviewWorkspace = async (ctx) => {
|
|
|
20394
20763
|
}
|
|
20395
20764
|
};
|
|
20396
20765
|
|
|
20397
|
-
var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientId, errorFallbackComponent, applicationEnvironment, rollbarAccessToken, previewBaseUrl, }) => {
|
|
20766
|
+
var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientId, errorFallbackComponent, applicationEnvironment, rollbarAccessToken, previewBaseUrl, modelsSrc, componentsSrc = "src", }) => {
|
|
20398
20767
|
const coreRoot = path$1.resolve(__dirname, "..");
|
|
20399
20768
|
const clientRoot = process.cwd();
|
|
20769
|
+
if (!path$1.isAbsolute(componentsSrc)) {
|
|
20770
|
+
componentsSrc = path$1.resolve(clientRoot, componentsSrc);
|
|
20771
|
+
if (!existsSync(componentsSrc)) {
|
|
20772
|
+
throw new Error(`componentsSrc directory ${componentsSrc} does not exist`);
|
|
20773
|
+
}
|
|
20774
|
+
}
|
|
20775
|
+
if (modelsSrc && !path$1.isAbsolute(modelsSrc)) {
|
|
20776
|
+
modelsSrc = path$1.resolve(clientRoot, modelsSrc);
|
|
20777
|
+
if (!existsSync(modelsSrc)) {
|
|
20778
|
+
throw new Error(`modelsSrc directory ${modelsSrc} does not exist`);
|
|
20779
|
+
}
|
|
20780
|
+
}
|
|
20400
20781
|
return {
|
|
20401
20782
|
core: {
|
|
20402
20783
|
rootDir: coreRoot,
|
|
@@ -20405,8 +20786,9 @@ var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientI
|
|
|
20405
20786
|
},
|
|
20406
20787
|
client: {
|
|
20407
20788
|
rootDir: clientRoot,
|
|
20789
|
+
srcDir: path$1.resolve(clientRoot, componentsSrc),
|
|
20790
|
+
modelsSrc: modelsSrc ? path$1.resolve(clientRoot, modelsSrc) : undefined,
|
|
20408
20791
|
buildDir: path$1.resolve(clientRoot, ".embeddable-build"),
|
|
20409
|
-
srcDir: path$1.resolve(clientRoot, "src"),
|
|
20410
20792
|
tmpDir: path$1.resolve(clientRoot, ".embeddable-tmp"),
|
|
20411
20793
|
componentDir: path$1.resolve(clientRoot, ".embeddable-build", "component"),
|
|
20412
20794
|
stencilBuild: path$1.resolve(clientRoot, ".embeddable-build", "dist", "embeddable-wrapper"),
|