@cloudbase/cals 0.5.13-alpha.6 → 0.5.13-alpha.8
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/utils/dts/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export interface IInputDataWidgetItem {
|
|
|
19
19
|
idList: string[];
|
|
20
20
|
}
|
|
21
21
|
export interface IInputDataRepeaterItem {
|
|
22
|
+
widgetId: string;
|
|
22
23
|
currentItemAlias: string;
|
|
23
24
|
currentIndexAlias: string;
|
|
24
25
|
itemData: IJsonSchemaAny;
|
|
@@ -30,6 +31,10 @@ export interface IInputDataRedefineAnyType {
|
|
|
30
31
|
updateProps: {
|
|
31
32
|
widgetPropName: string;
|
|
32
33
|
widgetPropTypeSchema: IJsonSchemaAny;
|
|
34
|
+
datasource: {
|
|
35
|
+
name: string;
|
|
36
|
+
title: string;
|
|
37
|
+
};
|
|
33
38
|
}[];
|
|
34
39
|
}
|
|
35
40
|
export interface IOptions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/dts/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/dts/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAG/D,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,CAAC,EAAE,iBAAiB,CAAA;IACpC,aAAa,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,iBAAiB,CAAC;QAAC,MAAM,CAAC,EAAE,cAAc,CAAA;KAAE,EAA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E,eAAe,EAAE,OAAO,CAAA;KAA+B;IAcnS,MAAM,CAAC,MAAM,CAAC,OAAO,GAAE,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAgF;CAanI;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,SAAS,GAAE,UAAe,EAAE,OAAO,GAAE,QAA0G,GAAG,OAAO,CAAC,MAAM,CAAC,CA2CzM;AA2YD,eAAO,MAAM,UAAU,6yDA8DtB,CAAA;AAyDD;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAO5D;AAID,eAAO,MAAM,mBAAmB,+tBAmB/B,CAAA;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,KAAA,GAAG,OAAO,CAAC,MAAM,CAAC,CAQ5D"}
|
package/lib/utils/dts/index.js
CHANGED
|
@@ -8,9 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.compileJSONToDTS = exports.jsonToDTSWorkerCode = exports.transpileToDTS = exports.workerCode = exports.generateWeDaAppDTS = exports.WeDaDTS = exports.IInputDataType = void 0;
|
|
13
16
|
const lodash_1 = require("lodash");
|
|
17
|
+
const json_easy_filter_1 = __importDefault(require("json-easy-filter"));
|
|
14
18
|
const auto_generated_1 = require("./auto-generated");
|
|
15
19
|
var IInputDataType;
|
|
16
20
|
(function (IInputDataType) {
|
|
@@ -129,7 +133,10 @@ function generateWeDaAppDTS(inputData = {}, options = { isCompMode: false, needG
|
|
|
129
133
|
if (placeholder) {
|
|
130
134
|
// 防止某项错误导致全部都错误
|
|
131
135
|
try {
|
|
132
|
-
const [dts] = yield _generateOneItemDTS(inputData[key], key);
|
|
136
|
+
const [dts, replaceRules] = yield _generateOneItemDTS(inputData[key], key);
|
|
137
|
+
replaceRules.forEach(rule => {
|
|
138
|
+
resultDts = resultDts.replace(rule.from, rule.to);
|
|
139
|
+
});
|
|
133
140
|
resultDts = resultDts.replace(placeholder, dts + '\n' + placeholder);
|
|
134
141
|
}
|
|
135
142
|
catch (e) {
|
|
@@ -163,9 +170,9 @@ exports.generateWeDaAppDTS = generateWeDaAppDTS;
|
|
|
163
170
|
/**
|
|
164
171
|
* 生成 weda 专有的注释信息
|
|
165
172
|
*/
|
|
166
|
-
function genWeDaCodeComment({ fieldName, title, description, type, group }) {
|
|
167
|
-
const desc = `${title || fieldName}\n${description || ''}
|
|
168
|
-
return desc + `\n@privateForWeDa\n${JSON.stringify({ group, displayType: type, displayName: title || '' })}`;
|
|
173
|
+
function genWeDaCodeComment({ fieldName, title, description, type, group, schema, subGroup, baseClass, datasource, }) {
|
|
174
|
+
const desc = (title || fieldName) ? `${title || fieldName}\n${description || ''}` : '';
|
|
175
|
+
return desc + `\n@privateForWeDa\n${JSON.stringify({ group, displayType: type, displayName: title || '', schema, subGroup, baseClass, datasource })}`;
|
|
169
176
|
}
|
|
170
177
|
/**
|
|
171
178
|
* 生成指定类型的 DTS
|
|
@@ -176,24 +183,32 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
176
183
|
/**
|
|
177
184
|
* 处理注释信息
|
|
178
185
|
*/
|
|
179
|
-
function _handleComment(inputData, group) {
|
|
186
|
+
function _handleComment(inputData, group, needKeepSchema) {
|
|
180
187
|
const _inputData = (0, lodash_1.cloneDeep)(inputData);
|
|
181
|
-
|
|
188
|
+
json_easy_filter_1.default.traverse(_inputData, function (key, value, path) {
|
|
182
189
|
var _a;
|
|
183
190
|
if ((value === null || value === void 0 ? void 0 : value.type) && !((_a = value === null || value === void 0 ? void 0 : value.type) === null || _a === void 0 ? void 0 : _a.type)) {
|
|
184
191
|
// value?.type?.type 有值,则证明 type 是自定义的字段,而非 JSONSchema 中的 type
|
|
192
|
+
let schema = null;
|
|
193
|
+
if (needKeepSchema) {
|
|
194
|
+
const isFirstLevel = path.length === 2 && (path === null || path === void 0 ? void 0 : path[0]) === 'properties';
|
|
195
|
+
if (isFirstLevel) {
|
|
196
|
+
// 只需要第一级属性需要保存,且只保存子信息(对象或数组的子项)
|
|
197
|
+
schema = (value.properties || value.items) ? value : null;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
185
200
|
value.description = genWeDaCodeComment({
|
|
186
201
|
fieldName: key,
|
|
187
202
|
title: value.title,
|
|
188
203
|
description: value.description,
|
|
189
204
|
group: group,
|
|
190
|
-
type: value.type
|
|
205
|
+
type: value.type,
|
|
206
|
+
schema
|
|
191
207
|
});
|
|
192
208
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return schema;
|
|
209
|
+
});
|
|
210
|
+
_inputData.description = ''; // 避免第一层出现注释
|
|
211
|
+
return _inputData;
|
|
197
212
|
}
|
|
198
213
|
/**
|
|
199
214
|
* 获取用于显示的数据类型(仅有 number, string , boolean, array, object 等内置基础类型)
|
|
@@ -234,14 +249,14 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
234
249
|
[IInputDataType.globalState]: function (inputData) {
|
|
235
250
|
return __awaiter(this, void 0, void 0, function* () {
|
|
236
251
|
// 完善注释信息
|
|
237
|
-
const handledInputData = _handleComment(inputData, GroupEnum.GLOBAL_VAR);
|
|
252
|
+
const handledInputData = _handleComment(inputData, GroupEnum.GLOBAL_VAR, true);
|
|
238
253
|
return yield _compile(handledInputData);
|
|
239
254
|
});
|
|
240
255
|
},
|
|
241
256
|
[IInputDataType.pageState]: function (inputData) {
|
|
242
257
|
return __awaiter(this, void 0, void 0, function* () {
|
|
243
258
|
// 完善注释信息
|
|
244
|
-
const handledInputData = _handleComment(inputData, GroupEnum.PAGE_VAR);
|
|
259
|
+
const handledInputData = _handleComment(inputData, GroupEnum.PAGE_VAR, true);
|
|
245
260
|
return yield _compile(handledInputData);
|
|
246
261
|
});
|
|
247
262
|
},
|
|
@@ -339,8 +354,15 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
339
354
|
// ${exportMethodsDTS}
|
|
340
355
|
// }
|
|
341
356
|
// `
|
|
357
|
+
const interfaceName = _genCompInterfaceName(item.module, item.component);
|
|
342
358
|
return `
|
|
343
|
-
|
|
359
|
+
/**
|
|
360
|
+
${genWeDaCodeComment({
|
|
361
|
+
fieldName: interfaceName,
|
|
362
|
+
schema: item.exportProperties,
|
|
363
|
+
}).split('\n').map(item => `* ${item}`).join('\n')}
|
|
364
|
+
*/
|
|
365
|
+
declare class ${interfaceName} extends UserWidget {
|
|
344
366
|
|
|
345
367
|
${exportPropertiesDTS}
|
|
346
368
|
|
|
@@ -362,7 +384,9 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
362
384
|
title: '',
|
|
363
385
|
description: '',
|
|
364
386
|
group: GroupEnum.COMPONENT,
|
|
365
|
-
type: 'component'
|
|
387
|
+
type: 'component',
|
|
388
|
+
baseClass: interfaceName,
|
|
389
|
+
datasource: `$${id}_start$ $${id}_end$`
|
|
366
390
|
}).split('\n').map(item => `* ${item}`).join('\n')}
|
|
367
391
|
*/
|
|
368
392
|
const ${id}: ${interfaceName}`).join('\n');
|
|
@@ -387,20 +411,23 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
387
411
|
/**
|
|
388
412
|
${genWeDaCodeComment({
|
|
389
413
|
fieldName: item.currentItemAlias,
|
|
390
|
-
title: '',
|
|
414
|
+
title: '当前项值',
|
|
391
415
|
description: '',
|
|
392
416
|
group: GroupEnum.REPEATER,
|
|
393
|
-
type: getDisplayReturnType(itemDataDTS)
|
|
417
|
+
type: getDisplayReturnType(itemDataDTS),
|
|
418
|
+
schema: item.itemData,
|
|
419
|
+
subGroup: item.widgetId
|
|
394
420
|
}).split('\n').map(item => `* ${item}`).join('\n')}
|
|
395
421
|
*/
|
|
396
422
|
const ${item.currentItemAlias}: ${itemDataDTS}
|
|
397
423
|
/**
|
|
398
424
|
${genWeDaCodeComment({
|
|
399
425
|
fieldName: item.currentIndexAlias,
|
|
400
|
-
title: '',
|
|
426
|
+
title: '当前下标',
|
|
401
427
|
description: '',
|
|
402
428
|
group: GroupEnum.REPEATER,
|
|
403
|
-
type: 'number'
|
|
429
|
+
type: 'number',
|
|
430
|
+
subGroup: item.widgetId
|
|
404
431
|
}).split('\n').map(item => `* ${item}`).join('\n')}
|
|
405
432
|
*/
|
|
406
433
|
const ${item.currentIndexAlias}: number
|
|
@@ -415,7 +442,7 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
415
442
|
const compInterfaceName = _genCompInterfaceName(item.module, item.component);
|
|
416
443
|
const widgetInterfaceName = `${item.widgetId}_${compInterfaceName}`;
|
|
417
444
|
/**
|
|
418
|
-
* 更新
|
|
445
|
+
* 更新 widget 的类型名
|
|
419
446
|
*/
|
|
420
447
|
replaceRules.push({
|
|
421
448
|
from: new RegExp(`(const ${item.widgetId}): .*`),
|
|
@@ -424,9 +451,16 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
424
451
|
/**
|
|
425
452
|
* 增加类
|
|
426
453
|
*/
|
|
454
|
+
const datasources = {};
|
|
427
455
|
const propDefinitions = yield Promise.all(item.updateProps.map((prop) => __awaiter(this, void 0, void 0, function* () {
|
|
428
456
|
const properties = _handleComment(prop.widgetPropTypeSchema, GroupEnum.DATA_FIELD);
|
|
429
457
|
const widgetPropTypeDTS = yield _compile(Object.assign(Object.assign({}, prop.widgetPropTypeSchema), properties), true);
|
|
458
|
+
if (!datasources[prop.datasource.name]) {
|
|
459
|
+
datasources[prop.datasource.name] = { fields: [prop.widgetPropName], schema: prop.widgetPropTypeSchema, name: prop.datasource.name, title: prop.datasource.title };
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
datasources[prop.datasource.name].fields.push(prop.widgetPropName);
|
|
463
|
+
}
|
|
430
464
|
// 是否是多层级字段,如 "a.b"
|
|
431
465
|
// FIXME: 当前只支持 a.b 这种形式,不支持 a[].b
|
|
432
466
|
const multiLevelField = prop.widgetPropName.includes('.');
|
|
@@ -454,6 +488,17 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
454
488
|
${multiLevelField ? `${firstField}: Omit<${compInterfaceName}['${firstField}'], '${othersFields.join(".")}'> & ${JSON.stringify(multiLevelFieldObj[firstField]).replace('"$$schema$$"', widgetPropTypeDTS)}` : `${prop.widgetPropName}: ${widgetPropTypeDTS}`}
|
|
455
489
|
`;
|
|
456
490
|
})));
|
|
491
|
+
/**
|
|
492
|
+
* 更新数据源信息
|
|
493
|
+
*/
|
|
494
|
+
const datasourceInfoList = Object.values(datasources);
|
|
495
|
+
if (datasourceInfoList.length > 0) {
|
|
496
|
+
console.log(datasourceInfoList);
|
|
497
|
+
replaceRules.push({
|
|
498
|
+
from: new RegExp(`(\\$${item.widgetId}_start\\$).*(\\$${item.widgetId}_end\\$)`),
|
|
499
|
+
to: `$1${JSON.stringify(datasourceInfoList)}$2`
|
|
500
|
+
});
|
|
501
|
+
}
|
|
457
502
|
return `
|
|
458
503
|
declare class ${widgetInterfaceName} extends ${compInterfaceName} {
|
|
459
504
|
${propDefinitions.join('\n')}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/cals",
|
|
3
|
-
"version": "0.5.13-alpha.
|
|
3
|
+
"version": "0.5.13-alpha.8",
|
|
4
4
|
"description": "Common application specifications",
|
|
5
5
|
"main": "lib/utils/index.js",
|
|
6
6
|
"source": "src/utils/index.ts",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"acorn": "^8.0.4",
|
|
33
|
+
"json-easy-filter": "^0.3.1",
|
|
33
34
|
"json-schema-to-typescript-for-browser": "^11.0.3",
|
|
34
35
|
"lodash": "^4.17.20",
|
|
35
36
|
"postcss": "^8.4.20",
|