@secondlayer/sdk 15.5.1 → 16.0.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 +1 -1
- package/README.md +6 -6
- package/dist/index.d.ts +7 -16
- package/dist/index.js +8 -56
- package/dist/index.js.map +8 -9
- package/dist/sinks/bun-sqlite.d.ts +1 -1
- package/dist/sinks/bun-sqlite.js.map +1 -1
- package/dist/sinks/drizzle.d.ts +1 -1
- package/dist/sinks/drizzle.js.map +1 -1
- package/dist/sinks/kysely.d.ts +1 -1
- package/dist/sinks/kysely.js.map +1 -1
- package/dist/streams/index.d.ts +6 -13
- package/dist/streams/index.js +6 -55
- package/dist/streams/index.js.map +6 -7
- package/dist/subgraphs/index.d.ts +6 -12
- package/dist/subgraphs/index.js +8 -8
- package/dist/subgraphs/index.js.map +6 -6
- package/package.json +3 -3
|
@@ -1076,10 +1076,7 @@ type ConsumerBatchContext<
|
|
|
1076
1076
|
blocksBehind: number | null;
|
|
1077
1077
|
/**
|
|
1078
1078
|
* The full tip for this page — `StreamsTip` or `IndexTip` depending on the
|
|
1079
|
-
* surface.
|
|
1080
|
-
* which is the only way to reach it today and is also how the worst
|
|
1081
|
-
* `finalizedOnly` mistake becomes reachable (`return envelope.next_cursor`
|
|
1082
|
-
* jumps the cursor past events that were filtered out and never delivered).
|
|
1079
|
+
* surface.
|
|
1083
1080
|
*/
|
|
1084
1081
|
tip: TTip;
|
|
1085
1082
|
/**
|
|
@@ -1088,9 +1085,6 @@ type ConsumerBatchContext<
|
|
|
1088
1085
|
*/
|
|
1089
1086
|
reorgs: readonly TReorg[];
|
|
1090
1087
|
};
|
|
1091
|
-
/** @deprecated Use {@link ConsumerBatchContext} — the Index and Streams loops
|
|
1092
|
-
* share one shape now. Kept as an alias so existing annotations compile. */
|
|
1093
|
-
type StreamsBatchContext = ConsumerBatchContext;
|
|
1094
1088
|
/**
|
|
1095
1089
|
* The checkpoint for a reorg rollback. Persist `cursor` (the rewind position)
|
|
1096
1090
|
* inside the same transaction as your rollback so the two commit atomically.
|
|
@@ -1160,7 +1154,7 @@ type StreamsEventsConsumeParams<
|
|
|
1160
1154
|
* labels do not interleave within a page — add `onBatch` when you need
|
|
1161
1155
|
* strict global order across labels.
|
|
1162
1156
|
*/
|
|
1163
|
-
on?: { [K in keyof F] : (events: StreamsEventForFilter<F[K], D>[], ctx:
|
|
1157
|
+
on?: { [K in keyof F] : (events: StreamsEventForFilter<F[K], D>[], ctx: ConsumerBatchContext<StreamsTip, StreamsReorg> & WithSinkTx<TTx>) => void | Promise<void> };
|
|
1164
1158
|
batchSize?: number;
|
|
1165
1159
|
/**
|
|
1166
1160
|
* Apply a page of canonical events. Persist `ctx.cursor` in the same
|
|
@@ -1170,7 +1164,7 @@ type StreamsEventsConsumeParams<
|
|
|
1170
1164
|
* Optional only when `on` handles the page instead; a consume call with
|
|
1171
1165
|
* neither throws.
|
|
1172
1166
|
*/
|
|
1173
|
-
onBatch?: (events: D extends true ? IndexEvent[] : StreamsEvent[],
|
|
1167
|
+
onBatch?: (events: D extends true ? IndexEvent[] : StreamsEvent[], ctx: ConsumerBatchContext<StreamsTip, StreamsReorg> & WithSinkTx<TTx>) => void | string | null | undefined | Promise<void> | Promise<string | null | undefined>;
|
|
1174
1168
|
/**
|
|
1175
1169
|
* Roll your projection back to `reorg.fork_point_height`, persisting
|
|
1176
1170
|
* `ctx.cursor` in the same transaction. Called once per *new* reorg at or
|
|
@@ -1242,7 +1236,7 @@ type StreamsEventsConsumeBitcoinParams<TTx = never> = {
|
|
|
1242
1236
|
/** A mainnet address. */
|
|
1243
1237
|
address?: string;
|
|
1244
1238
|
batchSize?: number;
|
|
1245
|
-
onBatch: (events: RuneStreamsEvent[],
|
|
1239
|
+
onBatch: (events: RuneStreamsEvent[], ctx: ConsumerBatchContext<StreamsBitcoinTip, StreamsReorg> & WithSinkTx<TTx>) => void | string | null | undefined | Promise<void> | Promise<string | null | undefined>;
|
|
1246
1240
|
onReorg?: (reorg: StreamsReorg, ctx: StreamsReorgContext) => Promise<void> | void;
|
|
1247
1241
|
maxRollbackDepth?: number;
|
|
1248
1242
|
retryCount?: number;
|
|
@@ -1341,7 +1335,7 @@ type StreamsEventsReplayParams = {
|
|
|
1341
1335
|
from: string | null;
|
|
1342
1336
|
}) => Promise<void> | void;
|
|
1343
1337
|
/** Called per live page after the dump phase, like `consume`. */
|
|
1344
|
-
onBatch: (events: StreamsEvent[],
|
|
1338
|
+
onBatch: (events: StreamsEvent[], ctx: ConsumerBatchContext<StreamsTip, StreamsReorg>) => Promise<string | null | undefined> | string | null | undefined;
|
|
1345
1339
|
/**
|
|
1346
1340
|
* Called when the live-tail phase (after the dump backfill) crosses a reorg,
|
|
1347
1341
|
* before the cursor rewinds and re-reads the now-canonical events — same
|
|
@@ -1655,7 +1649,7 @@ type IndexConsumeOptions<
|
|
|
1655
1649
|
* an empty page still proves the loop is alive. Feed it to
|
|
1656
1650
|
* `consumerHealth().record`. */
|
|
1657
1651
|
onProgress?: (ctx: ConsumerBatchContext) => void;
|
|
1658
|
-
onBatch: (items: TItem[],
|
|
1652
|
+
onBatch: (items: TItem[], ctx: ConsumerBatchContext<TEnvelope["tip"], TEnvelope["reorgs"][number]> & WithSinkTx<TTx>) => void | string | null | undefined | Promise<void> | Promise<string | null | undefined>;
|
|
1659
1653
|
/** Called once per new reorg at or below the checkpoint, before the loop
|
|
1660
1654
|
* rewinds to `ctx.cursor` (`null` = pre-genesis) and re-reads. A reorg
|
|
1661
1655
|
* whose fork sits ABOVE the checkpoint is not a rollback: nothing past
|
package/dist/subgraphs/index.js
CHANGED
|
@@ -945,7 +945,7 @@ function stripSlash(url) {
|
|
|
945
945
|
return url.replace(/\/+$/, "");
|
|
946
946
|
}
|
|
947
947
|
function createArchiveClient(options = {}) {
|
|
948
|
-
const accountKey = resolveAccountKey(options.accountKey
|
|
948
|
+
const accountKey = resolveAccountKey(options.accountKey);
|
|
949
949
|
const fetchImpl = options.fetchImpl ?? ((input, init) => fetch(input, init));
|
|
950
950
|
const archiveBaseUrl = stripSlash(options.archiveBaseUrl ?? DEFAULT_ARCHIVE_BASE_URL);
|
|
951
951
|
const archiveOpsUrl = stripSlash(options.archiveOpsUrl ?? DEFAULT_ARCHIVE_OPS_URL);
|
|
@@ -1434,7 +1434,7 @@ async function consumeStreamsEvents(opts) {
|
|
|
1434
1434
|
const sink = opts.sink;
|
|
1435
1435
|
if (checkpoint !== null && (checkpoint !== cursor || emitted.length > 0)) {
|
|
1436
1436
|
await sink.commitBatch(checkpoint, async (tx) => {
|
|
1437
|
-
await opts.onBatch(emitted,
|
|
1437
|
+
await opts.onBatch(emitted, {
|
|
1438
1438
|
...ctx,
|
|
1439
1439
|
tx
|
|
1440
1440
|
});
|
|
@@ -1442,7 +1442,7 @@ async function consumeStreamsEvents(opts) {
|
|
|
1442
1442
|
}
|
|
1443
1443
|
nextCursor = checkpoint;
|
|
1444
1444
|
} else {
|
|
1445
|
-
const returnedCursor = await opts.onBatch(emitted,
|
|
1445
|
+
const returnedCursor = await opts.onBatch(emitted, ctx);
|
|
1446
1446
|
if (finalizedOnly)
|
|
1447
1447
|
assertFinalizedCheckpoint(returnedCursor, checkpoint);
|
|
1448
1448
|
nextCursor = returnedCursor ?? checkpoint;
|
|
@@ -1615,7 +1615,7 @@ async function consumeIndexFeed(opts) {
|
|
|
1615
1615
|
const sink = opts.sink;
|
|
1616
1616
|
if (checkpoint !== null && (checkpoint !== cursor || emitted.length > 0)) {
|
|
1617
1617
|
await sink.commitBatch(checkpoint, async (tx) => {
|
|
1618
|
-
await opts.onBatch(emitted,
|
|
1618
|
+
await opts.onBatch(emitted, {
|
|
1619
1619
|
...ctx,
|
|
1620
1620
|
tx
|
|
1621
1621
|
});
|
|
@@ -1623,7 +1623,7 @@ async function consumeIndexFeed(opts) {
|
|
|
1623
1623
|
}
|
|
1624
1624
|
nextCursor = checkpoint;
|
|
1625
1625
|
} else {
|
|
1626
|
-
const returnedCursor = await opts.onBatch(emitted,
|
|
1626
|
+
const returnedCursor = await opts.onBatch(emitted, ctx);
|
|
1627
1627
|
if (finalizedOnly)
|
|
1628
1628
|
assertFinalizedCheckpoint(returnedCursor, checkpoint);
|
|
1629
1629
|
nextCursor = returnedCursor ?? checkpoint;
|
|
@@ -2498,7 +2498,7 @@ function createStreamsClient(options) {
|
|
|
2498
2498
|
}
|
|
2499
2499
|
const dispatch = params.on;
|
|
2500
2500
|
const project = (events) => params.decoded ? events.map(decode) : events;
|
|
2501
|
-
const onBatch = async (events,
|
|
2501
|
+
const onBatch = async (events, ctx) => {
|
|
2502
2502
|
for (const label of labels) {
|
|
2503
2503
|
const forLabel = events.filter((event) => event.matched?.includes(label));
|
|
2504
2504
|
if (forLabel.length === 0)
|
|
@@ -2506,7 +2506,7 @@ function createStreamsClient(options) {
|
|
|
2506
2506
|
await dispatch?.[label]?.(project(forLabel), ctx);
|
|
2507
2507
|
}
|
|
2508
2508
|
const userOnBatch = params.onBatch;
|
|
2509
|
-
return await userOnBatch?.(project(events),
|
|
2509
|
+
return await userOnBatch?.(project(events), ctx);
|
|
2510
2510
|
};
|
|
2511
2511
|
return consumeStreamsEvents({
|
|
2512
2512
|
fromCursor: params.fromCursor,
|
|
@@ -2843,5 +2843,5 @@ export {
|
|
|
2843
2843
|
getSubgraph
|
|
2844
2844
|
};
|
|
2845
2845
|
|
|
2846
|
-
//# debugId=
|
|
2846
|
+
//# debugId=C622314DDE47F39064756E2164756E21
|
|
2847
2847
|
//# sourceMappingURL=index.js.map
|