5
5
import { Pipeline as LitePipeline } from '../lite-api/pipeline' ;
6
6
import { PipelineResult } from '../lite-api/pipeline-result' ;
7
7
import { DocumentData , DocumentReference } from '../lite-api/reference' ;
8
- import { AddFields , Stage } from '../lite-api/stage' ;
8
+ import { AddFields , Sort , Stage , Where } from '../lite-api/stage' ;
9
9
import { UserDataReader } from '../lite-api/user_data_reader' ;
10
10
import { AbstractUserDataWriter } from '../lite-api/user_data_writer' ;
11
11
import { DocumentKey } from '../model/document_key' ;
@@ -15,6 +15,8 @@ import { DocumentSnapshot, PipelineSnapshot } from './snapshot';
15
15
import { FirestoreError } from '../util/error' ;
16
16
import { Unsubscribe } from './reference_impl' ;
17
17
import { cast } from '../util/input_validation' ;
18
+ import { Field , FilterCondition } from '../api' ;
19
+ import { Expr } from '../lite-api/expressions' ;
18
20
19
21
export class Pipeline <
20
22
AppModelType = DocumentData
@@ -49,6 +51,20 @@ export class Pipeline<
49
51
) ;
50
52
}
51
53
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
+
52
68
/**
53
69
* Executes this pipeline and returns a Promise to represent the asynchronous operation.
54
70
*
@@ -106,23 +122,30 @@ export class Pipeline<
106
122
* @internal
107
123
* @private
108
124
*/
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
+
114
140
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
+ ]
121
144
)
122
145
) ;
123
146
124
147
const client = ensureFirestoreConfigured ( this . db ) ;
125
- firestoreClientListenPipeline ( client , this , observer ) ;
148
+ firestoreClientListenPipeline ( client , this , { next , error , complete } ) ;
126
149
127
150
return ( ) => { } ;
128
151
}
0 commit comments