@roit/roit-data-firestore 1.2.48 → 1.2.50
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/ArchivePluginRegistry.js +2 -2
- package/dist/archive/ArchiveService.d.ts +3 -12
- package/dist/archive/ArchiveService.js +12 -35
- package/dist/archive/IArchivePlugin.d.ts +2 -11
- package/dist/config/BaseRepository.js +4 -1
- package/dist/config/ReadonlyRepository.js +1 -1
- package/dist/exception/RepositoryException.js +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -3
- package/dist/model/CacheProviders.js +1 -1
- package/dist/query/ManualQueryHelper.js +1 -1
- package/dist/query/QueryPredicateFunctionTransform.js +1 -3
- package/dist/template/FunctionCreateOrUpdateTemplate.txt +7 -5
- package/dist/template/FunctionDeleteTemplate.txt +5 -4
- package/dist/template/FunctionFindAllTemplate.txt +0 -1
- package/dist/template/FunctionUpdatePartialTemplate.txt +5 -5
- package/dist/template/FunctionUpdateTemplate.txt +6 -6
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -17,9 +17,6 @@ export declare class ArchiveService {
|
|
|
17
17
|
private static instance;
|
|
18
18
|
private static readonly lock;
|
|
19
19
|
private static isInitializing;
|
|
20
|
-
private config;
|
|
21
|
-
/** ProjectId of the Firestore being archived (for path organization) */
|
|
22
|
-
private projectId;
|
|
23
20
|
private isInitialized;
|
|
24
21
|
private logger;
|
|
25
22
|
/**
|
|
@@ -34,7 +31,6 @@ export declare class ArchiveService {
|
|
|
34
31
|
* Requires the firestore-archive plugin to be registered
|
|
35
32
|
*/
|
|
36
33
|
isEnabled(): boolean;
|
|
37
|
-
static isEnabled(): boolean;
|
|
38
34
|
/**
|
|
39
35
|
* Checks if a document is archived
|
|
40
36
|
*/
|
|
@@ -44,9 +40,9 @@ export declare class ArchiveService {
|
|
|
44
40
|
*
|
|
45
41
|
* Returns the trimmed string or undefined when missing/invalid.
|
|
46
42
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
getArchivePath(documentData: any): string | undefined;
|
|
44
|
+
getArchiveHash(documentData: any): string | undefined;
|
|
45
|
+
markerKey(): string | undefined;
|
|
50
46
|
/**
|
|
51
47
|
* Checks if a document is archived and retrieves its complete data
|
|
52
48
|
*/
|
|
@@ -90,10 +86,5 @@ export declare class ArchiveService {
|
|
|
90
86
|
* Delegates to the firestore-archive plugin
|
|
91
87
|
*/
|
|
92
88
|
clearArchivedCache(collectionName?: string, docId?: string): Promise<void>;
|
|
93
|
-
/**
|
|
94
|
-
* Returns the projectId of the Firestore being archived
|
|
95
|
-
* (used for path organization in Storage)
|
|
96
|
-
*/
|
|
97
|
-
getProjectId(): string;
|
|
98
89
|
}
|
|
99
90
|
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ArchiveService = void 0;
|
|
4
|
-
const ArchiveConfig_1 = require("../config/ArchiveConfig");
|
|
5
4
|
const index_1 = require("./index");
|
|
6
5
|
/**
|
|
7
6
|
* Logger for ArchiveService
|
|
@@ -33,6 +32,7 @@ class ArchiveService {
|
|
|
33
32
|
* Private constructor to prevent direct instantiation
|
|
34
33
|
*/
|
|
35
34
|
constructor() {
|
|
35
|
+
// Instance properties
|
|
36
36
|
this.isInitialized = false;
|
|
37
37
|
// Empty constructor - initialization will be done in initialize()
|
|
38
38
|
}
|
|
@@ -63,21 +63,12 @@ class ArchiveService {
|
|
|
63
63
|
if (this.isInitialized) {
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
this.logger = new ArchiveLogger(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (!this.projectId) {
|
|
71
|
-
this.logger.warn('projectId not configured - using environment variable');
|
|
72
|
-
this.projectId = process.env.FIRESTORE_PROJECTID || process.env.GCP_PROJECT || '';
|
|
73
|
-
}
|
|
74
|
-
this.logger.debug(`Configuração: projectId=${this.projectId}, enabled=${this.config.enabled}`);
|
|
75
|
-
if (!this.config.enabled) {
|
|
76
|
-
this.logger.info('Archive disabled via configuration');
|
|
77
|
-
this.isInitialized = true;
|
|
78
|
-
return;
|
|
66
|
+
const debug = ['true', true].includes(process.env.FIRESTORE_DEBUG || '') || (0, index_1.getArchivePlugin)().debugEnabled();
|
|
67
|
+
this.logger = new ArchiveLogger(debug);
|
|
68
|
+
if ((0, index_1.hasArchivePlugin)()) {
|
|
69
|
+
this.logger.debug(`Plugin firestore-archive registered: enabled=${(0, index_1.getArchivePlugin)().isEnabled()}`);
|
|
79
70
|
}
|
|
80
|
-
|
|
71
|
+
else {
|
|
81
72
|
this.logger.warn('Plugin firestore-archive not registered - archive disabled');
|
|
82
73
|
}
|
|
83
74
|
this.isInitialized = true;
|
|
@@ -94,10 +85,6 @@ class ArchiveService {
|
|
|
94
85
|
// Archive only works with registered plugin
|
|
95
86
|
return (0, index_1.hasArchivePlugin)() && (0, index_1.getArchivePlugin)().isEnabled();
|
|
96
87
|
}
|
|
97
|
-
static isEnabled() {
|
|
98
|
-
// Archive only works with registered plugin
|
|
99
|
-
return (0, index_1.hasArchivePlugin)() && (0, index_1.getArchivePlugin)().isEnabled();
|
|
100
|
-
}
|
|
101
88
|
/**
|
|
102
89
|
* Checks if a document is archived
|
|
103
90
|
*/
|
|
@@ -112,19 +99,19 @@ class ArchiveService {
|
|
|
112
99
|
*
|
|
113
100
|
* Returns the trimmed string or undefined when missing/invalid.
|
|
114
101
|
*/
|
|
115
|
-
|
|
102
|
+
getArchivePath(documentData) {
|
|
116
103
|
if (!this.isEnabled()) {
|
|
117
104
|
return undefined;
|
|
118
105
|
}
|
|
119
106
|
return (0, index_1.getArchivePlugin)().getArchivePath(documentData);
|
|
120
107
|
}
|
|
121
|
-
|
|
108
|
+
getArchiveHash(documentData) {
|
|
122
109
|
if (!this.isEnabled()) {
|
|
123
110
|
return undefined;
|
|
124
111
|
}
|
|
125
112
|
return (0, index_1.getArchivePlugin)().getArchiveHash(documentData);
|
|
126
113
|
}
|
|
127
|
-
|
|
114
|
+
markerKey() {
|
|
128
115
|
if (!this.isEnabled()) {
|
|
129
116
|
return undefined;
|
|
130
117
|
}
|
|
@@ -138,18 +125,17 @@ class ArchiveService {
|
|
|
138
125
|
return null;
|
|
139
126
|
}
|
|
140
127
|
const docId = doc.id;
|
|
141
|
-
const archivePath =
|
|
128
|
+
const archivePath = this.getArchivePath(doc) || '';
|
|
142
129
|
if (!archivePath) {
|
|
143
130
|
throw new Error(`ArchiveService.getArchivedDocument: ${(0, index_1.getArchivePlugin)().markerKey() || ''} archive path is required. collection=${collectionName} docId=${docId}`);
|
|
144
131
|
}
|
|
145
132
|
// Extract hash from stub for integrity verification
|
|
146
|
-
const expectedHash =
|
|
133
|
+
const expectedHash = this.getArchiveHash(doc);
|
|
147
134
|
// Delegate to plugin (isEnabled already ensures it exists)
|
|
148
135
|
return (0, index_1.getArchivePlugin)().getArchivedDocument({
|
|
149
136
|
collection: collectionName,
|
|
150
137
|
docId,
|
|
151
138
|
archivePath,
|
|
152
|
-
projectId: this.projectId,
|
|
153
139
|
expectedHash,
|
|
154
140
|
});
|
|
155
141
|
}
|
|
@@ -177,7 +163,6 @@ class ArchiveService {
|
|
|
177
163
|
docId,
|
|
178
164
|
newData,
|
|
179
165
|
options,
|
|
180
|
-
projectId: this.projectId,
|
|
181
166
|
archivePath,
|
|
182
167
|
});
|
|
183
168
|
}
|
|
@@ -201,7 +186,6 @@ class ArchiveService {
|
|
|
201
186
|
return (0, index_1.getArchivePlugin)().deleteArchivedDocument({
|
|
202
187
|
collection: collectionName,
|
|
203
188
|
docId,
|
|
204
|
-
projectId: this.projectId,
|
|
205
189
|
archivePath,
|
|
206
190
|
});
|
|
207
191
|
}
|
|
@@ -219,7 +203,7 @@ class ArchiveService {
|
|
|
219
203
|
}
|
|
220
204
|
const archivedData = await this.getArchivedDocument(collectionName, stubData);
|
|
221
205
|
if (!archivedData) {
|
|
222
|
-
this.logger.warn(`Archived data not found for document: ${collectionName}/${stubData
|
|
206
|
+
this.logger.warn(`Archived data not found for document: ${collectionName}/${stubData?.id || ''}`);
|
|
223
207
|
return stubData; // Return stub if archived data is not found
|
|
224
208
|
}
|
|
225
209
|
// Merge: storage data overwrites the stub, except the marker key
|
|
@@ -236,13 +220,6 @@ class ArchiveService {
|
|
|
236
220
|
}
|
|
237
221
|
await (0, index_1.getArchivePlugin)().invalidateCache(collectionName, docId);
|
|
238
222
|
}
|
|
239
|
-
/**
|
|
240
|
-
* Returns the projectId of the Firestore being archived
|
|
241
|
-
* (used for path organization in Storage)
|
|
242
|
-
*/
|
|
243
|
-
getProjectId() {
|
|
244
|
-
return this.projectId;
|
|
245
|
-
}
|
|
246
223
|
}
|
|
247
224
|
exports.ArchiveService = ArchiveService;
|
|
248
225
|
// Singleton instance
|
|
@@ -28,7 +28,6 @@ export interface IArchivePlugin {
|
|
|
28
28
|
* @param collection - Collection name
|
|
29
29
|
* @param docId - Document ID
|
|
30
30
|
* @param archivePath - Full object path in Storage
|
|
31
|
-
* @param projectId - Project ID (optional)
|
|
32
31
|
* @param expectedHash - Expected hash from Firestore stub for integrity verification (optional)
|
|
33
32
|
* @returns Operation result
|
|
34
33
|
*/
|
|
@@ -36,7 +35,6 @@ export interface IArchivePlugin {
|
|
|
36
35
|
collection: string;
|
|
37
36
|
docId: string;
|
|
38
37
|
archivePath: string;
|
|
39
|
-
projectId?: string;
|
|
40
38
|
expectedHash?: string;
|
|
41
39
|
}): Promise<Record<string, unknown> | null>;
|
|
42
40
|
/**
|
|
@@ -46,7 +44,6 @@ export interface IArchivePlugin {
|
|
|
46
44
|
* @param docId - Document ID
|
|
47
45
|
* @param newData - New data to merge
|
|
48
46
|
* @param options - Options (unarchive: true to remove from Storage)
|
|
49
|
-
* @param projectId - Project ID (optional)
|
|
50
47
|
* @param archivePath - Full object path in Storage. Required when unarchive=true
|
|
51
48
|
* @returns Merged data
|
|
52
49
|
*/
|
|
@@ -57,7 +54,6 @@ export interface IArchivePlugin {
|
|
|
57
54
|
options?: {
|
|
58
55
|
unarchive?: boolean;
|
|
59
56
|
};
|
|
60
|
-
projectId?: string;
|
|
61
57
|
archivePath: string;
|
|
62
58
|
}): Promise<{
|
|
63
59
|
result: {
|
|
@@ -72,14 +68,13 @@ export interface IArchivePlugin {
|
|
|
72
68
|
*
|
|
73
69
|
* @param collection - Collection name
|
|
74
70
|
* @param docId - Document ID
|
|
75
|
-
* @param
|
|
71
|
+
* @param archivePath - Full object path in Storage
|
|
76
72
|
* @returns Operation result
|
|
77
73
|
*/
|
|
78
74
|
deleteArchivedDocument(params: {
|
|
79
75
|
collection: string;
|
|
80
76
|
docId: string;
|
|
81
77
|
archivePath: string;
|
|
82
|
-
projectId?: string;
|
|
83
78
|
}): Promise<{
|
|
84
79
|
success: boolean;
|
|
85
80
|
message?: string;
|
|
@@ -96,9 +91,5 @@ export interface IArchivePlugin {
|
|
|
96
91
|
getArchivePath(doc: Record<string, unknown> | null | undefined): string | undefined;
|
|
97
92
|
isArchived(doc: Record<string, unknown> | null | undefined): boolean;
|
|
98
93
|
markerKey(): string | undefined;
|
|
99
|
-
|
|
100
|
-
* Returns the current configuration (for debugging/inspection)
|
|
101
|
-
* Added in firestore-archive v1.1.0
|
|
102
|
-
*/
|
|
103
|
-
getConfig?(): Record<string, unknown> | undefined;
|
|
94
|
+
debugEnabled(): boolean;
|
|
104
95
|
}
|
|
@@ -33,9 +33,13 @@ class BaseRepository {
|
|
|
33
33
|
*/
|
|
34
34
|
async clearArchivedCache(collectionName, docId) {
|
|
35
35
|
const archiveService = await ArchiveService_1.ArchiveService.getInstance();
|
|
36
|
+
if (!archiveService.isEnabled()) {
|
|
37
|
+
return Promise.resolve();
|
|
38
|
+
}
|
|
36
39
|
await archiveService.clearArchivedCache(collectionName, docId);
|
|
37
40
|
}
|
|
38
41
|
}
|
|
42
|
+
exports.BaseRepository = BaseRepository;
|
|
39
43
|
__decorate([
|
|
40
44
|
(0, Query_1.Query)(),
|
|
41
45
|
__metadata("design:type", Function)
|
|
@@ -84,4 +88,3 @@ __decorate([
|
|
|
84
88
|
(0, Query_1.Query)(),
|
|
85
89
|
__metadata("design:type", Function)
|
|
86
90
|
], BaseRepository.prototype, "aggregation", void 0);
|
|
87
|
-
exports.BaseRepository = BaseRepository;
|
|
@@ -22,6 +22,7 @@ class ReadonlyRepository {
|
|
|
22
22
|
return ManualQueryHelper_1.ManualQueryHelper.executeQueryManualPaginated(className, config);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
exports.ReadonlyRepository = ReadonlyRepository;
|
|
25
26
|
__decorate([
|
|
26
27
|
(0, Query_1.Query)(),
|
|
27
28
|
__metadata("design:type", Function)
|
|
@@ -30,4 +31,3 @@ __decorate([
|
|
|
30
31
|
(0, Query_1.Query)(),
|
|
31
32
|
__metadata("design:type", Function)
|
|
32
33
|
], ReadonlyRepository.prototype, "findById", void 0);
|
|
33
|
-
exports.ReadonlyRepository = ReadonlyRepository;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ export { Cacheable } from "./decorators/Cacheable";
|
|
|
11
11
|
export { BaseRepository } from "./config/BaseRepository";
|
|
12
12
|
export { ReadonlyRepository } from "./config/ReadonlyRepository";
|
|
13
13
|
export { GenericRepository } from "./config/GenericRepository";
|
|
14
|
-
export { ArchiveConfig } from "./config/ArchiveConfig";
|
|
15
14
|
export { CacheProviders } from "./model/CacheProviders";
|
|
16
15
|
export { FirestoreInstance } from "./config/FirestoreInstance";
|
|
17
16
|
/**
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.resetArchivePlugin = exports.hasArchivePlugin = exports.getArchivePlugin = exports.registerArchivePlugin = exports.FirestoreInstance = exports.CacheProviders = exports.
|
|
17
|
+
exports.resetArchivePlugin = exports.hasArchivePlugin = exports.getArchivePlugin = exports.registerArchivePlugin = exports.FirestoreInstance = exports.CacheProviders = exports.GenericRepository = exports.ReadonlyRepository = exports.BaseRepository = exports.Cacheable = exports.Query = exports.Repository = void 0;
|
|
18
18
|
require("reflect-metadata");
|
|
19
19
|
/**
|
|
20
20
|
* decorators
|
|
@@ -34,8 +34,6 @@ var ReadonlyRepository_1 = require("./config/ReadonlyRepository");
|
|
|
34
34
|
Object.defineProperty(exports, "ReadonlyRepository", { enumerable: true, get: function () { return ReadonlyRepository_1.ReadonlyRepository; } });
|
|
35
35
|
var GenericRepository_1 = require("./config/GenericRepository");
|
|
36
36
|
Object.defineProperty(exports, "GenericRepository", { enumerable: true, get: function () { return GenericRepository_1.GenericRepository; } });
|
|
37
|
-
var ArchiveConfig_1 = require("./config/ArchiveConfig");
|
|
38
|
-
Object.defineProperty(exports, "ArchiveConfig", { enumerable: true, get: function () { return ArchiveConfig_1.ArchiveConfig; } });
|
|
39
37
|
var CacheProviders_1 = require("./model/CacheProviders");
|
|
40
38
|
Object.defineProperty(exports, "CacheProviders", { enumerable: true, get: function () { return CacheProviders_1.CacheProviders; } });
|
|
41
39
|
var FirestoreInstance_1 = require("./config/FirestoreInstance");
|
|
@@ -5,4 +5,4 @@ var CacheProviders;
|
|
|
5
5
|
(function (CacheProviders) {
|
|
6
6
|
CacheProviders["LOCAL"] = "LOCAL";
|
|
7
7
|
CacheProviders["REDIS"] = "REDIS";
|
|
8
|
-
})(CacheProviders
|
|
8
|
+
})(CacheProviders || (exports.CacheProviders = CacheProviders = {}));
|
|
@@ -37,7 +37,7 @@ class ManualQueryHelper {
|
|
|
37
37
|
try {
|
|
38
38
|
// The ArchiveService now manages the cache internally based on the configuration
|
|
39
39
|
const archivedData = await archiveService.getArchivedDocument(collectionName, doc);
|
|
40
|
-
const markerKey =
|
|
40
|
+
const markerKey = archiveService.markerKey();
|
|
41
41
|
if (archivedData && markerKey) {
|
|
42
42
|
// Merges the stub data with the archived data
|
|
43
43
|
// Preserve the marker from stub to prevent archivedData from overwriting it
|
|
@@ -80,9 +80,7 @@ class QueryPredicateFunctionTransform {
|
|
|
80
80
|
aggregateSum: firestore_1.AggregateField.sum,
|
|
81
81
|
aggregateCount: firestore_1.AggregateField.count,
|
|
82
82
|
startTracer: Tracer_1.startTracer,
|
|
83
|
-
archiveService: ArchiveService_1.ArchiveService.getInstance()
|
|
84
|
-
getArchivePath: ArchiveService_1.ArchiveService.getArchivePath,
|
|
85
|
-
markerKey: ArchiveService_1.ArchiveService.markerKey,
|
|
83
|
+
archiveService: ArchiveService_1.ArchiveService.getInstance()
|
|
86
84
|
};
|
|
87
85
|
if (!options?.collection) {
|
|
88
86
|
throw new Error(`Collection is required`);
|
|
@@ -27,9 +27,11 @@ createOrUpdate(items) {
|
|
|
27
27
|
if (!item.id) item.id = uuid();
|
|
28
28
|
return item;
|
|
29
29
|
});
|
|
30
|
+
|
|
31
|
+
const archiveIsEnabled = archiveService.isEnabled()
|
|
30
32
|
|
|
31
33
|
const docRefs = itemsWithIds.map(item => collection.doc(item.id));
|
|
32
|
-
const existingDocs = (
|
|
34
|
+
const existingDocs = (archiveIsEnabled && docRefs.length > 0)
|
|
33
35
|
? yield db.getAll(...docRefs)
|
|
34
36
|
: [];
|
|
35
37
|
|
|
@@ -41,9 +43,9 @@ createOrUpdate(items) {
|
|
|
41
43
|
let shouldUnarchive = false;
|
|
42
44
|
|
|
43
45
|
// VERIFICAÇÃO DE DOCUMENTO ARQUIVADO
|
|
44
|
-
if (
|
|
46
|
+
if (archiveIsEnabled && existingDocs[i]?.exists) {
|
|
45
47
|
const currentData = existingDocs[i].data();
|
|
46
|
-
const archivePath =
|
|
48
|
+
const archivePath = archiveService.getArchivePath(currentData);
|
|
47
49
|
if (currentData && archivePath) {
|
|
48
50
|
const updateResult = yield archiveService.updateArchivedDocument(
|
|
49
51
|
'<COLLECTION_REPLACE>',
|
|
@@ -81,9 +83,9 @@ createOrUpdate(items) {
|
|
|
81
83
|
itemData.ttlExpirationAt = getTtlTimestamp(ttlExpirationIn, ttlUnit);
|
|
82
84
|
}
|
|
83
85
|
|
|
84
|
-
if (shouldUnarchive &&
|
|
86
|
+
if (shouldUnarchive && archiveService.markerKey()) {
|
|
85
87
|
const FieldValue = global.instances.FieldValue;
|
|
86
|
-
itemData[
|
|
88
|
+
itemData[archiveService.markerKey()] = FieldValue.delete();
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
batch.set(docRef, itemData, { merge: true });
|
|
@@ -16,17 +16,18 @@ delete(ids) {
|
|
|
16
16
|
const archiveService = yield global.instances.archiveService;
|
|
17
17
|
const batch = db.batch();
|
|
18
18
|
const collection = db.collection('<COLLECTION_REPLACE>');
|
|
19
|
+
|
|
20
|
+
const archiveIsEnabled = archiveService.isEnabled();
|
|
19
21
|
|
|
20
|
-
// Verificar quais documentos estão arquivados antes de deletar
|
|
21
22
|
const archivedDocs = [];
|
|
22
|
-
if (
|
|
23
|
+
if (archiveIsEnabled) {
|
|
23
24
|
const docRefs = ids.map(id => collection.doc(id));
|
|
24
25
|
const docs = docRefs.length > 0 ? yield db.getAll(...docRefs) : [];
|
|
25
26
|
for (let i = 0; i < docs.length; i++) {
|
|
26
27
|
const doc = docs[i];
|
|
27
28
|
if (doc && doc.exists) {
|
|
28
29
|
const data = doc.data();
|
|
29
|
-
const archivePath =
|
|
30
|
+
const archivePath = archiveService.getArchivePath(data);
|
|
30
31
|
if (data && archivePath) {
|
|
31
32
|
archivedDocs.push({ id: ids[i], archivePath });
|
|
32
33
|
}
|
|
@@ -42,7 +43,7 @@ delete(ids) {
|
|
|
42
43
|
yield batch.commit();
|
|
43
44
|
|
|
44
45
|
// Deletar arquivos do Storage para documentos arquivados
|
|
45
|
-
if (
|
|
46
|
+
if (archiveIsEnabled && archivedDocs.length > 0) {
|
|
46
47
|
const deletePromises = archivedDocs.map(({ id: docId, archivePath }) =>
|
|
47
48
|
archiveService.deleteArchivedDocument('<COLLECTION_REPLACE>', docId, archivePath)
|
|
48
49
|
.catch(err => {
|
|
@@ -12,14 +12,14 @@ updatePartial(id, item) {
|
|
|
12
12
|
const document = db.collection('<COLLECTION_REPLACE>').doc(id);
|
|
13
13
|
|
|
14
14
|
let shouldUnarchive = false;
|
|
15
|
+
const archiveIsEnabled = archiveService.isEnabled()
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
if (archiveService.isEnabled()) {
|
|
17
|
+
if (archiveIsEnabled) {
|
|
18
18
|
const currentDoc = yield document.get();
|
|
19
19
|
|
|
20
20
|
if (currentDoc.exists) {
|
|
21
21
|
const currentData = currentDoc.data();
|
|
22
|
-
const archivePath =
|
|
22
|
+
const archivePath = archiveService.getArchivePath(currentData);
|
|
23
23
|
|
|
24
24
|
if (currentData && archivePath) {
|
|
25
25
|
const updateResult = yield archiveService.updateArchivedDocument(
|
|
@@ -48,9 +48,9 @@ updatePartial(id, item) {
|
|
|
48
48
|
updateTimestampAt
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
if (shouldUnarchive &&
|
|
51
|
+
if (shouldUnarchive && archiveService.markerKey()) {
|
|
52
52
|
const FieldValue = global.instances.FieldValue;
|
|
53
|
-
itemData[
|
|
53
|
+
itemData[archiveService.markerKey()] = FieldValue.delete();
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
yield document.set(itemData, { merge: true });
|
|
@@ -29,9 +29,10 @@ update(items) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
const archiveIsEnabled = archiveService.isEnabled()
|
|
32
33
|
// Buscar documentos existentes em lote (otimização)
|
|
33
34
|
const docRefs = items.map(item => collection.doc(item.id));
|
|
34
|
-
const existingDocs = (
|
|
35
|
+
const existingDocs = (archiveIsEnabled && docRefs.length > 0)
|
|
35
36
|
? yield db.getAll(...docRefs)
|
|
36
37
|
: [];
|
|
37
38
|
|
|
@@ -42,10 +43,9 @@ update(items) {
|
|
|
42
43
|
const docRef = docRefs[i];
|
|
43
44
|
let shouldUnarchive = false;
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
if (archiveService.isEnabled() && existingDocs[i]?.exists) {
|
|
46
|
+
if (archiveIsEnabled && existingDocs[i]?.exists) {
|
|
47
47
|
const currentData = existingDocs[i].data();
|
|
48
|
-
const archivePath =
|
|
48
|
+
const archivePath = archiveService.getArchivePath(currentData);
|
|
49
49
|
|
|
50
50
|
if (currentData && archivePath) {
|
|
51
51
|
const updateResult = yield archiveService.updateArchivedDocument(
|
|
@@ -76,9 +76,9 @@ update(items) {
|
|
|
76
76
|
itemData.ttlExpirationAt = getTtlTimestamp(ttlExpirationIn, ttlUnit);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
if (shouldUnarchive &&
|
|
79
|
+
if (shouldUnarchive && archiveService.markerKey()) {
|
|
80
80
|
const FieldValue = global.instances.FieldValue;
|
|
81
|
-
itemData[
|
|
81
|
+
itemData[archiveService.markerKey()] = FieldValue.delete();
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
batch.set(docRef, itemData, { merge: true });
|