@wutiange/log-listener-plugin 1.3.0-alpha.1 → 1.3.0-alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +201 -201
- package/README.md +2 -2
- package/dist/server.d.ts +10 -0
- package/dist/server.js +45 -0
- package/dist/server.js.map +1 -0
- package/dist/src/HTTPInterceptor.d.ts +48 -0
- package/dist/src/HTTPInterceptor.js +202 -0
- package/dist/src/HTTPInterceptor.js.map +1 -0
- package/dist/src/logPlugin.d.ts +19 -20
- package/dist/src/logPlugin.js +108 -122
- package/dist/src/logPlugin.js.map +1 -1
- package/package.json +47 -47
- package/src/HTTPInterceptor.ts +319 -0
- package/src/__tests__/console.test.ts +25 -25
- package/src/common.ts +4 -4
- package/src/logPlugin.ts +238 -229
- package/src/server.ts +66 -66
- package/src/utils.ts +47 -47
- package/dist/packages/network-logger/Logger.d.ts +0 -28
- package/dist/packages/network-logger/Logger.js +0 -192
- package/dist/packages/network-logger/Logger.js.map +0 -1
- package/dist/packages/network-logger/NetworkRequestInfo.d.ts +0 -37
- package/dist/packages/network-logger/NetworkRequestInfo.js +0 -151
- package/dist/packages/network-logger/NetworkRequestInfo.js.map +0 -1
- package/dist/packages/network-logger/constant.d.ts +0 -2
- package/dist/packages/network-logger/constant.js +0 -6
- package/dist/packages/network-logger/constant.js.map +0 -1
- package/dist/packages/network-logger/types.d.ts +0 -14
- package/dist/packages/network-logger/types.js +0 -3
- package/dist/packages/network-logger/types.js.map +0 -1
- package/dist/packages/network-logger/utils/debounce.d.ts +0 -2
- package/dist/packages/network-logger/utils/debounce.js +0 -20
- package/dist/packages/network-logger/utils/debounce.js.map +0 -1
- package/dist/packages/network-logger/utils/extractHost.d.ts +0 -2
- package/dist/packages/network-logger/utils/extractHost.js +0 -9
- package/dist/packages/network-logger/utils/extractHost.js.map +0 -1
- package/dist/packages/network-logger/utils/fromEntries.d.ts +0 -2
- package/dist/packages/network-logger/utils/fromEntries.js +0 -8
- package/dist/packages/network-logger/utils/fromEntries.js.map +0 -1
- package/dist/packages/network-logger/utils/logger.d.ts +0 -1
- package/dist/packages/network-logger/utils/logger.js +0 -6
- package/dist/packages/network-logger/utils/logger.js.map +0 -1
- package/dist/src/CompatibilityManager.d.ts +0 -27
- package/dist/src/CompatibilityManager.js +0 -82
- package/dist/src/CompatibilityManager.js.map +0 -1
- package/dist/src/console.d.ts +0 -1
- package/dist/src/console.js +0 -20
- package/dist/src/console.js.map +0 -1
- package/dist/src/fetch.d.ts +0 -1
- package/dist/src/fetch.js +0 -48
- package/dist/src/fetch.js.map +0 -1
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.js +0 -8
- package/dist/src/index.js.map +0 -1
- package/packages/network-logger/Logger.ts +0 -274
- package/packages/network-logger/NetworkRequestInfo.ts +0 -161
- package/packages/network-logger/constant.ts +0 -3
- package/packages/network-logger/types.ts +0 -36
- package/packages/network-logger/utils/debounce.ts +0 -21
- package/packages/network-logger/utils/extractHost.ts +0 -7
- package/packages/network-logger/utils/fromEntries.ts +0 -7
- package/packages/network-logger/utils/logger.ts +0 -2
- package/src/CompatibilityManager.ts +0 -71
@@ -1,36 +0,0 @@
|
|
1
|
-
import NetworkRequestInfo from './NetworkRequestInfo';
|
2
|
-
|
3
|
-
export type Headers = {[header: string]: string};
|
4
|
-
export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
5
|
-
export type StartNetworkLoggingOptions = {
|
6
|
-
/**
|
7
|
-
* Max number of requests to keep before overwriting
|
8
|
-
* @default 500
|
9
|
-
*/
|
10
|
-
maxRequests?: number;
|
11
|
-
/** List of hosts to ignore, e.g. `services.test.com` */
|
12
|
-
ignoredHosts?: string[];
|
13
|
-
/** List of urls to ignore, e.g. `https://services.test.com/test` */
|
14
|
-
ignoredUrls?: string[];
|
15
|
-
/**
|
16
|
-
* List of url patterns to ignore, e.g. `/^GET https://test.com\/pages\/.*$/`
|
17
|
-
*
|
18
|
-
* Url to match with is in the format: `${method} ${url}`, e.g. `GET https://test.com/pages/123`
|
19
|
-
*/
|
20
|
-
ignoredPatterns?: RegExp[];
|
21
|
-
/**
|
22
|
-
* Force the network logger to start even if another program is using the network interceptor
|
23
|
-
* e.g. a dev/debuging program
|
24
|
-
*/
|
25
|
-
forceEnable?: boolean;
|
26
|
-
/**
|
27
|
-
* Refresh rate of the logger in milliseconds
|
28
|
-
* @default 50
|
29
|
-
*/
|
30
|
-
refreshRate?: number;
|
31
|
-
};
|
32
|
-
|
33
|
-
export type NetworkRequestInfoRow = Pick<
|
34
|
-
NetworkRequestInfo,
|
35
|
-
'url' | 'gqlOperation' | 'id' | 'method' | 'status' | 'duration' | 'startTime'
|
36
|
-
>;
|
@@ -1,21 +0,0 @@
|
|
1
|
-
// https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_debounce
|
2
|
-
function debounce(func: Function, wait: number, immediate: boolean = false) {
|
3
|
-
let timeout: ReturnType<typeof setTimeout> | undefined;
|
4
|
-
return function () {
|
5
|
-
const args = arguments;
|
6
|
-
clearTimeout(timeout);
|
7
|
-
// @ts-ignore
|
8
|
-
if (immediate && !timeout) {
|
9
|
-
func.apply(this, args);
|
10
|
-
}
|
11
|
-
timeout = setTimeout(function () {
|
12
|
-
timeout = undefined;
|
13
|
-
// @ts-ignore
|
14
|
-
if (!immediate) {
|
15
|
-
func.apply(this, args);
|
16
|
-
}
|
17
|
-
}, wait);
|
18
|
-
};
|
19
|
-
}
|
20
|
-
|
21
|
-
export default debounce;
|
@@ -1,71 +0,0 @@
|
|
1
|
-
import NetworkRequestInfo from "../packages/network-logger/NetworkRequestInfo";
|
2
|
-
|
3
|
-
class CompatibilityManager {
|
4
|
-
private static requestInfoObj: Record<string, NetworkRequestInfo> = {}
|
5
|
-
static async interceptionToNetwork(data: NetworkRequestInfo[]) {
|
6
|
-
const tempWillSendArr: NetworkRequestInfo[] = []
|
7
|
-
if (Object.keys(CompatibilityManager.requestInfoObj).length === 0) {
|
8
|
-
CompatibilityManager.requestInfoObj = data.reduce((e, c) => {
|
9
|
-
if (c.endTime) {
|
10
|
-
const startReq = c.copy()
|
11
|
-
startReq.endTime = 0;
|
12
|
-
tempWillSendArr.push(startReq, c)
|
13
|
-
return e
|
14
|
-
}
|
15
|
-
tempWillSendArr.push(c)
|
16
|
-
return {...e, [c.id]: c}
|
17
|
-
}, {})
|
18
|
-
} else {
|
19
|
-
data.forEach(e => {
|
20
|
-
const tempObj = CompatibilityManager.requestInfoObj
|
21
|
-
if (!(e.id in tempObj)) {
|
22
|
-
if (!e.endTime) {
|
23
|
-
tempWillSendArr.push(e)
|
24
|
-
CompatibilityManager.requestInfoObj[e.id] = e
|
25
|
-
} else {
|
26
|
-
const startReq = e.copy()
|
27
|
-
startReq.endTime = 0;
|
28
|
-
tempWillSendArr.push(startReq, e)
|
29
|
-
}
|
30
|
-
return
|
31
|
-
}
|
32
|
-
if (e.id in tempObj && e.endTime) {
|
33
|
-
tempWillSendArr.push(e)
|
34
|
-
delete CompatibilityManager.requestInfoObj[e.id]
|
35
|
-
return
|
36
|
-
}
|
37
|
-
})
|
38
|
-
}
|
39
|
-
|
40
|
-
// 将要发送的数据转换成兼容的数据
|
41
|
-
return CompatibilityManager.asyncSwapSendArr(tempWillSendArr)
|
42
|
-
}
|
43
|
-
|
44
|
-
private static async asyncSwapSendArr(data: NetworkRequestInfo[]) {
|
45
|
-
const asyncTempArr = await Promise.all(data.map(async (e) => {
|
46
|
-
if (e.endTime) {
|
47
|
-
return {
|
48
|
-
headers: e.responseHeaders,
|
49
|
-
body: await e.getResponseBody(),
|
50
|
-
requestId: e.id,
|
51
|
-
statusCode: e.status,
|
52
|
-
endTime: e.endTime,
|
53
|
-
};
|
54
|
-
} else {
|
55
|
-
return {
|
56
|
-
url: e.url,
|
57
|
-
id: e.id,
|
58
|
-
method: e.method,
|
59
|
-
headers: e.requestHeaders,
|
60
|
-
body: e.getRequestBody(),
|
61
|
-
createTime: e.startTime,
|
62
|
-
};
|
63
|
-
}
|
64
|
-
}));
|
65
|
-
|
66
|
-
return asyncTempArr;
|
67
|
-
}
|
68
|
-
}
|
69
|
-
|
70
|
-
|
71
|
-
export default CompatibilityManager
|