@react-native-firebase/firestore 21.7.1 → 21.7.3

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.
@@ -229,7 +229,18 @@ RCT_EXPORT_METHOD(aggregateQuery
229
229
  : (RCTPromiseRejectBlock)reject) {
230
230
  FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
231
231
  databaseId:databaseId];
232
- FIRQuery *query = [RNFBFirestoreCommon getQueryForFirestore:firestore path:path type:type];
232
+
233
+ FIRQuery *firestoreBaseQuery = [RNFBFirestoreCommon getQueryForFirestore:firestore
234
+ path:path
235
+ type:type];
236
+ RNFBFirestoreQuery *firestoreQuery =
237
+ [[RNFBFirestoreQuery alloc] initWithModifiers:firestore
238
+ query:firestoreBaseQuery
239
+ filters:filters
240
+ orders:orders
241
+ options:options];
242
+
243
+ FIRQuery *query = [firestoreQuery instance];
233
244
 
234
245
  NSMutableArray<FIRAggregateField *> *aggregateFields =
235
246
  [[NSMutableArray<FIRAggregateField *> alloc] init];
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  *
16
16
  */
17
-
17
+ import { createDeprecationProxy } from '@react-native-firebase/app/lib/common';
18
18
  import FirestoreDocumentSnapshot from './FirestoreDocumentSnapshot';
19
19
 
20
20
  const TYPE_MAP = {
@@ -31,7 +31,9 @@ export default class FirestoreDocumentChange {
31
31
  }
32
32
 
33
33
  get doc() {
34
- return new FirestoreDocumentSnapshot(this._firestore, this._nativeData.doc);
34
+ return createDeprecationProxy(
35
+ new FirestoreDocumentSnapshot(this._firestore, this._nativeData.doc),
36
+ );
35
37
  }
36
38
 
37
39
  get newIndex() {
@@ -15,7 +15,13 @@
15
15
  *
16
16
  */
17
17
 
18
- import { isObject, isString, isUndefined } from '@react-native-firebase/app/lib/common';
18
+ import {
19
+ isObject,
20
+ isString,
21
+ isUndefined,
22
+ createDeprecationProxy,
23
+ filterModularArgument,
24
+ } from '@react-native-firebase/app/lib/common';
19
25
  import NativeError from '@react-native-firebase/app/lib/internal/NativeFirebaseError';
20
26
  import { parseSetOptions, parseSnapshotArgs, parseUpdateArgs } from './utils';
21
27
  import { buildNativeMap, provideDocumentReferenceClass } from './utils/serialize';
@@ -103,7 +109,7 @@ export default class FirestoreDocumentReference {
103
109
 
104
110
  return this._firestore.native
105
111
  .documentGet(this.path, options)
106
- .then(data => new FirestoreDocumentSnapshot(this._firestore, data));
112
+ .then(data => createDeprecationProxy(new FirestoreDocumentSnapshot(this._firestore, data)));
107
113
  }
108
114
 
109
115
  isEqual(other) {
@@ -154,9 +160,8 @@ export default class FirestoreDocumentReference {
154
160
  if (event.body.error) {
155
161
  handleError(NativeError.fromEvent(event.body.error, 'firestore'));
156
162
  } else {
157
- const documentSnapshot = new FirestoreDocumentSnapshot(
158
- this._firestore,
159
- event.body.snapshot,
163
+ const documentSnapshot = createDeprecationProxy(
164
+ new FirestoreDocumentSnapshot(this._firestore, event.body.snapshot),
160
165
  );
161
166
  handleSuccess(documentSnapshot);
162
167
  }
@@ -193,7 +198,8 @@ export default class FirestoreDocumentReference {
193
198
  }
194
199
 
195
200
  update(...args) {
196
- if (args.length === 0) {
201
+ const updatedArgs = filterModularArgument(args);
202
+ if (updatedArgs.length === 0) {
197
203
  throw new Error(
198
204
  'firebase.firestore().doc().update(*) expected at least 1 argument but was called with 0 arguments.',
199
205
  );
@@ -201,7 +207,7 @@ export default class FirestoreDocumentReference {
201
207
 
202
208
  let data;
203
209
  try {
204
- data = parseUpdateArgs(args);
210
+ data = parseUpdateArgs(updatedArgs);
205
211
  } catch (e) {
206
212
  throw new Error(`firebase.firestore().doc().update(*) ${e.message}`);
207
213
  }
@@ -21,6 +21,8 @@ import {
21
21
  isObject,
22
22
  isString,
23
23
  isUndefined,
24
+ filterModularArgument,
25
+ createDeprecationProxy,
24
26
  } from '@react-native-firebase/app/lib/common';
25
27
  import NativeError from '@react-native-firebase/app/lib/internal/NativeFirebaseError';
26
28
  import { FirestoreAggregateQuery } from './FirestoreAggregate';
@@ -133,33 +135,35 @@ export default class FirestoreQuery {
133
135
  }
134
136
 
135
137
  count() {
136
- return new FirestoreAggregateQuery(
137
- this._firestore,
138
- this,
139
- this._collectionPath,
140
- this._modifiers,
138
+ return createDeprecationProxy(
139
+ new FirestoreAggregateQuery(this._firestore, this, this._collectionPath, this._modifiers),
141
140
  );
142
141
  }
143
142
 
144
143
  countFromServer() {
144
+ // deprecation warning called in count()
145
145
  return this.count();
146
146
  }
147
147
 
148
148
  endAt(docOrField, ...fields) {
149
- return new FirestoreQuery(
150
- this._firestore,
151
- this._collectionPath,
152
- this._handleQueryCursor('endAt', docOrField, fields),
153
- this._queryName,
149
+ return createDeprecationProxy(
150
+ new FirestoreQuery(
151
+ this._firestore,
152
+ this._collectionPath,
153
+ this._handleQueryCursor('endAt', docOrField, filterModularArgument(fields)),
154
+ this._queryName,
155
+ ),
154
156
  );
155
157
  }
156
158
 
157
159
  endBefore(docOrField, ...fields) {
158
- return new FirestoreQuery(
159
- this._firestore,
160
- this._collectionPath,
161
- this._handleQueryCursor('endBefore', docOrField, fields),
162
- this._queryName,
160
+ return createDeprecationProxy(
161
+ new FirestoreQuery(
162
+ this._firestore,
163
+ this._collectionPath,
164
+ this._handleQueryCursor('endBefore', docOrField, filterModularArgument(fields)),
165
+ this._queryName,
166
+ ),
163
167
  );
164
168
  }
165
169
 
@@ -250,7 +254,9 @@ export default class FirestoreQuery {
250
254
 
251
255
  const modifiers = this._modifiers._copy().limit(limit);
252
256
 
253
- return new FirestoreQuery(this._firestore, this._collectionPath, modifiers, this._queryName);
257
+ return createDeprecationProxy(
258
+ new FirestoreQuery(this._firestore, this._collectionPath, modifiers, this._queryName),
259
+ );
254
260
  }
255
261
 
256
262
  limitToLast(limitToLast) {
@@ -262,7 +268,9 @@ export default class FirestoreQuery {
262
268
 
263
269
  const modifiers = this._modifiers._copy().limitToLast(limitToLast);
264
270
 
265
- return new FirestoreQuery(this._firestore, this._collectionPath, modifiers, this._queryName);
271
+ return createDeprecationProxy(
272
+ new FirestoreQuery(this._firestore, this._collectionPath, modifiers, this._queryName),
273
+ );
266
274
  }
267
275
 
268
276
  onSnapshot(...args) {
@@ -274,7 +282,7 @@ export default class FirestoreQuery {
274
282
  this._modifiers.validatelimitToLast();
275
283
 
276
284
  try {
277
- const options = parseSnapshotArgs(args);
285
+ const options = parseSnapshotArgs(filterModularArgument(args));
278
286
  snapshotListenOptions = options.snapshotListenOptions;
279
287
  callback = options.callback;
280
288
  onNext = options.onNext;
@@ -386,24 +394,30 @@ export default class FirestoreQuery {
386
394
  throw new Error(`firebase.firestore().collection().orderBy() ${e.message}`);
387
395
  }
388
396
 
389
- return new FirestoreQuery(this._firestore, this._collectionPath, modifiers, this._queryName);
397
+ return createDeprecationProxy(
398
+ new FirestoreQuery(this._firestore, this._collectionPath, modifiers, this._queryName),
399
+ );
390
400
  }
391
401
 
392
402
  startAfter(docOrField, ...fields) {
393
- return new FirestoreQuery(
394
- this._firestore,
395
- this._collectionPath,
396
- this._handleQueryCursor('startAfter', docOrField, fields),
397
- this._queryName,
403
+ return createDeprecationProxy(
404
+ new FirestoreQuery(
405
+ this._firestore,
406
+ this._collectionPath,
407
+ this._handleQueryCursor('startAfter', docOrField, filterModularArgument(fields)),
408
+ this._queryName,
409
+ ),
398
410
  );
399
411
  }
400
412
 
401
413
  startAt(docOrField, ...fields) {
402
- return new FirestoreQuery(
403
- this._firestore,
404
- this._collectionPath,
405
- this._handleQueryCursor('startAt', docOrField, fields),
406
- this._queryName,
414
+ return createDeprecationProxy(
415
+ new FirestoreQuery(
416
+ this._firestore,
417
+ this._collectionPath,
418
+ this._handleQueryCursor('startAt', docOrField, filterModularArgument(fields)),
419
+ this._queryName,
420
+ ),
407
421
  );
408
422
  }
409
423
 
@@ -487,6 +501,8 @@ export default class FirestoreQuery {
487
501
  throw new Error(`firebase.firestore().collection().where() ${e.message}`);
488
502
  }
489
503
 
490
- return new FirestoreQuery(this._firestore, this._collectionPath, modifiers, this._queryName);
504
+ return createDeprecationProxy(
505
+ new FirestoreQuery(this._firestore, this._collectionPath, modifiers, this._queryName),
506
+ );
491
507
  }
492
508
  }
@@ -20,6 +20,7 @@ import {
20
20
  isFunction,
21
21
  isObject,
22
22
  isUndefined,
23
+ createDeprecationProxy,
23
24
  } from '@react-native-firebase/app/lib/common';
24
25
  import FirestoreDocumentChange from './FirestoreDocumentChange';
25
26
  import FirestoreDocumentSnapshot from './FirestoreDocumentSnapshot';
@@ -31,7 +32,9 @@ export default class FirestoreQuerySnapshot {
31
32
  this._source = nativeData.source;
32
33
  this._excludesMetadataChanges = nativeData.excludesMetadataChanges;
33
34
  this._changes = nativeData.changes.map($ => new FirestoreDocumentChange(firestore, $));
34
- this._docs = nativeData.documents.map($ => new FirestoreDocumentSnapshot(firestore, $));
35
+ this._docs = nativeData.documents.map($ =>
36
+ createDeprecationProxy(new FirestoreDocumentSnapshot(firestore, $)),
37
+ );
35
38
  this._metadata = new FirestoreSnapshotMetadata(nativeData.metadata);
36
39
  }
37
40
 
@@ -15,6 +15,7 @@
15
15
  *
16
16
  */
17
17
 
18
+ import { createDeprecationProxy } from '@react-native-firebase/app/lib/common';
18
19
  import { getReactNativeModule } from '@react-native-firebase/app/lib/internal/nativeModule';
19
20
  import FirestoreBlob from './FirestoreBlob';
20
21
  import FirestoreFieldPath from './FirestoreFieldPath';
@@ -25,10 +26,10 @@ import { Filter } from './FirestoreFilter';
25
26
  export default {
26
27
  Blob: FirestoreBlob,
27
28
  FieldPath: FirestoreFieldPath,
28
- FieldValue: FirestoreFieldValue,
29
+ FieldValue: createDeprecationProxy(FirestoreFieldValue),
29
30
  GeoPoint: FirestoreGeoPoint,
30
- Timestamp: FirestoreTimestamp,
31
- Filter: Filter,
31
+ Timestamp: createDeprecationProxy(FirestoreTimestamp),
32
+ Filter: createDeprecationProxy(Filter),
32
33
 
33
34
  CACHE_SIZE_UNLIMITED: -1,
34
35
 
@@ -15,7 +15,7 @@
15
15
  *
16
16
  */
17
17
 
18
- import { isObject } from '@react-native-firebase/app/lib/common';
18
+ import { isObject, createDeprecationProxy } from '@react-native-firebase/app/lib/common';
19
19
  import FirestoreDocumentReference from './FirestoreDocumentReference';
20
20
  import FirestoreDocumentSnapshot from './FirestoreDocumentSnapshot';
21
21
  import { parseSetOptions, parseUpdateArgs } from './utils';
@@ -52,7 +52,7 @@ export default class FirestoreTransaction {
52
52
  this._calledGetCount++;
53
53
  return this._firestore.native
54
54
  .transactionGetDocument(this._meta.id, documentRef.path)
55
- .then(data => new FirestoreDocumentSnapshot(this._firestore, data));
55
+ .then(data => createDeprecationProxy(new FirestoreDocumentSnapshot(this._firestore, data)));
56
56
  }
57
57
 
58
58
  /**
package/lib/index.d.ts CHANGED
@@ -2392,7 +2392,6 @@ export default defaultExport;
2392
2392
  * Attach namespace to `firebase.` and `FirebaseApp.`.
2393
2393
  */
2394
2394
  declare module '@react-native-firebase/app' {
2395
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2396
2395
  namespace ReactNativeFirebase {
2397
2396
  import FirebaseModuleWithStaticsAndApp = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp;
2398
2397
  interface Module {
package/lib/index.js CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  isString,
24
24
  isUndefined,
25
25
  isAndroid,
26
+ createDeprecationProxy,
26
27
  } from '@react-native-firebase/app/lib/common';
27
28
  import { setReactNativeModule } from '@react-native-firebase/app/lib/internal/nativeModule';
28
29
  import {
@@ -175,7 +176,7 @@ class FirebaseFirestoreModule extends FirebaseModule {
175
176
  );
176
177
  }
177
178
 
178
- return new FirestoreCollectionReference(this, path);
179
+ return createDeprecationProxy(new FirestoreCollectionReference(this, path));
179
180
  }
180
181
 
181
182
  collectionGroup(collectionId) {
@@ -197,11 +198,13 @@ class FirebaseFirestoreModule extends FirebaseModule {
197
198
  );
198
199
  }
199
200
 
200
- return new FirestoreQuery(
201
- this,
202
- this._referencePath.child(collectionId),
203
- new FirestoreQueryModifiers().asCollectionGroupQuery(),
204
- undefined,
201
+ return createDeprecationProxy(
202
+ new FirestoreQuery(
203
+ this,
204
+ this._referencePath.child(collectionId),
205
+ new FirestoreQueryModifiers().asCollectionGroupQuery(),
206
+ undefined,
207
+ ),
205
208
  );
206
209
  }
207
210
 
@@ -224,7 +227,7 @@ class FirebaseFirestoreModule extends FirebaseModule {
224
227
  throw new Error("firebase.firestore().doc(*) 'documentPath' must point to a document.");
225
228
  }
226
229
 
227
- return new FirestoreDocumentReference(this, path);
230
+ return createDeprecationProxy(new FirestoreDocumentReference(this, path));
228
231
  }
229
232
 
230
233
  async enableNetwork() {
@@ -377,7 +380,7 @@ class FirebaseFirestoreModule extends FirebaseModule {
377
380
  if (this._settings.persistence === false) {
378
381
  return null;
379
382
  }
380
- return new FirestorePersistentCacheIndexManager(this);
383
+ return createDeprecationProxy(new FirestorePersistentCacheIndexManager(this));
381
384
  }
382
385
  }
383
386
 
@@ -96,6 +96,9 @@ export type WithFieldValue<T> =
96
96
  ? { [K in keyof T]: WithFieldValue<T[K]> | FieldValue }
97
97
  : never);
98
98
 
99
+ export type EmulatorMockTokenOptions = ({ user_id: string } | { sub: string }) &
100
+ Partial<FirebaseIdToken>;
101
+
99
102
  /**
100
103
  * Returns the existing default {@link Firestore} instance that is associated with the
101
104
  * default {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
@@ -131,6 +134,24 @@ export function getFirestore(app?: FirebaseApp): Firestore;
131
134
  */
132
135
  export declare function getFirestore(app?: FirebaseApp, databaseId?: string): Firestore;
133
136
 
137
+ /**
138
+ * Modify this instance to communicate with the Cloud Firestore emulator.
139
+ *
140
+ * @param firestore - A reference to the root `Firestore` instance.
141
+ * instance is associated with.
142
+ * @param host: emulator host (eg, 'localhost')
143
+ * @param port: emulator port (eg, 8080)
144
+ * @param options.mockUserToken - the mock auth token to use for unit testing
145
+ * @returns void.
146
+ */
147
+ export declare function connectFirestoreEmulator(
148
+ firestore: Firestore,
149
+ host: string,
150
+ port: number,
151
+ options?: {
152
+ mockUserToken?: EmulatorMockTokenOptions | string;
153
+ },
154
+ ): void;
134
155
  /**
135
156
  * Gets a `DocumentReference` instance that refers to the document at the
136
157
  * specified absolute path.
@@ -373,10 +394,19 @@ export function disableNetwork(firestore: Firestore): Promise<void>;
373
394
  * Aimed primarily at clearing up any data cached from running tests. Needs to be executed before any database calls
374
395
  * are made.
375
396
  *
397
+ * Deprecated, please use `clearIndexedDbPersistence` instead.
376
398
  * @param firestore - A reference to the root `Firestore` instance.
377
399
  */
378
400
  export function clearPersistence(firestore: Firestore): Promise<void>;
379
401
 
402
+ /**
403
+ * Aimed primarily at clearing up any data cached from running tests. Needs to be executed before any database calls
404
+ * are made.
405
+ *
406
+ * @param firestore - A reference to the root `Firestore` instance.
407
+ */
408
+ export function clearIndexedDbPersistence(firestore: Firestore): Promise<void>;
409
+
380
410
  /**
381
411
  * Terminates the provided {@link Firestore} instance.
382
412
  *
@@ -503,6 +533,62 @@ interface AggregateSpec {
503
533
  [field: string]: AggregateFieldType;
504
534
  }
505
535
 
536
+ interface FirebaseIdToken {
537
+ // Always set to https://securetoken.google.com/PROJECT_ID
538
+ iss: string;
539
+
540
+ // Always set to PROJECT_ID
541
+ aud: string;
542
+
543
+ // The user's unique ID
544
+ sub: string;
545
+
546
+ // The token issue time, in seconds since epoch
547
+ iat: number;
548
+
549
+ // The token expiry time, normally 'iat' + 3600
550
+ exp: number;
551
+
552
+ // The user's unique ID. Must be equal to 'sub'
553
+ user_id: string;
554
+
555
+ // The time the user authenticated, normally 'iat'
556
+ auth_time: number;
557
+
558
+ // The sign in provider, only set when the provider is 'anonymous'
559
+ provider_id?: 'anonymous';
560
+
561
+ // The user's primary email
562
+ email?: string;
563
+
564
+ // The user's email verification status
565
+ email_verified?: boolean;
566
+
567
+ // The user's primary phone number
568
+ phone_number?: string;
569
+
570
+ // The user's display name
571
+ name?: string;
572
+
573
+ // The user's profile photo URL
574
+ picture?: string;
575
+
576
+ // Information on all identities linked to this user
577
+ firebase: {
578
+ // The primary sign-in provider
579
+ sign_in_provider: FirebaseSignInProvider;
580
+
581
+ // A map of providers to the user's list of unique identifiers from
582
+ // each provider
583
+ identities?: { [provider in FirebaseSignInProvider]?: string[] };
584
+ };
585
+
586
+ // Custom claims set by the developer
587
+ [claim: string]: unknown;
588
+
589
+ uid?: never; // Try to catch a common mistake of "uid" (should be "sub" instead).
590
+ }
591
+
506
592
  /**
507
593
  * The union of all `AggregateField` types that are supported by Firestore.
508
594
  */