ropegeo-common 1.10.1 → 1.10.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.
|
@@ -9,15 +9,19 @@ import { DifficultyFilterOptions } from './difficultyFilterOptions';
|
|
|
9
9
|
export declare class RouteFilter {
|
|
10
10
|
source: PageDataSource[] | null;
|
|
11
11
|
regionId: string | null;
|
|
12
|
-
|
|
12
|
+
/** Null or empty = no route-type filter (all types). */
|
|
13
|
+
routeTypes: RouteType[] | null;
|
|
13
14
|
difficultyOptions: DifficultyFilterOptions | null;
|
|
14
|
-
constructor(source?: PageDataSource[] | null, regionId?: string | null,
|
|
15
|
+
constructor(source?: PageDataSource[] | null, regionId?: string | null, routeTypes?: RouteType[] | null, difficultyOptions?: DifficultyFilterOptions | null);
|
|
15
16
|
toRoutesParams(): RoutesParams;
|
|
16
17
|
toJSON(): Record<string, unknown>;
|
|
17
18
|
toString(): string;
|
|
18
19
|
static fromJsonString(json: string): RouteFilter;
|
|
19
20
|
static fromJSON(parsed: unknown): RouteFilter;
|
|
21
|
+
private static normalizeRouteTypesList;
|
|
22
|
+
/** Accepts `routeTypes` array or legacy singular `routeType` string. */
|
|
23
|
+
private static parseRouteTypesField;
|
|
24
|
+
private static parseRouteTypeToken;
|
|
20
25
|
private static parseSourceField;
|
|
21
|
-
private static parseRouteType;
|
|
22
26
|
}
|
|
23
27
|
//# sourceMappingURL=routeFilter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routeFilter.d.ts","sourceRoot":"","sources":["../../../src/models/filters/routeFilter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,0CAA0C,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2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B;IAOlC,OAAO,CAAC,MAAM,CAAC,gBAAgB;CAmBlC"}
|
|
@@ -10,10 +10,10 @@ const difficultyFilterOptions_1 = require("./difficultyFilterOptions");
|
|
|
10
10
|
* Persisted explore / minimap route filter. Null fields mean “no constraint” on that axis.
|
|
11
11
|
*/
|
|
12
12
|
class RouteFilter {
|
|
13
|
-
constructor(source = null, regionId = null,
|
|
13
|
+
constructor(source = null, regionId = null, routeTypes = null, difficultyOptions = null) {
|
|
14
14
|
this.source = source;
|
|
15
15
|
this.regionId = regionId;
|
|
16
|
-
this.
|
|
16
|
+
this.routeTypes = RouteFilter.normalizeRouteTypesList(routeTypes);
|
|
17
17
|
this.difficultyOptions = difficultyOptions;
|
|
18
18
|
}
|
|
19
19
|
toRoutesParams() {
|
|
@@ -26,7 +26,9 @@ class RouteFilter {
|
|
|
26
26
|
}
|
|
27
27
|
return new routesParams_1.RoutesParams({
|
|
28
28
|
region: null,
|
|
29
|
-
routeTypes: this.
|
|
29
|
+
routeTypes: this.routeTypes != null && this.routeTypes.length > 0
|
|
30
|
+
? [...this.routeTypes]
|
|
31
|
+
: null,
|
|
30
32
|
difficulty: this.difficultyOptions !== null
|
|
31
33
|
? this.difficultyOptions.toDifficultyParams()
|
|
32
34
|
: null,
|
|
@@ -37,7 +39,9 @@ class RouteFilter {
|
|
|
37
39
|
: [...this.source];
|
|
38
40
|
return new routesParams_1.RoutesParams({
|
|
39
41
|
region: { id: rid, source: src },
|
|
40
|
-
routeTypes: this.
|
|
42
|
+
routeTypes: this.routeTypes != null && this.routeTypes.length > 0
|
|
43
|
+
? [...this.routeTypes]
|
|
44
|
+
: null,
|
|
41
45
|
difficulty: this.difficultyOptions !== null
|
|
42
46
|
? this.difficultyOptions.toDifficultyParams()
|
|
43
47
|
: null,
|
|
@@ -47,7 +51,7 @@ class RouteFilter {
|
|
|
47
51
|
return {
|
|
48
52
|
source: this.source,
|
|
49
53
|
regionId: this.regionId,
|
|
50
|
-
|
|
54
|
+
routeTypes: this.routeTypes,
|
|
51
55
|
difficultyOptions: this.difficultyOptions !== null
|
|
52
56
|
? this.difficultyOptions.toJSON()
|
|
53
57
|
: null,
|
|
@@ -75,14 +79,57 @@ class RouteFilter {
|
|
|
75
79
|
const regionId = o.regionId === null || o.regionId === undefined
|
|
76
80
|
? null
|
|
77
81
|
: String(o.regionId);
|
|
78
|
-
const
|
|
79
|
-
? null
|
|
80
|
-
: RouteFilter.parseRouteType(o.routeType);
|
|
82
|
+
const routeTypes = RouteFilter.parseRouteTypesField(o);
|
|
81
83
|
let difficultyOptions = null;
|
|
82
84
|
if (o.difficultyOptions != null && typeof o.difficultyOptions === 'object') {
|
|
83
85
|
difficultyOptions = difficultyFilterOptions_1.DifficultyFilterOptions.fromResult(o.difficultyOptions);
|
|
84
86
|
}
|
|
85
|
-
return new RouteFilter(source, regionId,
|
|
87
|
+
return new RouteFilter(source, regionId, routeTypes, difficultyOptions);
|
|
88
|
+
}
|
|
89
|
+
static normalizeRouteTypesList(list) {
|
|
90
|
+
if (list == null || list.length === 0)
|
|
91
|
+
return null;
|
|
92
|
+
const out = [];
|
|
93
|
+
for (const t of list) {
|
|
94
|
+
if (!Object.values(routeType_1.RouteType).includes(t)) {
|
|
95
|
+
throw new Error(`Invalid RouteType: ${JSON.stringify(t)}`);
|
|
96
|
+
}
|
|
97
|
+
if (!out.includes(t))
|
|
98
|
+
out.push(t);
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
/** Accepts `routeTypes` array or legacy singular `routeType` string. */
|
|
103
|
+
static parseRouteTypesField(o) {
|
|
104
|
+
const raw = o.routeTypes;
|
|
105
|
+
if (raw !== null && raw !== undefined) {
|
|
106
|
+
if (!Array.isArray(raw)) {
|
|
107
|
+
throw new Error('RouteFilter.routeTypes must be an array or null');
|
|
108
|
+
}
|
|
109
|
+
const types = raw.map((item, i) => {
|
|
110
|
+
if (typeof item !== 'string') {
|
|
111
|
+
throw new Error(`RouteFilter.routeTypes[${i}] must be a string`);
|
|
112
|
+
}
|
|
113
|
+
return RouteFilter.parseRouteTypeToken(item);
|
|
114
|
+
});
|
|
115
|
+
return RouteFilter.normalizeRouteTypesList(types);
|
|
116
|
+
}
|
|
117
|
+
const legacy = o.routeType;
|
|
118
|
+
if (legacy === null || legacy === undefined) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
if (typeof legacy !== 'string') {
|
|
122
|
+
throw new Error('RouteFilter.routeType must be a string or null');
|
|
123
|
+
}
|
|
124
|
+
return RouteFilter.normalizeRouteTypesList([
|
|
125
|
+
RouteFilter.parseRouteTypeToken(legacy),
|
|
126
|
+
]);
|
|
127
|
+
}
|
|
128
|
+
static parseRouteTypeToken(v) {
|
|
129
|
+
if (!Object.values(routeType_1.RouteType).includes(v)) {
|
|
130
|
+
throw new Error(`Invalid RouteType: ${JSON.stringify(v)}`);
|
|
131
|
+
}
|
|
132
|
+
return v;
|
|
86
133
|
}
|
|
87
134
|
static parseSourceField(v) {
|
|
88
135
|
if (v === null || v === undefined)
|
|
@@ -104,11 +151,5 @@ class RouteFilter {
|
|
|
104
151
|
}
|
|
105
152
|
return out.length === 0 ? null : out;
|
|
106
153
|
}
|
|
107
|
-
static parseRouteType(v) {
|
|
108
|
-
if (typeof v !== 'string' || !Object.values(routeType_1.RouteType).includes(v)) {
|
|
109
|
-
throw new Error(`Invalid RouteType: ${JSON.stringify(v)}`);
|
|
110
|
-
}
|
|
111
|
-
return v;
|
|
112
|
-
}
|
|
113
154
|
}
|
|
114
155
|
exports.RouteFilter = RouteFilter;
|