@@ -53,7 +53,7 @@ export default abstract class PostgrestBuilder<Result>
53
53
onrejected ?: ( ( reason : any ) => TResult2 | PromiseLike < TResult2 > ) | undefined | null
54
54
) : PromiseLike < TResult1 | TResult2 > {
55
55
// https://postgrest.org/en/stable/api.html#switching-schemas
56
- if ( typeof this . schema === ' undefined' ) {
56
+ if ( this . schema === undefined ) {
57
57
// skip
58
58
} else if ( [ 'GET' , 'HEAD' ] . includes ( this . method ) ) {
59
59
this . headers [ 'Accept-Profile' ] = this . schema
@@ -73,27 +73,26 @@ export default abstract class PostgrestBuilder<Result>
73
73
body : JSON . stringify ( this . body ) ,
74
74
signal : this . signal ,
75
75
} ) . 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
79
79
let status = res . status
80
80
let statusText = res . statusText
81
81
82
82
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
88
87
} else if ( this . headers [ 'Accept' ] === 'text/csv' ) {
89
- data = text
88
+ data = body
90
89
} else if (
91
90
this . headers [ 'Accept' ] &&
92
- this . headers [ 'Accept' ] . indexOf ( 'application/vnd.pgrst.plan+text' ) !== - 1
91
+ this . headers [ 'Accept' ] . includes ( 'application/vnd.pgrst.plan+text' )
93
92
) {
94
- data = text
93
+ data = body
95
94
} else {
96
- data = JSON . parse ( text )
95
+ data = JSON . parse ( body )
97
96
}
98
97
}
99
98
@@ -114,7 +113,7 @@ export default abstract class PostgrestBuilder<Result>
114
113
}
115
114
116
115
if ( error && this . allowEmpty && error ?. details ?. includes ( 'Results contain 0 rows' ) ) {
117
- error = undefined
116
+ error = null
118
117
status = 200
119
118
statusText = 'OK'
120
119
}
@@ -142,10 +141,10 @@ export default abstract class PostgrestBuilder<Result>
142
141
hint : '' ,
143
142
code : fetchError . code || '' ,
144
143
} ,
145
- data : undefined ,
146
- count : undefined ,
147
- status : 400 ,
148
- statusText : 'Bad Request ' ,
144
+ data : null ,
145
+ count : null ,
146
+ status : 0 ,
147
+ statusText : '' ,
149
148
} ) )
150
149
}
151
150
0 commit comments