Skip to content

Commit 076236e

Browse files
committed
Fixes. Passing integration tests.
1 parent 2f3d48a commit 076236e

File tree

5 files changed

+82
-105
lines changed

5 files changed

+82
-105
lines changed

common/api-review/firestore-lite.api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,8 +2176,8 @@ export function xor(left: FilterExpr, ...right: FilterExpr[]): Xor;
21762176

21772177
// Warnings were encountered during analysis:
21782178
//
2179-
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9258:9 - (ae-incompatible-release-tags) The symbol "accumulators" is marked as @public, but its signature references "AccumulatorTarget" which is marked as @beta
2180-
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9259:9 - (ae-incompatible-release-tags) The symbol "groups" is marked as @public, but its signature references "Selectable" which is marked as @beta
2181-
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9288:9 - (ae-incompatible-release-tags) The symbol "orderings" is marked as @public, but its signature references "Ordering" which is marked as @beta
2179+
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9258:9 - (ae-incompatible-release-tags) The symbol "accumulators" is marked as @public, but its signature references "AccumulatorTarget" which is marked as @beta
2180+
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9259:9 - (ae-incompatible-release-tags) The symbol "groups" is marked as @public, but its signature references "Selectable" which is marked as @beta
2181+
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9288:9 - (ae-incompatible-release-tags) The symbol "orderings" is marked as @public, but its signature references "Ordering" which is marked as @beta
21822182

21832183
```

common/api-review/firestore.api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,8 +2464,8 @@ export function xor(left: FilterExpr, ...right: FilterExpr[]): Xor;
24642464

24652465
// Warnings were encountered during analysis:
24662466
//
2467-
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/index.d.ts:10108:9 - (ae-incompatible-release-tags) The symbol "accumulators" is marked as @public, but its signature references "AccumulatorTarget" which is marked as @beta
2468-
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/index.d.ts:10109:9 - (ae-incompatible-release-tags) The symbol "groups" is marked as @public, but its signature references "Selectable" which is marked as @beta
2469-
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/index.d.ts:10138:9 - (ae-incompatible-release-tags) The symbol "orderings" is marked as @public, but its signature references "Ordering" which is marked as @beta
2467+
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/index.d.ts:10108:9 - (ae-incompatible-release-tags) The symbol "accumulators" is marked as @public, but its signature references "AccumulatorTarget" which is marked as @beta
2468+
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/index.d.ts:10109:9 - (ae-incompatible-release-tags) The symbol "groups" is marked as @public, but its signature references "Selectable" which is marked as @beta
2469+
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/index.d.ts:10138:9 - (ae-incompatible-release-tags) The symbol "orderings" is marked as @public, but its signature references "Ordering" which is marked as @beta
24702470

24712471
```

packages/firestore/src/lite-api/pipeline.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,9 @@ export class Pipeline<AppModelType = DocumentData> {
223223
*/
224224
select(...selections: Array<Selectable | string>): Pipeline<AppModelType> {
225225
const copy = this.stages.map(s => s);
226-
copy.push(new Select(this.selectablesToMap(selections)));
226+
let projections: Map<string, Expr> = this.selectablesToMap(selections);
227+
projections = this.readUserData('select', projections);
228+
copy.push(new Select(projections));
227229
return new Pipeline(
228230
this.liteDb,
229231
this.userDataReader,
@@ -781,20 +783,24 @@ export class Pipeline<AppModelType = DocumentData> {
781783
execute(): Promise<Array<PipelineResult<AppModelType>>> {
782784
const datastore = getDatastore(this.liteDb);
783785
return invokeExecutePipeline(datastore, this).then(result => {
784-
const docs = result.map(
785-
element =>
786-
new PipelineResult<AppModelType>(
787-
this.userDataWriter,
788-
element.key?.path
789-
? this.documentReferenceFactory(element.key)
790-
: undefined,
791-
element.fields,
792-
element.executionTime?.toTimestamp(),
793-
element.createTime?.toTimestamp(),
794-
element.updateTime?.toTimestamp()
795-
//this.converter
796-
)
797-
);
786+
const docs = result
787+
// Currently ignore any response from ExecutePipeline that does
788+
// not contain any document data in the `fields` property.
789+
.filter(element => !!element.fields)
790+
.map(
791+
element =>
792+
new PipelineResult<AppModelType>(
793+
this.userDataWriter,
794+
element.key?.path
795+
? this.documentReferenceFactory(element.key)
796+
: undefined,
797+
element.fields,
798+
element.executionTime?.toTimestamp(),
799+
element.createTime?.toTimestamp(),
800+
element.updateTime?.toTimestamp()
801+
//this.converter
802+
)
803+
);
798804

799805
return docs;
800806
});

packages/firestore/src/lite-api/reference.ts

Lines changed: 15 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -184,81 +184,21 @@ export class Query<
184184
* @internal
185185
*/
186186
pipeline(): Pipeline {
187-
throw Error('Not implemented - Query.pipeline()');
188-
// let pipeline;
189-
// if (this._queryOptions.allDescendants) {
190-
// pipeline = this.firestore
191-
// .pipeline()
192-
// .collectionGroup(this._queryOptions.collectionId);
193-
// } else {
194-
// pipeline = this.firestore
195-
// .pipeline()
196-
// .collection(
197-
// this._queryOptions.parentPath.append(this._queryOptions.collectionId)
198-
// .relativeName
199-
// );
200-
// }
201-
202-
// // filters
203-
// for (const f of this._queryOptions.filters) {
204-
// pipeline = pipeline.where(toPipelineFilterCondition(f, this._serializer));
205-
// }
206-
207-
// // projections
208-
// const projections = this._queryOptions.projection?.fields || [];
209-
// if (projections.length > 0) {
210-
// pipeline = pipeline.select(
211-
// ...projections.map(p => Field.of(p.fieldPath!))
212-
// );
213-
// }
214-
215-
// // orderbys
216-
// const exists = this.createImplicitOrderBy().map(fieldOrder => {
217-
// return Field.of(fieldOrder.field).exists();
218-
// });
219-
// if (exists.length > 1) {
220-
// const [first, ...rest] = exists;
221-
// pipeline = pipeline.where(and(first, ...rest));
222-
// } else if (exists.length === 1) {
223-
// pipeline = pipeline.where(exists[0]);
224-
// }
225-
226-
// const orderings = this.createImplicitOrderBy().map(fieldOrder => {
227-
// let dir: 'ascending' | 'descending' | undefined = undefined;
228-
// switch (fieldOrder.direction) {
229-
// case 'ASCENDING': {
230-
// dir = 'ascending';
231-
// break;
232-
// }
233-
// case 'DESCENDING': {
234-
// dir = 'descending';
235-
// break;
236-
// }
237-
// }
238-
// return new Ordering(Field.of(fieldOrder.field), dir || 'ascending');
239-
// });
240-
// if (orderings.length > 0) {
241-
// pipeline = pipeline.sort({orderings: orderings});
242-
// }
243-
244-
// // Cursors, Limit and Offset
245-
// if (
246-
// !!this._queryOptions.startAt ||
247-
// !!this._queryOptions.endAt ||
248-
// this._queryOptions.limitType === LimitType.Last
249-
// ) {
250-
// throw new Error(
251-
// 'Query to Pipeline conversion: cursors and limitToLast is not supported yet.'
252-
// );
253-
// } else {
254-
// if (this._queryOptions.offset) {
255-
// pipeline = pipeline.offset(this._queryOptions.offset);
256-
// }
257-
// if (this._queryOptions.limit) {
258-
// pipeline = pipeline.limit(this._queryOptions.limit);
259-
// }
260-
// }
261-
// return pipeline;
187+
let pipeline;
188+
if (this._query.collectionGroup) {
189+
pipeline = this.firestore
190+
.pipeline()
191+
.collectionGroup(this._query.collectionGroup);
192+
} else {
193+
pipeline = this.firestore
194+
.pipeline()
195+
.collection(this._query.path.canonicalString());
196+
}
197+
198+
// TODO(pipeline) convert existing query filters, limits, etc into
199+
// pipeline stages
200+
201+
return pipeline;
262202
}
263203
}
264204

packages/firestore/test/integration/api/pipeline.test.ts

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ apiDescribe.only('Pipelines', persistence => {
229229

230230
beforeEach(async () => {
231231
const setupDeferred = new Deferred<void>();
232+
testDeferred = new Deferred<void>();
232233
withTestCollectionPromise = withTestCollection(
233234
persistence,
234235
{},
@@ -242,21 +243,31 @@ apiDescribe.only('Pipelines', persistence => {
242243
}
243244
);
244245

245-
await setupDeferred;
246+
await setupDeferred.promise;
246247
});
247248

248249
afterEach(async () => {
249250
testDeferred?.resolve();
250251
await withTestCollectionPromise;
251252
});
252253

254+
// setLogLevel('debug')
255+
253256
it('empty results as expected', async () => {
254257
const result = await firestore
255258
.pipeline()
256259
.collection(randomCol.path)
257260
.limit(0)
258261
.execute();
259-
expect(result).to.be.empty;
262+
expect(result.length).to.equal(0);
263+
});
264+
265+
it('full results as expected', async () => {
266+
const result = await firestore
267+
.pipeline()
268+
.collection(randomCol.path)
269+
.execute();
270+
expect(result.length).to.equal(10);
260271
});
261272

262273
it('returns aggregate results as expected', async () => {
@@ -292,7 +303,8 @@ apiDescribe.only('Pipelines', persistence => {
292303
).to.be.rejected;
293304
});
294305

295-
it('returns distinct values as expected', async () => {
306+
// skip: toLower not supported
307+
it.skip('returns distinct values as expected', async () => {
296308
const results = await randomCol
297309
.pipeline()
298310
.where(lt('published', 1900))
@@ -314,6 +326,7 @@ apiDescribe.only('Pipelines', persistence => {
314326
groups: ['genre']
315327
})
316328
.where(gt('avgRating', 4.3))
329+
.sort(Field.of('avgRating').descending())
317330
.execute();
318331
expectResults(
319332
results,
@@ -446,7 +459,8 @@ apiDescribe.only('Pipelines', persistence => {
446459
expect(results.length).to.equal(10);
447460
});
448461

449-
it('arrayConcat works', async () => {
462+
// skip: arrayConcat not supported
463+
it.skip('arrayConcat works', async () => {
450464
const results = await randomCol
451465
.pipeline()
452466
.select(
@@ -510,18 +524,33 @@ apiDescribe.only('Pipelines', persistence => {
510524
Field.of('title')
511525
)
512526
.where(gt('titleLength', 20))
527+
.sort(Field.of('title').ascending())
513528
.execute();
529+
514530
expectResults(
515531
results,
516-
{ titleLength: 32, title: "The Hitchhiker's Guide to the Galaxy" },
532+
517533
{
518-
titleLength: 27,
534+
titleLength: 29,
519535
title: 'One Hundred Years of Solitude'
536+
},
537+
{
538+
titleLength: 36,
539+
title: "The Hitchhiker's Guide to the Galaxy"
540+
},
541+
{
542+
titleLength: 21,
543+
title: 'The Lord of the Rings'
544+
},
545+
{
546+
titleLength: 21,
547+
title: 'To Kill a Mockingbird'
520548
}
521549
);
522550
});
523551

524-
it('testToLowercase', async () => {
552+
// skip: toLower not supported
553+
it.skip('testToLowercase', async () => {
525554
const results = await randomCol
526555
.pipeline()
527556
.select(Field.of('title').toLower().as('lowercaseTitle'))
@@ -532,7 +561,8 @@ apiDescribe.only('Pipelines', persistence => {
532561
});
533562
});
534563

535-
it('testToUppercase', async () => {
564+
// skip: toUpper not supported
565+
it.skip('testToUppercase', async () => {
536566
const results = await randomCol
537567
.pipeline()
538568
.select(Field.of('author').toUpper().as('uppercaseAuthor'))
@@ -541,7 +571,8 @@ apiDescribe.only('Pipelines', persistence => {
541571
expectResults(results, { uppercaseAuthor: 'DOUGLAS ADAMS' });
542572
});
543573

544-
it('testTrim', async () => {
574+
// skip: trim not supported
575+
it.skip('testTrim', async () => {
545576
const results = await randomCol
546577
.pipeline()
547578
.addFields(strConcat(' ', Field.of('title'), ' ').as('spacedTitle'))

0 commit comments

Comments
 (0)