slonik-interceptor-query-cache 47.3.2 → 48.0.0
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 +6 -0
- package/dist/Logger.js +2 -5
- package/dist/Logger.js.map +1 -1
- package/dist/factories/createQueryCacheInterceptor.d.ts +1 -1
- package/dist/factories/createQueryCacheInterceptor.d.ts.map +1 -1
- package/dist/factories/createQueryCacheInterceptor.js +7 -11
- package/dist/factories/createQueryCacheInterceptor.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -5
- package/dist/index.js.map +1 -1
- package/dist/utilities/extractCacheAttributes.d.ts +1 -1
- package/dist/utilities/extractCacheAttributes.d.ts.map +1 -1
- package/dist/utilities/extractCacheAttributes.js +3 -7
- package/dist/utilities/extractCacheAttributes.js.map +1 -1
- package/dist/utilities/extractCacheAttributes.test.js +17 -22
- package/dist/utilities/extractCacheAttributes.test.js.map +1 -1
- package/dist/utilities/normalizeCacheAttributes.d.ts +2 -2
- package/dist/utilities/normalizeCacheAttributes.d.ts.map +1 -1
- package/dist/utilities/normalizeCacheAttributes.js +1 -5
- package/dist/utilities/normalizeCacheAttributes.js.map +1 -1
- package/dist/utilities/normalizeCacheAttributes.test.js +4 -9
- package/dist/utilities/normalizeCacheAttributes.test.js.map +1 -1
- package/eslint.config.js +4 -0
- package/package.json +11 -9
- package/src/factories/createQueryCacheInterceptor.ts +4 -9
- package/src/index.ts +1 -1
- package/src/utilities/extractCacheAttributes.test.ts +1 -1
- package/src/utilities/extractCacheAttributes.ts +1 -1
- package/src/utilities/normalizeCacheAttributes.test.ts +1 -1
- package/src/utilities/normalizeCacheAttributes.ts +2 -2
- package/tsconfig.json +3 -3
- package/eslint.config.cjs +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# slonik-interceptor-query-cache
|
|
2
2
|
|
|
3
|
+
## 48.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#692](https://github.com/gajus/slonik/pull/692) [`31db3aa`](https://github.com/gajus/slonik/commit/31db3aa0f0f64cd2fadfc854815d2c0e346b75be) Thanks [@gajus](https://github.com/gajus)! - migrate to esm
|
|
8
|
+
|
|
3
9
|
## 47.3.2
|
|
4
10
|
|
|
5
11
|
## 47.3.1
|
package/dist/Logger.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Logger = void 0;
|
|
4
|
-
const roarr_1 = require("roarr");
|
|
5
|
-
exports.Logger = roarr_1.Roarr.child({
|
|
1
|
+
import { Roarr } from 'roarr';
|
|
2
|
+
export const Logger = Roarr.child({
|
|
6
3
|
package: 'slonik-interceptor-query-cache',
|
|
7
4
|
});
|
|
8
5
|
//# sourceMappingURL=Logger.js.map
|
package/dist/Logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../src/Logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../src/Logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAE9B,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC;IAChC,OAAO,EAAE,gCAAgC;CAC1C,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createQueryCacheInterceptor.d.ts","sourceRoot":"","sources":["../../src/factories/createQueryCacheInterceptor.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"createQueryCacheInterceptor.d.ts","sourceRoot":"","sources":["../../src/factories/createQueryCacheInterceptor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAM9E,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,EAAE,OAAO,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAMF,KAAK,kBAAkB,GAAG;IACxB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAQF,KAAK,OAAO,GAAG;IACb,GAAG,EAAE,CACH,KAAK,EAAE,KAAK,EACZ,eAAe,EAAE,eAAe,KAC7B,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC;IACjD,GAAG,EAAE,CACH,KAAK,EAAE,KAAK,EACZ,eAAe,EAAE,eAAe,EAChC,WAAW,EAAE,WAAW,CAAC,cAAc,CAAC,KACrC,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,2BAA2B,GACtC,oBAAoB,kBAAkB,KACrC,WAkFF,CAAC"}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const extractCacheAttributes_1 = require("../utilities/extractCacheAttributes");
|
|
6
|
-
const normalizeCacheAttributes_1 = require("../utilities/normalizeCacheAttributes");
|
|
7
|
-
const log = Logger_1.Logger.child({
|
|
1
|
+
import { Logger } from '../Logger.js';
|
|
2
|
+
import { extractCacheAttributes } from '../utilities/extractCacheAttributes.js';
|
|
3
|
+
import { normalizeCacheAttributes } from '../utilities/normalizeCacheAttributes.js';
|
|
4
|
+
const log = Logger.child({
|
|
8
5
|
namespace: 'createQueryCacheInterceptor',
|
|
9
6
|
});
|
|
10
|
-
const createQueryCacheInterceptor = (configurationInput) => {
|
|
7
|
+
export const createQueryCacheInterceptor = (configurationInput) => {
|
|
11
8
|
const configuration = {
|
|
12
9
|
...configurationInput,
|
|
13
10
|
};
|
|
@@ -50,11 +47,11 @@ const createQueryCacheInterceptor = (configurationInput) => {
|
|
|
50
47
|
if (context.transactionId) {
|
|
51
48
|
return null;
|
|
52
49
|
}
|
|
53
|
-
const extractedCacheAttributes =
|
|
50
|
+
const extractedCacheAttributes = extractCacheAttributes(query.sql, query.values);
|
|
54
51
|
if (!extractedCacheAttributes) {
|
|
55
52
|
return null;
|
|
56
53
|
}
|
|
57
|
-
const cacheAttributes =
|
|
54
|
+
const cacheAttributes = normalizeCacheAttributes(extractedCacheAttributes);
|
|
58
55
|
context.sandbox.cache = {
|
|
59
56
|
cacheAttributes,
|
|
60
57
|
};
|
|
@@ -63,5 +60,4 @@ const createQueryCacheInterceptor = (configurationInput) => {
|
|
|
63
60
|
name: 'slonik-interceptor-query-cache',
|
|
64
61
|
};
|
|
65
62
|
};
|
|
66
|
-
exports.createQueryCacheInterceptor = createQueryCacheInterceptor;
|
|
67
63
|
//# sourceMappingURL=createQueryCacheInterceptor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createQueryCacheInterceptor.js","sourceRoot":"","sources":["../../src/factories/createQueryCacheInterceptor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createQueryCacheInterceptor.js","sourceRoot":"","sources":["../../src/factories/createQueryCacheInterceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAChF,OAAO,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AAGpF,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC;IACvB,SAAS,EAAE,6BAA6B;CACzC,CAAC,CAAC;AAkCH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,kBAAsC,EACzB,EAAE;IACf,MAAM,aAAa,GAAkB;QACnC,GAAG,kBAAkB;KACtB,CAAC;IAEF,OAAO;QACL,oBAAoB,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;YAC7C,IAAI,OAAO,CAAC,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B,GAAG,sBAAsB,CACrD,KAAK,CAAC,GAAG,EACT,KAAK,CAAC,MAAM,CACb,CAAC;YAEF,IAAI,CAAC,wBAAwB,EAAE,CAAC;gBAC9B,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,eAAe,GAAG,wBAAwB,CAC9C,wBAAwB,CACzB,CAAC;YAEF,OAAO,CAAC,OAAO,CAAC,KAAK,GAAG;gBACtB,eAAe;aAChB,CAAC;YAEF,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,EAAE,gCAAgC;KACvC,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createQueryCacheInterceptor } from './factories/createQueryCacheInterceptor';
|
|
1
|
+
export { createQueryCacheInterceptor } from './factories/createQueryCacheInterceptor.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,4CAA4C,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createQueryCacheInterceptor = void 0;
|
|
4
|
-
var createQueryCacheInterceptor_1 = require("./factories/createQueryCacheInterceptor");
|
|
5
|
-
Object.defineProperty(exports, "createQueryCacheInterceptor", { enumerable: true, get: function () { return createQueryCacheInterceptor_1.createQueryCacheInterceptor; } });
|
|
1
|
+
export { createQueryCacheInterceptor } from './factories/createQueryCacheInterceptor.js';
|
|
6
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,4CAA4C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractCacheAttributes.d.ts","sourceRoot":"","sources":["../../src/utilities/extractCacheAttributes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"extractCacheAttributes.d.ts","sourceRoot":"","sources":["../../src/utilities/extractCacheAttributes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAMvD,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,OAAO,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAQF,eAAO,MAAM,sBAAsB,GACjC,SAAS,MAAM,EACf,QAAQ,SAAS,wBAAwB,EAAE,KAC1C,wBAAwB,GAAG,IAuB7B,CAAC"}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractCacheAttributes = void 0;
|
|
4
|
-
const node_crypto_1 = require("node:crypto");
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
5
2
|
const hash = (subject) => {
|
|
6
|
-
return
|
|
3
|
+
return createHash('sha256').update(subject).digest('hex').slice(0, 24);
|
|
7
4
|
};
|
|
8
5
|
const TtlRegex = /-- @cache-ttl (\d+)/u;
|
|
9
6
|
const DiscardEmptyRegex = /-- @cache-discard-empty (true|false)/u;
|
|
10
7
|
const KeyRegex = /-- @cache-key ([$\w\-:/]+)/iu;
|
|
11
8
|
const CommentRegex = /^\s*--.*$/gmu;
|
|
12
9
|
// TODO throw an error if an unknown attribute is used
|
|
13
|
-
const extractCacheAttributes = (subject, values) => {
|
|
10
|
+
export const extractCacheAttributes = (subject, values) => {
|
|
14
11
|
const ttl = subject.match(TtlRegex)?.[1];
|
|
15
12
|
if (!ttl) {
|
|
16
13
|
return null;
|
|
@@ -28,5 +25,4 @@ const extractCacheAttributes = (subject, values) => {
|
|
|
28
25
|
valueHash,
|
|
29
26
|
};
|
|
30
27
|
};
|
|
31
|
-
exports.extractCacheAttributes = extractCacheAttributes;
|
|
32
28
|
//# sourceMappingURL=extractCacheAttributes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractCacheAttributes.js","sourceRoot":"","sources":["../../src/utilities/extractCacheAttributes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extractCacheAttributes.js","sourceRoot":"","sources":["../../src/utilities/extractCacheAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,MAAM,IAAI,GAAG,CAAC,OAAe,EAAE,EAAE;IAC/B,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACzE,CAAC,CAAC;AAUF,MAAM,QAAQ,GAAG,sBAAsB,CAAC;AACxC,MAAM,iBAAiB,GAAG,uCAAuC,CAAC;AAClE,MAAM,QAAQ,GAAG,8BAA8B,CAAC;AAChD,MAAM,YAAY,GAAG,cAAc,CAAC;AAEpC,sDAAsD;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,OAAe,EACf,MAA2C,EACV,EAAE;IACnC,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEzC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,IAAI,CAAC;IACd,CAAC;IAED,0DAA0D;IAC1D,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,CAAC;IAE5D,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC;IAEtE,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAE/C,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,4BAA4B,CAAC;IAEzE,OAAO;QACL,QAAQ;QACR,YAAY;QACZ,GAAG;QACH,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC;QAChB,SAAS;KACV,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const extractCacheAttributes_1 = require("./extractCacheAttributes");
|
|
7
|
-
const ava_1 = __importDefault(require("ava"));
|
|
8
|
-
(0, ava_1.default)('returns null when query does not contain cache attributes', (t) => {
|
|
9
|
-
t.is((0, extractCacheAttributes_1.extractCacheAttributes)('', []), null);
|
|
1
|
+
import { extractCacheAttributes } from './extractCacheAttributes.js';
|
|
2
|
+
import test from 'ava';
|
|
3
|
+
test('returns null when query does not contain cache attributes', (t) => {
|
|
4
|
+
t.is(extractCacheAttributes('', []), null);
|
|
10
5
|
});
|
|
11
|
-
(
|
|
12
|
-
t.deepEqual(
|
|
6
|
+
test('extracts @cache-ttl', (t) => {
|
|
7
|
+
t.deepEqual(extractCacheAttributes('-- @cache-ttl 60', []), {
|
|
13
8
|
bodyHash: 'e3b0c44298fc1c149afbf4c8',
|
|
14
9
|
discardEmpty: false,
|
|
15
10
|
key: 'query:$bodyHash:$valueHash',
|
|
@@ -17,15 +12,15 @@ const ava_1 = __importDefault(require("ava"));
|
|
|
17
12
|
valueHash: '4f53cda18c2baa0c0354bb5f',
|
|
18
13
|
});
|
|
19
14
|
});
|
|
20
|
-
(
|
|
21
|
-
t.deepEqual(
|
|
15
|
+
test('extracts @cache-discard-empty', (t) => {
|
|
16
|
+
t.deepEqual(extractCacheAttributes('-- @cache-ttl 60\n-- @cache-discard-empty false', []), {
|
|
22
17
|
bodyHash: '01ba4719c80b6fe911b091a7',
|
|
23
18
|
discardEmpty: false,
|
|
24
19
|
key: 'query:$bodyHash:$valueHash',
|
|
25
20
|
ttl: 60,
|
|
26
21
|
valueHash: '4f53cda18c2baa0c0354bb5f',
|
|
27
22
|
});
|
|
28
|
-
t.deepEqual(
|
|
23
|
+
t.deepEqual(extractCacheAttributes('-- @cache-ttl 60\n-- @cache-discard-empty true', []), {
|
|
29
24
|
bodyHash: '01ba4719c80b6fe911b091a7',
|
|
30
25
|
discardEmpty: true,
|
|
31
26
|
key: 'query:$bodyHash:$valueHash',
|
|
@@ -33,8 +28,8 @@ const ava_1 = __importDefault(require("ava"));
|
|
|
33
28
|
valueHash: '4f53cda18c2baa0c0354bb5f',
|
|
34
29
|
});
|
|
35
30
|
});
|
|
36
|
-
(
|
|
37
|
-
t.deepEqual(
|
|
31
|
+
test('computes the parameter value hash', (t) => {
|
|
32
|
+
t.deepEqual(extractCacheAttributes('-- @cache-ttl 60', [1]), {
|
|
38
33
|
bodyHash: 'e3b0c44298fc1c149afbf4c8',
|
|
39
34
|
discardEmpty: false,
|
|
40
35
|
key: 'query:$bodyHash:$valueHash',
|
|
@@ -42,15 +37,15 @@ const ava_1 = __importDefault(require("ava"));
|
|
|
42
37
|
valueHash: '080a9ed428559ef602668b4c',
|
|
43
38
|
});
|
|
44
39
|
});
|
|
45
|
-
(
|
|
46
|
-
t.deepEqual(
|
|
40
|
+
test('computes the body hash; white spaces do not affect the body hash', (t) => {
|
|
41
|
+
t.deepEqual(extractCacheAttributes('-- @cache-ttl 60\nSELECT 1', []), {
|
|
47
42
|
bodyHash: 'f815101480e0c02658d3bac8',
|
|
48
43
|
discardEmpty: false,
|
|
49
44
|
key: 'query:$bodyHash:$valueHash',
|
|
50
45
|
ttl: 60,
|
|
51
46
|
valueHash: '4f53cda18c2baa0c0354bb5f',
|
|
52
47
|
});
|
|
53
|
-
t.deepEqual(
|
|
48
|
+
t.deepEqual(extractCacheAttributes('-- @cache-ttl 60\n\nSELECT 1', []), {
|
|
54
49
|
bodyHash: 'db4396c23e75fa095eddf372',
|
|
55
50
|
discardEmpty: false,
|
|
56
51
|
key: 'query:$bodyHash:$valueHash',
|
|
@@ -58,15 +53,15 @@ const ava_1 = __importDefault(require("ava"));
|
|
|
58
53
|
valueHash: '4f53cda18c2baa0c0354bb5f',
|
|
59
54
|
});
|
|
60
55
|
});
|
|
61
|
-
(
|
|
62
|
-
t.deepEqual(
|
|
56
|
+
test('computes the body hash; comments do not affect the body hash', (t) => {
|
|
57
|
+
t.deepEqual(extractCacheAttributes('-- @cache-ttl 60\nSELECT 1', []), {
|
|
63
58
|
bodyHash: 'f815101480e0c02658d3bac8',
|
|
64
59
|
discardEmpty: false,
|
|
65
60
|
key: 'query:$bodyHash:$valueHash',
|
|
66
61
|
ttl: 60,
|
|
67
62
|
valueHash: '4f53cda18c2baa0c0354bb5f',
|
|
68
63
|
});
|
|
69
|
-
t.deepEqual(
|
|
64
|
+
t.deepEqual(extractCacheAttributes('-- @cache-ttl 120\nSELECT 1', []), {
|
|
70
65
|
bodyHash: 'f815101480e0c02658d3bac8',
|
|
71
66
|
discardEmpty: false,
|
|
72
67
|
key: 'query:$bodyHash:$valueHash',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractCacheAttributes.test.js","sourceRoot":"","sources":["../../src/utilities/extractCacheAttributes.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extractCacheAttributes.test.js","sourceRoot":"","sources":["../../src/utilities/extractCacheAttributes.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,IAAI,MAAM,KAAK,CAAC;AAEvB,IAAI,CAAC,2DAA2D,EAAE,CAAC,CAAC,EAAE,EAAE;IACtE,CAAC,CAAC,EAAE,CAAC,sBAAsB,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;AAC7C,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,qBAAqB,EAAE,CAAC,CAAC,EAAE,EAAE;IAChC,CAAC,CAAC,SAAS,CAAC,sBAAsB,CAAC,kBAAkB,EAAE,EAAE,CAAC,EAAE;QAC1D,QAAQ,EAAE,0BAA0B;QACpC,YAAY,EAAE,KAAK;QACnB,GAAG,EAAE,4BAA4B;QACjC,GAAG,EAAE,EAAE;QACP,SAAS,EAAE,0BAA0B;KACtC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,+BAA+B,EAAE,CAAC,CAAC,EAAE,EAAE;IAC1C,CAAC,CAAC,SAAS,CACT,sBAAsB,CACpB,iDAAiD,EACjD,EAAE,CACH,EACD;QACE,QAAQ,EAAE,0BAA0B;QACpC,YAAY,EAAE,KAAK;QACnB,GAAG,EAAE,4BAA4B;QACjC,GAAG,EAAE,EAAE;QACP,SAAS,EAAE,0BAA0B;KACtC,CACF,CAAC;IAEF,CAAC,CAAC,SAAS,CACT,sBAAsB,CACpB,gDAAgD,EAChD,EAAE,CACH,EACD;QACE,QAAQ,EAAE,0BAA0B;QACpC,YAAY,EAAE,IAAI;QAClB,GAAG,EAAE,4BAA4B;QACjC,GAAG,EAAE,EAAE;QACP,SAAS,EAAE,0BAA0B;KACtC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,mCAAmC,EAAE,CAAC,CA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4B;QACjC,GAAG,EAAE,GAAG;QACR,SAAS,EAAE,0BAA0B;KACtC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { CacheAttributes } from '../factories/createQueryCacheInterceptor.js';
|
|
2
|
+
import type { ExtractedCacheAttributes } from './extractCacheAttributes.js';
|
|
3
3
|
export declare const normalizeCacheAttributes: (extractedCacheAttributes: ExtractedCacheAttributes) => CacheAttributes;
|
|
4
4
|
//# sourceMappingURL=normalizeCacheAttributes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeCacheAttributes.d.ts","sourceRoot":"","sources":["../../src/utilities/normalizeCacheAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"normalizeCacheAttributes.d.ts","sourceRoot":"","sources":["../../src/utilities/normalizeCacheAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AACnF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAE5E,eAAO,MAAM,wBAAwB,GACnC,0BAA0B,wBAAwB,KACjD,eAQF,CAAC"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeCacheAttributes = void 0;
|
|
4
|
-
const normalizeCacheAttributes = (extractedCacheAttributes) => {
|
|
1
|
+
export const normalizeCacheAttributes = (extractedCacheAttributes) => {
|
|
5
2
|
return {
|
|
6
3
|
discardEmpty: extractedCacheAttributes.discardEmpty,
|
|
7
4
|
key: extractedCacheAttributes.key
|
|
@@ -10,5 +7,4 @@ const normalizeCacheAttributes = (extractedCacheAttributes) => {
|
|
|
10
7
|
ttl: extractedCacheAttributes.ttl,
|
|
11
8
|
};
|
|
12
9
|
};
|
|
13
|
-
exports.normalizeCacheAttributes = normalizeCacheAttributes;
|
|
14
10
|
//# sourceMappingURL=normalizeCacheAttributes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeCacheAttributes.js","sourceRoot":"","sources":["../../src/utilities/normalizeCacheAttributes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"normalizeCacheAttributes.js","sourceRoot":"","sources":["../../src/utilities/normalizeCacheAttributes.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,wBAAkD,EACjC,EAAE;IACnB,OAAO;QACL,YAAY,EAAE,wBAAwB,CAAC,YAAY;QACnD,GAAG,EAAE,wBAAwB,CAAC,GAAG;aAC9B,UAAU,CAAC,WAAW,EAAE,wBAAwB,CAAC,QAAQ,CAAC;aAC1D,UAAU,CAAC,YAAY,EAAE,wBAAwB,CAAC,SAAS,CAAC;QAC/D,GAAG,EAAE,wBAAwB,CAAC,GAAG;KAClC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const normalizeCacheAttributes_1 = require("./normalizeCacheAttributes");
|
|
7
|
-
const ava_1 = __importDefault(require("ava"));
|
|
8
|
-
(0, ava_1.default)('replaces $bodyHash and $valueHash', (t) => {
|
|
9
|
-
t.deepEqual((0, normalizeCacheAttributes_1.normalizeCacheAttributes)({
|
|
1
|
+
import { normalizeCacheAttributes } from './normalizeCacheAttributes.js';
|
|
2
|
+
import test from 'ava';
|
|
3
|
+
test('replaces $bodyHash and $valueHash', (t) => {
|
|
4
|
+
t.deepEqual(normalizeCacheAttributes({
|
|
10
5
|
bodyHash: 'foo',
|
|
11
6
|
discardEmpty: false,
|
|
12
7
|
key: '$bodyHash:$valueHash',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeCacheAttributes.test.js","sourceRoot":"","sources":["../../src/utilities/normalizeCacheAttributes.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"normalizeCacheAttributes.test.js","sourceRoot":"","sources":["../../src/utilities/normalizeCacheAttributes.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,IAAI,MAAM,KAAK,CAAC;AAEvB,IAAI,CAAC,mCAAmC,EAAE,CAAC,CAAC,EAAE,EAAE;IAC9C,CAAC,CAAC,SAAS,CACT,wBAAwB,CAAC;QACvB,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,KAAK;QACnB,GAAG,EAAE,sBAAsB;QAC3B,GAAG,EAAE,EAAE;QACP,SAAS,EAAE,KAAK;KACjB,CAAC,EACF;QACE,YAAY,EAAE,KAAK;QACnB,GAAG,EAAE,SAAS;QACd,GAAG,EAAE,EAAE;KACR,CACF,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/eslint.config.js
ADDED
package/package.json
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"files": [
|
|
12
12
|
"src/**/*.test.ts"
|
|
13
13
|
],
|
|
14
|
-
"
|
|
15
|
-
"
|
|
14
|
+
"nodeArguments": [
|
|
15
|
+
"--import=tsimp"
|
|
16
16
|
]
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
@@ -21,14 +21,15 @@
|
|
|
21
21
|
"description": "Logs Slonik queries.",
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"ava": "^6.3.0",
|
|
24
|
-
"eslint": "9.
|
|
25
|
-
"slonik": "^
|
|
26
|
-
"
|
|
24
|
+
"eslint": "9.27.0",
|
|
25
|
+
"slonik": "^48.0.0",
|
|
26
|
+
"tsimp": "^2.0.12",
|
|
27
27
|
"typescript": "^5.8.3",
|
|
28
|
-
"
|
|
28
|
+
"typescript-eslint": "^8.32.1",
|
|
29
|
+
"@slonik/eslint-config": "^48.0.0"
|
|
29
30
|
},
|
|
30
31
|
"engines": {
|
|
31
|
-
"node": ">=
|
|
32
|
+
"node": ">=24"
|
|
32
33
|
},
|
|
33
34
|
"keywords": [
|
|
34
35
|
"postgresql",
|
|
@@ -45,8 +46,9 @@
|
|
|
45
46
|
"type": "git",
|
|
46
47
|
"url": "https://github.com/gajus/slonik"
|
|
47
48
|
},
|
|
48
|
-
"
|
|
49
|
-
"
|
|
49
|
+
"type": "module",
|
|
50
|
+
"types": "./dist/index.d.ts",
|
|
51
|
+
"version": "48.0.0",
|
|
50
52
|
"scripts": {
|
|
51
53
|
"build": "rm -fr ./dist && tsc",
|
|
52
54
|
"lint": "eslint ./src && tsc --noEmit",
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { Logger } from '../Logger';
|
|
2
|
-
import { extractCacheAttributes } from '../utilities/extractCacheAttributes';
|
|
3
|
-
import { normalizeCacheAttributes } from '../utilities/normalizeCacheAttributes';
|
|
4
|
-
import {
|
|
5
|
-
type Interceptor,
|
|
6
|
-
type Query,
|
|
7
|
-
type QueryResult,
|
|
8
|
-
type QueryResultRow,
|
|
9
|
-
} from 'slonik';
|
|
1
|
+
import { Logger } from '../Logger.js';
|
|
2
|
+
import { extractCacheAttributes } from '../utilities/extractCacheAttributes.js';
|
|
3
|
+
import { normalizeCacheAttributes } from '../utilities/normalizeCacheAttributes.js';
|
|
4
|
+
import type { Interceptor, Query, QueryResult, QueryResultRow } from 'slonik';
|
|
10
5
|
|
|
11
6
|
const log = Logger.child({
|
|
12
7
|
namespace: 'createQueryCacheInterceptor',
|
package/src/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createQueryCacheInterceptor } from './factories/createQueryCacheInterceptor';
|
|
1
|
+
export { createQueryCacheInterceptor } from './factories/createQueryCacheInterceptor.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import type { PrimitiveValueExpression } from 'slonik';
|
|
3
3
|
|
|
4
4
|
const hash = (subject: string) => {
|
|
5
5
|
return createHash('sha256').update(subject).digest('hex').slice(0, 24);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { CacheAttributes } from '../factories/createQueryCacheInterceptor.js';
|
|
2
|
+
import type { ExtractedCacheAttributes } from './extractCacheAttributes.js';
|
|
3
3
|
|
|
4
4
|
export const normalizeCacheAttributes = (
|
|
5
5
|
extractedCacheAttributes: ExtractedCacheAttributes,
|
package/tsconfig.json
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
"declarationMap": true,
|
|
6
6
|
"esModuleInterop": true,
|
|
7
7
|
"lib": [
|
|
8
|
-
"
|
|
8
|
+
"es2024"
|
|
9
9
|
],
|
|
10
|
-
"module": "
|
|
10
|
+
"module": "ES2022",
|
|
11
11
|
"moduleResolution": "node",
|
|
12
12
|
"noImplicitAny": false,
|
|
13
13
|
"noImplicitReturns": true,
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"skipLibCheck": true,
|
|
16
16
|
"sourceMap": true,
|
|
17
17
|
"strict": true,
|
|
18
|
-
"target": "
|
|
18
|
+
"target": "es2024",
|
|
19
19
|
"useUnknownInCatchVariables": false
|
|
20
20
|
},
|
|
21
21
|
"include": [
|
package/eslint.config.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = [...require('@slonik/eslint-config')];
|