@secondlayer/subgraphs 1.3.1 → 1.3.3
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 +1 -1
- package/dist/src/index.js +22 -11
- package/dist/src/index.js.map +8 -8
- package/dist/src/runtime/block-processor.js +4 -4
- package/dist/src/runtime/block-processor.js.map +5 -5
- package/dist/src/runtime/catchup.d.ts +16 -2
- package/dist/src/runtime/catchup.js +68 -20
- package/dist/src/runtime/catchup.js.map +6 -6
- package/dist/src/runtime/context.js +4 -4
- package/dist/src/runtime/context.js.map +3 -3
- package/dist/src/runtime/processor.js +87 -31
- package/dist/src/runtime/processor.js.map +13 -13
- package/dist/src/runtime/reindex.js +22 -11
- package/dist/src/runtime/reindex.js.map +7 -7
- package/dist/src/runtime/reorg.js +4 -4
- package/dist/src/runtime/reorg.js.map +5 -5
- package/dist/src/schema/index.js +6 -6
- package/dist/src/schema/index.js.map +4 -4
- package/dist/src/service.js +87 -31
- package/dist/src/service.js.map +13 -13
- package/dist/src/validate.js.map +2 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ export default defineSubgraph({
|
|
|
51
51
|
});
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
Deploy via CLI (`sl subgraphs deploy path/to/definition.ts`), SDK (`sl.subgraphs.deploy({...})`), or MCP (`subgraphs_deploy`). The dashboard is read-only — creation always happens through an API surface.
|
|
54
|
+
Deploy via CLI (`sl subgraphs deploy path/to/definition.ts`), SDK (`sl.subgraphs.deploy({...})`), or MCP (`subgraphs_deploy`). The CLI can also scaffold from a deployed contract with `sl subgraphs scaffold <contract> -o subgraphs/name.ts`; scaffold writes or amends `package.json` and runs `bun install` unless `--no-install` is passed. The dashboard is read-only — creation always happens through an API surface.
|
|
55
55
|
|
|
56
56
|
## Exports
|
|
57
57
|
|
package/dist/src/index.js
CHANGED
|
@@ -256,9 +256,9 @@ class SubgraphContext {
|
|
|
256
256
|
const blockHeight = op.data._block_height ?? this.block.height;
|
|
257
257
|
const txId = op.data._tx_id ?? this._tx.txId;
|
|
258
258
|
const baseRow = op.kind === "update" ? { ...op.data, ...op.set ?? {} } : { ...op.data };
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
259
|
+
baseRow._upsert_keys = undefined;
|
|
260
|
+
baseRow._upsert_fallback_keys = undefined;
|
|
261
|
+
baseRow._upsert_fallback_set = undefined;
|
|
262
262
|
return {
|
|
263
263
|
op: op.kind,
|
|
264
264
|
table: op.table,
|
|
@@ -1405,16 +1405,16 @@ function generateSubgraphSQL(def, schemaNameOverride) {
|
|
|
1405
1405
|
const statements = [];
|
|
1406
1406
|
const needsTrgm = Object.values(def.schema).some((table) => Object.values(table.columns).some((col) => col.search));
|
|
1407
1407
|
if (needsTrgm) {
|
|
1408
|
-
statements.push(
|
|
1408
|
+
statements.push("CREATE EXTENSION IF NOT EXISTS pg_trgm");
|
|
1409
1409
|
}
|
|
1410
1410
|
statements.push(`CREATE SCHEMA IF NOT EXISTS ${schemaName}`);
|
|
1411
1411
|
for (const [tableName, tableDef] of Object.entries(def.schema)) {
|
|
1412
1412
|
const qualifiedName = `${schemaName}.${tableName}`;
|
|
1413
1413
|
const columnDefs = [
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1414
|
+
"_id BIGSERIAL PRIMARY KEY",
|
|
1415
|
+
"_block_height BIGINT NOT NULL",
|
|
1416
|
+
"_tx_id TEXT NOT NULL",
|
|
1417
|
+
"_created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()"
|
|
1418
1418
|
];
|
|
1419
1419
|
for (const [colName, col] of Object.entries(tableDef.columns)) {
|
|
1420
1420
|
const sqlType = TYPE_MAP[col.type];
|
|
@@ -1510,6 +1510,7 @@ function avgEventsPerBlock(batch) {
|
|
|
1510
1510
|
// src/runtime/reindex.ts
|
|
1511
1511
|
var LOG_INTERVAL = 1000;
|
|
1512
1512
|
var HEALTH_FLUSH_INTERVAL = 1000;
|
|
1513
|
+
var PROGRESS_FLUSH_INTERVAL_MS = 5000;
|
|
1513
1514
|
var HOBBY_REINDEX_BATCH_CONFIG = {
|
|
1514
1515
|
defaultBatchSize: 50,
|
|
1515
1516
|
minBatchSize: 25,
|
|
@@ -1584,6 +1585,8 @@ async function processBlockRange(def, opts) {
|
|
|
1584
1585
|
let pendingErrors = 0;
|
|
1585
1586
|
let pendingLastError;
|
|
1586
1587
|
let lastHealthFlushBlock = 0;
|
|
1588
|
+
let lastHealthFlushAt = Date.now();
|
|
1589
|
+
let lastProgressFlushAt = Date.now();
|
|
1587
1590
|
const batchConfig = resolveReindexBatchConfig();
|
|
1588
1591
|
let batchSize = batchConfig.defaultBatchSize;
|
|
1589
1592
|
let currentHeight = fromBlock;
|
|
@@ -1596,6 +1599,7 @@ async function processBlockRange(def, opts) {
|
|
|
1596
1599
|
pendingErrors = 0;
|
|
1597
1600
|
pendingLastError = undefined;
|
|
1598
1601
|
lastHealthFlushBlock = blocksProcessed;
|
|
1602
|
+
lastHealthFlushAt = Date.now();
|
|
1599
1603
|
};
|
|
1600
1604
|
let nextBatchEnd = Math.min(currentHeight + batchSize - 1, toBlock);
|
|
1601
1605
|
let nextBatchPromise = loadBlockRange(sourceDb, currentHeight, nextBatchEnd);
|
|
@@ -1659,8 +1663,11 @@ async function processBlockRange(def, opts) {
|
|
|
1659
1663
|
await stats.flush(targetDb);
|
|
1660
1664
|
}
|
|
1661
1665
|
}
|
|
1662
|
-
|
|
1666
|
+
const now = Date.now();
|
|
1667
|
+
const shouldFlushProgress = blocksProcessed % 100 === 0 || now - lastProgressFlushAt >= PROGRESS_FLUSH_INTERVAL_MS;
|
|
1668
|
+
if (shouldFlushProgress) {
|
|
1663
1669
|
await updateSubgraphStatus2(targetDb, subgraphName, status, height);
|
|
1670
|
+
lastProgressFlushAt = now;
|
|
1664
1671
|
}
|
|
1665
1672
|
if (blocksProcessed % LOG_INTERVAL === 0) {
|
|
1666
1673
|
logger5.info(`${status === "reindexing" ? "Reindex" : "Backfill"} progress`, {
|
|
@@ -1672,7 +1679,11 @@ async function processBlockRange(def, opts) {
|
|
|
1672
1679
|
});
|
|
1673
1680
|
}
|
|
1674
1681
|
}
|
|
1675
|
-
if (
|
|
1682
|
+
if (status === "reindexing" && blocksProcessed > 0) {
|
|
1683
|
+
await updateSubgraphStatus2(targetDb, subgraphName, status, batchEnd);
|
|
1684
|
+
}
|
|
1685
|
+
const shouldFlushHealth = blocksProcessed - lastHealthFlushBlock >= HEALTH_FLUSH_INTERVAL || Date.now() - lastHealthFlushAt >= PROGRESS_FLUSH_INTERVAL_MS;
|
|
1686
|
+
if (shouldFlushHealth) {
|
|
1676
1687
|
await flushHealth();
|
|
1677
1688
|
}
|
|
1678
1689
|
if (batchFailedBlocks.length > 0 && opts.subgraphId) {
|
|
@@ -2147,5 +2158,5 @@ export {
|
|
|
2147
2158
|
backfillSubgraph
|
|
2148
2159
|
};
|
|
2149
2160
|
|
|
2150
|
-
//# debugId=
|
|
2161
|
+
//# debugId=6E118676092C466764756E2164756E21
|
|
2151
2162
|
//# sourceMappingURL=index.js.map
|