@secondlayer/subgraphs 4.0.2 → 4.0.4

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 CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  Typed on-chain indexing for Stacks. Declare event filters + column schema with `defineSubgraph()`; the runtime decodes blocks, matches filters, runs your handlers inside a transactional context, and exposes the result as a Postgres schema you query over REST or SQL.
4
4
 
5
- Subgraphs have a visibility: deploys default `visibility: public` — anon-readable at `/v1/subgraphs/<name>/<table>`, in a single global public namespace (409 `PUBLIC_NAME_TAKEN` if the name is taken). Override with `--visibility public|private` at deploy.
6
-
7
5
  Subgraph rows fan out to HTTP subscribers through a post-flush outbox emitter — signed Standard Webhooks POSTs with retries, circuit breaker, and replay.
8
6
 
9
7
  ## Install
@@ -102,8 +100,8 @@ Delivery bodies and response previews land in `subscription_deliveries`. Rows wh
102
100
  Once rows land in your DB, generate a typed schema for your ORM:
103
101
 
104
102
  ```bash
105
- secondlayer subgraphs codegen subgraphs/my.ts --target prisma -o prisma/schema.prisma
106
- secondlayer subgraphs codegen subgraphs/my.ts --target drizzle -o db/schema.ts
103
+ secondlayer codegen subgraph subgraphs/my.ts --target prisma -o prisma/schema.prisma
104
+ secondlayer codegen subgraph subgraphs/my.ts --target drizzle -o db/schema.ts
107
105
  ```
108
106
 
109
107
  Prisma and Drizzle have first-class generators (`generatePrismaSchema` /
package/dist/src/index.js CHANGED
@@ -1868,6 +1868,7 @@ function matchSources(sources, transactions, events, traitContracts = new Map, f
1868
1868
  // src/runtime/block-processor.ts
1869
1869
  import { getTargetDb } from "@secondlayer/shared/db";
1870
1870
  import { resolveTraitContractIds } from "@secondlayer/shared/db/queries/contracts";
1871
+ import { recordGapBatch } from "@secondlayer/shared/db/queries/subgraph-gaps";
1871
1872
  import { advanceOperationCursor } from "@secondlayer/shared/db/queries/subgraph-operations";
1872
1873
  import {
1873
1874
  recordLiveError,
@@ -3020,6 +3021,19 @@ async function processBlock(subgraph, subgraphName, blockHeight, opts) {
3020
3021
  throw new LiveCursorRaceLostError(subgraphName, blockHeight);
3021
3022
  }
3022
3023
  }
3024
+ if (rr.errors > 0 && !rewind) {
3025
+ if (opts?.subgraphId) {
3026
+ await recordGapBatch(tx, opts.subgraphId, subgraphName, [
3027
+ { start: blockHeight, end: blockHeight, reason: "processing_error" }
3028
+ ]);
3029
+ } else {
3030
+ logger7.warn("Block errors not recorded as a gap — no subgraphId", {
3031
+ subgraph: subgraphName,
3032
+ blockHeight,
3033
+ errors: rr.errors
3034
+ });
3035
+ }
3036
+ }
3023
3037
  if (rr.processed > 0 || rr.errors > 0) {
3024
3038
  const lastError = rr.errors > 0 ? `${rr.errors} error(s) at block ${blockHeight}` : undefined;
3025
3039
  await recordSubgraphProcessed(tx, subgraphName, rr.processed, rr.errors, lastError);
@@ -3411,7 +3425,8 @@ async function catchUpSubgraph(subgraph, subgraphName) {
3411
3425
  throw new ReorgEpochChangedError(subgraphName);
3412
3426
  }
3413
3427
  return processBlockWithRetry(subgraph, subgraphName, height, {
3414
- preloaded
3428
+ preloaded,
3429
+ subgraphId: subgraphRow.id
3415
3430
  });
3416
3431
  });
3417
3432
  } catch (err) {
@@ -3470,7 +3485,7 @@ async function catchUpSubgraph(subgraph, subgraphName) {
3470
3485
  import { getErrorMessage as getErrorMessage3 } from "@secondlayer/shared";
3471
3486
  import { getRawClient, getTargetDb as getTargetDb3 } from "@secondlayer/shared/db";
3472
3487
  import {
3473
- recordGapBatch,
3488
+ recordGapBatch as recordGapBatch2,
3474
3489
  resolveGaps
3475
3490
  } from "@secondlayer/shared/db/queries/subgraph-gaps";
3476
3491
  import {
@@ -3753,7 +3768,7 @@ async function processBlockRange(def, opts) {
3753
3768
  }
3754
3769
  if (batchFailedBlocks.length > 0 && opts.subgraphId) {
3755
3770
  const gaps = coalesceFailedBlocks(batchFailedBlocks);
3756
- await recordGapBatch(targetDb, opts.subgraphId, subgraphName, gaps).catch((err) => {
3771
+ await recordGapBatch2(targetDb, opts.subgraphId, subgraphName, gaps).catch((err) => {
3757
3772
  logger10.warn("Failed to record subgraph gaps", {
3758
3773
  subgraph: subgraphName,
3759
3774
  error: err instanceof Error ? err.message : String(err)
@@ -4446,7 +4461,7 @@ function generatePrismaSchema(def, opts = {}) {
4446
4461
  const schemaName = opts.schemaName ?? pgSchemaName(def.name);
4447
4462
  const env = opts.datasourceEnv ?? "DATABASE_URL";
4448
4463
  const header = [
4449
- `// Generated by \`sl subgraphs codegen --target prisma\` from subgraph "${def.name}". Do not edit by hand.`,
4464
+ `// Generated by \`sl codegen subgraph --target prisma\` from subgraph "${def.name}". Do not edit by hand.`,
4450
4465
  "",
4451
4466
  "datasource db {",
4452
4467
  ' provider = "postgresql"',
@@ -4599,7 +4614,7 @@ function generateDrizzleSchema(def, opts = {}) {
4599
4614
  const relationDecls = renderRelations(def.schema);
4600
4615
  const typeExports = Object.keys(def.schema).map((name) => `export type ${pascalCase(name)} = typeof ${snakeToCamel(name)}.$inferSelect;`);
4601
4616
  return [
4602
- `// Generated by \`sl subgraphs codegen --target drizzle\` from subgraph "${def.name}". Do not edit by hand.`,
4617
+ `// Generated by \`sl codegen subgraph --target drizzle\` from subgraph "${def.name}". Do not edit by hand.`,
4603
4618
  imports,
4604
4619
  "",
4605
4620
  `export const sg = pgSchema("${schemaName}");`,
@@ -4658,7 +4673,7 @@ ${dbEntries.join(`
4658
4673
  }`;
4659
4674
  const rowExports = Object.keys(def.schema).map((name) => `export type ${pascalCase(name)}Row = Selectable<${pascalCase(name)}>;`);
4660
4675
  return [
4661
- `// Generated by \`sl subgraphs codegen --target kysely\` from subgraph "${def.name}". Do not edit by hand.`,
4676
+ `// Generated by \`sl codegen subgraph --target kysely\` from subgraph "${def.name}". Do not edit by hand.`,
4662
4677
  `import type { Generated, Selectable } from "kysely";`,
4663
4678
  "",
4664
4679
  interfaces.join(`
@@ -4713,7 +4728,7 @@ ${lines.join(`
4713
4728
  });
4714
4729
  const rows = entries.map(([table]) => `export type ${pascalCase(table)}Row = Selectable<${pascalCase(table)}>;`);
4715
4730
  return [
4716
- "// Generated by `sl index codegen --target kysely`. Do not edit by hand.",
4731
+ "// Generated by `sl codegen index --target kysely`. Do not edit by hand.",
4717
4732
  `import type { Selectable } from "kysely";`,
4718
4733
  "",
4719
4734
  interfaces.join(`
@@ -4769,7 +4784,7 @@ ${lines.join(`
4769
4784
  });
4770
4785
  const rows = entries.map(([table]) => `export type ${pascalCase(table)} = typeof ${snakeToCamel(table)}.$inferSelect;`);
4771
4786
  return [
4772
- "// Generated by `sl index codegen --target drizzle`. Do not edit by hand.",
4787
+ "// Generated by `sl codegen index --target drizzle`. Do not edit by hand.",
4773
4788
  `import { ${[...used].sort().join(", ")} } from "drizzle-orm/pg-core";`,
4774
4789
  "",
4775
4790
  ...schemaName ? [`export const sg = pgSchema("${schemaName}");`, ""] : [],
@@ -4866,7 +4881,7 @@ ${block.join(`
4866
4881
  }`);
4867
4882
  }
4868
4883
  const header = [
4869
- "// Generated by `sl index codegen --target prisma`. Do not edit by hand.",
4884
+ "// Generated by `sl codegen index --target prisma`. Do not edit by hand.",
4870
4885
  ...skipped.length ? [
4871
4886
  `// Omitted (no read-set primary key, query via another target): ${skipped.join(", ")}`
4872
4887
  ] : [],
@@ -5257,5 +5272,5 @@ export {
5257
5272
  ChainReadError
5258
5273
  };
5259
5274
 
5260
- //# debugId=544EEADDD1FD235264756E2164756E21
5275
+ //# debugId=5422814BCC96BC1064756E2164756E21
5261
5276
  //# sourceMappingURL=index.js.map