@abtnode/core 1.16.11-next-73f5f388 → 1.16.11-next-49394ba1

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.
@@ -134,7 +134,7 @@ class BlockletDownloader extends EventEmitter {
134
134
 
135
135
  const { preDownload = () => {}, postDownload = () => {}, skipCheckIntegrity, onProgress = () => {} } = options;
136
136
 
137
- const { downloadComponentIds, downloadList } = await this.getDownloadList({
137
+ const { downloadComponentIds, downloadList, skipList } = await this.getDownloadList({
138
138
  blocklet,
139
139
  skipCheckIntegrity,
140
140
  });
@@ -142,24 +142,35 @@ class BlockletDownloader extends EventEmitter {
142
142
  await preDownload({ downloadList, downloadComponentIds });
143
143
 
144
144
  try {
145
+ // Fake progress events for cached bundles
146
+ skipList.forEach((meta) => {
147
+ const info = pick(meta, ['title', 'name', 'did', 'version']);
148
+ onProgress({ status: 'downloading', component: info });
149
+ setTimeout(
150
+ () => {
151
+ onProgress({ status: 'completed', component: info });
152
+ },
153
+ process.env.NODE_ENV === 'test' ? 0 : Math.random() * 800
154
+ );
155
+ });
156
+
145
157
  this.logger.info('Start Download Blocklet', {
146
158
  name,
147
159
  did,
148
160
  bundles: downloadList.map((x) => get(x, 'dist.tarball')),
149
161
  });
150
- const tasks = [];
151
- for (const meta of downloadList) {
152
- const url = meta.dist.tarball;
153
- tasks.push(
154
- this.bundleDownloader.download(meta, did, url, {
162
+
163
+ const results = await Promise.all(
164
+ downloadList.map(async (meta) => {
165
+ const url = meta.dist.tarball;
166
+ return this.bundleDownloader.download(meta, did, url, {
155
167
  ...options,
156
168
  onProgress: (data) => {
157
169
  onProgress({ ...data, component: pick(meta, ['title', 'name', 'did', 'version']) });
158
170
  },
159
- })
160
- );
161
- }
162
- const results = await Promise.all(tasks);
171
+ });
172
+ })
173
+ );
163
174
 
164
175
  const isCancelled = results.some((x) => x.isCancelled);
165
176
 
@@ -187,19 +198,21 @@ class BlockletDownloader extends EventEmitter {
187
198
  * }}
188
199
  * @returns {{
189
200
  * downloadList: Array<import('@abtnode/client').BlockletMeta>;
201
+ * skipList: Array<import('@abtnode/client').BlockletMeta>;
190
202
  * downloadComponentIds: Array<string>; // like: "z8ia1i2yq67x39vruqQTbkVcwCnqRGx8zSPsJ/z8iZwubkNdA1BfEUwc5NJpY2Jnfm7yEbyvmKS"
191
203
  * }}
192
204
  */
193
205
  async getDownloadList({ blocklet, skipCheckIntegrity }) {
194
206
  const downloadComponentIds = [];
195
- const metas = {};
207
+ const scheduled = {};
208
+ const skipped = {};
196
209
 
197
210
  const cachedBundles = (await this.cache.get(CACHE_KEY)) || [];
198
211
 
199
212
  forEachComponentV2Sync(blocklet, (component) => {
200
213
  const bundleId = getComponentBundleId(component);
201
214
 
202
- if (metas[bundleId]) {
215
+ if (scheduled[bundleId]) {
203
216
  this.logger.info(`skip download duplicate bundle ${bundleId}`);
204
217
  return;
205
218
  }
@@ -210,6 +223,7 @@ class BlockletDownloader extends EventEmitter {
210
223
  skipCheckIntegrity,
211
224
  });
212
225
  if (!needComponentDownload) {
226
+ skipped[bundleId] = component.meta;
213
227
  this.logger.info(`skip download existed bundle ${bundleId}`, { source: component.source });
214
228
  return;
215
229
  }
@@ -222,13 +236,14 @@ class BlockletDownloader extends EventEmitter {
222
236
  return;
223
237
  }
224
238
 
225
- metas[bundleId] = component.meta;
239
+ scheduled[bundleId] = component.meta;
226
240
  downloadComponentIds.push(component.meta.did);
227
241
  });
228
242
 
229
- const downloadList = Object.values(metas);
243
+ const downloadList = Object.values(scheduled);
244
+ const skipList = Object.values(skipped);
230
245
 
231
- return { downloadList, downloadComponentIds };
246
+ return { downloadList, skipList, downloadComponentIds };
232
247
  }
233
248
  }
234
249
 
@@ -1437,6 +1437,16 @@ class BlockletManager extends BaseBlockletManager {
1437
1437
  return blocklet;
1438
1438
  }
1439
1439
 
1440
+ // {Record<BlockletStatus, Array<Did>>}
1441
+ const updates = new Map();
1442
+ const addToUpdates = (componentDid, status) => {
1443
+ if (updates.has(status)) {
1444
+ updates.get(status).push(componentDid);
1445
+ } else {
1446
+ updates.set(status, [componentDid]);
1447
+ }
1448
+ };
1449
+
1440
1450
  await forEachComponentV2(
1441
1451
  blocklet,
1442
1452
  async (component) => {
@@ -1452,7 +1462,7 @@ class BlockletManager extends BaseBlockletManager {
1452
1462
  const status = await getProcessState(component.env.processId);
1453
1463
  if (component.status !== status) {
1454
1464
  component.status = status;
1455
- await states.blocklet.setBlockletStatus(did, status, { componentDids: [component.meta.did] });
1465
+ addToUpdates(component.meta.did, status);
1456
1466
  }
1457
1467
  } catch {
1458
1468
  if (
@@ -1467,13 +1477,20 @@ class BlockletManager extends BaseBlockletManager {
1467
1477
  ) {
1468
1478
  const status = BlockletStatus.stopped;
1469
1479
  component.status = status;
1470
- await states.blocklet.setBlockletStatus(did, status, { componentDids: [component.meta.did] });
1480
+ addToUpdates(component.meta.did, status);
1471
1481
  }
1472
1482
  }
1473
1483
  },
1474
1484
  { parallel: true }
1475
1485
  );
1476
1486
 
1487
+ // iterate updates
1488
+ if (updates.size > 0) {
1489
+ for (const [status, dids] of updates) {
1490
+ await states.blocklet.setBlockletStatus(did, status, { componentDids: dids });
1491
+ }
1492
+ }
1493
+
1477
1494
  blocklet.status = getBlockletStatus(blocklet);
1478
1495
 
1479
1496
  return blocklet;
@@ -138,7 +138,7 @@ const setupAppOwner = async (node, sessionId) => {
138
138
  userDid: ownerDid,
139
139
  teamDid: appDid,
140
140
  }),
141
- ownerProfile: { ...appOwnerProfile, avatar: parseUserAvatar(user.avatar, { dataDir: serverDataDir }) },
141
+ ownerProfile: { ...appOwnerProfile, avatar: await parseUserAvatar(user.avatar, { dataDir: serverDataDir }) },
142
142
  preferredColor: 'default',
143
143
  expirationDate: undefined,
144
144
  });
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.11-next-73f5f388",
6
+ "version": "1.16.11-next-49394ba1",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,18 +19,18 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "Apache-2.0",
21
21
  "dependencies": {
22
- "@abtnode/auth": "1.16.11-next-73f5f388",
23
- "@abtnode/certificate-manager": "1.16.11-next-73f5f388",
24
- "@abtnode/constant": "1.16.11-next-73f5f388",
25
- "@abtnode/cron": "1.16.11-next-73f5f388",
26
- "@abtnode/logger": "1.16.11-next-73f5f388",
27
- "@abtnode/models": "1.16.11-next-73f5f388",
28
- "@abtnode/queue": "1.16.11-next-73f5f388",
29
- "@abtnode/rbac": "1.16.11-next-73f5f388",
30
- "@abtnode/router-provider": "1.16.11-next-73f5f388",
31
- "@abtnode/static-server": "1.16.11-next-73f5f388",
32
- "@abtnode/timemachine": "1.16.11-next-73f5f388",
33
- "@abtnode/util": "1.16.11-next-73f5f388",
22
+ "@abtnode/auth": "1.16.11-next-49394ba1",
23
+ "@abtnode/certificate-manager": "1.16.11-next-49394ba1",
24
+ "@abtnode/constant": "1.16.11-next-49394ba1",
25
+ "@abtnode/cron": "1.16.11-next-49394ba1",
26
+ "@abtnode/logger": "1.16.11-next-49394ba1",
27
+ "@abtnode/models": "1.16.11-next-49394ba1",
28
+ "@abtnode/queue": "1.16.11-next-49394ba1",
29
+ "@abtnode/rbac": "1.16.11-next-49394ba1",
30
+ "@abtnode/router-provider": "1.16.11-next-49394ba1",
31
+ "@abtnode/static-server": "1.16.11-next-49394ba1",
32
+ "@abtnode/timemachine": "1.16.11-next-49394ba1",
33
+ "@abtnode/util": "1.16.11-next-49394ba1",
34
34
  "@arcblock/did": "1.18.80",
35
35
  "@arcblock/did-auth": "1.18.80",
36
36
  "@arcblock/did-ext": "^1.18.80",
@@ -41,9 +41,9 @@
41
41
  "@arcblock/pm2-events": "^0.0.5",
42
42
  "@arcblock/validator": "^1.18.80",
43
43
  "@arcblock/vc": "1.18.80",
44
- "@blocklet/constant": "1.16.11-next-73f5f388",
45
- "@blocklet/meta": "1.16.11-next-73f5f388",
46
- "@blocklet/sdk": "1.16.11-next-73f5f388",
44
+ "@blocklet/constant": "1.16.11-next-49394ba1",
45
+ "@blocklet/meta": "1.16.11-next-49394ba1",
46
+ "@blocklet/sdk": "1.16.11-next-49394ba1",
47
47
  "@did-space/client": "^0.2.113",
48
48
  "@fidm/x509": "^1.2.1",
49
49
  "@ocap/mcrypto": "1.18.80",
@@ -96,5 +96,5 @@
96
96
  "express": "^4.18.2",
97
97
  "jest": "^27.5.1"
98
98
  },
99
- "gitHead": "0f77a5958181b871bc285eeeda1eade9a5c1f231"
99
+ "gitHead": "bff5782698d3fdce6a5f1a3af144c809d283020d"
100
100
  }