@blocklet/meta 1.8.68-beta-500af7e5 → 1.8.68
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 +4 -9
- package/lib/channel.js +4 -19
- package/lib/did.js +0 -3
- package/lib/extension.d.ts +0 -4
- package/lib/extension.js +0 -4
- package/lib/file.d.ts +0 -2
- package/lib/file.js +1 -6
- package/lib/fix.d.ts +0 -3
- package/lib/fix.js +1 -15
- package/lib/index.d.ts +3 -8
- package/lib/index.js +1 -5
- package/lib/info.d.ts +0 -1
- package/lib/info.js +5 -8
- package/lib/name.d.ts +0 -6
- package/lib/name.js +4 -28
- package/lib/parse-navigation-from-blocklet.js +25 -29
- package/lib/parse-navigation.js +6 -13
- package/lib/parse.js +5 -8
- package/lib/payment/v2.js +60 -52
- package/lib/schema.d.ts +1 -3
- package/lib/schema.js +32 -79
- package/lib/service.js +1 -7
- package/lib/types/schema.d.ts +1 -2
- package/lib/url-friendly.d.ts +0 -2
- package/lib/url-friendly.js +1 -7
- package/lib/util-meta.js +23 -14
- package/lib/util.d.ts +6 -32
- package/lib/util.js +24 -41
- package/lib/validate.js +2 -5
- package/lib/verify-multi-sig.js +14 -3
- package/lib/wallet.d.ts +1 -1
- package/lib/wallet.js +3 -4
- package/package.json +16 -17
package/lib/channel.d.ts
CHANGED
|
@@ -1,32 +1,27 @@
|
|
|
1
1
|
declare const getAppPublicChannelRegex: () => RegExp;
|
|
2
|
-
declare const getRelayChannelRegex: () => RegExp;
|
|
3
2
|
declare const getAppPublicChannel: (appDid: string) => string;
|
|
4
|
-
declare const getRelayChannel: (appDid: string, topic: string) => string;
|
|
5
3
|
declare const CHANNEL_TYPE: {
|
|
6
4
|
DID: string;
|
|
7
5
|
APP: string;
|
|
8
|
-
RELAY: string;
|
|
9
6
|
};
|
|
10
7
|
declare const parseChannel: (channel: string) => {
|
|
11
8
|
type: string;
|
|
12
9
|
appDid?: string;
|
|
13
|
-
topic?: string;
|
|
14
10
|
};
|
|
15
|
-
export { CHANNEL_TYPE
|
|
11
|
+
export { CHANNEL_TYPE };
|
|
12
|
+
export { getAppPublicChannel };
|
|
13
|
+
export { getAppPublicChannelRegex };
|
|
14
|
+
export { parseChannel };
|
|
16
15
|
declare const _default: {
|
|
17
16
|
CHANNEL_TYPE: {
|
|
18
17
|
DID: string;
|
|
19
18
|
APP: string;
|
|
20
|
-
RELAY: string;
|
|
21
19
|
};
|
|
22
20
|
getAppPublicChannel: (appDid: string) => string;
|
|
23
21
|
getAppPublicChannelRegex: () => RegExp;
|
|
24
|
-
getRelayChannel: (appDid: string, topic: string) => string;
|
|
25
|
-
getRelayChannelRegex: () => RegExp;
|
|
26
22
|
parseChannel: (channel: string) => {
|
|
27
23
|
type: string;
|
|
28
24
|
appDid?: string;
|
|
29
|
-
topic?: string;
|
|
30
25
|
};
|
|
31
26
|
};
|
|
32
27
|
export default _default;
|
package/lib/channel.js
CHANGED
|
@@ -1,39 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseChannel = exports.
|
|
3
|
+
exports.parseChannel = 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;
|
|
10
8
|
const getAppPublicChannel = (appDid) => `app:${appDid}:public`;
|
|
11
9
|
exports.getAppPublicChannel = getAppPublicChannel;
|
|
12
|
-
const getRelayChannel = (appDid, topic) => `relay:${appDid}:${topic}`;
|
|
13
|
-
exports.getRelayChannel = getRelayChannel;
|
|
14
10
|
const CHANNEL_TYPE = {
|
|
15
11
|
DID: 'DID',
|
|
16
12
|
APP: 'APP',
|
|
17
|
-
RELAY: 'RELAY',
|
|
18
13
|
};
|
|
19
14
|
exports.CHANNEL_TYPE = CHANNEL_TYPE;
|
|
20
15
|
const parseChannel = (channel) => {
|
|
21
16
|
if (!channel) {
|
|
22
17
|
throw new Error('Channel should not be empty');
|
|
23
18
|
}
|
|
24
|
-
|
|
25
|
-
if (
|
|
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])) {
|
|
19
|
+
const matchAppPublicChannel = getAppPublicChannelRegex().exec(channel);
|
|
20
|
+
if (matchAppPublicChannel) {
|
|
34
21
|
return {
|
|
35
22
|
type: CHANNEL_TYPE.APP,
|
|
36
|
-
appDid:
|
|
23
|
+
appDid: matchAppPublicChannel[1],
|
|
37
24
|
};
|
|
38
25
|
}
|
|
39
26
|
if ((0, did_1.isValid)(channel)) {
|
|
@@ -48,7 +35,5 @@ exports.default = {
|
|
|
48
35
|
CHANNEL_TYPE,
|
|
49
36
|
getAppPublicChannel,
|
|
50
37
|
getAppPublicChannelRegex,
|
|
51
|
-
getRelayChannel,
|
|
52
|
-
getRelayChannelRegex,
|
|
53
38
|
parseChannel,
|
|
54
39
|
};
|
package/lib/did.js
CHANGED
|
@@ -3,9 +3,6 @@ const mcrypto_1 = require("@ocap/mcrypto");
|
|
|
3
3
|
const util_1 = require("@ocap/util");
|
|
4
4
|
const did_1 = require("@arcblock/did");
|
|
5
5
|
const toBlockletDid = (name) => {
|
|
6
|
-
if ((0, did_1.isValid)(name)) {
|
|
7
|
-
return name;
|
|
8
|
-
}
|
|
9
6
|
const pk = (0, util_1.toHex)(Buffer.from(typeof name === 'string' ? name.trim() : name));
|
|
10
7
|
return (0, did_1.fromPublicKey)(pk, { role: mcrypto_1.types.RoleType.ROLE_ANY });
|
|
11
8
|
};
|
package/lib/extension.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { Extension, Root } from 'joi';
|
|
2
2
|
declare const fileExtension: (joi: Root) => Extension;
|
|
3
|
-
/**
|
|
4
|
-
* joi extend did 判断
|
|
5
|
-
* 由于需要兼容新旧两种 did 模式判断,所以这里不能做 role 类型判断
|
|
6
|
-
*/
|
|
7
3
|
declare const didExtension: (joi: Root) => Extension;
|
|
8
4
|
export { fileExtension };
|
|
9
5
|
export { didExtension };
|
package/lib/extension.js
CHANGED
package/lib/file.d.ts
CHANGED
|
@@ -6,9 +6,7 @@ declare const select: (dir: string, { throwOnError }?: {
|
|
|
6
6
|
declare const update: (file: string, meta: TBlockletMeta, { fix }?: {
|
|
7
7
|
fix?: boolean;
|
|
8
8
|
}) => void;
|
|
9
|
-
declare const read: (file: string) => unknown;
|
|
10
9
|
export { list };
|
|
11
|
-
export { read };
|
|
12
10
|
export { select };
|
|
13
11
|
export { update };
|
|
14
12
|
declare const _default: {
|
package/lib/file.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.update = exports.select = exports.
|
|
6
|
+
exports.update = exports.select = exports.list = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
9
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
@@ -43,11 +43,6 @@ const update = (file, meta, { fix = true } = {}) => {
|
|
|
43
43
|
fs_extra_1.default.writeFileSync(file, js_yaml_1.default.dump(meta, { sortKeys: false, skipInvalid: true }));
|
|
44
44
|
};
|
|
45
45
|
exports.update = update;
|
|
46
|
-
const read = (file) => {
|
|
47
|
-
const fileContent = fs_extra_1.default.readFileSync(file, 'utf8').toString();
|
|
48
|
-
return js_yaml_1.default.load(fileContent);
|
|
49
|
-
};
|
|
50
|
-
exports.read = read;
|
|
51
46
|
exports.default = {
|
|
52
47
|
list,
|
|
53
48
|
select,
|
package/lib/fix.d.ts
CHANGED
|
@@ -8,14 +8,12 @@ declare const formatPerson: (person: string | Record<string, any>) => string;
|
|
|
8
8
|
declare const parsePerson: (person: string) => any;
|
|
9
9
|
declare const fixPerson: (data: any) => any;
|
|
10
10
|
declare const fixInterfaces: (meta: any, removeMerged?: boolean) => any;
|
|
11
|
-
declare const fixName: (meta: any) => any;
|
|
12
11
|
export { fixRequired };
|
|
13
12
|
export { fixRepository };
|
|
14
13
|
export { fixFiles };
|
|
15
14
|
export { fixKeywords };
|
|
16
15
|
export { fixPerson };
|
|
17
16
|
export { fixTags };
|
|
18
|
-
export { fixName };
|
|
19
17
|
export { formatPerson };
|
|
20
18
|
export { parsePerson };
|
|
21
19
|
export { fixInterfaces };
|
|
@@ -27,7 +25,6 @@ declare const _default: {
|
|
|
27
25
|
fixKeywords: (data: any) => void;
|
|
28
26
|
fixPerson: (data: any) => any;
|
|
29
27
|
fixTags: (data: any) => void;
|
|
30
|
-
fixName: (meta: any) => any;
|
|
31
28
|
formatPerson: (person: string | Record<string, any>) => string;
|
|
32
29
|
parsePerson: (person: string) => any;
|
|
33
30
|
fixInterfaces: (meta: any, removeMerged?: boolean) => any;
|
package/lib/fix.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.fixService = exports.fixInterfaces = exports.parsePerson = exports.formatPerson = exports.
|
|
29
|
+
exports.fixService = exports.fixInterfaces = exports.parsePerson = exports.formatPerson = exports.fixTags = exports.fixPerson = exports.fixKeywords = exports.fixFiles = exports.fixRepository = exports.fixRequired = void 0;
|
|
30
30
|
const fs_1 = __importDefault(require("fs"));
|
|
31
31
|
const path_1 = __importDefault(require("path"));
|
|
32
32
|
const get_1 = __importDefault(require("lodash/get"));
|
|
@@ -35,7 +35,6 @@ const debug_1 = __importDefault(require("debug"));
|
|
|
35
35
|
const validate_1 = require("./validate");
|
|
36
36
|
Object.defineProperty(exports, "fixService", { enumerable: true, get: function () { return validate_1.fixAndValidateService; } });
|
|
37
37
|
const constants_1 = __importDefault(require("./constants"));
|
|
38
|
-
const name_1 = require("./name");
|
|
39
38
|
const debug = (0, debug_1.default)('@blocklet/meta:fix');
|
|
40
39
|
const { BLOCKLET_DEFAULT_VERSION, BLOCKLET_DEFAULT_PORT_NAME, BLOCKLET_DYNAMIC_PATH_PREFIX, BLOCKLET_INTERFACE_TYPE_WEB, BLOCKLET_INTERFACE_PUBLIC, } = constants_1.default;
|
|
41
40
|
// Assign sensible defaults: description/main/group/version/public_url
|
|
@@ -229,18 +228,6 @@ const fixInterfaces = (meta, removeMerged = true) => {
|
|
|
229
228
|
return meta;
|
|
230
229
|
};
|
|
231
230
|
exports.fixInterfaces = fixInterfaces;
|
|
232
|
-
const fixName = (meta) => {
|
|
233
|
-
const { did } = meta;
|
|
234
|
-
try {
|
|
235
|
-
(0, name_1.validateNewDid)(did);
|
|
236
|
-
meta.name = did;
|
|
237
|
-
}
|
|
238
|
-
catch {
|
|
239
|
-
/* empty */
|
|
240
|
-
}
|
|
241
|
-
return meta;
|
|
242
|
-
};
|
|
243
|
-
exports.fixName = fixName;
|
|
244
231
|
exports.default = {
|
|
245
232
|
fixRequired,
|
|
246
233
|
fixRepository,
|
|
@@ -248,7 +235,6 @@ exports.default = {
|
|
|
248
235
|
fixKeywords,
|
|
249
236
|
fixPerson,
|
|
250
237
|
fixTags,
|
|
251
|
-
fixName,
|
|
252
238
|
formatPerson,
|
|
253
239
|
parsePerson,
|
|
254
240
|
fixInterfaces,
|
package/lib/index.d.ts
CHANGED
|
@@ -6,14 +6,13 @@ import getBlockletWallet from './wallet';
|
|
|
6
6
|
import getBlockletInfo from './info';
|
|
7
7
|
import getBlockletEngine from './engine';
|
|
8
8
|
import { validateMeta, fixAndValidateService } from './validate';
|
|
9
|
-
import { formatPerson, parsePerson, fixPerson, fixInterfaces, fixService
|
|
10
|
-
import { list, select, update
|
|
9
|
+
import { formatPerson, parsePerson, fixPerson, fixInterfaces, fixService } from './fix';
|
|
10
|
+
import { list, select, update } from './file';
|
|
11
11
|
import verifyMultiSig from './verify-multi-sig';
|
|
12
12
|
export { constants };
|
|
13
13
|
export { list };
|
|
14
14
|
export { select };
|
|
15
15
|
export { update };
|
|
16
|
-
export { read };
|
|
17
16
|
export { parse };
|
|
18
17
|
export { validateMeta };
|
|
19
18
|
export { fixAndValidateService };
|
|
@@ -22,7 +21,6 @@ export { parsePerson };
|
|
|
22
21
|
export { fixPerson };
|
|
23
22
|
export { fixInterfaces };
|
|
24
23
|
export { fixService };
|
|
25
|
-
export { fixName };
|
|
26
24
|
export { toBlockletDid };
|
|
27
25
|
export { getBlockletWallet };
|
|
28
26
|
export { getBlockletInfo };
|
|
@@ -37,7 +35,6 @@ declare const _default: {
|
|
|
37
35
|
update: (file: string, meta: import("./types").TBlockletMeta, { fix }?: {
|
|
38
36
|
fix?: boolean;
|
|
39
37
|
}) => void;
|
|
40
|
-
read: (file: string) => unknown;
|
|
41
38
|
parse: (dir: string, { ensureMain, ensureFiles, ensureDist, ensureComponentStore, extraRawAttrs, schemaOptions, defaultStoreUrl, fix, }?: {
|
|
42
39
|
ensureMain?: boolean;
|
|
43
40
|
ensureFiles?: boolean;
|
|
@@ -62,7 +59,6 @@ declare const _default: {
|
|
|
62
59
|
parsePerson: (person: string) => any;
|
|
63
60
|
fixPerson: (data: any) => any;
|
|
64
61
|
fixInterfaces: (meta: any, removeMerged?: boolean) => any;
|
|
65
|
-
fixName: (meta: any) => any;
|
|
66
62
|
fixService: (meta: import("./types").TBlockletMeta) => import("./types").TBlockletMeta;
|
|
67
63
|
toBlockletDid: {
|
|
68
64
|
(name: string | Buffer): string;
|
|
@@ -74,7 +70,7 @@ declare const _default: {
|
|
|
74
70
|
name: string;
|
|
75
71
|
};
|
|
76
72
|
};
|
|
77
|
-
getBlockletWallet: (blockletDid: string, nodeSk?: string, type?:
|
|
73
|
+
getBlockletWallet: (blockletDid: string, nodeSk?: string, type?: import("@arcblock/did").DIDType, index?: number) => import("@ocap/wallet").WalletObject<string>;
|
|
78
74
|
getBlockletInfo: (state: import("@abtnode/client").BlockletState, nodeSk?: string, { returnWallet }?: {
|
|
79
75
|
returnWallet?: boolean;
|
|
80
76
|
}) => {
|
|
@@ -85,7 +81,6 @@ declare const _default: {
|
|
|
85
81
|
passportColor?: string;
|
|
86
82
|
appUrl: string;
|
|
87
83
|
wallet?: import("@ocap/wallet").WalletObject<string>;
|
|
88
|
-
permanentWallet?: import("@ocap/wallet").WalletObject<string>;
|
|
89
84
|
};
|
|
90
85
|
getBlockletEngine: (meta: import("./types").TBlockletMeta) => import("./types").TEngine;
|
|
91
86
|
verifyMultiSig: (blockletMeta: import("./types").TBlockletMeta) => boolean;
|
package/lib/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.verifyMultiSig = exports.getBlockletEngine = exports.getBlockletInfo = exports.getBlockletWallet = exports.toBlockletDid = exports.
|
|
6
|
+
exports.verifyMultiSig = exports.getBlockletEngine = exports.getBlockletInfo = exports.getBlockletWallet = exports.toBlockletDid = exports.fixService = exports.fixInterfaces = exports.fixPerson = exports.parsePerson = exports.formatPerson = exports.fixAndValidateService = exports.validateMeta = exports.parse = exports.update = exports.select = exports.list = exports.constants = void 0;
|
|
7
7
|
const constants_1 = __importDefault(require("./constants"));
|
|
8
8
|
exports.constants = constants_1.default;
|
|
9
9
|
const parse_1 = __importDefault(require("./parse"));
|
|
@@ -25,12 +25,10 @@ Object.defineProperty(exports, "parsePerson", { enumerable: true, get: function
|
|
|
25
25
|
Object.defineProperty(exports, "fixPerson", { enumerable: true, get: function () { return fix_1.fixPerson; } });
|
|
26
26
|
Object.defineProperty(exports, "fixInterfaces", { enumerable: true, get: function () { return fix_1.fixInterfaces; } });
|
|
27
27
|
Object.defineProperty(exports, "fixService", { enumerable: true, get: function () { return fix_1.fixService; } });
|
|
28
|
-
Object.defineProperty(exports, "fixName", { enumerable: true, get: function () { return fix_1.fixName; } });
|
|
29
28
|
const file_1 = require("./file");
|
|
30
29
|
Object.defineProperty(exports, "list", { enumerable: true, get: function () { return file_1.list; } });
|
|
31
30
|
Object.defineProperty(exports, "select", { enumerable: true, get: function () { return file_1.select; } });
|
|
32
31
|
Object.defineProperty(exports, "update", { enumerable: true, get: function () { return file_1.update; } });
|
|
33
|
-
Object.defineProperty(exports, "read", { enumerable: true, get: function () { return file_1.read; } });
|
|
34
32
|
const verify_multi_sig_1 = __importDefault(require("./verify-multi-sig"));
|
|
35
33
|
exports.verifyMultiSig = verify_multi_sig_1.default;
|
|
36
34
|
exports.default = {
|
|
@@ -38,7 +36,6 @@ exports.default = {
|
|
|
38
36
|
list: file_1.list,
|
|
39
37
|
select: file_1.select,
|
|
40
38
|
update: file_1.update,
|
|
41
|
-
read: file_1.read,
|
|
42
39
|
parse: parse_1.default,
|
|
43
40
|
validateMeta: validate_1.validateMeta,
|
|
44
41
|
fixAndValidateService: validate_1.fixAndValidateService,
|
|
@@ -46,7 +43,6 @@ exports.default = {
|
|
|
46
43
|
parsePerson: fix_1.parsePerson,
|
|
47
44
|
fixPerson: fix_1.fixPerson,
|
|
48
45
|
fixInterfaces: fix_1.fixInterfaces,
|
|
49
|
-
fixName: fix_1.fixName,
|
|
50
46
|
fixService: fix_1.fixService,
|
|
51
47
|
toBlockletDid: did_1.default,
|
|
52
48
|
getBlockletWallet: wallet_1.default,
|
package/lib/info.d.ts
CHANGED
package/lib/info.js
CHANGED
|
@@ -30,18 +30,16 @@ const getBlockletInfo = (state, nodeSk, { returnWallet = true } = {}) => {
|
|
|
30
30
|
}
|
|
31
31
|
const customSk = envs.find((x) => x.key === 'BLOCKLET_APP_SK');
|
|
32
32
|
const customType = envs.find((x) => x.key === 'BLOCKLET_WALLET_TYPE');
|
|
33
|
-
const permanentSk = envs.find((x) => x.key === 'BLOCKLET_APP_PSK');
|
|
34
33
|
let type;
|
|
35
34
|
if (customType && customType.value === 'eth') {
|
|
36
35
|
type = customType.value;
|
|
37
36
|
}
|
|
38
37
|
let wallet = null;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
38
|
+
if (customSk && customSk.value && customType) {
|
|
39
|
+
wallet = (0, wallet_1.default)(customSk.value, null, type);
|
|
40
|
+
}
|
|
41
|
+
else if (customSk && customSk.value) {
|
|
42
|
+
wallet = (0, wallet_1.default)(customSk.value);
|
|
45
43
|
}
|
|
46
44
|
else {
|
|
47
45
|
if (!nodeSk || typeof nodeSk !== 'string') {
|
|
@@ -62,7 +60,6 @@ const getBlockletInfo = (state, nodeSk, { returnWallet = true } = {}) => {
|
|
|
62
60
|
passportColor,
|
|
63
61
|
appUrl,
|
|
64
62
|
wallet,
|
|
65
|
-
permanentWallet: permanentWallet || wallet,
|
|
66
63
|
};
|
|
67
64
|
};
|
|
68
65
|
module.exports = getBlockletInfo;
|
package/lib/name.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 检查一个 did 是否为新版 blocklet-did(这里只需要判断是否为 ROLE_BLOCKLET 即可)
|
|
3
|
-
* @param did 需要检查是否为新版 did 的值
|
|
4
|
-
*/
|
|
5
|
-
export declare const validateNewDid: (did: string) => void;
|
|
6
1
|
export declare const validateName: (name: string) => void;
|
|
7
2
|
declare const _default: {
|
|
8
3
|
validateName: (name: string) => void;
|
|
9
|
-
validateNewDid: (did: string) => void;
|
|
10
4
|
};
|
|
11
5
|
export default _default;
|
package/lib/name.js
CHANGED
|
@@ -3,39 +3,15 @@ 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.validateName =
|
|
7
|
-
const did_1 = require("@arcblock/did");
|
|
6
|
+
exports.validateName = void 0;
|
|
8
7
|
const validate_npm_package_name_1 = __importDefault(require("validate-npm-package-name"));
|
|
9
|
-
const MAX_NAME_LENGTH = 32;
|
|
10
|
-
/**
|
|
11
|
-
* 检查一个 did 是否为新版 blocklet-did(这里只需要判断是否为 ROLE_BLOCKLET 即可)
|
|
12
|
-
* @param did 需要检查是否为新版 did 的值
|
|
13
|
-
*/
|
|
14
|
-
const validateNewDid = (did) => {
|
|
15
|
-
const typeInfo = (0, did_1.toTypeInfo)(did);
|
|
16
|
-
if (typeInfo.role !== did_1.types.RoleType.ROLE_BLOCKLET) {
|
|
17
|
-
throw new Error("Blocklet DID's type must be ROLE_BLOCKLET");
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
exports.validateNewDid = validateNewDid;
|
|
21
8
|
const validateName = (name) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
(0
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
// old did mode
|
|
28
|
-
const { validForNewPackages, errors = [], warnings = [] } = (0, validate_npm_package_name_1.default)(name);
|
|
29
|
-
if (!validForNewPackages) {
|
|
30
|
-
throw new Error(errors[0] || warnings[0]);
|
|
31
|
-
}
|
|
32
|
-
if (name.length > MAX_NAME_LENGTH) {
|
|
33
|
-
throw new Error('Blocklet name is too long');
|
|
34
|
-
}
|
|
9
|
+
const { validForNewPackages, errors = [], warnings = [] } = (0, validate_npm_package_name_1.default)(name);
|
|
10
|
+
if (!validForNewPackages) {
|
|
11
|
+
throw new Error(errors[0] || warnings[0]);
|
|
35
12
|
}
|
|
36
13
|
};
|
|
37
14
|
exports.validateName = validateName;
|
|
38
15
|
exports.default = {
|
|
39
16
|
validateName: exports.validateName,
|
|
40
|
-
validateNewDid: exports.validateNewDid,
|
|
41
17
|
};
|
|
@@ -74,13 +74,13 @@ function tryParseItem(item) {
|
|
|
74
74
|
try {
|
|
75
75
|
return JSON.parse(item);
|
|
76
76
|
}
|
|
77
|
-
catch {
|
|
77
|
+
catch (_a) {
|
|
78
78
|
return item;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
function normalizeNavigationList(navigationList) {
|
|
82
82
|
return navigationList.map((item) => {
|
|
83
|
-
const tempData = {
|
|
83
|
+
const tempData = Object.assign({}, item);
|
|
84
84
|
if (tempData.role) {
|
|
85
85
|
tempData.role = tryParseItem(tempData.role);
|
|
86
86
|
}
|
|
@@ -209,10 +209,11 @@ function parseBlockletNavigationList(blocklet = {}) {
|
|
|
209
209
|
* @returns
|
|
210
210
|
*/
|
|
211
211
|
function genNavigationListByBlocklet(current, parent = {}) {
|
|
212
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
212
213
|
const targetList = [];
|
|
213
214
|
const { children = [], meta = {} } = current;
|
|
214
|
-
const navigation = (0, cloneDeep_1.default)(meta
|
|
215
|
-
if (current.meta
|
|
215
|
+
const navigation = (0, cloneDeep_1.default)((meta === null || meta === void 0 ? void 0 : meta.navigation) || []);
|
|
216
|
+
if (((_b = (_a = current.meta) === null || _a === void 0 ? void 0 : _a.capabilities) === null || _b === void 0 ? void 0 : _b.navigation) !== false) {
|
|
216
217
|
targetList.push(...navigation);
|
|
217
218
|
}
|
|
218
219
|
const parentName = parent.name || '';
|
|
@@ -225,17 +226,15 @@ function parseBlockletNavigationList(blocklet = {}) {
|
|
|
225
226
|
const mergeName = [parentName, currentName, childName].filter(Boolean).join('.');
|
|
226
227
|
const childNavigation = child.meta.navigation || [];
|
|
227
228
|
const mergeBase = (0, url_join_1.default)(parentBase, currentBase, childBase);
|
|
228
|
-
if (child.meta
|
|
229
|
+
if (((_d = (_c = child.meta) === null || _c === void 0 ? void 0 : _c.capabilities) === null || _d === void 0 ? void 0 : _d.navigation) !== false) {
|
|
229
230
|
components.push({
|
|
230
231
|
did: child.meta.did,
|
|
231
232
|
name: mergeName,
|
|
232
233
|
link: mergeBase,
|
|
233
234
|
title: child.meta.title || '',
|
|
234
|
-
navigation: childNavigation.map((item) => ({
|
|
235
|
+
navigation: childNavigation.map((item) => (Object.assign({
|
|
235
236
|
// 给每个 navigation 赋予一个 setion,用于在 autocomplete 提供依据 section 筛选的基础
|
|
236
|
-
section: DEFAULT_SECTION,
|
|
237
|
-
...item,
|
|
238
|
-
})),
|
|
237
|
+
section: DEFAULT_SECTION }, item))),
|
|
239
238
|
});
|
|
240
239
|
}
|
|
241
240
|
// 在现有的 navigation 中判断是否存在 children
|
|
@@ -251,7 +250,7 @@ function parseBlockletNavigationList(blocklet = {}) {
|
|
|
251
250
|
if (child.meta.navigation && child.meta.navigation.length > 0) {
|
|
252
251
|
const items = genNavigationListByBlocklet(child, { mountPoint: currentBase, name: currentName });
|
|
253
252
|
if (items.length > 0) {
|
|
254
|
-
matchNavigation.items = matchNavigation.items
|
|
253
|
+
matchNavigation.items = (_e = matchNavigation.items) !== null && _e !== void 0 ? _e : [];
|
|
255
254
|
matchNavigation.items.push(...items);
|
|
256
255
|
}
|
|
257
256
|
}
|
|
@@ -260,7 +259,7 @@ function parseBlockletNavigationList(blocklet = {}) {
|
|
|
260
259
|
}
|
|
261
260
|
}
|
|
262
261
|
}
|
|
263
|
-
else if (child.meta
|
|
262
|
+
else if (((_g = (_f = child.meta) === null || _f === void 0 ? void 0 : _f.capabilities) === null || _g === void 0 ? void 0 : _g.navigation) !== false) {
|
|
264
263
|
const childItems = genNavigationListByBlocklet(child, { mountPoint: currentBase, name: currentName });
|
|
265
264
|
// 否则动态注入一个 navigation
|
|
266
265
|
const tmpData = {
|
|
@@ -290,6 +289,7 @@ function parseBlockletNavigationList(blocklet = {}) {
|
|
|
290
289
|
function patchBuiltinNavigation(navigation) {
|
|
291
290
|
const copyNavigation = (0, cloneDeep_1.default)(navigation).filter((item) => item.id);
|
|
292
291
|
deepWalk(copyNavigation, (item, parent) => {
|
|
292
|
+
var _a;
|
|
293
293
|
if (item.items && item.items.length) {
|
|
294
294
|
for (let i = item.items.length - 1; i >= 0; i--) {
|
|
295
295
|
if (!item.items[i].id) {
|
|
@@ -309,7 +309,7 @@ function patchBuiltinNavigation(navigation) {
|
|
|
309
309
|
item.id = [parent.id, item.id].join(ID_SEPARATE);
|
|
310
310
|
}
|
|
311
311
|
item.from = item.from || 'yaml';
|
|
312
|
-
item.visible = item.visible
|
|
312
|
+
item.visible = (_a = item.visible) !== null && _a !== void 0 ? _a : true;
|
|
313
313
|
}, { key: 'items' });
|
|
314
314
|
return copyNavigation;
|
|
315
315
|
}
|
|
@@ -324,6 +324,7 @@ function compactNavigation(navigation, depth = 2) {
|
|
|
324
324
|
const resData = flatternNavigation(copyNavigation, {
|
|
325
325
|
depth,
|
|
326
326
|
transform: (item, parent) => {
|
|
327
|
+
var _a;
|
|
327
328
|
if (parent) {
|
|
328
329
|
if (!item._parent) {
|
|
329
330
|
item._parent = parent.id;
|
|
@@ -332,7 +333,7 @@ function compactNavigation(navigation, depth = 2) {
|
|
|
332
333
|
}
|
|
333
334
|
}
|
|
334
335
|
item.section = item.section || parent.section || [DEFAULT_SECTION];
|
|
335
|
-
item.visible = item.visible
|
|
336
|
+
item.visible = (_a = item.visible) !== null && _a !== void 0 ? _a : parent.visible;
|
|
336
337
|
}
|
|
337
338
|
item.component = [parent.component, item.component].filter(Boolean).join('.');
|
|
338
339
|
return item;
|
|
@@ -373,7 +374,7 @@ function getNavigationListBySection(navigationItem, section) {
|
|
|
373
374
|
}
|
|
374
375
|
return false;
|
|
375
376
|
})
|
|
376
|
-
.map((item) => ({
|
|
377
|
+
.map((item) => (Object.assign(Object.assign({}, item), { section })));
|
|
377
378
|
}
|
|
378
379
|
return [];
|
|
379
380
|
}
|
|
@@ -391,11 +392,7 @@ function splitNavigationBySection(navigation) {
|
|
|
391
392
|
// eslint-disable-next-line no-inner-declarations
|
|
392
393
|
function patchNavigationItem(item, section) {
|
|
393
394
|
const sectionNavigationList = getNavigationListBySection(item, section);
|
|
394
|
-
itemNavigationList.push({
|
|
395
|
-
...baseNavigation,
|
|
396
|
-
section,
|
|
397
|
-
items: sectionNavigationList,
|
|
398
|
-
});
|
|
395
|
+
itemNavigationList.push(Object.assign(Object.assign({}, baseNavigation), { section, items: sectionNavigationList }));
|
|
399
396
|
}
|
|
400
397
|
if (Array.isArray(navigationItem.section)) {
|
|
401
398
|
for (const section of navigationItem.section) {
|
|
@@ -418,10 +415,7 @@ function splitNavigationBySection(navigation) {
|
|
|
418
415
|
}
|
|
419
416
|
}
|
|
420
417
|
else {
|
|
421
|
-
itemNavigationList.push({
|
|
422
|
-
...navigationItem,
|
|
423
|
-
section: DEFAULT_SECTION,
|
|
424
|
-
});
|
|
418
|
+
itemNavigationList.push(Object.assign(Object.assign({}, navigationItem), { section: DEFAULT_SECTION }));
|
|
425
419
|
}
|
|
426
420
|
allNavigationList.push(...itemNavigationList);
|
|
427
421
|
}
|
|
@@ -459,7 +453,7 @@ exports.nestNavigationList = nestNavigationList;
|
|
|
459
453
|
function filterNavigation(navigationList, components = []) {
|
|
460
454
|
const nestedNavigation = nestNavigationList(navigationList);
|
|
461
455
|
deepWalk(nestedNavigation, (item) => {
|
|
462
|
-
if (item
|
|
456
|
+
if (item === null || item === void 0 ? void 0 : item.component) {
|
|
463
457
|
if (!components.some((x) => x.name === item.component)) {
|
|
464
458
|
item.visible = false;
|
|
465
459
|
}
|
|
@@ -473,13 +467,14 @@ function filterNavigation(navigationList, components = []) {
|
|
|
473
467
|
}
|
|
474
468
|
}, { key: 'items' });
|
|
475
469
|
const filteredNavigation = nestedNavigation.filter((item) => {
|
|
470
|
+
var _a;
|
|
476
471
|
if (item.visible === false)
|
|
477
472
|
return false;
|
|
478
473
|
// 如果某一菜单的 子菜单 均为隐藏状态,则一级菜单本身也不显示出来
|
|
479
474
|
if (item.items &&
|
|
480
475
|
Array.isArray(item.items) &&
|
|
481
476
|
item.items.length > 0 &&
|
|
482
|
-
item.items
|
|
477
|
+
((_a = item.items) === null || _a === void 0 ? void 0 : _a.every((v) => v.visible === false)))
|
|
483
478
|
return false;
|
|
484
479
|
return true;
|
|
485
480
|
});
|
|
@@ -499,9 +494,10 @@ function cleanOrphanNavigation(list) {
|
|
|
499
494
|
}
|
|
500
495
|
exports.cleanOrphanNavigation = cleanOrphanNavigation;
|
|
501
496
|
function parseNavigation(blocklet = {}, options = {}) {
|
|
497
|
+
var _a;
|
|
502
498
|
const { beforeProcess = (v) => v } = options;
|
|
503
499
|
const { navigationList: builtinNavigation, components } = parseBlockletNavigationList(blocklet);
|
|
504
|
-
const customNavigationList = blocklet
|
|
500
|
+
const customNavigationList = ((_a = blocklet === null || blocklet === void 0 ? void 0 : blocklet.settings) === null || _a === void 0 ? void 0 : _a.navigations) || [];
|
|
505
501
|
const compactedNavigation = compactNavigation(beforeProcess(builtinNavigation));
|
|
506
502
|
const patchedNavigation = patchBuiltinNavigation(compactedNavigation);
|
|
507
503
|
const splitNavigation = splitNavigationBySection(patchedNavigation);
|
|
@@ -513,7 +509,7 @@ function parseNavigation(blocklet = {}, options = {}) {
|
|
|
513
509
|
const { section } = cur;
|
|
514
510
|
const link = smartJoinLink(cur.link, x.link);
|
|
515
511
|
const component = [cur.component, x.component].filter(Boolean).join('.');
|
|
516
|
-
return {
|
|
512
|
+
return Object.assign(Object.assign({}, x), { section, link, component, parent: '' });
|
|
517
513
|
}));
|
|
518
514
|
return all;
|
|
519
515
|
}
|
|
@@ -524,10 +520,10 @@ function parseNavigation(blocklet = {}, options = {}) {
|
|
|
524
520
|
const flatNavigation = flatternNavigation(levelUpNavigation, {
|
|
525
521
|
transform(item, parent) {
|
|
526
522
|
let { component } = item;
|
|
527
|
-
if (parent
|
|
523
|
+
if (parent === null || parent === void 0 ? void 0 : parent.component) {
|
|
528
524
|
component = [parent.component, item.component].filter(Boolean).join('.');
|
|
529
525
|
}
|
|
530
|
-
return {
|
|
526
|
+
return Object.assign(Object.assign({}, item), { component });
|
|
531
527
|
},
|
|
532
528
|
});
|
|
533
529
|
const rawNavigation = (0, unionWith_1.default)(normalizeNavigationList(customNavigationList), flatNavigation, (prev, next) => {
|
package/lib/parse-navigation.js
CHANGED
|
@@ -24,9 +24,7 @@ const getGroups = (navigation) => {
|
|
|
24
24
|
if (!groups[sec]) {
|
|
25
25
|
groups[sec] = [];
|
|
26
26
|
}
|
|
27
|
-
const item = {
|
|
28
|
-
...nav,
|
|
29
|
-
};
|
|
27
|
+
const item = Object.assign({}, nav);
|
|
30
28
|
if (nav.section) {
|
|
31
29
|
item.section = sec === '__undefined__' ? [] : [sec];
|
|
32
30
|
}
|
|
@@ -39,8 +37,9 @@ const getChildName = (nav) => nav.component || nav.child;
|
|
|
39
37
|
const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
40
38
|
const result = [];
|
|
41
39
|
(navigation || []).forEach((nav) => {
|
|
40
|
+
var _a, _b;
|
|
42
41
|
if (!getChildName(nav)) {
|
|
43
|
-
if (_level > 1 && nav.items
|
|
42
|
+
if (_level > 1 && ((_a = nav.items) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
44
43
|
const list = doParseNavigation(nav.items, blocklet, prefix, _level + 1);
|
|
45
44
|
result.push(...list);
|
|
46
45
|
return;
|
|
@@ -64,7 +63,7 @@ const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
|
64
63
|
if (nav.role) {
|
|
65
64
|
item.role = nav.role;
|
|
66
65
|
}
|
|
67
|
-
if (nav.items
|
|
66
|
+
if ((_b = nav.items) === null || _b === void 0 ? void 0 : _b.length) {
|
|
68
67
|
const list = doParseNavigation(nav.items, blocklet, prefix, _level + 1);
|
|
69
68
|
if (list.length) {
|
|
70
69
|
item.items = list;
|
|
@@ -125,10 +124,7 @@ const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
|
125
124
|
if (list.length > 1) {
|
|
126
125
|
// more than 1 child nav
|
|
127
126
|
delete item.link;
|
|
128
|
-
result.push({
|
|
129
|
-
...item,
|
|
130
|
-
items: list,
|
|
131
|
-
});
|
|
127
|
+
result.push(Object.assign(Object.assign({}, item), { items: list }));
|
|
132
128
|
}
|
|
133
129
|
else {
|
|
134
130
|
// only 1 child nav
|
|
@@ -147,10 +143,7 @@ const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
|
147
143
|
item.section = item.section || groupSection;
|
|
148
144
|
}
|
|
149
145
|
item.items = list;
|
|
150
|
-
result.push({
|
|
151
|
-
...item,
|
|
152
|
-
items: list,
|
|
153
|
-
});
|
|
146
|
+
result.push(Object.assign(Object.assign({}, item), { items: list }));
|
|
154
147
|
}
|
|
155
148
|
else {
|
|
156
149
|
// secondary menu
|