slonik-interceptor-query-logging 1.4.7 → 40.2.5
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/CHANGELOG.md +40 -0
- package/README.md +0 -2
- package/dist/{src/factories → factories}/createQueryLoggingInterceptor.d.ts +4 -3
- package/dist/factories/createQueryLoggingInterceptor.d.ts.map +1 -0
- package/dist/{src/factories → factories}/createQueryLoggingInterceptor.js +15 -6
- package/dist/factories/createQueryLoggingInterceptor.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/{src/factories/index.js → index.js} +2 -1
- package/dist/index.js.map +1 -0
- package/dist/{src/utilities → utilities}/getAutoExplainPayload.d.ts +1 -0
- package/dist/utilities/getAutoExplainPayload.d.ts.map +1 -0
- package/dist/{src/utilities → utilities}/getAutoExplainPayload.js +1 -0
- package/dist/utilities/getAutoExplainPayload.js.map +1 -0
- package/dist/utilities/getAutoExplainPayload.test.d.ts +2 -0
- package/dist/utilities/getAutoExplainPayload.test.d.ts.map +1 -0
- package/dist/utilities/getAutoExplainPayload.test.js +27 -0
- package/dist/utilities/getAutoExplainPayload.test.js.map +1 -0
- package/dist/{src/utilities → utilities}/isAutoExplainJsonMessage.d.ts +1 -0
- package/dist/utilities/isAutoExplainJsonMessage.d.ts.map +1 -0
- package/dist/{src/utilities → utilities}/isAutoExplainJsonMessage.js +2 -1
- package/dist/utilities/isAutoExplainJsonMessage.js.map +1 -0
- package/dist/utilities/isAutoExplainJsonMessage.test.d.ts +2 -0
- package/dist/utilities/isAutoExplainJsonMessage.test.d.ts.map +1 -0
- package/dist/utilities/isAutoExplainJsonMessage.test.js +11 -0
- package/dist/utilities/isAutoExplainJsonMessage.test.js.map +1 -0
- package/package.json +14 -29
- package/src/.eslintrc +26 -0
- package/src/factories/createQueryLoggingInterceptor.ts +50 -29
- package/src/index.ts +1 -5
- package/src/utilities/getAutoExplainPayload.test.ts +30 -0
- package/src/utilities/getAutoExplainPayload.ts +4 -4
- package/src/utilities/isAutoExplainJsonMessage.test.ts +6 -0
- package/src/utilities/isAutoExplainJsonMessage.ts +3 -1
- package/tsconfig.json +9 -11
- package/LICENSE +0 -24
- package/dist/src/factories/index.d.ts +0 -1
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +0 -6
- package/dist/src/utilities/index.d.ts +0 -2
- package/dist/src/utilities/index.js +0 -7
- package/src/factories/index.ts +0 -3
- package/src/utilities/index.ts +0 -6
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# slonik-interceptor-query-logging
|
|
2
|
+
|
|
3
|
+
## 40.2.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`ef802a9`](https://github.com/gajus/slonik/commit/ef802a91be2bc6e69b077c544cc7f9e5a2687433) Thanks [@gajus](https://github.com/gajus)! - force patch bump
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`ef802a9`](https://github.com/gajus/slonik/commit/ef802a91be2bc6e69b077c544cc7f9e5a2687433)]:
|
|
10
|
+
- slonik@40.2.5
|
|
11
|
+
|
|
12
|
+
## 40.2.4
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [`c1064fc`](https://github.com/gajus/slonik/commit/c1064fc3f21f839effc1687737942332a7c05b0d) Thanks [@gajus](https://github.com/gajus)! - update access
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`c1064fc`](https://github.com/gajus/slonik/commit/c1064fc3f21f839effc1687737942332a7c05b0d)]:
|
|
19
|
+
- slonik@40.2.4
|
|
20
|
+
|
|
21
|
+
## 40.2.3
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- [#577](https://github.com/gajus/slonik/pull/577) [`4007ab7`](https://github.com/gajus/slonik/commit/4007ab7e07d5b71e8f41e145584979fa36885275) Thanks [@gajus](https://github.com/gajus)! - abstract packages using internal modules
|
|
26
|
+
|
|
27
|
+
- [#579](https://github.com/gajus/slonik/pull/579) [`2779fd1`](https://github.com/gajus/slonik/commit/2779fd15ddae35b9830f4c156648e444cd793f13) Thanks [@gajus](https://github.com/gajus)! - add slonik-sql-tag-raw
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [[`4007ab7`](https://github.com/gajus/slonik/commit/4007ab7e07d5b71e8f41e145584979fa36885275), [`2779fd1`](https://github.com/gajus/slonik/commit/2779fd15ddae35b9830f4c156648e444cd793f13)]:
|
|
30
|
+
- slonik@40.2.3
|
|
31
|
+
|
|
32
|
+
## 2.0.0
|
|
33
|
+
|
|
34
|
+
### Major Changes
|
|
35
|
+
|
|
36
|
+
- [#575](https://github.com/gajus/slonik/pull/575) [`050cd78`](https://github.com/gajus/slonik/commit/050cd788a77b6ce5e410c0985d01a09733f994bd) Thanks [@gajus](https://github.com/gajus)! - Increase minimum supported node.js version
|
|
37
|
+
|
|
38
|
+
### Minor Changes
|
|
39
|
+
|
|
40
|
+
- [#575](https://github.com/gajus/slonik/pull/575) [`050cd78`](https://github.com/gajus/slonik/commit/050cd788a77b6ce5e410c0985d01a09733f994bd) Thanks [@gajus](https://github.com/gajus)! - Adding interceptors to the monorepo.
|
package/README.md
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# slonik-interceptor-query-logging
|
|
2
2
|
|
|
3
|
-
[](https://travis-ci.com/github/gajus/slonik-interceptor-query-logging)
|
|
4
|
-
[](https://coveralls.io/github/gajus/slonik-interceptor-query-logging)
|
|
5
3
|
[](https://www.npmjs.org/package/slonik-interceptor-query-logging)
|
|
6
4
|
[](https://github.com/gajus/canonical)
|
|
7
5
|
[](https://twitter.com/kuizinas)
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Interceptor } from 'slonik';
|
|
2
2
|
/**
|
|
3
3
|
* @property logValues Dictates whether to include parameter values used to execute the query. (default: true)
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
type UserConfigurationType = {
|
|
6
6
|
logValues: boolean;
|
|
7
7
|
};
|
|
8
|
-
export declare const createQueryLoggingInterceptor: (userConfiguration?: UserConfigurationType
|
|
8
|
+
export declare const createQueryLoggingInterceptor: (userConfiguration?: UserConfigurationType) => Interceptor;
|
|
9
9
|
export {};
|
|
10
|
+
//# sourceMappingURL=createQueryLoggingInterceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createQueryLoggingInterceptor.d.ts","sourceRoot":"","sources":["../../src/factories/createQueryLoggingInterceptor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAC;AAE1C;;GAEG;AACH,KAAK,qBAAqB,GAAG;IAC3B,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAgBF,eAAO,MAAM,6BAA6B,uBACpB,qBAAqB,KACxC,WAgGF,CAAC"}
|
|
@@ -4,11 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createQueryLoggingInterceptor = void 0;
|
|
7
|
+
const getAutoExplainPayload_1 = require("../utilities/getAutoExplainPayload");
|
|
8
|
+
const isAutoExplainJsonMessage_1 = require("../utilities/isAutoExplainJsonMessage");
|
|
7
9
|
const pretty_ms_1 = __importDefault(require("pretty-ms"));
|
|
8
10
|
const serialize_error_1 = require("serialize-error");
|
|
9
|
-
const utilities_1 = require("../utilities");
|
|
10
11
|
const stringifyCallSite = (callSite) => {
|
|
11
|
-
return (callSite.fileName || '') +
|
|
12
|
+
return ((callSite.fileName || '') +
|
|
13
|
+
':' +
|
|
14
|
+
callSite.lineNumber +
|
|
15
|
+
':' +
|
|
16
|
+
callSite.columnNumber);
|
|
12
17
|
};
|
|
13
18
|
const defaultConfiguration = {
|
|
14
19
|
logValues: true,
|
|
@@ -28,14 +33,15 @@ const createQueryLoggingInterceptor = (userConfiguration) => {
|
|
|
28
33
|
if (!notice.message) {
|
|
29
34
|
continue;
|
|
30
35
|
}
|
|
31
|
-
if ((0,
|
|
36
|
+
if ((0, isAutoExplainJsonMessage_1.isAutoExplainJsonMessage)(notice.message)) {
|
|
32
37
|
context.log.info({
|
|
33
|
-
autoExplain: (0,
|
|
38
|
+
autoExplain: (0, getAutoExplainPayload_1.getAutoExplainPayload)(notice.message),
|
|
34
39
|
}, 'auto explain');
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
42
|
context.log.debug({
|
|
38
|
-
executionTime: (0, pretty_ms_1.default)(Number(process.hrtime.bigint() - BigInt(context.queryInputTime)) /
|
|
43
|
+
executionTime: (0, pretty_ms_1.default)(Number(process.hrtime.bigint() - BigInt(context.queryInputTime)) /
|
|
44
|
+
1000000),
|
|
39
45
|
rowCount,
|
|
40
46
|
}, 'query execution result');
|
|
41
47
|
return null;
|
|
@@ -46,7 +52,9 @@ const createQueryLoggingInterceptor = (userConfiguration) => {
|
|
|
46
52
|
stackTrace = [];
|
|
47
53
|
for (const callSite of context.stackTrace) {
|
|
48
54
|
// Hide the internal call sites.
|
|
49
|
-
if (callSite.fileName !== null &&
|
|
55
|
+
if (callSite.fileName !== null &&
|
|
56
|
+
!callSite.fileName.includes('node_modules/slonik/') &&
|
|
57
|
+
!callSite.fileName.includes('next_tick')) {
|
|
50
58
|
stackTrace.push(stringifyCallSite(callSite));
|
|
51
59
|
}
|
|
52
60
|
}
|
|
@@ -79,3 +87,4 @@ const createQueryLoggingInterceptor = (userConfiguration) => {
|
|
|
79
87
|
};
|
|
80
88
|
};
|
|
81
89
|
exports.createQueryLoggingInterceptor = createQueryLoggingInterceptor;
|
|
90
|
+
//# sourceMappingURL=createQueryLoggingInterceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createQueryLoggingInterceptor.js","sourceRoot":"","sources":["../../src/factories/createQueryLoggingInterceptor.ts"],"names":[],"mappings":";;;;;;AAAA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AAC;aAC7B,EACD,mCAAmC,CACpC,CAAC;YAEF,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAlGW,QAAA,6BAA6B,iCAkGxC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,2CAA2C,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createQueryLoggingInterceptor = void 0;
|
|
4
|
-
var createQueryLoggingInterceptor_1 = require("./createQueryLoggingInterceptor");
|
|
4
|
+
var createQueryLoggingInterceptor_1 = require("./factories/createQueryLoggingInterceptor");
|
|
5
5
|
Object.defineProperty(exports, "createQueryLoggingInterceptor", { enumerable: true, get: function () { return createQueryLoggingInterceptor_1.createQueryLoggingInterceptor; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2FAA0F;AAAjF,8IAAA,6BAA6B,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAutoExplainPayload.d.ts","sourceRoot":"","sources":["../../src/utilities/getAutoExplainPayload.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qBAAqB,kBAAmB,MAAM,QAc1D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAutoExplainPayload.js","sourceRoot":"","sources":["../../src/utilities/getAutoExplainPayload.ts"],"names":[],"mappings":";;;AAAA,2CAAyC;AAElC,MAAM,qBAAqB,GAAG,CAAC,aAAqB,EAAE,EAAE;IAC7D,MAAM,OAAO,GAAG,IAAA,wBAAW,EAAC,aAAa,CAAC,CAAC;IAE3C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;QACxB,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAC;KACH;IAED,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;KACpE;IAED,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC;AAdW,QAAA,qBAAqB,yBAchC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAutoExplainPayload.test.d.ts","sourceRoot":"","sources":["../../src/utilities/getAutoExplainPayload.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getAutoExplainPayload_1 = require("./getAutoExplainPayload");
|
|
7
|
+
const ava_1 = __importDefault(require("ava"));
|
|
8
|
+
(0, ava_1.default)('extracts JSON from the message', (t) => {
|
|
9
|
+
t.deepEqual((0, getAutoExplainPayload_1.getAutoExplainPayload)('duration: {"foo":"bar"}'), {
|
|
10
|
+
foo: 'bar',
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
(0, ava_1.default)('throws an error if payload is not found', (t) => {
|
|
14
|
+
t.throws(() => {
|
|
15
|
+
(0, getAutoExplainPayload_1.getAutoExplainPayload)('duration:');
|
|
16
|
+
}, {
|
|
17
|
+
message: 'Notice message does not contain a recognizable JSON payload.',
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
(0, ava_1.default)('throws an error if multiple payloads are found', (t) => {
|
|
21
|
+
t.throws(() => {
|
|
22
|
+
(0, getAutoExplainPayload_1.getAutoExplainPayload)('duration: {"foo":"bar"} {"foo":"bar"}');
|
|
23
|
+
}, {
|
|
24
|
+
message: 'Notice message contains multiple JSON payloads.',
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=getAutoExplainPayload.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAutoExplainPayload.test.js","sourceRoot":"","sources":["../../src/utilities/getAutoExplainPayload.test.ts"],"names":[],"mappings":";;;;;AAAA,mEAAgE;AAChE,8CAAuB;AAEvB,IAAA,aAAI,EAAC,gCAAgC,EAAE,CAAC,CAAC,EAAE,EAAE;IAC3C,CAAC,CAAC,SAAS,CAAC,IAAA,6CAAqB,EAAC,yBAAyB,CAAC,EAAE;QAC5D,GAAG,EAAE,KAAK;KACX,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAA,aAAI,EAAC,yCAAyC,EAAE,CAAC,CAAC,EAAE,EAAE;IACpD,CAAC,CAAC,MAAM,CACN,GAAG,EAAE;QACH,IAAA,6CAAqB,EAAC,WAAW,CAAC,CAAC;IACrC,CAAC,EACD;QACE,OAAO,EAAE,8DAA8D;KACxE,CACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAA,aAAI,EAAC,gDAAgD,EAAE,CAAC,CAAC,EAAE,EAAE;IAC3D,CAAC,CAAC,MAAM,CACN,GAAG,EAAE;QACH,IAAA,6CAAqB,EAAC,uCAAuC,CAAC,CAAC;IACjE,CAAC,EACD;QACE,OAAO,EAAE,iDAAiD;KAC3D,CACF,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isAutoExplainJsonMessage.d.ts","sourceRoot":"","sources":["../../src/utilities/isAutoExplainJsonMessage.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,kBAAmB,MAAM,KAAG,OAIhE,CAAC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isAutoExplainJsonMessage = void 0;
|
|
4
4
|
const isAutoExplainJsonMessage = (noticeMessage) => {
|
|
5
|
-
return noticeMessage.trim().startsWith('duration:') && noticeMessage.includes('{');
|
|
5
|
+
return (noticeMessage.trim().startsWith('duration:') && noticeMessage.includes('{'));
|
|
6
6
|
};
|
|
7
7
|
exports.isAutoExplainJsonMessage = isAutoExplainJsonMessage;
|
|
8
|
+
//# sourceMappingURL=isAutoExplainJsonMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isAutoExplainJsonMessage.js","sourceRoot":"","sources":["../../src/utilities/isAutoExplainJsonMessage.ts"],"names":[],"mappings":";;;AAAO,MAAM,wBAAwB,GAAG,CAAC,aAAqB,EAAW,EAAE;IACzE,OAAO,CACL,aAAa,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,CAC5E,CAAC;AACJ,CAAC,CAAC;AAJW,QAAA,wBAAwB,4BAInC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isAutoExplainJsonMessage.test.d.ts","sourceRoot":"","sources":["../../src/utilities/isAutoExplainJsonMessage.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const isAutoExplainJsonMessage_1 = require("./isAutoExplainJsonMessage");
|
|
7
|
+
const ava_1 = __importDefault(require("ava"));
|
|
8
|
+
(0, ava_1.default)('recognizes notice containing JSON', (t) => {
|
|
9
|
+
t.true((0, isAutoExplainJsonMessage_1.isAutoExplainJsonMessage)('duration: {}'));
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=isAutoExplainJsonMessage.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isAutoExplainJsonMessage.test.js","sourceRoot":"","sources":["../../src/utilities/isAutoExplainJsonMessage.test.ts"],"names":[],"mappings":";;;;;AAAA,yEAAsE;AACtE,8CAAuB;AAEvB,IAAA,aAAI,EAAC,mCAAmC,EAAE,CAAC,CAAC,EAAE,EAAE;IAC9C,CAAC,CAAC,IAAI,CAAC,IAAA,mDAAwB,EAAC,cAAc,CAAC,CAAC,CAAC;AACnD,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"ts"
|
|
10
10
|
],
|
|
11
11
|
"files": [
|
|
12
|
-
"test
|
|
12
|
+
"src/**/*.test.ts"
|
|
13
13
|
],
|
|
14
14
|
"require": [
|
|
15
15
|
"ts-node/register/transpile-only"
|
|
@@ -22,30 +22,15 @@
|
|
|
22
22
|
},
|
|
23
23
|
"description": "Logs Slonik queries.",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"babel-plugin-transform-export-default-name": "^2.1.0",
|
|
30
|
-
"coveralls": "^3.1.1",
|
|
31
|
-
"del-cli": "^4.0.1",
|
|
32
|
-
"eslint": "^8.4.1",
|
|
33
|
-
"eslint-config-canonical": "^32.46.0",
|
|
34
|
-
"husky": "^7.0.4",
|
|
35
|
-
"inline-loops.macro": "^1.2.2",
|
|
36
|
-
"nyc": "^15.1.0",
|
|
37
|
-
"semantic-release": "^18.0.1",
|
|
38
|
-
"sinon": "^12.0.1",
|
|
25
|
+
"ava": "^5.3.1",
|
|
26
|
+
"eslint": "^8.57.0",
|
|
27
|
+
"eslint-config-canonical": "^42.8.1",
|
|
28
|
+
"slonik": "^40.2.5",
|
|
39
29
|
"ts-node": "^10.4.0",
|
|
40
30
|
"typescript": "^4.5.3"
|
|
41
31
|
},
|
|
42
32
|
"engines": {
|
|
43
|
-
"node": ">=
|
|
44
|
-
},
|
|
45
|
-
"husky": {
|
|
46
|
-
"hooks": {
|
|
47
|
-
"pre-commit": "npm run lint && npm run test && npm run build"
|
|
48
|
-
}
|
|
33
|
+
"node": ">=18"
|
|
49
34
|
},
|
|
50
35
|
"keywords": [
|
|
51
36
|
"postgresql",
|
|
@@ -53,20 +38,20 @@
|
|
|
53
38
|
"logging"
|
|
54
39
|
],
|
|
55
40
|
"license": "BSD-3-Clause",
|
|
56
|
-
"main": "./dist/
|
|
41
|
+
"main": "./dist/index.js",
|
|
57
42
|
"name": "slonik-interceptor-query-logging",
|
|
58
43
|
"peerDependencies": {
|
|
59
|
-
"slonik": ">=
|
|
44
|
+
"slonik": ">=40.2.5"
|
|
60
45
|
},
|
|
61
46
|
"repository": {
|
|
62
47
|
"type": "git",
|
|
63
|
-
"url": "https://github.com/gajus/slonik
|
|
48
|
+
"url": "https://github.com/gajus/slonik"
|
|
64
49
|
},
|
|
65
50
|
"scripts": {
|
|
66
|
-
"build": "
|
|
67
|
-
"lint": "eslint ./src
|
|
68
|
-
"test": "
|
|
51
|
+
"build": "rm -fr ./dist && tsc",
|
|
52
|
+
"lint": "eslint ./src && tsc --noEmit",
|
|
53
|
+
"test": "ava --verbose --serial"
|
|
69
54
|
},
|
|
70
|
-
"typings": "./dist/
|
|
71
|
-
"version": "
|
|
55
|
+
"typings": "./dist/index.d.ts",
|
|
56
|
+
"version": "40.2.5"
|
|
72
57
|
}
|
package/src/.eslintrc
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "canonical/auto",
|
|
3
|
+
"ignorePatterns": [
|
|
4
|
+
"dist",
|
|
5
|
+
"package-lock.json"
|
|
6
|
+
],
|
|
7
|
+
"overrides": [
|
|
8
|
+
{
|
|
9
|
+
"files": "*.ts",
|
|
10
|
+
"rules": {
|
|
11
|
+
"import/no-cycle": 0,
|
|
12
|
+
"no-restricted-imports": ["error", "pg"]
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"files": ["*.test.ts", "**/*.test/*"],
|
|
17
|
+
"extends": "canonical/ava",
|
|
18
|
+
"rules": {
|
|
19
|
+
"@typescript-eslint/no-explicit-any": 0,
|
|
20
|
+
"@typescript-eslint/no-unused-expressions": 0,
|
|
21
|
+
"ava/no-ignored-test-files": 0
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"root": true
|
|
26
|
+
}
|
|
@@ -1,31 +1,33 @@
|
|
|
1
|
+
import { getAutoExplainPayload } from '../utilities/getAutoExplainPayload';
|
|
2
|
+
import { isAutoExplainJsonMessage } from '../utilities/isAutoExplainJsonMessage';
|
|
1
3
|
import prettyMs from 'pretty-ms';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
} from 'serialize-error';
|
|
5
|
-
import type {
|
|
6
|
-
Interceptor,
|
|
7
|
-
} from 'slonik';
|
|
8
|
-
import {
|
|
9
|
-
getAutoExplainPayload,
|
|
10
|
-
isAutoExplainJsonMessage,
|
|
11
|
-
} from '../utilities';
|
|
4
|
+
import { serializeError } from 'serialize-error';
|
|
5
|
+
import { type Interceptor } from 'slonik';
|
|
12
6
|
|
|
13
7
|
/**
|
|
14
8
|
* @property logValues Dictates whether to include parameter values used to execute the query. (default: true)
|
|
15
9
|
*/
|
|
16
10
|
type UserConfigurationType = {
|
|
17
|
-
logValues: boolean
|
|
11
|
+
logValues: boolean;
|
|
18
12
|
};
|
|
19
13
|
|
|
20
14
|
const stringifyCallSite = (callSite) => {
|
|
21
|
-
return (
|
|
15
|
+
return (
|
|
16
|
+
(callSite.fileName || '') +
|
|
17
|
+
':' +
|
|
18
|
+
callSite.lineNumber +
|
|
19
|
+
':' +
|
|
20
|
+
callSite.columnNumber
|
|
21
|
+
);
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
const defaultConfiguration = {
|
|
25
25
|
logValues: true,
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
export const createQueryLoggingInterceptor = (
|
|
28
|
+
export const createQueryLoggingInterceptor = (
|
|
29
|
+
userConfiguration?: UserConfigurationType,
|
|
30
|
+
): Interceptor => {
|
|
29
31
|
const configuration = {
|
|
30
32
|
...defaultConfiguration,
|
|
31
33
|
...userConfiguration,
|
|
@@ -45,16 +47,25 @@ export const createQueryLoggingInterceptor = (userConfiguration?: UserConfigurat
|
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
if (isAutoExplainJsonMessage(notice.message)) {
|
|
48
|
-
context.log.info(
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
context.log.info(
|
|
51
|
+
{
|
|
52
|
+
autoExplain: getAutoExplainPayload(notice.message),
|
|
53
|
+
},
|
|
54
|
+
'auto explain',
|
|
55
|
+
);
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
58
|
|
|
54
|
-
context.log.debug(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
context.log.debug(
|
|
60
|
+
{
|
|
61
|
+
executionTime: prettyMs(
|
|
62
|
+
Number(process.hrtime.bigint() - BigInt(context.queryInputTime)) /
|
|
63
|
+
1_000_000,
|
|
64
|
+
),
|
|
65
|
+
rowCount,
|
|
66
|
+
},
|
|
67
|
+
'query execution result',
|
|
68
|
+
);
|
|
58
69
|
|
|
59
70
|
return null;
|
|
60
71
|
},
|
|
@@ -66,7 +77,11 @@ export const createQueryLoggingInterceptor = (userConfiguration?: UserConfigurat
|
|
|
66
77
|
|
|
67
78
|
for (const callSite of context.stackTrace) {
|
|
68
79
|
// Hide the internal call sites.
|
|
69
|
-
if (
|
|
80
|
+
if (
|
|
81
|
+
callSite.fileName !== null &&
|
|
82
|
+
!callSite.fileName.includes('node_modules/slonik/') &&
|
|
83
|
+
!callSite.fileName.includes('next_tick')
|
|
84
|
+
) {
|
|
70
85
|
stackTrace.push(stringifyCallSite(callSite));
|
|
71
86
|
}
|
|
72
87
|
}
|
|
@@ -86,18 +101,24 @@ export const createQueryLoggingInterceptor = (userConfiguration?: UserConfigurat
|
|
|
86
101
|
}
|
|
87
102
|
}
|
|
88
103
|
|
|
89
|
-
context.log.debug(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
104
|
+
context.log.debug(
|
|
105
|
+
{
|
|
106
|
+
sql: query.sql,
|
|
107
|
+
stackTrace,
|
|
108
|
+
values,
|
|
109
|
+
},
|
|
110
|
+
'executing query',
|
|
111
|
+
);
|
|
94
112
|
|
|
95
113
|
return null;
|
|
96
114
|
},
|
|
97
115
|
queryExecutionError: (context, query, error) => {
|
|
98
|
-
context.log.error(
|
|
99
|
-
|
|
100
|
-
|
|
116
|
+
context.log.error(
|
|
117
|
+
{
|
|
118
|
+
error: serializeError(error),
|
|
119
|
+
},
|
|
120
|
+
'query execution produced an error',
|
|
121
|
+
);
|
|
101
122
|
|
|
102
123
|
return null;
|
|
103
124
|
},
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getAutoExplainPayload } from './getAutoExplainPayload';
|
|
2
|
+
import test from 'ava';
|
|
3
|
+
|
|
4
|
+
test('extracts JSON from the message', (t) => {
|
|
5
|
+
t.deepEqual(getAutoExplainPayload('duration: {"foo":"bar"}'), {
|
|
6
|
+
foo: 'bar',
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('throws an error if payload is not found', (t) => {
|
|
11
|
+
t.throws(
|
|
12
|
+
() => {
|
|
13
|
+
getAutoExplainPayload('duration:');
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
message: 'Notice message does not contain a recognizable JSON payload.',
|
|
17
|
+
},
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('throws an error if multiple payloads are found', (t) => {
|
|
22
|
+
t.throws(
|
|
23
|
+
() => {
|
|
24
|
+
getAutoExplainPayload('duration: {"foo":"bar"} {"foo":"bar"}');
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
message: 'Notice message contains multiple JSON payloads.',
|
|
28
|
+
},
|
|
29
|
+
);
|
|
30
|
+
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
extractJson,
|
|
3
|
-
} from 'crack-json';
|
|
1
|
+
import { extractJson } from 'crack-json';
|
|
4
2
|
|
|
5
3
|
export const getAutoExplainPayload = (noticeMessage: string) => {
|
|
6
4
|
const matches = extractJson(noticeMessage);
|
|
7
5
|
|
|
8
6
|
if (matches.length === 0) {
|
|
9
|
-
throw new Error(
|
|
7
|
+
throw new Error(
|
|
8
|
+
'Notice message does not contain a recognizable JSON payload.',
|
|
9
|
+
);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
if (matches.length > 1) {
|
package/tsconfig.json
CHANGED
|
@@ -2,25 +2,23 @@
|
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"allowSyntheticDefaultImports": true,
|
|
4
4
|
"declaration": true,
|
|
5
|
+
"declarationMap": true,
|
|
5
6
|
"esModuleInterop": true,
|
|
6
|
-
"
|
|
7
|
+
"lib": [
|
|
8
|
+
"es2021"
|
|
9
|
+
],
|
|
7
10
|
"module": "commonjs",
|
|
8
11
|
"moduleResolution": "node",
|
|
9
12
|
"noImplicitAny": false,
|
|
10
13
|
"noImplicitReturns": true,
|
|
11
|
-
"noUnusedLocals": true,
|
|
12
|
-
"noUnusedParameters": false,
|
|
13
14
|
"outDir": "dist",
|
|
14
15
|
"skipLibCheck": true,
|
|
16
|
+
"sourceMap": true,
|
|
15
17
|
"strict": true,
|
|
16
|
-
"target": "
|
|
18
|
+
"target": "es2020",
|
|
19
|
+
"useUnknownInCatchVariables": false
|
|
17
20
|
},
|
|
18
|
-
"exclude": [
|
|
19
|
-
"dist",
|
|
20
|
-
"node_modules"
|
|
21
|
-
],
|
|
22
21
|
"include": [
|
|
23
|
-
"src"
|
|
24
|
-
"test"
|
|
22
|
+
"src"
|
|
25
23
|
]
|
|
26
|
-
}
|
|
24
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2021, Gajus Kuizinas (http://gajus.com/)
|
|
2
|
-
All rights reserved.
|
|
3
|
-
|
|
4
|
-
Redistribution and use in source and binary forms, with or without
|
|
5
|
-
modification, are permitted provided that the following conditions are met:
|
|
6
|
-
* Redistributions of source code must retain the above copyright
|
|
7
|
-
notice, this list of conditions and the following disclaimer.
|
|
8
|
-
* Redistributions in binary form must reproduce the above copyright
|
|
9
|
-
notice, this list of conditions and the following disclaimer in the
|
|
10
|
-
documentation and/or other materials provided with the distribution.
|
|
11
|
-
* Neither the name of the Gajus Kuizinas (http://gajus.com/) nor the
|
|
12
|
-
names of its contributors may be used to endorse or promote products
|
|
13
|
-
derived from this software without specific prior written permission.
|
|
14
|
-
|
|
15
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
16
|
-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
17
|
-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
18
|
-
DISCLAIMED. IN NO EVENT SHALL GAJUS KUIZINAS BE LIABLE FOR ANY
|
|
19
|
-
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
20
|
-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
21
|
-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
22
|
-
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
23
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
24
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createQueryLoggingInterceptor, } from './createQueryLoggingInterceptor';
|
package/dist/src/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createQueryLoggingInterceptor, } from './factories';
|
package/dist/src/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// @flow
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.createQueryLoggingInterceptor = void 0;
|
|
5
|
-
var factories_1 = require("./factories");
|
|
6
|
-
Object.defineProperty(exports, "createQueryLoggingInterceptor", { enumerable: true, get: function () { return factories_1.createQueryLoggingInterceptor; } });
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isAutoExplainJsonMessage = exports.getAutoExplainPayload = void 0;
|
|
4
|
-
var getAutoExplainPayload_1 = require("./getAutoExplainPayload");
|
|
5
|
-
Object.defineProperty(exports, "getAutoExplainPayload", { enumerable: true, get: function () { return getAutoExplainPayload_1.getAutoExplainPayload; } });
|
|
6
|
-
var isAutoExplainJsonMessage_1 = require("./isAutoExplainJsonMessage");
|
|
7
|
-
Object.defineProperty(exports, "isAutoExplainJsonMessage", { enumerable: true, get: function () { return isAutoExplainJsonMessage_1.isAutoExplainJsonMessage; } });
|
package/src/factories/index.ts
DELETED