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
package/src/Batch.res.mjs CHANGED
@@ -1,38 +1,34 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
3
  import * as Utils from "./Utils.res.mjs";
4
- import * as $$BigInt from "./bindings/BigInt.res.mjs";
5
4
  import * as ChainMap from "./ChainMap.res.mjs";
6
- import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
7
5
  import * as FetchState from "./FetchState.res.mjs";
8
6
  import * as ReorgDetection from "./ReorgDetection.res.mjs";
9
7
 
10
8
  function getOrderedNextChain(fetchStates, batchSizePerChain) {
11
- var earliestChain;
12
- var earliestChainTimestamp = 0;
13
- var chainKeys = ChainMap.keys(fetchStates);
14
- for(var idx = 0 ,idx_finish = chainKeys.length - 1; idx <= idx_finish; ++idx){
15
- var chain = chainKeys[idx];
16
- var fetchState = ChainMap.get(fetchStates, chain);
9
+ let earliestChain;
10
+ let earliestChainTimestamp = 0;
11
+ let chainKeys = ChainMap.keys(fetchStates);
12
+ for (let idx = 0, idx_finish = chainKeys.length - 1; idx <= idx_finish; ++idx) {
13
+ let chain = chainKeys[idx];
14
+ let fetchState = ChainMap.get(fetchStates, chain);
17
15
  if (FetchState.isActivelyIndexing(fetchState)) {
18
- var batchSize = batchSizePerChain[chain];
19
- var timestamp = FetchState.getTimestampAt(fetchState, batchSize !== undefined ? batchSize : 0);
20
- var earliestChain$1 = earliestChain;
16
+ let batchSize = batchSizePerChain[chain];
17
+ let timestamp = FetchState.getTimestampAt(fetchState, batchSize !== undefined ? batchSize : 0);
18
+ let earliestChain$1 = earliestChain;
21
19
  if (!(earliestChain$1 !== undefined && (timestamp > earliestChainTimestamp || timestamp === earliestChainTimestamp && chain > earliestChain$1.chainId))) {
22
20
  earliestChain = fetchState;
23
21
  earliestChainTimestamp = timestamp;
24
22
  }
25
-
26
23
  }
27
-
28
24
  }
29
25
  return earliestChain;
30
26
  }
31
27
 
32
- var immutableEmptyBatchSizePerChain = {};
28
+ let immutableEmptyBatchSizePerChain = {};
33
29
 
34
30
  function hasOrderedReadyItem(fetchStates) {
35
- var fetchState = getOrderedNextChain(fetchStates, immutableEmptyBatchSizePerChain);
31
+ let fetchState = getOrderedNextChain(fetchStates, immutableEmptyBatchSizePerChain);
36
32
  if (fetchState !== undefined) {
37
33
  return FetchState.hasReadyItem(fetchState);
38
34
  } else {
@@ -41,13 +37,13 @@ function hasOrderedReadyItem(fetchStates) {
41
37
  }
42
38
 
43
39
  function hasUnorderedReadyItem(fetchStates) {
44
- return ChainMap.values(fetchStates).some(function (fetchState) {
45
- if (FetchState.isActivelyIndexing(fetchState)) {
46
- return FetchState.hasReadyItem(fetchState);
47
- } else {
48
- return false;
49
- }
50
- });
40
+ return ChainMap.values(fetchStates).some(fetchState => {
41
+ if (FetchState.isActivelyIndexing(fetchState)) {
42
+ return FetchState.hasReadyItem(fetchState);
43
+ } else {
44
+ return false;
45
+ }
46
+ });
51
47
  }
52
48
 
53
49
  function hasMultichainReadyItem(fetchStates, multichain) {
@@ -61,37 +57,35 @@ function hasMultichainReadyItem(fetchStates, multichain) {
61
57
  function getChainAfterBatchIfProgressed(chainBeforeBatch, progressBlockNumberAfterBatch, fetchStateAfterBatch, batchSize) {
62
58
  if (chainBeforeBatch.progressBlockNumber < progressBlockNumberAfterBatch) {
63
59
  return {
64
- batchSize: batchSize,
65
- progressBlockNumber: progressBlockNumberAfterBatch,
66
- sourceBlockNumber: chainBeforeBatch.sourceBlockNumber,
67
- totalEventsProcessed: chainBeforeBatch.totalEventsProcessed + batchSize,
68
- fetchState: fetchStateAfterBatch,
69
- isProgressAtHeadWhenBatchCreated: progressBlockNumberAfterBatch >= chainBeforeBatch.sourceBlockNumber - chainBeforeBatch.chainConfig.blockLag
70
- };
60
+ batchSize: batchSize,
61
+ progressBlockNumber: progressBlockNumberAfterBatch,
62
+ sourceBlockNumber: chainBeforeBatch.sourceBlockNumber,
63
+ totalEventsProcessed: chainBeforeBatch.totalEventsProcessed + batchSize,
64
+ fetchState: fetchStateAfterBatch,
65
+ isProgressAtHeadWhenBatchCreated: progressBlockNumberAfterBatch >= chainBeforeBatch.sourceBlockNumber - chainBeforeBatch.chainConfig.blockLag
66
+ };
71
67
  }
72
-
73
68
  }
74
69
 
75
70
  function getProgressedChainsById(chainsBeforeBatch, batchSizePerChain, progressBlockNumberPerChain) {
76
- var progressedChainsById = {};
77
- Belt_Array.forEachU(ChainMap.values(chainsBeforeBatch), (function (chainBeforeBatch) {
78
- var fetchState = chainBeforeBatch.fetchState;
79
- var progressBlockNumber = progressBlockNumberPerChain[String(fetchState.chainId)];
80
- var progressBlockNumberAfterBatch = progressBlockNumber !== undefined ? progressBlockNumber : chainBeforeBatch.progressBlockNumber;
81
- var batchSize = batchSizePerChain[String(fetchState.chainId)];
82
- var progressedChain;
83
- if (batchSize !== undefined) {
84
- var leftItems = fetchState.buffer.slice(batchSize);
85
- progressedChain = getChainAfterBatchIfProgressed(chainBeforeBatch, progressBlockNumberAfterBatch, FetchState.updateInternal(fetchState, undefined, undefined, leftItems, undefined, undefined), batchSize);
86
- } else {
87
- progressedChain = getChainAfterBatchIfProgressed(chainBeforeBatch, progressBlockNumberAfterBatch, chainBeforeBatch.fetchState, 0);
88
- }
89
- if (progressedChain !== undefined) {
90
- progressedChainsById[chainBeforeBatch.fetchState.chainId] = progressedChain;
91
- return ;
92
- }
93
-
94
- }));
71
+ let progressedChainsById = {};
72
+ ChainMap.values(chainsBeforeBatch).forEach(chainBeforeBatch => {
73
+ let fetchState = chainBeforeBatch.fetchState;
74
+ let progressBlockNumber = progressBlockNumberPerChain[fetchState.chainId.toString()];
75
+ let progressBlockNumberAfterBatch = progressBlockNumber !== undefined ? progressBlockNumber : chainBeforeBatch.progressBlockNumber;
76
+ let batchSize = batchSizePerChain[fetchState.chainId.toString()];
77
+ let progressedChain;
78
+ if (batchSize !== undefined) {
79
+ let leftItems = fetchState.buffer.slice(batchSize);
80
+ progressedChain = getChainAfterBatchIfProgressed(chainBeforeBatch, progressBlockNumberAfterBatch, FetchState.updateInternal(fetchState, undefined, undefined, leftItems, undefined, undefined), batchSize);
81
+ } else {
82
+ progressedChain = getChainAfterBatchIfProgressed(chainBeforeBatch, progressBlockNumberAfterBatch, chainBeforeBatch.fetchState, 0);
83
+ }
84
+ if (progressedChain !== undefined) {
85
+ progressedChainsById[chainBeforeBatch.fetchState.chainId] = progressedChain;
86
+ return;
87
+ }
88
+ });
95
89
  return progressedChainsById;
96
90
  }
97
91
 
@@ -99,11 +93,11 @@ function addReorgCheckpoints(prevCheckpointId, reorgDetection, fromBlockExclusiv
99
93
  if (!(reorgDetection.shouldRollbackOnReorg && !Utils.Dict.isEmpty(reorgDetection.dataByBlockNumber))) {
100
94
  return prevCheckpointId;
101
95
  }
102
- var prevCheckpointId$1 = prevCheckpointId;
103
- for(var blockNumber = fromBlockExclusive + 1 ,blockNumber_finish = toBlockExclusive - 1; blockNumber <= blockNumber_finish; ++blockNumber){
104
- var hash = ReorgDetection.getHashByBlockNumber(reorgDetection, blockNumber);
96
+ let prevCheckpointId$1 = prevCheckpointId;
97
+ for (let blockNumber = fromBlockExclusive + 1, blockNumber_finish = toBlockExclusive - 1; blockNumber <= blockNumber_finish; ++blockNumber) {
98
+ let hash = ReorgDetection.getHashByBlockNumber(reorgDetection, blockNumber);
105
99
  if (hash !== null) {
106
- var checkpointId = $$BigInt.add(prevCheckpointId$1, 1n);
100
+ let checkpointId = prevCheckpointId$1 + 1n;
107
101
  prevCheckpointId$1 = checkpointId;
108
102
  mutCheckpointIds.push(checkpointId);
109
103
  mutCheckpointChainIds.push(chainId);
@@ -111,48 +105,45 @@ function addReorgCheckpoints(prevCheckpointId, reorgDetection, fromBlockExclusiv
111
105
  mutCheckpointBlockHashes.push(hash);
112
106
  mutCheckpointEventsProcessed.push(0);
113
107
  }
114
-
115
108
  }
116
109
  return prevCheckpointId$1;
117
110
  }
118
111
 
119
112
  function prepareOrderedBatch(checkpointIdBeforeBatch, chainsBeforeBatch, batchSizeTarget) {
120
- var totalBatchSize = 0;
121
- var isFinished = false;
122
- var prevCheckpointId = checkpointIdBeforeBatch;
123
- var mutBatchSizePerChain = {};
124
- var mutProgressBlockNumberPerChain = {};
125
- var fetchStates = ChainMap.map(chainsBeforeBatch, (function (chainBeforeBatch) {
126
- return chainBeforeBatch.fetchState;
127
- }));
128
- var items = [];
129
- var checkpointIds = [];
130
- var checkpointChainIds = [];
131
- var checkpointBlockNumbers = [];
132
- var checkpointBlockHashes = [];
133
- var checkpointEventsProcessed = [];
134
- while(totalBatchSize < batchSizeTarget && !isFinished) {
135
- var fetchState = getOrderedNextChain(fetchStates, mutBatchSizePerChain);
113
+ let totalBatchSize = 0;
114
+ let isFinished = false;
115
+ let prevCheckpointId = checkpointIdBeforeBatch;
116
+ let mutBatchSizePerChain = {};
117
+ let mutProgressBlockNumberPerChain = {};
118
+ let fetchStates = ChainMap.map(chainsBeforeBatch, chainBeforeBatch => chainBeforeBatch.fetchState);
119
+ let items = [];
120
+ let checkpointIds = [];
121
+ let checkpointChainIds = [];
122
+ let checkpointBlockNumbers = [];
123
+ let checkpointBlockHashes = [];
124
+ let checkpointEventsProcessed = [];
125
+ while (totalBatchSize < batchSizeTarget && !isFinished) {
126
+ let fetchState = getOrderedNextChain(fetchStates, mutBatchSizePerChain);
136
127
  if (fetchState !== undefined) {
137
- var chainBeforeBatch = ChainMap.get(chainsBeforeBatch, ChainMap.Chain.makeUnsafe(fetchState.chainId));
138
- var batchSize = mutBatchSizePerChain[fetchState.chainId];
139
- var itemsCountBefore = batchSize !== undefined ? batchSize : 0;
140
- var progressBlockNumber = mutProgressBlockNumberPerChain[fetchState.chainId];
141
- var prevBlockNumber = progressBlockNumber !== undefined ? progressBlockNumber : chainBeforeBatch.progressBlockNumber;
142
- var newItemsCount = FetchState.getReadyItemsCount(fetchState, 1, itemsCountBefore);
128
+ let chainBeforeBatch = ChainMap.get(chainsBeforeBatch, ChainMap.Chain.makeUnsafe(fetchState.chainId));
129
+ let batchSize = mutBatchSizePerChain[fetchState.chainId];
130
+ let itemsCountBefore = batchSize !== undefined ? batchSize : 0;
131
+ let progressBlockNumber = mutProgressBlockNumberPerChain[fetchState.chainId];
132
+ let prevBlockNumber = progressBlockNumber !== undefined ? progressBlockNumber : chainBeforeBatch.progressBlockNumber;
133
+ let newItemsCount = FetchState.getReadyItemsCount(fetchState, 1, itemsCountBefore);
143
134
  if (newItemsCount > 0) {
144
- var item0 = fetchState.buffer[itemsCountBefore];
145
- var blockNumber = item0.blockNumber;
146
- var chainId = fetchState.chainId;
147
- var reorgDetection = chainBeforeBatch.reorgDetection;
148
- var prevCheckpointId$1 = prevCheckpointId;
149
- var tmp;
135
+ let item0 = fetchState.buffer[itemsCountBefore];
136
+ let blockNumber = item0.blockNumber;
137
+ let chainId = fetchState.chainId;
138
+ let reorgDetection = chainBeforeBatch.reorgDetection;
139
+ let prevCheckpointId$1 = prevCheckpointId;
140
+ let tmp;
150
141
  if (reorgDetection.shouldRollbackOnReorg && !Utils.Dict.isEmpty(reorgDetection.dataByBlockNumber)) {
151
- var prevCheckpointId$2 = prevCheckpointId$1;
152
- for(var blockNumber$1 = prevBlockNumber + 1 ,blockNumber_finish = blockNumber - 1; blockNumber$1 <= blockNumber_finish; ++blockNumber$1){
153
- var hash = ReorgDetection.getHashByBlockNumber(reorgDetection, blockNumber$1);
142
+ let prevCheckpointId$2 = prevCheckpointId$1;
143
+ for (let blockNumber$1 = prevBlockNumber + 1, blockNumber_finish = blockNumber - 1; blockNumber$1 <= blockNumber_finish; ++blockNumber$1) {
144
+ let hash = ReorgDetection.getHashByBlockNumber(reorgDetection, blockNumber$1);
154
145
  if (hash !== null) {
155
- var checkpointId = $$BigInt.add(prevCheckpointId$2, 1n);
146
+ let checkpointId = prevCheckpointId$2 + 1n;
156
147
  prevCheckpointId$2 = checkpointId;
157
148
  checkpointIds.push(checkpointId);
158
149
  checkpointChainIds.push(chainId);
@@ -160,16 +151,15 @@ function prepareOrderedBatch(checkpointIdBeforeBatch, chainsBeforeBatch, batchSi
160
151
  checkpointBlockHashes.push(hash);
161
152
  checkpointEventsProcessed.push(0);
162
153
  }
163
-
164
154
  }
165
155
  tmp = prevCheckpointId$2;
166
156
  } else {
167
157
  tmp = prevCheckpointId$1;
168
158
  }
169
159
  prevCheckpointId = tmp;
170
- var checkpointId$1 = $$BigInt.add(prevCheckpointId, 1n);
160
+ let checkpointId$1 = prevCheckpointId + 1n;
171
161
  items.push(item0);
172
- for(var idx = 1 ,idx_finish = newItemsCount - 1; idx <= idx_finish; ++idx){
162
+ for (let idx = 1, idx_finish = newItemsCount - 1; idx <= idx_finish; ++idx) {
173
163
  items.push(fetchState.buffer[itemsCountBefore + idx]);
174
164
  }
175
165
  checkpointIds.push(checkpointId$1);
@@ -182,18 +172,18 @@ function prepareOrderedBatch(checkpointIdBeforeBatch, chainsBeforeBatch, batchSi
182
172
  mutBatchSizePerChain[fetchState.chainId] = itemsCountBefore + newItemsCount;
183
173
  mutProgressBlockNumberPerChain[fetchState.chainId] = blockNumber;
184
174
  } else {
185
- var blockNumberAfterBatch = FetchState.bufferBlockNumber(fetchState);
186
- var chainId$1 = fetchState.chainId;
187
- var toBlockExclusive = blockNumberAfterBatch + 1;
188
- var reorgDetection$1 = chainBeforeBatch.reorgDetection;
189
- var prevCheckpointId$3 = prevCheckpointId;
190
- var tmp$1;
175
+ let blockNumberAfterBatch = FetchState.bufferBlockNumber(fetchState);
176
+ let chainId$1 = fetchState.chainId;
177
+ let toBlockExclusive = blockNumberAfterBatch + 1;
178
+ let reorgDetection$1 = chainBeforeBatch.reorgDetection;
179
+ let prevCheckpointId$3 = prevCheckpointId;
180
+ let tmp$1;
191
181
  if (reorgDetection$1.shouldRollbackOnReorg && !Utils.Dict.isEmpty(reorgDetection$1.dataByBlockNumber)) {
192
- var prevCheckpointId$4 = prevCheckpointId$3;
193
- for(var blockNumber$2 = prevBlockNumber + 1 ,blockNumber_finish$1 = toBlockExclusive - 1; blockNumber$2 <= blockNumber_finish$1; ++blockNumber$2){
194
- var hash$1 = ReorgDetection.getHashByBlockNumber(reorgDetection$1, blockNumber$2);
182
+ let prevCheckpointId$4 = prevCheckpointId$3;
183
+ for (let blockNumber$2 = prevBlockNumber + 1, blockNumber_finish$1 = toBlockExclusive - 1; blockNumber$2 <= blockNumber_finish$1; ++blockNumber$2) {
184
+ let hash$1 = ReorgDetection.getHashByBlockNumber(reorgDetection$1, blockNumber$2);
195
185
  if (hash$1 !== null) {
196
- var checkpointId$2 = $$BigInt.add(prevCheckpointId$4, 1n);
186
+ let checkpointId$2 = prevCheckpointId$4 + 1n;
197
187
  prevCheckpointId$4 = checkpointId$2;
198
188
  checkpointIds.push(checkpointId$2);
199
189
  checkpointChainIds.push(chainId$1);
@@ -201,7 +191,6 @@ function prepareOrderedBatch(checkpointIdBeforeBatch, chainsBeforeBatch, batchSi
201
191
  checkpointBlockHashes.push(hash$1);
202
192
  checkpointEventsProcessed.push(0);
203
193
  }
204
-
205
194
  }
206
195
  tmp$1 = prevCheckpointId$4;
207
196
  } else {
@@ -216,54 +205,52 @@ function prepareOrderedBatch(checkpointIdBeforeBatch, chainsBeforeBatch, batchSi
216
205
  }
217
206
  };
218
207
  return {
219
- totalBatchSize: totalBatchSize,
220
- items: items,
221
- progressedChainsById: getProgressedChainsById(chainsBeforeBatch, mutBatchSizePerChain, mutProgressBlockNumberPerChain),
222
- checkpointIds: checkpointIds,
223
- checkpointChainIds: checkpointChainIds,
224
- checkpointBlockNumbers: checkpointBlockNumbers,
225
- checkpointBlockHashes: checkpointBlockHashes,
226
- checkpointEventsProcessed: checkpointEventsProcessed
227
- };
208
+ totalBatchSize: totalBatchSize,
209
+ items: items,
210
+ progressedChainsById: getProgressedChainsById(chainsBeforeBatch, mutBatchSizePerChain, mutProgressBlockNumberPerChain),
211
+ checkpointIds: checkpointIds,
212
+ checkpointChainIds: checkpointChainIds,
213
+ checkpointBlockNumbers: checkpointBlockNumbers,
214
+ checkpointBlockHashes: checkpointBlockHashes,
215
+ checkpointEventsProcessed: checkpointEventsProcessed
216
+ };
228
217
  }
229
218
 
230
219
  function prepareUnorderedBatch(checkpointIdBeforeBatch, chainsBeforeBatch, batchSizeTarget) {
231
- var preparedFetchStates = FetchState.sortForUnorderedBatch(ChainMap.values(chainsBeforeBatch).map(function (chainBeforeBatch) {
232
- return chainBeforeBatch.fetchState;
233
- }), batchSizeTarget);
234
- var chainIdx = 0;
235
- var preparedNumber = preparedFetchStates.length;
236
- var totalBatchSize = 0;
237
- var prevCheckpointId = checkpointIdBeforeBatch;
238
- var mutBatchSizePerChain = {};
239
- var mutProgressBlockNumberPerChain = {};
240
- var items = [];
241
- var checkpointIds = [];
242
- var checkpointChainIds = [];
243
- var checkpointBlockNumbers = [];
244
- var checkpointBlockHashes = [];
245
- var checkpointEventsProcessed = [];
246
- while(totalBatchSize < batchSizeTarget && chainIdx < preparedNumber) {
247
- var fetchState = preparedFetchStates[chainIdx];
248
- var chainBatchSize = FetchState.getReadyItemsCount(fetchState, batchSizeTarget - totalBatchSize, 0);
249
- var chainBeforeBatch = ChainMap.get(chainsBeforeBatch, ChainMap.Chain.makeUnsafe(fetchState.chainId));
250
- var prevBlockNumber = chainBeforeBatch.progressBlockNumber;
220
+ let preparedFetchStates = FetchState.sortForUnorderedBatch(ChainMap.values(chainsBeforeBatch).map(chainBeforeBatch => chainBeforeBatch.fetchState), batchSizeTarget);
221
+ let chainIdx = 0;
222
+ let preparedNumber = preparedFetchStates.length;
223
+ let totalBatchSize = 0;
224
+ let prevCheckpointId = checkpointIdBeforeBatch;
225
+ let mutBatchSizePerChain = {};
226
+ let mutProgressBlockNumberPerChain = {};
227
+ let items = [];
228
+ let checkpointIds = [];
229
+ let checkpointChainIds = [];
230
+ let checkpointBlockNumbers = [];
231
+ let checkpointBlockHashes = [];
232
+ let checkpointEventsProcessed = [];
233
+ while (totalBatchSize < batchSizeTarget && chainIdx < preparedNumber) {
234
+ let fetchState = preparedFetchStates[chainIdx];
235
+ let chainBatchSize = FetchState.getReadyItemsCount(fetchState, batchSizeTarget - totalBatchSize, 0);
236
+ let chainBeforeBatch = ChainMap.get(chainsBeforeBatch, ChainMap.Chain.makeUnsafe(fetchState.chainId));
237
+ let prevBlockNumber = chainBeforeBatch.progressBlockNumber;
251
238
  if (chainBatchSize > 0) {
252
- for(var idx = 0 ,idx_finish = chainBatchSize - 1; idx <= idx_finish; ++idx){
253
- var item = fetchState.buffer[idx];
254
- var blockNumber = item.blockNumber;
239
+ for (let idx = 0, idx_finish = chainBatchSize - 1; idx <= idx_finish; ++idx) {
240
+ let item = fetchState.buffer[idx];
241
+ let blockNumber = item.blockNumber;
255
242
  if (blockNumber !== prevBlockNumber) {
256
- var chainId = fetchState.chainId;
257
- var fromBlockExclusive = prevBlockNumber;
258
- var reorgDetection = chainBeforeBatch.reorgDetection;
259
- var prevCheckpointId$1 = prevCheckpointId;
260
- var tmp;
243
+ let chainId = fetchState.chainId;
244
+ let fromBlockExclusive = prevBlockNumber;
245
+ let reorgDetection = chainBeforeBatch.reorgDetection;
246
+ let prevCheckpointId$1 = prevCheckpointId;
247
+ let tmp;
261
248
  if (reorgDetection.shouldRollbackOnReorg && !Utils.Dict.isEmpty(reorgDetection.dataByBlockNumber)) {
262
- var prevCheckpointId$2 = prevCheckpointId$1;
263
- for(var blockNumber$1 = fromBlockExclusive + 1 ,blockNumber_finish = blockNumber - 1; blockNumber$1 <= blockNumber_finish; ++blockNumber$1){
264
- var hash = ReorgDetection.getHashByBlockNumber(reorgDetection, blockNumber$1);
249
+ let prevCheckpointId$2 = prevCheckpointId$1;
250
+ for (let blockNumber$1 = fromBlockExclusive + 1, blockNumber_finish = blockNumber - 1; blockNumber$1 <= blockNumber_finish; ++blockNumber$1) {
251
+ let hash = ReorgDetection.getHashByBlockNumber(reorgDetection, blockNumber$1);
265
252
  if (hash !== null) {
266
- var checkpointId = $$BigInt.add(prevCheckpointId$2, 1n);
253
+ let checkpointId = prevCheckpointId$2 + 1n;
267
254
  prevCheckpointId$2 = checkpointId;
268
255
  checkpointIds.push(checkpointId);
269
256
  checkpointChainIds.push(chainId);
@@ -271,14 +258,13 @@ function prepareUnorderedBatch(checkpointIdBeforeBatch, chainsBeforeBatch, batch
271
258
  checkpointBlockHashes.push(hash);
272
259
  checkpointEventsProcessed.push(0);
273
260
  }
274
-
275
261
  }
276
262
  tmp = prevCheckpointId$2;
277
263
  } else {
278
264
  tmp = prevCheckpointId$1;
279
265
  }
280
266
  prevCheckpointId = tmp;
281
- var checkpointId$1 = $$BigInt.add(prevCheckpointId, 1n);
267
+ let checkpointId$1 = prevCheckpointId + 1n;
282
268
  checkpointIds.push(checkpointId$1);
283
269
  checkpointChainIds.push(fetchState.chainId);
284
270
  checkpointBlockNumbers.push(blockNumber);
@@ -287,7 +273,7 @@ function prepareUnorderedBatch(checkpointIdBeforeBatch, chainsBeforeBatch, batch
287
273
  prevBlockNumber = blockNumber;
288
274
  prevCheckpointId = checkpointId$1;
289
275
  } else {
290
- var lastIndex = checkpointEventsProcessed.length - 1;
276
+ let lastIndex = checkpointEventsProcessed.length - 1;
291
277
  checkpointEventsProcessed[lastIndex] = checkpointEventsProcessed[lastIndex] + 1;
292
278
  }
293
279
  items.push(item);
@@ -295,19 +281,19 @@ function prepareUnorderedBatch(checkpointIdBeforeBatch, chainsBeforeBatch, batch
295
281
  totalBatchSize = totalBatchSize + chainBatchSize;
296
282
  mutBatchSizePerChain[fetchState.chainId] = chainBatchSize;
297
283
  }
298
- var progressBlockNumberAfterBatch = FetchState.getUnorderedMultichainProgressBlockNumberAt(fetchState, chainBatchSize);
299
- var chainId$1 = fetchState.chainId;
300
- var toBlockExclusive = progressBlockNumberAfterBatch + 1;
301
- var fromBlockExclusive$1 = prevBlockNumber;
302
- var reorgDetection$1 = chainBeforeBatch.reorgDetection;
303
- var prevCheckpointId$3 = prevCheckpointId;
304
- var tmp$1;
284
+ let progressBlockNumberAfterBatch = FetchState.getUnorderedMultichainProgressBlockNumberAt(fetchState, chainBatchSize);
285
+ let chainId$1 = fetchState.chainId;
286
+ let toBlockExclusive = progressBlockNumberAfterBatch + 1;
287
+ let fromBlockExclusive$1 = prevBlockNumber;
288
+ let reorgDetection$1 = chainBeforeBatch.reorgDetection;
289
+ let prevCheckpointId$3 = prevCheckpointId;
290
+ let tmp$1;
305
291
  if (reorgDetection$1.shouldRollbackOnReorg && !Utils.Dict.isEmpty(reorgDetection$1.dataByBlockNumber)) {
306
- var prevCheckpointId$4 = prevCheckpointId$3;
307
- for(var blockNumber$2 = fromBlockExclusive$1 + 1 ,blockNumber_finish$1 = toBlockExclusive - 1; blockNumber$2 <= blockNumber_finish$1; ++blockNumber$2){
308
- var hash$1 = ReorgDetection.getHashByBlockNumber(reorgDetection$1, blockNumber$2);
292
+ let prevCheckpointId$4 = prevCheckpointId$3;
293
+ for (let blockNumber$2 = fromBlockExclusive$1 + 1, blockNumber_finish$1 = toBlockExclusive - 1; blockNumber$2 <= blockNumber_finish$1; ++blockNumber$2) {
294
+ let hash$1 = ReorgDetection.getHashByBlockNumber(reorgDetection$1, blockNumber$2);
309
295
  if (hash$1 !== null) {
310
- var checkpointId$2 = $$BigInt.add(prevCheckpointId$4, 1n);
296
+ let checkpointId$2 = prevCheckpointId$4 + 1n;
311
297
  prevCheckpointId$4 = checkpointId$2;
312
298
  checkpointIds.push(checkpointId$2);
313
299
  checkpointChainIds.push(chainId$1);
@@ -315,7 +301,6 @@ function prepareUnorderedBatch(checkpointIdBeforeBatch, chainsBeforeBatch, batch
315
301
  checkpointBlockHashes.push(hash$1);
316
302
  checkpointEventsProcessed.push(0);
317
303
  }
318
-
319
304
  }
320
305
  tmp$1 = prevCheckpointId$4;
321
306
  } else {
@@ -326,19 +311,19 @@ function prepareUnorderedBatch(checkpointIdBeforeBatch, chainsBeforeBatch, batch
326
311
  chainIdx = chainIdx + 1;
327
312
  };
328
313
  return {
329
- totalBatchSize: totalBatchSize,
330
- items: items,
331
- progressedChainsById: getProgressedChainsById(chainsBeforeBatch, mutBatchSizePerChain, mutProgressBlockNumberPerChain),
332
- checkpointIds: checkpointIds,
333
- checkpointChainIds: checkpointChainIds,
334
- checkpointBlockNumbers: checkpointBlockNumbers,
335
- checkpointBlockHashes: checkpointBlockHashes,
336
- checkpointEventsProcessed: checkpointEventsProcessed
337
- };
314
+ totalBatchSize: totalBatchSize,
315
+ items: items,
316
+ progressedChainsById: getProgressedChainsById(chainsBeforeBatch, mutBatchSizePerChain, mutProgressBlockNumberPerChain),
317
+ checkpointIds: checkpointIds,
318
+ checkpointChainIds: checkpointChainIds,
319
+ checkpointBlockNumbers: checkpointBlockNumbers,
320
+ checkpointBlockHashes: checkpointBlockHashes,
321
+ checkpointEventsProcessed: checkpointEventsProcessed
322
+ };
338
323
  }
339
324
 
340
325
  function make(checkpointIdBeforeBatch, chainsBeforeBatch, multichain, batchSizeTarget) {
341
- var tmp;
326
+ let tmp;
342
327
  tmp = multichain === "ordered" ? ChainMap.size(chainsBeforeBatch) === 1 : true;
343
328
  if (tmp) {
344
329
  return prepareUnorderedBatch(checkpointIdBeforeBatch, chainsBeforeBatch, batchSizeTarget);
@@ -348,11 +333,11 @@ function make(checkpointIdBeforeBatch, chainsBeforeBatch, multichain, batchSizeT
348
333
  }
349
334
 
350
335
  function findFirstEventBlockNumber(batch, chainId) {
351
- var idx = 0;
352
- var result;
353
- var checkpointsLength = batch.checkpointIds.length;
354
- while(idx < checkpointsLength && result === undefined) {
355
- var checkpointChainId = batch.checkpointChainIds[idx];
336
+ let idx = 0;
337
+ let result;
338
+ let checkpointsLength = batch.checkpointIds.length;
339
+ while (idx < checkpointsLength && result === undefined) {
340
+ let checkpointChainId = batch.checkpointChainIds[idx];
356
341
  if (checkpointChainId === chainId && batch.checkpointEventsProcessed[idx] > 0) {
357
342
  result = batch.checkpointBlockNumbers[idx];
358
343
  } else {
@@ -363,10 +348,10 @@ function findFirstEventBlockNumber(batch, chainId) {
363
348
  }
364
349
 
365
350
  function findLastEventItem(batch, chainId) {
366
- var idx = batch.items.length - 1;
367
- var result;
368
- while(idx >= 0 && result === undefined) {
369
- var item = batch.items[idx];
351
+ let idx = batch.items.length - 1;
352
+ let result;
353
+ while (idx >= 0 && result === undefined) {
354
+ let item = batch.items[idx];
370
355
  if (item.kind === 0 && item.chain === chainId) {
371
356
  result = item;
372
357
  } else {
@@ -377,17 +362,17 @@ function findLastEventItem(batch, chainId) {
377
362
  }
378
363
 
379
364
  export {
380
- getOrderedNextChain ,
381
- immutableEmptyBatchSizePerChain ,
382
- hasOrderedReadyItem ,
383
- hasUnorderedReadyItem ,
384
- hasMultichainReadyItem ,
385
- getProgressedChainsById ,
386
- addReorgCheckpoints ,
387
- prepareOrderedBatch ,
388
- prepareUnorderedBatch ,
389
- make ,
390
- findFirstEventBlockNumber ,
391
- findLastEventItem ,
365
+ getOrderedNextChain,
366
+ immutableEmptyBatchSizePerChain,
367
+ hasOrderedReadyItem,
368
+ hasUnorderedReadyItem,
369
+ hasMultichainReadyItem,
370
+ getProgressedChainsById,
371
+ addReorgCheckpoints,
372
+ prepareOrderedBatch,
373
+ prepareUnorderedBatch,
374
+ make,
375
+ findFirstEventBlockNumber,
376
+ findLastEventItem,
392
377
  }
393
378
  /* Utils Not a pure module */
package/src/Bin.res ADDED
@@ -0,0 +1,89 @@
1
+ @val external processChdir: string => unit = "process.chdir"
2
+ let setEnvVar: (string, string) => unit = %raw(`(k, v) => { process.env[k] = v; }`)
3
+
4
+ // Crash on unhandled promise rejections with a readable error.
5
+ // ReScript exceptions compile to plain objects, not Error instances, so Node.js prints "#<Object>".
6
+ NodeJs.globalProcess->NodeJs.onUnhandledRejection(reason => {
7
+ Logging.errorWithExn(reason->Utils.prettifyExn, "Unhandled promise rejection")
8
+ NodeJs.process->NodeJs.exitWithCode(Failure)
9
+ })
10
+
11
+ // Wire format mirrors the Rust `executor::Command` enum — a tagged JSON
12
+ // object with a `kind` discriminator.
13
+ // `migrate` is `Null.t`, not `option`: Rust serde encodes `None` as JSON
14
+ // `null`, but ReScript's `option` expects `undefined`, so a `null` value
15
+ // wrongly passes `Option.map`'s `!== undefined` check. Callers convert via
16
+ // `Null.toOption` at use time.
17
+ type startCmd = {
18
+ migrate: Null.t<Main.migrateOpts>,
19
+ cwd: string,
20
+ env: dict<JSON.t>,
21
+ config: JSON.t,
22
+ }
23
+ type migrateCmd = {reset: bool, persistedState: JSON.t, config: JSON.t}
24
+ type dropSchemaCmd = {config: JSON.t}
25
+
26
+ type command =
27
+ | Start(startCmd)
28
+ | Migrate(migrateCmd)
29
+ | DropSchema(dropSchemaCmd)
30
+
31
+ let decodeCommand = (json: JSON.t): command => {
32
+ let obj = switch json->JSON.Decode.object {
33
+ | Some(o) => o
34
+ | None => JsError.throwWithMessage("Invalid command payload: not an object")
35
+ }
36
+ let kind = switch obj->Dict.get("kind")->Option.flatMap(JSON.Decode.string) {
37
+ | Some(k) => k
38
+ | None => JsError.throwWithMessage("Invalid command payload: missing kind")
39
+ }
40
+ switch kind {
41
+ | "start" => Start(json->(Utils.magic: JSON.t => startCmd))
42
+ | "migrate" => Migrate(json->(Utils.magic: JSON.t => migrateCmd))
43
+ | "drop-schema" => DropSchema(json->(Utils.magic: JSON.t => dropSchemaCmd))
44
+ | other => JsError.throwWithMessage(`Unknown command kind: ${other}`)
45
+ }
46
+ }
47
+
48
+ let applyEnv = (env: dict<JSON.t>) =>
49
+ env->Dict.forEachWithKey((value, key) => {
50
+ switch value->JSON.Decode.string {
51
+ | Some(v) => setEnvVar(key, v)
52
+ | None => ()
53
+ }
54
+ })
55
+
56
+ let run = async args => {
57
+ try {
58
+ switch (await Core.runCli(args))->Null.toOption {
59
+ // Rust-only command (codegen / init / stop / docker / help / version /
60
+ // scripts) — nothing for JS to do, exit cleanly.
61
+ | None => ()
62
+ | Some(json) =>
63
+ switch decodeCommand(json->JSON.parseOrThrow) {
64
+ | Start({migrate, cwd, env, config}) =>
65
+ Config.prime(config)
66
+ processChdir(cwd)
67
+ applyEnv(env)
68
+ await Main.start(~migrate=?migrate->Null.toOption)
69
+ | Migrate({reset, persistedState, config}) =>
70
+ Config.prime(config)
71
+ await Main.migrate(~reset, ~persistedState)
72
+ | DropSchema({config}) =>
73
+ Config.prime(config)
74
+ await Main.dropSchema()
75
+ }
76
+ }
77
+ } catch {
78
+ | exn =>
79
+ // Log just the exception's own message — wrapping it in "Failed at
80
+ // initialization" and pino's err serializer buries the real cause under
81
+ // a nested `err: { type, message, stack, ... }` block.
82
+ let message = switch exn->JsExn.anyToExnInternal {
83
+ | JsExn(e) => e->JsExn.message->Option.getOr("Failed at initialization")
84
+ | _ => "Failed at initialization"
85
+ }
86
+ Logging.error(message)
87
+ NodeJs.process->NodeJs.exitWithCode(Failure)
88
+ }
89
+ }