@tsed/platform-cache 7.0.0-alpha.1 → 7.0.0-beta.3

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 (42) hide show
  1. package/lib/cjs/decorators/useCache.js +11 -0
  2. package/lib/cjs/decorators/useCache.js.map +1 -0
  3. package/lib/cjs/index.js +7 -0
  4. package/lib/cjs/index.js.map +1 -0
  5. package/lib/cjs/interceptors/PlatformCacheInterceptor.js +134 -0
  6. package/lib/cjs/interceptors/PlatformCacheInterceptor.js.map +1 -0
  7. package/lib/cjs/interfaces/PlatformCacheOptions.js +3 -0
  8. package/lib/cjs/interfaces/PlatformCacheOptions.js.map +1 -0
  9. package/lib/cjs/interfaces/PlatformCachedObject.js +3 -0
  10. package/lib/cjs/interfaces/PlatformCachedObject.js.map +1 -0
  11. package/lib/cjs/interfaces/index.js +5 -0
  12. package/lib/cjs/interfaces/index.js.map +1 -0
  13. package/lib/cjs/services/PlatformCache.js +96 -0
  14. package/lib/cjs/services/PlatformCache.js.map +1 -0
  15. package/lib/esm/decorators/useCache.js +7 -0
  16. package/lib/esm/decorators/useCache.js.map +1 -0
  17. package/lib/esm/index.js +4 -0
  18. package/lib/esm/index.js.map +1 -0
  19. package/lib/esm/interceptors/PlatformCacheInterceptor.js +131 -0
  20. package/lib/esm/interceptors/PlatformCacheInterceptor.js.map +1 -0
  21. package/lib/esm/interfaces/PlatformCacheOptions.js +2 -0
  22. package/lib/esm/interfaces/PlatformCacheOptions.js.map +1 -0
  23. package/lib/esm/interfaces/PlatformCachedObject.js +2 -0
  24. package/lib/esm/interfaces/PlatformCachedObject.js.map +1 -0
  25. package/lib/esm/interfaces/index.js +2 -0
  26. package/lib/esm/interfaces/index.js.map +1 -0
  27. package/lib/esm/services/PlatformCache.js +93 -0
  28. package/lib/esm/services/PlatformCache.js.map +1 -0
  29. package/lib/{decorators → types/decorators}/useCache.d.ts +0 -0
  30. package/lib/{index.d.ts → types/index.d.ts} +0 -1
  31. package/lib/{interceptors → types/interceptors}/PlatformCacheInterceptor.d.ts +0 -0
  32. package/lib/{interfaces → types/interfaces}/PlatformCacheOptions.d.ts +1 -1
  33. package/lib/{interfaces → types/interfaces}/PlatformCachedObject.d.ts +0 -0
  34. package/lib/{interfaces → types/interfaces}/index.d.ts +2 -2
  35. package/lib/{services → types/services}/PlatformCache.d.ts +5 -3
  36. package/package.json +21 -17
  37. package/tsconfig.compile.esm.json +23 -0
  38. package/lib/PlatformCacheModule.d.ts +0 -5
  39. package/lib/index.js +0 -348
  40. package/lib/index.js.map +0 -1
  41. package/lib/index.modern.js +0 -345
  42. package/lib/index.modern.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformCache.js","sourceRoot":"","sources":["../../../src/services/PlatformCache.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAE,UAAU,EAAC,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAC,aAAa,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAC,WAAW,EAA2B,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAIlF,MAAM,kBAAkB,GAAG,CAAC,IAAW,EAAE,EAAE;IACzC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAQ,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACjG,CAAC,CAAC;AAMF;;GAEG;AAEH,IAAa,aAAa,GAA1B,MAAa,aAAa;IAMxB,QAAQ;QACN,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAwB,OAAO,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,G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CAAC,CAAC;QAE9D,OAAO,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM;YACnB,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC,MAAM,EAAE,EAAC,GAAG,KAAK,EAAC,CAAC;YAC/C,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC;gBACnB,GAAG,KAAK;gBACR,GAAG;gBACH,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK;aACjD,CAAC,CAAC;IACT,CAAC;CACF,CAAA;AA1FC;IADC,aAAa,EAAE;;+CACQ;AAFb,aAAa;IADzB,MAAM,EAAE;GACI,aAAa,CA4FzB;SA5FY,aAAa","sourcesContent":["import {isClass, isFunction} from \"@tsed/core\";\nimport {Configuration, Module} from \"@tsed/di\";\nimport {deserialize, JsonDeserializerOptions, serialize} from \"@tsed/json-mapper\";\nimport type {Cache, CachingConfig, MultiCache, TtlFunction} from \"cache-manager\";\nimport {PlatformCacheSettings} from \"../interfaces\";\n\nconst defaultKeyResolver = (args: any[]) => {\n return args.map((arg: any) => (isClass(arg) ? JSON.stringify(serialize(arg)) : arg)).join(\":\");\n};\n\nexport type CacheManager = (Cache | MultiCache) & {\n keys?(): Promise<string[]>;\n};\n\n/**\n * @platform\n */\n@Module()\nexport class PlatformCache {\n @Configuration()\n settings: Configuration;\n\n cache: CacheManager | undefined;\n\n disabled(): boolean {\n return !this.settings.get<PlatformCacheSettings>(\"cache\");\n }\n\n async $onInit() {\n const settings = this.settings.get<PlatformCacheSettings>(\"cache\");\n\n if (settings) {\n this.cache = await this.createCacheManager(settings);\n }\n }\n\n defaultKeyResolver() {\n return this.settings.get<(args: any[], ctx?: any) => string>(\"cache.keyResolver\", defaultKeyResolver);\n }\n\n defaultTtl() {\n return this.settings.get<number | TtlFunction>(\"cache.ttl\");\n }\n\n ttl(result?: any, currentTtl?: number | TtlFunction) {\n const ttl = currentTtl === undefined ? this.defaultTtl() : currentTtl;\n\n return isFunction(ttl) ? ttl(result) : ttl;\n }\n\n wrap<T>(key: string, fetch: () => Promise<T>, options?: CachingConfig): Promise<T> {\n if (!this.cache) {\n return fetch();\n }\n\n return this.cache?.wrap<T>(key, fetch, options as any);\n }\n\n async get<T>(key: string, options: JsonDeserializerOptions = {}): Promise<T | undefined> {\n return deserialize(this.cache?.get<T>(key), options);\n }\n\n async set<T>(key: string, value: any, options?: CachingConfig): Promise<T | undefined> {\n return this.cache?.set<T>(key, value, options);\n }\n\n async del(key: string): Promise<void> {\n await this.cache?.del(key);\n }\n\n async reset(): Promise<void> {\n // @ts-ignore\n await this.cache?.reset();\n }\n\n async keys(): Promise<string[]> {\n if (this.cache?.keys) {\n return this.cache.keys();\n }\n // istanbul ignore next\n return [];\n }\n\n async getMatchingKeys(patterns: string): Promise<string[]> {\n const [keys, {default: micromatch}] = await Promise.all([this.keys(), import(\"micromatch\")]);\n\n return micromatch(keys, patterns);\n }\n\n async deleteMatchingKeys(patterns: string): Promise<string[]> {\n const keys = await this.getMatchingKeys(patterns);\n\n await Promise.all(keys.map((key: string) => this.del(key)));\n\n return keys;\n }\n\n protected async createCacheManager(settings: PlatformCacheSettings) {\n const {caches, store = \"memory\", ttl, ...props} = settings;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const {default: cacheManager} = await import(\"cache-manager\");\n\n return caches?.length\n ? cacheManager.multiCaching(caches, {...props})\n : cacheManager.caching({\n ...props,\n ttl,\n store: isFunction(store) ? await store() : store\n });\n }\n}\n"]}
@@ -1,4 +1,3 @@
1
1
  export * from "./interfaces";
2
2
  export * from "./services/PlatformCache";
3
3
  export * from "./decorators/useCache";
4
- export * from "./PlatformCacheModule";
@@ -1,6 +1,6 @@
1
1
  import { MetadataTypes } from "@tsed/core";
2
2
  import { BaseContext } from "@tsed/di";
3
- import { TtlFunction } from "cache-manager";
3
+ import type { TtlFunction } from "cache-manager";
4
4
  export interface PlatformCacheOptions extends MetadataTypes {
5
5
  ttl?: number | TtlFunction;
6
6
  key?: string | ((args: any[], ctx?: BaseContext) => string);
@@ -1,11 +1,11 @@
1
1
  import type { BaseContext } from "@tsed/di";
2
- import { Cache, CacheOptions, CachingConfig, Store } from "cache-manager";
2
+ import type { Cache, CacheOptions, CachingConfig, Store } from "cache-manager";
3
3
  export * from "./PlatformCachedObject";
4
4
  export interface PlatformCacheSettings extends CacheOptions, CachingConfig {
5
5
  caches?: Cache[];
6
6
  store?: "memory" | "none" | Store | {
7
7
  create(...args: any[]): Store;
8
- };
8
+ } | (() => any);
9
9
  max?: number;
10
10
  keyResolver?: (args: any[], ctx: BaseContext) => string;
11
11
  /**
@@ -1,6 +1,7 @@
1
1
  import { Configuration } from "@tsed/di";
2
2
  import { JsonDeserializerOptions } from "@tsed/json-mapper";
3
- import cacheManager, { Cache, CachingConfig, MultiCache, TtlFunction } from "cache-manager";
3
+ import type { Cache, CachingConfig, MultiCache, TtlFunction } from "cache-manager";
4
+ import { PlatformCacheSettings } from "../interfaces";
4
5
  export declare type CacheManager = (Cache | MultiCache) & {
5
6
  keys?(): Promise<string[]>;
6
7
  };
@@ -11,9 +12,9 @@ export declare class PlatformCache {
11
12
  settings: Configuration;
12
13
  cache: CacheManager | undefined;
13
14
  disabled(): boolean;
14
- $onInit(): void;
15
+ $onInit(): Promise<void>;
15
16
  defaultKeyResolver(): (args: any[], ctx?: any) => string;
16
- defaultTtl(): number | cacheManager.TtlFunction;
17
+ defaultTtl(): number | TtlFunction;
17
18
  ttl(result?: any, currentTtl?: number | TtlFunction): number;
18
19
  wrap<T>(key: string, fetch: () => Promise<T>, options?: CachingConfig): Promise<T>;
19
20
  get<T>(key: string, options?: JsonDeserializerOptions): Promise<T | undefined>;
@@ -23,4 +24,5 @@ export declare class PlatformCache {
23
24
  keys(): Promise<string[]>;
24
25
  getMatchingKeys(patterns: string): Promise<string[]>;
25
26
  deleteMatchingKeys(patterns: string): Promise<string[]>;
27
+ protected createCacheManager(settings: PlatformCacheSettings): Promise<MultiCache>;
26
28
  }
package/package.json CHANGED
@@ -1,17 +1,21 @@
1
1
  {
2
2
  "name": "@tsed/platform-cache",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0-beta.3",
4
4
  "description": "Platform cache module for Ts.ED Framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
7
- "main": "./lib/index.js",
8
- "typings": "./lib/index.d.ts",
7
+ "main": "./lib/cjs/index.js",
8
+ "typings": "./lib/types/index.d.ts",
9
9
  "exports": {
10
- "require": "./lib/index.js",
11
- "default": "./lib/index.modern.js"
10
+ "types": "./lib/types/index.d.ts",
11
+ "import": "./lib/esm/index.js",
12
+ "require": "./lib/cjs/index.js",
13
+ "default": "./lib/esm/index.js"
12
14
  },
13
15
  "scripts": {
14
- "build": "microbundle --target node --no-compress --format modern,cjs --tsconfig ./tsconfig.compile.json"
16
+ "build": "yarn run build:esm && yarn run build:cjs",
17
+ "build:cjs": "tsc --build tsconfig.compile.json",
18
+ "build:esm": "tsc --build tsconfig.compile.esm.json"
15
19
  },
16
20
  "dependencies": {
17
21
  "@types/cache-manager": "^3.4.2",
@@ -20,26 +24,26 @@
20
24
  "tslib": "2.2.0"
21
25
  },
22
26
  "devDependencies": {
23
- "@tsed/core": "7.0.0-alpha.1",
24
- "@tsed/di": "7.0.0-alpha.1",
25
- "@tsed/exceptions": "7.0.0-alpha.1",
26
- "@tsed/json-mapper": "7.0.0-alpha.1",
27
- "@tsed/schema": "7.0.0-alpha.1",
27
+ "@tsed/core": "7.0.0-beta.3",
28
+ "@tsed/di": "7.0.0-beta.3",
29
+ "@tsed/exceptions": "7.0.0-beta.3",
30
+ "@tsed/json-mapper": "7.0.0-beta.3",
31
+ "@tsed/schema": "7.0.0-beta.3",
28
32
  "@types/cache-manager": "^3.4.2",
29
33
  "@types/micromatch": "^4.0.1"
30
34
  },
31
35
  "peerDependencies": {
32
- "@tsed/core": "^7.0.0-alpha.1",
33
- "@tsed/di": "^7.0.0-alpha.1",
34
- "@tsed/exceptions": "^7.0.0-alpha.1",
35
- "@tsed/json-mapper": "^7.0.0-alpha.1",
36
- "@tsed/schema": "^7.0.0-alpha.1"
36
+ "@tsed/core": "^7.0.0-beta.3",
37
+ "@tsed/di": "^7.0.0-beta.3",
38
+ "@tsed/exceptions": "^7.0.0-beta.3",
39
+ "@tsed/json-mapper": "^7.0.0-beta.3",
40
+ "@tsed/schema": "^7.0.0-beta.3"
37
41
  },
38
42
  "repository": "https://github.com/tsedio/tsed",
39
43
  "bugs": {
40
44
  "url": "https://github.com/tsedio/tsed/issues"
41
45
  },
42
- "homepage": "https://github.com/tsedio/tsed/tree/alpha/packages/platform/platform-cache",
46
+ "homepage": "https://github.com/tsedio/tsed/tree/beta/packages/platform/platform-cache",
43
47
  "author": "Romain Lenzotti",
44
48
  "license": "MIT"
45
49
  }
@@ -0,0 +1,23 @@
1
+ {
2
+ "extends": "./tsconfig.compile.json",
3
+ "compilerOptions": {
4
+ "baseUrl": ".",
5
+ "module": "ES2020",
6
+ "rootDir": "src",
7
+ "outDir": "./lib/esm",
8
+ "declaration": true,
9
+ "declarationDir": "./lib/types"
10
+ },
11
+ "exclude": [
12
+ "node_modules",
13
+ "test",
14
+ "lib",
15
+ "benchmark",
16
+ "coverage",
17
+ "spec",
18
+ "**/*.benchmark.ts",
19
+ "**/*.spec.ts",
20
+ "keys",
21
+ "jest.config.js"
22
+ ]
23
+ }
@@ -1,5 +0,0 @@
1
- /**
2
- * @ignore
3
- */
4
- export declare class PlatformCacheModule {
5
- }
package/lib/index.js DELETED
@@ -1,348 +0,0 @@
1
- var tslib = require('tslib');
2
- var core = require('@tsed/core');
3
- var di = require('@tsed/di');
4
- var jsonMapper = require('@tsed/json-mapper');
5
- var cacheManager = require('cache-manager');
6
- var micromatch = require('micromatch');
7
- var schema = require('@tsed/schema');
8
- var http = require('http');
9
-
10
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
-
12
- var cacheManager__default = /*#__PURE__*/_interopDefaultLegacy(cacheManager);
13
- var micromatch__default = /*#__PURE__*/_interopDefaultLegacy(micromatch);
14
-
15
- function _extends() {
16
- _extends = Object.assign || function (target) {
17
- for (var i = 1; i < arguments.length; i++) {
18
- var source = arguments[i];
19
-
20
- for (var key in source) {
21
- if (Object.prototype.hasOwnProperty.call(source, key)) {
22
- target[key] = source[key];
23
- }
24
- }
25
- }
26
-
27
- return target;
28
- };
29
-
30
- return _extends.apply(this, arguments);
31
- }
32
-
33
- function _objectWithoutPropertiesLoose(source, excluded) {
34
- if (source == null) return {};
35
- var target = {};
36
- var sourceKeys = Object.keys(source);
37
- var key, i;
38
-
39
- for (i = 0; i < sourceKeys.length; i++) {
40
- key = sourceKeys[i];
41
- if (excluded.indexOf(key) >= 0) continue;
42
- target[key] = source[key];
43
- }
44
-
45
- return target;
46
- }
47
-
48
- const _excluded = ["caches", "store", "ttl"];
49
-
50
- const defaultKeyResolver = args => {
51
- return args.map(arg => core.isClass(arg) ? JSON.stringify(jsonMapper.serialize(arg)) : arg).join(":");
52
- };
53
- /**
54
- * @platform
55
- */
56
-
57
-
58
- exports.PlatformCache = class PlatformCache {
59
- disabled() {
60
- return !this.settings.get("cache");
61
- }
62
-
63
- $onInit() {
64
- const settings = this.settings.get("cache");
65
-
66
- if (settings) {
67
- const {
68
- caches,
69
- store = "memory",
70
- ttl
71
- } = settings,
72
- props = _objectWithoutPropertiesLoose(settings, _excluded); // eslint-disable-next-line @typescript-eslint/no-unused-vars
73
-
74
-
75
- this.cache = caches != null && caches.length ? cacheManager__default['default'].multiCaching(caches, _extends({}, props)) : cacheManager__default['default'].caching(_extends({}, props, {
76
- ttl,
77
- store
78
- }));
79
- }
80
- }
81
-
82
- defaultKeyResolver() {
83
- return this.settings.get("cache.keyResolver", defaultKeyResolver);
84
- }
85
-
86
- defaultTtl() {
87
- return this.settings.get("cache.ttl");
88
- }
89
-
90
- ttl(result, currentTtl) {
91
- const ttl = currentTtl === undefined ? this.defaultTtl() : currentTtl;
92
- return core.isFunction(ttl) ? ttl(result) : ttl;
93
- }
94
-
95
- wrap(key, fetch, options) {
96
- var _this$cache;
97
-
98
- if (!this.cache) {
99
- return fetch();
100
- }
101
-
102
- return (_this$cache = this.cache) == null ? void 0 : _this$cache.wrap(key, fetch, options);
103
- }
104
-
105
- async get(key, options = {}) {
106
- var _this$cache2;
107
-
108
- return jsonMapper.deserialize((_this$cache2 = this.cache) == null ? void 0 : _this$cache2.get(key), options);
109
- }
110
-
111
- async set(key, value, options) {
112
- var _this$cache3;
113
-
114
- return (_this$cache3 = this.cache) == null ? void 0 : _this$cache3.set(key, value, options);
115
- }
116
-
117
- async del(key) {
118
- var _this$cache4;
119
-
120
- await ((_this$cache4 = this.cache) == null ? void 0 : _this$cache4.del(key));
121
- }
122
-
123
- async reset() {
124
- var _this$cache5;
125
-
126
- // @ts-ignore
127
- await ((_this$cache5 = this.cache) == null ? void 0 : _this$cache5.reset());
128
- }
129
-
130
- async keys() {
131
- var _this$cache6;
132
-
133
- if ((_this$cache6 = this.cache) != null && _this$cache6.keys) {
134
- return this.cache.keys();
135
- } // istanbul ignore next
136
-
137
-
138
- return [];
139
- }
140
-
141
- async getMatchingKeys(patterns) {
142
- const keys = await this.keys();
143
- return micromatch__default['default'](keys, patterns);
144
- }
145
-
146
- async deleteMatchingKeys(patterns) {
147
- const keys = await this.getMatchingKeys(patterns);
148
- await Promise.all(keys.map(key => this.del(key)));
149
- return keys;
150
- }
151
-
152
- };
153
-
154
- tslib.__decorate([di.Configuration(), tslib.__metadata("design:type", Object)], exports.PlatformCache.prototype, "settings", void 0);
155
-
156
- exports.PlatformCache = tslib.__decorate([di.Injectable()], exports.PlatformCache);
157
-
158
- const cleanHeaders = headers => {
159
- return Object.entries(headers).filter(([key]) => !["content-length", "x-request-id", "cache-control"].includes(key)).reduce((headers, [key, value]) => {
160
- return _extends({}, headers, {
161
- [key]: value
162
- });
163
- }, {});
164
- };
165
- /**
166
- * @platform
167
- */
168
-
169
-
170
- let PlatformCacheInterceptor = class PlatformCacheInterceptor {
171
- async intercept(context, next) {
172
- if (this.cache.disabled()) {
173
- return next();
174
- }
175
-
176
- if (!this.isEndpoint(context)) {
177
- return this.cacheMethod(context, next);
178
- }
179
-
180
- return this.cacheResponse(context, next);
181
- }
182
-
183
- getArgs(context) {
184
- return context.args.reduce((args, arg) => {
185
- if (arg instanceof di.DIContext || arg instanceof http.IncomingMessage || arg instanceof http.ServerResponse) {
186
- return args;
187
- }
188
-
189
- if (core.isClass(arg)) {
190
- return args.concat(jsonMapper.serialize(arg));
191
- }
192
-
193
- return args.concat(arg);
194
- }, []);
195
- }
196
-
197
- getOptions(context) {
198
- const {
199
- ttl,
200
- type,
201
- collectionType,
202
- key: k = this.cache.defaultKeyResolver()
203
- } = context.options || {};
204
- const args = this.getArgs(context);
205
- const keyArgs = core.isString(k) ? k : k(args);
206
- return {
207
- ttl,
208
- type,
209
- args,
210
- collectionType,
211
- keyArgs
212
- };
213
- }
214
-
215
- isEndpoint({
216
- target,
217
- propertyKey
218
- }) {
219
- return core.Store.fromMethod(target, propertyKey).has(schema.JsonEntityStore);
220
- }
221
-
222
- async cacheMethod(context, next) {
223
- const {
224
- ttl,
225
- type,
226
- collectionType,
227
- keyArgs,
228
- args
229
- } = this.getOptions(context);
230
- const key = [core.nameOf(context.target), context.propertyKey, keyArgs].join(":");
231
- const cachedObject = await this.cache.get(key);
232
-
233
- if (cachedObject) {
234
- const {
235
- data
236
- } = cachedObject;
237
- return jsonMapper.deserialize(JSON.parse(data), {
238
- collectionType,
239
- type
240
- });
241
- }
242
-
243
- const result = await next();
244
- const calculatedTtl = this.cache.ttl(result, ttl);
245
- await this.cache.set(key, {
246
- ttl: calculatedTtl,
247
- args,
248
- data: JSON.stringify(jsonMapper.serialize(result, {
249
- type,
250
- collectionType
251
- }))
252
- }, {
253
- ttl: calculatedTtl
254
- });
255
- return result;
256
- }
257
-
258
- async cacheResponse(context, next) {
259
- const $ctx = context.args[context.args.length - 1];
260
- const {
261
- request,
262
- response
263
- } = $ctx;
264
-
265
- if (request.method !== "GET") {
266
- return next();
267
- }
268
-
269
- const {
270
- ttl,
271
- args,
272
- keyArgs
273
- } = this.getOptions(context);
274
- const key = [request.method, request.url, keyArgs].join(":");
275
- const cachedObject = await this.cache.get(key);
276
-
277
- if (cachedObject && !(response.get("cache-control") === "no-cache")) {
278
- return this.sendResponse(cachedObject, $ctx);
279
- }
280
-
281
- const result = await next();
282
- const calculatedTtl = this.cache.ttl(result, ttl);
283
- const expires = calculatedTtl + Date.now() / 1000;
284
- $ctx.response.setHeaders({
285
- "cache-control": `max-age=${calculatedTtl}`
286
- }); // cache final response with his headers and body
287
-
288
- response.onEnd(async () => {
289
- const data = JSON.stringify(response.getBody());
290
- const headers = cleanHeaders(response.getHeaders());
291
- await this.cache.set(key, {
292
- ttl: calculatedTtl,
293
- args,
294
- data,
295
- expires,
296
- headers
297
- }, {
298
- ttl: calculatedTtl
299
- });
300
- });
301
- return result;
302
- }
303
-
304
- sendResponse(cachedObject, $ctx) {
305
- const {
306
- headers,
307
- ttl
308
- } = cachedObject;
309
- const {
310
- request,
311
- response
312
- } = $ctx;
313
- const requestEtag = request.get("if-none-match");
314
-
315
- if (requestEtag && headers.etag === requestEtag) {
316
- response.status(304).setHeaders(headers).body(undefined);
317
- return undefined;
318
- }
319
-
320
- const data = JSON.parse(cachedObject.data);
321
- $ctx.response.setHeaders(_extends({}, headers, {
322
- "x-cached": "true",
323
- "cache-control": `max-age=${ttl}`
324
- })).body(data);
325
- return data;
326
- }
327
-
328
- };
329
-
330
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", exports.PlatformCache)], PlatformCacheInterceptor.prototype, "cache", void 0);
331
-
332
- PlatformCacheInterceptor = tslib.__decorate([di.Interceptor()], PlatformCacheInterceptor);
333
-
334
- function UseCache(options = {}) {
335
- return core.useDecorators(di.Intercept(PlatformCacheInterceptor, options));
336
- }
337
-
338
- /**
339
- * @ignore
340
- */
341
-
342
- exports.PlatformCacheModule = class PlatformCacheModule {};
343
- exports.PlatformCacheModule = tslib.__decorate([di.Module({
344
- imports: [exports.PlatformCache]
345
- })], exports.PlatformCacheModule);
346
-
347
- exports.UseCache = UseCache;
348
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../src/services/PlatformCache.ts","../src/interceptors/PlatformCacheInterceptor.ts","../src/decorators/useCache.ts","../src/PlatformCacheModule.ts"],"sourcesContent":["import {isClass, isFunction} from \"@tsed/core\";\nimport {Configuration, Injectable} from \"@tsed/di\";\nimport {deserialize, JsonDeserializerOptions, serialize} from \"@tsed/json-mapper\";\nimport cacheManager, {Cache, CachingConfig, MultiCache, TtlFunction} from \"cache-manager\";\nimport micromatch from \"micromatch\";\nimport {PlatformCacheSettings} from \"../interfaces\";\n\nconst defaultKeyResolver = (args: any[]) => {\n return args.map((arg: any) => (isClass(arg) ? JSON.stringify(serialize(arg)) : arg)).join(\":\");\n};\n\nexport type CacheManager = (Cache | MultiCache) & {\n keys?(): Promise<string[]>;\n};\n\n/**\n * @platform\n */\n@Injectable()\nexport class PlatformCache {\n @Configuration()\n settings: Configuration;\n\n cache: CacheManager | undefined;\n\n disabled(): boolean {\n return !this.settings.get<PlatformCacheSettings>(\"cache\");\n }\n\n $onInit() {\n const settings = this.settings.get<PlatformCacheSettings>(\"cache\");\n\n if (settings) {\n const {caches, store = \"memory\", ttl, ...props} = settings;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n this.cache = caches?.length\n ? cacheManager.multiCaching(caches, {...props})\n : cacheManager.caching({\n ...props,\n ttl,\n store\n });\n }\n }\n\n defaultKeyResolver() {\n return this.settings.get<(args: any[], ctx?: any) => string>(\"cache.keyResolver\", defaultKeyResolver);\n }\n\n defaultTtl() {\n return this.settings.get<number | TtlFunction>(\"cache.ttl\");\n }\n\n ttl(result?: any, currentTtl?: number | TtlFunction) {\n const ttl = currentTtl === undefined ? this.defaultTtl() : currentTtl;\n\n return isFunction(ttl) ? ttl(result) : ttl;\n }\n\n wrap<T>(key: string, fetch: () => Promise<T>, options?: CachingConfig): Promise<T> {\n if (!this.cache) {\n return fetch();\n }\n\n return this.cache?.wrap<T>(key, fetch, options as any);\n }\n\n async get<T>(key: string, options: JsonDeserializerOptions = {}): Promise<T | undefined> {\n return deserialize(this.cache?.get<T>(key), options);\n }\n\n async set<T>(key: string, value: any, options?: CachingConfig): Promise<T | undefined> {\n return this.cache?.set<T>(key, value, options);\n }\n\n async del(key: string): Promise<void> {\n await this.cache?.del(key);\n }\n\n async reset(): Promise<void> {\n // @ts-ignore\n await this.cache?.reset();\n }\n\n async keys(): Promise<string[]> {\n if (this.cache?.keys) {\n return this.cache.keys();\n }\n // istanbul ignore next\n return [];\n }\n\n async getMatchingKeys(patterns: string): Promise<string[]> {\n const keys = await this.keys();\n\n return micromatch(keys, patterns);\n }\n\n async deleteMatchingKeys(patterns: string): Promise<string[]> {\n const keys = await this.getMatchingKeys(patterns);\n\n await Promise.all(keys.map((key: string) => this.del(key)));\n\n return keys;\n }\n}\n","import {isClass, isString, nameOf, Store} from \"@tsed/core\";\nimport {BaseContext, DIContext, Inject, Interceptor, InterceptorContext, InterceptorMethods, InterceptorNext} from \"@tsed/di\";\nimport {deserialize, serialize} from \"@tsed/json-mapper\";\nimport {JsonEntityStore} from \"@tsed/schema\";\nimport {IncomingMessage, ServerResponse} from \"http\";\nimport {PlatformCachedObject} from \"../interfaces/PlatformCachedObject\";\nimport {PlatformCacheOptions} from \"../interfaces/PlatformCacheOptions\";\nimport {PlatformCache} from \"../services/PlatformCache\";\n\nconst cleanHeaders = (headers: Record<string, unknown>) => {\n return Object.entries(headers)\n .filter(([key]) => ![\"content-length\", \"x-request-id\", \"cache-control\"].includes(key))\n .reduce((headers, [key, value]) => {\n return {\n ...headers,\n [key]: value\n };\n }, {});\n};\n\n/**\n * @platform\n */\n@Interceptor()\nexport class PlatformCacheInterceptor implements InterceptorMethods {\n @Inject()\n protected cache: PlatformCache;\n\n async intercept(context: InterceptorContext<any, PlatformCacheOptions>, next: InterceptorNext) {\n if (this.cache.disabled()) {\n return next();\n }\n\n if (!this.isEndpoint(context)) {\n return this.cacheMethod(context, next);\n }\n\n return this.cacheResponse(context, next);\n }\n\n protected getArgs(context: InterceptorContext<unknown, PlatformCacheOptions>) {\n return context.args.reduce((args, arg) => {\n if (arg instanceof DIContext || arg instanceof IncomingMessage || arg instanceof ServerResponse) {\n return args;\n }\n\n if (isClass(arg)) {\n return args.concat(serialize(arg));\n }\n\n return args.concat(arg);\n }, []);\n }\n\n protected getOptions(context: InterceptorContext<any, PlatformCacheOptions>) {\n const {ttl, type, collectionType, key: k = this.cache.defaultKeyResolver()} = context.options || {};\n\n const args = this.getArgs(context);\n const keyArgs = isString(k) ? k : k(args);\n\n return {ttl, type, args, collectionType, keyArgs};\n }\n\n protected isEndpoint({target, propertyKey}: InterceptorContext<any, PlatformCacheOptions>) {\n return Store.fromMethod(target, propertyKey).has(JsonEntityStore);\n }\n\n protected async cacheMethod(context: InterceptorContext<any, PlatformCacheOptions>, next: InterceptorNext) {\n const {ttl, type, collectionType, keyArgs, args} = this.getOptions(context);\n const key = [nameOf(context.target), context.propertyKey, keyArgs].join(\":\");\n\n const cachedObject = await this.cache.get<PlatformCachedObject>(key);\n\n if (cachedObject) {\n const {data} = cachedObject;\n\n return deserialize(JSON.parse(data), {collectionType, type});\n }\n\n const result = await next();\n const calculatedTtl = this.cache.ttl(result, ttl);\n\n await this.cache.set<PlatformCachedObject>(\n key,\n {\n ttl: calculatedTtl,\n args,\n data: JSON.stringify(serialize(result, {type, collectionType}))\n },\n {\n ttl: calculatedTtl\n }\n );\n\n return result;\n }\n\n protected async cacheResponse(context: InterceptorContext<any, PlatformCacheOptions>, next: InterceptorNext) {\n const $ctx: BaseContext = context.args[context.args.length - 1];\n const {request, response} = $ctx;\n\n if (request.method !== \"GET\") {\n return next();\n }\n\n const {ttl, args, keyArgs} = this.getOptions(context);\n\n const key = [request.method, request.url, keyArgs].join(\":\");\n\n const cachedObject = await this.cache.get<PlatformCachedObject>(key);\n\n if (cachedObject && !(response.get(\"cache-control\") === \"no-cache\")) {\n return this.sendResponse(cachedObject, $ctx);\n }\n\n const result = await next();\n\n const calculatedTtl = this.cache.ttl(result, ttl);\n const expires = calculatedTtl + Date.now() / 1000;\n $ctx.response.setHeaders({\n \"cache-control\": `max-age=${calculatedTtl}`\n });\n\n // cache final response with his headers and body\n response.onEnd(async () => {\n const data = JSON.stringify(response.getBody());\n const headers = cleanHeaders(response.getHeaders());\n\n await this.cache.set<PlatformCachedObject>(\n key,\n {\n ttl: calculatedTtl,\n args,\n data,\n expires,\n headers\n },\n {\n ttl: calculatedTtl\n }\n );\n });\n\n return result;\n }\n\n protected sendResponse(cachedObject: PlatformCachedObject, $ctx: BaseContext) {\n const {headers, ttl} = cachedObject;\n const {request, response} = $ctx;\n\n const requestEtag = request.get(\"if-none-match\");\n\n if (requestEtag && headers.etag === requestEtag) {\n response.status(304).setHeaders(headers).body(undefined);\n\n return undefined;\n }\n\n const data = JSON.parse(cachedObject.data);\n\n $ctx.response\n .setHeaders({\n ...headers,\n \"x-cached\": \"true\",\n \"cache-control\": `max-age=${ttl}`\n })\n .body(data);\n\n return data;\n }\n}\n","import {useDecorators} from \"@tsed/core\";\nimport {Intercept} from \"@tsed/di\";\nimport {PlatformCacheInterceptor} from \"../interceptors/PlatformCacheInterceptor\";\nimport {PlatformCacheOptions} from \"../interfaces/PlatformCacheOptions\";\n\nexport function UseCache(options: PlatformCacheOptions = {}) {\n return useDecorators(Intercept(PlatformCacheInterceptor, options));\n}\n","import {Module} from \"@tsed/di\";\nimport {PlatformCache} from \"./services/PlatformCache\";\n\n/**\n * @ignore\n */\n@Module({\n imports: [PlatformCache]\n})\nexport class PlatformCacheModule {}\n"],"names":["defaultKeyResolver","args","map","arg","isClass","JSON","stringify","serialize","join","PlatformCache","disabled","settings","get","$onInit","caches","store","ttl","props","cache","length","cacheManager","multiCaching","caching","defaultTtl","result","currentTtl","undefined","isFunction","wrap","key","fetch","options","deserialize","set","value","del","reset","keys","getMatchingKeys","patterns","micromatch","deleteMatchingKeys","Promise","all","__decorate","Configuration","Injectable","cleanHeaders","headers","Object","entries","filter","includes","reduce","PlatformCacheInterceptor","intercept","context","next","isEndpoint","cacheMethod","cacheResponse","getArgs","DIContext","IncomingMessage","ServerResponse","concat","getOptions","type","collectionType","k","keyArgs","isString","target","propertyKey","Store","fromMethod","has","JsonEntityStore","nameOf","cachedObject","data","parse","calculatedTtl","$ctx","request","response","method","url","sendResponse","expires","Date","now","setHeaders","onEnd","getBody","getHeaders","requestEtag","etag","status","body","Inject","Interceptor","UseCache","useDecorators","Intercept","PlatformCacheModule","Module","imports"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,MAAMA,kBAAkB,GAAIC,IAAD;AACzB,SAAOA,IAAI,CAACC,GAAL,CAAUC,GAAD,IAAeC,YAAO,CAACD,GAAD,CAAP,GAAeE,IAAI,CAACC,SAAL,CAAeC,oBAAS,CAACJ,GAAD,CAAxB,CAAf,GAAgDA,GAAxE,EAA8EK,IAA9E,CAAmF,GAAnF,CAAP;AACD,CAFD;AAQA;;;;;AAIaC,qBAAa,GAA1B,MAAaA,aAAb;AAMEC,EAAAA,QAAQ;AACN,WAAO,CAAC,KAAKC,QAAL,CAAcC,GAAd,CAAyC,OAAzC,CAAR;AACD;;AAEDC,EAAAA,OAAO;AACL,UAAMF,QAAQ,GAAG,KAAKA,QAAL,CAAcC,GAAd,CAAyC,OAAzC,CAAjB;;AAEA,QAAID,QAAJ,EAAc;AACZ,YAAM;AAACG,QAAAA,MAAD;AAASC,QAAAA,KAAK,GAAG,QAAjB;AAA2BC,QAAAA;AAA3B,UAA4CL,QAAlD;AAAA,YAAyCM,KAAzC,iCAAkDN,QAAlD,aADY;;;AAGZ,WAAKO,KAAL,GAAaJ,MAAM,QAAN,IAAAA,MAAM,CAAEK,M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