@colisweb/rescript-toolkit 1.31.0 → 2.2.0

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colisweb/rescript-toolkit",
3
- "version": "1.31.0",
3
+ "version": "2.2.0",
4
4
  "scripts": {
5
5
  "clean": "rescript clean",
6
6
  "build": "rescript build",
@@ -1,4 +1,4 @@
1
- module Date = {
1
+ module Datetime = {
2
2
  type date = Js.Date.t
3
3
 
4
4
  let encoder: Decco.encoder<date> = value => value->Js.Date.toISOString->Decco.stringToJson
@@ -15,6 +15,24 @@ module Date = {
15
15
  type t = @decco.codec(codec) date
16
16
  }
17
17
 
18
+ module Date = {
19
+ type date = Js.Date.t
20
+
21
+ let encoder: Decco.encoder<date> = date =>
22
+ date->BsDateFns.formatWithPattern("yyyy-MM-dd")->Decco.stringToJson
23
+
24
+ let decoder: Decco.decoder<date> = json =>
25
+ switch Decco.stringFromJson(json) {
26
+ | Ok(v) => Js.Date.fromString(v)->Ok
27
+ | Error(_) as err => err
28
+ }
29
+
30
+ let codec: Decco.codec<date> = (encoder, decoder)
31
+
32
+ @decco
33
+ type t = @decco.codec(codec) date
34
+ }
35
+
18
36
  module Int = {
19
37
  let encoder = value => value->Decco.intToJson
20
38
 
@@ -5,16 +5,21 @@ module type RouterConfig = {
5
5
  }
6
6
 
7
7
  module Make = (Config: RouterConfig) => {
8
+ type contextState = {
9
+ currentRoute: Config.t,
10
+ previousRoute: option<Config.t>,
11
+ }
8
12
  let navigate = (route: Config.t) => RescriptReactRouter.push(route->Config.toString)
9
13
 
10
14
  let replace = (route: Config.t) => RescriptReactRouter.replace(route->Config.toString)
11
15
 
12
- let routerContext = React.createContext(
13
- RescriptReactRouter.dangerouslyGetInitialUrl()->Config.make,
14
- )
16
+ let routerContext = React.createContext({
17
+ currentRoute: RescriptReactRouter.dangerouslyGetInitialUrl()->Config.make,
18
+ previousRoute: None,
19
+ })
15
20
 
16
21
  module RouterContextProvider = {
17
- let makeProps = (~value: Config.t, ~children, ()) =>
22
+ let makeProps = (~value: contextState, ~children, ()) =>
18
23
  {
19
24
  "value": value,
20
25
  "children": children,
@@ -30,6 +35,8 @@ module Make = (Config: RouterConfig) => {
30
35
  RescriptReactRouter.dangerouslyGetInitialUrl()->Config.make
31
36
  )
32
37
 
38
+ let previousRoute = Toolkit__Hooks.usePrevious(currentRoute)
39
+
33
40
  React.useLayoutEffect1(() => {
34
41
  let watcherID = RescriptReactRouter.watchUrl(url =>
35
42
  setCurrentRoute(_ => url |> Config.make)
@@ -37,7 +44,14 @@ module Make = (Config: RouterConfig) => {
37
44
  Some(() => RescriptReactRouter.unwatchUrl(watcherID))
38
45
  }, [setCurrentRoute])
39
46
 
40
- <RouterContextProvider value=currentRoute> {children(~currentRoute)} </RouterContextProvider>
47
+ let contextValue: contextState = {
48
+ previousRoute: previousRoute,
49
+ currentRoute: currentRoute,
50
+ }
51
+
52
+ <RouterContextProvider value={contextValue}>
53
+ {children(~currentRoute)}
54
+ </RouterContextProvider>
41
55
  }
42
56
  }
43
57
 
@@ -47,7 +61,7 @@ module Make = (Config: RouterConfig) => {
47
61
  routeA->Config.toString === routeB->Config.toString
48
62
 
49
63
  let useIsCurrentRoute = (route: Config.t): bool => {
50
- let currentRoute = React.useContext(routerContext)
64
+ let {currentRoute} = React.useContext(routerContext)
51
65
  isRouteEqual(currentRoute, route)
52
66
  }
53
67
 
@@ -0,0 +1,114 @@
1
+ open BsSentryReactNative
2
+
3
+ let error = (loc: ReScriptLogger.Location.t, event) => {
4
+ open Sentry
5
+ withScope(scope => {
6
+ scope->Scope.setExtra("module", loc.subModulePath->List.toArray)
7
+ scope->Scope.setExtra("fullPath", loc.fullPath)
8
+ scope->Scope.setExtra("function", loc.value)
9
+ captureMessage(event)
10
+ })
11
+ }
12
+
13
+ let error1 = (loc: ReScriptLogger.Location.t, event, (label, data)) => {
14
+ open Sentry
15
+ withScope(scope => {
16
+ scope->Scope.setExtra("module", loc.subModulePath->List.toArray)
17
+ scope->Scope.setExtra("fullPath", loc.fullPath)
18
+ scope->Scope.setExtra("function", loc.value)
19
+ scope->Scope.setExtra(label, data)
20
+ captureMessage(event)
21
+ })
22
+ }
23
+
24
+ let error2 = (loc: ReScriptLogger.Location.t, event, (label1, data1), (label2, data2)) => {
25
+ open Sentry
26
+ withScope(scope => {
27
+ scope->Scope.setExtra("module", loc.subModulePath->List.toArray)
28
+ scope->Scope.setExtra("fullPath", loc.fullPath)
29
+ scope->Scope.setExtra("function", loc.value)
30
+ scope->Scope.setExtra(label1, data1)
31
+ scope->Scope.setExtra(label2, data2)
32
+ captureMessage(event)
33
+ })
34
+ }
35
+
36
+ let error3 = (
37
+ loc: ReScriptLogger.Location.t,
38
+ event,
39
+ (label1, data1),
40
+ (label2, data2),
41
+ (label3, data3),
42
+ ) => {
43
+ open Sentry
44
+ withScope(scope => {
45
+ scope->Scope.setExtra("module", loc.subModulePath->List.toArray)
46
+ scope->Scope.setExtra("fullPath", loc.fullPath)
47
+ scope->Scope.setExtra("function", loc.value)
48
+ scope->Scope.setExtra(label1, data1)
49
+ scope->Scope.setExtra(label2, data2)
50
+ scope->Scope.setExtra(label3, data3)
51
+ captureMessage(event)
52
+ })
53
+ }
54
+ let error4 = (
55
+ loc: ReScriptLogger.Location.t,
56
+ event,
57
+ (label1, data1),
58
+ (label2, data2),
59
+ (label3, data3),
60
+ (label4, data4),
61
+ ) => {
62
+ open Sentry
63
+ withScope(scope => {
64
+ scope->Scope.setExtra("module", loc.subModulePath->List.toArray)
65
+ scope->Scope.setExtra("fullPath", loc.fullPath)
66
+ scope->Scope.setExtra("function", loc.value)
67
+ scope->Scope.setExtra(label1, data1)
68
+ scope->Scope.setExtra(label2, data2)
69
+ scope->Scope.setExtra(label3, data3)
70
+ scope->Scope.setExtra(label4, data4)
71
+ captureMessage(event)
72
+ })
73
+ }
74
+ let error5 = (
75
+ loc: ReScriptLogger.Location.t,
76
+ event,
77
+ (label1, data1),
78
+ (label2, data2),
79
+ (label3, data3),
80
+ (label4, data4),
81
+ (label5, data5),
82
+ ) => {
83
+ open Sentry
84
+ withScope(scope => {
85
+ scope->Scope.setExtra("module", loc.subModulePath->List.toArray)
86
+ scope->Scope.setExtra("fullPath", loc.fullPath)
87
+ scope->Scope.setExtra("function", loc.value)
88
+ scope->Scope.setExtra(label1, data1)
89
+ scope->Scope.setExtra(label2, data2)
90
+ scope->Scope.setExtra(label3, data3)
91
+ scope->Scope.setExtra(label4, data4)
92
+ scope->Scope.setExtra(label5, data5)
93
+ captureMessage(event)
94
+ })
95
+ }
96
+
97
+ let errorWithData = (loc: ReScriptLogger.Location.t, event, (label, data)) => {
98
+ open Sentry
99
+ withScope(scope => {
100
+ scope->Scope.setExtra("module", loc.subModulePath->List.toArray)
101
+ scope->Scope.setExtra(label, data)
102
+ captureMessage(event)
103
+ })
104
+ }
105
+
106
+ let errorWithData2 = (loc: ReScriptLogger.Location.t, event, (label1, data1), (label2, data2)) => {
107
+ open Sentry
108
+ withScope(scope => {
109
+ scope->Scope.setExtra("module", loc.subModulePath->List.toArray)
110
+ scope->Scope.setExtra(label1, data1)
111
+ scope->Scope.setExtra(label2, data2)
112
+ captureMessage(event)
113
+ })
114
+ }
@@ -2,21 +2,23 @@ module Sentry = {
2
2
  module Scope = {
3
3
  type t
4
4
 
5
- @bs.send external setExtra: (t, string, 'a) => unit = "setExtra"
5
+ @send external setExtra: (t, string, 'a) => unit = "setExtra"
6
6
  }
7
7
 
8
- @module("@sentry/react-native")
9
- external init: Js.t<'a> => unit = "init"
8
+ @module("sentry-expo") external init: 'a => unit = "init"
10
9
 
11
- @module("@sentry/react-native")
10
+ @module("sentry-expo") @scope("Native")
12
11
  external setTag: (string, string) => unit = "setTag"
13
12
 
14
- @module("@sentry/react-native")
13
+ @module("sentry-expo") @scope("Native")
14
+ external setUser: 'a => unit = "setUser"
15
+
16
+ @module("sentry-expo") @scope("Native")
15
17
  external captureException: Js.Promise.error => unit = "captureException"
16
18
 
17
- @module("@sentry/react-native")
19
+ @module("sentry-expo") @scope("Native")
18
20
  external captureMessage: string => unit = "captureMessage"
19
21
 
20
- @module("@sentry/react-native")
22
+ @module("sentry-expo") @scope("Native")
21
23
  external withScope: (Scope.t => unit) => unit = "withScope"
22
24
  }
@@ -0,0 +1,13 @@
1
+ type fallbackProps = {
2
+ error: Js.Exn.t,
3
+ resetErrorBoundary: unit => unit,
4
+ }
5
+
6
+ @module("react-error-boundary") @react.component
7
+ external make: (
8
+ ~fallback: React.element=?,
9
+ ~fallbackComponent: fallbackProps => React.element=?,
10
+ ~fallbackRender: fallbackProps => React.element=?,
11
+ ~children: React.element,
12
+ ~resetKeys: array<'a>=?,
13
+ ) => React.element = "ErrorBoundary"