@secondlayer/sdk 6.23.0 → 6.24.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/README.md +26 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.js +11 -2
- package/dist/index.js.map +5 -5
- package/dist/streams/index.d.ts +7 -0
- package/dist/streams/index.js +11 -2
- package/dist/streams/index.js.map +5 -5
- package/dist/subgraphs/index.d.ts +7 -0
- package/dist/subgraphs/index.js +11 -2
- package/dist/subgraphs/index.js.map +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,7 +40,8 @@ Everything is indexing — the question is how much of the indexer you run:
|
|
|
40
40
|
|
|
41
41
|
- `sl.index` — decoded rows we keep indexed: query FT/NFT transfers, all event
|
|
42
42
|
types (`events`), and `contractCalls` — or build your own app index on them
|
|
43
|
-
with `
|
|
43
|
+
with the checkpointed `consume()` loop (automatic reorg rewind), `walk()`
|
|
44
|
+
sweeps, and resumable cursors on every page.
|
|
44
45
|
- `sl.subgraphs` — deploy your own indexer (one `defineSubgraph()` file via the
|
|
45
46
|
CLI), then read your hosted tables here. We run the loop.
|
|
46
47
|
- `sl.streams` — the raw ordered event firehose Index itself is built on, with
|
|
@@ -251,6 +252,30 @@ for await (const transfer of sl.index.ftTransfers.walk({
|
|
|
251
252
|
}
|
|
252
253
|
```
|
|
253
254
|
|
|
255
|
+
Checkpointed consumer — build your app index.
|
|
256
|
+
|
|
257
|
+
`index.events.consume` / `index.contractCalls.consume` is the same contract as
|
|
258
|
+
the Streams consumer: write your rows inside `onBatch`, return the cursor you
|
|
259
|
+
committed, and reorgs rewind automatically to the fork point. `finalizedOnly`
|
|
260
|
+
holds delivery to rows at or below `tip.finalized_height` (Index rows carry no
|
|
261
|
+
per-event flag). Full runnable example: `examples/sales-index/`.
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
await sl.index.contractCalls.consume({
|
|
265
|
+
contractId: "SP...marketplace-v4",
|
|
266
|
+
functionName: "purchase-asset",
|
|
267
|
+
fromCursor: await loadCheckpoint(), // null on first run
|
|
268
|
+
fromHeight: 0, // first run: backfill from genesis
|
|
269
|
+
onBatch: async (calls, envelope, ctx) => {
|
|
270
|
+
await commitRowsAndCheckpoint(calls, ctx.cursor);
|
|
271
|
+
return ctx.cursor;
|
|
272
|
+
},
|
|
273
|
+
onReorg: async (reorg) => {
|
|
274
|
+
await rollbackAboveHeight(reorg.fork_point_height);
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
```
|
|
278
|
+
|
|
254
279
|
## Transaction-inclusion proofs
|
|
255
280
|
|
|
256
281
|
Verify — **without trusting Secondlayer** — that a transaction is included in a
|
package/dist/index.d.ts
CHANGED
|
@@ -649,6 +649,13 @@ type StreamsEventsReplayParams = {
|
|
|
649
649
|
onDumpFile: (file: StreamsDumpFile) => Promise<void> | void
|
|
650
650
|
/** Called per live page after the dump phase, like `consume`. */
|
|
651
651
|
onBatch: (events: StreamsEvent[], envelope: StreamsEventsEnvelope) => Promise<string | null | undefined> | string | null | undefined
|
|
652
|
+
/**
|
|
653
|
+
* Called when the live-tail phase (after the dump backfill) crosses a reorg,
|
|
654
|
+
* before the cursor rewinds and re-reads the now-canonical events — same
|
|
655
|
+
* contract as `consume`. The dump-backfill phase is finalized and never
|
|
656
|
+
* reorgs; omit this to leave stale rows from an orphaned fork in place.
|
|
657
|
+
*/
|
|
658
|
+
onReorg?: (reorg: StreamsReorg, ctx: StreamsReorgContext) => Promise<void> | void
|
|
652
659
|
mode?: "tail" | "bounded"
|
|
653
660
|
batchSize?: number
|
|
654
661
|
emptyBackoffMs?: number
|
package/dist/index.js
CHANGED
|
@@ -1221,7 +1221,15 @@ function createStreamsDumps(opts) {
|
|
|
1221
1221
|
return baseUrl;
|
|
1222
1222
|
}
|
|
1223
1223
|
function fileUrl(file) {
|
|
1224
|
-
|
|
1224
|
+
const base = requireBaseUrl();
|
|
1225
|
+
const path = file.path.replace(/^\/+/, "");
|
|
1226
|
+
try {
|
|
1227
|
+
const basePath = new URL(base).pathname.replace(/^\/+|\/+$/g, "");
|
|
1228
|
+
if (basePath && path.startsWith(`${basePath}/`)) {
|
|
1229
|
+
return `${base}/${path.slice(basePath.length + 1)}`;
|
|
1230
|
+
}
|
|
1231
|
+
} catch {}
|
|
1232
|
+
return `${base}/${path}`;
|
|
1225
1233
|
}
|
|
1226
1234
|
async function list() {
|
|
1227
1235
|
const url = `${requireBaseUrl()}/manifest/latest.json`;
|
|
@@ -1629,6 +1637,7 @@ function createStreamsClient(options) {
|
|
|
1629
1637
|
batchSize: params.batchSize ?? 100,
|
|
1630
1638
|
fetchEvents,
|
|
1631
1639
|
onBatch: params.onBatch,
|
|
1640
|
+
onReorg: params.onReorg,
|
|
1632
1641
|
emptyBackoffMs: params.emptyBackoffMs,
|
|
1633
1642
|
maxPages: params.maxPages,
|
|
1634
1643
|
maxEmptyPolls: params.maxEmptyPolls,
|
|
@@ -2493,5 +2502,5 @@ export {
|
|
|
2493
2502
|
ApiError
|
|
2494
2503
|
};
|
|
2495
2504
|
|
|
2496
|
-
//# debugId=
|
|
2505
|
+
//# debugId=3115754A9CBB338064756E2164756E21
|
|
2497
2506
|
//# sourceMappingURL=index.js.map
|