-
-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathtypes.ts
79 lines (69 loc) · 1.87 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
export type Fetch = typeof fetch
/**
* Error format
*
* {@link https://postgrest.org/en/stable/api.html?highlight=options#errors-and-http-status-codes}
*/
export type PostgrestError = {
message: string
details: string
hint: string
code: string
}
/**
* Response format
*
* {@link https://github.com/supabase/supabase-js/issues/32}
*/
interface PostgrestResponseBase {
status: number
statusText: string
}
interface PostgrestResponseSuccess<T> extends PostgrestResponseBase {
error: null
data: T[]
count: number | null
}
interface PostgrestResponseFailure extends PostgrestResponseBase {
error: PostgrestError
data: null
count: null
}
export type PostgrestResponse<T, ThrowOnError> = ThrowOnError extends true
? PostgrestResponseSuccess<T>
: PostgrestResponseSuccess<T> | PostgrestResponseFailure
interface PostgrestSingleResponseSuccess<T> extends PostgrestResponseBase {
error: null
data: T
count: number | null
}
export type PostgrestSingleResponse<T, ThrowOnError> = ThrowOnError extends true
? PostgrestSingleResponseSuccess<T>
: PostgrestSingleResponseSuccess<T> | PostgrestResponseFailure
export type PostgrestMaybeSingleResponse<T, ThrowOnError> = PostgrestSingleResponse<
T | null,
ThrowOnError
>
export type GenericTable = {
Row: Record<string, unknown>
Insert: Record<string, unknown>
Update: Record<string, unknown>
}
export type GenericUpdatableView = {
Row: Record<string, unknown>
Insert: Record<string, unknown>
Update: Record<string, unknown>
}
export type GenericNonUpdatableView = {
Row: Record<string, unknown>
}
export type GenericView = GenericUpdatableView | GenericNonUpdatableView
export type GenericFunction = {
Args: Record<string, unknown>
Returns: unknown
}
export type GenericSchema = {
Tables: Record<string, GenericTable>
Views: Record<string, GenericView>
Functions: Record<string, GenericFunction>
}