@nestjs-pipeline/cache 0.2.0 → 0.2.1
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/README.md +3 -0
- package/dist/helpers/build-attributes.d.ts +36 -0
- package/dist/helpers/build-attributes.d.ts.map +1 -0
- package/dist/helpers/build-attributes.js +45 -0
- package/dist/helpers/build-attributes.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -468,6 +468,8 @@ The behavior records diagnostics on `context.items`:
|
|
|
468
468
|
|
|
469
469
|
Exported as unique `Symbol` constants (`CACHE_HIT_ITEM` and `CACHE_KEY_ITEM`) to prevent key collisions in `context.items`. `CACHE_HIT_ITEM_TOKEN` and `CACHE_KEY_ITEM_TOKEN` are typed tokens over the same keys for `getPipelineItem` / `requirePipelineItem` from `@nestjs-pipeline/core`.
|
|
470
470
|
|
|
471
|
+
`buildCacheAttributes(context)` turns the hit flag into the attribute `cache.hit`. Use it for span attributes through `AttributesBehavior` of [`@nestjs-pipeline/opentelemetry`](https://github.com/aristoteliss/nestjs-pipeline/tree/master/packages/pipeline-opentelemetry#attributes-from-other-behaviors), for audit `metadata`, or on a log line; it needs no telemetry package. It returns `{}` when the behavior did not run, never a fabricated miss, and never includes the key.
|
|
472
|
+
|
|
471
473
|
|
|
472
474
|
---
|
|
473
475
|
|
|
@@ -545,6 +547,7 @@ import {
|
|
|
545
547
|
CACHE_KEY_ITEM_TOKEN,
|
|
546
548
|
CacheManagerAdapter,
|
|
547
549
|
buildCache,
|
|
550
|
+
buildCacheAttributes,
|
|
548
551
|
buildKeyv,
|
|
549
552
|
createPartitionedCacheKeyFactory,
|
|
550
553
|
MissingCachePartitionError,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type IPipelineContext } from '@nestjs-pipeline/core';
|
|
2
|
+
/**
|
|
3
|
+
* The cache decision of one execution as flat attributes:
|
|
4
|
+
* `{ 'cache.hit': boolean }` once `CacheBehavior` looked the response up, and
|
|
5
|
+
* `{}` when it did not run, so a request without caching never reports a
|
|
6
|
+
* fabricated miss. The cache key is never included: it carries the tenant and
|
|
7
|
+
* the principal, and is unbounded as a value.
|
|
8
|
+
*
|
|
9
|
+
* The result is plain data and needs no telemetry package: put it on a span, a
|
|
10
|
+
* log line, an audit record or a metric label (bounded values only).
|
|
11
|
+
*
|
|
12
|
+
* @param context - The pipeline execution, read after `CacheBehavior` ran.
|
|
13
|
+
* @returns The attributes; empty when the behavior did not run.
|
|
14
|
+
*
|
|
15
|
+
* @example Span attributes, with `AttributesBehavior` of `@nestjs-pipeline/opentelemetry`
|
|
16
|
+
* ```ts
|
|
17
|
+
* PipelineModule.forRoot({
|
|
18
|
+
* globalBehaviors: {
|
|
19
|
+
* before: [TraceBehavior, [AttributesBehavior, { factories: [buildCacheAttributes] }]],
|
|
20
|
+
* },
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example A log line from a custom behavior, after the chain ran
|
|
25
|
+
* ```ts
|
|
26
|
+
* async handle(context: IPipelineContext, next: NextDelegate) {
|
|
27
|
+
* try {
|
|
28
|
+
* return await next();
|
|
29
|
+
* } finally {
|
|
30
|
+
* this.logger.log({ request: context.requestName, ...buildCacheAttributes(context) });
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function buildCacheAttributes(context: IPipelineContext): Record<string, boolean>;
|
|
36
|
+
//# sourceMappingURL=build-attributes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-attributes.d.ts","sourceRoot":"","sources":["../../src/helpers/build-attributes.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,uBAAuB,CAAC;AAG/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,gBAAgB,GACxB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAIzB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright (C) 2026-present Aristotelis — see repository license. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.buildCacheAttributes = buildCacheAttributes;
|
|
5
|
+
const core_1 = require("@nestjs-pipeline/core");
|
|
6
|
+
const cache_behavior_1 = require("../cache.behavior");
|
|
7
|
+
/**
|
|
8
|
+
* The cache decision of one execution as flat attributes:
|
|
9
|
+
* `{ 'cache.hit': boolean }` once `CacheBehavior` looked the response up, and
|
|
10
|
+
* `{}` when it did not run, so a request without caching never reports a
|
|
11
|
+
* fabricated miss. The cache key is never included: it carries the tenant and
|
|
12
|
+
* the principal, and is unbounded as a value.
|
|
13
|
+
*
|
|
14
|
+
* The result is plain data and needs no telemetry package: put it on a span, a
|
|
15
|
+
* log line, an audit record or a metric label (bounded values only).
|
|
16
|
+
*
|
|
17
|
+
* @param context - The pipeline execution, read after `CacheBehavior` ran.
|
|
18
|
+
* @returns The attributes; empty when the behavior did not run.
|
|
19
|
+
*
|
|
20
|
+
* @example Span attributes, with `AttributesBehavior` of `@nestjs-pipeline/opentelemetry`
|
|
21
|
+
* ```ts
|
|
22
|
+
* PipelineModule.forRoot({
|
|
23
|
+
* globalBehaviors: {
|
|
24
|
+
* before: [TraceBehavior, [AttributesBehavior, { factories: [buildCacheAttributes] }]],
|
|
25
|
+
* },
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example A log line from a custom behavior, after the chain ran
|
|
30
|
+
* ```ts
|
|
31
|
+
* async handle(context: IPipelineContext, next: NextDelegate) {
|
|
32
|
+
* try {
|
|
33
|
+
* return await next();
|
|
34
|
+
* } finally {
|
|
35
|
+
* this.logger.log({ request: context.requestName, ...buildCacheAttributes(context) });
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
function buildCacheAttributes(context) {
|
|
41
|
+
return (0, core_1.hasPipelineItem)(context, cache_behavior_1.CACHE_HIT_ITEM_TOKEN)
|
|
42
|
+
? { 'cache.hit': (0, core_1.getPipelineItem)(context, cache_behavior_1.CACHE_HIT_ITEM_TOKEN) === true }
|
|
43
|
+
: {};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=build-attributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-attributes.js","sourceRoot":"","sources":["../../src/helpers/build-attributes.ts"],"names":[],"mappings":";AAAA,sEAAsE;;AA0CtE,oDAMC;AA9CD,gDAI+B;AAC/B,sDAAyD;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,SAAgB,oBAAoB,CAClC,OAAyB;IAEzB,OAAO,IAAA,sBAAe,EAAC,OAAO,EAAE,qCAAoB,CAAC;QACnD,CAAC,CAAC,EAAE,WAAW,EAAE,IAAA,sBAAe,EAAC,OAAO,EAAE,qCAAoB,CAAC,KAAK,IAAI,EAAE;QAC1E,CAAC,CAAC,EAAE,CAAC;AACT,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { CACHE_HIT_ITEM, CACHE_HIT_ITEM_TOKEN, CACHE_KEY_ITEM, CACHE_KEY_ITEM_TO
|
|
|
3
3
|
export { CacheModule } from './cache.module';
|
|
4
4
|
export { CACHE_DEFAULT_OPTIONS, PIPELINE_CACHE } from './constants/tokens';
|
|
5
5
|
export { type CachePartitionDimension, MissingCachePartitionError, } from './errors/missing-partition.error';
|
|
6
|
+
export { buildCacheAttributes } from './helpers/build-attributes';
|
|
6
7
|
export { type CacheIntentOptions, cache, } from './helpers/cache.intent';
|
|
7
8
|
export { buildCache, buildKeyv } from './helpers/cache-factory';
|
|
8
9
|
export { createPartitionedCacheKeyFactory, type PartitionedCacheKeyOptions, } from './helpers/cache-key';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EACnB,KAAK,cAAc,GACpB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACpB,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EACL,KAAK,uBAAuB,EAC5B,0BAA0B,GAC3B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,GACN,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EACL,gCAAgC,EAChC,KAAK,0BAA0B,GAChC,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,GACf,MAAM,sCAAsC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EACnB,KAAK,cAAc,GACpB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACpB,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EACL,KAAK,uBAAuB,EAC5B,0BAA0B,GAC3B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,GACN,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EACL,gCAAgC,EAChC,KAAK,0BAA0B,GAChC,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,GACf,MAAM,sCAAsC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* Copyright (C) 2026-present Aristotelis — see repository license. */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.createPartitionedCacheKeyFactory = exports.buildKeyv = exports.buildCache = exports.cache = exports.MissingCachePartitionError = exports.PIPELINE_CACHE = exports.CACHE_DEFAULT_OPTIONS = exports.CacheModule = exports.CacheBehavior = exports.CACHE_KEY_ITEM_TOKEN = exports.CACHE_KEY_ITEM = exports.CACHE_HIT_ITEM_TOKEN = exports.CACHE_HIT_ITEM = exports.CacheManagerAdapter = void 0;
|
|
4
|
+
exports.createPartitionedCacheKeyFactory = exports.buildKeyv = exports.buildCache = exports.cache = exports.buildCacheAttributes = exports.MissingCachePartitionError = exports.PIPELINE_CACHE = exports.CACHE_DEFAULT_OPTIONS = exports.CacheModule = exports.CacheBehavior = exports.CACHE_KEY_ITEM_TOKEN = exports.CACHE_KEY_ITEM = exports.CACHE_HIT_ITEM_TOKEN = exports.CACHE_HIT_ITEM = exports.CacheManagerAdapter = void 0;
|
|
5
5
|
var cache_manager_adapter_1 = require("./adapters/cache-manager.adapter");
|
|
6
6
|
Object.defineProperty(exports, "CacheManagerAdapter", { enumerable: true, get: function () { return cache_manager_adapter_1.CacheManagerAdapter; } });
|
|
7
7
|
var cache_behavior_1 = require("./cache.behavior");
|
|
@@ -17,6 +17,8 @@ Object.defineProperty(exports, "CACHE_DEFAULT_OPTIONS", { enumerable: true, get:
|
|
|
17
17
|
Object.defineProperty(exports, "PIPELINE_CACHE", { enumerable: true, get: function () { return tokens_1.PIPELINE_CACHE; } });
|
|
18
18
|
var missing_partition_error_1 = require("./errors/missing-partition.error");
|
|
19
19
|
Object.defineProperty(exports, "MissingCachePartitionError", { enumerable: true, get: function () { return missing_partition_error_1.MissingCachePartitionError; } });
|
|
20
|
+
var build_attributes_1 = require("./helpers/build-attributes");
|
|
21
|
+
Object.defineProperty(exports, "buildCacheAttributes", { enumerable: true, get: function () { return build_attributes_1.buildCacheAttributes; } });
|
|
20
22
|
var cache_intent_1 = require("./helpers/cache.intent");
|
|
21
23
|
Object.defineProperty(exports, "cache", { enumerable: true, get: function () { return cache_intent_1.cache; } });
|
|
22
24
|
var cache_factory_1 = require("./helpers/cache-factory");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,sEAAsE;;;AAEtE,0EAG0C;AAFxC,4HAAA,mBAAmB,OAAA;AAGrB,mDAM0B;AALxB,gHAAA,cAAc,OAAA;AACd,sHAAA,oBAAoB,OAAA;AACpB,gHAAA,cAAc,OAAA;AACd,sHAAA,oBAAoB,OAAA;AACpB,+GAAA,aAAa,OAAA;AAEf,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,6CAA2E;AAAlE,+GAAA,qBAAqB,OAAA;AAAE,wGAAA,cAAc,OAAA;AAC9C,4EAG0C;AADxC,qIAAA,0BAA0B,OAAA;AAE5B,uDAGgC;AAD9B,qGAAA,KAAK,OAAA;AAEP,yDAAgE;AAAvD,2GAAA,UAAU,OAAA;AAAE,0GAAA,SAAS,OAAA;AAC9B,iDAG6B;AAF3B,6HAAA,gCAAgC,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,sEAAsE;;;AAEtE,0EAG0C;AAFxC,4HAAA,mBAAmB,OAAA;AAGrB,mDAM0B;AALxB,gHAAA,cAAc,OAAA;AACd,sHAAA,oBAAoB,OAAA;AACpB,gHAAA,cAAc,OAAA;AACd,sHAAA,oBAAoB,OAAA;AACpB,+GAAA,aAAa,OAAA;AAEf,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,6CAA2E;AAAlE,+GAAA,qBAAqB,OAAA;AAAE,wGAAA,cAAc,OAAA;AAC9C,4EAG0C;AADxC,qIAAA,0BAA0B,OAAA;AAE5B,+DAAkE;AAAzD,wHAAA,oBAAoB,OAAA;AAC7B,uDAGgC;AAD9B,qGAAA,KAAK,OAAA;AAEP,yDAAgE;AAAvD,2GAAA,UAAU,OAAA;AAAE,0GAAA,SAAS,OAAA;AAC9B,iDAG6B;AAF3B,6HAAA,gCAAgC,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs-pipeline/cache",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Caching behavior for the NestJS pipeline — cache-manager v7 on top of Keyv with pluggable stores (memory, redis, memcache, sqlite, postgres).",
|
|
5
5
|
"author": "Aristotelis <aristotelis@ik.me>",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|