22import * as googleAuth from "google-auth-library" ;
33
44export enum FirestoreOperator {
5- LESS_THAN = ' LESS_THAN' ,
6- LESS_THAN_OR_EQUAL = ' LESS_THAN_OR_EQUAL' ,
7- GREATER_THAN = ' GREATER_THAN' ,
8- GREATER_THAN_OR_EQUAL = ' GREATER_THAN_OR_EQUAL' ,
9- EQUAL = ' EQUAL' ,
10- NOT_EQUAL = ' NOT_EQUAL' ,
11- ARRAY_CONTAINS = ' ARRAY_CONTAINS' ,
12- IN = 'IN' ,
13- ARRAY_CONTAINS_ANY = ' ARRAY_CONTAINS_ANY' ,
14- NOT_IN = ' NOT_IN' ,
15- IS_NAN = ' IS_NAN' ,
16- IS_NULL = ' IS_NULL' ,
17- IS_NOT_NAN = ' IS_NOT_NAN' ,
18- IS_NOT_NULL = ' IS_NOT_NULL'
5+ LESS_THAN = " LESS_THAN" ,
6+ LESS_THAN_OR_EQUAL = " LESS_THAN_OR_EQUAL" ,
7+ GREATER_THAN = " GREATER_THAN" ,
8+ GREATER_THAN_OR_EQUAL = " GREATER_THAN_OR_EQUAL" ,
9+ EQUAL = " EQUAL" ,
10+ NOT_EQUAL = " NOT_EQUAL" ,
11+ ARRAY_CONTAINS = " ARRAY_CONTAINS" ,
12+ IN = "IN" ,
13+ ARRAY_CONTAINS_ANY = " ARRAY_CONTAINS_ANY" ,
14+ NOT_IN = " NOT_IN" ,
15+ IS_NAN = " IS_NAN" ,
16+ IS_NULL = " IS_NULL" ,
17+ IS_NOT_NAN = " IS_NOT_NAN" ,
18+ IS_NOT_NULL = " IS_NOT_NULL" ,
1919}
2020
2121export class FirestoreAdminClient {
@@ -91,7 +91,12 @@ export class FirestoreAdminClient {
9191 if ( responseData ?. error ) {
9292 this . errorHandler ( responseData . error , "createDocument" ) ;
9393 }
94- return responseData ;
94+ const jsonDocument = this . documentToJson ( responseData . fields ) ;
95+ return {
96+ _id : responseData . name . split ( `/` ) . pop ( ) ,
97+ _path : responseData . name . split ( "documents/" ) [ 1 ] ,
98+ ...jsonDocument ,
99+ } ;
95100 }
96101
97102 /**
@@ -155,16 +160,16 @@ export class FirestoreAdminClient {
155160 if ( options . where ) {
156161 structuredQuery . where = {
157162 compositeFilter : {
158- op : ' AND' ,
163+ op : " AND" ,
159164 filters : options . where . filters . map ( ( [ field , op , value ] ) => ( {
160165 fieldFilter : {
161166 field : { fieldPath : field } ,
162167 op,
163- value : this . encodeValue ( value )
164- }
165- } ) )
166- }
167- }
168+ value : this . encodeValue ( value ) ,
169+ } ,
170+ } ) ) ,
171+ } ,
172+ } ;
168173 }
169174
170175 if ( options . orderBy ) {
@@ -195,8 +200,13 @@ export class FirestoreAdminClient {
195200 const data : any = await response . json ( ) ;
196201
197202 if ( data ?. error || data ?. [ 0 ] ?. error ) {
198- this . errorHandler ( data . error ?? data ?. [ 0 ] ?. error , `${ this . firestoreBaseUrl } /${ path } :runQuery` ) ;
199- console . log ( { extendedDetails : data . error ?. details ?? data ?. [ 0 ] ?. error ?. details } ) ;
203+ this . errorHandler (
204+ data . error ?? data ?. [ 0 ] ?. error ,
205+ `${ this . firestoreBaseUrl } /${ path } :runQuery` ,
206+ ) ;
207+ console . log ( {
208+ extendedDetails : data . error ?. details ?? data ?. [ 0 ] ?. error ?. details ,
209+ } ) ;
200210 return [ ] ;
201211 }
202212
@@ -205,13 +215,11 @@ export class FirestoreAdminClient {
205215 return [ ] ;
206216 }
207217
208-
209-
210218 return data . map ( ( doc : any ) => {
211219 const docId = doc . document ?. name . split ( `/` ) . pop ( ) ?? "unknown" ;
212- console . log ( { docId} ) ;
213- const documentFields = doc . document ?. fields || { }
214- return { ...this . documentToJson ( documentFields ) , _id : docId }
220+ console . log ( { docId } ) ;
221+ const documentFields = doc . document ?. fields || { } ;
222+ return { ...this . documentToJson ( documentFields ) , _id : docId } ;
215223 } ) ;
216224 } else {
217225 const response = await fetch ( `${ this . firestoreBaseUrl } /${ path } ` , {
@@ -226,8 +234,8 @@ export class FirestoreAdminClient {
226234
227235 return data . documents . map ( ( doc : any ) => {
228236 const docId = doc . name . split ( `/` ) . pop ( ) ?? "unknown" ;
229- const documentFields = doc . fields || { }
230- return { ...this . documentToJson ( documentFields ) , _id : docId }
237+ const documentFields = doc . fields || { } ;
238+ return { ...this . documentToJson ( documentFields ) , _id : docId } ;
231239 } ) ;
232240 }
233241 }
@@ -267,7 +275,12 @@ export class FirestoreAdminClient {
267275 if ( responseData ?. error ) {
268276 this . errorHandler ( responseData . error , "updateDocument" ) ;
269277 }
270- return responseData ;
278+ const jsonDocument = this . documentToJson ( responseData . fields ) ;
279+ return {
280+ _id : responseData . name . split ( `/` ) . pop ( ) ,
281+ _path : responseData . name . split ( "documents/" ) [ 1 ] ,
282+ ...jsonDocument ,
283+ } ;
271284 }
272285
273286 private documentToJson ( fields : any ) : any {
0 commit comments