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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/bin.mjs +2 -48
  2. package/evm.schema.json +67 -0
  3. package/fuel.schema.json +67 -0
  4. package/index.d.ts +822 -38
  5. package/index.js +5 -3
  6. package/package.json +10 -8
  7. package/rescript.json +5 -9
  8. package/src/Address.res +4 -5
  9. package/src/Address.res.mjs +9 -12
  10. package/src/Api.res +15 -0
  11. package/src/Api.res.mjs +20 -0
  12. package/src/Batch.res +32 -34
  13. package/src/Batch.res.mjs +172 -187
  14. package/src/Bin.res +89 -0
  15. package/src/Bin.res.mjs +97 -0
  16. package/src/ChainFetcher.res +33 -57
  17. package/src/ChainFetcher.res.mjs +197 -227
  18. package/src/ChainManager.res +6 -14
  19. package/src/ChainManager.res.mjs +74 -85
  20. package/src/ChainMap.res +14 -16
  21. package/src/ChainMap.res.mjs +38 -38
  22. package/src/Config.res +193 -135
  23. package/src/Config.res.mjs +566 -592
  24. package/src/Core.res +182 -0
  25. package/src/Core.res.mjs +207 -0
  26. package/src/Ecosystem.res +25 -4
  27. package/src/Ecosystem.res.mjs +12 -13
  28. package/src/Env.res +20 -13
  29. package/src/Env.res.mjs +124 -113
  30. package/src/EnvSafe.res +269 -0
  31. package/src/EnvSafe.res.mjs +296 -0
  32. package/src/EnvSafe.resi +18 -0
  33. package/src/Envio.res +37 -26
  34. package/src/Envio.res.mjs +59 -60
  35. package/src/ErrorHandling.res +2 -2
  36. package/src/ErrorHandling.res.mjs +15 -15
  37. package/src/EventConfigBuilder.res +219 -81
  38. package/src/EventConfigBuilder.res.mjs +259 -202
  39. package/src/EventProcessing.res +27 -38
  40. package/src/EventProcessing.res.mjs +165 -183
  41. package/src/EventUtils.res +11 -11
  42. package/src/EventUtils.res.mjs +21 -22
  43. package/src/EvmTypes.res +0 -1
  44. package/src/EvmTypes.res.mjs +5 -5
  45. package/src/FetchState.res +360 -256
  46. package/src/FetchState.res.mjs +958 -914
  47. package/src/GlobalState.res +365 -351
  48. package/src/GlobalState.res.mjs +958 -992
  49. package/src/GlobalStateManager.res +1 -2
  50. package/src/GlobalStateManager.res.mjs +36 -44
  51. package/src/HandlerLoader.res +107 -23
  52. package/src/HandlerLoader.res.mjs +128 -38
  53. package/src/HandlerRegister.res +127 -103
  54. package/src/HandlerRegister.res.mjs +164 -164
  55. package/src/HandlerRegister.resi +12 -4
  56. package/src/Hasura.res +35 -22
  57. package/src/Hasura.res.mjs +158 -167
  58. package/src/InMemoryStore.res +20 -27
  59. package/src/InMemoryStore.res.mjs +64 -80
  60. package/src/InMemoryTable.res +34 -39
  61. package/src/InMemoryTable.res.mjs +165 -170
  62. package/src/Internal.res +52 -33
  63. package/src/Internal.res.mjs +84 -81
  64. package/src/LazyLoader.res.mjs +55 -61
  65. package/src/LoadLayer.res +77 -78
  66. package/src/LoadLayer.res.mjs +160 -189
  67. package/src/LoadManager.res +16 -21
  68. package/src/LoadManager.res.mjs +79 -84
  69. package/src/LogSelection.res +236 -68
  70. package/src/LogSelection.res.mjs +211 -141
  71. package/src/Logging.res +13 -9
  72. package/src/Logging.res.mjs +130 -143
  73. package/src/Main.res +428 -51
  74. package/src/Main.res.mjs +528 -271
  75. package/src/Persistence.res +77 -84
  76. package/src/Persistence.res.mjs +131 -132
  77. package/src/PgStorage.res +291 -167
  78. package/src/PgStorage.res.mjs +797 -817
  79. package/src/Prometheus.res +50 -58
  80. package/src/Prometheus.res.mjs +345 -373
  81. package/src/ReorgDetection.res +22 -24
  82. package/src/ReorgDetection.res.mjs +100 -106
  83. package/src/SafeCheckpointTracking.res +7 -7
  84. package/src/SafeCheckpointTracking.res.mjs +40 -43
  85. package/src/SimulateItems.res +41 -49
  86. package/src/SimulateItems.res.mjs +257 -272
  87. package/src/Sink.res +2 -2
  88. package/src/Sink.res.mjs +22 -26
  89. package/src/TableIndices.res +1 -2
  90. package/src/TableIndices.res.mjs +42 -48
  91. package/src/TestIndexer.res +196 -189
  92. package/src/TestIndexer.res.mjs +536 -536
  93. package/src/TestIndexerProxyStorage.res +15 -16
  94. package/src/TestIndexerProxyStorage.res.mjs +98 -122
  95. package/src/TestIndexerWorker.res +4 -0
  96. package/src/TestIndexerWorker.res.mjs +7 -0
  97. package/src/Throttler.res +3 -3
  98. package/src/Throttler.res.mjs +23 -24
  99. package/src/Time.res +1 -1
  100. package/src/Time.res.mjs +18 -21
  101. package/src/TopicFilter.res +3 -3
  102. package/src/TopicFilter.res.mjs +29 -30
  103. package/src/UserContext.res +93 -54
  104. package/src/UserContext.res.mjs +197 -182
  105. package/src/Utils.res +141 -86
  106. package/src/Utils.res.mjs +334 -295
  107. package/src/bindings/BigDecimal.res +0 -2
  108. package/src/bindings/BigDecimal.res.mjs +19 -23
  109. package/src/bindings/ClickHouse.res +28 -27
  110. package/src/bindings/ClickHouse.res.mjs +243 -240
  111. package/src/bindings/DateFns.res +11 -11
  112. package/src/bindings/DateFns.res.mjs +7 -7
  113. package/src/bindings/EventSource.res.mjs +2 -2
  114. package/src/bindings/Express.res +2 -5
  115. package/src/bindings/Hrtime.res +2 -2
  116. package/src/bindings/Hrtime.res.mjs +30 -32
  117. package/src/bindings/Lodash.res.mjs +1 -1
  118. package/src/bindings/NodeJs.res +14 -9
  119. package/src/bindings/NodeJs.res.mjs +20 -20
  120. package/src/bindings/Pino.res +8 -10
  121. package/src/bindings/Pino.res.mjs +40 -43
  122. package/src/bindings/Postgres.res +2 -5
  123. package/src/bindings/Postgres.res.mjs +9 -9
  124. package/src/bindings/PromClient.res +17 -2
  125. package/src/bindings/PromClient.res.mjs +30 -7
  126. package/src/bindings/SDSL.res.mjs +2 -2
  127. package/src/bindings/Viem.res +4 -4
  128. package/src/bindings/Viem.res.mjs +20 -22
  129. package/src/bindings/Vitest.res +1 -1
  130. package/src/bindings/Vitest.res.mjs +2 -2
  131. package/src/bindings/WebSocket.res +1 -1
  132. package/src/db/EntityHistory.res +9 -3
  133. package/src/db/EntityHistory.res.mjs +84 -59
  134. package/src/db/InternalTable.res +62 -60
  135. package/src/db/InternalTable.res.mjs +271 -203
  136. package/src/db/Schema.res +1 -2
  137. package/src/db/Schema.res.mjs +28 -32
  138. package/src/db/Table.res +28 -27
  139. package/src/db/Table.res.mjs +276 -292
  140. package/src/sources/EventRouter.res +21 -16
  141. package/src/sources/EventRouter.res.mjs +55 -57
  142. package/src/sources/Evm.res +17 -1
  143. package/src/sources/Evm.res.mjs +16 -8
  144. package/src/sources/EvmChain.res +15 -17
  145. package/src/sources/EvmChain.res.mjs +40 -42
  146. package/src/sources/Fuel.res +14 -1
  147. package/src/sources/Fuel.res.mjs +16 -8
  148. package/src/sources/FuelSDK.res +1 -1
  149. package/src/sources/FuelSDK.res.mjs +6 -8
  150. package/src/sources/HyperFuel.res +8 -10
  151. package/src/sources/HyperFuel.res.mjs +113 -123
  152. package/src/sources/HyperFuelClient.res.mjs +6 -7
  153. package/src/sources/HyperFuelSource.res +19 -20
  154. package/src/sources/HyperFuelSource.res.mjs +339 -356
  155. package/src/sources/HyperSync.res +11 -13
  156. package/src/sources/HyperSync.res.mjs +206 -220
  157. package/src/sources/HyperSyncClient.res +5 -7
  158. package/src/sources/HyperSyncClient.res.mjs +70 -75
  159. package/src/sources/HyperSyncHeightStream.res +8 -9
  160. package/src/sources/HyperSyncHeightStream.res.mjs +78 -86
  161. package/src/sources/HyperSyncJsonApi.res +18 -15
  162. package/src/sources/HyperSyncJsonApi.res.mjs +201 -231
  163. package/src/sources/HyperSyncSource.res +17 -21
  164. package/src/sources/HyperSyncSource.res.mjs +268 -290
  165. package/src/sources/Rpc.res +5 -5
  166. package/src/sources/Rpc.res.mjs +168 -192
  167. package/src/sources/RpcSource.res +166 -167
  168. package/src/sources/RpcSource.res.mjs +972 -1046
  169. package/src/sources/RpcWebSocketHeightStream.res +10 -11
  170. package/src/sources/RpcWebSocketHeightStream.res.mjs +131 -145
  171. package/src/sources/SimulateSource.res +1 -1
  172. package/src/sources/SimulateSource.res.mjs +35 -38
  173. package/src/sources/Source.res +1 -1
  174. package/src/sources/Source.res.mjs +3 -3
  175. package/src/sources/SourceManager.res +39 -20
  176. package/src/sources/SourceManager.res.mjs +340 -371
  177. package/src/sources/SourceManager.resi +2 -1
  178. package/src/sources/Svm.res +12 -5
  179. package/src/sources/Svm.res.mjs +44 -41
  180. package/src/tui/Tui.res +23 -12
  181. package/src/tui/Tui.res.mjs +292 -290
  182. package/src/tui/bindings/Ink.res +2 -4
  183. package/src/tui/bindings/Ink.res.mjs +35 -41
  184. package/src/tui/components/BufferedProgressBar.res +7 -7
  185. package/src/tui/components/BufferedProgressBar.res.mjs +46 -46
  186. package/src/tui/components/CustomHooks.res +1 -2
  187. package/src/tui/components/CustomHooks.res.mjs +102 -122
  188. package/src/tui/components/Messages.res +1 -2
  189. package/src/tui/components/Messages.res.mjs +38 -42
  190. package/src/tui/components/SyncETA.res +10 -11
  191. package/src/tui/components/SyncETA.res.mjs +178 -196
  192. package/src/tui/components/TuiData.res +1 -1
  193. package/src/tui/components/TuiData.res.mjs +7 -6
  194. package/src/vendored/Rest.res +52 -66
  195. package/src/vendored/Rest.res.mjs +324 -364
  196. package/svm.schema.json +67 -0
  197. package/src/Address.gen.ts +0 -8
  198. package/src/Config.gen.ts +0 -19
  199. package/src/Envio.gen.ts +0 -55
  200. package/src/EvmTypes.gen.ts +0 -6
  201. package/src/InMemoryStore.gen.ts +0 -6
  202. package/src/Internal.gen.ts +0 -64
  203. package/src/PgStorage.gen.ts +0 -10
  204. package/src/PgStorage.res.d.mts +0 -5
  205. package/src/Types.ts +0 -56
  206. package/src/bindings/BigDecimal.gen.ts +0 -14
  207. package/src/bindings/BigDecimal.res.d.mts +0 -5
  208. package/src/bindings/BigInt.gen.ts +0 -10
  209. package/src/bindings/BigInt.res +0 -70
  210. package/src/bindings/BigInt.res.d.mts +0 -5
  211. package/src/bindings/BigInt.res.mjs +0 -154
  212. package/src/bindings/Ethers.res.d.mts +0 -5
  213. package/src/bindings/Pino.gen.ts +0 -17
  214. package/src/bindings/Postgres.gen.ts +0 -8
  215. package/src/bindings/Postgres.res.d.mts +0 -5
  216. package/src/bindings/Promise.res +0 -67
  217. package/src/bindings/Promise.res.mjs +0 -26
  218. package/src/db/InternalTable.gen.ts +0 -36
  219. package/src/sources/HyperSyncClient.gen.ts +0 -19
@@ -4,9 +4,8 @@ import * as Utils from "./Utils.res.mjs";
4
4
  import * as Hrtime from "./bindings/Hrtime.res.mjs";
5
5
  import * as Logging from "./Logging.res.mjs";
6
6
  import * as Internal from "./Internal.res.mjs";
7
- import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
7
+ import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
8
8
  import * as Prometheus from "./Prometheus.res.mjs";
9
- import * as Caml_option from "rescript/lib/es6/caml_option.js";
10
9
  import * as LoadManager from "./LoadManager.res.mjs";
11
10
  import * as Persistence from "./Persistence.res.mjs";
12
11
  import * as TableIndices from "./TableIndices.res.mjs";
@@ -14,90 +13,82 @@ import * as ErrorHandling from "./ErrorHandling.res.mjs";
14
13
  import * as InMemoryStore from "./InMemoryStore.res.mjs";
15
14
  import * as InMemoryTable from "./InMemoryTable.res.mjs";
16
15
  import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
17
- import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
16
+ import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
18
17
 
19
18
  function loadById(loadManager, persistence, entityConfig, inMemoryStore, shouldGroup, item, entityId) {
20
- var key = entityConfig.name + ".get";
21
- var inMemTable = InMemoryStore.getInMemTable(inMemoryStore, entityConfig);
22
- var load = async function (idsToLoad, param) {
23
- var timerRef = Prometheus.StorageLoad.startOperation(key);
24
- var dbEntities;
19
+ let key = entityConfig.name + `.get`;
20
+ let inMemTable = InMemoryStore.getInMemTable(inMemoryStore, entityConfig);
21
+ let load = async (idsToLoad, param) => {
22
+ let storage = Persistence.getInitializedStorageOrThrow(persistence);
23
+ let timerRef = Prometheus.StorageLoad.startOperation(storage.name, key);
24
+ let dbEntities;
25
25
  try {
26
- dbEntities = await Persistence.getInitializedStorageOrThrow(persistence).loadByIdsOrThrow(idsToLoad, entityConfig.table, entityConfig.rowsSchema);
27
- }
28
- catch (raw_exn){
29
- var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
26
+ dbEntities = await storage.loadByIdsOrThrow(idsToLoad, entityConfig.table, entityConfig.rowsSchema);
27
+ } catch (raw_exn) {
28
+ let exn = Primitive_exceptions.internalToException(raw_exn);
30
29
  if (exn.RE_EXN_ID === Persistence.StorageError) {
31
30
  dbEntities = ErrorHandling.mkLogAndRaise(Logging.getItemLogger(item), exn.message, exn.reason);
32
31
  } else {
33
32
  throw exn;
34
33
  }
35
34
  }
36
- var entitiesMap = {};
37
- for(var idx = 0 ,idx_finish = dbEntities.length; idx < idx_finish; ++idx){
38
- var entity = dbEntities[idx];
35
+ let entitiesMap = {};
36
+ for (let idx = 0, idx_finish = dbEntities.length; idx < idx_finish; ++idx) {
37
+ let entity = dbEntities[idx];
39
38
  entitiesMap[entity.id] = entity;
40
39
  }
41
- idsToLoad.forEach(function (entityId) {
42
- InMemoryTable.Entity.initValue(inMemTable, entityId, entitiesMap[entityId], false);
43
- });
44
- return Prometheus.StorageLoad.endOperation(timerRef, key, idsToLoad.length, dbEntities.length);
40
+ idsToLoad.forEach(entityId => InMemoryTable.Entity.initValue(inMemTable, entityId, entitiesMap[entityId], false));
41
+ return Prometheus.StorageLoad.endOperation(timerRef, storage.name, key, idsToLoad.length, dbEntities.length);
45
42
  };
46
- return LoadManager.call(loadManager, entityId, key, load, LoadManager.noopHasher, shouldGroup, (function (hash) {
47
- return InMemoryTable.hasByHash(inMemTable.table, hash);
48
- }), InMemoryTable.Entity.getUnsafe(inMemTable));
43
+ return LoadManager.call(loadManager, entityId, key, load, LoadManager.noopHasher, shouldGroup, hash => InMemoryTable.hasByHash(inMemTable.table, hash), InMemoryTable.Entity.getUnsafe(inMemTable));
49
44
  }
50
45
 
51
46
  function callEffect(effect, arg, inMemTable, timerRef, onError) {
52
- var effectName = effect.name;
53
- var hadActiveCalls = effect.activeCallsCount > 0;
47
+ let effectName = effect.name;
48
+ let hadActiveCalls = effect.activeCallsCount > 0;
54
49
  effect.activeCallsCount = effect.activeCallsCount + 1 | 0;
55
50
  Prometheus.SafeGauge.handleInt(Prometheus.EffectCalls.activeCallsCount, effectName, effect.activeCallsCount);
56
51
  if (hadActiveCalls) {
57
- var elapsed = Hrtime.secondsBetween(effect.prevCallStartTimerRef, timerRef);
52
+ let elapsed = Hrtime.secondsBetween(effect.prevCallStartTimerRef, timerRef);
58
53
  if (elapsed > 0) {
59
54
  Prometheus.SafeCounter.handleFloat(Prometheus.EffectCalls.timeCounter, effectName, elapsed);
60
55
  }
61
-
62
56
  }
63
57
  effect.prevCallStartTimerRef = timerRef;
64
- return effect.handler(arg).then(function (output) {
65
- inMemTable.dict[arg.cacheKey] = output;
66
- if (arg.context.cache) {
67
- inMemTable.idsToStore.push(arg.cacheKey);
68
- return ;
69
- }
70
-
71
- }).catch(function (exn) {
72
- onError(arg.cacheKey, exn);
73
- }).finally(function () {
74
- effect.activeCallsCount = effect.activeCallsCount - 1 | 0;
75
- Prometheus.SafeGauge.handleInt(Prometheus.EffectCalls.activeCallsCount, effectName, effect.activeCallsCount);
76
- var newTimer = Hrtime.makeTimer();
77
- Prometheus.SafeCounter.handleFloat(Prometheus.EffectCalls.timeCounter, effectName, Hrtime.secondsBetween(effect.prevCallStartTimerRef, newTimer));
78
- effect.prevCallStartTimerRef = newTimer;
79
- Prometheus.SafeCounter.increment(Prometheus.EffectCalls.totalCallsCount, effectName);
80
- Prometheus.SafeCounter.handleFloat(Prometheus.EffectCalls.sumTimeCounter, effectName, Hrtime.toSecondsFloat(Hrtime.timeSince(timerRef)));
81
- });
58
+ return effect.handler(arg).then(output => {
59
+ inMemTable.dict[arg.cacheKey] = output;
60
+ if (arg.context.cache) {
61
+ inMemTable.idsToStore.push(arg.cacheKey);
62
+ return;
63
+ }
64
+ }).catch(exn => onError(arg.cacheKey, exn)).finally(() => {
65
+ effect.activeCallsCount = effect.activeCallsCount - 1 | 0;
66
+ Prometheus.SafeGauge.handleInt(Prometheus.EffectCalls.activeCallsCount, effectName, effect.activeCallsCount);
67
+ let newTimer = Hrtime.makeTimer();
68
+ Prometheus.SafeCounter.handleFloat(Prometheus.EffectCalls.timeCounter, effectName, Hrtime.secondsBetween(effect.prevCallStartTimerRef, newTimer));
69
+ effect.prevCallStartTimerRef = newTimer;
70
+ Prometheus.SafeCounter.increment(Prometheus.EffectCalls.totalCallsCount, effectName);
71
+ Prometheus.SafeCounter.handleFloat(Prometheus.EffectCalls.sumTimeCounter, effectName, Hrtime.toSecondsFloat(Hrtime.timeSince(timerRef)));
72
+ });
82
73
  }
83
74
 
84
75
  function executeWithRateLimit(effect, effectArgs, inMemTable, onError, isFromQueue) {
85
- var effectName = effect.name;
86
- var timerRef = Hrtime.makeTimer();
87
- var promises = [];
88
- var state = effect.rateLimit;
76
+ let effectName = effect.name;
77
+ let timerRef = Hrtime.makeTimer();
78
+ let promises = [];
79
+ let state = effect.rateLimit;
89
80
  if (state !== undefined) {
90
- var now = Date.now();
81
+ let now = Date.now();
91
82
  if (now >= state.windowStartTime + state.durationMs) {
92
83
  state.availableCalls = state.callsPerDuration;
93
84
  state.windowStartTime = now;
94
85
  state.nextWindowPromise = undefined;
95
86
  }
96
- var immediateCount = Math.min(state.availableCalls, effectArgs.length);
97
- var immediateArgs = Belt_Array.slice(effectArgs, 0, immediateCount);
98
- var queuedArgs = Belt_Array.sliceToEnd(effectArgs, immediateCount);
87
+ let immediateCount = Math.min(state.availableCalls, effectArgs.length);
88
+ let immediateArgs = Belt_Array.slice(effectArgs, 0, immediateCount);
89
+ let queuedArgs = Belt_Array.sliceToEnd(effectArgs, immediateCount);
99
90
  state.availableCalls = state.availableCalls - immediateCount | 0;
100
- for(var idx = 0 ,idx_finish = immediateArgs.length; idx < idx_finish; ++idx){
91
+ for (let idx = 0, idx_finish = immediateArgs.length; idx < idx_finish; ++idx) {
101
92
  promises.push(callEffect(effect, immediateArgs[idx], inMemTable, timerRef, onError));
102
93
  }
103
94
  if (immediateCount > 0 && isFromQueue) {
@@ -109,29 +100,28 @@ function executeWithRateLimit(effect, effectArgs, inMemTable, onError, isFromQue
109
100
  state.queueCount = state.queueCount + queuedArgs.length | 0;
110
101
  Prometheus.EffectQueueCount.set(state.queueCount, effectName);
111
102
  }
112
- var millisUntilReset = {
103
+ let millisUntilReset = {
113
104
  contents: 0
114
105
  };
115
- var p = state.nextWindowPromise;
116
- var nextWindowPromise;
106
+ let p = state.nextWindowPromise;
107
+ let nextWindowPromise;
117
108
  if (p !== undefined) {
118
- nextWindowPromise = Caml_option.valFromOption(p);
109
+ nextWindowPromise = p;
119
110
  } else {
120
111
  millisUntilReset.contents = state.windowStartTime + state.durationMs - now | 0;
121
- var p$1 = Utils.delay(millisUntilReset.contents);
122
- state.nextWindowPromise = Caml_option.some(p$1);
112
+ let p$1 = Utils.delay(millisUntilReset.contents);
113
+ state.nextWindowPromise = p$1;
123
114
  nextWindowPromise = p$1;
124
115
  }
125
- promises.push(nextWindowPromise.then(function () {
126
- if (millisUntilReset.contents > 0) {
127
- Prometheus.SafeCounter.handleFloat(Prometheus.EffectQueueCount.timeCounter, effectName, millisUntilReset.contents / 1000);
128
- }
129
- return executeWithRateLimit(effect, queuedArgs, inMemTable, onError, true);
130
- }));
116
+ promises.push(nextWindowPromise.then(() => {
117
+ if (millisUntilReset.contents > 0) {
118
+ Prometheus.SafeCounter.handleFloat(Prometheus.EffectQueueCount.timeCounter, effectName, millisUntilReset.contents / 1000);
119
+ }
120
+ return executeWithRateLimit(effect, queuedArgs, inMemTable, onError, true);
121
+ }));
131
122
  }
132
-
133
123
  } else {
134
- for(var idx$1 = 0 ,idx_finish$1 = effectArgs.length; idx$1 < idx_finish$1; ++idx$1){
124
+ for (let idx$1 = 0, idx_finish$1 = effectArgs.length; idx$1 < idx_finish$1; ++idx$1) {
135
125
  promises.push(callEffect(effect, effectArgs[idx$1], inMemTable, timerRef, onError));
136
126
  }
137
127
  }
@@ -139,158 +129,139 @@ function executeWithRateLimit(effect, effectArgs, inMemTable, onError, isFromQue
139
129
  }
140
130
 
141
131
  function loadEffect(loadManager, persistence, effect, effectArgs, inMemoryStore, shouldGroup, item) {
142
- var effectName = effect.name;
143
- var key = effectName + ".effect";
144
- var inMemTable = InMemoryStore.getEffectInMemTable(inMemoryStore, effect);
145
- var load = async function (args, onError) {
146
- var idsToLoad = args.map(function (arg) {
147
- return arg.cacheKey;
148
- });
149
- var idsFromCache = new Set();
150
- var match = persistence.storageStatus;
151
- var tmp;
132
+ let effectName = effect.name;
133
+ let key = effectName + `.effect`;
134
+ let inMemTable = InMemoryStore.getEffectInMemTable(inMemoryStore, effect);
135
+ let load = async (args, onError) => {
136
+ let idsToLoad = args.map(arg => arg.cacheKey);
137
+ let idsFromCache = new Set();
138
+ let match = persistence.storageStatus;
139
+ let tmp;
152
140
  tmp = typeof match !== "object" || match.TAG === "Initializing" ? false : Utils.Dict.has(match._0.cache, effectName);
153
141
  if (tmp) {
154
- var timerRef = Prometheus.StorageLoad.startOperation(key);
155
- var match$1 = effect.storageMeta;
156
- var outputSchema = match$1.outputSchema;
157
- var dbEntities;
142
+ let storage = Persistence.getInitializedStorageOrThrow(persistence);
143
+ let timerRef = Prometheus.StorageLoad.startOperation(storage.name, key);
144
+ let match$1 = effect.storageMeta;
145
+ let outputSchema = match$1.outputSchema;
146
+ let dbEntities;
158
147
  try {
159
- dbEntities = await Persistence.getInitializedStorageOrThrow(persistence).loadByIdsOrThrow(idsToLoad, match$1.table, Internal.effectCacheItemRowsSchema);
160
- }
161
- catch (raw_exn){
162
- var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
148
+ dbEntities = await storage.loadByIdsOrThrow(idsToLoad, match$1.table, Internal.effectCacheItemRowsSchema);
149
+ } catch (raw_exn) {
150
+ let exn = Primitive_exceptions.internalToException(raw_exn);
163
151
  Logging.childWarn(Logging.getItemLogger(item), {
164
- msg: "Failed to load cache effect cache. The indexer will continue working, but the effect will not be able to use the cache.",
165
- err: Utils.prettifyExn(exn),
166
- effect: effectName
167
- });
152
+ msg: `Failed to load cache effect cache. The indexer will continue working, but the effect will not be able to use the cache.`,
153
+ err: Utils.prettifyExn(exn),
154
+ effect: effectName
155
+ });
168
156
  dbEntities = [];
169
157
  }
170
- dbEntities.forEach(function (dbEntity) {
171
- try {
172
- var output = S$RescriptSchema.parseOrThrow(dbEntity.output, outputSchema);
173
- idsFromCache.add(dbEntity.id);
174
- inMemTable.dict[dbEntity.id] = output;
175
- return ;
176
- }
177
- catch (raw_error){
178
- var error = Caml_js_exceptions.internalToOCamlException(raw_error);
179
- if (error.RE_EXN_ID === S$RescriptSchema.Raised) {
180
- inMemTable.invalidationsCount = inMemTable.invalidationsCount + 1 | 0;
181
- Prometheus.EffectCacheInvalidationsCount.increment(effectName);
182
- return Logging.childTrace(Logging.getItemLogger(item), {
183
- msg: "Invalidated effect cache",
184
- input: dbEntity.id,
185
- effect: effectName,
186
- err: S$RescriptSchema.$$Error.message(error._1)
187
- });
188
- }
189
- throw error;
190
- }
191
- });
192
- Prometheus.StorageLoad.endOperation(timerRef, key, idsToLoad.length, dbEntities.length);
158
+ dbEntities.forEach(dbEntity => {
159
+ try {
160
+ let output = S$RescriptSchema.parseOrThrow(dbEntity.output, outputSchema);
161
+ idsFromCache.add(dbEntity.id);
162
+ inMemTable.dict[dbEntity.id] = output;
163
+ return;
164
+ } catch (raw_error) {
165
+ let error = Primitive_exceptions.internalToException(raw_error);
166
+ if (error.RE_EXN_ID === S$RescriptSchema.Raised) {
167
+ inMemTable.invalidationsCount = inMemTable.invalidationsCount + 1 | 0;
168
+ Prometheus.EffectCacheInvalidationsCount.increment(effectName);
169
+ return Logging.childTrace(Logging.getItemLogger(item), {
170
+ msg: "Invalidated effect cache",
171
+ input: dbEntity.id,
172
+ effect: effectName,
173
+ err: S$RescriptSchema.$$Error.message(error._1)
174
+ });
175
+ }
176
+ throw error;
177
+ }
178
+ });
179
+ Prometheus.StorageLoad.endOperation(timerRef, storage.name, key, idsToLoad.length, dbEntities.length);
193
180
  }
194
- var remainingCallsCount = idsToLoad.length - idsFromCache.size | 0;
181
+ let remainingCallsCount = idsToLoad.length - idsFromCache.size | 0;
195
182
  if (remainingCallsCount <= 0) {
196
- return ;
183
+ return;
197
184
  }
198
- var argsToCall = [];
199
- for(var idx = 0 ,idx_finish = args.length; idx < idx_finish; ++idx){
200
- var arg = args[idx];
185
+ let argsToCall = [];
186
+ for (let idx = 0, idx_finish = args.length; idx < idx_finish; ++idx) {
187
+ let arg = args[idx];
201
188
  if (!idsFromCache.has(arg.cacheKey)) {
202
189
  argsToCall.push(arg);
203
190
  }
204
-
205
191
  }
206
192
  if (Utils.$$Array.notEmpty(argsToCall)) {
207
193
  return await executeWithRateLimit(effect, argsToCall, inMemTable, onError, false);
208
194
  }
209
-
210
195
  };
211
- return LoadManager.call(loadManager, effectArgs, key, load, (function (args) {
212
- return args.cacheKey;
213
- }), shouldGroup, (function (hash) {
214
- return Utils.Dict.has(inMemTable.dict, hash);
215
- }), (function (hash) {
216
- return inMemTable.dict[hash];
217
- }));
196
+ return LoadManager.call(loadManager, effectArgs, key, load, args => args.cacheKey, shouldGroup, hash => Utils.Dict.has(inMemTable.dict, hash), hash => inMemTable.dict[hash]);
218
197
  }
219
198
 
220
199
  function loadByField(loadManager, persistence, operator, entityConfig, inMemoryStore, fieldName, fieldValueSchema, shouldGroup, item, fieldValue) {
221
- var operatorCallName;
200
+ let operatorCallName;
222
201
  switch (operator) {
223
202
  case "Eq" :
224
- operatorCallName = "eq";
225
- break;
203
+ operatorCallName = "eq";
204
+ break;
226
205
  case "Gt" :
227
- operatorCallName = "gt";
228
- break;
206
+ operatorCallName = "gt";
207
+ break;
229
208
  case "Lt" :
230
- operatorCallName = "lt";
231
- break;
232
-
209
+ operatorCallName = "lt";
210
+ break;
233
211
  }
234
- var key = entityConfig.name + ".getWhere." + fieldName + "." + operatorCallName;
235
- var inMemTable = InMemoryStore.getInMemTable(inMemoryStore, entityConfig);
236
- var load = async function (fieldValues, param) {
237
- var timerRef = Prometheus.StorageLoad.startOperation(key);
238
- var size = {
212
+ let key = entityConfig.name + `.getWhere.` + fieldName + `.` + operatorCallName;
213
+ let inMemTable = InMemoryStore.getInMemTable(inMemoryStore, entityConfig);
214
+ let load = async (fieldValues, param) => {
215
+ let storage = Persistence.getInitializedStorageOrThrow(persistence);
216
+ let timerRef = Prometheus.StorageLoad.startOperation(storage.name, key);
217
+ let size = {
239
218
  contents: 0
240
219
  };
241
- var indiciesToLoad = fieldValues.map(function (fieldValue) {
242
- return {
243
- fieldName: fieldName,
244
- fieldValue: fieldValue,
245
- operator: operator
246
- };
247
- });
248
- await Promise.all(indiciesToLoad.map(async function (index) {
249
- InMemoryTable.Entity.addEmptyIndex(inMemTable, index);
250
- try {
251
- var tmp;
252
- switch (index.operator) {
253
- case "Eq" :
254
- tmp = "=";
255
- break;
256
- case "Gt" :
257
- tmp = ">";
258
- break;
259
- case "Lt" :
260
- tmp = "<";
261
- break;
262
-
263
- }
264
- var entities = await Persistence.getInitializedStorageOrThrow(persistence).loadByFieldOrThrow(TableIndices.Index.getFieldName(index), fieldValueSchema, index.fieldValue, tmp, entityConfig.table, entityConfig.rowsSchema);
265
- Belt_Array.forEach(entities, (function (entity) {
266
- InMemoryTable.Entity.initValue(inMemTable, entity.id, entity, false);
267
- }));
268
- size.contents = size.contents + entities.length | 0;
269
- return ;
270
- }
271
- catch (raw_exn){
272
- var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
273
- if (exn.RE_EXN_ID === Persistence.StorageError) {
274
- return ErrorHandling.mkLogAndRaise(Logging.createChildFrom(Logging.getItemLogger(item), {
275
- operator: operatorCallName,
276
- tableName: entityConfig.table.tableName,
277
- fieldName: fieldName,
278
- fieldValue: fieldValue
279
- }), exn.message, exn.reason);
280
- }
281
- throw exn;
282
- }
283
- }));
284
- return Prometheus.StorageLoad.endOperation(timerRef, key, fieldValues.length, size.contents);
220
+ let indiciesToLoad = fieldValues.map(fieldValue => ({
221
+ fieldName: fieldName,
222
+ fieldValue: fieldValue,
223
+ operator: operator
224
+ }));
225
+ await Promise.all(indiciesToLoad.map(async index => {
226
+ InMemoryTable.Entity.addEmptyIndex(inMemTable, index);
227
+ try {
228
+ let tmp;
229
+ switch (index.operator) {
230
+ case "Eq" :
231
+ tmp = "=";
232
+ break;
233
+ case "Gt" :
234
+ tmp = ">";
235
+ break;
236
+ case "Lt" :
237
+ tmp = "<";
238
+ break;
239
+ }
240
+ let entities = await storage.loadByFieldOrThrow(TableIndices.Index.getFieldName(index), fieldValueSchema, index.fieldValue, tmp, entityConfig.table, entityConfig.rowsSchema);
241
+ entities.forEach(entity => InMemoryTable.Entity.initValue(inMemTable, entity.id, entity, false));
242
+ size.contents = size.contents + entities.length | 0;
243
+ return;
244
+ } catch (raw_exn) {
245
+ let exn = Primitive_exceptions.internalToException(raw_exn);
246
+ if (exn.RE_EXN_ID === Persistence.StorageError) {
247
+ return ErrorHandling.mkLogAndRaise(Logging.createChildFrom(Logging.getItemLogger(item), {
248
+ operator: operatorCallName,
249
+ tableName: entityConfig.table.tableName,
250
+ fieldName: fieldName,
251
+ fieldValue: fieldValue
252
+ }), exn.message, exn.reason);
253
+ }
254
+ throw exn;
255
+ }
256
+ }));
257
+ return Prometheus.StorageLoad.endOperation(timerRef, storage.name, key, fieldValues.length, size.contents);
285
258
  };
286
- return LoadManager.call(loadManager, fieldValue, key, load, (function (fieldValue) {
287
- return TableIndices.FieldValue.toString(fieldValue);
288
- }), shouldGroup, InMemoryTable.Entity.hasIndex(inMemTable, fieldName, operator), InMemoryTable.Entity.getUnsafeOnIndex(inMemTable, fieldName, operator));
259
+ return LoadManager.call(loadManager, fieldValue, key, load, fieldValue => TableIndices.FieldValue.toString(fieldValue), shouldGroup, InMemoryTable.Entity.hasIndex(inMemTable, fieldName, operator), InMemoryTable.Entity.getUnsafeOnIndex(inMemTable, fieldName, operator));
289
260
  }
290
261
 
291
262
  export {
292
- loadById ,
293
- loadByField ,
294
- loadEffect ,
263
+ loadById,
264
+ loadByField,
265
+ loadEffect,
295
266
  }
296
267
  /* Utils Not a pure module */
@@ -1,5 +1,3 @@
1
- open Belt
2
-
3
1
  module Call = {
4
2
  type input
5
3
  type output
@@ -31,7 +29,7 @@ type t = {
31
29
  }
32
30
 
33
31
  let make = () => {
34
- groups: Js.Dict.empty(),
32
+ groups: Dict.make(),
35
33
  isCollecting: false,
36
34
  }
37
35
 
@@ -47,22 +45,19 @@ let schedule = async loadManager => {
47
45
 
48
46
  let groups = loadManager.groups
49
47
  groups
50
- ->Js.Dict.keys
48
+ ->Dict.keysToArray
51
49
  ->Utils.Array.forEachAsync(async key => {
52
- let group = groups->Js.Dict.unsafeGet(key)
50
+ let group = groups->Dict.getUnsafe(key)
53
51
  let calls = group.calls
54
52
 
55
53
  let inputsToLoad = []
56
54
  let currentInputKeys = []
57
- calls
58
- ->Js.Dict.keys
59
- ->Js.Array2.forEach(inputKey => {
60
- let call = calls->Js.Dict.unsafeGet(inputKey)
55
+ calls->Utils.Dict.forEachWithKey((call, inputKey) => {
61
56
  if !call.isLoading {
62
57
  call.isLoading = true
63
- currentInputKeys->Js.Array2.push(inputKey)->ignore
58
+ currentInputKeys->Array.push(inputKey)->ignore
64
59
  if group.hasInMemory(inputKey)->not {
65
- inputsToLoad->Js.Array2.push(call.input)->ignore
60
+ inputsToLoad->Array.push(call.input)->ignore
66
61
  }
67
62
  }
68
63
  })
@@ -70,14 +65,14 @@ let schedule = async loadManager => {
70
65
  if inputsToLoad->Utils.Array.isEmpty->not {
71
66
  try {
72
67
  await group.load(inputsToLoad, ~onError=(~inputKey, ~exn) => {
73
- let call = calls->Js.Dict.unsafeGet(inputKey)
68
+ let call = calls->Dict.getUnsafe(inputKey)
74
69
  call.exn = Some(exn)
75
70
  })
76
71
  } catch {
77
72
  | exn => {
78
73
  let exn = exn->Utils.prettifyExn
79
74
  currentInputKeys->Array.forEach(inputKey => {
80
- let call = calls->Js.Dict.unsafeGet(inputKey)
75
+ let call = calls->Dict.getUnsafe(inputKey)
81
76
  call.exn = Some(exn)
82
77
  })
83
78
  }
@@ -85,8 +80,8 @@ let schedule = async loadManager => {
85
80
  }
86
81
 
87
82
  if currentInputKeys->Utils.Array.isEmpty->not {
88
- currentInputKeys->Js.Array2.forEach(inputKey => {
89
- let call = calls->Js.Dict.unsafeGet(inputKey)
83
+ currentInputKeys->Array.forEach(inputKey => {
84
+ let call = calls->Dict.getUnsafe(inputKey)
90
85
  calls->Utils.Dict.deleteInPlace(inputKey)
91
86
  switch call.exn {
92
87
  | Some(exn) => call.reject(exn->Utils.prettifyExn)
@@ -97,8 +92,8 @@ let schedule = async loadManager => {
97
92
  // Clean up executed batch to reset
98
93
  // provided load function which
99
94
  // might have an outdated function context
100
- let latestGroup = groups->Js.Dict.unsafeGet(key)
101
- if latestGroup.calls->Js.Dict.keys->Utils.Array.isEmpty {
95
+ let latestGroup = groups->Dict.getUnsafe(key)
96
+ if latestGroup.calls->Utils.Dict.isEmpty {
102
97
  groups->Utils.Dict.deleteInPlace(key)
103
98
  }
104
99
  }
@@ -144,7 +139,7 @@ let call = (
144
139
  | Some(group) => group
145
140
  | None => {
146
141
  let g: Group.t = {
147
- calls: Js.Dict.empty(),
142
+ calls: Dict.make(),
148
143
  load: load->(
149
144
  Utils.magic: (
150
145
  (array<'input>, ~onError: (~inputKey: string, ~exn: exn) => unit) => promise<unit>
@@ -158,7 +153,7 @@ let call = (
158
153
  ),
159
154
  hasInMemory: hasInMemory->(Utils.magic: (string => bool) => string => bool),
160
155
  }
161
- loadManager.groups->Js.Dict.set(key, g)
156
+ loadManager.groups->Dict.set(key, g)
162
157
  g
163
158
  }
164
159
  }
@@ -175,11 +170,11 @@ let call = (
175
170
  exn: None,
176
171
  isLoading: false,
177
172
  }
178
- group.calls->Js.Dict.set(inputKey, call)
173
+ group.calls->Dict.set(inputKey, call)
179
174
  })
180
175
 
181
176
  // Don't use ref since it'll allocate an object to store .contents
182
- (group.calls->Js.Dict.unsafeGet(inputKey)).promise = promise
177
+ (group.calls->Dict.getUnsafe(inputKey)).promise = promise
183
178
 
184
179
  if !loadManager.isCollecting {
185
180
  let _: promise<unit> = loadManager->schedule