@cloudbase/cals 0.5.11-beta3 → 0.5.12-alpha.0
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/parser/cals/index.d.ts.map +1 -1
- package/lib/parser/cals/index.js +0 -7
- package/lib/parser/cals/utils/runtime.d.ts.map +1 -1
- package/lib/parser/cals/utils/runtime.js +1 -6
- package/lib/parser/expression/index.d.ts +1 -2
- package/lib/parser/expression/index.d.ts.map +1 -1
- package/lib/parser/expression/index.js +0 -1
- package/lib/types/basic/common.d.ts +0 -4
- package/lib/types/basic/common.d.ts.map +1 -1
- package/lib/utils/dts/auto-generated copy.d.ts +2 -0
- package/lib/utils/dts/auto-generated copy.d.ts.map +1 -0
- package/lib/utils/dts/auto-generated copy.js +392 -0
- package/lib/utils/dts/auto-generated.d.ts +1 -1
- package/lib/utils/dts/auto-generated.d.ts.map +1 -1
- package/lib/utils/dts/auto-generated.js +238 -66
- package/lib/utils/dts/build.js +36 -12
- package/lib/utils/dts/index.d.ts +10 -0
- package/lib/utils/dts/index.d.ts.map +1 -1
- package/lib/utils/dts/index.js +82 -36
- package/package.json +2 -2
package/lib/utils/dts/index.js
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -32,19 +9,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
9
|
});
|
|
33
10
|
};
|
|
34
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.transpileToDTS = exports.workerCode = exports.generateWeDaAppDTS = exports.WeDaDTS = exports.IInputDataType = void 0;
|
|
36
|
-
const jstt = __importStar(require("json-schema-to-typescript-for-browser/dist/bundle.js"));
|
|
12
|
+
exports.compileJSONToDTS = exports.jsonToDTSWorkerCode = exports.transpileToDTS = exports.workerCode = exports.generateWeDaAppDTS = exports.WeDaDTS = exports.IInputDataType = void 0;
|
|
37
13
|
const auto_generated_1 = require("./auto-generated");
|
|
38
|
-
const compile = jstt.compile;
|
|
39
14
|
var IInputDataType;
|
|
40
15
|
(function (IInputDataType) {
|
|
41
16
|
IInputDataType["globalState"] = "globalState";
|
|
17
|
+
IInputDataType["wGlobalState"] = "wGlobalState";
|
|
42
18
|
IInputDataType["pageState"] = "pageState";
|
|
19
|
+
IInputDataType["wPageState"] = "wPageState";
|
|
43
20
|
IInputDataType["compState"] = "compState";
|
|
44
21
|
IInputDataType["pageParams"] = "pageParams";
|
|
22
|
+
IInputDataType["wPageParams"] = "wPageParams";
|
|
45
23
|
IInputDataType["forState"] = "forState";
|
|
46
24
|
IInputDataType["globalCommonCodes"] = "globalCommonCodes";
|
|
25
|
+
IInputDataType["wGlobalCommonCodes"] = "wGlobalCommonCodes";
|
|
47
26
|
IInputDataType["pageHandlerCodes"] = "pageHandlerCodes";
|
|
27
|
+
IInputDataType["wPageHandlerCodes"] = "wPageHandlerCodes";
|
|
48
28
|
IInputDataType["compHandlerCodes"] = "compHandlerCodes";
|
|
49
29
|
IInputDataType["compPropData"] = "compPropData";
|
|
50
30
|
IInputDataType["compPropEvents"] = "compPropEvents";
|
|
@@ -69,12 +49,17 @@ const DtsPlaceholder = {
|
|
|
69
49
|
};
|
|
70
50
|
const DtsInnerSign = {
|
|
71
51
|
[IInputDataType.globalState]: "Global State Inner",
|
|
52
|
+
[IInputDataType.wGlobalState]: "wGlobal State Inner",
|
|
72
53
|
[IInputDataType.pageState]: "Page State Inner",
|
|
54
|
+
[IInputDataType.wPageState]: "wPage State Inner",
|
|
73
55
|
[IInputDataType.compState]: "Comp State Inner",
|
|
74
56
|
[IInputDataType.pageParams]: "Page Param Inner",
|
|
57
|
+
[IInputDataType.wPageParams]: "wPage Param Inner",
|
|
75
58
|
[IInputDataType.forState]: "Global For Inner",
|
|
76
59
|
[IInputDataType.globalCommonCodes]: "Global Common Inner",
|
|
60
|
+
[IInputDataType.wGlobalCommonCodes]: "wGlobal Common Inner",
|
|
77
61
|
[IInputDataType.pageHandlerCodes]: "Page Handler Inner",
|
|
62
|
+
[IInputDataType.wPageHandlerCodes]: "wPage Handler Inner",
|
|
78
63
|
[IInputDataType.compHandlerCodes]: "Comp Handler Inner",
|
|
79
64
|
[IInputDataType.compPropData]: "Comp Prop Data Inner",
|
|
80
65
|
[IInputDataType.compPropEvents]: "Comp Prop Events Inner",
|
|
@@ -101,13 +86,30 @@ class WeDaDTS {
|
|
|
101
86
|
static updateDTSPartial(inputData, itemType, options = { setEmptyIfError: false }) {
|
|
102
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
88
|
let dts = '';
|
|
89
|
+
// 必须区分$w下的和$page、$app下的,否则replace Inner Begin和Inner End的时候会有问题
|
|
90
|
+
const DTSMap = {
|
|
91
|
+
[DtsInnerSign[IInputDataType.globalState]]: DtsInnerSign[IInputDataType.wGlobalState],
|
|
92
|
+
[DtsInnerSign[IInputDataType.pageState]]: DtsInnerSign[IInputDataType.wPageState],
|
|
93
|
+
[DtsInnerSign[IInputDataType.pageParams]]: DtsInnerSign[IInputDataType.wPageParams],
|
|
94
|
+
[DtsInnerSign[IInputDataType.globalCommonCodes]]: DtsInnerSign[IInputDataType.wGlobalCommonCodes],
|
|
95
|
+
[DtsInnerSign[IInputDataType.pageHandlerCodes]]: DtsInnerSign[IInputDataType.wPageHandlerCodes],
|
|
96
|
+
};
|
|
97
|
+
const reg = new RegExp(`^(\\s*\\/\\/ ${DtsInnerSign[itemType]} Begin)[\\s\\S]*(^\\s*\\/\\/ ${DtsInnerSign[itemType]} End)`, 'm');
|
|
104
98
|
try {
|
|
105
99
|
dts = yield _generateOneItemDTS(inputData, itemType);
|
|
106
|
-
WeDaDTS._dts = WeDaDTS._dts.replace(
|
|
100
|
+
WeDaDTS._dts = WeDaDTS._dts.replace(reg, `$1\n${dts}\n$2`);
|
|
101
|
+
if (DTSMap[DtsInnerSign[itemType]]) {
|
|
102
|
+
const reg = new RegExp(`^(\\s*\\/\\/ ${DTSMap[DtsInnerSign[itemType]]} Begin)[\\s\\S]*(^\\s*\\/\\/ ${DTSMap[DtsInnerSign[itemType]]} End)`, 'm');
|
|
103
|
+
WeDaDTS._dts = WeDaDTS._dts.replace(reg, `$1\n${dts}\n$2`);
|
|
104
|
+
}
|
|
107
105
|
}
|
|
108
106
|
catch (e) {
|
|
109
107
|
if (options.setEmptyIfError) {
|
|
110
|
-
WeDaDTS._dts = WeDaDTS._dts.replace(
|
|
108
|
+
WeDaDTS._dts = WeDaDTS._dts.replace(reg, `$1\n${dts}\n$2`);
|
|
109
|
+
if (DTSMap[DtsInnerSign[itemType]]) {
|
|
110
|
+
const reg = new RegExp(`^(\\s*\\/\\/ ${DTSMap[DtsInnerSign[itemType]]} Begin)[\\s\\S]*(^\\s*\\/\\/ ${DTSMap[DtsInnerSign[itemType]]} End)`, 'm');
|
|
111
|
+
WeDaDTS._dts = WeDaDTS._dts.replace(reg, `$1\n${dts}\n$2`);
|
|
112
|
+
}
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
});
|
|
@@ -140,7 +142,7 @@ function generateWeDaAppDTS(inputData = {}, options = { isCompMode: false, needG
|
|
|
140
142
|
// 防止某项错误导致全部都错误
|
|
141
143
|
try {
|
|
142
144
|
const dts = yield _generateOneItemDTS(inputData[key], key);
|
|
143
|
-
resultDts = resultDts.
|
|
145
|
+
resultDts = resultDts.replaceAll(placeholder, dts + placeholder);
|
|
144
146
|
}
|
|
145
147
|
catch (e) {
|
|
146
148
|
console.error(e);
|
|
@@ -312,7 +314,7 @@ function _generateOneItemDTS(inputData, itemType) {
|
|
|
312
314
|
}
|
|
313
315
|
function _compile(jsonschema, isObjNeedWrapper = false) {
|
|
314
316
|
return __awaiter(this, void 0, void 0, function* () {
|
|
315
|
-
let dts = yield
|
|
317
|
+
let dts = yield compileJSONToDTS(jsonschema);
|
|
316
318
|
if (dts.search(/^export interface IWeDa/) >= 0) {
|
|
317
319
|
dts = dts.replace(/^export interface.*$/m, '');
|
|
318
320
|
dts = dts.substring(0, dts.length - 2);
|
|
@@ -392,13 +394,16 @@ addEventListener('message', (message) => {
|
|
|
392
394
|
}
|
|
393
395
|
})
|
|
394
396
|
`;
|
|
395
|
-
function TypescriptWorker() {
|
|
396
|
-
let
|
|
397
|
-
let sendMessageCallbackFn = {};
|
|
397
|
+
function TypescriptWorker(workerId, workerCode) {
|
|
398
|
+
let typescriptWorkerMap = {};
|
|
398
399
|
return function getInstance() {
|
|
400
|
+
var _a;
|
|
401
|
+
let typescriptWorker = (_a = typescriptWorkerMap[workerId]) === null || _a === void 0 ? void 0 : _a.typescriptWorker;
|
|
399
402
|
if (!typescriptWorker) {
|
|
400
|
-
const
|
|
401
|
-
|
|
403
|
+
const sendMessageCallbackFn = {};
|
|
404
|
+
const workerURL = URL.createObjectURL(new Blob([workerCode]));
|
|
405
|
+
// 在 node 环境 unittest 时增加 name 参数用于辨别是哪个 worker
|
|
406
|
+
typescriptWorker = new Worker(workerURL + (workerURL.search('blob:http://localhost') === 0 ? '?name=' + workerId : ''));
|
|
402
407
|
typescriptWorker.onmessage = function (event) {
|
|
403
408
|
const { action } = event.data;
|
|
404
409
|
if (action === 'dts_back') {
|
|
@@ -406,8 +411,13 @@ function TypescriptWorker() {
|
|
|
406
411
|
sendMessageCallbackFn[id] && sendMessageCallbackFn[id](dts);
|
|
407
412
|
}
|
|
408
413
|
};
|
|
414
|
+
typescriptWorkerMap[workerId] = {
|
|
415
|
+
typescriptWorker,
|
|
416
|
+
sendMessageCallbackFn
|
|
417
|
+
};
|
|
409
418
|
}
|
|
410
419
|
function sendMessage(msgData, callbackFn) {
|
|
420
|
+
const { typescriptWorker, sendMessageCallbackFn } = typescriptWorkerMap[workerId];
|
|
411
421
|
const id = Math.random()
|
|
412
422
|
.toString(36)
|
|
413
423
|
.substring(2, 5);
|
|
@@ -429,7 +439,7 @@ function TypescriptWorker() {
|
|
|
429
439
|
*
|
|
430
440
|
* })
|
|
431
441
|
*/
|
|
432
|
-
const getTypescriptWorker = TypescriptWorker();
|
|
442
|
+
const getTypescriptWorker = TypescriptWorker('transpileToDTS', exports.workerCode);
|
|
433
443
|
/**
|
|
434
444
|
* 通过 js/ts 代码生成 dts
|
|
435
445
|
*/
|
|
@@ -442,3 +452,39 @@ function transpileToDTS(code) {
|
|
|
442
452
|
});
|
|
443
453
|
}
|
|
444
454
|
exports.transpileToDTS = transpileToDTS;
|
|
455
|
+
exports.jsonToDTSWorkerCode = `
|
|
456
|
+
importScripts('https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/release/_url/devtools/json-schema-to-typescript-for-browser.min.js');
|
|
457
|
+
|
|
458
|
+
function transpile(jsonschema) {
|
|
459
|
+
return jstt.compile(jsonschema, 'IWeDa', { additionalProperties: false, bannerComment: '', format: false })
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
addEventListener('message', (message) => {
|
|
463
|
+
const {action, data: {id, jsonschema}} = message.data
|
|
464
|
+
switch(action) {
|
|
465
|
+
case 'dts':
|
|
466
|
+
transpile(jsonschema).then(dts => {
|
|
467
|
+
postMessage({action: 'dts_back', data: {id, dts}})
|
|
468
|
+
}).catch(err => postMessage({action: 'dts_back', data: {id, dts: 'Parse error:' + err.message}}))
|
|
469
|
+
break
|
|
470
|
+
default:
|
|
471
|
+
break
|
|
472
|
+
}
|
|
473
|
+
})
|
|
474
|
+
`;
|
|
475
|
+
const getCompileJSONToDTSWorker = TypescriptWorker('compileJSONToDTS', exports.jsonToDTSWorkerCode);
|
|
476
|
+
/**
|
|
477
|
+
* Webworker 版本的 JSON to DTS
|
|
478
|
+
*/
|
|
479
|
+
function compileJSONToDTS(jsonschema) {
|
|
480
|
+
return new Promise((resolve, reject) => {
|
|
481
|
+
const worker = getCompileJSONToDTSWorker();
|
|
482
|
+
worker.sendMessage({ action: 'dts', data: { jsonschema } }, (dts) => {
|
|
483
|
+
if (dts.search('Parse error:') === 0)
|
|
484
|
+
reject(dts);
|
|
485
|
+
else
|
|
486
|
+
resolve(dts);
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
exports.compileJSONToDTS = compileJSONToDTS;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/cals",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.12-alpha.0",
|
|
4
4
|
"description": "Common application specifications",
|
|
5
5
|
"main": "lib/utils/index.js",
|
|
6
6
|
"source": "src/utils/index.ts",
|
|
@@ -53,4 +53,4 @@
|
|
|
53
53
|
"typescript": "^4.7.4",
|
|
54
54
|
"typescript-json-schema": "^0.53.0"
|
|
55
55
|
}
|
|
56
|
-
}
|
|
56
|
+
}
|