18
18
import * as legacy from '@firebase/firestore-types' ;
19
19
import * as exp from '../index' ;
20
20
21
- import {
22
- addDoc ,
23
- doc ,
24
- FieldPath as FieldPathExp ,
25
- getDocs ,
26
- getDocsFromCache ,
27
- getDocsFromServer ,
28
- onSnapshot ,
29
- query ,
30
- queryEqual ,
31
- refEqual ,
32
- endAt ,
33
- endBefore ,
34
- startAfter ,
35
- startAt ,
36
- limitToLast ,
37
- limit ,
38
- orderBy ,
39
- where ,
40
- Bytes as BytesExp
41
- } from '../../exp/index' ;
42
- import { UntypedFirestoreDataConverter } from '../../src/api/user_data_reader' ;
21
+ import { FieldPath as FieldPathExp , Bytes as BytesExp } from '../../exp/index' ;
43
22
import {
44
23
isPlainObject ,
45
24
validateSetOptions
@@ -48,10 +27,7 @@ import { Compat } from '../../src/compat/compat';
48
27
import {
49
28
Firestore ,
50
29
DocumentReference ,
51
- DocumentSnapshot ,
52
- QuerySnapshot ,
53
- wrapObserver ,
54
- extractSnapshotOptions
30
+ DocumentSnapshot
55
31
} from '../../src/api/database' ;
56
32
57
33
export { GeoPoint , Timestamp } from '../index' ;
@@ -185,182 +161,6 @@ export class WriteBatch
185
161
}
186
162
}
187
163
188
- export class Query < T = legacy . DocumentData >
189
- extends Compat < exp . Query < T > >
190
- implements legacy . Query < T > {
191
- constructor ( readonly firestore : Firestore , delegate : exp . Query < T > ) {
192
- super ( delegate ) ;
193
- }
194
-
195
- where (
196
- fieldPath : string | FieldPath ,
197
- opStr : legacy . WhereFilterOp ,
198
- value : any
199
- ) : Query < T > {
200
- return new Query < T > (
201
- this . firestore ,
202
- query ( this . _delegate , where ( unwrap ( fieldPath ) , opStr , unwrap ( value ) ) )
203
- ) ;
204
- }
205
-
206
- orderBy (
207
- fieldPath : string | FieldPath ,
208
- directionStr ?: legacy . OrderByDirection
209
- ) : Query < T > {
210
- return new Query < T > (
211
- this . firestore ,
212
- query ( this . _delegate , orderBy ( unwrap ( fieldPath ) , directionStr ) )
213
- ) ;
214
- }
215
-
216
- limit ( n : number ) : Query < T > {
217
- return new Query < T > ( this . firestore , query ( this . _delegate , limit ( n ) ) ) ;
218
- }
219
-
220
- limitToLast ( n : number ) : Query < T > {
221
- return new Query < T > ( this . firestore , query ( this . _delegate , limitToLast ( n ) ) ) ;
222
- }
223
-
224
- startAt ( ...args : any [ ] ) : Query < T > {
225
- return new Query (
226
- this . firestore ,
227
- query ( this . _delegate , startAt ( ...unwrap ( args ) ) )
228
- ) ;
229
- }
230
-
231
- startAfter ( ...args : any [ ] ) : Query < T > {
232
- return new Query (
233
- this . firestore ,
234
- query ( this . _delegate , startAfter ( ...unwrap ( args ) ) )
235
- ) ;
236
- }
237
-
238
- endBefore ( ...args : any [ ] ) : Query < T > {
239
- return new Query (
240
- this . firestore ,
241
- query ( this . _delegate , endBefore ( ...unwrap ( args ) ) )
242
- ) ;
243
- }
244
-
245
- endAt ( ...args : any [ ] ) : Query < T > {
246
- return new Query (
247
- this . firestore ,
248
- query ( this . _delegate , endAt ( ...unwrap ( args ) ) )
249
- ) ;
250
- }
251
-
252
- isEqual ( other : legacy . Query < T > ) : boolean {
253
- return queryEqual ( this . _delegate , ( other as Query < T > ) . _delegate ) ;
254
- }
255
-
256
- get ( options ?: legacy . GetOptions ) : Promise < QuerySnapshot < T > > {
257
- let query : Promise < exp . QuerySnapshot < T > > ;
258
- if ( options ?. source === 'cache' ) {
259
- query = getDocsFromCache ( this . _delegate ) ;
260
- } else if ( options ?. source === 'server' ) {
261
- query = getDocsFromServer ( this . _delegate ) ;
262
- } else {
263
- query = getDocs ( this . _delegate ) ;
264
- }
265
- return query . then ( result => new QuerySnapshot ( this . firestore , result ) ) ;
266
- }
267
-
268
- onSnapshot ( observer : {
269
- next ?: ( snapshot : QuerySnapshot < T > ) => void ;
270
- error ?: ( error : legacy . FirestoreError ) => void ;
271
- complete ?: ( ) => void ;
272
- } ) : ( ) => void ;
273
- onSnapshot (
274
- options : legacy . SnapshotListenOptions ,
275
- observer : {
276
- next ?: ( snapshot : QuerySnapshot < T > ) => void ;
277
- error ?: ( error : legacy . FirestoreError ) => void ;
278
- complete ?: ( ) => void ;
279
- }
280
- ) : ( ) => void ;
281
- onSnapshot (
282
- onNext : ( snapshot : QuerySnapshot < T > ) => void ,
283
- onError ?: ( error : legacy . FirestoreError ) => void ,
284
- onCompletion ?: ( ) => void
285
- ) : ( ) => void ;
286
- onSnapshot (
287
- options : legacy . SnapshotListenOptions ,
288
- onNext : ( snapshot : QuerySnapshot < T > ) => void ,
289
- onError ?: ( error : legacy . FirestoreError ) => void ,
290
- onCompletion ?: ( ) => void
291
- ) : ( ) => void ;
292
- onSnapshot ( ...args : any ) : ( ) => void {
293
- const options = extractSnapshotOptions ( args ) ;
294
- const observer = wrapObserver < QuerySnapshot < T > , exp . QuerySnapshot < T > > (
295
- args ,
296
- snap => new QuerySnapshot ( this . firestore , snap )
297
- ) ;
298
- return onSnapshot ( this . _delegate , options , observer ) ;
299
- }
300
-
301
- withConverter < U > ( converter : legacy . FirestoreDataConverter < U > ) : Query < U > {
302
- return new Query < U > (
303
- this . firestore ,
304
- this . _delegate . withConverter (
305
- converter as UntypedFirestoreDataConverter < U >
306
- )
307
- ) ;
308
- }
309
- }
310
-
311
- export class CollectionReference < T = legacy . DocumentData >
312
- extends Query < T >
313
- implements legacy . CollectionReference < T > {
314
- constructor (
315
- readonly firestore : Firestore ,
316
- readonly _delegate : exp . CollectionReference < T >
317
- ) {
318
- super ( firestore , _delegate ) ;
319
- }
320
-
321
- readonly id = this . _delegate . id ;
322
- readonly path = this . _delegate . path ;
323
-
324
- get parent ( ) : DocumentReference < legacy . DocumentData > | null {
325
- const docRef = this . _delegate . parent ;
326
- return docRef
327
- ? new DocumentReference < legacy . DocumentData > ( this . firestore , docRef )
328
- : null ;
329
- }
330
-
331
- doc ( documentPath ?: string ) : DocumentReference < T > {
332
- if ( documentPath !== undefined ) {
333
- return new DocumentReference (
334
- this . firestore ,
335
- doc ( this . _delegate , documentPath )
336
- ) ;
337
- } else {
338
- return new DocumentReference ( this . firestore , doc ( this . _delegate ) ) ;
339
- }
340
- }
341
-
342
- add ( data : T ) : Promise < DocumentReference < T > > {
343
- return addDoc ( this . _delegate , unwrap ( data ) ) . then (
344
- docRef => new DocumentReference ( this . firestore , docRef )
345
- ) ;
346
- }
347
-
348
- isEqual ( other : CollectionReference < T > ) : boolean {
349
- return refEqual ( this . _delegate , other . _delegate ) ;
350
- }
351
-
352
- withConverter < U > (
353
- converter : legacy . FirestoreDataConverter < U >
354
- ) : CollectionReference < U > {
355
- return new CollectionReference < U > (
356
- this . firestore ,
357
- this . _delegate . withConverter (
358
- converter as UntypedFirestoreDataConverter < U >
359
- )
360
- ) ;
361
- }
362
- }
363
-
364
164
export class FieldPath
365
165
extends Compat < FieldPathExp >
366
166
implements legacy . FieldPath {
0 commit comments