55import { Pipeline as LitePipeline } from '../lite-api/pipeline' ;
66import { PipelineResult } from '../lite-api/pipeline-result' ;
77import { DocumentData , DocumentReference } from '../lite-api/reference' ;
8- import { AddFields , Stage } from '../lite-api/stage' ;
8+ import { AddFields , Sort , Stage , Where } from '../lite-api/stage' ;
99import { UserDataReader } from '../lite-api/user_data_reader' ;
1010import { AbstractUserDataWriter } from '../lite-api/user_data_writer' ;
1111import { DocumentKey } from '../model/document_key' ;
@@ -15,6 +15,8 @@ import { DocumentSnapshot, PipelineSnapshot } from './snapshot';
1515import { FirestoreError } from '../util/error' ;
1616import { Unsubscribe } from './reference_impl' ;
1717import { cast } from '../util/input_validation' ;
18+ import { Field , FilterCondition } from '../api' ;
19+ import { Expr } from '../lite-api/expressions' ;
1820
1921export class Pipeline <
2022 AppModelType = DocumentData
@@ -49,6 +51,20 @@ export class Pipeline<
4951 ) ;
5052 }
5153
54+ where ( condition : FilterCondition & Expr ) : Pipeline < AppModelType > {
55+ const copy = this . stages . map ( s => s ) ;
56+ super . readUserData ( 'where' , condition ) ;
57+ copy . push ( new Where ( condition ) ) ;
58+ return new Pipeline (
59+ this . db ,
60+ this . userDataReader ,
61+ this . userDataWriter ,
62+ this . documentReferenceFactory ,
63+ copy ,
64+ this . converter
65+ ) ;
66+ }
67+
5268 /**
5369 * Executes this pipeline and returns a Promise to represent the asynchronous operation.
5470 *
@@ -106,23 +122,30 @@ export class Pipeline<
106122 * @internal
107123 * @private
108124 */
109- _onSnapshot ( observer : {
110- next ?: ( snapshot : PipelineSnapshot ) => void ;
111- error ?: ( error : FirestoreError ) => void ;
112- complete ?: ( ) => void ;
113- } ) : Unsubscribe {
125+ _onSnapshot (
126+ next : ( snapshot : PipelineSnapshot ) => void ,
127+ error ?: ( error : FirestoreError ) => void ,
128+ complete ?: ( ) => void
129+ ) : Unsubscribe {
130+ // this.stages.push(
131+ // new AddFields(
132+ // this.selectablesToMap([
133+ // '__name__',
134+ // '__create_time__',
135+ // '__update_time__'
136+ // ])
137+ // )
138+ // );
139+
114140 this . stages . push (
115- new AddFields (
116- this . selectablesToMap ( [
117- '__name__' ,
118- '__create_time__' ,
119- '__update_time__'
120- ] )
141+ new Sort ( [
142+ Field . of ( '__name__' ) . ascending ( )
143+ ]
121144 )
122145 ) ;
123146
124147 const client = ensureFirestoreConfigured ( this . db ) ;
125- firestoreClientListenPipeline ( client , this , observer ) ;
148+ firestoreClientListenPipeline ( client , this , { next , error , complete } ) ;
126149
127150 return ( ) => { } ;
128151 }
0 commit comments