@data-weave/backend-firestore 0.6.4 → 0.7.1
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.
|
@@ -44,6 +44,7 @@ class FirestoreDataManager {
|
|
|
44
44
|
this.referenceOptions = {
|
|
45
45
|
readMode: this.managerOptions.readMode,
|
|
46
46
|
snapshotOptions: this.managerOptions.snapshotOptions,
|
|
47
|
+
filterDeleted: this.managerOptions.deleteMode === 'soft',
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
validateOptions(options) {
|
|
@@ -55,7 +56,11 @@ class FirestoreDataManager {
|
|
|
55
56
|
const snapshot = await options.transaction.get(this.firestore.doc(this.collection, id));
|
|
56
57
|
if (!(0, utils_1.checkIfReferenceExists)(snapshot))
|
|
57
58
|
return undefined;
|
|
58
|
-
|
|
59
|
+
const data = snapshot.data(this.referenceOptions.snapshotOptions);
|
|
60
|
+
if (this.managerOptions.deleteMode === 'soft' && data?.deleted === true) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
return data;
|
|
59
64
|
}
|
|
60
65
|
return await ref.resolve();
|
|
61
66
|
}
|
|
@@ -4,6 +4,12 @@ export type { FirestoreReferenceContext } from './errors';
|
|
|
4
4
|
export interface FirestoreReferenceOptions<T> extends LiveReferenceOptions<T> {
|
|
5
5
|
readMode?: FirestoreReadMode;
|
|
6
6
|
snapshotOptions?: FirestoreTypes.SnapshotOptions;
|
|
7
|
+
/**
|
|
8
|
+
* When true, documents flagged as soft-deleted (`__deleted === true`) are treated as
|
|
9
|
+
* non-existent and resolve to `undefined`. Set by the data manager when running in
|
|
10
|
+
* `deleteMode: 'soft'` so single-document reads stay consistent with list queries.
|
|
11
|
+
*/
|
|
12
|
+
filterDeleted?: boolean;
|
|
7
13
|
}
|
|
8
14
|
export declare class FirestoreReference<T extends DocumentData, S extends DocumentData> extends LiveReference<T> {
|
|
9
15
|
private readonly firestore;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FirestoreReference = void 0;
|
|
4
4
|
const datamanager_1 = require("@data-weave/datamanager");
|
|
5
5
|
const errors_1 = require("./errors");
|
|
6
|
+
const FirestoreMetadata_1 = require("./FirestoreMetadata");
|
|
6
7
|
const utils_1 = require("./utils");
|
|
7
8
|
class FirestoreReference extends datamanager_1.LiveReference {
|
|
8
9
|
firestore;
|
|
@@ -63,12 +64,16 @@ class FirestoreReference extends datamanager_1.LiveReference {
|
|
|
63
64
|
}
|
|
64
65
|
unsubscribe() {
|
|
65
66
|
this.unsubscribeFromSnapshot?.();
|
|
66
|
-
this.
|
|
67
|
+
this.onStale();
|
|
67
68
|
}
|
|
68
69
|
parseDocumentSnapshot(docSnapshot) {
|
|
69
70
|
if (!(0, utils_1.checkIfReferenceExists)(docSnapshot))
|
|
70
71
|
throw new Error(`Document does not exist ${this.docRef.path}`);
|
|
71
|
-
|
|
72
|
+
const data = docSnapshot.data(this.options?.snapshotOptions);
|
|
73
|
+
if (this.options?.filterDeleted && data?.deleted === true) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
return data;
|
|
72
77
|
}
|
|
73
78
|
}
|
|
74
79
|
exports.FirestoreReference = FirestoreReference;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@data-weave/backend-firestore",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"author": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"registry": "https://registry.npmjs.org/"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@data-weave/datamanager": "~0.
|
|
26
|
+
"@data-weave/datamanager": "~0.7.1",
|
|
27
27
|
"@firebase/firestore": "^4.7.8",
|
|
28
28
|
"@firebase/functions-types": "^0.6.3",
|
|
29
29
|
"@google-cloud/firestore": "^7.11.1",
|