@secondlayer/subgraphs 6.3.6 → 6.5.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.
@@ -15,7 +15,7 @@ import { AbiContract as AbiContract3, ExtractFunctionArgs as ExtractFunctionArgs
15
15
  */
16
16
  type ChainReadCacheMode = "per-block" | "contract-constant";
17
17
  type ChainReadOptions = {
18
- cache?: ChainReadCacheMode
18
+ cache?: ChainReadCacheMode;
19
19
  };
20
20
  /**
21
21
  * `ChainReadClient` with the ABI generic erased. Structurally cheap, so the
@@ -24,7 +24,7 @@ type ChainReadOptions = {
24
24
  */
25
25
  interface ErasedChainReadClient {
26
26
  contract(contractId: string, abi: unknown, options?: ChainReadOptions): {
27
- read: Record<string, (args?: Record<string, unknown>) => Promise<unknown>>
27
+ read: Record<string, (args?: Record<string, unknown>) => Promise<unknown>>;
28
28
  };
29
29
  }
30
30
  import { AbiContract as AbiContract2 } from "@secondlayer/stacks/clarity";
@@ -87,7 +87,7 @@ interface StxLockFilter {
87
87
  * as-of each processed block. Lets a source index "all SIP-010 tokens" etc.
88
88
  */
89
89
  type TraitScope = {
90
- trait?: string
90
+ trait?: string;
91
91
  };
92
92
  /**
93
93
  * Scope a source to a DYNAMIC address set discovered from another source's
@@ -127,10 +127,10 @@ type TraitScope = {
127
127
  interface FactoryScope {
128
128
  factory?: {
129
129
  /** Source name whose events reveal the addresses. */
130
- from: string
130
+ from: string;
131
131
  /** Dotted path to the address on that source's payload
132
132
  * (e.g. `"data.pool"`, `"contractId"`, `"data.token.id"`). */
133
- field: string
133
+ field: string;
134
134
  };
135
135
  }
136
136
  /** FT event filters */
@@ -203,12 +203,12 @@ interface ContractCallEvent {
203
203
  resultHex: string | null;
204
204
  /** Transaction metadata. */
205
205
  tx: {
206
- txId: string
207
- sender: string
208
- type: string
209
- status: string
210
- contractId: string | null
211
- functionName: string | null
206
+ txId: string;
207
+ sender: string;
208
+ type: string;
209
+ status: string;
210
+ contractId: string | null;
211
+ functionName: string | null;
212
212
  };
213
213
  }
214
214
  /** Contract event filters */
@@ -277,12 +277,12 @@ interface MapWriteFilter extends TraitScope, FactoryScope {
277
277
  * - `{ list: F }` — a list of `F`.
278
278
  */
279
279
  type PrintField = ColumnType | {
280
- type: PrintField
281
- optional: true
280
+ type: PrintField;
281
+ optional: true;
282
282
  } | {
283
- tuple: Record<string, PrintField>
283
+ tuple: Record<string, PrintField>;
284
284
  } | {
285
- list: PrintField
285
+ list: PrintField;
286
286
  };
287
287
  /**
288
288
  * Per-topic field schema for a print_event source. When declared, the handler's
@@ -294,34 +294,34 @@ type PrintField = ColumnType | {
294
294
  */
295
295
  type PrintEventPrints = Record<string, Record<string, PrintField>>;
296
296
  type PrintEventFields = FactoryScope & {
297
- type: "print_event"
298
- topic?: string
297
+ type: "print_event";
298
+ topic?: string;
299
299
  };
300
300
  /**
301
301
  * Pinned to one or more contract ids with no trait — `prints` is required so
302
302
  * `event.data` is typed and empty-table handlers cannot typecheck.
303
303
  */
304
304
  type PinnedPrintEventFilter = PrintEventFields & {
305
- contractId: string | readonly string[]
306
- trait?: undefined
307
- prints: PrintEventPrints
305
+ contractId: string | readonly string[];
306
+ trait?: undefined;
307
+ prints: PrintEventPrints;
308
308
  };
309
309
  /**
310
310
  * Trait-scoped print source (optionally narrowed by contractId). No single
311
311
  * schema — `prints` stays optional.
312
312
  */
313
313
  type TraitPrintEventFilter = PrintEventFields & {
314
- contractId?: string | readonly string[]
315
- trait: string
316
- prints?: PrintEventPrints
314
+ contractId?: string | readonly string[];
315
+ trait: string;
316
+ prints?: PrintEventPrints;
317
317
  };
318
318
  /**
319
319
  * Unpinned / factory-only print source (no contractId). `prints` optional.
320
320
  */
321
321
  type UnpinnedPrintEventFilter = PrintEventFields & {
322
- contractId?: undefined
323
- trait?: string
324
- prints?: PrintEventPrints
322
+ contractId?: undefined;
323
+ trait?: string;
324
+ prints?: PrintEventPrints;
325
325
  };
326
326
  /**
327
327
  * Print-event filter. Pinned sources (contractId set, no trait) require
@@ -354,26 +354,26 @@ interface SystemRow {
354
354
  type InferTableRow<T extends SubgraphTable> = SystemRow & { [K in keyof T["columns"]] : InferColumnType<T["columns"][K]> };
355
355
  /** Comparison operators for a scalar value */
356
356
  type ComparisonFilter<T> = {
357
- eq?: T
358
- neq?: T
359
- gt?: T
360
- gte?: T
361
- lt?: T
362
- lte?: T
357
+ eq?: T;
358
+ neq?: T;
359
+ gt?: T;
360
+ gte?: T;
361
+ lt?: T;
362
+ lte?: T;
363
363
  /** Match any value in the set. */
364
- in?: T[]
364
+ in?: T[];
365
365
  /** Match none of the values in the set. */
366
- notIn?: T[]
366
+ notIn?: T[];
367
367
  /** SQL ILIKE pattern (case-insensitive); `%`/`_` wildcards. Strings only. */
368
- like?: string
368
+ like?: string;
369
369
  };
370
370
  /** Where clause — each column accepts a scalar (eq) or comparison object */
371
371
  type WhereInput<TRow> = { [K in keyof TRow]? : TRow[K] | ComparisonFilter<TRow[K]> };
372
372
  /** A column is optional on insert when it's nullable or has a SQL default. */
373
373
  type IsOptionalColumn<C> = C extends {
374
- nullable: true
374
+ nullable: true;
375
375
  } ? true : C extends {
376
- default: string | number | boolean
376
+ default: string | number | boolean;
377
377
  } ? true : false;
378
378
  /**
379
379
  * Like `InferColumnType` but for WRITE inputs: numeric (`uint`/`int`) columns
@@ -404,12 +404,12 @@ type RowWhere<
404
404
  */
405
405
  interface TypedSubgraphContext<S extends SubgraphSchema> {
406
406
  block: {
407
- height: number
408
- hash: string
409
- timestamp: number
410
- burnBlockHeight: number
407
+ height: number;
408
+ hash: string;
409
+ timestamp: number;
410
+ burnBlockHeight: number;
411
411
  /** Nakamoto StacksBlockId, when the block row carries one. */
412
- indexBlockHash?: string | null
412
+ indexBlockHash?: string | null;
413
413
  };
414
414
  tx: TxMeta;
415
415
  /**
@@ -521,10 +521,10 @@ interface ContractDeployPayload {
521
521
  * present for back-compat. Without an `abi`, the payload is {@link ContractCallEvent}.
522
522
  */
523
523
  type ContractCallPayload<F> = F extends {
524
- abi: infer A extends AbiContract3
525
- functionName: infer N extends string
524
+ abi: infer A extends AbiContract3;
525
+ functionName: infer N extends string;
526
526
  } ? N extends ExtractFunctionNames<A> ? ContractCallEvent & {
527
- input: ExtractFunctionArgs2<A, N>
527
+ input: ExtractFunctionArgs2<A, N>;
528
528
  } : ContractCallEvent : ContractCallEvent;
529
529
  interface NestedContractCallPayload {
530
530
  contractId: string;
@@ -568,24 +568,24 @@ interface MapDeletePayload {
568
568
  * per topic; otherwise it falls back to the untyped {@link PrintEventPayload}.
569
569
  */
570
570
  type PrintEventFor<F> = F extends {
571
- prints: infer P extends Record<string, Record<string, PrintField>>
571
+ prints: infer P extends Record<string, Record<string, PrintField>>;
572
572
  } ? { [K in keyof P] : {
573
- contractId: string
574
- topic: K
575
- data: PrintDataOf<P[K]>
576
- tx: TxMeta
573
+ contractId: string;
574
+ topic: K;
575
+ data: PrintDataOf<P[K]>;
576
+ tx: TxMeta;
577
577
  } }[keyof P] : PrintEventPayload;
578
578
  /** TS type of one declared print field (nested tuples and lists included). */
579
579
  type PrintFieldToTS<F> = F extends ColumnType ? ColumnToTS<F> : F extends {
580
- type: infer Inner
581
- optional: true
580
+ type: infer Inner;
581
+ optional: true;
582
582
  } ? PrintFieldToTS<Inner> : F extends {
583
- tuple: infer T extends Record<string, PrintField>
583
+ tuple: infer T extends Record<string, PrintField>;
584
584
  } ? PrintDataOf<T> : F extends {
585
- list: infer Item
585
+ list: infer Item;
586
586
  } ? PrintFieldToTS<Item>[] : unknown;
587
587
  type OptionalFieldKeys<T> = { [K in keyof T] : T[K] extends {
588
- optional: true
588
+ optional: true;
589
589
  } ? K : never }[keyof T];
590
590
  /** Collapse an intersection into one object literal, so hovering `event.data`
591
591
  * shows the fields rather than `A & B`. */
@@ -598,37 +598,37 @@ type Flatten<T> = { [K in keyof T] : T[K] } & {};
598
598
  type PrintDataOf<T extends Record<string, PrintField>> = Flatten<{ [K in Exclude<keyof T, OptionalFieldKeys<T>>] : PrintFieldToTS<T[K]> } & { [K in OptionalFieldKeys<T>]? : PrintFieldToTS<T[K]> }>;
599
599
  /** The event payload a handler receives for a given source filter. */
600
600
  type EventForFilter<F extends SubgraphFilter> = F extends {
601
- type: "print_event"
601
+ type: "print_event";
602
602
  } ? PrintEventFor<F> : F extends {
603
- type: "ft_transfer"
603
+ type: "ft_transfer";
604
604
  } ? FtTransferPayload : F extends {
605
- type: "ft_mint"
605
+ type: "ft_mint";
606
606
  } ? FtMintPayload : F extends {
607
- type: "ft_burn"
607
+ type: "ft_burn";
608
608
  } ? FtBurnPayload : F extends {
609
- type: "nft_transfer"
609
+ type: "nft_transfer";
610
610
  } ? NftTransferPayload : F extends {
611
- type: "nft_mint"
611
+ type: "nft_mint";
612
612
  } ? NftMintPayload : F extends {
613
- type: "nft_burn"
613
+ type: "nft_burn";
614
614
  } ? NftBurnPayload : F extends {
615
- type: "stx_transfer"
615
+ type: "stx_transfer";
616
616
  } ? StxTransferPayload : F extends {
617
- type: "stx_mint"
617
+ type: "stx_mint";
618
618
  } ? StxMintPayload : F extends {
619
- type: "stx_burn"
619
+ type: "stx_burn";
620
620
  } ? StxBurnPayload : F extends {
621
- type: "stx_lock"
621
+ type: "stx_lock";
622
622
  } ? StxLockPayload : F extends {
623
- type: "contract_call"
623
+ type: "contract_call";
624
624
  } ? ContractCallPayload<F> : F extends {
625
- type: "contract_deploy"
625
+ type: "contract_deploy";
626
626
  } ? ContractDeployPayload : F extends {
627
- type: "nested_contract_call"
627
+ type: "nested_contract_call";
628
628
  } ? NestedContractCallPayload : F extends {
629
- type: "var_set"
629
+ type: "var_set";
630
630
  } ? VarSetPayload : F extends {
631
- type: infer T extends "map_set" | "map_insert" | "map_delete"
631
+ type: infer T extends "map_set" | "map_insert" | "map_delete";
632
632
  } ? T extends "map_delete" ? MapDeletePayload : MapWritePayload : never;
633
633
  interface BlockMeta {
634
634
  height: number;
@@ -658,26 +658,26 @@ interface MatchedTx {
658
658
  sourceName: string;
659
659
  }
660
660
  type TxRecord = {
661
- tx_id: string
662
- type: string
663
- sender: string
664
- status: string
661
+ tx_id: string;
662
+ type: string;
663
+ sender: string;
664
+ status: string;
665
665
  /** Position within the block — the runner sorts dispatch into chain order. */
666
- tx_index?: number
667
- contract_id?: string | null
668
- function_name?: string | null
669
- function_args?: unknown | null
670
- raw_result?: string | null
666
+ tx_index?: number;
667
+ contract_id?: string | null;
668
+ function_name?: string | null;
669
+ function_args?: unknown | null;
670
+ raw_result?: string | null;
671
671
  };
672
672
  type EventRecord = {
673
- id: string
674
- tx_id: string
675
- type: string
673
+ id: string;
674
+ tx_id: string;
675
+ type: string;
676
676
  /** Classic `event_index`, or `ordinal` when `clock === "vm"`. */
677
- event_index: number
678
- data: unknown
677
+ event_index: number;
678
+ data: unknown;
679
679
  /** Set on opt-in `vm_events` rows. Two clocks never sort or dedupe together. */
680
- clock?: "vm"
680
+ clock?: "vm";
681
681
  };
682
682
  /**
683
683
  * Build a typed event payload based on the source filter type.
@@ -699,9 +699,9 @@ interface TestSubgraphContext<S extends SubgraphSchema> extends Omit<TypedSubgra
699
699
  setTx(tx: Partial<TxMeta2>): void;
700
700
  /** Insert ops queued since `opsCheckpoint()`, for preview IN/OUT traces. */
701
701
  pendingInsertsSince(checkpoint: number): Array<{
702
- table: string
703
- keys: string[]
704
- row: Record<string, unknown>
702
+ table: string;
703
+ keys: string[];
704
+ row: Record<string, unknown>;
705
705
  }>;
706
706
  /** Length of the pending-ops queue (same as runtime `opsCheckpoint`). */
707
707
  opsCheckpoint(): number;
@@ -716,11 +716,11 @@ interface TestSubgraphContext<S extends SubgraphSchema> extends Omit<TypedSubgra
716
716
  * ```
717
717
  */
718
718
  declare function createTestContext<const S extends SubgraphSchema>(schema: S, options?: {
719
- block?: Partial<BlockMeta>
720
- tx?: Partial<TxMeta2>
719
+ block?: Partial<BlockMeta>;
720
+ tx?: Partial<TxMeta2>;
721
721
  /** Stubbed `ctx.client.readOnly` results, keyed
722
722
  * `"<contractId>.<function-name>"`. */
723
- reads?: Record<string, unknown>
723
+ reads?: Record<string, unknown>;
724
724
  }): TestSubgraphContext<S>;
725
725
  /**
726
726
  * Build a handler-shaped event payload for a source, typed by that source's
@@ -735,7 +735,7 @@ declare function createTestContext<const S extends SubgraphSchema>(schema: S, op
735
735
  * ```
736
736
  */
737
737
  declare function buildEvent<const F extends SubgraphFilter>(source: F, payload: Record<string, unknown>, options?: {
738
- tx?: Partial<TxMeta2>
738
+ tx?: Partial<TxMeta2>;
739
739
  }): EventForFilter<F>;
740
740
  /**
741
741
  * Shared subgraph test run — payload map + in-memory handlers + fail-closed
@@ -785,8 +785,8 @@ interface EventTrace {
785
785
  inKeys: string[];
786
786
  /** Tables written by this event; empty when the mapping wrote nothing. */
787
787
  outs: Array<{
788
- table: string
789
- keys: string[]
788
+ table: string;
789
+ keys: string[];
790
790
  }>;
791
791
  }
792
792
  interface SubgraphTestResult {
@@ -795,13 +795,13 @@ interface SubgraphTestResult {
795
795
  matched: number;
796
796
  written: number;
797
797
  tables: Array<{
798
- name: string
799
- rows: number
800
- sampleRow?: Record<string, unknown>
798
+ name: string;
799
+ rows: number;
800
+ sampleRow?: Record<string, unknown>;
801
801
  }>;
802
802
  firstEvent?: {
803
- source: string
804
- data?: unknown
803
+ source: string;
804
+ data?: unknown;
805
805
  };
806
806
  hint?: string;
807
807
  /** Present when `trace: true`. */
@@ -819,7 +819,7 @@ interface RunSubgraphTestInput {
819
819
  }
820
820
  /** Map an Index event row onto the payload shape a handler expects. */
821
821
  declare function toHandlerPayload(_filter: {
822
- type: string
822
+ type: string;
823
823
  } | undefined, row: IndexEventRow): Record<string, unknown>;
824
824
  /** Map an Index contract-call row onto the ContractCallEvent handler shape. */
825
825
  declare function toContractCallPayload(row: IndexContractCallRow): Record<string, unknown>;
@@ -831,8 +831,8 @@ declare function runSubgraphTest(input: RunSubgraphTestInput): Promise<SubgraphT
831
831
  interface ProbeHandlersDef {
832
832
  schema: SubgraphSchema;
833
833
  sources: Record<string, {
834
- type: string
835
- [key: string]: unknown
834
+ type: string;
835
+ [key: string]: unknown;
836
836
  }>;
837
837
  handlers: Record<string, unknown>;
838
838
  }
@@ -848,7 +848,7 @@ interface ProbeHandlersResult {
848
848
  * EMPTY_MAPPING before DDL apply.
849
849
  */
850
850
  declare function probeHandlers(def: ProbeHandlersDef, samples: Array<{
851
- source: string
852
- event: Record<string, unknown>
851
+ source: string;
852
+ event: Record<string, unknown>;
853
853
  }>): Promise<ProbeHandlersResult>;
854
854
  export { BlockMeta, EventTrace, IndexContractCallRow, IndexEventRow, IndexTestRow, ProbeHandlersDef, ProbeHandlersResult, RunSubgraphTestInput, SubgraphTestResult, SubgraphTestSource, TestSubgraphContext, TxMeta2 as TxMeta, buildEvent, buildEventPayload, createTestContext, probeHandlers, runSubgraphTest, toContractCallPayload, toHandlerPayload };