@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.
package/dist/index.d.ts CHANGED
@@ -686,7 +686,10 @@ type StreamsEventsSubscribeParams = {
686
686
  * block as `${height - 1}:<sentinel>`, so a rewound cursor parses to a
687
687
  * position that was never reached.
688
688
  */
689
- type ConsumerBatchContext = {
689
+ type ConsumerBatchContext<
690
+ TTip = unknown,
691
+ TReorg = unknown
692
+ > = {
690
693
  /** Checkpoint to commit alongside your rows. */
691
694
  cursor: string | null
692
695
  /** Highest canonical block the sweep has reached. `null` before the first
@@ -696,6 +699,19 @@ type ConsumerBatchContext = {
696
699
  tipHeight: number
697
700
  /** `tipHeight - height`, floored at 0. `null` until `height` is known. */
698
701
  blocksBehind: number | null
702
+ /**
703
+ * The full tip for this page — `StreamsTip` or `IndexTip` depending on the
704
+ * surface. Exposed here so a handler never needs the `envelope` parameter,
705
+ * which is the only way to reach it today and is also how the worst
706
+ * `finalizedOnly` mistake becomes reachable (`return envelope.next_cursor`
707
+ * jumps the cursor past events that were filtered out and never delivered).
708
+ */
709
+ tip: TTip
710
+ /**
711
+ * Reorgs reported alongside this page; empty when none. Rollback still
712
+ * belongs in `onReorg` — this is for observability inside a batch.
713
+ */
714
+ reorgs: readonly TReorg[]
699
715
  };
700
716
  /** @deprecated Use {@link ConsumerBatchContext} — the Index and Streams loops
701
717
  * share one shape now. Kept as an alias so existing annotations compile. */
@@ -1539,8 +1555,8 @@ type IndexTransaction = {
1539
1555
  cause: number
1540
1556
  }
1541
1557
  };
1542
- type TransactionsEnvelope = {
1543
- transactions: IndexTransaction[]
1558
+ type TransactionsEnvelope<TRow = IndexTransaction> = {
1559
+ transactions: TRow[]
1544
1560
  next_cursor: string | null
1545
1561
  tip: IndexTip
1546
1562
  reorgs: IndexReorg[]
@@ -1549,7 +1565,17 @@ type TransactionEnvelope = {
1549
1565
  transaction: IndexTransaction
1550
1566
  tip: IndexTip
1551
1567
  };
1568
+ /** Transaction columns that survive any projection. */
1569
+ type TransactionAlwaysFields = "cursor" | "block_height" | "tx_id";
1570
+ /** A Transaction row narrowed to the requested columns plus the always-present ones. */
1571
+ type TransactionFields<F extends keyof IndexTransaction & string> = Pick<IndexTransaction, (F | TransactionAlwaysFields) & keyof IndexTransaction>;
1552
1572
  type TransactionsListParams = {
1573
+ /**
1574
+ * Columns to return. The server projects the row, so an unrequested column
1575
+ * is physically absent — and the narrowing overload on `list` makes reading
1576
+ * one a compile error rather than `undefined` at runtime.
1577
+ */
1578
+ fields?: readonly (keyof IndexTransaction & string)[]
1553
1579
  cursor?: string | null
1554
1580
  fromCursor?: string | null
1555
1581
  limit?: number
@@ -1814,8 +1840,8 @@ type SbtcDepositEnvelope = {
1814
1840
  deposit: IndexSbtcDepositDetail
1815
1841
  tip: IndexTip
1816
1842
  };
1817
- type SbtcWithdrawalsEnvelope = {
1818
- withdrawals: IndexSbtcWithdrawal[]
1843
+ type SbtcWithdrawalsEnvelope<TRow = IndexSbtcWithdrawal> = {
1844
+ withdrawals: TRow[]
1819
1845
  next_cursor: string | null
1820
1846
  tip: IndexTip
1821
1847
  reorgs: IndexReorg[]
@@ -1862,7 +1888,17 @@ type SbtcDepositsWalkParams = Omit<SbtcDepositsListParams, "limit"> & {
1862
1888
  batchSize?: number
1863
1889
  signal?: AbortSignal
1864
1890
  };
1891
+ /** SbtcWithdrawal columns that survive any projection. */
1892
+ type SbtcWithdrawalAlwaysFields = "cursor" | "request_id";
1893
+ /** A SbtcWithdrawal row narrowed to the requested columns plus the always-present ones. */
1894
+ type SbtcWithdrawalFields<F extends keyof IndexSbtcWithdrawal & string> = Pick<IndexSbtcWithdrawal, (F | SbtcWithdrawalAlwaysFields) & keyof IndexSbtcWithdrawal>;
1865
1895
  type SbtcWithdrawalsListParams = {
1896
+ /**
1897
+ * Columns to return. The server projects the row, so an unrequested column
1898
+ * is physically absent — and the narrowing overload on `list` makes reading
1899
+ * one a compile error rather than `undefined` at runtime.
1900
+ */
1901
+ fields?: readonly (keyof IndexSbtcWithdrawal & string)[]
1866
1902
  cursor?: string | null
1867
1903
  fromCursor?: string | null
1868
1904
  limit?: number
@@ -1922,6 +1958,11 @@ interface SbtcResource {
1922
1958
  get(bitcoinTxid: string): Promise<SbtcDepositEnvelope | null>
1923
1959
  };
1924
1960
  withdrawals: {
1961
+ /** Narrowing overload: `fields` shrinks the row type to exactly the
1962
+ * requested columns plus {@link SbtcWithdrawalAlwaysFields}. */
1963
+ list<const F extends keyof IndexSbtcWithdrawal & string>(params: SbtcWithdrawalsListParams & {
1964
+ fields: readonly F[]
1965
+ }): Promise<SbtcWithdrawalsEnvelope<SbtcWithdrawalFields<F>>>
1925
1966
  list(params?: SbtcWithdrawalsListParams): Promise<SbtcWithdrawalsEnvelope>
1926
1967
  walk(params?: SbtcWithdrawalsWalkParams): AsyncIterable<IndexSbtcWithdrawal>
1927
1968
  /** Fetch a withdrawal's full lifecycle by request id; 404 → null. */
@@ -2026,15 +2067,25 @@ type IndexPox5Event = {
2026
2067
  /** The full decoded print tuple as JSON. */
2027
2068
  data: unknown
2028
2069
  };
2029
- type Pox5EventsEnvelope = {
2030
- events: IndexPox5Event[]
2070
+ type Pox5EventsEnvelope<TRow = IndexPox5Event> = {
2071
+ events: TRow[]
2031
2072
  next_cursor: string | null
2032
2073
  tip: IndexTip
2033
2074
  reorgs: IndexReorg[]
2034
2075
  /** Present only when the PoX-5 decoder is disabled, explaining an empty feed. */
2035
2076
  notes?: string
2036
2077
  };
2078
+ /** Pox5Event columns that survive any projection. */
2079
+ type Pox5EventAlwaysFields = "cursor" | "block_height" | "topic";
2080
+ /** A Pox5Event row narrowed to the requested columns plus the always-present ones. */
2081
+ type Pox5EventFields<F extends keyof IndexPox5Event & string> = Pick<IndexPox5Event, (F | Pox5EventAlwaysFields) & keyof IndexPox5Event>;
2037
2082
  type Pox5EventsListParams = {
2083
+ /**
2084
+ * Columns to return. The server projects the row, so an unrequested column
2085
+ * is physically absent — and the narrowing overload on `list` makes reading
2086
+ * one a compile error rather than `undefined` at runtime.
2087
+ */
2088
+ fields?: readonly (keyof IndexPox5Event & string)[]
2038
2089
  cursor?: string | null
2039
2090
  fromCursor?: string | null
2040
2091
  limit?: number
@@ -2057,6 +2108,11 @@ type Pox5EventsWalkParams = Omit<Pox5EventsListParams, "limit"> & {
2057
2108
  * epoch 4.0 hard fork onward (PoX-4's `index.stacking` stream ends there). */
2058
2109
  interface Pox5Resource {
2059
2110
  events: {
2111
+ /** Narrowing overload: `fields` shrinks the row type to exactly the
2112
+ * requested columns plus {@link Pox5EventAlwaysFields}. */
2113
+ list<const F extends keyof IndexPox5Event & string>(params: Pox5EventsListParams & {
2114
+ fields: readonly F[]
2115
+ }): Promise<Pox5EventsEnvelope<Pox5EventFields<F>>>
2060
2116
  list(params?: Pox5EventsListParams): Promise<Pox5EventsEnvelope>
2061
2117
  walk(params?: Pox5EventsWalkParams): AsyncIterable<IndexPox5Event>
2062
2118
  };
@@ -2184,7 +2240,16 @@ declare class Index extends BaseClient {
2184
2240
  /** Full transaction documents: paginated `list`/`walk`, plus `get` by tx_id
2185
2241
  * (resolves to null on 404). */
2186
2242
  readonly transactions: {
2187
- list: (params?: TransactionsListParams) => Promise<TransactionsEnvelope>
2243
+ /** Narrowing overload: `fields` shrinks the row type to exactly the
2244
+ * requested columns plus {@link TransactionAlwaysFields}. Declared as
2245
+ * an overloaded call signature because an arrow property cannot carry
2246
+ * overloads. */
2247
+ list: {
2248
+ <const F extends keyof IndexTransaction & string>(params: TransactionsListParams & {
2249
+ fields: readonly F[]
2250
+ }): Promise<TransactionsEnvelope<TransactionFields<F>>>
2251
+ (params?: TransactionsListParams): Promise<TransactionsEnvelope>
2252
+ }
2188
2253
  walk: (params?: TransactionsWalkParams) => AsyncIterable<IndexTransaction>
2189
2254
  get: (txId: string) => Promise<TransactionEnvelope | null>
2190
2255
  getProof: (txId: string) => Promise<TransactionProof | null>
package/dist/index.js CHANGED
@@ -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 = {}) {
@@ -2878,5 +2884,5 @@ export {
2878
2884
  ApiError
2879
2885
  };
2880
2886
 
2881
- //# debugId=F96DBA9B81801E0B64756E2164756E21
2887
+ //# debugId=2212082A9E39DB7664756E2164756E21
2882
2888
  //# sourceMappingURL=index.js.map