@blocklet/meta 1.8.34 → 1.8.36

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 (58) hide show
  1. package/lib/channel.d.ts +27 -0
  2. package/lib/channel.js +32 -32
  3. package/lib/constants.d.ts +2 -0
  4. package/lib/constants.js +6 -3
  5. package/lib/did.d.ts +10 -0
  6. package/lib/did.js +18 -24
  7. package/lib/engine.d.ts +7 -0
  8. package/lib/engine.js +21 -25
  9. package/lib/entry.d.ts +3 -0
  10. package/lib/entry.js +51 -64
  11. package/lib/extension.d.ts +10 -0
  12. package/lib/extension.js +78 -77
  13. package/lib/file.d.ts +21 -0
  14. package/lib/file.js +44 -39
  15. package/lib/fix.d.ts +33 -0
  16. package/lib/fix.js +218 -208
  17. package/lib/get-component-process-id.d.ts +5 -0
  18. package/lib/get-component-process-id.js +13 -14
  19. package/lib/has-reserved-key.d.ts +3 -0
  20. package/lib/has-reserved-key.js +10 -9
  21. package/lib/index.d.ts +82 -0
  22. package/lib/index.js +51 -34
  23. package/lib/info.d.ts +13 -0
  24. package/lib/info.js +58 -60
  25. package/lib/name.d.ts +5 -0
  26. package/lib/name.js +14 -7
  27. package/lib/nft-templates.d.ts +86 -0
  28. package/lib/nft-templates.js +47 -42
  29. package/lib/parse-navigation.d.ts +3 -0
  30. package/lib/parse-navigation.js +167 -228
  31. package/lib/parse.d.ts +22 -0
  32. package/lib/parse.js +71 -82
  33. package/lib/payment/index.d.ts +254 -0
  34. package/lib/payment/index.js +13 -6
  35. package/lib/payment/v1.d.ts +185 -0
  36. package/lib/payment/v1.js +80 -81
  37. package/lib/payment/v2.d.ts +242 -0
  38. package/lib/payment/v2.js +453 -531
  39. package/lib/schema.d.ts +50 -0
  40. package/lib/schema.js +405 -402
  41. package/lib/service-configs/auth.json +61 -61
  42. package/lib/service.d.ts +26 -0
  43. package/lib/service.js +69 -85
  44. package/lib/types/index.d.ts +1 -0
  45. package/lib/types/index.js +18 -0
  46. package/lib/types/schema.d.ts +241 -0
  47. package/lib/types/schema.js +3 -0
  48. package/lib/util-meta.d.ts +42 -0
  49. package/lib/util-meta.js +138 -158
  50. package/lib/util.d.ts +185 -0
  51. package/lib/util.js +359 -414
  52. package/lib/validate.d.ts +10 -0
  53. package/lib/validate.js +28 -34
  54. package/lib/verify-multi-sig.d.ts +3 -0
  55. package/lib/verify-multi-sig.js +94 -101
  56. package/lib/wallet.d.ts +9 -0
  57. package/lib/wallet.js +17 -27
  58. package/package.json +40 -18
@@ -1,249 +1,188 @@
1
- const get = require('lodash/get');
2
- const cloneDeep = require('lodash/cloneDeep');
3
- const isEqual = require('lodash/isEqual');
4
- const normalizePathPrefix = require('@abtnode/util/lib/normalize-path-prefix');
5
-
6
- const parseLinkString = (link, prefix = '') =>
7
- link.startsWith('/') ? normalizePathPrefix(`${prefix}${link || '/'}`) : link;
8
-
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const get_1 = __importDefault(require("lodash/get"));
6
+ const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
7
+ const isEqual_1 = __importDefault(require("lodash/isEqual"));
8
+ const normalize_path_prefix_1 = __importDefault(require("@abtnode/util/lib/normalize-path-prefix"));
9
+ const parseLinkString = (link, prefix = '') => link.startsWith('/') ? (0, normalize_path_prefix_1.default)(`${prefix}${link || '/'}`) : link;
9
10
  const parseLink = (input, prefix) => {
10
- if (Object.prototype.toString.call(input) === '[object Object]') {
11
- return Object.entries(input).reduce((o, [key, value]) => {
12
- o[key] = parseLinkString(value, prefix);
13
- return o;
14
- }, {});
15
- }
16
-
17
- return parseLinkString(input, prefix);
11
+ if (Object.prototype.toString.call(input) === '[object Object]') {
12
+ return Object.entries(input).reduce((o, [key, value]) => {
13
+ o[key] = parseLinkString(value, prefix);
14
+ return o;
15
+ }, {});
16
+ }
17
+ return parseLinkString(input, prefix);
18
18
  };
19
-
20
19
  const getGroups = (navigation) => {
21
- const groups = {};
22
- for (const nav of navigation) {
23
- const sections = !nav.section || !nav.section.length ? ['__undefined__'] : nav.section;
24
- for (const sec of sections) {
25
- if (!groups[sec]) {
26
- groups[sec] = [];
27
- }
28
-
29
- const item = {
30
- ...nav,
31
- };
32
-
33
- if (nav.section) {
34
- item.section = sec === '__undefined__' ? [] : [sec];
35
- }
36
-
37
- groups[sec].push(item);
20
+ const groups = {};
21
+ for (const nav of navigation) {
22
+ const sections = !nav.section || !nav.section.length ? ['__undefined__'] : nav.section;
23
+ for (const sec of sections) {
24
+ if (!groups[sec]) {
25
+ groups[sec] = [];
26
+ }
27
+ const item = Object.assign({}, nav);
28
+ if (nav.section) {
29
+ item.section = sec === '__undefined__' ? [] : [sec];
30
+ }
31
+ groups[sec].push(item);
32
+ }
38
33
  }
39
- }
40
- return Object.values(groups);
34
+ return Object.values(groups);
41
35
  };
42
-
43
36
  const getChildName = (nav) => nav.component || nav.child;
44
-
45
- /**
46
- * @param {*} navigation src
47
- * @param {*} blocklet
48
- * @param {*} prefix prefix of link
49
- * @param {*} _level 1: primary menu, >2: secondary menu
50
- */
51
37
  const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
52
- const result = [];
53
-
54
- (navigation || []).forEach((nav) => {
55
- if (!getChildName(nav)) {
56
- if (_level > 1 && nav.items?.length) {
57
- const list = doParseNavigation(nav.items, blocklet, prefix, _level + 1);
58
- result.push(...list);
59
- return;
60
- }
61
-
62
- const item = {
63
- title: nav.title,
64
- };
65
-
66
- if (nav.section) {
67
- item.section = nav.section;
68
- }
69
-
70
- if (nav.icon) {
71
- item.icon = nav.icon;
72
- }
73
-
74
- if (nav.link) {
75
- item.link = parseLink(nav.link, prefix);
76
- } else {
77
- item.link = '';
78
- }
79
-
80
- if (nav.role) {
81
- item.role = nav.role;
82
- }
83
-
84
- if (nav.items?.length) {
85
- const list = doParseNavigation(nav.items, blocklet, prefix, _level + 1);
86
- if (list.length) {
87
- item.items = list;
38
+ const result = [];
39
+ (navigation || []).forEach((nav) => {
40
+ var _a, _b;
41
+ if (!getChildName(nav)) {
42
+ if (_level > 1 && ((_a = nav.items) === null || _a === void 0 ? void 0 : _a.length)) {
43
+ const list = doParseNavigation(nav.items, blocklet, prefix, _level + 1);
44
+ result.push(...list);
45
+ return;
46
+ }
47
+ const item = {
48
+ title: nav.title,
49
+ };
50
+ if (nav.section) {
51
+ item.section = nav.section;
52
+ }
53
+ if (nav.icon) {
54
+ item.icon = nav.icon;
55
+ }
56
+ if (nav.link) {
57
+ item.link = parseLink(nav.link, prefix);
58
+ }
59
+ else {
60
+ item.link = '';
61
+ }
62
+ if (nav.role) {
63
+ item.role = nav.role;
64
+ }
65
+ if ((_b = nav.items) === null || _b === void 0 ? void 0 : _b.length) {
66
+ const list = doParseNavigation(nav.items, blocklet, prefix, _level + 1);
67
+ if (list.length) {
68
+ item.items = list;
69
+ }
70
+ }
71
+ result.push(item);
72
+ return;
88
73
  }
89
- }
90
-
91
- result.push(item);
92
- return;
93
- }
94
-
95
- if (!blocklet) {
96
- return;
97
- }
98
-
99
- // parse child
100
- const child = (blocklet.children || []).find((x) => [x.meta.name, x.meta.did].includes(getChildName(nav)));
101
- if (!child) {
102
- return;
103
- }
104
- const childTitle = child.meta.title || child.meta.name;
105
-
106
- const itemProto = {
107
- title: nav.title || childTitle,
108
- };
109
-
110
- if (nav.section) {
111
- itemProto.section = nav.section;
112
- }
113
-
114
- if (nav.icon) {
115
- itemProto.icon = nav.icon;
116
- }
117
-
118
- if (nav.role) {
119
- itemProto.role = nav.role;
120
- }
121
-
122
- // get groups by section
123
- const groups = getGroups(get(child, 'meta.navigation', []));
124
-
125
- if (!groups.length) {
126
- // child does not declares menu
127
- const item = cloneDeep(itemProto);
128
- item.link = parseLink(child.mountPoint || '/', prefix);
129
- result.push(item);
130
- } else {
131
- for (const childNavigation of groups) {
132
- if (childNavigation.length === 1) {
133
- // child declares one menu
134
- const childNav = childNavigation[0];
135
-
136
- const item = cloneDeep(itemProto);
137
-
138
- item.title = nav.title || childNav.title || childTitle;
139
-
140
- if (childNav.icon) {
141
- item.icon = item.icon || childNav.icon;
142
- }
143
-
144
- if (childNav.role) {
145
- item.role = item.role || childNav.role;
146
- }
147
-
148
- if (childNav.section) {
149
- item.section = item.section || childNav.section;
150
- }
151
-
152
- item.link = parseLink(childNavigation[0].link || '/', normalizePathPrefix(`${prefix}${child.mountPoint}`));
153
-
154
- // doParseNavigation because child nav depth may be > 1
155
- const list = doParseNavigation(
156
- childNavigation,
157
- child,
158
- normalizePathPrefix(`${prefix}${child.mountPoint}`),
159
- _level + 1
160
- );
161
-
162
- if (list.length > 1) {
163
- // more than 1 child nav
164
- delete item.link;
165
- result.push({
166
- ...item,
167
- items: list,
168
- });
169
- } else {
170
- // only 1 child nav
171
- item.link = list[0].link;
74
+ if (!blocklet) {
75
+ return;
76
+ }
77
+ // parse child
78
+ const child = (blocklet.children || []).find((x) => [x.meta.name, x.meta.did].includes(getChildName(nav)));
79
+ if (!child) {
80
+ return;
81
+ }
82
+ const childTitle = child.meta.title || child.meta.name;
83
+ const itemProto = {
84
+ title: nav.title || childTitle,
85
+ };
86
+ if (nav.section) {
87
+ itemProto.section = nav.section;
88
+ }
89
+ if (nav.icon) {
90
+ itemProto.icon = nav.icon;
91
+ }
92
+ if (nav.role) {
93
+ itemProto.role = nav.role;
94
+ }
95
+ // get groups by section
96
+ const groups = getGroups((0, get_1.default)(child, 'meta.navigation', []));
97
+ if (!groups.length) {
98
+ // child does not declares menu
99
+ const item = (0, cloneDeep_1.default)(itemProto);
100
+ item.link = parseLink(child.mountPoint || '/', prefix);
172
101
  result.push(item);
173
- }
174
- } else {
175
- // child declares multiple menus
176
- const groupSection = childNavigation[0].section || [];
177
-
178
- const list = doParseNavigation(
179
- childNavigation,
180
- child,
181
- normalizePathPrefix(`${prefix}${child.mountPoint}`),
182
- _level + 1
183
- );
184
-
185
- if (_level === 1) {
186
- // primary menu
187
- const item = cloneDeep(itemProto);
188
-
189
- if (groupSection.length) {
190
- item.section = item.section || groupSection;
102
+ }
103
+ else {
104
+ for (const childNavigation of groups) {
105
+ if (childNavigation.length === 1) {
106
+ // child declares one menu
107
+ const childNav = childNavigation[0];
108
+ const item = (0, cloneDeep_1.default)(itemProto);
109
+ item.title = nav.title || childNav.title || childTitle;
110
+ if (childNav.icon) {
111
+ item.icon = item.icon || childNav.icon;
112
+ }
113
+ if (childNav.role) {
114
+ item.role = item.role || childNav.role;
115
+ }
116
+ if (childNav.section) {
117
+ item.section = item.section || childNav.section;
118
+ }
119
+ item.link = parseLink(childNavigation[0].link || '/', (0, normalize_path_prefix_1.default)(`${prefix}${child.mountPoint}`));
120
+ // doParseNavigation because child nav depth may be > 1
121
+ const list = doParseNavigation(childNavigation, child, (0, normalize_path_prefix_1.default)(`${prefix}${child.mountPoint}`), _level + 1);
122
+ if (list.length > 1) {
123
+ // more than 1 child nav
124
+ delete item.link;
125
+ result.push(Object.assign(Object.assign({}, item), { items: list }));
126
+ }
127
+ else {
128
+ // only 1 child nav
129
+ item.link = list[0].link;
130
+ result.push(item);
131
+ }
132
+ }
133
+ else {
134
+ // child declares multiple menus
135
+ const groupSection = childNavigation[0].section || [];
136
+ const list = doParseNavigation(childNavigation, child, (0, normalize_path_prefix_1.default)(`${prefix}${child.mountPoint}`), _level + 1);
137
+ if (_level === 1) {
138
+ // primary menu
139
+ const item = (0, cloneDeep_1.default)(itemProto);
140
+ if (groupSection.length) {
141
+ item.section = item.section || groupSection;
142
+ }
143
+ item.items = list;
144
+ result.push(Object.assign(Object.assign({}, item), { items: list }));
145
+ }
146
+ else {
147
+ // secondary menu
148
+ result.push(...list);
149
+ }
150
+ }
191
151
  }
192
-
193
- item.items = list;
194
- result.push({
195
- ...item,
196
- items: list,
197
- });
198
- } else {
199
- // secondary menu
200
- result.push(...list);
201
- }
202
152
  }
203
- }
204
- }
205
- });
206
-
207
- return result;
153
+ });
154
+ return result;
208
155
  };
209
-
210
156
  const markDuplicate = (navigation, compares = []) => {
211
- navigation.forEach((item) => {
212
- const compare = { link: item.link, section: item.section || [] };
213
- if (item.link && compares.some((x) => isEqual(x, compare))) {
214
- item.duplicate = true;
215
- }
216
- if (item.link) {
217
- compares.push(compare);
218
- }
219
-
220
- if (item.items) {
221
- markDuplicate(item.items, compares);
222
- }
223
- });
224
-
225
- return navigation;
157
+ navigation.forEach((item) => {
158
+ const compare = { link: item.link, section: item.section || [] };
159
+ if (item.link && compares.some((x) => (0, isEqual_1.default)(x, compare))) {
160
+ item.duplicate = true;
161
+ }
162
+ if (item.link) {
163
+ compares.push(compare);
164
+ }
165
+ if (item.items) {
166
+ markDuplicate(item.items, compares);
167
+ }
168
+ });
169
+ return navigation;
226
170
  };
227
-
228
171
  const filterDuplicate = (navigation) => {
229
- const res = navigation.filter((x) => !x.duplicate);
230
- res.forEach((item) => {
231
- if (item.items) {
232
- item.items = filterDuplicate(item.items);
233
- }
234
- });
235
-
236
- return res;
172
+ const res = navigation.filter((x) => !x.duplicate);
173
+ res.forEach((item) => {
174
+ if (item.items) {
175
+ item.items = filterDuplicate(item.items);
176
+ }
177
+ });
178
+ return res;
237
179
  };
238
-
239
180
  const uniq = (navigation) => {
240
- return filterDuplicate(markDuplicate(navigation));
181
+ return filterDuplicate(markDuplicate(navigation));
241
182
  };
242
-
243
183
  const parseNavigation = (...args) => {
244
- const res = doParseNavigation(...args);
245
-
246
- return uniq(res).filter((x) => x.link || (x.items && x.items.length));
184
+ // @ts-expect-error
185
+ const res = doParseNavigation(...args);
186
+ return uniq(res).filter((x) => x.link || (x.items && x.items.length));
247
187
  };
248
-
249
188
  module.exports = parseNavigation;
package/lib/parse.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { TBlockletMeta } from './types';
2
+ /**
3
+ * Get blocklet meta from blocklet.yml
4
+ * @param {string} dir blocklet directory
5
+ * @param {object} options.extraRawAttrs extra attributes, will be used as base attributes
6
+ * @param {boolean} options.ensureMain should we verify that main exists
7
+ * @param {boolean} options.ensureDist should we verify that dist exists
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
+ */
11
+ declare const parse: (dir: string, { ensureMain, ensureFiles, ensureDist, extraRawAttrs, serviceMetas, schemaOptions, fix, }?: {
12
+ ensureMain?: boolean;
13
+ ensureFiles?: boolean;
14
+ ensureDist?: boolean;
15
+ extraRawAttrs?: any;
16
+ serviceMetas?: any;
17
+ schemaOptions?: any;
18
+ enableDefaults?: boolean;
19
+ extraAttrSpec?: any;
20
+ fix?: boolean;
21
+ }) => TBlockletMeta;
22
+ export = parse;
package/lib/parse.js CHANGED
@@ -1,15 +1,18 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const yaml = require('js-yaml');
4
- const camelCase = require('lodash/camelCase');
5
- const debug = require('debug')('@blocklet/meta:parse');
6
-
7
- const { BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT } = require('./constants');
8
-
9
- const toBlockletDid = require('./did');
10
- const { createBlockletSchema } = require('./schema');
11
- const { fixRequired, fixRepository, fixFiles, fixPerson, fixKeywords, fixTags, fixService } = require('./fix');
12
-
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const fs_1 = __importDefault(require("fs"));
6
+ const path_1 = __importDefault(require("path"));
7
+ const js_yaml_1 = __importDefault(require("js-yaml"));
8
+ const camelCase_1 = __importDefault(require("lodash/camelCase"));
9
+ const debug_1 = __importDefault(require("debug"));
10
+ const constants_1 = __importDefault(require("./constants"));
11
+ const did_1 = __importDefault(require("./did"));
12
+ const schema_1 = require("./schema");
13
+ const fix_1 = require("./fix");
14
+ const debug = (0, debug_1.default)('@blocklet/meta:parse');
15
+ const { BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT } = constants_1.default;
13
16
  /**
14
17
  * Get blocklet meta from blocklet.yml
15
18
  * @param {string} dir blocklet directory
@@ -19,77 +22,63 @@ const { fixRequired, fixRepository, fixFiles, fixPerson, fixKeywords, fixTags, f
19
22
  * @param {boolean} options.ensureFiles should we verify that logo and files exists
20
23
  * @param {Array} options.serviceMetas should we verify that each service is validate (using JSON Schema defined serviceMetas)
21
24
  */
22
- const parse = (
23
- dir,
24
- {
25
- ensureMain = false,
26
- ensureFiles = false,
27
- ensureDist = false,
28
- extraRawAttrs = {},
29
- serviceMetas,
30
- schemaOptions = {},
31
- fix = true,
32
- } = {}
33
- ) => {
34
- let result = {};
35
-
36
- const blockletMetaFile = path.join(dir, BLOCKLET_META_FILE);
37
- const blockletMetaFileAlt = path.join(dir, BLOCKLET_META_FILE_ALT);
38
- if (fs.existsSync(blockletMetaFile)) {
39
- try {
40
- result = Object.assign(result, yaml.load(fs.readFileSync(blockletMetaFile).toString(), { json: true }));
41
- debug(`parse ${blockletMetaFile}`, result);
42
- } catch (err) {
43
- console.error(`parse_blocklet_meta from ${BLOCKLET_META_FILE} failed`, err);
25
+ const parse = (dir, { ensureMain = false, ensureFiles = false, ensureDist = false, extraRawAttrs = {}, serviceMetas, schemaOptions = {}, fix = true, } = {}) => {
26
+ let result = {};
27
+ const blockletMetaFile = path_1.default.join(dir, BLOCKLET_META_FILE);
28
+ const blockletMetaFileAlt = path_1.default.join(dir, BLOCKLET_META_FILE_ALT);
29
+ if (fs_1.default.existsSync(blockletMetaFile)) {
30
+ try {
31
+ result = Object.assign(result, js_yaml_1.default.load(fs_1.default.readFileSync(blockletMetaFile).toString(), { json: true }));
32
+ debug(`parse ${blockletMetaFile}`, result);
33
+ }
34
+ catch (err) {
35
+ console.error(`parse_blocklet_meta from ${BLOCKLET_META_FILE} failed`, err);
36
+ }
37
+ }
38
+ else if (fs_1.default.existsSync(blockletMetaFileAlt)) {
39
+ try {
40
+ result = Object.assign(result, js_yaml_1.default.load(fs_1.default.readFileSync(blockletMetaFileAlt).toString(), { json: true }));
41
+ debug(`parse ${blockletMetaFileAlt}`, result);
42
+ }
43
+ catch (err) {
44
+ console.error(`parse_blocklet_meta from ${BLOCKLET_META_FILE_ALT} failed`, err);
45
+ }
46
+ }
47
+ else {
48
+ throw new Error(`no ${BLOCKLET_META_FILE} or ${BLOCKLET_META_FILE_ALT} found`);
49
+ }
50
+ // User Can override with extra meta attrs: useful for registry
51
+ if (extraRawAttrs) {
52
+ result = Object.assign(result, extraRawAttrs);
53
+ }
54
+ if (!fix) {
55
+ // @ts-ignore
56
+ return result;
44
57
  }
45
- } else if (fs.existsSync(blockletMetaFileAlt)) {
46
- try {
47
- result = Object.assign(result, yaml.load(fs.readFileSync(blockletMetaFileAlt).toString(), { json: true }));
48
- debug(`parse ${blockletMetaFileAlt}`, result);
49
- } catch (err) {
50
- console.error(`parse_blocklet_meta from ${BLOCKLET_META_FILE_ALT} failed`, err);
58
+ // Fix
59
+ (0, fix_1.fixRequired)(result, dir);
60
+ (0, fix_1.fixRepository)(result);
61
+ (0, fix_1.fixFiles)(result);
62
+ (0, fix_1.fixKeywords)(result);
63
+ (0, fix_1.fixTags)(result);
64
+ (0, fix_1.fixPerson)(result);
65
+ // @ts-expect-error TS(2554) FIXME: Expected 1 arguments, but got 2.
66
+ (0, fix_1.fixService)(result, serviceMetas);
67
+ debug('fix', result);
68
+ // We will overwrite did anyway
69
+ result.path = `/${result.group}/${result.name}`;
70
+ result.did = (0, did_1.default)(Buffer.from(result.name, 'utf8'));
71
+ // Ensure camelCase
72
+ result = Object.keys(result).reduce((acc, k) => {
73
+ acc[(0, camelCase_1.default)(k)] = result[k];
74
+ return acc;
75
+ }, {});
76
+ // Validate and cleanup
77
+ const schema = (0, schema_1.createBlockletSchema)(dir, Object.assign({ ensureMain, ensureFiles, ensureDist }, schemaOptions));
78
+ const { value, error } = schema.validate(result);
79
+ if (error) {
80
+ throw new Error(`Invalid blocklet.yml: ${error.details.map((x) => x.message).join(', ')}`);
51
81
  }
52
- } else {
53
- throw new Error(`no ${BLOCKLET_META_FILE} or ${BLOCKLET_META_FILE_ALT} found`);
54
- }
55
-
56
- // User Can override with extra meta attrs: useful for registry
57
- if (extraRawAttrs) {
58
- result = Object.assign(result, extraRawAttrs);
59
- }
60
-
61
- if (!fix) {
62
- return result;
63
- }
64
-
65
- // Fix
66
- fixRequired(result, dir);
67
- fixRepository(result);
68
- fixFiles(result);
69
- fixKeywords(result);
70
- fixTags(result);
71
- fixPerson(result);
72
- fixService(result, serviceMetas);
73
- debug('fix', result);
74
-
75
- // We will overwrite did anyway
76
- result.path = `/${result.group}/${result.name}`;
77
- result.did = toBlockletDid(Buffer.from(result.name, 'utf8'));
78
-
79
- // Ensure camelCase
80
- result = Object.keys(result).reduce((acc, k) => {
81
- acc[camelCase(k)] = result[k];
82
- return acc;
83
- }, {});
84
-
85
- // Validate and cleanup
86
- const schema = createBlockletSchema(dir, { ensureMain, ensureFiles, ensureDist, ...schemaOptions });
87
- const { value, error } = schema.validate(result);
88
- if (error) {
89
- throw new Error(`Invalid blocklet.yml: ${error.details.map((x) => x.message).join(', ')}`);
90
- }
91
-
92
- return value;
82
+ return value;
93
83
  };
94
-
95
84
  module.exports = parse;