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
@@ -3,64 +3,62 @@
3
3
  import * as Rest from "../vendored/Rest.res.mjs";
4
4
  import * as Utils from "../Utils.res.mjs";
5
5
  import * as Hrtime from "../bindings/Hrtime.res.mjs";
6
- import * as Js_exn from "rescript/lib/es6/js_exn.js";
7
6
  import * as Source from "./Source.res.mjs";
8
7
  import * as Logging from "../Logging.res.mjs";
9
8
  import * as Internal from "../Internal.res.mjs";
10
9
  import * as HyperSync from "./HyperSync.res.mjs";
11
- import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
10
+ import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
12
11
  import * as Prometheus from "../Prometheus.res.mjs";
13
- import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
14
12
  import * as EventRouter from "./EventRouter.res.mjs";
15
13
  import * as LogSelection from "../LogSelection.res.mjs";
16
14
  import * as ErrorHandling from "../ErrorHandling.res.mjs";
17
- import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js";
15
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
16
+ import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
18
17
  import * as HyperSyncClient from "./HyperSyncClient.res.mjs";
19
- import * as Caml_splice_call from "rescript/lib/es6/caml_splice_call.js";
20
18
  import * as HyperSyncJsonApi from "./HyperSyncJsonApi.res.mjs";
21
- import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
19
+ import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
22
20
  import * as HyperSyncHeightStream from "./HyperSyncHeightStream.res.mjs";
23
21
 
24
22
  function getSelectionConfig(selection, chain) {
25
- var nonOptionalBlockFieldNames = new Set();
26
- var nonOptionalTransactionFieldNames = new Set();
27
- var capitalizedBlockFields = new Set();
28
- var capitalizedTransactionFields = new Set();
29
- var staticTopicSelectionsByContract = {};
30
- var dynamicEventFiltersByContract = {};
31
- var dynamicWildcardEventFiltersByContract = {};
32
- var noAddressesTopicSelections = [];
33
- var contractNames = new Set();
34
- Belt_Array.forEach(selection.eventConfigs, (function (param) {
35
- var contractName = param.contractName;
36
- Belt_Array.forEach(Array.from(param.selectedBlockFields), (function (name) {
37
- if (!Internal.evmNullableBlockFields.has(name)) {
38
- nonOptionalBlockFieldNames.add(name);
39
- }
40
- capitalizedBlockFields.add(Utils.$$String.capitalize(name));
41
- }));
42
- Belt_Array.forEach(Array.from(param.selectedTransactionFields), (function (name) {
43
- if (!Internal.evmNullableTransactionFields.has(name)) {
44
- nonOptionalTransactionFieldNames.add(name);
45
- }
46
- capitalizedTransactionFields.add(Utils.$$String.capitalize(name));
47
- }));
48
- var eventFilters = param.getEventFiltersOrThrow(chain);
49
- if (param.dependsOnAddresses) {
50
- contractNames.add(contractName);
51
- if (eventFilters.TAG === "Static") {
52
- return Utils.Dict.pushMany(staticTopicSelectionsByContract, contractName, eventFilters._0);
53
- } else {
54
- return Utils.Dict.push(param.isWildcard ? dynamicWildcardEventFiltersByContract : dynamicEventFiltersByContract, contractName, eventFilters._0);
55
- }
56
- }
57
- var tmp;
58
- tmp = eventFilters.TAG === "Static" ? eventFilters._0 : eventFilters._0([]);
59
- Caml_splice_call.spliceObjApply(noAddressesTopicSelections, "push", [tmp]);
60
- }));
61
- var fieldSelection_block = Array.from(capitalizedBlockFields);
62
- var fieldSelection_transaction = Array.from(capitalizedTransactionFields);
63
- var fieldSelection_log = [
23
+ let nonOptionalBlockFieldNames = new Set();
24
+ let nonOptionalTransactionFieldNames = new Set();
25
+ let capitalizedBlockFields = new Set();
26
+ let capitalizedTransactionFields = new Set();
27
+ let staticTopicSelectionsByContract = {};
28
+ let dynamicEventFiltersByContract = {};
29
+ let dynamicWildcardEventFiltersByContract = {};
30
+ let noAddressesTopicSelections = [];
31
+ let contractNames = new Set();
32
+ selection.eventConfigs.forEach(param => {
33
+ let contractName = param.contractName;
34
+ Array.from(param.selectedBlockFields).forEach(name => {
35
+ if (!Internal.evmNullableBlockFields.has(name)) {
36
+ nonOptionalBlockFieldNames.add(name);
37
+ }
38
+ capitalizedBlockFields.add(Utils.$$String.capitalize(name));
39
+ });
40
+ Array.from(param.selectedTransactionFields).forEach(name => {
41
+ if (!Internal.evmNullableTransactionFields.has(name)) {
42
+ nonOptionalTransactionFieldNames.add(name);
43
+ }
44
+ capitalizedTransactionFields.add(Utils.$$String.capitalize(name));
45
+ });
46
+ let eventFilters = param.getEventFiltersOrThrow(chain);
47
+ if (param.dependsOnAddresses) {
48
+ contractNames.add(contractName);
49
+ if (eventFilters.TAG === "Static") {
50
+ return Utils.Dict.pushMany(staticTopicSelectionsByContract, contractName, eventFilters._0);
51
+ } else {
52
+ return Utils.Dict.push(param.isWildcard ? dynamicWildcardEventFiltersByContract : dynamicEventFiltersByContract, contractName, eventFilters._0);
53
+ }
54
+ }
55
+ let tmp;
56
+ tmp = eventFilters.TAG === "Static" ? eventFilters._0 : eventFilters._0([]);
57
+ noAddressesTopicSelections.push(...tmp);
58
+ });
59
+ let fieldSelection_block = Array.from(capitalizedBlockFields);
60
+ let fieldSelection_transaction = Array.from(capitalizedTransactionFields);
61
+ let fieldSelection_log = [
64
62
  "Address",
65
63
  "Data",
66
64
  "LogIndex",
@@ -69,85 +67,79 @@ function getSelectionConfig(selection, chain) {
69
67
  "Topic2",
70
68
  "Topic3"
71
69
  ];
72
- var fieldSelection = {
70
+ let fieldSelection = {
73
71
  block: fieldSelection_block,
74
72
  transaction: fieldSelection_transaction,
75
73
  log: fieldSelection_log
76
74
  };
77
- var noAddressesLogSelection = LogSelection.make([], noAddressesTopicSelections);
78
- var getLogSelectionOrThrow = function (addressesByContractName) {
79
- var logSelections = [];
75
+ let noAddressesLogSelection = LogSelection.make([], noAddressesTopicSelections);
76
+ let getLogSelectionOrThrow = addressesByContractName => {
77
+ let logSelections = [];
80
78
  if (!Utils.$$Array.isEmpty(noAddressesLogSelection.topicSelections)) {
81
79
  logSelections.push(noAddressesLogSelection);
82
80
  }
83
- contractNames.forEach(function (contractName) {
84
- var addresses = addressesByContractName[contractName];
85
- if (addresses === undefined) {
86
- return ;
87
- }
88
- if (addresses.length === 0) {
89
- return ;
90
- }
91
- var topicSelections = staticTopicSelectionsByContract[contractName];
92
- if (topicSelections !== undefined) {
93
- logSelections.push(LogSelection.make(addresses, topicSelections));
94
- }
95
- var fns = dynamicEventFiltersByContract[contractName];
96
- if (fns !== undefined) {
97
- logSelections.push(LogSelection.make(addresses, Belt_Array.flatMapU(fns, (function (fn) {
98
- return fn(addresses);
99
- }))));
100
- }
101
- var fns$1 = dynamicWildcardEventFiltersByContract[contractName];
102
- if (fns$1 !== undefined) {
103
- logSelections.push(LogSelection.make([], Belt_Array.flatMapU(fns$1, (function (fn) {
104
- return fn(addresses);
105
- }))));
106
- return ;
107
- }
108
-
109
- });
81
+ contractNames.forEach(contractName => {
82
+ let addresses = addressesByContractName[contractName];
83
+ if (addresses === undefined) {
84
+ return;
85
+ }
86
+ if (addresses.length === 0) {
87
+ return;
88
+ }
89
+ let topicSelections = staticTopicSelectionsByContract[contractName];
90
+ if (topicSelections !== undefined) {
91
+ logSelections.push(LogSelection.make(addresses, topicSelections));
92
+ }
93
+ let fns = dynamicEventFiltersByContract[contractName];
94
+ if (fns !== undefined) {
95
+ logSelections.push(LogSelection.make(addresses, fns.flatMap(fn => fn(addresses))));
96
+ }
97
+ let fns$1 = dynamicWildcardEventFiltersByContract[contractName];
98
+ if (fns$1 !== undefined) {
99
+ logSelections.push(LogSelection.make([], fns$1.flatMap(fn => fn(addresses))));
100
+ return;
101
+ }
102
+ });
110
103
  return logSelections;
111
104
  };
112
105
  return {
113
- getLogSelectionOrThrow: getLogSelectionOrThrow,
114
- fieldSelection: fieldSelection,
115
- nonOptionalBlockFieldNames: Array.from(nonOptionalBlockFieldNames),
116
- nonOptionalTransactionFieldNames: Array.from(nonOptionalTransactionFieldNames)
117
- };
106
+ getLogSelectionOrThrow: getLogSelectionOrThrow,
107
+ fieldSelection: fieldSelection,
108
+ nonOptionalBlockFieldNames: Array.from(nonOptionalBlockFieldNames),
109
+ nonOptionalTransactionFieldNames: Array.from(nonOptionalTransactionFieldNames)
110
+ };
118
111
  }
119
112
 
120
113
  function memoGetSelectionConfig(chain) {
121
- return Utils.$$WeakMap.memoize(function (selection) {
122
- return getSelectionConfig(selection, chain);
123
- });
114
+ return Utils.$$WeakMap.memoize(selection => getSelectionConfig(selection, chain));
124
115
  }
125
116
 
126
117
  function make(param) {
127
- var lowercaseAddresses = param.lowercaseAddresses;
128
- var apiToken = param.apiToken;
129
- var eventRouter = param.eventRouter;
130
- var allEventSignatures = param.allEventSignatures;
131
- var endpointUrl = param.endpointUrl;
132
- var chain = param.chain;
133
- var name = "HyperSync";
134
- var getSelectionConfig = memoGetSelectionConfig(chain);
135
- var apiToken$1 = apiToken !== undefined ? apiToken : Js_exn.raiseError("An API token is required for using HyperSync as a data-source.\nSet the ENVIO_API_TOKEN environment variable in your .env file.\nLearn more or get a free API token at: https://envio.dev/app/api-tokens");
136
- var client = HyperSyncClient.make(endpointUrl, apiToken$1, param.clientTimeoutMillis, param.clientMaxRetries, !lowercaseAddresses, param.serializationFormat, param.enableQueryCaching, undefined, undefined, undefined);
137
- var hscDecoder = {
118
+ let lowercaseAddresses = param.lowercaseAddresses;
119
+ let apiToken = param.apiToken;
120
+ let eventRouter = param.eventRouter;
121
+ let allEventSignatures = param.allEventSignatures;
122
+ let endpointUrl = param.endpointUrl;
123
+ let chain = param.chain;
124
+ let name = "HyperSync";
125
+ let getSelectionConfig = memoGetSelectionConfig(chain);
126
+ let apiToken$1 = apiToken !== undefined ? apiToken : Stdlib_JsError.throwWithMessage(`An API token is required for using HyperSync as a data-source.
127
+ Set the ENVIO_API_TOKEN environment variable in your .env file.
128
+ Learn more or get a free API token at: https://envio.dev/app/api-tokens`);
129
+ let client = HyperSyncClient.make(endpointUrl, apiToken$1, param.clientTimeoutMillis, param.clientMaxRetries, !lowercaseAddresses, param.serializationFormat, param.enableQueryCaching, undefined, undefined, undefined);
130
+ let hscDecoder = {
138
131
  contents: undefined
139
132
  };
140
- var getHscDecoder = function () {
141
- var decoder = hscDecoder.contents;
133
+ let getHscDecoder = () => {
134
+ let decoder = hscDecoder.contents;
142
135
  if (decoder !== undefined) {
143
136
  return decoder;
144
137
  }
145
- var decoder$1;
138
+ let decoder$1;
146
139
  try {
147
140
  decoder$1 = HyperSyncClient.Decoder.fromSignatures(allEventSignatures);
148
- }
149
- catch (raw_exn){
150
- var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
141
+ } catch (raw_exn) {
142
+ let exn = Primitive_exceptions.internalToException(raw_exn);
151
143
  return ErrorHandling.mkLogAndRaise(undefined, "Failed to instantiate a decoder from hypersync client, please double check your ABI", exn);
152
144
  }
153
145
  if (lowercaseAddresses) {
@@ -157,115 +149,111 @@ function make(param) {
157
149
  }
158
150
  return decoder$1;
159
151
  };
160
- var UndefinedValue = /* @__PURE__ */Caml_exceptions.create("UndefinedValue");
161
- var makeEventBatchQueueItem = function (item, params, eventConfig) {
162
- var block = item.block;
163
- var log = item.log;
152
+ let UndefinedValue = /* @__PURE__ */Primitive_exceptions.create("UndefinedValue");
153
+ let makeEventBatchQueueItem = (item, params, eventConfig) => {
154
+ let block = item.block;
155
+ let log = item.log;
164
156
  return {
165
- kind: 0,
166
- eventConfig: eventConfig,
167
- timestamp: block.timestamp,
168
- chain: chain,
169
- blockNumber: block.number,
170
- logIndex: log.logIndex,
171
- event: {
172
- contractName: eventConfig.contractName,
173
- eventName: eventConfig.name,
174
- params: params,
175
- chainId: chain,
176
- srcAddress: log.address,
177
- logIndex: log.logIndex,
178
- transaction: item.transaction,
179
- block: block
180
- }
181
- };
182
- };
183
- var getItemsOrThrow = async function (fromBlock, toBlock, addressesByContractName, indexingContracts, knownHeight, param, selection, retry, logger) {
184
- var mkLogAndRaise = function (extra, extra$1) {
185
- return ErrorHandling.mkLogAndRaise(logger, extra, extra$1);
157
+ kind: 0,
158
+ eventConfig: eventConfig,
159
+ timestamp: block.timestamp,
160
+ chain: chain,
161
+ blockNumber: block.number,
162
+ logIndex: log.logIndex,
163
+ event: {
164
+ contractName: eventConfig.contractName,
165
+ eventName: eventConfig.name,
166
+ params: params,
167
+ chainId: chain,
168
+ srcAddress: log.address,
169
+ logIndex: log.logIndex,
170
+ transaction: item.transaction,
171
+ block: block
172
+ }
186
173
  };
187
- var totalTimeRef = Hrtime.makeTimer();
188
- var selectionConfig = getSelectionConfig(selection);
189
- var logSelections;
174
+ };
175
+ let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName, indexingAddresses, knownHeight, param, selection, retry, logger) => {
176
+ let mkLogAndRaise = (extra, extra$1) => ErrorHandling.mkLogAndRaise(logger, extra, extra$1);
177
+ let totalTimeRef = Hrtime.makeTimer();
178
+ let selectionConfig = getSelectionConfig(selection);
179
+ let logSelections;
190
180
  try {
191
181
  logSelections = selectionConfig.getLogSelectionOrThrow(addressesByContractName);
192
- }
193
- catch (raw_exn){
194
- var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
182
+ } catch (raw_exn) {
183
+ let exn = Primitive_exceptions.internalToException(raw_exn);
195
184
  logSelections = ErrorHandling.mkLogAndRaise(logger, "Failed getting log selection for the query", exn);
196
185
  }
197
- var startFetchingBatchTimeRef = Hrtime.makeTimer();
186
+ let startFetchingBatchTimeRef = Hrtime.makeTimer();
198
187
  Prometheus.SourceRequestCount.increment(name, chain, "getLogs");
199
- var pageUnsafe;
188
+ let pageUnsafe;
200
189
  try {
201
190
  pageUnsafe = await HyperSync.GetLogs.query(client, fromBlock, toBlock, logSelections, selectionConfig.fieldSelection, selectionConfig.nonOptionalBlockFieldNames, selectionConfig.nonOptionalTransactionFieldNames);
202
- }
203
- catch (raw_error){
204
- var error = Caml_js_exceptions.internalToOCamlException(raw_error);
191
+ } catch (raw_error) {
192
+ let error = Primitive_exceptions.internalToException(raw_error);
205
193
  if (error.RE_EXN_ID === HyperSync.GetLogs.$$Error) {
206
- var error$1 = error._1;
207
- var tmp;
194
+ let error$1 = error._1;
195
+ let tmp;
208
196
  if (typeof error$1 !== "object") {
209
- var backoffMillis = retry !== 0 ? Math.imul(500, retry) : 100;
197
+ let backoffMillis = retry !== 0 ? 500 * retry | 0 : 100;
210
198
  tmp = {
211
199
  TAG: "WithBackoff",
212
- message: "Block #" + String(fromBlock) + " not found in HyperSync. HyperSync has multiple instances and it's possible that they drift independently slightly from the head. Indexing should continue correctly after retrying the query in " + String(backoffMillis) + "ms.",
200
+ message: `Block #` + fromBlock.toString() + ` not found in HyperSync. HyperSync has multiple instances and it's possible that they drift independently slightly from the head. Indexing should continue correctly after retrying the query in ` + backoffMillis.toString() + `ms.`,
213
201
  backoffMillis: backoffMillis
214
202
  };
215
203
  } else {
216
204
  tmp = {
217
205
  TAG: "ImpossibleForTheQuery",
218
- message: "Source returned invalid data with missing required fields: " + error$1.missingParams.join(", ")
206
+ message: `Source returned invalid data with missing required fields: ` + error$1.missingParams.join(", ")
219
207
  };
220
208
  }
221
209
  throw {
222
- RE_EXN_ID: Source.GetItemsError,
223
- _1: {
224
- TAG: "FailedGettingItems",
225
- exn: null,
226
- attemptedToBlock: Belt_Option.getWithDefault(toBlock, knownHeight),
227
- retry: tmp
228
- },
229
- Error: new Error()
230
- };
210
+ RE_EXN_ID: Source.GetItemsError,
211
+ _1: {
212
+ TAG: "FailedGettingItems",
213
+ exn: null,
214
+ attemptedToBlock: Stdlib_Option.getOr(toBlock, knownHeight),
215
+ retry: tmp
216
+ },
217
+ Error: new Error()
218
+ };
231
219
  }
232
220
  throw {
233
- RE_EXN_ID: Source.GetItemsError,
234
- _1: {
235
- TAG: "FailedGettingItems",
236
- exn: error,
237
- attemptedToBlock: Belt_Option.getWithDefault(toBlock, knownHeight),
238
- retry: {
239
- TAG: "WithBackoff",
240
- message: "Unexpected issue while fetching events from HyperSync client. Attempt a retry.",
241
- backoffMillis: retry !== 0 ? Math.imul(1000, retry) : 500
242
- }
243
- },
244
- Error: new Error()
245
- };
221
+ RE_EXN_ID: Source.GetItemsError,
222
+ _1: {
223
+ TAG: "FailedGettingItems",
224
+ exn: error,
225
+ attemptedToBlock: Stdlib_Option.getOr(toBlock, knownHeight),
226
+ retry: {
227
+ TAG: "WithBackoff",
228
+ message: `Unexpected issue while fetching events from HyperSync client. Attempt a retry.`,
229
+ backoffMillis: retry !== 0 ? 1000 * retry | 0 : 500
230
+ }
231
+ },
232
+ Error: new Error()
233
+ };
246
234
  }
247
- var pageFetchTime = Hrtime.toSecondsFloat(Hrtime.timeSince(startFetchingBatchTimeRef));
248
- var knownHeight$1 = pageUnsafe.archiveHeight;
249
- var heighestBlockQueried = pageUnsafe.nextBlock - 1 | 0;
250
- var match = pageUnsafe.rollbackGuard;
251
- var lastBlockQueriedPromise;
235
+ let pageFetchTime = Hrtime.toSecondsFloat(Hrtime.timeSince(startFetchingBatchTimeRef));
236
+ let knownHeight$1 = pageUnsafe.archiveHeight;
237
+ let heighestBlockQueried = pageUnsafe.nextBlock - 1 | 0;
238
+ let match = pageUnsafe.rollbackGuard;
239
+ let lastBlockQueriedPromise;
252
240
  if (match !== undefined) {
253
241
  lastBlockQueriedPromise = Promise.resolve({
254
- blockHash: match.hash,
255
- blockNumber: match.blockNumber,
256
- blockTimestamp: match.timestamp
257
- });
242
+ blockHash: match.hash,
243
+ blockNumber: match.blockNumber,
244
+ blockTimestamp: match.timestamp
245
+ });
258
246
  } else {
259
- var match$1 = Belt_Array.get(pageUnsafe.items, pageUnsafe.items.length - 1 | 0);
260
- var exit = 0;
247
+ let match$1 = Belt_Array.get(pageUnsafe.items, pageUnsafe.items.length - 1 | 0);
248
+ let exit = 0;
261
249
  if (match$1 !== undefined) {
262
- var block = match$1.block;
250
+ let block = match$1.block;
263
251
  if (block.number === heighestBlockQueried) {
264
252
  lastBlockQueriedPromise = Promise.resolve({
265
- blockHash: block.hash,
266
- blockNumber: block.number,
267
- blockTimestamp: block.timestamp
268
- });
253
+ blockHash: block.hash,
254
+ blockNumber: block.number,
255
+ blockTimestamp: block.timestamp
256
+ });
269
257
  } else {
270
258
  exit = 1;
271
259
  }
@@ -273,135 +261,125 @@ function make(param) {
273
261
  exit = 1;
274
262
  }
275
263
  if (exit === 1) {
276
- lastBlockQueriedPromise = HyperSync.queryBlockData(client, heighestBlockQueried, name, chain, logger).then(function (res) {
277
- if (res.TAG !== "Ok") {
278
- return mkLogAndRaise("Failed to query blockData for block " + String(heighestBlockQueried), HyperSync.queryErrorToMsq(res._0));
279
- }
280
- var blockData = res._0;
281
- if (blockData !== undefined) {
282
- return blockData;
283
- } else {
284
- return mkLogAndRaise("Failure, blockData for block " + String(heighestBlockQueried) + " unexpectedly returned None", {
285
- RE_EXN_ID: "Not_found"
286
- });
287
- }
264
+ lastBlockQueriedPromise = HyperSync.queryBlockData(client, heighestBlockQueried, name, chain, logger).then(res => {
265
+ if (res.TAG !== "Ok") {
266
+ return mkLogAndRaise(`Failed to query blockData for block ` + heighestBlockQueried.toString(), HyperSync.queryErrorToMsq(res._0));
267
+ }
268
+ let blockData = res._0;
269
+ if (blockData !== undefined) {
270
+ return blockData;
271
+ } else {
272
+ return mkLogAndRaise(`Failure, blockData for block ` + heighestBlockQueried.toString() + ` unexpectedly returned None`, {
273
+ RE_EXN_ID: "Not_found"
288
274
  });
275
+ }
276
+ });
289
277
  }
290
-
291
278
  }
292
- var parsingTimeRef = Hrtime.makeTimer();
293
- var parsedQueueItems = [];
294
- var parsedEvents;
279
+ let parsingTimeRef = Hrtime.makeTimer();
280
+ let parsedQueueItems = [];
281
+ let parsedEvents;
295
282
  try {
296
283
  parsedEvents = await getHscDecoder().decodeEvents(pageUnsafe.events);
297
- }
298
- catch (raw_exn$1){
299
- var exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1);
284
+ } catch (raw_exn$1) {
285
+ let exn$1 = Primitive_exceptions.internalToException(raw_exn$1);
300
286
  parsedEvents = mkLogAndRaise("Failed to parse events using hypersync client, please double check your ABI.", exn$1);
301
287
  }
302
- Belt_Array.forEachWithIndex(pageUnsafe.items, (function (index, item) {
303
- var block = item.block;
304
- var log = item.log;
305
- var topic0 = Utils.$$Array.firstUnsafe(log.topics);
306
- var maybeEventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(topic0, log.topics.length), log.address, block.number, indexingContracts);
307
- var maybeDecodedEvent = parsedEvents[index];
308
- if (maybeEventConfig === undefined) {
309
- return ;
310
- }
311
- if (maybeDecodedEvent === null || maybeDecodedEvent === undefined) {
312
- maybeDecodedEvent === null;
313
- } else {
314
- parsedQueueItems.push(makeEventBatchQueueItem(item, maybeEventConfig.convertHyperSyncEventArgs(maybeDecodedEvent), maybeEventConfig));
315
- return ;
316
- }
317
- var logIndex = log.logIndex;
318
- var blockNumber = block.number;
319
- var exn = {
320
- RE_EXN_ID: UndefinedValue
321
- };
322
- if (maybeEventConfig.isWildcard) {
323
- return ;
324
- }
325
- var msg = "Event " + maybeEventConfig.name + " was unexpectedly parsed as undefined";
326
- var logger$1 = Logging.createChildFrom(logger, {
327
- chainId: chain,
328
- blockNumber: blockNumber,
329
- logIndex: logIndex,
330
- decoder: "hypersync-client"
331
- });
332
- ErrorHandling.mkLogAndRaise(logger$1, msg, exn);
333
- }));
334
- var parsingTimeElapsed = Hrtime.toSecondsFloat(Hrtime.timeSince(parsingTimeRef));
335
- var rangeLastBlock = await lastBlockQueriedPromise;
336
- var reorgGuard_prevRangeLastBlock = Belt_Option.map(pageUnsafe.rollbackGuard, (function (v) {
337
- return {
338
- blockHash: v.firstParentHash,
339
- blockNumber: v.firstBlockNumber - 1 | 0
340
- };
341
- }));
342
- var reorgGuard = {
288
+ Belt_Array.forEachWithIndex(pageUnsafe.items, (index, item) => {
289
+ let block = item.block;
290
+ let log = item.log;
291
+ let topic0 = Utils.$$Array.firstUnsafe(log.topics);
292
+ let maybeEventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(topic0, log.topics.length), log.address, block.number, indexingAddresses);
293
+ let maybeDecodedEvent = parsedEvents[index];
294
+ if (maybeEventConfig === undefined) {
295
+ return;
296
+ }
297
+ if (maybeDecodedEvent == null) {
298
+ maybeDecodedEvent === null;
299
+ } else {
300
+ parsedQueueItems.push(makeEventBatchQueueItem(item, maybeEventConfig.convertHyperSyncEventArgs(maybeDecodedEvent), maybeEventConfig));
301
+ return;
302
+ }
303
+ let logIndex = log.logIndex;
304
+ let blockNumber = block.number;
305
+ let exn = {
306
+ RE_EXN_ID: UndefinedValue
307
+ };
308
+ if (maybeEventConfig.isWildcard) {
309
+ return;
310
+ }
311
+ let msg = `Event ` + maybeEventConfig.name + ` was unexpectedly parsed as undefined`;
312
+ let logger$1 = Logging.createChildFrom(logger, {
313
+ chainId: chain,
314
+ blockNumber: blockNumber,
315
+ logIndex: logIndex,
316
+ decoder: "hypersync-client"
317
+ });
318
+ ErrorHandling.mkLogAndRaise(logger$1, msg, exn);
319
+ });
320
+ let parsingTimeElapsed = Hrtime.toSecondsFloat(Hrtime.timeSince(parsingTimeRef));
321
+ let rangeLastBlock = await lastBlockQueriedPromise;
322
+ let reorgGuard_prevRangeLastBlock = Stdlib_Option.map(pageUnsafe.rollbackGuard, v => ({
323
+ blockHash: v.firstParentHash,
324
+ blockNumber: v.firstBlockNumber - 1 | 0
325
+ }));
326
+ let reorgGuard = {
343
327
  rangeLastBlock: rangeLastBlock,
344
328
  prevRangeLastBlock: reorgGuard_prevRangeLastBlock
345
329
  };
346
- var totalTimeElapsed = Hrtime.toSecondsFloat(Hrtime.timeSince(totalTimeRef));
347
- var stats_parsing$unknowntime$unknown$lpars$rpar = parsingTimeElapsed;
348
- var stats_page$unknownfetch$unknowntime$unknown$lpars$rpar = pageFetchTime;
349
- var stats = {
330
+ let totalTimeElapsed = Hrtime.toSecondsFloat(Hrtime.timeSince(totalTimeRef));
331
+ let stats_parsing$unknowntime$unknown$lpars$rpar = parsingTimeElapsed;
332
+ let stats_page$unknownfetch$unknowntime$unknown$lpars$rpar = pageFetchTime;
333
+ let stats = {
350
334
  "total time elapsed (s)": totalTimeElapsed,
351
335
  "parsing time (s)": stats_parsing$unknowntime$unknown$lpars$rpar,
352
336
  "page fetch time (s)": stats_page$unknownfetch$unknowntime$unknown$lpars$rpar
353
337
  };
354
338
  return {
355
- knownHeight: knownHeight$1,
356
- reorgGuard: reorgGuard,
357
- parsedQueueItems: parsedQueueItems,
358
- fromBlockQueried: fromBlock,
359
- latestFetchedBlockNumber: rangeLastBlock.blockNumber,
360
- latestFetchedBlockTimestamp: rangeLastBlock.blockTimestamp,
361
- stats: stats
362
- };
363
- };
364
- var getBlockHashes = function (blockNumbers, logger) {
365
- return HyperSync.queryBlockDataMulti(client, blockNumbers, name, chain, logger).then(HyperSync.mapExn);
339
+ knownHeight: knownHeight$1,
340
+ reorgGuard: reorgGuard,
341
+ parsedQueueItems: parsedQueueItems,
342
+ fromBlockQueried: fromBlock,
343
+ latestFetchedBlockNumber: rangeLastBlock.blockNumber,
344
+ latestFetchedBlockTimestamp: rangeLastBlock.blockTimestamp,
345
+ stats: stats
346
+ };
366
347
  };
367
- var jsonApiClient = Rest.client(endpointUrl, undefined);
348
+ let getBlockHashes = (blockNumbers, logger) => HyperSync.queryBlockDataMulti(client, blockNumbers, name, chain, logger).then(HyperSync.mapExn);
349
+ let jsonApiClient = Rest.client(endpointUrl, undefined);
368
350
  return {
369
- name: name,
370
- sourceFor: "Sync",
371
- chain: chain,
372
- poweredByHyperSync: true,
373
- pollingInterval: 100,
374
- getBlockHashes: getBlockHashes,
375
- getHeightOrThrow: (async function () {
376
- var timerRef = Hrtime.makeTimer();
377
- var height = await Rest.$$fetch(HyperSyncJsonApi.heightRoute, apiToken$1, jsonApiClient);
378
- var result;
379
- if (typeof height === "number") {
380
- result = height;
381
- } else if (height === "Your token is malformed. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens.") {
382
- Logging.error("Your ENVIO_API_TOKEN is malformed. The indexer will not be able to fetch events. Update the token and restart the indexer using 'pnpm envio start'. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens");
383
- await new Promise((function (param, param$1) {
384
-
385
- }));
386
- result = 0;
387
- } else {
388
- result = Js_exn.raiseError(height);
389
- }
390
- var seconds = Hrtime.toSecondsFloat(Hrtime.timeSince(timerRef));
391
- Prometheus.SourceRequestCount.increment(name, chain, "getHeight");
392
- Prometheus.SourceRequestCount.addSeconds(name, chain, "getHeight", seconds);
393
- return result;
394
- }),
395
- getItemsOrThrow: getItemsOrThrow,
396
- createHeightSubscription: (function (onHeight) {
397
- return HyperSyncHeightStream.subscribe(endpointUrl, apiToken$1, chain, onHeight);
398
- })
399
- };
351
+ name: name,
352
+ sourceFor: "Sync",
353
+ chain: chain,
354
+ poweredByHyperSync: true,
355
+ pollingInterval: 100,
356
+ getBlockHashes: getBlockHashes,
357
+ getHeightOrThrow: async () => {
358
+ let timerRef = Hrtime.makeTimer();
359
+ let height = await Rest.fetch(HyperSyncJsonApi.heightRoute, apiToken$1, jsonApiClient);
360
+ let result;
361
+ if (typeof height === "number") {
362
+ result = height;
363
+ } else if (height === `Your token is malformed. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens.`) {
364
+ Logging.error(`Your ENVIO_API_TOKEN is malformed. The indexer will not be able to fetch events. Update the token and restart the indexer using 'pnpm envio start'. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens`);
365
+ await new Promise((param, param$1) => {});
366
+ result = 0;
367
+ } else {
368
+ result = Stdlib_JsError.throwWithMessage(height);
369
+ }
370
+ let seconds = Hrtime.toSecondsFloat(Hrtime.timeSince(timerRef));
371
+ Prometheus.SourceRequestCount.increment(name, chain, "getHeight");
372
+ Prometheus.SourceRequestCount.addSeconds(name, chain, "getHeight", seconds);
373
+ return result;
374
+ },
375
+ getItemsOrThrow: getItemsOrThrow,
376
+ createHeightSubscription: onHeight => HyperSyncHeightStream.subscribe(endpointUrl, apiToken$1, chain, onHeight)
377
+ };
400
378
  }
401
379
 
402
380
  export {
403
- getSelectionConfig ,
404
- memoGetSelectionConfig ,
405
- make ,
381
+ getSelectionConfig,
382
+ memoGetSelectionConfig,
383
+ make,
406
384
  }
407
385
  /* Rest Not a pure module */