@blocklet/meta 1.8.66-beta-ff281dd5 → 1.8.66-beta-7f4224af

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.
package/lib/channel.d.ts CHANGED
@@ -1,27 +1,32 @@
1
1
  declare const getAppPublicChannelRegex: () => RegExp;
2
+ declare const getRelayChannelRegex: () => RegExp;
2
3
  declare const getAppPublicChannel: (appDid: string) => string;
4
+ declare const getRelayChannel: (appDid: string, topic: string) => string;
3
5
  declare const CHANNEL_TYPE: {
4
6
  DID: string;
5
7
  APP: string;
8
+ RELAY: string;
6
9
  };
7
10
  declare const parseChannel: (channel: string) => {
8
11
  type: string;
9
12
  appDid?: string;
13
+ topic?: string;
10
14
  };
11
- export { CHANNEL_TYPE };
12
- export { getAppPublicChannel };
13
- export { getAppPublicChannelRegex };
14
- export { parseChannel };
15
+ export { CHANNEL_TYPE, getAppPublicChannel, getAppPublicChannelRegex, getRelayChannel, getRelayChannelRegex, parseChannel, };
15
16
  declare const _default: {
16
17
  CHANNEL_TYPE: {
17
18
  DID: string;
18
19
  APP: string;
20
+ RELAY: string;
19
21
  };
20
22
  getAppPublicChannel: (appDid: string) => string;
21
23
  getAppPublicChannelRegex: () => RegExp;
24
+ getRelayChannel: (appDid: string, topic: string) => string;
25
+ getRelayChannelRegex: () => RegExp;
22
26
  parseChannel: (channel: string) => {
23
27
  type: string;
24
28
  appDid?: string;
29
+ topic?: string;
25
30
  };
26
31
  };
27
32
  export default _default;
package/lib/channel.js CHANGED
@@ -1,26 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseChannel = exports.getAppPublicChannelRegex = exports.getAppPublicChannel = exports.CHANNEL_TYPE = void 0;
3
+ exports.parseChannel = exports.getRelayChannelRegex = exports.getRelayChannel = exports.getAppPublicChannelRegex = exports.getAppPublicChannel = exports.CHANNEL_TYPE = void 0;
4
4
  /* eslint-disable @typescript-eslint/indent */
5
5
  const did_1 = require("@arcblock/did");
6
6
  const getAppPublicChannelRegex = () => /app:(\w+):public/;
7
7
  exports.getAppPublicChannelRegex = getAppPublicChannelRegex;
8
+ const getRelayChannelRegex = () => /relay:(\w+):(\w+)/;
9
+ exports.getRelayChannelRegex = getRelayChannelRegex;
8
10
  const getAppPublicChannel = (appDid) => `app:${appDid}:public`;
9
11
  exports.getAppPublicChannel = getAppPublicChannel;
12
+ const getRelayChannel = (appDid, topic) => `relay:${appDid}:${topic}`;
13
+ exports.getRelayChannel = getRelayChannel;
10
14
  const CHANNEL_TYPE = {
11
15
  DID: 'DID',
12
16
  APP: 'APP',
17
+ RELAY: 'RELAY',
13
18
  };
14
19
  exports.CHANNEL_TYPE = CHANNEL_TYPE;
15
20
  const parseChannel = (channel) => {
16
21
  if (!channel) {
17
22
  throw new Error('Channel should not be empty');
18
23
  }
19
- const matchAppPublicChannel = getAppPublicChannelRegex().exec(channel);
20
- if (matchAppPublicChannel) {
24
+ let match = getRelayChannelRegex().exec(channel);
25
+ if (match && (0, did_1.isValid)(match[1])) {
26
+ return {
27
+ type: CHANNEL_TYPE.RELAY,
28
+ appDid: match[1],
29
+ topic: match[2],
30
+ };
31
+ }
32
+ match = getAppPublicChannelRegex().exec(channel);
33
+ if (match && (0, did_1.isValid)(match[1])) {
21
34
  return {
22
35
  type: CHANNEL_TYPE.APP,
23
- appDid: matchAppPublicChannel[1],
36
+ appDid: match[1],
24
37
  };
25
38
  }
26
39
  if ((0, did_1.isValid)(channel)) {
@@ -35,5 +48,7 @@ exports.default = {
35
48
  CHANNEL_TYPE,
36
49
  getAppPublicChannel,
37
50
  getAppPublicChannelRegex,
51
+ getRelayChannel,
52
+ getRelayChannelRegex,
38
53
  parseChannel,
39
54
  };
package/lib/util.d.ts CHANGED
@@ -54,10 +54,21 @@ declare const forEachBlocklet: (blocklet: BlockletState | ComponentState, cb: Fu
54
54
  declare const forEachBlockletSync: (blocklet: any, cb: Function) => Promise<unknown>;
55
55
  declare const forEachChild: (blocklet: any, cb: Function, params?: any) => Promise<any>;
56
56
  declare const forEachChildSync: (blocklet: BlockletState, cb: Function) => Promise<any>;
57
- declare const findComponentById: (blocklet: BlockletState | ComponentState, componentId: string | Array<string>, { _ancestors, returnAncestors, }?: {
58
- _ancestors?: any[];
57
+ declare const findComponent: (blocklet: BlockletState | ComponentState, isEqualFn: (component: ComponentState, context: {
58
+ ancestors: Array<ComponentState>;
59
+ }) => boolean, { _ancestors, returnAncestors, }?: {
60
+ _ancestors?: Array<ComponentState>;
61
+ returnAncestors?: boolean;
62
+ }) => ComponentState | {
63
+ component: ComponentState;
64
+ ancestors: Array<ComponentState>;
65
+ };
66
+ declare const findComponentById: (blocklet: BlockletState | ComponentState, componentId: string | Array<string>, { returnAncestors, }?: {
59
67
  returnAncestors?: boolean;
60
- }) => any;
68
+ }) => ComponentState | {
69
+ component: ComponentState;
70
+ ancestors: Array<ComponentState>;
71
+ };
61
72
  declare const isEnvShareable: (env?: TConfig) => boolean;
62
73
  declare const getSharedConfigObj: (component: BlockletState, ancestors?: any[]) => any;
63
74
  declare const isPreferenceKey: (x: TConfig) => Boolean;
@@ -78,6 +89,7 @@ declare const hasRunnableComponent: (blocklet: BlockletState) => boolean;
78
89
  declare const getDisplayName: (blocklet: BlockletState, onlyUseMeta?: boolean) => string;
79
90
  declare const fixBlockletStatus: (blocklet?: BlockletState) => void;
80
91
  declare const findWebInterface: (blocklet?: BlockletState | TBlockletMeta) => any;
92
+ declare const findWebInterfacePort: (blocklet?: BlockletState) => any;
81
93
  declare const findServiceFromMeta: (meta?: TBlockletMeta, ServiceName?: string) => any;
82
94
  declare const getWhoCanAccess: (blocklet?: BlockletState) => any;
83
95
  declare const getConnectAppUrl: ({ request, baseUrl }: {
@@ -108,6 +120,7 @@ export { hasRunnableComponent };
108
120
  export { getDisplayName };
109
121
  export { fixBlockletStatus };
110
122
  export { findWebInterface };
123
+ export { findWebInterfacePort };
111
124
  export { findServiceFromMeta };
112
125
  export { getWhoCanAccess };
113
126
  export { replaceSlotToIp };
@@ -115,6 +128,7 @@ export { urlFriendly };
115
128
  export { getComponentId };
116
129
  export { getComponentName };
117
130
  export { getComponentBundleId };
131
+ export { findComponent };
118
132
  export { findComponentById };
119
133
  export { getParentComponentName };
120
134
  export { getConnectAppUrl };
@@ -151,6 +165,7 @@ declare const _default: {
151
165
  getDisplayName: (blocklet: BlockletState, onlyUseMeta?: boolean) => string;
152
166
  fixBlockletStatus: (blocklet?: BlockletState) => void;
153
167
  findWebInterface: (blocklet?: TBlockletMeta | BlockletState) => any;
168
+ findWebInterfacePort: (blocklet?: BlockletState) => any;
154
169
  findServiceFromMeta: (meta?: TBlockletMeta, ServiceName?: string) => any;
155
170
  getWhoCanAccess: (blocklet?: BlockletState) => any;
156
171
  replaceSlotToIp: (url?: string, ip?: string) => string;
@@ -179,10 +194,21 @@ declare const _default: {
179
194
  version: string;
180
195
  };
181
196
  }) => string;
182
- findComponentById: (blocklet: BlockletState | ComponentState, componentId: string | string[], { _ancestors, returnAncestors, }?: {
183
- _ancestors?: any[];
197
+ findComponent: (blocklet: BlockletState | ComponentState, isEqualFn: (component: ComponentState, context: {
198
+ ancestors: ComponentState[];
199
+ }) => boolean, { _ancestors, returnAncestors, }?: {
200
+ _ancestors?: ComponentState[];
201
+ returnAncestors?: boolean;
202
+ }) => ComponentState | {
203
+ component: ComponentState;
204
+ ancestors: ComponentState[];
205
+ };
206
+ findComponentById: (blocklet: BlockletState | ComponentState, componentId: string | string[], { returnAncestors, }?: {
184
207
  returnAncestors?: boolean;
185
- }) => any;
208
+ }) => ComponentState | {
209
+ component: ComponentState;
210
+ ancestors: ComponentState[];
211
+ };
186
212
  getParentComponentName: (name?: string) => string;
187
213
  getConnectAppUrl: ({ request, baseUrl }: {
188
214
  request: Partial<Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>>;
package/lib/util.js CHANGED
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getRolesFromAuthConfig = exports.isPreferenceKey = exports.isExternalBlocklet = exports.getChainInfo = exports.getConnectAppUrl = exports.getParentComponentName = exports.findComponentById = exports.getComponentBundleId = exports.getComponentName = exports.getComponentId = exports.urlFriendly = exports.replaceSlotToIp = exports.getWhoCanAccess = exports.findServiceFromMeta = exports.findWebInterface = exports.fixBlockletStatus = exports.getDisplayName = 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;
15
+ exports.getRolesFromAuthConfig = exports.isPreferenceKey = exports.isExternalBlocklet = exports.getChainInfo = exports.getConnectAppUrl = exports.getParentComponentName = exports.findComponentById = exports.findComponent = exports.getComponentBundleId = exports.getComponentName = exports.getComponentId = exports.urlFriendly = exports.replaceSlotToIp = exports.getWhoCanAccess = exports.findServiceFromMeta = exports.findWebInterfacePort = exports.findWebInterface = exports.fixBlockletStatus = exports.getDisplayName = 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;
16
16
  /* eslint-disable no-await-in-loop */
17
17
  const get_1 = __importDefault(require("lodash/get"));
18
18
  const slugify_1 = __importDefault(require("slugify"));
@@ -153,13 +153,11 @@ exports.forEachChild = forEachChild;
153
153
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
154
154
  const forEachChildSync = (blocklet, cb) => forEachChild(blocklet, cb, { sync: true });
155
155
  exports.forEachChildSync = forEachChildSync;
156
- const findComponentById = (blocklet, componentId, { _ancestors = [], returnAncestors = false, } = {}) => {
157
- if (Array.isArray(componentId)) {
158
- // eslint-disable-next-line no-param-reassign
159
- componentId = componentId.join('/');
156
+ const findComponent = (blocklet, isEqualFn, { _ancestors = [], returnAncestors = false, } = {}) => {
157
+ if (!isEqualFn) {
158
+ return null;
160
159
  }
161
- const id = getComponentId(blocklet, _ancestors);
162
- if (componentId === id) {
160
+ if (isEqualFn(blocklet, { ancestors: _ancestors })) {
163
161
  if (returnAncestors) {
164
162
  return {
165
163
  component: blocklet,
@@ -170,13 +168,24 @@ const findComponentById = (blocklet, componentId, { _ancestors = [], returnAnces
170
168
  }
171
169
  for (const child of blocklet.children || []) {
172
170
  const ancestors = _ancestors.concat(blocklet);
173
- const component = findComponentById(child, componentId, { _ancestors: ancestors, returnAncestors });
171
+ const component = findComponent(child, isEqualFn, { _ancestors: ancestors, returnAncestors });
174
172
  if (component) {
175
173
  return component;
176
174
  }
177
175
  }
178
176
  return null;
179
177
  };
178
+ exports.findComponent = findComponent;
179
+ const findComponentById = (blocklet, componentId, { returnAncestors = false, } = {}) => {
180
+ if (Array.isArray(componentId)) {
181
+ // eslint-disable-next-line no-param-reassign
182
+ componentId = componentId.join('/');
183
+ }
184
+ return findComponent(blocklet, (component, { ancestors }) => {
185
+ const id = getComponentId(component, ancestors);
186
+ return componentId === id;
187
+ }, { returnAncestors });
188
+ };
180
189
  exports.findComponentById = findComponentById;
181
190
  const isEnvShareable = (env) => {
182
191
  return (!!env &&
@@ -365,6 +374,18 @@ const findWebInterface = (blocklet) => {
365
374
  return interfaces.find((x) => x.type === BLOCKLET_INTERFACE_TYPE_WEB);
366
375
  };
367
376
  exports.findWebInterface = findWebInterface;
377
+ const findWebInterfacePort = (blocklet) => {
378
+ if (!blocklet) {
379
+ return null;
380
+ }
381
+ const webInterface = findWebInterface(blocklet);
382
+ const { ports } = blocklet;
383
+ if (!webInterface || !ports) {
384
+ return null;
385
+ }
386
+ return ports[webInterface.port];
387
+ };
388
+ exports.findWebInterfacePort = findWebInterfacePort;
368
389
  const findServiceFromMeta = (meta, ServiceName) => {
369
390
  const names = [ServiceName];
370
391
  // backward compatible
@@ -445,6 +466,7 @@ exports.default = {
445
466
  getDisplayName,
446
467
  fixBlockletStatus,
447
468
  findWebInterface,
469
+ findWebInterfacePort,
448
470
  findServiceFromMeta,
449
471
  getWhoCanAccess,
450
472
  replaceSlotToIp,
@@ -452,6 +474,7 @@ exports.default = {
452
474
  getComponentId,
453
475
  getComponentName,
454
476
  getComponentBundleId,
477
+ findComponent,
455
478
  findComponentById,
456
479
  getParentComponentName,
457
480
  getConnectAppUrl,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.66-beta-ff281dd5",
6
+ "version": "1.8.66-beta-7f4224af",
7
7
  "description": "Library to parse/validate/fix blocklet meta",
8
8
  "main": "./lib/index.js",
9
9
  "typings": "./lib/index.d.ts",
@@ -24,19 +24,19 @@
24
24
  "author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
- "@abtnode/client": "1.8.66-beta-ff281dd5",
28
- "@abtnode/constant": "1.8.66-beta-ff281dd5",
29
- "@abtnode/util": "1.8.66-beta-ff281dd5",
30
- "@arcblock/did": "1.18.42",
31
- "@arcblock/did-ext": "1.18.42",
32
- "@arcblock/did-util": "1.18.42",
33
- "@arcblock/jwt": "1.18.42",
34
- "@blocklet/constant": "1.8.66-beta-ff281dd5",
35
- "@ocap/asset": "1.18.42",
36
- "@ocap/mcrypto": "1.18.42",
37
- "@ocap/types": "1.18.42",
38
- "@ocap/util": "1.18.42",
39
- "@ocap/wallet": "1.18.42",
27
+ "@abtnode/client": "1.8.66-beta-7f4224af",
28
+ "@abtnode/constant": "1.8.66-beta-7f4224af",
29
+ "@abtnode/util": "1.8.66-beta-7f4224af",
30
+ "@arcblock/did": "1.18.47",
31
+ "@arcblock/did-ext": "1.18.47",
32
+ "@arcblock/did-util": "1.18.47",
33
+ "@arcblock/jwt": "1.18.47",
34
+ "@blocklet/constant": "1.8.66-beta-7f4224af",
35
+ "@ocap/asset": "1.18.47",
36
+ "@ocap/mcrypto": "1.18.47",
37
+ "@ocap/types": "1.18.47",
38
+ "@ocap/util": "1.18.47",
39
+ "@ocap/wallet": "1.18.47",
40
40
  "ajv": "^8.11.0",
41
41
  "axios": "^0.27.2",
42
42
  "cjk-length": "^1.0.0",
@@ -59,7 +59,7 @@
59
59
  "validate-npm-package-name": "^3.0.0"
60
60
  },
61
61
  "devDependencies": {
62
- "@abtnode/client": "^1.8.64",
62
+ "@abtnode/client": "^1.8.65",
63
63
  "@arcblock/eslint-config-ts": "^0.2.3",
64
64
  "@types/express": "^4.17.14",
65
65
  "@types/jest": "^29.2.2",
@@ -80,5 +80,5 @@
80
80
  "ts-node": "^10.9.1",
81
81
  "typescript": "^4.8.4"
82
82
  },
83
- "gitHead": "92edfc81679a4749b30a7f8195d487afa148e26b"
83
+ "gitHead": "72d418f63ecb76b1d5d62edbcc5f336cb62bf308"
84
84
  }