envio 3.0.0-alpha.21 → 3.0.0-alpha.23

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.
Files changed (220) hide show
  1. package/README.md +3 -3
  2. package/bin.mjs +2 -48
  3. package/evm.schema.json +67 -0
  4. package/fuel.schema.json +67 -0
  5. package/index.d.ts +822 -38
  6. package/index.js +5 -3
  7. package/package.json +10 -8
  8. package/rescript.json +5 -9
  9. package/src/Address.res +4 -5
  10. package/src/Address.res.mjs +9 -12
  11. package/src/Api.res +15 -0
  12. package/src/Api.res.mjs +20 -0
  13. package/src/Batch.res +32 -34
  14. package/src/Batch.res.mjs +172 -187
  15. package/src/Bin.res +89 -0
  16. package/src/Bin.res.mjs +97 -0
  17. package/src/ChainFetcher.res +33 -57
  18. package/src/ChainFetcher.res.mjs +197 -227
  19. package/src/ChainManager.res +6 -14
  20. package/src/ChainManager.res.mjs +74 -85
  21. package/src/ChainMap.res +14 -16
  22. package/src/ChainMap.res.mjs +38 -38
  23. package/src/Config.res +193 -135
  24. package/src/Config.res.mjs +566 -592
  25. package/src/Core.res +182 -0
  26. package/src/Core.res.mjs +207 -0
  27. package/src/Ecosystem.res +25 -4
  28. package/src/Ecosystem.res.mjs +12 -13
  29. package/src/Env.res +20 -13
  30. package/src/Env.res.mjs +124 -113
  31. package/src/EnvSafe.res +269 -0
  32. package/src/EnvSafe.res.mjs +296 -0
  33. package/src/EnvSafe.resi +18 -0
  34. package/src/Envio.res +37 -26
  35. package/src/Envio.res.mjs +59 -60
  36. package/src/ErrorHandling.res +2 -2
  37. package/src/ErrorHandling.res.mjs +15 -15
  38. package/src/EventConfigBuilder.res +219 -81
  39. package/src/EventConfigBuilder.res.mjs +259 -202
  40. package/src/EventProcessing.res +27 -38
  41. package/src/EventProcessing.res.mjs +165 -183
  42. package/src/EventUtils.res +11 -11
  43. package/src/EventUtils.res.mjs +21 -22
  44. package/src/EvmTypes.res +0 -1
  45. package/src/EvmTypes.res.mjs +5 -5
  46. package/src/FetchState.res +360 -256
  47. package/src/FetchState.res.mjs +958 -914
  48. package/src/GlobalState.res +365 -351
  49. package/src/GlobalState.res.mjs +958 -992
  50. package/src/GlobalStateManager.res +1 -2
  51. package/src/GlobalStateManager.res.mjs +36 -44
  52. package/src/HandlerLoader.res +107 -23
  53. package/src/HandlerLoader.res.mjs +128 -38
  54. package/src/HandlerRegister.res +127 -103
  55. package/src/HandlerRegister.res.mjs +164 -164
  56. package/src/HandlerRegister.resi +12 -4
  57. package/src/Hasura.res +35 -22
  58. package/src/Hasura.res.mjs +158 -167
  59. package/src/InMemoryStore.res +20 -27
  60. package/src/InMemoryStore.res.mjs +64 -80
  61. package/src/InMemoryTable.res +34 -39
  62. package/src/InMemoryTable.res.mjs +165 -170
  63. package/src/Internal.res +52 -33
  64. package/src/Internal.res.mjs +84 -81
  65. package/src/LazyLoader.res.mjs +55 -61
  66. package/src/LoadLayer.res +77 -78
  67. package/src/LoadLayer.res.mjs +160 -189
  68. package/src/LoadManager.res +16 -21
  69. package/src/LoadManager.res.mjs +79 -84
  70. package/src/LogSelection.res +236 -68
  71. package/src/LogSelection.res.mjs +211 -141
  72. package/src/Logging.res +13 -9
  73. package/src/Logging.res.mjs +130 -143
  74. package/src/Main.res +430 -51
  75. package/src/Main.res.mjs +530 -271
  76. package/src/Persistence.res +80 -84
  77. package/src/Persistence.res.mjs +131 -132
  78. package/src/PgStorage.res +294 -167
  79. package/src/PgStorage.res.mjs +799 -817
  80. package/src/Prometheus.res +50 -58
  81. package/src/Prometheus.res.mjs +345 -373
  82. package/src/ReorgDetection.res +22 -24
  83. package/src/ReorgDetection.res.mjs +100 -106
  84. package/src/SafeCheckpointTracking.res +7 -7
  85. package/src/SafeCheckpointTracking.res.mjs +40 -43
  86. package/src/SimulateItems.res +41 -49
  87. package/src/SimulateItems.res.mjs +257 -272
  88. package/src/Sink.res +2 -2
  89. package/src/Sink.res.mjs +22 -26
  90. package/src/TableIndices.res +1 -2
  91. package/src/TableIndices.res.mjs +42 -48
  92. package/src/TestIndexer.res +196 -189
  93. package/src/TestIndexer.res.mjs +536 -536
  94. package/src/TestIndexerProxyStorage.res +16 -16
  95. package/src/TestIndexerProxyStorage.res.mjs +99 -122
  96. package/src/TestIndexerWorker.res +4 -0
  97. package/src/TestIndexerWorker.res.mjs +7 -0
  98. package/src/Throttler.res +3 -3
  99. package/src/Throttler.res.mjs +23 -24
  100. package/src/Time.res +1 -1
  101. package/src/Time.res.mjs +18 -21
  102. package/src/TopicFilter.res +3 -3
  103. package/src/TopicFilter.res.mjs +29 -30
  104. package/src/UserContext.res +93 -54
  105. package/src/UserContext.res.mjs +197 -182
  106. package/src/Utils.res +141 -86
  107. package/src/Utils.res.mjs +334 -295
  108. package/src/bindings/BigDecimal.res +0 -2
  109. package/src/bindings/BigDecimal.res.mjs +19 -23
  110. package/src/bindings/ClickHouse.res +28 -27
  111. package/src/bindings/ClickHouse.res.mjs +243 -240
  112. package/src/bindings/DateFns.res +11 -11
  113. package/src/bindings/DateFns.res.mjs +7 -7
  114. package/src/bindings/EventSource.res.mjs +2 -2
  115. package/src/bindings/Express.res +2 -5
  116. package/src/bindings/Hrtime.res +2 -2
  117. package/src/bindings/Hrtime.res.mjs +30 -32
  118. package/src/bindings/Lodash.res.mjs +1 -1
  119. package/src/bindings/NodeJs.res +14 -9
  120. package/src/bindings/NodeJs.res.mjs +20 -20
  121. package/src/bindings/Pino.res +8 -10
  122. package/src/bindings/Pino.res.mjs +40 -43
  123. package/src/bindings/Postgres.res +7 -5
  124. package/src/bindings/Postgres.res.mjs +9 -9
  125. package/src/bindings/PromClient.res +17 -2
  126. package/src/bindings/PromClient.res.mjs +30 -7
  127. package/src/bindings/SDSL.res.mjs +2 -2
  128. package/src/bindings/Viem.res +4 -4
  129. package/src/bindings/Viem.res.mjs +20 -22
  130. package/src/bindings/Vitest.res +1 -1
  131. package/src/bindings/Vitest.res.mjs +2 -2
  132. package/src/bindings/WebSocket.res +1 -1
  133. package/src/db/EntityHistory.res +9 -3
  134. package/src/db/EntityHistory.res.mjs +84 -59
  135. package/src/db/InternalTable.res +62 -60
  136. package/src/db/InternalTable.res.mjs +271 -203
  137. package/src/db/Schema.res +1 -2
  138. package/src/db/Schema.res.mjs +28 -32
  139. package/src/db/Table.res +28 -27
  140. package/src/db/Table.res.mjs +276 -292
  141. package/src/sources/EventRouter.res +21 -16
  142. package/src/sources/EventRouter.res.mjs +55 -57
  143. package/src/sources/Evm.res +17 -1
  144. package/src/sources/Evm.res.mjs +16 -8
  145. package/src/sources/EvmChain.res +15 -17
  146. package/src/sources/EvmChain.res.mjs +40 -42
  147. package/src/sources/Fuel.res +14 -1
  148. package/src/sources/Fuel.res.mjs +16 -8
  149. package/src/sources/FuelSDK.res +1 -1
  150. package/src/sources/FuelSDK.res.mjs +6 -8
  151. package/src/sources/HyperFuel.res +8 -10
  152. package/src/sources/HyperFuel.res.mjs +113 -123
  153. package/src/sources/HyperFuelClient.res.mjs +6 -7
  154. package/src/sources/HyperFuelSource.res +19 -20
  155. package/src/sources/HyperFuelSource.res.mjs +339 -356
  156. package/src/sources/HyperSync.res +11 -13
  157. package/src/sources/HyperSync.res.mjs +206 -220
  158. package/src/sources/HyperSyncClient.res +5 -7
  159. package/src/sources/HyperSyncClient.res.mjs +70 -75
  160. package/src/sources/HyperSyncHeightStream.res +8 -9
  161. package/src/sources/HyperSyncHeightStream.res.mjs +78 -86
  162. package/src/sources/HyperSyncJsonApi.res +18 -15
  163. package/src/sources/HyperSyncJsonApi.res.mjs +201 -231
  164. package/src/sources/HyperSyncSource.res +17 -21
  165. package/src/sources/HyperSyncSource.res.mjs +268 -290
  166. package/src/sources/Rpc.res +5 -5
  167. package/src/sources/Rpc.res.mjs +168 -192
  168. package/src/sources/RpcSource.res +166 -167
  169. package/src/sources/RpcSource.res.mjs +972 -1046
  170. package/src/sources/RpcWebSocketHeightStream.res +10 -11
  171. package/src/sources/RpcWebSocketHeightStream.res.mjs +131 -145
  172. package/src/sources/SimulateSource.res +1 -1
  173. package/src/sources/SimulateSource.res.mjs +35 -38
  174. package/src/sources/Source.res +1 -1
  175. package/src/sources/Source.res.mjs +3 -3
  176. package/src/sources/SourceManager.res +39 -20
  177. package/src/sources/SourceManager.res.mjs +340 -371
  178. package/src/sources/SourceManager.resi +2 -1
  179. package/src/sources/Svm.res +12 -5
  180. package/src/sources/Svm.res.mjs +44 -41
  181. package/src/tui/Tui.res +23 -12
  182. package/src/tui/Tui.res.mjs +292 -290
  183. package/src/tui/bindings/Ink.res +2 -4
  184. package/src/tui/bindings/Ink.res.mjs +35 -41
  185. package/src/tui/components/BufferedProgressBar.res +7 -7
  186. package/src/tui/components/BufferedProgressBar.res.mjs +46 -46
  187. package/src/tui/components/CustomHooks.res +1 -2
  188. package/src/tui/components/CustomHooks.res.mjs +102 -122
  189. package/src/tui/components/Messages.res +1 -2
  190. package/src/tui/components/Messages.res.mjs +38 -42
  191. package/src/tui/components/SyncETA.res +10 -11
  192. package/src/tui/components/SyncETA.res.mjs +178 -196
  193. package/src/tui/components/TuiData.res +1 -1
  194. package/src/tui/components/TuiData.res.mjs +7 -6
  195. package/src/vendored/Rest.res +52 -66
  196. package/src/vendored/Rest.res.mjs +324 -364
  197. package/svm.schema.json +67 -0
  198. package/src/Address.gen.ts +0 -8
  199. package/src/Config.gen.ts +0 -19
  200. package/src/Envio.gen.ts +0 -55
  201. package/src/EvmTypes.gen.ts +0 -6
  202. package/src/InMemoryStore.gen.ts +0 -6
  203. package/src/Internal.gen.ts +0 -64
  204. package/src/PgStorage.gen.ts +0 -10
  205. package/src/PgStorage.res.d.mts +0 -5
  206. package/src/Types.ts +0 -56
  207. package/src/bindings/BigDecimal.gen.ts +0 -14
  208. package/src/bindings/BigDecimal.res.d.mts +0 -5
  209. package/src/bindings/BigInt.gen.ts +0 -10
  210. package/src/bindings/BigInt.res +0 -70
  211. package/src/bindings/BigInt.res.d.mts +0 -5
  212. package/src/bindings/BigInt.res.mjs +0 -154
  213. package/src/bindings/Ethers.res.d.mts +0 -5
  214. package/src/bindings/Pino.gen.ts +0 -17
  215. package/src/bindings/Postgres.gen.ts +0 -8
  216. package/src/bindings/Postgres.res.d.mts +0 -5
  217. package/src/bindings/Promise.res +0 -67
  218. package/src/bindings/Promise.res.mjs +0 -26
  219. package/src/db/InternalTable.gen.ts +0 -36
  220. package/src/sources/HyperSyncClient.gen.ts +0 -19
@@ -1,75 +1,71 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
- import * as $$Ink from "../bindings/Ink.res.mjs";
4
- import * as $$Ink$1 from "ink";
5
- import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
6
- import * as Caml_option from "rescript/lib/es6/caml_option.js";
3
+ import * as Ink from "../bindings/Ink.res.mjs";
4
+ import * as Ink$1 from "ink";
7
5
  import * as CustomHooks from "./CustomHooks.res.mjs";
8
6
  import * as JsxRuntime from "react/jsx-runtime";
9
7
 
10
8
  function Messages$Message(props) {
11
- var message = props.message;
12
- return JsxRuntime.jsx($$Ink$1.Text, {
13
- children: message.content,
14
- color: CustomHooks.InitApi.toTheme(message.color)
15
- });
9
+ let message = props.message;
10
+ return JsxRuntime.jsx(Ink$1.Text, {
11
+ children: message.content,
12
+ color: CustomHooks.InitApi.toTheme(message.color)
13
+ });
16
14
  }
17
15
 
18
- var Message = {
16
+ let Message = {
19
17
  make: Messages$Message
20
18
  };
21
19
 
22
20
  function Messages$Notifications(props) {
23
21
  return JsxRuntime.jsxs(JsxRuntime.Fragment, {
24
- children: [
25
- JsxRuntime.jsx($$Ink.Newline.make, {}),
26
- JsxRuntime.jsx($$Ink$1.Text, {
27
- children: "Notifications:",
28
- bold: true
29
- }),
30
- props.children
31
- ]
32
- });
22
+ children: [
23
+ JsxRuntime.jsx(Ink.Newline.make, {}),
24
+ JsxRuntime.jsx(Ink$1.Text, {
25
+ children: "Notifications:",
26
+ bold: true
27
+ }),
28
+ props.children
29
+ ]
30
+ });
33
31
  }
34
32
 
35
- var Notifications = {
33
+ let Notifications = {
36
34
  make: Messages$Notifications
37
35
  };
38
36
 
39
37
  function Messages(props) {
40
- var messages = CustomHooks.useMessages(props.config);
41
- var tmp;
38
+ let messages = CustomHooks.useMessages(props.config);
39
+ let tmp;
42
40
  if (typeof messages !== "object") {
43
41
  tmp = null;
44
42
  } else if (messages.TAG === "Data") {
45
- var messages$1 = messages._0;
43
+ let messages$1 = messages._0;
46
44
  tmp = messages$1.length !== 0 ? JsxRuntime.jsx(Messages$Notifications, {
47
- children: Belt_Array.mapWithIndex(messages$1, (function (i, message) {
48
- return JsxRuntime.jsx(Messages$Message, {
49
- message: message
50
- }, String(i));
51
- }))
52
- }) : null;
45
+ children: messages$1.map((message, i) => JsxRuntime.jsx(Messages$Message, {
46
+ message: message
47
+ }, i.toString()))
48
+ }) : null;
53
49
  } else {
54
50
  tmp = JsxRuntime.jsx(Messages$Notifications, {
55
- children: JsxRuntime.jsx(Messages$Message, {
56
- message: {
57
- color: "danger",
58
- content: "Failed to load messages from envio server"
59
- }
60
- })
61
- });
51
+ children: JsxRuntime.jsx(Messages$Message, {
52
+ message: {
53
+ color: "danger",
54
+ content: "Failed to load messages from envio server"
55
+ }
56
+ })
57
+ });
62
58
  }
63
59
  return JsxRuntime.jsx(JsxRuntime.Fragment, {
64
- children: Caml_option.some(tmp)
65
- });
60
+ children: tmp
61
+ });
66
62
  }
67
63
 
68
- var make = Messages;
64
+ let make = Messages;
69
65
 
70
66
  export {
71
- Message ,
72
- Notifications ,
73
- make ,
67
+ Message,
68
+ Notifications,
69
+ make,
74
70
  }
75
71
  /* Ink Not a pure module */
@@ -1,5 +1,4 @@
1
1
  open Ink
2
- open Belt
3
2
 
4
3
  let isIndexerFullySynced = (chains: array<TuiData.chain>) => {
5
4
  chains->Array.reduce(true, (accum, current) => {
@@ -25,12 +24,12 @@ let getTotalRemainingBlocks = (chains: array<TuiData.chain>) => {
25
24
  })
26
25
  }
27
26
 
28
- let getLatestTimeCaughtUpToHead = (chains: array<TuiData.chain>, indexerStartTime: Js.Date.t) => {
27
+ let getLatestTimeCaughtUpToHead = (chains: array<TuiData.chain>, indexerStartTime: Date.t) => {
29
28
  let latesttimestampCaughtUpToHeadOrEndblockFloat = chains->Array.reduce(0.0, (accum, current) => {
30
29
  switch current.progress {
31
30
  | Synced({timestampCaughtUpToHeadOrEndblock}) =>
32
- timestampCaughtUpToHeadOrEndblock->Js.Date.valueOf > accum
33
- ? timestampCaughtUpToHeadOrEndblock->Js.Date.valueOf
31
+ timestampCaughtUpToHeadOrEndblock->Date.getTime > accum
32
+ ? timestampCaughtUpToHeadOrEndblock->Date.getTime
34
33
  : accum
35
34
  | Syncing(_)
36
35
  | SearchingForEvents => accum
@@ -39,7 +38,7 @@ let getLatestTimeCaughtUpToHead = (chains: array<TuiData.chain>, indexerStartTim
39
38
 
40
39
  DateFns.formatDistanceWithOptions(
41
40
  indexerStartTime,
42
- latesttimestampCaughtUpToHeadOrEndblockFloat->Js.Date.fromFloat,
41
+ latesttimestampCaughtUpToHeadOrEndblockFloat->Date.fromTime,
43
42
  {includeSeconds: true},
44
43
  )
45
44
  }
@@ -81,14 +80,14 @@ let useEta = (~chains, ~indexerStartTime) => {
81
80
  let (timeSinceStart, setTimeSinceStart) = React.useState(_ => 0.)
82
81
 
83
82
  React.useEffect2(() => {
84
- setTimeSinceStart(_ => Js.Date.now() -. indexerStartTime->Js.Date.valueOf)
83
+ setTimeSinceStart(_ => Date.now() -. indexerStartTime->Date.getTime)
85
84
  setSecondsToSub(_ => 0.)
86
85
 
87
- let intervalId = Js.Global.setInterval(() => {
86
+ let intervalId = setInterval(() => {
88
87
  setSecondsToSub(prev => prev +. 1.)
89
88
  }, 1000)
90
89
 
91
- Some(() => Js.Global.clearInterval(intervalId))
90
+ Some(() => clearInterval(intervalId))
92
91
  }, (chains, indexerStartTime))
93
92
 
94
93
  //blocksProcessed/remainingBlocks = timeSoFar/eta
@@ -96,13 +95,13 @@ let useEta = (~chains, ~indexerStartTime) => {
96
95
 
97
96
  let blocksProcessed = getTotalBlocksProcessed(chains)->Int.toFloat
98
97
  if shouldDisplayEta && blocksProcessed > 0. {
99
- let nowDate = Js.Date.now()
98
+ let nowDate = Date.now()
100
99
  let remainingBlocks = getTotalRemainingBlocks(chains)->Int.toFloat
101
100
  let etaFloat = timeSinceStart /. blocksProcessed *. remainingBlocks
102
101
  let millisToSub = secondsToSub *. 1000.
103
102
  let etaFloat = Pervasives.max(etaFloat -. millisToSub, 0.0) //template this
104
- let eta = (etaFloat +. nowDate)->Js.Date.fromFloat
105
- let interval: DateFns.interval = {start: nowDate->Js.Date.fromFloat, end: eta}
103
+ let eta = (etaFloat +. nowDate)->Date.fromTime
104
+ let interval: DateFns.interval = {start: nowDate->Date.fromTime, end: eta}
106
105
  let duration = DateFns.intervalToDuration(interval)
107
106
  let formattedDuration = DateFns.formatDuration(
108
107
  duration,
@@ -1,263 +1,245 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
- import * as $$Ink from "ink";
4
- import * as Caml from "rescript/lib/es6/caml.js";
3
+ import * as Ink from "ink";
5
4
  import * as React from "react";
6
5
  import * as DateFns from "date-fns";
7
- import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
8
6
  import InkSpinner from "ink-spinner";
7
+ import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
8
+ import * as Primitive_float from "@rescript/runtime/lib/es6/Primitive_float.js";
9
9
  import * as JsxRuntime from "react/jsx-runtime";
10
10
 
11
11
  function isIndexerFullySynced(chains) {
12
- return Belt_Array.reduce(chains, true, (function (accum, current) {
13
- var match = current.progress;
14
- if (typeof match !== "object" || match.TAG === "Syncing") {
15
- return false;
16
- } else {
17
- return accum;
18
- }
19
- }));
12
+ return Stdlib_Array.reduce(chains, true, (accum, current) => {
13
+ let match = current.progress;
14
+ if (typeof match !== "object" || match.TAG === "Syncing") {
15
+ return false;
16
+ } else {
17
+ return accum;
18
+ }
19
+ });
20
20
  }
21
21
 
22
22
  function getTotalRemainingBlocks(chains) {
23
- return Belt_Array.reduce(chains, 0, (function (accum, param) {
24
- var progress = param.progress;
25
- var endBlock = param.endBlock;
26
- var finalBlock = endBlock !== undefined ? endBlock : param.knownHeight;
27
- if (typeof progress !== "object") {
28
- return (finalBlock - param.latestFetchedBlockNumber | 0) + accum | 0;
29
- }
30
- progress.TAG === "Syncing";
31
- return (finalBlock - progress._0.latestProcessedBlock | 0) + accum | 0;
32
- }));
23
+ return Stdlib_Array.reduce(chains, 0, (accum, param) => {
24
+ let progress = param.progress;
25
+ let endBlock = param.endBlock;
26
+ let finalBlock = endBlock !== undefined ? endBlock : param.knownHeight;
27
+ if (typeof progress !== "object") {
28
+ return (finalBlock - param.latestFetchedBlockNumber | 0) + accum | 0;
29
+ }
30
+ progress.TAG === "Syncing";
31
+ return (finalBlock - progress._0.latestProcessedBlock | 0) + accum | 0;
32
+ });
33
33
  }
34
34
 
35
35
  function getLatestTimeCaughtUpToHead(chains, indexerStartTime) {
36
- var latesttimestampCaughtUpToHeadOrEndblockFloat = Belt_Array.reduce(chains, 0.0, (function (accum, current) {
37
- var match = current.progress;
38
- if (typeof match !== "object") {
39
- return accum;
40
- }
41
- if (match.TAG === "Syncing") {
42
- return accum;
43
- }
44
- var timestampCaughtUpToHeadOrEndblock = match._0.timestampCaughtUpToHeadOrEndblock;
45
- if (timestampCaughtUpToHeadOrEndblock.valueOf() > accum) {
46
- return timestampCaughtUpToHeadOrEndblock.valueOf();
47
- } else {
48
- return accum;
49
- }
50
- }));
36
+ let latesttimestampCaughtUpToHeadOrEndblockFloat = Stdlib_Array.reduce(chains, 0.0, (accum, current) => {
37
+ let match = current.progress;
38
+ if (typeof match !== "object") {
39
+ return accum;
40
+ }
41
+ if (match.TAG === "Syncing") {
42
+ return accum;
43
+ }
44
+ let timestampCaughtUpToHeadOrEndblock = match._0.timestampCaughtUpToHeadOrEndblock;
45
+ if (timestampCaughtUpToHeadOrEndblock.getTime() > accum) {
46
+ return timestampCaughtUpToHeadOrEndblock.getTime();
47
+ } else {
48
+ return accum;
49
+ }
50
+ });
51
51
  return DateFns.formatDistance(indexerStartTime, new Date(latesttimestampCaughtUpToHeadOrEndblockFloat), {
52
- includeSeconds: true
53
- });
52
+ includeSeconds: true
53
+ });
54
54
  }
55
55
 
56
56
  function getTotalBlocksProcessed(chains) {
57
- return Belt_Array.reduce(chains, 0, (function (accum, param) {
58
- var progress = param.progress;
59
- if (typeof progress !== "object") {
60
- return param.latestFetchedBlockNumber + accum | 0;
61
- }
62
- progress.TAG === "Syncing";
63
- var match = progress._0;
64
- return (match.latestProcessedBlock - match.firstEventBlockNumber | 0) + accum | 0;
65
- }));
57
+ return Stdlib_Array.reduce(chains, 0, (accum, param) => {
58
+ let progress = param.progress;
59
+ if (typeof progress !== "object") {
60
+ return param.latestFetchedBlockNumber + accum | 0;
61
+ }
62
+ progress.TAG === "Syncing";
63
+ let match = progress._0;
64
+ return (match.latestProcessedBlock - match.firstEventBlockNumber | 0) + accum | 0;
65
+ });
66
66
  }
67
67
 
68
68
  function useShouldDisplayEta(chains) {
69
- var match = React.useState(function () {
70
- return false;
69
+ let match = React.useState(() => false);
70
+ let setShouldDisplayEta = match[1];
71
+ let shouldDisplayEta = match[0];
72
+ React.useEffect(() => {
73
+ if (!shouldDisplayEta) {
74
+ let allChainsStartedFetching = chains.every(chain => {
75
+ if (chain.knownHeight > 0) {
76
+ return chain.latestFetchedBlockNumber > 0;
77
+ } else {
78
+ return false;
79
+ }
71
80
  });
72
- var setShouldDisplayEta = match[1];
73
- var shouldDisplayEta = match[0];
74
- React.useEffect((function () {
75
- if (!shouldDisplayEta) {
76
- var allChainsStartedFetching = Belt_Array.every(chains, (function (chain) {
77
- if (chain.knownHeight > 0) {
78
- return chain.latestFetchedBlockNumber > 0;
79
- } else {
80
- return false;
81
- }
82
- }));
83
- if (allChainsStartedFetching) {
84
- setShouldDisplayEta(function (param) {
85
- return true;
86
- });
87
- }
88
-
89
- }
90
-
91
- }), [chains]);
81
+ if (allChainsStartedFetching) {
82
+ setShouldDisplayEta(param => true);
83
+ }
84
+ }
85
+ }, [chains]);
92
86
  return shouldDisplayEta;
93
87
  }
94
88
 
95
89
  function useEta(chains, indexerStartTime) {
96
- var shouldDisplayEta = useShouldDisplayEta(chains);
97
- var match = React.useState(function () {
98
- return 0;
99
- });
100
- var setSecondsToSub = match[1];
101
- var match$1 = React.useState(function () {
102
- return 0;
103
- });
104
- var setTimeSinceStart = match$1[1];
105
- React.useEffect((function () {
106
- setTimeSinceStart(function (param) {
107
- return Date.now() - indexerStartTime.valueOf();
108
- });
109
- setSecondsToSub(function (param) {
110
- return 0;
111
- });
112
- var intervalId = setInterval((function () {
113
- setSecondsToSub(function (prev) {
114
- return prev + 1;
115
- });
116
- }), 1000);
117
- return (function () {
118
- clearInterval(intervalId);
119
- });
120
- }), [
121
- chains,
122
- indexerStartTime
123
- ]);
124
- var blocksProcessed = getTotalBlocksProcessed(chains);
90
+ let shouldDisplayEta = useShouldDisplayEta(chains);
91
+ let match = React.useState(() => 0);
92
+ let setSecondsToSub = match[1];
93
+ let match$1 = React.useState(() => 0);
94
+ let setTimeSinceStart = match$1[1];
95
+ React.useEffect(() => {
96
+ setTimeSinceStart(param => Date.now() - indexerStartTime.getTime());
97
+ setSecondsToSub(param => 0);
98
+ let intervalId = setInterval(() => setSecondsToSub(prev => prev + 1), 1000);
99
+ return () => {
100
+ clearInterval(intervalId);
101
+ };
102
+ }, [
103
+ chains,
104
+ indexerStartTime
105
+ ]);
106
+ let blocksProcessed = getTotalBlocksProcessed(chains);
125
107
  if (!(shouldDisplayEta && blocksProcessed > 0)) {
126
- return ;
108
+ return;
127
109
  }
128
- var nowDate = Date.now();
129
- var remainingBlocks = getTotalRemainingBlocks(chains);
130
- var etaFloat = match$1[0] / blocksProcessed * remainingBlocks;
131
- var millisToSub = match[0] * 1000;
132
- var etaFloat$1 = Caml.float_max(etaFloat - millisToSub, 0.0);
133
- var eta = new Date(etaFloat$1 + nowDate);
134
- var interval_start = new Date(nowDate);
135
- var interval = {
110
+ let nowDate = Date.now();
111
+ let remainingBlocks = getTotalRemainingBlocks(chains);
112
+ let etaFloat = match$1[0] / blocksProcessed * remainingBlocks;
113
+ let millisToSub = match[0] * 1000;
114
+ let etaFloat$1 = Primitive_float.max(etaFloat - millisToSub, 0.0);
115
+ let eta = new Date(etaFloat$1 + nowDate);
116
+ let interval_start = new Date(nowDate);
117
+ let interval = {
136
118
  start: interval_start,
137
119
  end: eta
138
120
  };
139
- var duration = DateFns.intervalToDuration(interval);
140
- var formattedDuration = DateFns.formatDuration(duration, {
141
- format: [
142
- "hours",
143
- "minutes",
144
- "seconds"
145
- ]
146
- });
147
- var tmp = formattedDuration === "" ? "less than 1 second" : formattedDuration;
121
+ let duration = DateFns.intervalToDuration(interval);
122
+ let formattedDuration = DateFns.formatDuration(duration, {
123
+ format: [
124
+ "hours",
125
+ "minutes",
126
+ "seconds"
127
+ ]
128
+ });
129
+ let tmp = formattedDuration === "" ? "less than 1 second" : formattedDuration;
148
130
  return tmp;
149
131
  }
150
132
 
151
133
  function SyncETA$Syncing(props) {
152
- return JsxRuntime.jsxs($$Ink.Text, {
153
- children: [
154
- JsxRuntime.jsx($$Ink.Text, {
155
- children: "Sync Time ETA: "
156
- }),
157
- JsxRuntime.jsx($$Ink.Text, {
158
- children: props.etaStr
159
- }),
160
- JsxRuntime.jsx($$Ink.Text, {
161
- children: " ("
162
- }),
163
- JsxRuntime.jsx($$Ink.Text, {
164
- children: JsxRuntime.jsx(InkSpinner, {}),
165
- color: "#9860E5"
166
- }),
167
- JsxRuntime.jsx($$Ink.Text, {
168
- children: " in progress",
169
- color: "#FFBB2F"
170
- }),
171
- JsxRuntime.jsx($$Ink.Text, {
172
- children: ")"
173
- })
174
- ],
175
- bold: true
176
- });
134
+ return JsxRuntime.jsxs(Ink.Text, {
135
+ children: [
136
+ JsxRuntime.jsx(Ink.Text, {
137
+ children: "Sync Time ETA: "
138
+ }),
139
+ JsxRuntime.jsx(Ink.Text, {
140
+ children: props.etaStr
141
+ }),
142
+ JsxRuntime.jsx(Ink.Text, {
143
+ children: " ("
144
+ }),
145
+ JsxRuntime.jsx(Ink.Text, {
146
+ children: JsxRuntime.jsx(InkSpinner, {}),
147
+ color: "#9860E5"
148
+ }),
149
+ JsxRuntime.jsx(Ink.Text, {
150
+ children: " in progress",
151
+ color: "#FFBB2F"
152
+ }),
153
+ JsxRuntime.jsx(Ink.Text, {
154
+ children: ")"
155
+ })
156
+ ],
157
+ bold: true
158
+ });
177
159
  }
178
160
 
179
- var Syncing = {
161
+ let Syncing = {
180
162
  make: SyncETA$Syncing
181
163
  };
182
164
 
183
165
  function SyncETA$Synced(props) {
184
- return JsxRuntime.jsxs($$Ink.Text, {
185
- children: [
186
- JsxRuntime.jsx($$Ink.Text, {
187
- children: "Time Synced: "
188
- }),
189
- JsxRuntime.jsx($$Ink.Text, {
190
- children: props.latestTimeCaughtUpToHeadStr
191
- }),
192
- JsxRuntime.jsx($$Ink.Text, {
193
- children: " ("
194
- }),
195
- JsxRuntime.jsx($$Ink.Text, {
196
- children: "synced",
197
- color: "#3B8C3D"
198
- }),
199
- JsxRuntime.jsx($$Ink.Text, {
200
- children: ")"
201
- })
202
- ],
203
- bold: true
204
- });
166
+ return JsxRuntime.jsxs(Ink.Text, {
167
+ children: [
168
+ JsxRuntime.jsx(Ink.Text, {
169
+ children: "Time Synced: "
170
+ }),
171
+ JsxRuntime.jsx(Ink.Text, {
172
+ children: props.latestTimeCaughtUpToHeadStr
173
+ }),
174
+ JsxRuntime.jsx(Ink.Text, {
175
+ children: " ("
176
+ }),
177
+ JsxRuntime.jsx(Ink.Text, {
178
+ children: "synced",
179
+ color: "#3B8C3D"
180
+ }),
181
+ JsxRuntime.jsx(Ink.Text, {
182
+ children: ")"
183
+ })
184
+ ],
185
+ bold: true
186
+ });
205
187
  }
206
188
 
207
- var Synced = {
189
+ let Synced = {
208
190
  make: SyncETA$Synced
209
191
  };
210
192
 
211
193
  function SyncETA$Calculating(props) {
212
- return JsxRuntime.jsxs($$Ink.Text, {
213
- children: [
214
- JsxRuntime.jsx($$Ink.Text, {
215
- children: JsxRuntime.jsx(InkSpinner, {}),
216
- color: "#9860E5"
217
- }),
218
- JsxRuntime.jsx($$Ink.Text, {
219
- children: " Calculating ETA...",
220
- bold: true
221
- })
222
- ]
223
- });
194
+ return JsxRuntime.jsxs(Ink.Text, {
195
+ children: [
196
+ JsxRuntime.jsx(Ink.Text, {
197
+ children: JsxRuntime.jsx(InkSpinner, {}),
198
+ color: "#9860E5"
199
+ }),
200
+ JsxRuntime.jsx(Ink.Text, {
201
+ children: " Calculating ETA...",
202
+ bold: true
203
+ })
204
+ ]
205
+ });
224
206
  }
225
207
 
226
- var Calculating = {
208
+ let Calculating = {
227
209
  make: SyncETA$Calculating
228
210
  };
229
211
 
230
212
  function SyncETA(props) {
231
- var indexerStartTime = props.indexerStartTime;
232
- var chains = props.chains;
233
- var optEta = useEta(chains, indexerStartTime);
213
+ let indexerStartTime = props.indexerStartTime;
214
+ let chains = props.chains;
215
+ let optEta = useEta(chains, indexerStartTime);
234
216
  if (!isIndexerFullySynced(chains)) {
235
217
  if (optEta !== undefined) {
236
218
  return JsxRuntime.jsx(SyncETA$Syncing, {
237
- etaStr: optEta
238
- });
219
+ etaStr: optEta
220
+ });
239
221
  } else {
240
222
  return JsxRuntime.jsx(SyncETA$Calculating, {});
241
223
  }
242
224
  }
243
- var latestTimeCaughtUpToHeadStr = getLatestTimeCaughtUpToHead(chains, indexerStartTime);
225
+ let latestTimeCaughtUpToHeadStr = getLatestTimeCaughtUpToHead(chains, indexerStartTime);
244
226
  return JsxRuntime.jsx(SyncETA$Synced, {
245
- latestTimeCaughtUpToHeadStr: latestTimeCaughtUpToHeadStr
246
- });
227
+ latestTimeCaughtUpToHeadStr: latestTimeCaughtUpToHeadStr
228
+ });
247
229
  }
248
230
 
249
- var make = SyncETA;
231
+ let make = SyncETA;
250
232
 
251
233
  export {
252
- isIndexerFullySynced ,
253
- getTotalRemainingBlocks ,
254
- getLatestTimeCaughtUpToHead ,
255
- getTotalBlocksProcessed ,
256
- useShouldDisplayEta ,
257
- useEta ,
258
- Syncing ,
259
- Synced ,
260
- Calculating ,
261
- make ,
234
+ isIndexerFullySynced,
235
+ getTotalRemainingBlocks,
236
+ getLatestTimeCaughtUpToHead,
237
+ getTotalBlocksProcessed,
238
+ useShouldDisplayEta,
239
+ useEta,
240
+ Syncing,
241
+ Synced,
242
+ Calculating,
243
+ make,
262
244
  }
263
245
  /* ink Not a pure module */
@@ -5,7 +5,7 @@ type syncing = {
5
5
  }
6
6
  type synced = {
7
7
  ...syncing,
8
- timestampCaughtUpToHeadOrEndblock: Js.Date.t,
8
+ timestampCaughtUpToHeadOrEndblock: Date.t,
9
9
  }
10
10
 
11
11
  type progress = SearchingForEvents | Syncing(syncing) | Synced(synced)
@@ -1,5 +1,6 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
+ import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js";
3
4
 
4
5
  function getNumberOfEventsProccessed(progress) {
5
6
  if (typeof progress !== "object") {
@@ -10,8 +11,8 @@ function getNumberOfEventsProccessed(progress) {
10
11
  }
11
12
 
12
13
  function minOfOption(a, b) {
13
- if (b !== undefined && a >= b) {
14
- return b;
14
+ if (b !== undefined) {
15
+ return Primitive_int.min(a, b);
15
16
  } else {
16
17
  return a;
17
18
  }
@@ -26,9 +27,9 @@ function formatFloatLocaleString(n) {
26
27
  }
27
28
 
28
29
  export {
29
- getNumberOfEventsProccessed ,
30
- minOfOption ,
31
- formatLocaleString ,
32
- formatFloatLocaleString ,
30
+ getNumberOfEventsProccessed,
31
+ minOfOption,
32
+ formatLocaleString,
33
+ formatFloatLocaleString,
33
34
  }
34
35
  /* No side effect */