ropegeo-common 1.2.0 → 1.2.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.
|
@@ -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.
|