Skip to content

Commit 0c607c9

Browse files
Make FieldPath a Compat class (#3819)
1 parent cddc551 commit 0c607c9

File tree

16 files changed

+382
-445
lines changed

16 files changed

+382
-445
lines changed

packages/firestore/exp/dependencies.json

Lines changed: 86 additions & 83 deletions
Large diffs are not rendered by default.

packages/firestore/exp/test/shim.ts

Lines changed: 37 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@ import * as exp from '../index';
2323

2424
import {
2525
addDoc,
26-
arrayRemove,
27-
arrayUnion,
2826
clearIndexedDbPersistence,
2927
collection,
3028
collectionGroup,
3129
deleteDoc,
32-
deleteField,
3330
disableNetwork,
3431
doc,
3532
DocumentReference as DocumentReferenceExp,
@@ -43,15 +40,13 @@ import {
4340
getDocs,
4441
getDocsFromCache,
4542
getDocsFromServer,
46-
increment,
4743
initializeFirestore,
4844
onSnapshot,
4945
onSnapshotsInSync,
5046
query,
5147
queryEqual,
5248
refEqual,
5349
runTransaction,
54-
serverTimestamp,
5550
setDoc,
5651
snapshotEqual,
5752
terminate,
@@ -71,18 +66,20 @@ import {
7166
import { UntypedFirestoreDataConverter } from '../../src/api/user_data_reader';
7267
import { isPartialObserver, PartialObserver } from '../../src/api/observer';
7368
import { isPlainObject } from '../../src/util/input_validation';
69+
import { Compat } from '../../src/compat/compat';
7470

7571
export { GeoPoint, Timestamp } from '../index';
72+
export { FieldValue } from '../../src/compat/field_value';
7673

7774
/* eslint-disable @typescript-eslint/no-explicit-any */
7875

7976
// This module defines a shim layer that implements the legacy API on top
8077
// of the experimental SDK. This shim is used to run integration tests against
8178
// both SDK versions.
8279

83-
export class FirebaseApp implements FirebaseAppLegacy {
84-
constructor(readonly _delegate: FirebaseAppExp) {}
85-
80+
export class FirebaseApp
81+
extends Compat<FirebaseAppExp>
82+
implements FirebaseAppLegacy {
8683
name = this._delegate.name;
8784
options = this._delegate.options;
8885
automaticDataCollectionEnabled = this._delegate
@@ -93,9 +90,9 @@ export class FirebaseApp implements FirebaseAppLegacy {
9390
}
9491
}
9592

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 {
9996
app = new FirebaseApp(this._delegate.app);
10097

10198
settings(settings: legacy.Settings): void {
@@ -170,11 +167,15 @@ export class FirebaseFirestore implements legacy.FirebaseFirestore {
170167
};
171168
}
172169

173-
export class Transaction implements legacy.Transaction {
170+
export class Transaction
171+
extends Compat<exp.Transaction>
172+
implements legacy.Transaction {
174173
constructor(
175174
private readonly _firestore: FirebaseFirestore,
176-
private readonly _delegate: exp.Transaction
177-
) {}
175+
delegate: exp.Transaction
176+
) {
177+
super(delegate);
178+
}
178179

179180
get<T>(documentRef: DocumentReference<T>): Promise<DocumentSnapshot<T>> {
180181
return this._delegate
@@ -231,9 +232,9 @@ export class Transaction implements legacy.Transaction {
231232
}
232233
}
233234

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 {
237238
set<T>(
238239
documentRef: DocumentReference<T>,
239240
data: T,
@@ -288,11 +289,14 @@ export class WriteBatch implements legacy.WriteBatch {
288289
}
289290

290291
export class DocumentReference<T = legacy.DocumentData>
292+
extends Compat<exp.DocumentReference<T>>
291293
implements legacy.DocumentReference<T> {
292294
constructor(
293295
readonly firestore: FirebaseFirestore,
294-
readonly _delegate: exp.DocumentReference<T>
295-
) {}
296+
delegate: exp.DocumentReference<T>
297+
) {
298+
super(delegate);
299+
}
296300

297301
readonly id = this._delegate.id;
298302
readonly path = this._delegate.path;
@@ -407,11 +411,14 @@ export class DocumentReference<T = legacy.DocumentData>
407411
}
408412

409413
export class DocumentSnapshot<T = legacy.DocumentData>
414+
extends Compat<exp.DocumentSnapshot<T>>
410415
implements legacy.DocumentSnapshot<T> {
411416
constructor(
412417
private readonly _firestore: FirebaseFirestore,
413-
readonly _delegate: exp.DocumentSnapshot<T>
414-
) {}
418+
delegate: exp.DocumentSnapshot<T>
419+
) {
420+
super(delegate);
421+
}
415422

416423
readonly ref = new DocumentReference<T>(this._firestore, this._delegate.ref);
417424
readonly id = this._delegate.id;
@@ -449,11 +456,12 @@ export class QueryDocumentSnapshot<T = legacy.DocumentData>
449456
}
450457
}
451458

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+
}
457465

458466
where(
459467
fieldPath: string | FieldPath,
@@ -680,34 +688,6 @@ export class CollectionReference<T = legacy.DocumentData>
680688
}
681689
}
682690

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-
711691
export class FieldPath implements legacy.FieldPath {
712692
private readonly fieldNames: string[];
713693

@@ -728,9 +708,7 @@ export class FieldPath implements legacy.FieldPath {
728708
}
729709
}
730710

731-
export class Blob implements legacy.Blob {
732-
constructor(readonly _delegate: BytesExp) {}
733-
711+
export class Blob extends Compat<BytesExp> implements legacy.Blob {
734712
static fromBase64String(base64: string): Blob {
735713
return new Blob(BytesExp.fromBase64String(base64));
736714
}
@@ -790,17 +768,9 @@ function wrap(value: any): any {
790768
function unwrap(value: any): any {
791769
if (Array.isArray(value)) {
792770
return value.map(v => unwrap(v));
793-
} else if (value instanceof FieldPath) {
794-
return value._delegate;
795-
} else if (value instanceof FieldValue) {
771+
} else if (value instanceof Compat) {
796772
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) {
773+
} else if (value instanceof FieldPath) {
804774
return value._delegate;
805775
} else if (isPlainObject(value)) {
806776
const obj: any = {};

packages/firestore/index.console.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ export {
2525
export { Blob } from './src/api/blob';
2626
export { GeoPoint } from './src/api/geo_point';
2727
export { FieldPath } from './src/api/field_path';
28-
export { FieldValue } from './src/api/field_value';
28+
export { FieldValue } from './src/compat/field_value';
2929
export { Timestamp } from './src/api/timestamp';

0 commit comments

Comments
 (0)