@blocklet/resolver 1.16.23-beta-f85576a6 → 1.16.23-beta-aeb9f5bd

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.
Files changed (2) hide show
  1. package/index.js +72 -1
  2. package/package.json +8 -8
package/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.parseBlocklet = exports.parseComponents = exports.getComponentConfig = exports.validateBlockletMeta = exports.ensureMeta = exports.filterDuplicateComponents = exports.isDidMatchName = void 0;
6
+ exports.parseOptionalComponents = exports.filterRequiredComponents = exports.parseBlocklet = exports.parseComponents = exports.getComponentConfig = exports.validateBlockletMeta = exports.ensureMeta = exports.filterDuplicateComponents = exports.isDidMatchName = void 0;
7
7
  /* eslint-disable prettier/prettier */
8
8
  /* eslint-disable no-await-in-loop */
9
9
  const semver_1 = __importDefault(require("semver"));
@@ -177,3 +177,74 @@ const parseBlocklet = async (url) => {
177
177
  return dynamicComponents;
178
178
  };
179
179
  exports.parseBlocklet = parseBlocklet;
180
+ const filterRequiredComponents = (component, children) => {
181
+ const requiredNames = new Set(component.meta?.components?.filter((v) => v.required).map((v) => v.name) || []);
182
+ requiredNames.add(component.meta.name);
183
+ const requiredChildren = children.filter((child) => requiredNames.has(child.meta.name));
184
+ return requiredChildren;
185
+ };
186
+ exports.filterRequiredComponents = filterRequiredComponents;
187
+ const parseOptionalComponents = async (children) => {
188
+ if (!children || !children.length) {
189
+ return [];
190
+ }
191
+ const optionalComponents = [];
192
+ const childrenNames = new Set(children.map((v) => v.meta.name));
193
+ const hasOptionalChildren = new Set();
194
+ const optionalNames = new Set();
195
+ const appendNames = new Set();
196
+ const dependenciesMap = {};
197
+ children.forEach((child) => {
198
+ child.meta.components?.forEach((component) => {
199
+ if (!childrenNames.has(component.name)) {
200
+ hasOptionalChildren.add(child.meta.did);
201
+ optionalNames.add(component.name);
202
+ if (!dependenciesMap[component.name]) {
203
+ dependenciesMap[component.name] = [];
204
+ }
205
+ dependenciesMap[component.name].push({
206
+ parentDid: child.meta.did,
207
+ parentName: child.meta.name,
208
+ parentTitle: child.meta.title,
209
+ required: !!component.required,
210
+ mountPoint: !!component.mountPoint,
211
+ });
212
+ }
213
+ });
214
+ });
215
+ for (const child of children) {
216
+ if (!child.meta || !hasOptionalChildren.has(child.meta.did)) {
217
+ // eslint-disable-next-line no-continue
218
+ continue;
219
+ }
220
+ const hasNotFetchChild = child.meta.components.find((component) => !childrenNames.has(component.name) && !appendNames.has(component.name));
221
+ if (!hasNotFetchChild) {
222
+ // eslint-disable-next-line no-continue
223
+ continue;
224
+ }
225
+ try {
226
+ const { dynamicComponents } = await (0, exports.parseComponents)(child);
227
+ for (const component of dynamicComponents) {
228
+ const { mountPoint, bundleSource, meta } = component;
229
+ if (!optionalNames.has(meta.name) || appendNames.has(meta.name)) {
230
+ // eslint-disable-next-line no-continue
231
+ continue;
232
+ }
233
+ const optionalChild = {
234
+ logoUrl: `${bundleSource.store}/assets/${meta.did}/logo.png?v=${meta.version}`,
235
+ dependencies: dependenciesMap[meta.name] || [],
236
+ mountPoint,
237
+ bundleSource,
238
+ meta,
239
+ };
240
+ appendNames.add(meta.name);
241
+ optionalComponents.push(optionalChild);
242
+ }
243
+ }
244
+ catch (err) {
245
+ throw new Error(`Can not parse optional child: ${child.meta.name}`);
246
+ }
247
+ }
248
+ return optionalComponents;
249
+ };
250
+ exports.parseOptionalComponents = parseOptionalComponents;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.23-beta-f85576a6",
6
+ "version": "1.16.23-beta-aeb9f5bd",
7
7
  "description": "Blocklet meta resolver",
8
8
  "main": "index.js",
9
9
  "files": [
@@ -21,22 +21,22 @@
21
21
  "license": "Apache-2.0",
22
22
  "dependencies": {
23
23
  "@arcblock/did": "^1.18.108",
24
- "@blocklet/constant": "1.16.23-beta-f85576a6",
25
- "@blocklet/meta": "1.16.23-beta-f85576a6",
24
+ "@blocklet/constant": "1.16.23-beta-aeb9f5bd",
25
+ "@blocklet/meta": "1.16.23-beta-aeb9f5bd",
26
26
  "semver": "^7.3.8"
27
27
  },
28
28
  "devDependencies": {
29
- "@abtnode/types": "1.16.23-beta-f85576a6",
29
+ "@abtnode/types": "1.16.23-beta-aeb9f5bd",
30
30
  "@arcblock/eslint-config-ts": "^0.2.4",
31
- "@types/jest": "^29.2.0",
31
+ "@types/jest": "^29.5.11",
32
32
  "@types/node": "^18.11.0",
33
33
  "@typescript-eslint/eslint-plugin": "^5.40.1",
34
34
  "@typescript-eslint/parser": "^5.40.1",
35
35
  "eslint": "^8.25.0",
36
- "jest": "^27.5.1",
36
+ "jest": "^29.7.0",
37
37
  "prettier": "^2.7.1",
38
- "ts-jest": "^27.1.5",
38
+ "ts-jest": "^29.1.1",
39
39
  "typescript": "^5.0.4"
40
40
  },
41
- "gitHead": "bac83a74944b4cef3ccb386277023caf0e1d5cd4"
41
+ "gitHead": "418cacd970d373aecc8706f8992e57369d394577"
42
42
  }