envio 2.21.5 → 2.22.1
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/index.js +2 -2
- package/package.json +11 -8
- package/rescript.json +1 -1
- package/src/Address.res.js +30 -0
- package/src/ChainMap.res.js +77 -0
- package/src/Envio.res +2 -0
- package/src/Envio.res.js +16 -0
- package/src/ErrorHandling.res +0 -26
- package/src/ErrorHandling.res.js +56 -0
- package/src/EventUtils.res.js +75 -0
- package/src/EvmTypes.res.js +16 -0
- package/src/FetchState.res.js +969 -0
- package/src/Hasura.res +297 -0
- package/src/Hasura.res.js +245 -0
- package/src/Internal.res +26 -0
- package/src/Internal.res.js +50 -0
- package/src/LazyLoader.res.js +117 -0
- package/src/LoadManager.res.js +124 -0
- package/src/LogSelection.res.js +203 -0
- package/src/Logging.res +31 -31
- package/src/Logging.res.js +247 -0
- package/src/Persistence.res +111 -0
- package/src/Persistence.res.js +90 -0
- package/src/PgStorage.res +165 -0
- package/src/PgStorage.res.js +125 -0
- package/src/Prometheus.res +75 -40
- package/src/Prometheus.res.js +750 -0
- package/src/ReorgDetection.res.js +223 -0
- package/src/Throttler.res.js +60 -0
- package/src/Time.res.js +41 -0
- package/src/TopicFilter.res.js +86 -0
- package/src/Utils.res.js +527 -0
- package/src/bindings/BigDecimal.gen.ts +1 -1
- package/src/bindings/BigDecimal.res.js +41 -0
- package/src/bindings/BigInt.res.js +138 -0
- package/src/bindings/Ethers.gen.ts +1 -1
- package/src/bindings/Ethers.res.js +109 -0
- package/src/bindings/Express.res.js +2 -0
- package/src/bindings/Hrtime.res.js +66 -0
- package/src/bindings/NodeJs.res.js +29 -0
- package/src/bindings/Pino.res.js +95 -0
- package/src/bindings/Postgres.res.js +16 -0
- package/src/bindings/PromClient.res.js +17 -0
- package/src/bindings/Promise.res +5 -0
- package/src/bindings/Promise.res.js +25 -0
- package/src/bindings/SDSL.res.js +8 -0
- package/src/bindings/Viem.res.js +45 -0
- package/src/db/EntityHistory.res +3 -3
- package/src/db/EntityHistory.res.js +307 -0
- package/src/db/Schema.res.js +54 -0
- package/src/db/Table.res.js +365 -0
- package/src/sources/Fuel.res.js +28 -0
- package/src/sources/HyperFuel.res.js +193 -0
- package/src/sources/HyperFuelClient.res.js +19 -0
- package/src/sources/HyperSync.res.js +301 -0
- package/src/sources/HyperSyncClient.res.js +99 -0
- package/src/sources/HyperSyncJsonApi.res.js +259 -0
- package/src/sources/Rpc.res.js +198 -0
- package/src/sources/Source.res.js +9 -0
- package/src/sources/SourceManager.res.js +366 -0
- package/src/vendored/Rest.res.js +574 -0
- package/src/Enum.res +0 -22
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var $$Array = require("rescript/lib/js/array.js");
|
|
5
|
+
var Table = require("./db/Table.res.js");
|
|
6
|
+
var Utils = require("./Utils.res.js");
|
|
7
|
+
var Schema = require("./db/Schema.res.js");
|
|
8
|
+
var Belt_Array = require("rescript/lib/js/belt_Array.js");
|
|
9
|
+
|
|
10
|
+
function makeCreateIndexSqlUnsafe(tableName, indexFields, pgSchema) {
|
|
11
|
+
var indexName = tableName + "_" + indexFields.join("_");
|
|
12
|
+
var index = Belt_Array.map(indexFields, (function (idx) {
|
|
13
|
+
return "\"" + idx + "\"";
|
|
14
|
+
})).join(", ");
|
|
15
|
+
return "CREATE INDEX IF NOT EXISTS \"" + indexName + "\" ON \"" + pgSchema + "\".\"" + tableName + "\"(" + index + ");";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function makeCreateTableIndicesSqlUnsafe(table, pgSchema) {
|
|
19
|
+
var tableName = table.tableName;
|
|
20
|
+
var createIndex = function (indexField) {
|
|
21
|
+
return makeCreateIndexSqlUnsafe(tableName, [indexField], pgSchema);
|
|
22
|
+
};
|
|
23
|
+
var createCompositeIndex = function (indexFields) {
|
|
24
|
+
return makeCreateIndexSqlUnsafe(tableName, indexFields, pgSchema);
|
|
25
|
+
};
|
|
26
|
+
var singleIndices = Table.getSingleIndices(table);
|
|
27
|
+
var compositeIndices = Table.getCompositeIndices(table);
|
|
28
|
+
return Belt_Array.map(singleIndices, createIndex).join("\n") + Belt_Array.map(compositeIndices, createCompositeIndex).join("\n");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function makeCreateTableSqlUnsafe(table, pgSchema) {
|
|
32
|
+
var fieldsMapped = Belt_Array.map(Table.getFields(table), (function (field) {
|
|
33
|
+
var defaultValue = field.defaultValue;
|
|
34
|
+
var fieldType = field.fieldType;
|
|
35
|
+
var fieldName = Table.getDbFieldName(field);
|
|
36
|
+
var tmp;
|
|
37
|
+
tmp = fieldType === "TIMESTAMP" || fieldType === "TIMESTAMP WITH TIME ZONE" || fieldType === "JSONB" || fieldType === "SERIAL" || fieldType === "TEXT" || fieldType === "DOUBLE PRECISION" || fieldType === "NUMERIC" || fieldType === "BOOLEAN" || fieldType === "INTEGER" || fieldType === "TIMESTAMP WITH TIME ZONE NULL" || fieldType.startsWith("NUMERIC(") ? fieldType : "\"" + pgSchema + "\"." + fieldType;
|
|
38
|
+
return "\"" + fieldName + "\" " + tmp + (
|
|
39
|
+
field.isArray ? "[]" : ""
|
|
40
|
+
) + (
|
|
41
|
+
defaultValue !== undefined ? " DEFAULT " + defaultValue : (
|
|
42
|
+
field.isNullable ? "" : " NOT NULL"
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
})).join(", ");
|
|
46
|
+
var primaryKeyFieldNames = Table.getPrimaryKeyFieldNames(table);
|
|
47
|
+
var primaryKey = Belt_Array.map(primaryKeyFieldNames, (function (field) {
|
|
48
|
+
return "\"" + field + "\"";
|
|
49
|
+
})).join(", ");
|
|
50
|
+
return "CREATE TABLE IF NOT EXISTS \"" + pgSchema + "\".\"" + table.tableName + "\"(" + fieldsMapped + (
|
|
51
|
+
primaryKeyFieldNames.length !== 0 ? ", PRIMARY KEY(" + primaryKey + ")" : ""
|
|
52
|
+
) + ");";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function makeInitializeTransaction(pgSchema, staticTables, entities, enums, cleanRun) {
|
|
56
|
+
var allTables = $$Array.copy(staticTables);
|
|
57
|
+
var allEntityTables = [];
|
|
58
|
+
entities.forEach(function (entity) {
|
|
59
|
+
allEntityTables.push(entity.table);
|
|
60
|
+
allTables.push(entity.table);
|
|
61
|
+
allTables.push(entity.entityHistory.table);
|
|
62
|
+
});
|
|
63
|
+
var derivedSchema = Schema.make(allEntityTables);
|
|
64
|
+
var query = {
|
|
65
|
+
contents: (
|
|
66
|
+
cleanRun ? "DROP SCHEMA IF EXISTS \"" + pgSchema + "\" CASCADE;\nCREATE SCHEMA \"" + pgSchema + "\";" : "CREATE SCHEMA IF NOT EXISTS \"" + pgSchema + "\";"
|
|
67
|
+
) + ("GRANT ALL ON SCHEMA \"" + pgSchema + "\" TO postgres;\nGRANT ALL ON SCHEMA \"" + pgSchema + "\" TO public;")
|
|
68
|
+
};
|
|
69
|
+
enums.forEach(function (enumConfig) {
|
|
70
|
+
var enumCreateQuery = "CREATE TYPE \"" + pgSchema + "\"." + enumConfig.name + " AS ENUM(" + enumConfig.variants.map(function (v) {
|
|
71
|
+
return "'" + v + "'";
|
|
72
|
+
}).join(", ") + ");";
|
|
73
|
+
query.contents = query.contents + "\n" + (
|
|
74
|
+
cleanRun ? enumCreateQuery : "IF NOT EXISTS (\n SELECT 1 FROM pg_type \n WHERE typname = '" + enumConfig.name.toLowerCase() + "' \n AND typnamespace = (SELECT oid FROM pg_namespace WHERE nspname = '" + pgSchema + "')\n) THEN \n " + enumCreateQuery + "\nEND IF;"
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
allTables.forEach(function (table) {
|
|
78
|
+
query.contents = query.contents + "\n" + makeCreateTableSqlUnsafe(table, pgSchema);
|
|
79
|
+
});
|
|
80
|
+
allTables.forEach(function (table) {
|
|
81
|
+
var indices = makeCreateTableIndicesSqlUnsafe(table, pgSchema);
|
|
82
|
+
if (indices !== "") {
|
|
83
|
+
query.contents = query.contents + "\n" + indices;
|
|
84
|
+
return ;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
});
|
|
88
|
+
var functionsQuery = {
|
|
89
|
+
contents: ""
|
|
90
|
+
};
|
|
91
|
+
entities.forEach(function (entity) {
|
|
92
|
+
functionsQuery.contents = functionsQuery.contents + "\n" + entity.entityHistory.createInsertFnQuery;
|
|
93
|
+
Table.getDerivedFromFields(entity.table).forEach(function (derivedFromField) {
|
|
94
|
+
var indexField = Utils.unwrapResultExn(Schema.getDerivedFromFieldName(derivedSchema, derivedFromField));
|
|
95
|
+
query.contents = query.contents + "\n" + makeCreateIndexSqlUnsafe(derivedFromField.derivedFromEntity, [indexField], pgSchema);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
return [cleanRun ? query.contents : "DO $$ BEGIN " + query.contents + " END $$;"].concat(functionsQuery.contents !== "" ? [functionsQuery.contents] : []);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function make(sql, pgSchema) {
|
|
102
|
+
var isInitialized = async function () {
|
|
103
|
+
var schemas = await sql.unsafe("SELECT schema_name FROM information_schema.schemata WHERE schema_name = '" + pgSchema + "';");
|
|
104
|
+
return Utils.$$Array.notEmpty(schemas);
|
|
105
|
+
};
|
|
106
|
+
var initialize = async function (entities, staticTables, enums, cleanRun) {
|
|
107
|
+
var queries = makeInitializeTransaction(pgSchema, staticTables, entities, enums, cleanRun);
|
|
108
|
+
await sql.begin(function (sql) {
|
|
109
|
+
return queries.map(function (query) {
|
|
110
|
+
return sql.unsafe(query);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
isInitialized: isInitialized,
|
|
116
|
+
initialize: initialize
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
exports.makeCreateIndexSqlUnsafe = makeCreateIndexSqlUnsafe;
|
|
121
|
+
exports.makeCreateTableIndicesSqlUnsafe = makeCreateTableIndicesSqlUnsafe;
|
|
122
|
+
exports.makeCreateTableSqlUnsafe = makeCreateTableSqlUnsafe;
|
|
123
|
+
exports.makeInitializeTransaction = makeInitializeTransaction;
|
|
124
|
+
exports.make = make;
|
|
125
|
+
/* Table Not a pure module */
|
package/src/Prometheus.res
CHANGED
|
@@ -16,12 +16,6 @@ let executeBatchDurationCounter = PromClient.Counter.makeCounter({
|
|
|
16
16
|
"labelNames": [],
|
|
17
17
|
})
|
|
18
18
|
|
|
19
|
-
let eventsProcessedCounter = PromClient.Gauge.makeGauge({
|
|
20
|
-
"name": "events_processed",
|
|
21
|
-
"help": "Total number of events processed",
|
|
22
|
-
"labelNames": ["chainId"],
|
|
23
|
-
})
|
|
24
|
-
|
|
25
19
|
let allChainsSyncedToHead = PromClient.Gauge.makeGauge({
|
|
26
20
|
"name": "hyperindex_synced_to_head",
|
|
27
21
|
"help": "All chains fully synced",
|
|
@@ -207,12 +201,6 @@ module BenchmarkSummaryData = {
|
|
|
207
201
|
}
|
|
208
202
|
}
|
|
209
203
|
|
|
210
|
-
let processedUntilHeight = PromClient.Gauge.makeGauge({
|
|
211
|
-
"name": "chain_block_height_processed",
|
|
212
|
-
"help": "Block height processed by indexer",
|
|
213
|
-
"labelNames": ["chainId"],
|
|
214
|
-
})
|
|
215
|
-
|
|
216
204
|
let incrementLoadEntityDurationCounter = (~duration) => {
|
|
217
205
|
loadEntitiesDurationCounter->PromClient.Counter.incMany(duration)
|
|
218
206
|
}
|
|
@@ -225,12 +213,6 @@ let incrementExecuteBatchDurationCounter = (~duration) => {
|
|
|
225
213
|
executeBatchDurationCounter->PromClient.Counter.incMany(duration)
|
|
226
214
|
}
|
|
227
215
|
|
|
228
|
-
let setEventsProcessedGuage = (~number, ~chainId) => {
|
|
229
|
-
eventsProcessedCounter
|
|
230
|
-
->PromClient.Gauge.labels({"chainId": chainId})
|
|
231
|
-
->PromClient.Gauge.set(number)
|
|
232
|
-
}
|
|
233
|
-
|
|
234
216
|
let setSourceChainHeight = (~blockNumber, ~chain) => {
|
|
235
217
|
sourceChainHeight
|
|
236
218
|
->PromClient.Gauge.labels({"chainId": chain->ChainMap.Chain.toString})
|
|
@@ -241,12 +223,6 @@ let setAllChainsSyncedToHead = () => {
|
|
|
241
223
|
allChainsSyncedToHead->PromClient.Gauge.set(1)
|
|
242
224
|
}
|
|
243
225
|
|
|
244
|
-
let setProcessedUntilHeight = (~blockNumber, ~chain) => {
|
|
245
|
-
processedUntilHeight
|
|
246
|
-
->PromClient.Gauge.labels({"chainId": chain->ChainMap.Chain.toString})
|
|
247
|
-
->PromClient.Gauge.set(blockNumber)
|
|
248
|
-
}
|
|
249
|
-
|
|
250
226
|
module BenchmarkCounters = {
|
|
251
227
|
type labels = {label: string}
|
|
252
228
|
let labelSchema = S.schema(s => {
|
|
@@ -304,18 +280,6 @@ module Info = {
|
|
|
304
280
|
}
|
|
305
281
|
}
|
|
306
282
|
|
|
307
|
-
module ProgressBlockNumber = {
|
|
308
|
-
let gauge = SafeGauge.makeOrThrow(
|
|
309
|
-
~name="envio_progress_block_number",
|
|
310
|
-
~help="The block number to track the progress of indexing at. Currently uses the fully fetched block number. In the future will be changed to block number processed and stored in the database.",
|
|
311
|
-
~labelSchema=chainIdLabelsSchema,
|
|
312
|
-
)
|
|
313
|
-
|
|
314
|
-
let set = (~blockNumber, ~chainId) => {
|
|
315
|
-
gauge->SafeGauge.handleInt(~labels=chainId, ~value=blockNumber)
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
283
|
module IndexingAddresses = {
|
|
320
284
|
let gauge = SafeGauge.makeOrThrow(
|
|
321
285
|
~name="envio_indexing_addresses",
|
|
@@ -428,8 +392,6 @@ module IndexingBufferBlockNumber = {
|
|
|
428
392
|
deprecatedGauge
|
|
429
393
|
->PromClient.Gauge.labels({"chainId": chainId})
|
|
430
394
|
->PromClient.Gauge.set(blockNumber)
|
|
431
|
-
// TODO: Use the block number stored in the database instead
|
|
432
|
-
ProgressBlockNumber.set(~blockNumber, ~chainId)
|
|
433
395
|
gauge->SafeGauge.handleInt(~labels=chainId, ~value=blockNumber)
|
|
434
396
|
}
|
|
435
397
|
}
|
|
@@ -484,7 +446,7 @@ module ReorgCount = {
|
|
|
484
446
|
"labelNames": ["chainId"],
|
|
485
447
|
})
|
|
486
448
|
|
|
487
|
-
let
|
|
449
|
+
let gauge = SafeGauge.makeOrThrow(
|
|
488
450
|
~name="envio_reorg_count",
|
|
489
451
|
~help="Total number of reorgs detected",
|
|
490
452
|
~labelSchema=chainIdLabelsSchema,
|
|
@@ -494,7 +456,7 @@ module ReorgCount = {
|
|
|
494
456
|
deprecatedCounter
|
|
495
457
|
->PromClient.Counter.labels({"chainId": chain->ChainMap.Chain.toString})
|
|
496
458
|
->PromClient.Counter.inc
|
|
497
|
-
|
|
459
|
+
gauge->SafeGauge.increment(~labels=chain->ChainMap.Chain.toChainId)
|
|
498
460
|
}
|
|
499
461
|
}
|
|
500
462
|
|
|
@@ -545,6 +507,30 @@ module RollbackTargetBlockNumber = {
|
|
|
545
507
|
}
|
|
546
508
|
}
|
|
547
509
|
|
|
510
|
+
module ProcessingBlockNumber = {
|
|
511
|
+
let gauge = SafeGauge.makeOrThrow(
|
|
512
|
+
~name="envio_processing_block_number",
|
|
513
|
+
~help="The latest item block number included in the currently processing batch for the chain.",
|
|
514
|
+
~labelSchema=chainIdLabelsSchema,
|
|
515
|
+
)
|
|
516
|
+
|
|
517
|
+
let set = (~blockNumber, ~chainId) => {
|
|
518
|
+
gauge->SafeGauge.handleInt(~labels=chainId, ~value=blockNumber)
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
module ProcessingBatchSize = {
|
|
523
|
+
let gauge = SafeGauge.makeOrThrow(
|
|
524
|
+
~name="envio_processing_batch_size",
|
|
525
|
+
~help="The number of items included in the currently processing batch for the chain.",
|
|
526
|
+
~labelSchema=chainIdLabelsSchema,
|
|
527
|
+
)
|
|
528
|
+
|
|
529
|
+
let set = (~batchSize, ~chainId) => {
|
|
530
|
+
gauge->SafeGauge.handleInt(~labels=chainId, ~value=batchSize)
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
548
534
|
module ProcessingMaxBatchSize = {
|
|
549
535
|
let gauge = PromClient.Gauge.makeGauge({
|
|
550
536
|
"name": "envio_processing_max_batch_size",
|
|
@@ -555,3 +541,52 @@ module ProcessingMaxBatchSize = {
|
|
|
555
541
|
gauge->PromClient.Gauge.set(maxBatchSize)
|
|
556
542
|
}
|
|
557
543
|
}
|
|
544
|
+
|
|
545
|
+
module ProgressBlockNumber = {
|
|
546
|
+
let gauge = SafeGauge.makeOrThrow(
|
|
547
|
+
~name="envio_progress_block_number",
|
|
548
|
+
~help="The block number of the latest block processed and stored in the database.",
|
|
549
|
+
~labelSchema=chainIdLabelsSchema,
|
|
550
|
+
)
|
|
551
|
+
|
|
552
|
+
let set = (~blockNumber, ~chainId) => {
|
|
553
|
+
gauge->SafeGauge.handleInt(~labels=chainId, ~value=blockNumber)
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
module ProgressEventsCount = {
|
|
558
|
+
let deprecatedGauge = PromClient.Gauge.makeGauge({
|
|
559
|
+
"name": "events_processed",
|
|
560
|
+
"help": "Total number of events processed",
|
|
561
|
+
"labelNames": ["chainId"],
|
|
562
|
+
})
|
|
563
|
+
|
|
564
|
+
let gauge = SafeGauge.makeOrThrow(
|
|
565
|
+
~name="envio_progress_events_count",
|
|
566
|
+
~help="The number of events processed and reflected in the database.",
|
|
567
|
+
~labelSchema=chainIdLabelsSchema,
|
|
568
|
+
)
|
|
569
|
+
|
|
570
|
+
let set = (~processedCount, ~chainId) => {
|
|
571
|
+
deprecatedGauge
|
|
572
|
+
->PromClient.Gauge.labels({"chainId": chainId})
|
|
573
|
+
->PromClient.Gauge.set(processedCount)
|
|
574
|
+
gauge->SafeGauge.handleInt(~labels=chainId, ~value=processedCount)
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
let effectLabelsSchema = S.object(s => {
|
|
579
|
+
s.field("effect", S.string)
|
|
580
|
+
})
|
|
581
|
+
|
|
582
|
+
module EffectCallsCount = {
|
|
583
|
+
let gauge = SafeGauge.makeOrThrow(
|
|
584
|
+
~name="envio_effect_calls_count",
|
|
585
|
+
~help="The number of calls to the effect. Including both handler execution and cache hits.",
|
|
586
|
+
~labelSchema=effectLabelsSchema,
|
|
587
|
+
)
|
|
588
|
+
|
|
589
|
+
let set = (~callsCount, ~effectName) => {
|
|
590
|
+
gauge->SafeGauge.handleInt(~labels=effectName, ~value=callsCount)
|
|
591
|
+
}
|
|
592
|
+
}
|