@secondlayer/subgraphs 4.2.1 → 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.
@@ -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
- * Subscription receivers that already consumed the now-reverted events
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 subscription. The receiver is expected to
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 emitSubscriptionOutbox(tx, subgraphName, manifest, matcher, blockHeight) {
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
- subscription_id: s.id,
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("subscription_outbox").values(rows).onConflict((oc) => oc.columns(["subscription_id", "dedup_key"]).doNothing()).execute();
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/subscription-state.ts
3051
- import { listSubscriptions } from "@secondlayer/shared/db/queries/subscriptions";
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 SubscriptionMatcher {
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/subscription-state.ts
3214
- var matcher = new SubscriptionMatcher;
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 subscriptions WHERE status = 'active'
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 emitSubscriptionOutbox(tx, subgraphName, manifest, matcher, block.height);
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("subscription_outbox").columns([
4069
- "subscription_id",
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("subscriptions").select((eb2) => [
4079
- "id as subscription_id",
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(["subscription_id", "dedup_key"]).doNothing()).execute().catch((err) => {
4098
- logger10.error("Failed to emit revert event for subscriptions", {
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=C83516F4FE20D8A864756E2164756E21
4123
+ //# debugId=33AD56BC3ED3D91464756E2164756E21
4124
4124
  //# sourceMappingURL=reorg.js.map