@blocklet/meta 1.16.11-next-a232f5fb → 1.16.11-next-09bc31f8

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 (3) hide show
  1. package/lib/util.d.ts +54 -25
  2. package/lib/util.js +112 -1
  3. package/package.json +5 -5
package/lib/util.d.ts CHANGED
@@ -4,8 +4,9 @@ import type { TBlockletMeta, TEnvironment } from './types';
4
4
  type TConfig = TEnvironment & {
5
5
  key: string;
6
6
  };
7
- type Component = BlockletState | ComponentState;
8
- type ComponentPro = Component & {
7
+ type TApp = BlockletState;
8
+ type TComponent = BlockletState | ComponentState;
9
+ type TComponentPro = TComponent & {
9
10
  configObj?: Record<string, string>;
10
11
  environmentObj?: Record<string, string>;
11
12
  };
@@ -44,7 +45,7 @@ declare const getComponentBundleId: (component: {
44
45
  * @a/b/@c/d/@e/f => @a/b/@c/d
45
46
  */
46
47
  declare const getParentComponentName: (name?: string) => string;
47
- declare const forEachBlocklet: (blocklet: ComponentPro, cb: Function, { parallel, concurrencyLimit, sync, params: inputParams, _parent, _root, _level, _tasks: inputTasks, _ancestors, _limit, }?: {
48
+ declare const forEachBlocklet: (blocklet: TComponentPro, cb: Function, { parallel, concurrencyLimit, sync, params: inputParams, _parent, _root, _level, _tasks: inputTasks, _ancestors, _limit, }?: {
48
49
  parallel?: boolean;
49
50
  concurrencyLimit?: number;
50
51
  sync?: boolean;
@@ -57,23 +58,32 @@ declare const forEachBlocklet: (blocklet: ComponentPro, cb: Function, { parallel
57
58
  _limit?: (fn: () => void) => void;
58
59
  }) => Promise<unknown>;
59
60
  declare const forEachBlockletSync: (blocklet: any, cb: Function) => Promise<unknown>;
61
+ declare const forEachComponentV2: (blocklet: TApp, cb: Function, { parallel, concurrencyLimit, sync, }?: {
62
+ parallel?: boolean;
63
+ concurrencyLimit?: number;
64
+ sync?: boolean;
65
+ }) => Promise<unknown>;
66
+ declare const forEachComponentV2Sync: (blocklet: any, cb: Function) => Promise<unknown>;
60
67
  declare const forEachChild: (blocklet: any, cb: Function, params?: any) => Promise<any>;
61
68
  declare const forEachChildSync: (blocklet: BlockletState, cb: Function) => Promise<any>;
62
- declare const findComponent: (blocklet: Component, isEqualFn: (component: Component, context: {
63
- ancestors: Array<Component>;
69
+ declare const findComponent: (blocklet: TComponent, isEqualFn: (component: TComponent, context: {
70
+ ancestors: Array<TComponent>;
64
71
  }) => boolean, { _ancestors, returnAncestors, }?: {
65
- _ancestors?: Array<Component>;
72
+ _ancestors?: Array<TComponent>;
66
73
  returnAncestors?: boolean;
67
- }) => Component | {
68
- component: Component;
69
- ancestors: Array<Component>;
74
+ }) => TComponent | {
75
+ component: TComponent;
76
+ ancestors: Array<TComponent>;
70
77
  };
71
78
  declare const findComponentById: (blocklet: BlockletState | ComponentState, componentId: string | Array<string>, { returnAncestors, }?: {
72
79
  returnAncestors?: boolean;
73
- }) => Component | {
74
- component: Component;
75
- ancestors: Array<Component>;
80
+ }) => TComponent | {
81
+ component: TComponent;
82
+ ancestors: Array<TComponent>;
76
83
  };
84
+ declare const findComponentV2: (app: TApp, isEqualFn: (component: TComponent, app: TApp) => boolean) => ComponentState;
85
+ declare const findComponentByIdV2: (app: TApp, componentId: string | Array<string>) => ComponentState;
86
+ declare const filterComponentsV2: (app: TApp, isEqualFn: (component: TComponent, app: TApp) => boolean) => any[];
77
87
  declare const isEnvShareable: (env?: TConfig) => boolean;
78
88
  declare const getSharedConfigObj: (component: BlockletState, ancestors?: any[]) => any;
79
89
  declare const isPreferenceKey: (x: TConfig) => Boolean;
@@ -115,7 +125,7 @@ type ChainInfo = {
115
125
  host: string;
116
126
  };
117
127
  declare const getChainInfo: (env: Record<string, string>) => ChainInfo;
118
- declare const getBlockletChainInfo: (blocklet?: ComponentPro) => ChainInfo;
128
+ declare const getBlockletChainInfo: (blocklet?: TComponentPro) => ChainInfo;
119
129
  declare const isExternalBlocklet: (blocklet?: BlockletState) => boolean;
120
130
  declare const getRolesFromAuthConfig: (config: {
121
131
  whoCanAccess: string;
@@ -130,12 +140,21 @@ declare const getBlockletServices: (blocklet: Partial<BlockletState>) => Array<{
130
140
  declare const isInProgress: (status: string | number) => boolean;
131
141
  declare const isBeforeInstalled: (status: string | number) => boolean;
132
142
  declare const isRunning: (status: string | number) => boolean;
133
- export { isFreeBlocklet, isFreeComponent, isComponentBlocklet, forEachBlocklet, forEachBlockletSync, forEachChild, forEachChildSync, isDeletableBlocklet, getSharedConfigObj, getAppMissingConfigs, getComponentMissingConfigs, isEnvShareable, wipeSensitiveData, hasRunnableComponent, getAppName, getAppName as getDisplayName, getAppDescription, fixBlockletStatus, findWebInterface, findWebInterfacePort, findServiceFromMeta, getWhoCanAccess, replaceSlotToIp, getComponentId, getComponentName, getComponentBundleId, findComponent, findComponentById, getParentComponentName, getConnectAppUrl, getChainInfo, getBlockletChainInfo, isExternalBlocklet, isPreferenceKey, getRolesFromAuthConfig, getBlockletAppIdList, getBlockletServices, isInProgress, isBeforeInstalled, isRunning, };
143
+ type TComponentInternalInfo = {
144
+ title: string;
145
+ did: string;
146
+ name: string;
147
+ mountPoint: string;
148
+ status: number;
149
+ port: number;
150
+ };
151
+ declare const getComponentsInternalInfo: (app: TApp) => Array<TComponentInternalInfo>;
152
+ export { isFreeBlocklet, isFreeComponent, isComponentBlocklet, forEachBlocklet, forEachBlockletSync, forEachChild, forEachChildSync, forEachComponentV2, forEachComponentV2Sync, isDeletableBlocklet, getSharedConfigObj, getAppMissingConfigs, getComponentMissingConfigs, isEnvShareable, wipeSensitiveData, hasRunnableComponent, getAppName, getAppName as getDisplayName, getAppDescription, fixBlockletStatus, findWebInterface, findWebInterfacePort, findServiceFromMeta, getWhoCanAccess, replaceSlotToIp, getComponentId, getComponentName, getComponentBundleId, findComponent, findComponentById, findComponentV2, findComponentByIdV2, filterComponentsV2, getParentComponentName, getConnectAppUrl, getChainInfo, getBlockletChainInfo, isExternalBlocklet, isPreferenceKey, getRolesFromAuthConfig, getBlockletAppIdList, getBlockletServices, isInProgress, isBeforeInstalled, isRunning, getComponentsInternalInfo, TComponentInternalInfo, };
134
153
  declare const _default: {
135
154
  isFreeBlocklet: (meta: TBlockletMeta) => boolean;
136
155
  isFreeComponent: (meta: TBlockletMeta) => boolean;
137
156
  isComponentBlocklet: (meta?: TBlockletMeta) => boolean;
138
- forEachBlocklet: (blocklet: ComponentPro, cb: Function, { parallel, concurrencyLimit, sync, params: inputParams, _parent, _root, _level, _tasks: inputTasks, _ancestors, _limit, }?: {
157
+ forEachBlocklet: (blocklet: TComponentPro, cb: Function, { parallel, concurrencyLimit, sync, params: inputParams, _parent, _root, _level, _tasks: inputTasks, _ancestors, _limit, }?: {
139
158
  parallel?: boolean;
140
159
  concurrencyLimit?: number;
141
160
  sync?: boolean;
@@ -150,6 +169,12 @@ declare const _default: {
150
169
  forEachBlockletSync: (blocklet: any, cb: Function) => Promise<unknown>;
151
170
  forEachChild: (blocklet: any, cb: Function, params?: any) => Promise<any>;
152
171
  forEachChildSync: (blocklet: BlockletState, cb: Function) => Promise<any>;
172
+ forEachComponentV2: (blocklet: BlockletState, cb: Function, { parallel, concurrencyLimit, sync, }?: {
173
+ parallel?: boolean;
174
+ concurrencyLimit?: number;
175
+ sync?: boolean;
176
+ }) => Promise<unknown>;
177
+ forEachComponentV2Sync: (blocklet: any, cb: Function) => Promise<unknown>;
153
178
  isDeletableBlocklet: (blocklet?: BlockletState) => boolean;
154
179
  getSharedConfigObj: (component: BlockletState, ancestors?: any[]) => any;
155
180
  getAppMissingConfigs: (blocklet?: any) => any[];
@@ -190,28 +215,31 @@ declare const _default: {
190
215
  version: string;
191
216
  };
192
217
  }) => string;
193
- findComponent: (blocklet: Component, isEqualFn: (component: Component, context: {
194
- ancestors: Component[];
218
+ findComponent: (blocklet: TComponent, isEqualFn: (component: TComponent, context: {
219
+ ancestors: TComponent[];
195
220
  }) => boolean, { _ancestors, returnAncestors, }?: {
196
- _ancestors?: Component[];
221
+ _ancestors?: TComponent[];
197
222
  returnAncestors?: boolean;
198
- }) => Component | {
199
- component: Component;
200
- ancestors: Component[];
223
+ }) => TComponent | {
224
+ component: TComponent;
225
+ ancestors: TComponent[];
201
226
  };
202
227
  findComponentById: (blocklet: BlockletState | ComponentState, componentId: string | string[], { returnAncestors, }?: {
203
228
  returnAncestors?: boolean;
204
- }) => Component | {
205
- component: Component;
206
- ancestors: Component[];
229
+ }) => TComponent | {
230
+ component: TComponent;
231
+ ancestors: TComponent[];
207
232
  };
233
+ findComponentV2: (app: BlockletState, isEqualFn: (component: TComponent, app: BlockletState) => boolean) => ComponentState;
234
+ findComponentByIdV2: (app: BlockletState, componentId: string | string[]) => ComponentState;
235
+ filterComponentsV2: (app: BlockletState, isEqualFn: (component: TComponent, app: BlockletState) => boolean) => any[];
208
236
  getParentComponentName: (name?: string) => string;
209
237
  getConnectAppUrl: ({ request, baseUrl }: {
210
238
  request: Partial<Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>>;
211
239
  baseUrl: string;
212
240
  }) => string;
213
241
  getChainInfo: (env: Record<string, string>) => ChainInfo;
214
- getBlockletChainInfo: (blocklet?: ComponentPro) => ChainInfo;
242
+ getBlockletChainInfo: (blocklet?: TComponentPro) => ChainInfo;
215
243
  isExternalBlocklet: (blocklet?: BlockletState) => boolean;
216
244
  isPreferenceKey: (x: TConfig) => Boolean;
217
245
  getRolesFromAuthConfig: (config: {
@@ -226,5 +254,6 @@ declare const _default: {
226
254
  isInProgress: (status: string | number) => boolean;
227
255
  isBeforeInstalled: (status: string | number) => boolean;
228
256
  isRunning: (status: string | number) => boolean;
257
+ getComponentsInternalInfo: (app: BlockletState) => TComponentInternalInfo[];
229
258
  };
230
259
  export default _default;
package/lib/util.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.isRunning = exports.isBeforeInstalled = exports.isInProgress = exports.getBlockletServices = exports.getBlockletAppIdList = exports.getRolesFromAuthConfig = exports.isPreferenceKey = exports.isExternalBlocklet = exports.getBlockletChainInfo = exports.getChainInfo = exports.getConnectAppUrl = exports.getParentComponentName = exports.findComponentById = exports.findComponent = exports.getComponentBundleId = exports.getComponentName = exports.getComponentId = exports.replaceSlotToIp = exports.getWhoCanAccess = exports.findServiceFromMeta = exports.findWebInterfacePort = exports.findWebInterface = exports.fixBlockletStatus = exports.getAppDescription = exports.getDisplayName = exports.getAppName = exports.hasRunnableComponent = exports.wipeSensitiveData = exports.isEnvShareable = exports.getComponentMissingConfigs = exports.getAppMissingConfigs = exports.getSharedConfigObj = exports.isDeletableBlocklet = exports.forEachChildSync = exports.forEachChild = exports.forEachBlockletSync = exports.forEachBlocklet = exports.isComponentBlocklet = exports.isFreeComponent = exports.isFreeBlocklet = void 0;
6
+ exports.getComponentsInternalInfo = exports.isRunning = exports.isBeforeInstalled = exports.isInProgress = exports.getBlockletServices = exports.getBlockletAppIdList = exports.getRolesFromAuthConfig = exports.isPreferenceKey = exports.isExternalBlocklet = exports.getBlockletChainInfo = exports.getChainInfo = exports.getConnectAppUrl = exports.getParentComponentName = exports.filterComponentsV2 = exports.findComponentByIdV2 = exports.findComponentV2 = exports.findComponentById = exports.findComponent = exports.getComponentBundleId = exports.getComponentName = exports.getComponentId = exports.replaceSlotToIp = exports.getWhoCanAccess = exports.findServiceFromMeta = exports.findWebInterfacePort = exports.findWebInterface = exports.fixBlockletStatus = exports.getAppDescription = exports.getDisplayName = exports.getAppName = exports.hasRunnableComponent = exports.wipeSensitiveData = exports.isEnvShareable = exports.getComponentMissingConfigs = exports.getAppMissingConfigs = exports.getSharedConfigObj = exports.isDeletableBlocklet = exports.forEachComponentV2Sync = exports.forEachComponentV2 = exports.forEachChildSync = exports.forEachChild = exports.forEachBlockletSync = exports.forEachBlocklet = exports.isComponentBlocklet = exports.isFreeComponent = exports.isFreeBlocklet = void 0;
7
7
  /* eslint-disable no-await-in-loop */
8
8
  const get_1 = __importDefault(require("lodash/get"));
9
9
  const uniq_1 = __importDefault(require("lodash/uniq"));
@@ -131,6 +131,46 @@ const forEachBlocklet = (blocklet, cb, { parallel = false, concurrencyLimit = 5,
131
131
  exports.forEachBlocklet = forEachBlocklet;
132
132
  const forEachBlockletSync = (blocklet, cb) => forEachBlocklet(blocklet, cb, { sync: true });
133
133
  exports.forEachBlockletSync = forEachBlockletSync;
134
+ const forEachComponentV2 = (blocklet, cb, { parallel = false, concurrencyLimit = 5, sync, } = {}) => {
135
+ // sync
136
+ if (sync) {
137
+ if (blocklet.children) {
138
+ for (const child of blocklet.children) {
139
+ cb(child);
140
+ }
141
+ }
142
+ return null;
143
+ }
144
+ // serial
145
+ if (!parallel) {
146
+ // eslint-disable-next-line no-async-promise-executor
147
+ return new Promise(async (resolve, reject) => {
148
+ try {
149
+ if (blocklet.children) {
150
+ for (const child of blocklet.children) {
151
+ await cb(child);
152
+ }
153
+ }
154
+ resolve(null);
155
+ }
156
+ catch (err) {
157
+ reject(err);
158
+ }
159
+ });
160
+ }
161
+ // parallel
162
+ const limit = (0, p_limit_1.default)(concurrencyLimit);
163
+ const tasks = [];
164
+ if (blocklet.children) {
165
+ for (const child of blocklet.children) {
166
+ tasks.push(limit(() => cb(child)));
167
+ }
168
+ }
169
+ return Promise.all(tasks);
170
+ };
171
+ exports.forEachComponentV2 = forEachComponentV2;
172
+ const forEachComponentV2Sync = (blocklet, cb) => forEachComponentV2(blocklet, cb, { sync: true });
173
+ exports.forEachComponentV2Sync = forEachComponentV2Sync;
134
174
  const forEachChild = (blocklet, cb, params) => {
135
175
  return forEachBlocklet(blocklet, (b, opt) => {
136
176
  if (opt.level === 0) {
@@ -177,6 +217,48 @@ const findComponentById = (blocklet, componentId, { returnAncestors = false, } =
177
217
  }, { returnAncestors });
178
218
  };
179
219
  exports.findComponentById = findComponentById;
220
+ const findComponentV2 = (app, isEqualFn) => {
221
+ if (!isEqualFn) {
222
+ return null;
223
+ }
224
+ for (const child of app.children || []) {
225
+ if (isEqualFn(child, app)) {
226
+ return child;
227
+ }
228
+ }
229
+ return null;
230
+ };
231
+ exports.findComponentV2 = findComponentV2;
232
+ const findComponentByIdV2 = (app, componentId) => {
233
+ if (!componentId) {
234
+ return null;
235
+ }
236
+ if (Array.isArray(componentId)) {
237
+ // eslint-disable-next-line no-param-reassign
238
+ componentId = componentId.join('/');
239
+ }
240
+ return findComponentV2(app, (component, _app) => {
241
+ if (componentId.includes('/')) {
242
+ const id = getComponentId(component, [_app]);
243
+ return componentId === id;
244
+ }
245
+ return componentId === component.meta.did;
246
+ });
247
+ };
248
+ exports.findComponentByIdV2 = findComponentByIdV2;
249
+ const filterComponentsV2 = (app, isEqualFn) => {
250
+ if (!isEqualFn) {
251
+ return [];
252
+ }
253
+ const list = [];
254
+ for (const child of app.children || []) {
255
+ if (isEqualFn(child, app)) {
256
+ list.push(child);
257
+ }
258
+ }
259
+ return list;
260
+ };
261
+ exports.filterComponentsV2 = filterComponentsV2;
180
262
  const isEnvShareable = (env) => {
181
263
  return (!!env &&
182
264
  !!(env.key || env.name) &&
@@ -572,6 +654,29 @@ const isBeforeInstalled = (status) => [
572
654
  exports.isBeforeInstalled = isBeforeInstalled;
573
655
  const isRunning = (status) => [constant_2.BlockletStatus.running, 'running'].includes(status);
574
656
  exports.isRunning = isRunning;
657
+ const getComponentsInternalInfo = (app) => {
658
+ const components = [];
659
+ if (!app) {
660
+ return components;
661
+ }
662
+ forEachComponentV2Sync(app, (x) => {
663
+ const component = {
664
+ title: x.meta.title,
665
+ did: x.meta.did,
666
+ name: x.meta.name,
667
+ mountPoint: x.mountPoint || '',
668
+ status: x.status,
669
+ port: 0,
670
+ };
671
+ const webInterface = findWebInterface(x);
672
+ if (webInterface && (x.environments || []).find((y) => y.key === webInterface.port)) {
673
+ component.port = x.environments.find((y) => y.key === webInterface.port).value;
674
+ }
675
+ components.push(component);
676
+ });
677
+ return components;
678
+ };
679
+ exports.getComponentsInternalInfo = getComponentsInternalInfo;
575
680
  exports.default = {
576
681
  isFreeBlocklet,
577
682
  isFreeComponent,
@@ -580,6 +685,8 @@ exports.default = {
580
685
  forEachBlockletSync,
581
686
  forEachChild,
582
687
  forEachChildSync,
688
+ forEachComponentV2,
689
+ forEachComponentV2Sync,
583
690
  isDeletableBlocklet,
584
691
  getSharedConfigObj,
585
692
  getAppMissingConfigs,
@@ -601,6 +708,9 @@ exports.default = {
601
708
  getComponentBundleId,
602
709
  findComponent,
603
710
  findComponentById,
711
+ findComponentV2,
712
+ findComponentByIdV2,
713
+ filterComponentsV2,
604
714
  getParentComponentName,
605
715
  getConnectAppUrl,
606
716
  getChainInfo,
@@ -612,4 +722,5 @@ exports.default = {
612
722
  isInProgress,
613
723
  isBeforeInstalled,
614
724
  isRunning,
725
+ getComponentsInternalInfo,
615
726
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.11-next-a232f5fb",
6
+ "version": "1.16.11-next-09bc31f8",
7
7
  "description": "Library to parse/validate/fix blocklet meta",
8
8
  "main": "./lib/index.js",
9
9
  "typings": "./lib/index.d.ts",
@@ -24,13 +24,13 @@
24
24
  "author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
25
25
  "license": "Apache-2.0",
26
26
  "dependencies": {
27
- "@abtnode/constant": "1.16.11-next-a232f5fb",
28
- "@abtnode/util": "1.16.11-next-a232f5fb",
27
+ "@abtnode/constant": "1.16.11-next-09bc31f8",
28
+ "@abtnode/util": "1.16.11-next-09bc31f8",
29
29
  "@arcblock/did": "1.18.80",
30
30
  "@arcblock/did-ext": "1.18.80",
31
31
  "@arcblock/did-util": "1.18.80",
32
32
  "@arcblock/jwt": "1.18.80",
33
- "@blocklet/constant": "1.16.11-next-a232f5fb",
33
+ "@blocklet/constant": "1.16.11-next-09bc31f8",
34
34
  "@ocap/asset": "1.18.80",
35
35
  "@ocap/mcrypto": "1.18.80",
36
36
  "@ocap/types": "1.18.80",
@@ -79,5 +79,5 @@
79
79
  "ts-node": "^10.9.1",
80
80
  "typescript": "^5.0.4"
81
81
  },
82
- "gitHead": "1af264e9b6648aa191fbf23c67717262ac717697"
82
+ "gitHead": "c51355ac77d07dc27e2fb6c44ce2a45432a9469b"
83
83
  }