@tsed/platform-cache 8.0.0-alpha.4 → 8.0.0-alpha.6

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.
Files changed (31) hide show
  1. package/lib/types/interfaces/interfaces.d.ts +1 -1
  2. package/package.json +13 -14
  3. package/lib/cjs/decorators/useCache.js +0 -10
  4. package/lib/cjs/decorators/useCache.js.map +0 -1
  5. package/lib/cjs/index.js +0 -15
  6. package/lib/cjs/index.js.map +0 -1
  7. package/lib/cjs/interceptors/PlatformCacheInterceptor.js +0 -185
  8. package/lib/cjs/interceptors/PlatformCacheInterceptor.js.map +0 -1
  9. package/lib/cjs/interfaces/PlatformCacheOptions.js +0 -3
  10. package/lib/cjs/interfaces/PlatformCacheOptions.js.map +0 -1
  11. package/lib/cjs/interfaces/PlatformCachedObject.js +0 -3
  12. package/lib/cjs/interfaces/PlatformCachedObject.js.map +0 -1
  13. package/lib/cjs/interfaces/interfaces.js +0 -3
  14. package/lib/cjs/interfaces/interfaces.js.map +0 -1
  15. package/lib/cjs/package.json +0 -3
  16. package/lib/cjs/services/PlatformCache.js +0 -166
  17. package/lib/cjs/services/PlatformCache.js.map +0 -1
  18. package/lib/cjs/utils/getPrefix.js +0 -14
  19. package/lib/cjs/utils/getPrefix.js.map +0 -1
  20. package/lib/cjs/utils/isEndpoint.js +0 -10
  21. package/lib/cjs/utils/isEndpoint.js.map +0 -1
  22. package/lib/esm/package.json +0 -3
  23. package/lib/types-esm/decorators/useCache.d.ts +0 -2
  24. package/lib/types-esm/index.d.ts +0 -11
  25. package/lib/types-esm/interceptors/PlatformCacheInterceptor.d.ts +0 -37
  26. package/lib/types-esm/interfaces/PlatformCacheOptions.d.ts +0 -25
  27. package/lib/types-esm/interfaces/PlatformCachedObject.d.ts +0 -7
  28. package/lib/types-esm/interfaces/interfaces.d.ts +0 -30
  29. package/lib/types-esm/services/PlatformCache.d.ts +0 -47
  30. package/lib/types-esm/utils/getPrefix.d.ts +0 -2
  31. package/lib/types-esm/utils/isEndpoint.d.ts +0 -2
@@ -1,6 +1,6 @@
1
1
  import type { BaseContext } from "@tsed/di";
2
2
  import type { Cache, CachingConfig, Store } from "cache-manager";
3
- import type { FactoryStore } from "cache-manager/dist/caching";
3
+ import type { FactoryStore } from "cache-manager/dist/caching.js";
4
4
  import type { CacheManager } from "../services/PlatformCache.js";
5
5
  export type PlatformCacheSettings<Config extends Record<string, any> = any, S extends Store = any> = CachingConfig<Config> & {
6
6
  caches?: Cache[];
package/package.json CHANGED
@@ -1,17 +1,16 @@
1
1
  {
2
2
  "name": "@tsed/platform-cache",
3
3
  "description": "Platform cache module for Ts.ED Framework",
4
- "type": "commonjs",
5
- "version": "8.0.0-alpha.4",
4
+ "type": "module",
5
+ "version": "8.0.0-alpha.6",
6
6
  "source": "./src/index.ts",
7
- "main": "./lib/cjs/index.js",
7
+ "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
9
9
  "typings": "./lib/types/index.d.ts",
10
10
  "exports": {
11
11
  ".": {
12
12
  "types": "./lib/types/index.d.ts",
13
13
  "import": "./lib/esm/index.js",
14
- "require": "./lib/cjs/index.js",
15
14
  "default": "./lib/cjs/index.js"
16
15
  }
17
16
  },
@@ -28,22 +27,22 @@
28
27
  "tslib": "2.6.1"
29
28
  },
30
29
  "devDependencies": {
31
- "@tsed/barrels": "8.0.0-alpha.4",
32
- "@tsed/core": "8.0.0-alpha.4",
33
- "@tsed/di": "8.0.0-alpha.4",
34
- "@tsed/json-mapper": "8.0.0-alpha.4",
35
- "@tsed/schema": "8.0.0-alpha.4",
36
- "@tsed/typescript": "8.0.0-alpha.4",
30
+ "@tsed/barrels": "8.0.0-alpha.6",
31
+ "@tsed/core": "8.0.0-alpha.6",
32
+ "@tsed/di": "8.0.0-alpha.6",
33
+ "@tsed/json-mapper": "8.0.0-alpha.6",
34
+ "@tsed/schema": "8.0.0-alpha.6",
35
+ "@tsed/typescript": "8.0.0-alpha.6",
37
36
  "@types/micromatch": "^4.0.6",
38
37
  "eslint": "^8.57.0",
39
38
  "typescript": "4.9.5",
40
39
  "vitest": "2.0.4"
41
40
  },
42
41
  "peerDependencies": {
43
- "@tsed/core": "8.0.0-alpha.4",
44
- "@tsed/di": "8.0.0-alpha.4",
45
- "@tsed/json-mapper": "8.0.0-alpha.4",
46
- "@tsed/schema": "8.0.0-alpha.4"
42
+ "@tsed/core": "8.0.0-alpha.6",
43
+ "@tsed/di": "8.0.0-alpha.6",
44
+ "@tsed/json-mapper": "8.0.0-alpha.6",
45
+ "@tsed/schema": "8.0.0-alpha.6"
47
46
  },
48
47
  "peerDependenciesMeta": {
49
48
  "@tsed/core": {
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UseCache = void 0;
4
- const di_1 = require("@tsed/di");
5
- const PlatformCacheInterceptor_js_1 = require("../interceptors/PlatformCacheInterceptor.js");
6
- function UseCache(options = {}) {
7
- return (0, di_1.Intercept)(PlatformCacheInterceptor_js_1.PlatformCacheInterceptor, options);
8
- }
9
- exports.UseCache = UseCache;
10
- //# sourceMappingURL=useCache.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useCache.js","sourceRoot":"","sources":["../../../src/decorators/useCache.ts"],"names":[],"mappings":";;;AAAA,iCAAmC;AACnC,6FAAqF;AAGrF,SAAgB,QAAQ,CAAC,UAAgC,EAAE;IACzD,OAAO,IAAA,cAAS,EAAC,sDAAwB,EAAE,OAAO,CAAC,CAAC;AACtD,CAAC;AAFD,4BAEC"}
package/lib/cjs/index.js DELETED
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- /**
5
- * @file Automatically generated by @tsed/barrels.
6
- */
7
- tslib_1.__exportStar(require("./decorators/useCache.js"), exports);
8
- tslib_1.__exportStar(require("./interceptors/PlatformCacheInterceptor.js"), exports);
9
- tslib_1.__exportStar(require("./interfaces/interfaces.js"), exports);
10
- tslib_1.__exportStar(require("./interfaces/PlatformCachedObject.js"), exports);
11
- tslib_1.__exportStar(require("./interfaces/PlatformCacheOptions.js"), exports);
12
- tslib_1.__exportStar(require("./services/PlatformCache.js"), exports);
13
- tslib_1.__exportStar(require("./utils/getPrefix.js"), exports);
14
- tslib_1.__exportStar(require("./utils/isEndpoint.js"), exports);
15
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,mEAAyC;AACzC,qFAA2D;AAC3D,qEAA2C;AAC3C,+EAAqD;AACrD,+EAAqD;AACrD,sEAA4C;AAC5C,+DAAqC;AACrC,gEAAsC"}
@@ -1,185 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PlatformCacheInterceptor = void 0;
4
- const tslib_1 = require("tslib");
5
- const core_1 = require("@tsed/core");
6
- const di_1 = require("@tsed/di");
7
- const json_mapper_1 = require("@tsed/json-mapper");
8
- const logger_1 = require("@tsed/logger");
9
- const http_1 = require("http");
10
- const PlatformCache_js_1 = require("../services/PlatformCache.js");
11
- const getPrefix_js_1 = require("../utils/getPrefix.js");
12
- const isEndpoint_js_1 = require("../utils/isEndpoint.js");
13
- const cleanHeaders = (headers, blacklist) => {
14
- return Object.entries(headers)
15
- .filter(([key]) => !blacklist.includes(key.toLowerCase()))
16
- .reduce((headers, [key, value]) => {
17
- return {
18
- ...headers,
19
- [key]: value
20
- };
21
- }, {});
22
- };
23
- /**
24
- * @platform
25
- */
26
- let PlatformCacheInterceptor = class PlatformCacheInterceptor {
27
- intercept(context, next) {
28
- if (this.cache.disabled()) {
29
- return next();
30
- }
31
- if (!(0, isEndpoint_js_1.isEndpoint)(context.target, context.propertyKey)) {
32
- return this.cacheMethod(context, next);
33
- }
34
- return this.cacheResponse(context, next);
35
- }
36
- async canRefreshInBackground(key, { refreshThreshold, ttl }, next) {
37
- const inQueue = await this.hasKeyInQueue(key);
38
- if (refreshThreshold && !inQueue) {
39
- await this.addKeyToQueue(key);
40
- const currentTTL = await this.cache.ttl(key);
41
- const calculatedTTL = this.cache.calculateTTL(currentTTL, ttl);
42
- if (currentTTL === undefined || currentTTL < calculatedTTL - refreshThreshold) {
43
- await next();
44
- }
45
- await this.deleteKeyFromQueue(key);
46
- }
47
- }
48
- async cacheMethod(context, next) {
49
- const { key, type, ttl, collectionType, refreshThreshold, args, canCache } = this.getOptions(context);
50
- const set = (result) => {
51
- if (!canCache || (canCache && canCache(result))) {
52
- const calculatedTTL = this.cache.calculateTTL(result, ttl);
53
- const data = (0, json_mapper_1.serialize)(result, { type, collectionType });
54
- this.cache.setCachedObject(key, data, { args, ttl: calculatedTTL });
55
- }
56
- };
57
- const cachedObject = await this.cache.getCachedObject(key);
58
- if (!cachedObject || this.cache.isForceRefresh()) {
59
- const result = await next();
60
- if (!(!cachedObject && this.cache.isForceRefresh())) {
61
- set(result);
62
- }
63
- return result;
64
- }
65
- this.canRefreshInBackground(key, { refreshThreshold, ttl }, async () => {
66
- const result = await next();
67
- await set(result);
68
- }).catch((er) => this.logger.error({
69
- event: "CACHE_ERROR",
70
- method: "cacheMethod",
71
- concerned_key: key,
72
- class_name: (0, core_1.nameOf)(context.target),
73
- property_key: context.propertyKey,
74
- error_description: er.message,
75
- stack: er.stack
76
- }));
77
- const { data } = cachedObject;
78
- return (0, json_mapper_1.deserialize)(JSON.parse(data), { collectionType, type });
79
- }
80
- async cacheResponse(context, next) {
81
- const { request, response } = context.args[context.args.length - 1];
82
- if (request.method !== "GET") {
83
- return next();
84
- }
85
- const { key, ttl, args, $ctx } = this.getOptions(context);
86
- const cachedObject = await this.cache.getCachedObject(key);
87
- if (cachedObject && !(request.get("cache-control") === "no-cache")) {
88
- return this.sendResponse(cachedObject, $ctx);
89
- }
90
- const result = await next();
91
- const calculatedTTL = this.cache.calculateTTL(result, ttl);
92
- $ctx.response.setHeaders({
93
- "cache-control": `max-age=${calculatedTTL}`
94
- });
95
- // cache final response with his headers and body
96
- response.onEnd(() => {
97
- this.cache.setCachedObject(key, response.getBody(), {
98
- ttl: calculatedTTL,
99
- args,
100
- headers: cleanHeaders(response.getHeaders(), this.blacklist)
101
- });
102
- });
103
- return result;
104
- }
105
- getArgs(context) {
106
- return context.args.reduce((args, arg) => {
107
- if (arg instanceof di_1.DIContext || arg instanceof http_1.IncomingMessage || arg instanceof http_1.ServerResponse) {
108
- return args;
109
- }
110
- if ((0, core_1.isClass)(arg)) {
111
- return args.concat((0, json_mapper_1.serialize)(arg));
112
- }
113
- return args.concat(arg);
114
- }, []);
115
- }
116
- getOptions(context) {
117
- const $ctx = context.args[context.args.length - 1];
118
- const { ttl, type, collectionType, key: k = this.cache.defaultKeyResolver(), refreshThreshold } = context.options || {};
119
- let { canCache } = context.options || {};
120
- const args = this.getArgs(context);
121
- const keyArgs = (0, core_1.isString)(k) ? k : k(args, $ctx);
122
- if (canCache && canCache === "no-nullish") {
123
- canCache = (item) => ![null, undefined].includes(item);
124
- }
125
- return {
126
- key: [...[this.prefix, ...(0, getPrefix_js_1.getPrefix)(context.target, context.propertyKey)].filter(Boolean), keyArgs].join(":"),
127
- refreshThreshold,
128
- ttl,
129
- type,
130
- args,
131
- collectionType,
132
- keyArgs,
133
- canCache,
134
- $ctx
135
- };
136
- }
137
- async hasKeyInQueue(key) {
138
- return !!(await this.cache.get(`$$queue:${key}`));
139
- }
140
- async addKeyToQueue(key) {
141
- await this.cache.set(`$$queue:${key}`, true, { ttl: 120 });
142
- }
143
- async deleteKeyFromQueue(key) {
144
- await this.cache.del(`$$queue:${key}`);
145
- }
146
- sendResponse(cachedObject, $ctx) {
147
- const { headers, ttl } = cachedObject;
148
- const { request, response } = $ctx;
149
- const requestEtag = request.get("if-none-match");
150
- if (requestEtag && headers.etag === requestEtag) {
151
- response.status(304).setHeaders(headers).body(undefined);
152
- return undefined;
153
- }
154
- const data = JSON.parse(cachedObject.data);
155
- $ctx.response
156
- .setHeaders({
157
- ...headers,
158
- "x-cached": "true",
159
- "cache-control": `max-age=${ttl}`
160
- })
161
- .body(data);
162
- return data;
163
- }
164
- };
165
- tslib_1.__decorate([
166
- (0, di_1.Inject)(),
167
- tslib_1.__metadata("design:type", PlatformCache_js_1.PlatformCache)
168
- ], PlatformCacheInterceptor.prototype, "cache", void 0);
169
- tslib_1.__decorate([
170
- (0, di_1.Inject)(),
171
- tslib_1.__metadata("design:type", logger_1.Logger)
172
- ], PlatformCacheInterceptor.prototype, "logger", void 0);
173
- tslib_1.__decorate([
174
- (0, di_1.Constant)("cache.prefix", ""),
175
- tslib_1.__metadata("design:type", String)
176
- ], PlatformCacheInterceptor.prototype, "prefix", void 0);
177
- tslib_1.__decorate([
178
- (0, di_1.Constant)("cache.ignoreHeaders", ["content-length", "x-request-id", "cache-control", "vary", "content-encoding"]),
179
- tslib_1.__metadata("design:type", Array)
180
- ], PlatformCacheInterceptor.prototype, "blacklist", void 0);
181
- PlatformCacheInterceptor = tslib_1.__decorate([
182
- (0, di_1.Interceptor)()
183
- ], PlatformCacheInterceptor);
184
- exports.PlatformCacheInterceptor = PlatformCacheInterceptor;
185
- //# sourceMappingURL=PlatformCacheInterceptor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformCacheInterceptor.js","sourceRoot":"","sources":["../../../src/interceptors/PlatformCacheInterceptor.ts"],"names":[],"mappings":";;;;AAAA,qCAAqD;AACrD,iCAAwI;AACxI,mDAAyD;AACzD,yCAAoC;AACpC,+BAAqD;AAGrD,mEAA2D;AAC3D,wDAAgD;AAChD,0DAAkD;AAClD,MAAM,YAAY,GAAG,CAAC,OAAgC,EAAE,SAAmB,EAAE,EAAE;IAC7E,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;SAC3B,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;S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1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=PlatformCacheOptions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformCacheOptions.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformCacheOptions.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=PlatformCachedObject.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformCachedObject.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformCachedObject.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=interfaces.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,166 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PlatformCache = void 0;
4
- const tslib_1 = require("tslib");
5
- const core_1 = require("@tsed/core");
6
- const di_1 = require("@tsed/di");
7
- const json_mapper_1 = require("@tsed/json-mapper");
8
- const logger_1 = require("@tsed/logger");
9
- const async_hooks_1 = require("async_hooks");
10
- const getPrefix_js_1 = require("../utils/getPrefix.js");
11
- const defaultKeyResolver = (args) => {
12
- return args.map((arg) => ((0, core_1.isClass)(arg) ? JSON.stringify((0, json_mapper_1.serialize)(arg)) : arg)).join(":");
13
- };
14
- const storage = new async_hooks_1.AsyncLocalStorage();
15
- /**
16
- * @platform
17
- */
18
- let PlatformCache = class PlatformCache {
19
- #cache;
20
- get cache() {
21
- return this.#cache;
22
- }
23
- async $onInit() {
24
- const settings = this.settings.get("cache");
25
- if (settings) {
26
- this.#cache = await this.createCacheManager(settings);
27
- await this.injector.emit("$onCreateCacheManager", this.#cache);
28
- }
29
- }
30
- getKeysOf(target, propertyKey) {
31
- const prefix = (0, getPrefix_js_1.getPrefix)(target, propertyKey);
32
- return this.keys(`${prefix.join(":")}:*`);
33
- }
34
- disabled() {
35
- return !this.settings.get("cache");
36
- }
37
- defaultKeyResolver() {
38
- return this.settings.get("cache.keyResolver", defaultKeyResolver);
39
- }
40
- defaultTtl() {
41
- return this.settings.get("cache.ttl");
42
- }
43
- calculateTTL(result, currentTtl) {
44
- const ttl = currentTtl === undefined ? this.defaultTtl() : currentTtl;
45
- return (0, core_1.isFunction)(ttl) ? ttl(result) : ttl;
46
- }
47
- ttl(key) {
48
- if (this.cache && "store" in this.cache && this.cache.store.ttl) {
49
- return this.cache.store.ttl(key);
50
- }
51
- return Promise.resolve();
52
- }
53
- wrap(key, fetch, ttl) {
54
- if (!this.cache) {
55
- return fetch();
56
- }
57
- return this.cache?.wrap(key, fetch, ttl);
58
- }
59
- get(key, options = {}) {
60
- return Promise.resolve((0, json_mapper_1.deserialize)(this.cache?.get(key), options));
61
- }
62
- async set(key, value, options) {
63
- await this.cache?.set(key, value, options?.ttl);
64
- return;
65
- }
66
- async getCachedObject(key) {
67
- try {
68
- return await this.get(key);
69
- }
70
- catch (er) {
71
- this.logger.error({
72
- event: "CACHE_ERROR",
73
- method: "getCachedObject",
74
- error: er
75
- });
76
- }
77
- }
78
- async setCachedObject(key, data, opts) {
79
- try {
80
- await this.set(key, {
81
- ...opts,
82
- data: JSON.stringify(data)
83
- }, {
84
- ttl: opts.ttl
85
- });
86
- }
87
- catch (er) {
88
- this.logger.error({
89
- event: "CACHE_ERROR",
90
- method: "setCachedObject",
91
- error: er
92
- });
93
- }
94
- }
95
- async del(key) {
96
- await this.cache?.del(key);
97
- }
98
- async reset() {
99
- // @ts-ignore
100
- await this.cache?.reset();
101
- }
102
- keys(...args) {
103
- if (this.cache && "store" in this.cache && this.cache.store.keys) {
104
- return this.cache.store.keys(...args);
105
- }
106
- return Promise.resolve([]);
107
- }
108
- async deleteKeys(patterns) {
109
- const keys = await this.keys(patterns);
110
- await Promise.all(keys.map((key) => this.del(key)));
111
- return keys;
112
- }
113
- /**
114
- * Use micromatch instead native patterns. Use this method if the native store method doesn't support glob patterns
115
- * @param patterns
116
- */
117
- async getMatchingKeys(patterns) {
118
- const [keys, { default: micromatch }] = await Promise.all([this.keys(), import("micromatch")]);
119
- return micromatch(keys, patterns);
120
- }
121
- async deleteMatchingKeys(patterns) {
122
- const keys = await this.getMatchingKeys(patterns);
123
- await Promise.all(keys.map((key) => this.del(key)));
124
- return keys;
125
- }
126
- refresh(callback) {
127
- return storage.run({ forceRefresh: true }, callback);
128
- }
129
- isForceRefresh() {
130
- return !!storage.getStore()?.forceRefresh;
131
- }
132
- async createCacheManager(settings) {
133
- const { caches, store = "memory", ttl, ...props } = settings;
134
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
135
- const { multiCaching, caching } = await import("cache-manager");
136
- return caches?.length
137
- ? multiCaching(caches)
138
- : caching(this.mapStore(store), {
139
- ...props,
140
- ttl
141
- });
142
- }
143
- mapStore(store) {
144
- if (!(0, core_1.isString)(store) && "create" in store) {
145
- return store.create;
146
- }
147
- return store;
148
- }
149
- };
150
- tslib_1.__decorate([
151
- (0, di_1.Configuration)(),
152
- tslib_1.__metadata("design:type", Object)
153
- ], PlatformCache.prototype, "settings", void 0);
154
- tslib_1.__decorate([
155
- (0, di_1.Inject)(),
156
- tslib_1.__metadata("design:type", di_1.InjectorService)
157
- ], PlatformCache.prototype, "injector", void 0);
158
- tslib_1.__decorate([
159
- (0, di_1.Inject)(),
160
- tslib_1.__metadata("design:type", logger_1.Logger)
161
- ], PlatformCache.prototype, "logger", void 0);
162
- PlatformCache = tslib_1.__decorate([
163
- (0, di_1.Module)()
164
- ], PlatformCache);
165
- exports.PlatformCache = PlatformCache;
166
- //# sourceMappingURL=PlatformCache.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformCache.js","sourceRoot":"","sources":["../../../src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AC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,YAAY,CAAC;IAC5C,CAAC;IAES,KAAK,CAAC,kBAAkB,CAAC,QAA+B;QAChE,MAAM,EAAC,MAAM,EAAE,KAAK,GAAG,QAAQ,EAAE,GAAG,EAAE,GAAG,KAAK,EAAC,GAAG,QAAQ,CAAC;QAC3D,6DAA6D;QAC7D,MAAM,EAAC,YAAY,EAAE,OAAO,EAAC,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;QAE9D,OAAO,MAAM,EAAE,MAAM;YACnB,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC;YACtB,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;gBAC5B,GAAG,KAAK;gBACR,GAAG;aACJ,CAAC,CAAC;IACT,CAAC;IAEO,QAAQ,CAAC,KAA+C;QAC9D,IAAI,CAAC,IAAA,eAAQ,EAAC,KAAK,CAAC,IAAI,QAAQ,IAAI,KAAK,EAAE;YACzC,OAAO,KAAK,CAAC,MAAM,CAAC;SACrB;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAA;AAlLC;IAAC,IAAA,kBAAa,GAAE;;+CACkB;AAElC;IAAC,IAAA,WAAM,GAAE;sCACW,oBAAe;+CAAC;AAEpC;IAAC,IAAA,WAAM,GAAE;sCACS,eAAM;6CAAC;AARd,aAAa;IADzB,IAAA,WAAM,GAAE;GACI,aAAa,CAmLzB;AAnLY,sCAAa"}
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPrefix = void 0;
4
- const core_1 = require("@tsed/core");
5
- const di_1 = require("@tsed/di");
6
- function getPrefix(target, propertyKey) {
7
- const { prefix } = (0, di_1.getInterceptorOptions)(target, propertyKey);
8
- if (prefix) {
9
- return [prefix];
10
- }
11
- return [(0, core_1.nameOf)(target), propertyKey];
12
- }
13
- exports.getPrefix = getPrefix;
14
- //# sourceMappingURL=getPrefix.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getPrefix.js","sourceRoot":"","sources":["../../../src/utils/getPrefix.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AACxC,iCAA+C;AAG/C,SAAgB,SAAS,CAAC,MAAiB,EAAE,WAA4B;IACvE,MAAM,EAAC,MAAM,EAAC,GAAG,IAAA,0BAAqB,EAAuB,MAAM,EAAE,WAAW,CAAC,CAAC;IAClF,IAAI,MAAM,EAAE;QACV,OAAO,CAAC,MAAM,CAAC,CAAC;KACjB;IAED,OAAO,CAAC,IAAA,aAAM,EAAC,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC;AACvC,CAAC;AAPD,8BAOC"}
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isEndpoint = void 0;
4
- const core_1 = require("@tsed/core");
5
- const schema_1 = require("@tsed/schema");
6
- function isEndpoint(target, propertyKey) {
7
- return core_1.Store.fromMethod(target, propertyKey).has(schema_1.JsonEntityStore);
8
- }
9
- exports.isEndpoint = isEndpoint;
10
- //# sourceMappingURL=isEndpoint.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isEndpoint.js","sourceRoot":"","sources":["../../../src/utils/isEndpoint.ts"],"names":[],"mappings":";;;AAAA,qCAAuC;AACvC,yCAA6C;AAE7C,SAAgB,UAAU,CAAC,MAAiB,EAAE,WAA4B;IACxE,OAAO,YAAK,CAAC,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,GAAG,CAAC,wBAAe,CAAC,CAAC;AACpE,CAAC;AAFD,gCAEC"}
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
@@ -1,2 +0,0 @@
1
- import { PlatformCacheOptions } from "../interfaces/PlatformCacheOptions.js";
2
- export declare function UseCache(options?: PlatformCacheOptions): any;
@@ -1,11 +0,0 @@
1
- /**
2
- * @file Automatically generated by @tsed/barrels.
3
- */
4
- export * from "./decorators/useCache.js";
5
- export * from "./interceptors/PlatformCacheInterceptor.js";
6
- export * from "./interfaces/interfaces.js";
7
- export * from "./interfaces/PlatformCachedObject.js";
8
- export * from "./interfaces/PlatformCacheOptions.js";
9
- export * from "./services/PlatformCache.js";
10
- export * from "./utils/getPrefix.js";
11
- export * from "./utils/isEndpoint.js";
@@ -1,37 +0,0 @@
1
- import { BaseContext, InterceptorContext, InterceptorMethods, InterceptorNext } from "@tsed/di";
2
- import { Logger } from "@tsed/logger";
3
- import { PlatformCachedObject } from "../interfaces/PlatformCachedObject.js";
4
- import { PlatformCacheOptions } from "../interfaces/PlatformCacheOptions.js";
5
- import { PlatformCache } from "../services/PlatformCache.js";
6
- /**
7
- * @platform
8
- */
9
- export declare class PlatformCacheInterceptor implements InterceptorMethods {
10
- protected cache: PlatformCache;
11
- protected logger: Logger;
12
- protected prefix: string;
13
- protected blacklist: string[];
14
- intercept(context: InterceptorContext<any, PlatformCacheOptions>, next: InterceptorNext): unknown;
15
- canRefreshInBackground(key: string, { refreshThreshold, ttl }: {
16
- refreshThreshold?: number;
17
- ttl: any;
18
- }, next: Function): Promise<void>;
19
- cacheMethod(context: InterceptorContext<any, PlatformCacheOptions>, next: InterceptorNext): Promise<any>;
20
- cacheResponse(context: InterceptorContext<any, PlatformCacheOptions>, next: InterceptorNext): Promise<any>;
21
- protected getArgs(context: InterceptorContext<unknown, PlatformCacheOptions>): any;
22
- protected getOptions(context: InterceptorContext<any, PlatformCacheOptions>): {
23
- key: string;
24
- refreshThreshold: number | undefined;
25
- ttl: import("../services/PlatformCache.js").Ttl | undefined;
26
- type: any;
27
- args: any;
28
- collectionType: any;
29
- keyArgs: string;
30
- canCache: ((item: any) => boolean) | undefined;
31
- $ctx: any;
32
- };
33
- protected hasKeyInQueue(key: string): Promise<boolean>;
34
- protected addKeyToQueue(key: string): Promise<void>;
35
- protected deleteKeyFromQueue(key: string): Promise<void>;
36
- protected sendResponse(cachedObject: PlatformCachedObject, $ctx: BaseContext): any;
37
- }
@@ -1,25 +0,0 @@
1
- import { MetadataTypes } from "@tsed/core";
2
- import { BaseContext } from "@tsed/di";
3
- import type { Ttl } from "../services/PlatformCache.js";
4
- export interface PlatformCacheOptions extends MetadataTypes {
5
- /**
6
- * key expiration ttl in seconds.
7
- */
8
- ttl?: Ttl;
9
- /**
10
- * By default, the key is generated from the method name and the arguments passed to the method.
11
- */
12
- prefix?: string;
13
- /**
14
- * Algorithm used to generate the key. By default, the key is generated from the method name and the arguments passed to the method.
15
- */
16
- key?: string | ((args: any[], ctx?: BaseContext) => string);
17
- /**
18
- * threshold to refresh the cache.
19
- */
20
- refreshThreshold?: number;
21
- /**
22
- * The function determine if the result must be cached or not.
23
- */
24
- canCache?: ((item: any) => boolean) | "no-nullish";
25
- }
@@ -1,7 +0,0 @@
1
- export interface PlatformCachedObject {
2
- ttl: number;
3
- args: any[];
4
- data: any;
5
- expires: number;
6
- headers: Record<string, number | string | string[]>;
7
- }
@@ -1,30 +0,0 @@
1
- import type { BaseContext } from "@tsed/di";
2
- import type { Cache, CachingConfig, Store } from "cache-manager";
3
- import type { FactoryStore } from "cache-manager/dist/caching";
4
- import type { CacheManager } from "../services/PlatformCache.js";
5
- export type PlatformCacheSettings<Config extends Record<string, any> = any, S extends Store = any> = CachingConfig<Config> & {
6
- caches?: Cache[];
7
- store?: "memory" | Store | FactoryStore<S, Config>;
8
- max?: number;
9
- keyResolver?: (args: any[], ctx: BaseContext) => string;
10
- prefix?: string;
11
- /**
12
- * List of headers to ignore when caching the response. Default: ["content-length", "x-request-id", "cache-control", "vary", "content-encoding"]
13
- */
14
- ignoreHeaders?: string[];
15
- /**
16
- * You may pass in any other arguments these will be passed on to the `create` method of your store,
17
- * otherwise they will be ignored.
18
- */
19
- [key: string]: any;
20
- };
21
- declare global {
22
- namespace TsED {
23
- interface Configuration {
24
- cache?: PlatformCacheSettings | false;
25
- }
26
- }
27
- }
28
- export interface OnCreateCacheManager {
29
- $onCreateCacheManager(cache: CacheManager): void | Promise<void>;
30
- }
@@ -1,47 +0,0 @@
1
- import { Type } from "@tsed/core";
2
- import { Configuration, InjectorService } from "@tsed/di";
3
- import { JsonDeserializerOptions } from "@tsed/json-mapper";
4
- import { Logger } from "@tsed/logger";
5
- import type { Cache, CachingConfig, MultiCache } from "cache-manager";
6
- import { PlatformCacheSettings } from "../interfaces/interfaces.js";
7
- import { PlatformCachedObject } from "../interfaces/PlatformCachedObject.js";
8
- export type CacheManager = Cache | MultiCache;
9
- export type Ttl = number | ((result: any) => number);
10
- /**
11
- * @platform
12
- */
13
- export declare class PlatformCache {
14
- #private;
15
- protected settings: Configuration;
16
- protected injector: InjectorService;
17
- protected logger: Logger;
18
- get cache(): CacheManager | undefined;
19
- $onInit(): Promise<void>;
20
- getKeysOf(target: Type<any>, propertyKey: string | symbol): Promise<string[]>;
21
- disabled(): boolean;
22
- defaultKeyResolver(): (args: any[], ctx?: any) => string;
23
- defaultTtl(): Ttl;
24
- calculateTTL(result?: any, currentTtl?: Ttl): number;
25
- ttl(key: string): Promise<void> | Promise<number>;
26
- wrap<T>(key: string, fetch: () => Promise<T>, ttl?: number): Promise<T>;
27
- get<T>(key: string, options?: JsonDeserializerOptions): Promise<T | undefined>;
28
- set<T>(key: string, value: any, options?: CachingConfig<T>): Promise<T | undefined>;
29
- getCachedObject(key: string): Promise<PlatformCachedObject | undefined>;
30
- setCachedObject(key: string, data: any, opts: {
31
- ttl: number;
32
- } & Record<string, any>): Promise<void>;
33
- del(key: string): Promise<void>;
34
- reset(): Promise<void>;
35
- keys(...args: any[]): Promise<string[]>;
36
- deleteKeys(patterns: string): Promise<string[]>;
37
- /**
38
- * Use micromatch instead native patterns. Use this method if the native store method doesn't support glob patterns
39
- * @param patterns
40
- */
41
- getMatchingKeys(patterns: string): Promise<string[]>;
42
- deleteMatchingKeys(patterns: string): Promise<string[]>;
43
- refresh(callback: () => Promise<any> | any): any;
44
- isForceRefresh(): boolean;
45
- protected createCacheManager(settings: PlatformCacheSettings): Promise<MultiCache | import("cache-manager").MemoryCache>;
46
- private mapStore;
47
- }
@@ -1,2 +0,0 @@
1
- import { Type } from "@tsed/core";
2
- export declare function getPrefix(target: Type<any>, propertyKey: string | symbol): (string | symbol)[];
@@ -1,2 +0,0 @@
1
- import { Type } from "@tsed/core";
2
- export declare function isEndpoint(target: Type<any>, propertyKey: string | symbol): boolean;