Skip to content

Commit 4555a37

Browse files
Merge
2 parents 9d97119 + 6cd65fc commit 4555a37

File tree

6 files changed

+660
-1029
lines changed

6 files changed

+660
-1029
lines changed

packages/firestore/exp/src/api/reference.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ import { DocumentSnapshot, QuerySnapshot } from './snapshot';
2828
import {
2929
applyFirestoreDataConverter,
3030
ensureFirestoreConfigured,
31-
SnapshotMetadata,
32-
validateHasExplicitOrderByForLimitToLast
31+
SnapshotMetadata
3332
} from '../../../src/api/database';
3433
import { ViewSnapshot } from '../../../src/core/view_snapshot';
3534
import {
@@ -39,7 +38,8 @@ import {
3938
newUserDataReader,
4039
Query,
4140
SetOptions,
42-
UpdateData
41+
UpdateData,
42+
validateHasExplicitOrderByForLimitToLast
4343
} from '../../../lite/src/api/reference';
4444
import { Document } from '../../../src/model/document';
4545
import {
@@ -87,7 +87,20 @@ import { AbstractUserDataWriter } from '../../../src/api/user_data_writer';
8787
export {
8888
DocumentReference,
8989
CollectionReference,
90-
Query
90+
Query,
91+
collection,
92+
collectionGroup,
93+
doc,
94+
query,
95+
where,
96+
limit,
97+
limitToLast,
98+
orderBy,
99+
startAt,
100+
startAfter,
101+
endAt,
102+
endBefore,
103+
queryEqual
91104
} from '../../../lite/src/api/reference';
92105

93106
/**

packages/firestore/exp/test/shim.ts

Lines changed: 1 addition & 206 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,10 @@
1616
*/
1717

1818
import * as legacy from '@firebase/firestore-types';
19-
import * as exp from '../index';
2019

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';
4320
import { isPlainObject } from '../../src/util/input_validation';
21+
import { FieldPath as FieldPathExp, Bytes as BytesExp } from '../../exp/index';
4422
import { Compat } from '../../src/compat/compat';
45-
import {
46-
Firestore,
47-
DocumentReference,
48-
QuerySnapshot,
49-
wrapObserver,
50-
extractSnapshotOptions
51-
} from '../../src/api/database';
5223

5324
export { GeoPoint, Timestamp } from '../index';
5425

@@ -58,182 +29,6 @@ export { GeoPoint, Timestamp } from '../index';
5829
// of the experimental SDK. This shim is used to run integration tests against
5930
// both SDK versions.
6031

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-
23732
export class FieldPath
23833
extends Compat<FieldPathExp>
23934
implements legacy.FieldPath {

0 commit comments

Comments
 (0)