@blocklet/meta 1.16.24 → 1.16.25-beta-4f765cf3

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.
@@ -0,0 +1,16 @@
1
+ interface GetRequiredComponentsLayers {
2
+ targetDid: string;
3
+ children: {
4
+ meta: {
5
+ did: string;
6
+ };
7
+ dependencies: {
8
+ did: string;
9
+ required: boolean;
10
+ }[];
11
+ }[];
12
+ deep?: number;
13
+ filter?: (children: any) => boolean;
14
+ }
15
+ declare const getRequiredComponentsLayers: ({ targetDid, children, filter, deep }: GetRequiredComponentsLayers) => string[][];
16
+ export { getRequiredComponentsLayers };
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRequiredComponentsLayers = void 0;
4
+ function removeDuplicates(queue) {
5
+ const usedDid = new Set();
6
+ for (let i = 0; i < queue.length; i++) {
7
+ for (let j = 0; j < queue[i].length; j++) {
8
+ if (usedDid.has(queue[i][j])) {
9
+ queue[i].splice(j, 1);
10
+ j--;
11
+ }
12
+ else {
13
+ usedDid.add(queue[i][j]);
14
+ }
15
+ }
16
+ }
17
+ return queue;
18
+ }
19
+ // Get the dependency did matrix, the lowest-level dependent did is at the front, and each subsequent layer will be deduplicated
20
+ const getRequiredComponentsLayers = ({ targetDid, children, filter, deep = 9 }) => {
21
+ if (!children || !children.length) {
22
+ return [];
23
+ }
24
+ const usedDid = new Set();
25
+ const childrenMap = {};
26
+ children.forEach((child) => {
27
+ childrenMap[child.meta.did] = child;
28
+ });
29
+ const getRequiredDependents = (did) => {
30
+ if (usedDid.has(did)) {
31
+ return [];
32
+ }
33
+ usedDid.add(did);
34
+ const child = children.find((x) => x.meta.did === did);
35
+ const dependencies = child?.dependencies || [];
36
+ return dependencies
37
+ .filter((v) => {
38
+ if (!childrenMap[v.did] || !v.required) {
39
+ return false;
40
+ }
41
+ if (filter) {
42
+ return filter(childrenMap[v.did]);
43
+ }
44
+ return true;
45
+ })
46
+ .map((v) => v.did);
47
+ };
48
+ const requiredDependents = getRequiredDependents(targetDid);
49
+ const queue = [requiredDependents];
50
+ for (let i = 0; i < deep - 1; i++) {
51
+ const newDependents = [];
52
+ queue[0].forEach((did) => {
53
+ const dependents = getRequiredDependents(did);
54
+ newDependents.push(...dependents);
55
+ });
56
+ if (newDependents.length) {
57
+ queue.unshift(newDependents);
58
+ }
59
+ }
60
+ return removeDuplicates(queue).filter((v) => v.length);
61
+ };
62
+ exports.getRequiredComponentsLayers = getRequiredComponentsLayers;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.24",
6
+ "version": "1.16.25-beta-4f765cf3",
7
7
  "description": "Library to parse/validate/fix blocklet meta",
8
8
  "main": "./lib/index.js",
9
9
  "typings": "./lib/index.d.ts",
@@ -25,17 +25,17 @@
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.24",
29
- "@arcblock/did": "1.18.110",
30
- "@arcblock/did-ext": "1.18.110",
31
- "@arcblock/did-util": "1.18.110",
32
- "@arcblock/jwt": "1.18.110",
33
- "@blocklet/constant": "1.16.24",
34
- "@ocap/asset": "1.18.110",
35
- "@ocap/mcrypto": "1.18.110",
36
- "@ocap/types": "1.18.110",
37
- "@ocap/util": "1.18.110",
38
- "@ocap/wallet": "1.18.110",
28
+ "@abtnode/constant": "1.16.25-beta-4f765cf3",
29
+ "@arcblock/did": "1.18.113",
30
+ "@arcblock/did-ext": "1.18.113",
31
+ "@arcblock/did-util": "1.18.113",
32
+ "@arcblock/jwt": "1.18.113",
33
+ "@blocklet/constant": "1.16.25-beta-4f765cf3",
34
+ "@ocap/asset": "1.18.113",
35
+ "@ocap/mcrypto": "1.18.113",
36
+ "@ocap/types": "1.18.113",
37
+ "@ocap/util": "1.18.113",
38
+ "@ocap/wallet": "1.18.113",
39
39
  "ajv": "^8.11.0",
40
40
  "axios": "^0.27.2",
41
41
  "cjk-length": "^1.0.0",
@@ -79,5 +79,5 @@
79
79
  "ts-node": "^10.9.1",
80
80
  "typescript": "^5.0.4"
81
81
  },
82
- "gitHead": "6cd6669cb3569f96433e18b1dac346432741a1a7"
82
+ "gitHead": "7783a4bf883bb44b4266651b04008ef65bf6c2ce"
83
83
  }