@secondlayer/sdk 6.48.1 → 6.49.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 +16 -4
- package/dist/index.js +26 -5
- package/dist/index.js.map +6 -6
- package/dist/streams/index.d.ts +12 -3
- package/dist/streams/index.js +15 -4
- package/dist/streams/index.js.map +4 -4
- package/dist/subgraphs/index.d.ts +12 -3
- package/dist/subgraphs/index.js +25 -5
- package/dist/subgraphs/index.js.map +4 -4
- package/package.json +1 -1
package/dist/subgraphs/index.js
CHANGED
|
@@ -606,13 +606,15 @@ function resumeHeight(cursor) {
|
|
|
606
606
|
return null;
|
|
607
607
|
}
|
|
608
608
|
}
|
|
609
|
-
function batchContext(cursor, height, tip, reorgs = []) {
|
|
609
|
+
function batchContext(cursor, height, tip, reorgs = [], scannedHeight = null) {
|
|
610
610
|
const tipHeight = tip.block_height;
|
|
611
|
+
const position = scannedHeight ?? height;
|
|
611
612
|
return {
|
|
612
613
|
cursor,
|
|
613
614
|
height,
|
|
615
|
+
scannedHeight: position,
|
|
614
616
|
tipHeight,
|
|
615
|
-
blocksBehind:
|
|
617
|
+
blocksBehind: position === null ? null : Math.max(0, tipHeight - position),
|
|
616
618
|
tip,
|
|
617
619
|
reorgs
|
|
618
620
|
};
|
|
@@ -679,6 +681,7 @@ async function consumeStreamsEvents(opts) {
|
|
|
679
681
|
let pages = 0;
|
|
680
682
|
let emptyPolls = 0;
|
|
681
683
|
let height = resumeHeight(cursor);
|
|
684
|
+
let scanned = height;
|
|
682
685
|
while (pages < maxPages && emptyPolls < maxEmptyPolls && !opts.signal?.aborted) {
|
|
683
686
|
const envelope = await fetchPageWithRetry(() => opts.fetchEvents({
|
|
684
687
|
cursor,
|
|
@@ -710,6 +713,7 @@ async function consumeStreamsEvents(opts) {
|
|
|
710
713
|
}
|
|
711
714
|
cursor = rewind;
|
|
712
715
|
height = forkPoint > 0 ? forkPoint - 1 : null;
|
|
716
|
+
scanned = height;
|
|
713
717
|
emptyPolls = 0;
|
|
714
718
|
continue;
|
|
715
719
|
}
|
|
@@ -717,7 +721,14 @@ async function consumeStreamsEvents(opts) {
|
|
|
717
721
|
const emitted = finalizedOnly ? envelope.events.filter((event) => event.finalized) : envelope.events;
|
|
718
722
|
const checkpoint = finalizedOnly ? emitted.at(-1)?.cursor ?? cursor : envelope.next_cursor;
|
|
719
723
|
height = emitted.at(-1)?.block_height ?? height;
|
|
720
|
-
|
|
724
|
+
if (emitted.length > 0) {
|
|
725
|
+
scanned = height;
|
|
726
|
+
} else if (checkpoint !== null && checkpoint !== cursor) {
|
|
727
|
+
scanned = resumeHeight(checkpoint) ?? scanned;
|
|
728
|
+
} else if (envelope.events.length === 0) {
|
|
729
|
+
scanned = envelope.tip.block_height;
|
|
730
|
+
}
|
|
731
|
+
const ctx = batchContext(checkpoint ?? cursor, height, envelope.tip, envelope.reorgs, scanned);
|
|
721
732
|
opts.onProgress?.(ctx);
|
|
722
733
|
let nextCursor;
|
|
723
734
|
if (opts.sink) {
|
|
@@ -846,6 +857,7 @@ async function consumeIndexFeed(opts) {
|
|
|
846
857
|
let pages = 0;
|
|
847
858
|
let emptyPolls = 0;
|
|
848
859
|
let height = resumeHeight(cursor);
|
|
860
|
+
let scanned = height;
|
|
849
861
|
while (pages < maxPages && emptyPolls < maxEmptyPolls && !opts.signal?.aborted) {
|
|
850
862
|
const envelope = await fetchPageWithRetry(() => opts.fetchPage({
|
|
851
863
|
cursor,
|
|
@@ -871,6 +883,7 @@ async function consumeIndexFeed(opts) {
|
|
|
871
883
|
}
|
|
872
884
|
cursor = rewind;
|
|
873
885
|
height = forkPoint > 0 ? forkPoint - 1 : null;
|
|
886
|
+
scanned = height;
|
|
874
887
|
emptyPolls = 0;
|
|
875
888
|
continue;
|
|
876
889
|
}
|
|
@@ -879,7 +892,14 @@ async function consumeIndexFeed(opts) {
|
|
|
879
892
|
const emitted = finalizedOnly ? items.filter((item) => item.block_height <= envelope.tip.finalized_height) : items;
|
|
880
893
|
const checkpoint = finalizedOnly ? emitted.at(-1)?.cursor ?? cursor : envelope.next_cursor;
|
|
881
894
|
height = emitted.at(-1)?.block_height ?? height;
|
|
882
|
-
|
|
895
|
+
if (emitted.length > 0) {
|
|
896
|
+
scanned = height;
|
|
897
|
+
} else if (checkpoint !== null && checkpoint !== cursor) {
|
|
898
|
+
scanned = resumeHeight(checkpoint) ?? scanned;
|
|
899
|
+
} else {
|
|
900
|
+
scanned = finalizedOnly ? envelope.tip.finalized_height : envelope.tip.block_height;
|
|
901
|
+
}
|
|
902
|
+
const ctx = batchContext(checkpoint ?? cursor, height, envelope.tip, envelope.reorgs, scanned);
|
|
883
903
|
opts.onProgress?.(ctx);
|
|
884
904
|
let nextCursor;
|
|
885
905
|
if (opts.sink) {
|
|
@@ -2212,5 +2232,5 @@ export {
|
|
|
2212
2232
|
Subgraphs
|
|
2213
2233
|
};
|
|
2214
2234
|
|
|
2215
|
-
//# debugId=
|
|
2235
|
+
//# debugId=0E0B0BAAF8B4C44E64756E2164756E21
|
|
2216
2236
|
//# sourceMappingURL=index.js.map
|