-
Notifications
You must be signed in to change notification settings - Fork 3
/
Fetch.res
179 lines (157 loc) · 5.5 KB
/
Fetch.res
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
module AbortController = Fetch_Abort.Controller
module AbortSignal = Fetch_Abort.Signal
module AbortEvent = Fetch_Abort.Event
module Blob = Fetch_Blob
module FormData = Fetch_FormData
type method = [#GET | #HEAD | #POST | #PUT | #DELETE | #CONNECT | #OPTIONS | #TRACE | #PATCH]
type referrerPolicy = [
| #""
| #"no-referrer"
| #"no-referrer-when-downgrade"
| #"same-origin"
| #origin
| #"strict-origin"
| #"origin-when-cross-origin"
| #"strict-origin-when-cross-origin"
| #"unsafe-url"
]
type requestDestination = [
| #""
| #audio
| #audioworklet
| #document
| #embed
| #font
| #frame
| #iframe
| #image
| #manifest
| #object
| #paintworklet
| #report
| #script
| #sharedworker
| #style
| #track
| #video
| #worker
| #xslt
]
type requestMode = [#navigate | #"same-origin" | #"no-cors" | #cors]
type requestCredentials = [#omit | #"same-origin" | #"include"]
type requestCache = [
| #default
| #"no-store"
| #reload
| #"no-cache"
| #"force-cache"
| #"only-if-cached"
]
type requestRedirect = [#follow | #error | #manual]
type requestDuplex = [#half]
type responseType = [#basic | #cors | #default | #error | #opaque | #opaqueredirect]
module Body = {
type t
external string: string => t = "%identity"
external blob: Blob.t => t = "%identity"
external formData: FormData.t => t = "%identity"
// external bufferSource: bufferSource => t = "%identity"
// external urlSearchParams: urlSearchParams => t = "%identity"
@val external none: t = "null"
}
module Headers = {
type t
type init
module Init = {
external object: {..} => init = "%identity"
external array: array<(string, string)> => init = "%identity"
}
@new external empty: t = "Headers"
@new external make: init => t = "Headers"
/**
* Non-standard
*/ @new external clone: t => t = "Headers"
@new external fromObject: {..} => t = "Headers"
@new external fromArray: array<(string, string)> => t = "Headers"
@send external append: (t, string, string) => unit = "append"
@send external delete: (t, string) => unit = "delete"
@send @return(nullable)
external get: (t, string) => option<string> = "get"
@send external has: (t, string) => bool = "has"
@send external set: (t, string, string) => unit = "set"
// The following are taken from the iterable protocol spec
/**
* Callback arguments are (value, key, headers)
*/ @send
external forEach: (t, @uncurry (string, string, t) => unit) => unit = "forEach"
@send external entries: t => Js.Array.array_like<(string, string)> = "entries"
@send external keys: t => Js.Array.array_like<string> = "keys"
@send external values: t => Js.Array.array_like<string> = "values"
}
module Request = {
type t
type init = {
method?: method,
body?: Body.t,
headers?: Headers.t,
referrer?: string,
referrerPolicy?: referrerPolicy,
mode?: requestMode,
credentials?: requestCredentials,
cache?: requestCache,
redirect?: requestRedirect,
integrity?: string,
keepalive?: bool,
signal?: AbortSignal.t,
duplex?: requestDuplex,
// window?: any // can only be set to null
}
@new external make: (string, init) => t = "Request"
@new external fromRequest: (t, init) => t = "Request"
@get external method: t => method = "method"
@get external url: t => string = "url"
@get external headers: t => Headers.t = "headers"
@get external destination: t => requestDestination = "destination"
@get external referrer: t => string = "referrer"
@get external referrerPolicy: t => referrerPolicy = "referrerPolicy"
@get external mode: t => requestMode = "mode"
@get external credentials: t => requestCredentials = "credentials"
@get external cache: t => requestCache = "cache"
@get external redirect: t => requestRedirect = "redirect"
@get external integrity: t => string = "integrity"
@get external keepalive: t => bool = "keepalive"
@get external isReloadNavigation: t => bool = "isReloadNavigation"
@get external isHistoryNavigation: t => bool = "isHistoryNavigation"
@get external signal: t => AbortSignal.t = "signal"
@send external clone: t => t = "clone"
// Body mixin
// @get external body: t => readableStream = "body"
@get external bodyUsed: t => bool = "bodyUsed"
@send external text: t => promise<string> = "text"
@send external json: t => promise<Js.Json.t> = "json"
@send external blob: t => promise<Blob.t> = "blob"
@send external formData: t => promise<FormData.t> = "formData"
// @send external arrayBuffer: t => promise<arrayBuffer> = "arrayBuffer"
}
module Response = {
type t
@get external type_: t => responseType = "type"
@get external url: t => string = "url"
@get external redirected: t => bool = "redirected"
@get external status: t => int = "status"
@get external ok: t => bool = "ok"
@get external statusText: t => string = "statusText"
@get external headers: t => Headers.t = "headers"
@send external clone: t => t = "clone"
// Body mixin
// @get external body: t => readableStream = "body"
@get external bodyUsed: t => bool = "bodyUsed"
@send external text: t => promise<string> = "text"
@send external json: t => promise<Js.Json.t> = "json"
@send external blob: t => promise<Blob.t> = "blob"
@send external formData: t => promise<FormData.t> = "formData"
// @send external arrayBuffer: t => promise<arrayBuffer> = "arrayBuffer"
}
@val external fetch: (string, Request.init) => promise<Response.t> = "fetch"
@val external get: string => promise<Response.t> = "fetch"
@val external send: Request.t => promise<Response.t> = "fetch"