@colisweb/rescript-toolkit 2.13.0 → 2.13.3
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/bsconfig.json +0 -1
- package/package.json +1 -1
- package/src/logger/Toolkit__BrowserLogger.res +11 -29
- package/src/request/Toolkit__Request.res +3 -191
- package/src/unleash/Toolkit__Unleash.res +1 -1
- package/src/vendors/{Axios2.res → Axios.res} +0 -0
- package/src/vendors/BsReactSelect.res +65 -0
- package/src/fetcher/Toolkit__Fetcher2.res +0 -28
- package/src/request/Toolkit__Request2.res +0 -12
package/bsconfig.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
open BsSentry
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type t
|
|
4
|
+
@val external windowInstance: option<t> = "window"
|
|
5
|
+
@val external window: t = "window"
|
|
6
|
+
@val external process: t = "import.meta.env"
|
|
7
|
+
let get = () => Js.typeof(windowInstance) !== "undefined" ? window : process
|
|
8
|
+
let instance = get()
|
|
9
|
+
|
|
10
|
+
@get external _nodeEnv: t => string = "NODE_ENV"
|
|
11
|
+
|
|
12
|
+
let nodeEnv = instance->_nodeEnv
|
|
4
13
|
|
|
5
14
|
let debugStyle = "background-color: #208E9C; color: white; padding: 5px; font-size: 10px;"
|
|
6
15
|
let warningStyle = "background-color: #FFAD2D; color: white; padding: 5px; font-size: 10px;"
|
|
@@ -19,7 +28,7 @@ let debug2 = (str, str2) => {
|
|
|
19
28
|
}
|
|
20
29
|
let debug3 = (str, str2, str3) => {
|
|
21
30
|
if nodeEnv !== "production" {
|
|
22
|
-
Js.Console.logMany(["%cDEBUG", debugStyle, str, str2, str3])
|
|
31
|
+
Js.Console.logMany(["%cDEBUG", debugStyle, Obj.magic(str), Obj.magic(str2), Obj.magic(str3)])
|
|
23
32
|
}
|
|
24
33
|
}
|
|
25
34
|
|
|
@@ -63,30 +72,3 @@ let error2 = (str, str2) => {
|
|
|
63
72
|
})
|
|
64
73
|
}
|
|
65
74
|
}
|
|
66
|
-
|
|
67
|
-
let error3 = (str, str2, str3) => {
|
|
68
|
-
if nodeEnv !== "production" {
|
|
69
|
-
Js.Console.logMany(["%cERROR", errorStyle, str, str2, str3])
|
|
70
|
-
} else {
|
|
71
|
-
open Sentry
|
|
72
|
-
withScope(scope => {
|
|
73
|
-
scope->Scope.setExtra("1-data", str2)
|
|
74
|
-
scope->Scope.setExtra("2-data", str3)
|
|
75
|
-
captureMessage(Obj.magic(str))
|
|
76
|
-
})
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
let error4 = (str, str2, str3, str4) => {
|
|
81
|
-
if nodeEnv !== "production" {
|
|
82
|
-
Js.Console.logMany(["%cERROR", errorStyle, str, str2, str3, str4])
|
|
83
|
-
} else {
|
|
84
|
-
open Sentry
|
|
85
|
-
withScope(scope => {
|
|
86
|
-
scope->Scope.setExtra("1-data", str2)
|
|
87
|
-
scope->Scope.setExtra("2-data", str3)
|
|
88
|
-
scope->Scope.setExtra("3-data", str4)
|
|
89
|
-
captureMessage(Obj.magic(str))
|
|
90
|
-
})
|
|
91
|
-
}
|
|
92
|
-
}
|
|
@@ -1,200 +1,12 @@
|
|
|
1
|
-
type config
|
|
2
|
-
type headers
|
|
3
|
-
type undecodedData
|
|
4
|
-
type failedResponseData
|
|
5
|
-
|
|
6
|
-
type undecodedResponse = {
|
|
7
|
-
data: undecodedData,
|
|
8
|
-
headers: headers,
|
|
9
|
-
config: config,
|
|
10
|
-
status: int,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
type noResponse = {
|
|
14
|
-
message: string,
|
|
15
|
-
config: config,
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type rec failedResponse = {
|
|
19
|
-
message: string,
|
|
20
|
-
config: config,
|
|
21
|
-
response: response,
|
|
22
|
-
}
|
|
23
|
-
and response = {
|
|
24
|
-
data: failedResponseData,
|
|
25
|
-
headers: headers,
|
|
26
|
-
status: int,
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
external castToJs: 'a => Js.t<'b> = "%identity"
|
|
30
|
-
external castToFailedResponse: Js.Promise.error => failedResponse = "%identity"
|
|
31
|
-
external castToNoResponse: Js.Promise.error => noResponse = "%identity"
|
|
32
|
-
external castToUndecodedResponse: Js.t<'a> => undecodedResponse = "%identity"
|
|
33
|
-
|
|
34
|
-
type error<'a> = [
|
|
35
|
-
| #noResponse(noResponse)
|
|
36
|
-
| #invalidResponse(failedResponse)
|
|
37
|
-
| #invalidResponseData(undecodedResponse, string)
|
|
38
|
-
| #invalidErrorData
|
|
39
|
-
| #unknown(Js.Promise.error)
|
|
40
|
-
| #custom('a)
|
|
41
|
-
]
|
|
42
|
-
|
|
43
|
-
let toResult = (
|
|
44
|
-
promise,
|
|
45
|
-
~mapError: option<failedResponse => option<result<'data, error<'a>>>>=?,
|
|
46
|
-
~errorDecoder=?,
|
|
47
|
-
mapData: Js.Json.t => result<'data, Decco.decodeError>,
|
|
48
|
-
): Promise.promise<result<'data, error<'error>>> =>
|
|
49
|
-
promise
|
|
50
|
-
->Promise.Js.fromBsPromise
|
|
51
|
-
->Promise.Js.toResult
|
|
52
|
-
->Promise.map(res =>
|
|
53
|
-
switch res {
|
|
54
|
-
| Ok(response) =>
|
|
55
|
-
switch response["data"]->mapData {
|
|
56
|
-
| Ok(_) as ok => ok
|
|
57
|
-
| Error(error) => {
|
|
58
|
-
Toolkit__BrowserLogger.error2("Decoder failure", error)
|
|
59
|
-
Error(
|
|
60
|
-
#invalidResponseData(
|
|
61
|
-
response->castToUndecodedResponse,
|
|
62
|
-
"\"" ++ (error.path ++ ("\" " ++ error.message)),
|
|
63
|
-
),
|
|
64
|
-
)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
| Error(error) =>
|
|
68
|
-
if (error->castToJs)["response"] {
|
|
69
|
-
switch (mapError, errorDecoder) {
|
|
70
|
-
| (_, Some(errorDecoder)) =>
|
|
71
|
-
let error = (error->castToFailedResponse).response.data->Obj.magic->errorDecoder
|
|
72
|
-
|
|
73
|
-
switch error {
|
|
74
|
-
| Ok(err) => Error(#custom(err))
|
|
75
|
-
| Error(_err) =>
|
|
76
|
-
Toolkit__BrowserLogger.error2("errorDecoder", _err)
|
|
77
|
-
|
|
78
|
-
Error(#invalidErrorData)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
| (Some(mapError), _) =>
|
|
82
|
-
switch error->castToFailedResponse->mapError {
|
|
83
|
-
| None => Error(#invalidResponse(error->castToFailedResponse))
|
|
84
|
-
| Some(result) => result
|
|
85
|
-
}
|
|
86
|
-
| _ => Error(#invalidResponse(error->castToFailedResponse))
|
|
87
|
-
}
|
|
88
|
-
} else if (error->castToJs)["request"] {
|
|
89
|
-
Error(#noResponse(error->castToNoResponse))
|
|
90
|
-
} else {
|
|
91
|
-
Error(#unknown(error))
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
type requestError<'a> = error<'a>
|
|
97
|
-
|
|
98
1
|
module type Config = {
|
|
99
2
|
type argument
|
|
100
3
|
type response
|
|
101
4
|
type error
|
|
102
|
-
let exec: argument => Promise.promise<
|
|
5
|
+
let exec: argument => Promise.promise<
|
|
6
|
+
result<response, Axios.WithResult.customError<error, Js.Json.t>>,
|
|
7
|
+
>
|
|
103
8
|
}
|
|
104
9
|
|
|
105
10
|
module Make = (Config: Config) => {
|
|
106
11
|
include Config
|
|
107
12
|
}
|
|
108
|
-
|
|
109
|
-
/* Http method */
|
|
110
|
-
|
|
111
|
-
let get = (
|
|
112
|
-
request: Axios.Instance.t,
|
|
113
|
-
url: string,
|
|
114
|
-
~mapError: option<failedResponse => option<result<'data, error<'a>>>>=?,
|
|
115
|
-
~errorDecoder=?,
|
|
116
|
-
mapData: Js.Json.t => result<'response, Decco.decodeError>,
|
|
117
|
-
): Promise.promise<result<'response, error<'error>>> =>
|
|
118
|
-
request->Axios.Instance.get(url)->toResult(~mapError?, ~errorDecoder?, mapData)
|
|
119
|
-
|
|
120
|
-
let getc = (
|
|
121
|
-
request: Axios.Instance.t,
|
|
122
|
-
url: string,
|
|
123
|
-
~mapError: option<failedResponse => option<result<'data, error<'a>>>>=?,
|
|
124
|
-
~errorDecoder=?,
|
|
125
|
-
~config,
|
|
126
|
-
mapData: Js.Json.t => result<'response, Decco.decodeError>,
|
|
127
|
-
): Promise.promise<result<'response, error<'error>>> =>
|
|
128
|
-
request->Axios.Instance.getc(url, config)->toResult(~mapError?, ~errorDecoder?, mapData)
|
|
129
|
-
|
|
130
|
-
let post = (
|
|
131
|
-
request: Axios.Instance.t,
|
|
132
|
-
url: string,
|
|
133
|
-
~mapError: option<failedResponse => option<result<'data, error<'a>>>>=?,
|
|
134
|
-
~errorDecoder=?,
|
|
135
|
-
mapData: Js.Json.t => result<'response, Decco.decodeError>,
|
|
136
|
-
): Promise.promise<result<'response, error<'error>>> =>
|
|
137
|
-
request->Axios.Instance.post(url)->toResult(~mapError?, ~errorDecoder?, mapData)
|
|
138
|
-
|
|
139
|
-
let postData = (
|
|
140
|
-
request: Axios.Instance.t,
|
|
141
|
-
url: string,
|
|
142
|
-
~mapError: option<failedResponse => option<result<'data, error<'a>>>>=?,
|
|
143
|
-
~errorDecoder=?,
|
|
144
|
-
~config=?,
|
|
145
|
-
mapData: Js.Json.t => result<'response, Decco.decodeError>,
|
|
146
|
-
body: Js.Json.t,
|
|
147
|
-
): Promise.promise<result<'response, error<'error>>> =>
|
|
148
|
-
switch config {
|
|
149
|
-
| None =>
|
|
150
|
-
request
|
|
151
|
-
->Axios.Instance.postData(url, body->castToJs)
|
|
152
|
-
->toResult(~mapError?, ~errorDecoder?, mapData)
|
|
153
|
-
| Some(c) =>
|
|
154
|
-
request
|
|
155
|
-
->Axios.Instance.postDatac(url, body->castToJs, c)
|
|
156
|
-
->toResult(~mapError?, ~errorDecoder?, mapData)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
let put = (
|
|
160
|
-
request: Axios.Instance.t,
|
|
161
|
-
url: string,
|
|
162
|
-
~mapError: option<failedResponse => option<result<'data, error<'a>>>>=?,
|
|
163
|
-
~errorDecoder=?,
|
|
164
|
-
mapData: Js.Json.t => result<'response, Decco.decodeError>,
|
|
165
|
-
): Promise.promise<result<'response, error<'error>>> =>
|
|
166
|
-
request->Axios.Instance.put(url)->toResult(~mapError?, ~errorDecoder?, mapData)
|
|
167
|
-
|
|
168
|
-
let putData = (
|
|
169
|
-
request: Axios.Instance.t,
|
|
170
|
-
url: string,
|
|
171
|
-
~mapError: option<failedResponse => option<result<'data, error<'a>>>>=?,
|
|
172
|
-
~errorDecoder=?,
|
|
173
|
-
~config=?,
|
|
174
|
-
mapData: Js.Json.t => result<'response, Decco.decodeError>,
|
|
175
|
-
body: Js.Json.t,
|
|
176
|
-
): Promise.promise<result<'response, error<'error>>> =>
|
|
177
|
-
switch config {
|
|
178
|
-
| None =>
|
|
179
|
-
request
|
|
180
|
-
->Axios.Instance.putData(url, body->castToJs)
|
|
181
|
-
->toResult(~mapError?, ~errorDecoder?, mapData)
|
|
182
|
-
| Some(c) =>
|
|
183
|
-
request
|
|
184
|
-
->Axios.Instance.putDatac(url, body->castToJs, c)
|
|
185
|
-
->toResult(~mapError?, ~errorDecoder?, mapData)
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
let delete = (
|
|
189
|
-
request: Axios.Instance.t,
|
|
190
|
-
url: string,
|
|
191
|
-
~mapError: option<failedResponse => option<result<'data, error<'a>>>>=?,
|
|
192
|
-
~errorDecoder=?,
|
|
193
|
-
~config=?,
|
|
194
|
-
mapData: Js.Json.t => result<'response, Decco.decodeError>,
|
|
195
|
-
): Promise.promise<result<'response, error<'error>>> =>
|
|
196
|
-
switch config {
|
|
197
|
-
| None => request->Axios.Instance.delete(url)->toResult(~mapError?, ~errorDecoder?, mapData)
|
|
198
|
-
| Some(c) =>
|
|
199
|
-
request->Axios.Instance.deletec(url, c)->toResult(~mapError?, ~errorDecoder?, mapData)
|
|
200
|
-
}
|
|
@@ -27,7 +27,7 @@ module MakeFeature = (C: Config) => {
|
|
|
27
27
|
type t = config<C.argument>
|
|
28
28
|
|
|
29
29
|
let exec = (var: C.input) =>
|
|
30
|
-
|
|
30
|
+
Axios.get(C.envUrl ++ C.featureName, ())
|
|
31
31
|
->Promise.Js.toResult
|
|
32
32
|
->Promise.flatMapOk(({data}) => {
|
|
33
33
|
Promise.resolved(t_decode(data))
|
|
File without changes
|
|
@@ -127,3 +127,68 @@ module ReactAsyncSelectMultiple = {
|
|
|
127
127
|
~loadOptions: string => Promise.Js.t<array<labelOption<'value>>, string>,
|
|
128
128
|
) => React.element = "default"
|
|
129
129
|
}
|
|
130
|
+
|
|
131
|
+
module ReactSelectMultipleCreateInput = {
|
|
132
|
+
module ReactSelect = {
|
|
133
|
+
type components = {"DropDownIndicator": React.element}
|
|
134
|
+
|
|
135
|
+
@module("react-select/creatable") @react.component
|
|
136
|
+
external make: (
|
|
137
|
+
~components: components,
|
|
138
|
+
~inputValue: string,
|
|
139
|
+
~isClearable: option<bool>=?,
|
|
140
|
+
~isMulti: option<bool>=?,
|
|
141
|
+
~menuIsOpen: option<bool>=?,
|
|
142
|
+
~onChange: array<string> => unit,
|
|
143
|
+
~onInputChange: string => unit,
|
|
144
|
+
~onKeyDown: ReactEvent.Keyboard.t => unit,
|
|
145
|
+
~placeholder: option<string>=?,
|
|
146
|
+
~value: array<string>,
|
|
147
|
+
~isDisabled: option<bool>=?,
|
|
148
|
+
~isLoading: option<bool>=?,
|
|
149
|
+
~className: option<string>=?,
|
|
150
|
+
) => React.element = "CreatableSelect"
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@react.component
|
|
154
|
+
let make = (
|
|
155
|
+
~inputValue: string,
|
|
156
|
+
~onInputChange: string => unit,
|
|
157
|
+
~value: array<string>,
|
|
158
|
+
~onChange: array<string> => unit,
|
|
159
|
+
~isClearable=true,
|
|
160
|
+
~placeholder="",
|
|
161
|
+
~isDisabled=false,
|
|
162
|
+
~isLoading=false,
|
|
163
|
+
~className="",
|
|
164
|
+
) =>
|
|
165
|
+
<ReactSelect
|
|
166
|
+
components={"DropDownIndicator": React.null}
|
|
167
|
+
isMulti=true
|
|
168
|
+
onKeyDown={e => {
|
|
169
|
+
if inputValue === "" {
|
|
170
|
+
()
|
|
171
|
+
} else {
|
|
172
|
+
switch e->ReactEvent.Keyboard.key {
|
|
173
|
+
| "Enter"
|
|
174
|
+
| "Tab" => {
|
|
175
|
+
onInputChange("")
|
|
176
|
+
onChange(value->Array.concat([inputValue]))
|
|
177
|
+
e->ReactEvent.Keyboard.preventDefault
|
|
178
|
+
}
|
|
179
|
+
| _ => ()
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}}
|
|
183
|
+
menuIsOpen={false}
|
|
184
|
+
inputValue
|
|
185
|
+
isClearable
|
|
186
|
+
onChange
|
|
187
|
+
onInputChange
|
|
188
|
+
placeholder
|
|
189
|
+
value
|
|
190
|
+
isDisabled
|
|
191
|
+
isLoading
|
|
192
|
+
className
|
|
193
|
+
/>
|
|
194
|
+
}
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
}
|