@opentripplanner/core-utils 13.0.0-alpha.1 → 13.0.0-alpha.3

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.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/esm/graphql.d.js.map +1 -1
  4. package/esm/index.js.map +1 -1
  5. package/esm/itinerary.js +78 -115
  6. package/esm/itinerary.js.map +1 -1
  7. package/esm/map.js +3 -3
  8. package/esm/map.js.map +1 -1
  9. package/esm/profile.js +17 -18
  10. package/esm/profile.js.map +1 -1
  11. package/esm/query-gen.js +35 -45
  12. package/esm/query-gen.js.map +1 -1
  13. package/esm/query.js +135 -191
  14. package/esm/query.js.map +1 -1
  15. package/esm/route.js +74 -97
  16. package/esm/route.js.map +1 -1
  17. package/esm/storage.js +4 -5
  18. package/esm/storage.js.map +1 -1
  19. package/esm/suspense.js +1 -3
  20. package/esm/suspense.js.map +1 -1
  21. package/esm/time.js +13 -17
  22. package/esm/time.js.map +1 -1
  23. package/esm/ui.js +0 -5
  24. package/esm/ui.js.map +1 -1
  25. package/lib/graphql.d.js.map +1 -1
  26. package/lib/index.js +3 -19
  27. package/lib/index.js.map +1 -1
  28. package/lib/itinerary.js +114 -199
  29. package/lib/itinerary.js.map +1 -1
  30. package/lib/map.d.ts +1 -1
  31. package/lib/map.d.ts.map +1 -1
  32. package/lib/map.js +9 -20
  33. package/lib/map.js.map +1 -1
  34. package/lib/profile.js +17 -19
  35. package/lib/profile.js.map +1 -1
  36. package/lib/query-gen.d.ts +4 -4
  37. package/lib/query-gen.d.ts.map +1 -1
  38. package/lib/query-gen.js +34 -45
  39. package/lib/query-gen.js.map +1 -1
  40. package/lib/query-params.jsx +893 -0
  41. package/lib/query.js +66 -118
  42. package/lib/query.js.map +1 -1
  43. package/lib/route.js +73 -101
  44. package/lib/route.js.map +1 -1
  45. package/lib/storage.js +6 -11
  46. package/lib/storage.js.map +1 -1
  47. package/lib/suspense.d.ts +1 -1
  48. package/lib/suspense.d.ts.map +1 -1
  49. package/lib/suspense.js +3 -9
  50. package/lib/suspense.js.map +1 -1
  51. package/lib/time.js +19 -38
  52. package/lib/time.js.map +1 -1
  53. package/lib/ui.js +1 -8
  54. package/lib/ui.js.map +1 -1
  55. package/package.json +7 -8
  56. package/src/query-params.jsx +893 -0
  57. package/tsconfig.tsbuildinfo +1 -1
  58. package/esm/query-params.js +0 -786
  59. package/esm/query-params.js.map +0 -1
  60. package/lib/query-params.js +0 -756
  61. package/lib/query-params.js.map +0 -1
  62. /package/{src/query-params.js → esm/query-params.jsx} +0 -0
package/esm/query.js CHANGED
@@ -1,12 +1,8 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
- import _typeof from "@babel/runtime/helpers/typeof";
3
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
5
-
6
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
7
-
8
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
9
-
4
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
6
  import { format, isMatch, parse } from "date-fns";
11
7
  import getGeocoder from "@opentripplanner/geocoder/lib";
12
8
  import qs from "qs";
@@ -14,14 +10,16 @@ import { getTransitModes, hasCar, isAccessMode } from "./itinerary";
14
10
  import { coordsToString, stringToCoords } from "./map";
15
11
  import queryParams from "./query-params";
16
12
  import { getCurrentTime, getCurrentDate, OTP_API_DATE_FORMAT, OTP_API_TIME_FORMAT } from "./time";
13
+
17
14
  /* The list of default parameters considered in the settings panel */
18
15
 
19
16
  export var defaultParams = ["wheelchair", "maxWalkDistance", "walkReluctance", "maxWalkTime", "maxBikeDistance", "maxBikeTime", "bikeSpeed", "optimize", "optimizeBike", "maxEScooterDistance", "watts"];
17
+
20
18
  /**
21
19
  * List of time formats to parse when reading query params.
22
20
  */
23
-
24
21
  var 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"];
22
+
25
23
  /* A function to retrieve a property value from an entry in the query-params
26
24
  * table, checking for either a static value or a function */
27
25
 
@@ -32,26 +30,27 @@ export function ensureSingleAccessMode(queryModes) {
32
30
  // Count the number of access modes
33
31
  var accessCount = queryModes.filter(function (m) {
34
32
  return isAccessMode(m);
35
- }).length; // If multiple access modes are specified, keep only the first one
33
+ }).length;
36
34
 
35
+ // If multiple access modes are specified, keep only the first one
37
36
  if (accessCount > 1) {
38
37
  var firstAccess = queryModes.find(function (m) {
39
38
  return isAccessMode(m);
40
39
  });
41
40
  queryModes = queryModes.filter(function (m) {
42
41
  return !isAccessMode(m) || m === firstAccess;
43
- }); // If no access modes are specified, add 'WALK' as the default
42
+ });
43
+
44
+ // If no access modes are specified, add 'WALK' as the default
44
45
  } else if (accessCount === 0) {
45
46
  queryModes.push("WALK");
46
47
  }
47
-
48
48
  return queryModes;
49
49
  }
50
50
  export function getUrlParams() {
51
51
  if (window) {
52
52
  return qs.parse(window.location.href.split("?")[1]);
53
53
  }
54
-
55
54
  return undefined;
56
55
  }
57
56
  export function getOtpUrlParams() {
@@ -61,34 +60,29 @@ export function getOtpUrlParams() {
61
60
  }
62
61
  export function getTripOptionsFromQuery(query) {
63
62
  var keepPlace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
64
-
65
- var options = _objectSpread({}, query); // Delete time/date options and from/to
66
-
67
-
63
+ var options = _objectSpread({}, query);
64
+ // Delete time/date options and from/to
68
65
  delete options.time;
69
66
  delete options.departArrive;
70
67
  delete options.date;
71
-
72
68
  if (!keepPlace) {
73
69
  delete options.from;
74
70
  delete options.to;
75
71
  }
76
-
77
72
  return options;
78
73
  }
74
+
79
75
  /**
80
76
  * Gets the query param's default value that is either a constant or by
81
77
  * executing the default value function.
82
78
  */
83
-
84
79
  function getDefaultQueryParamValue(param) {
85
80
  return typeof param["default"] === "function" ? param["default"]() : param["default"];
86
81
  }
82
+
87
83
  /**
88
84
  * Get the default query to OTP based on the given config.
89
85
  */
90
-
91
-
92
86
  export function getDefaultQuery() {
93
87
  var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
94
88
  var defaultQuery = {
@@ -99,21 +93,19 @@ export function getDefaultQuery() {
99
93
  }).forEach(function (qp) {
100
94
  defaultQuery[qp.name] = getDefaultQueryParamValue(qp);
101
95
  });
102
-
103
96
  if (config) {
104
97
  if (config.routingTypes && config.routingTypes.length > 0) {
105
98
  defaultQuery.routingType = config.routingTypes[0].key;
106
99
  }
107
-
108
100
  if (config.defaultQueryParams) {
109
101
  Object.keys(config.defaultQueryParams).forEach(function (key) {
110
102
  defaultQuery[key] = config.defaultQueryParams[key];
111
103
  });
112
104
  }
113
105
  }
114
-
115
106
  return defaultQuery;
116
107
  }
108
+
117
109
  /**
118
110
  * Determine if the specified query param applies to the given query (based on
119
111
  * routing type and the param's own applicable function).
@@ -122,47 +114,43 @@ export function getDefaultQuery() {
122
114
  * @param config OTP config
123
115
  * @return {Boolean}
124
116
  */
125
-
126
117
  function isParamApplicable(paramInfo, query, config) {
127
118
  var applicable = paramInfo.applicable,
128
- routingTypes = paramInfo.routingTypes;
119
+ routingTypes = paramInfo.routingTypes;
129
120
  if (!routingTypes.includes(query.routingType)) return false;
130
-
131
121
  if (typeof applicable === "function" && !applicable(query, config)) {
132
122
  return false;
133
123
  }
134
-
135
124
  return true;
136
125
  }
126
+
137
127
  /**
138
128
  * Helper method which replaces OTP flex modes with single FLEX mode that's
139
129
  * more useful and easier to work with.
140
130
  */
141
-
142
-
143
131
  export function reduceOtpFlexModes(modes) {
144
132
  var enabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
145
133
  if (!enabled) return modes;
146
134
  return modes.reduce(function (prev, cur) {
147
- var newModes = prev; // Add the current mode if it is not a flex mode
148
-
135
+ var newModes = prev;
136
+ // Add the current mode if it is not a flex mode
149
137
  if (!cur.includes("FLEX")) {
150
- newModes.push(cur); // If it is a flex mode, do not add it but rather add the custom flex mode
138
+ newModes.push(cur);
139
+ // If it is a flex mode, do not add it but rather add the custom flex mode
151
140
  // if not already present
152
141
  } else if (!newModes.includes("FLEX")) {
153
142
  newModes.push("FLEX");
154
143
  }
155
-
156
144
  return newModes;
157
145
  }, []);
158
146
  }
147
+
159
148
  /**
160
149
  * Helper method to process a mode string, replacing all instances of FLEX
161
150
  * with the full set of FLEX modes used by otp-2
162
151
  * @param {*} mode a mode String, not an array
163
152
  * @returns a mode String, not an array (with flex modes expanded)
164
153
  */
165
-
166
154
  export function expandOtpFlexMode(mode) {
167
155
  var modes = reduceOtpFlexModes(mode.split(","));
168
156
  return modes.map(function (m) {
@@ -170,25 +158,21 @@ export function expandOtpFlexMode(mode) {
170
158
  if (m === "FLEX_EGRESS" || m === "FLEX_ACCESS" || m === "FLEX_DIRECT") {
171
159
  if (mode.includes("FLEX")) return "";
172
160
  }
173
-
174
161
  if (m === "FLEX") {
175
162
  return "FLEX_EGRESS,FLEX_ACCESS,FLEX_DIRECT";
176
163
  }
177
-
178
164
  return m;
179
165
  }).join(",");
180
166
  }
167
+
181
168
  /**
182
169
  * Determines whether the specified query differs from the default query, i.e.,
183
170
  * whether the user has modified any trip options (including mode) from their
184
171
  * default values.
185
172
  */
186
-
187
173
  export function isNotDefaultQuery(query, config) {
188
174
  var _config$modes;
189
-
190
175
  var activeModes = reduceOtpFlexModes(query.mode.split(",").sort(), (_config$modes = config.modes) === null || _config$modes === void 0 ? void 0 : _config$modes.mergeFlex);
191
-
192
176
  if (activeModes.length !== 2 || activeModes[0] !== "TRANSIT" || activeModes[1] !== "WALK") {
193
177
  // Default mode is TRANSIT,WALK. If general TRANSIT is not used, check
194
178
  // against available transit modes in config.
@@ -197,33 +181,30 @@ export function isNotDefaultQuery(query, config) {
197
181
  return value === defaultModes[index];
198
182
  });
199
183
  if (!modesEqual) return true;
200
- } // If modes are equal, check the remaining params.
201
-
202
-
184
+ }
185
+ // If modes are equal, check the remaining params.
203
186
  var defaultQuery = getDefaultQuery(config);
204
-
205
- var _loop = function _loop(i) {
206
- var param = defaultParams[i];
207
- var paramInfo = queryParams.find(function (qp) {
208
- return qp.name === param;
209
- }); // If the parameter applies to the query and does not match the default
210
- // value, the query is not default.
211
-
212
- if (isParamApplicable(paramInfo, query, config) && query[param] !== defaultQuery[param]) {
213
- return {
214
- v: true
215
- };
216
- }
217
- };
218
-
187
+ var _loop = function _loop() {
188
+ var param = defaultParams[i];
189
+ var paramInfo = queryParams.find(function (qp) {
190
+ return qp.name === param;
191
+ });
192
+ // If the parameter applies to the query and does not match the default
193
+ // value, the query is not default.
194
+ if (isParamApplicable(paramInfo, query, config) && query[param] !== defaultQuery[param]) {
195
+ return {
196
+ v: true
197
+ };
198
+ }
199
+ },
200
+ _ret;
219
201
  for (var i = 0; i < defaultParams.length; i++) {
220
- var _ret = _loop(i);
221
-
222
- if (_typeof(_ret) === "object") return _ret.v;
202
+ _ret = _loop();
203
+ if (_ret) return _ret.v;
223
204
  }
224
-
225
205
  return false;
226
206
  }
207
+
227
208
  /**
228
209
  * Geocode utility for returning the first result for the provided place name text.
229
210
  * @param {string} text - text to search
@@ -231,7 +212,6 @@ export function isNotDefaultQuery(query, config) {
231
212
  * @param {string} geocoderMethod - an alternate geocoder api method to use. Defaults to `search`
232
213
  * @return {Location}
233
214
  */
234
-
235
215
  function getFirstGeocodeResult(_x, _x2) {
236
216
  return _getFirstGeocodeResult.apply(this, arguments);
237
217
  }
@@ -242,43 +222,34 @@ function getFirstGeocodeResult(_x, _x2) {
242
222
  * @return {Location} - location or null if the value is falsey or the parsed
243
223
  * coordinates do not result in both a lat and lon
244
224
  */
245
-
246
-
247
225
  function _getFirstGeocodeResult() {
248
- _getFirstGeocodeResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(text, geocoderConfig) {
226
+ _getFirstGeocodeResult = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(text, geocoderConfig) {
249
227
  var geocoderMethod,
250
- geocoder,
251
- _args = arguments;
228
+ geocoder,
229
+ _args = arguments;
252
230
  return _regeneratorRuntime.wrap(function _callee$(_context) {
253
- while (1) {
254
- switch (_context.prev = _context.next) {
255
- case 0:
256
- geocoderMethod = _args.length > 2 && _args[2] !== undefined ? _args[2] : "search";
257
- geocoder = getGeocoder(geocoderConfig); // Attempt to geocode search text and return first result if found.
258
- // TODO: Import geocoder from @opentripplanner
259
-
260
- return _context.abrupt("return", geocoder[geocoderMethod]({
261
- text: text
262
- }).then(function (result) {
263
- var firstResult = result.features && result.features[0];
264
-
265
- if (firstResult) {
266
- return geocoder.getLocationFromGeocodedFeature(firstResult);
267
- }
268
-
269
- return null;
270
- }));
271
-
272
- case 3:
273
- case "end":
274
- return _context.stop();
275
- }
231
+ while (1) switch (_context.prev = _context.next) {
232
+ case 0:
233
+ geocoderMethod = _args.length > 2 && _args[2] !== undefined ? _args[2] : "search";
234
+ geocoder = getGeocoder(geocoderConfig); // Attempt to geocode search text and return first result if found.
235
+ // TODO: Import geocoder from @opentripplanner
236
+ return _context.abrupt("return", geocoder[geocoderMethod]({
237
+ text: text
238
+ }).then(function (result) {
239
+ var firstResult = result.features && result.features[0];
240
+ if (firstResult) {
241
+ return geocoder.getLocationFromGeocodedFeature(firstResult);
242
+ }
243
+ return null;
244
+ }));
245
+ case 3:
246
+ case "end":
247
+ return _context.stop();
276
248
  }
277
249
  }, _callee);
278
250
  }));
279
251
  return _getFirstGeocodeResult.apply(this, arguments);
280
252
  }
281
-
282
253
  export function parseLocationString(value) {
283
254
  if (!value) return null;
284
255
  var parts = value.split("::");
@@ -290,6 +261,7 @@ export function parseLocationString(value) {
290
261
  lon: coordinates[1] || null
291
262
  } : null;
292
263
  }
264
+
293
265
  /**
294
266
  * Convert a string query param for a from or to place into a location. If
295
267
  * coordinates not provided and geocoder config is present, use the first
@@ -298,7 +270,6 @@ export function parseLocationString(value) {
298
270
  * @param {Object} [geocoderConfig=null]
299
271
  * @return {Location}
300
272
  */
301
-
302
273
  function queryParamToLocation(_x3, _x4) {
303
274
  return _queryParamToLocation.apply(this, arguments);
304
275
  }
@@ -308,41 +279,31 @@ function queryParamToLocation(_x3, _x4) {
308
279
  * @param {Object} params An object representing the parsed querystring of url
309
280
  * params.
310
281
  */
311
-
312
-
313
282
  function _queryParamToLocation() {
314
- _queryParamToLocation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(value, geocoderConfig) {
283
+ _queryParamToLocation = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(value, geocoderConfig) {
315
284
  var location;
316
285
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
317
- while (1) {
318
- switch (_context2.prev = _context2.next) {
319
- case 0:
320
- location = parseLocationString(value);
321
-
322
- if (!(!location && value && geocoderConfig)) {
323
- _context2.next = 5;
324
- break;
325
- }
326
-
327
- _context2.next = 4;
328
- return getFirstGeocodeResult(value, geocoderConfig, geocoderConfig.autoMethod);
329
-
330
- case 4:
331
- location = _context2.sent;
332
-
333
- case 5:
334
- return _context2.abrupt("return", location);
335
-
336
- case 6:
337
- case "end":
338
- return _context2.stop();
339
- }
286
+ while (1) switch (_context2.prev = _context2.next) {
287
+ case 0:
288
+ location = parseLocationString(value);
289
+ if (!(!location && value && geocoderConfig)) {
290
+ _context2.next = 5;
291
+ break;
292
+ }
293
+ _context2.next = 4;
294
+ return getFirstGeocodeResult(value, geocoderConfig, geocoderConfig.autoMethod);
295
+ case 4:
296
+ location = _context2.sent;
297
+ case 5:
298
+ return _context2.abrupt("return", location);
299
+ case 6:
300
+ case "end":
301
+ return _context2.stop();
340
302
  }
341
303
  }, _callee2);
342
304
  }));
343
305
  return _queryParamToLocation.apply(this, arguments);
344
306
  }
345
-
346
307
  export function planParamsToQuery(params) {
347
308
  var query = {};
348
309
  Object.keys(params).forEach(function (key) {
@@ -350,19 +311,15 @@ export function planParamsToQuery(params) {
350
311
  case "fromPlace":
351
312
  query.from = parseLocationString(params.fromPlace);
352
313
  break;
353
-
354
314
  case "toPlace":
355
315
  query.to = parseLocationString(params.toPlace);
356
316
  break;
357
-
358
317
  case "arriveBy":
359
318
  query.departArrive = params.arriveBy === "true" ? "ARRIVE" : params.arriveBy === "false" ? "DEPART" : "NOW";
360
319
  break;
361
-
362
320
  case "date":
363
321
  query.date = params.date || getCurrentDate();
364
322
  break;
365
-
366
323
  case "time":
367
324
  {
368
325
  // Match one of the supported time formats
@@ -372,19 +329,17 @@ export function planParamsToQuery(params) {
372
329
  query.time = matchedTimeFormat ? format(parse(params.time, matchedTimeFormat, new Date()), OTP_API_TIME_FORMAT) : getCurrentTime();
373
330
  }
374
331
  break;
375
-
376
332
  case "intermediatePlaces":
377
333
  // If query has intermediate places, ensure that they are parsed
378
334
  // as locations.
379
335
  query.intermediatePlaces = params.intermediatePlaces ? params.intermediatePlaces.map(parseLocationString) : [];
380
336
  break;
381
-
382
337
  default:
383
338
  {
384
- var maybeNumber = Number(params[key]); // If the param value is an empty string literal and is not a number,
339
+ var maybeNumber = Number(params[key]);
340
+ // If the param value is an empty string literal and is not a number,
385
341
  // use string value. Else, use parsed number value.
386
342
  // See https://github.com/opentripplanner/otp-ui/issues/50
387
-
388
343
  query[key] = params[key] === "" || Number.isNaN(maybeNumber) ? params[key] : maybeNumber;
389
344
  break;
390
345
  }
@@ -392,6 +347,7 @@ export function planParamsToQuery(params) {
392
347
  });
393
348
  return query;
394
349
  }
350
+
395
351
  /**
396
352
  * Async method to create a otp query based on a the url params. This provides
397
353
  * the same functionality as planParamsToQuery, except that it will also attempt
@@ -401,10 +357,10 @@ export function planParamsToQuery(params) {
401
357
  * params.
402
358
  * @param config the config in the otp-rr store.
403
359
  */
404
-
405
360
  export function planParamsToQueryAsync(_x5) {
406
361
  return _planParamsToQueryAsync.apply(this, arguments);
407
362
  }
363
+
408
364
  /**
409
365
  * Create an object that can be used as a querystring in making an OTP
410
366
  * PlannerResource request.
@@ -418,64 +374,52 @@ export function planParamsToQueryAsync(_x5) {
418
374
  * @param {boolean} ignoreRealtimeUpdates If true, will create a request that
419
375
  * does not use realtime data.
420
376
  */
421
-
422
377
  function _planParamsToQueryAsync() {
423
- _planParamsToQueryAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
378
+ _planParamsToQueryAsync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
424
379
  var config,
425
- query,
426
- _args3 = arguments;
380
+ query,
381
+ _args3 = arguments;
427
382
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
428
- while (1) {
429
- switch (_context3.prev = _context3.next) {
430
- case 0:
431
- config = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
432
- // Construct query from plan params.
433
- query = planParamsToQuery(params); // Attempt to geocode from and to params if the string parsing does not return
434
- // valid locations.
435
-
436
- if (query.from) {
437
- _context3.next = 6;
438
- break;
439
- }
440
-
441
- _context3.next = 5;
442
- return queryParamToLocation(params.fromPlace, config.geocoder);
443
-
444
- case 5:
445
- query.from = _context3.sent;
446
-
447
- case 6:
448
- if (query.to) {
449
- _context3.next = 10;
450
- break;
451
- }
452
-
453
- _context3.next = 9;
454
- return queryParamToLocation(params.toPlace, config.geocoder);
455
-
456
- case 9:
457
- query.to = _context3.sent;
458
-
459
- case 10:
460
- return _context3.abrupt("return", query);
461
-
462
- case 11:
463
- case "end":
464
- return _context3.stop();
465
- }
383
+ while (1) switch (_context3.prev = _context3.next) {
384
+ case 0:
385
+ config = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
386
+ // Construct query from plan params.
387
+ query = planParamsToQuery(params); // Attempt to geocode from and to params if the string parsing does not return
388
+ // valid locations.
389
+ if (query.from) {
390
+ _context3.next = 6;
391
+ break;
392
+ }
393
+ _context3.next = 5;
394
+ return queryParamToLocation(params.fromPlace, config.geocoder);
395
+ case 5:
396
+ query.from = _context3.sent;
397
+ case 6:
398
+ if (query.to) {
399
+ _context3.next = 10;
400
+ break;
401
+ }
402
+ _context3.next = 9;
403
+ return queryParamToLocation(params.toPlace, config.geocoder);
404
+ case 9:
405
+ query.to = _context3.sent;
406
+ case 10:
407
+ return _context3.abrupt("return", query);
408
+ case 11:
409
+ case "end":
410
+ return _context3.stop();
466
411
  }
467
412
  }, _callee3);
468
413
  }));
469
414
  return _planParamsToQueryAsync.apply(this, arguments);
470
415
  }
471
-
472
416
  export function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {
473
417
  var _config$modes2;
474
-
475
418
  var routingType = currentQuery.routingType;
476
419
  var isItinerary = routingType === "ITINERARY";
477
- var params = {}; // Start with the universe of OTP parameters defined in query-params.js:
420
+ var params = {};
478
421
 
422
+ // Start with the universe of OTP parameters defined in query-params.js:
479
423
  queryParams.filter(function (qp) {
480
424
  // A given parameter is included in the request if all of the following:
481
425
  // 1. Must apply to the active routing type (ITINERARY or PROFILE)
@@ -487,60 +431,60 @@ export function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {
487
431
  // functions (if provided)
488
432
  var rewriteFunction = isItinerary ? qp.itineraryRewrite : qp.profileRewrite;
489
433
  params = Object.assign(params, rewriteFunction ? rewriteFunction(currentQuery[qp.name]) : _defineProperty({}, qp.name, currentQuery[qp.name]));
490
- }); // Additional processing specific to ITINERARY mode
434
+ });
491
435
 
436
+ // Additional processing specific to ITINERARY mode
492
437
  if (isItinerary) {
493
438
  // override ignoreRealtimeUpdates if provided
494
439
  if (typeof ignoreRealtimeUpdates === "boolean") {
495
440
  params.ignoreRealtimeUpdates = ignoreRealtimeUpdates;
496
- } // check date/time validity; ignore both if either is invalid
497
-
441
+ }
498
442
 
443
+ // check date/time validity; ignore both if either is invalid
499
444
  var dateValid = isMatch(params.date, OTP_API_DATE_FORMAT);
500
445
  var timeValid = isMatch(params.time, OTP_API_TIME_FORMAT);
501
-
502
446
  if (!dateValid || !timeValid) {
503
447
  delete params.time;
504
448
  delete params.date;
505
- } // temp: set additional parameters for CAR_HAIL or CAR_RENT trips
506
-
449
+ }
507
450
 
451
+ // temp: set additional parameters for CAR_HAIL or CAR_RENT trips
508
452
  if (params.mode && (params.mode.includes("CAR_HAIL") || params.mode.includes("CAR_RENT"))) {
509
- params.minTransitDistance = "50%"; // increase search timeout because these queries can take a while
510
-
453
+ params.minTransitDistance = "50%";
454
+ // increase search timeout because these queries can take a while
511
455
  params.searchTimeout = 10000;
512
- } // set onlyTransitTrips for car rental searches
513
-
456
+ }
514
457
 
458
+ // set onlyTransitTrips for car rental searches
515
459
  if (params.mode && params.mode.includes("CAR_RENT")) {
516
460
  params.onlyTransitTrips = true;
517
- } // Additional processing specific to PROFILE mode
461
+ }
518
462
 
463
+ // Additional processing specific to PROFILE mode
519
464
  } else {
520
465
  // check start and end time validity; ignore both if either is invalid
521
466
  var startTimeValid = isMatch(params.startTime, OTP_API_TIME_FORMAT);
522
467
  var endTimeValid = isMatch(params.endTime, OTP_API_TIME_FORMAT);
523
-
524
468
  if (!startTimeValid || !endTimeValid) {
525
469
  delete params.startTimeValid;
526
470
  delete params.endTimeValid;
527
471
  }
528
- } // TODO: check that valid from/to locations are provided
529
- // hack to add walking to driving/TNC trips
472
+ }
530
473
 
474
+ // TODO: check that valid from/to locations are provided
531
475
 
476
+ // hack to add walking to driving/TNC trips
532
477
  if (hasCar(params.mode)) {
533
478
  params.mode += ",WALK";
534
- } // Replace FLEX placeholder with OTP flex modes
535
- // Explicit false check allows avoiding a breaking change -- undefined is true
536
-
479
+ }
537
480
 
481
+ // Replace FLEX placeholder with OTP flex modes
482
+ // Explicit false check allows avoiding a breaking change -- undefined is true
538
483
  if (params.mode && ((_config$modes2 = config.modes) === null || _config$modes2 === void 0 ? void 0 : _config$modes2.mergeFlex) !== false) {
539
484
  // Ensure query is in reduced format to avoid replacing twice
540
485
  var reducedMode = reduceOtpFlexModes(params.mode.split(",")).join(",");
541
486
  params.mode = expandOtpFlexMode(reducedMode);
542
487
  }
543
-
544
488
  return params;
545
489
  }
546
490
  //# sourceMappingURL=query.js.map