@secondlayer/subgraphs 3.11.0 → 3.12.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.
@@ -237,6 +237,9 @@ interface SubgraphDefinition {
237
237
  description?: string;
238
238
  /** Block height to start indexing from (default: 1) */
239
239
  startBlock?: number;
240
+ /** 'concurrent' = tip-first: live at tip now, history backfills behind.
241
+ * Requires order-tolerant handlers. Default 'blocking'. */
242
+ backfillMode?: "blocking" | "concurrent";
240
243
  /** Named source filters — keys become handler keys */
241
244
  sources: Record<string, SubgraphFilter>;
242
245
  /** Tables in this subgraph */
@@ -252,6 +255,8 @@ interface ReindexOptions {
252
255
  fromBlock?: number;
253
256
  toBlock?: number;
254
257
  schemaName?: string;
258
+ /** Op row to receive processed_events on each progress flush. */
259
+ operationId?: string;
255
260
  signal?: AbortSignal;
256
261
  }
257
262
  /**
@@ -269,6 +274,7 @@ declare function reindexSubgraph(def: SubgraphDefinition, opts?: ReindexOptions)
269
274
  */
270
275
  declare function resumeReindex(def: SubgraphDefinition, opts: {
271
276
  schemaName: string
277
+ operationId?: string
272
278
  signal?: AbortSignal
273
279
  }): Promise<{
274
280
  processed: number
@@ -282,6 +288,7 @@ declare function backfillSubgraph(def: SubgraphDefinition, opts: {
282
288
  fromBlock: number
283
289
  toBlock: number
284
290
  schemaName?: string
291
+ operationId?: string
285
292
  signal?: AbortSignal
286
293
  }): Promise<{
287
294
  processed: number
@@ -727,6 +734,14 @@ interface ColumnDiff {
727
734
  * Compare two multi-table subgraph schemas and return differences.
728
735
  */
729
736
  declare function diffSchema(existing: SubgraphSchema, incoming: SubgraphSchema): TableDiff;
737
+ /**
738
+ * Returns true if the diff contains any breaking changes
739
+ * (removed tables, removed columns, or changed column types).
740
+ */
741
+ declare function hasBreakingChanges(diff: TableDiff): {
742
+ breaking: boolean
743
+ reasons: string[]
744
+ };
730
745
  interface DeployDiff {
731
746
  addedTables: string[];
732
747
  removedTables: string[];
@@ -794,4 +809,17 @@ declare function deploySchema(db: AnyDb, def: SubgraphDefinition, handlerPath: s
794
809
  version: string
795
810
  diff?: DeployDiff
796
811
  }>;
797
- export { validateSubgraphDefinition, resumeReindex, renderDeployPlan, reindexSubgraph, pgSchemaName, generateSubgraphSQL, generatePrismaSchema, generateKyselySchema, generateIndexSchema, generateDrizzleSchema, diffSchema, deploySchema, defineSubgraph, backfillSubgraph, WriteRow, WhereInput, TypedSubgraphDefinition, TypedSubgraphContext, TypedHandlers, TxMeta, TableDiff, SystemRow, SubscribeOptions, SubgraphTableClient, SubgraphTable, SubgraphSchema, SubgraphHandler, SubgraphFilter, SubgraphDefinition, SubgraphContext, SubgraphColumn, StxTransferPayload, StxTransferFilter, StxMintPayload, StxMintFilter, StxLockPayload, StxLockFilter, StxBurnPayload, StxBurnFilter, RowValue, ReindexOptions, PrismaGenOptions, PrintEventPayload, PrintEventFor, PrintEventFilter, NftTransferPayload, NftTransferFilter, NftMintPayload, NftMintFilter, NftBurnPayload, NftBurnFilter, KyselyGenOptions, InferTableRow, InferSubgraphClient, InferColumnType, IndexCodegenTarget, IndexCodegenOptions, INDEX_CODEGEN_TABLES, GeneratedSQL, FtTransferPayload, FtTransferFilter, FtMintPayload, FtMintFilter, FtBurnPayload, FtBurnFilter, FindManyOptions, EventForFilter, DrizzleGenOptions, DeployPlan, DeployDiff, ContractDeployPayload, ContractDeployFilter, ContractCallPayload, ContractCallFilter, ContractCallEvent, ComputedValue, ComparisonFilter, ColumnType, ColumnToTS, ColumnDiff, ByoMigrationPlan, ByoBreakingChangeError, AnyEvent, AggregateSpec, AggregateResult };
812
+ /** A (decoded event type, optional contract scope) pair the sparse probe
813
+ * checks. Contract scoping is what makes token-subgraph reindexes leap over
814
+ * everything that isn't their token. */
815
+ type SparseProbeTarget = {
816
+ eventType: string
817
+ contractId?: string
818
+ };
819
+ /** Sparse scanning is sound only when EVERY source is an event-type filter —
820
+ * a contract_call/contract_deploy source matches transactions, which the
821
+ * event probe can't see. */
822
+ declare function canSparseScan(subgraph: SubgraphDefinition): boolean;
823
+ /** Probe targets for a subgraph's filters: decoded type + contract scope when\\n* the filter pins one (assetIdentifier "SP….contract::asset" or contractId). */
824
+ declare function sparseProbeTargets(subgraph: SubgraphDefinition): SparseProbeTarget[];
825
+ export { validateSubgraphDefinition, sparseProbeTargets, resumeReindex, renderDeployPlan, reindexSubgraph, pgSchemaName, hasBreakingChanges, generateSubgraphSQL, generatePrismaSchema, generateKyselySchema, generateIndexSchema, generateDrizzleSchema, diffSchema, deploySchema, defineSubgraph, canSparseScan, backfillSubgraph, WriteRow, WhereInput, TypedSubgraphDefinition, TypedSubgraphContext, TypedHandlers, TxMeta, TableDiff, SystemRow, SubscribeOptions, SubgraphTableClient, SubgraphTable, SubgraphSchema, SubgraphHandler, SubgraphFilter, SubgraphDefinition, SubgraphContext, SubgraphColumn, StxTransferPayload, StxTransferFilter, StxMintPayload, StxMintFilter, StxLockPayload, StxLockFilter, StxBurnPayload, StxBurnFilter, SparseProbeTarget, RowValue, ReindexOptions, PrismaGenOptions, PrintEventPayload, PrintEventFor, PrintEventFilter, NftTransferPayload, NftTransferFilter, NftMintPayload, NftMintFilter, NftBurnPayload, NftBurnFilter, KyselyGenOptions, InferTableRow, InferSubgraphClient, InferColumnType, IndexCodegenTarget, IndexCodegenOptions, INDEX_CODEGEN_TABLES, GeneratedSQL, FtTransferPayload, FtTransferFilter, FtMintPayload, FtMintFilter, FtBurnPayload, FtBurnFilter, FindManyOptions, EventForFilter, DrizzleGenOptions, DeployPlan, DeployDiff, ContractDeployPayload, ContractDeployFilter, ContractCallPayload, ContractCallFilter, ContractCallEvent, ComputedValue, ComparisonFilter, ColumnType, ColumnToTS, ColumnDiff, ByoMigrationPlan, ByoBreakingChangeError, AnyEvent, AggregateSpec, AggregateResult };
package/dist/src/index.js CHANGED
@@ -69,6 +69,7 @@ var SubgraphDefinitionSchema = z.object({
69
69
  version: z.string().optional(),
70
70
  description: z.string().optional(),
71
71
  startBlock: z.number().int().nonnegative().optional(),
72
+ backfillMode: z.enum(["blocking", "concurrent"]).optional(),
72
73
  sources: z.record(z.string(), SubgraphFilterSchema).refine((s) => Object.keys(s).length > 0, "Must have at least one source"),
73
74
  schema: SubgraphSchemaSchema,
74
75
  handlers: z.record(z.string(), z.any())
@@ -1858,6 +1859,7 @@ import {
1858
1859
  recordGapBatch,
1859
1860
  resolveGaps
1860
1861
  } from "@secondlayer/shared/db/queries/subgraph-gaps";
1862
+ import { updateOperationProcessedEvents } from "@secondlayer/shared/db/queries/subgraph-operations";
1861
1863
  import {
1862
1864
  recordSubgraphProcessed as recordSubgraphProcessed2,
1863
1865
  updateSubgraphStatus as updateSubgraphStatus2
@@ -2124,6 +2126,9 @@ async function processBlockRange(def, opts) {
2124
2126
  const shouldFlushProgress = blocksProcessed % 100 === 0 || now - lastProgressFlushAt >= PROGRESS_FLUSH_INTERVAL_MS;
2125
2127
  if (shouldFlushProgress) {
2126
2128
  await updateSubgraphStatus2(targetDb, subgraphName, status, height);
2129
+ if (opts.operationId) {
2130
+ await updateOperationProcessedEvents(targetDb, opts.operationId, totalEventsProcessed).catch(() => {});
2131
+ }
2127
2132
  lastProgressFlushAt = now;
2128
2133
  }
2129
2134
  if (blocksProcessed % LOG_INTERVAL === 0) {
@@ -2241,6 +2246,7 @@ async function reindexSubgraph(def, opts) {
2241
2246
  isCatchup: false,
2242
2247
  apiKeyId: null,
2243
2248
  subgraphId: subgraphRow?.id,
2249
+ operationId: opts?.operationId,
2244
2250
  signal: opts?.signal
2245
2251
  });
2246
2252
  if (result.aborted) {
@@ -2316,6 +2322,7 @@ async function resumeReindex(def, opts) {
2316
2322
  isCatchup: false,
2317
2323
  apiKeyId: null,
2318
2324
  subgraphId: row.id,
2325
+ operationId: opts.operationId,
2319
2326
  signal: opts.signal
2320
2327
  });
2321
2328
  if (result.aborted) {
@@ -2364,6 +2371,7 @@ async function backfillSubgraph(def, opts) {
2364
2371
  isCatchup: false,
2365
2372
  apiKeyId: null,
2366
2373
  subgraphId: subgraphRow?.id,
2374
+ operationId: opts.operationId,
2367
2375
  signal: opts.signal
2368
2376
  });
2369
2377
  if (result.aborted) {
@@ -3238,10 +3246,12 @@ function getDefault(type) {
3238
3246
  }
3239
3247
  export {
3240
3248
  validateSubgraphDefinition,
3249
+ sparseProbeTargets,
3241
3250
  resumeReindex,
3242
3251
  renderDeployPlan,
3243
3252
  reindexSubgraph,
3244
3253
  pgSchemaName,
3254
+ hasBreakingChanges,
3245
3255
  generateSubgraphSQL,
3246
3256
  generatePrismaSchema,
3247
3257
  generateKyselySchema,
@@ -3250,10 +3260,11 @@ export {
3250
3260
  diffSchema,
3251
3261
  deploySchema,
3252
3262
  defineSubgraph,
3263
+ canSparseScan,
3253
3264
  backfillSubgraph,
3254
3265
  INDEX_CODEGEN_TABLES,
3255
3266
  ByoBreakingChangeError
3256
3267
  };
3257
3268
 
3258
- //# debugId=9A94DC6E9FCF6CD964756E2164756E21
3269
+ //# debugId=415665ECDA2A436C64756E2164756E21
3259
3270
  //# sourceMappingURL=index.js.map