@cloudbase/cals 0.5.13-alpha.1 → 0.5.13-alpha.11
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;
|
|
@@ -27,8 +28,15 @@ export interface IInputDataRedefineAnyType {
|
|
|
27
28
|
module: string;
|
|
28
29
|
component: string;
|
|
29
30
|
widgetId: string;
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
updateProps: {
|
|
32
|
+
widgetPropName: string;
|
|
33
|
+
widgetPropTitle: string;
|
|
34
|
+
widgetPropTypeSchema: IJsonSchemaAny;
|
|
35
|
+
datasource: {
|
|
36
|
+
name: string;
|
|
37
|
+
title: string;
|
|
38
|
+
};
|
|
39
|
+
}[];
|
|
32
40
|
}
|
|
33
41
|
export interface IOptions {
|
|
34
42
|
isCompMode?: boolean;
|
|
@@ -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;IACp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GAAG,YAAY,EAAE,GAAG,MAAM,EAAE,GAAG,wBAAwB,EAAE,GAAG,oBAAoB,EAAE,GAAG,sBAAsB,EAAE,GAAG,yBAAyB,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,GAAE;QAAE,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;AA8YD,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) {
|
|
@@ -88,14 +92,16 @@ class WeDaDTS {
|
|
|
88
92
|
*/
|
|
89
93
|
static updateDTSPartial(inputData, itemType, options = { setEmptyIfError: false }) {
|
|
90
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
let dts = '';
|
|
92
95
|
try {
|
|
93
|
-
[dts,
|
|
96
|
+
const [dts, replaceRules] = yield _generateOneItemDTS(inputData, itemType);
|
|
97
|
+
replaceRules.forEach(rule => {
|
|
98
|
+
WeDaDTS._dts = WeDaDTS._dts.replace(rule.from, rule.to);
|
|
99
|
+
});
|
|
94
100
|
WeDaDTS._dts = WeDaDTS._dts.replace(new RegExp(`^(\\s*\\/\\/ ${DtsInnerSign[itemType]} Begin)[\\s\\S]*(^\\s*\\/\\/ ${DtsInnerSign[itemType]} End)`, 'm'), `$1\n${dts}\n$2`);
|
|
95
101
|
}
|
|
96
102
|
catch (e) {
|
|
97
103
|
if (options.setEmptyIfError) {
|
|
98
|
-
WeDaDTS._dts = WeDaDTS._dts.replace(new RegExp(`^(\\s*\\/\\/ ${DtsInnerSign[itemType]} Begin)[\\s\\S]*(^\\s*\\/\\/ ${DtsInnerSign[itemType]} End)`, 'm'), `$1\n${
|
|
104
|
+
WeDaDTS._dts = WeDaDTS._dts.replace(new RegExp(`^(\\s*\\/\\/ ${DtsInnerSign[itemType]} Begin)[\\s\\S]*(^\\s*\\/\\/ ${DtsInnerSign[itemType]} End)`, 'm'), `$1\n${''}\n$2`);
|
|
99
105
|
}
|
|
100
106
|
}
|
|
101
107
|
});
|
|
@@ -127,7 +133,10 @@ function generateWeDaAppDTS(inputData = {}, options = { isCompMode: false, needG
|
|
|
127
133
|
if (placeholder) {
|
|
128
134
|
// 防止某项错误导致全部都错误
|
|
129
135
|
try {
|
|
130
|
-
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
|
+
});
|
|
131
140
|
resultDts = resultDts.replace(placeholder, dts + '\n' + placeholder);
|
|
132
141
|
}
|
|
133
142
|
catch (e) {
|
|
@@ -161,34 +170,45 @@ exports.generateWeDaAppDTS = generateWeDaAppDTS;
|
|
|
161
170
|
/**
|
|
162
171
|
* 生成 weda 专有的注释信息
|
|
163
172
|
*/
|
|
164
|
-
function genWeDaCodeComment({ fieldName, title, description, type, group }) {
|
|
165
|
-
const desc = `${title || fieldName}\n${description || ''}
|
|
166
|
-
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 })}`;
|
|
167
176
|
}
|
|
168
177
|
/**
|
|
169
178
|
* 生成指定类型的 DTS
|
|
170
179
|
*/
|
|
171
|
-
function _generateOneItemDTS(inputData, itemType
|
|
180
|
+
function _generateOneItemDTS(inputData, itemType) {
|
|
172
181
|
return __awaiter(this, void 0, void 0, function* () {
|
|
182
|
+
const replaceRules = [];
|
|
173
183
|
/**
|
|
174
184
|
* 处理注释信息
|
|
175
185
|
*/
|
|
176
|
-
function _handleComment(inputData, group) {
|
|
186
|
+
function _handleComment(inputData, group, needKeepSchema) {
|
|
177
187
|
const _inputData = (0, lodash_1.cloneDeep)(inputData);
|
|
178
|
-
|
|
179
|
-
|
|
188
|
+
json_easy_filter_1.default.traverse(_inputData, function (key, value, path) {
|
|
189
|
+
var _a;
|
|
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)) {
|
|
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
|
+
}
|
|
180
200
|
value.description = genWeDaCodeComment({
|
|
181
201
|
fieldName: key,
|
|
182
202
|
title: value.title,
|
|
183
203
|
description: value.description,
|
|
184
204
|
group: group,
|
|
185
|
-
type: value.type
|
|
205
|
+
type: value.type,
|
|
206
|
+
schema
|
|
186
207
|
});
|
|
187
208
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return schema;
|
|
209
|
+
});
|
|
210
|
+
_inputData.description = ''; // 避免第一层出现注释
|
|
211
|
+
return _inputData;
|
|
192
212
|
}
|
|
193
213
|
/**
|
|
194
214
|
* 获取用于显示的数据类型(仅有 number, string , boolean, array, object 等内置基础类型)
|
|
@@ -229,14 +249,14 @@ function _generateOneItemDTS(inputData, itemType, currentWholdDTS) {
|
|
|
229
249
|
[IInputDataType.globalState]: function (inputData) {
|
|
230
250
|
return __awaiter(this, void 0, void 0, function* () {
|
|
231
251
|
// 完善注释信息
|
|
232
|
-
const handledInputData = _handleComment(inputData, GroupEnum.GLOBAL_VAR);
|
|
252
|
+
const handledInputData = _handleComment(inputData, GroupEnum.GLOBAL_VAR, true);
|
|
233
253
|
return yield _compile(handledInputData);
|
|
234
254
|
});
|
|
235
255
|
},
|
|
236
256
|
[IInputDataType.pageState]: function (inputData) {
|
|
237
257
|
return __awaiter(this, void 0, void 0, function* () {
|
|
238
258
|
// 完善注释信息
|
|
239
|
-
const handledInputData = _handleComment(inputData, GroupEnum.PAGE_VAR);
|
|
259
|
+
const handledInputData = _handleComment(inputData, GroupEnum.PAGE_VAR, true);
|
|
240
260
|
return yield _compile(handledInputData);
|
|
241
261
|
});
|
|
242
262
|
},
|
|
@@ -334,8 +354,15 @@ function _generateOneItemDTS(inputData, itemType, currentWholdDTS) {
|
|
|
334
354
|
// ${exportMethodsDTS}
|
|
335
355
|
// }
|
|
336
356
|
// `
|
|
357
|
+
const interfaceName = _genCompInterfaceName(item.module, item.component);
|
|
337
358
|
return `
|
|
338
|
-
|
|
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 {
|
|
339
366
|
|
|
340
367
|
${exportPropertiesDTS}
|
|
341
368
|
|
|
@@ -357,7 +384,9 @@ function _generateOneItemDTS(inputData, itemType, currentWholdDTS) {
|
|
|
357
384
|
title: '',
|
|
358
385
|
description: '',
|
|
359
386
|
group: GroupEnum.COMPONENT,
|
|
360
|
-
type: 'component'
|
|
387
|
+
type: 'component',
|
|
388
|
+
baseClass: interfaceName,
|
|
389
|
+
datasource: `$${id}_start$ $${id}_end$`
|
|
361
390
|
}).split('\n').map(item => `* ${item}`).join('\n')}
|
|
362
391
|
*/
|
|
363
392
|
const ${id}: ${interfaceName}`).join('\n');
|
|
@@ -368,25 +397,37 @@ function _generateOneItemDTS(inputData, itemType, currentWholdDTS) {
|
|
|
368
397
|
[IInputDataType.repeaterScope]: function (inputData) {
|
|
369
398
|
return __awaiter(this, void 0, void 0, function* () {
|
|
370
399
|
const results = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
371
|
-
let itemDataDTS =
|
|
400
|
+
let itemDataDTS = '';
|
|
401
|
+
if (item.itemData.title) {
|
|
402
|
+
// 特殊场景:数据字段
|
|
403
|
+
const handledInputData = _handleComment(item.itemData, GroupEnum.DATA_FIELD);
|
|
404
|
+
itemDataDTS = yield _compile(handledInputData, true);
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
// 普通的循环项数据
|
|
408
|
+
itemDataDTS = yield _compile(item.itemData, true);
|
|
409
|
+
}
|
|
372
410
|
return `
|
|
373
411
|
/**
|
|
374
412
|
${genWeDaCodeComment({
|
|
375
413
|
fieldName: item.currentItemAlias,
|
|
376
|
-
title: '',
|
|
414
|
+
title: '当前项值',
|
|
377
415
|
description: '',
|
|
378
416
|
group: GroupEnum.REPEATER,
|
|
379
|
-
type: getDisplayReturnType(itemDataDTS)
|
|
417
|
+
type: getDisplayReturnType(itemDataDTS),
|
|
418
|
+
schema: item.itemData,
|
|
419
|
+
subGroup: item.widgetId
|
|
380
420
|
}).split('\n').map(item => `* ${item}`).join('\n')}
|
|
381
421
|
*/
|
|
382
422
|
const ${item.currentItemAlias}: ${itemDataDTS}
|
|
383
423
|
/**
|
|
384
424
|
${genWeDaCodeComment({
|
|
385
425
|
fieldName: item.currentIndexAlias,
|
|
386
|
-
title: '',
|
|
426
|
+
title: '当前下标',
|
|
387
427
|
description: '',
|
|
388
428
|
group: GroupEnum.REPEATER,
|
|
389
|
-
type: 'number'
|
|
429
|
+
type: 'number',
|
|
430
|
+
subGroup: item.widgetId
|
|
390
431
|
}).split('\n').map(item => `* ${item}`).join('\n')}
|
|
391
432
|
*/
|
|
392
433
|
const ${item.currentIndexAlias}: number
|
|
@@ -400,24 +441,70 @@ function _generateOneItemDTS(inputData, itemType, currentWholdDTS) {
|
|
|
400
441
|
const results = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
401
442
|
const compInterfaceName = _genCompInterfaceName(item.module, item.component);
|
|
402
443
|
const widgetInterfaceName = `${item.widgetId}_${compInterfaceName}`;
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
444
|
+
/**
|
|
445
|
+
* 更新 widget 的类型名
|
|
446
|
+
*/
|
|
447
|
+
replaceRules.push({
|
|
448
|
+
from: new RegExp(`(const ${item.widgetId}): .*`),
|
|
449
|
+
to: `$1: ${widgetInterfaceName}`
|
|
450
|
+
});
|
|
451
|
+
/**
|
|
452
|
+
* 增加类
|
|
453
|
+
*/
|
|
454
|
+
const datasources = {};
|
|
455
|
+
const propDefinitions = yield Promise.all(item.updateProps.map((prop) => __awaiter(this, void 0, void 0, function* () {
|
|
456
|
+
const properties = _handleComment(prop.widgetPropTypeSchema, GroupEnum.DATA_FIELD);
|
|
457
|
+
const widgetPropTypeDTS = yield _compile(Object.assign(Object.assign({}, prop.widgetPropTypeSchema), properties), true);
|
|
458
|
+
// 同个数据源,有可能是数组类型,所以需要区分开
|
|
459
|
+
const id = `${prop.datasource.name}_${prop.widgetPropTypeSchema.type}`;
|
|
460
|
+
if (!datasources[id]) {
|
|
461
|
+
datasources[id] = { fields: [{ name: prop.widgetPropName, title: prop.widgetPropTitle }], schema: prop.widgetPropTypeSchema, name: prop.datasource.name, title: prop.datasource.title };
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
datasources[id].fields.push({ name: prop.widgetPropName, title: prop.widgetPropTitle });
|
|
465
|
+
}
|
|
466
|
+
// 是否是多层级字段,如 "a.b"
|
|
467
|
+
// FIXME: 当前只支持 a.b 这种形式,不支持 a[].b
|
|
468
|
+
const multiLevelField = prop.widgetPropName.includes('.');
|
|
469
|
+
let multiLevelFields = [];
|
|
470
|
+
let multiLevelFieldObj = {};
|
|
471
|
+
let firstField = '';
|
|
472
|
+
let othersFields = [];
|
|
473
|
+
if (multiLevelField) {
|
|
474
|
+
multiLevelFields = prop.widgetPropName.split('.');
|
|
475
|
+
(0, lodash_1.set)(multiLevelFieldObj, prop.widgetPropName, "$$schema$$");
|
|
476
|
+
const [_firstField, ..._othersFields] = multiLevelFields;
|
|
477
|
+
firstField = _firstField;
|
|
478
|
+
othersFields = _othersFields;
|
|
479
|
+
}
|
|
480
|
+
return `
|
|
481
|
+
/**
|
|
482
|
+
${genWeDaCodeComment({
|
|
483
|
+
fieldName: prop.widgetPropName,
|
|
484
|
+
title: prop.widgetPropTypeSchema.title,
|
|
485
|
+
description: prop.widgetPropTypeSchema.description,
|
|
486
|
+
group: undefined,
|
|
487
|
+
type: getDisplayReturnType(widgetPropTypeDTS)
|
|
488
|
+
}).split('\n').map(item => `* ${item}`).join('\n')}
|
|
489
|
+
*/
|
|
490
|
+
${multiLevelField ? `${firstField}: Omit<${compInterfaceName}['${firstField}'], '${othersFields.join(".")}'> & ${JSON.stringify(multiLevelFieldObj[firstField]).replace('"$$schema$$"', widgetPropTypeDTS)}` : `${prop.widgetPropName}: ${widgetPropTypeDTS}`}
|
|
491
|
+
`;
|
|
492
|
+
})));
|
|
493
|
+
/**
|
|
494
|
+
* 更新数据源信息
|
|
495
|
+
*/
|
|
496
|
+
const datasourceInfoList = Object.values(datasources);
|
|
497
|
+
if (datasourceInfoList.length > 0) {
|
|
498
|
+
console.log(datasourceInfoList);
|
|
499
|
+
replaceRules.push({
|
|
500
|
+
from: new RegExp(`(\\$${item.widgetId}_start\\$).*(\\$${item.widgetId}_end\\$)`),
|
|
501
|
+
// encodeURIComponent 是为了能正常 parse 成 JSON
|
|
502
|
+
to: `$1${encodeURIComponent(JSON.stringify(datasourceInfoList))}$2`
|
|
503
|
+
});
|
|
504
|
+
}
|
|
408
505
|
return `
|
|
409
506
|
declare class ${widgetInterfaceName} extends ${compInterfaceName} {
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
${genWeDaCodeComment({
|
|
413
|
-
fieldName: item.widgetPropName,
|
|
414
|
-
title: item.widgetPropTypeSchema.title,
|
|
415
|
-
description: item.widgetPropTypeSchema.description,
|
|
416
|
-
group: undefined,
|
|
417
|
-
type: getDisplayReturnType(widgetPropTypeDTS)
|
|
418
|
-
}).split('\n').map(item => `* ${item}`).join('\n')}
|
|
419
|
-
*/
|
|
420
|
-
${item.widgetPropName}: ${widgetPropTypeDTS}
|
|
507
|
+
${propDefinitions.join('\n')}
|
|
421
508
|
}
|
|
422
509
|
`;
|
|
423
510
|
})));
|
|
@@ -427,14 +514,14 @@ function _generateOneItemDTS(inputData, itemType, currentWholdDTS) {
|
|
|
427
514
|
};
|
|
428
515
|
let dts = '';
|
|
429
516
|
if (!inputData)
|
|
430
|
-
return dts;
|
|
517
|
+
return [dts, replaceRules];
|
|
431
518
|
const handler = hanlderMap[itemType];
|
|
432
519
|
// 优先判断是否有独立的处理逻辑
|
|
433
520
|
if (handler) {
|
|
434
521
|
dts = yield handler.call(hanlderMap, inputData);
|
|
435
522
|
}
|
|
436
523
|
dts = dts || (yield _compile(inputData));
|
|
437
|
-
return [dts,
|
|
524
|
+
return [dts, replaceRules];
|
|
438
525
|
});
|
|
439
526
|
}
|
|
440
527
|
// 仅仅为了与 unittest 共享,外部请不要使用
|
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.11",
|
|
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",
|