envio 3.0.0-alpha.21 → 3.0.0-alpha.22

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 (219) hide show
  1. package/bin.mjs +2 -48
  2. package/evm.schema.json +67 -0
  3. package/fuel.schema.json +67 -0
  4. package/index.d.ts +822 -38
  5. package/index.js +5 -3
  6. package/package.json +10 -8
  7. package/rescript.json +5 -9
  8. package/src/Address.res +4 -5
  9. package/src/Address.res.mjs +9 -12
  10. package/src/Api.res +15 -0
  11. package/src/Api.res.mjs +20 -0
  12. package/src/Batch.res +32 -34
  13. package/src/Batch.res.mjs +172 -187
  14. package/src/Bin.res +89 -0
  15. package/src/Bin.res.mjs +97 -0
  16. package/src/ChainFetcher.res +33 -57
  17. package/src/ChainFetcher.res.mjs +197 -227
  18. package/src/ChainManager.res +6 -14
  19. package/src/ChainManager.res.mjs +74 -85
  20. package/src/ChainMap.res +14 -16
  21. package/src/ChainMap.res.mjs +38 -38
  22. package/src/Config.res +193 -135
  23. package/src/Config.res.mjs +566 -592
  24. package/src/Core.res +182 -0
  25. package/src/Core.res.mjs +207 -0
  26. package/src/Ecosystem.res +25 -4
  27. package/src/Ecosystem.res.mjs +12 -13
  28. package/src/Env.res +20 -13
  29. package/src/Env.res.mjs +124 -113
  30. package/src/EnvSafe.res +269 -0
  31. package/src/EnvSafe.res.mjs +296 -0
  32. package/src/EnvSafe.resi +18 -0
  33. package/src/Envio.res +37 -26
  34. package/src/Envio.res.mjs +59 -60
  35. package/src/ErrorHandling.res +2 -2
  36. package/src/ErrorHandling.res.mjs +15 -15
  37. package/src/EventConfigBuilder.res +219 -81
  38. package/src/EventConfigBuilder.res.mjs +259 -202
  39. package/src/EventProcessing.res +27 -38
  40. package/src/EventProcessing.res.mjs +165 -183
  41. package/src/EventUtils.res +11 -11
  42. package/src/EventUtils.res.mjs +21 -22
  43. package/src/EvmTypes.res +0 -1
  44. package/src/EvmTypes.res.mjs +5 -5
  45. package/src/FetchState.res +360 -256
  46. package/src/FetchState.res.mjs +958 -914
  47. package/src/GlobalState.res +365 -351
  48. package/src/GlobalState.res.mjs +958 -992
  49. package/src/GlobalStateManager.res +1 -2
  50. package/src/GlobalStateManager.res.mjs +36 -44
  51. package/src/HandlerLoader.res +107 -23
  52. package/src/HandlerLoader.res.mjs +128 -38
  53. package/src/HandlerRegister.res +127 -103
  54. package/src/HandlerRegister.res.mjs +164 -164
  55. package/src/HandlerRegister.resi +12 -4
  56. package/src/Hasura.res +35 -22
  57. package/src/Hasura.res.mjs +158 -167
  58. package/src/InMemoryStore.res +20 -27
  59. package/src/InMemoryStore.res.mjs +64 -80
  60. package/src/InMemoryTable.res +34 -39
  61. package/src/InMemoryTable.res.mjs +165 -170
  62. package/src/Internal.res +52 -33
  63. package/src/Internal.res.mjs +84 -81
  64. package/src/LazyLoader.res.mjs +55 -61
  65. package/src/LoadLayer.res +77 -78
  66. package/src/LoadLayer.res.mjs +160 -189
  67. package/src/LoadManager.res +16 -21
  68. package/src/LoadManager.res.mjs +79 -84
  69. package/src/LogSelection.res +236 -68
  70. package/src/LogSelection.res.mjs +211 -141
  71. package/src/Logging.res +13 -9
  72. package/src/Logging.res.mjs +130 -143
  73. package/src/Main.res +428 -51
  74. package/src/Main.res.mjs +528 -271
  75. package/src/Persistence.res +77 -84
  76. package/src/Persistence.res.mjs +131 -132
  77. package/src/PgStorage.res +291 -167
  78. package/src/PgStorage.res.mjs +797 -817
  79. package/src/Prometheus.res +50 -58
  80. package/src/Prometheus.res.mjs +345 -373
  81. package/src/ReorgDetection.res +22 -24
  82. package/src/ReorgDetection.res.mjs +100 -106
  83. package/src/SafeCheckpointTracking.res +7 -7
  84. package/src/SafeCheckpointTracking.res.mjs +40 -43
  85. package/src/SimulateItems.res +41 -49
  86. package/src/SimulateItems.res.mjs +257 -272
  87. package/src/Sink.res +2 -2
  88. package/src/Sink.res.mjs +22 -26
  89. package/src/TableIndices.res +1 -2
  90. package/src/TableIndices.res.mjs +42 -48
  91. package/src/TestIndexer.res +196 -189
  92. package/src/TestIndexer.res.mjs +536 -536
  93. package/src/TestIndexerProxyStorage.res +15 -16
  94. package/src/TestIndexerProxyStorage.res.mjs +98 -122
  95. package/src/TestIndexerWorker.res +4 -0
  96. package/src/TestIndexerWorker.res.mjs +7 -0
  97. package/src/Throttler.res +3 -3
  98. package/src/Throttler.res.mjs +23 -24
  99. package/src/Time.res +1 -1
  100. package/src/Time.res.mjs +18 -21
  101. package/src/TopicFilter.res +3 -3
  102. package/src/TopicFilter.res.mjs +29 -30
  103. package/src/UserContext.res +93 -54
  104. package/src/UserContext.res.mjs +197 -182
  105. package/src/Utils.res +141 -86
  106. package/src/Utils.res.mjs +334 -295
  107. package/src/bindings/BigDecimal.res +0 -2
  108. package/src/bindings/BigDecimal.res.mjs +19 -23
  109. package/src/bindings/ClickHouse.res +28 -27
  110. package/src/bindings/ClickHouse.res.mjs +243 -240
  111. package/src/bindings/DateFns.res +11 -11
  112. package/src/bindings/DateFns.res.mjs +7 -7
  113. package/src/bindings/EventSource.res.mjs +2 -2
  114. package/src/bindings/Express.res +2 -5
  115. package/src/bindings/Hrtime.res +2 -2
  116. package/src/bindings/Hrtime.res.mjs +30 -32
  117. package/src/bindings/Lodash.res.mjs +1 -1
  118. package/src/bindings/NodeJs.res +14 -9
  119. package/src/bindings/NodeJs.res.mjs +20 -20
  120. package/src/bindings/Pino.res +8 -10
  121. package/src/bindings/Pino.res.mjs +40 -43
  122. package/src/bindings/Postgres.res +2 -5
  123. package/src/bindings/Postgres.res.mjs +9 -9
  124. package/src/bindings/PromClient.res +17 -2
  125. package/src/bindings/PromClient.res.mjs +30 -7
  126. package/src/bindings/SDSL.res.mjs +2 -2
  127. package/src/bindings/Viem.res +4 -4
  128. package/src/bindings/Viem.res.mjs +20 -22
  129. package/src/bindings/Vitest.res +1 -1
  130. package/src/bindings/Vitest.res.mjs +2 -2
  131. package/src/bindings/WebSocket.res +1 -1
  132. package/src/db/EntityHistory.res +9 -3
  133. package/src/db/EntityHistory.res.mjs +84 -59
  134. package/src/db/InternalTable.res +62 -60
  135. package/src/db/InternalTable.res.mjs +271 -203
  136. package/src/db/Schema.res +1 -2
  137. package/src/db/Schema.res.mjs +28 -32
  138. package/src/db/Table.res +28 -27
  139. package/src/db/Table.res.mjs +276 -292
  140. package/src/sources/EventRouter.res +21 -16
  141. package/src/sources/EventRouter.res.mjs +55 -57
  142. package/src/sources/Evm.res +17 -1
  143. package/src/sources/Evm.res.mjs +16 -8
  144. package/src/sources/EvmChain.res +15 -17
  145. package/src/sources/EvmChain.res.mjs +40 -42
  146. package/src/sources/Fuel.res +14 -1
  147. package/src/sources/Fuel.res.mjs +16 -8
  148. package/src/sources/FuelSDK.res +1 -1
  149. package/src/sources/FuelSDK.res.mjs +6 -8
  150. package/src/sources/HyperFuel.res +8 -10
  151. package/src/sources/HyperFuel.res.mjs +113 -123
  152. package/src/sources/HyperFuelClient.res.mjs +6 -7
  153. package/src/sources/HyperFuelSource.res +19 -20
  154. package/src/sources/HyperFuelSource.res.mjs +339 -356
  155. package/src/sources/HyperSync.res +11 -13
  156. package/src/sources/HyperSync.res.mjs +206 -220
  157. package/src/sources/HyperSyncClient.res +5 -7
  158. package/src/sources/HyperSyncClient.res.mjs +70 -75
  159. package/src/sources/HyperSyncHeightStream.res +8 -9
  160. package/src/sources/HyperSyncHeightStream.res.mjs +78 -86
  161. package/src/sources/HyperSyncJsonApi.res +18 -15
  162. package/src/sources/HyperSyncJsonApi.res.mjs +201 -231
  163. package/src/sources/HyperSyncSource.res +17 -21
  164. package/src/sources/HyperSyncSource.res.mjs +268 -290
  165. package/src/sources/Rpc.res +5 -5
  166. package/src/sources/Rpc.res.mjs +168 -192
  167. package/src/sources/RpcSource.res +166 -167
  168. package/src/sources/RpcSource.res.mjs +972 -1046
  169. package/src/sources/RpcWebSocketHeightStream.res +10 -11
  170. package/src/sources/RpcWebSocketHeightStream.res.mjs +131 -145
  171. package/src/sources/SimulateSource.res +1 -1
  172. package/src/sources/SimulateSource.res.mjs +35 -38
  173. package/src/sources/Source.res +1 -1
  174. package/src/sources/Source.res.mjs +3 -3
  175. package/src/sources/SourceManager.res +39 -20
  176. package/src/sources/SourceManager.res.mjs +340 -371
  177. package/src/sources/SourceManager.resi +2 -1
  178. package/src/sources/Svm.res +12 -5
  179. package/src/sources/Svm.res.mjs +44 -41
  180. package/src/tui/Tui.res +23 -12
  181. package/src/tui/Tui.res.mjs +292 -290
  182. package/src/tui/bindings/Ink.res +2 -4
  183. package/src/tui/bindings/Ink.res.mjs +35 -41
  184. package/src/tui/components/BufferedProgressBar.res +7 -7
  185. package/src/tui/components/BufferedProgressBar.res.mjs +46 -46
  186. package/src/tui/components/CustomHooks.res +1 -2
  187. package/src/tui/components/CustomHooks.res.mjs +102 -122
  188. package/src/tui/components/Messages.res +1 -2
  189. package/src/tui/components/Messages.res.mjs +38 -42
  190. package/src/tui/components/SyncETA.res +10 -11
  191. package/src/tui/components/SyncETA.res.mjs +178 -196
  192. package/src/tui/components/TuiData.res +1 -1
  193. package/src/tui/components/TuiData.res.mjs +7 -6
  194. package/src/vendored/Rest.res +52 -66
  195. package/src/vendored/Rest.res.mjs +324 -364
  196. package/svm.schema.json +67 -0
  197. package/src/Address.gen.ts +0 -8
  198. package/src/Config.gen.ts +0 -19
  199. package/src/Envio.gen.ts +0 -55
  200. package/src/EvmTypes.gen.ts +0 -6
  201. package/src/InMemoryStore.gen.ts +0 -6
  202. package/src/Internal.gen.ts +0 -64
  203. package/src/PgStorage.gen.ts +0 -10
  204. package/src/PgStorage.res.d.mts +0 -5
  205. package/src/Types.ts +0 -56
  206. package/src/bindings/BigDecimal.gen.ts +0 -14
  207. package/src/bindings/BigDecimal.res.d.mts +0 -5
  208. package/src/bindings/BigInt.gen.ts +0 -10
  209. package/src/bindings/BigInt.res +0 -70
  210. package/src/bindings/BigInt.res.d.mts +0 -5
  211. package/src/bindings/BigInt.res.mjs +0 -154
  212. package/src/bindings/Ethers.res.d.mts +0 -5
  213. package/src/bindings/Pino.gen.ts +0 -17
  214. package/src/bindings/Postgres.gen.ts +0 -8
  215. package/src/bindings/Postgres.res.d.mts +0 -5
  216. package/src/bindings/Promise.res +0 -67
  217. package/src/bindings/Promise.res.mjs +0 -26
  218. package/src/db/InternalTable.gen.ts +0 -36
  219. package/src/sources/HyperSyncClient.gen.ts +0 -19
@@ -2,110 +2,105 @@
2
2
 
3
3
  import * as Utils from "../Utils.res.mjs";
4
4
  import * as Address from "../Address.res.mjs";
5
- import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
5
+ import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
6
6
  import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
7
7
  import * as HypersyncClient from "@envio-dev/hypersync-client";
8
8
 
9
- var serializationFormatSchema = S$RescriptSchema.$$enum([
10
- "Json",
11
- "CapnProto"
12
- ]);
9
+ let serializationFormatSchema = S$RescriptSchema.$$enum([
10
+ "Json",
11
+ "CapnProto"
12
+ ]);
13
13
 
14
14
  function makeTopicSelection(topic0Opt, topic1Opt, topic2Opt, topic3Opt) {
15
- var topic0 = topic0Opt !== undefined ? topic0Opt : [];
16
- var topic1 = topic1Opt !== undefined ? topic1Opt : [];
17
- var topic2 = topic2Opt !== undefined ? topic2Opt : [];
18
- var topic3 = topic3Opt !== undefined ? topic3Opt : [];
15
+ let topic0 = topic0Opt !== undefined ? topic0Opt : [];
16
+ let topic1 = topic1Opt !== undefined ? topic1Opt : [];
17
+ let topic2 = topic2Opt !== undefined ? topic2Opt : [];
18
+ let topic3 = topic3Opt !== undefined ? topic3Opt : [];
19
19
  return [
20
- topic0,
21
- topic1,
22
- topic2,
23
- topic3
24
- ];
20
+ topic0,
21
+ topic1,
22
+ topic2,
23
+ topic3
24
+ ];
25
25
  }
26
26
 
27
27
  function makeLogSelection(address, topics) {
28
28
  return {
29
- address: address,
30
- topics: topics
31
- };
29
+ address: address,
30
+ topics: topics
31
+ };
32
32
  }
33
33
 
34
- var QueryTypes = {
34
+ let QueryTypes = {
35
35
  makeTopicSelection: makeTopicSelection,
36
36
  makeLogSelection: makeLogSelection
37
37
  };
38
38
 
39
- var accessListSchema = S$RescriptSchema.object(function (s) {
40
- return {
41
- address: s.f("address", S$RescriptSchema.option(Address.schema)),
42
- storageKeys: s.f("storageKeys", S$RescriptSchema.option(S$RescriptSchema.array(S$RescriptSchema.string)))
43
- };
44
- });
39
+ let accessListSchema = S$RescriptSchema.object(s => ({
40
+ address: s.f("address", S$RescriptSchema.option(Address.schema)),
41
+ storageKeys: s.f("storageKeys", S$RescriptSchema.option(S$RescriptSchema.array(S$RescriptSchema.string)))
42
+ }));
45
43
 
46
- var authorizationListSchema = S$RescriptSchema.object(function (s) {
47
- return {
48
- chainId: s.f("chainId", S$RescriptSchema.bigint),
49
- address: s.f("address", Address.schema),
50
- nonce: s.f("nonce", S$RescriptSchema.$$int),
51
- yParity: s.f("yParity", S$RescriptSchema.$$enum([
52
- 0,
53
- 1
54
- ])),
55
- r: s.f("r", S$RescriptSchema.string),
56
- s: s.f("s", S$RescriptSchema.string)
57
- };
58
- });
44
+ let authorizationListSchema = S$RescriptSchema.object(s => ({
45
+ chainId: s.f("chainId", S$RescriptSchema.bigint),
46
+ address: s.f("address", Address.schema),
47
+ nonce: s.f("nonce", S$RescriptSchema.int),
48
+ yParity: s.f("yParity", S$RescriptSchema.$$enum([
49
+ 0,
50
+ 1
51
+ ])),
52
+ r: s.f("r", S$RescriptSchema.string),
53
+ s: s.f("s", S$RescriptSchema.string)
54
+ }));
59
55
 
60
- var ResponseTypes = {
56
+ let ResponseTypes = {
61
57
  accessListSchema: accessListSchema,
62
58
  authorizationListSchema: authorizationListSchema
63
59
  };
64
60
 
65
- var HeightStream = {};
61
+ let HeightStream = {};
66
62
 
67
63
  function make(url, apiToken, httpReqTimeoutMillis, maxNumRetries, enableChecksumAddressesOpt, serializationFormat, enableQueryCaching, retryBaseMs, retryBackoffMs, retryCeilingMs) {
68
- var enableChecksumAddresses = enableChecksumAddressesOpt !== undefined ? enableChecksumAddressesOpt : true;
69
- var envioVersion = Utils.EnvioPackage.value.version;
64
+ let enableChecksumAddresses = enableChecksumAddressesOpt !== undefined ? enableChecksumAddressesOpt : true;
65
+ let envioVersion = Utils.EnvioPackage.value.version;
70
66
  return HypersyncClient.HypersyncClient.newWithAgent({
71
- url: url,
72
- apiToken: apiToken,
73
- httpReqTimeoutMillis: httpReqTimeoutMillis,
74
- maxNumRetries: maxNumRetries,
75
- retryBackoffMs: retryBackoffMs,
76
- retryBaseMs: retryBaseMs,
77
- retryCeilingMs: retryCeilingMs,
78
- enableChecksumAddresses: enableChecksumAddresses,
79
- serializationFormat: serializationFormat,
80
- enableQueryCaching: enableQueryCaching
81
- }, "hyperindex/" + envioVersion);
67
+ url: url,
68
+ apiToken: apiToken,
69
+ httpReqTimeoutMillis: httpReqTimeoutMillis,
70
+ maxNumRetries: maxNumRetries,
71
+ retryBackoffMs: retryBackoffMs,
72
+ retryBaseMs: retryBaseMs,
73
+ retryCeilingMs: retryCeilingMs,
74
+ enableChecksumAddresses: enableChecksumAddresses,
75
+ serializationFormat: serializationFormat,
76
+ enableQueryCaching: enableQueryCaching
77
+ }, `hyperindex/` + envioVersion);
82
78
  }
83
79
 
84
- var logLevelSchema = S$RescriptSchema.$$enum([
85
- "trace",
86
- "debug",
87
- "info",
88
- "warn",
89
- "error"
90
- ]);
80
+ let logLevelSchema = S$RescriptSchema.$$enum([
81
+ "trace",
82
+ "debug",
83
+ "info",
84
+ "warn",
85
+ "error"
86
+ ]);
91
87
 
92
88
  function toUnderlying(_d) {
93
- while(true) {
94
- var d = _d;
89
+ while (true) {
90
+ let d = _d;
95
91
  if (Array.isArray(d)) {
96
92
  return Belt_Array.map(d, toUnderlying);
97
93
  }
98
94
  switch (typeof d) {
99
95
  case "boolean" :
100
- return d;
96
+ return d;
101
97
  case "string" :
102
- return d;
98
+ return d;
103
99
  case "bigint" :
104
- return d;
100
+ return d;
105
101
  case "object" :
106
- _d = d.val;
107
- continue ;
108
-
102
+ _d = d.val;
103
+ continue;
109
104
  }
110
105
  };
111
106
  }
@@ -114,18 +109,18 @@ function fromSignatures(prim) {
114
109
  return HypersyncClient.Decoder.fromSignatures(prim);
115
110
  }
116
111
 
117
- var Decoder = {
112
+ let Decoder = {
118
113
  toUnderlying: toUnderlying,
119
114
  fromSignatures: fromSignatures
120
115
  };
121
116
 
122
117
  export {
123
- serializationFormatSchema ,
124
- QueryTypes ,
125
- ResponseTypes ,
126
- HeightStream ,
127
- make ,
128
- logLevelSchema ,
129
- Decoder ,
118
+ serializationFormatSchema,
119
+ QueryTypes,
120
+ ResponseTypes,
121
+ HeightStream,
122
+ make,
123
+ logLevelSchema,
124
+ Decoder,
130
125
  }
131
126
  /* serializationFormatSchema Not a pure module */
@@ -7,17 +7,17 @@ let subscribe = (~hyperSyncUrl, ~apiToken, ~chainId, ~onHeight: int => unit): (u
7
7
  let errorCount = ref(0)
8
8
  let baseDuration = 50
9
9
  // Timeout doesn't do anything for initialization
10
- let timeoutIdRef = ref(Js.Global.setTimeout(() => (), 0))
10
+ let timeoutIdRef = ref(setTimeout(() => (), 0))
11
11
 
12
12
  // On every successful ping or height event, clear the timeout and set a new one.
13
13
  // If the timeout lapses, close and reconnect the EventSource.
14
14
  let rec updateTimeoutId = () => {
15
- timeoutIdRef.contents->Js.Global.clearTimeout
15
+ timeoutIdRef.contents->clearTimeout
16
16
 
17
17
  // Should receive a ping at least every 5s, so 15s is a safe margin
18
18
  // for staleness to restart the EventSource connection
19
19
  let staleTimeMillis = 15_000
20
- let newTimeoutId = Js.Global.setTimeout(() => {
20
+ let newTimeoutId = setTimeout(() => {
21
21
  Logging.trace({
22
22
  "msg": "Timeout fired for height stream",
23
23
  "chainId": chainId,
@@ -34,11 +34,10 @@ let subscribe = (~hyperSyncUrl, ~apiToken, ~chainId, ~onHeight: int => unit): (u
34
34
  // and update the timeout.
35
35
  and scheduleReconnect = () => {
36
36
  // Clear any pending stale/reconnect timeout to avoid double reconnect
37
- timeoutIdRef.contents->Js.Global.clearTimeout
37
+ timeoutIdRef.contents->clearTimeout
38
38
  let delay =
39
- baseDuration *
40
- Js.Math.pow_float(~base=2.0, ~exp=errorCount.contents->Belt.Int.toFloat)->Belt.Float.toInt
41
- timeoutIdRef := Js.Global.setTimeout(() => refreshEventSource(), Pervasives.min(delay, 60_000))
39
+ baseDuration * Math.pow(2.0, ~exp=errorCount.contents->Belt.Int.toFloat)->Belt.Float.toInt
40
+ timeoutIdRef := setTimeout(() => refreshEventSource(), Pervasives.min(delay, 60_000))
42
41
  }
43
42
  and refreshEventSource = () => {
44
43
  // Close the old EventSource if it exists (on a new connection after timeout)
@@ -56,7 +55,7 @@ let subscribe = (~hyperSyncUrl, ~apiToken, ~chainId, ~onHeight: int => unit): (u
56
55
  url,
57
56
  ~args={
58
57
  ...args,
59
- headers: Js.Dict.fromArray([
58
+ headers: Dict.fromArray([
60
59
  ("Authorization", `Bearer ${apiToken}`),
61
60
  ("User-Agent", userAgent),
62
61
  ]),
@@ -128,7 +127,7 @@ let subscribe = (~hyperSyncUrl, ~apiToken, ~chainId, ~onHeight: int => unit): (u
128
127
 
129
128
  // Return unsubscribe function
130
129
  () => {
131
- timeoutIdRef.contents->Js.Global.clearTimeout
130
+ timeoutIdRef.contents->clearTimeout
132
131
  switch eventsourceRef.contents {
133
132
  | Some(es) => es->EventSource.close
134
133
  | None => ()
@@ -1,120 +1,112 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
3
  import * as Utils from "../Utils.res.mjs";
4
- import * as Js_dict from "rescript/lib/es6/js_dict.js";
5
4
  import * as Logging from "../Logging.res.mjs";
6
- import * as Belt_Int from "rescript/lib/es6/belt_Int.js";
7
- import * as Caml_obj from "rescript/lib/es6/caml_obj.js";
5
+ import * as Belt_Int from "@rescript/runtime/lib/es6/Belt_Int.js";
8
6
  import * as Prometheus from "../Prometheus.res.mjs";
9
- import * as Caml_option from "rescript/lib/es6/caml_option.js";
10
7
  import * as Eventsource from "eventsource";
8
+ import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js";
9
+ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
11
10
 
12
11
  function subscribe(hyperSyncUrl, apiToken, chainId, onHeight) {
13
- var eventsourceRef = {
12
+ let eventsourceRef = {
14
13
  contents: undefined
15
14
  };
16
- var errorCount = {
15
+ let errorCount = {
17
16
  contents: 0
18
17
  };
19
- var timeoutIdRef = {
20
- contents: setTimeout((function () {
21
-
22
- }), 0)
18
+ let timeoutIdRef = {
19
+ contents: setTimeout(() => {}, 0)
23
20
  };
24
- var updateTimeoutId = function () {
21
+ let updateTimeoutId = () => {
25
22
  clearTimeout(timeoutIdRef.contents);
26
- var newTimeoutId = setTimeout((function () {
27
- Logging.trace({
28
- msg: "Timeout fired for height stream",
29
- chainId: chainId,
30
- url: hyperSyncUrl,
31
- staleTimeMillis: 15000
32
- });
33
- refreshEventSource();
34
- }), 15000);
23
+ let newTimeoutId = setTimeout(() => {
24
+ Logging.trace({
25
+ msg: "Timeout fired for height stream",
26
+ chainId: chainId,
27
+ url: hyperSyncUrl,
28
+ staleTimeMillis: 15000
29
+ });
30
+ refreshEventSource();
31
+ }, 15000);
35
32
  timeoutIdRef.contents = newTimeoutId;
36
33
  };
37
- var scheduleReconnect = function () {
34
+ let scheduleReconnect = () => {
38
35
  clearTimeout(timeoutIdRef.contents);
39
- var delay = Math.imul(50, Math.pow(2.0, errorCount.contents) | 0);
40
- timeoutIdRef.contents = setTimeout((function () {
41
- refreshEventSource();
42
- }), delay < 60000 ? delay : 60000);
36
+ let delay = 50 * (Math.pow(2.0, errorCount.contents) | 0) | 0;
37
+ timeoutIdRef.contents = setTimeout(() => refreshEventSource(), Primitive_int.min(delay, 60000));
43
38
  };
44
- var refreshEventSource = function () {
45
- var es = eventsourceRef.contents;
39
+ let refreshEventSource = () => {
40
+ let es = eventsourceRef.contents;
46
41
  if (es !== undefined) {
47
- Caml_option.valFromOption(es).close();
42
+ Primitive_option.valFromOption(es).close();
48
43
  }
49
- var userAgent = "hyperindex/" + Utils.EnvioPackage.value.version;
50
- var es$1 = new Eventsource.EventSource(hyperSyncUrl + "/height/sse", {
51
- fetch: (function (url, args) {
52
- var newrecord = Caml_obj.obj_dup(args);
53
- return fetch(url, (newrecord.headers = Js_dict.fromArray([
54
- [
55
- "Authorization",
56
- "Bearer " + apiToken
57
- ],
58
- [
59
- "User-Agent",
60
- userAgent
61
- ]
62
- ]), newrecord));
63
- })
64
- });
65
- eventsourceRef.contents = Caml_option.some(es$1);
44
+ let userAgent = `hyperindex/` + Utils.EnvioPackage.value.version;
45
+ let es$1 = new Eventsource.EventSource(hyperSyncUrl + `/height/sse`, {
46
+ fetch: (url, args) => {
47
+ let newrecord = {...args};
48
+ return fetch(url, (newrecord.headers = Object.fromEntries([
49
+ [
50
+ "Authorization",
51
+ `Bearer ` + apiToken
52
+ ],
53
+ [
54
+ "User-Agent",
55
+ userAgent
56
+ ]
57
+ ]), newrecord));
58
+ }
59
+ });
60
+ eventsourceRef.contents = Primitive_option.some(es$1);
66
61
  updateTimeoutId();
67
- es$1.onopen = (function () {
68
- errorCount.contents = 0;
69
- Logging.trace({
70
- msg: "SSE connection opened for height stream",
71
- chainId: chainId,
72
- url: hyperSyncUrl
73
- });
62
+ es$1.onopen = () => {
63
+ errorCount.contents = 0;
64
+ Logging.trace({
65
+ msg: "SSE connection opened for height stream",
66
+ chainId: chainId,
67
+ url: hyperSyncUrl
74
68
  });
75
- es$1.onerror = (function (error) {
76
- errorCount.contents = errorCount.contents + 1 | 0;
77
- Logging.trace({
78
- msg: "EventSource error on height stream, reconnecting",
79
- chainId: chainId,
80
- url: hyperSyncUrl,
81
- status: error.status,
82
- error: error.message,
83
- errorCount: errorCount.contents
84
- });
85
- scheduleReconnect();
69
+ };
70
+ es$1.onerror = error => {
71
+ errorCount.contents = errorCount.contents + 1 | 0;
72
+ Logging.trace({
73
+ msg: "EventSource error on height stream, reconnecting",
74
+ chainId: chainId,
75
+ url: hyperSyncUrl,
76
+ status: error.status,
77
+ error: error.message,
78
+ errorCount: errorCount.contents
86
79
  });
87
- es$1.addEventListener("ping", (function (_event) {
88
- updateTimeoutId();
89
- }));
90
- es$1.addEventListener("height", (function ($$event) {
91
- var height = Belt_Int.fromString($$event.data);
92
- if (height !== undefined) {
93
- Prometheus.SourceRequestCount.increment("HyperSync", chainId, "heightStream");
94
- updateTimeoutId();
95
- return onHeight(height);
96
- } else {
97
- return Logging.trace({
98
- msg: "Height was not a number in event.data",
99
- chainId: chainId,
100
- data: $$event.data
101
- });
102
- }
103
- }));
80
+ scheduleReconnect();
81
+ };
82
+ es$1.addEventListener("ping", _event => updateTimeoutId());
83
+ es$1.addEventListener("height", event => {
84
+ let height = Belt_Int.fromString(event.data);
85
+ if (height !== undefined) {
86
+ Prometheus.SourceRequestCount.increment("HyperSync", chainId, "heightStream");
87
+ updateTimeoutId();
88
+ return onHeight(height);
89
+ } else {
90
+ return Logging.trace({
91
+ msg: "Height was not a number in event.data",
92
+ chainId: chainId,
93
+ data: event.data
94
+ });
95
+ }
96
+ });
104
97
  };
105
98
  refreshEventSource();
106
- return function () {
99
+ return () => {
107
100
  clearTimeout(timeoutIdRef.contents);
108
- var es = eventsourceRef.contents;
101
+ let es = eventsourceRef.contents;
109
102
  if (es !== undefined) {
110
- Caml_option.valFromOption(es).close();
111
- return ;
103
+ Primitive_option.valFromOption(es).close();
104
+ return;
112
105
  }
113
-
114
106
  };
115
107
  }
116
108
 
117
109
  export {
118
- subscribe ,
110
+ subscribe,
119
111
  }
120
112
  /* Utils Not a pure module */
@@ -231,15 +231,15 @@ module ResponseTypes = {
231
231
  stateRoot: ?s.field("state_root", S.option(S.string)),
232
232
  receiptsRoot: ?s.field("receipts_root", S.option(S.string)),
233
233
  miner: ?s.field("miner", S.option(S.string)),
234
- difficulty: ?s.field("difficulty", S.option(S.null(BigInt.schema))),
235
- totalDifficulty: ?s.field("total_difficulty", S.option(S.null(BigInt.schema))),
234
+ difficulty: ?s.field("difficulty", S.option(S.null(Utils.BigInt.schema))),
235
+ totalDifficulty: ?s.field("total_difficulty", S.option(S.null(Utils.BigInt.schema))),
236
236
  extraData: ?s.field("extra_data", S.option(S.string)),
237
- size: ?s.field("size", S.option(BigInt.schema)),
238
- gasLimit: ?s.field("gas_limit", S.option(BigInt.schema)),
239
- gasUsed: ?s.field("gas_used", S.option(BigInt.schema)),
240
- timestamp: ?s.field("timestamp", S.option(BigInt.schema)),
237
+ size: ?s.field("size", S.option(Utils.BigInt.schema)),
238
+ gasLimit: ?s.field("gas_limit", S.option(Utils.BigInt.schema)),
239
+ gasUsed: ?s.field("gas_used", S.option(Utils.BigInt.schema)),
240
+ timestamp: ?s.field("timestamp", S.option(Utils.BigInt.schema)),
241
241
  uncles: ?s.field("unclus", S.option(S.null(S.string))),
242
- baseFeePerGas: ?s.field("base_fee_per_gas", S.option(S.null(BigInt.schema))),
242
+ baseFeePerGas: ?s.field("base_fee_per_gas", S.option(S.null(Utils.BigInt.schema))),
243
243
  })
244
244
 
245
245
  type transactionData = {
@@ -275,23 +275,26 @@ module ResponseTypes = {
275
275
  blockHash: ?s.field("block_hash", S.option(S.string)),
276
276
  blockNumber: ?s.field("block_number", S.option(S.int)),
277
277
  from: ?s.field("from", S.option(S.null(S.string))),
278
- gas: ?s.field("gas", S.option(BigInt.schema)),
279
- gasPrice: ?s.field("gas_price", S.option(S.null(BigInt.schema))),
278
+ gas: ?s.field("gas", S.option(Utils.BigInt.schema)),
279
+ gasPrice: ?s.field("gas_price", S.option(S.null(Utils.BigInt.schema))),
280
280
  hash: ?s.field("hash", S.option(S.string)),
281
281
  input: ?s.field("input", S.option(S.string)),
282
282
  nonce: ?s.field("nonce", S.option(S.int)),
283
283
  to: ?s.field("to", S.option(S.null(S.string))),
284
284
  transactionIndex: ?s.field("transaction_index", S.option(S.int)),
285
- value: ?s.field("value", S.option(BigInt.schema)),
285
+ value: ?s.field("value", S.option(Utils.BigInt.schema)),
286
286
  v: ?s.field("v", S.option(S.null(S.string))),
287
287
  r: ?s.field("r", S.option(S.null(S.string))),
288
288
  s: ?s.field("s", S.option(S.null(S.string))),
289
- maxPriorityFeePerGas: ?s.field("max_priority_fee_per_gas", S.option(S.null(BigInt.schema))),
290
- maxFeePerGas: ?s.field("max_fee_per_gas", S.option(S.null(BigInt.schema))),
289
+ maxPriorityFeePerGas: ?s.field(
290
+ "max_priority_fee_per_gas",
291
+ S.option(S.null(Utils.BigInt.schema)),
292
+ ),
293
+ maxFeePerGas: ?s.field("max_fee_per_gas", S.option(S.null(Utils.BigInt.schema))),
291
294
  chainId: ?s.field("chain_id", S.option(S.null(S.int))),
292
- cumulativeGasUsed: ?s.field("cumulative_gas_used", S.option(BigInt.schema)),
293
- effectiveGasPrice: ?s.field("effective_gas_price", S.option(BigInt.schema)),
294
- gasUsed: ?s.field("gas_used", S.option(BigInt.schema)),
295
+ cumulativeGasUsed: ?s.field("cumulative_gas_used", S.option(Utils.BigInt.schema)),
296
+ effectiveGasPrice: ?s.field("effective_gas_price", S.option(Utils.BigInt.schema)),
297
+ gasUsed: ?s.field("gas_used", S.option(Utils.BigInt.schema)),
295
298
  contractAddress: ?s.field("contract_address", S.option(S.null(S.string))),
296
299
  logsBoom: ?s.field("logs_bloom", S.option(S.string)),
297
300
  type_: ?s.field("type", S.option(S.null(S.int))),