ropegeo-common 1.2.1 → 1.2.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.
@@ -1,13 +1,15 @@
1
1
  /**
2
- * Stub cursor for region previews pagination. Encodes to base64url for the nextCursor string.
3
- * Cursor logic will be implemented in Webscraper.
2
+ * Cursor for region previews pagination. Encodes to base64url for the nextCursor string.
4
3
  */
5
4
  export declare class RegionPreviewsCursor {
6
- readonly value: string;
7
- constructor(value: string);
5
+ readonly sortKey: number;
6
+ readonly type: string;
7
+ readonly id: string;
8
+ constructor(sortKey: number, type: string, id: string);
8
9
  encodeBase64(): string;
9
10
  /**
10
- * Decodes a base64url-encoded cursor string. Throws if the string is invalid.
11
+ * Decodes a base64url-encoded cursor string. Throws if the string is invalid
12
+ * or does not represent a valid RegionPreviewsCursor shape.
11
13
  */
12
14
  static decodeBase64(encoded: string): RegionPreviewsCursor;
13
15
  }
@@ -1 +1 @@
1
- {"version":3,"file":"regionPreviewsCursor.d.ts","sourceRoot":"","sources":["../../../../src/types/api/getRopewikiRegionPreviews/regionPreviewsCursor.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,qBAAa,oBAAoB;aACD,KAAK,EAAE,MAAM;gBAAb,KAAK,EAAE,MAAM;IAEzC,YAAY,IAAI,MAAM;IAItB;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,oBAAoB;CAkB7D"}
1
+ {"version":3,"file":"regionPreviewsCursor.d.ts","sourceRoot":"","sources":["../../../../src/types/api/getRopewikiRegionPreviews/regionPreviewsCursor.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,qBAAa,oBAAoB;aAET,OAAO,EAAE,MAAM;aACf,IAAI,EAAE,MAAM;aACZ,EAAE,EAAE,MAAM;gBAFV,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM;IAG9B,YAAY,IAAI,MAAM;IAWtB;;;OAGG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,oBAAoB;CA0C7D"}
@@ -5,18 +5,24 @@ exports.RegionPreviewsCursor = void 0;
5
5
  const ENCODING = 'utf8';
6
6
  const BASE64URL = 'base64url';
7
7
  /**
8
- * Stub cursor for region previews pagination. Encodes to base64url for the nextCursor string.
9
- * Cursor logic will be implemented in Webscraper.
8
+ * Cursor for region previews pagination. Encodes to base64url for the nextCursor string.
10
9
  */
11
10
  class RegionPreviewsCursor {
12
- constructor(value) {
13
- this.value = value;
11
+ constructor(sortKey, type, id) {
12
+ this.sortKey = sortKey;
13
+ this.type = type;
14
+ this.id = id;
14
15
  }
15
16
  encodeBase64() {
16
- return Buffer.from(JSON.stringify({ value: this.value }), ENCODING).toString(BASE64URL);
17
+ return Buffer.from(JSON.stringify({
18
+ sortKey: this.sortKey,
19
+ type: this.type,
20
+ id: this.id,
21
+ }), ENCODING).toString(BASE64URL);
17
22
  }
18
23
  /**
19
- * Decodes a base64url-encoded cursor string. Throws if the string is invalid.
24
+ * Decodes a base64url-encoded cursor string. Throws if the string is invalid
25
+ * or does not represent a valid RegionPreviewsCursor shape.
20
26
  */
21
27
  static decodeBase64(encoded) {
22
28
  if (typeof encoded !== 'string' || encoded === '') {
@@ -31,11 +37,25 @@ class RegionPreviewsCursor {
31
37
  const message = err instanceof Error ? err.message : String(err);
32
38
  throw new Error(`Invalid region previews cursor encoding: ${message}`);
33
39
  }
34
- if (decoded == null || typeof decoded !== 'object' || !('value' in decoded)) {
35
- throw new Error('Region previews cursor must be an object with value');
40
+ if (decoded == null ||
41
+ typeof decoded !== 'object' ||
42
+ !('sortKey' in decoded) ||
43
+ !('type' in decoded) ||
44
+ !('id' in decoded)) {
45
+ throw new Error('Region previews cursor must be an object with sortKey, type, and id');
36
46
  }
37
47
  const obj = decoded;
38
- return new RegionPreviewsCursor(String(obj.value ?? ''));
48
+ const sortKey = Number(obj.sortKey);
49
+ if (Number.isNaN(sortKey)) {
50
+ throw new Error(`Region previews cursor sortKey must be a number, got: ${JSON.stringify(obj.sortKey)}`);
51
+ }
52
+ if (typeof obj.type !== 'string') {
53
+ throw new Error(`Region previews cursor type must be a string, got: ${typeof obj.type}`);
54
+ }
55
+ if (typeof obj.id !== 'string') {
56
+ throw new Error(`Region previews cursor id must be a string, got: ${typeof obj.id}`);
57
+ }
58
+ return new RegionPreviewsCursor(sortKey, obj.type, obj.id);
39
59
  }
40
60
  }
41
61
  exports.RegionPreviewsCursor = RegionPreviewsCursor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ropegeo-common",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Shared types and utilities for RopeGeo and WebScraper",
5
5
  "license": "ISC",
6
6
  "repository": {