1
1
// @ts -ignore
2
2
import nodeFetch from '@supabase/node-fetch'
3
3
4
- import type { Fetch , PostgrestSingleResponse } from './types'
4
+ import type { Fetch , PostgrestResponseSuccess , PostgrestSingleResponse } from './types'
5
5
6
- export default abstract class PostgrestBuilder < Result >
6
+ export default abstract class PostgrestBuilder < Result , ThrowOnError extends boolean = false >
7
7
implements PromiseLike < PostgrestSingleResponse < Result > >
8
8
{
9
9
protected method : 'GET' | 'HEAD' | 'POST' | 'PATCH' | 'DELETE'
10
10
protected url : URL
11
11
protected headers : Record < string , string >
12
12
protected schema ?: string
13
13
protected body ?: unknown
14
- protected shouldThrowOnError = false
14
+ protected shouldThrowOnError : boolean
15
15
protected signal ?: AbortSignal
16
16
protected fetch : Fetch
17
17
protected isMaybeSingle : boolean
18
18
19
- constructor ( builder : PostgrestBuilder < Result > ) {
19
+ constructor ( builder : PostgrestBuilder < Result , ThrowOnError > ) {
20
20
this . method = builder . method
21
21
this . url = builder . url
22
22
this . headers = builder . headers
@@ -35,20 +35,18 @@ export default abstract class PostgrestBuilder<Result>
35
35
}
36
36
}
37
37
38
- /**
39
- * If there's an error with the query, throwOnError will reject the promise by
40
- * throwing the error instead of returning it as part of a successful response.
41
- *
42
- * {@link https://github.com/supabase/supabase-js/issues/92}
43
- */
44
- throwOnError ( ) : this {
38
+ throwOnError ( ) : PostgrestBuilder < Result , true > {
45
39
this . shouldThrowOnError = true
46
- return this
40
+ return this as PostgrestBuilder < Result , true >
47
41
}
48
42
49
43
then < TResult1 = PostgrestSingleResponse < Result > , TResult2 = never > (
50
44
onfulfilled ?:
51
- | ( ( value : PostgrestSingleResponse < Result > ) => TResult1 | PromiseLike < TResult1 > )
45
+ | ( (
46
+ value : ThrowOnError extends true
47
+ ? PostgrestResponseSuccess < Result >
48
+ : PostgrestSingleResponse < Result >
49
+ ) => TResult1 | PromiseLike < TResult1 > )
52
50
| undefined
53
51
| null ,
54
52
onrejected ?: ( ( reason : any ) => TResult2 | PromiseLike < TResult2 > ) | undefined | null
0 commit comments