@secondlayer/sdk 6.0.0 → 6.2.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 +230 -125
- package/dist/index.js +376 -404
- package/dist/index.js.map +17 -15
- package/dist/streams/index.d.ts +62 -2
- package/dist/streams/index.js +310 -226
- package/dist/streams/index.js.map +12 -9
- package/dist/subgraphs/index.d.ts +208 -1
- package/dist/subgraphs/index.js +311 -141
- package/dist/subgraphs/index.js.map +13 -10
- package/package.json +2 -2
|
@@ -105,6 +105,170 @@ declare class Subgraphs extends BaseClient {
|
|
|
105
105
|
private createTableClient;
|
|
106
106
|
}
|
|
107
107
|
import { InferSubgraphClient as InferSubgraphClient2 } from "@secondlayer/subgraphs";
|
|
108
|
+
/**
|
|
109
|
+
* Typed client for the contract-discovery API (`GET /v1/contracts`).
|
|
110
|
+
*
|
|
111
|
+
* "Find all contracts conforming to a trait" — backed by the contract registry:
|
|
112
|
+
* `declared` traits parsed from Clarity source, `inferred` standards from static
|
|
113
|
+
* ABI shape-matching. Anonymous public read. `trait` is required; the ABI blob is
|
|
114
|
+
* omitted unless `include: "abi"` is passed.
|
|
115
|
+
*/
|
|
116
|
+
/** Whether a trait match must be declared in source, inferred from ABI, or either. */
|
|
117
|
+
type ContractConformance = "declared" | "inferred" | "any";
|
|
118
|
+
interface ContractsListParams {
|
|
119
|
+
/** Required. Trait identifier to match (e.g. "sip-010", or a fully-qualified trait). */
|
|
120
|
+
trait: string;
|
|
121
|
+
/** Match source. Defaults to "any" server-side. */
|
|
122
|
+
conformance?: ContractConformance;
|
|
123
|
+
/** Set to "abi" to include the full ABI blob in each row. */
|
|
124
|
+
include?: "abi";
|
|
125
|
+
/** Page size, 1–500 (default 100 server-side). */
|
|
126
|
+
limit?: number;
|
|
127
|
+
/** Opaque cursor from a prior response's `next_cursor`. */
|
|
128
|
+
cursor?: string;
|
|
129
|
+
}
|
|
130
|
+
interface ContractSummary {
|
|
131
|
+
contract_id: string;
|
|
132
|
+
deployer: string;
|
|
133
|
+
block_height: number;
|
|
134
|
+
declared_traits: string[] | null;
|
|
135
|
+
inferred_standards: string[] | null;
|
|
136
|
+
abi_status: string;
|
|
137
|
+
/** Present only when `include: "abi"` was requested. */
|
|
138
|
+
abi?: unknown;
|
|
139
|
+
}
|
|
140
|
+
interface ContractsEnvelope {
|
|
141
|
+
contracts: ContractSummary[];
|
|
142
|
+
next_cursor: string | null;
|
|
143
|
+
}
|
|
144
|
+
declare class Contracts extends BaseClient {
|
|
145
|
+
constructor(options?: Partial<SecondLayerOptions>);
|
|
146
|
+
/** Find contracts conforming to `trait`. `trait` is required (server 400s without it). */
|
|
147
|
+
list(params: ContractsListParams): Promise<ContractsEnvelope>;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Typed client for the Foundation Datasets REST API (`/v1/datasets/*`).
|
|
151
|
+
*
|
|
152
|
+
* Most datasets are cursor-paginated event lists with a uniform `list`/`walk`
|
|
153
|
+
* surface; a few (bns names/namespaces/resolve, network-health) are
|
|
154
|
+
* offset/single-object/summary and get bespoke methods. Query params are typed
|
|
155
|
+
* per dataset; rows are `DatasetRow` (JSON) in v1 — per-dataset row interfaces
|
|
156
|
+
* are a fast-follow.
|
|
157
|
+
*/
|
|
158
|
+
/** A dataset row — flat JSON object. Per-dataset interfaces are a follow-up. */
|
|
159
|
+
type DatasetRow = Record<string, unknown>;
|
|
160
|
+
/** Filters shared by every cursor-paginated dataset. */
|
|
161
|
+
interface CursorListParams {
|
|
162
|
+
cursor?: string;
|
|
163
|
+
limit?: number;
|
|
164
|
+
fromBlock?: number;
|
|
165
|
+
toBlock?: number;
|
|
166
|
+
}
|
|
167
|
+
interface CursorEnvelope {
|
|
168
|
+
rows: DatasetRow[];
|
|
169
|
+
next_cursor: string | null;
|
|
170
|
+
tip?: {
|
|
171
|
+
block_height: number
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
type RangeFilters = CursorListParams;
|
|
175
|
+
type StxTransfersParams = RangeFilters & {
|
|
176
|
+
sender?: string
|
|
177
|
+
recipient?: string
|
|
178
|
+
};
|
|
179
|
+
type SbtcEventsParams = RangeFilters & {
|
|
180
|
+
topic?: string
|
|
181
|
+
address?: string
|
|
182
|
+
};
|
|
183
|
+
type SbtcTokenEventsParams = RangeFilters & {
|
|
184
|
+
eventType?: string
|
|
185
|
+
sender?: string
|
|
186
|
+
recipient?: string
|
|
187
|
+
};
|
|
188
|
+
type Pox4CallsParams = RangeFilters & {
|
|
189
|
+
functionName?: string
|
|
190
|
+
stacker?: string
|
|
191
|
+
delegateTo?: string
|
|
192
|
+
signerKey?: string
|
|
193
|
+
rewardCycle?: number
|
|
194
|
+
/** Any-role: matches caller OR stacker OR delegate_to. */
|
|
195
|
+
address?: string
|
|
196
|
+
};
|
|
197
|
+
type BurnchainRewardsParams = RangeFilters & {
|
|
198
|
+
/** Filter to one Bitcoin reward address. */
|
|
199
|
+
recipient?: string
|
|
200
|
+
};
|
|
201
|
+
type BurnchainRewardSlotsParams = RangeFilters & {
|
|
202
|
+
/** Filter to one reward-set Bitcoin address. */
|
|
203
|
+
holder?: string
|
|
204
|
+
};
|
|
205
|
+
type BnsEventsParams = RangeFilters & {
|
|
206
|
+
topic?: string
|
|
207
|
+
namespace?: string
|
|
208
|
+
name?: string
|
|
209
|
+
owner?: string
|
|
210
|
+
};
|
|
211
|
+
type BnsNamespaceEventsParams = RangeFilters & {
|
|
212
|
+
status?: string
|
|
213
|
+
namespace?: string
|
|
214
|
+
};
|
|
215
|
+
type BnsMarketplaceEventsParams = RangeFilters & {
|
|
216
|
+
action?: string
|
|
217
|
+
bnsId?: string
|
|
218
|
+
};
|
|
219
|
+
type CursorDataset<P> = {
|
|
220
|
+
list: (params?: P) => Promise<CursorEnvelope>
|
|
221
|
+
walk: (params?: P & {
|
|
222
|
+
batchSize?: number
|
|
223
|
+
signal?: AbortSignal
|
|
224
|
+
}) => AsyncIterable<DatasetRow>
|
|
225
|
+
};
|
|
226
|
+
declare class Datasets extends BaseClient {
|
|
227
|
+
constructor(options?: Partial<SecondLayerOptions>);
|
|
228
|
+
/** Dataset catalog + freshness (the discovery endpoint). */
|
|
229
|
+
listDatasets(): Promise<unknown>;
|
|
230
|
+
/**
|
|
231
|
+
* Generic cursor query by slug — used by the CLI. Params are passed through as
|
|
232
|
+
* REST query keys (snake_case), so callers can use the documented filter names
|
|
233
|
+
* directly. Throws for non-cursor (bespoke) datasets.
|
|
234
|
+
*/
|
|
235
|
+
query(slug: string, params?: Record<string, unknown>): Promise<CursorEnvelope>;
|
|
236
|
+
readonly stxTransfers: CursorDataset<StxTransfersParams>;
|
|
237
|
+
readonly sbtcEvents: CursorDataset<SbtcEventsParams>;
|
|
238
|
+
readonly sbtcTokenEvents: CursorDataset<SbtcTokenEventsParams>;
|
|
239
|
+
readonly pox4Calls: CursorDataset<Pox4CallsParams>;
|
|
240
|
+
readonly burnchainRewards: CursorDataset<BurnchainRewardsParams>;
|
|
241
|
+
readonly burnchainRewardSlots: CursorDataset<BurnchainRewardSlotsParams>;
|
|
242
|
+
readonly bnsEvents: CursorDataset<BnsEventsParams>;
|
|
243
|
+
readonly bnsNamespaceEvents: CursorDataset<BnsNamespaceEventsParams>;
|
|
244
|
+
readonly bnsMarketplaceEvents: CursorDataset<BnsMarketplaceEventsParams>;
|
|
245
|
+
/** BNS names — offset-paginated. */
|
|
246
|
+
bnsNames(params?: {
|
|
247
|
+
namespace?: string
|
|
248
|
+
owner?: string
|
|
249
|
+
limit?: number
|
|
250
|
+
offset?: number
|
|
251
|
+
}): Promise<{
|
|
252
|
+
names: DatasetRow[]
|
|
253
|
+
}>;
|
|
254
|
+
/** All BNS namespaces (no pagination). */
|
|
255
|
+
bnsNamespaces(): Promise<{
|
|
256
|
+
namespaces: DatasetRow[]
|
|
257
|
+
}>;
|
|
258
|
+
/** Resolve a fully-qualified BNS name → single record. */
|
|
259
|
+
bnsResolve(fqn: string): Promise<{
|
|
260
|
+
name: DatasetRow | null
|
|
261
|
+
}>;
|
|
262
|
+
/** Network health summary. */
|
|
263
|
+
networkHealth(): Promise<{
|
|
264
|
+
summary: DatasetRow
|
|
265
|
+
}>;
|
|
266
|
+
private get;
|
|
267
|
+
/** Map camelCase filter fields to snake_case query keys (dropping pagination
|
|
268
|
+
* controls) and build the canonical query suffix. */
|
|
269
|
+
private paramsToQuery;
|
|
270
|
+
private cursorDataset;
|
|
271
|
+
}
|
|
108
272
|
type IndexTip = {
|
|
109
273
|
block_height: number
|
|
110
274
|
lag_seconds: number
|
|
@@ -414,6 +578,11 @@ type PrintPayload = {
|
|
|
414
578
|
raw_value?: string
|
|
415
579
|
};
|
|
416
580
|
type StreamsEventBase = {
|
|
581
|
+
/**
|
|
582
|
+
* Globally unique, monotonic position of this event (`<block>:<index>`). Use
|
|
583
|
+
* it as the primary key of your projection rows — replaying a batch then
|
|
584
|
+
* upserts cleanly. Don't synthesize your own id from `tx_id`/`event_index`.
|
|
585
|
+
*/
|
|
417
586
|
cursor: string
|
|
418
587
|
block_height: number
|
|
419
588
|
block_hash: string
|
|
@@ -510,9 +679,32 @@ type StreamsEventsStreamParams = {
|
|
|
510
679
|
maxEmptyPolls?: number
|
|
511
680
|
signal?: AbortSignal
|
|
512
681
|
};
|
|
682
|
+
/**
|
|
683
|
+
* The checkpoint the SDK computes for a batch. Persist `cursor` inside the same
|
|
684
|
+
* transaction as your projection writes, then resume from it via `fromCursor`.
|
|
685
|
+
* It is the position to advance to: `next_cursor` normally, or the last
|
|
686
|
+
* finalized event when `finalizedOnly` is set.
|
|
687
|
+
*/
|
|
688
|
+
type StreamsBatchContext = {
|
|
689
|
+
cursor: string | null
|
|
690
|
+
};
|
|
691
|
+
/**
|
|
692
|
+
* The checkpoint for a reorg rollback. Persist `cursor` (the rewind position)
|
|
693
|
+
* inside the same transaction as your rollback so the two commit atomically.
|
|
694
|
+
*/
|
|
695
|
+
type StreamsReorgContext = {
|
|
696
|
+
cursor: string
|
|
697
|
+
};
|
|
513
698
|
type StreamsEventsConsumeParams = {
|
|
514
699
|
fromCursor?: string | null
|
|
515
700
|
mode?: "tail" | "bounded"
|
|
701
|
+
/**
|
|
702
|
+
* Emit only finalized (immutable) events and never surface reorgs. The SDK
|
|
703
|
+
* checkpoints at the last finalized event and re-reads the unfinalized tail
|
|
704
|
+
* until it settles. Trades finality lag for zero reorg handling; `onReorg` is
|
|
705
|
+
* ignored.
|
|
706
|
+
*/
|
|
707
|
+
finalizedOnly?: boolean
|
|
516
708
|
types?: readonly StreamsEventType[]
|
|
517
709
|
notTypes?: readonly StreamsEventType[]
|
|
518
710
|
contractId?: StreamsFilterValue
|
|
@@ -520,7 +712,20 @@ type StreamsEventsConsumeParams = {
|
|
|
520
712
|
recipient?: StreamsFilterValue
|
|
521
713
|
assetIdentifier?: string
|
|
522
714
|
batchSize?: number
|
|
523
|
-
|
|
715
|
+
/**
|
|
716
|
+
* Apply a page of canonical events. Persist `ctx.cursor` in the same
|
|
717
|
+
* transaction as your writes. Returning a cursor overrides `ctx.cursor` as
|
|
718
|
+
* the resume point (advanced manual control); returning nothing uses it.
|
|
719
|
+
*/
|
|
720
|
+
onBatch: (events: StreamsEvent[], envelope: StreamsEventsEnvelope, ctx: StreamsBatchContext) => void | string | null | undefined | Promise<void> | Promise<string | null | undefined>
|
|
721
|
+
/**
|
|
722
|
+
* Roll your projection back to `reorg.fork_point_height`, persisting
|
|
723
|
+
* `ctx.cursor` in the same transaction. Called once per *new* reorg
|
|
724
|
+
* (deduped in-memory, fork-ascending) before the SDK rewinds and re-reads the
|
|
725
|
+
* now-canonical events. Omit it to ignore reorgs (events stay canonical, but
|
|
726
|
+
* stale rows from an orphaned fork are left in place).
|
|
727
|
+
*/
|
|
728
|
+
onReorg?: (reorg: StreamsReorg, ctx: StreamsReorgContext) => Promise<void> | void
|
|
524
729
|
emptyBackoffMs?: number
|
|
525
730
|
maxPages?: number
|
|
526
731
|
maxEmptyPolls?: number
|
|
@@ -660,6 +865,8 @@ declare class Subscriptions extends BaseClient {
|
|
|
660
865
|
declare class SecondLayer extends BaseClient {
|
|
661
866
|
readonly streams: StreamsClient;
|
|
662
867
|
readonly index: Index;
|
|
868
|
+
readonly datasets: Datasets;
|
|
869
|
+
readonly contracts: Contracts;
|
|
663
870
|
readonly subgraphs: Subgraphs;
|
|
664
871
|
readonly subscriptions: Subscriptions;
|
|
665
872
|
constructor(options?: Partial<SecondLayerOptions>);
|