@secondlayer/sdk 9.0.2 → 10.1.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/AGENTS.md +85 -17
- package/README.md +98 -31
- package/dist/index.d.ts +234 -113
- package/dist/index.js +768 -436
- package/dist/index.js.map +19 -19
- package/dist/sinks/bun-sqlite.d.ts +18 -4
- package/dist/sinks/bun-sqlite.js +21 -20
- package/dist/sinks/bun-sqlite.js.map +5 -5
- package/dist/sinks/core.d.ts +30 -7
- package/dist/sinks/core.js +16 -19
- package/dist/sinks/core.js.map +4 -4
- package/dist/sinks/drizzle.d.ts +23 -6
- package/dist/sinks/drizzle.js +22 -21
- package/dist/sinks/drizzle.js.map +5 -5
- package/dist/sinks/kysely.d.ts +26 -11
- package/dist/sinks/kysely.js +23 -21
- package/dist/sinks/kysely.js.map +5 -5
- package/dist/sinks/testing.d.ts +4 -1
- package/dist/sinks/testing.js +14 -1
- package/dist/sinks/testing.js.map +3 -3
- package/dist/streams/index.d.ts +92 -23
- package/dist/streams/index.js +395 -183
- package/dist/streams/index.js.map +12 -12
- package/dist/subgraphs/index.d.ts +202 -94
- package/dist/subgraphs/index.js +764 -434
- package/dist/subgraphs/index.js.map +17 -17
- package/package.json +4 -4
|
@@ -16,20 +16,50 @@ interface SecondLayerOptions {
|
|
|
16
16
|
dumpsBaseUrl?: string;
|
|
17
17
|
/** Deploy origin label sent as `x-sl-origin` (telemetry). Defaults to `cli`. */
|
|
18
18
|
origin?: "cli" | "mcp" | "session";
|
|
19
|
+
/** Check the ed25519 signature on every Streams read. Omit for lenient
|
|
20
|
+
* (verify when signed, pass through unsigned self-host responses), `true`
|
|
21
|
+
* or `{ publicKey }` for strict, `false` for off. Reaches `sl.streams`. */
|
|
22
|
+
verify?: boolean | {
|
|
23
|
+
publicKey: string;
|
|
24
|
+
};
|
|
25
|
+
/** Check the dumps manifest signature before trusting any file hash
|
|
26
|
+
* (default on). Reaches `sl.streams.dumps`. */
|
|
27
|
+
verifyDumpsManifest?: boolean;
|
|
28
|
+
/** How long one request may take, headers and body, before it fails with a
|
|
29
|
+
* retryable `ApiError` (default 30 000 ms). A hung socket then trips the
|
|
30
|
+
* retry policy instead of stalling a walk or consume loop forever. `0`
|
|
31
|
+
* disables the timeout. */
|
|
32
|
+
requestTimeoutMs?: number;
|
|
19
33
|
}
|
|
34
|
+
/** Per-call options every `request*` method accepts. */
|
|
35
|
+
type RequestOptions = {
|
|
36
|
+
/** Cancels the in-flight request (and its body read). The rejection is the
|
|
37
|
+
* signal's reason, an `AbortError` by default, never an `ApiError`. */
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
};
|
|
20
40
|
declare abstract class BaseClient {
|
|
21
41
|
protected baseUrl: string;
|
|
22
42
|
protected apiKey?: string;
|
|
23
43
|
protected origin: "cli" | "mcp" | "session";
|
|
24
44
|
protected fetchImpl: FetchLike;
|
|
45
|
+
protected requestTimeoutMs: number;
|
|
25
46
|
constructor(options?: Partial<SecondLayerOptions>);
|
|
26
47
|
static authHeaders(apiKey?: string): Record<string, string>;
|
|
27
|
-
protected request<T>(method: string, path: string, body?: unknown): Promise<T>;
|
|
48
|
+
protected request<T>(method: string, path: string, body?: unknown, opts?: RequestOptions): Promise<T>;
|
|
28
49
|
/** Like `request`, but maps a 404 to `null` instead of throwing — the one
|
|
29
50
|
* place that owns the "absent resource" rule for `get*` accessors. */
|
|
30
|
-
protected requestOrNull<T>(method: string, path: string, body?: unknown): Promise<T | null>;
|
|
31
|
-
protected requestText(method: string, path: string, body?: unknown): Promise<string>;
|
|
32
|
-
|
|
51
|
+
protected requestOrNull<T>(method: string, path: string, body?: unknown, opts?: RequestOptions): Promise<T | null>;
|
|
52
|
+
protected requestText(method: string, path: string, body?: unknown, opts?: RequestOptions): Promise<string>;
|
|
53
|
+
/** Run one request under the caller's signal plus the per-request timeout.
|
|
54
|
+
* One combined signal covers the fetch and the body read, so a socket that
|
|
55
|
+
* stalls mid-body times out the same way one that never answers does. A
|
|
56
|
+
* timeout rejects with a retryable `ApiError`; a caller abort rejects with
|
|
57
|
+
* the signal's reason so loops can tell "stop" from "try again". */
|
|
58
|
+
private withRequestBudget;
|
|
59
|
+
/** Issue the HTTP request and map non-2xx statuses onto the error family.
|
|
60
|
+
* `signal` is the combined caller-plus-timeout signal from `request*`;
|
|
61
|
+
* subclasses that stream a body call this directly and read it themselves. */
|
|
62
|
+
protected fetchResponse(method: string, path: string, body?: unknown, signal?: AbortSignal): Promise<Response>;
|
|
33
63
|
}
|
|
34
64
|
interface SubgraphSource {
|
|
35
65
|
name: string;
|
|
@@ -92,8 +122,10 @@ declare class Subgraphs extends BaseClient {
|
|
|
92
122
|
markdown(name: string, options?: SubgraphSpecOptions): Promise<string>;
|
|
93
123
|
/**
|
|
94
124
|
* Reindex always drops and rebuilds the whole subgraph, so it takes no
|
|
95
|
-
* block range
|
|
96
|
-
* Use {@link backfill} to process a specific range.
|
|
125
|
+
* block range; the API rejects one with `REINDEX_RANGE_NOT_SUPPORTED`.
|
|
126
|
+
* Use {@link backfill} to process a specific range. While a reindex or
|
|
127
|
+
* backfill is already running the API answers 409 with code
|
|
128
|
+
* `OPERATION_IN_PROGRESS`; poll {@link operations} until it finishes.
|
|
97
129
|
*/
|
|
98
130
|
reindex(name: string): Promise<ReindexResponse>;
|
|
99
131
|
stop(name: string): Promise<{
|
|
@@ -101,6 +133,8 @@ declare class Subgraphs extends BaseClient {
|
|
|
101
133
|
operationId?: string;
|
|
102
134
|
status?: string;
|
|
103
135
|
}>;
|
|
136
|
+
/** Process one block range. 409 `OPERATION_IN_PROGRESS` while another
|
|
137
|
+
* reindex or backfill runs on this subgraph. */
|
|
104
138
|
backfill(name: string, options: {
|
|
105
139
|
fromBlock: number;
|
|
106
140
|
toBlock: number;
|
|
@@ -130,6 +164,9 @@ declare class Subgraphs extends BaseClient {
|
|
|
130
164
|
/** Status of a single operation (poll the `operationId` returned by
|
|
131
165
|
* reindex/backfill/stop until `status` is terminal). */
|
|
132
166
|
getOperation(name: string, operationId: string): Promise<SubgraphOperationStatus>;
|
|
167
|
+
/** Create or update a subgraph. A deploy that needs a rebuild queues one;
|
|
168
|
+
* if a reindex or backfill is already running the API answers 409 with
|
|
169
|
+
* code `OPERATION_IN_PROGRESS` (an `ApiError`, not a dedicated class). */
|
|
133
170
|
deploy(data: DeploySubgraphRequest): Promise<DeploySubgraphResponse>;
|
|
134
171
|
getSource(name: string): Promise<SubgraphSource>;
|
|
135
172
|
/**
|
|
@@ -160,6 +197,13 @@ declare class Subgraphs extends BaseClient {
|
|
|
160
197
|
name: string;
|
|
161
198
|
schema: Record<string, unknown>;
|
|
162
199
|
}>(def: T): InferSubgraphClient<T>;
|
|
200
|
+
/**
|
|
201
|
+
* `columns` is the table's declared column set from `defineSubgraph()`.
|
|
202
|
+
* Filters and orderBy always accept the canonical system names
|
|
203
|
+
* `_id` / `_blockHeight` / `_txId` / `_createdAt`; the unprefixed
|
|
204
|
+
* shorthands (`id`, `blockHeight`, ...) mean the system column only when
|
|
205
|
+
* the table declares no column of that name.
|
|
206
|
+
*/
|
|
163
207
|
private createTableClient;
|
|
164
208
|
}
|
|
165
209
|
import { InferSubgraphClient as InferSubgraphClient2 } from "@secondlayer/subgraphs";
|
|
@@ -367,8 +411,11 @@ interface ConsumerSink<Tx = unknown> {
|
|
|
367
411
|
* same `rewindCursor` (the lowest fork point) but its own
|
|
368
412
|
* `forkPointHeight` — scope the undo by `forkPointHeight` only (contract
|
|
369
413
|
* invariant #11), and expect re-application after a crash (#10).
|
|
414
|
+
*
|
|
415
|
+
* `rewindCursor` is `null` only for a fork at genesis: clear the
|
|
416
|
+
* checkpoint so the next run starts from the first event.
|
|
370
417
|
*/
|
|
371
|
-
rollback(forkPointHeight: number, rewindCursor: string): Promise<void>;
|
|
418
|
+
rollback(forkPointHeight: number, rewindCursor: string | null): Promise<void>;
|
|
372
419
|
}
|
|
373
420
|
/** `ctx` gains `tx` exactly when a sink is attached; without one the shape
|
|
374
421
|
* is unchanged (an intersection with `unknown` is an identity, so
|
|
@@ -516,11 +563,41 @@ type StreamsEventsSubscribeParams = {
|
|
|
516
563
|
filters?: StreamsFilterMap;
|
|
517
564
|
/** Abort to unsubscribe (the returned function does the same). */
|
|
518
565
|
signal?: AbortSignal;
|
|
519
|
-
/**
|
|
566
|
+
/**
|
|
567
|
+
* Called for each pushed event, in order. The resume cursor advances only
|
|
568
|
+
* after this resolves, so a handler that throws sees the same event again
|
|
569
|
+
* on reconnect (at-least-once). Key durable writes by `cursor`.
|
|
570
|
+
*/
|
|
520
571
|
onEvent: (event: StreamsEvent) => void | Promise<void>;
|
|
521
|
-
/**
|
|
522
|
-
*
|
|
572
|
+
/**
|
|
573
|
+
* Called on every failure. Transport errors (dropped socket, 5xx, 429, a
|
|
574
|
+
* stale connection, a throwing handler) reconnect from the last handled
|
|
575
|
+
* cursor with exponential backoff. Errors that a retry cannot fix (401,
|
|
576
|
+
* 4xx, a bad signature) end the subscription and reject its `done`.
|
|
577
|
+
*/
|
|
523
578
|
onError?: (err: unknown) => void;
|
|
579
|
+
/**
|
|
580
|
+
* First reconnect pause in ms (default 1000). Doubles per consecutive
|
|
581
|
+
* failure up to 30 s with jitter, resets once a frame arrives, and never
|
|
582
|
+
* undercuts a `Retry-After`.
|
|
583
|
+
*/
|
|
584
|
+
reconnectDelayMs?: number;
|
|
585
|
+
/**
|
|
586
|
+
* Reconnect when no frame (pings included) arrives for this long (default
|
|
587
|
+
* 60000, three server heartbeats). Catches a half-open socket that never
|
|
588
|
+
* errors; set it above your instance's heartbeat interval.
|
|
589
|
+
*/
|
|
590
|
+
staleAfterMs?: number;
|
|
591
|
+
};
|
|
592
|
+
/**
|
|
593
|
+
* Handle for a live subscription: call it to unsubscribe. `done` resolves
|
|
594
|
+
* after unsubscribe (or the signal aborting) and rejects with the error that
|
|
595
|
+
* ended the loop when a retry could not fix it, so a worker can `await`
|
|
596
|
+
* it instead of polling for silence.
|
|
597
|
+
*/
|
|
598
|
+
type StreamsSubscription = {
|
|
599
|
+
(): void;
|
|
600
|
+
done: Promise<void>;
|
|
524
601
|
};
|
|
525
602
|
/**
|
|
526
603
|
* The checkpoint the SDK computes for a batch. Persist `cursor` inside the same
|
|
@@ -585,8 +662,11 @@ type StreamsBatchContext = ConsumerBatchContext;
|
|
|
585
662
|
* The checkpoint for a reorg rollback. Persist `cursor` (the rewind position)
|
|
586
663
|
* inside the same transaction as your rollback so the two commit atomically.
|
|
587
664
|
*/
|
|
665
|
+
/** `cursor` is the rewind position the loop resumes from after `onReorg`:
|
|
666
|
+
* the foot of the fork point, or `null` for a fork at genesis. Persist it
|
|
667
|
+
* in the same transaction as the rollback. */
|
|
588
668
|
type StreamsReorgContext = {
|
|
589
|
-
cursor: string;
|
|
669
|
+
cursor: string | null;
|
|
590
670
|
};
|
|
591
671
|
type StreamsEventsConsumeParams<
|
|
592
672
|
TTx = never,
|
|
@@ -606,7 +686,8 @@ type StreamsEventsConsumeParams<
|
|
|
606
686
|
* the loop resumes from the sink's committed cursor, `onBatch` receives
|
|
607
687
|
* `ctx.tx` and must write ONLY through it (rows and cursor commit in one
|
|
608
688
|
* transaction), reorg rollback is automatic, and `onBatch`'s return value
|
|
609
|
-
* is ignored.
|
|
689
|
+
* is ignored. Folds (balances) invert in the sink's `onRollback`, not in
|
|
690
|
+
* `onReorg`.
|
|
610
691
|
*/
|
|
611
692
|
sink?: ConsumerSink<TTx>;
|
|
612
693
|
/** Fires once per page, before `onBatch` and before any early return. */
|
|
@@ -654,12 +735,23 @@ type StreamsEventsConsumeParams<
|
|
|
654
735
|
onBatch?: (events: D extends true ? IndexEvent[] : StreamsEvent[], envelope: StreamsEventsEnvelope, ctx: StreamsBatchContext & WithSinkTx<TTx>) => void | string | null | undefined | Promise<void> | Promise<string | null | undefined>;
|
|
655
736
|
/**
|
|
656
737
|
* Roll your projection back to `reorg.fork_point_height`, persisting
|
|
657
|
-
* `ctx.cursor` in the same transaction. Called once per *new* reorg
|
|
658
|
-
* (deduped in-memory, fork-ascending) before the SDK
|
|
659
|
-
* now-canonical events.
|
|
660
|
-
*
|
|
738
|
+
* `ctx.cursor` in the same transaction. Called once per *new* reorg at or
|
|
739
|
+
* below the checkpoint (deduped in-memory, fork-ascending) before the SDK
|
|
740
|
+
* rewinds and re-reads the now-canonical events. A reorg whose fork sits
|
|
741
|
+
* above the checkpoint is not a rollback (nothing past it was written) and
|
|
742
|
+
* is skipped. Omit it to ignore reorgs (events stay canonical, but stale
|
|
743
|
+
* rows from an orphaned fork are left in place).
|
|
744
|
+
*
|
|
745
|
+
* With `onReorg` or a `sink` attached, every empty page also polls
|
|
746
|
+
* `reorgs.list` (one extra request per idle poll) so a fork that lands
|
|
747
|
+
* while the consumer idles at the tip is rolled back too.
|
|
661
748
|
*/
|
|
662
749
|
onReorg?: (reorg: StreamsReorg, ctx: StreamsReorgContext) => Promise<void> | void;
|
|
750
|
+
/** Deepest rewind one reorg may make below the checkpoint before the loop
|
|
751
|
+
* refuses with `ValidationError`. Default 1000 blocks. The fork point is
|
|
752
|
+
* server supplied and drives a delete on every declared table, so raise
|
|
753
|
+
* this only for a source you trust. */
|
|
754
|
+
maxRollbackDepth?: number;
|
|
663
755
|
/** Page-fetch retries after the first failure (429/5xx/network only —
|
|
664
756
|
* 4xx and handler throws always propagate). Default 3; `0` disables. */
|
|
665
757
|
retryCount?: number;
|
|
@@ -722,8 +814,16 @@ type StreamsEventsReplayParams = {
|
|
|
722
814
|
* Called once per finalized dump file, in block order, before live tailing.
|
|
723
815
|
* Process the parquet with your own tooling (e.g. DuckDB) — the SDK does not
|
|
724
816
|
* decode parquet. Use `client.dumps.download(file)` to fetch + verify bytes.
|
|
817
|
+
*
|
|
818
|
+
* Delivery is file-granular and at-least-once: a file whose range straddles
|
|
819
|
+
* `from` is handed over whole. `ctx.from` is that cursor (`null` from
|
|
820
|
+
* genesis); skip rows at or below it, or key rows by `cursor` so a re-run
|
|
821
|
+
* is an idempotent no-op. Files ending at or below `from` are not handed
|
|
822
|
+
* over at all.
|
|
725
823
|
*/
|
|
726
|
-
onDumpFile: (file: StreamsDumpFile
|
|
824
|
+
onDumpFile: (file: StreamsDumpFile, ctx: {
|
|
825
|
+
from: string | null;
|
|
826
|
+
}) => Promise<void> | void;
|
|
727
827
|
/** Called per live page after the dump phase, like `consume`. */
|
|
728
828
|
onBatch: (events: StreamsEvent[], envelope: StreamsEventsEnvelope) => Promise<string | null | undefined> | string | null | undefined;
|
|
729
829
|
/**
|
|
@@ -858,9 +958,11 @@ type StreamsClient = {
|
|
|
858
958
|
* Subscribe to the real-time SSE push surface. Calls `onEvent` for each new
|
|
859
959
|
* canonical event as the server pushes it (chain cadence, not poll-bounded),
|
|
860
960
|
* and verifies each frame's inline ed25519 signature when the client was
|
|
861
|
-
* created with `verify`. Returns an unsubscribe function
|
|
961
|
+
* created with `verify`. Returns an unsubscribe function whose `done`
|
|
962
|
+
* settles when the loop ends. Not reorg-aware: an event delivered then
|
|
963
|
+
* orphaned is never retracted. Durable writers use `consume()`.
|
|
862
964
|
*/
|
|
863
|
-
subscribe(params: StreamsEventsSubscribeParams):
|
|
965
|
+
subscribe(params: StreamsEventsSubscribeParams): StreamsSubscription;
|
|
864
966
|
};
|
|
865
967
|
blocks: {
|
|
866
968
|
events(heightOrHash: number | string): Promise<StreamsEventsListEnvelope>;
|
|
@@ -931,7 +1033,8 @@ type IndexConsumeOptions<
|
|
|
931
1033
|
* the loop resumes from the sink's committed cursor, `onBatch` receives
|
|
932
1034
|
* `ctx.tx` and must write ONLY through it (rows and cursor commit in one
|
|
933
1035
|
* transaction — a throw aborts both), reorg rollback is automatic (no
|
|
934
|
-
* `onReorg` needed), and `onBatch`'s return value is ignored.
|
|
1036
|
+
* `onReorg` needed), and `onBatch`'s return value is ignored. Folds
|
|
1037
|
+
* (balances) invert in the sink's `onRollback`, not in `onReorg`.
|
|
935
1038
|
*/
|
|
936
1039
|
sink?: ConsumerSink<TTx>;
|
|
937
1040
|
/** Fires once per page, before `onBatch` and before any early return —
|
|
@@ -939,9 +1042,18 @@ type IndexConsumeOptions<
|
|
|
939
1042
|
* `consumerHealth().record`. */
|
|
940
1043
|
onProgress?: (ctx: ConsumerBatchContext) => void;
|
|
941
1044
|
onBatch: (items: TItem[], envelope: TEnvelope, ctx: ConsumerBatchContext & WithSinkTx<TTx>) => void | string | null | undefined | Promise<void> | Promise<string | null | undefined>;
|
|
1045
|
+
/** Called once per new reorg at or below the checkpoint, before the loop
|
|
1046
|
+
* rewinds to `ctx.cursor` (`null` = pre-genesis) and re-reads. A reorg
|
|
1047
|
+
* whose fork sits ABOVE the checkpoint is not a rollback: nothing past
|
|
1048
|
+
* it was written, so it is noted and the page is read as normal. */
|
|
942
1049
|
onReorg?: (reorg: IndexReorg, ctx: {
|
|
943
|
-
cursor: string;
|
|
1050
|
+
cursor: string | null;
|
|
944
1051
|
}) => Promise<void> | void;
|
|
1052
|
+
/** Deepest rewind one reorg may make below the checkpoint before the loop
|
|
1053
|
+
* refuses with `ValidationError`. Default 1000 blocks. The fork point is
|
|
1054
|
+
* server supplied and drives a delete on every declared table, so raise
|
|
1055
|
+
* this only for a source you trust. */
|
|
1056
|
+
maxRollbackDepth?: number;
|
|
945
1057
|
sleep?: Sleep;
|
|
946
1058
|
emptyBackoffMs?: number;
|
|
947
1059
|
maxPages?: number;
|
|
@@ -1037,10 +1149,20 @@ type FtTransfersListParams = {
|
|
|
1037
1149
|
fromHeight?: number;
|
|
1038
1150
|
toHeight?: number;
|
|
1039
1151
|
};
|
|
1040
|
-
|
|
1152
|
+
/** Options every `walk*` feed shares on top of its list filters. Page fetches
|
|
1153
|
+
* retry with the same `retryCount`/`retryDelay`/`onError` vocabulary as
|
|
1154
|
+
* `consume()`; the tradeoff is that a walk can pause for the retry delays
|
|
1155
|
+
* instead of failing fast on the first 429. */
|
|
1156
|
+
type WalkOptions = PageRetryOptions & {
|
|
1157
|
+
/** Rows per page request. Default 200, max `INDEX_MAX_PAGE_SIZE` (1000). */
|
|
1041
1158
|
batchSize?: number;
|
|
1159
|
+
/** Stops the walk. The iterator always rejects with the signal's reason (an
|
|
1160
|
+
* `AbortError` by default), whether the abort lands during a page request
|
|
1161
|
+
* (which is cancelled) or between yields, so a caller can tell a finished
|
|
1162
|
+
* walk from a stopped one. */
|
|
1042
1163
|
signal?: AbortSignal;
|
|
1043
1164
|
};
|
|
1165
|
+
type FtTransfersWalkParams = Omit<FtTransfersListParams, "limit"> & WalkOptions;
|
|
1044
1166
|
type NftTransfer = {
|
|
1045
1167
|
cursor: string;
|
|
1046
1168
|
block_height: number;
|
|
@@ -1078,10 +1200,7 @@ type NftTransfersListParams = {
|
|
|
1078
1200
|
fromHeight?: number;
|
|
1079
1201
|
toHeight?: number;
|
|
1080
1202
|
};
|
|
1081
|
-
type NftTransfersWalkParams = Omit<NftTransfersListParams, "limit"> &
|
|
1082
|
-
batchSize?: number;
|
|
1083
|
-
signal?: AbortSignal;
|
|
1084
|
-
};
|
|
1203
|
+
type NftTransfersWalkParams = Omit<NftTransfersListParams, "limit"> & WalkOptions;
|
|
1085
1204
|
type IndexEventBase = {
|
|
1086
1205
|
cursor: string;
|
|
1087
1206
|
block_height: number;
|
|
@@ -1236,10 +1355,7 @@ type EventsListParams<T extends IndexEventType = IndexEventType> = {
|
|
|
1236
1355
|
*/
|
|
1237
1356
|
fields?: readonly (keyof IndexEventOf<T> & string)[];
|
|
1238
1357
|
};
|
|
1239
|
-
type EventsWalkParams<T extends IndexEventType = IndexEventType> = Omit<EventsListParams<T>, "limit"> &
|
|
1240
|
-
batchSize?: number;
|
|
1241
|
-
signal?: AbortSignal;
|
|
1242
|
-
};
|
|
1358
|
+
type EventsWalkParams<T extends IndexEventType = IndexEventType> = Omit<EventsListParams<T>, "limit"> & WalkOptions;
|
|
1243
1359
|
type EventsConsumeParams<
|
|
1244
1360
|
T extends IndexEventType = IndexEventType,
|
|
1245
1361
|
TTx = never
|
|
@@ -1279,10 +1395,7 @@ type ContractCallsListParams = {
|
|
|
1279
1395
|
* Mutually exclusive with contractId. */
|
|
1280
1396
|
trait?: string;
|
|
1281
1397
|
};
|
|
1282
|
-
type ContractCallsWalkParams = Omit<ContractCallsListParams, "limit"> &
|
|
1283
|
-
batchSize?: number;
|
|
1284
|
-
signal?: AbortSignal;
|
|
1285
|
-
};
|
|
1398
|
+
type ContractCallsWalkParams = Omit<ContractCallsListParams, "limit"> & WalkOptions;
|
|
1286
1399
|
type ContractCallsConsumeParams<TTx = never> = Omit<ContractCallsListParams, "cursor" | "fromCursor" | "limit"> & IndexConsumeOptions<IndexContractCall, ContractCallsEnvelope, TTx>;
|
|
1287
1400
|
/** One canonical block in the sync map. Lean by design — block + parent hash
|
|
1288
1401
|
* for chain linkage, burn anchor for Bitcoin confirmations. Use `blocks` for
|
|
@@ -1307,10 +1420,7 @@ type CanonicalListParams = {
|
|
|
1307
1420
|
fromHeight?: number;
|
|
1308
1421
|
toHeight?: number;
|
|
1309
1422
|
};
|
|
1310
|
-
type CanonicalWalkParams = Omit<CanonicalListParams, "limit"> &
|
|
1311
|
-
batchSize?: number;
|
|
1312
|
-
signal?: AbortSignal;
|
|
1313
|
-
};
|
|
1423
|
+
type CanonicalWalkParams = Omit<CanonicalListParams, "limit"> & WalkOptions;
|
|
1314
1424
|
/** A block resource. Metadata is intentionally thin — only chain-linkage and
|
|
1315
1425
|
* burn-anchor fields are persisted (no miner / tx_count / signer). */
|
|
1316
1426
|
type IndexBlock = {
|
|
@@ -1339,10 +1449,7 @@ type BlocksListParams = {
|
|
|
1339
1449
|
fromHeight?: number;
|
|
1340
1450
|
toHeight?: number;
|
|
1341
1451
|
};
|
|
1342
|
-
type BlocksWalkParams = Omit<BlocksListParams, "limit"> &
|
|
1343
|
-
batchSize?: number;
|
|
1344
|
-
signal?: AbortSignal;
|
|
1345
|
-
};
|
|
1452
|
+
type BlocksWalkParams = Omit<BlocksListParams, "limit"> & WalkOptions;
|
|
1346
1453
|
type IndexPostCondition = {
|
|
1347
1454
|
type: "stx";
|
|
1348
1455
|
principal: string;
|
|
@@ -1448,10 +1555,7 @@ type TransactionsListParams = {
|
|
|
1448
1555
|
fromHeight?: number;
|
|
1449
1556
|
toHeight?: number;
|
|
1450
1557
|
};
|
|
1451
|
-
type TransactionsWalkParams = Omit<TransactionsListParams, "limit"> &
|
|
1452
|
-
batchSize?: number;
|
|
1453
|
-
signal?: AbortSignal;
|
|
1454
|
-
};
|
|
1558
|
+
type TransactionsWalkParams = Omit<TransactionsListParams, "limit"> & WalkOptions;
|
|
1455
1559
|
/** A decoded PoX-4 stacking action (one per stacking contract call). */
|
|
1456
1560
|
type IndexStackingAction = {
|
|
1457
1561
|
cursor: string;
|
|
@@ -1495,10 +1599,7 @@ type StackingListParams = {
|
|
|
1495
1599
|
fromHeight?: number;
|
|
1496
1600
|
toHeight?: number;
|
|
1497
1601
|
};
|
|
1498
|
-
type StackingWalkParams = Omit<StackingListParams, "limit"> &
|
|
1499
|
-
batchSize?: number;
|
|
1500
|
-
signal?: AbortSignal;
|
|
1501
|
-
};
|
|
1602
|
+
type StackingWalkParams = Omit<StackingListParams, "limit"> & WalkOptions;
|
|
1502
1603
|
/** A pending (unconfirmed) transaction. Like a transaction document but
|
|
1503
1604
|
* pre-chain — no block_height/tx_index/result/events — with `received_at` and
|
|
1504
1605
|
* a sequence cursor instead of a block position. */
|
|
@@ -1554,10 +1655,7 @@ type MempoolListParams = {
|
|
|
1554
1655
|
/** Filter to pending calls to a single function (composes with `contractId`). */
|
|
1555
1656
|
functionName?: string;
|
|
1556
1657
|
};
|
|
1557
|
-
type MempoolWalkParams = Omit<MempoolListParams, "limit"> &
|
|
1558
|
-
batchSize?: number;
|
|
1559
|
-
signal?: AbortSignal;
|
|
1560
|
-
};
|
|
1658
|
+
type MempoolWalkParams = Omit<MempoolListParams, "limit"> & WalkOptions;
|
|
1561
1659
|
/**
|
|
1562
1660
|
* Empirical per-topic print payload schema for a contract, inferred from
|
|
1563
1661
|
* sampled on-chain events. `topics` is sorted by count desc; `sampled` is true
|
|
@@ -1749,10 +1847,7 @@ type SbtcDepositsListParams = {
|
|
|
1749
1847
|
type SbtcDepositAlwaysFields = "cursor" | "block_height";
|
|
1750
1848
|
/** A deposit row narrowed to the requested columns plus the always-present ones. */
|
|
1751
1849
|
type SbtcDepositFields<F extends keyof IndexSbtcDeposit & string> = Pick<IndexSbtcDeposit, (F | SbtcDepositAlwaysFields) & keyof IndexSbtcDeposit>;
|
|
1752
|
-
type SbtcDepositsWalkParams = Omit<SbtcDepositsListParams, "limit"> &
|
|
1753
|
-
batchSize?: number;
|
|
1754
|
-
signal?: AbortSignal;
|
|
1755
|
-
};
|
|
1850
|
+
type SbtcDepositsWalkParams = Omit<SbtcDepositsListParams, "limit"> & WalkOptions;
|
|
1756
1851
|
/** SbtcWithdrawal columns that survive any projection. */
|
|
1757
1852
|
type SbtcWithdrawalAlwaysFields = "cursor" | "request_id";
|
|
1758
1853
|
/** A SbtcWithdrawal row narrowed to the requested columns plus the always-present ones. */
|
|
@@ -1777,10 +1872,7 @@ type SbtcWithdrawalsListParams = {
|
|
|
1777
1872
|
fromHeight?: number;
|
|
1778
1873
|
toHeight?: number;
|
|
1779
1874
|
};
|
|
1780
|
-
type SbtcWithdrawalsWalkParams = Omit<SbtcWithdrawalsListParams, "limit"> &
|
|
1781
|
-
batchSize?: number;
|
|
1782
|
-
signal?: AbortSignal;
|
|
1783
|
-
};
|
|
1875
|
+
type SbtcWithdrawalsWalkParams = Omit<SbtcWithdrawalsListParams, "limit"> & WalkOptions;
|
|
1784
1876
|
type SbtcEventsListParams = {
|
|
1785
1877
|
cursor?: string | null;
|
|
1786
1878
|
fromCursor?: string | null;
|
|
@@ -1793,10 +1885,7 @@ type SbtcEventsListParams = {
|
|
|
1793
1885
|
fromHeight?: number;
|
|
1794
1886
|
toHeight?: number;
|
|
1795
1887
|
};
|
|
1796
|
-
type SbtcEventsWalkParams = Omit<SbtcEventsListParams, "limit"> &
|
|
1797
|
-
batchSize?: number;
|
|
1798
|
-
signal?: AbortSignal;
|
|
1799
|
-
};
|
|
1888
|
+
type SbtcEventsWalkParams = Omit<SbtcEventsListParams, "limit"> & WalkOptions;
|
|
1800
1889
|
type SbtcEventsConsumeParams<TTx = never> = Omit<SbtcEventsListParams, "cursor" | "fromCursor" | "limit"> & IndexConsumeOptions<IndexSbtcEvent, SbtcEventsEnvelope, TTx>;
|
|
1801
1890
|
type SbtcDepositsConsumeParams<TTx = never> = Omit<SbtcDepositsListParams, "cursor" | "fromCursor" | "limit" | "fields"> & IndexConsumeOptions<IndexSbtcDeposit, SbtcDepositsEnvelope, TTx>;
|
|
1802
1891
|
/** `index.sbtc` — the decoded sBTC peg surface (deposits, withdrawals, raw
|
|
@@ -1887,10 +1976,7 @@ type PoxCyclesListParams = {
|
|
|
1887
1976
|
cursor?: number | null;
|
|
1888
1977
|
limit?: number;
|
|
1889
1978
|
};
|
|
1890
|
-
type PoxCyclesWalkParams = Omit<PoxCyclesListParams, "limit"> &
|
|
1891
|
-
batchSize?: number;
|
|
1892
|
-
signal?: AbortSignal;
|
|
1893
|
-
};
|
|
1979
|
+
type PoxCyclesWalkParams = Omit<PoxCyclesListParams, "limit"> & WalkOptions;
|
|
1894
1980
|
/** `index.pox` — PoX reward-cycle aggregates. */
|
|
1895
1981
|
interface PoxResource {
|
|
1896
1982
|
cycles: {
|
|
@@ -1965,10 +2051,7 @@ type Pox5EventsListParams = {
|
|
|
1965
2051
|
fromHeight?: number;
|
|
1966
2052
|
toHeight?: number;
|
|
1967
2053
|
};
|
|
1968
|
-
type Pox5EventsWalkParams = Omit<Pox5EventsListParams, "limit"> &
|
|
1969
|
-
batchSize?: number;
|
|
1970
|
-
signal?: AbortSignal;
|
|
1971
|
-
};
|
|
2054
|
+
type Pox5EventsWalkParams = Omit<Pox5EventsListParams, "limit"> & WalkOptions;
|
|
1972
2055
|
/** `index.pox5` — decoded PoX-5 print events, the staking primitive from the
|
|
1973
2056
|
* epoch 4.0 hard fork onward (PoX-4's `index.stacking` stream ends there). */
|
|
1974
2057
|
interface Pox5Resource {
|
|
@@ -2173,9 +2256,13 @@ declare class Index extends BaseClient {
|
|
|
2173
2256
|
private listNftTransfers;
|
|
2174
2257
|
/** Shared keyset-pagination loop for every `walk*` feed: seed the cursor from
|
|
2175
2258
|
* `cursor`/`fromCursor` (and `fromHeight` 0 on the first page), then page until
|
|
2176
|
-
* the
|
|
2177
|
-
*
|
|
2178
|
-
*
|
|
2259
|
+
* the server stops advancing the cursor (`next_cursor` null or unchanged). A
|
|
2260
|
+
* short page is not a tail signal: the server clamps oversized limits without
|
|
2261
|
+
* saying so, so trusting page length truncated backfills. The cost is one
|
|
2262
|
+
* extra empty fetch at the end of feeds that never return a null cursor.
|
|
2263
|
+
* `list` merges the resource's filter params; `itemsOf` selects the envelope's
|
|
2264
|
+
* item array. Each page fetch retries under `fetchPageWithRetry`; the cursor
|
|
2265
|
+
* is a string keyset for every feed except PoX cycles, which use a number. */
|
|
2179
2266
|
private keysetWalk;
|
|
2180
2267
|
private walkFtTransfers;
|
|
2181
2268
|
private walkNftTransfers;
|
|
@@ -2262,22 +2349,43 @@ interface ActiveSubgraphOperation {
|
|
|
2262
2349
|
status: SubgraphOperationStatus["status"];
|
|
2263
2350
|
progress: number | null;
|
|
2264
2351
|
}
|
|
2352
|
+
/** Why one snapshot field could not be read. Serialized from the SDK error
|
|
2353
|
+
* family so a snapshot stays plain data. */
|
|
2354
|
+
interface ContextFieldError {
|
|
2355
|
+
message: string;
|
|
2356
|
+
/** Stable code from the API envelope (`UNAUTHORIZED`, `INDEX_NOT_READY`)
|
|
2357
|
+
* or the SDK (`REQUEST_TIMEOUT`); absent for a bare transport failure. */
|
|
2358
|
+
code?: string;
|
|
2359
|
+
/** HTTP status; `0` when the API could not be reached. */
|
|
2360
|
+
status?: number;
|
|
2361
|
+
/** Whether the same read can succeed on a retry (429, 5xx, network). */
|
|
2362
|
+
retryable: boolean;
|
|
2363
|
+
}
|
|
2364
|
+
/** One snapshot field: the value, or `null` plus the error that produced it.
|
|
2365
|
+
* `value: null` with no `error` means the read succeeded and found nothing. */
|
|
2366
|
+
interface ContextField<T> {
|
|
2367
|
+
value: T | null;
|
|
2368
|
+
error?: ContextFieldError;
|
|
2369
|
+
}
|
|
2265
2370
|
/**
|
|
2266
|
-
* A point-in-time orientation snapshot for an agent:
|
|
2267
|
-
*
|
|
2268
|
-
*
|
|
2371
|
+
* A point-in-time orientation snapshot for an agent: the live tips and what
|
|
2372
|
+
* this instance holds. Every field is a {@link ContextField}, so a missing
|
|
2373
|
+
* value says why it is missing (API unreachable, token rejected, index still
|
|
2374
|
+
* catching up) instead of a bare `null`. `context()` itself never throws.
|
|
2269
2375
|
*/
|
|
2270
2376
|
interface ContextSnapshot {
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2377
|
+
/** Token identity from `/api/accounts/me`. A self-hosted instance has no
|
|
2378
|
+
* account system: the read 404s and the field carries that error. */
|
|
2379
|
+
account: ContextField<ContextAccount>;
|
|
2380
|
+
streamsTip: ContextField<StreamsTip>;
|
|
2381
|
+
indexTip: ContextField<IndexTip>;
|
|
2382
|
+
subgraphs: ContextField<SubgraphSummary2[]>;
|
|
2383
|
+
subscriptions: ContextField<{
|
|
2276
2384
|
count: number;
|
|
2277
2385
|
byStatus: Record<string, number>;
|
|
2278
|
-
}
|
|
2386
|
+
}>;
|
|
2279
2387
|
/** In-flight reindex operations (bounded to subgraphs reporting `reindexing`). */
|
|
2280
|
-
activeOperations: ActiveSubgraphOperation[]
|
|
2388
|
+
activeOperations: ContextField<ActiveSubgraphOperation[]>;
|
|
2281
2389
|
}
|
|
2282
2390
|
declare class SecondLayer extends BaseClient {
|
|
2283
2391
|
readonly streams: StreamsClient;
|
|
@@ -2287,14 +2395,8 @@ declare class SecondLayer extends BaseClient {
|
|
|
2287
2395
|
readonly subscriptions: Subscriptions;
|
|
2288
2396
|
constructor(options?: Partial<SecondLayerOptions>);
|
|
2289
2397
|
/**
|
|
2290
|
-
* Assemble a {@link ContextSnapshot} — the same orientation an MCP agent reads
|
|
2291
|
-
* from `secondlayer://context`, but available to any SDK/CLI consumer. Reads
|
|
2292
|
-
* run concurrently and degrade to `null` per field on failure.
|
|
2293
|
-
*/
|
|
2294
|
-
/**
|
|
2295
2398
|
* Up to 10 public reads in one round trip (`POST /v1/batch`). Each item
|
|
2296
|
-
*
|
|
2297
|
-
* PAYMENT-BALANCE/SESSION) apply to every item.
|
|
2399
|
+
* is authorized on its own; the client's bearer token applies to every item.
|
|
2298
2400
|
*/
|
|
2299
2401
|
batch(requests: Array<{
|
|
2300
2402
|
path: string;
|
|
@@ -2306,6 +2408,12 @@ declare class SecondLayer extends BaseClient {
|
|
|
2306
2408
|
body: unknown;
|
|
2307
2409
|
}>;
|
|
2308
2410
|
}>;
|
|
2411
|
+
/**
|
|
2412
|
+
* Assemble a {@link ContextSnapshot}: the same orientation an MCP agent
|
|
2413
|
+
* reads from `secondlayer://context`, available to any SDK/CLI consumer.
|
|
2414
|
+
* Reads run concurrently; a failed read lands as `{ value: null, error }`
|
|
2415
|
+
* on its field rather than rejecting the whole snapshot.
|
|
2416
|
+
*/
|
|
2309
2417
|
context(): Promise<ContextSnapshot>;
|
|
2310
2418
|
}
|
|
2311
2419
|
/**
|