backend-manager 3.2.61 → 3.2.62
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/package.json
CHANGED
|
@@ -168,7 +168,7 @@ Module.prototype.clearFirestore = function() {
|
|
|
168
168
|
// Clear temporary/usage in firestore by deleting the doc
|
|
169
169
|
admin.firestore().collection('temporary').listDocuments()
|
|
170
170
|
.then((snap) => {
|
|
171
|
-
const chunks = []
|
|
171
|
+
const chunks = [];
|
|
172
172
|
for (let i = 0; i < snap.length; i += 500) {
|
|
173
173
|
chunks.push(snap.slice(i, i + 500))
|
|
174
174
|
}
|
|
@@ -196,32 +196,41 @@ Utilities.prototype.get = function (docPath, options) {
|
|
|
196
196
|
options.maxAge = options.maxAge || (1000 * 60 * 5); // 5 minutes
|
|
197
197
|
options.readTime = typeof options.readTime === 'undefined' ? null : options.readTime;
|
|
198
198
|
options.log = typeof options.log === 'undefined' ? false : options.log;
|
|
199
|
+
options.format = typeof options.format === 'undefined' ? 'raw' : options.format;
|
|
199
200
|
|
|
200
201
|
self.cache = self.cache || Manager.storage({name: 'cache', temporary: true, clear: false});
|
|
201
202
|
|
|
202
203
|
const item = self.cache.get(docPath).value();
|
|
203
204
|
const age = item ? Date.now() - item.time : null;
|
|
204
205
|
|
|
206
|
+
function _format(doc) {
|
|
207
|
+
if (options.format === 'raw') {
|
|
208
|
+
return doc;
|
|
209
|
+
} else if (options.format === 'data') {
|
|
210
|
+
return doc.data();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Log
|
|
205
215
|
if (options.readTime) {
|
|
206
216
|
const { Timestamp } = require('firebase-admin/firestore')
|
|
207
217
|
const time = Math.round(new Date(options.readTime).getTime() / 1000 / 60);
|
|
208
|
-
const
|
|
218
|
+
const timeLog = new Date(time * 1000 * 60);
|
|
209
219
|
|
|
220
|
+
// Log
|
|
210
221
|
if (options.log) {
|
|
211
|
-
console.log('Read time:',
|
|
222
|
+
console.log('Read time:', timeLog);
|
|
212
223
|
}
|
|
213
224
|
|
|
214
|
-
//
|
|
225
|
+
// Loop docs
|
|
215
226
|
admin.firestore().runTransaction(
|
|
216
227
|
updateFunction => updateFunction.get(admin.firestore().doc(docPath)),
|
|
217
228
|
{readOnly: true, readTime: new Timestamp(time * 60, 0)}
|
|
218
229
|
)
|
|
219
|
-
.then(snap =>
|
|
220
|
-
|
|
221
|
-
})
|
|
222
|
-
.catch(e => reject(e));
|
|
230
|
+
.then((snap) => resolve(_format(snap)))
|
|
231
|
+
.catch((e) => reject(e));
|
|
223
232
|
} else if (item && age && age < options.maxAge) {
|
|
224
|
-
return resolve(item.doc);
|
|
233
|
+
return resolve(_format(item.doc));
|
|
225
234
|
} else {
|
|
226
235
|
admin.firestore().doc(docPath)
|
|
227
236
|
.get()
|
|
@@ -236,9 +245,9 @@ Utilities.prototype.get = function (docPath, options) {
|
|
|
236
245
|
.write();
|
|
237
246
|
}
|
|
238
247
|
|
|
239
|
-
return resolve(doc);
|
|
248
|
+
return resolve(_format(doc));
|
|
240
249
|
})
|
|
241
|
-
.catch(e => reject(e));
|
|
250
|
+
.catch((e) => reject(e));
|
|
242
251
|
}
|
|
243
252
|
});
|
|
244
253
|
};
|