nmtjs 0.15.2 → 0.15.3
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.
|
@@ -11,6 +11,7 @@ export declare const LoggingCallMiddleware: (options?: {
|
|
|
11
11
|
errorLevel?: "error" | "fatal" | "warn" | undefined;
|
|
12
12
|
includePayload?: boolean | undefined;
|
|
13
13
|
includeResponse?: boolean | undefined;
|
|
14
|
+
includeStreamChunks?: boolean | undefined;
|
|
14
15
|
}) => import("./middlewares.ts").Middleware<{
|
|
15
16
|
logger: import("@nmtjs/core").FactoryInjectable<import("pino").Logger, {
|
|
16
17
|
logger: import("@nmtjs/core").LazyInjectable<import("pino").Logger, import("@nmtjs/core").Scope.Global>;
|
|
@@ -21,26 +21,28 @@ export const LoggingCallContextMiddleware = (cb = defaultContext) => createMiddl
|
|
|
21
21
|
});
|
|
22
22
|
},
|
|
23
23
|
});
|
|
24
|
-
export const LoggingCallMiddleware = (options = {
|
|
24
|
+
export const LoggingCallMiddleware = (options = {}) => createMiddleware({
|
|
25
25
|
dependencies: { logger: CoreInjectables.logger('RPC') },
|
|
26
26
|
handle: async ({ logger }, call, next, payload) => {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const { includePayload, includeResponse, includeStreamChunks, level, errorLevel, } = {
|
|
28
|
+
level: 'info',
|
|
29
|
+
errorLevel: 'error',
|
|
30
|
+
includePayload: true,
|
|
31
|
+
includeResponse: true,
|
|
32
|
+
includeStreamChunks: true,
|
|
33
|
+
...options,
|
|
34
|
+
};
|
|
35
|
+
const logFn = logger[level].bind(logger);
|
|
36
|
+
const errorLogFn = logger[errorLevel].bind(logger);
|
|
37
|
+
logFn(includePayload
|
|
30
38
|
? { procedure: call.procedure.contract.name, payload: payload }
|
|
31
39
|
: { procedure: call.procedure.contract.name }, 'RPC call');
|
|
32
40
|
const isIterableProcedure = IsStreamProcedureContract(call.procedure.contract);
|
|
33
41
|
try {
|
|
34
42
|
const response = await next();
|
|
35
|
-
if (
|
|
43
|
+
if (includeResponse) {
|
|
36
44
|
if (isIterableProcedure) {
|
|
37
45
|
logFn({ result: 'success', response: 'Stream' }, 'RPC response');
|
|
38
|
-
return async function* (...args) {
|
|
39
|
-
for await (const chunk of response(...args)) {
|
|
40
|
-
logFn({ callId: call.callId, chunk }, 'RPC stream chunk');
|
|
41
|
-
yield chunk;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
46
|
}
|
|
45
47
|
else {
|
|
46
48
|
logFn({ result: 'success', response }, 'RPC response');
|
|
@@ -49,6 +51,21 @@ export const LoggingCallMiddleware = (options = { level: 'info', includePayload:
|
|
|
49
51
|
else {
|
|
50
52
|
logFn({ result: 'success' }, 'RPC response');
|
|
51
53
|
}
|
|
54
|
+
if (isIterableProcedure && includeStreamChunks) {
|
|
55
|
+
return async function* (...args) {
|
|
56
|
+
try {
|
|
57
|
+
for await (const chunk of response(...args)) {
|
|
58
|
+
logFn({ callId: call.callId, chunk }, 'RPC stream chunk');
|
|
59
|
+
yield chunk;
|
|
60
|
+
}
|
|
61
|
+
logFn({ callId: call.callId }, 'RPC stream end');
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
errorLogFn({ callId: call.callId, error }, 'RPC stream error');
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
52
69
|
return response;
|
|
53
70
|
}
|
|
54
71
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../../../src/runtime/application/api/logging.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAGjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAEnD,MAAM,cAAc,GAAG,CAAC,OAAuB,EAAE,OAAgB,EA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AAK,CAAA;wBACb,CAAC;wBACD,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,gBAAgB,CAAC,CAAA;oBAClD,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,kBAAkB,CAAC,CAAA;wBAC9D,MAAM,KAAK,CAAA;oBACb,CAAC;gBAAA,CACF,CAAA;YACH,CAAC;YAED,OAAO,QAAQ,CAAA;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,WAAW,CAAC,CAAA;YAClC,MAAM,KAAK,CAAA;QACb,CAAC;IAAA,CACF;CACF,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -47,16 +47,16 @@
|
|
|
47
47
|
"oxc-resolver": "11.19.1",
|
|
48
48
|
"prom-client": "git@github.com:siimon/prom-client.git#d4d2dcb366384833951e0116caca707b5f62aa5e",
|
|
49
49
|
"vite": "8.0.1",
|
|
50
|
-
"@nmtjs/
|
|
51
|
-
"@nmtjs/
|
|
52
|
-
"@nmtjs/
|
|
53
|
-
"@nmtjs/
|
|
54
|
-
"@nmtjs/
|
|
55
|
-
"@nmtjs/
|
|
56
|
-
"@nmtjs/protocol": "0.15.
|
|
57
|
-
"@nmtjs/type": "0.15.
|
|
58
|
-
"@nmtjs/
|
|
59
|
-
"@nmtjs/ws-transport": "0.15.
|
|
50
|
+
"@nmtjs/common": "0.15.3",
|
|
51
|
+
"@nmtjs/core": "0.15.3",
|
|
52
|
+
"@nmtjs/gateway": "0.15.3",
|
|
53
|
+
"@nmtjs/http-transport": "0.15.3",
|
|
54
|
+
"@nmtjs/msgpack-format": "0.15.3",
|
|
55
|
+
"@nmtjs/contract": "0.15.3",
|
|
56
|
+
"@nmtjs/protocol": "0.15.3",
|
|
57
|
+
"@nmtjs/type": "0.15.3",
|
|
58
|
+
"@nmtjs/json-format": "0.15.3",
|
|
59
|
+
"@nmtjs/ws-transport": "0.15.3"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@nmtjs/proxy": "1.0.0-beta.4",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"LICENSE.md",
|
|
80
80
|
"README.md"
|
|
81
81
|
],
|
|
82
|
-
"version": "0.15.
|
|
82
|
+
"version": "0.15.3",
|
|
83
83
|
"scripts": {
|
|
84
84
|
"clean-build": "rm -rf ./dist"
|
|
85
85
|
}
|
|
@@ -39,16 +39,32 @@ export const LoggingCallMiddleware = (
|
|
|
39
39
|
errorLevel?: 'warn' | 'error' | 'fatal'
|
|
40
40
|
includePayload?: boolean
|
|
41
41
|
includeResponse?: boolean
|
|
42
|
-
|
|
42
|
+
includeStreamChunks?: boolean
|
|
43
|
+
} = {},
|
|
43
44
|
) =>
|
|
44
45
|
createMiddleware({
|
|
45
46
|
dependencies: { logger: CoreInjectables.logger('RPC') },
|
|
46
47
|
handle: async ({ logger }, call, next, payload) => {
|
|
47
|
-
const
|
|
48
|
-
|
|
48
|
+
const {
|
|
49
|
+
includePayload,
|
|
50
|
+
includeResponse,
|
|
51
|
+
includeStreamChunks,
|
|
52
|
+
level,
|
|
53
|
+
errorLevel,
|
|
54
|
+
} = {
|
|
55
|
+
level: 'info' as const,
|
|
56
|
+
errorLevel: 'error' as const,
|
|
57
|
+
includePayload: true,
|
|
58
|
+
includeResponse: true,
|
|
59
|
+
includeStreamChunks: true,
|
|
60
|
+
...options,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const logFn = logger[level].bind(logger)
|
|
64
|
+
const errorLogFn = logger[errorLevel].bind(logger)
|
|
49
65
|
|
|
50
66
|
logFn(
|
|
51
|
-
|
|
67
|
+
includePayload
|
|
52
68
|
? { procedure: call.procedure.contract.name, payload: payload }
|
|
53
69
|
: { procedure: call.procedure.contract.name },
|
|
54
70
|
'RPC call',
|
|
@@ -60,21 +76,31 @@ export const LoggingCallMiddleware = (
|
|
|
60
76
|
|
|
61
77
|
try {
|
|
62
78
|
const response = await next()
|
|
63
|
-
if (
|
|
79
|
+
if (includeResponse) {
|
|
64
80
|
if (isIterableProcedure) {
|
|
65
81
|
logFn({ result: 'success', response: 'Stream' }, 'RPC response')
|
|
66
|
-
|
|
82
|
+
} else {
|
|
83
|
+
logFn({ result: 'success', response }, 'RPC response')
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
logFn({ result: 'success' }, 'RPC response')
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (isIterableProcedure && includeStreamChunks) {
|
|
90
|
+
return async function* (...args: any[]) {
|
|
91
|
+
try {
|
|
67
92
|
for await (const chunk of response(...args)) {
|
|
68
93
|
logFn({ callId: call.callId, chunk }, 'RPC stream chunk')
|
|
69
94
|
yield chunk
|
|
70
95
|
}
|
|
96
|
+
logFn({ callId: call.callId }, 'RPC stream end')
|
|
97
|
+
} catch (error) {
|
|
98
|
+
errorLogFn({ callId: call.callId, error }, 'RPC stream error')
|
|
99
|
+
throw error
|
|
71
100
|
}
|
|
72
|
-
} else {
|
|
73
|
-
logFn({ result: 'success', response }, 'RPC response')
|
|
74
101
|
}
|
|
75
|
-
} else {
|
|
76
|
-
logFn({ result: 'success' }, 'RPC response')
|
|
77
102
|
}
|
|
103
|
+
|
|
78
104
|
return response
|
|
79
105
|
} catch (error) {
|
|
80
106
|
errorLogFn({ error }, 'RPC error')
|