@secondlayer/sdk 6.43.0 → 6.45.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. */
@@ -1062,6 +1078,7 @@ type IndexUsage = {
1062
1078
  type FtTransfer = {
1063
1079
  cursor: string
1064
1080
  block_height: number
1081
+ block_time?: string | null
1065
1082
  tx_id: string
1066
1083
  tx_index: number
1067
1084
  event_index: number
@@ -1072,13 +1089,25 @@ type FtTransfer = {
1072
1089
  recipient: string
1073
1090
  amount: string
1074
1091
  };
1075
- type FtTransfersEnvelope = {
1076
- events: FtTransfer[]
1092
+ type FtTransfersEnvelope<TRow = FtTransfer> = {
1093
+ events: TRow[]
1077
1094
  next_cursor: string | null
1078
1095
  tip: IndexTip
1079
1096
  reorgs: IndexReorg[]
1080
1097
  };
1098
+ /** Transfer columns that survive any projection — the consume contract
1099
+ * (`cursor`, `block_height`) plus the `event_type` discriminant. */
1100
+ type FtTransferAlwaysFields = "cursor" | "block_height" | "event_type";
1101
+ /** An ft-transfer row narrowed to the requested columns plus the always-present ones. */
1102
+ type FtTransferFields<F extends keyof FtTransfer & string> = Pick<FtTransfer, (F | FtTransferAlwaysFields) & keyof FtTransfer>;
1081
1103
  type FtTransfersListParams = {
1104
+ /**
1105
+ * Columns to return. The server projects the row, so an unrequested column
1106
+ * is physically absent — and the narrowing overload on `list` makes reading
1107
+ * one a compile error rather than `undefined` at runtime. Omitting
1108
+ * `block_time` also lets the server skip the blocks join.
1109
+ */
1110
+ fields?: readonly (keyof FtTransfer & string)[]
1082
1111
  cursor?: string | null
1083
1112
  fromCursor?: string | null
1084
1113
  limit?: number
@@ -1095,6 +1124,7 @@ type FtTransfersWalkParams = Omit<FtTransfersListParams, "limit"> & {
1095
1124
  type NftTransfer = {
1096
1125
  cursor: string
1097
1126
  block_height: number
1127
+ block_time?: string | null
1098
1128
  tx_id: string
1099
1129
  tx_index: number
1100
1130
  event_index: number
@@ -1105,13 +1135,19 @@ type NftTransfer = {
1105
1135
  recipient: string
1106
1136
  value: string
1107
1137
  };
1108
- type NftTransfersEnvelope = {
1109
- events: NftTransfer[]
1138
+ type NftTransfersEnvelope<TRow = NftTransfer> = {
1139
+ events: TRow[]
1110
1140
  next_cursor: string | null
1111
1141
  tip: IndexTip
1112
1142
  reorgs: IndexReorg[]
1113
1143
  };
1144
+ /** See {@link FtTransferAlwaysFields}. */
1145
+ type NftTransferAlwaysFields = "cursor" | "block_height" | "event_type";
1146
+ /** An nft-transfer row narrowed to the requested columns plus the always-present ones. */
1147
+ type NftTransferFields<F extends keyof NftTransfer & string> = Pick<NftTransfer, (F | NftTransferAlwaysFields) & keyof NftTransfer>;
1114
1148
  type NftTransfersListParams = {
1149
+ /** Columns to return (see {@link FtTransfersListParams.fields}). */
1150
+ fields?: readonly (keyof NftTransfer & string)[]
1115
1151
  cursor?: string | null
1116
1152
  fromCursor?: string | null
1117
1153
  limit?: number
@@ -1451,8 +1487,8 @@ type IndexTransaction = {
1451
1487
  cause: number
1452
1488
  }
1453
1489
  };
1454
- type TransactionsEnvelope = {
1455
- transactions: IndexTransaction[]
1490
+ type TransactionsEnvelope<TRow = IndexTransaction> = {
1491
+ transactions: TRow[]
1456
1492
  next_cursor: string | null
1457
1493
  tip: IndexTip
1458
1494
  reorgs: IndexReorg[]
@@ -1461,7 +1497,17 @@ type TransactionEnvelope = {
1461
1497
  transaction: IndexTransaction
1462
1498
  tip: IndexTip
1463
1499
  };
1500
+ /** Transaction columns that survive any projection. */
1501
+ type TransactionAlwaysFields = "cursor" | "block_height" | "tx_id";
1502
+ /** A Transaction row narrowed to the requested columns plus the always-present ones. */
1503
+ type TransactionFields<F extends keyof IndexTransaction & string> = Pick<IndexTransaction, (F | TransactionAlwaysFields) & keyof IndexTransaction>;
1464
1504
  type TransactionsListParams = {
1505
+ /**
1506
+ * Columns to return. The server projects the row, so an unrequested column
1507
+ * is physically absent — and the narrowing overload on `list` makes reading
1508
+ * one a compile error rather than `undefined` at runtime.
1509
+ */
1510
+ fields?: readonly (keyof IndexTransaction & string)[]
1465
1511
  cursor?: string | null
1466
1512
  fromCursor?: string | null
1467
1513
  limit?: number
@@ -1726,8 +1772,8 @@ type SbtcDepositEnvelope = {
1726
1772
  deposit: IndexSbtcDepositDetail
1727
1773
  tip: IndexTip
1728
1774
  };
1729
- type SbtcWithdrawalsEnvelope = {
1730
- withdrawals: IndexSbtcWithdrawal[]
1775
+ type SbtcWithdrawalsEnvelope<TRow = IndexSbtcWithdrawal> = {
1776
+ withdrawals: TRow[]
1731
1777
  next_cursor: string | null
1732
1778
  tip: IndexTip
1733
1779
  reorgs: IndexReorg[]
@@ -1774,7 +1820,17 @@ type SbtcDepositsWalkParams = Omit<SbtcDepositsListParams, "limit"> & {
1774
1820
  batchSize?: number
1775
1821
  signal?: AbortSignal
1776
1822
  };
1823
+ /** SbtcWithdrawal columns that survive any projection. */
1824
+ type SbtcWithdrawalAlwaysFields = "cursor" | "request_id";
1825
+ /** A SbtcWithdrawal row narrowed to the requested columns plus the always-present ones. */
1826
+ type SbtcWithdrawalFields<F extends keyof IndexSbtcWithdrawal & string> = Pick<IndexSbtcWithdrawal, (F | SbtcWithdrawalAlwaysFields) & keyof IndexSbtcWithdrawal>;
1777
1827
  type SbtcWithdrawalsListParams = {
1828
+ /**
1829
+ * Columns to return. The server projects the row, so an unrequested column
1830
+ * is physically absent — and the narrowing overload on `list` makes reading
1831
+ * one a compile error rather than `undefined` at runtime.
1832
+ */
1833
+ fields?: readonly (keyof IndexSbtcWithdrawal & string)[]
1778
1834
  cursor?: string | null
1779
1835
  fromCursor?: string | null
1780
1836
  limit?: number
@@ -1834,6 +1890,11 @@ interface SbtcResource {
1834
1890
  get(bitcoinTxid: string): Promise<SbtcDepositEnvelope | null>
1835
1891
  };
1836
1892
  withdrawals: {
1893
+ /** Narrowing overload: `fields` shrinks the row type to exactly the
1894
+ * requested columns plus {@link SbtcWithdrawalAlwaysFields}. */
1895
+ list<const F extends keyof IndexSbtcWithdrawal & string>(params: SbtcWithdrawalsListParams & {
1896
+ fields: readonly F[]
1897
+ }): Promise<SbtcWithdrawalsEnvelope<SbtcWithdrawalFields<F>>>
1837
1898
  list(params?: SbtcWithdrawalsListParams): Promise<SbtcWithdrawalsEnvelope>
1838
1899
  walk(params?: SbtcWithdrawalsWalkParams): AsyncIterable<IndexSbtcWithdrawal>
1839
1900
  /** Fetch a withdrawal's full lifecycle by request id; 404 → null. */
@@ -1938,15 +1999,25 @@ type IndexPox5Event = {
1938
1999
  /** The full decoded print tuple as JSON. */
1939
2000
  data: unknown
1940
2001
  };
1941
- type Pox5EventsEnvelope = {
1942
- events: IndexPox5Event[]
2002
+ type Pox5EventsEnvelope<TRow = IndexPox5Event> = {
2003
+ events: TRow[]
1943
2004
  next_cursor: string | null
1944
2005
  tip: IndexTip
1945
2006
  reorgs: IndexReorg[]
1946
2007
  /** Present only when the PoX-5 decoder is disabled, explaining an empty feed. */
1947
2008
  notes?: string
1948
2009
  };
2010
+ /** Pox5Event columns that survive any projection. */
2011
+ type Pox5EventAlwaysFields = "cursor" | "block_height" | "topic";
2012
+ /** A Pox5Event row narrowed to the requested columns plus the always-present ones. */
2013
+ type Pox5EventFields<F extends keyof IndexPox5Event & string> = Pick<IndexPox5Event, (F | Pox5EventAlwaysFields) & keyof IndexPox5Event>;
1949
2014
  type Pox5EventsListParams = {
2015
+ /**
2016
+ * Columns to return. The server projects the row, so an unrequested column
2017
+ * is physically absent — and the narrowing overload on `list` makes reading
2018
+ * one a compile error rather than `undefined` at runtime.
2019
+ */
2020
+ fields?: readonly (keyof IndexPox5Event & string)[]
1950
2021
  cursor?: string | null
1951
2022
  fromCursor?: string | null
1952
2023
  limit?: number
@@ -1969,6 +2040,11 @@ type Pox5EventsWalkParams = Omit<Pox5EventsListParams, "limit"> & {
1969
2040
  * epoch 4.0 hard fork onward (PoX-4's `index.stacking` stream ends there). */
1970
2041
  interface Pox5Resource {
1971
2042
  events: {
2043
+ /** Narrowing overload: `fields` shrinks the row type to exactly the
2044
+ * requested columns plus {@link Pox5EventAlwaysFields}. */
2045
+ list<const F extends keyof IndexPox5Event & string>(params: Pox5EventsListParams & {
2046
+ fields: readonly F[]
2047
+ }): Promise<Pox5EventsEnvelope<Pox5EventFields<F>>>
1972
2048
  list(params?: Pox5EventsListParams): Promise<Pox5EventsEnvelope>
1973
2049
  walk(params?: Pox5EventsWalkParams): AsyncIterable<IndexPox5Event>
1974
2050
  };
@@ -1981,14 +2057,44 @@ interface Pox5Resource {
1981
2057
  * no amount filtering and no asset-slug resolution on /v1/index/ft-transfers.
1982
2058
  */
1983
2059
  interface FtTransfersResource {
2060
+ /** Narrowing overload for the callable shorthand — same wire path as
2061
+ * `list`, so it must narrow identically. */
2062
+ <const F extends keyof FtTransfer & string>(params: FtTransfersListParams & {
2063
+ fields: readonly F[]
2064
+ }): Promise<FtTransfersEnvelope<FtTransferFields<F>>>;
1984
2065
  (params?: FtTransfersListParams): Promise<FtTransfersEnvelope>;
2066
+ /** Narrowing overload: `fields` shrinks the row type to exactly the
2067
+ * requested columns plus {@link FtTransferAlwaysFields}. */
2068
+ list<const F extends keyof FtTransfer & string>(params: FtTransfersListParams & {
2069
+ fields: readonly F[]
2070
+ }): Promise<FtTransfersEnvelope<FtTransferFields<F>>>;
1985
2071
  list(params?: FtTransfersListParams): Promise<FtTransfersEnvelope>;
2072
+ /** Narrowing overload, matching `list`: `walk` forwards `fields` to the
2073
+ * wire, so without this the yielded rows are stripped while the type
2074
+ * still promises every column. */
2075
+ walk<const F extends keyof FtTransfer & string>(params: FtTransfersWalkParams & {
2076
+ fields: readonly F[]
2077
+ }): AsyncIterable<FtTransferFields<F>>;
1986
2078
  walk(params?: FtTransfersWalkParams): AsyncIterable<FtTransfer>;
1987
2079
  }
1988
2080
  /** `index.nftTransfers` — callable shorthand for `.list()` (see {@link FtTransfersResource}). */
1989
2081
  interface NftTransfersResource {
2082
+ /** Narrowing overload for the callable shorthand — same wire path as
2083
+ * `list`, so it must narrow identically. */
2084
+ <const F extends keyof NftTransfer & string>(params: NftTransfersListParams & {
2085
+ fields: readonly F[]
2086
+ }): Promise<NftTransfersEnvelope<NftTransferFields<F>>>;
1990
2087
  (params?: NftTransfersListParams): Promise<NftTransfersEnvelope>;
2088
+ /** Narrowing overload: `fields` shrinks the row type to exactly the
2089
+ * requested columns plus {@link NftTransferAlwaysFields}. */
2090
+ list<const F extends keyof NftTransfer & string>(params: NftTransfersListParams & {
2091
+ fields: readonly F[]
2092
+ }): Promise<NftTransfersEnvelope<NftTransferFields<F>>>;
1991
2093
  list(params?: NftTransfersListParams): Promise<NftTransfersEnvelope>;
2094
+ /** Narrowing overload, matching `list` (see {@link FtTransfersResource}). */
2095
+ walk<const F extends keyof NftTransfer & string>(params: NftTransfersWalkParams & {
2096
+ fields: readonly F[]
2097
+ }): AsyncIterable<NftTransferFields<F>>;
1992
2098
  walk(params?: NftTransfersWalkParams): AsyncIterable<NftTransfer>;
1993
2099
  }
1994
2100
  /** `index.events` — callable shorthand for `.list()`; `eventType` is required. */
@@ -2096,7 +2202,16 @@ declare class Index extends BaseClient {
2096
2202
  /** Full transaction documents: paginated `list`/`walk`, plus `get` by tx_id
2097
2203
  * (resolves to null on 404). */
2098
2204
  readonly transactions: {
2099
- list: (params?: TransactionsListParams) => Promise<TransactionsEnvelope>
2205
+ /** Narrowing overload: `fields` shrinks the row type to exactly the
2206
+ * requested columns plus {@link TransactionAlwaysFields}. Declared as
2207
+ * an overloaded call signature because an arrow property cannot carry
2208
+ * overloads. */
2209
+ list: {
2210
+ <const F extends keyof IndexTransaction & string>(params: TransactionsListParams & {
2211
+ fields: readonly F[]
2212
+ }): Promise<TransactionsEnvelope<TransactionFields<F>>>
2213
+ (params?: TransactionsListParams): Promise<TransactionsEnvelope>
2214
+ }
2100
2215
  walk: (params?: TransactionsWalkParams) => AsyncIterable<IndexTransaction>
2101
2216
  get: (txId: string) => Promise<TransactionEnvelope | null>
2102
2217
  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) {
@@ -1058,7 +1061,8 @@ class Index extends BaseClient {
1058
1061
  sender: params.sender,
1059
1062
  recipient: params.recipient,
1060
1063
  from_height: params.fromHeight,
1061
- to_height: params.toHeight
1064
+ to_height: params.toHeight,
1065
+ fields: params.fields?.join(",")
1062
1066
  })}`);
1063
1067
  }
1064
1068
  async listNftTransfers(params = {}) {
@@ -1071,7 +1075,8 @@ class Index extends BaseClient {
1071
1075
  sender: params.sender,
1072
1076
  recipient: params.recipient,
1073
1077
  from_height: params.fromHeight,
1074
- to_height: params.toHeight
1078
+ to_height: params.toHeight,
1079
+ fields: params.fields?.join(",")
1075
1080
  })}`);
1076
1081
  }
1077
1082
  async* keysetWalk(params, list, itemsOf) {
@@ -1177,7 +1182,8 @@ class Index extends BaseClient {
1177
1182
  sender: params.sender,
1178
1183
  contract_id: params.contractId,
1179
1184
  from_height: params.fromHeight,
1180
- to_height: params.toHeight
1185
+ to_height: params.toHeight,
1186
+ fields: params.fields?.join(",")
1181
1187
  })}`);
1182
1188
  }
1183
1189
  async getTransaction(txId) {
@@ -1250,7 +1256,8 @@ class Index extends BaseClient {
1250
1256
  request_id: params.requestId,
1251
1257
  settlement_confirmed: params.settlementConfirmed,
1252
1258
  from_height: params.fromHeight,
1253
- to_height: params.toHeight
1259
+ to_height: params.toHeight,
1260
+ fields: params.fields?.join(",")
1254
1261
  })}`);
1255
1262
  }
1256
1263
  walkSbtcWithdrawals(params = {}) {
@@ -1292,7 +1299,8 @@ class Index extends BaseClient {
1292
1299
  bond_index: params.bondIndex,
1293
1300
  reward_cycle: params.rewardCycle,
1294
1301
  from_height: params.fromHeight,
1295
- to_height: params.toHeight
1302
+ to_height: params.toHeight,
1303
+ fields: params.fields?.join(",")
1296
1304
  })}`);
1297
1305
  }
1298
1306
  walkPox5Events(params = {}) {
@@ -2182,5 +2190,5 @@ export {
2182
2190
  Subgraphs
2183
2191
  };
2184
2192
 
2185
- //# debugId=E63059793EB272A464756E2164756E21
2193
+ //# debugId=2CB03593632F542B64756E2164756E21
2186
2194
  //# sourceMappingURL=index.js.map