@colisweb/rescript-toolkit 5.7.1 → 5.8.1
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/.gitlab-ci.yml +1 -1
- package/.secure_files/{ci-functions-v17.7.2 → ci-functions-v17.12.0} +116 -64
- package/.secure_files/{ci-functions-v17.7.0 → ci-functions-v17.12.0-feat-add-mysql-service-1.0.1beta} +138 -83
- package/.secure_files/{ci-functions-v17.7.1 → ci-functions-v17.12.0-feat-add-mysql-service-1.0.2beta} +138 -83
- package/.secure_files/{ci-functions-v17.2.4 → ci-functions-v17.12.0-feat-add-mysql-service-1.0.3beta} +214 -103
- package/.secure_files/ci-functions-v17.12.0-feat-add-mysql-service-1.0.4beta +2658 -0
- package/.secure_files/ci-functions-v17.12.0-feat-add-mysql-service-1.0.5beta +2658 -0
- package/.secure_files/ci-functions-v17.12.0-feat-add-mysql-service-1.0.6beta +2658 -0
- package/.secure_files/ci-functions-v17.12.0-feat-add-mysql-service-1.0.7beta +2658 -0
- package/.secure_files/ci-functions-v17.13.0 +2659 -0
- package/.secure_files/ci-functions-v17.14.0 +2659 -0
- package/package.json +2 -2
- package/rescript.json +5 -2
- package/src/primitives/Toolkit__Primitives.res +0 -8
- package/src/primitives/Toolkit__Primitives_Result.res +18 -0
- package/src/request/Request.res +37 -23
- package/src/request/index.md +79 -82
- package/src/vendors/Swr.res +2 -0
- package/.secure_files/ci-functions-v17.2.1 +0 -2547
- package/.secure_files/ci-functions-v17.2.2 +0 -2547
- package/.secure_files/ci-functions-v17.2.3 +0 -2547
- package/.secure_files/ci-functions-v17.3.0 +0 -2547
- package/.secure_files/ci-functions-v17.3.1 +0 -2547
- package/.secure_files/ci-functions-v17.3.2 +0 -2547
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colisweb/rescript-toolkit",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.8.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rescript clean",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@colisweb/bs-react-intl-extractor-bin": "0.12.2",
|
|
31
31
|
"@datadog/browser-rum": "5.8.0",
|
|
32
|
-
"@dck/rescript-ky": "2.0.
|
|
32
|
+
"@dck/rescript-ky": "2.0.4",
|
|
33
33
|
"@dck/rescript-promise": "1.1.0",
|
|
34
34
|
"@dck/restorative": "1.1.0",
|
|
35
35
|
"@greenlabs/ppx-spice": "0.2.1",
|
package/rescript.json
CHANGED
|
@@ -34,7 +34,9 @@
|
|
|
34
34
|
"@dck/rescript-ky"
|
|
35
35
|
],
|
|
36
36
|
"ppx-flags": [
|
|
37
|
-
[
|
|
37
|
+
[
|
|
38
|
+
"@greenlabs/ppx-spice/ppx"
|
|
39
|
+
],
|
|
38
40
|
"lenses-ppx/ppx",
|
|
39
41
|
"res-react-intl/ppx"
|
|
40
42
|
],
|
|
@@ -46,6 +48,7 @@
|
|
|
46
48
|
"-bs-super-errors",
|
|
47
49
|
"-bs-no-version-header",
|
|
48
50
|
"-open Belt",
|
|
51
|
+
"-open Toolkit__Primitives_Result",
|
|
49
52
|
"-open Cx"
|
|
50
53
|
]
|
|
51
|
-
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Result = {
|
|
2
|
+
include Belt.Result
|
|
3
|
+
|
|
4
|
+
let get = result =>
|
|
5
|
+
switch result {
|
|
6
|
+
| Ok(v) => Some(v)
|
|
7
|
+
| Error(_) => None
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
let mapError = (result: t<'a, 'b>, fn: 'b => 'c) => {
|
|
11
|
+
switch result {
|
|
12
|
+
| Ok(_) as ok => ok
|
|
13
|
+
| Error(err) => Error(fn(err))
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let mapOk = map
|
|
18
|
+
}
|
package/src/request/Request.res
CHANGED
|
@@ -8,13 +8,13 @@ type requestConfig<'apiError, 'response> = {
|
|
|
8
8
|
path: string,
|
|
9
9
|
requestOptions: Ky.requestOptions<Js.Json.t>,
|
|
10
10
|
key?: array<string>,
|
|
11
|
-
mapCustomErrors?: Ky.error => error<'apiError
|
|
12
|
-
mapRawResponse?:
|
|
11
|
+
mapCustomErrors?: Ky.error => Promise.t<error<'apiError>>,
|
|
12
|
+
mapRawResponse?: result<Js.Json.t, Ky.error> => Promise.t<result<'response, error<'apiError>>>,
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
%%private(
|
|
16
16
|
let fetch = (
|
|
17
|
-
~instance
|
|
17
|
+
~instance,
|
|
18
18
|
~path,
|
|
19
19
|
~requestOptions,
|
|
20
20
|
~mapRawResponse=?,
|
|
@@ -25,35 +25,40 @@ type requestConfig<'apiError, 'response> = {
|
|
|
25
25
|
// - parseJson
|
|
26
26
|
// - abort controller signal
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
})
|
|
31
|
-
kyResponse
|
|
32
|
-
->Ky.Response.json()
|
|
28
|
+
(instance->Ky.Instance.asCallable)(path, ~options=requestOptions)
|
|
29
|
+
->Ky.Response.jsonFromPromise()
|
|
33
30
|
->Promise.Js.fromBsPromise
|
|
34
31
|
->Promise.Js.toResult
|
|
35
32
|
->Promise.flatMap(result => {
|
|
36
33
|
let result: result<Js.Json.t, Ky.error> = result->Obj.magic
|
|
37
34
|
|
|
38
35
|
let mapRawResponseOrDecode = switch mapRawResponse {
|
|
39
|
-
| Some(fn) => fn(result
|
|
36
|
+
| Some(fn) => fn(result)
|
|
40
37
|
| None =>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
Promise.resolved(
|
|
39
|
+
switch result {
|
|
40
|
+
| Error(err) => Error(Unknown(err))
|
|
41
|
+
| Ok(response) =>
|
|
42
|
+
switch response->response_decode {
|
|
43
|
+
| Ok(response) => Ok(response)
|
|
44
|
+
| Error(decodeError) => Error(DecodeError(decodeError))
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
)
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
let mappedCustomErrors =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
let mappedCustomErrors = mapRawResponseOrDecode->Promise.flatMapError(error => {
|
|
51
|
+
switch error {
|
|
52
|
+
| Unknown(err) =>
|
|
53
|
+
mapCustomErrors->Option.mapWithDefault(
|
|
54
|
+
Promise.resolved(Error(Unknown(err))),
|
|
55
|
+
fn => fn(err)->Promise.map(v => {Error(v)}),
|
|
56
|
+
)
|
|
57
|
+
| err => Promise.resolved(Error(err))
|
|
58
|
+
}
|
|
59
|
+
})
|
|
55
60
|
|
|
56
|
-
|
|
61
|
+
mappedCustomErrors
|
|
57
62
|
})
|
|
58
63
|
}
|
|
59
64
|
)
|
|
@@ -127,7 +132,7 @@ let useOptionalFetcher = (
|
|
|
127
132
|
and type error = error
|
|
128
133
|
),
|
|
129
134
|
argument: option<argument>,
|
|
130
|
-
): Toolkit__Hooks.fetcher<response
|
|
135
|
+
): Toolkit__Hooks.fetcher<option<response>> => {
|
|
131
136
|
let module(C) = config
|
|
132
137
|
|
|
133
138
|
Toolkit__Hooks.useOptionalFetcher(
|
|
@@ -210,3 +215,12 @@ let decodeResponseError = (responseError, decoder) => {
|
|
|
210
215
|
->Promise.mapError(Obj.magic)
|
|
211
216
|
->Promise.flatMapOk(json => json->decoder->Promise.resolved)
|
|
212
217
|
}
|
|
218
|
+
|
|
219
|
+
let decodeRawResponse = (result: result<Js.Json.t, Ky.error>, decoder): result<
|
|
220
|
+
'a,
|
|
221
|
+
error<'apiError>,
|
|
222
|
+
> => {
|
|
223
|
+
result
|
|
224
|
+
->Result.mapError(err => Unknown(err))
|
|
225
|
+
->Result.flatMap(json => json->decoder->Result.mapError(err => DecodeError(err)))
|
|
226
|
+
}
|
package/src/request/index.md
CHANGED
|
@@ -4,100 +4,97 @@
|
|
|
4
4
|
|
|
5
5
|
```rescript
|
|
6
6
|
module API = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
[@spice]
|
|
12
|
-
type response = array(user)
|
|
13
|
-
[@spice]
|
|
14
|
-
and user = {
|
|
15
|
-
name: string
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
type error = string;
|
|
19
|
-
|
|
20
|
-
let exec = clientId => {
|
|
21
|
-
request->Request.get(baseUrl(~clientId), response_decode);
|
|
22
|
-
};
|
|
23
|
-
};
|
|
7
|
+
let kyInstance = Ky.Instance.create({
|
|
8
|
+
prefixUrl: `${ColiswebApi__Env.v6ApiUrl}`,
|
|
9
|
+
timeout: ColiswebApi__Env.isNodeDevelopment ? 5000 : 20000,
|
|
10
|
+
})
|
|
24
11
|
|
|
25
|
-
|
|
12
|
+
module FetchUsers = {
|
|
13
|
+
type argument = ()
|
|
14
|
+
|
|
15
|
+
@spice
|
|
16
|
+
type user = {
|
|
17
|
+
id: string,
|
|
18
|
+
name: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@spice
|
|
22
|
+
type response = {
|
|
23
|
+
users: array<user>
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type error = unit
|
|
27
|
+
|
|
28
|
+
let config = () => {
|
|
29
|
+
kyInstance,
|
|
30
|
+
requestOptions: {
|
|
31
|
+
method: Ky.HttpMethod.GET,
|
|
32
|
+
},
|
|
33
|
+
key: [
|
|
34
|
+
"FetchUser"
|
|
35
|
+
],
|
|
36
|
+
path: `/users`,
|
|
37
|
+
}
|
|
26
38
|
};
|
|
27
39
|
};
|
|
28
40
|
|
|
29
|
-
API.FetchUsers
|
|
41
|
+
let (data, isLoading, _) = Request.useFetcher(module(API.FetchUsers), Some())
|
|
42
|
+
|
|
43
|
+
Request.fetchAPI(module(API.FetchUsers), Some())
|
|
44
|
+
->Promise.tapOk(({users}) => Js.log(users))
|
|
30
45
|
```
|
|
31
46
|
|
|
32
47
|
### Handle custom error
|
|
33
48
|
|
|
34
49
|
```rescript
|
|
35
50
|
module API = {
|
|
51
|
+
let kyInstance = Ky.Instance.create({
|
|
52
|
+
prefixUrl: `${ColiswebApi__Env.v6ApiUrl}`,
|
|
53
|
+
timeout: ColiswebApi__Env.isNodeDevelopment ? 5000 : 20000,
|
|
54
|
+
})
|
|
55
|
+
|
|
36
56
|
module FetchUsers = {
|
|
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
|
-
let codec: Spice.codec(errorType) = (encoder, decoder);
|
|
70
|
-
|
|
71
|
-
[@spice]
|
|
72
|
-
type t = [@spice.codec codec] errorType;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
module Config = {
|
|
76
|
-
type argument = unit;
|
|
77
|
-
|
|
78
|
-
[@spice]
|
|
79
|
-
type response = array(user)
|
|
80
|
-
[@spice]
|
|
81
|
-
and user = {
|
|
82
|
-
name: string
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
[@spice]
|
|
86
|
-
type error = Error.t;
|
|
87
|
-
|
|
88
|
-
let exec = clientId => {
|
|
89
|
-
request->Request.get(baseUrl(~clientId), ~errorDecoder=error_decode,response_decode);
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
module Request = Toolkit.Request.Make(Config);
|
|
57
|
+
type argument = ()
|
|
58
|
+
|
|
59
|
+
@spice
|
|
60
|
+
type user = {
|
|
61
|
+
id: string,
|
|
62
|
+
name: string
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@spice
|
|
66
|
+
type response = {
|
|
67
|
+
users: array<user>
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
type error = Anything
|
|
71
|
+
|
|
72
|
+
let config = () => {
|
|
73
|
+
kyInstance,
|
|
74
|
+
requestOptions: {
|
|
75
|
+
method: Ky.HttpMethod.GET,
|
|
76
|
+
},
|
|
77
|
+
key: [
|
|
78
|
+
"FetchUser"
|
|
79
|
+
],
|
|
80
|
+
path: `/users`,
|
|
81
|
+
mapCustomErrors: error =>
|
|
82
|
+
switch error.response {
|
|
83
|
+
| Some({status: 409}) => Custom(Anything)
|
|
84
|
+
| _ => Unknown(error)
|
|
85
|
+
}->Promise.resolved,
|
|
86
|
+
}
|
|
94
87
|
};
|
|
95
88
|
};
|
|
96
89
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
90
|
+
|
|
91
|
+
Request.fetchAPI(module(API.FetchUsers), Some())
|
|
92
|
+
->Promise.tapOk(({users}) => Js.log(users))
|
|
93
|
+
->Promise.tapError(error => {
|
|
94
|
+
switch error {
|
|
95
|
+
| Custom(Anything) => ...
|
|
96
|
+
| DecodeError(spiceError) => ...
|
|
97
|
+
| Unknown(kyError) => ...
|
|
98
|
+
}
|
|
99
|
+
})
|
|
103
100
|
```
|
package/src/vendors/Swr.res
CHANGED
|
@@ -95,6 +95,8 @@ module SwrConfig = {
|
|
|
95
95
|
external mutate0: (t, SwrKey.t) => unit = "mutate"
|
|
96
96
|
@send
|
|
97
97
|
external mutateByKey: (t, key) => unit = "mutate"
|
|
98
|
+
@send
|
|
99
|
+
external mutateByKeyWithParams: (t, key, 'data, bool) => unit = "mutate"
|
|
98
100
|
|
|
99
101
|
@send
|
|
100
102
|
external mutate: (t, SwrKey.t, 'data, bool) => unit = "mutate"
|