@wutiange/log-listener-plugin 1.1.10 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +20 -2
- package/dist/index.js.map +1 -1
- package/dist/server.js +6 -1
- package/dist/server.js.map +1 -1
- package/package.json +9 -1
- package/src/index.ts +18 -4
- package/src/server.ts +6 -1
package/dist/index.js
CHANGED
@@ -61,9 +61,27 @@ class Logger {
|
|
61
61
|
this._log('error', 'default', ...data);
|
62
62
|
}
|
63
63
|
uniqueReq(uniqueId, input, init) {
|
64
|
-
var _a, _b;
|
64
|
+
var _a, _b, _c;
|
65
65
|
return __awaiter(this, void 0, void 0, function* () {
|
66
|
-
|
66
|
+
let url = null;
|
67
|
+
let method = (_a = init === null || init === void 0 ? void 0 : init.method) !== null && _a !== void 0 ? _a : 'get';
|
68
|
+
let headers = init === null || init === void 0 ? void 0 : init.headers;
|
69
|
+
let body = init === null || init === void 0 ? void 0 : init.body;
|
70
|
+
if (input instanceof Request) {
|
71
|
+
url = input.url;
|
72
|
+
method = (_b = input.method) !== null && _b !== void 0 ? _b : 'get';
|
73
|
+
headers = input.headers;
|
74
|
+
body = input.body;
|
75
|
+
}
|
76
|
+
else if (input instanceof URL) {
|
77
|
+
url = input.href;
|
78
|
+
}
|
79
|
+
else {
|
80
|
+
url = input;
|
81
|
+
}
|
82
|
+
return (_c = this.server) === null || _c === void 0 ? void 0 : _c.network(Object.assign(Object.assign({}, this.baseData), { url, id: uniqueId, method,
|
83
|
+
headers,
|
84
|
+
body, createTime: Date.now() }));
|
67
85
|
});
|
68
86
|
}
|
69
87
|
_res(uniqueId, id, response) {
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAA6B;AAG7B,MAAM,MAAM;IAAZ;QAEU,WAAM,GAAkB,IAAI,CAAA;QAC5B,aAAQ,GAAwB,EAAE,CAAA;QAClC,YAAO,GAAkB,IA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KAAA;IAEK,GAAG,CAAC,KAAwB,EAAE,IAAkB;;YACpD,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;QAC/C,CAAC;KAAA;IAEK,GAAG,CAAC,EAAU,EAAE,QAAmB;;YACvC,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAA;QAC3C,CAAC;KAAA;CACF;AAGD,kBAAe,IAAI,MAAM,EAAE,CAAA"}
|
package/dist/server.js
CHANGED
@@ -33,7 +33,12 @@ class Server {
|
|
33
33
|
headers: {
|
34
34
|
'Content-Type': 'application/json;charset=utf-8'
|
35
35
|
},
|
36
|
-
body: JSON.stringify(data)
|
36
|
+
body: JSON.stringify(data, (_, val) => {
|
37
|
+
if (val instanceof Error) {
|
38
|
+
return val.toString();
|
39
|
+
}
|
40
|
+
return val;
|
41
|
+
})
|
37
42
|
}),
|
38
43
|
(0, utils_1.sleep)(this.timeout, true)
|
39
44
|
]);
|
package/dist/server.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mCAAgC;AAEhC,MAAM,MAAM;IAMV,YAAY,GAAW,EAAE,UAAkB,IAAI;QALvC,YAAO,GAAG,EAAE,CAAC;QACb,SAAI,GAAG,KAAK,CAAA;QAKlB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,aAAa,CAAC,OAAO,GAAG,IAAI;QAC1B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAEa,IAAI,CAAC,IAAY,EAAE,IAAyB;;YACxD,IAAI,CAAC;gBACH,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;oBAClB,OAAO,IAAI,CAAA;gBACb,CAAC;gBACD,MAA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EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;4BACpC,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;gCACzB,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAA;4BACvB,CAAC;4BACD,OAAO,GAAG,CAAA;wBACZ,CAAC,CAAC;qBACH,CAAC;oBACF,IAAA,aAAK,EAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC;iBAC1B,CAAC,CAAA;gBACF,IAAI,MAAM,YAAY,QAAQ,EAAE,CAAC;oBAC/B,OAAO,MAAM,CAAC,IAAI,EAAE,CAAA;gBACtB,CAAC;gBACD,OAAO,IAAI,CAAA;YACb,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,IAAI,CAAA;YACb,CAAC;QACH,CAAC;KAAA;IAED,SAAS,CAAC,GAAW;QACnB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAA;IACpB,CAAC;IAEK,GAAG,CAAC,IAAyB;;YACjC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QAC/B,CAAC;KAAA;IAEK,OAAO,CAAC,IAAyB;;YACrC,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;QACnC,CAAC;KAAA;CACF;AAED,kBAAe,MAAM,CAAA"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@wutiange/log-listener-plugin",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.2.0",
|
4
4
|
"description": "这是log-record的插件,如果需要使用这个日志监听,那么就需要把这个插件安装到项目中",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -8,6 +8,14 @@
|
|
8
8
|
"author": "wutiange <wutiange20@qq,com>",
|
9
9
|
"license": "MIT",
|
10
10
|
"private": false,
|
11
|
+
"exports": {
|
12
|
+
"console": {
|
13
|
+
"default": "./dist/console.js"
|
14
|
+
},
|
15
|
+
"fetch": {
|
16
|
+
"default": "./dist/fetch.js"
|
17
|
+
}
|
18
|
+
},
|
11
19
|
"scripts": {
|
12
20
|
"build": "tsc",
|
13
21
|
"dev": "ts-node ./src/index.ts",
|
package/src/index.ts
CHANGED
@@ -61,13 +61,27 @@ class Logger {
|
|
61
61
|
}
|
62
62
|
|
63
63
|
async uniqueReq(uniqueId: string, input: RequestInfo | URL, init?: RequestInit) {
|
64
|
+
let url: string | null = null
|
65
|
+
let method = init?.method ?? 'get'
|
66
|
+
let headers = init?.headers
|
67
|
+
let body = init?.body
|
68
|
+
if (input instanceof Request) {
|
69
|
+
url = input.url
|
70
|
+
method = input.method ?? 'get'
|
71
|
+
headers = input.headers
|
72
|
+
body = input.body
|
73
|
+
} else if (input instanceof URL) {
|
74
|
+
url = input.href
|
75
|
+
} else {
|
76
|
+
url = input
|
77
|
+
}
|
64
78
|
return this.server?.network({
|
65
79
|
...this.baseData,
|
66
|
-
url
|
80
|
+
url,
|
67
81
|
id: uniqueId,
|
68
|
-
method
|
69
|
-
headers
|
70
|
-
body
|
82
|
+
method,
|
83
|
+
headers,
|
84
|
+
body,
|
71
85
|
createTime: Date.now(),
|
72
86
|
})
|
73
87
|
}
|
package/src/server.ts
CHANGED
@@ -27,7 +27,12 @@ class Server {
|
|
27
27
|
headers: {
|
28
28
|
'Content-Type': 'application/json;charset=utf-8'
|
29
29
|
},
|
30
|
-
body: JSON.stringify(data)
|
30
|
+
body: JSON.stringify(data, (_, val) => {
|
31
|
+
if (val instanceof Error) {
|
32
|
+
return val.toString()
|
33
|
+
}
|
34
|
+
return val
|
35
|
+
})
|
31
36
|
}),
|
32
37
|
sleep(this.timeout, true)
|
33
38
|
])
|