@colisweb/rescript-toolkit 2.10.0 → 2.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module type Config = {
|
|
2
|
+
module Request: Toolkit__Request2.Config
|
|
3
|
+
let key: Request.argument => array<string>
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
module Make = (Config: Config) => {
|
|
7
|
+
let key: Config.Request.argument => array<string> = Config.key
|
|
8
|
+
|
|
9
|
+
let use = (
|
|
10
|
+
~options: option<Swr.fetcherOptions>=?,
|
|
11
|
+
key: option<Config.Request.argument>,
|
|
12
|
+
): Toolkit__Hooks.fetcher<Config.Request.response> =>
|
|
13
|
+
Toolkit__Hooks.useFetcher(~options?, key->Option.map(Config.key), () => {
|
|
14
|
+
let key = key->Option.getExn
|
|
15
|
+
|
|
16
|
+
Config.Request.exec(key)->Promise.Js.fromResult
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
let useOptional = (
|
|
20
|
+
~options: option<Swr.fetcherOptions>=?,
|
|
21
|
+
key: option<Config.Request.argument>,
|
|
22
|
+
): Toolkit__Hooks.fetcher<option<Config.Request.response>> =>
|
|
23
|
+
Toolkit__Hooks.useOptionalFetcher(~options?, key->Option.map(Config.key), () => {
|
|
24
|
+
let key = key->Option.getExn
|
|
25
|
+
|
|
26
|
+
Config.Request.exec(key)->Promise.Js.fromResult
|
|
27
|
+
})
|
|
28
|
+
}
|
package/src/vendors/Axios2.res
CHANGED
|
@@ -23,24 +23,24 @@ type auth = {
|
|
|
23
23
|
}
|
|
24
24
|
type proxy = {host: int, port: int, auth: auth}
|
|
25
25
|
|
|
26
|
-
type response<'data
|
|
26
|
+
type response<'data> = {
|
|
27
27
|
data: 'data,
|
|
28
28
|
status: int,
|
|
29
29
|
statusText: string,
|
|
30
|
-
headers: Js.t<
|
|
30
|
+
headers: Js.Dict.t<string>,
|
|
31
31
|
config: config,
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
type error<'responseData
|
|
35
|
-
request: option<
|
|
36
|
-
response: option<response<'responseData
|
|
34
|
+
type error<'responseData> = {
|
|
35
|
+
request: option<Js.Json.t>,
|
|
36
|
+
response: option<response<'responseData>>,
|
|
37
37
|
message: string,
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
type adapter<'a, 'b, 'err> = config => Promise.Js.t<response<'a
|
|
40
|
+
type adapter<'a, 'b, 'err> = config => Promise.Js.t<response<'a>, 'err>
|
|
41
41
|
|
|
42
42
|
@module("axios")
|
|
43
|
-
external isAxiosError: error<'a
|
|
43
|
+
external isAxiosError: error<'a> => bool = "isAxiosError"
|
|
44
44
|
|
|
45
45
|
@obj
|
|
46
46
|
external makeConfig: (
|
|
@@ -72,24 +72,15 @@ external makeConfig: (
|
|
|
72
72
|
) => config = ""
|
|
73
73
|
|
|
74
74
|
@module("axios")
|
|
75
|
-
external get: (string, ~config: config=?, unit) => Promise.Js.t<response<'data
|
|
76
|
-
"get"
|
|
75
|
+
external get: (string, ~config: config=?, unit) => Promise.Js.t<response<'data>, 'err> = "get"
|
|
77
76
|
|
|
78
77
|
@module("axios")
|
|
79
|
-
external post: (
|
|
80
|
-
|
|
81
|
-
~data: 'a,
|
|
82
|
-
~config: config=?,
|
|
83
|
-
unit,
|
|
84
|
-
) => Promise.Js.t<response<'data, 'headers>, 'err> = "post"
|
|
78
|
+
external post: (string, ~data: 'a, ~config: config=?, unit) => Promise.Js.t<response<'data>, 'err> =
|
|
79
|
+
"post"
|
|
85
80
|
|
|
86
81
|
@module("axios")
|
|
87
|
-
external put: (
|
|
88
|
-
|
|
89
|
-
~data: 'a,
|
|
90
|
-
~config: config=?,
|
|
91
|
-
unit,
|
|
92
|
-
) => Promise.Js.t<response<'data, 'headers>, 'err> = "put"
|
|
82
|
+
external put: (string, ~data: 'a, ~config: config=?, unit) => Promise.Js.t<response<'data>, 'err> =
|
|
83
|
+
"put"
|
|
93
84
|
|
|
94
85
|
@module("axios")
|
|
95
86
|
external patch: (
|
|
@@ -97,21 +88,14 @@ external patch: (
|
|
|
97
88
|
~data: 'a,
|
|
98
89
|
~config: config=?,
|
|
99
90
|
unit,
|
|
100
|
-
) => Promise.Js.t<response<'data
|
|
91
|
+
) => Promise.Js.t<response<'data>, 'err> = "patch"
|
|
101
92
|
|
|
102
93
|
@module("axios")
|
|
103
|
-
external delete: (
|
|
104
|
-
string,
|
|
105
|
-
~config: config=?,
|
|
106
|
-
unit,
|
|
107
|
-
) => Promise.Js.t<response<'data, 'headers>, 'err> = "delete"
|
|
94
|
+
external delete: (string, ~config: config=?, unit) => Promise.Js.t<response<'data>, 'err> = "delete"
|
|
108
95
|
|
|
109
96
|
@module("axios")
|
|
110
|
-
external options: (
|
|
111
|
-
|
|
112
|
-
~config: config=?,
|
|
113
|
-
unit,
|
|
114
|
-
) => Promise.Js.t<response<'data, 'headers>, 'err> = "options"
|
|
97
|
+
external options: (string, ~config: config=?, unit) => Promise.Js.t<response<'data>, 'err> =
|
|
98
|
+
"options"
|
|
115
99
|
|
|
116
100
|
module Interceptors = {
|
|
117
101
|
@module("axios") @scope(("default", "interceptors", "request"))
|
|
@@ -123,19 +107,15 @@ module Interceptors = {
|
|
|
123
107
|
}
|
|
124
108
|
|
|
125
109
|
module WithResult = {
|
|
126
|
-
type customError<'apiError, 'response
|
|
127
|
-
| #default(error<'response
|
|
110
|
+
type customError<'apiError, 'response> = [
|
|
111
|
+
| #default(error<'response>)
|
|
128
112
|
| #decodeError(Decco.decodeError)
|
|
129
113
|
| #custom('apiError)
|
|
130
114
|
]
|
|
131
115
|
|
|
132
116
|
type decodeData<'newData, 'err> = Js.Json.t => result<'newData, 'err>
|
|
133
117
|
|
|
134
|
-
type mapError<'a, 'response, 'headers, 'request> = error<
|
|
135
|
-
'response,
|
|
136
|
-
'headers,
|
|
137
|
-
'request,
|
|
138
|
-
> => customError<'a, 'response, 'headers, 'request>
|
|
118
|
+
type mapError<'a, 'response, 'headers, 'request> = error<'response> => customError<'a, 'response>
|
|
139
119
|
|
|
140
120
|
let toResult = (promise, ~mapError, ~decodeData) =>
|
|
141
121
|
promise
|
|
@@ -151,53 +131,47 @@ module WithResult = {
|
|
|
151
131
|
})
|
|
152
132
|
|
|
153
133
|
let get = (
|
|
154
|
-
string,
|
|
155
134
|
~config=?,
|
|
156
135
|
~decodeData: decodeData<'newData, 'err>,
|
|
157
136
|
~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
|
|
158
|
-
|
|
159
|
-
) => get(string, ~config?,
|
|
137
|
+
string,
|
|
138
|
+
) => get(string, ~config?, ())->toResult(~decodeData, ~mapError)
|
|
160
139
|
|
|
161
140
|
let post = (
|
|
162
|
-
string,
|
|
163
141
|
~data,
|
|
164
142
|
~config=?,
|
|
165
143
|
~decodeData: decodeData<'newData, 'err>,
|
|
166
144
|
~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
|
|
167
|
-
|
|
168
|
-
) => post(string, ~data, ~config?,
|
|
145
|
+
string,
|
|
146
|
+
) => post(string, ~data, ~config?, ())->toResult(~decodeData, ~mapError)
|
|
169
147
|
|
|
170
148
|
let put = (
|
|
171
|
-
string,
|
|
172
149
|
~data,
|
|
173
150
|
~config=?,
|
|
174
151
|
~decodeData: decodeData<'newData, 'err>,
|
|
175
152
|
~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
|
|
176
|
-
|
|
177
|
-
) => put(string, ~data, ~config?,
|
|
153
|
+
string,
|
|
154
|
+
) => put(string, ~data, ~config?, ())->toResult(~decodeData, ~mapError)
|
|
178
155
|
|
|
179
156
|
let patch = (
|
|
180
|
-
string,
|
|
181
157
|
~data,
|
|
182
158
|
~config=?,
|
|
183
159
|
~decodeData: decodeData<'newData, 'err>,
|
|
184
160
|
~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
|
|
185
|
-
|
|
186
|
-
) => patch(string, ~data, ~config?,
|
|
161
|
+
string,
|
|
162
|
+
) => patch(string, ~data, ~config?, ())->toResult(~decodeData, ~mapError)
|
|
187
163
|
|
|
188
164
|
let delete = (
|
|
189
|
-
string,
|
|
190
165
|
~config=?,
|
|
191
166
|
~decodeData: decodeData<'newData, 'err>,
|
|
192
167
|
~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
|
|
193
|
-
|
|
194
|
-
) => delete(string, ~config?,
|
|
168
|
+
string,
|
|
169
|
+
) => delete(string, ~config?, ())->toResult(~decodeData, ~mapError)
|
|
195
170
|
|
|
196
171
|
let options = (
|
|
197
|
-
string,
|
|
198
172
|
~config=?,
|
|
199
173
|
~decodeData: decodeData<'newData, 'err>,
|
|
200
174
|
~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
|
|
201
|
-
|
|
202
|
-
) => options(string, ~config?,
|
|
175
|
+
string,
|
|
176
|
+
) => options(string, ~config?, ())->toResult(~decodeData, ~mapError)
|
|
203
177
|
}
|
|
@@ -53,6 +53,11 @@ external parseISO: string => Js.Date.t = "parseISO"
|
|
|
53
53
|
|
|
54
54
|
@module("date-fns") external formatWithPattern: (Js.Date.t, string) => string = "format"
|
|
55
55
|
|
|
56
|
+
type formatWithPatternOptions = {locale: dateFnsLocale}
|
|
57
|
+
@module("date-fns")
|
|
58
|
+
external formatWithPatternWithOptions: (Js.Date.t, string, formatWithPatternOptions) => string =
|
|
59
|
+
"format"
|
|
60
|
+
|
|
56
61
|
// set
|
|
57
62
|
|
|
58
63
|
@module("date-fns")
|