@secondlayer/sdk 6.47.0 → 6.48.1
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 +1286 -1211
- package/dist/index.js +21 -5
- package/dist/index.js.map +5 -5
- package/dist/sinks/bun-sqlite.d.ts +158 -0
- package/dist/sinks/bun-sqlite.js +255 -0
- package/dist/sinks/bun-sqlite.js.map +12 -0
- package/dist/sinks/core.d.ts +195 -0
- package/dist/sinks/core.js +215 -0
- package/dist/sinks/core.js.map +11 -0
- package/dist/sinks/drizzle.d.ts +184 -0
- package/dist/sinks/drizzle.js +309 -0
- package/dist/sinks/drizzle.js.map +12 -0
- package/dist/sinks/kysely.d.ts +87 -2
- package/dist/sinks/kysely.js +91 -54
- package/dist/sinks/kysely.js.map +6 -5
- package/dist/sinks/testing.d.ts +183 -0
- package/dist/sinks/testing.js +194 -0
- package/dist/sinks/testing.js.map +10 -0
- package/dist/streams/index.d.ts +558 -482
- package/dist/streams/index.js +18 -3
- package/dist/streams/index.js.map +4 -4
- package/dist/streams/rows.d.ts +208 -208
- package/dist/streams/rows.js +1 -1
- package/dist/streams/rows.js.map +2 -2
- package/dist/subgraphs/index.d.ts +1044 -968
- package/dist/subgraphs/index.js +21 -5
- package/dist/subgraphs/index.js.map +5 -5
- package/dist/x402.d.ts +49 -49
- package/dist/x402.js +1 -1
- package/dist/x402.js.map +2 -2
- package/package.json +25 -3
package/dist/subgraphs/index.js
CHANGED
|
@@ -592,6 +592,20 @@ 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 assertSinkModeCompatible(sink, finalizedOnly) {
|
|
596
|
+
if (sink?.capabilities?.finalizedOnly && !finalizedOnly) {
|
|
597
|
+
throw new ValidationError("This sink declares capabilities.finalizedOnly — it cannot roll back reorged rows, and following the unfinalized tip would corrupt it at the first fork. Pass finalizedOnly: true to consume(), or use a sink that implements rollback.", 400);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
function resumeHeight(cursor) {
|
|
601
|
+
if (cursor === null)
|
|
602
|
+
return null;
|
|
603
|
+
try {
|
|
604
|
+
return Cursor.parse(cursor).blockHeight;
|
|
605
|
+
} catch {
|
|
606
|
+
return null;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
595
609
|
function batchContext(cursor, height, tip, reorgs = []) {
|
|
596
610
|
const tipHeight = tip.block_height;
|
|
597
611
|
return {
|
|
@@ -658,12 +672,13 @@ async function consumeStreamsEvents(opts) {
|
|
|
658
672
|
const emptyBackoffMs = opts.emptyBackoffMs ?? 500;
|
|
659
673
|
const maxPages = opts.maxPages ?? Number.POSITIVE_INFINITY;
|
|
660
674
|
const maxEmptyPolls = opts.maxEmptyPolls ?? Number.POSITIVE_INFINITY;
|
|
675
|
+
assertSinkModeCompatible(opts.sink, finalizedOnly);
|
|
661
676
|
const committedCursor = await opts.sink?.loadCursor() ?? null;
|
|
662
677
|
let cursor = opts.fromCursor ?? committedCursor;
|
|
663
678
|
const handledReorgs = new Set;
|
|
664
679
|
let pages = 0;
|
|
665
680
|
let emptyPolls = 0;
|
|
666
|
-
let height =
|
|
681
|
+
let height = resumeHeight(cursor);
|
|
667
682
|
while (pages < maxPages && emptyPolls < maxEmptyPolls && !opts.signal?.aborted) {
|
|
668
683
|
const envelope = await fetchPageWithRetry(() => opts.fetchEvents({
|
|
669
684
|
cursor,
|
|
@@ -702,7 +717,7 @@ async function consumeStreamsEvents(opts) {
|
|
|
702
717
|
const emitted = finalizedOnly ? envelope.events.filter((event) => event.finalized) : envelope.events;
|
|
703
718
|
const checkpoint = finalizedOnly ? emitted.at(-1)?.cursor ?? cursor : envelope.next_cursor;
|
|
704
719
|
height = emitted.at(-1)?.block_height ?? height;
|
|
705
|
-
const ctx = batchContext(checkpoint, height, envelope.tip, envelope.reorgs);
|
|
720
|
+
const ctx = batchContext(checkpoint ?? cursor, height, envelope.tip, envelope.reorgs);
|
|
706
721
|
opts.onProgress?.(ctx);
|
|
707
722
|
let nextCursor;
|
|
708
723
|
if (opts.sink) {
|
|
@@ -824,12 +839,13 @@ async function consumeIndexFeed(opts) {
|
|
|
824
839
|
const emptyBackoffMs = opts.emptyBackoffMs ?? 500;
|
|
825
840
|
const maxPages = opts.maxPages ?? Number.POSITIVE_INFINITY;
|
|
826
841
|
const maxEmptyPolls = opts.maxEmptyPolls ?? Number.POSITIVE_INFINITY;
|
|
842
|
+
assertSinkModeCompatible(opts.sink, finalizedOnly);
|
|
827
843
|
const committedCursor = await opts.sink?.loadCursor() ?? null;
|
|
828
844
|
let cursor = opts.fromCursor ?? committedCursor;
|
|
829
845
|
const handledReorgs = new Set;
|
|
830
846
|
let pages = 0;
|
|
831
847
|
let emptyPolls = 0;
|
|
832
|
-
let height =
|
|
848
|
+
let height = resumeHeight(cursor);
|
|
833
849
|
while (pages < maxPages && emptyPolls < maxEmptyPolls && !opts.signal?.aborted) {
|
|
834
850
|
const envelope = await fetchPageWithRetry(() => opts.fetchPage({
|
|
835
851
|
cursor,
|
|
@@ -863,7 +879,7 @@ async function consumeIndexFeed(opts) {
|
|
|
863
879
|
const emitted = finalizedOnly ? items.filter((item) => item.block_height <= envelope.tip.finalized_height) : items;
|
|
864
880
|
const checkpoint = finalizedOnly ? emitted.at(-1)?.cursor ?? cursor : envelope.next_cursor;
|
|
865
881
|
height = emitted.at(-1)?.block_height ?? height;
|
|
866
|
-
const ctx = batchContext(checkpoint, height, envelope.tip, envelope.reorgs);
|
|
882
|
+
const ctx = batchContext(checkpoint ?? cursor, height, envelope.tip, envelope.reorgs);
|
|
867
883
|
opts.onProgress?.(ctx);
|
|
868
884
|
let nextCursor;
|
|
869
885
|
if (opts.sink) {
|
|
@@ -2196,5 +2212,5 @@ export {
|
|
|
2196
2212
|
Subgraphs
|
|
2197
2213
|
};
|
|
2198
2214
|
|
|
2199
|
-
//# debugId=
|
|
2215
|
+
//# debugId=BE9B5D3664FE5C8464756E2164756E21
|
|
2200
2216
|
//# sourceMappingURL=index.js.map
|