@@ -19,25 +19,40 @@ interface PostgrestError {
19
19
*/
20
20
interface PostgrestResponse < T > {
21
21
error : PostgrestError | null
22
- data : T | T [ ] | null
22
+ data : T [ ] | null
23
23
status : number
24
24
statusText : string
25
25
// For backward compatibility: body === data
26
- body : T | T [ ] | null
26
+ body : T [ ] | null
27
27
}
28
28
29
- export abstract class PostgrestBuilder < T > implements PromiseLike < any > {
30
- method ! : 'GET' | 'HEAD' | 'POST' | 'PATCH' | 'DELETE'
31
- url ! : URL
32
- headers ! : { [ key : string ] : string }
33
- schema ?: string
34
- body ?: Partial < T > | Partial < T > [ ]
29
+ export interface PostgrestSingleResponse < T > {
30
+ error : PostgrestError | null
31
+ data : T | null
32
+ status : number
33
+ statusText : string
34
+ // For backward compatibility: body === data
35
+ body : T | null
36
+ }
37
+
38
+ export abstract class PostgrestBuilder < T > implements PromiseLike < PostgrestResponse < T > > {
39
+ protected method ! : 'GET' | 'HEAD' | 'POST' | 'PATCH' | 'DELETE'
40
+ protected url ! : URL
41
+ protected headers ! : { [ key : string ] : string }
42
+ protected schema ?: string
43
+ protected body ?: Partial < T > | Partial < T > [ ]
35
44
36
45
constructor ( builder : PostgrestBuilder < T > ) {
37
46
Object . assign ( this , builder )
38
47
}
39
48
40
- then ( onfulfilled ?: ( value : any ) => any , onrejected ?: ( value : any ) => any ) : Promise < any > {
49
+ then < TResult1 = PostgrestResponse < T > , TResult2 = never > (
50
+ onfulfilled ?:
51
+ | ( ( value : PostgrestResponse < T > ) => TResult1 | PromiseLike < TResult1 > )
52
+ | undefined
53
+ | null ,
54
+ onrejected ?: ( value : any ) => any
55
+ ) : Promise < any > {
41
56
// https://postgrest.org/en/stable/api.html#switching-schemas
42
57
if ( typeof this . schema === 'undefined' ) {
43
58
// skip
@@ -64,13 +79,14 @@ export abstract class PostgrestBuilder<T> implements PromiseLike<any> {
64
79
error = await res . json ( )
65
80
data = null
66
81
}
67
- return {
82
+ const postgrestResponse : PostgrestResponse < T > = {
68
83
error,
69
84
data,
70
85
status : res . status ,
71
86
statusText : res . statusText ,
72
87
body : data ,
73
- } as PostgrestResponse < T >
88
+ }
89
+ return postgrestResponse
74
90
} )
75
91
. then ( onfulfilled , onrejected )
76
92
}
0 commit comments