@cloudbase/cals 0.5.13-alpha.0 → 0.5.13-alpha.10

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.
@@ -19,10 +19,24 @@ 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;
25
26
  }
27
+ export interface IInputDataRedefineAnyType {
28
+ module: string;
29
+ component: string;
30
+ widgetId: string;
31
+ updateProps: {
32
+ widgetPropName: string;
33
+ widgetPropTypeSchema: IJsonSchemaAny;
34
+ datasource: {
35
+ name: string;
36
+ title: string;
37
+ };
38
+ }[];
39
+ }
26
40
  export interface IOptions {
27
41
  isCompMode?: boolean;
28
42
  needGlobalFormula?: boolean;
@@ -42,7 +56,8 @@ export declare enum IInputDataType {
42
56
  compPropEvents = "compPropEvents",
43
57
  usedComponents = "usedComponents",
44
58
  usedWidgets = "usedWidgets",
45
- repeaterScope = "repeaterScope"
59
+ repeaterScope = "repeaterScope",
60
+ redefineAnyType = "redefineAnyType"
46
61
  }
47
62
  export interface IInputData {
48
63
  [IInputDataType.globalState]?: IJsonSchemaObject;
@@ -58,6 +73,7 @@ export interface IInputData {
58
73
  [IInputDataType.usedComponents]?: IInputDataUsedComponents[];
59
74
  [IInputDataType.usedWidgets]?: IInputDataWidgetItem[];
60
75
  [IInputDataType.repeaterScope]?: IInputDataRepeaterItem[];
76
+ [IInputDataType.redefineAnyType]?: IInputDataRedefineAnyType[];
61
77
  }
62
78
  /**
63
79
  * 通过该类可以共享同个dts。
@@ -72,7 +88,7 @@ export declare class WeDaDTS {
72
88
  /**
73
89
  * 部分更新 - 只更新一种类型
74
90
  */
75
- static updateDTSPartial(inputData: IJsonSchemaObject | IDTSCodeItem[] | string[] | IInputDataUsedComponents[] | IInputDataWidgetItem[] | IInputDataRepeaterItem[], itemType: IInputDataType, options?: {
91
+ static updateDTSPartial(inputData: IJsonSchemaObject | IDTSCodeItem[] | string[] | IInputDataUsedComponents[] | IInputDataWidgetItem[] | IInputDataRepeaterItem[] | IInputDataRedefineAnyType[], itemType: IInputDataType, options?: {
76
92
  setEmptyIfError: boolean;
77
93
  }): Promise<void>;
78
94
  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":"AACA,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,QAAQ,EAAE,cAAc,CAAA;CACzB;AAED,MAAM,WAAW,QAAQ;IAEvB,UAAU,CAAC,EAAE,OAAO,CAAA;IAEpB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAE3B,aAAa,CAAC,EAAE,OAAO,CAAA;IAEvB,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B;AAED,oBAAY,cAAc;IACxB,WAAW,gBAAgB;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E,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"}
@@ -8,8 +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;
16
+ const lodash_1 = require("lodash");
17
+ const json_easy_filter_1 = __importDefault(require("json-easy-filter"));
13
18
  const auto_generated_1 = require("./auto-generated");
14
19
  var IInputDataType;
15
20
  (function (IInputDataType) {
@@ -26,6 +31,7 @@ var IInputDataType;
26
31
  IInputDataType["usedComponents"] = "usedComponents";
27
32
  IInputDataType["usedWidgets"] = "usedWidgets";
28
33
  IInputDataType["repeaterScope"] = "repeaterScope";
34
+ IInputDataType["redefineAnyType"] = "redefineAnyType";
29
35
  })(IInputDataType = exports.IInputDataType || (exports.IInputDataType = {}));
30
36
  const DtsPlaceholder = {
31
37
  [IInputDataType.globalState]: "// Global State 全局变量 - Don't touch me",
@@ -40,7 +46,8 @@ const DtsPlaceholder = {
40
46
  [IInputDataType.compPropEvents]: "// Comp Prop Events 组件事件 - Don't touch me",
41
47
  [IInputDataType.usedComponents]: "// Used Components - Don't touch me",
42
48
  [IInputDataType.usedWidgets]: "// used widgets - Don't touch me",
43
- [IInputDataType.repeaterScope]: "// repeater scope - Don't touch me"
49
+ [IInputDataType.repeaterScope]: "// repeater scope - Don't touch me",
50
+ [IInputDataType.redefineAnyType]: "// Redefine Any Type - Don't touch me",
44
51
  };
45
52
  const DtsInnerSign = {
46
53
  [IInputDataType.globalState]: "Global State Inner",
@@ -55,8 +62,18 @@ const DtsInnerSign = {
55
62
  [IInputDataType.compPropEvents]: "Comp Prop Events Inner",
56
63
  [IInputDataType.usedComponents]: "Used Components Inner",
57
64
  [IInputDataType.usedWidgets]: "used widgets Inner",
58
- [IInputDataType.repeaterScope]: "repeater scope Inner"
65
+ [IInputDataType.repeaterScope]: "repeater scope Inner",
66
+ [IInputDataType.redefineAnyType]: "Redefine Any Type Inner",
59
67
  };
68
+ var GroupEnum;
69
+ (function (GroupEnum) {
70
+ GroupEnum["GLOBAL_VAR"] = "globalVar";
71
+ GroupEnum["PAGE_VAR"] = "pageVar";
72
+ GroupEnum["PAGE_PARAM"] = "pageParam";
73
+ GroupEnum["COMPONENT"] = "component";
74
+ GroupEnum["REPEATER"] = "repeater";
75
+ GroupEnum["DATA_FIELD"] = "dataField";
76
+ })(GroupEnum || (GroupEnum = {}));
60
77
  /**
61
78
  * 通过该类可以共享同个dts。
62
79
  * 场景:在 weda 中,低代码的变更会通知更改 dts,而低码编辑器和表达式编辑器对 dts 的需求是不一样的,这样不同的 dts 共享的是同一份全的 dts。如果直接调用 generateWeDaAppDTS 会导致 dts 重复地解析
@@ -75,14 +92,16 @@ class WeDaDTS {
75
92
  */
76
93
  static updateDTSPartial(inputData, itemType, options = { setEmptyIfError: false }) {
77
94
  return __awaiter(this, void 0, void 0, function* () {
78
- let dts = '';
79
95
  try {
80
- dts = yield _generateOneItemDTS(inputData, itemType);
96
+ const [dts, replaceRules] = yield _generateOneItemDTS(inputData, itemType);
97
+ replaceRules.forEach(rule => {
98
+ WeDaDTS._dts = WeDaDTS._dts.replace(rule.from, rule.to);
99
+ });
81
100
  WeDaDTS._dts = WeDaDTS._dts.replace(new RegExp(`^(\\s*\\/\\/ ${DtsInnerSign[itemType]} Begin)[\\s\\S]*(^\\s*\\/\\/ ${DtsInnerSign[itemType]} End)`, 'm'), `$1\n${dts}\n$2`);
82
101
  }
83
102
  catch (e) {
84
103
  if (options.setEmptyIfError) {
85
- WeDaDTS._dts = WeDaDTS._dts.replace(new RegExp(`^(\\s*\\/\\/ ${DtsInnerSign[itemType]} Begin)[\\s\\S]*(^\\s*\\/\\/ ${DtsInnerSign[itemType]} End)`, 'm'), `$1\n${dts}\n$2`);
104
+ WeDaDTS._dts = WeDaDTS._dts.replace(new RegExp(`^(\\s*\\/\\/ ${DtsInnerSign[itemType]} Begin)[\\s\\S]*(^\\s*\\/\\/ ${DtsInnerSign[itemType]} End)`, 'm'), `$1\n${''}\n$2`);
86
105
  }
87
106
  }
88
107
  });
@@ -114,8 +133,11 @@ function generateWeDaAppDTS(inputData = {}, options = { isCompMode: false, needG
114
133
  if (placeholder) {
115
134
  // 防止某项错误导致全部都错误
116
135
  try {
117
- const dts = yield _generateOneItemDTS(inputData[key], key);
118
- resultDts = resultDts.replace(placeholder, dts + placeholder);
136
+ const [dts, replaceRules] = yield _generateOneItemDTS(inputData[key], key);
137
+ replaceRules.forEach(rule => {
138
+ resultDts = resultDts.replace(rule.from, rule.to);
139
+ });
140
+ resultDts = resultDts.replace(placeholder, dts + '\n' + placeholder);
119
141
  }
120
142
  catch (e) {
121
143
  console.error(e);
@@ -141,17 +163,110 @@ function generateWeDaAppDTS(inputData = {}, options = { isCompMode: false, needG
141
163
  if (!(options === null || options === void 0 ? void 0 : options.needRepeaterScope)) {
142
164
  resultDts = resultDts.replace(/\/\/ repeater scope Inner Begin[\s\S]*\/\/ repeater scope Inner End$/m, '');
143
165
  }
144
- // console.log(resultDts)
145
166
  return resultDts;
146
167
  });
147
168
  }
148
169
  exports.generateWeDaAppDTS = generateWeDaAppDTS;
170
+ /**
171
+ * 生成 weda 专有的注释信息
172
+ */
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 })}`;
176
+ }
149
177
  /**
150
178
  * 生成指定类型的 DTS
151
179
  */
152
180
  function _generateOneItemDTS(inputData, itemType) {
153
181
  return __awaiter(this, void 0, void 0, function* () {
182
+ const replaceRules = [];
183
+ /**
184
+ * 处理注释信息
185
+ */
186
+ function _handleComment(inputData, group, needKeepSchema) {
187
+ const _inputData = (0, lodash_1.cloneDeep)(inputData);
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
+ }
200
+ value.description = genWeDaCodeComment({
201
+ fieldName: key,
202
+ title: value.title,
203
+ description: value.description,
204
+ group: group,
205
+ type: value.type,
206
+ schema
207
+ });
208
+ }
209
+ });
210
+ _inputData.description = ''; // 避免第一层出现注释
211
+ return _inputData;
212
+ }
213
+ /**
214
+ * 获取用于显示的数据类型(仅有 number, string , boolean, array, object 等内置基础类型)
215
+ */
216
+ function getDisplayReturnType(typeStr) {
217
+ let displayType = typeStr.trim();
218
+ if (displayType.endsWith('[]')) {
219
+ displayType = 'array';
220
+ }
221
+ else if (displayType.endsWith('}')) {
222
+ displayType = 'object';
223
+ }
224
+ return displayType;
225
+ }
226
+ /**
227
+ * 获取组件接口定义名称
228
+ */
229
+ function _genCompInterfaceName(module, component) {
230
+ return `${module.replace(/-/g, '_')}_${component}`;
231
+ }
232
+ function _compile(jsonschema, isObjNeedWrapper = false) {
233
+ return __awaiter(this, void 0, void 0, function* () {
234
+ let dts = yield compileJSONToDTS(jsonschema);
235
+ if (dts.search(/^export interface IWeDa/) >= 0) {
236
+ dts = dts.replace(/^export interface.*$/m, '');
237
+ dts = dts.substring(0, dts.length - 2);
238
+ if (isObjNeedWrapper) {
239
+ dts = `{${dts}}`;
240
+ }
241
+ }
242
+ else {
243
+ dts = dts.replace(/^export type IWeDa =/m, '');
244
+ }
245
+ return dts;
246
+ });
247
+ }
154
248
  const hanlderMap = {
249
+ [IInputDataType.globalState]: function (inputData) {
250
+ return __awaiter(this, void 0, void 0, function* () {
251
+ // 完善注释信息
252
+ const handledInputData = _handleComment(inputData, GroupEnum.GLOBAL_VAR, true);
253
+ return yield _compile(handledInputData);
254
+ });
255
+ },
256
+ [IInputDataType.pageState]: function (inputData) {
257
+ return __awaiter(this, void 0, void 0, function* () {
258
+ // 完善注释信息
259
+ const handledInputData = _handleComment(inputData, GroupEnum.PAGE_VAR, true);
260
+ return yield _compile(handledInputData);
261
+ });
262
+ },
263
+ [IInputDataType.pageParams]: function (inputData) {
264
+ return __awaiter(this, void 0, void 0, function* () {
265
+ // 完善注释信息
266
+ const handledInputData = _handleComment(inputData, GroupEnum.PAGE_PARAM);
267
+ return yield _compile(handledInputData);
268
+ });
269
+ },
155
270
  [IInputDataType.globalCommonCodes]: function (inputData) {
156
271
  return __awaiter(this, void 0, void 0, function* () {
157
272
  const dts = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
@@ -205,7 +320,8 @@ function _generateOneItemDTS(inputData, itemType) {
205
320
  // 属性
206
321
  let exportPropertiesDTS = '';
207
322
  if (item.exportProperties) {
208
- exportPropertiesDTS = yield _compile(item.exportProperties);
323
+ const handledProperties = _handleComment(item.exportProperties);
324
+ exportPropertiesDTS = yield _compile(handledProperties);
209
325
  }
210
326
  // 方法
211
327
  let exportMethodsDTS = '';
@@ -238,8 +354,15 @@ function _generateOneItemDTS(inputData, itemType) {
238
354
  // ${exportMethodsDTS}
239
355
  // }
240
356
  // `
357
+ const interfaceName = _genCompInterfaceName(item.module, item.component);
241
358
  return `
242
- declare class ${_genCompInterfaceName(item.module, item.component)} extends UserWidget {
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 {
243
366
 
244
367
  ${exportPropertiesDTS}
245
368
 
@@ -254,7 +377,19 @@ function _generateOneItemDTS(inputData, itemType) {
254
377
  return inputData.map(item => {
255
378
  if (item.idList && item.idList.length > 0) {
256
379
  const interfaceName = _genCompInterfaceName(item.module, item.component);
257
- return item.idList.map(id => `const ${id}: ${interfaceName}`).join('\n');
380
+ return item.idList.map(id => `
381
+ /**
382
+ ${genWeDaCodeComment({
383
+ fieldName: id,
384
+ title: '',
385
+ description: '',
386
+ group: GroupEnum.COMPONENT,
387
+ type: 'component',
388
+ baseClass: interfaceName,
389
+ datasource: `$${id}_start$ $${id}_end$`
390
+ }).split('\n').map(item => `* ${item}`).join('\n')}
391
+ */
392
+ const ${id}: ${interfaceName}`).join('\n');
258
393
  }
259
394
  return '';
260
395
  }).join('\n');
@@ -262,45 +397,131 @@ function _generateOneItemDTS(inputData, itemType) {
262
397
  [IInputDataType.repeaterScope]: function (inputData) {
263
398
  return __awaiter(this, void 0, void 0, function* () {
264
399
  const results = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
265
- let itemDataDTS = yield _compile(item.itemData, true);
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
+ }
266
410
  return `
411
+ /**
412
+ ${genWeDaCodeComment({
413
+ fieldName: item.currentItemAlias,
414
+ title: '当前项值',
415
+ description: '',
416
+ group: GroupEnum.REPEATER,
417
+ type: getDisplayReturnType(itemDataDTS),
418
+ schema: item.itemData,
419
+ subGroup: item.widgetId
420
+ }).split('\n').map(item => `* ${item}`).join('\n')}
421
+ */
267
422
  const ${item.currentItemAlias}: ${itemDataDTS}
423
+ /**
424
+ ${genWeDaCodeComment({
425
+ fieldName: item.currentIndexAlias,
426
+ title: '当前下标',
427
+ description: '',
428
+ group: GroupEnum.REPEATER,
429
+ type: 'number',
430
+ subGroup: item.widgetId
431
+ }).split('\n').map(item => `* ${item}`).join('\n')}
432
+ */
268
433
  const ${item.currentIndexAlias}: number
269
434
  `;
270
435
  })));
271
436
  return results.join('\n');
272
437
  });
273
438
  },
439
+ [IInputDataType.redefineAnyType]: function (inputData) {
440
+ return __awaiter(this, void 0, void 0, function* () {
441
+ const results = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
442
+ const compInterfaceName = _genCompInterfaceName(item.module, item.component);
443
+ const widgetInterfaceName = `${item.widgetId}_${compInterfaceName}`;
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: [prop.widgetPropName], schema: prop.widgetPropTypeSchema, name: prop.datasource.name, title: prop.datasource.title };
462
+ }
463
+ else {
464
+ datasources[id].fields.push(prop.widgetPropName);
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
+ }
505
+ return `
506
+ declare class ${widgetInterfaceName} extends ${compInterfaceName} {
507
+ ${propDefinitions.join('\n')}
508
+ }
509
+ `;
510
+ })));
511
+ return results.join('\n');
512
+ });
513
+ }
274
514
  };
275
515
  let dts = '';
276
516
  if (!inputData)
277
- return dts;
517
+ return [dts, replaceRules];
278
518
  const handler = hanlderMap[itemType];
279
519
  // 优先判断是否有独立的处理逻辑
280
520
  if (handler) {
281
521
  dts = yield handler.call(hanlderMap, inputData);
282
522
  }
283
523
  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
- }
524
+ return [dts, replaceRules];
304
525
  });
305
526
  }
306
527
  // 仅仅为了与 unittest 共享,外部请不要使用
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cals",
3
- "version": "0.5.13-alpha.0",
3
+ "version": "0.5.13-alpha.10",
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",