@secondlayer/subgraphs 4.2.0 → 4.3.0
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 +9 -9
- package/dist/src/index.js +11 -11
- package/dist/src/index.js.map +9 -9
- package/dist/src/runtime/block-processor.js +11 -11
- package/dist/src/runtime/block-processor.js.map +9 -9
- package/dist/src/runtime/catchup.js +11 -11
- package/dist/src/runtime/catchup.js.map +9 -9
- package/dist/src/runtime/context.d.ts +1 -1
- package/dist/src/runtime/context.js.map +1 -1
- package/dist/src/runtime/emitter.d.ts +10 -10
- package/dist/src/runtime/emitter.js +68 -44
- package/dist/src/runtime/emitter.js.map +14 -13
- package/dist/src/runtime/processor.js +64 -36
- package/dist/src/runtime/processor.js.map +13 -12
- package/dist/src/runtime/reindex.js +11 -11
- package/dist/src/runtime/reindex.js.map +9 -9
- package/dist/src/runtime/reorg.d.ts +2 -2
- package/dist/src/runtime/reorg.js +17 -17
- package/dist/src/runtime/reorg.js.map +10 -10
- package/dist/src/runtime/replay.d.ts +6 -6
- package/dist/src/runtime/replay.js +26 -26
- package/dist/src/runtime/replay.js.map +4 -4
- package/dist/src/runtime/runner.d.ts +1 -1
- package/dist/src/service.js +79 -36
- package/dist/src/service.js.map +14 -13
- package/dist/src/testing/index.js.map +1 -1
- package/dist/src/triggers/index.d.ts +2 -2
- package/dist/src/triggers/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -405,9 +405,9 @@ import { Subgraph } from "@secondlayer/shared/db";
|
|
|
405
405
|
* subgraph table, then reprocess `blockHeight` (subsequent heights will
|
|
406
406
|
* be reprocessed as the indexer ingests new-chain blocks).
|
|
407
407
|
*
|
|
408
|
-
*
|
|
408
|
+
* Webhook receivers that already consumed the now-reverted events
|
|
409
409
|
* need to know about the rollback. We emit one `<table>.reverted` event
|
|
410
|
-
* per affected table per
|
|
410
|
+
* per affected table per webhook. The receiver is expected to
|
|
411
411
|
* reverse any side-effects keyed on the rolled-back rows; if they ignore
|
|
412
412
|
* revert events, at least we provided the signal.
|
|
413
413
|
*/
|
|
@@ -2701,7 +2701,7 @@ function stableStringify(obj) {
|
|
|
2701
2701
|
return acc;
|
|
2702
2702
|
}, {}));
|
|
2703
2703
|
}
|
|
2704
|
-
async function
|
|
2704
|
+
async function emitWebhookOutbox(tx, subgraphName, manifest, matcher, blockHeight) {
|
|
2705
2705
|
if (!isEmitOutboxEnabled()) {
|
|
2706
2706
|
if (!loggedKillSwitch) {
|
|
2707
2707
|
logger6.warn("SECONDLAYER_EMIT_OUTBOX=false — outbox emission bypassed");
|
|
@@ -2720,7 +2720,7 @@ async function emitSubscriptionOutbox(tx, subgraphName, manifest, matcher, block
|
|
|
2720
2720
|
const eventType = `${subgraphName}.${write.table}.${OP_VERB[write.op]}`;
|
|
2721
2721
|
for (const s of subs) {
|
|
2722
2722
|
rows.push({
|
|
2723
|
-
|
|
2723
|
+
webhook_id: s.id,
|
|
2724
2724
|
subgraph_name: subgraphName,
|
|
2725
2725
|
table_name: write.table,
|
|
2726
2726
|
block_height: blockHeight,
|
|
@@ -2734,7 +2734,7 @@ async function emitSubscriptionOutbox(tx, subgraphName, manifest, matcher, block
|
|
|
2734
2734
|
}
|
|
2735
2735
|
if (rows.length === 0)
|
|
2736
2736
|
return 0;
|
|
2737
|
-
await tx.insertInto("
|
|
2737
|
+
await tx.insertInto("webhook_outbox").values(rows).onConflict((oc) => oc.columns(["webhook_id", "dedup_key"]).doNothing()).execute();
|
|
2738
2738
|
return rows.length;
|
|
2739
2739
|
}
|
|
2740
2740
|
|
|
@@ -3047,8 +3047,8 @@ async function answerRead(hostCtx, msg) {
|
|
|
3047
3047
|
}
|
|
3048
3048
|
}
|
|
3049
3049
|
|
|
3050
|
-
// src/runtime/
|
|
3051
|
-
import {
|
|
3050
|
+
// src/runtime/webhook-state.ts
|
|
3051
|
+
import { listWebhooks } from "@secondlayer/shared/db/queries/webhooks";
|
|
3052
3052
|
import { sql as sql3 } from "kysely";
|
|
3053
3053
|
|
|
3054
3054
|
// src/runtime/emitter-matcher.ts
|
|
@@ -3168,7 +3168,7 @@ function key(subgraphName, tableName) {
|
|
|
3168
3168
|
return `${subgraphName}\x00${tableName}`;
|
|
3169
3169
|
}
|
|
3170
3170
|
|
|
3171
|
-
class
|
|
3171
|
+
class WebhookMatcher {
|
|
3172
3172
|
byKey = new Map;
|
|
3173
3173
|
byId = new Map;
|
|
3174
3174
|
setAll(subs) {
|
|
@@ -3210,11 +3210,11 @@ class SubscriptionMatcher {
|
|
|
3210
3210
|
}
|
|
3211
3211
|
}
|
|
3212
3212
|
|
|
3213
|
-
// src/runtime/
|
|
3214
|
-
var matcher = new
|
|
3213
|
+
// src/runtime/webhook-state.ts
|
|
3214
|
+
var matcher = new WebhookMatcher;
|
|
3215
3215
|
async function refreshMatcher(db) {
|
|
3216
3216
|
const rows = await sql3`
|
|
3217
|
-
SELECT * FROM
|
|
3217
|
+
SELECT * FROM webhooks WHERE status = 'active'
|
|
3218
3218
|
`.execute(db);
|
|
3219
3219
|
matcher.setAll(rows.rows);
|
|
3220
3220
|
return matcher.size();
|
|
@@ -3504,7 +3504,7 @@ async function processBlock(subgraph, subgraphName, blockHeight, opts) {
|
|
|
3504
3504
|
const manifest = await ctx.flush();
|
|
3505
3505
|
flushedWrites = manifest.count > 0;
|
|
3506
3506
|
if (manifest.count > 0) {
|
|
3507
|
-
await
|
|
3507
|
+
await emitWebhookOutbox(tx, subgraphName, manifest, matcher, block.height);
|
|
3508
3508
|
}
|
|
3509
3509
|
flushMs = performance.now() - flushStart;
|
|
3510
3510
|
}
|
|
@@ -4065,8 +4065,8 @@ async function reorgOneSubgraph(sg, schema, blockHeight, loadSubgraphDef) {
|
|
|
4065
4065
|
for (const [tableName, rows] of Object.entries(revertedByTable)) {
|
|
4066
4066
|
if (rows.length === 0)
|
|
4067
4067
|
continue;
|
|
4068
|
-
await targetDb.insertInto("
|
|
4069
|
-
"
|
|
4068
|
+
await targetDb.insertInto("webhook_outbox").columns([
|
|
4069
|
+
"webhook_id",
|
|
4070
4070
|
"subgraph_name",
|
|
4071
4071
|
"table_name",
|
|
4072
4072
|
"block_height",
|
|
@@ -4075,8 +4075,8 @@ async function reorgOneSubgraph(sg, schema, blockHeight, loadSubgraphDef) {
|
|
|
4075
4075
|
"dedup_key",
|
|
4076
4076
|
"row_pk",
|
|
4077
4077
|
"status"
|
|
4078
|
-
]).expression((eb) => eb.selectFrom("
|
|
4079
|
-
"id as
|
|
4078
|
+
]).expression((eb) => eb.selectFrom("webhooks").select((eb2) => [
|
|
4079
|
+
"id as webhook_id",
|
|
4080
4080
|
eb2.val(sg.name).as("subgraph_name"),
|
|
4081
4081
|
eb2.val(tableName).as("table_name"),
|
|
4082
4082
|
eb2.val(blockHeight).as("block_height"),
|
|
@@ -4094,8 +4094,8 @@ async function reorgOneSubgraph(sg, schema, blockHeight, loadSubgraphDef) {
|
|
|
4094
4094
|
reorgRoot: blockHeight
|
|
4095
4095
|
}).as("row_pk"),
|
|
4096
4096
|
eb2.val("pending").as("status")
|
|
4097
|
-
]).where("subgraph_name", "=", sg.name).where("table_name", "=", tableName).where("status", "=", "active")).onConflict((oc) => oc.columns(["
|
|
4098
|
-
logger10.error("Failed to emit revert event for
|
|
4097
|
+
]).where("subgraph_name", "=", sg.name).where("table_name", "=", tableName).where("status", "=", "active")).onConflict((oc) => oc.columns(["webhook_id", "dedup_key"]).doNothing()).execute().catch((err) => {
|
|
4098
|
+
logger10.error("Failed to emit revert event for webhooks", {
|
|
4099
4099
|
event: "reorg_revert_emit_dropped",
|
|
4100
4100
|
subgraph: sg.name,
|
|
4101
4101
|
table: tableName,
|
|
@@ -4120,5 +4120,5 @@ export {
|
|
|
4120
4120
|
handleSubgraphReorg
|
|
4121
4121
|
};
|
|
4122
4122
|
|
|
4123
|
-
//# debugId=
|
|
4123
|
+
//# debugId=33AD56BC3ED3D91464756E2164756E21
|
|
4124
4124
|
//# sourceMappingURL=reorg.js.map
|