@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
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:
|
|
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
|
|
@@ -1802,8 +1828,8 @@ type IndexSbtcSummary = {
|
|
|
1802
1828
|
total_locked_sats: string
|
|
1803
1829
|
sbtc_supply_sats: string | null
|
|
1804
1830
|
};
|
|
1805
|
-
type SbtcDepositsEnvelope = {
|
|
1806
|
-
deposits:
|
|
1831
|
+
type SbtcDepositsEnvelope<TRow = IndexSbtcDeposit> = {
|
|
1832
|
+
deposits: TRow[]
|
|
1807
1833
|
next_cursor: string | null
|
|
1808
1834
|
tip: IndexTip
|
|
1809
1835
|
reorgs: IndexReorg[]
|
|
@@ -1814,8 +1840,8 @@ type SbtcDepositEnvelope = {
|
|
|
1814
1840
|
deposit: IndexSbtcDepositDetail
|
|
1815
1841
|
tip: IndexTip
|
|
1816
1842
|
};
|
|
1817
|
-
type SbtcWithdrawalsEnvelope = {
|
|
1818
|
-
withdrawals:
|
|
1843
|
+
type SbtcWithdrawalsEnvelope<TRow = IndexSbtcWithdrawal> = {
|
|
1844
|
+
withdrawals: TRow[]
|
|
1819
1845
|
next_cursor: string | null
|
|
1820
1846
|
tip: IndexTip
|
|
1821
1847
|
reorgs: IndexReorg[]
|
|
@@ -1847,12 +1873,32 @@ type SbtcDepositsListParams = {
|
|
|
1847
1873
|
bitcoinTxid?: string
|
|
1848
1874
|
fromHeight?: number
|
|
1849
1875
|
toHeight?: number
|
|
1876
|
+
/**
|
|
1877
|
+
* Columns to return. The server projects the row, so an unrequested column
|
|
1878
|
+
* is physically absent — and the narrowing overload on `list` makes reading
|
|
1879
|
+
* one a compile error rather than `undefined` at runtime.
|
|
1880
|
+
*/
|
|
1881
|
+
fields?: readonly (keyof IndexSbtcDeposit & string)[]
|
|
1850
1882
|
};
|
|
1883
|
+
/** Deposit columns that survive any projection — pagination needs them. */
|
|
1884
|
+
type SbtcDepositAlwaysFields = "cursor" | "block_height";
|
|
1885
|
+
/** A deposit row narrowed to the requested columns plus the always-present ones. */
|
|
1886
|
+
type SbtcDepositFields<F extends keyof IndexSbtcDeposit & string> = Pick<IndexSbtcDeposit, (F | SbtcDepositAlwaysFields) & keyof IndexSbtcDeposit>;
|
|
1851
1887
|
type SbtcDepositsWalkParams = Omit<SbtcDepositsListParams, "limit"> & {
|
|
1852
1888
|
batchSize?: number
|
|
1853
1889
|
signal?: AbortSignal
|
|
1854
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>;
|
|
1855
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)[]
|
|
1856
1902
|
cursor?: string | null
|
|
1857
1903
|
fromCursor?: string | null
|
|
1858
1904
|
limit?: number
|
|
@@ -1892,6 +1938,11 @@ type SbtcDepositsConsumeParams<TTx = never> = Omit<SbtcDepositsListParams, "curs
|
|
|
1892
1938
|
* events, scoreboard). The only productized decoded sBTC peg feed on Stacks. */
|
|
1893
1939
|
interface SbtcResource {
|
|
1894
1940
|
deposits: {
|
|
1941
|
+
/** Narrowing overload: `fields` shrinks the row type to exactly the
|
|
1942
|
+
* requested columns plus {@link SbtcDepositAlwaysFields}. */
|
|
1943
|
+
list<const F extends keyof IndexSbtcDeposit & string>(params: SbtcDepositsListParams & {
|
|
1944
|
+
fields: readonly F[]
|
|
1945
|
+
}): Promise<SbtcDepositsEnvelope<SbtcDepositFields<F>>>
|
|
1895
1946
|
list(params?: SbtcDepositsListParams): Promise<SbtcDepositsEnvelope>
|
|
1896
1947
|
walk(params?: SbtcDepositsWalkParams): AsyncIterable<IndexSbtcDeposit>
|
|
1897
1948
|
/** Checkpointed sweep of completed deposits — append-only, so safe to
|
|
@@ -1907,6 +1958,11 @@ interface SbtcResource {
|
|
|
1907
1958
|
get(bitcoinTxid: string): Promise<SbtcDepositEnvelope | null>
|
|
1908
1959
|
};
|
|
1909
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>>>
|
|
1910
1966
|
list(params?: SbtcWithdrawalsListParams): Promise<SbtcWithdrawalsEnvelope>
|
|
1911
1967
|
walk(params?: SbtcWithdrawalsWalkParams): AsyncIterable<IndexSbtcWithdrawal>
|
|
1912
1968
|
/** Fetch a withdrawal's full lifecycle by request id; 404 → null. */
|
|
@@ -2011,15 +2067,25 @@ type IndexPox5Event = {
|
|
|
2011
2067
|
/** The full decoded print tuple as JSON. */
|
|
2012
2068
|
data: unknown
|
|
2013
2069
|
};
|
|
2014
|
-
type Pox5EventsEnvelope = {
|
|
2015
|
-
events:
|
|
2070
|
+
type Pox5EventsEnvelope<TRow = IndexPox5Event> = {
|
|
2071
|
+
events: TRow[]
|
|
2016
2072
|
next_cursor: string | null
|
|
2017
2073
|
tip: IndexTip
|
|
2018
2074
|
reorgs: IndexReorg[]
|
|
2019
2075
|
/** Present only when the PoX-5 decoder is disabled, explaining an empty feed. */
|
|
2020
2076
|
notes?: string
|
|
2021
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>;
|
|
2022
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)[]
|
|
2023
2089
|
cursor?: string | null
|
|
2024
2090
|
fromCursor?: string | null
|
|
2025
2091
|
limit?: number
|
|
@@ -2042,6 +2108,11 @@ type Pox5EventsWalkParams = Omit<Pox5EventsListParams, "limit"> & {
|
|
|
2042
2108
|
* epoch 4.0 hard fork onward (PoX-4's `index.stacking` stream ends there). */
|
|
2043
2109
|
interface Pox5Resource {
|
|
2044
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>>>
|
|
2045
2116
|
list(params?: Pox5EventsListParams): Promise<Pox5EventsEnvelope>
|
|
2046
2117
|
walk(params?: Pox5EventsWalkParams): AsyncIterable<IndexPox5Event>
|
|
2047
2118
|
};
|
|
@@ -2169,7 +2240,16 @@ declare class Index extends BaseClient {
|
|
|
2169
2240
|
/** Full transaction documents: paginated `list`/`walk`, plus `get` by tx_id
|
|
2170
2241
|
* (resolves to null on 404). */
|
|
2171
2242
|
readonly transactions: {
|
|
2172
|
-
|
|
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
|
+
}
|
|
2173
2253
|
walk: (params?: TransactionsWalkParams) => AsyncIterable<IndexTransaction>
|
|
2174
2254
|
get: (txId: string) => Promise<TransactionEnvelope | null>
|
|
2175
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,
|
|
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 = {}) {
|
|
@@ -2877,5 +2884,5 @@ export {
|
|
|
2877
2884
|
ApiError
|
|
2878
2885
|
};
|
|
2879
2886
|
|
|
2880
|
-
//# debugId=
|
|
2887
|
+
//# debugId=2212082A9E39DB7664756E2164756E21
|
|
2881
2888
|
//# sourceMappingURL=index.js.map
|