envio 3.0.0-alpha.4 → 3.0.0-alpha.5

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 (55) hide show
  1. package/index.d.ts +329 -0
  2. package/index.js +3 -0
  3. package/package.json +13 -6
  4. package/rescript.json +4 -1
  5. package/src/ChainFetcher.res +25 -1
  6. package/src/ChainFetcher.res.mjs +19 -1
  7. package/src/Config.res +211 -18
  8. package/src/Config.res.mjs +226 -27
  9. package/src/{Indexer.res → Ctx.res} +1 -1
  10. package/src/EventProcessing.res +18 -18
  11. package/src/EventProcessing.res.mjs +14 -14
  12. package/src/GlobalState.res +29 -35
  13. package/src/GlobalState.res.mjs +47 -47
  14. package/src/GlobalStateManager.res +68 -0
  15. package/src/GlobalStateManager.res.mjs +75 -0
  16. package/src/GlobalStateManager.resi +7 -0
  17. package/src/Internal.res +0 -1
  18. package/src/LogSelection.res +33 -27
  19. package/src/LogSelection.res.mjs +6 -0
  20. package/src/Main.res +342 -0
  21. package/src/Main.res.mjs +289 -0
  22. package/src/PgStorage.gen.ts +10 -0
  23. package/src/PgStorage.res +24 -2
  24. package/src/PgStorage.res.d.mts +5 -0
  25. package/src/PgStorage.res.mjs +22 -1
  26. package/src/UserContext.res +0 -1
  27. package/src/UserContext.res.mjs +0 -2
  28. package/src/Utils.res +13 -0
  29. package/src/bindings/Ethers.res +0 -4
  30. package/src/bindings/Ethers.res.mjs +0 -5
  31. package/src/bindings/Postgres.gen.ts +8 -0
  32. package/src/bindings/Postgres.res +3 -0
  33. package/src/bindings/Postgres.res.d.mts +5 -0
  34. package/src/bindings/RescriptMocha.res +123 -0
  35. package/src/bindings/RescriptMocha.res.mjs +18 -0
  36. package/src/bindings/Yargs.res +8 -0
  37. package/src/bindings/Yargs.res.mjs +2 -0
  38. package/src/sources/FuelSDK.res +4 -3
  39. package/src/tui/Tui.res +266 -0
  40. package/src/tui/Tui.res.mjs +342 -0
  41. package/src/tui/bindings/Ink.res +376 -0
  42. package/src/tui/bindings/Ink.res.mjs +75 -0
  43. package/src/tui/bindings/Style.res +123 -0
  44. package/src/tui/bindings/Style.res.mjs +2 -0
  45. package/src/tui/components/BufferedProgressBar.res +40 -0
  46. package/src/tui/components/BufferedProgressBar.res.mjs +57 -0
  47. package/src/tui/components/CustomHooks.res +114 -0
  48. package/src/tui/components/CustomHooks.res.mjs +162 -0
  49. package/src/tui/components/Messages.res +41 -0
  50. package/src/tui/components/Messages.res.mjs +75 -0
  51. package/src/tui/components/SyncETA.res +193 -0
  52. package/src/tui/components/SyncETA.res.mjs +269 -0
  53. package/src/tui/components/TuiData.res +46 -0
  54. package/src/tui/components/TuiData.res.mjs +29 -0
  55. /package/src/{Indexer.res.mjs → Ctx.res.mjs} +0 -0
@@ -0,0 +1,269 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as $$Ink from "ink";
4
+ import * as Caml from "rescript/lib/es6/caml.js";
5
+ import * as React from "react";
6
+ import * as DateFns from "date-fns";
7
+ import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
8
+ import InkSpinner from "ink-spinner";
9
+ import * as JsxRuntime from "react/jsx-runtime";
10
+
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
+ }));
20
+ }
21
+
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
+ }));
33
+ }
34
+
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
+ }));
51
+ return DateFns.formatDistance(indexerStartTime, new Date(latesttimestampCaughtUpToHeadOrEndblockFloat), {
52
+ includeSeconds: true
53
+ });
54
+ }
55
+
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
+ }));
66
+ }
67
+
68
+ function useShouldDisplayEta(chains) {
69
+ var match = React.useState(function () {
70
+ return false;
71
+ });
72
+ var setShouldDisplayEta = match[1];
73
+ var shouldDisplayEta = match[0];
74
+ React.useEffect((function () {
75
+ if (!shouldDisplayEta) {
76
+ var match = Belt_Array.reduce(chains, [
77
+ true,
78
+ 0
79
+ ], (function (param, chain) {
80
+ return [
81
+ param[0] && chain.numBatchesFetched >= 1,
82
+ param[1] + chain.numBatchesFetched | 0
83
+ ];
84
+ }));
85
+ var numChains = chains.length;
86
+ var minTotalBatches = numChains + 2 | 0;
87
+ var hasMinNumBatches = match[1] >= minTotalBatches;
88
+ var shouldDisplayEta$1 = match[0] && hasMinNumBatches;
89
+ if (shouldDisplayEta$1) {
90
+ setShouldDisplayEta(function (param) {
91
+ return true;
92
+ });
93
+ }
94
+
95
+ }
96
+
97
+ }), [chains]);
98
+ return shouldDisplayEta;
99
+ }
100
+
101
+ function useEta(chains, indexerStartTime) {
102
+ var shouldDisplayEta = useShouldDisplayEta(chains);
103
+ var match = React.useState(function () {
104
+ return 0;
105
+ });
106
+ var setSecondsToSub = match[1];
107
+ var match$1 = React.useState(function () {
108
+ return 0;
109
+ });
110
+ var setTimeSinceStart = match$1[1];
111
+ React.useEffect((function () {
112
+ setTimeSinceStart(function (param) {
113
+ return Date.now() - indexerStartTime.valueOf();
114
+ });
115
+ setSecondsToSub(function (param) {
116
+ return 0;
117
+ });
118
+ var intervalId = setInterval((function () {
119
+ setSecondsToSub(function (prev) {
120
+ return prev + 1;
121
+ });
122
+ }), 1000);
123
+ return (function () {
124
+ clearInterval(intervalId);
125
+ });
126
+ }), [
127
+ chains,
128
+ indexerStartTime
129
+ ]);
130
+ var blocksProcessed = getTotalBlocksProcessed(chains);
131
+ if (!(shouldDisplayEta && blocksProcessed > 0)) {
132
+ return ;
133
+ }
134
+ var nowDate = Date.now();
135
+ var remainingBlocks = getTotalRemainingBlocks(chains);
136
+ var etaFloat = match$1[0] / blocksProcessed * remainingBlocks;
137
+ var millisToSub = match[0] * 1000;
138
+ var etaFloat$1 = Caml.float_max(etaFloat - millisToSub, 0.0);
139
+ var eta = new Date(etaFloat$1 + nowDate);
140
+ var interval_start = new Date(nowDate);
141
+ var interval = {
142
+ start: interval_start,
143
+ end: eta
144
+ };
145
+ var duration = DateFns.intervalToDuration(interval);
146
+ var formattedDuration = DateFns.formatDuration(duration, {
147
+ format: [
148
+ "hours",
149
+ "minutes",
150
+ "seconds"
151
+ ]
152
+ });
153
+ var tmp = formattedDuration === "" ? "less than 1 second" : formattedDuration;
154
+ return tmp;
155
+ }
156
+
157
+ function SyncETA$Syncing(props) {
158
+ return JsxRuntime.jsxs($$Ink.Text, {
159
+ children: [
160
+ JsxRuntime.jsx($$Ink.Text, {
161
+ children: "Sync Time ETA: "
162
+ }),
163
+ JsxRuntime.jsx($$Ink.Text, {
164
+ children: props.etaStr
165
+ }),
166
+ JsxRuntime.jsx($$Ink.Text, {
167
+ children: " ("
168
+ }),
169
+ JsxRuntime.jsx($$Ink.Text, {
170
+ children: JsxRuntime.jsx(InkSpinner, {}),
171
+ color: "#9860E5"
172
+ }),
173
+ JsxRuntime.jsx($$Ink.Text, {
174
+ children: " in progress",
175
+ color: "#FFBB2F"
176
+ }),
177
+ JsxRuntime.jsx($$Ink.Text, {
178
+ children: ")"
179
+ })
180
+ ],
181
+ bold: true
182
+ });
183
+ }
184
+
185
+ var Syncing = {
186
+ make: SyncETA$Syncing
187
+ };
188
+
189
+ function SyncETA$Synced(props) {
190
+ return JsxRuntime.jsxs($$Ink.Text, {
191
+ children: [
192
+ JsxRuntime.jsx($$Ink.Text, {
193
+ children: "Time Synced: "
194
+ }),
195
+ JsxRuntime.jsx($$Ink.Text, {
196
+ children: props.latestTimeCaughtUpToHeadStr
197
+ }),
198
+ JsxRuntime.jsx($$Ink.Text, {
199
+ children: " ("
200
+ }),
201
+ JsxRuntime.jsx($$Ink.Text, {
202
+ children: "synced",
203
+ color: "#3B8C3D"
204
+ }),
205
+ JsxRuntime.jsx($$Ink.Text, {
206
+ children: ")"
207
+ })
208
+ ],
209
+ bold: true
210
+ });
211
+ }
212
+
213
+ var Synced = {
214
+ make: SyncETA$Synced
215
+ };
216
+
217
+ function SyncETA$Calculating(props) {
218
+ return JsxRuntime.jsxs($$Ink.Text, {
219
+ children: [
220
+ JsxRuntime.jsx($$Ink.Text, {
221
+ children: JsxRuntime.jsx(InkSpinner, {}),
222
+ color: "#9860E5"
223
+ }),
224
+ JsxRuntime.jsx($$Ink.Text, {
225
+ children: " Calculating ETA...",
226
+ bold: true
227
+ })
228
+ ]
229
+ });
230
+ }
231
+
232
+ var Calculating = {
233
+ make: SyncETA$Calculating
234
+ };
235
+
236
+ function SyncETA(props) {
237
+ var indexerStartTime = props.indexerStartTime;
238
+ var chains = props.chains;
239
+ var optEta = useEta(chains, indexerStartTime);
240
+ if (!isIndexerFullySynced(chains)) {
241
+ if (optEta !== undefined) {
242
+ return JsxRuntime.jsx(SyncETA$Syncing, {
243
+ etaStr: optEta
244
+ });
245
+ } else {
246
+ return JsxRuntime.jsx(SyncETA$Calculating, {});
247
+ }
248
+ }
249
+ var latestTimeCaughtUpToHeadStr = getLatestTimeCaughtUpToHead(chains, indexerStartTime);
250
+ return JsxRuntime.jsx(SyncETA$Synced, {
251
+ latestTimeCaughtUpToHeadStr: latestTimeCaughtUpToHeadStr
252
+ });
253
+ }
254
+
255
+ var make = SyncETA;
256
+
257
+ export {
258
+ isIndexerFullySynced ,
259
+ getTotalRemainingBlocks ,
260
+ getLatestTimeCaughtUpToHead ,
261
+ getTotalBlocksProcessed ,
262
+ useShouldDisplayEta ,
263
+ useEta ,
264
+ Syncing ,
265
+ Synced ,
266
+ Calculating ,
267
+ make ,
268
+ }
269
+ /* ink Not a pure module */
@@ -0,0 +1,46 @@
1
+ type syncing = {
2
+ firstEventBlockNumber: int,
3
+ latestProcessedBlock: int,
4
+ numEventsProcessed: int,
5
+ }
6
+ type synced = {
7
+ ...syncing,
8
+ timestampCaughtUpToHeadOrEndblock: Js.Date.t,
9
+ }
10
+
11
+ type progress = SearchingForEvents | Syncing(syncing) | Synced(synced)
12
+
13
+ let getNumberOfEventsProccessed = (progress: progress) => {
14
+ switch progress {
15
+ | SearchingForEvents => 0
16
+ | Syncing(syncing) => syncing.numEventsProcessed
17
+ | Synced(synced) => synced.numEventsProcessed
18
+ }
19
+ }
20
+ type chain = {
21
+ chainId: string,
22
+ eventsProcessed: int,
23
+ progressBlock: option<int>,
24
+ bufferBlock: option<int>,
25
+ sourceBlock: option<int>,
26
+ startBlock: int,
27
+ endBlock: option<int>,
28
+ firstEventBlockNumber: option<int>,
29
+ poweredByHyperSync: bool,
30
+ progress: progress,
31
+ latestFetchedBlockNumber: int,
32
+ knownHeight: int,
33
+ numBatchesFetched: int,
34
+ }
35
+
36
+ let minOfOption: (int, option<int>) => int = (a: int, b: option<int>) => {
37
+ switch (a, b) {
38
+ | (a, Some(b)) => min(a, b)
39
+ | (a, None) => a
40
+ }
41
+ }
42
+
43
+ type number
44
+ @val external number: int => number = "Number"
45
+ @send external toLocaleString: number => string = "toLocaleString"
46
+ let formatLocaleString = n => n->number->toLocaleString
@@ -0,0 +1,29 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+
4
+ function getNumberOfEventsProccessed(progress) {
5
+ if (typeof progress !== "object") {
6
+ return 0;
7
+ } else {
8
+ return progress._0.numEventsProcessed;
9
+ }
10
+ }
11
+
12
+ function minOfOption(a, b) {
13
+ if (b !== undefined && a >= b) {
14
+ return b;
15
+ } else {
16
+ return a;
17
+ }
18
+ }
19
+
20
+ function formatLocaleString(n) {
21
+ return Number(n).toLocaleString();
22
+ }
23
+
24
+ export {
25
+ getNumberOfEventsProccessed ,
26
+ minOfOption ,
27
+ formatLocaleString ,
28
+ }
29
+ /* No side effect */
File without changes