@secondlayer/sdk 6.43.0 → 6.44.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.
@@ -630,7 +630,10 @@ type StreamsEventsSubscribeParams = {
630
630
  * block as `${height - 1}:<sentinel>`, so a rewound cursor parses to a
631
631
  * position that was never reached.
632
632
  */
633
- type ConsumerBatchContext = {
633
+ type ConsumerBatchContext<
634
+ TTip = unknown,
635
+ TReorg = unknown
636
+ > = {
634
637
  /** Checkpoint to commit alongside your rows. */
635
638
  cursor: string | null
636
639
  /** Highest canonical block the sweep has reached. `null` before the first
@@ -640,6 +643,19 @@ type ConsumerBatchContext = {
640
643
  tipHeight: number
641
644
  /** `tipHeight - height`, floored at 0. `null` until `height` is known. */
642
645
  blocksBehind: number | null
646
+ /**
647
+ * The full tip for this page — `StreamsTip` or `IndexTip` depending on the
648
+ * surface. Exposed here so a handler never needs the `envelope` parameter,
649
+ * which is the only way to reach it today and is also how the worst
650
+ * `finalizedOnly` mistake becomes reachable (`return envelope.next_cursor`
651
+ * jumps the cursor past events that were filtered out and never delivered).
652
+ */
653
+ tip: TTip
654
+ /**
655
+ * Reorgs reported alongside this page; empty when none. Rollback still
656
+ * belongs in `onReorg` — this is for observability inside a batch.
657
+ */
658
+ reorgs: readonly TReorg[]
643
659
  };
644
660
  /** @deprecated Use {@link ConsumerBatchContext} — the Index and Streams loops
645
661
  * share one shape now. Kept as an alias so existing annotations compile. */
@@ -1451,8 +1467,8 @@ type IndexTransaction = {
1451
1467
  cause: number
1452
1468
  }
1453
1469
  };
1454
- type TransactionsEnvelope = {
1455
- transactions: IndexTransaction[]
1470
+ type TransactionsEnvelope<TRow = IndexTransaction> = {
1471
+ transactions: TRow[]
1456
1472
  next_cursor: string | null
1457
1473
  tip: IndexTip
1458
1474
  reorgs: IndexReorg[]
@@ -1461,7 +1477,17 @@ type TransactionEnvelope = {
1461
1477
  transaction: IndexTransaction
1462
1478
  tip: IndexTip
1463
1479
  };
1480
+ /** Transaction columns that survive any projection. */
1481
+ type TransactionAlwaysFields = "cursor" | "block_height" | "tx_id";
1482
+ /** A Transaction row narrowed to the requested columns plus the always-present ones. */
1483
+ type TransactionFields<F extends keyof IndexTransaction & string> = Pick<IndexTransaction, (F | TransactionAlwaysFields) & keyof IndexTransaction>;
1464
1484
  type TransactionsListParams = {
1485
+ /**
1486
+ * Columns to return. The server projects the row, so an unrequested column
1487
+ * is physically absent — and the narrowing overload on `list` makes reading
1488
+ * one a compile error rather than `undefined` at runtime.
1489
+ */
1490
+ fields?: readonly (keyof IndexTransaction & string)[]
1465
1491
  cursor?: string | null
1466
1492
  fromCursor?: string | null
1467
1493
  limit?: number
@@ -1726,8 +1752,8 @@ type SbtcDepositEnvelope = {
1726
1752
  deposit: IndexSbtcDepositDetail
1727
1753
  tip: IndexTip
1728
1754
  };
1729
- type SbtcWithdrawalsEnvelope = {
1730
- withdrawals: IndexSbtcWithdrawal[]
1755
+ type SbtcWithdrawalsEnvelope<TRow = IndexSbtcWithdrawal> = {
1756
+ withdrawals: TRow[]
1731
1757
  next_cursor: string | null
1732
1758
  tip: IndexTip
1733
1759
  reorgs: IndexReorg[]
@@ -1774,7 +1800,17 @@ type SbtcDepositsWalkParams = Omit<SbtcDepositsListParams, "limit"> & {
1774
1800
  batchSize?: number
1775
1801
  signal?: AbortSignal
1776
1802
  };
1803
+ /** SbtcWithdrawal columns that survive any projection. */
1804
+ type SbtcWithdrawalAlwaysFields = "cursor" | "request_id";
1805
+ /** A SbtcWithdrawal row narrowed to the requested columns plus the always-present ones. */
1806
+ type SbtcWithdrawalFields<F extends keyof IndexSbtcWithdrawal & string> = Pick<IndexSbtcWithdrawal, (F | SbtcWithdrawalAlwaysFields) & keyof IndexSbtcWithdrawal>;
1777
1807
  type SbtcWithdrawalsListParams = {
1808
+ /**
1809
+ * Columns to return. The server projects the row, so an unrequested column
1810
+ * is physically absent — and the narrowing overload on `list` makes reading
1811
+ * one a compile error rather than `undefined` at runtime.
1812
+ */
1813
+ fields?: readonly (keyof IndexSbtcWithdrawal & string)[]
1778
1814
  cursor?: string | null
1779
1815
  fromCursor?: string | null
1780
1816
  limit?: number
@@ -1834,6 +1870,11 @@ interface SbtcResource {
1834
1870
  get(bitcoinTxid: string): Promise<SbtcDepositEnvelope | null>
1835
1871
  };
1836
1872
  withdrawals: {
1873
+ /** Narrowing overload: `fields` shrinks the row type to exactly the
1874
+ * requested columns plus {@link SbtcWithdrawalAlwaysFields}. */
1875
+ list<const F extends keyof IndexSbtcWithdrawal & string>(params: SbtcWithdrawalsListParams & {
1876
+ fields: readonly F[]
1877
+ }): Promise<SbtcWithdrawalsEnvelope<SbtcWithdrawalFields<F>>>
1837
1878
  list(params?: SbtcWithdrawalsListParams): Promise<SbtcWithdrawalsEnvelope>
1838
1879
  walk(params?: SbtcWithdrawalsWalkParams): AsyncIterable<IndexSbtcWithdrawal>
1839
1880
  /** Fetch a withdrawal's full lifecycle by request id; 404 → null. */
@@ -1938,15 +1979,25 @@ type IndexPox5Event = {
1938
1979
  /** The full decoded print tuple as JSON. */
1939
1980
  data: unknown
1940
1981
  };
1941
- type Pox5EventsEnvelope = {
1942
- events: IndexPox5Event[]
1982
+ type Pox5EventsEnvelope<TRow = IndexPox5Event> = {
1983
+ events: TRow[]
1943
1984
  next_cursor: string | null
1944
1985
  tip: IndexTip
1945
1986
  reorgs: IndexReorg[]
1946
1987
  /** Present only when the PoX-5 decoder is disabled, explaining an empty feed. */
1947
1988
  notes?: string
1948
1989
  };
1990
+ /** Pox5Event columns that survive any projection. */
1991
+ type Pox5EventAlwaysFields = "cursor" | "block_height" | "topic";
1992
+ /** A Pox5Event row narrowed to the requested columns plus the always-present ones. */
1993
+ type Pox5EventFields<F extends keyof IndexPox5Event & string> = Pick<IndexPox5Event, (F | Pox5EventAlwaysFields) & keyof IndexPox5Event>;
1949
1994
  type Pox5EventsListParams = {
1995
+ /**
1996
+ * Columns to return. The server projects the row, so an unrequested column
1997
+ * is physically absent — and the narrowing overload on `list` makes reading
1998
+ * one a compile error rather than `undefined` at runtime.
1999
+ */
2000
+ fields?: readonly (keyof IndexPox5Event & string)[]
1950
2001
  cursor?: string | null
1951
2002
  fromCursor?: string | null
1952
2003
  limit?: number
@@ -1969,6 +2020,11 @@ type Pox5EventsWalkParams = Omit<Pox5EventsListParams, "limit"> & {
1969
2020
  * epoch 4.0 hard fork onward (PoX-4's `index.stacking` stream ends there). */
1970
2021
  interface Pox5Resource {
1971
2022
  events: {
2023
+ /** Narrowing overload: `fields` shrinks the row type to exactly the
2024
+ * requested columns plus {@link Pox5EventAlwaysFields}. */
2025
+ list<const F extends keyof IndexPox5Event & string>(params: Pox5EventsListParams & {
2026
+ fields: readonly F[]
2027
+ }): Promise<Pox5EventsEnvelope<Pox5EventFields<F>>>
1972
2028
  list(params?: Pox5EventsListParams): Promise<Pox5EventsEnvelope>
1973
2029
  walk(params?: Pox5EventsWalkParams): AsyncIterable<IndexPox5Event>
1974
2030
  };
@@ -2096,7 +2152,16 @@ declare class Index extends BaseClient {
2096
2152
  /** Full transaction documents: paginated `list`/`walk`, plus `get` by tx_id
2097
2153
  * (resolves to null on 404). */
2098
2154
  readonly transactions: {
2099
- list: (params?: TransactionsListParams) => Promise<TransactionsEnvelope>
2155
+ /** Narrowing overload: `fields` shrinks the row type to exactly the
2156
+ * requested columns plus {@link TransactionAlwaysFields}. Declared as
2157
+ * an overloaded call signature because an arrow property cannot carry
2158
+ * overloads. */
2159
+ list: {
2160
+ <const F extends keyof IndexTransaction & string>(params: TransactionsListParams & {
2161
+ fields: readonly F[]
2162
+ }): Promise<TransactionsEnvelope<TransactionFields<F>>>
2163
+ (params?: TransactionsListParams): Promise<TransactionsEnvelope>
2164
+ }
2100
2165
  walk: (params?: TransactionsWalkParams) => AsyncIterable<IndexTransaction>
2101
2166
  get: (txId: string) => Promise<TransactionEnvelope | null>
2102
2167
  getProof: (txId: string) => Promise<TransactionProof | null>
@@ -592,12 +592,15 @@ function assertFinalizedCheckpoint(returned, checkpoint) {
592
592
  throw new ValidationError(`onBatch returned cursor "${returned}", above the last delivered finalized event${boundary}. With finalizedOnly, events past that point were filtered out and will be re-read once finalized — committing beyond it skips them permanently. Return ctx.cursor (or nothing); never envelope.next_cursor.`, 400);
593
593
  }
594
594
  }
595
- function batchContext(cursor, height, tipHeight) {
595
+ function batchContext(cursor, height, tip, reorgs = []) {
596
+ const tipHeight = tip.block_height;
596
597
  return {
597
598
  cursor,
598
599
  height,
599
600
  tipHeight,
600
- blocksBehind: height === null ? null : Math.max(0, tipHeight - height)
601
+ blocksBehind: height === null ? null : Math.max(0, tipHeight - height),
602
+ tip,
603
+ reorgs
601
604
  };
602
605
  }
603
606
  var MAX_RETRY_AFTER_MS = 300000;
@@ -699,7 +702,7 @@ async function consumeStreamsEvents(opts) {
699
702
  const emitted = finalizedOnly ? envelope.events.filter((event) => event.finalized) : envelope.events;
700
703
  const checkpoint = finalizedOnly ? emitted.at(-1)?.cursor ?? cursor : envelope.next_cursor;
701
704
  height = emitted.at(-1)?.block_height ?? height;
702
- const ctx = batchContext(checkpoint, height, envelope.tip.block_height);
705
+ const ctx = batchContext(checkpoint, height, envelope.tip, envelope.reorgs);
703
706
  opts.onProgress?.(ctx);
704
707
  let nextCursor;
705
708
  if (opts.sink) {
@@ -860,7 +863,7 @@ async function consumeIndexFeed(opts) {
860
863
  const emitted = finalizedOnly ? items.filter((item) => item.block_height <= envelope.tip.finalized_height) : items;
861
864
  const checkpoint = finalizedOnly ? emitted.at(-1)?.cursor ?? cursor : envelope.next_cursor;
862
865
  height = emitted.at(-1)?.block_height ?? height;
863
- const ctx = batchContext(checkpoint, height, envelope.tip.block_height);
866
+ const ctx = batchContext(checkpoint, height, envelope.tip, envelope.reorgs);
864
867
  opts.onProgress?.(ctx);
865
868
  let nextCursor;
866
869
  if (opts.sink) {
@@ -1177,7 +1180,8 @@ class Index extends BaseClient {
1177
1180
  sender: params.sender,
1178
1181
  contract_id: params.contractId,
1179
1182
  from_height: params.fromHeight,
1180
- to_height: params.toHeight
1183
+ to_height: params.toHeight,
1184
+ fields: params.fields?.join(",")
1181
1185
  })}`);
1182
1186
  }
1183
1187
  async getTransaction(txId) {
@@ -1250,7 +1254,8 @@ class Index extends BaseClient {
1250
1254
  request_id: params.requestId,
1251
1255
  settlement_confirmed: params.settlementConfirmed,
1252
1256
  from_height: params.fromHeight,
1253
- to_height: params.toHeight
1257
+ to_height: params.toHeight,
1258
+ fields: params.fields?.join(",")
1254
1259
  })}`);
1255
1260
  }
1256
1261
  walkSbtcWithdrawals(params = {}) {
@@ -1292,7 +1297,8 @@ class Index extends BaseClient {
1292
1297
  bond_index: params.bondIndex,
1293
1298
  reward_cycle: params.rewardCycle,
1294
1299
  from_height: params.fromHeight,
1295
- to_height: params.toHeight
1300
+ to_height: params.toHeight,
1301
+ fields: params.fields?.join(",")
1296
1302
  })}`);
1297
1303
  }
1298
1304
  walkPox5Events(params = {}) {
@@ -2182,5 +2188,5 @@ export {
2182
2188
  Subgraphs
2183
2189
  };
2184
2190
 
2185
- //# debugId=E63059793EB272A464756E2164756E21
2191
+ //# debugId=228E6E1BCAEED70464756E2164756E21
2186
2192
  //# sourceMappingURL=index.js.map