@embeddable.com/sdk-utils 0.7.4 → 0.8.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/lib/componentLibraryUtils.d.ts +23 -0
- package/lib/componentLibraryUtils.test.d.ts +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.esm.js +73 -29
- package/lib/index.esm.js.map +1 -1
- package/lib/readJsonFile.d.ts +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const getComponentLibraryConfig: (componentLibrary: string | ComponentLibraryConfig) => {
|
|
2
|
+
libraryName: string;
|
|
3
|
+
include: string[];
|
|
4
|
+
exclude: string[];
|
|
5
|
+
};
|
|
6
|
+
export declare const EXTERNAL_LIBRARY_META_FILE_NAME = "embeddable-components.json";
|
|
7
|
+
export declare const EXTERNAL_LIBRARY_GLOBAL_HOOKS_META_NAME = "globalHooks.json";
|
|
8
|
+
export declare const getComponentLibraryMeta: (ctx: any, componentLibrary: string | ComponentLibraryConfig) => Promise<{
|
|
9
|
+
components: string[];
|
|
10
|
+
editors: string[];
|
|
11
|
+
plugin: string;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const getGlobalHooksMeta: (ctx: any, libraryName: string) => Promise<GlobalHooksMeta>;
|
|
14
|
+
type GlobalHooksMeta = {
|
|
15
|
+
themeProvider?: string;
|
|
16
|
+
lifecycleHooks: string[];
|
|
17
|
+
};
|
|
18
|
+
export type ComponentLibraryConfig = {
|
|
19
|
+
name: string;
|
|
20
|
+
include?: string[];
|
|
21
|
+
exclude?: string[];
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/index.d.ts
CHANGED
|
@@ -2,3 +2,5 @@ export { default as findFiles } from "./findFiles";
|
|
|
2
2
|
export { default as runProcess } from "./runProcess";
|
|
3
3
|
export { errorFormatter, formatErrorPath } from "./errorFormatter";
|
|
4
4
|
export { getContentHash } from "./fileContentHash";
|
|
5
|
+
export { loadJson } from "./readJsonFile";
|
|
6
|
+
export { getComponentLibraryConfig, getComponentLibraryMeta, EXTERNAL_LIBRARY_META_FILE_NAME, getGlobalHooksMeta, EXTERNAL_LIBRARY_GLOBAL_HOOKS_META_NAME, ComponentLibraryConfig, } from "./componentLibraryUtils";
|
package/lib/index.esm.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { readdir, lstat } from 'node:fs/promises';
|
|
1
|
+
import { readdir, lstat, readFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { fork } from 'node:child_process';
|
|
4
4
|
import ora from 'ora';
|
|
5
5
|
import * as crypto from 'node:crypto';
|
|
6
|
+
import * as path from 'path';
|
|
6
7
|
|
|
7
8
|
var findFiles = async (initialSrcDir, regex) => {
|
|
8
9
|
const filesList = [];
|
|
@@ -592,7 +593,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
592
593
|
var errorUtil;
|
|
593
594
|
(function (errorUtil) {
|
|
594
595
|
errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
595
|
-
errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message ===
|
|
596
|
+
errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
596
597
|
})(errorUtil || (errorUtil = {}));
|
|
597
598
|
|
|
598
599
|
var _ZodEnum_cache, _ZodNativeEnum_cache;
|
|
@@ -649,14 +650,14 @@ function processCreateParams(params) {
|
|
|
649
650
|
var _a, _b;
|
|
650
651
|
const { message } = params;
|
|
651
652
|
if (iss.code === "invalid_enum_value") {
|
|
652
|
-
return { message: message !== null && message !==
|
|
653
|
+
return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
|
|
653
654
|
}
|
|
654
655
|
if (typeof ctx.data === "undefined") {
|
|
655
|
-
return { message: (_a = message !== null && message !==
|
|
656
|
+
return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
|
|
656
657
|
}
|
|
657
658
|
if (iss.code !== "invalid_type")
|
|
658
659
|
return { message: ctx.defaultError };
|
|
659
|
-
return { message: (_b = message !== null && message !==
|
|
660
|
+
return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
|
|
660
661
|
};
|
|
661
662
|
return { errorMap: customMap, description };
|
|
662
663
|
}
|
|
@@ -712,10 +713,10 @@ class ZodType {
|
|
|
712
713
|
const ctx = {
|
|
713
714
|
common: {
|
|
714
715
|
issues: [],
|
|
715
|
-
async: (_a = params === null || params ===
|
|
716
|
-
contextualErrorMap: params === null || params ===
|
|
716
|
+
async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
|
|
717
|
+
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
|
|
717
718
|
},
|
|
718
|
-
path: (params === null || params ===
|
|
719
|
+
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
719
720
|
schemaErrorMap: this._def.errorMap,
|
|
720
721
|
parent: null,
|
|
721
722
|
data,
|
|
@@ -749,7 +750,7 @@ class ZodType {
|
|
|
749
750
|
};
|
|
750
751
|
}
|
|
751
752
|
catch (err) {
|
|
752
|
-
if ((_b = (_a = err === null || err ===
|
|
753
|
+
if ((_b = (_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes("encountered")) {
|
|
753
754
|
this["~standard"].async = true;
|
|
754
755
|
}
|
|
755
756
|
ctx.common = {
|
|
@@ -776,10 +777,10 @@ class ZodType {
|
|
|
776
777
|
const ctx = {
|
|
777
778
|
common: {
|
|
778
779
|
issues: [],
|
|
779
|
-
contextualErrorMap: params === null || params ===
|
|
780
|
+
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
|
|
780
781
|
async: true,
|
|
781
782
|
},
|
|
782
|
-
path: (params === null || params ===
|
|
783
|
+
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
783
784
|
schemaErrorMap: this._def.errorMap,
|
|
784
785
|
parent: null,
|
|
785
786
|
data,
|
|
@@ -1470,10 +1471,10 @@ class ZodString extends ZodType {
|
|
|
1470
1471
|
}
|
|
1471
1472
|
return this._addCheck({
|
|
1472
1473
|
kind: "datetime",
|
|
1473
|
-
precision: typeof (options === null || options ===
|
|
1474
|
-
offset: (_a = options === null || options ===
|
|
1475
|
-
local: (_b = options === null || options ===
|
|
1476
|
-
...errorUtil.errToObj(options === null || options ===
|
|
1474
|
+
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
|
1475
|
+
offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
|
|
1476
|
+
local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
|
|
1477
|
+
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
|
|
1477
1478
|
});
|
|
1478
1479
|
}
|
|
1479
1480
|
date(message) {
|
|
@@ -1489,8 +1490,8 @@ class ZodString extends ZodType {
|
|
|
1489
1490
|
}
|
|
1490
1491
|
return this._addCheck({
|
|
1491
1492
|
kind: "time",
|
|
1492
|
-
precision: typeof (options === null || options ===
|
|
1493
|
-
...errorUtil.errToObj(options === null || options ===
|
|
1493
|
+
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
|
1494
|
+
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
|
|
1494
1495
|
});
|
|
1495
1496
|
}
|
|
1496
1497
|
duration(message) {
|
|
@@ -1507,8 +1508,8 @@ class ZodString extends ZodType {
|
|
|
1507
1508
|
return this._addCheck({
|
|
1508
1509
|
kind: "includes",
|
|
1509
1510
|
value: value,
|
|
1510
|
-
position: options === null || options ===
|
|
1511
|
-
...errorUtil.errToObj(options === null || options ===
|
|
1511
|
+
position: options === null || options === void 0 ? void 0 : options.position,
|
|
1512
|
+
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
|
|
1512
1513
|
});
|
|
1513
1514
|
}
|
|
1514
1515
|
startsWith(value, message) {
|
|
@@ -1645,7 +1646,7 @@ ZodString.create = (params) => {
|
|
|
1645
1646
|
return new ZodString({
|
|
1646
1647
|
checks: [],
|
|
1647
1648
|
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
1648
|
-
coerce: (_a = params === null || params ===
|
|
1649
|
+
coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
|
|
1649
1650
|
...processCreateParams(params),
|
|
1650
1651
|
});
|
|
1651
1652
|
};
|
|
@@ -1899,7 +1900,7 @@ ZodNumber.create = (params) => {
|
|
|
1899
1900
|
return new ZodNumber({
|
|
1900
1901
|
checks: [],
|
|
1901
1902
|
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
1902
|
-
coerce: (params === null || params ===
|
|
1903
|
+
coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
|
|
1903
1904
|
...processCreateParams(params),
|
|
1904
1905
|
});
|
|
1905
1906
|
};
|
|
@@ -2080,7 +2081,7 @@ ZodBigInt.create = (params) => {
|
|
|
2080
2081
|
return new ZodBigInt({
|
|
2081
2082
|
checks: [],
|
|
2082
2083
|
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
2083
|
-
coerce: (_a = params === null || params ===
|
|
2084
|
+
coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
|
|
2084
2085
|
...processCreateParams(params),
|
|
2085
2086
|
});
|
|
2086
2087
|
};
|
|
@@ -2105,7 +2106,7 @@ class ZodBoolean extends ZodType {
|
|
|
2105
2106
|
ZodBoolean.create = (params) => {
|
|
2106
2107
|
return new ZodBoolean({
|
|
2107
2108
|
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
2108
|
-
coerce: (params === null || params ===
|
|
2109
|
+
coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
|
|
2109
2110
|
...processCreateParams(params),
|
|
2110
2111
|
});
|
|
2111
2112
|
};
|
|
@@ -2215,7 +2216,7 @@ class ZodDate extends ZodType {
|
|
|
2215
2216
|
ZodDate.create = (params) => {
|
|
2216
2217
|
return new ZodDate({
|
|
2217
2218
|
checks: [],
|
|
2218
|
-
coerce: (params === null || params ===
|
|
2219
|
+
coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
|
|
2219
2220
|
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
2220
2221
|
...processCreateParams(params),
|
|
2221
2222
|
});
|
|
@@ -2643,10 +2644,10 @@ class ZodObject extends ZodType {
|
|
|
2643
2644
|
? {
|
|
2644
2645
|
errorMap: (issue, ctx) => {
|
|
2645
2646
|
var _a, _b, _c, _d;
|
|
2646
|
-
const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b ===
|
|
2647
|
+
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;
|
|
2647
2648
|
if (issue.code === "unrecognized_keys")
|
|
2648
2649
|
return {
|
|
2649
|
-
message: (_d = errorUtil.errToObj(message).message) !== null && _d !==
|
|
2650
|
+
message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
|
|
2650
2651
|
};
|
|
2651
2652
|
return {
|
|
2652
2653
|
message: defaultError,
|
|
@@ -3656,7 +3657,7 @@ function createZodEnum(values, params) {
|
|
|
3656
3657
|
class ZodEnum extends ZodType {
|
|
3657
3658
|
constructor() {
|
|
3658
3659
|
super(...arguments);
|
|
3659
|
-
_ZodEnum_cache.set(this,
|
|
3660
|
+
_ZodEnum_cache.set(this, void 0);
|
|
3660
3661
|
}
|
|
3661
3662
|
_parse(input) {
|
|
3662
3663
|
if (typeof input.data !== "string") {
|
|
@@ -3726,7 +3727,7 @@ ZodEnum.create = createZodEnum;
|
|
|
3726
3727
|
class ZodNativeEnum extends ZodType {
|
|
3727
3728
|
constructor() {
|
|
3728
3729
|
super(...arguments);
|
|
3729
|
-
_ZodNativeEnum_cache.set(this,
|
|
3730
|
+
_ZodNativeEnum_cache.set(this, void 0);
|
|
3730
3731
|
}
|
|
3731
3732
|
_parse(input) {
|
|
3732
3733
|
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
@@ -4308,5 +4309,48 @@ const getContentHash = (contentString) => {
|
|
|
4308
4309
|
.substring(0, 5);
|
|
4309
4310
|
};
|
|
4310
4311
|
|
|
4311
|
-
|
|
4312
|
+
const loadJson = async (filePath) => {
|
|
4313
|
+
const data = await readFile(filePath, "utf-8");
|
|
4314
|
+
return JSON.parse(data);
|
|
4315
|
+
};
|
|
4316
|
+
|
|
4317
|
+
const getComponentLibraryConfig = (componentLibrary) => {
|
|
4318
|
+
let libraryName = componentLibrary;
|
|
4319
|
+
const include = [];
|
|
4320
|
+
const exclude = [];
|
|
4321
|
+
if (typeof componentLibrary === "object" && componentLibrary !== null) {
|
|
4322
|
+
libraryName = componentLibrary.name;
|
|
4323
|
+
if (componentLibrary.include) {
|
|
4324
|
+
include.push(...componentLibrary.include);
|
|
4325
|
+
}
|
|
4326
|
+
if (componentLibrary.exclude) {
|
|
4327
|
+
exclude.push(...componentLibrary.exclude);
|
|
4328
|
+
}
|
|
4329
|
+
}
|
|
4330
|
+
return { libraryName, include, exclude };
|
|
4331
|
+
};
|
|
4332
|
+
const EXTERNAL_LIBRARY_META_FILE_NAME = "embeddable-components.json";
|
|
4333
|
+
const EXTERNAL_LIBRARY_GLOBAL_HOOKS_META_NAME = "globalHooks.json";
|
|
4334
|
+
const getComponentLibraryMeta = async (ctx, componentLibrary) => {
|
|
4335
|
+
const { libraryName, include, exclude } = getComponentLibraryConfig(componentLibrary);
|
|
4336
|
+
const libraryMeta = (await loadJson(getLibraryPath(ctx, libraryName, EXTERNAL_LIBRARY_META_FILE_NAME)));
|
|
4337
|
+
const filterItems = (items) => {
|
|
4338
|
+
let result = items;
|
|
4339
|
+
if (include.length > 0) {
|
|
4340
|
+
result = result.filter((item) => include.includes(item));
|
|
4341
|
+
}
|
|
4342
|
+
return result.filter((item) => !exclude.includes(item));
|
|
4343
|
+
};
|
|
4344
|
+
return {
|
|
4345
|
+
...libraryMeta,
|
|
4346
|
+
components: filterItems(libraryMeta.components),
|
|
4347
|
+
editors: filterItems(libraryMeta.editors),
|
|
4348
|
+
};
|
|
4349
|
+
};
|
|
4350
|
+
const getGlobalHooksMeta = async (ctx, libraryName) => {
|
|
4351
|
+
return (await loadJson(getLibraryPath(ctx, libraryName, EXTERNAL_LIBRARY_GLOBAL_HOOKS_META_NAME)));
|
|
4352
|
+
};
|
|
4353
|
+
const getLibraryPath = (ctx, libraryName, fileName) => path.resolve(ctx.client.rootDir, "node_modules", libraryName, "dist", fileName);
|
|
4354
|
+
|
|
4355
|
+
export { EXTERNAL_LIBRARY_GLOBAL_HOOKS_META_NAME, EXTERNAL_LIBRARY_META_FILE_NAME, errorFormatter, findFiles, formatErrorPath, getComponentLibraryConfig, getComponentLibraryMeta, getContentHash, getGlobalHooksMeta, loadJson, runProcess };
|
|
4312
4356
|
//# sourceMappingURL=index.esm.js.map
|