@edgedev/firebase 1.9.7 → 1.9.8

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.
Files changed (2) hide show
  1. package/edgeFirebase.ts +24 -10
  2. package/package.json +1 -1
package/edgeFirebase.ts CHANGED
@@ -1303,8 +1303,8 @@ export const EdgeFirebase = class {
1303
1303
  collectionPath: string,
1304
1304
  docId: string
1305
1305
  ): Promise<actionResponse> => {
1306
- console.log(collectionPath)
1307
- console.log(docId)
1306
+ // console.log(collectionPath)
1307
+ // console.log(docId)
1308
1308
  const canRead = await this.permissionCheck("read", collectionPath + '/' + docId);
1309
1309
  this.data[collectionPath + '/' + docId] = {};
1310
1310
  this.stopSnapshot(collectionPath + '/' + docId);
@@ -1347,8 +1347,9 @@ export const EdgeFirebase = class {
1347
1347
  this.unsubscibe[collectionPath] = null;
1348
1348
  if (canRead) {
1349
1349
  const q = this.getQuery(collectionPath, queryList, orderList, max);
1350
-
1350
+
1351
1351
  return new Promise<actionResponse>((resolve, reject) => {
1352
+ let firstRun = true;
1352
1353
  const unsubscribe = onSnapshot(q, (querySnapshot) => {
1353
1354
  const items = {};
1354
1355
  querySnapshot.forEach((doc) => {
@@ -1358,13 +1359,25 @@ export const EdgeFirebase = class {
1358
1359
  });
1359
1360
  this.data[collectionPath] = items;
1360
1361
  this.unsubscibe[collectionPath] = unsubscribe;
1361
-
1362
- // Resolve the Promise with the success response
1363
- resolve(this.sendResponse({
1364
- success: true,
1365
- message: "",
1366
- meta: {}
1367
- }));
1362
+
1363
+ // Only resolve or reject the Promise on first run of onSnapshot
1364
+ if(firstRun) {
1365
+ if(Object.keys(items).length > 0) { // resolve if items fetched
1366
+ firstRun = false;
1367
+ resolve(this.sendResponse({
1368
+ success: true,
1369
+ message: "",
1370
+ meta: {}
1371
+ }));
1372
+ } else { // reject if no items fetched
1373
+ firstRun = false;
1374
+ reject(this.sendResponse({
1375
+ success: false,
1376
+ message: `No data found in "${collectionPath}"`,
1377
+ meta: {}
1378
+ }));
1379
+ }
1380
+ }
1368
1381
  }, (error) => {
1369
1382
  // Reject the Promise with the error response
1370
1383
  reject(this.sendResponse({
@@ -1382,6 +1395,7 @@ export const EdgeFirebase = class {
1382
1395
  });
1383
1396
  }
1384
1397
  };
1398
+
1385
1399
 
1386
1400
  private usersSnapshotStarting = false;
1387
1401
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgedev/firebase",
3
- "version": "1.9.7",
3
+ "version": "1.9.8",
4
4
  "description": "Vue 3 / Nuxt 3 Plugin or Nuxt 3 plugin for firebase authentication and firestore.",
5
5
  "main": "index.ts",
6
6
  "scripts": {