envio 3.0.0-alpha.2 → 3.0.0-alpha.20

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 (175) hide show
  1. package/README.md +164 -30
  2. package/bin.mjs +49 -0
  3. package/evm.schema.json +79 -169
  4. package/fuel.schema.json +50 -21
  5. package/index.d.ts +497 -1
  6. package/index.js +4 -0
  7. package/package.json +42 -31
  8. package/rescript.json +4 -1
  9. package/src/Batch.res +11 -8
  10. package/src/Batch.res.mjs +11 -9
  11. package/src/ChainFetcher.res +531 -0
  12. package/src/ChainFetcher.res.mjs +339 -0
  13. package/src/ChainManager.res +190 -0
  14. package/src/ChainManager.res.mjs +166 -0
  15. package/src/Change.res +3 -3
  16. package/src/Config.gen.ts +19 -0
  17. package/src/Config.res +737 -22
  18. package/src/Config.res.mjs +703 -26
  19. package/src/{Indexer.res → Ctx.res} +1 -1
  20. package/src/Ecosystem.res +9 -124
  21. package/src/Ecosystem.res.mjs +19 -160
  22. package/src/Env.res +30 -74
  23. package/src/Env.res.mjs +25 -87
  24. package/src/Envio.gen.ts +3 -1
  25. package/src/Envio.res +20 -9
  26. package/src/EventProcessing.res +469 -0
  27. package/src/EventProcessing.res.mjs +337 -0
  28. package/src/EvmTypes.gen.ts +6 -0
  29. package/src/EvmTypes.res +1 -0
  30. package/src/FetchState.res +1256 -639
  31. package/src/FetchState.res.mjs +1135 -612
  32. package/src/GlobalState.res +1190 -0
  33. package/src/GlobalState.res.mjs +1183 -0
  34. package/src/GlobalStateManager.res +68 -0
  35. package/src/GlobalStateManager.res.mjs +75 -0
  36. package/src/GlobalStateManager.resi +7 -0
  37. package/src/HandlerLoader.res +89 -0
  38. package/src/HandlerLoader.res.mjs +79 -0
  39. package/src/HandlerRegister.res +357 -0
  40. package/src/HandlerRegister.res.mjs +299 -0
  41. package/src/{EventRegister.resi → HandlerRegister.resi} +13 -13
  42. package/src/Hasura.res +111 -175
  43. package/src/Hasura.res.mjs +88 -150
  44. package/src/InMemoryStore.res +1 -1
  45. package/src/InMemoryStore.res.mjs +3 -3
  46. package/src/InMemoryTable.res +1 -1
  47. package/src/InMemoryTable.res.mjs +1 -1
  48. package/src/Internal.gen.ts +4 -0
  49. package/src/Internal.res +230 -12
  50. package/src/Internal.res.mjs +115 -1
  51. package/src/LoadLayer.res +444 -0
  52. package/src/LoadLayer.res.mjs +296 -0
  53. package/src/LoadLayer.resi +32 -0
  54. package/src/LogSelection.res +33 -27
  55. package/src/LogSelection.res.mjs +6 -0
  56. package/src/Logging.res +21 -7
  57. package/src/Logging.res.mjs +16 -8
  58. package/src/Main.res +377 -0
  59. package/src/Main.res.mjs +339 -0
  60. package/src/Persistence.res +7 -21
  61. package/src/Persistence.res.mjs +3 -3
  62. package/src/PgStorage.gen.ts +10 -0
  63. package/src/PgStorage.res +116 -69
  64. package/src/PgStorage.res.d.mts +5 -0
  65. package/src/PgStorage.res.mjs +93 -50
  66. package/src/Prometheus.res +294 -224
  67. package/src/Prometheus.res.mjs +353 -340
  68. package/src/ReorgDetection.res +6 -10
  69. package/src/ReorgDetection.res.mjs +6 -6
  70. package/src/SafeCheckpointTracking.res +4 -4
  71. package/src/SafeCheckpointTracking.res.mjs +2 -2
  72. package/src/Sink.res +4 -2
  73. package/src/Sink.res.mjs +2 -1
  74. package/src/TableIndices.res +0 -1
  75. package/src/TestIndexer.res +692 -0
  76. package/src/TestIndexer.res.mjs +527 -0
  77. package/src/TestIndexerProxyStorage.res +205 -0
  78. package/src/TestIndexerProxyStorage.res.mjs +151 -0
  79. package/src/TopicFilter.res +1 -1
  80. package/src/Types.ts +1 -1
  81. package/src/UserContext.res +424 -0
  82. package/src/UserContext.res.mjs +279 -0
  83. package/src/Utils.res +97 -26
  84. package/src/Utils.res.mjs +91 -44
  85. package/src/bindings/BigInt.res +10 -0
  86. package/src/bindings/BigInt.res.mjs +15 -0
  87. package/src/bindings/ClickHouse.res +120 -23
  88. package/src/bindings/ClickHouse.res.mjs +118 -28
  89. package/src/bindings/DateFns.res +74 -0
  90. package/src/bindings/DateFns.res.mjs +22 -0
  91. package/src/bindings/EventSource.res +8 -1
  92. package/src/bindings/EventSource.res.mjs +8 -1
  93. package/src/bindings/Express.res +1 -0
  94. package/src/bindings/Hrtime.res +14 -1
  95. package/src/bindings/Hrtime.res.mjs +22 -2
  96. package/src/bindings/Hrtime.resi +4 -0
  97. package/src/bindings/Lodash.res +0 -1
  98. package/src/bindings/NodeJs.res +49 -3
  99. package/src/bindings/NodeJs.res.mjs +11 -3
  100. package/src/bindings/Pino.res +24 -10
  101. package/src/bindings/Pino.res.mjs +14 -8
  102. package/src/bindings/Postgres.gen.ts +8 -0
  103. package/src/bindings/Postgres.res +5 -1
  104. package/src/bindings/Postgres.res.d.mts +5 -0
  105. package/src/bindings/PromClient.res +0 -10
  106. package/src/bindings/PromClient.res.mjs +0 -3
  107. package/src/bindings/Vitest.res +142 -0
  108. package/src/bindings/Vitest.res.mjs +9 -0
  109. package/src/bindings/WebSocket.res +27 -0
  110. package/src/bindings/WebSocket.res.mjs +2 -0
  111. package/src/bindings/Yargs.res +8 -0
  112. package/src/bindings/Yargs.res.mjs +2 -0
  113. package/src/db/EntityHistory.res +7 -7
  114. package/src/db/EntityHistory.res.mjs +9 -9
  115. package/src/db/InternalTable.res +59 -111
  116. package/src/db/InternalTable.res.mjs +73 -104
  117. package/src/db/Table.res +27 -8
  118. package/src/db/Table.res.mjs +25 -14
  119. package/src/sources/Evm.res +84 -0
  120. package/src/sources/Evm.res.mjs +105 -0
  121. package/src/sources/EvmChain.res +94 -0
  122. package/src/sources/EvmChain.res.mjs +60 -0
  123. package/src/sources/Fuel.res +19 -34
  124. package/src/sources/Fuel.res.mjs +34 -16
  125. package/src/sources/FuelSDK.res +38 -0
  126. package/src/sources/FuelSDK.res.mjs +29 -0
  127. package/src/sources/HyperFuel.res +2 -2
  128. package/src/sources/HyperFuel.resi +1 -1
  129. package/src/sources/HyperFuelClient.res +2 -2
  130. package/src/sources/HyperFuelSource.res +33 -13
  131. package/src/sources/HyperFuelSource.res.mjs +24 -16
  132. package/src/sources/HyperSync.res +36 -6
  133. package/src/sources/HyperSync.res.mjs +9 -7
  134. package/src/sources/HyperSync.resi +4 -0
  135. package/src/sources/HyperSyncClient.res +1 -1
  136. package/src/sources/HyperSyncHeightStream.res +47 -116
  137. package/src/sources/HyperSyncHeightStream.res.mjs +46 -73
  138. package/src/sources/HyperSyncSource.res +118 -139
  139. package/src/sources/HyperSyncSource.res.mjs +104 -121
  140. package/src/sources/Rpc.res +86 -14
  141. package/src/sources/Rpc.res.mjs +101 -9
  142. package/src/sources/RpcSource.res +621 -364
  143. package/src/sources/RpcSource.res.mjs +843 -410
  144. package/src/sources/RpcWebSocketHeightStream.res +181 -0
  145. package/src/sources/RpcWebSocketHeightStream.res.mjs +196 -0
  146. package/src/sources/Source.res +7 -5
  147. package/src/sources/SourceManager.res +325 -225
  148. package/src/sources/SourceManager.res.mjs +314 -171
  149. package/src/sources/SourceManager.resi +17 -6
  150. package/src/sources/Svm.res +81 -0
  151. package/src/sources/Svm.res.mjs +90 -0
  152. package/src/tui/Tui.res +247 -0
  153. package/src/tui/Tui.res.mjs +337 -0
  154. package/src/tui/bindings/Ink.res +371 -0
  155. package/src/tui/bindings/Ink.res.mjs +72 -0
  156. package/src/tui/bindings/Style.res +123 -0
  157. package/src/tui/bindings/Style.res.mjs +2 -0
  158. package/src/tui/components/BufferedProgressBar.res +40 -0
  159. package/src/tui/components/BufferedProgressBar.res.mjs +57 -0
  160. package/src/tui/components/CustomHooks.res +122 -0
  161. package/src/tui/components/CustomHooks.res.mjs +179 -0
  162. package/src/tui/components/Messages.res +41 -0
  163. package/src/tui/components/Messages.res.mjs +75 -0
  164. package/src/tui/components/SyncETA.res +174 -0
  165. package/src/tui/components/SyncETA.res.mjs +263 -0
  166. package/src/tui/components/TuiData.res +47 -0
  167. package/src/tui/components/TuiData.res.mjs +34 -0
  168. package/svm.schema.json +112 -0
  169. package/bin.js +0 -48
  170. package/src/EventRegister.res +0 -241
  171. package/src/EventRegister.res.mjs +0 -240
  172. package/src/bindings/Ethers.gen.ts +0 -14
  173. package/src/bindings/Ethers.res +0 -204
  174. package/src/bindings/Ethers.res.mjs +0 -130
  175. /package/src/{Indexer.res.mjs → Ctx.res.mjs} +0 -0
@@ -1,10 +1,12 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
3
  import * as Fs from "fs";
4
+ import * as Env from "./Env.res.mjs";
4
5
  import * as Path from "path";
5
6
  import * as $$Array from "rescript/lib/es6/array.js";
6
7
  import * as Table from "./db/Table.res.mjs";
7
8
  import * as Utils from "./Utils.res.mjs";
9
+ import * as $$BigInt from "./bindings/BigInt.res.mjs";
8
10
  import * as Config from "./Config.res.mjs";
9
11
  import * as Hrtime from "./bindings/Hrtime.res.mjs";
10
12
  import * as Js_exn from "rescript/lib/es6/js_exn.js";
@@ -12,7 +14,9 @@ import * as Schema from "./db/Schema.res.mjs";
12
14
  import * as Js_dict from "rescript/lib/es6/js_dict.js";
13
15
  import * as Logging from "./Logging.res.mjs";
14
16
  import * as $$Promise from "./bindings/Promise.res.mjs";
17
+ import * as Caml_obj from "rescript/lib/es6/caml_obj.js";
15
18
  import * as Internal from "./Internal.res.mjs";
19
+ import Postgres from "postgres";
16
20
  import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
17
21
  import * as Prometheus from "./Prometheus.res.mjs";
18
22
  import * as Caml_option from "rescript/lib/es6/caml_option.js";
@@ -26,6 +30,24 @@ import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
26
30
 
27
31
  var getCacheRowCountFnName = "get_cache_row_count";
28
32
 
33
+ function makeClient() {
34
+ return Postgres({
35
+ host: Env.Db.host,
36
+ port: Env.Db.port,
37
+ database: Env.Db.database,
38
+ username: Env.Db.user,
39
+ password: Env.Db.password,
40
+ ssl: Env.Db.ssl,
41
+ max: Env.Db.maxConnections,
42
+ onnotice: Caml_obj.equal(Env.userLogLevel, "warn") || Caml_obj.equal(Env.userLogLevel, "error") ? undefined : (function (_str) {
43
+
44
+ }),
45
+ transform: {
46
+ undefined: null
47
+ }
48
+ });
49
+ }
50
+
29
51
  function makeCreateIndexQuery(tableName, indexFields, pgSchema) {
30
52
  var indexName = tableName + "_" + indexFields.join("_");
31
53
  var index = Belt_Array.map(indexFields, (function (idx) {
@@ -34,13 +56,39 @@ function makeCreateIndexQuery(tableName, indexFields, pgSchema) {
34
56
  return "CREATE INDEX IF NOT EXISTS \"" + indexName + "\" ON \"" + pgSchema + "\".\"" + tableName + "\"(" + index + ");";
35
57
  }
36
58
 
59
+ function directionToSql(direction) {
60
+ if (direction === "Asc") {
61
+ return "";
62
+ } else {
63
+ return " DESC";
64
+ }
65
+ }
66
+
67
+ function directionToIndexName(direction) {
68
+ if (direction === "Asc") {
69
+ return "";
70
+ } else {
71
+ return "_desc";
72
+ }
73
+ }
74
+
75
+ function makeCreateCompositeIndexQuery(tableName, indexFields, pgSchema) {
76
+ var indexName = tableName + "_" + indexFields.map(function (f) {
77
+ return f.fieldName + directionToIndexName(f.direction);
78
+ }).join("_");
79
+ var index = Belt_Array.map(indexFields, (function (f) {
80
+ return "\"" + f.fieldName + "\"" + directionToSql(f.direction);
81
+ })).join(", ");
82
+ return "CREATE INDEX IF NOT EXISTS \"" + indexName + "\" ON \"" + pgSchema + "\".\"" + tableName + "\"(" + index + ");";
83
+ }
84
+
37
85
  function makeCreateTableIndicesQuery(table, pgSchema) {
38
86
  var tableName = table.tableName;
39
87
  var createIndex = function (indexField) {
40
88
  return makeCreateIndexQuery(tableName, [indexField], pgSchema);
41
89
  };
42
90
  var createCompositeIndex = function (indexFields) {
43
- return makeCreateIndexQuery(tableName, indexFields, pgSchema);
91
+ return makeCreateCompositeIndexQuery(tableName, indexFields, pgSchema);
44
92
  };
45
93
  var singleIndices = Table.getSingleIndices(table);
46
94
  var compositeIndices = Table.getCompositeIndices(table);
@@ -67,8 +115,10 @@ function makeCreateTableQuery(table, pgSchema, isNumericArrayAsText) {
67
115
  ) + ");";
68
116
  }
69
117
 
118
+ var entityHistoryCache = new WeakMap();
119
+
70
120
  function getEntityHistory(entityConfig) {
71
- var cache = entityConfig.pgEntityHistoryCache;
121
+ var cache = entityHistoryCache.get(entityConfig);
72
122
  if (cache !== undefined) {
73
123
  return cache;
74
124
  }
@@ -125,7 +175,7 @@ function getEntityHistory(entityConfig) {
125
175
  setChangeSchema: setChangeSchema,
126
176
  setChangeSchemaRows: cache_setChangeSchemaRows
127
177
  };
128
- entityConfig.pgEntityHistoryCache = cache$1;
178
+ entityHistoryCache.set(entityConfig, cache$1);
129
179
  return cache$1;
130
180
  }
131
181
 
@@ -150,7 +200,7 @@ function makeInitializeTransaction(pgSchema, pgUser, isHasuraEnabled, chainConfi
150
200
  var derivedSchema = Schema.make(allEntityTables);
151
201
  var query = {
152
202
  contents: (
153
- isEmptyPgSchema && pgSchema === "public" ? "" : "DROP SCHEMA IF EXISTS \"" + pgSchema + "\" CASCADE;\nCREATE SCHEMA \"" + pgSchema + "\";\n"
203
+ isEmptyPgSchema && pgSchema === "public" ? "CREATE SCHEMA IF NOT EXISTS \"" + pgSchema + "\";\n" : "DROP SCHEMA IF EXISTS \"" + pgSchema + "\" CASCADE;\nCREATE SCHEMA \"" + pgSchema + "\";\n"
154
204
  ) + ("GRANT ALL ON SCHEMA \"" + pgSchema + "\" TO \"" + pgUser + "\";\nGRANT ALL ON SCHEMA \"" + pgSchema + "\" TO public;")
155
205
  };
156
206
  enums.forEach(function (enumConfig) {
@@ -338,7 +388,8 @@ async function setOrThrow(sql, items, table, itemSchema, pgSchema) {
338
388
  chunks.forEach(function (chunk) {
339
389
  var chunkSize = chunk.length;
340
390
  var isFullChunk = chunkSize === 500;
341
- var response = sql.unsafe(isFullChunk ? data.query : makeInsertValuesSetQuery(pgSchema, table, itemSchema, chunkSize), data.convertOrThrow(chunk), {prepare: true});
391
+ var params = data.convertOrThrow(chunk);
392
+ var response = isFullChunk ? sql.unsafe(data.query, params, {prepare: true}) : sql.unsafe(makeInsertValuesSetQuery(pgSchema, table, itemSchema, chunkSize), params);
342
393
  responses.push(response);
343
394
  });
344
395
  await Promise.all(responses);
@@ -377,7 +428,7 @@ var psqlExecState = {
377
428
  contents: "Unknown"
378
429
  };
379
430
 
380
- async function getConnectedPsqlExec(pgUser, pgHost, pgDatabase, pgPort) {
431
+ async function getConnectedPsqlExec(pgUser, pgHost, pgDatabase, pgPort, containerName) {
381
432
  var promise = psqlExecState.contents;
382
433
  if (typeof promise === "object") {
383
434
  if (promise.TAG === "Pending") {
@@ -395,7 +446,7 @@ async function getConnectedPsqlExec(pgUser, pgHost, pgDatabase, pgPort) {
395
446
  _0: binary + " -h " + pgHost + " -p " + pgPort.toString() + " -U " + pgUser + " -d " + pgDatabase
396
447
  });
397
448
  }
398
- var binary$1 = "docker-compose exec -T -u " + pgUser + " envio-postgres psql";
449
+ var binary$1 = "docker exec -i -u " + pgUser + " " + containerName + " psql";
399
450
  Child_process.exec(binary$1 + " --version", (function (error, param, param$1) {
400
451
  if (error === null) {
401
452
  return resolve({
@@ -405,7 +456,7 @@ async function getConnectedPsqlExec(pgUser, pgHost, pgDatabase, pgPort) {
405
456
  } else {
406
457
  return resolve({
407
458
  TAG: "Error",
408
- _0: "Please check if \"psql\" binary is installed or docker-compose is running for the local indexer."
459
+ _0: "Please check if \"psql\" binary is installed or Docker container \"" + containerName + "\" is running."
409
460
  });
410
461
  }
411
462
  }));
@@ -531,7 +582,7 @@ async function writeBatch(sql, batch, rawEvents, pgSchema, rollbackTargetCheckpo
531
582
  if (Utils.$$Array.notEmpty(batchDeleteCheckpointIds)) {
532
583
  promises.push(sql.unsafe(makeInsertDeleteUpdatesQuery(entityConfig, pgSchema), [
533
584
  batchDeleteEntityIds,
534
- batchDeleteCheckpointIds
585
+ $$BigInt.arrayToStringArray(batchDeleteCheckpointIds)
535
586
  ], {prepare: true}));
536
587
  }
537
588
  if (Utils.$$Array.notEmpty(batchSetUpdates)) {
@@ -614,6 +665,7 @@ async function writeBatch(sql, batch, rawEvents, pgSchema, rollbackTargetCheckpo
614
665
  return {
615
666
  chainId: chainAfterBatch.fetchState.chainId,
616
667
  progressBlockNumber: chainAfterBatch.progressBlockNumber,
668
+ sourceBlockNumber: chainAfterBatch.sourceBlockNumber,
617
669
  totalEventsProcessed: chainAfterBatch.totalEventsProcessed
618
670
  };
619
671
  })));
@@ -684,6 +736,7 @@ function makeGetRollbackRemovedIdsQuery(entityConfig, pgSchema) {
684
736
  }
685
737
 
686
738
  function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, isHasuraEnabled, sink, onInitialize, onNewTables) {
739
+ var containerName = "envio-postgres";
687
740
  var psqlExecOptions_env = Js_dict.fromArray([
688
741
  [
689
742
  "PGPASSWORD",
@@ -697,7 +750,7 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, isH
697
750
  var psqlExecOptions = {
698
751
  env: psqlExecOptions_env
699
752
  };
700
- var cacheDirPath = Path.resolve("..", ".envio", "cache");
753
+ var cacheDirPath = Path.resolve(".envio", "cache");
701
754
  var isInitialized = async function () {
702
755
  var envioTables = await sql.unsafe("SELECT table_schema FROM information_schema.tables WHERE table_schema = '" + pgSchema + "' AND (table_name = 'event_sync_state' OR table_name = '" + InternalTable.Chains.table.tableName + "');");
703
756
  return Utils.$$Array.notEmpty(envioTables);
@@ -717,7 +770,7 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, isH
717
770
  _0: nothingToUploadErrorMessage
718
771
  });
719
772
  })),
720
- getConnectedPsqlExec(pgUser, pgHost, pgDatabase, pgPort)
773
+ getConnectedPsqlExec(pgUser, pgHost, pgDatabase, pgPort, containerName)
721
774
  ]);
722
775
  var exit = 0;
723
776
  var message;
@@ -788,7 +841,7 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, isH
788
841
  if (Utils.$$Array.notEmpty(schemaTableNames) && !schemaTableNames.some(function (table) {
789
842
  return table.table_name === InternalTable.Chains.table.tableName ? true : table.table_name === "event_sync_state";
790
843
  })) {
791
- Js_exn.raiseError("Cannot run Envio migrations on PostgreSQL schema \"" + pgSchema + "\" because it contains non-Envio tables. Running migrations would delete all data in this schema.\n\nTo resolve this:\n1. If you want to use this schema, first backup any important data, then drop it with: \"pnpm envio local db-migrate down\"\n2. Or specify a different schema name by setting the \"ENVIO_PG_PUBLIC_SCHEMA\" environment variable\n3. Or manually drop the schema in your database if you're certain the data is not needed.");
844
+ Js_exn.raiseError("Cannot run Envio migrations on PostgreSQL schema \"" + pgSchema + "\" because it contains non-Envio tables. Running migrations would delete all data in this schema.\n\nTo resolve this:\n1. If you want to use this schema, first backup any important data, then drop it with: \"pnpm envio local db-migrate down\"\n2. Or specify a different schema name by setting the \"ENVIO_PG_SCHEMA\" environment variable\n3. Or manually drop the schema in your database if you're certain the data is not needed.");
792
845
  }
793
846
  if (sink !== undefined) {
794
847
  await sink.initialize(chainConfigs, entities, enums);
@@ -816,7 +869,8 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, isH
816
869
  numEventsProcessed: 0,
817
870
  firstEventBlockNumber: undefined,
818
871
  timestampCaughtUpToHeadOrEndblock: undefined,
819
- dynamicContracts: []
872
+ dynamicContracts: [],
873
+ sourceBlockNumber: 0
820
874
  };
821
875
  }),
822
876
  checkpointId: InternalTable.Checkpoints.initialCheckpointId,
@@ -923,7 +977,7 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, isH
923
977
  recursive: true
924
978
  });
925
979
  }
926
- var psqlExec = await getConnectedPsqlExec(pgUser, pgHost, pgDatabase, pgPort);
980
+ var psqlExec = await getConnectedPsqlExec(pgUser, pgHost, pgDatabase, pgPort, containerName);
927
981
  if (psqlExec.TAG !== "Ok") {
928
982
  return Logging.error("Failed to dump cache. " + psqlExec._0);
929
983
  }
@@ -968,14 +1022,23 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, isH
968
1022
  numEventsProcessed: rawInitialState.numEventsProcessed,
969
1023
  firstEventBlockNumber: Caml_option.null_to_opt(rawInitialState.firstEventBlockNumber),
970
1024
  timestampCaughtUpToHeadOrEndblock: Caml_option.null_to_opt(rawInitialState.timestampCaughtUpToHeadOrEndblock),
971
- dynamicContracts: rawInitialState.dynamicContracts
1025
+ dynamicContracts: rawInitialState.dynamicContracts,
1026
+ sourceBlockNumber: rawInitialState.sourceBlockNumber
972
1027
  };
973
1028
  }));
974
1029
  }),
975
1030
  sql.unsafe(InternalTable.Checkpoints.makeCommitedCheckpointIdQuery(pgSchema)),
976
1031
  sql.unsafe(InternalTable.Checkpoints.makeGetReorgCheckpointsQuery(pgSchema))
977
1032
  ]);
978
- var checkpointId = match[2][0].id;
1033
+ var checkpointId = BigInt(match[2][0].id);
1034
+ var reorgCheckpoints = Belt_Array.map(match[3], (function (raw) {
1035
+ return {
1036
+ id: BigInt(raw.id),
1037
+ chain_id: raw.chain_id,
1038
+ block_number: raw.block_number,
1039
+ block_hash: raw.block_hash
1040
+ };
1041
+ }));
979
1042
  if (sink !== undefined) {
980
1043
  await sink.resume(checkpointId);
981
1044
  }
@@ -984,34 +1047,12 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, isH
984
1047
  cache: match[0],
985
1048
  chains: match[1],
986
1049
  checkpointId: checkpointId,
987
- reorgCheckpoints: match[3]
1050
+ reorgCheckpoints: reorgCheckpoints
988
1051
  };
989
1052
  };
990
- var executeUnsafe = function (query) {
991
- return sql.unsafe(query);
992
- };
993
- var hasEntityHistoryRows = async function () {
994
- var historyTables = await sql.unsafe("SELECT table_name FROM information_schema.tables \n WHERE table_schema = '" + pgSchema + "' \n AND table_name LIKE 'envio_history_%';");
995
- if (Utils.$$Array.isEmpty(historyTables)) {
996
- return false;
997
- }
998
- var checks = await Promise.all(Belt_Array.map(historyTables, (async function (table) {
999
- try {
1000
- var query = "SELECT EXISTS(SELECT 1 FROM \"" + pgSchema + "\".\"" + table.table_name + "\" LIMIT 1);";
1001
- var result = await sql.unsafe(query);
1002
- if (result.length !== 1) {
1003
- return false;
1004
- } else {
1005
- return result[0].exists;
1006
- }
1007
- }
1008
- catch (exn){
1009
- return false;
1010
- }
1011
- })));
1012
- return Belt_Array.some(checks, (function (v) {
1013
- return v;
1014
- }));
1053
+ var reset = async function () {
1054
+ var query = "DROP SCHEMA IF EXISTS \"" + pgSchema + "\" CASCADE;";
1055
+ return await sql.unsafe(query);
1015
1056
  };
1016
1057
  var setChainMeta = function (chainsData) {
1017
1058
  return InternalTable.Chains.setMeta(sql, pgSchema, chainsData).then(function (param) {
@@ -1032,8 +1073,8 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, isH
1032
1073
  };
1033
1074
  var getRollbackData = async function (entityConfig, rollbackTargetCheckpointId) {
1034
1075
  return await Promise.all([
1035
- sql.unsafe(makeGetRollbackRemovedIdsQuery(entityConfig, pgSchema), [rollbackTargetCheckpointId], {prepare: true}),
1036
- sql.unsafe(makeGetRollbackRestoredEntitiesQuery(entityConfig, pgSchema), [rollbackTargetCheckpointId], {prepare: true})
1076
+ sql.unsafe(makeGetRollbackRemovedIdsQuery(entityConfig, pgSchema), [rollbackTargetCheckpointId.toString()], {prepare: true}),
1077
+ sql.unsafe(makeGetRollbackRestoredEntitiesQuery(entityConfig, pgSchema), [rollbackTargetCheckpointId.toString()], {prepare: true})
1037
1078
  ]);
1038
1079
  };
1039
1080
  var writeBatchMethod = async function (batch, rawEvents, rollbackTargetCheckpointId, isInReorgThreshold, config, allEntities, updatedEffectsCache, updatedEntities) {
@@ -1041,7 +1082,7 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, isH
1041
1082
  if (sink !== undefined) {
1042
1083
  var timerRef = Hrtime.makeTimer();
1043
1084
  sinkPromise = Caml_option.some(sink.writeBatch(batch, updatedEntities).then(function () {
1044
- Prometheus.SinkWrite.increment(sink.name, Hrtime.intFromMillis(Hrtime.toMillis(Hrtime.timeSince(timerRef))));
1085
+ Prometheus.SinkWrite.increment(sink.name, Hrtime.toSecondsFloat(Hrtime.timeSince(timerRef)));
1045
1086
  }).catch(function (exn) {
1046
1087
  return exn;
1047
1088
  }));
@@ -1056,11 +1097,8 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, isH
1056
1097
  resumeInitialState: resumeInitialState,
1057
1098
  loadByIdsOrThrow: loadByIdsOrThrow,
1058
1099
  loadByFieldOrThrow: loadByFieldOrThrow,
1059
- setOrThrow: setOrThrow$1,
1060
- setEffectCacheOrThrow: setEffectCacheOrThrow,
1061
1100
  dumpEffectCache: dumpEffectCache,
1062
- executeUnsafe: executeUnsafe,
1063
- hasEntityHistoryRows: hasEntityHistoryRows,
1101
+ reset: reset,
1064
1102
  setChainMeta: setChainMeta,
1065
1103
  pruneStaleCheckpoints: pruneStaleCheckpoints,
1066
1104
  pruneStaleEntityHistory: pruneStaleEntityHistory,
@@ -1075,9 +1113,14 @@ var maxItemsPerQuery = 500;
1075
1113
 
1076
1114
  export {
1077
1115
  getCacheRowCountFnName ,
1116
+ makeClient ,
1078
1117
  makeCreateIndexQuery ,
1118
+ directionToSql ,
1119
+ directionToIndexName ,
1120
+ makeCreateCompositeIndexQuery ,
1079
1121
  makeCreateTableIndicesQuery ,
1080
1122
  makeCreateTableQuery ,
1123
+ entityHistoryCache ,
1081
1124
  getEntityHistory ,
1082
1125
  makeInitializeTransaction ,
1083
1126
  makeLoadByIdQuery ,
@@ -1108,4 +1151,4 @@ export {
1108
1151
  makeGetRollbackRemovedIdsQuery ,
1109
1152
  make ,
1110
1153
  }
1111
- /* pgErrorMessageSchema Not a pure module */
1154
+ /* entityHistoryCache Not a pure module */