@acmekit/caching 2.13.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/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/loaders/hash.d.ts +5 -0
- package/dist/loaders/hash.d.ts.map +1 -0
- package/dist/loaders/hash.js +9 -0
- package/dist/loaders/hash.js.map +1 -0
- package/dist/loaders/providers.d.ts +5 -0
- package/dist/loaders/providers.d.ts.map +1 -0
- package/dist/loaders/providers.js +64 -0
- package/dist/loaders/providers.js.map +1 -0
- package/dist/providers/memory-cache.d.ts +45 -0
- package/dist/providers/memory-cache.d.ts.map +1 -0
- package/dist/providers/memory-cache.js +205 -0
- package/dist/providers/memory-cache.js.map +1 -0
- package/dist/services/cache-module.d.ts +90 -0
- package/dist/services/cache-module.d.ts.map +1 -0
- package/dist/services/cache-module.js +204 -0
- package/dist/services/cache-module.js.map +1 -0
- package/dist/services/cache-provider.d.ts +13 -0
- package/dist/services/cache-provider.d.ts.map +1 -0
- package/dist/services/cache-provider.js +53 -0
- package/dist/services/cache-provider.js.map +1 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +11 -0
- package/dist/services/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/index.d.ts +82 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/parser.d.ts +44 -0
- package/dist/utils/parser.d.ts.map +1 -0
- package/dist/utils/parser.js +161 -0
- package/dist/utils/parser.js.map +1 -0
- package/dist/utils/strategy.d.ts +17 -0
- package/dist/utils/strategy.d.ts.map +1 -0
- package/dist/utils/strategy.js +98 -0
- package/dist/utils/strategy.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ICachingStrategy, ModuleJoinerConfig } from "@acmekit/framework/types";
|
|
2
|
+
import { type GraphQLSchema } from "@acmekit/framework/utils";
|
|
3
|
+
import { type CachingModuleService } from "../services";
|
|
4
|
+
import type { InjectedDependencies } from "../types";
|
|
5
|
+
import { EntityReference } from "./parser";
|
|
6
|
+
export declare class DefaultCacheStrategy implements ICachingStrategy {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(container: InjectedDependencies, cacheModule: CachingModuleService);
|
|
9
|
+
objectHash(input: any): string;
|
|
10
|
+
onApplicationStart(schema: GraphQLSchema, joinerConfigs: ModuleJoinerConfig[]): Promise<void>;
|
|
11
|
+
computeKey(input: object): Promise<string>;
|
|
12
|
+
computeTags(input: object, options?: {
|
|
13
|
+
entities?: EntityReference[];
|
|
14
|
+
operation?: "created" | "updated" | "deleted";
|
|
15
|
+
}): Promise<string[]>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../../src/utils/strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,KAAK,aAAa,EAInB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,WAAW,CAAA;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAElD,OAAO,EAA2B,eAAe,EAAE,MAAM,UAAU,CAAA;AAEnE,qBAAa,oBAAqB,YAAW,gBAAgB;;gBAOzD,SAAS,EAAE,oBAAoB,EAC/B,WAAW,EAAE,oBAAoB;IAOnC,UAAU,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM;IAKxB,kBAAkB,CACtB,MAAM,EAAE,aAAa,EACrB,aAAa,EAAE,kBAAkB,EAAE;IA0D/B,UAAU,CAAC,KAAK,EAAE,MAAM;IAIxB,WAAW,CACf,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,EAAE,eAAe,EAAE,CAAA;QAC5B,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;KAC9C,GACA,OAAO,CAAC,MAAM,EAAE,CAAC;CAyBrB"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
var _DefaultCacheStrategy_cacheInvalidationParser, _DefaultCacheStrategy_cacheModule, _DefaultCacheStrategy_container, _DefaultCacheStrategy_hasher;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.DefaultCacheStrategy = void 0;
|
|
19
|
+
const utils_1 = require("@acmekit/framework/utils");
|
|
20
|
+
const fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-stringify"));
|
|
21
|
+
const parser_1 = require("./parser");
|
|
22
|
+
class DefaultCacheStrategy {
|
|
23
|
+
constructor(container, cacheModule) {
|
|
24
|
+
_DefaultCacheStrategy_cacheInvalidationParser.set(this, void 0);
|
|
25
|
+
_DefaultCacheStrategy_cacheModule.set(this, void 0);
|
|
26
|
+
_DefaultCacheStrategy_container.set(this, void 0);
|
|
27
|
+
_DefaultCacheStrategy_hasher.set(this, void 0);
|
|
28
|
+
__classPrivateFieldSet(this, _DefaultCacheStrategy_cacheModule, cacheModule, "f");
|
|
29
|
+
__classPrivateFieldSet(this, _DefaultCacheStrategy_container, container, "f");
|
|
30
|
+
__classPrivateFieldSet(this, _DefaultCacheStrategy_hasher, container.hasher, "f");
|
|
31
|
+
}
|
|
32
|
+
objectHash(input) {
|
|
33
|
+
const str = (0, fast_json_stable_stringify_1.default)(input);
|
|
34
|
+
return __classPrivateFieldGet(this, _DefaultCacheStrategy_hasher, "f").call(this, str);
|
|
35
|
+
}
|
|
36
|
+
async onApplicationStart(schema, joinerConfigs) {
|
|
37
|
+
__classPrivateFieldSet(this, _DefaultCacheStrategy_cacheInvalidationParser, new parser_1.CacheInvalidationParser(schema, joinerConfigs), "f");
|
|
38
|
+
const eventBus = __classPrivateFieldGet(this, _DefaultCacheStrategy_container, "f")[utils_1.Modules.EVENT_BUS];
|
|
39
|
+
const handleEvent = async (data) => {
|
|
40
|
+
try {
|
|
41
|
+
// We dont have to await anything here and the rest can be done in the background
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
const eventName = data.name;
|
|
46
|
+
const operation = eventName.split(".").pop();
|
|
47
|
+
const entityType = eventName.split(".").slice(-2).shift();
|
|
48
|
+
const eventData = data.data;
|
|
49
|
+
const normalizedEventData = Array.isArray(eventData)
|
|
50
|
+
? eventData
|
|
51
|
+
: [eventData];
|
|
52
|
+
const tags = [];
|
|
53
|
+
for (const item of normalizedEventData) {
|
|
54
|
+
const ids = Array.isArray(item.id) ? item.id : [item.id];
|
|
55
|
+
for (const id of ids) {
|
|
56
|
+
const entityReference = {
|
|
57
|
+
type: (0, utils_1.upperCaseFirst)((0, utils_1.toCamelCase)(entityType)),
|
|
58
|
+
id,
|
|
59
|
+
};
|
|
60
|
+
const tags_ = await this.computeTags(item, {
|
|
61
|
+
entities: [entityReference],
|
|
62
|
+
operation,
|
|
63
|
+
});
|
|
64
|
+
tags.push(...tags_);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
void __classPrivateFieldGet(this, _DefaultCacheStrategy_cacheModule, "f").clear({
|
|
68
|
+
tags,
|
|
69
|
+
options: { autoInvalidate: true },
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
eventBus.subscribe("*", handleEvent);
|
|
74
|
+
eventBus.addInterceptor?.(handleEvent);
|
|
75
|
+
}
|
|
76
|
+
async computeKey(input) {
|
|
77
|
+
return this.objectHash(input);
|
|
78
|
+
}
|
|
79
|
+
async computeTags(input, options) {
|
|
80
|
+
// Parse the input object to identify entities
|
|
81
|
+
const entities_ = options?.entities ||
|
|
82
|
+
__classPrivateFieldGet(this, _DefaultCacheStrategy_cacheInvalidationParser, "f").parseObjectForEntities(input);
|
|
83
|
+
if (entities_.length === 0) {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
// Build invalidation events to get comprehensive cache keys
|
|
87
|
+
const events = __classPrivateFieldGet(this, _DefaultCacheStrategy_cacheInvalidationParser, "f").buildInvalidationEvents(entities_, options?.operation);
|
|
88
|
+
// Collect all unique cache keys from all events as tags
|
|
89
|
+
const tags = new Set();
|
|
90
|
+
events.forEach((event) => {
|
|
91
|
+
event.cacheKeys.forEach((key) => tags.add(key));
|
|
92
|
+
});
|
|
93
|
+
return Array.from(tags);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.DefaultCacheStrategy = DefaultCacheStrategy;
|
|
97
|
+
_DefaultCacheStrategy_cacheInvalidationParser = new WeakMap(), _DefaultCacheStrategy_cacheModule = new WeakMap(), _DefaultCacheStrategy_container = new WeakMap(), _DefaultCacheStrategy_hasher = new WeakMap();
|
|
98
|
+
//# sourceMappingURL=strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../src/utils/strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,oDAKiC;AAGjC,4FAAkD;AAClD,qCAAmE;AAEnE,MAAa,oBAAoB;IAM/B,YACE,SAA+B,EAC/B,WAAiC;QAPnC,gEAAiD;QACjD,oDAAmC;QACnC,kDAAgC;QAChC,+CAAiC;QAM/B,uBAAA,IAAI,qCAAgB,WAAW,MAAA,CAAA;QAC/B,uBAAA,IAAI,mCAAc,SAAS,MAAA,CAAA;QAC3B,uBAAA,IAAI,gCAAW,SAAS,CAAC,MAAM,MAAA,CAAA;IACjC,CAAC;IAED,UAAU,CAAC,KAAU;QACnB,MAAM,GAAG,GAAG,IAAA,oCAAS,EAAC,KAAK,CAAC,CAAA;QAC5B,OAAO,uBAAA,IAAI,oCAAQ,MAAZ,IAAI,EAAS,GAAG,CAAC,CAAA;IAC1B,CAAC;IAED,KAAK,CAAC,kBAAkB,CACtB,MAAqB,EACrB,aAAmC;QAEnC,uBAAA,IAAI,iDAA4B,IAAI,gCAAuB,CACzD,MAAM,EACN,aAAa,CACd,MAAA,CAAA;QAED,MAAM,QAAQ,GAAG,uBAAA,IAAI,uCAAW,CAAC,eAAO,CAAC,SAAS,CAAC,CAAA;QAEnD,MAAM,WAAW,GAAG,KAAK,EAAE,IAAW,EAAE,EAAE;YACxC,IAAI,CAAC;gBACH,iFAAiF;gBACjF,OAAM;YACR,CAAC;oBAAS,CAAC;gBACT,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAA;gBAC3B,MAAM,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAG7B,CAA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IACxC,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,KAAa;QAC5B,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;IAED,KAAK,CAAC,WAAW,CACf,KAAa,EACb,OAGC;QAED,8CAA8C;QAC9C,MAAM,SAAS,GACb,OAAO,EAAE,QAAQ;YACjB,uBAAA,IAAI,qDAAyB,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAA;QAE7D,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,EAAE,CAAA;QACX,CAAC;QAED,4DAA4D;QAC5D,MAAM,MAAM,GAAG,uBAAA,IAAI,qDAAyB,CAAC,uBAAuB,CAClE,SAAS,EACT,OAAO,EAAE,SAAS,CACnB,CAAA;QAED,wDAAwD;QACxD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;QAE9B,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YACvB,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;QACjD,CAAC,CAAC,CAAA;QAEF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;CACF;AAnHD,oDAmHC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@acmekit/caching",
|
|
3
|
+
"version": "2.13.1",
|
|
4
|
+
"description": "Caching Module for AcmeKit",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/acmekit/acmekit",
|
|
9
|
+
"directory": "packages/modules/caching"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"!dist/**/__tests__",
|
|
14
|
+
"!dist/**/__mocks__",
|
|
15
|
+
"!dist/**/__fixtures__"
|
|
16
|
+
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"author": "AcmeKit",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"watch": "yarn run -T tsc --build --watch",
|
|
24
|
+
"watch:test": "yarn run -T tsc --build tsconfig.spec.json --watch",
|
|
25
|
+
"resolve:aliases": "yarn run -T tsc --showConfig -p tsconfig.json > tsconfig.resolved.json && yarn run -T tsc-alias -p tsconfig.resolved.json && yarn run -T rimraf tsconfig.resolved.json",
|
|
26
|
+
"build": "yarn run -T rimraf dist && yarn run -T tsc --build && npm run resolve:aliases",
|
|
27
|
+
"test": "../../../node_modules/.bin/jest --passWithNoTests --bail --forceExit --testPathPattern=src",
|
|
28
|
+
"test:integration": "../../../node_modules/.bin/jest --passWithNoTests --forceExit --testPathPattern=\"integration-tests/__tests__/.*\\.ts\""
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@acmekit/framework": "2.13.1",
|
|
32
|
+
"@acmekit/test-utils": "2.13.1",
|
|
33
|
+
"awilix": "^8.0.1"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@acmekit/framework": "2.13.1",
|
|
37
|
+
"awilix": "^8.0.1"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"fast-json-stable-stringify": "^2.1.0",
|
|
41
|
+
"node-cache": "^5.1.2",
|
|
42
|
+
"xxhash-wasm": "^1.1.0"
|
|
43
|
+
}
|
|
44
|
+
}
|