@cloudbase/cals 0.5.13-alpha.0 → 0.5.13-alpha.1
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
|
@@ -23,6 +23,13 @@ export interface IInputDataRepeaterItem {
|
|
|
23
23
|
currentIndexAlias: string;
|
|
24
24
|
itemData: IJsonSchemaAny;
|
|
25
25
|
}
|
|
26
|
+
export interface IInputDataRedefineAnyType {
|
|
27
|
+
module: string;
|
|
28
|
+
component: string;
|
|
29
|
+
widgetId: string;
|
|
30
|
+
widgetPropName: string;
|
|
31
|
+
widgetPropTypeSchema: IJsonSchemaAny;
|
|
32
|
+
}
|
|
26
33
|
export interface IOptions {
|
|
27
34
|
isCompMode?: boolean;
|
|
28
35
|
needGlobalFormula?: boolean;
|
|
@@ -42,7 +49,8 @@ export declare enum IInputDataType {
|
|
|
42
49
|
compPropEvents = "compPropEvents",
|
|
43
50
|
usedComponents = "usedComponents",
|
|
44
51
|
usedWidgets = "usedWidgets",
|
|
45
|
-
repeaterScope = "repeaterScope"
|
|
52
|
+
repeaterScope = "repeaterScope",
|
|
53
|
+
redefineAnyType = "redefineAnyType"
|
|
46
54
|
}
|
|
47
55
|
export interface IInputData {
|
|
48
56
|
[IInputDataType.globalState]?: IJsonSchemaObject;
|
|
@@ -58,6 +66,7 @@ export interface IInputData {
|
|
|
58
66
|
[IInputDataType.usedComponents]?: IInputDataUsedComponents[];
|
|
59
67
|
[IInputDataType.usedWidgets]?: IInputDataWidgetItem[];
|
|
60
68
|
[IInputDataType.repeaterScope]?: IInputDataRepeaterItem[];
|
|
69
|
+
[IInputDataType.redefineAnyType]?: IInputDataRedefineAnyType[];
|
|
61
70
|
}
|
|
62
71
|
/**
|
|
63
72
|
* 通过该类可以共享同个dts。
|
|
@@ -72,7 +81,7 @@ export declare class WeDaDTS {
|
|
|
72
81
|
/**
|
|
73
82
|
* 部分更新 - 只更新一种类型
|
|
74
83
|
*/
|
|
75
|
-
static updateDTSPartial(inputData: IJsonSchemaObject | IDTSCodeItem[] | string[] | IInputDataUsedComponents[] | IInputDataWidgetItem[] | IInputDataRepeaterItem[], itemType: IInputDataType, options?: {
|
|
84
|
+
static updateDTSPartial(inputData: IJsonSchemaObject | IDTSCodeItem[] | string[] | IInputDataUsedComponents[] | IInputDataWidgetItem[] | IInputDataRepeaterItem[] | IInputDataRedefineAnyType[], itemType: IInputDataType, options?: {
|
|
76
85
|
setEmptyIfError: boolean;
|
|
77
86
|
}): Promise<void>;
|
|
78
87
|
static getDTS(options?: Omit<IOptions, "isCompMode">): string;
|
|
@@ -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":"AAEA,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,EAAE,CAAA;CACvF;AACD,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,EAAE,CAAA;CACjB;AACD,MAAM,WAAW,sBAAsB;IACrC,gBAAgB,EAAE,MAAM,CAAA;IACxB,iBAAiB,EAAE,MAAM,CAAA;IACzB,QAA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AAM,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
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.compileJSONToDTS = exports.jsonToDTSWorkerCode = exports.transpileToDTS = exports.workerCode = exports.generateWeDaAppDTS = exports.WeDaDTS = exports.IInputDataType = void 0;
|
|
13
|
+
const lodash_1 = require("lodash");
|
|
13
14
|
const auto_generated_1 = require("./auto-generated");
|
|
14
15
|
var IInputDataType;
|
|
15
16
|
(function (IInputDataType) {
|
|
@@ -26,6 +27,7 @@ var IInputDataType;
|
|
|
26
27
|
IInputDataType["usedComponents"] = "usedComponents";
|
|
27
28
|
IInputDataType["usedWidgets"] = "usedWidgets";
|
|
28
29
|
IInputDataType["repeaterScope"] = "repeaterScope";
|
|
30
|
+
IInputDataType["redefineAnyType"] = "redefineAnyType";
|
|
29
31
|
})(IInputDataType = exports.IInputDataType || (exports.IInputDataType = {}));
|
|
30
32
|
const DtsPlaceholder = {
|
|
31
33
|
[IInputDataType.globalState]: "// Global State 全局变量 - Don't touch me",
|
|
@@ -40,7 +42,8 @@ const DtsPlaceholder = {
|
|
|
40
42
|
[IInputDataType.compPropEvents]: "// Comp Prop Events 组件事件 - Don't touch me",
|
|
41
43
|
[IInputDataType.usedComponents]: "// Used Components - Don't touch me",
|
|
42
44
|
[IInputDataType.usedWidgets]: "// used widgets - Don't touch me",
|
|
43
|
-
[IInputDataType.repeaterScope]: "// repeater scope - Don't touch me"
|
|
45
|
+
[IInputDataType.repeaterScope]: "// repeater scope - Don't touch me",
|
|
46
|
+
[IInputDataType.redefineAnyType]: "// Redefine Any Type - Don't touch me",
|
|
44
47
|
};
|
|
45
48
|
const DtsInnerSign = {
|
|
46
49
|
[IInputDataType.globalState]: "Global State Inner",
|
|
@@ -55,8 +58,18 @@ const DtsInnerSign = {
|
|
|
55
58
|
[IInputDataType.compPropEvents]: "Comp Prop Events Inner",
|
|
56
59
|
[IInputDataType.usedComponents]: "Used Components Inner",
|
|
57
60
|
[IInputDataType.usedWidgets]: "used widgets Inner",
|
|
58
|
-
[IInputDataType.repeaterScope]: "repeater scope Inner"
|
|
61
|
+
[IInputDataType.repeaterScope]: "repeater scope Inner",
|
|
62
|
+
[IInputDataType.redefineAnyType]: "Redefine Any Type Inner",
|
|
59
63
|
};
|
|
64
|
+
var GroupEnum;
|
|
65
|
+
(function (GroupEnum) {
|
|
66
|
+
GroupEnum["GLOBAL_VAR"] = "globalVar";
|
|
67
|
+
GroupEnum["PAGE_VAR"] = "pageVar";
|
|
68
|
+
GroupEnum["PAGE_PARAM"] = "pageParam";
|
|
69
|
+
GroupEnum["COMPONENT"] = "component";
|
|
70
|
+
GroupEnum["REPEATER"] = "repeater";
|
|
71
|
+
GroupEnum["DATA_FIELD"] = "dataField";
|
|
72
|
+
})(GroupEnum || (GroupEnum = {}));
|
|
60
73
|
/**
|
|
61
74
|
* 通过该类可以共享同个dts。
|
|
62
75
|
* 场景:在 weda 中,低代码的变更会通知更改 dts,而低码编辑器和表达式编辑器对 dts 的需求是不一样的,这样不同的 dts 共享的是同一份全的 dts。如果直接调用 generateWeDaAppDTS 会导致 dts 重复地解析
|
|
@@ -77,7 +90,7 @@ class WeDaDTS {
|
|
|
77
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
91
|
let dts = '';
|
|
79
92
|
try {
|
|
80
|
-
dts = yield _generateOneItemDTS(inputData, itemType);
|
|
93
|
+
[dts, WeDaDTS._dts] = yield _generateOneItemDTS(inputData, itemType, WeDaDTS._dts);
|
|
81
94
|
WeDaDTS._dts = WeDaDTS._dts.replace(new RegExp(`^(\\s*\\/\\/ ${DtsInnerSign[itemType]} Begin)[\\s\\S]*(^\\s*\\/\\/ ${DtsInnerSign[itemType]} End)`, 'm'), `$1\n${dts}\n$2`);
|
|
82
95
|
}
|
|
83
96
|
catch (e) {
|
|
@@ -114,8 +127,8 @@ function generateWeDaAppDTS(inputData = {}, options = { isCompMode: false, needG
|
|
|
114
127
|
if (placeholder) {
|
|
115
128
|
// 防止某项错误导致全部都错误
|
|
116
129
|
try {
|
|
117
|
-
const dts = yield _generateOneItemDTS(inputData[key], key);
|
|
118
|
-
resultDts = resultDts.replace(placeholder, dts + placeholder);
|
|
130
|
+
const [dts] = yield _generateOneItemDTS(inputData[key], key);
|
|
131
|
+
resultDts = resultDts.replace(placeholder, dts + '\n' + placeholder);
|
|
119
132
|
}
|
|
120
133
|
catch (e) {
|
|
121
134
|
console.error(e);
|
|
@@ -141,17 +154,99 @@ function generateWeDaAppDTS(inputData = {}, options = { isCompMode: false, needG
|
|
|
141
154
|
if (!(options === null || options === void 0 ? void 0 : options.needRepeaterScope)) {
|
|
142
155
|
resultDts = resultDts.replace(/\/\/ repeater scope Inner Begin[\s\S]*\/\/ repeater scope Inner End$/m, '');
|
|
143
156
|
}
|
|
144
|
-
// console.log(resultDts)
|
|
145
157
|
return resultDts;
|
|
146
158
|
});
|
|
147
159
|
}
|
|
148
160
|
exports.generateWeDaAppDTS = generateWeDaAppDTS;
|
|
161
|
+
/**
|
|
162
|
+
* 生成 weda 专有的注释信息
|
|
163
|
+
*/
|
|
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 || '' })}`;
|
|
167
|
+
}
|
|
149
168
|
/**
|
|
150
169
|
* 生成指定类型的 DTS
|
|
151
170
|
*/
|
|
152
|
-
function _generateOneItemDTS(inputData, itemType) {
|
|
171
|
+
function _generateOneItemDTS(inputData, itemType, currentWholdDTS) {
|
|
153
172
|
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
/**
|
|
174
|
+
* 处理注释信息
|
|
175
|
+
*/
|
|
176
|
+
function _handleComment(inputData, group) {
|
|
177
|
+
const _inputData = (0, lodash_1.cloneDeep)(inputData);
|
|
178
|
+
const schema = JSON.parse(JSON.stringify(_inputData, (key, value) => {
|
|
179
|
+
if (value === null || value === void 0 ? void 0 : value.type) {
|
|
180
|
+
value.description = genWeDaCodeComment({
|
|
181
|
+
fieldName: key,
|
|
182
|
+
title: value.title,
|
|
183
|
+
description: value.description,
|
|
184
|
+
group: group,
|
|
185
|
+
type: value.type
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
return value;
|
|
189
|
+
}));
|
|
190
|
+
schema.description = ''; // 避免第一层出现注释
|
|
191
|
+
return schema;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* 获取用于显示的数据类型(仅有 number, string , boolean, array, object 等内置基础类型)
|
|
195
|
+
*/
|
|
196
|
+
function getDisplayReturnType(typeStr) {
|
|
197
|
+
let displayType = typeStr.trim();
|
|
198
|
+
if (displayType.endsWith('[]')) {
|
|
199
|
+
displayType = 'array';
|
|
200
|
+
}
|
|
201
|
+
else if (displayType.endsWith('}')) {
|
|
202
|
+
displayType = 'object';
|
|
203
|
+
}
|
|
204
|
+
return displayType;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* 获取组件接口定义名称
|
|
208
|
+
*/
|
|
209
|
+
function _genCompInterfaceName(module, component) {
|
|
210
|
+
return `${module.replace(/-/g, '_')}_${component}`;
|
|
211
|
+
}
|
|
212
|
+
function _compile(jsonschema, isObjNeedWrapper = false) {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
let dts = yield compileJSONToDTS(jsonschema);
|
|
215
|
+
if (dts.search(/^export interface IWeDa/) >= 0) {
|
|
216
|
+
dts = dts.replace(/^export interface.*$/m, '');
|
|
217
|
+
dts = dts.substring(0, dts.length - 2);
|
|
218
|
+
if (isObjNeedWrapper) {
|
|
219
|
+
dts = `{${dts}}`;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
dts = dts.replace(/^export type IWeDa =/m, '');
|
|
224
|
+
}
|
|
225
|
+
return dts;
|
|
226
|
+
});
|
|
227
|
+
}
|
|
154
228
|
const hanlderMap = {
|
|
229
|
+
[IInputDataType.globalState]: function (inputData) {
|
|
230
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
// 完善注释信息
|
|
232
|
+
const handledInputData = _handleComment(inputData, GroupEnum.GLOBAL_VAR);
|
|
233
|
+
return yield _compile(handledInputData);
|
|
234
|
+
});
|
|
235
|
+
},
|
|
236
|
+
[IInputDataType.pageState]: function (inputData) {
|
|
237
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
238
|
+
// 完善注释信息
|
|
239
|
+
const handledInputData = _handleComment(inputData, GroupEnum.PAGE_VAR);
|
|
240
|
+
return yield _compile(handledInputData);
|
|
241
|
+
});
|
|
242
|
+
},
|
|
243
|
+
[IInputDataType.pageParams]: function (inputData) {
|
|
244
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
// 完善注释信息
|
|
246
|
+
const handledInputData = _handleComment(inputData, GroupEnum.PAGE_PARAM);
|
|
247
|
+
return yield _compile(handledInputData);
|
|
248
|
+
});
|
|
249
|
+
},
|
|
155
250
|
[IInputDataType.globalCommonCodes]: function (inputData) {
|
|
156
251
|
return __awaiter(this, void 0, void 0, function* () {
|
|
157
252
|
const dts = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -205,7 +300,8 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
205
300
|
// 属性
|
|
206
301
|
let exportPropertiesDTS = '';
|
|
207
302
|
if (item.exportProperties) {
|
|
208
|
-
|
|
303
|
+
const handledProperties = _handleComment(item.exportProperties);
|
|
304
|
+
exportPropertiesDTS = yield _compile(handledProperties);
|
|
209
305
|
}
|
|
210
306
|
// 方法
|
|
211
307
|
let exportMethodsDTS = '';
|
|
@@ -254,7 +350,17 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
254
350
|
return inputData.map(item => {
|
|
255
351
|
if (item.idList && item.idList.length > 0) {
|
|
256
352
|
const interfaceName = _genCompInterfaceName(item.module, item.component);
|
|
257
|
-
return item.idList.map(id => `
|
|
353
|
+
return item.idList.map(id => `
|
|
354
|
+
/**
|
|
355
|
+
${genWeDaCodeComment({
|
|
356
|
+
fieldName: id,
|
|
357
|
+
title: '',
|
|
358
|
+
description: '',
|
|
359
|
+
group: GroupEnum.COMPONENT,
|
|
360
|
+
type: 'component' // 组件显示的类型为 component
|
|
361
|
+
}).split('\n').map(item => `* ${item}`).join('\n')}
|
|
362
|
+
*/
|
|
363
|
+
const ${id}: ${interfaceName}`).join('\n');
|
|
258
364
|
}
|
|
259
365
|
return '';
|
|
260
366
|
}).join('\n');
|
|
@@ -264,13 +370,60 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
264
370
|
const results = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
265
371
|
let itemDataDTS = yield _compile(item.itemData, true);
|
|
266
372
|
return `
|
|
373
|
+
/**
|
|
374
|
+
${genWeDaCodeComment({
|
|
375
|
+
fieldName: item.currentItemAlias,
|
|
376
|
+
title: '',
|
|
377
|
+
description: '',
|
|
378
|
+
group: GroupEnum.REPEATER,
|
|
379
|
+
type: getDisplayReturnType(itemDataDTS)
|
|
380
|
+
}).split('\n').map(item => `* ${item}`).join('\n')}
|
|
381
|
+
*/
|
|
267
382
|
const ${item.currentItemAlias}: ${itemDataDTS}
|
|
383
|
+
/**
|
|
384
|
+
${genWeDaCodeComment({
|
|
385
|
+
fieldName: item.currentIndexAlias,
|
|
386
|
+
title: '',
|
|
387
|
+
description: '',
|
|
388
|
+
group: GroupEnum.REPEATER,
|
|
389
|
+
type: 'number'
|
|
390
|
+
}).split('\n').map(item => `* ${item}`).join('\n')}
|
|
391
|
+
*/
|
|
268
392
|
const ${item.currentIndexAlias}: number
|
|
269
393
|
`;
|
|
270
394
|
})));
|
|
271
395
|
return results.join('\n');
|
|
272
396
|
});
|
|
273
397
|
},
|
|
398
|
+
[IInputDataType.redefineAnyType]: function (inputData) {
|
|
399
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
400
|
+
const results = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
401
|
+
const compInterfaceName = _genCompInterfaceName(item.module, item.component);
|
|
402
|
+
const widgetInterfaceName = `${item.widgetId}_${compInterfaceName}`;
|
|
403
|
+
// 更新
|
|
404
|
+
currentWholdDTS = currentWholdDTS.replace(new RegExp(`(const ${item.widgetId}): .*`), `$1: ${widgetInterfaceName}`);
|
|
405
|
+
// 增加类
|
|
406
|
+
const properties = _handleComment(item.widgetPropTypeSchema, GroupEnum.DATA_FIELD);
|
|
407
|
+
const widgetPropTypeDTS = yield _compile(Object.assign(Object.assign({}, item.widgetPropTypeSchema), properties), true);
|
|
408
|
+
return `
|
|
409
|
+
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}
|
|
421
|
+
}
|
|
422
|
+
`;
|
|
423
|
+
})));
|
|
424
|
+
return results.join('\n');
|
|
425
|
+
});
|
|
426
|
+
}
|
|
274
427
|
};
|
|
275
428
|
let dts = '';
|
|
276
429
|
if (!inputData)
|
|
@@ -281,26 +434,7 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
281
434
|
dts = yield handler.call(hanlderMap, inputData);
|
|
282
435
|
}
|
|
283
436
|
dts = dts || (yield _compile(inputData));
|
|
284
|
-
return dts;
|
|
285
|
-
function _genCompInterfaceName(module, component) {
|
|
286
|
-
return `${module.replace(/-/g, '_')}_${component}`;
|
|
287
|
-
}
|
|
288
|
-
function _compile(jsonschema, isObjNeedWrapper = false) {
|
|
289
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
290
|
-
let dts = yield compileJSONToDTS(jsonschema);
|
|
291
|
-
if (dts.search(/^export interface IWeDa/) >= 0) {
|
|
292
|
-
dts = dts.replace(/^export interface.*$/m, '');
|
|
293
|
-
dts = dts.substring(0, dts.length - 2);
|
|
294
|
-
if (isObjNeedWrapper) {
|
|
295
|
-
dts = `{${dts}}`;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
dts = dts.replace(/^export type IWeDa =/m, '');
|
|
300
|
-
}
|
|
301
|
-
return dts;
|
|
302
|
-
});
|
|
303
|
-
}
|
|
437
|
+
return [dts, currentWholdDTS];
|
|
304
438
|
});
|
|
305
439
|
}
|
|
306
440
|
// 仅仅为了与 unittest 共享,外部请不要使用
|