envio 2.32.3 → 3.0.0-alpha.0

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 (115) hide show
  1. package/bin.js +5 -3
  2. package/evm.schema.json +23 -6
  3. package/fuel.schema.json +17 -5
  4. package/index.d.ts +1 -27
  5. package/index.js +9 -6
  6. package/package.json +12 -7
  7. package/rescript.json +4 -3
  8. package/src/{Address.res.js → Address.res.mjs} +7 -6
  9. package/src/Batch.res +4 -4
  10. package/src/{Batch.res.js → Batch.res.mjs} +19 -18
  11. package/src/{ChainMap.res.js → ChainMap.res.mjs} +20 -19
  12. package/src/Change.res +9 -0
  13. package/src/Config.res +5 -5
  14. package/src/{Config.res.js → Config.res.mjs} +13 -10
  15. package/src/Envio.gen.ts +4 -17
  16. package/src/Envio.res +13 -38
  17. package/src/{Envio.res.js → Envio.res.mjs} +5 -16
  18. package/src/{ErrorHandling.res.js → ErrorHandling.res.mjs} +10 -9
  19. package/src/EventRegister.res +10 -11
  20. package/src/{EventRegister.res.js → EventRegister.res.mjs} +33 -26
  21. package/src/EventRegister.resi +2 -1
  22. package/src/{EventUtils.res.js → EventUtils.res.mjs} +10 -9
  23. package/src/{EvmTypes.res.js → EvmTypes.res.mjs} +5 -4
  24. package/src/{FetchState.res.js → FetchState.res.mjs} +44 -43
  25. package/src/{Hasura.res.js → Hasura.res.mjs} +25 -24
  26. package/src/InMemoryStore.res +7 -15
  27. package/src/{InMemoryStore.res.js → InMemoryStore.res.mjs} +21 -22
  28. package/src/InMemoryTable.res +50 -35
  29. package/src/{InMemoryTable.res.js → InMemoryTable.res.mjs} +73 -104
  30. package/src/Internal.gen.ts +1 -5
  31. package/src/Internal.res +29 -40
  32. package/src/Internal.res.mjs +58 -0
  33. package/src/{LazyLoader.res.js → LazyLoader.res.mjs} +14 -13
  34. package/src/{LoadManager.res.js → LoadManager.res.mjs} +11 -10
  35. package/src/{LogSelection.res.js → LogSelection.res.mjs} +14 -13
  36. package/src/{Logging.res.js → Logging.res.mjs} +37 -36
  37. package/src/Persistence.res +190 -38
  38. package/src/Persistence.res.mjs +213 -0
  39. package/src/PgStorage.res +700 -14
  40. package/src/{PgStorage.res.js → PgStorage.res.mjs} +478 -65
  41. package/src/Platform.res +140 -0
  42. package/src/Platform.res.mjs +170 -0
  43. package/src/Prometheus.res +41 -0
  44. package/src/{Prometheus.res.js → Prometheus.res.mjs} +106 -60
  45. package/src/{ReorgDetection.res.js → ReorgDetection.res.mjs} +12 -11
  46. package/src/SafeCheckpointTracking.res +5 -4
  47. package/src/{SafeCheckpointTracking.res.js → SafeCheckpointTracking.res.mjs} +6 -5
  48. package/src/Sink.res +47 -0
  49. package/src/Sink.res.mjs +37 -0
  50. package/src/{TableIndices.res.js → TableIndices.res.mjs} +8 -7
  51. package/src/{Throttler.res.js → Throttler.res.mjs} +7 -6
  52. package/src/{Time.res.js → Time.res.mjs} +8 -7
  53. package/src/{TopicFilter.res.js → TopicFilter.res.mjs} +18 -17
  54. package/src/Utils.res +42 -0
  55. package/src/{Utils.res.js → Utils.res.mjs} +71 -34
  56. package/src/bindings/BigDecimal.gen.ts +2 -2
  57. package/src/bindings/BigDecimal.res +5 -5
  58. package/src/bindings/BigDecimal.res.d.mts +5 -0
  59. package/src/bindings/{BigDecimal.res.js → BigDecimal.res.mjs} +10 -9
  60. package/src/bindings/BigInt.gen.ts +2 -2
  61. package/src/bindings/BigInt.res.d.mts +5 -0
  62. package/src/bindings/{BigInt.res.js → BigInt.res.mjs} +25 -24
  63. package/src/bindings/ClickHouse.res +387 -0
  64. package/src/bindings/ClickHouse.res.mjs +275 -0
  65. package/src/bindings/Ethers.gen.ts +2 -2
  66. package/src/bindings/Ethers.res.d.mts +5 -0
  67. package/src/bindings/{Ethers.res.js → Ethers.res.mjs} +18 -17
  68. package/src/bindings/Express.res.mjs +2 -0
  69. package/src/bindings/{Hrtime.res.js → Hrtime.res.mjs} +13 -12
  70. package/src/bindings/{Lodash.res.js → Lodash.res.mjs} +4 -3
  71. package/src/bindings/NodeJs.res +13 -1
  72. package/src/bindings/NodeJs.res.mjs +48 -0
  73. package/src/bindings/Pino.res +4 -4
  74. package/src/bindings/{Pino.res.js → Pino.res.mjs} +16 -15
  75. package/src/bindings/Postgres.res +17 -2
  76. package/src/bindings/{Postgres.res.js → Postgres.res.mjs} +4 -3
  77. package/src/bindings/{PromClient.res.js → PromClient.res.mjs} +6 -5
  78. package/src/bindings/{Promise.res.js → Promise.res.mjs} +6 -5
  79. package/src/bindings/{SDSL.res.js → SDSL.res.mjs} +3 -2
  80. package/src/bindings/{Viem.res.js → Viem.res.mjs} +9 -8
  81. package/src/bindings/vendored-lodash-fns.js +3 -35
  82. package/src/db/EntityHistory.res +33 -156
  83. package/src/db/EntityHistory.res.mjs +121 -0
  84. package/src/db/InternalTable.gen.ts +2 -2
  85. package/src/db/InternalTable.res +55 -56
  86. package/src/db/{InternalTable.res.js → InternalTable.res.mjs} +68 -71
  87. package/src/db/{Schema.res.js → Schema.res.mjs} +10 -9
  88. package/src/db/Table.res +86 -22
  89. package/src/db/{Table.res.js → Table.res.mjs} +108 -40
  90. package/src/sources/{EventRouter.res.js → EventRouter.res.mjs} +17 -16
  91. package/src/sources/{Fuel.res.js → Fuel.res.mjs} +6 -5
  92. package/src/sources/{HyperFuel.res.js → HyperFuel.res.mjs} +14 -13
  93. package/src/sources/{HyperFuelClient.res.js → HyperFuelClient.res.mjs} +7 -6
  94. package/src/sources/{HyperFuelSource.res.js → HyperFuelSource.res.mjs} +28 -27
  95. package/src/sources/{HyperSync.res.js → HyperSync.res.mjs} +21 -20
  96. package/src/sources/HyperSyncClient.gen.ts +1 -1
  97. package/src/sources/HyperSyncClient.res +78 -20
  98. package/src/sources/{HyperSyncClient.res.js → HyperSyncClient.res.mjs} +32 -15
  99. package/src/sources/{HyperSyncJsonApi.res.js → HyperSyncJsonApi.res.mjs} +10 -9
  100. package/src/sources/HyperSyncSource.res +77 -9
  101. package/src/sources/{HyperSyncSource.res.js → HyperSyncSource.res.mjs} +99 -38
  102. package/src/sources/{Rpc.res.js → Rpc.res.mjs} +16 -15
  103. package/src/sources/{RpcSource.res.js → RpcSource.res.mjs} +40 -39
  104. package/src/sources/Source.res +1 -1
  105. package/src/sources/{Source.res.js → Source.res.mjs} +4 -3
  106. package/src/sources/SourceManager.res +12 -1
  107. package/src/sources/{SourceManager.res.js → SourceManager.res.mjs} +32 -21
  108. package/src/sources/vendored-fuel-abi-coder.js +94 -149
  109. package/src/vendored/{Rest.res.js → Rest.res.mjs} +12 -11
  110. package/src/Internal.res.js +0 -62
  111. package/src/Persistence.res.js +0 -159
  112. package/src/bindings/NodeJs.res.js +0 -35
  113. package/src/db/EntityHistory.res.js +0 -195
  114. /package/src/{Indexer.res.js → Change.res.mjs} +0 -0
  115. /package/src/{bindings/Express.res.js → Indexer.res.mjs} +0 -0
@@ -39,7 +39,8 @@ module Entity = {
39
39
  type indexFieldNameToIndices = t<TableIndices.Index.t, indicesSerializedToValue>
40
40
 
41
41
  type entityWithIndices<'entity> = {
42
- entityRow: Internal.inMemoryStoreRowEntity<'entity>,
42
+ latest: option<'entity>,
43
+ status: Internal.inMemoryStoreEntityStatus<'entity>,
43
44
  entityIndices: Utils.Set.t<TableIndices.Index.t>,
44
45
  }
45
46
  type t<'entity> = {
@@ -147,18 +148,20 @@ module Entity = {
147
148
  //or if allowOverWriteEntity is true (used for mockDb in test helpers)
148
149
  if shouldWriteEntity {
149
150
  let entityIndices = Utils.Set.make()
150
- let initialStoreRow: Internal.inMemoryStoreRowEntity<'entity> = switch entity {
151
+ switch entity {
151
152
  | Some(entity) =>
152
153
  //update table indices in the case where there
153
154
  //is an already set entity
154
155
  inMemTable->updateIndices(~entity, ~entityIndices)
155
- InitialReadFromDb(AlreadySet(entity))
156
-
157
- | None => InitialReadFromDb(NotSet)
156
+ | None => ()
158
157
  }
159
158
  inMemTable.table.dict->Js.Dict.set(
160
159
  key->inMemTable.table.hash,
161
- {entityRow: initialStoreRow, entityIndices},
160
+ {
161
+ latest: entity,
162
+ status: Loaded,
163
+ entityIndices,
164
+ },
162
165
  )
163
166
  }
164
167
  }
@@ -166,56 +169,64 @@ module Entity = {
166
169
  let setRow = set
167
170
  let set = (
168
171
  inMemTable: t<'entity>,
169
- entityUpdate: EntityHistory.entityUpdate<'entity>,
172
+ change: Change.t<'entity>,
170
173
  ~shouldSaveHistory,
171
174
  ~containsRollbackDiffChange=false,
172
175
  ) => {
173
176
  //New entity row with only the latest update
174
177
  @inline
175
- let newEntityRow = () => Internal.Updated({
176
- latest: entityUpdate,
177
- history: shouldSaveHistory ? [entityUpdate] : [],
178
+ let newStatus = () => Internal.Updated({
179
+ latestChange: change,
180
+ history: shouldSaveHistory
181
+ ? [change]
182
+ : Utils.Array.immutableEmpty->(Utils.magic: array<unknown> => array<Change.t<'entity>>),
178
183
  containsRollbackDiffChange,
179
184
  })
185
+ let latest = switch change {
186
+ | Set({entity}) => Some(entity)
187
+ | Delete(_) => None
188
+ }
180
189
 
181
- let {entityRow, entityIndices} = switch inMemTable.table->get(entityUpdate.entityId) {
182
- | None => {entityRow: newEntityRow(), entityIndices: Utils.Set.make()}
183
- | Some({entityRow: InitialReadFromDb(_), entityIndices}) => {
184
- entityRow: newEntityRow(),
190
+ let updatedEntityRecord = switch inMemTable.table->get(change->Change.getEntityId) {
191
+ | None => {latest, status: newStatus(), entityIndices: Utils.Set.make()}
192
+ | Some({status: Loaded, entityIndices}) => {
193
+ latest,
194
+ status: newStatus(),
185
195
  entityIndices,
186
196
  }
187
- | Some({entityRow: Updated(previous_values), entityIndices}) =>
188
- let entityRow = Internal.Updated({
189
- latest: entityUpdate,
197
+ | Some({status: Updated(previous_values), entityIndices}) =>
198
+ let newStatus = Internal.Updated({
199
+ latestChange: change,
190
200
  history: switch shouldSaveHistory {
191
201
  // This prevents two db actions in the same event on the same entity from being recorded to the history table.
192
- | true if previous_values.latest.checkpointId === entityUpdate.checkpointId =>
202
+ | true
203
+ if previous_values.latestChange->Change.getCheckpointId ===
204
+ change->Change.getCheckpointId =>
193
205
  previous_values.history->Utils.Array.setIndexImmutable(
194
206
  previous_values.history->Array.length - 1,
195
- entityUpdate,
207
+ change,
196
208
  )
197
- | true => [...previous_values.history, entityUpdate]
209
+ | true => [...previous_values.history, change]
198
210
  | false => previous_values.history
199
211
  },
200
212
  containsRollbackDiffChange: previous_values.containsRollbackDiffChange,
201
213
  })
202
- {entityRow, entityIndices}
214
+ {latest, status: newStatus, entityIndices}
203
215
  }
204
216
 
205
- switch entityUpdate.entityUpdateAction {
206
- | Set(entity) => inMemTable->updateIndices(~entity, ~entityIndices)
207
- | Delete => inMemTable->deleteEntityFromIndices(~entityId=entityUpdate.entityId, ~entityIndices)
217
+ switch change {
218
+ | Set({entity}) =>
219
+ inMemTable->updateIndices(~entity, ~entityIndices=updatedEntityRecord.entityIndices)
220
+ | Delete({entityId}) =>
221
+ inMemTable->deleteEntityFromIndices(
222
+ ~entityId,
223
+ ~entityIndices=updatedEntityRecord.entityIndices,
224
+ )
208
225
  }
209
- inMemTable.table->setRow(entityUpdate.entityId, {entityRow, entityIndices})
226
+ inMemTable.table->setRow(change->Change.getEntityId, updatedEntityRecord)
210
227
  }
211
228
 
212
- let rowToEntity = row =>
213
- switch row.entityRow {
214
- | Internal.Updated({latest: {entityUpdateAction: Set(entity)}}) => Some(entity)
215
- | Updated({latest: {entityUpdateAction: Delete}}) => None
216
- | InitialReadFromDb(AlreadySet(entity)) => Some(entity)
217
- | InitialReadFromDb(NotSet) => None
218
- }
229
+ let rowToEntity = row => row.latest
219
230
 
220
231
  let getRow = get
221
232
 
@@ -330,10 +341,15 @@ module Entity = {
330
341
  }
331
342
  }
332
343
 
333
- let rows = (inMemTable: t<'entity>) => {
344
+ let updates = (inMemTable: t<'entity>) => {
334
345
  inMemTable.table
335
346
  ->values
336
- ->Array.map(v => v.entityRow)
347
+ ->Array.keepMapU(v =>
348
+ switch v.status {
349
+ | Updated(update) => Some(update)
350
+ | Loaded => None
351
+ }
352
+ )
337
353
  }
338
354
 
339
355
  let values = (inMemTable: t<'entity>) => {
@@ -353,4 +369,3 @@ module Entity = {
353
369
  },
354
370
  }
355
371
  }
356
-
@@ -1,16 +1,15 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
- 'use strict';
3
2
 
4
- var Utils = require("./Utils.res.js");
5
- var Js_exn = require("rescript/lib/js/js_exn.js");
6
- var Lodash = require("./bindings/Lodash.res.js");
7
- var Js_dict = require("rescript/lib/js/js_dict.js");
8
- var Belt_Array = require("rescript/lib/js/belt_Array.js");
9
- var Belt_Option = require("rescript/lib/js/belt_Option.js");
10
- var Caml_option = require("rescript/lib/js/caml_option.js");
11
- var TableIndices = require("./TableIndices.res.js");
12
- var ErrorHandling = require("./ErrorHandling.res.js");
13
- var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
3
+ import * as Utils from "./Utils.res.mjs";
4
+ import * as Js_exn from "rescript/lib/es6/js_exn.js";
5
+ import * as Lodash from "./bindings/Lodash.res.mjs";
6
+ import * as Js_dict from "rescript/lib/es6/js_dict.js";
7
+ import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
8
+ import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
9
+ import * as Caml_option from "rescript/lib/es6/caml_option.js";
10
+ import * as TableIndices from "./TableIndices.res.mjs";
11
+ import * as ErrorHandling from "./ErrorHandling.res.mjs";
12
+ import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js";
14
13
 
15
14
  function make(hash) {
16
15
  return {
@@ -147,114 +146,77 @@ function initValue(inMemTable, key, entity, allowOverWriteEntityOpt) {
147
146
  return ;
148
147
  }
149
148
  var entityIndices = new Set();
150
- var initialStoreRow;
151
149
  if (entity !== undefined) {
152
- var entity$1 = Caml_option.valFromOption(entity);
153
- updateIndices(inMemTable, entity$1, entityIndices);
154
- initialStoreRow = {
155
- TAG: "InitialReadFromDb",
156
- _0: {
157
- TAG: "AlreadySet",
158
- _0: entity$1
159
- }
160
- };
161
- } else {
162
- initialStoreRow = {
163
- TAG: "InitialReadFromDb",
164
- _0: "NotSet"
165
- };
150
+ updateIndices(inMemTable, Caml_option.valFromOption(entity), entityIndices);
166
151
  }
167
152
  inMemTable.table.dict[inMemTable.table.hash(key)] = {
168
- entityRow: initialStoreRow,
153
+ latest: entity,
154
+ status: "Loaded",
169
155
  entityIndices: entityIndices
170
156
  };
171
157
  }
172
158
 
173
- function set$1(inMemTable, entityUpdate, shouldSaveHistory, containsRollbackDiffChangeOpt) {
159
+ function set$1(inMemTable, change, shouldSaveHistory, containsRollbackDiffChangeOpt) {
174
160
  var containsRollbackDiffChange = containsRollbackDiffChangeOpt !== undefined ? containsRollbackDiffChangeOpt : false;
175
- var match = get(inMemTable.table, entityUpdate.entityId);
176
- var match$1;
161
+ var latest;
162
+ latest = change.type === "SET" ? Caml_option.some(change.entity) : undefined;
163
+ var match = get(inMemTable.table, change.entityId);
164
+ var updatedEntityRecord;
177
165
  if (match !== undefined) {
178
- var previous_values = match.entityRow;
179
- if (previous_values.TAG === "Updated") {
180
- var previous_values$1 = previous_values._0;
181
- var entityRow = {
182
- TAG: "Updated",
183
- _0: {
184
- latest: entityUpdate,
185
- history: shouldSaveHistory ? (
186
- previous_values$1.latest.checkpointId === entityUpdate.checkpointId ? Utils.$$Array.setIndexImmutable(previous_values$1.history, previous_values$1.history.length - 1 | 0, entityUpdate) : Belt_Array.concatMany([
187
- previous_values$1.history,
188
- [entityUpdate]
189
- ])
190
- ) : previous_values$1.history,
191
- containsRollbackDiffChange: previous_values$1.containsRollbackDiffChange
192
- }
193
- };
194
- match$1 = {
195
- entityRow: entityRow,
166
+ var previous_values = match.status;
167
+ if (typeof previous_values !== "object") {
168
+ updatedEntityRecord = {
169
+ latest: latest,
170
+ status: {
171
+ latestChange: change,
172
+ history: shouldSaveHistory ? [change] : Utils.$$Array.immutableEmpty,
173
+ containsRollbackDiffChange: containsRollbackDiffChange
174
+ },
196
175
  entityIndices: match.entityIndices
197
176
  };
198
177
  } else {
199
- match$1 = {
200
- entityRow: {
201
- TAG: "Updated",
202
- _0: {
203
- latest: entityUpdate,
204
- history: shouldSaveHistory ? [entityUpdate] : [],
205
- containsRollbackDiffChange: containsRollbackDiffChange
206
- }
207
- },
178
+ var newStatus = {
179
+ latestChange: change,
180
+ history: shouldSaveHistory ? (
181
+ previous_values.latestChange.checkpointId === change.checkpointId ? Utils.$$Array.setIndexImmutable(previous_values.history, previous_values.history.length - 1 | 0, change) : Belt_Array.concatMany([
182
+ previous_values.history,
183
+ [change]
184
+ ])
185
+ ) : previous_values.history,
186
+ containsRollbackDiffChange: previous_values.containsRollbackDiffChange
187
+ };
188
+ updatedEntityRecord = {
189
+ latest: latest,
190
+ status: newStatus,
208
191
  entityIndices: match.entityIndices
209
192
  };
210
193
  }
211
194
  } else {
212
- match$1 = {
213
- entityRow: {
214
- TAG: "Updated",
215
- _0: {
216
- latest: entityUpdate,
217
- history: shouldSaveHistory ? [entityUpdate] : [],
218
- containsRollbackDiffChange: containsRollbackDiffChange
219
- }
195
+ updatedEntityRecord = {
196
+ latest: latest,
197
+ status: {
198
+ latestChange: change,
199
+ history: shouldSaveHistory ? [change] : Utils.$$Array.immutableEmpty,
200
+ containsRollbackDiffChange: containsRollbackDiffChange
220
201
  },
221
202
  entityIndices: new Set()
222
203
  };
223
204
  }
224
- var entityIndices = match$1.entityIndices;
225
- var entity = entityUpdate.entityUpdateAction;
226
- if (typeof entity !== "object") {
227
- deleteEntityFromIndices(inMemTable, entityUpdate.entityId, entityIndices);
205
+ if (change.type === "SET") {
206
+ updateIndices(inMemTable, change.entity, updatedEntityRecord.entityIndices);
228
207
  } else {
229
- updateIndices(inMemTable, entity._0, entityIndices);
208
+ deleteEntityFromIndices(inMemTable, change.entityId, updatedEntityRecord.entityIndices);
230
209
  }
231
- set(inMemTable.table, entityUpdate.entityId, {
232
- entityRow: match$1.entityRow,
233
- entityIndices: entityIndices
234
- });
210
+ set(inMemTable.table, change.entityId, updatedEntityRecord);
235
211
  }
236
212
 
237
213
  function rowToEntity(row) {
238
- var match = row.entityRow;
239
- if (match.TAG === "Updated") {
240
- var entity = match._0.latest.entityUpdateAction;
241
- if (typeof entity !== "object") {
242
- return ;
243
- } else {
244
- return Caml_option.some(entity._0);
245
- }
246
- }
247
- var entity$1 = match._0;
248
- if (typeof entity$1 !== "object") {
249
- return ;
250
- } else {
251
- return Caml_option.some(entity$1._0);
252
- }
214
+ return row.latest;
253
215
  }
254
216
 
255
217
  function getUnsafe(inMemTable) {
256
218
  return function (key) {
257
- return rowToEntity(inMemTable.table.dict[key]);
219
+ return inMemTable.table.dict[key].latest;
258
220
  };
259
221
  }
260
222
 
@@ -295,7 +257,7 @@ function addEmptyIndex(inMemTable, index) {
295
257
  var fieldName = TableIndices.Index.getFieldName(index);
296
258
  var relatedEntityIds = new Set();
297
259
  Belt_Array.forEach(Js_dict.values(inMemTable.table.dict), (function (row) {
298
- var entity = rowToEntity(row);
260
+ var entity = row.latest;
299
261
  if (entity === undefined) {
300
262
  return ;
301
263
  }
@@ -340,9 +302,14 @@ function addIdToIndex(inMemTable, index, entityId) {
340
302
  }
341
303
  }
342
304
 
343
- function rows(inMemTable) {
344
- return Belt_Array.map(Js_dict.values(inMemTable.table.dict), (function (v) {
345
- return v.entityRow;
305
+ function updates(inMemTable) {
306
+ return Belt_Array.keepMapU(Js_dict.values(inMemTable.table.dict), (function (v) {
307
+ var update = v.status;
308
+ if (typeof update !== "object") {
309
+ return ;
310
+ } else {
311
+ return update;
312
+ }
346
313
  }));
347
314
  }
348
315
 
@@ -384,18 +351,20 @@ var Entity = {
384
351
  getUnsafeOnIndex: getUnsafeOnIndex,
385
352
  addEmptyIndex: addEmptyIndex,
386
353
  addIdToIndex: addIdToIndex,
387
- rows: rows,
354
+ updates: updates,
388
355
  values: values$1,
389
356
  clone: clone$1
390
357
  };
391
358
 
392
- exports.make = make;
393
- exports.set = set;
394
- exports.setByHash = setByHash;
395
- exports.hasByHash = hasByHash;
396
- exports.getUnsafeByHash = getUnsafeByHash;
397
- exports.get = get;
398
- exports.values = values;
399
- exports.clone = clone;
400
- exports.Entity = Entity;
359
+ export {
360
+ make ,
361
+ set ,
362
+ setByHash ,
363
+ hasByHash ,
364
+ getUnsafeByHash ,
365
+ get ,
366
+ values ,
367
+ clone ,
368
+ Entity ,
369
+ }
401
370
  /* Utils Not a pure module */
@@ -7,7 +7,7 @@ import type {GenericContractRegister as $$genericContractRegister} from './Types
7
7
 
8
8
  import type {Invalid as $$noEventFilters} from './Types.ts';
9
9
 
10
- import type {t as Address_t} from './Address.gen';
10
+ import type {t as Address_t} from './Address.gen.js';
11
11
 
12
12
  export type genericEvent<params,block,transaction> = {
13
13
  readonly params: params;
@@ -42,8 +42,6 @@ export type entityHandlerContext<entity> = {
42
42
  readonly deleteUnsafe: (_1:string) => void
43
43
  };
44
44
 
45
- export type chainInfo = { readonly isReady: boolean };
46
-
47
45
  export type genericHandlerWithLoader<loader,handler,eventFilters> = {
48
46
  readonly loader: loader;
49
47
  readonly handler: handler;
@@ -53,8 +51,6 @@ export type genericHandlerWithLoader<loader,handler,eventFilters> = {
53
51
  readonly preRegisterDynamicContracts?: boolean
54
52
  };
55
53
 
56
- export type blockEvent = { readonly number: number; readonly chainId: number };
57
-
58
54
  export type eventOptions<eventFilters> = {
59
55
  readonly wildcard?: boolean;
60
56
  readonly eventFilters?: eventFilters;
package/src/Internal.res CHANGED
@@ -54,11 +54,11 @@ type entityHandlerContext<'entity> = {
54
54
  deleteUnsafe: string => unit,
55
55
  }
56
56
 
57
- @genType
58
57
  type chainInfo = {
58
+ id: int,
59
59
  // true when the chain has completed initial sync and is processing live events
60
60
  // false during historical synchronization
61
- isReady: bool,
61
+ isLive: bool,
62
62
  }
63
63
 
64
64
  type chains = dict<chainInfo>
@@ -67,6 +67,7 @@ type loaderReturn
67
67
  type handlerContext = private {
68
68
  isPreload: bool,
69
69
  chains: chains,
70
+ chain: chainInfo,
70
71
  }
71
72
  type handlerArgs = {
72
73
  event: event,
@@ -169,11 +170,8 @@ type eventItem = private {
169
170
  event: event,
170
171
  }
171
172
 
172
- @genType
173
- type blockEvent = {
174
- number: int,
175
- chainId: int,
176
- }
173
+ // Opaque type to support both EVM and Fuel platforms
174
+ type blockEvent
177
175
 
178
176
  type onBlockArgs = {
179
177
  block: blockEvent,
@@ -212,6 +210,12 @@ external getItemBlockNumber: item => int = "blockNumber"
212
210
  @get
213
211
  external getItemLogIndex: item => int = "logIndex"
214
212
 
213
+ let getItemChainId = item =>
214
+ switch item {
215
+ | Event({chain}) => chain->ChainMap.Chain.toChainId
216
+ | Block({onBlockConfig: {chainId}}) => chainId
217
+ }
218
+
215
219
  @get
216
220
  external getItemDcs: item => option<dcs> = "dcs"
217
221
  @set
@@ -249,36 +253,22 @@ let fuelTransferParamsSchema = S.schema(s => {
249
253
  })
250
254
 
251
255
  type entity = private {id: string}
256
+ type clickHouseSetUpdatesCache = {
257
+ tableName: string,
258
+ convertOrThrow: Change.t<entity> => Js.Json.t,
259
+ }
252
260
  type genericEntityConfig<'entity> = {
253
261
  name: string,
254
262
  index: int,
255
263
  schema: S.t<'entity>,
256
264
  rowsSchema: S.t<array<'entity>>,
257
265
  table: Table.table,
258
- entityHistory: EntityHistory.t<'entity>,
266
+ mutable clickHouseSetUpdatesCache?: clickHouseSetUpdatesCache,
267
+ mutable pgEntityHistoryCache?: EntityHistory.pgEntityHistory<'entity>,
259
268
  }
260
269
  type entityConfig = genericEntityConfig<entity>
261
270
  external fromGenericEntityConfig: genericEntityConfig<'entity> => entityConfig = "%identity"
262
271
 
263
- type enum
264
- type enumConfig<'enum> = {
265
- name: string,
266
- variants: array<'enum>,
267
- schema: S.t<'enum>,
268
- default: 'enum,
269
- }
270
- external fromGenericEnumConfig: enumConfig<'enum> => enumConfig<enum> = "%identity"
271
-
272
- let makeEnumConfig = (~name, ~variants) => {
273
- name,
274
- variants,
275
- schema: S.enum(variants),
276
- default: switch variants->Belt.Array.get(0) {
277
- | Some(v) => v
278
- | None => Js.Exn.raiseError("No variants defined for enum " ++ name)
279
- },
280
- }
281
-
282
272
  type effectInput
283
273
  type effectOutput
284
274
  type effectContext = private {mutable cache: bool}
@@ -322,8 +312,8 @@ let makeCacheTable = (~effectName) => {
322
312
  Table.mkTable(
323
313
  cacheTablePrefix ++ effectName,
324
314
  ~fields=[
325
- Table.mkField("id", Text, ~fieldSchema=S.string, ~isPrimaryKey=true),
326
- Table.mkField("output", JsonB, ~fieldSchema=cacheOutputSchema, ~isNullable=true),
315
+ Table.mkField("id", String, ~fieldSchema=S.string, ~isPrimaryKey=true),
316
+ Table.mkField("output", Json, ~fieldSchema=cacheOutputSchema, ~isNullable=true),
327
317
  ],
328
318
  )
329
319
  }
@@ -331,9 +321,11 @@ let makeCacheTable = (~effectName) => {
331
321
  @genType.import(("./Types.ts", "Invalid"))
332
322
  type noEventFilters
333
323
 
324
+ type checkpointId = float
325
+
334
326
  type reorgCheckpoint = {
335
327
  @as("id")
336
- checkpointId: int,
328
+ checkpointId: float,
337
329
  @as("chain_id")
338
330
  chainId: int,
339
331
  @as("block_number")
@@ -342,13 +334,9 @@ type reorgCheckpoint = {
342
334
  blockHash: string,
343
335
  }
344
336
 
345
- type entityValueAtStartOfBatch<'entityType> =
346
- | NotSet // The entity isn't in the DB yet
347
- | AlreadySet('entityType)
348
-
349
- type updatedValue<'entityType> = {
350
- latest: EntityHistory.entityUpdate<'entityType>,
351
- history: array<EntityHistory.entityUpdate<'entityType>>,
337
+ type inMemoryStoreEntityUpdate<'entity> = {
338
+ latestChange: Change.t<'entity>,
339
+ history: array<Change.t<'entity>>,
352
340
  // In the event of a rollback, some entity updates may have been
353
341
  // been affected by a rollback diff. If there was no rollback diff
354
342
  // this will always be false.
@@ -359,6 +347,7 @@ type updatedValue<'entityType> = {
359
347
  containsRollbackDiffChange: bool,
360
348
  }
361
349
 
362
- type inMemoryStoreRowEntity<'entityType> =
363
- | Updated(updatedValue<'entityType>)
364
- | InitialReadFromDb(entityValueAtStartOfBatch<'entityType>) // This means there is no change from the db.
350
+ @unboxed
351
+ type inMemoryStoreEntityStatus<'entity> =
352
+ | Updated(inMemoryStoreEntityUpdate<'entity>)
353
+ | Loaded // This means there is no change from the db.
@@ -0,0 +1,58 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Table from "./db/Table.res.mjs";
4
+ import * as $$BigInt from "./bindings/BigInt.res.mjs";
5
+ import * as Address from "./Address.res.mjs";
6
+ import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
7
+
8
+ function getItemChainId(item) {
9
+ if (item.kind === 0) {
10
+ return item.chain;
11
+ } else {
12
+ return item.onBlockConfig.chainId;
13
+ }
14
+ }
15
+
16
+ var fuelSupplyParamsSchema = S$RescriptSchema.schema(function (s) {
17
+ return {
18
+ subId: s.m(S$RescriptSchema.string),
19
+ amount: s.m($$BigInt.schema)
20
+ };
21
+ });
22
+
23
+ var fuelTransferParamsSchema = S$RescriptSchema.schema(function (s) {
24
+ return {
25
+ to: s.m(Address.schema),
26
+ assetId: s.m(S$RescriptSchema.string),
27
+ amount: s.m($$BigInt.schema)
28
+ };
29
+ });
30
+
31
+ var cacheTablePrefix = "envio_effect_";
32
+
33
+ var cacheOutputSchema = S$RescriptSchema.json(false);
34
+
35
+ var effectCacheItemRowsSchema = S$RescriptSchema.array(S$RescriptSchema.schema(function (s) {
36
+ return {
37
+ id: s.m(S$RescriptSchema.string),
38
+ output: s.m(cacheOutputSchema)
39
+ };
40
+ }));
41
+
42
+ function makeCacheTable(effectName) {
43
+ return Table.mkTable(cacheTablePrefix + effectName, undefined, [
44
+ Table.mkField("id", "String", S$RescriptSchema.string, undefined, undefined, undefined, true, undefined, undefined),
45
+ Table.mkField("output", "Json", cacheOutputSchema, undefined, undefined, true, undefined, undefined, undefined)
46
+ ]);
47
+ }
48
+
49
+ export {
50
+ getItemChainId ,
51
+ fuelSupplyParamsSchema ,
52
+ fuelTransferParamsSchema ,
53
+ cacheTablePrefix ,
54
+ cacheOutputSchema ,
55
+ effectCacheItemRowsSchema ,
56
+ makeCacheTable ,
57
+ }
58
+ /* fuelSupplyParamsSchema Not a pure module */
@@ -1,12 +1,11 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
- 'use strict';
3
2
 
4
- var Utils = require("./Utils.res.js");
5
- var JsSdsl = require("js-sdsl");
6
- var Belt_Option = require("rescript/lib/js/belt_Option.js");
7
- var Caml_option = require("rescript/lib/js/caml_option.js");
8
- var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
9
- var Caml_js_exceptions = require("rescript/lib/js/caml_js_exceptions.js");
3
+ import * as Utils from "./Utils.res.mjs";
4
+ import * as JsSdsl from "js-sdsl";
5
+ import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
6
+ import * as Caml_option from "rescript/lib/es6/caml_option.js";
7
+ import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js";
8
+ import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
10
9
 
11
10
  var LoaderTimeout = /* @__PURE__ */Caml_exceptions.create("LazyLoader.LoaderTimeout");
12
11
 
@@ -108,10 +107,12 @@ function get(am, k) {
108
107
  return promise;
109
108
  }
110
109
 
111
- exports.LoaderTimeout = LoaderTimeout;
112
- exports.make = make;
113
- exports.deleteKey = deleteKey;
114
- exports.timeoutAfter = timeoutAfter;
115
- exports.loadNext = loadNext;
116
- exports.get = get;
110
+ export {
111
+ LoaderTimeout ,
112
+ make ,
113
+ deleteKey ,
114
+ timeoutAfter ,
115
+ loadNext ,
116
+ get ,
117
+ }
117
118
  /* Utils Not a pure module */