@colisweb/rescript-toolkit 1.26.2 → 1.28.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/package.json +8 -9
- package/src/fetcher/Toolkit__Fetcher.res +2 -5
- package/src/hooks/Toolkit__Hooks.res +8 -24
- package/src/ui/Toolkit__Ui_Dropdown.res +2 -1
- package/src/ui/Toolkit__Ui_Dropdown.resi +1 -0
- package/src/ui/Toolkit__Ui_Snackbar.res +102 -71
- package/src/ui/Toolkit__Ui_Snackbar.resi +1 -1
- package/src/vendors/{BsSwr.res → Swr.res} +17 -8
- package/src/vendors/Msw.res +0 -96
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colisweb/rescript-toolkit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"clean": "rescript clean",
|
|
6
6
|
"build": "rescript build",
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@colisweb/react-day-picker": "7.4.16",
|
|
26
|
-
"@openapi-contrib/openapi-schema-to-json-schema": "3.0.4",
|
|
27
26
|
"@reach/accordion": "0.16.1",
|
|
28
27
|
"@reach/alert-dialog": "0.16.0",
|
|
29
28
|
"@reach/auto-id": "0.16.0",
|
|
@@ -38,15 +37,15 @@
|
|
|
38
37
|
"@reach/tooltip": "0.16.0",
|
|
39
38
|
"@reach/visually-hidden": "0.16.0",
|
|
40
39
|
"@rescript/react": "0.10.3",
|
|
41
|
-
"autoprefixer": "10.3.
|
|
42
|
-
"axios": "0.
|
|
40
|
+
"autoprefixer": "10.3.6",
|
|
41
|
+
"axios": "0.22.0",
|
|
43
42
|
"bs-axios": "0.0.43",
|
|
44
43
|
"bs-css": "13.4.0",
|
|
45
44
|
"bs-css-emotion": "2.4.0",
|
|
46
45
|
"case": "1.6.3",
|
|
47
46
|
"click-outside-hook": "1.1.0",
|
|
48
47
|
"copy-to-clipboard": "3.3.1",
|
|
49
|
-
"date-fns": "2.
|
|
48
|
+
"date-fns": "2.24.0",
|
|
50
49
|
"decco": "1.5.0",
|
|
51
50
|
"dedent": "0.7.0",
|
|
52
51
|
"downshift": "5.2.5",
|
|
@@ -58,7 +57,7 @@
|
|
|
58
57
|
"postcss-preset-env": "6.7.0",
|
|
59
58
|
"prismjs": "1.23.0",
|
|
60
59
|
"react-datepicker": "3.8.0",
|
|
61
|
-
"react-icons": "4.
|
|
60
|
+
"react-icons": "4.3.1",
|
|
62
61
|
"react-select": "4.3.1",
|
|
63
62
|
"react-table": "7.7.0",
|
|
64
63
|
"react-use": "17.3.1",
|
|
@@ -71,8 +70,8 @@
|
|
|
71
70
|
"rescript-react-update": "4.0.0",
|
|
72
71
|
"restorative": "0.4.0-beta.1",
|
|
73
72
|
"string.prototype.matchall": "4.0.5",
|
|
74
|
-
"swr": "0.
|
|
75
|
-
"tailwindcss": "2.2.
|
|
73
|
+
"swr": "1.0.1",
|
|
74
|
+
"tailwindcss": "2.2.16"
|
|
76
75
|
},
|
|
77
76
|
"devDependencies": {
|
|
78
77
|
"@babel/core": "7.15.5",
|
|
@@ -88,6 +87,6 @@
|
|
|
88
87
|
"react": "17.0.2",
|
|
89
88
|
"react-dom": "17.0.2",
|
|
90
89
|
"react-is": "17.0.2",
|
|
91
|
-
"sass": "1.
|
|
90
|
+
"sass": "1.42.1"
|
|
92
91
|
}
|
|
93
92
|
}
|
|
@@ -4,16 +4,13 @@ module type Config = {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
module Make = (Config: Config) => {
|
|
7
|
-
let updateData = (key: Config.Request.argument, ~shouldRevalidate=false, ~data): unit =>
|
|
8
|
-
Toolkit__Hooks.updateFetcherData(Config.key(key), data, shouldRevalidate)
|
|
9
|
-
|
|
10
7
|
let trigger = (key: Config.Request.argument): unit =>
|
|
11
8
|
Toolkit__Hooks.triggerFetcher(Config.key(key))
|
|
12
9
|
|
|
13
10
|
let key: Config.Request.argument => array<string> = Config.key
|
|
14
11
|
|
|
15
12
|
let use = (
|
|
16
|
-
~options: option<
|
|
13
|
+
~options: option<Swr.fetcherOptions>=?,
|
|
17
14
|
key: option<Config.Request.argument>,
|
|
18
15
|
): Toolkit__Hooks.fetcher<Config.Request.response> =>
|
|
19
16
|
Toolkit__Hooks.useFetcher(~options?, key->Option.map(Config.key), () => {
|
|
@@ -23,7 +20,7 @@ module Make = (Config: Config) => {
|
|
|
23
20
|
})
|
|
24
21
|
|
|
25
22
|
let useOptional = (
|
|
26
|
-
~options: option<
|
|
23
|
+
~options: option<Swr.fetcherOptions>=?,
|
|
27
24
|
key: option<Config.Request.argument>,
|
|
28
25
|
): Toolkit__Hooks.fetcher<option<Config.Request.response>> =>
|
|
29
26
|
Toolkit__Hooks.useOptionalFetcher(~options?, key->Option.map(Config.key), () => {
|
|
@@ -57,18 +57,12 @@ let useInitialPreviousDistinct = (~compare=(a, b) => a === b, value) => {
|
|
|
57
57
|
// useFetcher
|
|
58
58
|
// ----------------------
|
|
59
59
|
|
|
60
|
-
type fetcherOptions = BsSwr.fetcherOptions
|
|
61
|
-
|
|
62
|
-
let fetcherOptions = BsSwr.fetcherOptions
|
|
63
|
-
|
|
64
60
|
type fetcher<'data> = ('data, bool, unit => Promise.t<result<bool, Js.Promise.error>>)
|
|
65
61
|
|
|
66
|
-
let
|
|
67
|
-
|
|
68
|
-
let triggerFetcher = BsSwr.trigger
|
|
62
|
+
let triggerFetcher = Swr.trigger
|
|
69
63
|
|
|
70
|
-
let useFetcher = (~options: option<fetcherOptions>=?, key: 'key, fn: 'fn): fetcher<'data> => {
|
|
71
|
-
let
|
|
64
|
+
let useFetcher = (~options: option<Swr.fetcherOptions>=?, key: 'key, fn: 'fn): fetcher<'data> => {
|
|
65
|
+
let {data, isValidating, mutate} = Swr.useSwr(
|
|
72
66
|
key,
|
|
73
67
|
fn,
|
|
74
68
|
Js.Obj.assign(
|
|
@@ -80,18 +74,13 @@ let useFetcher = (~options: option<fetcherOptions>=?, key: 'key, fn: 'fn): fetch
|
|
|
80
74
|
),
|
|
81
75
|
)
|
|
82
76
|
|
|
83
|
-
(
|
|
84
|
-
fetcher.data->Obj.magic,
|
|
85
|
-
fetcher.isValidating,
|
|
86
|
-
() =>
|
|
87
|
-
fetcher.revalidate(BsSwr.revalidateOptions())->Promise.Js.fromBsPromise->Promise.Js.toResult,
|
|
88
|
-
)
|
|
77
|
+
(data->Obj.magic, isValidating, () => Promise.Js.fromBsPromise(mutate(.))->Promise.Js.toResult)
|
|
89
78
|
}
|
|
90
79
|
|
|
91
|
-
let useOptionalFetcher = (~options: option<fetcherOptions>=?, key: 'key, fn: 'fn): fetcher<
|
|
80
|
+
let useOptionalFetcher = (~options: option<Swr.fetcherOptions>=?, key: 'key, fn: 'fn): fetcher<
|
|
92
81
|
'data,
|
|
93
82
|
> => {
|
|
94
|
-
let
|
|
83
|
+
let {data, isValidating, mutate} = Swr.useSwrOptional(
|
|
95
84
|
key,
|
|
96
85
|
fn,
|
|
97
86
|
Js.Obj.assign(
|
|
@@ -103,12 +92,7 @@ let useOptionalFetcher = (~options: option<fetcherOptions>=?, key: 'key, fn: 'fn
|
|
|
103
92
|
),
|
|
104
93
|
)
|
|
105
94
|
|
|
106
|
-
(
|
|
107
|
-
fetcher.data->Obj.magic,
|
|
108
|
-
fetcher.isValidating,
|
|
109
|
-
() =>
|
|
110
|
-
fetcher.revalidate(BsSwr.revalidateOptions())->Promise.Js.fromBsPromise->Promise.Js.toResult,
|
|
111
|
-
)
|
|
95
|
+
(data->Obj.magic, isValidating, () => mutate(.)->Promise.Js.fromBsPromise->Promise.Js.toResult)
|
|
112
96
|
}
|
|
113
97
|
|
|
114
98
|
// ----------------------
|
|
@@ -148,7 +132,7 @@ let useClipboard = (~onCopyNotificationMessage: option<string>=?, value: string)
|
|
|
148
132
|
let (hasCopied, setHasCopied) = React.useState(() => false)
|
|
149
133
|
let onCopy = React.useCallback1(() => {
|
|
150
134
|
onCopyNotificationMessage->Option.forEach(message =>
|
|
151
|
-
Toolkit__Ui_Snackbar.show(~title=message, ~variant=#success, ())
|
|
135
|
+
Toolkit__Ui_Snackbar.show(~title=message, ~variant=#success, ())->ignore
|
|
152
136
|
)
|
|
153
137
|
|
|
154
138
|
let didCopy = BsCopyToClipboard.copy(value)
|
|
@@ -11,6 +11,7 @@ let make = (
|
|
|
11
11
|
~children,
|
|
12
12
|
~dropdownClassName="",
|
|
13
13
|
~buttonClassName="",
|
|
14
|
+
~containerClassName="",
|
|
14
15
|
~defaultIsOpen=false,
|
|
15
16
|
~buttonColor: Toolkit__Ui_Button.color=#white,
|
|
16
17
|
~buttonSize: Toolkit__Ui_Button.size=#md,
|
|
@@ -53,7 +54,7 @@ let make = (
|
|
|
53
54
|
None
|
|
54
55
|
}, (isOpen, ref))
|
|
55
56
|
|
|
56
|
-
<div className="relative">
|
|
57
|
+
<div className={cx(["relative", containerClassName])}>
|
|
57
58
|
<Toolkit__Ui_Button
|
|
58
59
|
variant=buttonVariant
|
|
59
60
|
size=buttonSize
|
|
@@ -1,30 +1,43 @@
|
|
|
1
|
-
type rec state = {
|
|
2
|
-
isVisible: bool,
|
|
3
|
-
options: option<options>,
|
|
4
|
-
}
|
|
1
|
+
type rec state = {list: array<options>}
|
|
5
2
|
and options = {
|
|
3
|
+
id: id,
|
|
4
|
+
isVisible: bool,
|
|
6
5
|
title: string,
|
|
7
6
|
description: option<React.element>,
|
|
8
7
|
closable: bool,
|
|
9
8
|
variant: variant,
|
|
10
9
|
timeout: int,
|
|
11
10
|
}
|
|
11
|
+
and id
|
|
12
12
|
and variant = [#success | #warning | #danger]
|
|
13
13
|
|
|
14
14
|
type action =
|
|
15
15
|
| Show(options)
|
|
16
|
-
| Hide
|
|
16
|
+
| Hide(id)
|
|
17
|
+
| Remove(id)
|
|
17
18
|
|
|
18
|
-
let store = Restorative.createStore({
|
|
19
|
+
let store = Restorative.createStore({list: []}, (state, action) =>
|
|
19
20
|
switch action {
|
|
20
|
-
| Show(options) => {
|
|
21
|
-
| Hide => {
|
|
21
|
+
| Show(options) => {list: state.list->Array.concat([options])}
|
|
22
|
+
| Hide(id) => {
|
|
23
|
+
list: state.list->Array.map(e =>
|
|
24
|
+
if e.id === id {
|
|
25
|
+
{...e, isVisible: false}
|
|
26
|
+
} else {
|
|
27
|
+
e
|
|
28
|
+
}
|
|
29
|
+
),
|
|
30
|
+
}
|
|
31
|
+
| Remove(id) => {list: state.list->Array.keep(e => e.id !== id)}
|
|
22
32
|
}
|
|
23
33
|
)
|
|
24
34
|
|
|
25
|
-
let show = (~title, ~description=?, ~closable=true, ~variant, ~timeout=5000, ()) =>
|
|
35
|
+
let show = (~title, ~description=?, ~closable=true, ~variant, ~timeout=5000, ()) => {
|
|
36
|
+
let id: id = Js.Math.random()->Js.Float.toString->Obj.magic
|
|
26
37
|
store.dispatch(
|
|
27
38
|
Show({
|
|
39
|
+
id: id,
|
|
40
|
+
isVisible: true,
|
|
28
41
|
title: title,
|
|
29
42
|
description: description,
|
|
30
43
|
closable: closable,
|
|
@@ -32,76 +45,94 @@ let show = (~title, ~description=?, ~closable=true, ~variant, ~timeout=5000, ())
|
|
|
32
45
|
timeout: timeout,
|
|
33
46
|
}),
|
|
34
47
|
)
|
|
35
|
-
|
|
48
|
+
}
|
|
36
49
|
|
|
37
|
-
|
|
50
|
+
let remove = id => store.dispatch(Remove(id))
|
|
51
|
+
let hide = id => {
|
|
52
|
+
store.dispatch(Hide(id))
|
|
53
|
+
Js.Global.setTimeout(() => {
|
|
54
|
+
remove(id)
|
|
55
|
+
}, 160)->ignore
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module Item = {
|
|
38
59
|
@react.component
|
|
39
|
-
let make = () => {
|
|
40
|
-
let {isVisible,
|
|
41
|
-
let timeoutRef = React.useRef(None)
|
|
60
|
+
let make = (~options) => {
|
|
61
|
+
let {id, isVisible, variant, title, description, closable, timeout} = options
|
|
42
62
|
|
|
43
|
-
React.
|
|
44
|
-
if isVisible {
|
|
45
|
-
timeoutRef.current->Option.map(timeoutRef => timeoutRef->Js.Global.clearTimeout)->ignore
|
|
63
|
+
let (mounted, setMounted) = React.useState(() => false)
|
|
46
64
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
)
|
|
65
|
+
React.useEffect0(() => {
|
|
66
|
+
setMounted(_ => true)
|
|
67
|
+
let timeoutId = Js.Global.setTimeout(() => {
|
|
68
|
+
hide(id)
|
|
69
|
+
}, timeout)
|
|
70
|
+
Some(() => Js.Global.clearTimeout(timeoutId))
|
|
71
|
+
})
|
|
51
72
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
73
|
+
<div
|
|
74
|
+
className={cx([
|
|
75
|
+
"bg-white p-3 rounded shadow transition duration-500 ease-in-out mt-3 transform",
|
|
76
|
+
{
|
|
77
|
+
open Css
|
|
78
|
+
style(list{bottom(40->px)})
|
|
79
|
+
},
|
|
80
|
+
mounted ? "-translate-y-14 opacity-1" : "opacity-0",
|
|
81
|
+
isVisible ? "opacity-100 z-50" : "opacity-0 translate-x-[200px]",
|
|
82
|
+
{
|
|
83
|
+
switch variant {
|
|
84
|
+
| #success => "bg-success-500 text-white"
|
|
85
|
+
| #warning => "bg-warning-500 text-white"
|
|
86
|
+
| #danger => "bg-danger-500 text-white"
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
])}>
|
|
90
|
+
<div className="flex flex-gap-3">
|
|
91
|
+
<div>
|
|
92
|
+
{switch variant {
|
|
93
|
+
| #success => <BsReactIcons.MdCheckCircle size=28 />
|
|
94
|
+
| #warning => <BsReactIcons.MdWarning size=28 />
|
|
95
|
+
| #danger => <BsReactIcons.MdError size=28 />
|
|
96
|
+
}}
|
|
97
|
+
</div>
|
|
98
|
+
<div>
|
|
99
|
+
<strong> {title->React.string} </strong>
|
|
100
|
+
{description->Option.mapWithDefault(React.null, description =>
|
|
101
|
+
<p
|
|
102
|
+
className={cx([
|
|
103
|
+
"text-sm",
|
|
104
|
+
{
|
|
105
|
+
open Css
|
|
106
|
+
style(list{maxWidth(250->px)})
|
|
107
|
+
},
|
|
108
|
+
])}>
|
|
109
|
+
description
|
|
110
|
+
</p>
|
|
111
|
+
)}
|
|
112
|
+
</div>
|
|
113
|
+
{closable
|
|
114
|
+
? <button className="self-start" onClick={_ => hide(id)}>
|
|
115
|
+
<BsReactIcons.MdClose />
|
|
116
|
+
</button>
|
|
117
|
+
: React.null}
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
module Provider = {
|
|
124
|
+
@react.component
|
|
125
|
+
let make = () => {
|
|
126
|
+
let {list} = store.useStore()
|
|
56
127
|
|
|
57
128
|
<ReachUi.Portal>
|
|
58
129
|
<div
|
|
59
|
-
className=
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
isVisible ? "opacity-100 translate-y-0 z-50" : "opacity-0 translate-y-10",
|
|
66
|
-
options->Option.mapWithDefault("", options =>
|
|
67
|
-
switch options.variant {
|
|
68
|
-
| #success => "bg-success-500 text-white"
|
|
69
|
-
| #warning => "bg-warning-500 text-white"
|
|
70
|
-
| #danger => "bg-danger-500 text-white"
|
|
71
|
-
}
|
|
72
|
-
),
|
|
73
|
-
])}>
|
|
74
|
-
{options->Option.mapWithDefault(React.null, options =>
|
|
75
|
-
<div className="flex flex-gap-3">
|
|
76
|
-
<div>
|
|
77
|
-
{switch options.variant {
|
|
78
|
-
| #success => <BsReactIcons.MdCheckCircle size=28 />
|
|
79
|
-
| #warning => <BsReactIcons.MdWarning size=28 />
|
|
80
|
-
| #danger => <BsReactIcons.MdError size=28 />
|
|
81
|
-
}}
|
|
82
|
-
</div>
|
|
83
|
-
<div>
|
|
84
|
-
<strong> {options.title->React.string} </strong>
|
|
85
|
-
{options.description->Option.mapWithDefault(React.null, description =>
|
|
86
|
-
<p
|
|
87
|
-
className={cx([
|
|
88
|
-
"text-sm",
|
|
89
|
-
{
|
|
90
|
-
open Css
|
|
91
|
-
style(list{maxWidth(250->px)})
|
|
92
|
-
},
|
|
93
|
-
])}>
|
|
94
|
-
description
|
|
95
|
-
</p>
|
|
96
|
-
)}
|
|
97
|
-
</div>
|
|
98
|
-
{options.closable
|
|
99
|
-
? <button className="self-start" onClick={_ => hide()}>
|
|
100
|
-
<BsReactIcons.MdClose />
|
|
101
|
-
</button>
|
|
102
|
-
: React.null}
|
|
103
|
-
</div>
|
|
104
|
-
)}
|
|
130
|
+
className="fixed right-0 top-0 transform translate-y-14 h-full p-4 flex flex-col items-end justify-end">
|
|
131
|
+
{list
|
|
132
|
+
->Array.map(e => {
|
|
133
|
+
<Item key={e.id->Obj.magic} options=e />
|
|
134
|
+
})
|
|
135
|
+
->React.array}
|
|
105
136
|
</div>
|
|
106
137
|
</ReachUi.Portal>
|
|
107
138
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
type revalidateOptions
|
|
2
2
|
|
|
3
3
|
@obj
|
|
4
|
-
external
|
|
4
|
+
external makeRevalidateOptions: (
|
|
5
5
|
~retryCount: option<int>=?,
|
|
6
6
|
~dedupe: option<bool>=?,
|
|
7
7
|
unit,
|
|
@@ -10,10 +10,10 @@ external revalidateOptions: (
|
|
|
10
10
|
type fetcherOptions
|
|
11
11
|
|
|
12
12
|
@obj
|
|
13
|
-
external
|
|
13
|
+
external makeFetcherOptions: (
|
|
14
14
|
~suspense: bool=?,
|
|
15
15
|
~fetcher: 'fetcher=?,
|
|
16
|
-
~
|
|
16
|
+
~fallbackData: 'data=?,
|
|
17
17
|
~revalidateOnFocus: bool=?,
|
|
18
18
|
~revalidateOnMount: bool=?,
|
|
19
19
|
~revalidateOnReconnect: bool=?,
|
|
@@ -43,7 +43,7 @@ type fetcher<'data> = {
|
|
|
43
43
|
data: option<'data>,
|
|
44
44
|
error: option<Js.Exn.t>,
|
|
45
45
|
isValidating: bool,
|
|
46
|
-
|
|
46
|
+
mutate: (. unit) => Js.Promise.t<bool>,
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
@module("swr")
|
|
@@ -54,11 +54,20 @@ external useSwrOptional: ('key, 'fn, 'fetcherOptions) => fetcher<option<'data>>
|
|
|
54
54
|
|
|
55
55
|
@module("swr") external trigger: 'key => unit = "trigger"
|
|
56
56
|
|
|
57
|
-
@module("swr") external mutate: ('key, 'data, bool) => unit = "mutate"
|
|
58
|
-
|
|
59
|
-
@module("swr") external mutate0: 'key => unit = "mutate"
|
|
60
|
-
|
|
61
57
|
type cache
|
|
62
58
|
@module("swr") external cache: cache = "cache"
|
|
63
59
|
@send external clear: cache => unit = "clear"
|
|
64
60
|
@send external delete: (cache, 'key) => unit = "delete"
|
|
61
|
+
|
|
62
|
+
module SwrConfig = {
|
|
63
|
+
type t
|
|
64
|
+
|
|
65
|
+
@send
|
|
66
|
+
external mutate0: (t, 'key) => unit = "mutate"
|
|
67
|
+
|
|
68
|
+
@send
|
|
69
|
+
external mutate: (t, 'key, 'data, bool) => unit = "mutate"
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@module("swr")
|
|
73
|
+
external useSWRConfig: unit => SwrConfig.t = "useSWRConfig"
|
package/src/vendors/Msw.res
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
type mockedResponse
|
|
2
|
-
external mockedResponse: 'a => Js.Null.t<mockedResponse> = "%identity"
|
|
3
|
-
|
|
4
|
-
@get external body: mockedResponse => string = "body"
|
|
5
|
-
|
|
6
|
-
type responseTransformer = mockedResponse => mockedResponse
|
|
7
|
-
|
|
8
|
-
type headers
|
|
9
|
-
@send external setHeader: (headers, string, 'value) => unit = "set"
|
|
10
|
-
@send external getHeader: (headers, string) => 'value = "get"
|
|
11
|
-
|
|
12
|
-
type params
|
|
13
|
-
|
|
14
|
-
type request = {
|
|
15
|
-
url: string,
|
|
16
|
-
method: string,
|
|
17
|
-
headers: headers,
|
|
18
|
-
params: params,
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type context
|
|
22
|
-
|
|
23
|
-
type response
|
|
24
|
-
|
|
25
|
-
@send
|
|
26
|
-
external response: (
|
|
27
|
-
response,
|
|
28
|
-
Js.null<'a>,
|
|
29
|
-
array<responseTransformer>,
|
|
30
|
-
) => Js.Null.t<mockedResponse> = "apply"
|
|
31
|
-
let response = (res, responseTransformers) => response(res, Js.null, responseTransformers)
|
|
32
|
-
|
|
33
|
-
type responseResolver = (request, response, context) => Js.Promise.t<Js.Null.t<mockedResponse>>
|
|
34
|
-
|
|
35
|
-
@send
|
|
36
|
-
external status: (context, string) => responseTransformer = "status"
|
|
37
|
-
|
|
38
|
-
@send external json: (context, 'data) => responseTransformer = "json"
|
|
39
|
-
|
|
40
|
-
@send external text: (context, 'data) => responseTransformer = "text"
|
|
41
|
-
|
|
42
|
-
@send external xml: (context, 'data) => responseTransformer = "xml"
|
|
43
|
-
|
|
44
|
-
@send external delay: (context, int) => responseTransformer = "delay"
|
|
45
|
-
|
|
46
|
-
type requestHandler
|
|
47
|
-
|
|
48
|
-
type rest = {
|
|
49
|
-
get: (string, responseResolver) => requestHandler,
|
|
50
|
-
post: (string, responseResolver) => requestHandler,
|
|
51
|
-
put: (string, responseResolver) => requestHandler,
|
|
52
|
-
patch: (string, responseResolver) => requestHandler,
|
|
53
|
-
delete: (string, responseResolver) => requestHandler,
|
|
54
|
-
options: (string, responseResolver) => requestHandler,
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
@module("msw") external rest: rest = "rest"
|
|
58
|
-
|
|
59
|
-
@module("msw")
|
|
60
|
-
external restDict: Js.Dict.t<(string, responseResolver) => requestHandler> = "rest"
|
|
61
|
-
|
|
62
|
-
type worker
|
|
63
|
-
|
|
64
|
-
@module("msw") @variadic
|
|
65
|
-
external setupWorker: array<requestHandler> => worker = "setupWorker"
|
|
66
|
-
|
|
67
|
-
@send external start: worker => unit = "start"
|
|
68
|
-
|
|
69
|
-
@send external stop: worker => unit = "stop"
|
|
70
|
-
|
|
71
|
-
@send @variadic
|
|
72
|
-
external use: (worker, array<requestHandler>) => unit = "use"
|
|
73
|
-
|
|
74
|
-
@send external restoreHandlers: worker => unit = "restoreHandlers"
|
|
75
|
-
|
|
76
|
-
@send @variadic
|
|
77
|
-
external resetHandlers: (worker, array<requestHandler>) => unit = "resetHandlers"
|
|
78
|
-
|
|
79
|
-
module Node = {
|
|
80
|
-
type server
|
|
81
|
-
|
|
82
|
-
@module("msw/node") @variadic
|
|
83
|
-
external setupServer: array<requestHandler> => server = "setupServer"
|
|
84
|
-
|
|
85
|
-
@send external listen: server => unit = "listen"
|
|
86
|
-
|
|
87
|
-
@send external close: server => unit = "close"
|
|
88
|
-
|
|
89
|
-
@send @variadic
|
|
90
|
-
external use: (server, array<requestHandler>) => unit = "use"
|
|
91
|
-
|
|
92
|
-
@send external restoreHandlers: server => unit = "restoreHandlers"
|
|
93
|
-
|
|
94
|
-
@send @variadic
|
|
95
|
-
external resetHandlers: (server, array<requestHandler>) => unit = "resetHandlers"
|
|
96
|
-
}
|