@secondlayer/sdk 9.0.1 → 9.0.2

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 CHANGED
@@ -2606,7 +2606,9 @@ import { DecodedEventColumns, DecodedEventRow, DecodedFtBurn, DecodedFtBurnPaylo
2606
2606
  * Helpers for Streams cursors. A cursor is the opaque `<block>:<index>` string
2607
2607
  * that marks a position in the event stream; treat the format as an
2608
2608
  * implementation detail and go through these helpers instead of string-building
2609
- * it at call sites.
2609
+ * it at call sites. Encode/decode and the rewind sentinel come from the
2610
+ * canonical codec in `@secondlayer/shared` so the SDK cannot accept a spelling
2611
+ * the server would 400, or rewind to a different foot than Index/Streams.
2610
2612
  */
2611
2613
  declare const Cursor: {
2612
2614
  /**
@@ -2618,7 +2620,7 @@ declare const Cursor: {
2618
2620
  * is `height`: the new canonical block at `height` carries a fresh first
2619
2621
  * event at `(height, 0)` that the consumer MUST re-read.
2620
2622
  *
2621
- * Encoded as `${height-1}:${SENTINEL}` rather than the seemingly-natural
2623
+ * Encoded as `blockEndCursor(height - 1)` rather than the seemingly-natural
2622
2624
  * `${height}:0` — that earlier form was an off-by-one: being exclusive, it
2623
2625
  * skipped `(height, 0)`, silently dropping the fork block's first row on
2624
2626
  * every reorg. The sentinel is int4 max (the `event_index`/`tx_index` column
package/dist/index.js CHANGED
@@ -512,6 +512,13 @@ class Contracts extends BaseClient {
512
512
  }
513
513
  }
514
514
 
515
+ // src/streams/cursor.ts
516
+ import {
517
+ blockEndCursor,
518
+ decodeStreamsCursor,
519
+ encodeStreamsCursor
520
+ } from "@secondlayer/shared";
521
+
515
522
  // src/streams/errors.ts
516
523
  class StreamsServerError extends ApiError {
517
524
  constructor(message, status, body) {
@@ -528,21 +535,23 @@ class StreamsSignatureError extends SecondLayerError {
528
535
  }
529
536
 
530
537
  // src/streams/cursor.ts
531
- var REWIND_FOOT_INDEX_SENTINEL = 2147483647;
532
538
  var Cursor = {
533
539
  atHeight(height) {
534
- if (height <= 0)
535
- return "0:0";
536
- return `${height - 1}:${REWIND_FOOT_INDEX_SENTINEL}`;
540
+ if (height <= 0) {
541
+ return encodeStreamsCursor({ block_height: 0, event_index: 0 });
542
+ }
543
+ return encodeStreamsCursor(blockEndCursor(height - 1));
537
544
  },
538
545
  parse(cursor) {
539
- const parts = cursor.split(":");
540
- const blockHeight = Number(parts[0]);
541
- const eventIndex = Number(parts[1]);
542
- if (parts.length !== 2 || !Number.isInteger(blockHeight) || !Number.isInteger(eventIndex)) {
546
+ try {
547
+ const decoded = decodeStreamsCursor(cursor);
548
+ return {
549
+ blockHeight: decoded.block_height,
550
+ eventIndex: decoded.event_index
551
+ };
552
+ } catch {
543
553
  throw new ValidationError(`Invalid stream cursor "${cursor}"; expected "<block>:<index>" (e.g. "951475:3").`, 400);
544
554
  }
545
- return { blockHeight, eventIndex };
546
555
  }
547
556
  };
548
557
 
@@ -1585,12 +1594,8 @@ function parseFrame(raw) {
1585
1594
  function cursorTuple(cursor) {
1586
1595
  if (!cursor)
1587
1596
  return [-1, -1];
1588
- const parts = cursor.split(":");
1589
- const [block, index] = parts.map(Number);
1590
- if (parts.length !== 2 || !Number.isInteger(block) || !Number.isInteger(index)) {
1591
- throw new ValidationError(`Invalid stream cursor "${cursor}"; expected "<block>:<index>" (e.g. "951475:3").`, 400);
1592
- }
1593
- return [block, index];
1597
+ const { blockHeight, eventIndex } = Cursor.parse(cursor);
1598
+ return [blockHeight, eventIndex];
1594
1599
  }
1595
1600
  function maxCursor(a, b) {
1596
1601
  const [ah, ai] = cursorTuple(a);
@@ -2276,5 +2281,5 @@ export {
2276
2281
  ApiError
2277
2282
  };
2278
2283
 
2279
- //# debugId=D7FC8B721E6F36FC64756E2164756E21
2284
+ //# debugId=9A05B56B79C1360464756E2164756E21
2280
2285
  //# sourceMappingURL=index.js.map