@wutiange/log-listener-plugin 1.2.3 → 1.3.0-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. package/dist/console.js +14 -15
  2. package/dist/console.js.map +1 -1
  3. package/dist/fetch.js +28 -28
  4. package/dist/fetch.js.map +1 -1
  5. package/dist/index.d.ts +2 -23
  6. package/dist/index.js +2 -117
  7. package/dist/index.js.map +1 -1
  8. package/dist/packages/network-logger/Logger.d.ts +28 -0
  9. package/dist/packages/network-logger/Logger.js +192 -0
  10. package/dist/packages/network-logger/Logger.js.map +1 -0
  11. package/dist/packages/network-logger/NetworkRequestInfo.d.ts +37 -0
  12. package/dist/packages/network-logger/NetworkRequestInfo.js +151 -0
  13. package/dist/packages/network-logger/NetworkRequestInfo.js.map +1 -0
  14. package/dist/packages/network-logger/constant.d.ts +2 -0
  15. package/dist/packages/network-logger/constant.js +6 -0
  16. package/dist/packages/network-logger/constant.js.map +1 -0
  17. package/dist/packages/network-logger/types.d.ts +14 -0
  18. package/dist/packages/network-logger/types.js +3 -0
  19. package/dist/packages/network-logger/types.js.map +1 -0
  20. package/dist/packages/network-logger/utils/debounce.d.ts +2 -0
  21. package/dist/packages/network-logger/utils/debounce.js +20 -0
  22. package/dist/packages/network-logger/utils/debounce.js.map +1 -0
  23. package/dist/packages/network-logger/utils/extractHost.d.ts +2 -0
  24. package/dist/packages/network-logger/utils/extractHost.js +9 -0
  25. package/dist/packages/network-logger/utils/extractHost.js.map +1 -0
  26. package/dist/packages/network-logger/utils/fromEntries.d.ts +2 -0
  27. package/dist/packages/network-logger/utils/fromEntries.js +8 -0
  28. package/dist/packages/network-logger/utils/fromEntries.js.map +1 -0
  29. package/dist/packages/network-logger/utils/logger.d.ts +1 -0
  30. package/dist/packages/network-logger/utils/logger.js +6 -0
  31. package/dist/packages/network-logger/utils/logger.js.map +1 -0
  32. package/dist/src/CompatibilityManager.d.ts +27 -0
  33. package/dist/src/CompatibilityManager.js +82 -0
  34. package/dist/src/CompatibilityManager.js.map +1 -0
  35. package/dist/src/__tests__/console.test.d.ts +1 -0
  36. package/dist/{__tests__ → src/__tests__}/console.test.js +2 -2
  37. package/dist/src/__tests__/console.test.js.map +1 -0
  38. package/dist/src/common.js.map +1 -0
  39. package/dist/src/console.d.ts +1 -0
  40. package/dist/src/console.js +20 -0
  41. package/dist/src/console.js.map +1 -0
  42. package/dist/src/fetch.d.ts +1 -0
  43. package/dist/src/fetch.js +48 -0
  44. package/dist/src/fetch.js.map +1 -0
  45. package/dist/src/index.d.ts +2 -0
  46. package/dist/src/index.js +8 -0
  47. package/dist/src/index.js.map +1 -0
  48. package/dist/src/logPlugin.d.ts +32 -0
  49. package/dist/src/logPlugin.js +187 -0
  50. package/dist/src/logPlugin.js.map +1 -0
  51. package/dist/{server.d.ts → src/server.d.ts} +1 -1
  52. package/dist/{server.js → src/server.js} +14 -8
  53. package/dist/src/server.js.map +1 -0
  54. package/dist/src/utils.d.ts +3 -0
  55. package/dist/src/utils.js +38 -0
  56. package/dist/src/utils.js.map +1 -0
  57. package/package.json +13 -5
  58. package/packages/network-logger/Logger.ts +274 -0
  59. package/packages/network-logger/NetworkRequestInfo.ts +161 -0
  60. package/packages/network-logger/constant.ts +3 -0
  61. package/packages/network-logger/types.ts +36 -0
  62. package/packages/network-logger/utils/debounce.ts +21 -0
  63. package/packages/network-logger/utils/extractHost.ts +7 -0
  64. package/packages/network-logger/utils/fromEntries.ts +7 -0
  65. package/packages/network-logger/utils/logger.ts +2 -0
  66. package/src/CompatibilityManager.ts +71 -0
  67. package/src/__tests__/console.test.ts +2 -2
  68. package/src/common.ts +2 -3
  69. package/src/logPlugin.ts +229 -0
  70. package/src/server.ts +28 -23
  71. package/src/utils.ts +38 -0
  72. package/dist/__tests__/console.test.d.ts +0 -1
  73. package/dist/__tests__/console.test.js.map +0 -1
  74. package/dist/common.js.map +0 -1
  75. package/dist/server.js.map +0 -1
  76. package/dist/utils.d.ts +0 -1
  77. package/dist/utils.js +0 -14
  78. package/dist/utils.js.map +0 -1
  79. package/src/console.ts +0 -19
  80. package/src/fetch.ts +0 -35
  81. package/src/index.ts +0 -131
  82. /package/dist/{common.d.ts → src/common.d.ts} +0 -0
  83. /package/dist/{common.js → src/common.js} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"console.test.js","sourceRoot":"","sources":["../../src/__tests__/console.test.ts"],"names":[],"mappings":";;;;;AAAA,sBAAmB;AACnB,qDAA6B;AAC7B,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IACpB,EAAE,CAAC,gBAAgB,EAAE,GAAG,EAAE;QACxB,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;QACzB,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,eAAe,EAAE,GAAG,EAAE;QACvB,eAAM,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAA;QAC3C,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;QACzB,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;QACd,eAAM,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAA;QAC3C,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;QAC3B,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;QACf,eAAM,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAA;QAC3C,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;QAC7B,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":";;;;AAAa,KAAqB,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,EAA9D,WAAG,UAAE,YAAI,UAAE,aAAK,SAA8C;AAI/D,QAAA,SAAS,GAAG,MAAM,CAAC,KAAqB,CAAA"}
@@ -1 +0,0 @@
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,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAA;gBAC1C,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;oBAChC,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,EAAE;wBACvD,MAAM,EAAE,MAAM;wBACd,OAAO,EAAE;4BACP,cAAc,EAAE,gCAAgC;yBACjD;wBACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,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/dist/utils.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function sleep(ms: number, isReject?: boolean): Promise<unknown>;
package/dist/utils.js DELETED
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sleep = void 0;
4
- function sleep(ms, isReject = false) {
5
- return new Promise((resolve, reject) => {
6
- setTimeout(isReject ? () => reject({
7
- code: 11001,
8
- key: '@wutiange/log-listener-plugin%%timeout',
9
- msg: 'Timeout'
10
- }) : resolve, ms);
11
- });
12
- }
13
- exports.sleep = sleep;
14
- //# sourceMappingURL=utils.js.map
package/dist/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,SAAgB,KAAK,CAAC,EAAU,EAAE,WAAoB,KAAK;IACzD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC;YACjC,IAAI,EAAE,KAAK;YACX,GAAG,EAAE,wCAAwC;YAC7C,GAAG,EAAE,SAAS;SACf,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;AACJ,CAAC;AARD,sBAQC"}
package/src/console.ts DELETED
@@ -1,19 +0,0 @@
1
- import logger from './index'
2
-
3
- import('./common.js').then(common => {
4
- console.log = (...data: any[]) => {
5
- logger.log(...data)
6
- common.log(...data)
7
- }
8
-
9
- console.warn = (...data: any[]) => {
10
- logger.warn(...data)
11
- common.warn(...data)
12
- }
13
-
14
- console.error = (...data: any[]) => {
15
- logger.error(...data)
16
- common.error(...data)
17
- }
18
- })
19
-
package/src/fetch.ts DELETED
@@ -1,35 +0,0 @@
1
- import logger from './index'
2
- import { sleep } from './utils'
3
-
4
- import('./common.js').then(common => {
5
- // @ts-ignore
6
- global.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {
7
- const uniqueId = (Date.now() + Math.random()).toString(16)
8
- logger.uniqueReq(uniqueId, input, init)
9
- let isFetchFinished = false
10
- let isTimeout = false
11
- if (logger.getTimeout() !== null) {
12
- sleep(logger.getTimeout()).then(() => {
13
- if (!isFetchFinished) {
14
- isTimeout = true
15
- logger.resTimeout(uniqueId)
16
- }
17
- })
18
- }
19
-
20
- try {
21
- const response = await common.tempFetch(input, init)
22
- isFetchFinished = true
23
- if (response instanceof Response && !isTimeout) {
24
- logger.uniqueRes(uniqueId, response.clone())
25
- }
26
- return response
27
- } catch (error) {
28
- isFetchFinished = true
29
- if (!isTimeout) {
30
- logger.resResponseError(uniqueId)
31
- }
32
- throw new Error(error)
33
- }
34
- }
35
- })
package/src/index.ts DELETED
@@ -1,131 +0,0 @@
1
- import Server from "./server"
2
-
3
-
4
- class Logger {
5
-
6
- private server: Server | null = null
7
- private baseData: Record<string, any> = {}
8
- private timeout: number | null = null
9
-
10
- setBaseUrl(url: string) {
11
- if (this.server) {
12
- this.server.updateUrl(url)
13
- } else {
14
- this.server = new Server(url)
15
- }
16
- }
17
-
18
- setTimeout(timeout: number) {
19
- if (typeof timeout === 'number') {
20
- this.timeout = timeout
21
- this.server?.updateTimeout(this.timeout)
22
- }
23
- }
24
-
25
- getTimeout() {
26
- if (typeof this.timeout === 'number') {
27
- return this.timeout
28
- }
29
- return null
30
- }
31
-
32
- setBaseData(data: Record<string, any> = {}) {
33
- this.baseData = data
34
- }
35
-
36
- private _log(level: string, tag: string, ...data: any[]) {
37
- const sendData = {
38
- ...this.baseData,
39
- message: data,
40
- tag,
41
- level: level ?? 'log',
42
- createTime: Date.now()
43
- }
44
- this.server?.log(sendData)
45
- }
46
-
47
- tag(tag: string, ...data: any[]) {
48
- this._log('log', tag, ...data)
49
- }
50
-
51
- log(...data: any[]) {
52
- this._log('log', 'default', ...data)
53
- }
54
-
55
- warn(...data: any[]) {
56
- this._log('warn', 'default', ...data)
57
- }
58
-
59
- error(...data: any[]) {
60
- this._log('error', 'default', ...data)
61
- }
62
-
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 as Record<string, any>)['map']
72
- body = input.body
73
- } else if (input instanceof URL) {
74
- url = input.href
75
- } else {
76
- url = input
77
- }
78
- return this.server?.network({
79
- ...this.baseData,
80
- url,
81
- id: uniqueId,
82
- method,
83
- headers,
84
- body,
85
- createTime: Date.now(),
86
- })
87
- }
88
-
89
- private async _res(uniqueId?: string, id?: number, response?: Response) {
90
- const body = await response.text()
91
- return this.server?.network({
92
- ...this.baseData,
93
- headers: (response?.headers as Record<string, any>)['map'],
94
- body,
95
- requestId: uniqueId ?? Number(id),
96
- statusCode: response?.status,
97
- endTime: Date.now(),
98
- })
99
- }
100
-
101
- async resTimeout(uniqueId: string) {
102
- return this.server?.network({
103
- ...this.baseData,
104
- isTimeout: true,
105
- requestId: uniqueId,
106
- })
107
- }
108
-
109
- async resResponseError(uniqueId: string) {
110
- return this.server?.network({
111
- ...this.baseData,
112
- isResponseError: true,
113
- requestId: uniqueId,
114
- })
115
- }
116
-
117
- async uniqueRes(uniqueId: string, response?: Response) {
118
- return this._res(uniqueId, undefined, response)
119
- }
120
-
121
- async req(input: RequestInfo | URL, init?: RequestInit) {
122
- return this.uniqueReq(undefined, input, init)
123
- }
124
-
125
- async res(id: number, response?: Response) {
126
- return this._res(undefined, id, response)
127
- }
128
- }
129
-
130
-
131
- export default new Logger()
File without changes
File without changes