@edgedev/firebase 1.9.17 → 1.9.18
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/edgeFirebase.ts +41 -16
- package/package.json +1 -1
package/edgeFirebase.ts
CHANGED
|
@@ -1391,28 +1391,52 @@ export const EdgeFirebase = class {
|
|
|
1391
1391
|
collectionPath: string,
|
|
1392
1392
|
docId: string
|
|
1393
1393
|
): Promise<actionResponse> => {
|
|
1394
|
-
// console.log(collectionPath)
|
|
1395
|
-
// console.log(docId)
|
|
1396
1394
|
const canRead = await this.permissionCheck("read", collectionPath + '/' + docId);
|
|
1397
1395
|
this.data[collectionPath + '/' + docId] = {};
|
|
1398
1396
|
this.stopSnapshot(collectionPath + '/' + docId);
|
|
1399
1397
|
this.unsubscibe[collectionPath + '/' + docId] = null;
|
|
1400
1398
|
if (canRead) {
|
|
1401
1399
|
const docRef = doc(this.db, collectionPath, docId);
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1400
|
+
|
|
1401
|
+
return new Promise<actionResponse>((resolve, reject) => {
|
|
1402
|
+
let firstRun = true;
|
|
1403
|
+
const unsubscribe = onSnapshot(docRef, (doc) => {
|
|
1404
|
+
if (doc.exists()) {
|
|
1405
|
+
const item = doc.data();
|
|
1406
|
+
item.docId = doc.id;
|
|
1407
|
+
this.data[collectionPath + '/' + docId] = item;
|
|
1408
|
+
|
|
1409
|
+
// Only resolve the Promise on first run of onSnapshot if document exists
|
|
1410
|
+
if(firstRun) {
|
|
1411
|
+
firstRun = false;
|
|
1412
|
+
resolve(this.sendResponse({
|
|
1413
|
+
success: true,
|
|
1414
|
+
message: "startDocumentSnapshot " + collectionPath + '/' + docId,
|
|
1415
|
+
meta: {}
|
|
1416
|
+
}));
|
|
1417
|
+
}
|
|
1418
|
+
} else {
|
|
1419
|
+
this.data[collectionPath + '/' + docId] = {};
|
|
1420
|
+
|
|
1421
|
+
// Resolve the Promise with failure response if no document exists
|
|
1422
|
+
if(firstRun) {
|
|
1423
|
+
firstRun = false;
|
|
1424
|
+
resolve(this.sendResponse({
|
|
1425
|
+
success: false,
|
|
1426
|
+
message: `No document found in "${collectionPath}/${docId}"`,
|
|
1427
|
+
meta: {}
|
|
1428
|
+
}));
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
}, (error) => {
|
|
1432
|
+
// Reject the Promise with the error response
|
|
1433
|
+
reject(this.sendResponse({
|
|
1434
|
+
success: false,
|
|
1435
|
+
message: `Error fetching document from "${collectionPath}/${docId}": ${error.message}`,
|
|
1436
|
+
meta: {}
|
|
1437
|
+
}));
|
|
1438
|
+
});
|
|
1439
|
+
this.unsubscibe[collectionPath + '/' + docId] = unsubscribe;
|
|
1416
1440
|
});
|
|
1417
1441
|
} else {
|
|
1418
1442
|
return this.sendResponse({
|
|
@@ -1423,6 +1447,7 @@ export const EdgeFirebase = class {
|
|
|
1423
1447
|
}
|
|
1424
1448
|
};
|
|
1425
1449
|
|
|
1450
|
+
|
|
1426
1451
|
public startSnapshot = async (
|
|
1427
1452
|
collectionPath: string,
|
|
1428
1453
|
queryList: FirestoreQuery[] = [],
|