@secondlayer/sdk 6.48.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.js CHANGED
@@ -597,6 +597,15 @@ function assertSinkModeCompatible(sink, finalizedOnly) {
597
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
598
  }
599
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
+ }
600
609
  function batchContext(cursor, height, tip, reorgs = []) {
601
610
  const tipHeight = tip.block_height;
602
611
  return {
@@ -669,7 +678,7 @@ async function consumeStreamsEvents(opts) {
669
678
  const handledReorgs = new Set;
670
679
  let pages = 0;
671
680
  let emptyPolls = 0;
672
- let height = null;
681
+ let height = resumeHeight(cursor);
673
682
  while (pages < maxPages && emptyPolls < maxEmptyPolls && !opts.signal?.aborted) {
674
683
  const envelope = await fetchPageWithRetry(() => opts.fetchEvents({
675
684
  cursor,
@@ -708,7 +717,7 @@ async function consumeStreamsEvents(opts) {
708
717
  const emitted = finalizedOnly ? envelope.events.filter((event) => event.finalized) : envelope.events;
709
718
  const checkpoint = finalizedOnly ? emitted.at(-1)?.cursor ?? cursor : envelope.next_cursor;
710
719
  height = emitted.at(-1)?.block_height ?? height;
711
- const ctx = batchContext(checkpoint, height, envelope.tip, envelope.reorgs);
720
+ const ctx = batchContext(checkpoint ?? cursor, height, envelope.tip, envelope.reorgs);
712
721
  opts.onProgress?.(ctx);
713
722
  let nextCursor;
714
723
  if (opts.sink) {
@@ -836,7 +845,7 @@ async function consumeIndexFeed(opts) {
836
845
  const handledReorgs = new Set;
837
846
  let pages = 0;
838
847
  let emptyPolls = 0;
839
- let height = null;
848
+ let height = resumeHeight(cursor);
840
849
  while (pages < maxPages && emptyPolls < maxEmptyPolls && !opts.signal?.aborted) {
841
850
  const envelope = await fetchPageWithRetry(() => opts.fetchPage({
842
851
  cursor,
@@ -870,7 +879,7 @@ async function consumeIndexFeed(opts) {
870
879
  const emitted = finalizedOnly ? items.filter((item) => item.block_height <= envelope.tip.finalized_height) : items;
871
880
  const checkpoint = finalizedOnly ? emitted.at(-1)?.cursor ?? cursor : envelope.next_cursor;
872
881
  height = emitted.at(-1)?.block_height ?? height;
873
- const ctx = batchContext(checkpoint, height, envelope.tip, envelope.reorgs);
882
+ const ctx = batchContext(checkpoint ?? cursor, height, envelope.tip, envelope.reorgs);
874
883
  opts.onProgress?.(ctx);
875
884
  let nextCursor;
876
885
  if (opts.sink) {
@@ -2899,5 +2908,5 @@ export {
2899
2908
  ApiError
2900
2909
  };
2901
2910
 
2902
- //# debugId=AADEB8FAB0EE368C64756E2164756E21
2911
+ //# debugId=33DAF3413D4D67EA64756E2164756E21
2903
2912
  //# sourceMappingURL=index.js.map