@secondlayer/sdk 6.42.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 +90 -10
- package/dist/index.js +16 -9
- package/dist/index.js.map +6 -6
- package/dist/streams/index.d.ts +17 -1
- package/dist/streams/index.js +7 -4
- package/dist/streams/index.js.map +4 -4
- package/dist/subgraphs/index.d.ts +90 -10
- package/dist/subgraphs/index.js +16 -9
- package/dist/subgraphs/index.js.map +5 -5
- package/package.json +2 -2
|
@@ -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:
|
|
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
|
|
@@ -1714,8 +1740,8 @@ type IndexSbtcSummary = {
|
|
|
1714
1740
|
total_locked_sats: string
|
|
1715
1741
|
sbtc_supply_sats: string | null
|
|
1716
1742
|
};
|
|
1717
|
-
type SbtcDepositsEnvelope = {
|
|
1718
|
-
deposits:
|
|
1743
|
+
type SbtcDepositsEnvelope<TRow = IndexSbtcDeposit> = {
|
|
1744
|
+
deposits: TRow[]
|
|
1719
1745
|
next_cursor: string | null
|
|
1720
1746
|
tip: IndexTip
|
|
1721
1747
|
reorgs: IndexReorg[]
|
|
@@ -1726,8 +1752,8 @@ type SbtcDepositEnvelope = {
|
|
|
1726
1752
|
deposit: IndexSbtcDepositDetail
|
|
1727
1753
|
tip: IndexTip
|
|
1728
1754
|
};
|
|
1729
|
-
type SbtcWithdrawalsEnvelope = {
|
|
1730
|
-
withdrawals:
|
|
1755
|
+
type SbtcWithdrawalsEnvelope<TRow = IndexSbtcWithdrawal> = {
|
|
1756
|
+
withdrawals: TRow[]
|
|
1731
1757
|
next_cursor: string | null
|
|
1732
1758
|
tip: IndexTip
|
|
1733
1759
|
reorgs: IndexReorg[]
|
|
@@ -1759,12 +1785,32 @@ type SbtcDepositsListParams = {
|
|
|
1759
1785
|
bitcoinTxid?: string
|
|
1760
1786
|
fromHeight?: number
|
|
1761
1787
|
toHeight?: number
|
|
1788
|
+
/**
|
|
1789
|
+
* Columns to return. The server projects the row, so an unrequested column
|
|
1790
|
+
* is physically absent — and the narrowing overload on `list` makes reading
|
|
1791
|
+
* one a compile error rather than `undefined` at runtime.
|
|
1792
|
+
*/
|
|
1793
|
+
fields?: readonly (keyof IndexSbtcDeposit & string)[]
|
|
1762
1794
|
};
|
|
1795
|
+
/** Deposit columns that survive any projection — pagination needs them. */
|
|
1796
|
+
type SbtcDepositAlwaysFields = "cursor" | "block_height";
|
|
1797
|
+
/** A deposit row narrowed to the requested columns plus the always-present ones. */
|
|
1798
|
+
type SbtcDepositFields<F extends keyof IndexSbtcDeposit & string> = Pick<IndexSbtcDeposit, (F | SbtcDepositAlwaysFields) & keyof IndexSbtcDeposit>;
|
|
1763
1799
|
type SbtcDepositsWalkParams = Omit<SbtcDepositsListParams, "limit"> & {
|
|
1764
1800
|
batchSize?: number
|
|
1765
1801
|
signal?: AbortSignal
|
|
1766
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>;
|
|
1767
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)[]
|
|
1768
1814
|
cursor?: string | null
|
|
1769
1815
|
fromCursor?: string | null
|
|
1770
1816
|
limit?: number
|
|
@@ -1804,6 +1850,11 @@ type SbtcDepositsConsumeParams<TTx = never> = Omit<SbtcDepositsListParams, "curs
|
|
|
1804
1850
|
* events, scoreboard). The only productized decoded sBTC peg feed on Stacks. */
|
|
1805
1851
|
interface SbtcResource {
|
|
1806
1852
|
deposits: {
|
|
1853
|
+
/** Narrowing overload: `fields` shrinks the row type to exactly the
|
|
1854
|
+
* requested columns plus {@link SbtcDepositAlwaysFields}. */
|
|
1855
|
+
list<const F extends keyof IndexSbtcDeposit & string>(params: SbtcDepositsListParams & {
|
|
1856
|
+
fields: readonly F[]
|
|
1857
|
+
}): Promise<SbtcDepositsEnvelope<SbtcDepositFields<F>>>
|
|
1807
1858
|
list(params?: SbtcDepositsListParams): Promise<SbtcDepositsEnvelope>
|
|
1808
1859
|
walk(params?: SbtcDepositsWalkParams): AsyncIterable<IndexSbtcDeposit>
|
|
1809
1860
|
/** Checkpointed sweep of completed deposits — append-only, so safe to
|
|
@@ -1819,6 +1870,11 @@ interface SbtcResource {
|
|
|
1819
1870
|
get(bitcoinTxid: string): Promise<SbtcDepositEnvelope | null>
|
|
1820
1871
|
};
|
|
1821
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>>>
|
|
1822
1878
|
list(params?: SbtcWithdrawalsListParams): Promise<SbtcWithdrawalsEnvelope>
|
|
1823
1879
|
walk(params?: SbtcWithdrawalsWalkParams): AsyncIterable<IndexSbtcWithdrawal>
|
|
1824
1880
|
/** Fetch a withdrawal's full lifecycle by request id; 404 → null. */
|
|
@@ -1923,15 +1979,25 @@ type IndexPox5Event = {
|
|
|
1923
1979
|
/** The full decoded print tuple as JSON. */
|
|
1924
1980
|
data: unknown
|
|
1925
1981
|
};
|
|
1926
|
-
type Pox5EventsEnvelope = {
|
|
1927
|
-
events:
|
|
1982
|
+
type Pox5EventsEnvelope<TRow = IndexPox5Event> = {
|
|
1983
|
+
events: TRow[]
|
|
1928
1984
|
next_cursor: string | null
|
|
1929
1985
|
tip: IndexTip
|
|
1930
1986
|
reorgs: IndexReorg[]
|
|
1931
1987
|
/** Present only when the PoX-5 decoder is disabled, explaining an empty feed. */
|
|
1932
1988
|
notes?: string
|
|
1933
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>;
|
|
1934
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)[]
|
|
1935
2001
|
cursor?: string | null
|
|
1936
2002
|
fromCursor?: string | null
|
|
1937
2003
|
limit?: number
|
|
@@ -1954,6 +2020,11 @@ type Pox5EventsWalkParams = Omit<Pox5EventsListParams, "limit"> & {
|
|
|
1954
2020
|
* epoch 4.0 hard fork onward (PoX-4's `index.stacking` stream ends there). */
|
|
1955
2021
|
interface Pox5Resource {
|
|
1956
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>>>
|
|
1957
2028
|
list(params?: Pox5EventsListParams): Promise<Pox5EventsEnvelope>
|
|
1958
2029
|
walk(params?: Pox5EventsWalkParams): AsyncIterable<IndexPox5Event>
|
|
1959
2030
|
};
|
|
@@ -2081,7 +2152,16 @@ declare class Index extends BaseClient {
|
|
|
2081
2152
|
/** Full transaction documents: paginated `list`/`walk`, plus `get` by tx_id
|
|
2082
2153
|
* (resolves to null on 404). */
|
|
2083
2154
|
readonly transactions: {
|
|
2084
|
-
|
|
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
|
+
}
|
|
2085
2165
|
walk: (params?: TransactionsWalkParams) => AsyncIterable<IndexTransaction>
|
|
2086
2166
|
get: (txId: string) => Promise<TransactionEnvelope | null>
|
|
2087
2167
|
getProof: (txId: string) => Promise<TransactionProof | null>
|
package/dist/subgraphs/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,
|
|
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.
|
|
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.
|
|
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) {
|
|
@@ -1229,7 +1233,8 @@ class Index extends BaseClient {
|
|
|
1229
1233
|
sender: params.sender,
|
|
1230
1234
|
bitcoin_txid: params.bitcoinTxid,
|
|
1231
1235
|
from_height: params.fromHeight,
|
|
1232
|
-
to_height: params.toHeight
|
|
1236
|
+
to_height: params.toHeight,
|
|
1237
|
+
fields: params.fields?.join(",")
|
|
1233
1238
|
})}`);
|
|
1234
1239
|
}
|
|
1235
1240
|
walkSbtcDeposits(params = {}) {
|
|
@@ -1249,7 +1254,8 @@ class Index extends BaseClient {
|
|
|
1249
1254
|
request_id: params.requestId,
|
|
1250
1255
|
settlement_confirmed: params.settlementConfirmed,
|
|
1251
1256
|
from_height: params.fromHeight,
|
|
1252
|
-
to_height: params.toHeight
|
|
1257
|
+
to_height: params.toHeight,
|
|
1258
|
+
fields: params.fields?.join(",")
|
|
1253
1259
|
})}`);
|
|
1254
1260
|
}
|
|
1255
1261
|
walkSbtcWithdrawals(params = {}) {
|
|
@@ -1291,7 +1297,8 @@ class Index extends BaseClient {
|
|
|
1291
1297
|
bond_index: params.bondIndex,
|
|
1292
1298
|
reward_cycle: params.rewardCycle,
|
|
1293
1299
|
from_height: params.fromHeight,
|
|
1294
|
-
to_height: params.toHeight
|
|
1300
|
+
to_height: params.toHeight,
|
|
1301
|
+
fields: params.fields?.join(",")
|
|
1295
1302
|
})}`);
|
|
1296
1303
|
}
|
|
1297
1304
|
walkPox5Events(params = {}) {
|
|
@@ -2181,5 +2188,5 @@ export {
|
|
|
2181
2188
|
Subgraphs
|
|
2182
2189
|
};
|
|
2183
2190
|
|
|
2184
|
-
//# debugId=
|
|
2191
|
+
//# debugId=228E6E1BCAEED70464756E2164756E21
|
|
2185
2192
|
//# sourceMappingURL=index.js.map
|