envio 3.0.0-alpha.22 → 3.0.0-alpha.23
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 +3 -3
- package/package.json +6 -6
- package/src/Main.res +2 -0
- package/src/Main.res.mjs +4 -2
- package/src/Persistence.res +3 -0
- package/src/PgStorage.res +3 -0
- package/src/PgStorage.res.mjs +3 -1
- package/src/TestIndexerProxyStorage.res +1 -0
- package/src/TestIndexerProxyStorage.res.mjs +2 -1
- package/src/bindings/Postgres.res +5 -0
package/README.md
CHANGED
|
@@ -107,9 +107,9 @@ This scaffolds your entire indexer project, config, schema, and handler function
|
|
|
107
107
|
|
|
108
108
|
From there, three files define your indexer:
|
|
109
109
|
|
|
110
|
-
- `config.yaml
|
|
111
|
-
- `schema.graphql
|
|
112
|
-
- `src/EventHandlers
|
|
110
|
+
- `config.yaml`: networks, contracts, events, and indexing behaviour
|
|
111
|
+
- `schema.graphql`: the shape of your indexed data
|
|
112
|
+
- `src/EventHandlers.*`: your handler logic in TypeScript, JavaScript, or ReScript
|
|
113
113
|
|
|
114
114
|
[Full getting started guide →](https://docs.envio.dev/docs/HyperIndex/getting-started)
|
|
115
115
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "envio",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.23",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A latency and sync speed optimized, developer friendly blockchain data indexer.",
|
|
6
6
|
"bin": "./bin.mjs",
|
|
@@ -71,10 +71,10 @@
|
|
|
71
71
|
"tsx": "4.21.0"
|
|
72
72
|
},
|
|
73
73
|
"optionalDependencies": {
|
|
74
|
-
"envio-linux-x64": "3.0.0-alpha.
|
|
75
|
-
"envio-linux-x64-musl": "3.0.0-alpha.
|
|
76
|
-
"envio-linux-arm64": "3.0.0-alpha.
|
|
77
|
-
"envio-darwin-x64": "3.0.0-alpha.
|
|
78
|
-
"envio-darwin-arm64": "3.0.0-alpha.
|
|
74
|
+
"envio-linux-x64": "3.0.0-alpha.23",
|
|
75
|
+
"envio-linux-x64-musl": "3.0.0-alpha.23",
|
|
76
|
+
"envio-linux-arm64": "3.0.0-alpha.23",
|
|
77
|
+
"envio-darwin-x64": "3.0.0-alpha.23",
|
|
78
|
+
"envio-darwin-arm64": "3.0.0-alpha.23"
|
|
79
79
|
}
|
|
80
80
|
}
|
package/src/Main.res
CHANGED
|
@@ -615,12 +615,14 @@ let migrate = async (~reset, ~persistedState) => {
|
|
|
615
615
|
let persistence = PgStorage.makePersistenceFromConfig(~config)
|
|
616
616
|
await persistence->Persistence.init(~reset, ~chainConfigs=config.chainMap->ChainMap.values)
|
|
617
617
|
await Core.upsertPersistedState(persistedState->JSON.stringify)
|
|
618
|
+
await persistence.storage.close()
|
|
618
619
|
}
|
|
619
620
|
|
|
620
621
|
let dropSchema = async () => {
|
|
621
622
|
let config = Config.loadWithoutRegistrations()
|
|
622
623
|
let persistence = PgStorage.makePersistenceFromConfig(~config)
|
|
623
624
|
await persistence.storage.reset()
|
|
625
|
+
await persistence.storage.close()
|
|
624
626
|
}
|
|
625
627
|
|
|
626
628
|
let start = async (
|
package/src/Main.res.mjs
CHANGED
|
@@ -468,13 +468,15 @@ async function migrate(reset, persistedState) {
|
|
|
468
468
|
let config = Config.loadWithoutRegistrations();
|
|
469
469
|
let persistence = PgStorage.makePersistenceFromConfig(config, undefined);
|
|
470
470
|
await Persistence.init(persistence, ChainMap.values(config.chainMap), reset);
|
|
471
|
-
|
|
471
|
+
await Core.upsertPersistedState(JSON.stringify(persistedState));
|
|
472
|
+
return await persistence.storage.close();
|
|
472
473
|
}
|
|
473
474
|
|
|
474
475
|
async function dropSchema() {
|
|
475
476
|
let config = Config.loadWithoutRegistrations();
|
|
476
477
|
let persistence = PgStorage.makePersistenceFromConfig(config, undefined);
|
|
477
|
-
|
|
478
|
+
await persistence.storage.reset();
|
|
479
|
+
return await persistence.storage.close();
|
|
478
480
|
}
|
|
479
481
|
|
|
480
482
|
async function start(persistence, migrate, isTestOpt, exitAfterFirstEventBlockOpt, patchConfig) {
|
package/src/Persistence.res
CHANGED
|
@@ -121,6 +121,9 @@ type storage = {
|
|
|
121
121
|
~updatedEffectsCache: array<updatedEffectCache>,
|
|
122
122
|
~updatedEntities: array<updatedEntity>,
|
|
123
123
|
) => promise<unit>,
|
|
124
|
+
// Release any long-lived resources (e.g. the postgres connection pool) so
|
|
125
|
+
// short-lived CLI commands like `db-migrate setup` can exit cleanly.
|
|
126
|
+
close: unit => promise<unit>,
|
|
124
127
|
}
|
|
125
128
|
|
|
126
129
|
type storageStatus =
|
package/src/PgStorage.res
CHANGED
|
@@ -1648,6 +1648,8 @@ SELECT id, chain_id, -1, -1, contract_name FROM unnest($1::text[],$2::int[],$3::
|
|
|
1648
1648
|
)
|
|
1649
1649
|
}
|
|
1650
1650
|
|
|
1651
|
+
let close = () => sql->Postgres.endSql
|
|
1652
|
+
|
|
1651
1653
|
{
|
|
1652
1654
|
name: "postgres",
|
|
1653
1655
|
isInitialized,
|
|
@@ -1664,6 +1666,7 @@ SELECT id, chain_id, -1, -1, contract_name FROM unnest($1::text[],$2::int[],$3::
|
|
|
1664
1666
|
getRollbackProgressDiff,
|
|
1665
1667
|
getRollbackData,
|
|
1666
1668
|
writeBatch: writeBatchMethod,
|
|
1669
|
+
close,
|
|
1667
1670
|
}
|
|
1668
1671
|
}
|
|
1669
1672
|
|
package/src/PgStorage.res.mjs
CHANGED
|
@@ -1026,6 +1026,7 @@ SELECT id, chain_id, -1, -1, contract_name FROM unnest($1::text[],$2::int[],$3::
|
|
|
1026
1026
|
await writeBatch(sql, batch, rawEvents, pgSchema, rollbackTargetCheckpointId, isInReorgThreshold, config, allEntities, setEffectCacheOrThrow, updatedEffectsCache, updatedEntities, sinkPromise, undefined);
|
|
1027
1027
|
return Prometheus.StorageWrite.increment("postgres", Hrtime.toSecondsFloat(Hrtime.timeSince(primaryTimerRef)));
|
|
1028
1028
|
};
|
|
1029
|
+
let close = () => sql.end();
|
|
1029
1030
|
return {
|
|
1030
1031
|
name: "postgres",
|
|
1031
1032
|
isInitialized: isInitialized,
|
|
@@ -1041,7 +1042,8 @@ SELECT id, chain_id, -1, -1, contract_name FROM unnest($1::text[],$2::int[],$3::
|
|
|
1041
1042
|
getRollbackTargetCheckpoint: getRollbackTargetCheckpoint,
|
|
1042
1043
|
getRollbackProgressDiff: getRollbackProgressDiff,
|
|
1043
1044
|
getRollbackData: getRollbackData,
|
|
1044
|
-
writeBatch: writeBatchMethod
|
|
1045
|
+
writeBatch: writeBatchMethod,
|
|
1046
|
+
close: close
|
|
1045
1047
|
};
|
|
1046
1048
|
}
|
|
1047
1049
|
|
|
@@ -90,6 +90,11 @@ external makeSql: (~config: poolConfig) => sql = "default"
|
|
|
90
90
|
|
|
91
91
|
@send external beginSql: (sql, sql => promise<'result>) => promise<'result> = "begin"
|
|
92
92
|
|
|
93
|
+
// Graceful pool shutdown — drains in-flight queries, then closes connections.
|
|
94
|
+
// Without this the pool's idle TCP sockets keep Node's event loop alive after
|
|
95
|
+
// short-lived commands (db-migrate, drop-schema) finish their work.
|
|
96
|
+
@send external endSql: sql => promise<unit> = "end"
|
|
97
|
+
|
|
93
98
|
// TODO: can explore this approach (https://forum.rescript-lang.org/t/rfc-support-for-tagged-template-literals/3744)
|
|
94
99
|
// @send @variadic
|
|
95
100
|
// external sql: array<string> => (sql, array<string>) => int = "sql"
|