@react-native-firebase/firestore 18.4.0 → 18.6.0

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.
@@ -0,0 +1,202 @@
1
+ /**
2
+ * @typedef {import('..').FirebaseFirestoreTypes.DocumentReference} DocumentReference
3
+ * @typedef {import('..').FirebaseFirestoreTypes.DocumentSnapshot} DocumentSnapshot
4
+ * @typedef {import('..').FirebaseFirestoreTypes.FieldPath} FieldPath
5
+ * @typedef {import('..').FirebaseFirestoreTypes.QueryCompositeFilterConstraint} QueryCompositeFilterConstraint
6
+ * @typedef {import('..').FirebaseFirestoreTypes.QuerySnapshot} QuerySnapshot
7
+ * @typedef {import('..').FirebaseFirestoreTypes.Query} Query
8
+ * @typedef {import('..').FirebaseFirestoreTypes.WhereFilterOp} WhereFilterOp
9
+ * @typedef {import('../FirestoreFilter')._Filter} _Filter
10
+ * @typedef {import('./query').IQueryConstraint} IQueryConstraint
11
+ * @typedef {import('./query').OrderByDirection} OrderByDirection
12
+ * @typedef {import('./query').QueryFieldFilterConstraint} QueryFieldFilterConstraint
13
+ * @typedef {import('./query').QueryLimitConstraint} QueryLimitConstraint
14
+ * @typedef {import('./query').QueryNonFilterConstraint} QueryNonFilterConstraint
15
+ * @typedef {import('./query').QueryOrderByConstraint} QueryOrderByConstraint
16
+ * @typedef {import('./query').QueryStartAtConstraint} QueryStartAtConstraint
17
+ */
18
+
19
+ import { _Filter, Filter } from '../FirestoreFilter';
20
+
21
+ /**
22
+ * @implements {IQueryConstraint}
23
+ */
24
+ class QueryConstraint {
25
+ constructor(type, ...args) {
26
+ this.type = type;
27
+ this._args = args;
28
+ }
29
+
30
+ _apply(query) {
31
+ return query[this.type].apply(query, this._args);
32
+ }
33
+ }
34
+
35
+ /**
36
+ * @param {Query} query
37
+ * @param {QueryCompositeFilterConstraint | QueryConstraint | undefined} queryConstraint
38
+ * @param {(QueryConstraint | QueryNonFilterConstraint)[]} additionalQueryConstraints
39
+ * @returns {Query}
40
+ */
41
+ export function query(query, queryConstraint, ...additionalQueryConstraints) {
42
+ const queryConstraints = [queryConstraint, ...additionalQueryConstraints].filter(
43
+ constraint => constraint !== undefined,
44
+ );
45
+ let q = query;
46
+ for (const queryConstraint of queryConstraints) {
47
+ q = queryConstraint._apply(q);
48
+ }
49
+ return q;
50
+ }
51
+
52
+ /**
53
+ * @param {string | FieldPath} fieldPath
54
+ * @param {WhereFilterOp} opStr
55
+ * @param {unknown} value
56
+ * @returns {QueryFieldFilterConstraint}
57
+ */
58
+ export function where(fieldPath, opStr, value) {
59
+ return new QueryConstraint('where', fieldPath, opStr, value);
60
+ }
61
+
62
+ /**
63
+ * @param {QueryFieldFilterConstraint[]} queries
64
+ * @returns {_Filter[]}
65
+ */
66
+ function getFilterOps(queries) {
67
+ const ops = [];
68
+ for (const query of queries) {
69
+ if (query.type !== 'where') {
70
+ throw 'Not where'; // FIXME: Better error message
71
+ }
72
+
73
+ const args = query._args;
74
+ if (!args.length) {
75
+ throw 'No args'; // FIXME: Better error message
76
+ }
77
+
78
+ if (args[0] instanceof _Filter) {
79
+ ops.push(args[0]);
80
+ continue;
81
+ }
82
+
83
+ const [fieldPath, opStr, value] = args;
84
+ ops.push(Filter(fieldPath, opStr, value));
85
+ }
86
+ return ops;
87
+ }
88
+
89
+ /**
90
+ * @param {QueryFieldFilterConstraint[]} queries
91
+ * @returns {QueryCompositeFilterConstraint}
92
+ */
93
+ export function or(...queries) {
94
+ const ops = getFilterOps(queries);
95
+ return new QueryConstraint('where', Filter.or(...ops));
96
+ }
97
+
98
+ /**
99
+ * @param {QueryFieldFilterConstraint[]} queries
100
+ * @returns {QueryCompositeFilterConstraint}
101
+ */
102
+ export function and(...queries) {
103
+ const ops = getFilterOps(queries);
104
+ return new QueryConstraint('where', Filter.and(...ops));
105
+ }
106
+
107
+ /**
108
+ * @param {string | FieldPath} fieldPath
109
+ * @param {OrderByDirection} directionStr
110
+ * @returns {QueryOrderByConstraint}
111
+ */
112
+ export function orderBy(fieldPath, directionStr) {
113
+ return new QueryConstraint('orderBy', fieldPath, directionStr);
114
+ }
115
+
116
+ /**
117
+ * @param {(unknown | DocumentSnapshot)} docOrFields
118
+ * @returns {QueryStartAtConstraint}
119
+ */
120
+ export function startAt(...docOrFields) {
121
+ return new QueryConstraint('startAt', ...docOrFields);
122
+ }
123
+
124
+ /**
125
+ * @param {(unknown | DocumentSnapshot)} docOrFields
126
+ * @returns {QueryStartAtConstraint}
127
+ */
128
+ export function startAfter(...docOrFields) {
129
+ return new QueryConstraint('startAfter', ...docOrFields);
130
+ }
131
+
132
+ /**
133
+ * @param {number | string | boolean | null} value
134
+ * @param {string?} key
135
+ * @returns {QueryConstraint}
136
+ */
137
+ export function endAt(value, key) {
138
+ if (!key) {
139
+ return new QueryConstraint('endAt', value);
140
+ }
141
+ return new QueryConstraint('endAt', value, key);
142
+ }
143
+
144
+ /**
145
+ * @param {number | string | boolean | null} value
146
+ * @param {string?} key
147
+ * @returns {QueryConstraint}
148
+ */
149
+ export function endBefore(value, key) {
150
+ if (!key) {
151
+ return new QueryConstraint('endBefore', value);
152
+ }
153
+ return new QueryConstraint('endBefore', value, key);
154
+ }
155
+
156
+ /**
157
+ * @param {number} limit
158
+ * @returns {QueryLimitConstraint}
159
+ */
160
+ export function limit(limit) {
161
+ return new QueryConstraint('limit', limit);
162
+ }
163
+
164
+ /**
165
+ * @param {number} limit
166
+ * @returns {QueryConstraint}
167
+ */
168
+ export function limitToLast(limit) {
169
+ return new QueryConstraint('limitToLast', limit);
170
+ }
171
+
172
+ /**
173
+ * @param {Query} query
174
+ * @returns {Promise<QuerySnapshot>}
175
+ */
176
+ export function getDocs(query) {
177
+ return query.get({ source: 'default' });
178
+ }
179
+
180
+ /**
181
+ * @param {Query} query
182
+ * @returns {Promise<QuerySnapshot>}
183
+ */
184
+ export function getDocsFromCache(query) {
185
+ return query.get({ source: 'cache' });
186
+ }
187
+
188
+ /**
189
+ * @param {Query} query
190
+ * @returns {Promise<QuerySnapshot>}
191
+ */
192
+ export function getDocsFromServer(query) {
193
+ return query.get({ source: 'server' });
194
+ }
195
+
196
+ /**
197
+ * @param {DocumentReference} reference
198
+ * @returns {Promise<void>}
199
+ */
200
+ export function deleteDoc(reference) {
201
+ return reference.delete();
202
+ }
@@ -0,0 +1,203 @@
1
+ import { FirebaseFirestoreTypes } from '../index';
2
+
3
+ import DocumentReference = FirebaseFirestoreTypes.DocumentReference;
4
+ import DocumentSnapshot = FirebaseFirestoreTypes.DocumentSnapshot;
5
+ import SnapshotListenOptions = FirebaseFirestoreTypes.SnapshotListenOptions;
6
+ import QuerySnapshot = FirebaseFirestoreTypes.QuerySnapshot;
7
+ import Query = FirebaseFirestoreTypes.Query;
8
+
9
+ export type Unsubscribe = () => void;
10
+ export type FirestoreError = Error;
11
+
12
+ /**
13
+ * Attaches a listener for `DocumentSnapshot` events. You may either pass
14
+ * individual `onNext` and `onError` callbacks or pass a single observer
15
+ * object with `next` and `error` callbacks.
16
+ *
17
+ * NOTE: Although an `onCompletion` callback can be provided, it will
18
+ * never be called because the snapshot stream is never-ending.
19
+ *
20
+ * @param reference - A reference to the document to listen to.
21
+ * @param observer - A single object containing `next` and `error` callbacks.
22
+ * @returns An unsubscribe function that can be called to cancel
23
+ * the snapshot listener.
24
+ */
25
+ export function onSnapshot<T>(
26
+ reference: DocumentReference<T>,
27
+ observer: {
28
+ next?: (snapshot: DocumentSnapshot<T>) => void;
29
+ error?: (error: FirestoreError) => void;
30
+ complete?: () => void;
31
+ },
32
+ ): Unsubscribe;
33
+ /**
34
+ * Attaches a listener for `DocumentSnapshot` events. You may either pass
35
+ * individual `onNext` and `onError` callbacks or pass a single observer
36
+ * object with `next` and `error` callbacks.
37
+ *
38
+ * NOTE: Although an `onCompletion` callback can be provided, it will
39
+ * never be called because the snapshot stream is never-ending.
40
+ *
41
+ * @param reference - A reference to the document to listen to.
42
+ * @param options - Options controlling the listen behavior.
43
+ * @param observer - A single object containing `next` and `error` callbacks.
44
+ * @returns An unsubscribe function that can be called to cancel
45
+ * the snapshot listener.
46
+ */
47
+ export function onSnapshot<T>(
48
+ reference: DocumentReference<T>,
49
+ options: SnapshotListenOptions,
50
+ observer: {
51
+ next?: (snapshot: DocumentSnapshot<T>) => void;
52
+ error?: (error: FirestoreError) => void;
53
+ complete?: () => void;
54
+ },
55
+ ): Unsubscribe;
56
+ /**
57
+ * Attaches a listener for `DocumentSnapshot` events. You may either pass
58
+ * individual `onNext` and `onError` callbacks or pass a single observer
59
+ * object with `next` and `error` callbacks.
60
+ *
61
+ * NOTE: Although an `onCompletion` callback can be provided, it will
62
+ * never be called because the snapshot stream is never-ending.
63
+ *
64
+ * @param reference - A reference to the document to listen to.
65
+ * @param onNext - A callback to be called every time a new `DocumentSnapshot`
66
+ * is available.
67
+ * @param onError - A callback to be called if the listen fails or is
68
+ * cancelled. No further callbacks will occur.
69
+ * @param onCompletion - Can be provided, but will not be called since streams are
70
+ * never ending.
71
+ * @returns An unsubscribe function that can be called to cancel
72
+ * the snapshot listener.
73
+ */
74
+ export function onSnapshot<T>(
75
+ reference: DocumentReference<T>,
76
+ onNext: (snapshot: DocumentSnapshot<T>) => void,
77
+ onError?: (error: FirestoreError) => void,
78
+ onCompletion?: () => void,
79
+ ): Unsubscribe;
80
+ /**
81
+ * Attaches a listener for `DocumentSnapshot` events. You may either pass
82
+ * individual `onNext` and `onError` callbacks or pass a single observer
83
+ * object with `next` and `error` callbacks.
84
+ *
85
+ * NOTE: Although an `onCompletion` callback can be provided, it will
86
+ * never be called because the snapshot stream is never-ending.
87
+ *
88
+ * @param reference - A reference to the document to listen to.
89
+ * @param options - Options controlling the listen behavior.
90
+ * @param onNext - A callback to be called every time a new `DocumentSnapshot`
91
+ * is available.
92
+ * @param onError - A callback to be called if the listen fails or is
93
+ * cancelled. No further callbacks will occur.
94
+ * @param onCompletion - Can be provided, but will not be called since streams are
95
+ * never ending.
96
+ * @returns An unsubscribe function that can be called to cancel
97
+ * the snapshot listener.
98
+ */
99
+ export function onSnapshot<T>(
100
+ reference: DocumentReference<T>,
101
+ options: SnapshotListenOptions,
102
+ onNext: (snapshot: DocumentSnapshot<T>) => void,
103
+ onError?: (error: FirestoreError) => void,
104
+ onCompletion?: () => void,
105
+ ): Unsubscribe;
106
+ /**
107
+ * Attaches a listener for `QuerySnapshot` events. You may either pass
108
+ * individual `onNext` and `onError` callbacks or pass a single observer
109
+ * object with `next` and `error` callbacks. The listener can be cancelled by
110
+ * calling the function that is returned when `onSnapshot` is called.
111
+ *
112
+ * NOTE: Although an `onCompletion` callback can be provided, it will
113
+ * never be called because the snapshot stream is never-ending.
114
+ *
115
+ * @param query - The query to listen to.
116
+ * @param observer - A single object containing `next` and `error` callbacks.
117
+ * @returns An unsubscribe function that can be called to cancel
118
+ * the snapshot listener.
119
+ */
120
+ export function onSnapshot<T>(
121
+ query: Query<T>,
122
+ observer: {
123
+ next?: (snapshot: QuerySnapshot<T>) => void;
124
+ error?: (error: FirestoreError) => void;
125
+ complete?: () => void;
126
+ },
127
+ ): Unsubscribe;
128
+ /**
129
+ * Attaches a listener for `QuerySnapshot` events. You may either pass
130
+ * individual `onNext` and `onError` callbacks or pass a single observer
131
+ * object with `next` and `error` callbacks. The listener can be cancelled by
132
+ * calling the function that is returned when `onSnapshot` is called.
133
+ *
134
+ * NOTE: Although an `onCompletion` callback can be provided, it will
135
+ * never be called because the snapshot stream is never-ending.
136
+ *
137
+ * @param query - The query to listen to.
138
+ * @param options - Options controlling the listen behavior.
139
+ * @param observer - A single object containing `next` and `error` callbacks.
140
+ * @returns An unsubscribe function that can be called to cancel
141
+ * the snapshot listener.
142
+ */
143
+ export function onSnapshot<T>(
144
+ query: Query<T>,
145
+ options: SnapshotListenOptions,
146
+ observer: {
147
+ next?: (snapshot: QuerySnapshot<T>) => void;
148
+ error?: (error: FirestoreError) => void;
149
+ complete?: () => void;
150
+ },
151
+ ): Unsubscribe;
152
+ /**
153
+ * Attaches a listener for `QuerySnapshot` events. You may either pass
154
+ * individual `onNext` and `onError` callbacks or pass a single observer
155
+ * object with `next` and `error` callbacks. The listener can be cancelled by
156
+ * calling the function that is returned when `onSnapshot` is called.
157
+ *
158
+ * NOTE: Although an `onCompletion` callback can be provided, it will
159
+ * never be called because the snapshot stream is never-ending.
160
+ *
161
+ * @param query - The query to listen to.
162
+ * @param onNext - A callback to be called every time a new `QuerySnapshot`
163
+ * is available.
164
+ * @param onCompletion - Can be provided, but will not be called since streams are
165
+ * never ending.
166
+ * @param onError - A callback to be called if the listen fails or is
167
+ * cancelled. No further callbacks will occur.
168
+ * @returns An unsubscribe function that can be called to cancel
169
+ * the snapshot listener.
170
+ */
171
+ export function onSnapshot<T>(
172
+ query: Query<T>,
173
+ onNext: (snapshot: QuerySnapshot<T>) => void,
174
+ onError?: (error: FirestoreError) => void,
175
+ onCompletion?: () => void,
176
+ ): Unsubscribe;
177
+ /**
178
+ * Attaches a listener for `QuerySnapshot` events. You may either pass
179
+ * individual `onNext` and `onError` callbacks or pass a single observer
180
+ * object with `next` and `error` callbacks. The listener can be cancelled by
181
+ * calling the function that is returned when `onSnapshot` is called.
182
+ *
183
+ * NOTE: Although an `onCompletion` callback can be provided, it will
184
+ * never be called because the snapshot stream is never-ending.
185
+ *
186
+ * @param query - The query to listen to.
187
+ * @param options - Options controlling the listen behavior.
188
+ * @param onNext - A callback to be called every time a new `QuerySnapshot`
189
+ * is available.
190
+ * @param onCompletion - Can be provided, but will not be called since streams are
191
+ * never ending.
192
+ * @param onError - A callback to be called if the listen fails or is
193
+ * cancelled. No further callbacks will occur.
194
+ * @returns An unsubscribe function that can be called to cancel
195
+ * the snapshot listener.
196
+ */
197
+ export function onSnapshot<T>(
198
+ query: Query<T>,
199
+ options: SnapshotListenOptions,
200
+ onNext: (snapshot: QuerySnapshot<T>) => void,
201
+ onError?: (error: FirestoreError) => void,
202
+ onCompletion?: () => void,
203
+ ): Unsubscribe;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @typedef {import('../..').FirebaseFirestoreTypes.Query} Query
3
+ * @typedef {import('../..').FirebaseFirestoreTypes.DocumentReference} DocumentReference
4
+ * @typedef {import('snapshot').Unsubscribe} Unsubscribe
5
+ */
6
+
7
+ /**
8
+ * @param {Query | DocumentReference} reference
9
+ * @param {unknown} args
10
+ * @returns {Promise<unknown>}
11
+ */
12
+ export function onSnapshot(reference, ...args) {
13
+ return reference.onSnapshot(...args);
14
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @param {unknown} obj
3
+ * @returns {boolean}
4
+ */
5
+ export function isPartialObserver(obj) {
6
+ const observerMethods = ['next', 'error', 'complete'];
7
+ if (typeof obj !== 'object' || obj == null) return false;
8
+
9
+ for (const method of observerMethods) {
10
+ if (method in obj && typeof obj[method] === 'function') {
11
+ return true;
12
+ }
13
+ }
14
+
15
+ return false;
16
+ }
package/lib/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- module.exports = '18.4.0';
2
+ module.exports = '18.6.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-firebase/firestore",
3
- "version": "18.4.0",
3
+ "version": "18.6.0",
4
4
  "author": "Invertase <oss@invertase.io> (http://invertase.io)",
5
5
  "description": "React Native Firebase - Cloud Firestore is a NoSQL cloud database to store and sync data between your React Native application and Firebase's database. The API matches the Firebase Web SDK whilst taking advantage of the native SDKs performance and offline capabilities.",
6
6
  "main": "lib/index.js",
@@ -27,10 +27,10 @@
27
27
  "firestore"
28
28
  ],
29
29
  "peerDependencies": {
30
- "@react-native-firebase/app": "18.4.0"
30
+ "@react-native-firebase/app": "18.6.0"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
35
- "gitHead": "5f6460a87970d8b6013530de980bc760ddc70f90"
35
+ "gitHead": "adbbd4171adb1e3c2306da1285520abbaf9313b8"
36
36
  }