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.
- package/README.md +164 -30
- package/bin.mjs +49 -0
- package/evm.schema.json +79 -169
- package/fuel.schema.json +50 -21
- package/index.d.ts +497 -1
- package/index.js +4 -0
- package/package.json +42 -31
- package/rescript.json +4 -1
- package/src/Batch.res +11 -8
- package/src/Batch.res.mjs +11 -9
- package/src/ChainFetcher.res +531 -0
- package/src/ChainFetcher.res.mjs +339 -0
- package/src/ChainManager.res +190 -0
- package/src/ChainManager.res.mjs +166 -0
- package/src/Change.res +3 -3
- package/src/Config.gen.ts +19 -0
- package/src/Config.res +737 -22
- package/src/Config.res.mjs +703 -26
- package/src/{Indexer.res → Ctx.res} +1 -1
- package/src/Ecosystem.res +9 -124
- package/src/Ecosystem.res.mjs +19 -160
- package/src/Env.res +30 -74
- package/src/Env.res.mjs +25 -87
- package/src/Envio.gen.ts +3 -1
- package/src/Envio.res +20 -9
- package/src/EventProcessing.res +469 -0
- package/src/EventProcessing.res.mjs +337 -0
- package/src/EvmTypes.gen.ts +6 -0
- package/src/EvmTypes.res +1 -0
- package/src/FetchState.res +1256 -639
- package/src/FetchState.res.mjs +1135 -612
- package/src/GlobalState.res +1190 -0
- package/src/GlobalState.res.mjs +1183 -0
- package/src/GlobalStateManager.res +68 -0
- package/src/GlobalStateManager.res.mjs +75 -0
- package/src/GlobalStateManager.resi +7 -0
- package/src/HandlerLoader.res +89 -0
- package/src/HandlerLoader.res.mjs +79 -0
- package/src/HandlerRegister.res +357 -0
- package/src/HandlerRegister.res.mjs +299 -0
- package/src/{EventRegister.resi → HandlerRegister.resi} +13 -13
- package/src/Hasura.res +111 -175
- package/src/Hasura.res.mjs +88 -150
- package/src/InMemoryStore.res +1 -1
- package/src/InMemoryStore.res.mjs +3 -3
- package/src/InMemoryTable.res +1 -1
- package/src/InMemoryTable.res.mjs +1 -1
- package/src/Internal.gen.ts +4 -0
- package/src/Internal.res +230 -12
- package/src/Internal.res.mjs +115 -1
- package/src/LoadLayer.res +444 -0
- package/src/LoadLayer.res.mjs +296 -0
- package/src/LoadLayer.resi +32 -0
- package/src/LogSelection.res +33 -27
- package/src/LogSelection.res.mjs +6 -0
- package/src/Logging.res +21 -7
- package/src/Logging.res.mjs +16 -8
- package/src/Main.res +377 -0
- package/src/Main.res.mjs +339 -0
- package/src/Persistence.res +7 -21
- package/src/Persistence.res.mjs +3 -3
- package/src/PgStorage.gen.ts +10 -0
- package/src/PgStorage.res +116 -69
- package/src/PgStorage.res.d.mts +5 -0
- package/src/PgStorage.res.mjs +93 -50
- package/src/Prometheus.res +294 -224
- package/src/Prometheus.res.mjs +353 -340
- package/src/ReorgDetection.res +6 -10
- package/src/ReorgDetection.res.mjs +6 -6
- package/src/SafeCheckpointTracking.res +4 -4
- package/src/SafeCheckpointTracking.res.mjs +2 -2
- package/src/Sink.res +4 -2
- package/src/Sink.res.mjs +2 -1
- package/src/TableIndices.res +0 -1
- package/src/TestIndexer.res +692 -0
- package/src/TestIndexer.res.mjs +527 -0
- package/src/TestIndexerProxyStorage.res +205 -0
- package/src/TestIndexerProxyStorage.res.mjs +151 -0
- package/src/TopicFilter.res +1 -1
- package/src/Types.ts +1 -1
- package/src/UserContext.res +424 -0
- package/src/UserContext.res.mjs +279 -0
- package/src/Utils.res +97 -26
- package/src/Utils.res.mjs +91 -44
- package/src/bindings/BigInt.res +10 -0
- package/src/bindings/BigInt.res.mjs +15 -0
- package/src/bindings/ClickHouse.res +120 -23
- package/src/bindings/ClickHouse.res.mjs +118 -28
- package/src/bindings/DateFns.res +74 -0
- package/src/bindings/DateFns.res.mjs +22 -0
- package/src/bindings/EventSource.res +8 -1
- package/src/bindings/EventSource.res.mjs +8 -1
- package/src/bindings/Express.res +1 -0
- package/src/bindings/Hrtime.res +14 -1
- package/src/bindings/Hrtime.res.mjs +22 -2
- package/src/bindings/Hrtime.resi +4 -0
- package/src/bindings/Lodash.res +0 -1
- package/src/bindings/NodeJs.res +49 -3
- package/src/bindings/NodeJs.res.mjs +11 -3
- package/src/bindings/Pino.res +24 -10
- package/src/bindings/Pino.res.mjs +14 -8
- package/src/bindings/Postgres.gen.ts +8 -0
- package/src/bindings/Postgres.res +5 -1
- package/src/bindings/Postgres.res.d.mts +5 -0
- package/src/bindings/PromClient.res +0 -10
- package/src/bindings/PromClient.res.mjs +0 -3
- package/src/bindings/Vitest.res +142 -0
- package/src/bindings/Vitest.res.mjs +9 -0
- package/src/bindings/WebSocket.res +27 -0
- package/src/bindings/WebSocket.res.mjs +2 -0
- package/src/bindings/Yargs.res +8 -0
- package/src/bindings/Yargs.res.mjs +2 -0
- package/src/db/EntityHistory.res +7 -7
- package/src/db/EntityHistory.res.mjs +9 -9
- package/src/db/InternalTable.res +59 -111
- package/src/db/InternalTable.res.mjs +73 -104
- package/src/db/Table.res +27 -8
- package/src/db/Table.res.mjs +25 -14
- package/src/sources/Evm.res +84 -0
- package/src/sources/Evm.res.mjs +105 -0
- package/src/sources/EvmChain.res +94 -0
- package/src/sources/EvmChain.res.mjs +60 -0
- package/src/sources/Fuel.res +19 -34
- package/src/sources/Fuel.res.mjs +34 -16
- package/src/sources/FuelSDK.res +38 -0
- package/src/sources/FuelSDK.res.mjs +29 -0
- package/src/sources/HyperFuel.res +2 -2
- package/src/sources/HyperFuel.resi +1 -1
- package/src/sources/HyperFuelClient.res +2 -2
- package/src/sources/HyperFuelSource.res +33 -13
- package/src/sources/HyperFuelSource.res.mjs +24 -16
- package/src/sources/HyperSync.res +36 -6
- package/src/sources/HyperSync.res.mjs +9 -7
- package/src/sources/HyperSync.resi +4 -0
- package/src/sources/HyperSyncClient.res +1 -1
- package/src/sources/HyperSyncHeightStream.res +47 -116
- package/src/sources/HyperSyncHeightStream.res.mjs +46 -73
- package/src/sources/HyperSyncSource.res +118 -139
- package/src/sources/HyperSyncSource.res.mjs +104 -121
- package/src/sources/Rpc.res +86 -14
- package/src/sources/Rpc.res.mjs +101 -9
- package/src/sources/RpcSource.res +621 -364
- package/src/sources/RpcSource.res.mjs +843 -410
- package/src/sources/RpcWebSocketHeightStream.res +181 -0
- package/src/sources/RpcWebSocketHeightStream.res.mjs +196 -0
- package/src/sources/Source.res +7 -5
- package/src/sources/SourceManager.res +325 -225
- package/src/sources/SourceManager.res.mjs +314 -171
- package/src/sources/SourceManager.resi +17 -6
- package/src/sources/Svm.res +81 -0
- package/src/sources/Svm.res.mjs +90 -0
- package/src/tui/Tui.res +247 -0
- package/src/tui/Tui.res.mjs +337 -0
- package/src/tui/bindings/Ink.res +371 -0
- package/src/tui/bindings/Ink.res.mjs +72 -0
- package/src/tui/bindings/Style.res +123 -0
- package/src/tui/bindings/Style.res.mjs +2 -0
- package/src/tui/components/BufferedProgressBar.res +40 -0
- package/src/tui/components/BufferedProgressBar.res.mjs +57 -0
- package/src/tui/components/CustomHooks.res +122 -0
- package/src/tui/components/CustomHooks.res.mjs +179 -0
- package/src/tui/components/Messages.res +41 -0
- package/src/tui/components/Messages.res.mjs +75 -0
- package/src/tui/components/SyncETA.res +174 -0
- package/src/tui/components/SyncETA.res.mjs +263 -0
- package/src/tui/components/TuiData.res +47 -0
- package/src/tui/components/TuiData.res.mjs +34 -0
- package/svm.schema.json +112 -0
- package/bin.js +0 -48
- package/src/EventRegister.res +0 -241
- package/src/EventRegister.res.mjs +0 -240
- package/src/bindings/Ethers.gen.ts +0 -14
- package/src/bindings/Ethers.res +0 -204
- package/src/bindings/Ethers.res.mjs +0 -130
- /package/src/{Indexer.res.mjs → Ctx.res.mjs} +0 -0
package/src/PgStorage.res.mjs
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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("
|
|
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 \"
|
|
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:
|
|
1050
|
+
reorgCheckpoints: reorgCheckpoints
|
|
988
1051
|
};
|
|
989
1052
|
};
|
|
990
|
-
var
|
|
991
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
/*
|
|
1154
|
+
/* entityHistoryCache Not a pure module */
|