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' ;
@@ -128,182 +104,6 @@ export class Transaction
128
104
}
129
105
}
130
106
131
- export class Query < T = legacy . DocumentData >
132
- extends Compat < exp . Query < T > >
133
- implements legacy . Query < T > {
134
- constructor ( readonly firestore : Firestore , delegate : exp . Query < T > ) {
135
- super ( delegate ) ;
136
- }
137
-
138
- where (
139
- fieldPath : string | FieldPath ,
140
- opStr : legacy . WhereFilterOp ,
141
- value : any
142
- ) : Query < T > {
143
- return new Query < T > (
144
- this . firestore ,
145
- query ( this . _delegate , where ( unwrap ( fieldPath ) , opStr , unwrap ( value ) ) )
146
- ) ;
147
- }
148
-
149
- orderBy (
150
- fieldPath : string | FieldPath ,
151
- directionStr ?: legacy . OrderByDirection
152
- ) : Query < T > {
153
- return new Query < T > (
154
- this . firestore ,
155
- query ( this . _delegate , orderBy ( unwrap ( fieldPath ) , directionStr ) )
156
- ) ;
157
- }
158
-
159
- limit ( n : number ) : Query < T > {
160
- return new Query < T > ( this . firestore , query ( this . _delegate , limit ( n ) ) ) ;
161
- }
162
-
163
- limitToLast ( n : number ) : Query < T > {
164
- return new Query < T > ( this . firestore , query ( this . _delegate , limitToLast ( n ) ) ) ;
165
- }
166
-
167
- startAt ( ...args : any [ ] ) : Query < T > {
168
- return new Query (
169
- this . firestore ,
170
- query ( this . _delegate , startAt ( ...unwrap ( args ) ) )
171
- ) ;
172
- }
173
-
174
- startAfter ( ...args : any [ ] ) : Query < T > {
175
- return new Query (
176
- this . firestore ,
177
- query ( this . _delegate , startAfter ( ...unwrap ( args ) ) )
178
- ) ;
179
- }
180
-
181
- endBefore ( ...args : any [ ] ) : Query < T > {
182
- return new Query (
183
- this . firestore ,
184
- query ( this . _delegate , endBefore ( ...unwrap ( args ) ) )
185
- ) ;
186
- }
187
-
188
- endAt ( ...args : any [ ] ) : Query < T > {
189
- return new Query (
190
- this . firestore ,
191
- query ( this . _delegate , endAt ( ...unwrap ( args ) ) )
192
- ) ;
193
- }
194
-
195
- isEqual ( other : legacy . Query < T > ) : boolean {
196
- return queryEqual ( this . _delegate , ( other as Query < T > ) . _delegate ) ;
197
- }
198
-
199
- get ( options ?: legacy . GetOptions ) : Promise < QuerySnapshot < T > > {
200
- let query : Promise < exp . QuerySnapshot < T > > ;
201
- if ( options ?. source === 'cache' ) {
202
- query = getDocsFromCache ( this . _delegate ) ;
203
- } else if ( options ?. source === 'server' ) {
204
- query = getDocsFromServer ( this . _delegate ) ;
205
- } else {
206
- query = getDocs ( this . _delegate ) ;
207
- }
208
- return query . then ( result => new QuerySnapshot ( this . firestore , result ) ) ;
209
- }
210
-
211
- onSnapshot ( observer : {
212
- next ?: ( snapshot : QuerySnapshot < T > ) => void ;
213
- error ?: ( error : legacy . FirestoreError ) => void ;
214
- complete ?: ( ) => void ;
215
- } ) : ( ) => void ;
216
- onSnapshot (
217
- options : legacy . SnapshotListenOptions ,
218
- observer : {
219
- next ?: ( snapshot : QuerySnapshot < T > ) => void ;
220
- error ?: ( error : legacy . FirestoreError ) => void ;
221
- complete ?: ( ) => void ;
222
- }
223
- ) : ( ) => void ;
224
- onSnapshot (
225
- onNext : ( snapshot : QuerySnapshot < T > ) => void ,
226
- onError ?: ( error : legacy . FirestoreError ) => void ,
227
- onCompletion ?: ( ) => void
228
- ) : ( ) => void ;
229
- onSnapshot (
230
- options : legacy . SnapshotListenOptions ,
231
- onNext : ( snapshot : QuerySnapshot < T > ) => void ,
232
- onError ?: ( error : legacy . FirestoreError ) => void ,
233
- onCompletion ?: ( ) => void
234
- ) : ( ) => void ;
235
- onSnapshot ( ...args : any ) : ( ) => void {
236
- const options = extractSnapshotOptions ( args ) ;
237
- const observer = wrapObserver < QuerySnapshot < T > , exp . QuerySnapshot < T > > (
238
- args ,
239
- snap => new QuerySnapshot ( this . firestore , snap )
240
- ) ;
241
- return onSnapshot ( this . _delegate , options , observer ) ;
242
- }
243
-
244
- withConverter < U > ( converter : legacy . FirestoreDataConverter < U > ) : Query < U > {
245
- return new Query < U > (
246
- this . firestore ,
247
- this . _delegate . withConverter (
248
- converter as UntypedFirestoreDataConverter < U >
249
- )
250
- ) ;
251
- }
252
- }
253
-
254
- export class CollectionReference < T = legacy . DocumentData >
255
- extends Query < T >
256
- implements legacy . CollectionReference < T > {
257
- constructor (
258
- readonly firestore : Firestore ,
259
- readonly _delegate : exp . CollectionReference < T >
260
- ) {
261
- super ( firestore , _delegate ) ;
262
- }
263
-
264
- readonly id = this . _delegate . id ;
265
- readonly path = this . _delegate . path ;
266
-
267
- get parent ( ) : DocumentReference < legacy . DocumentData > | null {
268
- const docRef = this . _delegate . parent ;
269
- return docRef
270
- ? new DocumentReference < legacy . DocumentData > ( this . firestore , docRef )
271
- : null ;
272
- }
273
-
274
- doc ( documentPath ?: string ) : DocumentReference < T > {
275
- if ( documentPath !== undefined ) {
276
- return new DocumentReference (
277
- this . firestore ,
278
- doc ( this . _delegate , documentPath )
279
- ) ;
280
- } else {
281
- return new DocumentReference ( this . firestore , doc ( this . _delegate ) ) ;
282
- }
283
- }
284
-
285
- add ( data : T ) : Promise < DocumentReference < T > > {
286
- return addDoc ( this . _delegate , unwrap ( data ) ) . then (
287
- docRef => new DocumentReference ( this . firestore , docRef )
288
- ) ;
289
- }
290
-
291
- isEqual ( other : CollectionReference < T > ) : boolean {
292
- return refEqual ( this . _delegate , other . _delegate ) ;
293
- }
294
-
295
- withConverter < U > (
296
- converter : legacy . FirestoreDataConverter < U >
297
- ) : CollectionReference < U > {
298
- return new CollectionReference < U > (
299
- this . firestore ,
300
- this . _delegate . withConverter (
301
- converter as UntypedFirestoreDataConverter < U >
302
- )
303
- ) ;
304
- }
305
- }
306
-
307
107
export class FieldPath
308
108
extends Compat < FieldPathExp >
309
109
implements legacy . FieldPath {
0 commit comments