@blocklet/meta 1.16.41 → 1.16.42-beta-20250402-131159-7647e64d

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/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
- forEachBlocklet(blocklet, (d) => {
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 blocklet.configObj;
437
+ delete clone.configObj;
425
438
  // @ts-ignore
426
- delete blocklet.environmentObj;
439
+ delete clone.environmentObj;
427
440
  // @ts-ignore
428
- delete blocklet.settings?.session?.salt;
441
+ delete clone.settings?.session?.salt;
429
442
  }, { sync: true });
430
- return blocklet;
443
+ return clone;
431
444
  };
432
445
  exports.wipeSensitiveData = wipeSensitiveData;
433
446
  const isDeletableBlocklet = (blocklet) => {
@@ -0,0 +1,6 @@
1
+ declare function withCache<T>(fn: T, // The function to wrap
2
+ { maxSize, maxAge }?: {
3
+ maxSize?: number;
4
+ maxAge?: number;
5
+ }): T;
6
+ export default withCache;
@@ -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.41",
6
+ "version": "1.16.42-beta-20250402-131159-7647e64d",
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.41",
29
- "@abtnode/docker-utils": "1.16.41",
28
+ "@abtnode/constant": "1.16.42-beta-20250402-131159-7647e64d",
29
+ "@abtnode/docker-utils": "1.16.42-beta-20250402-131159-7647e64d",
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.41",
34
+ "@blocklet/constant": "1.16.42-beta-20250402-131159-7647e64d",
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": "54be9488459ae9a3544648d495e6204f9fad493a"
84
+ "gitHead": "f90e7dc430b14d99a8861d972967fb4b4c83c8ea"
84
85
  }