backend-manager 3.0.42 → 3.0.44

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "3.0.42",
3
+ "version": "3.0.44",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -0,0 +1,32 @@
1
+ const _ = require('lodash')
2
+
3
+ function Module() {
4
+
5
+ }
6
+
7
+ Module.prototype.main = function () {
8
+ const self = this;
9
+ const Manager = self.Manager;
10
+ const Api = self.Api;
11
+ const assistant = self.assistant;
12
+ const payload = self.payload;
13
+
14
+ return new Promise(async function(resolve, reject) {
15
+ self.Api.resolveUser({adminRequired: true})
16
+ .then(async (user) => {
17
+ // TODO: resolve the account and send back
18
+ // - Limits for the account
19
+ // - Usage for the account
20
+ // - Plan for the account
21
+
22
+ // used in EM, WM when signing in or running account().resolve()
23
+ // on WM, it should hide and show the auth-xxx-xxx things in WM
24
+ })
25
+ .catch(e => {
26
+ return reject(e);
27
+ })
28
+ });
29
+
30
+ };
31
+
32
+ module.exports = Module;
@@ -22,9 +22,13 @@ Utilities.prototype.iterateCollection = function (callback, options) {
22
22
  options.where = options.where || [];
23
23
  options.orderBy = options.orderBy || null;
24
24
  options.startAt = options.startAt || null;
25
+ options.startAfter = options.startAfter || null;
26
+ options.prefetchCursor = typeof options.prefetchCursor === 'undefined'
27
+ ? (!!options.startAt || !!options.startAfter) && !options.orderBy
28
+ : options.prefetchCursor;
25
29
  options.log = options.log;
26
30
 
27
- function listAllDocuments(nextPageToken) {
31
+ async function listAllDocuments(nextPageToken) {
28
32
  let query = admin.firestore().collection(options.collection)
29
33
 
30
34
  options.where
@@ -36,8 +40,24 @@ Utilities.prototype.iterateCollection = function (callback, options) {
36
40
  query = query.orderBy(options.orderBy);
37
41
  }
38
42
 
39
- if (batch === -1 && options.startAt) {
40
- query = query.startAt(options.startAt);
43
+ if (batch === -1) {
44
+ let prefetchedCursor = null;
45
+
46
+ if (options.prefetchCursor) {
47
+ prefetchedCursor = await admin.firestore().doc(`${options.collection}/${options.startAt || options.startAfter}`)
48
+ .get()
49
+ .catch(e => e);
50
+
51
+ if (prefetchedCursor instanceof Error) {
52
+ return reject(prefetchedCursor);
53
+ }
54
+ }
55
+
56
+ if (options.startAt) {
57
+ query = query.startAt(prefetchedCursor || options.startAt);
58
+ } else if (options.startAfter) {
59
+ query = query.startAfter(prefetchedCursor || options.startAfter);
60
+ }
41
61
  }
42
62
 
43
63
  // Start at next page