@cloudbase/cals 0.5.12 → 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.
@@ -44,7 +44,7 @@ function buildFormulaDTS() {
44
44
  const dts = yield fs_extra_1.default.readFile(tempDtsPath, 'utf8');
45
45
  yield fs_extra_1.default.remove(tempDtsPath);
46
46
  // 去掉最外层的模块声明
47
- return dts.replace(/^declare module.*$/m, '').replace(/\}$/m, '').replace(/^\s+/mg, '');
47
+ return dts.replace(/^declare module.*$/m, '').replace(/^\}$/m, '').replace(/^\s+/mg, '');
48
48
  });
49
49
  }
50
50
  });
@@ -56,13 +56,24 @@ function genWeDaAPPDTS() {
56
56
  * 获取所有的 DTS
57
57
  */
58
58
  const wedaFrameworkDTS = yield fs_extra_1.default.readFile(path_1.default.resolve(__dirname, 'framework', 'weda-framework.d.ts'), 'utf8'); // 低码框架
59
- const wedaAPIDTS = yield fs_extra_1.default.readFile(path_1.default.resolve(__dirname, 'framework', 'weda-api.d.ts'), 'utf8'); // 低码 API
60
- const wedaAuthDTS = yield fs_extra_1.default.readFile(path_1.default.resolve(__dirname, 'framework', 'weda-auth.d.ts'), 'utf8'); // Auth 信息
59
+ const wedaAppDTS = yield fs_extra_1.default.readFile(path_1.default.resolve(__dirname, 'framework', 'weda-app.d.ts'), 'utf-8'); // app对象
60
+ const wedaPageDTS = yield fs_extra_1.default.readFile(path_1.default.resolve(__dirname, 'framework', 'weda-page.d.ts'), 'utf-8'); // page对象
61
+ const wedaAuthDTS = yield fs_extra_1.default.readFile(path_1.default.resolve(__dirname, 'framework', 'weda-auth.d.ts'), 'utf8'); // auth对象
62
+ const wedaCloudDTS = yield fs_extra_1.default.readFile(path_1.default.resolve(__dirname, 'framework', 'weda-cloud.d.ts'), 'utf-8'); // cloud对象
63
+ const wedaUtilsDTS = yield fs_extra_1.default.readFile(path_1.default.resolve(__dirname, 'framework', 'weda-utils.d.ts'), 'utf-8'); // page对象
61
64
  const formulaDTS = yield buildFormulaDTS(); // 函数公式
62
65
  /**
63
66
  * 聚合 DTS
64
67
  */
65
- const wedaDTS = groupDTSs({ wedaFrameworkDTS, wedaAPIDTS, wedaAuthDTS, formulaDTS });
68
+ const wedaDTS = groupDTSs({
69
+ wedaFrameworkDTS,
70
+ wedaAppDTS,
71
+ wedaPageDTS,
72
+ wedaAuthDTS,
73
+ wedaCloudDTS,
74
+ wedaUtilsDTS,
75
+ formulaDTS,
76
+ });
66
77
  /**
67
78
  * 将聚合结果保存在 auto-generated.ts
68
79
  */
@@ -73,21 +84,22 @@ function genWeDaAPPDTS() {
73
84
  /**
74
85
  * 聚合所有的 DTS(不包括动态生成的)
75
86
  */
76
- function groupDTSs({ wedaFrameworkDTS = '', wedaAPIDTS = '', wedaAuthDTS = '', formulaDTS = '' }) {
87
+ function groupDTSs({ wedaFrameworkDTS = '', wedaAppDTS = '', wedaPageDTS = '', wedaAuthDTS = '', wedaCloudDTS = '', wedaUtilsDTS = '', formulaDTS = '', }) {
77
88
  let resultDts = wedaFrameworkDTS;
78
- // 函数公式:$app.utils.xxx
79
- resultDts = resultDts.replace("// Formula 函数公式 - Don't touch me", formulaDTS.replace(/export/g, ''));
89
+ // $app
90
+ resultDts = resultDts.replaceAll("// $app - Don't touch me", wedaAppDTS);
91
+ // $page
92
+ resultDts = resultDts.replaceAll("// $page - Don't touch me", wedaPageDTS);
93
+ // $w.auth
94
+ resultDts = resultDts.replaceAll("// $w.auth - Don't touch me", wedaAuthDTS.replace(/declare/g, ''));
95
+ // $w.cloud
96
+ resultDts = resultDts.replaceAll("// $w.cloud - Don't touch me", wedaCloudDTS.replace(/declare/g, ''));
97
+ // $w.utils
98
+ resultDts = resultDts.replaceAll("// $w.utils - Don't touch me", wedaUtilsDTS.replace(/declare/g, ''));
99
+ // 函数公式:$w.xxx
100
+ resultDts = resultDts.replaceAll("// Formula 函数公式 - Don't touch me", formulaDTS.replace(/export/g, ''));
80
101
  // 函数公式:全局变量提示
81
102
  resultDts = resultDts.replace("// Global Formula 全局函数公式- Don't touch me", formulaDTS.replace(/export/g, 'declare'));
82
- // 函数公式:$w.xxx
83
- resultDts = resultDts.replace("// $w global APIs - Don't touch me", formulaDTS.replace(/export/g, ''));
84
- // 增加 API
85
- const appAPIDTS = wedaAPIDTS.replace(/[\s\S]*\/\/ ============ App API Begin ============ \/\/([\s\S]*?)\/\/ ============ App API End ============ \/\/[\s\S]*/, '$1');
86
- resultDts = resultDts.replace("// App API - Don't touch me", appAPIDTS);
87
- const pageAPIDTS = wedaAPIDTS.replace(/[\s\S]*\/\/ ============ Page API Begin ============ \/\/([\s\S]*?)\/\/ ============ Page API End ============ \/\/[\s\S]*/, '$1');
88
- resultDts = resultDts.replace("// Page API - Don't touch me", pageAPIDTS);
89
- // 增加 Auth 信息
90
- resultDts = resultDts.replace("// Auth 认证 - Don't touch me", wedaAuthDTS);
91
103
  return resultDts;
92
104
  }
93
105
  function main() {
@@ -97,8 +109,11 @@ function main() {
97
109
  if (watchArgv === '--watch') {
98
110
  console.log('Start watching mode');
99
111
  (0, node_watch_1.default)(path_1.default.resolve(__dirname, 'framework', 'weda-framework.d.ts'), genWeDaAPPDTS);
100
- (0, node_watch_1.default)(path_1.default.resolve(__dirname, 'framework', 'weda-api.d.ts'), genWeDaAPPDTS);
112
+ (0, node_watch_1.default)(path_1.default.resolve(__dirname, 'framework', 'weda-app.d.ts'), genWeDaAPPDTS);
113
+ (0, node_watch_1.default)(path_1.default.resolve(__dirname, 'framework', 'weda-page.d.ts'), genWeDaAPPDTS);
101
114
  (0, node_watch_1.default)(path_1.default.resolve(__dirname, 'framework', 'weda-auth.d.ts'), genWeDaAPPDTS);
115
+ (0, node_watch_1.default)(path_1.default.resolve(__dirname, 'framework', 'weda-cloud.d.ts'), genWeDaAPPDTS);
116
+ (0, node_watch_1.default)(path_1.default.resolve(__dirname, 'framework', 'weda-utils.d.ts'), genWeDaAPPDTS);
102
117
  }
103
118
  });
104
119
  }
@@ -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":"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,CAAC,CAO5D;AAID,eAAO,MAAM,mBAAmB,+tBAmB/B,CAAA;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,KAAA,GAAG,OAAO,CAAC,MAAM,CAAC,CAQ5D"}
@@ -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
- exportPropertiesDTS = yield _compile(item.exportProperties);
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 => `const ${id}: ${interfaceName}`).join('\n');
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 共享,外部请不要使用
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cals",
3
- "version": "0.5.12",
3
+ "version": "0.5.13-alpha.1",
4
4
  "description": "Common application specifications",
5
5
  "main": "lib/utils/index.js",
6
6
  "source": "src/utils/index.ts",