@abtnode/core 1.16.12 → 1.16.13-beta-118c3420

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.
@@ -539,7 +539,7 @@ class BlockletManager extends BaseBlockletManager {
539
539
  entity: 'blocklet',
540
540
  action: 'check_if_started',
541
541
  ...params,
542
- id: did,
542
+ id: `${did}/${(componentDids || []).join(',')}`,
543
543
  });
544
544
  }
545
545
 
@@ -701,7 +701,7 @@ class BlockletManager extends BaseBlockletManager {
701
701
  const ticket = this.startQueue.push({
702
702
  entity: 'blocklet',
703
703
  action: 'restart',
704
- id: did,
704
+ id: `${did}/${(componentDids || []).join(',')}`,
705
705
  did,
706
706
  componentDids,
707
707
  context,
@@ -153,6 +153,7 @@ class BlockletState extends BaseState {
153
153
  this.defaultPort = config.blockletPort || 5555;
154
154
  // @didMap: { [did: string]: metaDid: string }
155
155
  this.didMap = new Map();
156
+ this.statusLocks = new Map();
156
157
  }
157
158
 
158
159
  async getBlocklet(did, { decryptSk = true } = {}) {
@@ -207,6 +208,8 @@ class BlockletState extends BaseState {
207
208
 
208
209
  this.didMap.delete(doc.meta?.did);
209
210
  this.didMap.delete(doc.appDid);
211
+ this.statusLocks.delete(doc.meta?.did);
212
+ this.statusLocks.delete(doc.appDid);
210
213
 
211
214
  this.emit('remove', doc);
212
215
  return formatBlocklet(doc, 'onRead', this.config.dek);
@@ -505,39 +508,49 @@ class BlockletState extends BaseState {
505
508
  throw new Error('Unsupported blocklet status');
506
509
  }
507
510
 
508
- const doc = await this.getBlocklet(did);
509
-
510
- if (doc.meta?.group === BlockletGroup.gateway && !doc.children?.length) {
511
- return this.updateBlocklet(did, { status });
512
- }
511
+ const statusLock = this._getStatusLock(did);
513
512
 
514
- // for backward compatibility
515
- if (!doc.structVersion && !doc.children?.length) {
516
- return this.updateBlocklet(did, { status });
517
- }
513
+ try {
514
+ await statusLock.acquire();
515
+ const doc = await this.getBlocklet(did);
518
516
 
519
- // update children status
520
- forEachComponentV2Sync(doc, (component) => {
521
- if (component.meta.group === BlockletGroup.gateway) {
522
- return;
517
+ if (doc.meta?.group === BlockletGroup.gateway && !doc.children?.length) {
518
+ return this.updateBlocklet(did, { status });
523
519
  }
524
520
 
525
- if (shouldSkipComponent(component.meta.did, componentDids)) {
526
- return;
521
+ // for backward compatibility
522
+ if (!doc.structVersion && !doc.children?.length) {
523
+ return this.updateBlocklet(did, { status });
527
524
  }
528
525
 
529
- component.status = status;
530
- if (status === BlockletStatus.running) {
531
- component.startedAt = new Date();
532
- component.stoppedAt = null;
533
- }
534
- if (status === BlockletStatus.stopped) {
535
- component.startedAt = null;
536
- component.stoppedAt = new Date();
537
- }
538
- });
526
+ // update children status
527
+ forEachComponentV2Sync(doc, (component) => {
528
+ if (component.meta.group === BlockletGroup.gateway) {
529
+ return;
530
+ }
539
531
 
540
- return this.updateBlocklet(did, pick(doc, ['status', 'children']));
532
+ if (shouldSkipComponent(component.meta.did, componentDids)) {
533
+ return;
534
+ }
535
+
536
+ component.status = status;
537
+ if (status === BlockletStatus.running) {
538
+ component.startedAt = new Date();
539
+ component.stoppedAt = null;
540
+ }
541
+ if (status === BlockletStatus.stopped) {
542
+ component.startedAt = null;
543
+ component.stoppedAt = new Date();
544
+ }
545
+ });
546
+
547
+ const res = await this.updateBlocklet(did, pick(doc, ['status', 'children']));
548
+ statusLock.release();
549
+ return res;
550
+ } catch (error) {
551
+ statusLock.release();
552
+ throw error;
553
+ }
541
554
  }
542
555
 
543
556
  setInstalledAt(did) {
@@ -641,6 +654,14 @@ class BlockletState extends BaseState {
641
654
  updateStructV1Did(did, v1Did) {
642
655
  return this.updateBlocklet(did, { structV1Did: v1Did });
643
656
  }
657
+
658
+ _getStatusLock(did) {
659
+ if (!this.statusLocks.has(did)) {
660
+ this.statusLocks[did] = new Lock();
661
+ }
662
+
663
+ return this.statusLocks[did];
664
+ }
644
665
  }
645
666
 
646
667
  BlockletState.BlockletStatus = BlockletStatus;
@@ -41,6 +41,13 @@ const {
41
41
  APP_STRUCT_VERSION,
42
42
  EXPIRED_BLOCKLET_DATA_RETENTION_DAYS,
43
43
  } = require('@abtnode/constant');
44
+ const {
45
+ parseComponents,
46
+ ensureMeta,
47
+ filterDuplicateComponents,
48
+ validateBlockletMeta,
49
+ getComponentConfig,
50
+ } = require('@blocklet/resolver');
44
51
  const formatBackSlash = require('@abtnode/util/lib/format-back-slash');
45
52
  const { toSvg: createDidLogo } =
46
53
  process.env.NODE_ENV !== 'test' ? require('@arcblock/did-motif') : require('@arcblock/did-motif/dist/did-motif.cjs');
@@ -67,7 +74,6 @@ const validateBlockletEntry = require('@blocklet/meta/lib/entry');
67
74
  const getBlockletEngine = require('@blocklet/meta/lib/engine');
68
75
  const getBlockletInfo = require('@blocklet/meta/lib/info');
69
76
  const getBlockletWallet = require('@blocklet/meta/lib/wallet');
70
- const { validateMeta, fixAndValidateService } = require('@blocklet/meta/lib/validate');
71
77
  const {
72
78
  forEachBlocklet,
73
79
  getDisplayName,
@@ -75,7 +81,6 @@ const {
75
81
  forEachBlockletSync,
76
82
  forEachChildSync,
77
83
  forEachComponentV2Sync,
78
- isComponentBlocklet,
79
84
  getSharedConfigObj,
80
85
  getComponentName,
81
86
  isEnvShareable,
@@ -85,13 +90,8 @@ const {
85
90
  isInProgress,
86
91
  isRunning,
87
92
  } = require('@blocklet/meta/lib/util');
88
- const toBlockletDid = require('@blocklet/meta/lib/did');
89
93
  const { titleSchema, descriptionSchema, logoSchema } = require('@blocklet/meta/lib/schema');
90
- const {
91
- getSourceUrlsFromConfig,
92
- getBlockletMetaFromUrls,
93
- getBlockletMetaFromUrl,
94
- } = require('@blocklet/meta/lib/util-meta');
94
+ const { getBlockletMetaFromUrl } = require('@blocklet/meta/lib/util-meta');
95
95
  const getComponentProcessId = require('@blocklet/meta/lib/get-component-process-id');
96
96
 
97
97
  const { validate: validateEngine, get: getEngine } = require('../blocklet/manager/engine');
@@ -103,12 +103,6 @@ const externalIpUtil = require('./get-accessible-external-node-ip');
103
103
  const { getIpDnsDomainForBlocklet } = require('./get-domain-for-blocklet');
104
104
  const { replaceDomainSlot } = require('./index');
105
105
 
106
- const getComponentConfig = (meta) => {
107
- const components = meta.components || meta.children || [];
108
- const staticComponents = (meta.staticComponents || []).map((x) => ({ ...x, static: true }));
109
- return [...components, ...staticComponents];
110
- };
111
-
112
106
  /**
113
107
  * get blocklet engine info, default is node
114
108
  * @param {object} blockletMeta blocklet meta
@@ -736,128 +730,6 @@ const reloadProcess = (processId) =>
736
730
  });
737
731
  });
738
732
 
739
- /**
740
- * this function has side effect to component (will set component.children: Array<staticComponent> )
741
- * this function has side effect to dynamicComponents (will push dynamicComponent in dynamicComponents)
742
- *
743
- * @param {Component} component
744
- * @param {{
745
- * ancestors: Array<{meta}>
746
- * dynamicComponents: Array<{Component}>
747
- * }} context
748
- * @returns {{
749
- * dynamicComponents: Array<Component>,
750
- * staticComponents: Array<Component>,
751
- * }}
752
- */
753
- const parseComponents = async (component, context = {}) => {
754
- const { ancestors = [], dynamicComponents = [] } = context;
755
- if (ancestors.length > 40) {
756
- throw new Error('The depth of component should not exceed 40');
757
- }
758
-
759
- const configs = getComponentConfig(component.meta) || [];
760
-
761
- if (!configs || !configs.length) {
762
- return {
763
- staticComponents: [],
764
- dynamicComponents,
765
- };
766
- }
767
-
768
- const staticComponents = [];
769
-
770
- // FIXME @linchen 改成并行获取
771
- for (const config of configs) {
772
- const isStatic = !!config.static;
773
-
774
- if (isStatic) {
775
- if (!config.name) {
776
- throw new Error(`Name does not found in child ${config.name}`);
777
- }
778
-
779
- if (!config.mountPoint) {
780
- throw new Error(`MountPoint does not found in child ${config.name}`);
781
- }
782
- }
783
-
784
- const urls = getSourceUrlsFromConfig(config);
785
-
786
- let rawMeta;
787
- try {
788
- rawMeta = await getBlockletMetaFromUrls(urls, { logger });
789
- } catch (error) {
790
- throw new Error(`Failed get component meta. Component: ${urls.join(', ')}, reason: ${error.message}`);
791
- }
792
-
793
- if (rawMeta.group === BlockletGroup.gateway) {
794
- throw new Error(`Cannot add gateway component ${rawMeta.title || rawMeta.did}`);
795
- }
796
-
797
- validateBlockletMeta(rawMeta, { ensureDist: true });
798
-
799
- if (!isComponentBlocklet(rawMeta)) {
800
- throw new Error(
801
- `The blocklet cannot be a component: ${rawMeta.title}. The reason may be that the developer set capabilities.component to false in blocklet.yml`
802
- );
803
- }
804
-
805
- const webInterface = findWebInterface(rawMeta);
806
- if (!webInterface) {
807
- throw new Error(`Web interface does not found in component ${rawMeta.title || rawMeta.name}`);
808
- }
809
-
810
- const meta = ensureMeta(rawMeta, { name: isStatic ? config.name : null });
811
-
812
- // check circular dependencies
813
- if (ancestors.map((x) => x.meta?.bundleDid).indexOf(meta.bundleDid) > -1) {
814
- throw new Error('Blocklet components have circular dependencies');
815
- }
816
-
817
- if (config.title) {
818
- meta.title = config.title;
819
- meta.title = await titleSchema.validateAsync(config.title);
820
- }
821
-
822
- if (config.description) {
823
- meta.description = await descriptionSchema.validateAsync(config.description);
824
- }
825
-
826
- const mountPoint = isStatic ? config.mountPoint : config.mountPoint || `/${meta.did}`;
827
-
828
- const child = {
829
- mountPoint,
830
- meta,
831
- bundleSource: config.source,
832
- dependencies: [],
833
- };
834
-
835
- if (isStatic) {
836
- staticComponents.push(child);
837
- } else {
838
- dynamicComponents.push(child);
839
- component.dependencies = component.dependencies || [];
840
- component.dependencies.push({
841
- did: child.meta.bundleDid,
842
- required: !!config.required,
843
- version: config.source.version || 'latest',
844
- });
845
- }
846
-
847
- await parseComponents(child, {
848
- ancestors: [...ancestors, { meta }],
849
- dynamicComponents,
850
- });
851
- }
852
-
853
- component.children = staticComponents;
854
-
855
- return {
856
- staticComponents,
857
- dynamicComponents,
858
- };
859
- };
860
-
861
733
  const validateBlocklet = (blocklet) =>
862
734
  forEachBlocklet(blocklet, (b) => {
863
735
  isRequirementsSatisfied(b.meta.requirements);
@@ -1327,45 +1199,6 @@ const needBlockletDownload = (blocklet, oldBlocklet) => {
1327
1199
  return get(oldBlocklet, 'meta.dist.integrity') !== get(blocklet, 'meta.dist.integrity');
1328
1200
  };
1329
1201
 
1330
- const isDidMatchName = (did, name) => {
1331
- if (isValidDid(did) && name === did) {
1332
- return true;
1333
- }
1334
-
1335
- return toBlockletDid(name) === did;
1336
- };
1337
-
1338
- /**
1339
- * set bundleDid and bundleMeta in meta
1340
- * update name and did to server index
1341
- * in app structure 2.0, application's bundleDid, bundleName, meta, did will be same
1342
- */
1343
- const ensureMeta = (meta, { name, did } = {}) => {
1344
- if (name && did && !isDidMatchName(did, name)) {
1345
- throw new Error(`name does not match with did: ${name}, ${did}`);
1346
- }
1347
-
1348
- const newMeta = {
1349
- ...meta,
1350
- };
1351
-
1352
- if (!newMeta.did || !newMeta.name || !isDidMatchName(newMeta.did, newMeta.name)) {
1353
- throw new Error(`name does not match with did in meta: ${newMeta.name}, ${newMeta.did}`);
1354
- }
1355
-
1356
- if (!meta.bundleDid) {
1357
- newMeta.bundleDid = meta.did;
1358
- newMeta.bundleName = meta.name;
1359
- }
1360
-
1361
- if (name) {
1362
- newMeta.name = name;
1363
- newMeta.did = did || toBlockletDid(name);
1364
- }
1365
-
1366
- return newMeta;
1367
- };
1368
-
1369
1202
  const getBlocklet = async ({
1370
1203
  did,
1371
1204
  dataDirs,
@@ -1784,36 +1617,6 @@ const checkVersionCompatibility = (components) => {
1784
1617
  }
1785
1618
  };
1786
1619
 
1787
- const filterDuplicateComponents = (components = [], currents = []) => {
1788
- const arr = [];
1789
-
1790
- components.forEach((component) => {
1791
- if (currents.some((x) => x.meta.did === component.meta.did)) {
1792
- return;
1793
- }
1794
-
1795
- const index = arr.findIndex((x) => x.meta.did === component.meta.did);
1796
- if (index > -1) {
1797
- const exist = arr[index];
1798
-
1799
- // 选择最小版本:
1800
- // 如果 com1 和 com2 都依赖某个 component, com1 声明依赖版本 1.0.0, 实际获取版本 1.0.0; com2 声明依赖版本 latest(不限), 实际获取版本 2.0.0 -> 则应该取 1.0.0
1801
- if (semver.lt(component.meta.version, exist.meta.version)) {
1802
- arr.splice(index, 1, component);
1803
- }
1804
- } else {
1805
- arr.push(component);
1806
- }
1807
- });
1808
-
1809
- return arr;
1810
- };
1811
-
1812
- const validateBlockletMeta = (meta, opts = {}) => {
1813
- fixAndValidateService(meta);
1814
- return validateMeta(meta, { ensureName: true, skipValidateDidName: true, schemaOptions: { ...opts } });
1815
- };
1816
-
1817
1620
  const getBlockletKnownAs = (blocklet) => {
1818
1621
  const alsoKnownAs = [blocklet.appDid];
1819
1622
  if (Array.isArray(blocklet.migratedFrom)) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.12",
6
+ "version": "1.16.13-beta-118c3420",
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.12",
23
- "@abtnode/certificate-manager": "1.16.12",
24
- "@abtnode/constant": "1.16.12",
25
- "@abtnode/cron": "1.16.12",
26
- "@abtnode/logger": "1.16.12",
27
- "@abtnode/models": "1.16.12",
28
- "@abtnode/queue": "1.16.12",
29
- "@abtnode/rbac": "1.16.12",
30
- "@abtnode/router-provider": "1.16.12",
31
- "@abtnode/static-server": "1.16.12",
32
- "@abtnode/timemachine": "1.16.12",
33
- "@abtnode/util": "1.16.12",
22
+ "@abtnode/auth": "1.16.13-beta-118c3420",
23
+ "@abtnode/certificate-manager": "1.16.13-beta-118c3420",
24
+ "@abtnode/constant": "1.16.13-beta-118c3420",
25
+ "@abtnode/cron": "1.16.13-beta-118c3420",
26
+ "@abtnode/logger": "1.16.13-beta-118c3420",
27
+ "@abtnode/models": "1.16.13-beta-118c3420",
28
+ "@abtnode/queue": "1.16.13-beta-118c3420",
29
+ "@abtnode/rbac": "1.16.13-beta-118c3420",
30
+ "@abtnode/router-provider": "1.16.13-beta-118c3420",
31
+ "@abtnode/static-server": "1.16.13-beta-118c3420",
32
+ "@abtnode/timemachine": "1.16.13-beta-118c3420",
33
+ "@abtnode/util": "1.16.13-beta-118c3420",
34
34
  "@arcblock/did": "1.18.84",
35
35
  "@arcblock/did-auth": "1.18.84",
36
36
  "@arcblock/did-ext": "^1.18.84",
@@ -41,9 +41,10 @@
41
41
  "@arcblock/pm2-events": "^0.0.5",
42
42
  "@arcblock/validator": "^1.18.84",
43
43
  "@arcblock/vc": "1.18.84",
44
- "@blocklet/constant": "1.16.12",
45
- "@blocklet/meta": "1.16.12",
46
- "@blocklet/sdk": "1.16.12",
44
+ "@blocklet/constant": "1.16.13-beta-118c3420",
45
+ "@blocklet/meta": "1.16.13-beta-118c3420",
46
+ "@blocklet/resolver": "1.16.13-beta-118c3420",
47
+ "@blocklet/sdk": "1.16.13-beta-118c3420",
47
48
  "@did-space/client": "^0.2.117",
48
49
  "@fidm/x509": "^1.2.1",
49
50
  "@ocap/mcrypto": "1.18.84",
@@ -96,5 +97,5 @@
96
97
  "express": "^4.18.2",
97
98
  "jest": "^27.5.1"
98
99
  },
99
- "gitHead": "f91a92c7621b0defbdb6b119ac657d712b1ca5bc"
100
+ "gitHead": "93e00311f882c8c153a1c6c3d18aa29c154f08f6"
100
101
  }