-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
types.ts
64 lines (58 loc) · 1.45 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
export type Fetch = typeof fetch
/**
* Response format
*
*/
export interface FunctionsResponseSuccess<T> {
data: T
error: null
}
export interface FunctionsResponseFailure {
data: null
error: any
}
export type FunctionsResponse<T> = FunctionsResponseSuccess<T> | FunctionsResponseFailure
export class FunctionsError extends Error {
context: any
constructor(message: string, name = 'FunctionsError', context?: any) {
super(message)
super.name = name
this.context = context
}
}
export class FunctionsFetchError extends FunctionsError {
constructor(context: any) {
super('Failed to send a request to the Edge Function', 'FunctionsFetchError', context)
}
}
export class FunctionsRelayError extends FunctionsError {
constructor(context: any) {
super('Relay Error invoking the Edge Function', 'FunctionsRelayError', context)
}
}
export class FunctionsHttpError extends FunctionsError {
constructor(context: any) {
super('Edge Function returned a non-2xx status code', 'FunctionsHttpError', context)
}
}
export type FunctionInvokeOptions = {
/**
* Object representing the headers to send with the request.
* */
headers?: { [key: string]: string }
/**
* The HTTP verb of the request
*/
method?: "POST"| "GET"| "PUT" | "PATCH" | "DELETE"
/**
* The body of the request.
*/
body?:
| File
| Blob
| ArrayBuffer
| FormData
| ReadableStream<Uint8Array>
| Record<string, any>
| string
}