@roit/roit-data-firestore 1.2.33 → 1.2.34
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 +41 -0
- package/dist/archive/ArchiveService.js +229 -0
- package/dist/cache/CacheResolver.d.ts +2 -0
- package/dist/cache/CacheResolver.js +66 -0
- package/dist/cache/providers/RedisCacheArchiveProvider.d.ts +20 -0
- package/dist/cache/providers/RedisCacheArchiveProvider.js +137 -0
- package/dist/config/ArchiveConfig.d.ts +8 -0
- package/dist/config/ArchiveConfig.js +14 -0
- package/dist/config/BaseRepository.d.ts +6 -0
- package/dist/config/BaseRepository.js +12 -0
- package/dist/emulator/FirestoreEmuator.js +5 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8 -2
- package/dist/model/Aggregate.d.ts +1 -1
- package/dist/model/CacheProviders.d.ts +2 -1
- package/dist/model/CacheProviders.js +1 -0
- package/dist/model/Paging.d.ts +1 -1
- package/dist/model/PersistFirestoreReadProps.d.ts +2 -2
- package/dist/model/RepositoryOptions.d.ts +1 -1
- package/dist/model/index.js +5 -1
- package/dist/platform/PlatformTools.js +5 -1
- package/dist/query/ManualQueryHelper.d.ts +4 -0
- package/dist/query/ManualQueryHelper.js +46 -2
- package/dist/query/QueryPredicateFunctionTransform.js +8 -2
- package/dist/template/FunctionFindAllTemplate.txt +19 -0
- package/dist/template/FunctionFindByIdTemplate.txt +11 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/util/TemplateLoading.js +5 -1
- package/package.json +4 -2
package/dist/model/Paging.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type PersistFirestoreReadProps = {
|
|
2
2
|
collection: string;
|
|
3
3
|
repositoryClassName: string;
|
|
4
4
|
functionSignature: string;
|
|
5
5
|
params?: string;
|
|
6
6
|
queryResult: any | any[];
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type PersistFirestoreReadEnrichedProps = {
|
|
9
9
|
collection: string;
|
|
10
10
|
env: string;
|
|
11
11
|
insertAt: string;
|
|
@@ -5,7 +5,7 @@ export declare class RepositoryOptions {
|
|
|
5
5
|
validatorOptions?: ValidatorOptions;
|
|
6
6
|
ttl?: TtlOption;
|
|
7
7
|
}
|
|
8
|
-
export
|
|
8
|
+
export type UnitType = "second" | "minute" | "hour" | "days" | "week" | "month" | "year";
|
|
9
9
|
export declare class TtlOption {
|
|
10
10
|
expirationIn: number;
|
|
11
11
|
unit: UnitType;
|
package/dist/model/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -3,6 +3,10 @@ import { Config, MQuery, MQuerySimple, Options } from '../model/MQuery';
|
|
|
3
3
|
export declare class ManualQueryHelper {
|
|
4
4
|
static executeQueryManual(className: string, config: Config, queryRef?: boolean): Promise<any>;
|
|
5
5
|
static executeQueryManualPaginated(className: string, config: Config): Promise<QueryResult>;
|
|
6
|
+
/**
|
|
7
|
+
* Processa documentos arquivados, recuperando seus dados completos do Cloud Storage
|
|
8
|
+
*/
|
|
9
|
+
private static processArchivedDocuments;
|
|
6
10
|
static handleExecuteQueryManual(className: string, config: Config, options: Options, queryRef?: boolean): Promise<QueryResult>;
|
|
7
11
|
static convertToMQuery(query: MQuerySimple): MQuery;
|
|
8
12
|
private static getData;
|
|
@@ -14,6 +14,8 @@ const FirestoreInstance_1 = require("../config/FirestoreInstance");
|
|
|
14
14
|
const MQuery_1 = require("../model/MQuery");
|
|
15
15
|
const QueryCreatorConfig_1 = require("./QueryCreatorConfig");
|
|
16
16
|
const QueryPredicateFunctionTransform_1 = require("./QueryPredicateFunctionTransform");
|
|
17
|
+
const ArchiveService_1 = require("../archive/ArchiveService");
|
|
18
|
+
// import { ArchiveConfig } from "../config/ArchiveConfig";
|
|
17
19
|
class ManualQueryHelper {
|
|
18
20
|
static executeQueryManual(className, config, queryRef = false) {
|
|
19
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -30,6 +32,46 @@ class ManualQueryHelper {
|
|
|
30
32
|
return this.handleExecuteQueryManual(className, config, { showCount: true });
|
|
31
33
|
});
|
|
32
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Processa documentos arquivados, recuperando seus dados completos do Cloud Storage
|
|
37
|
+
*/
|
|
38
|
+
static processArchivedDocuments(docs, collectionName) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const archiveService = yield ArchiveService_1.ArchiveService.getInstance();
|
|
41
|
+
// Verifica se o arquivamento está habilitado
|
|
42
|
+
if (!archiveService.isEnabled()) {
|
|
43
|
+
return docs;
|
|
44
|
+
}
|
|
45
|
+
const docsMap = new Map();
|
|
46
|
+
const recoveryPromises = docs.map((doc) => __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
docsMap.set(doc.id, doc);
|
|
48
|
+
if (!archiveService.isDocumentArchived(doc)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
// O ArchiveService agora gerencia o cache internamente baseado na configuração
|
|
53
|
+
const archivedData = yield archiveService.getArchivedDocument(collectionName, doc);
|
|
54
|
+
if (archivedData) {
|
|
55
|
+
// Remove o flag de arquivamento e mescla os dados
|
|
56
|
+
// const { fbArchivedAt, ...archivedDataWithoutFlag } = archivedData;
|
|
57
|
+
return Object.assign(Object.assign({}, doc), archivedData);
|
|
58
|
+
}
|
|
59
|
+
return doc;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.warn(`Erro ao recuperar documento arquivado ${doc.id}:`, error);
|
|
63
|
+
return doc;
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
const recoveredDocs = yield Promise.all(recoveryPromises);
|
|
67
|
+
recoveredDocs.forEach(doc => {
|
|
68
|
+
if (doc) {
|
|
69
|
+
docsMap.set(doc.id, doc);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return Array.from(docsMap.values());
|
|
73
|
+
});
|
|
74
|
+
}
|
|
33
75
|
static handleExecuteQueryManual(className, config, options, queryRef = false) {
|
|
34
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
77
|
return yield global.instances.startTracer('firestore.query', (span) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -94,7 +136,9 @@ class ManualQueryHelper {
|
|
|
94
136
|
}
|
|
95
137
|
const snapshot = yield queryExecute.get();
|
|
96
138
|
const data = this.getData(snapshot);
|
|
97
|
-
|
|
139
|
+
// PROCESSAR DOCUMENTOS ARQUIVADOS
|
|
140
|
+
const processedData = yield this.processArchivedDocuments(data, repositoryOptions.collection);
|
|
141
|
+
yield cacheResolver.cacheResult(className, 'any', { data: processedData, count }, JSON.stringify(Object.assign(Object.assign({}, config), { options })));
|
|
98
142
|
const firestoreReadAuditResolver = global.instances.firestoreReadAuditResolver;
|
|
99
143
|
yield firestoreReadAuditResolver.persistFirestoreRead({
|
|
100
144
|
collection: repositoryOptions.collection,
|
|
@@ -110,7 +154,7 @@ class ManualQueryHelper {
|
|
|
110
154
|
'firestore.operation.size': data.length,
|
|
111
155
|
});
|
|
112
156
|
return {
|
|
113
|
-
data,
|
|
157
|
+
data: processedData,
|
|
114
158
|
totalItens: count
|
|
115
159
|
};
|
|
116
160
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -39,6 +43,7 @@ const uuid = __importStar(require("uuid"));
|
|
|
39
43
|
const fs_1 = __importDefault(require("fs"));
|
|
40
44
|
const path_1 = __importDefault(require("path"));
|
|
41
45
|
const Tracer_1 = require("../tracer/Tracer");
|
|
46
|
+
const ArchiveService_1 = require("../archive/ArchiveService");
|
|
42
47
|
const functionQueryTemplate = fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../template/FunctionQueryTemplate.txt'), 'utf8');
|
|
43
48
|
const methodList = {
|
|
44
49
|
'aggregation': fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../template/FunctionAggregationTemplate.txt'), 'utf8'),
|
|
@@ -73,7 +78,8 @@ class QueryPredicateFunctionTransform {
|
|
|
73
78
|
aggregateAverage: firestore_1.AggregateField.average,
|
|
74
79
|
aggregateSum: firestore_1.AggregateField.sum,
|
|
75
80
|
aggregateCount: firestore_1.AggregateField.count,
|
|
76
|
-
startTracer: Tracer_1.startTracer
|
|
81
|
+
startTracer: Tracer_1.startTracer,
|
|
82
|
+
archiveService: ArchiveService_1.ArchiveService.getInstance()
|
|
77
83
|
};
|
|
78
84
|
if (!(options === null || options === void 0 ? void 0 : options.collection)) {
|
|
79
85
|
throw new Error(`Collection is required`);
|
|
@@ -6,6 +6,7 @@ findAll(paging) {
|
|
|
6
6
|
let methodSignature = '';
|
|
7
7
|
const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
|
|
8
8
|
const cacheResolver = global.instances.cacheResolver;
|
|
9
|
+
const archiveService = yield global.instances.archiveService;
|
|
9
10
|
const result = yield cacheResolver.getCacheResult(repositoryClassName, methodSignature, 'Any');
|
|
10
11
|
if (result) {
|
|
11
12
|
return result;
|
|
@@ -24,6 +25,24 @@ findAll(paging) {
|
|
|
24
25
|
const data = doc.data();
|
|
25
26
|
items.push(Object.assign({}, data));
|
|
26
27
|
});
|
|
28
|
+
// VERIFICAÇÃO DE ARQUIVAMENTO PARA MÚLTIPLOS DOCUMENTOS
|
|
29
|
+
const archivedItems = items.filter(item => archiveService.isDocumentArchived(item));
|
|
30
|
+
if (archivedItems.length > 0) {
|
|
31
|
+
const recoveryPromises = archivedItems.map((item) => {
|
|
32
|
+
return archiveService.getArchivedDocument('<COLLECTION_REPLACE>', item)
|
|
33
|
+
.then(archivedData => archivedData ? { ...item, ...archivedData } : item);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const recoveredItems = yield Promise.all(recoveryPromises);
|
|
37
|
+
|
|
38
|
+
// Substituir itens arquivados pelos recuperados
|
|
39
|
+
items = items.map(item => {
|
|
40
|
+
if (archiveService.isDocumentArchived(item)) {
|
|
41
|
+
return recoveredItems.find(recovered => recovered.id === item.id) || item;
|
|
42
|
+
}
|
|
43
|
+
return item;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
27
46
|
yield cacheResolver.cacheResult(repositoryClassName, methodSignature, items, 'Any');
|
|
28
47
|
const firestoreReadAuditResolver = global.instances.firestoreReadAuditResolver;
|
|
29
48
|
yield firestoreReadAuditResolver.persistFirestoreRead({
|
|
@@ -6,6 +6,7 @@ findById(id) {
|
|
|
6
6
|
let methodSignature = '';
|
|
7
7
|
const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
|
|
8
8
|
const cacheResolver = global.instances.cacheResolver;
|
|
9
|
+
const archiveService = yield global.instances.archiveService;
|
|
9
10
|
const result = yield cacheResolver.getCacheResult(repositoryClassName, methodSignature, id);
|
|
10
11
|
if (result) {
|
|
11
12
|
return result;
|
|
@@ -18,7 +19,16 @@ findById(id) {
|
|
|
18
19
|
}
|
|
19
20
|
const response = yield collection.doc(id).get();
|
|
20
21
|
const item = response.data();
|
|
21
|
-
|
|
22
|
+
// VERIFICAÇÃO DE ARQUIVAMENTO
|
|
23
|
+
if (item && archiveService.isDocumentArchived(item)) {
|
|
24
|
+
const archivedData = yield archiveService.getArchivedDocument('<COLLECTION_REPLACE>', item);
|
|
25
|
+
if (archivedData) {
|
|
26
|
+
const completeData = { ...item, ...archivedData };
|
|
27
|
+
yield cacheResolver.cacheResult(repositoryClassName, methodSignature, completeData, id);
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
yield cacheResolver.cacheResult(repositoryClassName, methodSignature, item, id);
|
|
31
|
+
}
|
|
22
32
|
const firestoreReadAuditResolver = global.instances.firestoreReadAuditResolver;
|
|
23
33
|
yield firestoreReadAuditResolver.persistFirestoreRead({
|
|
24
34
|
collection: '<COLLECTION_REPLACE>',
|