Skip to content

Commit e6f860e

Browse files
committed
remove api/pipeline and use the lite one
make execute and _onSnapshot free standing
1 parent 6e4a7e3 commit e6f860e

20 files changed

+145
-301
lines changed

packages/firestore/src/api/database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import {
4646
connectFirestoreEmulator,
4747
Firestore as LiteFirestore
4848
} from '../lite-api/database';
49-
import { PipelineSource } from './pipeline_source';
49+
import { PipelineSource } from '../lite-api/pipeline-source';
5050
import { DocumentReference, Query } from '../lite-api/reference';
5151
import { newUserDataReader } from '../lite-api/user_data_reader';
5252
import {

packages/firestore/src/api/pipeline.ts

Lines changed: 0 additions & 165 deletions
This file was deleted.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import { PipelineSnapshot } from './snapshot';
16+
import { FirestoreError } from '../util/error';
17+
import { Unsubscribe } from './reference_impl';
18+
import { Sort } from '../lite-api/stage';
19+
import { Field } from '../lite-api/expressions';
20+
import { ensureFirestoreConfigured, Firestore } from './database';
21+
import { ViewSnapshot } from '../core/view_snapshot';
22+
import {
23+
firestoreClientExecutePipeline,
24+
firestoreClientListen
25+
} from '../core/firestore_client';
26+
import { Pipeline } from '../lite-api/pipeline';
27+
import { PipelineResult } from '../lite-api/pipeline-result';
28+
29+
/**
30+
* Executes this pipeline and returns a Promise to represent the asynchronous operation.
31+
*
32+
* <p>The returned Promise can be used to track the progress of the pipeline execution
33+
* and retrieve the results (or handle any errors) asynchronously.
34+
*
35+
* <p>The pipeline results are returned as a list of {@link PipelineResult} objects. Each {@link
36+
* PipelineResult} typically represents a single key/value map that has passed through all the
37+
* stages of the pipeline, however this might differ depending on the stages involved in the
38+
* pipeline. For example:
39+
*
40+
* <ul>
41+
* <li>If there are no stages or only transformation stages, each {@link PipelineResult}
42+
* represents a single document.</li>
43+
* <li>If there is an aggregation, only a single {@link PipelineResult} is returned,
44+
* representing the aggregated results over the entire dataset .</li>
45+
* <li>If there is an aggregation stage with grouping, each {@link PipelineResult} represents a
46+
* distinct group and its associated aggregated values.</li>
47+
* </ul>
48+
*
49+
* <p>Example:
50+
*
51+
* ```typescript
52+
* const futureResults = await firestore.pipeline().collection("books")
53+
* .where(gt(Field.of("rating"), 4.5))
54+
* .select("title", "author", "rating")
55+
* .execute();
56+
* ```
57+
*
58+
* @return A Promise representing the asynchronous pipeline execution.
59+
*/
60+
export function execute<AppModelType>(
61+
pipeline: Pipeline<AppModelType>
62+
): Promise<Array<PipelineResult<AppModelType>>> {
63+
const client = ensureFirestoreConfigured(pipeline.liteDb as Firestore);
64+
return firestoreClientExecutePipeline(client, pipeline as Pipeline).then(
65+
result => {
66+
const docs = result.map(
67+
element =>
68+
new PipelineResult<AppModelType>(
69+
pipeline.userDataWriter,
70+
element.key?.path
71+
? pipeline.documentReferenceFactory(element.key)
72+
: undefined,
73+
element.fields,
74+
element.executionTime?.toTimestamp(),
75+
element.createTime?.toTimestamp(),
76+
element.updateTime?.toTimestamp()
77+
//this.converter
78+
)
79+
);
80+
81+
return docs;
82+
}
83+
);
84+
}
85+
86+
/**
87+
* @internal
88+
* @private
89+
*/
90+
export function _onSnapshot(
91+
pipeline: Pipeline,
92+
next: (snapshot: PipelineSnapshot) => void,
93+
error?: (error: FirestoreError) => void,
94+
complete?: () => void
95+
): Unsubscribe {
96+
// this.stages.push(
97+
// new AddFields(
98+
// this.selectablesToMap([
99+
// '__name__',
100+
// '__create_time__',
101+
// '__update_time__'
102+
// ])
103+
// )
104+
// );
105+
106+
pipeline.stages.push(new Sort([Field.of('__name__').ascending()]));
107+
108+
const client = ensureFirestoreConfigured(pipeline.liteDb as Firestore);
109+
const observer = {
110+
next: (snapshot: ViewSnapshot) => {
111+
new PipelineSnapshot(pipeline, snapshot);
112+
},
113+
error: error,
114+
complete: complete
115+
};
116+
// TODO(pipeline) hook up options
117+
firestoreClientListen(client, pipeline, {}, observer);
118+
119+
return () => {};
120+
}

packages/firestore/src/api/pipeline_source.ts

Lines changed: 0 additions & 91 deletions
This file was deleted.

packages/firestore/src/api/snapshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { Code, FirestoreError } from '../util/error';
4040

4141
import { Firestore } from './database';
4242
import { SnapshotListenOptions } from './reference_impl';
43-
import { Pipeline } from './pipeline';
43+
import { Pipeline } from '../lite-api/pipeline';
4444
import { PipelineResult, toPipelineResult } from '../lite-api/pipeline-result';
4545
import { isPipeline } from '../core/pipeline-util';
4646
import { newPipelineComparator } from '../core/pipeline_run';

0 commit comments

Comments
 (0)