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
@@ -5,348 +5,335 @@ import * as Main from "./Main.res.mjs";
5
5
  import * as Table from "./db/Table.res.mjs";
6
6
  import * as Utils from "./Utils.res.mjs";
7
7
  import * as Config from "./Config.res.mjs";
8
- import * as Js_exn from "rescript/lib/es6/js_exn.js";
9
- import * as Js_dict from "rescript/lib/es6/js_dict.js";
10
8
  import * as Logging from "./Logging.res.mjs";
11
- import * as $$Promise from "./bindings/Promise.res.mjs";
12
9
  import * as Process from "process";
13
- import * as Belt_Int from "rescript/lib/es6/belt_Int.js";
14
10
  import * as ChainMap from "./ChainMap.res.mjs";
15
- import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
16
- import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
17
- import * as Caml_option from "rescript/lib/es6/caml_option.js";
11
+ import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.js";
18
12
  import * as Persistence from "./Persistence.res.mjs";
13
+ import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
19
14
  import * as TableIndices from "./TableIndices.res.mjs";
20
15
  import * as InternalTable from "./db/InternalTable.res.mjs";
16
+ import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js";
21
17
  import * as SimulateItems from "./SimulateItems.res.mjs";
18
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
19
+ import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
20
+ import * as Stdlib_Promise from "@rescript/runtime/lib/es6/Stdlib_Promise.js";
22
21
  import * as Worker_threads from "worker_threads";
22
+ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
23
23
  import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
24
- import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
24
+ import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
25
25
  import * as TestIndexerProxyStorage from "./TestIndexerProxyStorage.res.mjs";
26
26
 
27
- function toIndexingContract(dc) {
27
+ function toIndexingAddress(dc) {
28
28
  return {
29
- address: dc.contract_address,
30
- contractName: dc.contract_name,
31
- startBlock: dc.registering_event_block_number,
32
- registrationBlock: dc.registering_event_block_number
33
- };
29
+ address: Config.EnvioAddresses.getAddress(dc),
30
+ contractName: dc.contract_name,
31
+ registrationBlock: dc.registration_block
32
+ };
34
33
  }
35
34
 
36
35
  function handleLoadByIds(state, tableName, ids) {
37
- var entityDict = Belt_Option.getWithDefault(Js_dict.get(state.entities, tableName), {});
38
- var entityConfig = state.entityConfigs[tableName];
39
- var results = [];
40
- Belt_Array.forEach(ids, (function (id) {
41
- var entity = Js_dict.get(entityDict, id);
42
- if (entity === undefined) {
43
- return ;
44
- }
45
- var jsonEntity = S$RescriptSchema.reverseConvertToJsonOrThrow(entity, entityConfig.schema);
46
- results.push(jsonEntity);
47
- }));
36
+ let entityDict = Stdlib_Option.getOr(state.entities[tableName], {});
37
+ let entityConfig = state.entityConfigs[tableName];
38
+ let results = [];
39
+ ids.forEach(id => {
40
+ let entity = entityDict[id];
41
+ if (entity === undefined) {
42
+ return;
43
+ }
44
+ let jsonEntity = S$RescriptSchema.reverseConvertToJsonOrThrow(entity, entityConfig.schema);
45
+ results.push(jsonEntity);
46
+ });
48
47
  return results;
49
48
  }
50
49
 
51
50
  function handleLoadByField(state, tableName, fieldName, fieldValue, operator) {
52
- var entityDict = Belt_Option.getWithDefault(Js_dict.get(state.entities, tableName), {});
53
- var entityConfig = state.entityConfigs[tableName];
54
- var results = [];
55
- var match = Table.getFieldByName(entityConfig.table, fieldName);
56
- var fieldSchema;
57
- var exit = 0;
51
+ let entityDict = Stdlib_Option.getOr(state.entities[tableName], {});
52
+ let entityConfig = state.entityConfigs[tableName];
53
+ let results = [];
54
+ let match = Table.getFieldByName(entityConfig.table, fieldName);
55
+ let fieldSchema;
56
+ let exit = 0;
58
57
  if (match !== undefined && match.TAG === "Field") {
59
58
  fieldSchema = match._0.fieldSchema;
60
59
  } else {
61
60
  exit = 1;
62
61
  }
63
62
  if (exit === 1) {
64
- fieldSchema = Js_exn.raiseError("Field " + fieldName + " not found in entity " + tableName);
63
+ fieldSchema = Stdlib_JsError.throwWithMessage(`Field ` + fieldName + ` not found in entity ` + tableName);
65
64
  }
66
- var parsedFieldValue = S$RescriptSchema.convertOrThrow(fieldValue, fieldSchema);
67
- Belt_Array.forEach(Js_dict.values(entityDict), (function (entity) {
68
- var entityFieldValue = Js_dict.get(entity, fieldName);
69
- if (entityFieldValue === undefined) {
70
- return ;
71
- }
72
- var entityFieldValue$1 = Caml_option.valFromOption(entityFieldValue);
73
- var matches = operator === "=" ? TableIndices.FieldValue.eq(entityFieldValue$1, parsedFieldValue) : (
74
- operator === ">" ? TableIndices.FieldValue.gt(entityFieldValue$1, parsedFieldValue) : TableIndices.FieldValue.lt(entityFieldValue$1, parsedFieldValue)
75
- );
76
- if (!matches) {
77
- return ;
78
- }
79
- var jsonEntity = S$RescriptSchema.reverseConvertToJsonOrThrow(entity, entityConfig.schema);
80
- results.push(jsonEntity);
81
- }));
65
+ let parsedFieldValue = S$RescriptSchema.convertOrThrow(fieldValue, fieldSchema);
66
+ Object.values(entityDict).forEach(entity => {
67
+ let entityFieldValue = entity[fieldName];
68
+ if (entityFieldValue === undefined) {
69
+ return;
70
+ }
71
+ let entityFieldValue$1 = Primitive_option.valFromOption(entityFieldValue);
72
+ let matches = operator === "=" ? TableIndices.FieldValue.eq(entityFieldValue$1, parsedFieldValue) : (
73
+ operator === ">" ? TableIndices.FieldValue.gt(entityFieldValue$1, parsedFieldValue) : TableIndices.FieldValue.lt(entityFieldValue$1, parsedFieldValue)
74
+ );
75
+ if (!matches) {
76
+ return;
77
+ }
78
+ let jsonEntity = S$RescriptSchema.reverseConvertToJsonOrThrow(entity, entityConfig.schema);
79
+ results.push(jsonEntity);
80
+ });
82
81
  return results;
83
82
  }
84
83
 
85
84
  function handleWriteBatch(state, updatedEntities, checkpointIds, checkpointChainIds, checkpointBlockNumbers, checkpointEventsProcessed) {
86
- var changesByCheckpoint = {};
87
- Belt_Array.forEach(updatedEntities, (function (param) {
88
- var entityName = param.entityName;
89
- var dict = Js_dict.get(state.entities, entityName);
90
- var entityDict;
91
- if (dict !== undefined) {
92
- entityDict = dict;
85
+ let changesByCheckpoint = {};
86
+ updatedEntities.forEach(param => {
87
+ let entityName = param.entityName;
88
+ let dict = state.entities[entityName];
89
+ let entityDict;
90
+ if (dict !== undefined) {
91
+ entityDict = dict;
92
+ } else {
93
+ let dict$1 = {};
94
+ state.entities[entityName] = dict$1;
95
+ entityDict = dict$1;
96
+ }
97
+ let entityConfig = state.entityConfigs[entityName];
98
+ param.updates.forEach(update => {
99
+ let processChange = change => {
100
+ if (change.type === "SET") {
101
+ let parsedEntity = S$RescriptSchema.parseOrThrow(change.entity, entityConfig.schema);
102
+ entityDict[change.entityId] = parsedEntity;
103
+ let checkpointKey = change.checkpointId.toString();
104
+ let changes = changesByCheckpoint[checkpointKey];
105
+ let entityChanges;
106
+ if (changes !== undefined) {
107
+ entityChanges = changes;
93
108
  } else {
94
- var dict$1 = {};
95
- state.entities[entityName] = dict$1;
96
- entityDict = dict$1;
109
+ let changes$1 = {};
110
+ changesByCheckpoint[checkpointKey] = changes$1;
111
+ entityChanges = changes$1;
97
112
  }
98
- var entityConfig = state.entityConfigs[entityName];
99
- Belt_Array.forEach(param.updates, (function (update) {
100
- var processChange = function (change) {
101
- if (change.type === "SET") {
102
- var parsedEntity = S$RescriptSchema.parseOrThrow(change.entity, entityConfig.schema);
103
- entityDict[change.entityId] = parsedEntity;
104
- var checkpointKey = change.checkpointId.toString();
105
- var changes = Js_dict.get(changesByCheckpoint, checkpointKey);
106
- var entityChanges;
107
- if (changes !== undefined) {
108
- entityChanges = changes;
109
- } else {
110
- var changes$1 = {};
111
- changesByCheckpoint[checkpointKey] = changes$1;
112
- entityChanges = changes$1;
113
- }
114
- var change$1 = Js_dict.get(entityChanges, entityName);
115
- var entityChange;
116
- if (change$1 !== undefined) {
117
- entityChange = change$1;
118
- } else {
119
- var change_sets = [];
120
- var change_deleted = [];
121
- var change$2 = {
122
- sets: change_sets,
123
- deleted: change_deleted
124
- };
125
- entityChanges[entityName] = change$2;
126
- entityChange = change$2;
127
- }
128
- entityChange.sets.push(parsedEntity);
129
- return ;
130
- }
131
- var entityId = change.entityId;
132
- Js_dict.unsafeDeleteKey(entityDict, entityId);
133
- var checkpointKey$1 = change.checkpointId.toString();
134
- var changes$2 = Js_dict.get(changesByCheckpoint, checkpointKey$1);
135
- var entityChanges$1;
136
- if (changes$2 !== undefined) {
137
- entityChanges$1 = changes$2;
138
- } else {
139
- var changes$3 = {};
140
- changesByCheckpoint[checkpointKey$1] = changes$3;
141
- entityChanges$1 = changes$3;
142
- }
143
- var change$3 = Js_dict.get(entityChanges$1, entityName);
144
- var entityChange$1;
145
- if (change$3 !== undefined) {
146
- entityChange$1 = change$3;
147
- } else {
148
- var change_sets$1 = [];
149
- var change_deleted$1 = [];
150
- var change$4 = {
151
- sets: change_sets$1,
152
- deleted: change_deleted$1
153
- };
154
- entityChanges$1[entityName] = change$4;
155
- entityChange$1 = change$4;
156
- }
157
- entityChange$1.deleted.push(entityId);
158
- };
159
- Belt_Array.forEach(update.history, processChange);
160
- if (update.history.length === 0) {
161
- return processChange(update.latestChange);
162
- }
163
-
164
- }));
165
- }));
166
- for(var i = 0 ,i_finish = checkpointIds.length; i < i_finish; ++i){
167
- var checkpointId = checkpointIds[i];
168
- var change = {};
169
- state.progressBlockByChain[String(checkpointChainIds[i])] = checkpointBlockNumbers[i];
113
+ let change$1 = entityChanges[entityName];
114
+ let entityChange;
115
+ if (change$1 !== undefined) {
116
+ entityChange = change$1;
117
+ } else {
118
+ let change_sets = [];
119
+ let change_deleted = [];
120
+ let change$2 = {
121
+ sets: change_sets,
122
+ deleted: change_deleted
123
+ };
124
+ entityChanges[entityName] = change$2;
125
+ entityChange = change$2;
126
+ }
127
+ entityChange.sets.push(parsedEntity);
128
+ return;
129
+ }
130
+ let entityId = change.entityId;
131
+ Stdlib_Dict.$$delete(entityDict, entityId);
132
+ let checkpointKey$1 = change.checkpointId.toString();
133
+ let changes$2 = changesByCheckpoint[checkpointKey$1];
134
+ let entityChanges$1;
135
+ if (changes$2 !== undefined) {
136
+ entityChanges$1 = changes$2;
137
+ } else {
138
+ let changes$3 = {};
139
+ changesByCheckpoint[checkpointKey$1] = changes$3;
140
+ entityChanges$1 = changes$3;
141
+ }
142
+ let change$3 = entityChanges$1[entityName];
143
+ let entityChange$1;
144
+ if (change$3 !== undefined) {
145
+ entityChange$1 = change$3;
146
+ } else {
147
+ let change_sets$1 = [];
148
+ let change_deleted$1 = [];
149
+ let change$4 = {
150
+ sets: change_sets$1,
151
+ deleted: change_deleted$1
152
+ };
153
+ entityChanges$1[entityName] = change$4;
154
+ entityChange$1 = change$4;
155
+ }
156
+ entityChange$1.deleted.push(entityId);
157
+ };
158
+ update.history.forEach(processChange);
159
+ if (update.history.length === 0) {
160
+ return processChange(update.latestChange);
161
+ }
162
+ });
163
+ });
164
+ for (let i = 0, i_finish = checkpointIds.length; i < i_finish; ++i) {
165
+ let checkpointId = checkpointIds[i];
166
+ let change = {};
167
+ state.progressBlockByChain[checkpointChainIds[i].toString()] = checkpointBlockNumbers[i];
170
168
  change["block"] = checkpointBlockNumbers[i];
171
169
  change["chainId"] = checkpointChainIds[i];
172
170
  change["eventsProcessed"] = checkpointEventsProcessed[i];
173
- var checkpointKey = checkpointId.toString();
174
- var entityChanges = Js_dict.get(changesByCheckpoint, checkpointKey);
171
+ let checkpointKey = checkpointId.toString();
172
+ let entityChanges = changesByCheckpoint[checkpointKey];
175
173
  if (entityChanges !== undefined) {
176
- Belt_Array.forEach(Js_dict.entries(entityChanges), (function(change){
177
- return function (param) {
178
- var match = param[1];
179
- var deleted = match.deleted;
180
- var sets = match.sets;
181
- var entityName = param[0];
182
- if (entityName === Config.DynamicContractRegistry.name) {
183
- var entityObj = {};
184
- if (sets.length !== 0) {
185
- var simplifiedSets = Belt_Array.map(sets, (function (entity) {
186
- return {
187
- address: entity.contract_address,
188
- contract: entity.contract_name
189
- };
190
- }));
191
- entityObj["sets"] = simplifiedSets;
192
- }
193
- change["addresses"] = entityObj;
194
- return ;
195
- }
196
- var entityObj$1 = {};
197
- if (sets.length !== 0) {
198
- entityObj$1["sets"] = sets;
199
- }
200
- if (deleted.length !== 0) {
201
- entityObj$1["deleted"] = deleted;
202
- }
203
- change[entityName] = entityObj$1;
174
+ Object.entries(entityChanges).forEach(param => {
175
+ let match = param[1];
176
+ let deleted = match.deleted;
177
+ let sets = match.sets;
178
+ let entityName = param[0];
179
+ if (entityName === Config.EnvioAddresses.name) {
180
+ let entityObj = {};
181
+ if (sets.length !== 0) {
182
+ let simplifiedSets = sets.map(entity => ({
183
+ address: Config.EnvioAddresses.getAddress(entity),
184
+ contract: entity.contract_name
185
+ }));
186
+ entityObj["sets"] = simplifiedSets;
204
187
  }
205
- }(change)));
188
+ change["addresses"] = entityObj;
189
+ return;
190
+ }
191
+ let entityObj$1 = {};
192
+ if (sets.length !== 0) {
193
+ entityObj$1["sets"] = sets;
194
+ }
195
+ if (deleted.length !== 0) {
196
+ entityObj$1["deleted"] = deleted;
197
+ }
198
+ change[entityName] = entityObj$1;
199
+ });
206
200
  }
207
201
  state.processChanges.push(change);
208
202
  }
209
203
  }
210
204
 
211
- function makeInitialState(config, processConfigChains, dynamicContractsByChain) {
212
- var chainKeys = Object.keys(processConfigChains);
213
- var chains = Belt_Array.map(chainKeys, (function (chainIdStr) {
214
- var chainId = Belt_Option.getWithDefault(Belt_Int.fromString(chainIdStr), 0);
215
- var chain = ChainMap.Chain.makeUnsafe(chainId);
216
- if (!ChainMap.has(config.chainMap, chain)) {
217
- Js_exn.raiseError("Chain " + chainIdStr + " is not configured in config.yaml");
218
- }
219
- var processChainConfig = processConfigChains[chainIdStr];
220
- var dynamicContracts = Belt_Option.getWithDefault(Js_dict.get(dynamicContractsByChain, chainIdStr), []);
221
- return {
222
- id: chainId,
223
- startBlock: processChainConfig.startBlock,
224
- endBlock: processChainConfig.endBlock,
225
- maxReorgDepth: 0,
226
- progressBlockNumber: -1,
227
- numEventsProcessed: 0,
228
- firstEventBlockNumber: undefined,
229
- timestampCaughtUpToHeadOrEndblock: undefined,
230
- dynamicContracts: dynamicContracts,
231
- sourceBlockNumber: Belt_Option.getWithDefault(processChainConfig.endBlock, 0)
232
- };
233
- }));
205
+ function makeInitialState(config, processConfigChains, indexingAddressesByChain) {
206
+ let chainKeys = Object.keys(processConfigChains);
207
+ let chains = chainKeys.map(chainIdStr => {
208
+ let chainId = Stdlib_Option.getOr(Stdlib_Int.fromString(chainIdStr, undefined), 0);
209
+ let chain = ChainMap.Chain.makeUnsafe(chainId);
210
+ if (!ChainMap.has(config.chainMap, chain)) {
211
+ Stdlib_JsError.throwWithMessage(`Chain ` + chainIdStr + ` is not configured in config.yaml`);
212
+ }
213
+ let processChainConfig = processConfigChains[chainIdStr];
214
+ let indexingAddresses = Stdlib_Option.getOr(indexingAddressesByChain[chainIdStr], []);
215
+ return {
216
+ id: chainId,
217
+ startBlock: processChainConfig.startBlock,
218
+ endBlock: processChainConfig.endBlock,
219
+ maxReorgDepth: 0,
220
+ progressBlockNumber: -1,
221
+ numEventsProcessed: 0,
222
+ firstEventBlockNumber: undefined,
223
+ timestampCaughtUpToHeadOrEndblock: undefined,
224
+ indexingAddresses: indexingAddresses,
225
+ sourceBlockNumber: Stdlib_Option.getOr(processChainConfig.endBlock, 0)
226
+ };
227
+ });
234
228
  return {
235
- cleanRun: true,
236
- cache: {},
237
- chains: chains,
238
- checkpointId: InternalTable.Checkpoints.initialCheckpointId,
239
- reorgCheckpoints: []
240
- };
229
+ cleanRun: true,
230
+ cache: {},
231
+ chains: chains,
232
+ checkpointId: InternalTable.Checkpoints.initialCheckpointId,
233
+ reorgCheckpoints: []
234
+ };
241
235
  }
242
236
 
243
- var rawChainConfigSchema = S$RescriptSchema.schema(function (s) {
244
- return {
245
- startBlock: s.m(S$RescriptSchema.option(S$RescriptSchema.$$int)),
246
- endBlock: s.m(S$RescriptSchema.option(S$RescriptSchema.$$int)),
247
- simulate: s.m(S$RescriptSchema.option(S$RescriptSchema.array(S$RescriptSchema.json(false))))
248
- };
249
- });
237
+ let rawChainConfigSchema = S$RescriptSchema.schema(s => ({
238
+ startBlock: s.m(S$RescriptSchema.option(S$RescriptSchema.int)),
239
+ endBlock: s.m(S$RescriptSchema.option(S$RescriptSchema.int)),
240
+ simulate: s.m(S$RescriptSchema.option(S$RescriptSchema.array(S$RescriptSchema.json(false))))
241
+ }));
250
242
 
251
- var processConfigSchema = S$RescriptSchema.schema(function (s) {
252
- return {
253
- chains: s.m(S$RescriptSchema.dict(rawChainConfigSchema))
254
- };
255
- });
243
+ let processConfigSchema = S$RescriptSchema.schema(s => ({
244
+ chains: s.m(S$RescriptSchema.dict(rawChainConfigSchema))
245
+ }));
256
246
 
257
247
  function getSimulateEndBlock(simulateItems, config, startBlock) {
258
- var maxBlock = {
248
+ let maxBlock = {
259
249
  contents: startBlock
260
250
  };
261
- Belt_Array.forEach(simulateItems, (function (rawJson) {
262
- var blockJson = rawJson.block;
263
- if (blockJson == null) {
264
- return ;
265
- }
266
- var n = Belt_Option.flatMap(Js_dict.get(blockJson, config.ecosystem.blockNumberName), (function (v) {
267
- if (v == null) {
268
- return ;
269
- } else {
270
- return Caml_option.some(v);
271
- }
272
- }));
273
- if (n !== undefined && n > maxBlock.contents) {
274
- maxBlock.contents = n;
275
- return ;
276
- }
277
-
278
- }));
251
+ simulateItems.forEach(rawJson => {
252
+ let blockJson = rawJson.block;
253
+ if (blockJson == null) {
254
+ return;
255
+ }
256
+ let n = Stdlib_Option.flatMap(blockJson[config.ecosystem.blockNumberName], v => {
257
+ if (v == null) {
258
+ return;
259
+ } else {
260
+ return Primitive_option.some(v);
261
+ }
262
+ });
263
+ if (n !== undefined && n > maxBlock.contents) {
264
+ maxBlock.contents = n;
265
+ return;
266
+ }
267
+ });
279
268
  return maxBlock.contents;
280
269
  }
281
270
 
282
271
  function parseBlockRange(chainIdStr, config, rawChainConfig, progressBlock) {
283
- var id = Belt_Int.fromString(chainIdStr);
284
- var chainId = id !== undefined ? id : Js_exn.raiseError("Invalid chain ID \"" + chainIdStr + "\": expected a numeric chain ID");
285
- var chain = ChainMap.Chain.makeUnsafe(chainId);
272
+ let id = Stdlib_Int.fromString(chainIdStr, undefined);
273
+ let chainId = id !== undefined ? id : Stdlib_JsError.throwWithMessage(`Invalid chain ID "` + chainIdStr + `": expected a numeric chain ID`);
274
+ let chain = ChainMap.Chain.makeUnsafe(chainId);
286
275
  if (!ChainMap.has(config.chainMap, chain)) {
287
- Js_exn.raiseError("Chain " + chainIdStr + " is not configured in config.yaml");
276
+ Stdlib_JsError.throwWithMessage(`Chain ` + chainIdStr + ` is not configured in config.yaml`);
288
277
  }
289
- var configChain = ChainMap.get(config.chainMap, chain);
290
- var sb = rawChainConfig.startBlock;
291
- var startBlock = sb !== undefined ? sb : (
278
+ let configChain = ChainMap.get(config.chainMap, chain);
279
+ let sb = rawChainConfig.startBlock;
280
+ let startBlock = sb !== undefined ? sb : (
292
281
  progressBlock !== undefined ? progressBlock + 1 | 0 : configChain.startBlock
293
282
  );
294
- var eb = rawChainConfig.endBlock;
295
- var endBlock = eb !== undefined ? eb : (
296
- Belt_Option.isSome(rawChainConfig.simulate) ? getSimulateEndBlock(Belt_Option.getExn(rawChainConfig.simulate), config, startBlock) : undefined
283
+ let eb = rawChainConfig.endBlock;
284
+ let endBlock = eb !== undefined ? eb : (
285
+ Stdlib_Option.isSome(rawChainConfig.simulate) ? getSimulateEndBlock(Stdlib_Option.getOrThrow(rawChainConfig.simulate, undefined), config, startBlock) : undefined
297
286
  );
298
287
  if (startBlock < configChain.startBlock) {
299
- Js_exn.raiseError("Invalid block range for chain " + chainIdStr + ": startBlock (" + String(startBlock) + ") is less than config.startBlock (" + String(configChain.startBlock) + "). " + ("Either use startBlock >= " + String(configChain.startBlock) + " or create a new test indexer with createTestIndexer()."));
288
+ Stdlib_JsError.throwWithMessage(`Invalid block range for chain ` + chainIdStr + `: startBlock (` + startBlock.toString() + `) is less than config.startBlock (` + configChain.startBlock.toString() + `). ` + (`Either use startBlock >= ` + configChain.startBlock.toString() + ` or create a new test indexer with createTestIndexer().`));
300
289
  }
301
- var match = configChain.endBlock;
290
+ let match = configChain.endBlock;
302
291
  if (endBlock !== undefined && match !== undefined && endBlock > match) {
303
- Js_exn.raiseError("Invalid block range for chain " + chainIdStr + ": endBlock (" + String(endBlock) + ") exceeds config.endBlock (" + String(match) + "). " + ("Either use endBlock <= " + String(match) + " or create a new test indexer with createTestIndexer()."));
292
+ Stdlib_JsError.throwWithMessage(`Invalid block range for chain ` + chainIdStr + `: endBlock (` + endBlock.toString() + `) exceeds config.endBlock (` + match.toString() + `). ` + (`Either use endBlock <= ` + match.toString() + ` or create a new test indexer with createTestIndexer().`));
304
293
  }
305
294
  if (progressBlock !== undefined && startBlock <= progressBlock) {
306
- Js_exn.raiseError("Invalid block range for chain " + chainIdStr + ": startBlock (" + String(startBlock) + ") must be greater than previously processed endBlock (" + String(progressBlock) + "). " + ("Either use startBlock > " + String(progressBlock) + " or create a new test indexer with createTestIndexer()."));
295
+ Stdlib_JsError.throwWithMessage(`Invalid block range for chain ` + chainIdStr + `: startBlock (` + startBlock.toString() + `) must be greater than previously processed endBlock (` + progressBlock.toString() + `). ` + (`Either use startBlock > ` + progressBlock.toString() + ` or create a new test indexer with createTestIndexer().`));
307
296
  }
308
297
  return {
309
- startBlock: startBlock,
310
- endBlock: endBlock
311
- };
298
+ startBlock: startBlock,
299
+ endBlock: endBlock
300
+ };
312
301
  }
313
302
 
314
303
  function getEntityFromState(state, entityConfig, entityId, methodName) {
315
304
  if (state.processInProgress) {
316
- Js_exn.raiseError("Cannot call " + entityConfig.name + "." + methodName + "() while indexer.process() is running. Wait for process() to complete before accessing entities directly.");
305
+ Stdlib_JsError.throwWithMessage(`Cannot call ` + entityConfig.name + `.` + methodName + `() while indexer.process() is running. ` + "Wait for process() to complete before accessing entities directly.");
317
306
  }
318
- var entityDict = Belt_Option.getWithDefault(Js_dict.get(state.entities, entityConfig.name), {});
319
- return Js_dict.get(entityDict, entityId);
307
+ let entityDict = Stdlib_Option.getOr(state.entities[entityConfig.name], {});
308
+ return entityDict[entityId];
320
309
  }
321
310
 
322
311
  function makeEntityGet(state, entityConfig) {
323
- return function (entityId) {
324
- return Promise.resolve(getEntityFromState(state, entityConfig, entityId, "get"));
325
- };
312
+ return entityId => Promise.resolve(getEntityFromState(state, entityConfig, entityId, "get"));
326
313
  }
327
314
 
328
315
  function makeEntityGetOrThrow(state, entityConfig) {
329
- return function (entityId, message) {
330
- var entity = getEntityFromState(state, entityConfig, entityId, "getOrThrow");
316
+ return (entityId, message) => {
317
+ let entity = getEntityFromState(state, entityConfig, entityId, "getOrThrow");
331
318
  if (entity !== undefined) {
332
319
  return Promise.resolve(entity);
333
320
  } else {
334
- return Js_exn.raiseError(message !== undefined ? message : "Entity " + entityConfig.name + " with id " + entityId + " not found");
321
+ return Stdlib_JsError.throwWithMessage(message !== undefined ? message : `Entity ` + entityConfig.name + ` with id ` + entityId + ` not found`);
335
322
  }
336
323
  };
337
324
  }
338
325
 
339
326
  function makeEntitySet(state, entityConfig) {
340
- return function (entity) {
327
+ return entity => {
341
328
  if (state.processInProgress) {
342
- Js_exn.raiseError("Cannot call " + entityConfig.name + ".set() while indexer.process() is running. Wait for process() to complete before modifying entities directly.");
329
+ Stdlib_JsError.throwWithMessage(`Cannot call ` + entityConfig.name + `.set() while indexer.process() is running. ` + "Wait for process() to complete before modifying entities directly.");
343
330
  }
344
- var dict = Js_dict.get(state.entities, entityConfig.name);
345
- var entityDict;
331
+ let dict = state.entities[entityConfig.name];
332
+ let entityDict;
346
333
  if (dict !== undefined) {
347
334
  entityDict = dict;
348
335
  } else {
349
- var dict$1 = {};
336
+ let dict$1 = {};
350
337
  state.entities[entityConfig.name] = dict$1;
351
338
  entityDict = dict$1;
352
339
  }
@@ -355,276 +342,289 @@ function makeEntitySet(state, entityConfig) {
355
342
  }
356
343
 
357
344
  function makeEntityGetAll(state, entityConfig) {
358
- return function () {
345
+ return () => {
359
346
  if (state.processInProgress) {
360
- Js_exn.raiseError("Cannot call " + entityConfig.name + ".getAll() while indexer.process() is running. Wait for process() to complete before accessing entities directly.");
347
+ Stdlib_JsError.throwWithMessage(`Cannot call ` + entityConfig.name + `.getAll() while indexer.process() is running. ` + "Wait for process() to complete before accessing entities directly.");
361
348
  }
362
- var entityDict = Belt_Option.getWithDefault(Js_dict.get(state.entities, entityConfig.name), {});
363
- return Promise.resolve(Js_dict.values(entityDict));
349
+ let entityDict = Stdlib_Option.getOr(state.entities[entityConfig.name], {});
350
+ return Promise.resolve(Object.values(entityDict));
364
351
  };
365
352
  }
366
353
 
367
- function makeCreateTestIndexer(config, workerPath, allEntities) {
368
- return function () {
369
- var entities = {};
370
- var entityConfigs = {};
371
- Belt_Array.forEach(allEntities, (function (entityConfig) {
372
- entities[entityConfig.name] = {};
373
- entityConfigs[entityConfig.name] = entityConfig;
374
- }));
375
- var state = {
354
+ function makeCreateTestIndexer(config, workerPath) {
355
+ return () => {
356
+ let allEntities = config.allEntities;
357
+ let entities = {};
358
+ let entityConfigs = {};
359
+ allEntities.forEach(entityConfig => {
360
+ entities[entityConfig.name] = {};
361
+ entityConfigs[entityConfig.name] = entityConfig;
362
+ });
363
+ let envioAddressesDict = entities[Config.EnvioAddresses.name];
364
+ ChainMap.values(config.chainMap).forEach(chainConfig => {
365
+ chainConfig.contracts.forEach(contract => {
366
+ contract.addresses.forEach(address => {
367
+ let entity_id = Config.EnvioAddresses.makeId(chainConfig.id, address);
368
+ let entity_chain_id = chainConfig.id;
369
+ let entity_contract_name = contract.name;
370
+ let entity = {
371
+ id: entity_id,
372
+ chain_id: entity_chain_id,
373
+ registration_block: -1,
374
+ registration_log_index: -1,
375
+ contract_name: entity_contract_name
376
+ };
377
+ envioAddressesDict[entity_id] = entity;
378
+ });
379
+ });
380
+ });
381
+ let state = {
376
382
  processInProgress: false,
377
383
  progressBlockByChain: {},
378
384
  entities: entities,
379
385
  entityConfigs: entityConfigs,
380
386
  processChanges: []
381
387
  };
382
- var entityOpsDict = {};
383
- Belt_Array.forEach(allEntities, (function (entityConfig) {
384
- if (entityConfig.name !== Config.DynamicContractRegistry.name) {
385
- entityOpsDict[entityConfig.name] = {
386
- get: makeEntityGet(state, entityConfig),
387
- getAll: makeEntityGetAll(state, entityConfig),
388
- getOrThrow: makeEntityGetOrThrow(state, entityConfig),
389
- set: makeEntitySet(state, entityConfig)
390
- };
391
- return ;
388
+ let entityOpsDict = {};
389
+ allEntities.forEach(entityConfig => {
390
+ if (entityConfig.name !== Config.EnvioAddresses.name) {
391
+ entityOpsDict[entityConfig.name] = {
392
+ get: makeEntityGet(state, entityConfig),
393
+ getAll: makeEntityGetAll(state, entityConfig),
394
+ getOrThrow: makeEntityGetOrThrow(state, entityConfig),
395
+ set: makeEntitySet(state, entityConfig)
396
+ };
397
+ return;
398
+ }
399
+ });
400
+ let chainIds = [];
401
+ let chains = Object.create(null);
402
+ ChainMap.values(config.chainMap).forEach(chainConfig => {
403
+ let chainIdStr = chainConfig.id.toString();
404
+ chainIds.push(chainConfig.id);
405
+ let chainObj = Object.create(null);
406
+ Object.defineProperty(Object.defineProperty(Object.defineProperty(Object.defineProperty(Object.defineProperty(chainObj, "id", {
407
+ enumerable: true,
408
+ value: chainConfig.id
409
+ }), "startBlock", {
410
+ enumerable: true,
411
+ value: chainConfig.startBlock
412
+ }), "endBlock", {
413
+ enumerable: true,
414
+ value: chainConfig.endBlock
415
+ }), "name", {
416
+ enumerable: true,
417
+ value: chainConfig.name
418
+ }), "isLive", {
419
+ enumerable: true,
420
+ value: false
421
+ });
422
+ chainConfig.contracts.forEach(contract => {
423
+ let contractObj = Object.create(null);
424
+ Object.defineProperty(Object.defineProperty(Object.defineProperty(contractObj, "name", {
425
+ enumerable: true,
426
+ value: contract.name
427
+ }), "abi", {
428
+ enumerable: true,
429
+ value: contract.abi
430
+ }), "addresses", {
431
+ enumerable: true,
432
+ get: () => {
433
+ if (state.processInProgress) {
434
+ Stdlib_JsError.throwWithMessage(`Cannot access ` + contract.name + `.addresses while indexer.process() is running. ` + "Wait for process() to complete before reading contract addresses.");
392
435
  }
393
-
394
- }));
395
- var chainIds = [];
396
- var chains = Object.create(null);
397
- Belt_Array.forEach(ChainMap.values(config.chainMap), (function (chainConfig) {
398
- var chainIdStr = String(chainConfig.id);
399
- chainIds.push(chainConfig.id);
400
- var chainObj = Object.create(null);
401
- Object.defineProperty(Object.defineProperty(Object.defineProperty(Object.defineProperty(Object.defineProperty(chainObj, "id", {
402
- enumerable: true,
403
- value: chainConfig.id
404
- }), "startBlock", {
405
- enumerable: true,
406
- value: chainConfig.startBlock
407
- }), "endBlock", {
408
- enumerable: true,
409
- value: chainConfig.endBlock
410
- }), "name", {
411
- enumerable: true,
412
- value: chainConfig.name
413
- }), "isLive", {
414
- enumerable: true,
415
- value: false
416
- });
417
- Belt_Array.forEach(chainConfig.contracts, (function (contract) {
418
- var contractObj = Object.create(null);
419
- Object.defineProperty(Object.defineProperty(Object.defineProperty(contractObj, "name", {
420
- enumerable: true,
421
- value: contract.name
422
- }), "abi", {
423
- enumerable: true,
424
- value: contract.abi
425
- }), "addresses", {
426
- enumerable: true,
427
- get: (function () {
428
- if (state.processInProgress) {
429
- Js_exn.raiseError("Cannot access " + contract.name + ".addresses while indexer.process() is running. Wait for process() to complete before reading contract addresses.");
430
- }
431
- var addresses = contract.addresses.slice(0);
432
- var dcDict = Js_dict.get(state.entities, Config.DynamicContractRegistry.name);
433
- if (dcDict !== undefined) {
434
- Belt_Array.forEach(Js_dict.values(dcDict), (function (entity) {
435
- if (entity.contract_name === contract.name && entity.chain_id === chainConfig.id) {
436
- addresses.push(entity.contract_address);
437
- return ;
438
- }
439
-
440
- }));
441
- }
442
- return addresses;
443
- })
444
- });
445
- Object.defineProperty(chainObj, contract.name, {
446
- enumerable: true,
447
- value: contractObj
448
- });
449
- }));
450
- Object.defineProperty(chains, chainIdStr, {
451
- enumerable: true,
452
- value: chainObj
453
- });
454
- if (chainConfig.name !== chainIdStr) {
455
- Object.defineProperty(chains, chainConfig.name, {
456
- enumerable: false,
457
- value: chainObj
458
- });
459
- return ;
436
+ let addresses = [];
437
+ let dcDict = state.entities[Config.EnvioAddresses.name];
438
+ if (dcDict !== undefined) {
439
+ Object.values(dcDict).forEach(entity => {
440
+ if (entity.contract_name === contract.name && entity.chain_id === chainConfig.id) {
441
+ addresses.push(Config.EnvioAddresses.getAddress(entity));
442
+ return;
443
+ }
444
+ });
460
445
  }
461
-
462
- }));
463
- var result = {};
446
+ return addresses;
447
+ }
448
+ });
449
+ Object.defineProperty(chainObj, contract.name, {
450
+ enumerable: true,
451
+ value: contractObj
452
+ });
453
+ });
454
+ Object.defineProperty(chains, chainIdStr, {
455
+ enumerable: true,
456
+ value: chainObj
457
+ });
458
+ if (chainConfig.name !== chainIdStr) {
459
+ Object.defineProperty(chains, chainConfig.name, {
460
+ enumerable: false,
461
+ value: chainObj
462
+ });
463
+ return;
464
+ }
465
+ });
466
+ let result = {};
464
467
  result["chainIds"] = chainIds;
465
468
  result["chains"] = chains;
466
- Belt_Array.forEach(Js_dict.entries(entityOpsDict), (function (param) {
467
- result[param[0]] = param[1];
468
- }));
469
- result["process"] = (function (processConfig) {
470
- if (state.processInProgress) {
471
- Js_exn.raiseError("createTestIndexer process is already running. Only one process call is allowed at a time");
469
+ Object.entries(entityOpsDict).forEach(param => {
470
+ result[param[0]] = param[1];
471
+ });
472
+ result["process"] = processConfig => {
473
+ if (state.processInProgress) {
474
+ Stdlib_JsError.throwWithMessage("createTestIndexer process is already running. Only one process call is allowed at a time");
475
+ }
476
+ let parsedConfig;
477
+ try {
478
+ parsedConfig = S$RescriptSchema.parseOrThrow(processConfig, processConfigSchema);
479
+ } catch (raw_exn) {
480
+ let exn = Primitive_exceptions.internalToException(raw_exn);
481
+ if (exn.RE_EXN_ID === S$RescriptSchema.Raised) {
482
+ parsedConfig = Stdlib_JsError.throwWithMessage(`Invalid processConfig: ` + Utils.prettifyExn(exn._1));
483
+ } else {
484
+ throw exn;
472
485
  }
473
- var parsedConfig;
474
- try {
475
- parsedConfig = S$RescriptSchema.parseOrThrow(processConfig, processConfigSchema);
486
+ }
487
+ let rawChains = parsedConfig.chains;
488
+ let chainKeys = Object.keys(rawChains);
489
+ if (chainKeys.length === 0) {
490
+ Stdlib_JsError.throwWithMessage("createTestIndexer requires at least one chain to be defined");
491
+ }
492
+ let sortedChainKeys = chainKeys.slice();
493
+ sortedChainKeys.sort((a, b) => {
494
+ let aId = Stdlib_Option.getOr(Stdlib_Int.fromString(a, undefined), 0);
495
+ let bId = Stdlib_Option.getOr(Stdlib_Int.fromString(b, undefined), 0);
496
+ return Primitive_int.compare(aId, bId);
497
+ });
498
+ let chainEntries = sortedChainKeys.map(chainIdStr => {
499
+ let rawChainConfig = rawChains[chainIdStr];
500
+ let id = Stdlib_Int.fromString(chainIdStr, undefined);
501
+ let chainId = id !== undefined ? id : Stdlib_JsError.throwWithMessage(`Invalid chain ID "` + chainIdStr + `": expected a numeric chain ID`);
502
+ let processChainConfig = parseBlockRange(chainIdStr, config, rawChainConfig, state.progressBlockByChain[chainIdStr]);
503
+ return [
504
+ chainIdStr,
505
+ chainId,
506
+ rawChainConfig,
507
+ processChainConfig
508
+ ];
509
+ });
510
+ state.processChanges = [];
511
+ let runChainWorker = param => {
512
+ let processChainConfig = param[3];
513
+ let rawChainConfig = param[2];
514
+ let chainId = param[1];
515
+ let chains = {};
516
+ chains[param[0]] = processChainConfig;
517
+ let indexingAddressesByChain = {};
518
+ let dcDict = state.entities[Config.EnvioAddresses.name];
519
+ if (dcDict !== undefined) {
520
+ Object.values(dcDict).forEach(entity => {
521
+ let dcChainIdStr = entity.chain_id.toString();
522
+ let arr = indexingAddressesByChain[dcChainIdStr];
523
+ let contracts;
524
+ if (arr !== undefined) {
525
+ contracts = arr;
526
+ } else {
527
+ let arr$1 = [];
528
+ indexingAddressesByChain[dcChainIdStr] = arr$1;
529
+ contracts = arr$1;
530
+ }
531
+ contracts.push(toIndexingAddress(entity));
532
+ });
476
533
  }
477
- catch (raw_exn){
478
- var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
479
- if (exn.RE_EXN_ID === S$RescriptSchema.Raised) {
480
- parsedConfig = Js_exn.raiseError("Invalid processConfig: " + Utils.prettifyExn(exn._1));
481
- } else {
534
+ let initialState = makeInitialState(config, chains, indexingAddressesByChain);
535
+ return new Promise((resolve, reject) => {
536
+ let workerData_startBlock = processChainConfig.startBlock;
537
+ let workerData_endBlock = processChainConfig.endBlock;
538
+ let workerData_simulate = rawChainConfig.simulate;
539
+ let workerData = {
540
+ chainId: chainId,
541
+ startBlock: workerData_startBlock,
542
+ endBlock: workerData_endBlock,
543
+ simulate: workerData_simulate,
544
+ initialState: initialState
545
+ };
546
+ let worker;
547
+ try {
548
+ worker = new Worker_threads.Worker(workerPath, {
549
+ workerData: workerData,
550
+ env: process.env
551
+ });
552
+ } catch (raw_exn) {
553
+ let exn = Primitive_exceptions.internalToException(raw_exn);
554
+ reject(exn);
482
555
  throw exn;
483
556
  }
557
+ worker.on("message", msg => {
558
+ let respond = data => {
559
+ worker.postMessage({
560
+ id: msg.id,
561
+ payload: {
562
+ type: "response",
563
+ data: data
564
+ }
565
+ });
566
+ };
567
+ let match = msg.payload;
568
+ switch (match.type) {
569
+ case "loadByIds" :
570
+ return respond(handleLoadByIds(state, match.tableName, match.ids));
571
+ case "loadByField" :
572
+ return respond(handleLoadByField(state, match.tableName, match.fieldName, match.fieldValue, match.operator));
573
+ case "writeBatch" :
574
+ handleWriteBatch(state, match.updatedEntities, match.checkpointIds, match.checkpointChainIds, match.checkpointBlockNumbers, match.checkpointEventsProcessed);
575
+ return respond(null);
576
+ }
577
+ });
578
+ worker.on("error", err => {
579
+ worker.terminate();
580
+ reject(err);
581
+ });
582
+ worker.on("exit", code => {
583
+ if (code !== 0) {
584
+ return reject(new Error(`Worker exited with code ` + code.toString()));
585
+ } else {
586
+ return resolve();
587
+ }
588
+ });
589
+ });
590
+ };
591
+ state.processInProgress = true;
592
+ let runChains = idx => {
593
+ if (idx >= chainEntries.length) {
594
+ state.processInProgress = false;
595
+ return Promise.resolve({
596
+ changes: state.processChanges
597
+ });
598
+ } else {
599
+ return runChainWorker(chainEntries[idx]).then(() => runChains(idx + 1 | 0));
484
600
  }
485
- var rawChains = parsedConfig.chains;
486
- var chainKeys = Object.keys(rawChains);
487
- if (chainKeys.length === 0) {
488
- Js_exn.raiseError("createTestIndexer requires at least one chain to be defined");
489
- }
490
- var sortedChainKeys = chainKeys.slice(0).sort(function (a, b) {
491
- var aId = Belt_Option.getWithDefault(Belt_Int.fromString(a), 0);
492
- var bId = Belt_Option.getWithDefault(Belt_Int.fromString(b), 0);
493
- return aId - bId | 0;
494
- });
495
- var chainEntries = Belt_Array.map(sortedChainKeys, (function (chainIdStr) {
496
- var rawChainConfig = rawChains[chainIdStr];
497
- var id = Belt_Int.fromString(chainIdStr);
498
- var chainId = id !== undefined ? id : Js_exn.raiseError("Invalid chain ID \"" + chainIdStr + "\": expected a numeric chain ID");
499
- var processChainConfig = parseBlockRange(chainIdStr, config, rawChainConfig, Js_dict.get(state.progressBlockByChain, chainIdStr));
500
- return [
501
- chainIdStr,
502
- chainId,
503
- rawChainConfig,
504
- processChainConfig
505
- ];
506
- }));
507
- state.processChanges = [];
508
- var runChainWorker = function (param) {
509
- var processChainConfig = param[3];
510
- var rawChainConfig = param[2];
511
- var chainId = param[1];
512
- var chains = {};
513
- chains[param[0]] = processChainConfig;
514
- var dynamicContractsByChain = {};
515
- var dcDict = Js_dict.get(state.entities, Config.DynamicContractRegistry.name);
516
- if (dcDict !== undefined) {
517
- Belt_Array.forEach(Js_dict.values(dcDict), (function (entity) {
518
- var dcChainIdStr = String(entity.chain_id);
519
- var arr = Js_dict.get(dynamicContractsByChain, dcChainIdStr);
520
- var contracts;
521
- if (arr !== undefined) {
522
- contracts = arr;
523
- } else {
524
- var arr$1 = [];
525
- dynamicContractsByChain[dcChainIdStr] = arr$1;
526
- contracts = arr$1;
527
- }
528
- contracts.push(toIndexingContract(entity));
529
- }));
530
- }
531
- var initialState = makeInitialState(config, chains, dynamicContractsByChain);
532
- return new Promise((function (resolve, reject) {
533
- var workerData_startBlock = processChainConfig.startBlock;
534
- var workerData_endBlock = processChainConfig.endBlock;
535
- var workerData_simulate = rawChainConfig.simulate;
536
- var workerData = {
537
- chainId: chainId,
538
- startBlock: workerData_startBlock,
539
- endBlock: workerData_endBlock,
540
- simulate: workerData_simulate,
541
- initialState: initialState
542
- };
543
- var worker;
544
- try {
545
- worker = new Worker_threads.Worker(workerPath, {
546
- workerData: workerData
547
- });
548
- }
549
- catch (raw_exn){
550
- var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
551
- reject(exn);
552
- throw exn;
553
- }
554
- worker.on("message", (function (msg) {
555
- var respond = function (data) {
556
- worker.postMessage({
557
- id: msg.id,
558
- payload: {
559
- type: "response",
560
- data: data
561
- }
562
- });
563
- };
564
- var match = msg.payload;
565
- switch (match.type) {
566
- case "loadByIds" :
567
- return respond(handleLoadByIds(state, match.tableName, match.ids));
568
- case "loadByField" :
569
- return respond(handleLoadByField(state, match.tableName, match.fieldName, match.fieldValue, match.operator));
570
- case "writeBatch" :
571
- handleWriteBatch(state, match.updatedEntities, match.checkpointIds, match.checkpointChainIds, match.checkpointBlockNumbers, match.checkpointEventsProcessed);
572
- return respond(null);
573
-
574
- }
575
- }));
576
- worker.on("error", (function (err) {
577
- worker.terminate();
578
- reject(err);
579
- }));
580
- worker.on("exit", (function (code) {
581
- if (code !== 0) {
582
- return reject(new Error("Worker exited with code " + String(code)));
583
- } else {
584
- return resolve();
585
- }
586
- }));
587
- }));
588
- };
589
- state.processInProgress = true;
590
- var runChains = function (idx) {
591
- if (idx >= chainEntries.length) {
592
- state.processInProgress = false;
593
- return Promise.resolve({
594
- changes: state.processChanges
595
- });
596
- } else {
597
- return runChainWorker(chainEntries[idx]).then(function () {
598
- return runChains(idx + 1 | 0);
599
- });
600
- }
601
- };
602
- return $$Promise.$$catch(runChains(0), (function (err) {
603
- state.processInProgress = false;
604
- return Promise.reject(Utils.prettifyExn(err));
605
- }));
601
+ };
602
+ return Stdlib_Promise.$$catch(runChains(0), err => {
603
+ state.processInProgress = false;
604
+ return Promise.reject(Utils.prettifyExn(err));
606
605
  });
606
+ };
607
607
  return result;
608
608
  };
609
609
  }
610
610
 
611
- function initTestWorker(makeGeneratedConfig) {
611
+ function initTestWorker() {
612
612
  if (Worker_threads.isMainThread) {
613
- Js_exn.raiseError("initTestWorker must be called from a worker thread");
613
+ Stdlib_JsError.throwWithMessage("initTestWorker must be called from a worker thread");
614
614
  }
615
- var port = Worker_threads.parentPort;
616
- var parentPort = (port == null) ? Js_exn.raiseError("initTestWorker: No parent port available") : port;
617
- var workerData = Worker_threads.workerData;
615
+ let port = Worker_threads.parentPort;
616
+ let parentPort = (port == null) ? Stdlib_JsError.throwWithMessage("initTestWorker: No parent port available") : port;
617
+ let workerData = Worker_threads.workerData;
618
618
  if (workerData == null) {
619
619
  Logging.error("TestIndexerWorker: No worker data provided");
620
620
  Process.exit(1);
621
- return ;
621
+ return;
622
622
  }
623
- var simulate = workerData.simulate;
624
- var endBlock = workerData.endBlock;
625
- var chainIdStr = String(workerData.chainId);
626
- var exitAfterFirstEventBlock = Belt_Option.isNone(endBlock);
627
- var resolvedChainDict = {};
623
+ let simulate = workerData.simulate;
624
+ let endBlock = workerData.endBlock;
625
+ let chainIdStr = workerData.chainId.toString();
626
+ let exitAfterFirstEventBlock = Stdlib_Option.isNone(endBlock);
627
+ let resolvedChainDict = {};
628
628
  resolvedChainDict["startBlock"] = workerData.startBlock;
629
629
  if (endBlock !== undefined) {
630
630
  resolvedChainDict["endBlock"] = endBlock;
@@ -632,67 +632,67 @@ function initTestWorker(makeGeneratedConfig) {
632
632
  if (simulate !== undefined) {
633
633
  resolvedChainDict["simulate"] = simulate;
634
634
  }
635
- var resolvedChainsDict = {};
635
+ let resolvedChainsDict = {};
636
636
  resolvedChainsDict[chainIdStr] = resolvedChainDict;
637
- var processConfig = {
637
+ let processConfig = {
638
638
  chains: resolvedChainsDict
639
639
  };
640
- var proxy = TestIndexerProxyStorage.make(parentPort, workerData.initialState);
641
- var storage = TestIndexerProxyStorage.makeStorage(proxy);
642
- var config = makeGeneratedConfig();
643
- var persistence = Persistence.make(config.userEntities, config.allEnums, storage);
640
+ let proxy = TestIndexerProxyStorage.make(parentPort, workerData.initialState);
641
+ let storage = TestIndexerProxyStorage.makeStorage(proxy);
642
+ let config = Config.loadWithoutRegistrations();
643
+ let persistence = Persistence.make(config.userEntities, config.allEnums, storage);
644
644
  if (Env.userLogLevel !== undefined) {
645
645
 
646
646
  } else {
647
647
  Logging.setLogLevel("silent");
648
648
  }
649
- var patchConfig = function (config, _registrations) {
650
- var config$1 = SimulateItems.patchConfig(config, processConfig);
649
+ let patchConfig = (config, _registrations) => {
650
+ let config$1 = SimulateItems.patchConfig(config, processConfig);
651
651
  if (exitAfterFirstEventBlock) {
652
652
  return {
653
- name: config$1.name,
654
- description: config$1.description,
655
- handlers: config$1.handlers,
656
- contractHandlers: config$1.contractHandlers,
657
- shouldRollbackOnReorg: config$1.shouldRollbackOnReorg,
658
- shouldSaveFullHistory: config$1.shouldSaveFullHistory,
659
- multichain: config$1.multichain,
660
- chainMap: config$1.chainMap,
661
- defaultChain: config$1.defaultChain,
662
- ecosystem: config$1.ecosystem,
663
- enableRawEvents: config$1.enableRawEvents,
664
- maxAddrInPartition: config$1.maxAddrInPartition,
665
- batchSize: 1,
666
- lowercaseAddresses: config$1.lowercaseAddresses,
667
- addContractNameToContractNameMapping: config$1.addContractNameToContractNameMapping,
668
- userEntitiesByName: config$1.userEntitiesByName,
669
- userEntities: config$1.userEntities,
670
- allEntities: config$1.allEntities,
671
- allEnums: config$1.allEnums
672
- };
653
+ name: config$1.name,
654
+ description: config$1.description,
655
+ handlers: config$1.handlers,
656
+ contractHandlers: config$1.contractHandlers,
657
+ shouldRollbackOnReorg: config$1.shouldRollbackOnReorg,
658
+ shouldSaveFullHistory: config$1.shouldSaveFullHistory,
659
+ storage: config$1.storage,
660
+ multichain: config$1.multichain,
661
+ chainMap: config$1.chainMap,
662
+ defaultChain: config$1.defaultChain,
663
+ ecosystem: config$1.ecosystem,
664
+ enableRawEvents: config$1.enableRawEvents,
665
+ maxAddrInPartition: config$1.maxAddrInPartition,
666
+ batchSize: 1,
667
+ lowercaseAddresses: config$1.lowercaseAddresses,
668
+ userEntitiesByName: config$1.userEntitiesByName,
669
+ userEntities: config$1.userEntities,
670
+ allEntities: config$1.allEntities,
671
+ allEnums: config$1.allEnums
672
+ };
673
673
  } else {
674
674
  return config$1;
675
675
  }
676
676
  };
677
- Main.start(makeGeneratedConfig, persistence, true, exitAfterFirstEventBlock, patchConfig);
677
+ Main.start(persistence, undefined, true, exitAfterFirstEventBlock, patchConfig);
678
678
  }
679
679
 
680
680
  export {
681
- toIndexingContract ,
682
- handleLoadByIds ,
683
- handleLoadByField ,
684
- handleWriteBatch ,
685
- makeInitialState ,
686
- rawChainConfigSchema ,
687
- processConfigSchema ,
688
- getSimulateEndBlock ,
689
- parseBlockRange ,
690
- getEntityFromState ,
691
- makeEntityGet ,
692
- makeEntityGetOrThrow ,
693
- makeEntitySet ,
694
- makeEntityGetAll ,
695
- makeCreateTestIndexer ,
696
- initTestWorker ,
681
+ toIndexingAddress,
682
+ handleLoadByIds,
683
+ handleLoadByField,
684
+ handleWriteBatch,
685
+ makeInitialState,
686
+ rawChainConfigSchema,
687
+ processConfigSchema,
688
+ getSimulateEndBlock,
689
+ parseBlockRange,
690
+ getEntityFromState,
691
+ makeEntityGet,
692
+ makeEntityGetOrThrow,
693
+ makeEntitySet,
694
+ makeEntityGetAll,
695
+ makeCreateTestIndexer,
696
+ initTestWorker,
697
697
  }
698
698
  /* rawChainConfigSchema Not a pure module */