@edgedev/firebase 1.0.14 → 1.0.17
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/index.ts +19 -3
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -8,7 +8,10 @@ import {
|
|
|
8
8
|
updateDoc,
|
|
9
9
|
doc,
|
|
10
10
|
query,
|
|
11
|
-
onSnapshot
|
|
11
|
+
onSnapshot,
|
|
12
|
+
WhereFilterOp,
|
|
13
|
+
QueryConstraint,
|
|
14
|
+
where
|
|
12
15
|
} from "firebase/firestore";
|
|
13
16
|
|
|
14
17
|
const firebaseConfig = {
|
|
@@ -31,10 +34,16 @@ export const unsubscibe: object = reactive({});
|
|
|
31
34
|
export const user: object = ref({});
|
|
32
35
|
|
|
33
36
|
// Composable to start snapshot listener and set unsubscribe function
|
|
34
|
-
export const startSnapshot = (
|
|
37
|
+
export const startSnapshot = (
|
|
38
|
+
collectionPath: string,
|
|
39
|
+
queryList: FirestoreQuery[] = []
|
|
40
|
+
): void => {
|
|
35
41
|
// This first "if" is to prevent multiple listeners on the same collection
|
|
36
42
|
if (!(data[collectionPath] instanceof Function)) {
|
|
37
|
-
const
|
|
43
|
+
const queryConditions: QueryConstraint[] = queryList.map((condition) =>
|
|
44
|
+
where(condition.field, condition.operator, condition.value)
|
|
45
|
+
);
|
|
46
|
+
const q = query(collection(db, collectionPath), ...queryConditions);
|
|
38
47
|
const unsubscribe = onSnapshot(q, (querySnapshot) => {
|
|
39
48
|
const items = {};
|
|
40
49
|
querySnapshot.forEach((doc) => {
|
|
@@ -52,6 +61,7 @@ export const storeDoc = (collectionPath: string, item: object): void => {
|
|
|
52
61
|
const cloneItem = JSON.parse(JSON.stringify(item));
|
|
53
62
|
const current_time = new Date().getTime();
|
|
54
63
|
cloneItem.last_updated = current_time;
|
|
64
|
+
cloneItem.uid = null;
|
|
55
65
|
if (Object.prototype.hasOwnProperty.call(user, "uid")) {
|
|
56
66
|
cloneItem.uid = user["uid"];
|
|
57
67
|
}
|
|
@@ -81,3 +91,9 @@ export const stopSnapshot = (collectionPath: string): void => {
|
|
|
81
91
|
unsubscibe[collectionPath] = null;
|
|
82
92
|
}
|
|
83
93
|
};
|
|
94
|
+
|
|
95
|
+
interface FirestoreQuery {
|
|
96
|
+
field: string;
|
|
97
|
+
operator: WhereFilterOp; // '==' | '<' | '<=' | '>' | '>=' | 'array-contains' | 'in' | 'array-contains-any';
|
|
98
|
+
value: unknown;
|
|
99
|
+
}
|