@cloudbase/cals 0.5.13-alpha.0 → 0.5.13-alpha.2
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,101 @@ 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
|
+
var _a;
|
|
180
|
+
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)) {
|
|
181
|
+
// value?.type?.type 有值,则证明 type 是自定义的字段,而非 JSONSchema 中的 type
|
|
182
|
+
value.description = genWeDaCodeComment({
|
|
183
|
+
fieldName: key,
|
|
184
|
+
title: value.title,
|
|
185
|
+
description: value.description,
|
|
186
|
+
group: group,
|
|
187
|
+
type: value.type
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return value;
|
|
191
|
+
}));
|
|
192
|
+
schema.description = ''; // 避免第一层出现注释
|
|
193
|
+
return schema;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* 获取用于显示的数据类型(仅有 number, string , boolean, array, object 等内置基础类型)
|
|
197
|
+
*/
|
|
198
|
+
function getDisplayReturnType(typeStr) {
|
|
199
|
+
let displayType = typeStr.trim();
|
|
200
|
+
if (displayType.endsWith('[]')) {
|
|
201
|
+
displayType = 'array';
|
|
202
|
+
}
|
|
203
|
+
else if (displayType.endsWith('}')) {
|
|
204
|
+
displayType = 'object';
|
|
205
|
+
}
|
|
206
|
+
return displayType;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* 获取组件接口定义名称
|
|
210
|
+
*/
|
|
211
|
+
function _genCompInterfaceName(module, component) {
|
|
212
|
+
return `${module.replace(/-/g, '_')}_${component}`;
|
|
213
|
+
}
|
|
214
|
+
function _compile(jsonschema, isObjNeedWrapper = false) {
|
|
215
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
+
let dts = yield compileJSONToDTS(jsonschema);
|
|
217
|
+
if (dts.search(/^export interface IWeDa/) >= 0) {
|
|
218
|
+
dts = dts.replace(/^export interface.*$/m, '');
|
|
219
|
+
dts = dts.substring(0, dts.length - 2);
|
|
220
|
+
if (isObjNeedWrapper) {
|
|
221
|
+
dts = `{${dts}}`;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
dts = dts.replace(/^export type IWeDa =/m, '');
|
|
226
|
+
}
|
|
227
|
+
return dts;
|
|
228
|
+
});
|
|
229
|
+
}
|
|
154
230
|
const hanlderMap = {
|
|
231
|
+
[IInputDataType.globalState]: function (inputData) {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
// 完善注释信息
|
|
234
|
+
const handledInputData = _handleComment(inputData, GroupEnum.GLOBAL_VAR);
|
|
235
|
+
return yield _compile(handledInputData);
|
|
236
|
+
});
|
|
237
|
+
},
|
|
238
|
+
[IInputDataType.pageState]: function (inputData) {
|
|
239
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
240
|
+
// 完善注释信息
|
|
241
|
+
const handledInputData = _handleComment(inputData, GroupEnum.PAGE_VAR);
|
|
242
|
+
return yield _compile(handledInputData);
|
|
243
|
+
});
|
|
244
|
+
},
|
|
245
|
+
[IInputDataType.pageParams]: function (inputData) {
|
|
246
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
247
|
+
// 完善注释信息
|
|
248
|
+
const handledInputData = _handleComment(inputData, GroupEnum.PAGE_PARAM);
|
|
249
|
+
return yield _compile(handledInputData);
|
|
250
|
+
});
|
|
251
|
+
},
|
|
155
252
|
[IInputDataType.globalCommonCodes]: function (inputData) {
|
|
156
253
|
return __awaiter(this, void 0, void 0, function* () {
|
|
157
254
|
const dts = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -205,7 +302,8 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
205
302
|
// 属性
|
|
206
303
|
let exportPropertiesDTS = '';
|
|
207
304
|
if (item.exportProperties) {
|
|
208
|
-
|
|
305
|
+
const handledProperties = _handleComment(item.exportProperties);
|
|
306
|
+
exportPropertiesDTS = yield _compile(handledProperties);
|
|
209
307
|
}
|
|
210
308
|
// 方法
|
|
211
309
|
let exportMethodsDTS = '';
|
|
@@ -254,7 +352,17 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
254
352
|
return inputData.map(item => {
|
|
255
353
|
if (item.idList && item.idList.length > 0) {
|
|
256
354
|
const interfaceName = _genCompInterfaceName(item.module, item.component);
|
|
257
|
-
return item.idList.map(id => `
|
|
355
|
+
return item.idList.map(id => `
|
|
356
|
+
/**
|
|
357
|
+
${genWeDaCodeComment({
|
|
358
|
+
fieldName: id,
|
|
359
|
+
title: '',
|
|
360
|
+
description: '',
|
|
361
|
+
group: GroupEnum.COMPONENT,
|
|
362
|
+
type: 'component' // 组件显示的类型为 component
|
|
363
|
+
}).split('\n').map(item => `* ${item}`).join('\n')}
|
|
364
|
+
*/
|
|
365
|
+
const ${id}: ${interfaceName}`).join('\n');
|
|
258
366
|
}
|
|
259
367
|
return '';
|
|
260
368
|
}).join('\n');
|
|
@@ -264,13 +372,60 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
264
372
|
const results = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
265
373
|
let itemDataDTS = yield _compile(item.itemData, true);
|
|
266
374
|
return `
|
|
375
|
+
/**
|
|
376
|
+
${genWeDaCodeComment({
|
|
377
|
+
fieldName: item.currentItemAlias,
|
|
378
|
+
title: '',
|
|
379
|
+
description: '',
|
|
380
|
+
group: GroupEnum.REPEATER,
|
|
381
|
+
type: getDisplayReturnType(itemDataDTS)
|
|
382
|
+
}).split('\n').map(item => `* ${item}`).join('\n')}
|
|
383
|
+
*/
|
|
267
384
|
const ${item.currentItemAlias}: ${itemDataDTS}
|
|
385
|
+
/**
|
|
386
|
+
${genWeDaCodeComment({
|
|
387
|
+
fieldName: item.currentIndexAlias,
|
|
388
|
+
title: '',
|
|
389
|
+
description: '',
|
|
390
|
+
group: GroupEnum.REPEATER,
|
|
391
|
+
type: 'number'
|
|
392
|
+
}).split('\n').map(item => `* ${item}`).join('\n')}
|
|
393
|
+
*/
|
|
268
394
|
const ${item.currentIndexAlias}: number
|
|
269
395
|
`;
|
|
270
396
|
})));
|
|
271
397
|
return results.join('\n');
|
|
272
398
|
});
|
|
273
399
|
},
|
|
400
|
+
[IInputDataType.redefineAnyType]: function (inputData) {
|
|
401
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
402
|
+
const results = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
403
|
+
const compInterfaceName = _genCompInterfaceName(item.module, item.component);
|
|
404
|
+
const widgetInterfaceName = `${item.widgetId}_${compInterfaceName}`;
|
|
405
|
+
// 更新
|
|
406
|
+
currentWholdDTS = currentWholdDTS.replace(new RegExp(`(const ${item.widgetId}): .*`), `$1: ${widgetInterfaceName}`);
|
|
407
|
+
// 增加类
|
|
408
|
+
const properties = _handleComment(item.widgetPropTypeSchema, GroupEnum.DATA_FIELD);
|
|
409
|
+
const widgetPropTypeDTS = yield _compile(Object.assign(Object.assign({}, item.widgetPropTypeSchema), properties), true);
|
|
410
|
+
return `
|
|
411
|
+
declare class ${widgetInterfaceName} extends ${compInterfaceName} {
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
${genWeDaCodeComment({
|
|
415
|
+
fieldName: item.widgetPropName,
|
|
416
|
+
title: item.widgetPropTypeSchema.title,
|
|
417
|
+
description: item.widgetPropTypeSchema.description,
|
|
418
|
+
group: undefined,
|
|
419
|
+
type: getDisplayReturnType(widgetPropTypeDTS)
|
|
420
|
+
}).split('\n').map(item => `* ${item}`).join('\n')}
|
|
421
|
+
*/
|
|
422
|
+
${item.widgetPropName}: ${widgetPropTypeDTS}
|
|
423
|
+
}
|
|
424
|
+
`;
|
|
425
|
+
})));
|
|
426
|
+
return results.join('\n');
|
|
427
|
+
});
|
|
428
|
+
}
|
|
274
429
|
};
|
|
275
430
|
let dts = '';
|
|
276
431
|
if (!inputData)
|
|
@@ -281,26 +436,7 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
281
436
|
dts = yield handler.call(hanlderMap, inputData);
|
|
282
437
|
}
|
|
283
438
|
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
|
-
}
|
|
439
|
+
return [dts, currentWholdDTS];
|
|
304
440
|
});
|
|
305
441
|
}
|
|
306
442
|
// 仅仅为了与 unittest 共享,外部请不要使用
|