@pisell/core 1.0.45 → 1.0.47
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/es/history/index.d.ts +4 -3
- package/es/indexDB/index.js +28 -24
- package/es/logger/index.js +3 -2
- package/es/models/index.d.ts +2 -1
- package/es/request/config.js +5 -0
- package/es/request/index.js +68 -24
- package/es/routes/index.d.ts +1 -1
- package/lib/history/index.d.ts +4 -3
- package/lib/indexDB/index.js +18 -17
- package/lib/logger/index.js +4 -2
- package/lib/models/index.d.ts +2 -1
- package/lib/request/config.js +5 -0
- package/lib/request/index.js +50 -21
- package/lib/routes/index.d.ts +1 -1
- package/package.json +1 -1
- package/es/app/app.d.ts +0 -99
- package/es/applicationManager/application.d.ts +0 -197
- package/es/applicationManager/index.d.ts +0 -19
- package/es/index.d.ts +0 -7
- package/es/logger/index.d.ts +0 -135
- package/es/menuManager/index.d.ts +0 -28
- package/es/request/config.d.ts +0 -3
- package/es/request/index.d.ts +0 -24
- package/es/request/type.d.ts +0 -52
- package/es/tasks/index.d.ts +0 -127
- package/es/utils/adaptiveThrottle/index.d.ts +0 -36
- package/lib/app/app.d.ts +0 -99
- package/lib/applicationManager/application.d.ts +0 -197
- package/lib/applicationManager/index.d.ts +0 -19
- package/lib/index.d.ts +0 -7
- package/lib/logger/index.d.ts +0 -135
- package/lib/menuManager/index.d.ts +0 -28
- package/lib/request/config.d.ts +0 -3
- package/lib/request/index.d.ts +0 -24
- package/lib/request/type.d.ts +0 -52
- package/lib/tasks/index.d.ts +0 -127
- package/lib/utils/adaptiveThrottle/index.d.ts +0 -36
package/es/history/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LocationDescriptor } from "history";
|
|
2
2
|
import type { History as HistoryType } from "history";
|
|
3
|
+
import { useHistory, useLocation, useParams } from "react-router-dom";
|
|
3
4
|
import App from "../app";
|
|
4
5
|
export interface HistoryOptions {
|
|
5
6
|
basename?: string;
|
|
@@ -7,9 +8,9 @@ export interface HistoryOptions {
|
|
|
7
8
|
}
|
|
8
9
|
export declare class History {
|
|
9
10
|
instance: HistoryType<unknown>;
|
|
10
|
-
useHistory:
|
|
11
|
-
useLocation:
|
|
12
|
-
useParams:
|
|
11
|
+
useHistory: typeof useHistory;
|
|
12
|
+
useLocation: typeof useLocation;
|
|
13
|
+
useParams: typeof useParams;
|
|
13
14
|
app: App;
|
|
14
15
|
interceptor?: (path: LocationDescriptor<unknown>, state: unknown, next: () => void) => void;
|
|
15
16
|
constructor(app: App, options?: HistoryOptions);
|
package/es/indexDB/index.js
CHANGED
|
@@ -326,17 +326,15 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
326
326
|
case 10:
|
|
327
327
|
_context3.prev = 10;
|
|
328
328
|
_context3.t0 = _context3["catch"](3);
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
throw new Error('添加数据失败');
|
|
329
|
+
_this4.app.logger.addLog({
|
|
330
|
+
type: 'error',
|
|
331
|
+
title: uuid,
|
|
332
|
+
metadata: {
|
|
333
|
+
msg: '添加数据失败',
|
|
334
|
+
error: _context3.t0.message
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
throw new Error(_context3.t0 === null || _context3.t0 === void 0 ? void 0 : _context3.t0.message);
|
|
340
338
|
case 14:
|
|
341
339
|
case "end":
|
|
342
340
|
return _context3.stop();
|
|
@@ -611,17 +609,15 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
611
609
|
case 10:
|
|
612
610
|
_context9.prev = 10;
|
|
613
611
|
_context9.t0 = _context9["catch"](3);
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
}
|
|
624
|
-
throw new Error('更新数据失败');
|
|
612
|
+
_this7.app.logger.addLog({
|
|
613
|
+
type: 'error',
|
|
614
|
+
title: uuid,
|
|
615
|
+
metadata: {
|
|
616
|
+
msg: '数据更新失败',
|
|
617
|
+
error: _context9.t0.message
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
throw new Error(_context9.t0 === null || _context9.t0 === void 0 ? void 0 : _context9.t0.message);
|
|
625
621
|
case 14:
|
|
626
622
|
case "end":
|
|
627
623
|
return _context9.stop();
|
|
@@ -1110,8 +1106,16 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1110
1106
|
case 9:
|
|
1111
1107
|
_context23.prev = 9;
|
|
1112
1108
|
_context23.t0 = _context23["catch"](2);
|
|
1113
|
-
|
|
1114
|
-
|
|
1109
|
+
_this14.app.logger.addLog({
|
|
1110
|
+
type: 'error',
|
|
1111
|
+
title: "[ IndexDB ] ERROR: - getAll(".concat(storeName, ")"),
|
|
1112
|
+
metadata: {
|
|
1113
|
+
msg: '获取所有数据失败',
|
|
1114
|
+
error: _context23.t0.message
|
|
1115
|
+
}
|
|
1116
|
+
});
|
|
1117
|
+
throw new Error(_context23.t0 === null || _context23.t0 === void 0 ? void 0 : _context23.t0.message);
|
|
1118
|
+
case 13:
|
|
1115
1119
|
case "end":
|
|
1116
1120
|
return _context23.stop();
|
|
1117
1121
|
}
|
package/es/logger/index.js
CHANGED
|
@@ -325,8 +325,9 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
325
325
|
|
|
326
326
|
// 将buffer中的metadata转换为对象
|
|
327
327
|
buffer = (_this$logBuffer = this.logBuffer) === null || _this$logBuffer === void 0 ? void 0 : _this$logBuffer.map(function (item) {
|
|
328
|
-
|
|
329
|
-
|
|
328
|
+
return _objectSpread(_objectSpread({}, item || {}), {}, {
|
|
329
|
+
metadata: JSON.parse(item.metadata || "{}")
|
|
330
|
+
});
|
|
330
331
|
});
|
|
331
332
|
bufferIds = buffer.map(function (item) {
|
|
332
333
|
return item.logId;
|
package/es/models/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import hooks from '../hooks';
|
|
2
|
+
import { Provider as StoreProvider } from "react-redux";
|
|
2
3
|
declare const models: import("./global").GlobalModal[];
|
|
3
4
|
declare type ModalsType = (typeof models[number]);
|
|
4
5
|
export interface Store {
|
|
@@ -38,7 +39,7 @@ declare const getDataByModel: <T extends "global", D extends keyof ModelsState[T
|
|
|
38
39
|
declare const setDataByModel: <T extends "global", D extends keyof ModelsState[T]>(model: string, key: any, value: any) => void;
|
|
39
40
|
declare const _default: {
|
|
40
41
|
getStore: () => Store;
|
|
41
|
-
StoreProvider:
|
|
42
|
+
StoreProvider: typeof StoreProvider;
|
|
42
43
|
setConfig: (models: any[]) => void;
|
|
43
44
|
};
|
|
44
45
|
export default _default;
|
package/es/request/config.js
CHANGED
|
@@ -10,6 +10,11 @@ import { mergeWith } from 'lodash';
|
|
|
10
10
|
var defaultConfig = {
|
|
11
11
|
axiosConfig: axiosConfig,
|
|
12
12
|
storage: new Storage(),
|
|
13
|
+
logger: {
|
|
14
|
+
maxRequestCount: 6,
|
|
15
|
+
maxRequestTime: 5000,
|
|
16
|
+
filterUrls: []
|
|
17
|
+
},
|
|
13
18
|
requestCallbacks: {
|
|
14
19
|
200: function _(resData) {
|
|
15
20
|
var res = resData.res,
|
package/es/request/index.js
CHANGED
|
@@ -11,6 +11,8 @@ import { createSignal } from "./cancelToken";
|
|
|
11
11
|
import { axiosConfig } from "./constants";
|
|
12
12
|
import { cacheFn } from "./cache";
|
|
13
13
|
import { interceptorsRequest, interceptorsResponse, interceptorsRequestError, interceptorsResponseError, requestCallback } from "./utils";
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
import { getUniqueId } from "@pisell/utils";
|
|
14
16
|
import axios from "axios";
|
|
15
17
|
import { getConfig, setConfig } from "./config";
|
|
16
18
|
import { getApp } from "../app";
|
|
@@ -22,44 +24,84 @@ axiosInstance.interceptors.request.use(interceptorsRequest, interceptorsRequestE
|
|
|
22
24
|
|
|
23
25
|
// 响应拦截器
|
|
24
26
|
axiosInstance.interceptors.response.use(interceptorsResponse, interceptorsResponseError);
|
|
27
|
+
|
|
28
|
+
// 请求计数
|
|
29
|
+
var requestCount = 0;
|
|
30
|
+
var isFilterUrl = function isFilterUrl(url) {
|
|
31
|
+
var _logger$filterUrls;
|
|
32
|
+
var _getConfig = getConfig(),
|
|
33
|
+
logger = _getConfig.logger;
|
|
34
|
+
return logger === null || logger === void 0 || (_logger$filterUrls = logger.filterUrls) === null || _logger$filterUrls === void 0 ? void 0 : _logger$filterUrls.some(function (filterUrl) {
|
|
35
|
+
return url.includes(filterUrl);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
25
38
|
export var createRequest = function createRequest(props) {
|
|
26
39
|
var data = props.data,
|
|
27
40
|
config = props.config,
|
|
28
41
|
method = props.method,
|
|
29
42
|
url = props.url;
|
|
30
|
-
var
|
|
31
|
-
getUrl =
|
|
43
|
+
var _getConfig2 = getConfig(),
|
|
44
|
+
getUrl = _getConfig2.getUrl,
|
|
45
|
+
logger = _getConfig2.logger;
|
|
32
46
|
var startTime = Date.now(); // 记录请求开始时间
|
|
47
|
+
var app = getApp();
|
|
48
|
+
var requestId = getUniqueId();
|
|
49
|
+
|
|
50
|
+
// 请求计数增加
|
|
51
|
+
requestCount++;
|
|
52
|
+
|
|
53
|
+
// 记录请求开始日志
|
|
54
|
+
app.logger.addLog({
|
|
55
|
+
type: 'info',
|
|
56
|
+
title: "[ Request ]: Start - ".concat(requestId),
|
|
57
|
+
metadata: {
|
|
58
|
+
url: url,
|
|
59
|
+
data: data,
|
|
60
|
+
method: method
|
|
61
|
+
}
|
|
62
|
+
});
|
|
33
63
|
|
|
64
|
+
// 如果请求计数超过最大请求数,则记录为警告日志
|
|
65
|
+
if (requestCount > ((logger === null || logger === void 0 ? void 0 : logger.maxRequestCount) || 6)) {
|
|
66
|
+
app.logger.addLog({
|
|
67
|
+
type: 'warning',
|
|
68
|
+
title: "[ Request ]: Max Request Count - ".concat(requestCount),
|
|
69
|
+
metadata: {
|
|
70
|
+
requestCount: requestCount
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
34
74
|
return new Promise(function (resolve, reject) {
|
|
35
75
|
var _method = method === "remove" ? "delete" : method;
|
|
36
|
-
var _url = getUrl === null || getUrl === void 0 ? void 0 : getUrl(props);
|
|
76
|
+
var _url = (getUrl === null || getUrl === void 0 ? void 0 : getUrl(props)) || '';
|
|
37
77
|
|
|
38
78
|
// 请求完成处理函数
|
|
39
|
-
var handleRequestComplete = function handleRequestComplete(result) {
|
|
40
|
-
var isError = arguments.length >
|
|
79
|
+
var handleRequestComplete = function handleRequestComplete(url, result) {
|
|
80
|
+
var isError = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
81
|
+
var requestId = arguments.length > 3 ? arguments[3] : undefined;
|
|
41
82
|
try {
|
|
42
83
|
var endTime = Date.now();
|
|
43
84
|
var duration = endTime - startTime;
|
|
85
|
+
var maxRequestTime = (logger === null || logger === void 0 ? void 0 : logger.maxRequestTime) || 5000;
|
|
44
86
|
|
|
45
|
-
//
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
data: data,
|
|
55
|
-
method: _method,
|
|
56
|
-
duration: "".concat((duration / 1000).toFixed(2), "s"),
|
|
57
|
-
timestamp: new Date(startTime).toISOString(),
|
|
58
|
-
isError: isError
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
87
|
+
// 如果请求URL在过滤列表中,则不判断超时时间
|
|
88
|
+
if (isFilterUrl(url)) {
|
|
89
|
+
maxRequestTime = 99999999;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 如果请求错误或者请求超过5秒,则记录为错误日志
|
|
93
|
+
var type = duration > maxRequestTime ? 'warning' : 'info';
|
|
94
|
+
if (isError) {
|
|
95
|
+
type = 'error';
|
|
62
96
|
}
|
|
97
|
+
app.logger.addLog({
|
|
98
|
+
type: type,
|
|
99
|
+
title: "[ Request ]: Complete - ".concat(requestId),
|
|
100
|
+
metadata: {
|
|
101
|
+
error: isError ? JSON.stringify(result) : '',
|
|
102
|
+
duration: "".concat((duration / 1000).toFixed(2), "s")
|
|
103
|
+
}
|
|
104
|
+
});
|
|
63
105
|
} catch (error) {}
|
|
64
106
|
return result;
|
|
65
107
|
};
|
|
@@ -68,7 +110,7 @@ export var createRequest = function createRequest(props) {
|
|
|
68
110
|
}, config), _objectSpread({
|
|
69
111
|
params: !["post", "put"].includes(_method) ? data : null
|
|
70
112
|
}, config)).then(function (res) {
|
|
71
|
-
handleRequestComplete(res, false);
|
|
113
|
+
handleRequestComplete(_url, res, false, requestId);
|
|
72
114
|
requestCallback({
|
|
73
115
|
res: res,
|
|
74
116
|
reject: reject,
|
|
@@ -76,13 +118,15 @@ export var createRequest = function createRequest(props) {
|
|
|
76
118
|
props: props
|
|
77
119
|
});
|
|
78
120
|
}).catch(function (err) {
|
|
79
|
-
handleRequestComplete(err, true);
|
|
121
|
+
handleRequestComplete(_url, err, true, requestId);
|
|
80
122
|
requestCallback({
|
|
81
123
|
err: err,
|
|
82
124
|
reject: reject,
|
|
83
125
|
resolve: resolve,
|
|
84
126
|
props: props
|
|
85
127
|
});
|
|
128
|
+
}).finally(function () {
|
|
129
|
+
requestCount--;
|
|
86
130
|
});
|
|
87
131
|
});
|
|
88
132
|
};
|
package/es/routes/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare class RouterManager {
|
|
|
20
20
|
get(name: string): RouteType;
|
|
21
21
|
has(name: string): boolean;
|
|
22
22
|
remove(name: string): void;
|
|
23
|
-
renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean |
|
|
23
|
+
renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean | JSX.Element | React.ReactFragment | null | undefined;
|
|
24
24
|
getPageByRoute(route: string): ApplicationInterface | undefined;
|
|
25
25
|
getRouterComponent({ fallback }: {
|
|
26
26
|
fallback?: React.ReactNode;
|
package/lib/history/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LocationDescriptor } from "history";
|
|
2
2
|
import type { History as HistoryType } from "history";
|
|
3
|
+
import { useHistory, useLocation, useParams } from "react-router-dom";
|
|
3
4
|
import App from "../app";
|
|
4
5
|
export interface HistoryOptions {
|
|
5
6
|
basename?: string;
|
|
@@ -7,9 +8,9 @@ export interface HistoryOptions {
|
|
|
7
8
|
}
|
|
8
9
|
export declare class History {
|
|
9
10
|
instance: HistoryType<unknown>;
|
|
10
|
-
useHistory:
|
|
11
|
-
useLocation:
|
|
12
|
-
useParams:
|
|
11
|
+
useHistory: typeof useHistory;
|
|
12
|
+
useLocation: typeof useLocation;
|
|
13
|
+
useParams: typeof useParams;
|
|
13
14
|
app: App;
|
|
14
15
|
interceptor?: (path: LocationDescriptor<unknown>, state: unknown, next: () => void) => void;
|
|
15
16
|
constructor(app: App, options?: HistoryOptions);
|
package/lib/indexDB/index.js
CHANGED
|
@@ -220,14 +220,12 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
220
220
|
}
|
|
221
221
|
return data;
|
|
222
222
|
} catch (error) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
throw new Error("添加数据失败");
|
|
223
|
+
this.app.logger.addLog({
|
|
224
|
+
type: "error",
|
|
225
|
+
title: uuid,
|
|
226
|
+
metadata: { msg: "添加数据失败", error: error.message }
|
|
227
|
+
});
|
|
228
|
+
throw new Error(error == null ? void 0 : error.message);
|
|
231
229
|
}
|
|
232
230
|
})(),
|
|
233
231
|
`add(${storeName})`
|
|
@@ -344,14 +342,12 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
344
342
|
}
|
|
345
343
|
return data;
|
|
346
344
|
} catch (error) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
}
|
|
354
|
-
throw new Error("更新数据失败");
|
|
345
|
+
this.app.logger.addLog({
|
|
346
|
+
type: "error",
|
|
347
|
+
title: uuid,
|
|
348
|
+
metadata: { msg: "数据更新失败", error: error.message }
|
|
349
|
+
});
|
|
350
|
+
throw new Error(error == null ? void 0 : error.message);
|
|
355
351
|
}
|
|
356
352
|
})(),
|
|
357
353
|
`update(${storeName})`
|
|
@@ -550,7 +546,12 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
550
546
|
const results = await this.db.table(storeName).toArray();
|
|
551
547
|
return results;
|
|
552
548
|
} catch (error) {
|
|
553
|
-
|
|
549
|
+
this.app.logger.addLog({
|
|
550
|
+
type: "error",
|
|
551
|
+
title: `[ IndexDB ] ERROR: - getAll(${storeName})`,
|
|
552
|
+
metadata: { msg: "获取所有数据失败", error: error.message }
|
|
553
|
+
});
|
|
554
|
+
throw new Error(error == null ? void 0 : error.message);
|
|
554
555
|
}
|
|
555
556
|
})(),
|
|
556
557
|
`getAll(${storeName})`
|
package/lib/logger/index.js
CHANGED
|
@@ -219,8 +219,10 @@ var LoggerManager = class {
|
|
|
219
219
|
const fileName = await this.createAWSFileName(urgent);
|
|
220
220
|
console.log("-------- 存储日志到AWS 开始", fileName);
|
|
221
221
|
const buffer = (_a = this.logBuffer) == null ? void 0 : _a.map((item) => {
|
|
222
|
-
|
|
223
|
-
|
|
222
|
+
return {
|
|
223
|
+
...item || {},
|
|
224
|
+
metadata: JSON.parse(item.metadata || "{}")
|
|
225
|
+
};
|
|
224
226
|
});
|
|
225
227
|
const bufferIds = buffer.map((item) => item.logId);
|
|
226
228
|
const logs = JSON.stringify(buffer, null, 2);
|
package/lib/models/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import hooks from '../hooks';
|
|
2
|
+
import { Provider as StoreProvider } from "react-redux";
|
|
2
3
|
declare const models: import("./global").GlobalModal[];
|
|
3
4
|
declare type ModalsType = (typeof models[number]);
|
|
4
5
|
export interface Store {
|
|
@@ -38,7 +39,7 @@ declare const getDataByModel: <T extends "global", D extends keyof ModelsState[T
|
|
|
38
39
|
declare const setDataByModel: <T extends "global", D extends keyof ModelsState[T]>(model: string, key: any, value: any) => void;
|
|
39
40
|
declare const _default: {
|
|
40
41
|
getStore: () => Store;
|
|
41
|
-
StoreProvider:
|
|
42
|
+
StoreProvider: typeof StoreProvider;
|
|
42
43
|
setConfig: (models: any[]) => void;
|
|
43
44
|
};
|
|
44
45
|
export default _default;
|
package/lib/request/config.js
CHANGED
|
@@ -29,6 +29,11 @@ var import_lodash = require("lodash");
|
|
|
29
29
|
var defaultConfig = {
|
|
30
30
|
axiosConfig: import_constants.axiosConfig,
|
|
31
31
|
storage: new import_storage.Storage(),
|
|
32
|
+
logger: {
|
|
33
|
+
maxRequestCount: 6,
|
|
34
|
+
maxRequestTime: 5e3,
|
|
35
|
+
filterUrls: []
|
|
36
|
+
},
|
|
32
37
|
requestCallbacks: {
|
|
33
38
|
200: (resData) => {
|
|
34
39
|
const { res, props, resolve, reject, err } = resData;
|
package/lib/request/index.js
CHANGED
|
@@ -44,6 +44,7 @@ var import_cancelToken = require("./cancelToken");
|
|
|
44
44
|
var import_constants = require("./constants");
|
|
45
45
|
var import_cache = require("./cache");
|
|
46
46
|
var import_utils = require("./utils");
|
|
47
|
+
var import_utils2 = require("@pisell/utils");
|
|
47
48
|
var import_axios = __toESM(require("axios"));
|
|
48
49
|
var import_config = require("./config");
|
|
49
50
|
var import_app = require("../app");
|
|
@@ -51,34 +52,60 @@ __reExport(request_exports, require("./type"), module.exports);
|
|
|
51
52
|
var axiosInstance = import_axios.default.create(import_constants.axiosConfig);
|
|
52
53
|
axiosInstance.interceptors.request.use(import_utils.interceptorsRequest, import_utils.interceptorsRequestError);
|
|
53
54
|
axiosInstance.interceptors.response.use(import_utils.interceptorsResponse, import_utils.interceptorsResponseError);
|
|
55
|
+
var requestCount = 0;
|
|
56
|
+
var isFilterUrl = (url) => {
|
|
57
|
+
var _a;
|
|
58
|
+
const { logger } = (0, import_config.getConfig)();
|
|
59
|
+
return (_a = logger == null ? void 0 : logger.filterUrls) == null ? void 0 : _a.some((filterUrl) => url.includes(filterUrl));
|
|
60
|
+
};
|
|
54
61
|
var createRequest = (props) => {
|
|
55
62
|
const { data, config, method, url } = props;
|
|
56
|
-
const { getUrl } = (0, import_config.getConfig)();
|
|
63
|
+
const { getUrl, logger } = (0, import_config.getConfig)();
|
|
57
64
|
const startTime = Date.now();
|
|
65
|
+
const app = (0, import_app.getApp)();
|
|
66
|
+
const requestId = (0, import_utils2.getUniqueId)();
|
|
67
|
+
requestCount++;
|
|
68
|
+
app.logger.addLog({
|
|
69
|
+
type: "info",
|
|
70
|
+
title: `[ Request ]: Start - ${requestId}`,
|
|
71
|
+
metadata: {
|
|
72
|
+
url,
|
|
73
|
+
data,
|
|
74
|
+
method
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
if (requestCount > ((logger == null ? void 0 : logger.maxRequestCount) || 6)) {
|
|
78
|
+
app.logger.addLog({
|
|
79
|
+
type: "warning",
|
|
80
|
+
title: `[ Request ]: Max Request Count - ${requestCount}`,
|
|
81
|
+
metadata: {
|
|
82
|
+
requestCount
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
58
86
|
return new Promise((resolve, reject) => {
|
|
59
87
|
const _method = method === "remove" ? "delete" : method;
|
|
60
|
-
let _url = getUrl == null ? void 0 : getUrl(props);
|
|
61
|
-
const handleRequestComplete = (result, isError = false) => {
|
|
88
|
+
let _url = (getUrl == null ? void 0 : getUrl(props)) || "";
|
|
89
|
+
const handleRequestComplete = (url2, result, isError = false, requestId2) => {
|
|
62
90
|
try {
|
|
63
91
|
const endTime = Date.now();
|
|
64
92
|
const duration = endTime - startTime;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
app.logger.addLog({
|
|
69
|
-
type: "warning",
|
|
70
|
-
title: "请求响应超过5秒",
|
|
71
|
-
metadata: {
|
|
72
|
-
url: _url || url,
|
|
73
|
-
data,
|
|
74
|
-
method: _method,
|
|
75
|
-
duration: `${(duration / 1e3).toFixed(2)}s`,
|
|
76
|
-
timestamp: new Date(startTime).toISOString(),
|
|
77
|
-
isError
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
93
|
+
let maxRequestTime = (logger == null ? void 0 : logger.maxRequestTime) || 5e3;
|
|
94
|
+
if (isFilterUrl(url2)) {
|
|
95
|
+
maxRequestTime = 99999999;
|
|
81
96
|
}
|
|
97
|
+
let type = duration > maxRequestTime ? "warning" : "info";
|
|
98
|
+
if (isError) {
|
|
99
|
+
type = "error";
|
|
100
|
+
}
|
|
101
|
+
app.logger.addLog({
|
|
102
|
+
type,
|
|
103
|
+
title: `[ Request ]: Complete - ${requestId2}`,
|
|
104
|
+
metadata: {
|
|
105
|
+
error: isError ? JSON.stringify(result) : "",
|
|
106
|
+
duration: `${(duration / 1e3).toFixed(2)}s`
|
|
107
|
+
}
|
|
108
|
+
});
|
|
82
109
|
} catch (error) {
|
|
83
110
|
}
|
|
84
111
|
return result;
|
|
@@ -94,11 +121,13 @@ var createRequest = (props) => {
|
|
|
94
121
|
...config
|
|
95
122
|
}
|
|
96
123
|
).then((res) => {
|
|
97
|
-
handleRequestComplete(res, false);
|
|
124
|
+
handleRequestComplete(_url, res, false, requestId);
|
|
98
125
|
(0, import_utils.requestCallback)({ res, reject, resolve, props });
|
|
99
126
|
}).catch((err) => {
|
|
100
|
-
handleRequestComplete(err, true);
|
|
127
|
+
handleRequestComplete(_url, err, true, requestId);
|
|
101
128
|
(0, import_utils.requestCallback)({ err, reject, resolve, props });
|
|
129
|
+
}).finally(() => {
|
|
130
|
+
requestCount--;
|
|
102
131
|
});
|
|
103
132
|
});
|
|
104
133
|
};
|
package/lib/routes/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare class RouterManager {
|
|
|
20
20
|
get(name: string): RouteType;
|
|
21
21
|
has(name: string): boolean;
|
|
22
22
|
remove(name: string): void;
|
|
23
|
-
renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean |
|
|
23
|
+
renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean | JSX.Element | React.ReactFragment | null | undefined;
|
|
24
24
|
getPageByRoute(route: string): ApplicationInterface | undefined;
|
|
25
25
|
getRouterComponent({ fallback }: {
|
|
26
26
|
fallback?: React.ReactNode;
|
package/package.json
CHANGED
package/es/app/app.d.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { RouterManager } from '../routes';
|
|
2
|
-
import { ApplicationManager } from '../applicationManager';
|
|
3
|
-
import { History, HistoryOptions } from '../history';
|
|
4
|
-
import { Data } from '../data';
|
|
5
|
-
import { Locales, LocalesOptions } from '../locales';
|
|
6
|
-
import { Storage, StorageOptions } from '../storage';
|
|
7
|
-
import { MenuManager } from '../menuManager';
|
|
8
|
-
import LoggerManager, { LoggerOptions } from '../logger';
|
|
9
|
-
import { TasksManager } from '../tasks';
|
|
10
|
-
import IndexDBManager, { DBOptions } from '../indexDB';
|
|
11
|
-
import CMD, { CMDOptions } from "../cmd";
|
|
12
|
-
import AWS, { AWSOptions } from "../aws";
|
|
13
|
-
declare global {
|
|
14
|
-
interface Window {
|
|
15
|
-
app: App;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export interface Bootstrap {
|
|
19
|
-
hooks: {
|
|
20
|
-
[key: string]: () => Promise<void>;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
export interface AppOptions {
|
|
24
|
-
logger?: LoggerOptions;
|
|
25
|
-
db?: DBOptions;
|
|
26
|
-
constants?: any;
|
|
27
|
-
history?: HistoryOptions;
|
|
28
|
-
storage?: StorageOptions;
|
|
29
|
-
locales?: LocalesOptions;
|
|
30
|
-
cmd?: CMDOptions;
|
|
31
|
-
aws?: AWSOptions;
|
|
32
|
-
getPisellos?: () => any;
|
|
33
|
-
}
|
|
34
|
-
declare class App {
|
|
35
|
-
private static instance;
|
|
36
|
-
private plugins;
|
|
37
|
-
globalData: any;
|
|
38
|
-
router: RouterManager;
|
|
39
|
-
applicationManager: ApplicationManager;
|
|
40
|
-
history: History;
|
|
41
|
-
data: Data;
|
|
42
|
-
hooks: import("../hooks").HooksExport;
|
|
43
|
-
locales: Locales;
|
|
44
|
-
models: {
|
|
45
|
-
getStore: () => import("../models").Store;
|
|
46
|
-
StoreProvider: any;
|
|
47
|
-
setConfig: (models: any[]) => void;
|
|
48
|
-
};
|
|
49
|
-
request: {
|
|
50
|
-
get: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
|
|
51
|
-
post: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
|
|
52
|
-
put: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
|
|
53
|
-
remove: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
|
|
54
|
-
custom: (url: string, config: import("../request").RequestSetting | undefined) => any;
|
|
55
|
-
setConfig: (newConfig: Partial<import("../request").RequestConfig>) => void;
|
|
56
|
-
getConfig: () => import("../request").RequestConfig;
|
|
57
|
-
};
|
|
58
|
-
storage: Storage;
|
|
59
|
-
menuManager: MenuManager;
|
|
60
|
-
cookie: {
|
|
61
|
-
setCookie: (name: string, value: string, domain?: string | undefined) => void;
|
|
62
|
-
getCookie: (name: string) => string | null;
|
|
63
|
-
deleteCookie: (name: string, domain?: string | undefined) => void;
|
|
64
|
-
checkCookie: (name: string) => boolean;
|
|
65
|
-
updateCookie: (name: string, value: string, domain?: string | undefined) => void;
|
|
66
|
-
};
|
|
67
|
-
website: {
|
|
68
|
-
setTitle: (title: string) => void;
|
|
69
|
-
setIcon: (paramsIcon: string) => void;
|
|
70
|
-
setAppleWebAppTitle: (title: string) => void;
|
|
71
|
-
};
|
|
72
|
-
logger: LoggerManager;
|
|
73
|
-
pubsub: import("../pubsub").PubSub;
|
|
74
|
-
cmd: CMD;
|
|
75
|
-
aws: AWS;
|
|
76
|
-
tasksManager: TasksManager;
|
|
77
|
-
getPisellos: any;
|
|
78
|
-
bootstrap?: Bootstrap;
|
|
79
|
-
dbManager: IndexDBManager | null;
|
|
80
|
-
constants: {
|
|
81
|
-
channel: string;
|
|
82
|
-
[key: string]: string;
|
|
83
|
-
};
|
|
84
|
-
private constructor();
|
|
85
|
-
static getInstance(options?: AppOptions): App;
|
|
86
|
-
setGlobalData(globalData: any): void;
|
|
87
|
-
usePlugin(name: string, plugin: any): void;
|
|
88
|
-
usePlugins(plugins: {
|
|
89
|
-
name: string;
|
|
90
|
-
plugin: any;
|
|
91
|
-
}[]): void;
|
|
92
|
-
getPlugin(name: string): any;
|
|
93
|
-
getGlobalData(): any;
|
|
94
|
-
install(): void;
|
|
95
|
-
unInstall(): void;
|
|
96
|
-
setBootstrap(bootstrap: Bootstrap): void;
|
|
97
|
-
getBootstrap(): Bootstrap | undefined;
|
|
98
|
-
}
|
|
99
|
-
export default App;
|