@opentripplanner/core-utils 13.0.0-alpha.1 → 13.0.0-alpha.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/LICENSE +21 -0
- package/README.md +1 -0
- package/esm/graphql.d.js.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/itinerary.js +78 -115
- package/esm/itinerary.js.map +1 -1
- package/esm/map.js +3 -3
- package/esm/map.js.map +1 -1
- package/esm/profile.js +17 -18
- package/esm/profile.js.map +1 -1
- package/esm/query-gen.js +35 -45
- package/esm/query-gen.js.map +1 -1
- package/esm/query.js +135 -191
- package/esm/query.js.map +1 -1
- package/esm/route.js +74 -97
- package/esm/route.js.map +1 -1
- package/esm/storage.js +4 -5
- package/esm/storage.js.map +1 -1
- package/esm/suspense.js +1 -3
- package/esm/suspense.js.map +1 -1
- package/esm/time.js +13 -17
- package/esm/time.js.map +1 -1
- package/esm/ui.js +0 -5
- package/esm/ui.js.map +1 -1
- package/lib/graphql.d.js.map +1 -1
- package/lib/index.js +3 -19
- package/lib/index.js.map +1 -1
- package/lib/itinerary.js +152 -249
- package/lib/itinerary.js.map +1 -1
- package/lib/map.d.ts +1 -1
- package/lib/map.d.ts.map +1 -1
- package/lib/map.js +9 -20
- package/lib/map.js.map +1 -1
- package/lib/profile.js +18 -20
- package/lib/profile.js.map +1 -1
- package/lib/query-gen.d.ts +4 -4
- package/lib/query-gen.d.ts.map +1 -1
- package/lib/query-gen.js +35 -47
- package/lib/query-gen.js.map +1 -1
- package/lib/query-params.jsx +893 -0
- package/lib/query.js +68 -122
- package/lib/query.js.map +1 -1
- package/lib/route.js +73 -101
- package/lib/route.js.map +1 -1
- package/lib/storage.js +6 -11
- package/lib/storage.js.map +1 -1
- package/lib/suspense.d.ts +1 -1
- package/lib/suspense.d.ts.map +1 -1
- package/lib/suspense.js +3 -9
- package/lib/suspense.js.map +1 -1
- package/lib/time.js +21 -44
- package/lib/time.js.map +1 -1
- package/lib/ui.js +1 -8
- package/lib/ui.js.map +1 -1
- package/package.json +7 -8
- package/src/query-params.jsx +893 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/esm/query-params.js +0 -786
- package/esm/query-params.js.map +0 -1
- package/lib/query-params.js +0 -756
- package/lib/query-params.js.map +0 -1
- /package/{src/query-params.js → esm/query-params.jsx} +0 -0
package/lib/query.js
CHANGED
|
@@ -1,132 +1,115 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.
|
|
7
|
+
exports.defaultParams = void 0;
|
|
9
8
|
exports.ensureSingleAccessMode = ensureSingleAccessMode;
|
|
10
|
-
exports.
|
|
9
|
+
exports.expandOtpFlexMode = expandOtpFlexMode;
|
|
10
|
+
exports.getDefaultQuery = getDefaultQuery;
|
|
11
11
|
exports.getOtpUrlParams = getOtpUrlParams;
|
|
12
|
+
exports.getQueryParamProperty = getQueryParamProperty;
|
|
13
|
+
exports.getRoutingParams = getRoutingParams;
|
|
12
14
|
exports.getTripOptionsFromQuery = getTripOptionsFromQuery;
|
|
13
|
-
exports.
|
|
14
|
-
exports.reduceOtpFlexModes = reduceOtpFlexModes;
|
|
15
|
-
exports.expandOtpFlexMode = expandOtpFlexMode;
|
|
15
|
+
exports.getUrlParams = getUrlParams;
|
|
16
16
|
exports.isNotDefaultQuery = isNotDefaultQuery;
|
|
17
17
|
exports.parseLocationString = parseLocationString;
|
|
18
18
|
exports.planParamsToQuery = planParamsToQuery;
|
|
19
19
|
exports.planParamsToQueryAsync = planParamsToQueryAsync;
|
|
20
|
-
exports.
|
|
21
|
-
exports.defaultParams = void 0;
|
|
22
|
-
|
|
20
|
+
exports.reduceOtpFlexModes = reduceOtpFlexModes;
|
|
23
21
|
var _dateFns = require("date-fns");
|
|
24
|
-
|
|
25
22
|
var _lib = _interopRequireDefault(require("@opentripplanner/geocoder/lib"));
|
|
26
|
-
|
|
27
23
|
var _qs = _interopRequireDefault(require("qs"));
|
|
28
|
-
|
|
29
24
|
var _itinerary = require("./itinerary");
|
|
30
|
-
|
|
31
25
|
var _map = require("./map");
|
|
32
|
-
|
|
33
26
|
var _queryParams = _interopRequireDefault(require("./query-params"));
|
|
34
|
-
|
|
35
27
|
var _time = require("./time");
|
|
36
|
-
|
|
37
28
|
/* The list of default parameters considered in the settings panel */
|
|
38
|
-
|
|
29
|
+
|
|
30
|
+
const defaultParams = exports.defaultParams = ["wheelchair", "maxWalkDistance", "walkReluctance", "maxWalkTime", "maxBikeDistance", "maxBikeTime", "bikeSpeed", "optimize", "optimizeBike", "maxEScooterDistance", "watts"];
|
|
31
|
+
|
|
39
32
|
/**
|
|
40
33
|
* List of time formats to parse when reading query params.
|
|
41
34
|
*/
|
|
42
|
-
|
|
43
|
-
exports.defaultParams = defaultParams;
|
|
44
35
|
const TIME_FORMATS = ["HH:mm:ss", "HH:mm", "H:mm", "h:mm:ss a", "h:mm:ssa", "h:mm a", "h:mma", "h:mm", "HHmm", "hmm", "ha"];
|
|
36
|
+
|
|
45
37
|
/* A function to retrieve a property value from an entry in the query-params
|
|
46
38
|
* table, checking for either a static value or a function */
|
|
47
39
|
|
|
48
40
|
function getQueryParamProperty(paramInfo, property, query) {
|
|
49
41
|
return typeof paramInfo[property] === "function" ? paramInfo[property](query) : paramInfo[property];
|
|
50
42
|
}
|
|
51
|
-
|
|
52
43
|
function ensureSingleAccessMode(queryModes) {
|
|
53
44
|
// Count the number of access modes
|
|
54
|
-
const accessCount = queryModes.filter(m => (0, _itinerary.isAccessMode)(m)).length;
|
|
45
|
+
const accessCount = queryModes.filter(m => (0, _itinerary.isAccessMode)(m)).length;
|
|
55
46
|
|
|
47
|
+
// If multiple access modes are specified, keep only the first one
|
|
56
48
|
if (accessCount > 1) {
|
|
57
49
|
const firstAccess = queryModes.find(m => (0, _itinerary.isAccessMode)(m));
|
|
58
|
-
queryModes = queryModes.filter(m => !(0, _itinerary.isAccessMode)(m) || m === firstAccess);
|
|
50
|
+
queryModes = queryModes.filter(m => !(0, _itinerary.isAccessMode)(m) || m === firstAccess);
|
|
51
|
+
|
|
52
|
+
// If no access modes are specified, add 'WALK' as the default
|
|
59
53
|
} else if (accessCount === 0) {
|
|
60
54
|
queryModes.push("WALK");
|
|
61
55
|
}
|
|
62
|
-
|
|
63
56
|
return queryModes;
|
|
64
57
|
}
|
|
65
|
-
|
|
66
58
|
function getUrlParams() {
|
|
67
59
|
if (window) {
|
|
68
60
|
return _qs.default.parse(window.location.href.split("?")[1]);
|
|
69
61
|
}
|
|
70
|
-
|
|
71
62
|
return undefined;
|
|
72
63
|
}
|
|
73
|
-
|
|
74
64
|
function getOtpUrlParams() {
|
|
75
65
|
return Object.keys(getUrlParams()).filter(key => !key.startsWith("ui_"));
|
|
76
66
|
}
|
|
77
|
-
|
|
78
67
|
function getTripOptionsFromQuery(query, keepPlace = false) {
|
|
79
|
-
const options = {
|
|
80
|
-
|
|
81
|
-
|
|
68
|
+
const options = {
|
|
69
|
+
...query
|
|
70
|
+
};
|
|
71
|
+
// Delete time/date options and from/to
|
|
82
72
|
delete options.time;
|
|
83
73
|
delete options.departArrive;
|
|
84
74
|
delete options.date;
|
|
85
|
-
|
|
86
75
|
if (!keepPlace) {
|
|
87
76
|
delete options.from;
|
|
88
77
|
delete options.to;
|
|
89
78
|
}
|
|
90
|
-
|
|
91
79
|
return options;
|
|
92
80
|
}
|
|
81
|
+
|
|
93
82
|
/**
|
|
94
83
|
* Gets the query param's default value that is either a constant or by
|
|
95
84
|
* executing the default value function.
|
|
96
85
|
*/
|
|
97
|
-
|
|
98
|
-
|
|
99
86
|
function getDefaultQueryParamValue(param) {
|
|
100
87
|
return typeof param.default === "function" ? param.default() : param.default;
|
|
101
88
|
}
|
|
89
|
+
|
|
102
90
|
/**
|
|
103
91
|
* Get the default query to OTP based on the given config.
|
|
104
92
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
93
|
function getDefaultQuery(config = null) {
|
|
108
94
|
const defaultQuery = {
|
|
109
95
|
routingType: "ITINERARY"
|
|
110
96
|
};
|
|
111
|
-
|
|
112
97
|
_queryParams.default.filter(qp => "default" in qp).forEach(qp => {
|
|
113
98
|
defaultQuery[qp.name] = getDefaultQueryParamValue(qp);
|
|
114
99
|
});
|
|
115
|
-
|
|
116
100
|
if (config) {
|
|
117
101
|
if (config.routingTypes && config.routingTypes.length > 0) {
|
|
118
102
|
defaultQuery.routingType = config.routingTypes[0].key;
|
|
119
103
|
}
|
|
120
|
-
|
|
121
104
|
if (config.defaultQueryParams) {
|
|
122
105
|
Object.keys(config.defaultQueryParams).forEach(key => {
|
|
123
106
|
defaultQuery[key] = config.defaultQueryParams[key];
|
|
124
107
|
});
|
|
125
108
|
}
|
|
126
109
|
}
|
|
127
|
-
|
|
128
110
|
return defaultQuery;
|
|
129
111
|
}
|
|
112
|
+
|
|
130
113
|
/**
|
|
131
114
|
* Determine if the specified query param applies to the given query (based on
|
|
132
115
|
* routing type and the param's own applicable function).
|
|
@@ -135,50 +118,44 @@ function getDefaultQuery(config = null) {
|
|
|
135
118
|
* @param config OTP config
|
|
136
119
|
* @return {Boolean}
|
|
137
120
|
*/
|
|
138
|
-
|
|
139
|
-
|
|
140
121
|
function isParamApplicable(paramInfo, query, config) {
|
|
141
122
|
const {
|
|
142
123
|
applicable,
|
|
143
124
|
routingTypes
|
|
144
125
|
} = paramInfo;
|
|
145
126
|
if (!routingTypes.includes(query.routingType)) return false;
|
|
146
|
-
|
|
147
127
|
if (typeof applicable === "function" && !applicable(query, config)) {
|
|
148
128
|
return false;
|
|
149
129
|
}
|
|
150
|
-
|
|
151
130
|
return true;
|
|
152
131
|
}
|
|
132
|
+
|
|
153
133
|
/**
|
|
154
134
|
* Helper method which replaces OTP flex modes with single FLEX mode that's
|
|
155
135
|
* more useful and easier to work with.
|
|
156
136
|
*/
|
|
157
|
-
|
|
158
|
-
|
|
159
137
|
function reduceOtpFlexModes(modes, enabled = true) {
|
|
160
138
|
if (!enabled) return modes;
|
|
161
139
|
return modes.reduce((prev, cur) => {
|
|
162
|
-
const newModes = prev;
|
|
163
|
-
|
|
140
|
+
const newModes = prev;
|
|
141
|
+
// Add the current mode if it is not a flex mode
|
|
164
142
|
if (!cur.includes("FLEX")) {
|
|
165
|
-
newModes.push(cur);
|
|
143
|
+
newModes.push(cur);
|
|
144
|
+
// If it is a flex mode, do not add it but rather add the custom flex mode
|
|
166
145
|
// if not already present
|
|
167
146
|
} else if (!newModes.includes("FLEX")) {
|
|
168
147
|
newModes.push("FLEX");
|
|
169
148
|
}
|
|
170
|
-
|
|
171
149
|
return newModes;
|
|
172
150
|
}, []);
|
|
173
151
|
}
|
|
152
|
+
|
|
174
153
|
/**
|
|
175
154
|
* Helper method to process a mode string, replacing all instances of FLEX
|
|
176
155
|
* with the full set of FLEX modes used by otp-2
|
|
177
156
|
* @param {*} mode a mode String, not an array
|
|
178
157
|
* @returns a mode String, not an array (with flex modes expanded)
|
|
179
158
|
*/
|
|
180
|
-
|
|
181
|
-
|
|
182
159
|
function expandOtpFlexMode(mode) {
|
|
183
160
|
const modes = reduceOtpFlexModes(mode.split(","));
|
|
184
161
|
return modes.map(m => {
|
|
@@ -186,26 +163,20 @@ function expandOtpFlexMode(mode) {
|
|
|
186
163
|
if (m === "FLEX_EGRESS" || m === "FLEX_ACCESS" || m === "FLEX_DIRECT") {
|
|
187
164
|
if (mode.includes("FLEX")) return "";
|
|
188
165
|
}
|
|
189
|
-
|
|
190
166
|
if (m === "FLEX") {
|
|
191
167
|
return "FLEX_EGRESS,FLEX_ACCESS,FLEX_DIRECT";
|
|
192
168
|
}
|
|
193
|
-
|
|
194
169
|
return m;
|
|
195
170
|
}).join(",");
|
|
196
171
|
}
|
|
172
|
+
|
|
197
173
|
/**
|
|
198
174
|
* Determines whether the specified query differs from the default query, i.e.,
|
|
199
175
|
* whether the user has modified any trip options (including mode) from their
|
|
200
176
|
* default values.
|
|
201
177
|
*/
|
|
202
|
-
|
|
203
|
-
|
|
204
178
|
function isNotDefaultQuery(query, config) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const activeModes = reduceOtpFlexModes(query.mode.split(",").sort(), (_config$modes = config.modes) === null || _config$modes === void 0 ? void 0 : _config$modes.mergeFlex);
|
|
208
|
-
|
|
179
|
+
const activeModes = reduceOtpFlexModes(query.mode.split(",").sort(), config.modes?.mergeFlex);
|
|
209
180
|
if (activeModes.length !== 2 || activeModes[0] !== "TRANSIT" || activeModes[1] !== "WALK") {
|
|
210
181
|
// Default mode is TRANSIT,WALK. If general TRANSIT is not used, check
|
|
211
182
|
// against available transit modes in config.
|
|
@@ -214,25 +185,21 @@ function isNotDefaultQuery(query, config) {
|
|
|
214
185
|
return value === defaultModes[index];
|
|
215
186
|
});
|
|
216
187
|
if (!modesEqual) return true;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
188
|
+
}
|
|
189
|
+
// If modes are equal, check the remaining params.
|
|
220
190
|
const defaultQuery = getDefaultQuery(config);
|
|
221
|
-
|
|
222
191
|
for (let i = 0; i < defaultParams.length; i++) {
|
|
223
192
|
const param = defaultParams[i];
|
|
224
|
-
|
|
225
|
-
|
|
193
|
+
const paramInfo = _queryParams.default.find(qp => qp.name === param);
|
|
194
|
+
// If the parameter applies to the query and does not match the default
|
|
226
195
|
// value, the query is not default.
|
|
227
|
-
|
|
228
|
-
|
|
229
196
|
if (isParamApplicable(paramInfo, query, config) && query[param] !== defaultQuery[param]) {
|
|
230
197
|
return true;
|
|
231
198
|
}
|
|
232
199
|
}
|
|
233
|
-
|
|
234
200
|
return false;
|
|
235
201
|
}
|
|
202
|
+
|
|
236
203
|
/**
|
|
237
204
|
* Geocode utility for returning the first result for the provided place name text.
|
|
238
205
|
* @param {string} text - text to search
|
|
@@ -240,24 +207,21 @@ function isNotDefaultQuery(query, config) {
|
|
|
240
207
|
* @param {string} geocoderMethod - an alternate geocoder api method to use. Defaults to `search`
|
|
241
208
|
* @return {Location}
|
|
242
209
|
*/
|
|
243
|
-
|
|
244
|
-
|
|
245
210
|
async function getFirstGeocodeResult(text, geocoderConfig, geocoderMethod = "search") {
|
|
246
|
-
const geocoder = (0, _lib.default)(geocoderConfig);
|
|
211
|
+
const geocoder = (0, _lib.default)(geocoderConfig);
|
|
212
|
+
// Attempt to geocode search text and return first result if found.
|
|
247
213
|
// TODO: Import geocoder from @opentripplanner
|
|
248
|
-
|
|
249
214
|
return geocoder[geocoderMethod]({
|
|
250
215
|
text
|
|
251
216
|
}).then(result => {
|
|
252
217
|
const firstResult = result.features && result.features[0];
|
|
253
|
-
|
|
254
218
|
if (firstResult) {
|
|
255
219
|
return geocoder.getLocationFromGeocodedFeature(firstResult);
|
|
256
220
|
}
|
|
257
|
-
|
|
258
221
|
return null;
|
|
259
222
|
});
|
|
260
223
|
}
|
|
224
|
+
|
|
261
225
|
/**
|
|
262
226
|
* OTP allows passing a location in the form '123 Main St::lat,lon', so we check
|
|
263
227
|
* for the double colon and parse the coordinates accordingly.
|
|
@@ -265,8 +229,6 @@ async function getFirstGeocodeResult(text, geocoderConfig, geocoderMethod = "sea
|
|
|
265
229
|
* @return {Location} - location or null if the value is falsey or the parsed
|
|
266
230
|
* coordinates do not result in both a lat and lon
|
|
267
231
|
*/
|
|
268
|
-
|
|
269
|
-
|
|
270
232
|
function parseLocationString(value) {
|
|
271
233
|
if (!value) return null;
|
|
272
234
|
const parts = value.split("::");
|
|
@@ -278,6 +240,7 @@ function parseLocationString(value) {
|
|
|
278
240
|
lon: coordinates[1] || null
|
|
279
241
|
} : null;
|
|
280
242
|
}
|
|
243
|
+
|
|
281
244
|
/**
|
|
282
245
|
* Convert a string query param for a from or to place into a location. If
|
|
283
246
|
* coordinates not provided and geocoder config is present, use the first
|
|
@@ -286,27 +249,22 @@ function parseLocationString(value) {
|
|
|
286
249
|
* @param {Object} [geocoderConfig=null]
|
|
287
250
|
* @return {Location}
|
|
288
251
|
*/
|
|
289
|
-
|
|
290
|
-
|
|
291
252
|
async function queryParamToLocation(value, geocoderConfig) {
|
|
292
253
|
let location = parseLocationString(value);
|
|
293
|
-
|
|
294
254
|
if (!location && value && geocoderConfig) {
|
|
295
255
|
// If a valid location was not found, but the place name text exists,
|
|
296
256
|
// attempt to geocode the name.
|
|
297
257
|
location = await getFirstGeocodeResult(value, geocoderConfig, geocoderConfig.autoMethod);
|
|
298
258
|
}
|
|
299
|
-
|
|
300
259
|
return location;
|
|
301
260
|
}
|
|
261
|
+
|
|
302
262
|
/**
|
|
303
263
|
* Create a otp query based on a the url params.
|
|
304
264
|
*
|
|
305
265
|
* @param {Object} params An object representing the parsed querystring of url
|
|
306
266
|
* params.
|
|
307
267
|
*/
|
|
308
|
-
|
|
309
|
-
|
|
310
268
|
function planParamsToQuery(params) {
|
|
311
269
|
const query = {};
|
|
312
270
|
Object.keys(params).forEach(key => {
|
|
@@ -314,19 +272,15 @@ function planParamsToQuery(params) {
|
|
|
314
272
|
case "fromPlace":
|
|
315
273
|
query.from = parseLocationString(params.fromPlace);
|
|
316
274
|
break;
|
|
317
|
-
|
|
318
275
|
case "toPlace":
|
|
319
276
|
query.to = parseLocationString(params.toPlace);
|
|
320
277
|
break;
|
|
321
|
-
|
|
322
278
|
case "arriveBy":
|
|
323
279
|
query.departArrive = params.arriveBy === "true" ? "ARRIVE" : params.arriveBy === "false" ? "DEPART" : "NOW";
|
|
324
280
|
break;
|
|
325
|
-
|
|
326
281
|
case "date":
|
|
327
282
|
query.date = params.date || (0, _time.getCurrentDate)();
|
|
328
283
|
break;
|
|
329
|
-
|
|
330
284
|
case "time":
|
|
331
285
|
{
|
|
332
286
|
// Match one of the supported time formats
|
|
@@ -334,19 +288,17 @@ function planParamsToQuery(params) {
|
|
|
334
288
|
query.time = matchedTimeFormat ? (0, _dateFns.format)((0, _dateFns.parse)(params.time, matchedTimeFormat, new Date()), _time.OTP_API_TIME_FORMAT) : (0, _time.getCurrentTime)();
|
|
335
289
|
}
|
|
336
290
|
break;
|
|
337
|
-
|
|
338
291
|
case "intermediatePlaces":
|
|
339
292
|
// If query has intermediate places, ensure that they are parsed
|
|
340
293
|
// as locations.
|
|
341
294
|
query.intermediatePlaces = params.intermediatePlaces ? params.intermediatePlaces.map(parseLocationString) : [];
|
|
342
295
|
break;
|
|
343
|
-
|
|
344
296
|
default:
|
|
345
297
|
{
|
|
346
|
-
const maybeNumber = Number(params[key]);
|
|
298
|
+
const maybeNumber = Number(params[key]);
|
|
299
|
+
// If the param value is an empty string literal and is not a number,
|
|
347
300
|
// use string value. Else, use parsed number value.
|
|
348
301
|
// See https://github.com/opentripplanner/otp-ui/issues/50
|
|
349
|
-
|
|
350
302
|
query[key] = params[key] === "" || Number.isNaN(maybeNumber) ? params[key] : maybeNumber;
|
|
351
303
|
break;
|
|
352
304
|
}
|
|
@@ -354,6 +306,7 @@ function planParamsToQuery(params) {
|
|
|
354
306
|
});
|
|
355
307
|
return query;
|
|
356
308
|
}
|
|
309
|
+
|
|
357
310
|
/**
|
|
358
311
|
* Async method to create a otp query based on a the url params. This provides
|
|
359
312
|
* the same functionality as planParamsToQuery, except that it will also attempt
|
|
@@ -363,23 +316,20 @@ function planParamsToQuery(params) {
|
|
|
363
316
|
* params.
|
|
364
317
|
* @param config the config in the otp-rr store.
|
|
365
318
|
*/
|
|
366
|
-
|
|
367
|
-
|
|
368
319
|
async function planParamsToQueryAsync(params, config = {}) {
|
|
369
320
|
// Construct query from plan params.
|
|
370
|
-
const query = planParamsToQuery(params);
|
|
321
|
+
const query = planParamsToQuery(params);
|
|
322
|
+
// Attempt to geocode from and to params if the string parsing does not return
|
|
371
323
|
// valid locations.
|
|
372
|
-
|
|
373
324
|
if (!query.from) {
|
|
374
325
|
query.from = await queryParamToLocation(params.fromPlace, config.geocoder);
|
|
375
326
|
}
|
|
376
|
-
|
|
377
327
|
if (!query.to) {
|
|
378
328
|
query.to = await queryParamToLocation(params.toPlace, config.geocoder);
|
|
379
329
|
}
|
|
380
|
-
|
|
381
330
|
return query;
|
|
382
331
|
}
|
|
332
|
+
|
|
383
333
|
/**
|
|
384
334
|
* Create an object that can be used as a querystring in making an OTP
|
|
385
335
|
* PlannerResource request.
|
|
@@ -393,15 +343,12 @@ async function planParamsToQueryAsync(params, config = {}) {
|
|
|
393
343
|
* @param {boolean} ignoreRealtimeUpdates If true, will create a request that
|
|
394
344
|
* does not use realtime data.
|
|
395
345
|
*/
|
|
396
|
-
|
|
397
|
-
|
|
398
346
|
function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {
|
|
399
|
-
var _config$modes2;
|
|
400
|
-
|
|
401
347
|
const routingType = currentQuery.routingType;
|
|
402
348
|
const isItinerary = routingType === "ITINERARY";
|
|
403
|
-
let params = {};
|
|
349
|
+
let params = {};
|
|
404
350
|
|
|
351
|
+
// Start with the universe of OTP parameters defined in query-params.js:
|
|
405
352
|
_queryParams.default.filter(qp => {
|
|
406
353
|
// A given parameter is included in the request if all of the following:
|
|
407
354
|
// 1. Must apply to the active routing type (ITINERARY or PROFILE)
|
|
@@ -415,61 +362,60 @@ function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {
|
|
|
415
362
|
params = Object.assign(params, rewriteFunction ? rewriteFunction(currentQuery[qp.name]) : {
|
|
416
363
|
[qp.name]: currentQuery[qp.name]
|
|
417
364
|
});
|
|
418
|
-
});
|
|
419
|
-
|
|
365
|
+
});
|
|
420
366
|
|
|
367
|
+
// Additional processing specific to ITINERARY mode
|
|
421
368
|
if (isItinerary) {
|
|
422
369
|
// override ignoreRealtimeUpdates if provided
|
|
423
370
|
if (typeof ignoreRealtimeUpdates === "boolean") {
|
|
424
371
|
params.ignoreRealtimeUpdates = ignoreRealtimeUpdates;
|
|
425
|
-
}
|
|
426
|
-
|
|
372
|
+
}
|
|
427
373
|
|
|
374
|
+
// check date/time validity; ignore both if either is invalid
|
|
428
375
|
const dateValid = (0, _dateFns.isMatch)(params.date, _time.OTP_API_DATE_FORMAT);
|
|
429
376
|
const timeValid = (0, _dateFns.isMatch)(params.time, _time.OTP_API_TIME_FORMAT);
|
|
430
|
-
|
|
431
377
|
if (!dateValid || !timeValid) {
|
|
432
378
|
delete params.time;
|
|
433
379
|
delete params.date;
|
|
434
|
-
}
|
|
435
|
-
|
|
380
|
+
}
|
|
436
381
|
|
|
382
|
+
// temp: set additional parameters for CAR_HAIL or CAR_RENT trips
|
|
437
383
|
if (params.mode && (params.mode.includes("CAR_HAIL") || params.mode.includes("CAR_RENT"))) {
|
|
438
|
-
params.minTransitDistance = "50%";
|
|
439
|
-
|
|
384
|
+
params.minTransitDistance = "50%";
|
|
385
|
+
// increase search timeout because these queries can take a while
|
|
440
386
|
params.searchTimeout = 10000;
|
|
441
|
-
}
|
|
442
|
-
|
|
387
|
+
}
|
|
443
388
|
|
|
389
|
+
// set onlyTransitTrips for car rental searches
|
|
444
390
|
if (params.mode && params.mode.includes("CAR_RENT")) {
|
|
445
391
|
params.onlyTransitTrips = true;
|
|
446
|
-
}
|
|
392
|
+
}
|
|
447
393
|
|
|
394
|
+
// Additional processing specific to PROFILE mode
|
|
448
395
|
} else {
|
|
449
396
|
// check start and end time validity; ignore both if either is invalid
|
|
450
397
|
const startTimeValid = (0, _dateFns.isMatch)(params.startTime, _time.OTP_API_TIME_FORMAT);
|
|
451
398
|
const endTimeValid = (0, _dateFns.isMatch)(params.endTime, _time.OTP_API_TIME_FORMAT);
|
|
452
|
-
|
|
453
399
|
if (!startTimeValid || !endTimeValid) {
|
|
454
400
|
delete params.startTimeValid;
|
|
455
401
|
delete params.endTimeValid;
|
|
456
402
|
}
|
|
457
|
-
}
|
|
458
|
-
// hack to add walking to driving/TNC trips
|
|
403
|
+
}
|
|
459
404
|
|
|
405
|
+
// TODO: check that valid from/to locations are provided
|
|
460
406
|
|
|
407
|
+
// hack to add walking to driving/TNC trips
|
|
461
408
|
if ((0, _itinerary.hasCar)(params.mode)) {
|
|
462
409
|
params.mode += ",WALK";
|
|
463
|
-
}
|
|
464
|
-
// Explicit false check allows avoiding a breaking change -- undefined is true
|
|
465
|
-
|
|
410
|
+
}
|
|
466
411
|
|
|
467
|
-
|
|
412
|
+
// Replace FLEX placeholder with OTP flex modes
|
|
413
|
+
// Explicit false check allows avoiding a breaking change -- undefined is true
|
|
414
|
+
if (params.mode && config.modes?.mergeFlex !== false) {
|
|
468
415
|
// Ensure query is in reduced format to avoid replacing twice
|
|
469
416
|
const reducedMode = reduceOtpFlexModes(params.mode.split(",")).join(",");
|
|
470
417
|
params.mode = expandOtpFlexMode(reducedMode);
|
|
471
418
|
}
|
|
472
|
-
|
|
473
419
|
return params;
|
|
474
420
|
}
|
|
475
421
|
//# sourceMappingURL=query.js.map
|
package/lib/query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/query.js"],"names":["defaultParams","TIME_FORMATS","getQueryParamProperty","paramInfo","property","query","ensureSingleAccessMode","queryModes","accessCount","filter","m","length","firstAccess","find","push","getUrlParams","window","qs","parse","location","href","split","undefined","getOtpUrlParams","Object","keys","key","startsWith","getTripOptionsFromQuery","keepPlace","options","time","departArrive","date","from","to","getDefaultQueryParamValue","param","default","getDefaultQuery","config","defaultQuery","routingType","queryParams","qp","forEach","name","routingTypes","defaultQueryParams","isParamApplicable","applicable","includes","reduceOtpFlexModes","modes","enabled","reduce","prev","cur","newModes","expandOtpFlexMode","mode","map","join","isNotDefaultQuery","activeModes","sort","mergeFlex","defaultModes","concat","modesEqual","every","value","index","i","getFirstGeocodeResult","text","geocoderConfig","geocoderMethod","geocoder","then","result","firstResult","features","getLocationFromGeocodedFeature","parseLocationString","parts","coordinates","lat","lon","queryParamToLocation","autoMethod","planParamsToQuery","params","fromPlace","toPlace","arriveBy","matchedTimeFormat","timeFormat","Date","OTP_API_TIME_FORMAT","intermediatePlaces","maybeNumber","Number","isNaN","planParamsToQueryAsync","getRoutingParams","currentQuery","ignoreRealtimeUpdates","isItinerary","indexOf","rewriteFunction","itineraryRewrite","profileRewrite","assign","dateValid","OTP_API_DATE_FORMAT","timeValid","minTransitDistance","searchTimeout","onlyTransitTrips","startTimeValid","startTime","endTimeValid","endTime","reducedMode"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAOA;AAEO,MAAMA,aAAa,GAAG,CAC3B,YAD2B,EAE3B,iBAF2B,EAG3B,gBAH2B,EAI3B,aAJ2B,EAK3B,iBAL2B,EAM3B,aAN2B,EAO3B,WAP2B,EAQ3B,UAR2B,EAS3B,cAT2B,EAU3B,qBAV2B,EAW3B,OAX2B,CAAtB;AAcP;AACA;AACA;;;AACA,MAAMC,YAAY,GAAG,CACnB,UADmB,EAEnB,OAFmB,EAGnB,MAHmB,EAInB,WAJmB,EAKnB,UALmB,EAMnB,QANmB,EAOnB,OAPmB,EAQnB,MARmB,EASnB,MATmB,EAUnB,KAVmB,EAWnB,IAXmB,CAArB;AAcA;AACA;;AAEO,SAASC,qBAAT,CAA+BC,SAA/B,EAA0CC,QAA1C,EAAoDC,KAApD,EAA2D;AAChE,SAAO,OAAOF,SAAS,CAACC,QAAD,CAAhB,KAA+B,UAA/B,GACHD,SAAS,CAACC,QAAD,CAAT,CAAoBC,KAApB,CADG,GAEHF,SAAS,CAACC,QAAD,CAFb;AAGD;;AAEM,SAASE,sBAAT,CAAgCC,UAAhC,EAA4C;AACjD;AACA,QAAMC,WAAW,GAAGD,UAAU,CAACE,MAAX,CAAkBC,CAAC,IAAI,6BAAaA,CAAb,CAAvB,EAAwCC,MAA5D,CAFiD,CAIjD;;AACA,MAAIH,WAAW,GAAG,CAAlB,EAAqB;AACnB,UAAMI,WAAW,GAAGL,UAAU,CAACM,IAAX,CAAgBH,CAAC,IAAI,6BAAaA,CAAb,CAArB,CAApB;AACAH,IAAAA,UAAU,GAAGA,UAAU,CAACE,MAAX,CAAkBC,CAAC,IAAI,CAAC,6BAAaA,CAAb,CAAD,IAAoBA,CAAC,KAAKE,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AAChC,IAAP,GAAcD,iBAAiB,CAACiE,WAAD,CAA/B;AACD;;AAED,SAAOhC,MAAP;AACD","sourcesContent":["import { format, isMatch, parse } from \"date-fns\";\nimport getGeocoder from \"@opentripplanner/geocoder/lib\";\nimport qs from \"qs\";\n\nimport { getTransitModes, hasCar, isAccessMode } from \"./itinerary\";\nimport { coordsToString, stringToCoords } from \"./map\";\nimport queryParams from \"./query-params\";\nimport {\n getCurrentTime,\n getCurrentDate,\n OTP_API_DATE_FORMAT,\n OTP_API_TIME_FORMAT\n} from \"./time\";\n\n/* The list of default parameters considered in the settings panel */\n\nexport const defaultParams = [\n \"wheelchair\",\n \"maxWalkDistance\",\n \"walkReluctance\",\n \"maxWalkTime\",\n \"maxBikeDistance\",\n \"maxBikeTime\",\n \"bikeSpeed\",\n \"optimize\",\n \"optimizeBike\",\n \"maxEScooterDistance\",\n \"watts\"\n];\n\n/**\n * List of time formats to parse when reading query params.\n */\nconst TIME_FORMATS = [\n \"HH:mm:ss\",\n \"HH:mm\",\n \"H:mm\",\n \"h:mm:ss a\",\n \"h:mm:ssa\",\n \"h:mm a\",\n \"h:mma\",\n \"h:mm\",\n \"HHmm\",\n \"hmm\",\n \"ha\"\n];\n\n/* A function to retrieve a property value from an entry in the query-params\n * table, checking for either a static value or a function */\n\nexport function getQueryParamProperty(paramInfo, property, query) {\n return typeof paramInfo[property] === \"function\"\n ? paramInfo[property](query)\n : paramInfo[property];\n}\n\nexport function ensureSingleAccessMode(queryModes) {\n // Count the number of access modes\n const accessCount = queryModes.filter(m => isAccessMode(m)).length;\n\n // If multiple access modes are specified, keep only the first one\n if (accessCount > 1) {\n const firstAccess = queryModes.find(m => isAccessMode(m));\n queryModes = queryModes.filter(m => !isAccessMode(m) || m === firstAccess);\n\n // If no access modes are specified, add 'WALK' as the default\n } else if (accessCount === 0) {\n queryModes.push(\"WALK\");\n }\n\n return queryModes;\n}\n\nexport function getUrlParams() {\n if (window) {\n return qs.parse(window.location.href.split(\"?\")[1]);\n }\n return undefined;\n}\n\nexport function getOtpUrlParams() {\n return Object.keys(getUrlParams()).filter(key => !key.startsWith(\"ui_\"));\n}\n\nexport function getTripOptionsFromQuery(query, keepPlace = false) {\n const options = { ...query };\n // Delete time/date options and from/to\n delete options.time;\n delete options.departArrive;\n delete options.date;\n if (!keepPlace) {\n delete options.from;\n delete options.to;\n }\n return options;\n}\n\n/**\n * Gets the query param's default value that is either a constant or by\n * executing the default value function.\n */\nfunction getDefaultQueryParamValue(param) {\n return typeof param.default === \"function\" ? param.default() : param.default;\n}\n\n/**\n * Get the default query to OTP based on the given config.\n */\nexport function getDefaultQuery(config = null) {\n const defaultQuery = { routingType: \"ITINERARY\" };\n queryParams\n .filter(qp => \"default\" in qp)\n .forEach(qp => {\n defaultQuery[qp.name] = getDefaultQueryParamValue(qp);\n });\n if (config) {\n if (config.routingTypes && config.routingTypes.length > 0) {\n defaultQuery.routingType = config.routingTypes[0].key;\n }\n if (config.defaultQueryParams) {\n Object.keys(config.defaultQueryParams).forEach(key => {\n defaultQuery[key] = config.defaultQueryParams[key];\n });\n }\n }\n return defaultQuery;\n}\n\n/**\n * Determine if the specified query param applies to the given query (based on\n * routing type and the param's own applicable function).\n * @param paramInfo an entry from query-params.js\n * @param query the query against which to check if the param applies\n * @param config OTP config\n * @return {Boolean}\n */\nfunction isParamApplicable(paramInfo, query, config) {\n const { applicable, routingTypes } = paramInfo;\n if (!routingTypes.includes(query.routingType)) return false;\n if (typeof applicable === \"function\" && !applicable(query, config)) {\n return false;\n }\n return true;\n}\n\n/**\n * Helper method which replaces OTP flex modes with single FLEX mode that's\n * more useful and easier to work with.\n */\nexport function reduceOtpFlexModes(modes, enabled = true) {\n if (!enabled) return modes;\n\n return modes.reduce((prev, cur) => {\n const newModes = prev;\n // Add the current mode if it is not a flex mode\n if (!cur.includes(\"FLEX\")) {\n newModes.push(cur);\n // If it is a flex mode, do not add it but rather add the custom flex mode\n // if not already present\n } else if (!newModes.includes(\"FLEX\")) {\n newModes.push(\"FLEX\");\n }\n return newModes;\n }, []);\n}\n\n/**\n * Helper method to process a mode string, replacing all instances of FLEX\n * with the full set of FLEX modes used by otp-2\n * @param {*} mode a mode String, not an array\n * @returns a mode String, not an array (with flex modes expanded)\n */\nexport function expandOtpFlexMode(mode) {\n const modes = reduceOtpFlexModes(mode.split(\",\"));\n return modes\n .map(m => {\n // If both the expanded and shrunk modes are included, remove the expanded one\n if (m === \"FLEX_EGRESS\" || m === \"FLEX_ACCESS\" || m === \"FLEX_DIRECT\") {\n if (mode.includes(\"FLEX\")) return \"\";\n }\n if (m === \"FLEX\") {\n return \"FLEX_EGRESS,FLEX_ACCESS,FLEX_DIRECT\";\n }\n return m;\n })\n .join(\",\");\n}\n\n/**\n * Determines whether the specified query differs from the default query, i.e.,\n * whether the user has modified any trip options (including mode) from their\n * default values.\n */\nexport function isNotDefaultQuery(query, config) {\n const activeModes = reduceOtpFlexModes(\n query.mode.split(\",\").sort(),\n config.modes?.mergeFlex\n );\n if (\n activeModes.length !== 2 ||\n activeModes[0] !== \"TRANSIT\" ||\n activeModes[1] !== \"WALK\"\n ) {\n // Default mode is TRANSIT,WALK. If general TRANSIT is not used, check\n // against available transit modes in config.\n const defaultModes = getTransitModes(config)\n .concat([\"WALK\"])\n .sort();\n const modesEqual =\n activeModes.length === defaultModes.length &&\n activeModes.every((value, index) => {\n return value === defaultModes[index];\n });\n if (!modesEqual) return true;\n }\n // If modes are equal, check the remaining params.\n const defaultQuery = getDefaultQuery(config);\n for (let i = 0; i < defaultParams.length; i++) {\n const param = defaultParams[i];\n const paramInfo = queryParams.find(qp => qp.name === param);\n // If the parameter applies to the query and does not match the default\n // value, the query is not default.\n if (\n isParamApplicable(paramInfo, query, config) &&\n query[param] !== defaultQuery[param]\n ) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Geocode utility for returning the first result for the provided place name text.\n * @param {string} text - text to search\n * @param {Object} geocoderConfig\n * @param {string} geocoderMethod - an alternate geocoder api method to use. Defaults to `search`\n * @return {Location}\n */\nasync function getFirstGeocodeResult(\n text,\n geocoderConfig,\n geocoderMethod = \"search\"\n) {\n const geocoder = getGeocoder(geocoderConfig);\n // Attempt to geocode search text and return first result if found.\n // TODO: Import geocoder from @opentripplanner\n return geocoder[geocoderMethod]({ text }).then(result => {\n const firstResult = result.features && result.features[0];\n if (firstResult) {\n return geocoder.getLocationFromGeocodedFeature(firstResult);\n }\n return null;\n });\n}\n\n/**\n * OTP allows passing a location in the form '123 Main St::lat,lon', so we check\n * for the double colon and parse the coordinates accordingly.\n * @param {string} value - query param for place described above\n * @return {Location} - location or null if the value is falsey or the parsed\n * coordinates do not result in both a lat and lon\n */\nexport function parseLocationString(value) {\n if (!value) return null;\n const parts = value.split(\"::\");\n const coordinates = parts[1]\n ? stringToCoords(parts[1])\n : stringToCoords(parts[0]);\n const name = parts[1] ? parts[0] : coordsToString(coordinates);\n return coordinates.length === 2\n ? {\n name: name || null,\n lat: coordinates[0] || null,\n lon: coordinates[1] || null\n }\n : null;\n}\n\n/**\n * Convert a string query param for a from or to place into a location. If\n * coordinates not provided and geocoder config is present, use the first\n * geocoded result.\n * @param {string} value\n * @param {Object} [geocoderConfig=null]\n * @return {Location}\n */\nasync function queryParamToLocation(value, geocoderConfig) {\n let location = parseLocationString(value);\n if (!location && value && geocoderConfig) {\n // If a valid location was not found, but the place name text exists,\n // attempt to geocode the name.\n location = await getFirstGeocodeResult(\n value,\n geocoderConfig,\n geocoderConfig.autoMethod\n );\n }\n return location;\n}\n\n/**\n * Create a otp query based on a the url params.\n *\n * @param {Object} params An object representing the parsed querystring of url\n * params.\n */\nexport function planParamsToQuery(params) {\n const query = {};\n Object.keys(params).forEach(key => {\n switch (key) {\n case \"fromPlace\":\n query.from = parseLocationString(params.fromPlace);\n break;\n case \"toPlace\":\n query.to = parseLocationString(params.toPlace);\n break;\n case \"arriveBy\":\n query.departArrive =\n params.arriveBy === \"true\"\n ? \"ARRIVE\"\n : params.arriveBy === \"false\"\n ? \"DEPART\"\n : \"NOW\";\n break;\n case \"date\":\n query.date = params.date || getCurrentDate();\n break;\n case \"time\":\n {\n // Match one of the supported time formats\n const matchedTimeFormat = TIME_FORMATS.find(timeFormat =>\n isMatch(params.time, timeFormat)\n );\n query.time = matchedTimeFormat\n ? format(\n parse(params.time, matchedTimeFormat, new Date()),\n OTP_API_TIME_FORMAT\n )\n : getCurrentTime();\n }\n break;\n case \"intermediatePlaces\":\n // If query has intermediate places, ensure that they are parsed\n // as locations.\n query.intermediatePlaces = params.intermediatePlaces\n ? params.intermediatePlaces.map(parseLocationString)\n : [];\n break;\n default: {\n const maybeNumber = Number(params[key]);\n // If the param value is an empty string literal and is not a number,\n // use string value. Else, use parsed number value.\n // See https://github.com/opentripplanner/otp-ui/issues/50\n query[key] =\n params[key] === \"\" || Number.isNaN(maybeNumber)\n ? params[key]\n : maybeNumber;\n break;\n }\n }\n });\n return query;\n}\n\n/**\n * Async method to create a otp query based on a the url params. This provides\n * the same functionality as planParamsToQuery, except that it will also attempt\n * to geocode the input from and to strings if no lat/lng values were provided.\n *\n * @param {Object} params An object representing the parsed querystring of url\n * params.\n * @param config the config in the otp-rr store.\n */\nexport async function planParamsToQueryAsync(params, config = {}) {\n // Construct query from plan params.\n const query = planParamsToQuery(params);\n // Attempt to geocode from and to params if the string parsing does not return\n // valid locations.\n if (!query.from) {\n query.from = await queryParamToLocation(params.fromPlace, config.geocoder);\n }\n if (!query.to) {\n query.to = await queryParamToLocation(params.toPlace, config.geocoder);\n }\n return query;\n}\n\n/**\n * Create an object that can be used as a querystring in making an OTP\n * PlannerResource request.\n *\n * See http://otp-docs.ibi-transit.com/api/resource_PlannerResource.html\n *\n * @param {Object} config The OTP application config. See types#configType\n * @param {Object} currentQuery The current query parameters as saved in the\n * application state. This method does some extra logic on top of this data\n * in order to create a request suitable for OTP. See __tests__/query.js#L14 for more.\n * @param {boolean} ignoreRealtimeUpdates If true, will create a request that\n * does not use realtime data.\n */\nexport function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {\n const routingType = currentQuery.routingType;\n const isItinerary = routingType === \"ITINERARY\";\n let params = {};\n\n // Start with the universe of OTP parameters defined in query-params.js:\n queryParams\n .filter(qp => {\n // A given parameter is included in the request if all of the following:\n // 1. Must apply to the active routing type (ITINERARY or PROFILE)\n // 2. Must be included in the current user-defined query\n // 3. Must pass the parameter's applicability test, if one is specified\n return (\n qp.routingTypes.indexOf(routingType) !== -1 &&\n qp.name in currentQuery &&\n (typeof qp.applicable !== \"function\" ||\n qp.applicable(currentQuery, config))\n );\n })\n .forEach(qp => {\n // Translate the applicable parameters according to their rewrite\n // functions (if provided)\n const rewriteFunction = isItinerary\n ? qp.itineraryRewrite\n : qp.profileRewrite;\n params = Object.assign(\n params,\n rewriteFunction\n ? rewriteFunction(currentQuery[qp.name])\n : { [qp.name]: currentQuery[qp.name] }\n );\n });\n\n // Additional processing specific to ITINERARY mode\n if (isItinerary) {\n // override ignoreRealtimeUpdates if provided\n if (typeof ignoreRealtimeUpdates === \"boolean\") {\n params.ignoreRealtimeUpdates = ignoreRealtimeUpdates;\n }\n\n // check date/time validity; ignore both if either is invalid\n const dateValid = isMatch(params.date, OTP_API_DATE_FORMAT);\n const timeValid = isMatch(params.time, OTP_API_TIME_FORMAT);\n\n if (!dateValid || !timeValid) {\n delete params.time;\n delete params.date;\n }\n\n // temp: set additional parameters for CAR_HAIL or CAR_RENT trips\n if (\n params.mode &&\n (params.mode.includes(\"CAR_HAIL\") || params.mode.includes(\"CAR_RENT\"))\n ) {\n params.minTransitDistance = \"50%\";\n // increase search timeout because these queries can take a while\n params.searchTimeout = 10000;\n }\n\n // set onlyTransitTrips for car rental searches\n if (params.mode && params.mode.includes(\"CAR_RENT\")) {\n params.onlyTransitTrips = true;\n }\n\n // Additional processing specific to PROFILE mode\n } else {\n // check start and end time validity; ignore both if either is invalid\n const startTimeValid = isMatch(params.startTime, OTP_API_TIME_FORMAT);\n const endTimeValid = isMatch(params.endTime, OTP_API_TIME_FORMAT);\n\n if (!startTimeValid || !endTimeValid) {\n delete params.startTimeValid;\n delete params.endTimeValid;\n }\n }\n\n // TODO: check that valid from/to locations are provided\n\n // hack to add walking to driving/TNC trips\n if (hasCar(params.mode)) {\n params.mode += \",WALK\";\n }\n\n // Replace FLEX placeholder with OTP flex modes\n // Explicit false check allows avoiding a breaking change -- undefined is true\n if (params.mode && config.modes?.mergeFlex !== false) {\n // Ensure query is in reduced format to avoid replacing twice\n const reducedMode = reduceOtpFlexModes(params.mode.split(\",\")).join(\",\");\n params.mode = expandOtpFlexMode(reducedMode);\n }\n\n return params;\n}\n"],"file":"query.js"}
|
|
1
|
+
{"version":3,"file":"query.js","names":["_dateFns","require","_lib","_interopRequireDefault","_qs","_itinerary","_map","_queryParams","_time","defaultParams","exports","TIME_FORMATS","getQueryParamProperty","paramInfo","property","query","ensureSingleAccessMode","queryModes","accessCount","filter","m","isAccessMode","length","firstAccess","find","push","getUrlParams","window","qs","parse","location","href","split","undefined","getOtpUrlParams","Object","keys","key","startsWith","getTripOptionsFromQuery","keepPlace","options","time","departArrive","date","from","to","getDefaultQueryParamValue","param","default","getDefaultQuery","config","defaultQuery","routingType","queryParams","qp","forEach","name","routingTypes","defaultQueryParams","isParamApplicable","applicable","includes","reduceOtpFlexModes","modes","enabled","reduce","prev","cur","newModes","expandOtpFlexMode","mode","map","join","isNotDefaultQuery","activeModes","sort","mergeFlex","defaultModes","getTransitModes","concat","modesEqual","every","value","index","i","getFirstGeocodeResult","text","geocoderConfig","geocoderMethod","geocoder","getGeocoder","then","result","firstResult","features","getLocationFromGeocodedFeature","parseLocationString","parts","coordinates","stringToCoords","coordsToString","lat","lon","queryParamToLocation","autoMethod","planParamsToQuery","params","fromPlace","toPlace","arriveBy","getCurrentDate","matchedTimeFormat","timeFormat","isMatch","format","Date","OTP_API_TIME_FORMAT","getCurrentTime","intermediatePlaces","maybeNumber","Number","isNaN","planParamsToQueryAsync","getRoutingParams","currentQuery","ignoreRealtimeUpdates","isItinerary","indexOf","rewriteFunction","itineraryRewrite","profileRewrite","assign","dateValid","OTP_API_DATE_FORMAT","timeValid","minTransitDistance","searchTimeout","onlyTransitTrips","startTimeValid","startTime","endTimeValid","endTime","hasCar","reducedMode"],"sources":["../src/query.js"],"sourcesContent":["import { format, isMatch, parse } from \"date-fns\";\nimport getGeocoder from \"@opentripplanner/geocoder/lib\";\nimport qs from \"qs\";\n\nimport { getTransitModes, hasCar, isAccessMode } from \"./itinerary\";\nimport { coordsToString, stringToCoords } from \"./map\";\nimport queryParams from \"./query-params\";\nimport {\n getCurrentTime,\n getCurrentDate,\n OTP_API_DATE_FORMAT,\n OTP_API_TIME_FORMAT\n} from \"./time\";\n\n/* The list of default parameters considered in the settings panel */\n\nexport const defaultParams = [\n \"wheelchair\",\n \"maxWalkDistance\",\n \"walkReluctance\",\n \"maxWalkTime\",\n \"maxBikeDistance\",\n \"maxBikeTime\",\n \"bikeSpeed\",\n \"optimize\",\n \"optimizeBike\",\n \"maxEScooterDistance\",\n \"watts\"\n];\n\n/**\n * List of time formats to parse when reading query params.\n */\nconst TIME_FORMATS = [\n \"HH:mm:ss\",\n \"HH:mm\",\n \"H:mm\",\n \"h:mm:ss a\",\n \"h:mm:ssa\",\n \"h:mm a\",\n \"h:mma\",\n \"h:mm\",\n \"HHmm\",\n \"hmm\",\n \"ha\"\n];\n\n/* A function to retrieve a property value from an entry in the query-params\n * table, checking for either a static value or a function */\n\nexport function getQueryParamProperty(paramInfo, property, query) {\n return typeof paramInfo[property] === \"function\"\n ? paramInfo[property](query)\n : paramInfo[property];\n}\n\nexport function ensureSingleAccessMode(queryModes) {\n // Count the number of access modes\n const accessCount = queryModes.filter(m => isAccessMode(m)).length;\n\n // If multiple access modes are specified, keep only the first one\n if (accessCount > 1) {\n const firstAccess = queryModes.find(m => isAccessMode(m));\n queryModes = queryModes.filter(m => !isAccessMode(m) || m === firstAccess);\n\n // If no access modes are specified, add 'WALK' as the default\n } else if (accessCount === 0) {\n queryModes.push(\"WALK\");\n }\n\n return queryModes;\n}\n\nexport function getUrlParams() {\n if (window) {\n return qs.parse(window.location.href.split(\"?\")[1]);\n }\n return undefined;\n}\n\nexport function getOtpUrlParams() {\n return Object.keys(getUrlParams()).filter(key => !key.startsWith(\"ui_\"));\n}\n\nexport function getTripOptionsFromQuery(query, keepPlace = false) {\n const options = { ...query };\n // Delete time/date options and from/to\n delete options.time;\n delete options.departArrive;\n delete options.date;\n if (!keepPlace) {\n delete options.from;\n delete options.to;\n }\n return options;\n}\n\n/**\n * Gets the query param's default value that is either a constant or by\n * executing the default value function.\n */\nfunction getDefaultQueryParamValue(param) {\n return typeof param.default === \"function\" ? param.default() : param.default;\n}\n\n/**\n * Get the default query to OTP based on the given config.\n */\nexport function getDefaultQuery(config = null) {\n const defaultQuery = { routingType: \"ITINERARY\" };\n queryParams\n .filter(qp => \"default\" in qp)\n .forEach(qp => {\n defaultQuery[qp.name] = getDefaultQueryParamValue(qp);\n });\n if (config) {\n if (config.routingTypes && config.routingTypes.length > 0) {\n defaultQuery.routingType = config.routingTypes[0].key;\n }\n if (config.defaultQueryParams) {\n Object.keys(config.defaultQueryParams).forEach(key => {\n defaultQuery[key] = config.defaultQueryParams[key];\n });\n }\n }\n return defaultQuery;\n}\n\n/**\n * Determine if the specified query param applies to the given query (based on\n * routing type and the param's own applicable function).\n * @param paramInfo an entry from query-params.js\n * @param query the query against which to check if the param applies\n * @param config OTP config\n * @return {Boolean}\n */\nfunction isParamApplicable(paramInfo, query, config) {\n const { applicable, routingTypes } = paramInfo;\n if (!routingTypes.includes(query.routingType)) return false;\n if (typeof applicable === \"function\" && !applicable(query, config)) {\n return false;\n }\n return true;\n}\n\n/**\n * Helper method which replaces OTP flex modes with single FLEX mode that's\n * more useful and easier to work with.\n */\nexport function reduceOtpFlexModes(modes, enabled = true) {\n if (!enabled) return modes;\n\n return modes.reduce((prev, cur) => {\n const newModes = prev;\n // Add the current mode if it is not a flex mode\n if (!cur.includes(\"FLEX\")) {\n newModes.push(cur);\n // If it is a flex mode, do not add it but rather add the custom flex mode\n // if not already present\n } else if (!newModes.includes(\"FLEX\")) {\n newModes.push(\"FLEX\");\n }\n return newModes;\n }, []);\n}\n\n/**\n * Helper method to process a mode string, replacing all instances of FLEX\n * with the full set of FLEX modes used by otp-2\n * @param {*} mode a mode String, not an array\n * @returns a mode String, not an array (with flex modes expanded)\n */\nexport function expandOtpFlexMode(mode) {\n const modes = reduceOtpFlexModes(mode.split(\",\"));\n return modes\n .map(m => {\n // If both the expanded and shrunk modes are included, remove the expanded one\n if (m === \"FLEX_EGRESS\" || m === \"FLEX_ACCESS\" || m === \"FLEX_DIRECT\") {\n if (mode.includes(\"FLEX\")) return \"\";\n }\n if (m === \"FLEX\") {\n return \"FLEX_EGRESS,FLEX_ACCESS,FLEX_DIRECT\";\n }\n return m;\n })\n .join(\",\");\n}\n\n/**\n * Determines whether the specified query differs from the default query, i.e.,\n * whether the user has modified any trip options (including mode) from their\n * default values.\n */\nexport function isNotDefaultQuery(query, config) {\n const activeModes = reduceOtpFlexModes(\n query.mode.split(\",\").sort(),\n config.modes?.mergeFlex\n );\n if (\n activeModes.length !== 2 ||\n activeModes[0] !== \"TRANSIT\" ||\n activeModes[1] !== \"WALK\"\n ) {\n // Default mode is TRANSIT,WALK. If general TRANSIT is not used, check\n // against available transit modes in config.\n const defaultModes = getTransitModes(config)\n .concat([\"WALK\"])\n .sort();\n const modesEqual =\n activeModes.length === defaultModes.length &&\n activeModes.every((value, index) => {\n return value === defaultModes[index];\n });\n if (!modesEqual) return true;\n }\n // If modes are equal, check the remaining params.\n const defaultQuery = getDefaultQuery(config);\n for (let i = 0; i < defaultParams.length; i++) {\n const param = defaultParams[i];\n const paramInfo = queryParams.find(qp => qp.name === param);\n // If the parameter applies to the query and does not match the default\n // value, the query is not default.\n if (\n isParamApplicable(paramInfo, query, config) &&\n query[param] !== defaultQuery[param]\n ) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Geocode utility for returning the first result for the provided place name text.\n * @param {string} text - text to search\n * @param {Object} geocoderConfig\n * @param {string} geocoderMethod - an alternate geocoder api method to use. Defaults to `search`\n * @return {Location}\n */\nasync function getFirstGeocodeResult(\n text,\n geocoderConfig,\n geocoderMethod = \"search\"\n) {\n const geocoder = getGeocoder(geocoderConfig);\n // Attempt to geocode search text and return first result if found.\n // TODO: Import geocoder from @opentripplanner\n return geocoder[geocoderMethod]({ text }).then(result => {\n const firstResult = result.features && result.features[0];\n if (firstResult) {\n return geocoder.getLocationFromGeocodedFeature(firstResult);\n }\n return null;\n });\n}\n\n/**\n * OTP allows passing a location in the form '123 Main St::lat,lon', so we check\n * for the double colon and parse the coordinates accordingly.\n * @param {string} value - query param for place described above\n * @return {Location} - location or null if the value is falsey or the parsed\n * coordinates do not result in both a lat and lon\n */\nexport function parseLocationString(value) {\n if (!value) return null;\n const parts = value.split(\"::\");\n const coordinates = parts[1]\n ? stringToCoords(parts[1])\n : stringToCoords(parts[0]);\n const name = parts[1] ? parts[0] : coordsToString(coordinates);\n return coordinates.length === 2\n ? {\n name: name || null,\n lat: coordinates[0] || null,\n lon: coordinates[1] || null\n }\n : null;\n}\n\n/**\n * Convert a string query param for a from or to place into a location. If\n * coordinates not provided and geocoder config is present, use the first\n * geocoded result.\n * @param {string} value\n * @param {Object} [geocoderConfig=null]\n * @return {Location}\n */\nasync function queryParamToLocation(value, geocoderConfig) {\n let location = parseLocationString(value);\n if (!location && value && geocoderConfig) {\n // If a valid location was not found, but the place name text exists,\n // attempt to geocode the name.\n location = await getFirstGeocodeResult(\n value,\n geocoderConfig,\n geocoderConfig.autoMethod\n );\n }\n return location;\n}\n\n/**\n * Create a otp query based on a the url params.\n *\n * @param {Object} params An object representing the parsed querystring of url\n * params.\n */\nexport function planParamsToQuery(params) {\n const query = {};\n Object.keys(params).forEach(key => {\n switch (key) {\n case \"fromPlace\":\n query.from = parseLocationString(params.fromPlace);\n break;\n case \"toPlace\":\n query.to = parseLocationString(params.toPlace);\n break;\n case \"arriveBy\":\n query.departArrive =\n params.arriveBy === \"true\"\n ? \"ARRIVE\"\n : params.arriveBy === \"false\"\n ? \"DEPART\"\n : \"NOW\";\n break;\n case \"date\":\n query.date = params.date || getCurrentDate();\n break;\n case \"time\":\n {\n // Match one of the supported time formats\n const matchedTimeFormat = TIME_FORMATS.find(timeFormat =>\n isMatch(params.time, timeFormat)\n );\n query.time = matchedTimeFormat\n ? format(\n parse(params.time, matchedTimeFormat, new Date()),\n OTP_API_TIME_FORMAT\n )\n : getCurrentTime();\n }\n break;\n case \"intermediatePlaces\":\n // If query has intermediate places, ensure that they are parsed\n // as locations.\n query.intermediatePlaces = params.intermediatePlaces\n ? params.intermediatePlaces.map(parseLocationString)\n : [];\n break;\n default: {\n const maybeNumber = Number(params[key]);\n // If the param value is an empty string literal and is not a number,\n // use string value. Else, use parsed number value.\n // See https://github.com/opentripplanner/otp-ui/issues/50\n query[key] =\n params[key] === \"\" || Number.isNaN(maybeNumber)\n ? params[key]\n : maybeNumber;\n break;\n }\n }\n });\n return query;\n}\n\n/**\n * Async method to create a otp query based on a the url params. This provides\n * the same functionality as planParamsToQuery, except that it will also attempt\n * to geocode the input from and to strings if no lat/lng values were provided.\n *\n * @param {Object} params An object representing the parsed querystring of url\n * params.\n * @param config the config in the otp-rr store.\n */\nexport async function planParamsToQueryAsync(params, config = {}) {\n // Construct query from plan params.\n const query = planParamsToQuery(params);\n // Attempt to geocode from and to params if the string parsing does not return\n // valid locations.\n if (!query.from) {\n query.from = await queryParamToLocation(params.fromPlace, config.geocoder);\n }\n if (!query.to) {\n query.to = await queryParamToLocation(params.toPlace, config.geocoder);\n }\n return query;\n}\n\n/**\n * Create an object that can be used as a querystring in making an OTP\n * PlannerResource request.\n *\n * See http://otp-docs.ibi-transit.com/api/resource_PlannerResource.html\n *\n * @param {Object} config The OTP application config. See types#configType\n * @param {Object} currentQuery The current query parameters as saved in the\n * application state. This method does some extra logic on top of this data\n * in order to create a request suitable for OTP. See __tests__/query.js#L14 for more.\n * @param {boolean} ignoreRealtimeUpdates If true, will create a request that\n * does not use realtime data.\n */\nexport function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {\n const routingType = currentQuery.routingType;\n const isItinerary = routingType === \"ITINERARY\";\n let params = {};\n\n // Start with the universe of OTP parameters defined in query-params.js:\n queryParams\n .filter(qp => {\n // A given parameter is included in the request if all of the following:\n // 1. Must apply to the active routing type (ITINERARY or PROFILE)\n // 2. Must be included in the current user-defined query\n // 3. Must pass the parameter's applicability test, if one is specified\n return (\n qp.routingTypes.indexOf(routingType) !== -1 &&\n qp.name in currentQuery &&\n (typeof qp.applicable !== \"function\" ||\n qp.applicable(currentQuery, config))\n );\n })\n .forEach(qp => {\n // Translate the applicable parameters according to their rewrite\n // functions (if provided)\n const rewriteFunction = isItinerary\n ? qp.itineraryRewrite\n : qp.profileRewrite;\n params = Object.assign(\n params,\n rewriteFunction\n ? rewriteFunction(currentQuery[qp.name])\n : { [qp.name]: currentQuery[qp.name] }\n );\n });\n\n // Additional processing specific to ITINERARY mode\n if (isItinerary) {\n // override ignoreRealtimeUpdates if provided\n if (typeof ignoreRealtimeUpdates === \"boolean\") {\n params.ignoreRealtimeUpdates = ignoreRealtimeUpdates;\n }\n\n // check date/time validity; ignore both if either is invalid\n const dateValid = isMatch(params.date, OTP_API_DATE_FORMAT);\n const timeValid = isMatch(params.time, OTP_API_TIME_FORMAT);\n\n if (!dateValid || !timeValid) {\n delete params.time;\n delete params.date;\n }\n\n // temp: set additional parameters for CAR_HAIL or CAR_RENT trips\n if (\n params.mode &&\n (params.mode.includes(\"CAR_HAIL\") || params.mode.includes(\"CAR_RENT\"))\n ) {\n params.minTransitDistance = \"50%\";\n // increase search timeout because these queries can take a while\n params.searchTimeout = 10000;\n }\n\n // set onlyTransitTrips for car rental searches\n if (params.mode && params.mode.includes(\"CAR_RENT\")) {\n params.onlyTransitTrips = true;\n }\n\n // Additional processing specific to PROFILE mode\n } else {\n // check start and end time validity; ignore both if either is invalid\n const startTimeValid = isMatch(params.startTime, OTP_API_TIME_FORMAT);\n const endTimeValid = isMatch(params.endTime, OTP_API_TIME_FORMAT);\n\n if (!startTimeValid || !endTimeValid) {\n delete params.startTimeValid;\n delete params.endTimeValid;\n }\n }\n\n // TODO: check that valid from/to locations are provided\n\n // hack to add walking to driving/TNC trips\n if (hasCar(params.mode)) {\n params.mode += \",WALK\";\n }\n\n // Replace FLEX placeholder with OTP flex modes\n // Explicit false check allows avoiding a breaking change -- undefined is true\n if (params.mode && config.modes?.mergeFlex !== false) {\n // Ensure query is in reduced format to avoid replacing twice\n const reducedMode = reduceOtpFlexModes(params.mode.split(\",\")).join(\",\");\n params.mode = expandOtpFlexMode(reducedMode);\n }\n\n return params;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,GAAA,GAAAD,sBAAA,CAAAF,OAAA;AAEA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,IAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAJ,sBAAA,CAAAF,OAAA;AACA,IAAAO,KAAA,GAAAP,OAAA;AAOA;;AAEO,MAAMQ,aAAa,GAAAC,OAAA,CAAAD,aAAA,GAAG,CAC3B,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,OAAO,CACR;;AAED;AACA;AACA;AACA,MAAME,YAAY,GAAG,CACnB,UAAU,EACV,OAAO,EACP,MAAM,EACN,WAAW,EACX,UAAU,EACV,QAAQ,EACR,OAAO,EACP,MAAM,EACN,MAAM,EACN,KAAK,EACL,IAAI,CACL;;AAED;AACA;;AAEO,SAASC,qBAAqBA,CAACC,SAAS,EAAEC,QAAQ,EAAEC,KAAK,EAAE;EAChE,OAAO,OAAOF,SAAS,CAACC,QAAQ,CAAC,KAAK,UAAU,GAC5CD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