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