@@ -53,7 +53,7 @@ export default abstract class PostgrestBuilder<Result>
5353 onrejected ?: ( ( reason : any ) => TResult2 | PromiseLike < TResult2 > ) | undefined | null
5454 ) : PromiseLike < TResult1 | TResult2 > {
5555 // https://postgrest.org/en/stable/api.html#switching-schemas
56- if ( typeof this . schema === ' undefined' ) {
56+ if ( this . schema === undefined ) {
5757 // skip
5858 } else if ( [ 'GET' , 'HEAD' ] . includes ( this . method ) ) {
5959 this . headers [ 'Accept-Profile' ] = this . schema
@@ -73,27 +73,26 @@ export default abstract class PostgrestBuilder<Result>
7373 body : JSON . stringify ( this . body ) ,
7474 signal : this . signal ,
7575 } ) . then ( async ( res ) => {
76- let error = undefined
77- let data = undefined
78- let count = undefined
76+ let error = null
77+ let data = null
78+ let count : number | null = null
7979 let status = res . status
8080 let statusText = res . statusText
8181
8282 if ( res . ok ) {
83- const isReturnMinimal = this . headers [ 'Prefer' ] ?. split ( ',' ) . includes ( 'return=minimal' )
84- if ( this . method !== 'HEAD' && ! isReturnMinimal ) {
85- const text = await res . text ( )
86- if ( ! text ) {
87- // discard `text`
83+ if ( this . method !== 'HEAD' ) {
84+ const body = await res . text ( )
85+ if ( body === "" ) {
86+ // Prefer: return=minimal
8887 } else if ( this . headers [ 'Accept' ] === 'text/csv' ) {
89- data = text
88+ data = body
9089 } else if (
9190 this . headers [ 'Accept' ] &&
92- this . headers [ 'Accept' ] . indexOf ( 'application/vnd.pgrst.plan+text' ) !== - 1
91+ this . headers [ 'Accept' ] . includes ( 'application/vnd.pgrst.plan+text' )
9392 ) {
94- data = text
93+ data = body
9594 } else {
96- data = JSON . parse ( text )
95+ data = JSON . parse ( body )
9796 }
9897 }
9998
@@ -114,7 +113,7 @@ export default abstract class PostgrestBuilder<Result>
114113 }
115114
116115 if ( error && this . allowEmpty && error ?. details ?. includes ( 'Results contain 0 rows' ) ) {
117- error = undefined
116+ error = null
118117 status = 200
119118 statusText = 'OK'
120119 }
@@ -142,10 +141,10 @@ export default abstract class PostgrestBuilder<Result>
142141 hint : '' ,
143142 code : fetchError . code || '' ,
144143 } ,
145- data : undefined ,
146- count : undefined ,
147- status : 400 ,
148- statusText : 'Bad Request ' ,
144+ data : null ,
145+ count : null ,
146+ status : 0 ,
147+ statusText : '' ,
149148 } ) )
150149 }
151150
0 commit comments