abler-api 1.0.19 → 1.0.20
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/README.md +8 -1
- package/dist/cjs/pp-util.js +26 -19
- package/package.json +46 -46
package/README.md
CHANGED
|
@@ -22,4 +22,11 @@ apiUtil.config(conf,errCfg,dbSql);
|
|
|
22
22
|
|
|
23
23
|
### preconditions
|
|
24
24
|
|
|
25
|
-
API
|
|
25
|
+
API服务启动时检查前置条件
|
|
26
|
+
|
|
27
|
+
### 更新日志
|
|
28
|
+
|
|
29
|
+
#### 1.0.20
|
|
30
|
+
|
|
31
|
+
- preconditions.checkAll(saveFile) 增加参数saveFile,指定保存检查结果的文件,若未指定或值为 undefined,则为保持和老版本兼容自动设置为 "../log/preconditions",若值为 “”, 则不保存文件
|
|
32
|
+
|
package/dist/cjs/pp-util.js
CHANGED
|
@@ -65,7 +65,8 @@ class preconditions$2 {
|
|
|
65
65
|
preconditions$2.checkPromises.push(p);
|
|
66
66
|
return preconditions$2;
|
|
67
67
|
}
|
|
68
|
-
static addChecker(checkFunc, args
|
|
68
|
+
static addChecker(checkFunc, ...args) {
|
|
69
|
+
const blocked = args.pop();
|
|
69
70
|
preconditions$2.checkFunctions.push({
|
|
70
71
|
check: checkFunc,
|
|
71
72
|
args: args,
|
|
@@ -82,7 +83,7 @@ class preconditions$2 {
|
|
|
82
83
|
}
|
|
83
84
|
return msg;
|
|
84
85
|
}
|
|
85
|
-
static async checkAll() {
|
|
86
|
+
static async checkAll(saveFile) {
|
|
86
87
|
try {
|
|
87
88
|
// for (let i = 0; i < preconditions.checkFunctions.length; i++) {
|
|
88
89
|
// const f = preconditions.checkFunctions[i];
|
|
@@ -91,7 +92,7 @@ class preconditions$2 {
|
|
|
91
92
|
// }
|
|
92
93
|
while (preconditions$2.checkFunctions.length > 0) {
|
|
93
94
|
const f = preconditions$2.checkFunctions.shift();
|
|
94
|
-
if (preconditions$2.pushMessage(await f.check(f.args)) && f.blocked) {
|
|
95
|
+
if (preconditions$2.pushMessage(await f.check(...f.args)) && f.blocked) {
|
|
95
96
|
break;
|
|
96
97
|
}
|
|
97
98
|
}
|
|
@@ -114,10 +115,16 @@ class preconditions$2 {
|
|
|
114
115
|
// console.log(preconditions.messages[i]);
|
|
115
116
|
// }
|
|
116
117
|
}
|
|
117
|
-
if (
|
|
118
|
-
|
|
118
|
+
if (saveFile === undefined) {
|
|
119
|
+
saveFile = path.join(process.cwd(), "..", "log", "preconditions"); // 兼容老版本
|
|
120
|
+
}
|
|
121
|
+
if (saveFile) {
|
|
122
|
+
const dir = path.dirname(saveFile);
|
|
123
|
+
if (!(await fs$1.async_exists(dir))) {
|
|
124
|
+
await fs$1.async_mkdir(dir);
|
|
125
|
+
}
|
|
126
|
+
await fs$1.async_writeFile(saveFile, text);
|
|
119
127
|
}
|
|
120
|
-
await fs$1.async_writeFile(`../log/preconditions`, text);
|
|
121
128
|
return !text;
|
|
122
129
|
}
|
|
123
130
|
|
|
@@ -150,8 +157,8 @@ class preconditions$2 {
|
|
|
150
157
|
static async initKvStorage(dbSql) {
|
|
151
158
|
return await initKvStorage(dbSql);
|
|
152
159
|
}
|
|
153
|
-
static async checkAppDbVersion() {
|
|
154
|
-
const dbVersionManager = new DbVersionManager();
|
|
160
|
+
static async checkAppDbVersion(...args) {
|
|
161
|
+
const dbVersionManager = new DbVersionManager(...args);
|
|
155
162
|
const updateInfo = await dbVersionManager.checkAppDbVersion();
|
|
156
163
|
return updateInfo.updateMessage;
|
|
157
164
|
}
|
|
@@ -344,18 +351,18 @@ class apiUtil$2 {
|
|
|
344
351
|
*/
|
|
345
352
|
static extractParams(req) {
|
|
346
353
|
if (!req._requestParams) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
req._requestParams[k] = req.body[k];
|
|
353
|
-
}
|
|
354
|
-
} else {
|
|
355
|
-
req._requestParams = req.body;
|
|
354
|
+
const contentType = req.headers["content-type"] || "application/json";
|
|
355
|
+
if (contentType.startsWith("multipart/form-data")) {
|
|
356
|
+
req._requestParams = new Object();
|
|
357
|
+
for (let k in req.body) {
|
|
358
|
+
req._requestParams[k] = req.body[k];
|
|
356
359
|
}
|
|
357
360
|
} else {
|
|
358
|
-
req.
|
|
361
|
+
if (req.method === "POST" || req.method === "PUT") {
|
|
362
|
+
req._requestParams = req.body;
|
|
363
|
+
} else {
|
|
364
|
+
req._requestParams = req.query;
|
|
365
|
+
}
|
|
359
366
|
}
|
|
360
367
|
if (req.headers["content-type"] !== "application/json") {
|
|
361
368
|
const obj = req._requestParams;
|
|
@@ -1934,7 +1941,7 @@ let conf$1;
|
|
|
1934
1941
|
*/
|
|
1935
1942
|
class commonMessenger$2 {
|
|
1936
1943
|
static myMsgAddr = "";
|
|
1937
|
-
static redisMessenger =
|
|
1944
|
+
static redisMessenger = RedisMessenger; // 假的,initMessenger 将设置真实的
|
|
1938
1945
|
static onMessage = [];
|
|
1939
1946
|
static initMessenger(appConfig, appErrCfg, msgChannel) {
|
|
1940
1947
|
conf$1 = appConfig;
|
package/package.json
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "abler-api",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "API服务相关工具",
|
|
5
|
-
"main": "./dist/cjs/pp-util.js",
|
|
6
|
-
"-module": "./dist/es/pp-util.js",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "npx rollup -c rollup.config.js",
|
|
9
|
-
"postbuild": "node ..\\postbuild.js",
|
|
10
|
-
"test": "echo \"Skip tests for this package\" && exit 0"
|
|
11
|
-
},
|
|
12
|
-
"files": [
|
|
13
|
-
"dist"
|
|
14
|
-
],
|
|
15
|
-
"author": "peng_peng",
|
|
16
|
-
"license": "ISC",
|
|
17
|
-
"dependencies": {
|
|
18
|
-
"abler-db": "^1.0.
|
|
19
|
-
"abler-i18n": "^1.0.2",
|
|
20
|
-
"abler-messenger": "^1.0.18",
|
|
21
|
-
"abler-net": "^1.0.5",
|
|
22
|
-
"abler-util": "^1.0.4",
|
|
23
|
-
"basic-auth": "^2.0.1",
|
|
24
|
-
"node-cron": "^3.0.1",
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"@babel/
|
|
30
|
-
"@babel/
|
|
31
|
-
"@babel/
|
|
32
|
-
"@babel/
|
|
33
|
-
"@
|
|
34
|
-
"@rollup/plugin-
|
|
35
|
-
"@rollup/plugin-
|
|
36
|
-
"@rollup/plugin-
|
|
37
|
-
"@
|
|
38
|
-
"@typescript-eslint/
|
|
39
|
-
"eslint": "^
|
|
40
|
-
"eslint
|
|
41
|
-
"
|
|
42
|
-
"rollup-plugin-
|
|
43
|
-
"rollup-plugin-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "abler-api",
|
|
3
|
+
"version": "1.0.20",
|
|
4
|
+
"description": "API服务相关工具",
|
|
5
|
+
"main": "./dist/cjs/pp-util.js",
|
|
6
|
+
"-module": "./dist/es/pp-util.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "npx rollup -c rollup.config.js",
|
|
9
|
+
"postbuild": "node ..\\postbuild.js",
|
|
10
|
+
"test": "echo \"Skip tests for this package\" && exit 0"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"author": "peng_peng",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"abler-db": "^1.0.20",
|
|
19
|
+
"abler-i18n": "^1.0.2",
|
|
20
|
+
"abler-messenger": "^1.0.18",
|
|
21
|
+
"abler-net": "^1.0.5",
|
|
22
|
+
"abler-util": "^1.0.4",
|
|
23
|
+
"basic-auth": "^2.0.1",
|
|
24
|
+
"node-cron": "^3.0.1",
|
|
25
|
+
"proxy-agent": "6.5.0",
|
|
26
|
+
"q": "^1.5.1"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@babel/core": "^7.18.5",
|
|
30
|
+
"@babel/eslint-parser": "^7.18.2",
|
|
31
|
+
"@babel/plugin-transform-runtime": "^7.18.0",
|
|
32
|
+
"@babel/preset-env": "^7.18.2",
|
|
33
|
+
"@babel/runtime": "^7.18.0",
|
|
34
|
+
"@rollup/plugin-babel": "^5.3.1",
|
|
35
|
+
"@rollup/plugin-commonjs": "^22.0.0",
|
|
36
|
+
"@rollup/plugin-eslint": "^8.0.2",
|
|
37
|
+
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^5.25.0",
|
|
39
|
+
"@typescript-eslint/parser": "^5.25.0",
|
|
40
|
+
"eslint": "^8.16.0",
|
|
41
|
+
"eslint-plugin-react": "^7.30.0",
|
|
42
|
+
"rollup-plugin-filesize": "^10.0.0",
|
|
43
|
+
"rollup-plugin-json": "^4.0.0",
|
|
44
|
+
"rollup-plugin-terser": "^7.0.2"
|
|
45
|
+
}
|
|
46
|
+
}
|