@roit/roit-data-firestore 0.0.20 → 0.0.22

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 (41) hide show
  1. package/README.md +3 -2
  2. package/dist/cache/CacheResolver.d.ts +6 -3
  3. package/dist/cache/CacheResolver.js +69 -29
  4. package/dist/cache/providers/CacheProvider.d.ts +5 -0
  5. package/dist/cache/providers/CacheProvider.js +2 -0
  6. package/dist/cache/providers/InMemory.d.ts +8 -0
  7. package/dist/cache/providers/InMemory.js +57 -0
  8. package/dist/cache/providers/InMemoryCacheProvider.d.ts +7 -0
  9. package/dist/cache/providers/InMemoryCacheProvider.js +37 -0
  10. package/dist/cache/providers/RedisCacheProvider.d.ts +9 -0
  11. package/dist/cache/providers/RedisCacheProvider.js +93 -0
  12. package/dist/cache/providers/index.d.ts +2 -0
  13. package/dist/cache/providers/index.js +5 -0
  14. package/dist/emulator/FirestoreEmuator.js +20 -1
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.js +3 -1
  17. package/dist/model/CacheProviders.d.ts +4 -0
  18. package/dist/model/CacheProviders.js +8 -0
  19. package/dist/model/CacheableOptions.d.ts +7 -0
  20. package/dist/model/CacheableOptions.js +9 -0
  21. package/dist/query/operator/CreateFunction.js +16 -4
  22. package/dist/tsconfig.build.tsbuildinfo +1 -1
  23. package/dist/util/TemplateLoading.js +20 -1
  24. package/package.json +4 -2
  25. package/src/cache/CacheResolver.ts +57 -28
  26. package/src/cache/providers/CacheProvider.ts +6 -0
  27. package/src/cache/providers/InMemoryCacheProvider.ts +36 -0
  28. package/src/cache/providers/RedisCacheProvider.ts +87 -0
  29. package/src/cache/providers/index.ts +2 -0
  30. package/src/index.ts +3 -1
  31. package/src/model/CacheProviders.ts +3 -0
  32. package/src/model/CacheableOptions.ts +10 -1
  33. package/src/query/operator/CreateFunction.ts +29 -5
  34. package/test/CacheResolver.spec.ts +26 -26
  35. package/tsconfig.json +1 -0
  36. package/dist/model/BaseRepository.d.ts +0 -7
  37. package/dist/model/BaseRepository.js +0 -36
  38. package/dist/model/QueryOption.d.ts +0 -4
  39. package/dist/model/QueryOption.js +0 -9
  40. package/dist/model/QueryOptionInternal.d.ts +0 -4
  41. package/dist/model/QueryOptionInternal.js +0 -7
package/README.md CHANGED
@@ -75,8 +75,9 @@ The anotation Cacheable is responsible from handler storage data in cache, local
75
75
  'findById'
76
76
  ],
77
77
  cacheOnlyContainResults: true, // Cache data only query return value (optional, default true)
78
- cacheProvider: 'Local', // Provider using (optional, default 'Local')
79
- includeOnlyMethods: [] // Includes only the methods that will be stored (optional, default [])
78
+ cacheProvider: CacheProviders.LOCAL, // REDIS or LOCAL (optional, default 'Local')
79
+ includeOnlyMethods: [] // Includes only the methods that will be stored (optional, default []),
80
+ cacheExpiresInSeconds: 60 // Cache expiration in seconds
80
81
  })
81
82
  ```
82
83
 
@@ -2,11 +2,14 @@ import { CacheableOptions } from "../model/CacheableOptions";
2
2
  export declare class CacheResolver {
3
3
  private static instance;
4
4
  private repositorys;
5
- private localCacheMap;
5
+ private providersImplMap;
6
+ private cacheProvider;
6
7
  private constructor();
7
8
  static getInstance(): CacheResolver;
8
9
  addRepository(repository: string, option?: CacheableOptions): void;
9
- getCacheResult(repositoryClassName: string, methodSignature: string, ...paramValue: any[]): any | undefined;
10
- cacheResult(repositoryClassName: string, methodSignature: string, valueToCache: any, ...paramValue: any[]): boolean;
11
10
  private buildKey;
11
+ buildRepositoryKey(repositoryClassName: string): string;
12
+ getCacheResult(repositoryClassName: string, methodSignature: string, ...paramValue: any[]): Promise<string | null>;
13
+ revokeCacheFromRepository(repository: string): Promise<void>;
14
+ cacheResult(repositoryClassName: string, methodSignature: string, valueToCache: any, ...paramValue: any[]): Promise<boolean>;
12
15
  }
@@ -1,50 +1,90 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.CacheResolver = void 0;
13
+ const CacheableOptions_1 = require("../model/CacheableOptions");
14
+ const providers_1 = require("./providers");
4
15
  const roit_environment_1 = require("roit-environment");
16
+ const RedisCacheProvider_1 = require("./providers/RedisCacheProvider");
17
+ const CacheProviders_1 = require("../model/CacheProviders");
5
18
  class CacheResolver {
6
19
  constructor() {
7
20
  this.repositorys = new Map;
8
- this.localCacheMap = new Map;
21
+ this.providersImplMap = new Map;
22
+ this.providersImplMap.set(CacheProviders_1.CacheProviders.LOCAL, providers_1.InMemoryCacheProvider);
23
+ this.providersImplMap.set(CacheProviders_1.CacheProviders.REDIS, RedisCacheProvider_1.RedisCacheProvider);
9
24
  }
10
25
  static getInstance() {
11
26
  return this.instance;
12
27
  }
13
28
  addRepository(repository, option) {
14
- this.repositorys.set(repository, option || {
15
- cacheOnlyContainResults: true,
16
- cacheProvider: 'Local',
17
- excludesMethods: [],
18
- includeOnlyMethods: []
19
- });
29
+ const options = option || new CacheableOptions_1.CacheableOptions;
30
+ const implementation = options.cacheProvider || CacheProviders_1.CacheProviders.LOCAL;
31
+ const providerImpl = this.providersImplMap.get(implementation);
32
+ this.cacheProvider = new providerImpl();
33
+ this.repositorys.set(repository, options);
34
+ }
35
+ buildKey(repositoryClassName, methodSignature, ...paramValue) {
36
+ const service = roit_environment_1.Environment.getProperty('service');
37
+ return `${roit_environment_1.Environment.currentEnv()}:${service}:${repositoryClassName}:${methodSignature}:${paramValue.join(',')}`;
38
+ }
39
+ buildRepositoryKey(repositoryClassName) {
40
+ return `${roit_environment_1.Environment.currentEnv()}:${roit_environment_1.Environment.getProperty('service')}:${repositoryClassName}`;
20
41
  }
21
42
  getCacheResult(repositoryClassName, methodSignature, ...paramValue) {
22
- const result = this.localCacheMap.get(this.buildKey(repositoryClassName, methodSignature, paramValue));
23
- if (result) {
24
- console.debug('[DEBUG] Caching >', `Return value in cache from key: ${this.buildKey(repositoryClassName, methodSignature, paramValue)}`);
25
- }
26
- return result;
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const key = this.buildKey(repositoryClassName, methodSignature, paramValue);
45
+ return this.cacheProvider.getCacheResult(key);
46
+ });
47
+ }
48
+ revokeCacheFromRepository(repository) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ const keys = yield this.cacheProvider.getCacheResult(repository);
51
+ if (keys && Array.isArray(keys)) {
52
+ for (const key of keys) {
53
+ if (Boolean(roit_environment_1.Environment.getProperty('firestore.debug'))) {
54
+ console.debug('[DEBUG] Caching >', `Removing key: ${key}`);
55
+ }
56
+ yield this.cacheProvider.delete(key);
57
+ }
58
+ }
59
+ });
27
60
  }
28
61
  cacheResult(repositoryClassName, methodSignature, valueToCache, ...paramValue) {
29
62
  var _a, _b, _c;
30
- const option = this.repositorys.get(repositoryClassName);
31
- if (option) {
32
- const excludesMethod = Array.isArray(option === null || option === void 0 ? void 0 : option.excludesMethods) && ((_a = option === null || option === void 0 ? void 0 : option.excludesMethods) === null || _a === void 0 ? void 0 : _a.find(me => me == methodSignature));
33
- const notIncludeOnlyMethod = Array.isArray(option === null || option === void 0 ? void 0 : option.includeOnlyMethods) && ((_b = option === null || option === void 0 ? void 0 : option.includeOnlyMethods) === null || _b === void 0 ? void 0 : _b.length) > 0 && ((_c = option === null || option === void 0 ? void 0 : option.includeOnlyMethods) === null || _c === void 0 ? void 0 : _c.find(me => me == methodSignature)) == undefined;
34
- const notContainResult = (option === null || option === void 0 ? void 0 : option.cacheOnlyContainResults) ? ((Array.isArray(valueToCache) && valueToCache.length == 0) || valueToCache == null && valueToCache == undefined) : false;
35
- if (excludesMethod || notIncludeOnlyMethod || notContainResult) {
36
- return false;
37
- }
38
- this.localCacheMap.set(this.buildKey(repositoryClassName, methodSignature, paramValue), valueToCache);
39
- if (Boolean(roit_environment_1.Environment.getProperty('firestore.debug'))) {
40
- console.debug('[DEBUG] Caching >', `Storage cache from key: ${this.buildKey(repositoryClassName, methodSignature, paramValue)}`);
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ const option = this.repositorys.get(repositoryClassName);
65
+ if (option) {
66
+ const key = this.buildKey(repositoryClassName, methodSignature, paramValue);
67
+ const excludesMethod = Array.isArray(option === null || option === void 0 ? void 0 : option.excludesMethods) && ((_a = option === null || option === void 0 ? void 0 : option.excludesMethods) === null || _a === void 0 ? void 0 : _a.find(me => me == methodSignature));
68
+ const notIncludeOnlyMethod = Array.isArray(option === null || option === void 0 ? void 0 : option.includeOnlyMethods) && ((_b = option === null || option === void 0 ? void 0 : option.includeOnlyMethods) === null || _b === void 0 ? void 0 : _b.length) > 0 && ((_c = option === null || option === void 0 ? void 0 : option.includeOnlyMethods) === null || _c === void 0 ? void 0 : _c.find(me => me == methodSignature)) == undefined;
69
+ const notContainResult = (option === null || option === void 0 ? void 0 : option.cacheOnlyContainResults) ? ((Array.isArray(valueToCache) && valueToCache.length == 0) || !valueToCache) : false;
70
+ if (excludesMethod || notIncludeOnlyMethod || notContainResult) {
71
+ return false;
72
+ }
73
+ yield this.cacheProvider.saveCacheResult(key, valueToCache, option.cacheExpiresInSeconds);
74
+ const repositoryKey = this.buildRepositoryKey(repositoryClassName);
75
+ let cache = yield this.cacheProvider.getCacheResult(repositoryKey);
76
+ if (!cache) {
77
+ cache = [];
78
+ }
79
+ if (!cache.find(item => item === key)) {
80
+ cache.push(key);
81
+ }
82
+ const cacheTtl = 0;
83
+ yield this.cacheProvider.saveCacheResult(repositoryKey, cache, cacheTtl);
84
+ return true;
41
85
  }
42
- return true;
43
- }
44
- return false;
45
- }
46
- buildKey(repositoryClassName, methodSignature, ...paramValue) {
47
- return `${repositoryClassName}:${methodSignature}:${paramValue.join(',')}`;
86
+ return false;
87
+ });
48
88
  }
49
89
  }
50
90
  exports.CacheResolver = CacheResolver;
@@ -0,0 +1,5 @@
1
+ export interface CacheProvider {
2
+ getCacheResult(key: string): Promise<any | null>;
3
+ saveCacheResult(key: string, valueToCache: any, ttl: number | undefined): Promise<void>;
4
+ delete(key: string): Promise<void>;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { CacheableOptions } from "../../model/CacheableOptions";
2
+ import { CacheProvider } from "./CacheProvider";
3
+ export declare class InMemory implements CacheProvider {
4
+ private localCacheMap;
5
+ constructor();
6
+ getCacheResult(key: string): any;
7
+ saveCacheResult(key: string, option: CacheableOptions | undefined, methodSignature: string, valueToCache: any): boolean;
8
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.InMemory = void 0;
13
+ const roit_environment_1 = require("roit-environment");
14
+ const villar_1 = require("villar");
15
+ const CacheProviders_1 = require("../../model/CacheProviders");
16
+ let InMemory = class InMemory {
17
+ constructor() {
18
+ this.localCacheMap = new Map;
19
+ console.log("Fui chamado");
20
+ }
21
+ getCacheResult(key) {
22
+ const result = this.localCacheMap.get(key);
23
+ if (Boolean(roit_environment_1.Environment.getProperty('firestore.debug'))) {
24
+ if (result) {
25
+ console.debug('[DEBUG] Caching >', `Return value in cache from key: ${key}`);
26
+ }
27
+ else {
28
+ console.log("[DEBUG] Does not have in cache", key);
29
+ }
30
+ }
31
+ return result;
32
+ }
33
+ saveCacheResult(key, option, methodSignature, valueToCache) {
34
+ var _a, _b, _c;
35
+ if (option) {
36
+ const excludesMethod = Array.isArray(option === null || option === void 0 ? void 0 : option.excludesMethods) && ((_a = option === null || option === void 0 ? void 0 : option.excludesMethods) === null || _a === void 0 ? void 0 : _a.find(me => me == methodSignature));
37
+ const notIncludeOnlyMethod = Array.isArray(option === null || option === void 0 ? void 0 : option.includeOnlyMethods) && ((_b = option === null || option === void 0 ? void 0 : option.includeOnlyMethods) === null || _b === void 0 ? void 0 : _b.length) > 0 && ((_c = option === null || option === void 0 ? void 0 : option.includeOnlyMethods) === null || _c === void 0 ? void 0 : _c.find(me => me == methodSignature)) == undefined;
38
+ const notContainResult = (option === null || option === void 0 ? void 0 : option.cacheOnlyContainResults) ? ((Array.isArray(valueToCache) && valueToCache.length == 0) || valueToCache == null && valueToCache == undefined) : false;
39
+ if (excludesMethod || notIncludeOnlyMethod || notContainResult) {
40
+ return false;
41
+ }
42
+ this.localCacheMap.set(key, valueToCache);
43
+ if (Boolean(roit_environment_1.Environment.getProperty('firestore.debug'))) {
44
+ console.debug('[DEBUG] Caching >', `Storage cache from key: ${key}`);
45
+ }
46
+ return true;
47
+ }
48
+ return false;
49
+ }
50
+ };
51
+ InMemory = __decorate([
52
+ (0, villar_1.Implementation)({
53
+ key: CacheProviders_1.CacheProviders.LOCAL
54
+ }),
55
+ __metadata("design:paramtypes", [])
56
+ ], InMemory);
57
+ exports.InMemory = InMemory;
@@ -0,0 +1,7 @@
1
+ import { CacheProvider } from "./CacheProvider";
2
+ export declare class InMemoryCacheProvider implements CacheProvider {
3
+ private cache;
4
+ getCacheResult(key: string): Promise<any | null>;
5
+ saveCacheResult(key: string, valueToCache: any, ttl: number): Promise<void>;
6
+ delete(key: string): Promise<void>;
7
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.InMemoryCacheProvider = void 0;
7
+ const roit_environment_1 = require("roit-environment");
8
+ const node_cache_1 = __importDefault(require("node-cache"));
9
+ class InMemoryCacheProvider {
10
+ constructor() {
11
+ this.cache = new node_cache_1.default();
12
+ }
13
+ getCacheResult(key) {
14
+ const result = this.cache.get(key);
15
+ if (Boolean(roit_environment_1.Environment.getProperty('firestore.debug'))) {
16
+ if (result) {
17
+ console.debug('[DEBUG] Local Caching >', `Return value in cache from key: ${key}`);
18
+ }
19
+ else {
20
+ console.log("[DEBUG] Local Caching > ", `Key [${key}] is not found in the cache`);
21
+ }
22
+ }
23
+ return Promise.resolve(result);
24
+ }
25
+ saveCacheResult(key, valueToCache, ttl) {
26
+ this.cache.set(key, valueToCache, ttl || 0);
27
+ if (Boolean(roit_environment_1.Environment.getProperty('firestore.debug'))) {
28
+ console.debug('[DEBUG] Caching >', `Storage cache from key: ${key}`);
29
+ }
30
+ return Promise.resolve();
31
+ }
32
+ delete(key) {
33
+ this.cache.del(key);
34
+ return Promise.resolve();
35
+ }
36
+ }
37
+ exports.InMemoryCacheProvider = InMemoryCacheProvider;
@@ -0,0 +1,9 @@
1
+ import { CacheProvider } from "./CacheProvider";
2
+ export declare class RedisCacheProvider implements CacheProvider {
3
+ private redis;
4
+ constructor();
5
+ private isRedisReady;
6
+ getCacheResult(key: string): Promise<any | null>;
7
+ saveCacheResult(key: string, valueToCache: any, ttl: number | undefined): Promise<void>;
8
+ delete(key: string): Promise<void>;
9
+ }
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RedisCacheProvider = void 0;
13
+ const redis_1 = require("redis");
14
+ const roit_environment_1 = require("roit-environment");
15
+ class RedisCacheProvider {
16
+ constructor() {
17
+ if (!this.redis) {
18
+ const url = roit_environment_1.Environment.getProperty('firestore.cache.redisUrl');
19
+ if (!url) {
20
+ console.error(`[ERROR] Redis Caching > environtment variable "firestore.cache.redisUrl" was not found!`);
21
+ return;
22
+ }
23
+ this.redis = (0, redis_1.createClient)({ url });
24
+ this.redis.on('error', (err) => {
25
+ if (Boolean(roit_environment_1.Environment.getProperty('firestore.debug'))) {
26
+ console.warn('[WARN] Redis error', err);
27
+ }
28
+ });
29
+ this.redis.on('ready', () => {
30
+ if (Boolean(roit_environment_1.Environment.getProperty('firestore.debug'))) {
31
+ console.log('[DEBUG] Redis Caching > Redis is ready');
32
+ }
33
+ });
34
+ this.redis.connect();
35
+ }
36
+ }
37
+ isRedisReady() {
38
+ return this.redis && this.redis.isReady;
39
+ }
40
+ getCacheResult(key) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ try {
43
+ if (this.isRedisReady()) {
44
+ const result = yield this.redis.get(key);
45
+ if (Boolean(roit_environment_1.Environment.getProperty('firestore.debug'))) {
46
+ if (result) {
47
+ console.debug('[DEBUG] Redis Caching >', `Return value in cache from key: ${key}`);
48
+ }
49
+ else {
50
+ console.log("[DEBUG] Redis Caching > ", `Key [${key}] is not found in the cache`);
51
+ }
52
+ }
53
+ if (result) {
54
+ return JSON.parse(result);
55
+ }
56
+ }
57
+ }
58
+ catch (error) {
59
+ return null;
60
+ }
61
+ });
62
+ }
63
+ saveCacheResult(key, valueToCache, ttl) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ if (this.isRedisReady()) {
66
+ try {
67
+ yield this.redis.set(key, JSON.stringify(valueToCache), {
68
+ EX: ttl || 0
69
+ });
70
+ if (Boolean(roit_environment_1.Environment.getProperty('firestore.debug'))) {
71
+ console.debug('[DEBUG] Caching >', `Storage cache from key: ${key}`);
72
+ }
73
+ }
74
+ catch (error) {
75
+ console.log(`[DEBUG] Redis Caching > Error when saving cache. Key: ${key}, value: ${valueToCache}, error: ${error}`);
76
+ }
77
+ }
78
+ });
79
+ }
80
+ delete(key) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ try {
83
+ if (this.isRedisReady()) {
84
+ yield this.redis.del(key);
85
+ }
86
+ }
87
+ catch (error) {
88
+ console.log(`[DEBUG] Redis Caching > Error when deleting key from redis. ${key}`);
89
+ }
90
+ });
91
+ }
92
+ }
93
+ exports.RedisCacheProvider = RedisCacheProvider;
@@ -0,0 +1,2 @@
1
+ export { CacheProvider } from './CacheProvider';
2
+ export { InMemoryCacheProvider } from './InMemoryCacheProvider';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryCacheProvider = void 0;
4
+ var InMemoryCacheProvider_1 = require("./InMemoryCacheProvider");
5
+ Object.defineProperty(exports, "InMemoryCacheProvider", { enumerable: true, get: function () { return InMemoryCacheProvider_1.InMemoryCacheProvider; } });
@@ -1,7 +1,26 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
2
21
  Object.defineProperty(exports, "__esModule", { value: true });
3
22
  const roit_environment_1 = require("roit-environment");
4
- const shell = require("shelljs");
23
+ const shell = __importStar(require("shelljs"));
5
24
  shell.exec('lsof -ti tcp:9005 | xargs kill');
6
25
  shell.exec('lsof -ti tcp:4000 | xargs kill');
7
26
  shell.exec(`firebase --config ${process.cwd()}/src/emulator/firebase.json emulators:start --project ${roit_environment_1.Environment.getProperty('firestore.projectId')}`);
package/dist/index.d.ts CHANGED
@@ -10,3 +10,4 @@ export { Cacheable } from "./decorators/Cacheable";
10
10
  */
11
11
  export { BaseRepository } from "./config/BaseRepository";
12
12
  export { ReadonlyRepository } from "./config/ReadonlyRepository";
13
+ export { CacheProviders } from "./model/CacheProviders";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReadonlyRepository = exports.BaseRepository = exports.Cacheable = exports.Query = exports.Repository = void 0;
3
+ exports.CacheProviders = exports.ReadonlyRepository = exports.BaseRepository = exports.Cacheable = exports.Query = exports.Repository = void 0;
4
4
  require("reflect-metadata");
5
5
  /**
6
6
  * decorators
@@ -18,3 +18,5 @@ var BaseRepository_1 = require("./config/BaseRepository");
18
18
  Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return BaseRepository_1.BaseRepository; } });
19
19
  var ReadonlyRepository_1 = require("./config/ReadonlyRepository");
20
20
  Object.defineProperty(exports, "ReadonlyRepository", { enumerable: true, get: function () { return ReadonlyRepository_1.ReadonlyRepository; } });
21
+ var CacheProviders_1 = require("./model/CacheProviders");
22
+ Object.defineProperty(exports, "CacheProviders", { enumerable: true, get: function () { return CacheProviders_1.CacheProviders; } });
@@ -0,0 +1,4 @@
1
+ export declare enum CacheProviders {
2
+ LOCAL = "LOCAL",
3
+ REDIS = "REDIS"
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CacheProviders = void 0;
4
+ var CacheProviders;
5
+ (function (CacheProviders) {
6
+ CacheProviders["LOCAL"] = "LOCAL";
7
+ CacheProviders["REDIS"] = "REDIS";
8
+ })(CacheProviders = exports.CacheProviders || (exports.CacheProviders = {}));
@@ -1,6 +1,13 @@
1
1
  export declare class CacheableOptions {
2
2
  cacheOnlyContainResults?: boolean;
3
+ /**
4
+ * (default: CacheProviders.LOCAL)
5
+ */
3
6
  cacheProvider?: string;
7
+ /**
8
+ * (default: 0) the standard TTL for cache element cache element. 0 = unlimited
9
+ */
10
+ cacheExpiresInSeconds?: number;
4
11
  excludesMethods?: Array<string>;
5
12
  includeOnlyMethods?: Array<string>;
6
13
  }
@@ -1,9 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CacheableOptions = void 0;
4
+ const CacheProviders_1 = require("./CacheProviders");
4
5
  class CacheableOptions {
5
6
  constructor() {
6
7
  this.cacheOnlyContainResults = true;
8
+ /**
9
+ * (default: CacheProviders.LOCAL)
10
+ */
11
+ this.cacheProvider = CacheProviders_1.CacheProviders.LOCAL;
12
+ /**
13
+ * (default: 0) the standard TTL for cache element cache element. 0 = unlimited
14
+ */
15
+ this.cacheExpiresInSeconds = 0;
7
16
  this.excludesMethods = new Array;
8
17
  this.includeOnlyMethods = new Array;
9
18
  }
@@ -72,6 +72,10 @@ class CreateFunction {
72
72
  yield document.update(Object.assign({ lastServiceModify,
73
73
  updateAt,
74
74
  updateTimestampAt }, item));
75
+ let repositoryClassName = '';
76
+ const cacheResolver = global.instances.cacheResolver;
77
+ const key = cacheResolver.buildRepositoryKey(repositoryClassName);
78
+ yield cacheResolver.revokeCacheFromRepository(key);
75
79
  }
76
80
  else {
77
81
  console.log('It was decreed that it is being executed try, no operation or effective transaction will be performed');
@@ -108,6 +112,10 @@ class CreateFunction {
108
112
  item.lastServiceModify = global.instances.Environment.getProperty('service') || 'PROJECT_UNDEFINED';
109
113
  const docRef = collection.doc(item.id);
110
114
  batch.update(docRef, JSON.parse(JSON.stringify(item)));
115
+ let repositoryClassName = '';
116
+ const cacheResolver = global.instances.cacheResolver;
117
+ const key = cacheResolver.buildRepositoryKey(repositoryClassName);
118
+ yield cacheResolver.revokeCacheFromRepository(key);
111
119
  }
112
120
  if (!environmentUtil.areWeTesting()) {
113
121
  yield batch.commit();
@@ -179,6 +187,10 @@ class CreateFunction {
179
187
  batch.delete(docRef);
180
188
  });
181
189
  if (!environmentUtil.areWeTesting()) {
190
+ let repositoryClassName = '';
191
+ const cacheResolver = global.instances.cacheResolver;
192
+ const key = cacheResolver.buildRepositoryKey(repositoryClassName);
193
+ yield cacheResolver.revokeCacheFromRepository(key);
182
194
  yield batch.commit();
183
195
  }
184
196
  else {
@@ -193,7 +205,7 @@ class CreateFunction {
193
205
  let methodSignature = '';
194
206
  const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
195
207
  const cacheResolver = global.instances.cacheResolver;
196
- const result = cacheResolver.getCacheResult(repositoryClassName, methodSignature, 'Any');
208
+ const result = yield cacheResolver.getCacheResult(repositoryClassName, methodSignature, 'Any');
197
209
  if (result) {
198
210
  return result;
199
211
  }
@@ -211,7 +223,7 @@ class CreateFunction {
211
223
  const data = doc.data();
212
224
  items.push(Object.assign({}, data));
213
225
  });
214
- cacheResolver.cacheResult(repositoryClassName, methodSignature, items, 'Any');
226
+ yield cacheResolver.cacheResult(repositoryClassName, methodSignature, items, 'Any');
215
227
  return items;
216
228
  });
217
229
  }
@@ -221,7 +233,7 @@ class CreateFunction {
221
233
  let methodSignature = '';
222
234
  const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
223
235
  const cacheResolver = global.instances.cacheResolver;
224
- const result = cacheResolver.getCacheResult(repositoryClassName, methodSignature, id);
236
+ const result = yield cacheResolver.getCacheResult(repositoryClassName, methodSignature, id);
225
237
  if (result) {
226
238
  return result;
227
239
  }
@@ -233,7 +245,7 @@ class CreateFunction {
233
245
  }
234
246
  const response = yield collection.doc(id).get();
235
247
  const item = response.data();
236
- cacheResolver.cacheResult(repositoryClassName, methodSignature, item, id);
248
+ yield cacheResolver.cacheResult(repositoryClassName, methodSignature, item, id);
237
249
  return item;
238
250
  });
239
251
  }