@blocklet/meta 1.8.54 → 1.8.56
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/index.d.ts +5 -3
- package/lib/parse.d.ts +4 -4
- package/lib/parse.js +21 -9
- package/lib/schema.d.ts +4 -2
- package/lib/schema.js +21 -10
- package/lib/types/schema.d.ts +26 -2
- package/lib/validate.d.ts +2 -1
- package/lib/validate.js +5 -2
- package/package.json +6 -6
package/lib/index.d.ts
CHANGED
|
@@ -35,21 +35,23 @@ declare const _default: {
|
|
|
35
35
|
update: (file: string, meta: import("./types").TBlockletMeta, { fix }?: {
|
|
36
36
|
fix?: boolean;
|
|
37
37
|
}) => void;
|
|
38
|
-
parse: (dir: string, { ensureMain, ensureFiles, ensureDist,
|
|
38
|
+
parse: (dir: string, { ensureMain, ensureFiles, ensureDist, ensureComponentStore, extraRawAttrs, schemaOptions, defaultStoreUrl, fix, }?: {
|
|
39
39
|
ensureMain?: boolean;
|
|
40
40
|
ensureFiles?: boolean;
|
|
41
41
|
ensureDist?: boolean;
|
|
42
|
+
ensureComponentStore?: boolean;
|
|
42
43
|
extraRawAttrs?: any;
|
|
43
|
-
serviceMetas?: any;
|
|
44
44
|
schemaOptions?: any;
|
|
45
45
|
enableDefaults?: boolean;
|
|
46
46
|
extraAttrSpec?: any;
|
|
47
|
+
defaultStoreUrl?: string | ((component: import("./types").TComponent) => string);
|
|
47
48
|
fix?: boolean;
|
|
48
49
|
}) => import("./types").TBlockletMeta;
|
|
49
|
-
validateMeta: (meta: any, { ensureMain, ensureFiles, ensureDist, schemaOptions, }?: {
|
|
50
|
+
validateMeta: (meta: any, { ensureMain, ensureFiles, ensureDist, ensureComponentStore, schemaOptions, }?: {
|
|
50
51
|
ensureMain?: boolean;
|
|
51
52
|
ensureFiles?: boolean;
|
|
52
53
|
ensureDist?: boolean;
|
|
54
|
+
ensureComponentStore?: boolean;
|
|
53
55
|
schemaOptions?: any;
|
|
54
56
|
}) => import("./types").TBlockletMeta;
|
|
55
57
|
fixAndValidateService: (meta: import("./types").TBlockletMeta) => import("./types").TBlockletMeta;
|
package/lib/parse.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TBlockletMeta } from './types';
|
|
1
|
+
import { TBlockletMeta, TComponent } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Get blocklet meta from blocklet.yml
|
|
4
4
|
* @param {string} dir blocklet directory
|
|
@@ -6,17 +6,17 @@ import { TBlockletMeta } from './types';
|
|
|
6
6
|
* @param {boolean} options.ensureMain should we verify that main exists
|
|
7
7
|
* @param {boolean} options.ensureDist should we verify that dist exists
|
|
8
8
|
* @param {boolean} options.ensureFiles should we verify that logo and files exists
|
|
9
|
-
* @param {Array} options.serviceMetas should we verify that each service is validate (using JSON Schema defined serviceMetas)
|
|
10
9
|
*/
|
|
11
|
-
declare const parse: (dir: string, { ensureMain, ensureFiles, ensureDist,
|
|
10
|
+
declare const parse: (dir: string, { ensureMain, ensureFiles, ensureDist, ensureComponentStore, extraRawAttrs, schemaOptions, defaultStoreUrl, fix, }?: {
|
|
12
11
|
ensureMain?: boolean;
|
|
13
12
|
ensureFiles?: boolean;
|
|
14
13
|
ensureDist?: boolean;
|
|
14
|
+
ensureComponentStore?: boolean;
|
|
15
15
|
extraRawAttrs?: any;
|
|
16
|
-
serviceMetas?: any;
|
|
17
16
|
schemaOptions?: any;
|
|
18
17
|
enableDefaults?: boolean;
|
|
19
18
|
extraAttrSpec?: any;
|
|
19
|
+
defaultStoreUrl?: string | ((component: TComponent) => string);
|
|
20
20
|
fix?: boolean;
|
|
21
21
|
}) => TBlockletMeta;
|
|
22
22
|
export = parse;
|
package/lib/parse.js
CHANGED
|
@@ -6,6 +6,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
6
6
|
const path_1 = __importDefault(require("path"));
|
|
7
7
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
8
8
|
const camelCase_1 = __importDefault(require("lodash/camelCase"));
|
|
9
|
+
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
9
10
|
const debug_1 = __importDefault(require("debug"));
|
|
10
11
|
const constants_1 = __importDefault(require("./constants"));
|
|
11
12
|
const schema_1 = require("./schema");
|
|
@@ -19,15 +20,15 @@ const { BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT } = constants_1.default;
|
|
|
19
20
|
* @param {boolean} options.ensureMain should we verify that main exists
|
|
20
21
|
* @param {boolean} options.ensureDist should we verify that dist exists
|
|
21
22
|
* @param {boolean} options.ensureFiles should we verify that logo and files exists
|
|
22
|
-
* @param {Array} options.serviceMetas should we verify that each service is validate (using JSON Schema defined serviceMetas)
|
|
23
23
|
*/
|
|
24
|
-
const parse = (dir, { ensureMain = false, ensureFiles = false, ensureDist = false, extraRawAttrs = {},
|
|
25
|
-
|
|
24
|
+
const parse = (dir, { ensureMain = false, ensureFiles = false, ensureDist = false, ensureComponentStore = true, extraRawAttrs = {}, schemaOptions = {}, defaultStoreUrl, fix = true, } = {}) => {
|
|
25
|
+
var _a;
|
|
26
|
+
let result;
|
|
26
27
|
const blockletMetaFile = path_1.default.join(dir, BLOCKLET_META_FILE);
|
|
27
28
|
const blockletMetaFileAlt = path_1.default.join(dir, BLOCKLET_META_FILE_ALT);
|
|
28
29
|
if (fs_1.default.existsSync(blockletMetaFile)) {
|
|
29
30
|
try {
|
|
30
|
-
result =
|
|
31
|
+
result = js_yaml_1.default.load(fs_1.default.readFileSync(blockletMetaFile).toString(), { json: true });
|
|
31
32
|
debug(`parse ${blockletMetaFile}`, result);
|
|
32
33
|
}
|
|
33
34
|
catch (err) {
|
|
@@ -36,7 +37,7 @@ const parse = (dir, { ensureMain = false, ensureFiles = false, ensureDist = fals
|
|
|
36
37
|
}
|
|
37
38
|
else if (fs_1.default.existsSync(blockletMetaFileAlt)) {
|
|
38
39
|
try {
|
|
39
|
-
result = Object.assign(
|
|
40
|
+
result = Object.assign({}, js_yaml_1.default.load(fs_1.default.readFileSync(blockletMetaFileAlt).toString(), { json: true }));
|
|
40
41
|
debug(`parse ${blockletMetaFileAlt}`, result);
|
|
41
42
|
}
|
|
42
43
|
catch (err) {
|
|
@@ -61,9 +62,16 @@ const parse = (dir, { ensureMain = false, ensureFiles = false, ensureDist = fals
|
|
|
61
62
|
(0, fix_1.fixKeywords)(result);
|
|
62
63
|
(0, fix_1.fixTags)(result);
|
|
63
64
|
(0, fix_1.fixPerson)(result);
|
|
64
|
-
|
|
65
|
-
(0
|
|
66
|
-
|
|
65
|
+
(0, fix_1.fixService)(result);
|
|
66
|
+
if (defaultStoreUrl && ((_a = result.components) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
67
|
+
result.components.forEach((x) => {
|
|
68
|
+
if ('name' in x.source) {
|
|
69
|
+
if (!x.source.store) {
|
|
70
|
+
x.source.store = typeof defaultStoreUrl === 'function' ? defaultStoreUrl((0, cloneDeep_1.default)(x)) : defaultStoreUrl;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
67
75
|
// We will overwrite did anyway
|
|
68
76
|
result.path = `/${result.group}/${result.name}`;
|
|
69
77
|
// Ensure camelCase
|
|
@@ -71,8 +79,12 @@ const parse = (dir, { ensureMain = false, ensureFiles = false, ensureDist = fals
|
|
|
71
79
|
acc[(0, camelCase_1.default)(k)] = result[k];
|
|
72
80
|
return acc;
|
|
73
81
|
}, {});
|
|
82
|
+
debug('fix', result);
|
|
74
83
|
// Validate and cleanup
|
|
75
|
-
const schema = (0, schema_1.createBlockletSchema)(dir, Object.assign({ ensureMain,
|
|
84
|
+
const schema = (0, schema_1.createBlockletSchema)(dir, Object.assign({ ensureMain,
|
|
85
|
+
ensureFiles,
|
|
86
|
+
ensureDist,
|
|
87
|
+
ensureComponentStore }, schemaOptions));
|
|
76
88
|
const { value, error } = schema.validate(result);
|
|
77
89
|
if (error) {
|
|
78
90
|
throw new Error(`Invalid blocklet.yml: ${error.details.map((x) => x.message).join(', ')}`);
|
package/lib/schema.d.ts
CHANGED
|
@@ -21,10 +21,11 @@ declare const navigationSchema: JOI.ArraySchema<any[]>;
|
|
|
21
21
|
declare const themeSchema: JOI.ObjectSchema<any>;
|
|
22
22
|
declare const authConfigSchema: JOI.ObjectSchema<any>;
|
|
23
23
|
declare const blockletMetaSchema: JOI.ObjectSchema<any>;
|
|
24
|
-
declare const createBlockletSchema: (baseDir: string, { ensureMain, ensureFiles, ensureDist, ...schemaOptions }?: {
|
|
24
|
+
declare const createBlockletSchema: (baseDir: string, { ensureMain, ensureFiles, ensureDist, ensureComponentStore, ...schemaOptions }?: {
|
|
25
25
|
ensureMain?: boolean;
|
|
26
26
|
ensureFiles?: boolean;
|
|
27
27
|
ensureDist?: boolean;
|
|
28
|
+
ensureComponentStore?: boolean;
|
|
28
29
|
}) => JOI.ObjectSchema;
|
|
29
30
|
export { blockletMetaSchema, blockletNameSchema, componentSchema, createBlockletSchema, descriptionSchema, distSchema, endpointSchema, engineSchema, environmentSchema, environmentNameSchema, interfaceSchema, logoSchema, mountPointSchema, navigationItemSchema, navigationSchema, personSchema, scriptsSchema, serviceSchema, signatureSchema, themeSchema, titleSchema, statsSchema, authConfigSchema, };
|
|
30
31
|
declare const _default: {
|
|
@@ -32,10 +33,11 @@ declare const _default: {
|
|
|
32
33
|
componentSchema: JOI.ObjectSchema<any>;
|
|
33
34
|
endpointSchema: JOI.ObjectSchema<any>;
|
|
34
35
|
serviceSchema: JOI.ObjectSchema<any>;
|
|
35
|
-
createBlockletSchema: (baseDir: string, { ensureMain, ensureFiles, ensureDist, ...schemaOptions }?: {
|
|
36
|
+
createBlockletSchema: (baseDir: string, { ensureMain, ensureFiles, ensureDist, ensureComponentStore, ...schemaOptions }?: {
|
|
36
37
|
ensureMain?: boolean;
|
|
37
38
|
ensureFiles?: boolean;
|
|
38
39
|
ensureDist?: boolean;
|
|
40
|
+
ensureComponentStore?: boolean;
|
|
39
41
|
}) => JOI.ObjectSchema<any>;
|
|
40
42
|
interfaceSchema: JOI.ObjectSchema<any>;
|
|
41
43
|
environmentSchema: JOI.ObjectSchema<any>;
|
package/lib/schema.js
CHANGED
|
@@ -259,16 +259,17 @@ const statsSchema = Joi.object({
|
|
|
259
259
|
unknownType: 'any',
|
|
260
260
|
});
|
|
261
261
|
exports.statsSchema = statsSchema;
|
|
262
|
-
const
|
|
262
|
+
const urlListSchema = Joi.alternatives().try(Joi.string().uri(), Joi.array().items(Joi.string().uri()).min(1));
|
|
263
|
+
const componentSchemaProps = {
|
|
263
264
|
name: blockletNameSchema.required(),
|
|
264
265
|
title: titleSchema,
|
|
265
266
|
description: descriptionSchema,
|
|
266
267
|
mountPoint: mountPointSchema,
|
|
267
268
|
services: Joi.array().items(serviceSchema).unique('name'),
|
|
268
269
|
source: Joi.alternatives().try(Joi.object({
|
|
269
|
-
url:
|
|
270
|
+
url: urlListSchema.required(),
|
|
270
271
|
}), Joi.object({
|
|
271
|
-
store:
|
|
272
|
+
store: urlListSchema,
|
|
272
273
|
name: blockletNameSchema.required(),
|
|
273
274
|
// TODO 目前只能支持锁死的版本号,接下载需要支持自适应的版本号,比如 4.x
|
|
274
275
|
version: Joi.alternatives().try(Joi.string().valid('latest'), Joi.semver().valid()).default('latest'),
|
|
@@ -286,8 +287,8 @@ const componentSchema = Joi.object({
|
|
|
286
287
|
services: Joi.array().items(serviceSchema).unique('name'),
|
|
287
288
|
}))
|
|
288
289
|
.optional(),
|
|
289
|
-
}
|
|
290
|
-
|
|
290
|
+
};
|
|
291
|
+
const createComponentSchema = (allowEmptyStore) => Joi.object(componentSchemaProps).custom((value, helper) => {
|
|
291
292
|
if (!value.mountPoint && (!value.mountPoints || !value.mountPoints.length)) {
|
|
292
293
|
// @ts-expect-error
|
|
293
294
|
return helper.message('child mountPoint is required');
|
|
@@ -296,13 +297,23 @@ const componentSchema = Joi.object({
|
|
|
296
297
|
// @ts-expect-error
|
|
297
298
|
return helper.message('child source is required');
|
|
298
299
|
}
|
|
300
|
+
if (!allowEmptyStore && value.source && value.source.name && !value.source.store) {
|
|
301
|
+
// @ts-expect-error
|
|
302
|
+
return helper.message(`missing 'store' in source of component ${value.name}`);
|
|
303
|
+
}
|
|
299
304
|
return value;
|
|
300
|
-
})
|
|
301
|
-
|
|
305
|
+
});
|
|
306
|
+
const componentSchema = createComponentSchema().meta({
|
|
302
307
|
className: 'TComponent',
|
|
303
308
|
unknownType: 'any',
|
|
304
309
|
});
|
|
305
310
|
exports.componentSchema = componentSchema;
|
|
311
|
+
const componentSchemaWithoutStoreCheck = createComponentSchema(true);
|
|
312
|
+
const componentsSchema = (checkStore) => Joi.array()
|
|
313
|
+
.items(checkStore ? componentSchema : componentSchemaWithoutStoreCheck)
|
|
314
|
+
.unique('name')
|
|
315
|
+
.optional()
|
|
316
|
+
.default([]);
|
|
306
317
|
const signatureSchema = Joi.object({
|
|
307
318
|
type: Joi.string().required(),
|
|
308
319
|
name: Joi.string().required(),
|
|
@@ -568,7 +579,7 @@ const blockletMetaProps = {
|
|
|
568
579
|
signatures: Joi.array().items(signatureSchema).optional(),
|
|
569
580
|
lastPublishedAt: Joi.string().isoDate().optional(),
|
|
570
581
|
// blocklet component support
|
|
571
|
-
components:
|
|
582
|
+
components: componentsSchema(),
|
|
572
583
|
// navigation & theme
|
|
573
584
|
navigation: navigationSchema,
|
|
574
585
|
theme: themeSchema,
|
|
@@ -587,7 +598,7 @@ const blockletMetaSchema = Joi.object(blockletMetaProps).options({ stripUnknown:
|
|
|
587
598
|
});
|
|
588
599
|
exports.blockletMetaSchema = blockletMetaSchema;
|
|
589
600
|
const createBlockletSchema = (baseDir, _a = {}) => {
|
|
590
|
-
var { ensureMain = false, ensureFiles = false, ensureDist = false } = _a, schemaOptions = __rest(_a, ["ensureMain", "ensureFiles", "ensureDist"]);
|
|
601
|
+
var { ensureMain = false, ensureFiles = false, ensureDist = false, ensureComponentStore = true } = _a, schemaOptions = __rest(_a, ["ensureMain", "ensureFiles", "ensureDist", "ensureComponentStore"]);
|
|
591
602
|
if (!baseDir || !fs_1.default.existsSync(baseDir)) {
|
|
592
603
|
// eslint-disable-next-line no-param-reassign
|
|
593
604
|
ensureFiles = false;
|
|
@@ -603,7 +614,7 @@ const createBlockletSchema = (baseDir, _a = {}) => {
|
|
|
603
614
|
? // eslint-disable-next-line
|
|
604
615
|
Joi.file().exists({ baseDir, canSkip: (dir, name) => [BLOCKLET_ENTRY_FILE, BLOCKLET_BUNDLE_FILE].includes(name) || (0, is_glob_1.default)(name) }) // prettier-ignore
|
|
605
616
|
: Joi.string().trim())
|
|
606
|
-
.optional(), dist: ensureDist ? distSchema.required() : distSchema.optional() }))
|
|
617
|
+
.optional(), dist: ensureDist ? distSchema.required() : distSchema.optional(), components: componentsSchema(ensureComponentStore) }))
|
|
607
618
|
.options(Object.assign({ stripUnknown: true, noDefaults: false }, schemaOptions))
|
|
608
619
|
.rename('children', 'components')
|
|
609
620
|
.custom((data, helper) => {
|
package/lib/types/schema.d.ts
CHANGED
|
@@ -17,7 +17,31 @@ export interface TBlockletMeta {
|
|
|
17
17
|
navigation?: boolean;
|
|
18
18
|
};
|
|
19
19
|
community?: string;
|
|
20
|
-
components?:
|
|
20
|
+
components?: {
|
|
21
|
+
description?: TDescription;
|
|
22
|
+
mountPoint?: TMountPoint;
|
|
23
|
+
mountPoints?: {
|
|
24
|
+
child: {
|
|
25
|
+
interfaceName: string;
|
|
26
|
+
};
|
|
27
|
+
root: {
|
|
28
|
+
interfaceName: string;
|
|
29
|
+
prefix: string;
|
|
30
|
+
};
|
|
31
|
+
services?: TService[];
|
|
32
|
+
}[];
|
|
33
|
+
name: TBlockletName;
|
|
34
|
+
resolved?: string | string;
|
|
35
|
+
services?: TService[];
|
|
36
|
+
source?: {
|
|
37
|
+
url: string | string[];
|
|
38
|
+
} | {
|
|
39
|
+
name: TBlockletName;
|
|
40
|
+
store?: string | string[];
|
|
41
|
+
version?: 'latest' | string;
|
|
42
|
+
};
|
|
43
|
+
title?: TTitle;
|
|
44
|
+
}[];
|
|
21
45
|
contributors?: TPerson[];
|
|
22
46
|
copyright?: {
|
|
23
47
|
owner?: string;
|
|
@@ -116,7 +140,7 @@ export interface TComponent {
|
|
|
116
140
|
url: string | string[];
|
|
117
141
|
} | {
|
|
118
142
|
name: TBlockletName;
|
|
119
|
-
store
|
|
143
|
+
store?: string | string[];
|
|
120
144
|
version?: 'latest' | string;
|
|
121
145
|
};
|
|
122
146
|
title?: TTitle;
|
package/lib/validate.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { TBlockletMeta } from './types';
|
|
2
2
|
declare const fixAndValidateService: (meta: TBlockletMeta) => TBlockletMeta;
|
|
3
|
-
declare const validateMeta: (meta: any, { ensureMain, ensureFiles, ensureDist, schemaOptions, }?: {
|
|
3
|
+
declare const validateMeta: (meta: any, { ensureMain, ensureFiles, ensureDist, ensureComponentStore, schemaOptions, }?: {
|
|
4
4
|
ensureMain?: boolean;
|
|
5
5
|
ensureFiles?: boolean;
|
|
6
6
|
ensureDist?: boolean;
|
|
7
|
+
ensureComponentStore?: boolean;
|
|
7
8
|
schemaOptions?: any;
|
|
8
9
|
}) => TBlockletMeta;
|
|
9
10
|
export default validateMeta;
|
package/lib/validate.js
CHANGED
|
@@ -20,8 +20,11 @@ const fixAndValidateService = (meta) => {
|
|
|
20
20
|
return meta;
|
|
21
21
|
};
|
|
22
22
|
exports.fixAndValidateService = fixAndValidateService;
|
|
23
|
-
const validateMeta = (meta, { ensureMain = false, ensureFiles = false, ensureDist = false, schemaOptions = {}, } = {}) => {
|
|
24
|
-
const schema = (0, schema_1.createBlockletSchema)(null, Object.assign({ ensureMain,
|
|
23
|
+
const validateMeta = (meta, { ensureMain = false, ensureFiles = false, ensureDist = false, ensureComponentStore = true, schemaOptions = {}, } = {}) => {
|
|
24
|
+
const schema = (0, schema_1.createBlockletSchema)(null, Object.assign({ ensureMain,
|
|
25
|
+
ensureFiles,
|
|
26
|
+
ensureDist,
|
|
27
|
+
ensureComponentStore }, schemaOptions));
|
|
25
28
|
const { value, error } = schema.validate(meta);
|
|
26
29
|
if (error) {
|
|
27
30
|
throw new Error(`Invalid blocklet meta: ${error.details.map((x) => x.message).join(', ')}`);
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.8.
|
|
6
|
+
"version": "1.8.56",
|
|
7
7
|
"description": "Library to parse/validate/fix blocklet meta",
|
|
8
8
|
"main": "./lib/index.js",
|
|
9
9
|
"typings": "./lib/index.d.ts",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@abtnode/client": "1.8.
|
|
28
|
-
"@abtnode/constant": "1.8.
|
|
29
|
-
"@abtnode/util": "1.8.
|
|
27
|
+
"@abtnode/client": "1.8.56",
|
|
28
|
+
"@abtnode/constant": "1.8.56",
|
|
29
|
+
"@abtnode/util": "1.8.56",
|
|
30
30
|
"@arcblock/did": "1.18.34",
|
|
31
31
|
"@arcblock/did-ext": "1.18.34",
|
|
32
32
|
"@arcblock/did-util": "1.18.34",
|
|
33
33
|
"@arcblock/jwt": "1.18.34",
|
|
34
|
-
"@blocklet/constant": "1.8.
|
|
34
|
+
"@blocklet/constant": "1.8.56",
|
|
35
35
|
"@ocap/asset": "1.18.34",
|
|
36
36
|
"@ocap/mcrypto": "1.18.34",
|
|
37
37
|
"@ocap/types": "1.18.34",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"ts-node": "^10.9.1",
|
|
81
81
|
"typescript": "^4.8.4"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "8c24c9d747e96e05510b9cbe863666960569fb46"
|
|
84
84
|
}
|