@@ -23,13 +23,10 @@ import * as exp from '../index';
23
23
24
24
import {
25
25
addDoc ,
26
- arrayRemove ,
27
- arrayUnion ,
28
26
clearIndexedDbPersistence ,
29
27
collection ,
30
28
collectionGroup ,
31
29
deleteDoc ,
32
- deleteField ,
33
30
disableNetwork ,
34
31
doc ,
35
32
DocumentReference as DocumentReferenceExp ,
@@ -43,15 +40,13 @@ import {
43
40
getDocs ,
44
41
getDocsFromCache ,
45
42
getDocsFromServer ,
46
- increment ,
47
43
initializeFirestore ,
48
44
onSnapshot ,
49
45
onSnapshotsInSync ,
50
46
query ,
51
47
queryEqual ,
52
48
refEqual ,
53
49
runTransaction ,
54
- serverTimestamp ,
55
50
setDoc ,
56
51
snapshotEqual ,
57
52
terminate ,
@@ -71,18 +66,20 @@ import {
71
66
import { UntypedFirestoreDataConverter } from '../../src/api/user_data_reader' ;
72
67
import { isPartialObserver , PartialObserver } from '../../src/api/observer' ;
73
68
import { isPlainObject } from '../../src/util/input_validation' ;
69
+ import { Compat } from '../../src/compat/compat' ;
74
70
75
71
export { GeoPoint , Timestamp } from '../index' ;
72
+ export { FieldValue } from '../../src/compat/field_value' ;
76
73
77
74
/* eslint-disable @typescript-eslint/no-explicit-any */
78
75
79
76
// This module defines a shim layer that implements the legacy API on top
80
77
// of the experimental SDK. This shim is used to run integration tests against
81
78
// both SDK versions.
82
79
83
- export class FirebaseApp implements FirebaseAppLegacy {
84
- constructor ( readonly _delegate : FirebaseAppExp ) { }
85
-
80
+ export class FirebaseApp
81
+ extends Compat < FirebaseAppExp >
82
+ implements FirebaseAppLegacy {
86
83
name = this . _delegate . name ;
87
84
options = this . _delegate . options ;
88
85
automaticDataCollectionEnabled = this . _delegate
@@ -93,9 +90,9 @@ export class FirebaseApp implements FirebaseAppLegacy {
93
90
}
94
91
}
95
92
96
- export class FirebaseFirestore implements legacy . FirebaseFirestore {
97
- constructor ( private readonly _delegate : exp . FirebaseFirestore ) { }
98
-
93
+ export class FirebaseFirestore
94
+ extends Compat < exp . FirebaseFirestore >
95
+ implements legacy . FirebaseFirestore {
99
96
app = new FirebaseApp ( this . _delegate . app ) ;
100
97
101
98
settings ( settings : legacy . Settings ) : void {
@@ -170,11 +167,15 @@ export class FirebaseFirestore implements legacy.FirebaseFirestore {
170
167
} ;
171
168
}
172
169
173
- export class Transaction implements legacy . Transaction {
170
+ export class Transaction
171
+ extends Compat < exp . Transaction >
172
+ implements legacy . Transaction {
174
173
constructor (
175
174
private readonly _firestore : FirebaseFirestore ,
176
- private readonly _delegate : exp . Transaction
177
- ) { }
175
+ private readonly delegate : exp . Transaction
176
+ ) {
177
+ super ( delegate ) ;
178
+ }
178
179
179
180
get < T > ( documentRef : DocumentReference < T > ) : Promise < DocumentSnapshot < T > > {
180
181
return this . _delegate
@@ -231,9 +232,9 @@ export class Transaction implements legacy.Transaction {
231
232
}
232
233
}
233
234
234
- export class WriteBatch implements legacy . WriteBatch {
235
- constructor ( private readonly _delegate : exp . WriteBatch ) { }
236
-
235
+ export class WriteBatch
236
+ extends Compat < exp . WriteBatch >
237
+ implements legacy . WriteBatch {
237
238
set < T > (
238
239
documentRef : DocumentReference < T > ,
239
240
data : T ,
@@ -288,11 +289,14 @@ export class WriteBatch implements legacy.WriteBatch {
288
289
}
289
290
290
291
export class DocumentReference < T = legacy . DocumentData >
292
+ extends Compat < exp . DocumentReference < T > >
291
293
implements legacy . DocumentReference < T > {
292
294
constructor (
293
295
readonly firestore : FirebaseFirestore ,
294
- readonly _delegate : exp . DocumentReference < T >
295
- ) { }
296
+ delegate : exp . DocumentReference < T >
297
+ ) {
298
+ super ( delegate ) ;
299
+ }
296
300
297
301
readonly id = this . _delegate . id ;
298
302
readonly path = this . _delegate . path ;
@@ -407,11 +411,14 @@ export class DocumentReference<T = legacy.DocumentData>
407
411
}
408
412
409
413
export class DocumentSnapshot < T = legacy . DocumentData >
414
+ extends Compat < exp . DocumentSnapshot < T > >
410
415
implements legacy . DocumentSnapshot < T > {
411
416
constructor (
412
417
private readonly _firestore : FirebaseFirestore ,
413
- readonly _delegate : exp . DocumentSnapshot < T >
414
- ) { }
418
+ delegate : exp . DocumentSnapshot < T >
419
+ ) {
420
+ super ( delegate ) ;
421
+ }
415
422
416
423
readonly ref = new DocumentReference < T > ( this . _firestore , this . _delegate . ref ) ;
417
424
readonly id = this . _delegate . id ;
@@ -449,11 +456,12 @@ export class QueryDocumentSnapshot<T = legacy.DocumentData>
449
456
}
450
457
}
451
458
452
- export class Query < T = legacy . DocumentData > implements legacy . Query < T > {
453
- constructor (
454
- readonly firestore : FirebaseFirestore ,
455
- readonly _delegate : exp . Query < T >
456
- ) { }
459
+ export class Query < T = legacy . DocumentData >
460
+ extends Compat < exp . Query < T > >
461
+ implements legacy . Query < T > {
462
+ constructor ( readonly firestore : FirebaseFirestore , delegate : exp . Query < T > ) {
463
+ super ( delegate ) ;
464
+ }
457
465
458
466
where (
459
467
fieldPath : string | FieldPath ,
@@ -680,34 +688,6 @@ export class CollectionReference<T = legacy.DocumentData>
680
688
}
681
689
}
682
690
683
- export class FieldValue implements legacy . FieldValue {
684
- constructor ( readonly _delegate : exp . FieldValue ) { }
685
-
686
- static serverTimestamp ( ) : FieldValue {
687
- return new FieldValue ( serverTimestamp ( ) ) ;
688
- }
689
-
690
- static delete ( ) : FieldValue {
691
- return new FieldValue ( deleteField ( ) ) ;
692
- }
693
-
694
- static arrayUnion ( ...elements : any [ ] ) : FieldValue {
695
- return new FieldValue ( arrayUnion ( ...unwrap ( elements ) ) ) ;
696
- }
697
-
698
- static arrayRemove ( ...elements : any [ ] ) : FieldValue {
699
- return new FieldValue ( arrayRemove ( ...unwrap ( elements ) ) ) ;
700
- }
701
-
702
- static increment ( n : number ) : FieldValue {
703
- return new FieldValue ( increment ( n ) ) ;
704
- }
705
-
706
- isEqual ( other : FieldValue ) : boolean {
707
- return this . _delegate . isEqual ( other . _delegate ) ;
708
- }
709
- }
710
-
711
691
export class FieldPath implements legacy . FieldPath {
712
692
private readonly fieldNames : string [ ] ;
713
693
@@ -728,9 +708,7 @@ export class FieldPath implements legacy.FieldPath {
728
708
}
729
709
}
730
710
731
- export class Blob implements legacy . Blob {
732
- constructor ( readonly _delegate : BytesExp ) { }
733
-
711
+ export class Blob extends Compat < BytesExp > implements legacy . Blob {
734
712
static fromBase64String ( base64 : string ) : Blob {
735
713
return new Blob ( BytesExp . fromBase64String ( base64 ) ) ;
736
714
}
@@ -790,17 +768,7 @@ function wrap(value: any): any {
790
768
function unwrap ( value : any ) : any {
791
769
if ( Array . isArray ( value ) ) {
792
770
return value . map ( v => unwrap ( v ) ) ;
793
- } else if ( value instanceof FieldPath ) {
794
- return value . _delegate ;
795
- } else if ( value instanceof FieldValue ) {
796
- return value . _delegate ;
797
- } else if ( value instanceof Blob ) {
798
- return value . _delegate ;
799
- } else if ( value instanceof DocumentReference ) {
800
- return value . _delegate ;
801
- } else if ( value instanceof DocumentSnapshot ) {
802
- return value . _delegate ;
803
- } else if ( value instanceof QueryDocumentSnapshot ) {
771
+ } else if ( value instanceof Compat ) {
804
772
return value . _delegate ;
805
773
} else if ( isPlainObject ( value ) ) {
806
774
const obj : any = { } ;
0 commit comments