@secondlayer/subgraphs 3.12.0 → 3.14.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.
Files changed (36) hide show
  1. package/dist/src/index.d.ts +54 -1
  2. package/dist/src/index.js +952 -199
  3. package/dist/src/index.js.map +12 -11
  4. package/dist/src/runtime/block-processor.d.ts +36 -1
  5. package/dist/src/runtime/block-processor.js +568 -86
  6. package/dist/src/runtime/block-processor.js.map +9 -8
  7. package/dist/src/runtime/catchup.d.ts +7 -0
  8. package/dist/src/runtime/catchup.js +587 -132
  9. package/dist/src/runtime/catchup.js.map +10 -9
  10. package/dist/src/runtime/context.d.ts +65 -3
  11. package/dist/src/runtime/context.js +390 -8
  12. package/dist/src/runtime/context.js.map +6 -4
  13. package/dist/src/runtime/processor.js +665 -248
  14. package/dist/src/runtime/processor.js.map +13 -13
  15. package/dist/src/runtime/reindex.d.ts +7 -0
  16. package/dist/src/runtime/reindex.js +618 -198
  17. package/dist/src/runtime/reindex.js.map +10 -10
  18. package/dist/src/runtime/reorg.d.ts +7 -0
  19. package/dist/src/runtime/reorg.js +588 -87
  20. package/dist/src/runtime/reorg.js.map +10 -9
  21. package/dist/src/runtime/replay.js.map +2 -2
  22. package/dist/src/runtime/runner.d.ts +70 -2
  23. package/dist/src/runtime/runner.js +56 -58
  24. package/dist/src/runtime/runner.js.map +3 -3
  25. package/dist/src/runtime/source-matcher.d.ts +2 -0
  26. package/dist/src/runtime/source-matcher.js.map +2 -2
  27. package/dist/src/schema/index.d.ts +7 -0
  28. package/dist/src/schema/index.js +20 -2
  29. package/dist/src/schema/index.js.map +4 -4
  30. package/dist/src/service.js +665 -248
  31. package/dist/src/service.js.map +13 -13
  32. package/dist/src/types.d.ts +7 -0
  33. package/dist/src/validate.d.ts +7 -0
  34. package/dist/src/validate.js +3 -2
  35. package/dist/src/validate.js.map +3 -3
  36. package/package.json +2 -2
@@ -206,6 +206,13 @@ interface SubgraphContext {
206
206
  update(table: string, where: Record<string, unknown>, set: Record<string, unknown>): void;
207
207
  upsert(table: string, key: Record<string, unknown>, row: Record<string, unknown>): void;
208
208
  delete(table: string, where: Record<string, unknown>): void;
209
+ /**
210
+ * Atomic counter update — the blessed accumulator primitive. Applies
211
+ * `col = COALESCE(col, 0) + delta` per column (insert-or-add); deltas may
212
+ * be negative. Requires a uniqueKeys constraint matching `key`. Prefer
213
+ * this over patchOrInsert with functional updaters for running totals.
214
+ */
215
+ increment(table: string, key: Record<string, unknown>, deltas: Record<string, bigint | number>): void;
209
216
  /** Partial update — sets only specified fields, preserves others */
210
217
  patch(table: string, where: Record<string, unknown>, set: Record<string, unknown>): void;
211
218
  /** Find-then-merge-or-insert. Values can be functions: (existing) => newValue */
@@ -657,6 +664,52 @@ declare function defineSubgraph<
657
664
  const Sources extends Record<string, SubgraphFilter>,
658
665
  const S extends SubgraphSchema
659
666
  >(def: TypedSubgraphDefinition<Sources, S>): TypedSubgraphDefinition<Sources, S>;
667
+ /**
668
+ * Empirical print-payload schema inference. Callers (the index print-schema
669
+ * endpoint) extract topic + raw Clarity hex per row; this module deserializes
670
+ * a bounded sample per topic, unifies the observed value shapes into a single
671
+ * structural tree, and renders Clarity/TS/ColumnType views of each field.
672
+ */
673
+ interface PrintSample {
674
+ blockHeight: number;
675
+ topic: string;
676
+ rawHex: string | null;
677
+ }
678
+ interface InferredPrintField {
679
+ /** Original kebab-case tuple key (the `topic` discriminant is excluded) */
680
+ name: string;
681
+ /** What handlers see on `e.data` — exact runner camelization */
682
+ camel_name: string;
683
+ /** Rendered Clarity type; buff/string lengths are the max observed */
684
+ clarity_type: string;
685
+ /** Decoded handler value type (uint→bigint, buffer→string, …) */
686
+ ts_type: string;
687
+ column_type: ColumnType;
688
+ /** Present in 100% of this topic's decoded samples */
689
+ always_present: boolean;
690
+ /** Only when optional observed: share of present samples that were some */
691
+ optional_some_rate?: number;
692
+ }
693
+ interface InferredTopicSchema {
694
+ topic: string;
695
+ count: number;
696
+ first_height: number;
697
+ last_height: number;
698
+ non_tuple: boolean;
699
+ fields: InferredPrintField[];
700
+ }
701
+ /**
702
+ * Kebab-case → camelCase using the exact runner regex, so `camel_name`
703
+ * matches what handlers see on `e.data` (runner.ts camelizeKeys).
704
+ */
705
+ declare function camelizeDataKey(str: string): string;
706
+ /**
707
+ * Infers per-topic field schemas from sampled print events. Counts and
708
+ * height bounds cover ALL rows of a topic (cheap); only a bounded subset is
709
+ * deserialized for typing. Rows with missing/undecodable hex still count but
710
+ * contribute nothing to typing.
711
+ */
712
+ declare function inferPrintTopics(samples: PrintSample[]): InferredTopicSchema[];
660
713
  interface GeneratedSQL {
661
714
  statements: string[];
662
715
  hash: string;
@@ -822,4 +875,4 @@ type SparseProbeTarget = {
822
875
  declare function canSparseScan(subgraph: SubgraphDefinition): boolean;
823
876
  /** Probe targets for a subgraph's filters: decoded type + contract scope when\\n* the filter pins one (assetIdentifier "SP….contract::asset" or contractId). */
824
877
  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 };
878
+ export { validateSubgraphDefinition, sparseProbeTargets, resumeReindex, renderDeployPlan, reindexSubgraph, pgSchemaName, inferPrintTopics, hasBreakingChanges, generateSubgraphSQL, generatePrismaSchema, generateKyselySchema, generateIndexSchema, generateDrizzleSchema, diffSchema, deploySchema, defineSubgraph, canSparseScan, camelizeDataKey, 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, PrintSample, PrintEventPayload, PrintEventFor, PrintEventFilter, NftTransferPayload, NftTransferFilter, NftMintPayload, NftMintFilter, NftBurnPayload, NftBurnFilter, KyselyGenOptions, InferredTopicSchema, InferredPrintField, 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 };