ropegeo-common 1.2.0 → 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.
- package/dist/types/api/getRopewikiRegionPreviews/regionPreviewsCursor.d.ts +7 -5
- package/dist/types/api/getRopewikiRegionPreviews/regionPreviewsCursor.d.ts.map +1 -1
- package/dist/types/api/getRopewikiRegionPreviews/regionPreviewsCursor.js +29 -9
- package/dist/types/api/getRoutes/routesParams.d.ts +7 -4
- package/dist/types/api/getRoutes/routesParams.d.ts.map +1 -1
- package/dist/types/api/getRoutes/routesParams.js +15 -12
- package/package.json +1 -1
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
|
7
|
-
|
|
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
|
|
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
|
-
*
|
|
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(
|
|
13
|
-
this.
|
|
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({
|
|
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 ||
|
|
35
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { PageDataSource } from '../../pageDataSource';
|
|
2
2
|
/**
|
|
3
3
|
* Validated params for getRoutes (GET /routes).
|
|
4
|
-
* source
|
|
4
|
+
* region is null when neither source nor region id are in the query; if one query param is present the other must also be present.
|
|
5
5
|
*/
|
|
6
6
|
export declare class RoutesParams {
|
|
7
|
-
|
|
8
|
-
readonly region:
|
|
9
|
-
|
|
7
|
+
/** When set, both source and region id were provided in the query. */
|
|
8
|
+
readonly region: {
|
|
9
|
+
source: PageDataSource;
|
|
10
|
+
id: string;
|
|
11
|
+
} | null;
|
|
12
|
+
constructor(source: PageDataSource | undefined, regionId: string | undefined);
|
|
10
13
|
/**
|
|
11
14
|
* Returns an object suitable for use as query string parameters.
|
|
12
15
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routesParams.d.ts","sourceRoot":"","sources":["../../../../src/types/api/getRoutes/routesParams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;GAGG;AACH,qBAAa,YAAY;IACrB,SAAgB,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"routesParams.d.ts","sourceRoot":"","sources":["../../../../src/types/api/getRoutes/routesParams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;GAGG;AACH,qBAAa,YAAY;IACrB,sEAAsE;IACtE,SAAgB,MAAM,EAAE;QAAE,MAAM,EAAE,cAAc,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;gBAE1D,MAAM,EAAE,cAAc,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS;IAiB5E;;OAEG;IACH,mBAAmB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAU7C;;;OAGG;IACH,MAAM,CAAC,qBAAqB,CACxB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GACtC,YAAY;IAWf,OAAO,CAAC,MAAM,CAAC,WAAW;CAQ7B"}
|
|
@@ -4,30 +4,33 @@ exports.RoutesParams = void 0;
|
|
|
4
4
|
const pageDataSource_1 = require("../../pageDataSource");
|
|
5
5
|
/**
|
|
6
6
|
* Validated params for getRoutes (GET /routes).
|
|
7
|
-
* source
|
|
7
|
+
* region is null when neither source nor region id are in the query; if one query param is present the other must also be present.
|
|
8
8
|
*/
|
|
9
9
|
class RoutesParams {
|
|
10
|
-
constructor(source,
|
|
10
|
+
constructor(source, regionId) {
|
|
11
11
|
const sourcePresent = source !== undefined;
|
|
12
|
-
const regionPresent =
|
|
12
|
+
const regionPresent = regionId !== undefined &&
|
|
13
|
+
typeof regionId === 'string' &&
|
|
14
|
+
regionId !== '';
|
|
13
15
|
if (sourcePresent !== regionPresent) {
|
|
14
16
|
throw new Error('Query parameters "source" and "region" must both be present or both be absent');
|
|
15
17
|
}
|
|
16
|
-
this.
|
|
17
|
-
|
|
18
|
+
this.region =
|
|
19
|
+
sourcePresent && regionPresent
|
|
20
|
+
? { source: source, id: regionId }
|
|
21
|
+
: null;
|
|
18
22
|
}
|
|
19
23
|
/**
|
|
20
24
|
* Returns an object suitable for use as query string parameters.
|
|
21
25
|
*/
|
|
22
26
|
toQueryStringParams() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
params.source = this.source;
|
|
27
|
+
if (this.region === null) {
|
|
28
|
+
return {};
|
|
26
29
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
return {
|
|
31
|
+
source: this.region.source,
|
|
32
|
+
region: this.region.id,
|
|
33
|
+
};
|
|
31
34
|
}
|
|
32
35
|
/**
|
|
33
36
|
* Parses query string parameters and returns validated params.
|