16
16
*/
17
17
18
18
import * as legacy from '@firebase/firestore-types' ;
19
- import * as exp from '../index' ;
20
19
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' ;
43
20
import { isPlainObject } from '../../src/util/input_validation' ;
21
+ import { FieldPath as FieldPathExp , Bytes as BytesExp } from '../../exp/index' ;
44
22
import { Compat } from '../../src/compat/compat' ;
45
- import {
46
- Firestore ,
47
- DocumentReference ,
48
- QuerySnapshot ,
49
- wrapObserver ,
50
- extractSnapshotOptions
51
- } from '../../src/api/database' ;
52
23
53
24
export { GeoPoint , Timestamp } from '../index' ;
54
25
@@ -58,182 +29,6 @@ export { GeoPoint, Timestamp } from '../index';
58
29
// of the experimental SDK. This shim is used to run integration tests against
59
30
// both SDK versions.
60
31
61
- export class Query < T = legacy . DocumentData >
62
- extends Compat < exp . Query < T > >
63
- implements legacy . Query < T > {
64
- constructor ( readonly firestore : Firestore , delegate : exp . Query < T > ) {
65
- super ( delegate ) ;
66
- }
67
-
68
- where (
69
- fieldPath : string | FieldPath ,
70
- opStr : legacy . WhereFilterOp ,
71
- value : any
72
- ) : Query < T > {
73
- return new Query < T > (
74
- this . firestore ,
75
- query ( this . _delegate , where ( unwrap ( fieldPath ) , opStr , unwrap ( value ) ) )
76
- ) ;
77
- }
78
-
79
- orderBy (
80
- fieldPath : string | FieldPath ,
81
- directionStr ?: legacy . OrderByDirection
82
- ) : Query < T > {
83
- return new Query < T > (
84
- this . firestore ,
85
- query ( this . _delegate , orderBy ( unwrap ( fieldPath ) , directionStr ) )
86
- ) ;
87
- }
88
-
89
- limit ( n : number ) : Query < T > {
90
- return new Query < T > ( this . firestore , query ( this . _delegate , limit ( n ) ) ) ;
91
- }
92
-
93
- limitToLast ( n : number ) : Query < T > {
94
- return new Query < T > ( this . firestore , query ( this . _delegate , limitToLast ( n ) ) ) ;
95
- }
96
-
97
- startAt ( ...args : any [ ] ) : Query < T > {
98
- return new Query (
99
- this . firestore ,
100
- query ( this . _delegate , startAt ( ...unwrap ( args ) ) )
101
- ) ;
102
- }
103
-
104
- startAfter ( ...args : any [ ] ) : Query < T > {
105
- return new Query (
106
- this . firestore ,
107
- query ( this . _delegate , startAfter ( ...unwrap ( args ) ) )
108
- ) ;
109
- }
110
-
111
- endBefore ( ...args : any [ ] ) : Query < T > {
112
- return new Query (
113
- this . firestore ,
114
- query ( this . _delegate , endBefore ( ...unwrap ( args ) ) )
115
- ) ;
116
- }
117
-
118
- endAt ( ...args : any [ ] ) : Query < T > {
119
- return new Query (
120
- this . firestore ,
121
- query ( this . _delegate , endAt ( ...unwrap ( args ) ) )
122
- ) ;
123
- }
124
-
125
- isEqual ( other : legacy . Query < T > ) : boolean {
126
- return queryEqual ( this . _delegate , ( other as Query < T > ) . _delegate ) ;
127
- }
128
-
129
- get ( options ?: legacy . GetOptions ) : Promise < QuerySnapshot < T > > {
130
- let query : Promise < exp . QuerySnapshot < T > > ;
131
- if ( options ?. source === 'cache' ) {
132
- query = getDocsFromCache ( this . _delegate ) ;
133
- } else if ( options ?. source === 'server' ) {
134
- query = getDocsFromServer ( this . _delegate ) ;
135
- } else {
136
- query = getDocs ( this . _delegate ) ;
137
- }
138
- return query . then ( result => new QuerySnapshot ( this . firestore , result ) ) ;
139
- }
140
-
141
- onSnapshot ( observer : {
142
- next ?: ( snapshot : QuerySnapshot < T > ) => void ;
143
- error ?: ( error : legacy . FirestoreError ) => void ;
144
- complete ?: ( ) => void ;
145
- } ) : ( ) => void ;
146
- onSnapshot (
147
- options : legacy . SnapshotListenOptions ,
148
- observer : {
149
- next ?: ( snapshot : QuerySnapshot < T > ) => void ;
150
- error ?: ( error : legacy . FirestoreError ) => void ;
151
- complete ?: ( ) => void ;
152
- }
153
- ) : ( ) => void ;
154
- onSnapshot (
155
- onNext : ( snapshot : QuerySnapshot < T > ) => void ,
156
- onError ?: ( error : legacy . FirestoreError ) => void ,
157
- onCompletion ?: ( ) => void
158
- ) : ( ) => void ;
159
- onSnapshot (
160
- options : legacy . SnapshotListenOptions ,
161
- onNext : ( snapshot : QuerySnapshot < T > ) => void ,
162
- onError ?: ( error : legacy . FirestoreError ) => void ,
163
- onCompletion ?: ( ) => void
164
- ) : ( ) => void ;
165
- onSnapshot ( ...args : any ) : ( ) => void {
166
- const options = extractSnapshotOptions ( args ) ;
167
- const observer = wrapObserver < QuerySnapshot < T > , exp . QuerySnapshot < T > > (
168
- args ,
169
- snap => new QuerySnapshot ( this . firestore , snap )
170
- ) ;
171
- return onSnapshot ( this . _delegate , options , observer ) ;
172
- }
173
-
174
- withConverter < U > ( converter : legacy . FirestoreDataConverter < U > ) : Query < U > {
175
- return new Query < U > (
176
- this . firestore ,
177
- this . _delegate . withConverter (
178
- converter as UntypedFirestoreDataConverter < U >
179
- )
180
- ) ;
181
- }
182
- }
183
-
184
- export class CollectionReference < T = legacy . DocumentData >
185
- extends Query < T >
186
- implements legacy . CollectionReference < T > {
187
- constructor (
188
- readonly firestore : Firestore ,
189
- readonly _delegate : exp . CollectionReference < T >
190
- ) {
191
- super ( firestore , _delegate ) ;
192
- }
193
-
194
- readonly id = this . _delegate . id ;
195
- readonly path = this . _delegate . path ;
196
-
197
- get parent ( ) : DocumentReference < legacy . DocumentData > | null {
198
- const docRef = this . _delegate . parent ;
199
- return docRef
200
- ? new DocumentReference < legacy . DocumentData > ( this . firestore , docRef )
201
- : null ;
202
- }
203
-
204
- doc ( documentPath ?: string ) : DocumentReference < T > {
205
- if ( documentPath !== undefined ) {
206
- return new DocumentReference (
207
- this . firestore ,
208
- doc ( this . _delegate , documentPath )
209
- ) ;
210
- } else {
211
- return new DocumentReference ( this . firestore , doc ( this . _delegate ) ) ;
212
- }
213
- }
214
-
215
- add ( data : T ) : Promise < DocumentReference < T > > {
216
- return addDoc ( this . _delegate , unwrap ( data ) ) . then (
217
- docRef => new DocumentReference ( this . firestore , docRef )
218
- ) ;
219
- }
220
-
221
- isEqual ( other : CollectionReference < T > ) : boolean {
222
- return refEqual ( this . _delegate , other . _delegate ) ;
223
- }
224
-
225
- withConverter < U > (
226
- converter : legacy . FirestoreDataConverter < U >
227
- ) : CollectionReference < U > {
228
- return new CollectionReference < U > (
229
- this . firestore ,
230
- this . _delegate . withConverter (
231
- converter as UntypedFirestoreDataConverter < U >
232
- )
233
- ) ;
234
- }
235
- }
236
-
237
32
export class FieldPath
238
33
extends Compat < FieldPathExp >
239
34
implements legacy . FieldPath {
0 commit comments