@blocklet/meta 1.16.41 → 1.16.42-beta-20250403-230303-c167c6a1
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/parse-navigation-from-blocklet.js +9 -0
- package/lib/util-meta.js +5 -4
- package/lib/util.js +18 -5
- package/lib/with-cache.d.ts +6 -0
- package/lib/with-cache.js +26 -0
- package/package.json +6 -5
|
@@ -516,6 +516,15 @@ exports.cleanOldNavigationHistory = cleanOldNavigationHistory;
|
|
|
516
516
|
function parseNavigation(blocklet = {}, options = {}) {
|
|
517
517
|
const { beforeProcess = (v) => v } = options;
|
|
518
518
|
const { navigationList: builtinNavigation, components } = parseBlockletNavigationList(blocklet);
|
|
519
|
+
// 移除存在 db 中的默认导航
|
|
520
|
+
if (blocklet?.settings?.navigations) {
|
|
521
|
+
if (!Array.isArray(blocklet.settings.navigations)) {
|
|
522
|
+
blocklet.settings.navigations = [];
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
blocklet.settings.navigations = [...blocklet.settings.navigations].filter((item) => !(item?.parent === '/team' && item.from === 'tmpl'));
|
|
526
|
+
}
|
|
527
|
+
}
|
|
519
528
|
const customNavigationList = cleanOldNavigationHistory(blocklet?.settings?.navigations || []);
|
|
520
529
|
const compactedNavigation = compactNavigation(beforeProcess(builtinNavigation));
|
|
521
530
|
const patchedNavigation = patchBuiltinNavigation(compactedNavigation);
|
package/lib/util-meta.js
CHANGED
|
@@ -14,6 +14,7 @@ const did_1 = __importDefault(require("./did"));
|
|
|
14
14
|
const validate_1 = require("./validate");
|
|
15
15
|
// @ts-ignore
|
|
16
16
|
const package_json_1 = require("../package.json");
|
|
17
|
+
const with_cache_1 = __importDefault(require("./with-cache"));
|
|
17
18
|
const { BLOCKLET_STORE_API_BLOCKLET_PREFIX } = constant_1.default;
|
|
18
19
|
// HACK: copy from core/state/lib/util/request.js
|
|
19
20
|
const api = axios_1.default.create({
|
|
@@ -23,7 +24,7 @@ const api = axios_1.default.create({
|
|
|
23
24
|
'x-blocklet-server-version': package_json_1.version,
|
|
24
25
|
},
|
|
25
26
|
});
|
|
26
|
-
const validateUrl = async (url, expectedHttpResTypes = ['application/json', 'text/plain']) => {
|
|
27
|
+
const validateUrl = (0, with_cache_1.default)(async (url, expectedHttpResTypes = ['application/json', 'text/plain']) => {
|
|
27
28
|
const parsed = new URL(url);
|
|
28
29
|
const { protocol } = parsed;
|
|
29
30
|
// file
|
|
@@ -50,13 +51,13 @@ const validateUrl = async (url, expectedHttpResTypes = ['application/json', 'tex
|
|
|
50
51
|
return true;
|
|
51
52
|
}
|
|
52
53
|
throw new Error(`Invalid url protocol: ${protocol.replace(/:$/, '')}`);
|
|
53
|
-
};
|
|
54
|
+
}, { maxSize: 1000, maxAge: 1000 * 120 });
|
|
54
55
|
exports.validateUrl = validateUrl;
|
|
55
56
|
const validateBlockletMeta = (meta, opts = {}) => {
|
|
56
57
|
(0, validate_1.fixAndValidateService)(meta);
|
|
57
58
|
return (0, validate_1.validateMeta)(meta, opts);
|
|
58
59
|
};
|
|
59
|
-
const getBlockletMetaByUrl = async (url) => {
|
|
60
|
+
const getBlockletMetaByUrl = (0, with_cache_1.default)(async (url) => {
|
|
60
61
|
const { protocol } = new URL(url);
|
|
61
62
|
if (protocol.startsWith('file')) {
|
|
62
63
|
const decoded = decodeURIComponent((0, url_1.fileURLToPath)(url));
|
|
@@ -76,7 +77,7 @@ const getBlockletMetaByUrl = async (url) => {
|
|
|
76
77
|
return meta;
|
|
77
78
|
}
|
|
78
79
|
throw new Error(`Invalid url protocol: ${protocol.replace(/:$/, '')}`);
|
|
79
|
-
};
|
|
80
|
+
}, { maxSize: 1000, maxAge: 1000 * 30 });
|
|
80
81
|
exports.getBlockletMetaByUrl = getBlockletMetaByUrl;
|
|
81
82
|
const getBlockletMetaFromUrl = async (url, { validateFn = validateBlockletMeta, returnUrl = false, ensureTarball = true, logger, } = {}) => {
|
|
82
83
|
const meta = await getBlockletMetaByUrl(url);
|
package/lib/util.js
CHANGED
|
@@ -403,7 +403,20 @@ const wipeSensitiveData = (blocklet) => {
|
|
|
403
403
|
if (!blocklet) {
|
|
404
404
|
return blocklet;
|
|
405
405
|
}
|
|
406
|
-
|
|
406
|
+
// Only clone the fields that need to be modified
|
|
407
|
+
const clone = {
|
|
408
|
+
...blocklet,
|
|
409
|
+
configs: (blocklet.configs || []).map((x) => ({ ...x })),
|
|
410
|
+
environments: (blocklet.environments || []).map((x) => ({ ...x })),
|
|
411
|
+
migratedFrom: (blocklet.migratedFrom || []).map((x) => ({ ...x })),
|
|
412
|
+
settings: blocklet.settings ? { ...blocklet.settings, session: { ...blocklet.settings.session } } : undefined,
|
|
413
|
+
children: (blocklet.children || []).map((child) => ({
|
|
414
|
+
...child,
|
|
415
|
+
configs: (child.configs || []).map((x) => ({ ...x })),
|
|
416
|
+
environments: (child.environments || []).map((x) => ({ ...x })),
|
|
417
|
+
})),
|
|
418
|
+
};
|
|
419
|
+
forEachBlocklet(clone, (d) => {
|
|
407
420
|
if (d.configs) {
|
|
408
421
|
d.configs = d.configs.filter((x) => !isPreferenceKey(x));
|
|
409
422
|
d.configs.forEach((x) => {
|
|
@@ -421,13 +434,13 @@ const wipeSensitiveData = (blocklet) => {
|
|
|
421
434
|
x.appSk = '__encrypted__';
|
|
422
435
|
});
|
|
423
436
|
// @ts-ignore
|
|
424
|
-
delete
|
|
437
|
+
delete clone.configObj;
|
|
425
438
|
// @ts-ignore
|
|
426
|
-
delete
|
|
439
|
+
delete clone.environmentObj;
|
|
427
440
|
// @ts-ignore
|
|
428
|
-
delete
|
|
441
|
+
delete clone.settings?.session?.salt;
|
|
429
442
|
}, { sync: true });
|
|
430
|
-
return
|
|
443
|
+
return clone;
|
|
431
444
|
};
|
|
432
445
|
exports.wipeSensitiveData = wipeSensitiveData;
|
|
433
446
|
const isDeletableBlocklet = (blocklet) => {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const lru_cache_1 = require("lru-cache");
|
|
4
|
+
function withCache(fn, // The function to wrap
|
|
5
|
+
{ maxSize = 1000, maxAge = 1000 * 120 } = {}) {
|
|
6
|
+
if (maxAge === 0) {
|
|
7
|
+
return fn;
|
|
8
|
+
}
|
|
9
|
+
const cache = new lru_cache_1.LRUCache({ max: maxSize, ttl: maxAge });
|
|
10
|
+
return (async (...args) => {
|
|
11
|
+
const key = JSON.stringify({ v: args });
|
|
12
|
+
if (cache.has(key) && key.indexOf('file://') === -1) {
|
|
13
|
+
return cache.get(key);
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const result = await fn(...args);
|
|
17
|
+
cache.set(key, result);
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
console.error(`[Cache Wrapper] Error during function execution for key ${key}:`, error);
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.default = withCache;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.
|
|
6
|
+
"version": "1.16.42-beta-20250403-230303-c167c6a1",
|
|
7
7
|
"description": "Library to parse/validate/fix blocklet meta",
|
|
8
8
|
"main": "./lib/index.js",
|
|
9
9
|
"typings": "./lib/index.d.ts",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
"author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
|
|
26
26
|
"license": "Apache-2.0",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@abtnode/constant": "1.16.
|
|
29
|
-
"@abtnode/docker-utils": "1.16.
|
|
28
|
+
"@abtnode/constant": "1.16.42-beta-20250403-230303-c167c6a1",
|
|
29
|
+
"@abtnode/docker-utils": "1.16.42-beta-20250403-230303-c167c6a1",
|
|
30
30
|
"@arcblock/did": "1.19.15",
|
|
31
31
|
"@arcblock/did-ext": "1.19.15",
|
|
32
32
|
"@arcblock/did-util": "1.19.15",
|
|
33
33
|
"@arcblock/jwt": "1.19.15",
|
|
34
|
-
"@blocklet/constant": "1.16.
|
|
34
|
+
"@blocklet/constant": "1.16.42-beta-20250403-230303-c167c6a1",
|
|
35
35
|
"@ocap/asset": "1.19.15",
|
|
36
36
|
"@ocap/mcrypto": "1.19.15",
|
|
37
37
|
"@ocap/types": "1.19.15",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"js-yaml": "^4.1.0",
|
|
53
53
|
"json-stable-stringify": "^1.0.1",
|
|
54
54
|
"lodash": "^4.17.21",
|
|
55
|
+
"lru-cache": "^11.0.2",
|
|
55
56
|
"p-limit": "^3.1.0",
|
|
56
57
|
"promise.any": "^2.0.4",
|
|
57
58
|
"slugify": "^1.6.5",
|
|
@@ -80,5 +81,5 @@
|
|
|
80
81
|
"ts-node": "^10.9.1",
|
|
81
82
|
"typescript": "^5.6.3"
|
|
82
83
|
},
|
|
83
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "34d6d981bb270af1d0ca59704715bfa82949a9fe"
|
|
84
85
|
}
|