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 and region are optional with no defaults; if one is present the other must also be present.
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
- readonly source: PageDataSource | undefined;
8
- readonly region: string | undefined;
9
- constructor(source: PageDataSource | undefined, region: string | undefined);
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,cAAc,GAAG,SAAS,CAAC;IACnD,SAAgB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;gBAE/B,MAAM,EAAE,cAAc,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS;IAa1E;;OAEG;IACH,mBAAmB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAW7C;;;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"}
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 and region are optional with no defaults; if one is present the other must also be present.
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, region) {
10
+ constructor(source, regionId) {
11
11
  const sourcePresent = source !== undefined;
12
- const regionPresent = region !== undefined && typeof region === 'string' && region !== '';
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.source = sourcePresent ? source : undefined;
17
- this.region = regionPresent ? region : undefined;
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
- const params = {};
24
- if (this.source !== undefined) {
25
- params.source = this.source;
27
+ if (this.region === null) {
28
+ return {};
26
29
  }
27
- if (this.region !== undefined) {
28
- params.region = this.region;
29
- }
30
- return params;
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ropegeo-common",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Shared types and utilities for RopeGeo and WebScraper",
5
5
  "license": "ISC",
6
6
  "repository": {