@@ -87,15 +87,31 @@ declare module './database' {
87
87
* @param pipeline The pipeline to execute.
88
88
* @return A Promise representing the asynchronous pipeline execution.
89
89
*/
90
- export function execute ( pipeline : LitePipeline ) : Promise < PipelineSnapshot > {
90
+ export function execute ( pipeline : LitePipeline ) : Promise < PipelineSnapshot > ;
91
+ export function execute (
92
+ pipeline : RealtimePipeline
93
+ ) : Promise < RealtimePipelineSnapshot > ;
94
+ export function execute (
95
+ pipeline : LitePipeline | RealtimePipeline
96
+ ) : Promise < PipelineSnapshot | RealtimePipelineSnapshot > {
91
97
const firestore = cast ( pipeline . _db , Firestore ) ;
92
98
const client = ensureFirestoreConfigured ( firestore ) ;
93
- return firestoreClientExecutePipeline ( client , pipeline ) . then ( result => {
94
- // Get the execution time from the first result.
95
- // firestoreClientExecutePipeline returns at least one PipelineStreamElement
96
- // even if the returned document set is empty.
97
- const executionTime =
98
- result . length > 0 ? result [ 0 ] . executionTime ?. toTimestamp ( ) : undefined ;
99
+
100
+ if ( pipeline instanceof RealtimePipeline ) {
101
+ return firestoreClientGetDocumentsViaSnapshotListener (
102
+ client ,
103
+ pipeline
104
+ ) . then (
105
+ snapshot =>
106
+ new RealtimePipelineSnapshot ( pipeline as RealtimePipeline , snapshot )
107
+ ) ;
108
+ } else {
109
+ return firestoreClientExecutePipeline ( client , pipeline ) . then ( result => {
110
+ // Get the execution time from the first result.
111
+ // firestoreClientExecutePipeline returns at least one PipelineStreamElement
112
+ // even if the returned document set is empty.
113
+ const executionTime =
114
+ result . length > 0 ? result [ 0 ] . executionTime ?. toTimestamp ( ) : undefined ;
99
115
100
116
const docs = result
101
117
// Currently ignore any response from ExecutePipeline that does
@@ -115,8 +131,9 @@ export function execute(pipeline: LitePipeline): Promise<PipelineSnapshot> {
115
131
)
116
132
) ;
117
133
118
- return new PipelineSnapshot ( pipeline , docs , executionTime ) ;
119
- } ) ;
134
+ return new PipelineSnapshot ( pipeline , docs , executionTime ) ;
135
+ } ) ;
136
+ }
120
137
}
121
138
122
139
// Augment the Firestore class with the pipeline() factory method
0 commit comments