@roit/roit-data-firestore 1.2.39 → 1.2.42
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/archive/ArchiveService.d.ts +0 -1
- package/dist/archive/ArchiveService.js +113 -136
- package/dist/cache/CacheResolver.js +80 -104
- package/dist/cache/providers/RedisCacheArchiveProvider.d.ts +0 -1
- package/dist/cache/providers/RedisCacheArchiveProvider.js +43 -69
- package/dist/cache/providers/RedisCacheProvider.js +37 -52
- package/dist/config/ArchiveConfig.d.ts +4 -0
- package/dist/config/ArchiveConfig.js +20 -1
- package/dist/config/BaseRepository.js +13 -30
- package/dist/config/ReadonlyRepository.js +7 -20
- package/dist/decorators/Repository.js +3 -12
- package/dist/exception/RepositoryException.js +1 -1
- package/dist/exception/handle/ValidatorDataHandle.js +12 -24
- package/dist/firestore-read-audit/FirestoreReadAuditResolver.js +15 -18
- package/dist/firestore-read-audit/providers/BigQueryFirestoreReadAuditProvider.js +53 -66
- package/dist/firestore-read-audit/providers/PubSubFirestoreReadAuditProvider.js +15 -26
- package/dist/model/CacheProviders.js +1 -1
- package/dist/model/MQuery.d.ts +4 -1
- package/dist/model/MQuery.js +4 -1
- package/dist/query/ManualQueryHelper.js +152 -147
- package/dist/query/QueryCreatorConfig.js +30 -42
- package/dist/query/QueryPredicateFunctionTransform.js +10 -10
- package/dist/query/TransformMethodFromQuery.js +2 -2
- package/dist/tracer/Tracer.js +5 -14
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/tsconfig.json +2 -2
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
26
|
exports.ArchiveService = void 0;
|
|
36
27
|
const storage_1 = require("@google-cloud/storage");
|
|
@@ -46,65 +37,63 @@ class ArchiveService {
|
|
|
46
37
|
*/
|
|
47
38
|
constructor() {
|
|
48
39
|
this.isInitialized = false;
|
|
49
|
-
this.isDebug = Boolean(ArchiveConfig_1.ArchiveConfig.getConfig().debug);
|
|
50
40
|
// Construtor vazio - inicialização será feita em initialize()
|
|
51
41
|
}
|
|
52
|
-
static getInstance() {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
});
|
|
42
|
+
static async getInstance() {
|
|
43
|
+
// Se já existe uma instância, retorna ela
|
|
44
|
+
if (ArchiveService.instance && ArchiveService.instance.isInitialized) {
|
|
45
|
+
return ArchiveService.instance;
|
|
46
|
+
}
|
|
47
|
+
// Se está inicializando, aguarda
|
|
48
|
+
if (ArchiveService.isInitializing) {
|
|
49
|
+
await ArchiveService.lock;
|
|
50
|
+
return ArchiveService.instance;
|
|
51
|
+
}
|
|
52
|
+
// Inicializa a instância
|
|
53
|
+
ArchiveService.isInitializing = true;
|
|
54
|
+
try {
|
|
55
|
+
if (!ArchiveService.instance) {
|
|
56
|
+
ArchiveService.instance = new ArchiveService();
|
|
57
|
+
}
|
|
58
|
+
await ArchiveService.instance.initialize();
|
|
59
|
+
return ArchiveService.instance;
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
ArchiveService.isInitializing = false;
|
|
63
|
+
}
|
|
76
64
|
}
|
|
77
|
-
initialize() {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (!this.firestore) {
|
|
89
|
-
this.firestore = new firestore_1.Firestore({
|
|
90
|
-
projectId: 'roit-intern-infra'
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
// REGISTRAR O ARCHIVESERVICE COMO REPOSITORY
|
|
94
|
-
this.cacheResolver.addRepository('ArchiveService', {
|
|
95
|
-
cacheExpiresInSeconds: 3600,
|
|
96
|
-
cacheProvider: CacheProviders_1.CacheProviders.REDIS_ARCHIVE
|
|
65
|
+
async initialize() {
|
|
66
|
+
if (this.isInitialized) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this.config = ArchiveConfig_1.ArchiveConfig.getConfig();
|
|
70
|
+
this.cacheResolver = CacheResolver_1.CacheResolver.getInstance();
|
|
71
|
+
this.projectId = this.config.projectId;
|
|
72
|
+
(0, ArchiveConfig_1.onDebugLog)(`Configuração: ${JSON.stringify(this.config)}`);
|
|
73
|
+
if (!this.firestore) {
|
|
74
|
+
this.firestore = new firestore_1.Firestore({
|
|
75
|
+
projectId: 'roit-intern-infra'
|
|
97
76
|
});
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
77
|
+
}
|
|
78
|
+
// REGISTRAR O ARCHIVESERVICE COMO REPOSITORY
|
|
79
|
+
this.cacheResolver.addRepository('ArchiveService', {
|
|
80
|
+
cacheExpiresInSeconds: 3600,
|
|
81
|
+
cacheProvider: CacheProviders_1.CacheProviders.REDIS_ARCHIVE
|
|
82
|
+
});
|
|
83
|
+
if (!this.config.enabled) {
|
|
84
|
+
(0, ArchiveConfig_1.onDebugLog)('Arquivamento desabilitado');
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
102
88
|
this.storage = new storage_1.Storage();
|
|
103
89
|
this.bucketName = this.config.bucketName;
|
|
104
90
|
if (!this.bucketName) {
|
|
105
|
-
|
|
91
|
+
(0, ArchiveConfig_1.onDebugWarn)('ArchiveService: bucket_name não configurado');
|
|
106
92
|
}
|
|
107
|
-
|
|
93
|
+
else {
|
|
94
|
+
(0, ArchiveConfig_1.onDebugLog)(`Bucket configurado: ${this.bucketName}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
108
97
|
}
|
|
109
98
|
static resetInstance() {
|
|
110
99
|
ArchiveService.instance = null;
|
|
@@ -125,100 +114,88 @@ class ArchiveService {
|
|
|
125
114
|
}
|
|
126
115
|
return documentData && documentData.fbArchivedAt;
|
|
127
116
|
}
|
|
128
|
-
pipeline(readStream, gunzip, writable) {
|
|
129
|
-
return
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
writable.on('error', reject);
|
|
134
|
-
});
|
|
117
|
+
async pipeline(readStream, gunzip, writable) {
|
|
118
|
+
return new Promise((resolve, reject) => {
|
|
119
|
+
readStream.pipe(gunzip).pipe(writable);
|
|
120
|
+
writable.on('finish', resolve);
|
|
121
|
+
writable.on('error', reject);
|
|
135
122
|
});
|
|
136
123
|
}
|
|
137
124
|
/**
|
|
138
125
|
* Recupera documento arquivado em formato JSON
|
|
139
126
|
*/
|
|
140
|
-
retrieveJsonDocument(collectionName, docId) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (!exists) {
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
const readStream = file.createReadStream();
|
|
151
|
-
const gunzip = zlib.createGunzip();
|
|
152
|
-
const chunks = [];
|
|
153
|
-
yield this.pipeline(readStream, gunzip, new stream_1.Writable({
|
|
154
|
-
write(chunk, _enc, cb) {
|
|
155
|
-
chunks.push(chunk);
|
|
156
|
-
cb();
|
|
157
|
-
}
|
|
158
|
-
}));
|
|
159
|
-
const result = Buffer.concat(chunks).toString('utf-8');
|
|
160
|
-
return JSON.parse(result);
|
|
161
|
-
}
|
|
162
|
-
catch (error) {
|
|
163
|
-
console.warn(`Erro ao recuperar documento JSON arquivado ${collectionName}/${docId}:`, error);
|
|
127
|
+
async retrieveJsonDocument(collectionName, docId) {
|
|
128
|
+
try {
|
|
129
|
+
const filePath = `${this.projectId}/${collectionName}/${docId}.json.gz`;
|
|
130
|
+
const bucket = this.storage.bucket(this.bucketName);
|
|
131
|
+
const file = bucket.file(filePath);
|
|
132
|
+
const [exists] = await file.exists();
|
|
133
|
+
if (!exists) {
|
|
164
134
|
return null;
|
|
165
135
|
}
|
|
166
|
-
|
|
136
|
+
const readStream = file.createReadStream();
|
|
137
|
+
const gunzip = zlib.createGunzip();
|
|
138
|
+
const chunks = [];
|
|
139
|
+
await this.pipeline(readStream, gunzip, new stream_1.Writable({
|
|
140
|
+
write(chunk, _enc, cb) {
|
|
141
|
+
chunks.push(chunk);
|
|
142
|
+
cb();
|
|
143
|
+
}
|
|
144
|
+
}));
|
|
145
|
+
const result = Buffer.concat(chunks).toString('utf-8');
|
|
146
|
+
return JSON.parse(result);
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
console.log(`${ArchiveConfig_1.DEBUG_PREFIX} Erro ao recuperar documento JSON arquivado ${collectionName}/${docId}:`, error);
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
167
152
|
}
|
|
168
153
|
/**
|
|
169
154
|
* Verifica se um documento está arquivado e recupera seus dados completos
|
|
170
155
|
*/
|
|
171
|
-
getArchivedDocument(collectionName, doc) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
console.log(`Cache hit para documento arquivado: ${collectionName}/${docId}`);
|
|
188
|
-
}
|
|
189
|
-
return cachedData;
|
|
190
|
-
}
|
|
156
|
+
async getArchivedDocument(collectionName, doc) {
|
|
157
|
+
if (!this.isEnabled()) {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
if (!this.bucketName) {
|
|
161
|
+
console.warn(`${ArchiveConfig_1.DEBUG_PREFIX} ArchiveService: bucket_name não configurado, não é possível recuperar documentos arquivados`);
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
const docId = doc.id;
|
|
165
|
+
// Verificar cache se habilitado
|
|
166
|
+
if (this.config.cache.enabled) {
|
|
167
|
+
const cacheKey = `archived_${collectionName}_${docId}`;
|
|
168
|
+
const cachedData = await this.cacheResolver.getCacheResult('ArchiveService', 'getArchivedDocument', cacheKey);
|
|
169
|
+
if (cachedData) {
|
|
170
|
+
(0, ArchiveConfig_1.onDebugLog)(`Cache hit para documento arquivado: ${collectionName}/${docId}`);
|
|
171
|
+
return cachedData;
|
|
191
172
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return archivedData;
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
const archivedData = await this.retrieveJsonDocument(collectionName, docId);
|
|
176
|
+
if (archivedData) {
|
|
177
|
+
// Salvar no cache se habilitado
|
|
178
|
+
if (this.config.cache.enabled) {
|
|
179
|
+
const cacheKey = `archived_${collectionName}_${docId}`;
|
|
180
|
+
await this.cacheResolver.cacheResult('ArchiveService', 'getArchivedDocument', archivedData, cacheKey);
|
|
181
|
+
(0, ArchiveConfig_1.onDebugLog)(`Documento arquivado cacheado: ${collectionName}/${docId}`);
|
|
204
182
|
}
|
|
183
|
+
return archivedData;
|
|
205
184
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
console.warn(`${ArchiveConfig_1.DEBUG_PREFIX} Erro ao recuperar documento arquivado ${collectionName}/${docId}:`, error);
|
|
188
|
+
}
|
|
189
|
+
return null;
|
|
211
190
|
}
|
|
212
191
|
/**
|
|
213
192
|
* Limpa o cache de documentos arquivados
|
|
214
193
|
*/
|
|
215
|
-
clearArchivedCache(collectionName, docId) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
yield this.cacheResolver.revokeArchiveCache(collectionName, docId);
|
|
221
|
-
});
|
|
194
|
+
async clearArchivedCache(collectionName, docId) {
|
|
195
|
+
if (!this.config.cache.enabled) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
await this.cacheResolver.revokeArchiveCache(collectionName, docId);
|
|
222
199
|
}
|
|
223
200
|
}
|
|
224
201
|
exports.ArchiveService = ArchiveService;
|
|
@@ -1,13 +1,4 @@
|
|
|
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
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.CacheResolver = void 0;
|
|
13
4
|
const CacheableOptions_1 = require("../model/CacheableOptions");
|
|
@@ -15,10 +6,10 @@ const providers_1 = require("./providers");
|
|
|
15
6
|
const RedisCacheProvider_1 = require("./providers/RedisCacheProvider");
|
|
16
7
|
const CacheProviders_1 = require("../model/CacheProviders");
|
|
17
8
|
const CurrentEnv_1 = require("../util/CurrentEnv");
|
|
18
|
-
const IsDebug_1 = require("../util/IsDebug");
|
|
19
9
|
const QueryPredicateFunctionTransform_1 = require("../query/QueryPredicateFunctionTransform");
|
|
20
10
|
const RedisCacheArchiveProvider_1 = require("./providers/RedisCacheArchiveProvider");
|
|
21
11
|
const ArchiveConfig_1 = require("../config/ArchiveConfig");
|
|
12
|
+
const IsDebug_1 = require("../util/IsDebug");
|
|
22
13
|
class CacheResolver {
|
|
23
14
|
constructor() {
|
|
24
15
|
this.repositorys = new Map;
|
|
@@ -43,112 +34,97 @@ class CacheResolver {
|
|
|
43
34
|
buildRepositoryKey(repositoryClassName) {
|
|
44
35
|
return `${CurrentEnv_1.currentEnv}:${repositoryClassName}`;
|
|
45
36
|
}
|
|
46
|
-
getCacheResult(repositoryClassName, methodSignature, ...paramValue) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return this.cacheProvider.getCacheResult(key);
|
|
53
|
-
});
|
|
37
|
+
async getCacheResult(repositoryClassName, methodSignature, ...paramValue) {
|
|
38
|
+
if (!this.repositorys.get(repositoryClassName)) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const key = this.buildKey(repositoryClassName, methodSignature, paramValue);
|
|
42
|
+
return this.cacheProvider.getCacheResult(key);
|
|
54
43
|
}
|
|
55
|
-
revokeCacheFromRepository(repositoryClassName) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
console.debug('[DEBUG] Caching >', `Removing key: ${key}`);
|
|
66
|
-
}
|
|
67
|
-
yield this.cacheProvider.delete(key);
|
|
44
|
+
async revokeCacheFromRepository(repositoryClassName) {
|
|
45
|
+
const key = this.buildRepositoryKey(repositoryClassName);
|
|
46
|
+
if (!this.repositorys.get(repositoryClassName)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const keys = await this.cacheProvider.getKeys(`${key}`);
|
|
50
|
+
if (keys && Array.isArray(keys)) {
|
|
51
|
+
for (const key of keys) {
|
|
52
|
+
if (IsDebug_1.isDebug) {
|
|
53
|
+
console.debug('[DEBUG] Caching >', `Removing key: ${key}`);
|
|
68
54
|
}
|
|
55
|
+
await this.cacheProvider.delete(key);
|
|
69
56
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
57
|
+
}
|
|
58
|
+
await this.cacheProvider.delete(key);
|
|
59
|
+
// REVOGAR CACHE DO ARCHIVE PARA A MESMA COLLECTION
|
|
60
|
+
await this.revokeArchiveCacheForRepository(repositoryClassName);
|
|
74
61
|
}
|
|
75
|
-
cacheResult(repositoryClassName, methodSignature, valueToCache, ...paramValue) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (excludesMethod || notIncludeOnlyMethod || notContainResult) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
yield this.cacheProvider.saveCacheResult(key, valueToCache, option.cacheExpiresInSeconds);
|
|
88
|
-
return true;
|
|
62
|
+
async cacheResult(repositoryClassName, methodSignature, valueToCache, ...paramValue) {
|
|
63
|
+
const option = this.repositorys.get(repositoryClassName);
|
|
64
|
+
if (option) {
|
|
65
|
+
const key = this.buildKey(repositoryClassName, methodSignature, paramValue);
|
|
66
|
+
const excludesMethod = Array.isArray(option?.excludesMethods) && option?.excludesMethods?.find(me => me == methodSignature);
|
|
67
|
+
const notIncludeOnlyMethod = Array.isArray(option?.includeOnlyMethods) && option?.includeOnlyMethods?.length > 0 && option?.includeOnlyMethods?.find(me => me == methodSignature) == undefined;
|
|
68
|
+
const notContainResult = option?.cacheOnlyContainResults ? ((Array.isArray(valueToCache) && valueToCache.length == 0) || !valueToCache) : false;
|
|
69
|
+
if (excludesMethod || notIncludeOnlyMethod || notContainResult) {
|
|
70
|
+
return false;
|
|
89
71
|
}
|
|
90
|
-
|
|
91
|
-
|
|
72
|
+
await this.cacheProvider.saveCacheResult(key, valueToCache, option.cacheExpiresInSeconds);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
92
76
|
}
|
|
93
|
-
revokeArchiveCache(collectionName, docId) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
77
|
+
async revokeArchiveCache(collectionName, docId) {
|
|
78
|
+
const repositoryKey = this.buildRepositoryKey('ArchiveService');
|
|
79
|
+
if (!this.repositorys.get('ArchiveService')) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const keys = await this.cacheProvider.getKeys(`${repositoryKey}`);
|
|
83
|
+
if (!keys || !Array.isArray(keys)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
for (const key of keys) {
|
|
87
|
+
let shouldDelete = false;
|
|
88
|
+
if (collectionName && docId) {
|
|
89
|
+
// Limpar cache de documento específico
|
|
90
|
+
const cacheKey = `archived_${collectionName}_${docId}`;
|
|
91
|
+
shouldDelete = key.includes(`getArchivedDocument:${cacheKey}`);
|
|
98
92
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
93
|
+
else if (collectionName) {
|
|
94
|
+
// Limpar cache de collection específica
|
|
95
|
+
shouldDelete = key.includes(`getArchivedDocument:archived_${collectionName}`);
|
|
102
96
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// Limpar cache de documento específico
|
|
107
|
-
const cacheKey = `archived_${collectionName}_${docId}`;
|
|
108
|
-
shouldDelete = key.includes(`getArchivedDocument:${cacheKey}`);
|
|
109
|
-
}
|
|
110
|
-
else if (collectionName) {
|
|
111
|
-
// Limpar cache de collection específica
|
|
112
|
-
shouldDelete = key.includes(`getArchivedDocument:archived_${collectionName}`);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
// Limpar todo o cache de arquivamento
|
|
116
|
-
shouldDelete = key.includes('getArchivedDocument');
|
|
117
|
-
}
|
|
118
|
-
if (shouldDelete) {
|
|
119
|
-
if (Boolean(ArchiveConfig_1.ArchiveConfig.getConfig().debug)) {
|
|
120
|
-
console.debug('[DEBUG] Archive Cache >', `Removing key: ${key}`);
|
|
121
|
-
}
|
|
122
|
-
yield this.cacheProvider.delete(key);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
revokeArchiveCacheForRepository(repositoryClassName) {
|
|
128
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
// Verificar se ArchiveService está registrado
|
|
130
|
-
if (!this.repositorys.get('ArchiveService')) {
|
|
131
|
-
return;
|
|
97
|
+
else {
|
|
98
|
+
// Limpar todo o cache de arquivamento
|
|
99
|
+
shouldDelete = key.includes('getArchivedDocument');
|
|
132
100
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return;
|
|
101
|
+
if (shouldDelete) {
|
|
102
|
+
(0, ArchiveConfig_1.onDebugLog)(`Archive Cache > Removing key: ${key}`);
|
|
103
|
+
await this.cacheProvider.delete(key);
|
|
137
104
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async revokeArchiveCacheForRepository(repositoryClassName) {
|
|
108
|
+
// Verificar se ArchiveService está registrado
|
|
109
|
+
if (!this.repositorys.get('ArchiveService')) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
// Obter a collection do repositório que está sendo revogado
|
|
113
|
+
const repositoryOptions = QueryPredicateFunctionTransform_1.QueryPredicateFunctionTransform.classConfig.get(repositoryClassName);
|
|
114
|
+
if (!repositoryOptions || !repositoryOptions.collection) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const collectionName = repositoryOptions.collection;
|
|
118
|
+
// Revogar cache do archive para essa collection
|
|
119
|
+
const archiveKeys = await this.cacheProvider.getKeys(`${CurrentEnv_1.currentEnv}:ArchiveService`);
|
|
120
|
+
if (archiveKeys && Array.isArray(archiveKeys)) {
|
|
121
|
+
for (const key of archiveKeys) {
|
|
122
|
+
if (key.includes(`getArchivedDocument:archived_${collectionName}`)) {
|
|
123
|
+
(0, ArchiveConfig_1.onDebugLog)(`Archive Cache > Removing archive key: ${key}`);
|
|
124
|
+
await this.cacheProvider.delete(key);
|
|
149
125
|
}
|
|
150
126
|
}
|
|
151
|
-
}
|
|
127
|
+
}
|
|
152
128
|
}
|
|
153
129
|
}
|
|
154
130
|
exports.CacheResolver = CacheResolver;
|