@opentripplanner/core-utils 9.0.0-alpha.1 → 9.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.
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=graphql.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"graphql.d.js"}
package/esm/index.js CHANGED
@@ -7,11 +7,13 @@ import * as route from "./route";
7
7
  import * as storage from "./storage";
8
8
  import * as time from "./time";
9
9
  import * as ui from "./ui";
10
+ import * as queryGen from "./query-gen";
10
11
  var core = {
11
12
  itinerary: itinerary,
12
13
  map: map,
13
14
  profile: profile,
14
15
  query: query,
16
+ queryGen: queryGen,
15
17
  queryParams: queryParams,
16
18
  route: route,
17
19
  storage: storage,
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["itinerary","map","profile","query","queryParams","route","storage","time","ui","core"],"mappings":"AAAA,OAAO,KAAKA,SAAZ,MAA2B,aAA3B;AACA,OAAO,KAAKC,GAAZ,MAAqB,OAArB;AACA,OAAO,KAAKC,OAAZ,MAAyB,WAAzB;AACA,OAAO,KAAKC,KAAZ,MAAuB,SAAvB;AACA,OAAO,KAAKC,WAAZ,MAA6B,gBAA7B;AACA,OAAO,KAAKC,KAAZ,MAAuB,SAAvB;AACA,OAAO,KAAKC,OAAZ,MAAyB,WAAzB;AACA,OAAO,KAAKC,IAAZ,MAAsB,QAAtB;AACA,OAAO,KAAKC,EAAZ,MAAoB,MAApB;AAEA,IAAMC,IAAI,GAAG;AACXT,EAAAA,SAAS,EAATA,SADW;AAEXC,EAAAA,GAAG,EAAHA,GAFW;AAGXC,EAAAA,OAAO,EAAPA,OAHW;AAIXC,EAAAA,KAAK,EAALA,KAJW;AAKXC,EAAAA,WAAW,EAAXA,WALW;AAMXC,EAAAA,KAAK,EAALA,KANW;AAOXC,EAAAA,OAAO,EAAPA,OAPW;AAQXC,EAAAA,IAAI,EAAJA,IARW;AASXC,EAAAA,EAAE,EAAFA;AATW,CAAb;AAYA,eAAeC,IAAf","sourcesContent":["import * as itinerary from \"./itinerary\";\nimport * as map from \"./map\";\nimport * as profile from \"./profile\";\nimport * as query from \"./query\";\nimport * as queryParams from \"./query-params\";\nimport * as route from \"./route\";\nimport * as storage from \"./storage\";\nimport * as time from \"./time\";\nimport * as ui from \"./ui\";\n\nconst core = {\n itinerary,\n map,\n profile,\n query,\n queryParams,\n route,\n storage,\n time,\n ui\n};\n\nexport default core;\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["itinerary","map","profile","query","queryParams","route","storage","time","ui","queryGen","core"],"mappings":"AAAA,OAAO,KAAKA,SAAZ,MAA2B,aAA3B;AACA,OAAO,KAAKC,GAAZ,MAAqB,OAArB;AACA,OAAO,KAAKC,OAAZ,MAAyB,WAAzB;AACA,OAAO,KAAKC,KAAZ,MAAuB,SAAvB;AACA,OAAO,KAAKC,WAAZ,MAA6B,gBAA7B;AACA,OAAO,KAAKC,KAAZ,MAAuB,SAAvB;AACA,OAAO,KAAKC,OAAZ,MAAyB,WAAzB;AACA,OAAO,KAAKC,IAAZ,MAAsB,QAAtB;AACA,OAAO,KAAKC,EAAZ,MAAoB,MAApB;AACA,OAAO,KAAKC,QAAZ,MAA0B,aAA1B;AAEA,IAAMC,IAAI,GAAG;AACXV,EAAAA,SAAS,EAATA,SADW;AAEXC,EAAAA,GAAG,EAAHA,GAFW;AAGXC,EAAAA,OAAO,EAAPA,OAHW;AAIXC,EAAAA,KAAK,EAALA,KAJW;AAKXM,EAAAA,QAAQ,EAARA,QALW;AAMXL,EAAAA,WAAW,EAAXA,WANW;AAOXC,EAAAA,KAAK,EAALA,KAPW;AAQXC,EAAAA,OAAO,EAAPA,OARW;AASXC,EAAAA,IAAI,EAAJA,IATW;AAUXC,EAAAA,EAAE,EAAFA;AAVW,CAAb;AAaA,eAAeE,IAAf","sourcesContent":["import * as itinerary from \"./itinerary\";\nimport * as map from \"./map\";\nimport * as profile from \"./profile\";\nimport * as query from \"./query\";\nimport * as queryParams from \"./query-params\";\nimport * as route from \"./route\";\nimport * as storage from \"./storage\";\nimport * as time from \"./time\";\nimport * as ui from \"./ui\";\nimport * as queryGen from \"./query-gen\";\n\nconst core = {\n itinerary,\n map,\n profile,\n query,\n queryGen,\n queryParams,\n route,\n storage,\n time,\n ui\n};\n\nexport default core;\n"],"file":"index.js"}
@@ -0,0 +1,136 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+
3
+ 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; }
4
+
5
+ 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; }
6
+
7
+ /* eslint-disable @typescript-eslint/no-unused-vars */
8
+ import { print } from "graphql";
9
+ var PlanQuery = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "PlanQuery" }, variableDefinitions: [{ kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "fromPlace" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "toPlace" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "modes" } }, type: { kind: "ListType", type: { kind: "NamedType", name: { kind: "Name", value: "TransportMode" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "time" } }, type: { kind: "NamedType", name: { kind: "Name", value: "String" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "date" } }, type: { kind: "NamedType", name: { kind: "Name", value: "String" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "wheelchair" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Boolean" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "bikeReluctance" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Float" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "carReluctance" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Float" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "walkReluctance" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Float" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "arriveBy" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Boolean" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "intermediatePlaces" } }, type: { kind: "ListType", type: { kind: "NamedType", name: { kind: "Name", value: "InputCoordinates" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "preferred" } }, type: { kind: "NamedType", name: { kind: "Name", value: "InputPreferred" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "unpreferred" } }, type: { kind: "NamedType", name: { kind: "Name", value: "InputUnpreferred" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "banned" } }, type: { kind: "NamedType", name: { kind: "Name", value: "InputBanned" } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "plan" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "fromPlace" }, value: { kind: "Variable", name: { kind: "Name", value: "fromPlace" } } }, { kind: "Argument", name: { kind: "Name", value: "toPlace" }, value: { kind: "Variable", name: { kind: "Name", value: "toPlace" } } }, { kind: "Argument", name: { kind: "Name", value: "transportModes" }, value: { kind: "Variable", name: { kind: "Name", value: "modes" } } }, { kind: "Argument", name: { kind: "Name", value: "locale" }, value: { kind: "StringValue", value: "en", block: false } }, { kind: "Argument", name: { kind: "Name", value: "time" }, value: { kind: "Variable", name: { kind: "Name", value: "time" } } }, { kind: "Argument", name: { kind: "Name", value: "date" }, value: { kind: "Variable", name: { kind: "Name", value: "date" } } }, { kind: "Argument", name: { kind: "Name", value: "wheelchair" }, value: { kind: "Variable", name: { kind: "Name", value: "wheelchair" } } }, { kind: "Argument", name: { kind: "Name", value: "bikeReluctance" }, value: { kind: "Variable", name: { kind: "Name", value: "bikeReluctance" } } }, { kind: "Argument", name: { kind: "Name", value: "carReluctance" }, value: { kind: "Variable", name: { kind: "Name", value: "carReluctance" } } }, { kind: "Argument", name: { kind: "Name", value: "walkReluctance" }, value: { kind: "Variable", name: { kind: "Name", value: "walkReluctance" } } }, { kind: "Argument", name: { kind: "Name", value: "arriveBy" }, value: { kind: "Variable", name: { kind: "Name", value: "arriveBy" } } }, { kind: "Argument", name: { kind: "Name", value: "intermediatePlaces" }, value: { kind: "Variable", name: { kind: "Name", value: "intermediatePlaces" } } }, { kind: "Argument", name: { kind: "Name", value: "preferred" }, value: { kind: "Variable", name: { kind: "Name", value: "preferred" } } }, { kind: "Argument", name: { kind: "Name", value: "unpreferred" }, value: { kind: "Variable", name: { kind: "Name", value: "unpreferred" } } }, { kind: "Argument", name: { kind: "Name", value: "banned" }, value: { kind: "Variable", name: { kind: "Name", value: "banned" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "itineraries" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "duration" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "endTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "startTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "waitingTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "walkTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "legs" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "distance" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "duration" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "endTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "mode" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "realTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "realtimeState" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "startTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "transitLeg" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "agency" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "timezone" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "url" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "legGeometry" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "length" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "points" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "intermediateStops" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "lat" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", alias: { kind: "Name", value: "stopCode" }, name: { kind: "Name", value: "code" }, arguments: [], directives: [] }, { kind: "Field", alias: { kind: "Name", value: "stopId" }, name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "locationType" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "route" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "shortName" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "color" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "textColor" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "type" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "from" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "lat" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "vertexType" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "stop" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "code" }, arguments: [], directives: [] }] } }] } }, { kind: "Field", name: { kind: "Name", value: "to" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "lat" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "vertexType" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "stop" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "code" }, arguments: [], directives: [] }] } }] } }, { kind: "Field", name: { kind: "Name", value: "steps" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "distance" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lat" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "elevationProfile" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "distance" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "elevation" }, arguments: [], directives: [] }] } }] } }] } }] } }] } }] } }], loc: { start: 0, end: 1587, source: { body: "query PlanQuery(\n\t$fromPlace: String!,\n\t$toPlace: String!,\n\t$modes: [TransportMode],\n\t$time: String,\n\t$date: String,\n\t$wheelchair: Boolean,\n\t$bikeReluctance: Float,\n\t$carReluctance: Float,\n\t$walkReluctance: Float,\n\t$arriveBy: Boolean,\n\t$intermediatePlaces: [InputCoordinates],\n\t$preferred: InputPreferred,\n\t$unpreferred: InputUnpreferred,\n\t$banned: InputBanned,\n) {\n\tplan(\n\t\tfromPlace: $fromPlace\n\t\ttoPlace: $toPlace\n\t\ttransportModes: $modes\n\t\tlocale: \"en\",\n\t\ttime: $time,\n\t\tdate: $date,\n\t\twheelchair: $wheelchair,\n\t\tbikeReluctance: $bikeReluctance,\n\t\tcarReluctance: $carReluctance,\n\t\twalkReluctance: $walkReluctance,\n\t\tarriveBy: $arriveBy,\n\t\tintermediatePlaces: $intermediatePlaces,\n\t\tpreferred: $preferred,\n\t\tunpreferred: $unpreferred,\n\t\tbanned: $banned,\n\t) {\n\t\titineraries {\n\t\t\tduration\n\t\t\tendTime\n\t\t\tstartTime\n\t\t\twaitingTime\n\t\t\twalkTime\n\t\t\tlegs {\n\t\t\t\tdistance\n\t\t\t\tduration\n\t\t\t\tendTime\n\t\t\t\tmode\n\t\t\t\trealTime\n\t\t\t\trealtimeState\t\n\t\t\t\tstartTime\n\t\t\t\ttransitLeg\n\t\t\t\tagency {\n\t\t\t\t\tname\n\t\t\t\t\tid\n\t\t\t\t\ttimezone\n\t\t\t\t\turl\n\t\t\t\t}\n\t\t\t\tlegGeometry {\n\t\t\t\t\tlength\n\t\t\t\t\tpoints\n\t\t\t\t}\n\t\t\t\tintermediateStops {\n\t\t\t\t\tlat\n\t\t\t\t\tlon\n\t\t\t\t\tname\n\t\t\t\t\tstopCode: code\n\t\t\t\t\tstopId: id\n\t\t\t\t\tlocationType\n\t\t\t\t}\n\t\t\t\troute {\n\t\t\t\t\tshortName\n\t\t\t\t\tcolor\n\t\t\t\t\ttextColor\n\t\t\t\t\tid\n\t\t\t\t\ttype\n\t\t\t\t}\n\t\t\t\tfrom {\n\t\t\t\t\tlat\n\t\t\t\t\tlon\n\t\t\t\t\tname\n\t\t\t\t\tvertexType\n\t\t\t\t\tstop {\n\t\t\t\t\t\tid\n\t\t\t\t\t\tcode\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tto {\n\t\t\t\t\tlat\n\t\t\t\t\tlon\n\t\t\t\t\tname\n\t\t\t\t\tvertexType\n\t\t\t\t\tstop {\n\t\t\t\t\t\tid\n\t\t\t\t\t\tcode\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tsteps {\n\t\t\t\t\tdistance\n\t\t\t\t\tlat\n\t\t\t\t\tlon\n\t\t\t\t\televationProfile {\n\t\t\t\t\t\tdistance\n\t\t\t\t\t\televation\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
10
+
11
+ /**
12
+ * Generates every possible mathematical subset of the input TransportModes.
13
+ * Uses code from:
14
+ * https://stackoverflow.com/questions/5752002/find-all-possible-subset-combos-in-an-array
15
+ * @param array Array of input transport modes
16
+ * @returns 2D array representing every possible subset of transport modes from input
17
+ */
18
+ function combinations(array) {
19
+ if (!array) return [];
20
+ return (// eslint-disable-next-line no-bitwise
21
+ new Array(1 << array.length).fill(null) // eslint-disable-next-line no-bitwise
22
+ .map(function (e1, i) {
23
+ return array.filter(function (e2, j) {
24
+ return i & 1 << j;
25
+ });
26
+ })
27
+ );
28
+ }
29
+
30
+ export var SIMPLIFICATIONS = {
31
+ AIRPLANE: "TRANSIT",
32
+ BICYCLE: "PERSONAL",
33
+ BUS: "TRANSIT",
34
+ CABLE_CAR: "TRANSIT",
35
+ CAR: "CAR",
36
+ FERRY: "TRANSIT",
37
+ FLEX: "SHARED",
38
+ // TODO: this allows FLEX+WALK. Is this reasonable?
39
+ FUNICULAR: "TRANSIT",
40
+ GONDOLA: "TRANSIT",
41
+ RAIL: "TRANSIT",
42
+ SCOOTER: "PERSONAL",
43
+ SUBWAY: "TRANSIT",
44
+ TRAM: "TRANSIT",
45
+ TRANSIT: "TRANSIT",
46
+ WALK: "WALK"
47
+ };
48
+ export var TRANSIT_SUBMODES = Object.keys(SIMPLIFICATIONS).filter(function (mode) {
49
+ return SIMPLIFICATIONS[mode] === "TRANSIT" && mode !== "TRANSIT";
50
+ });
51
+ export var TRANSIT_SUBMODES_AND_TRANSIT = Object.keys(SIMPLIFICATIONS).filter(function (mode) {
52
+ return SIMPLIFICATIONS[mode] === "TRANSIT";
53
+ });
54
+ export function generateCombinations(params) {
55
+ var VALID_COMBOS = [["WALK"], ["PERSONAL"], ["TRANSIT", "SHARED"], ["WALK", "SHARED"], ["TRANSIT"], ["TRANSIT", "PERSONAL"], ["TRANSIT", "CAR"]];
56
+ var BANNED_TOGETHER = ["SCOOTER", "BICYCLE"]; // List of the transit submodes that are included in the input params
57
+
58
+ var queryTransitSubmodes = params.modes.filter(function (mode) {
59
+ return TRANSIT_SUBMODES.includes(mode.mode);
60
+ }).map(function (mode) {
61
+ return mode.mode;
62
+ });
63
+ return combinations(params.modes).filter(function (combo) {
64
+ if (combo.length === 0) return false; // All current qualifiers currently simplify to "SHARED"
65
+
66
+ var simplifiedModes = Array.from(new Set(combo.map(function (c) {
67
+ return c.qualifier ? "SHARED" : SIMPLIFICATIONS[c.mode];
68
+ }))); // Ensure that if we have one transit mode, then we include ALL transit modes
69
+
70
+ if (simplifiedModes.includes("TRANSIT")) {
71
+ var flatModes = combo.map(function (m) {
72
+ return m.mode;
73
+ });
74
+
75
+ if (combo.reduce(function (prev, cur) {
76
+ if (queryTransitSubmodes.includes(cur.mode)) {
77
+ return prev - 1;
78
+ }
79
+
80
+ return prev;
81
+ }, queryTransitSubmodes.length) !== 0) {
82
+ return false;
83
+ }
84
+ } // OTP doesn't support multiple non-walk modes
85
+
86
+
87
+ if (BANNED_TOGETHER.every(function (m) {
88
+ return combo.find(function (c) {
89
+ return c.mode === m;
90
+ });
91
+ })) return false;
92
+ return !!VALID_COMBOS.find(function (vc) {
93
+ return simplifiedModes.every(function (m) {
94
+ return vc.includes(m);
95
+ }) && vc.every(function (m) {
96
+ return simplifiedModes.includes(m);
97
+ });
98
+ });
99
+ }) // create new filter that removes subTransit modes from appearing on their own
100
+ // ONLY IF there's multiple of them!
101
+ .map(function (combo) {
102
+ return _objectSpread(_objectSpread({}, params), {}, {
103
+ modes: combo
104
+ });
105
+ });
106
+ } // eslint-disable-next-line import/prefer-default-export
107
+
108
+ export function generateOtp2Query(params) {
109
+ var to = params.to,
110
+ from = params.from,
111
+ modeSettings = params.modeSettings; // This extracts the values from the mode settings to key value pairs
112
+
113
+ var modeSettingValues = modeSettings.reduce(function (prev, cur) {
114
+ prev[cur.key] = cur.value;
115
+ return prev;
116
+ }, {});
117
+ var walkReluctance = modeSettingValues.walkReluctance,
118
+ wheelchair = modeSettingValues.wheelchair,
119
+ bikeReluctance = modeSettingValues.bikeReluctance,
120
+ carReluctance = modeSettingValues.carReluctance,
121
+ allowBikeRental = modeSettingValues.allowBikeRental;
122
+ return {
123
+ query: print(PlanQuery),
124
+ variables: {
125
+ fromPlace: [from.lat, from.lon].join(","),
126
+ toPlace: [to.lat, to.lon].join(","),
127
+ modes: params.modes,
128
+ allowBikeRental: allowBikeRental,
129
+ walkReluctance: walkReluctance,
130
+ wheelchair: wheelchair,
131
+ bikeReluctance: bikeReluctance,
132
+ carReluctance: carReluctance
133
+ }
134
+ };
135
+ }
136
+ //# sourceMappingURL=query-gen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/query-gen.ts"],"names":["print","combinations","array","Array","length","fill","map","e1","i","filter","e2","j","SIMPLIFICATIONS","AIRPLANE","BICYCLE","BUS","CABLE_CAR","CAR","FERRY","FLEX","FUNICULAR","GONDOLA","RAIL","SCOOTER","SUBWAY","TRAM","TRANSIT","WALK","TRANSIT_SUBMODES","Object","keys","mode","TRANSIT_SUBMODES_AND_TRANSIT","generateCombinations","params","VALID_COMBOS","BANNED_TOGETHER","queryTransitSubmodes","modes","includes","combo","simplifiedModes","from","Set","c","qualifier","flatModes","m","reduce","prev","cur","every","find","vc","generateOtp2Query","to","modeSettings","modeSettingValues","key","value","walkReluctance","wheelchair","bikeReluctance","carReluctance","allowBikeRental","query","PlanQuery","variables","fromPlace","lat","lon","join","toPlace"],"mappings":";;;;;;AAAA;AACA,SAASA,KAAT,QAAsB,SAAtB;;;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,YAAT,CAAsBC,KAAtB,EAAiE;AAC/D,MAAI,CAACA,KAAL,EAAY,OAAO,EAAP;AACZ,SACE;AACA,QAAIC,KAAJ,CAAU,KAAKD,KAAK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AAOC,GAAP,EAAe;AAC3DD,IAAAA,IAAI,CAACC,GAAG,CAACQ,GAAL,CAAJ,GAAgBR,GAAG,CAACS,KAApB;AACA,WAAOV,IAAP;AACD,GAHyB,EAGvB,EAHuB,CAA1B;AAKA,MACEW,cADF,GAMIH,iBANJ,CACEG,cADF;AAAA,MAEEC,UAFF,GAMIJ,iBANJ,CAEEI,UAFF;AAAA,MAGEC,cAHF,GAMIL,iBANJ,CAGEK,cAHF;AAAA,MAIEC,aAJF,GAMIN,iBANJ,CAIEM,aAJF;AAAA,MAKEC,eALF,GAMIP,iBANJ,CAKEO,eALF;AAQA,SAAO;AACLC,IAAAA,KAAK,EAAEjE,KAAK,CAACkE,SAAD,CADP;AAELC,IAAAA,SAAS,EAAE;AACTC,MAAAA,SAAS,EAAE,CAAC1B,IAAI,CAAC2B,GAAN,EAAW3B,IAAI,CAAC4B,GAAhB,EAAqBC,IAArB,CAA0B,GAA1B,CADF;AAETC,MAAAA,OAAO,EAAE,CAACjB,EAAE,CAACc,GAAJ,EAASd,EAAE,CAACe,GAAZ,EAAiBC,IAAjB,CAAsB,GAAtB,CAFA;AAGTjC,MAAAA,KAAK,EAAEJ,MAAM,CAACI,KAHL;AAIT0B,MAAAA,eAAe,EAAfA,eAJS;AAKTJ,MAAAA,cAAc,EAAdA,cALS;AAMTC,MAAAA,UAAU,EAAVA,UANS;AAOTC,MAAAA,cAAc,EAAdA,cAPS;AAQTC,MAAAA,aAAa,EAAbA;AARS;AAFN,GAAP;AAaD","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { print } from \"graphql\";\nimport {\n ModeSetting,\n ModeSettingValues,\n TransportMode\n} from \"@opentripplanner/types\";\nimport { LonLatOutput } from \"@conveyal/lonlat\";\nimport PlanQuery from \"./planQuery.graphql\";\n\ntype OTPQueryParams = {\n to: LonLatOutput;\n from: LonLatOutput;\n modes: Array<TransportMode>;\n modeSettings: ModeSetting[];\n};\n\n/**\n * Generates every possible mathematical subset of the input TransportModes.\n * Uses code from:\n * https://stackoverflow.com/questions/5752002/find-all-possible-subset-combos-in-an-array\n * @param array Array of input transport modes\n * @returns 2D array representing every possible subset of transport modes from input\n */\nfunction combinations(array: TransportMode[]): TransportMode[][] {\n if (!array) return [];\n return (\n // eslint-disable-next-line no-bitwise\n new Array(1 << array.length)\n .fill(null)\n // eslint-disable-next-line no-bitwise\n .map((e1, i) => array.filter((e2, j) => i & (1 << j)))\n );\n}\nexport const SIMPLIFICATIONS = {\n AIRPLANE: \"TRANSIT\",\n BICYCLE: \"PERSONAL\",\n BUS: \"TRANSIT\",\n CABLE_CAR: \"TRANSIT\",\n CAR: \"CAR\",\n FERRY: \"TRANSIT\",\n FLEX: \"SHARED\", // TODO: this allows FLEX+WALK. Is this reasonable?\n FUNICULAR: \"TRANSIT\",\n GONDOLA: \"TRANSIT\",\n RAIL: \"TRANSIT\",\n SCOOTER: \"PERSONAL\",\n SUBWAY: \"TRANSIT\",\n TRAM: \"TRANSIT\",\n TRANSIT: \"TRANSIT\",\n WALK: \"WALK\"\n};\n\nexport const TRANSIT_SUBMODES = Object.keys(SIMPLIFICATIONS).filter(\n mode => SIMPLIFICATIONS[mode] === \"TRANSIT\" && mode !== \"TRANSIT\"\n);\nexport const TRANSIT_SUBMODES_AND_TRANSIT = Object.keys(SIMPLIFICATIONS).filter(\n mode => SIMPLIFICATIONS[mode] === \"TRANSIT\"\n);\n\nexport function generateCombinations(params: OTPQueryParams): OTPQueryParams[] {\n const VALID_COMBOS = [\n [\"WALK\"],\n [\"PERSONAL\"],\n [\"TRANSIT\", \"SHARED\"],\n [\"WALK\", \"SHARED\"],\n [\"TRANSIT\"],\n [\"TRANSIT\", \"PERSONAL\"],\n [\"TRANSIT\", \"CAR\"]\n ];\n\n const BANNED_TOGETHER = [\"SCOOTER\", \"BICYCLE\"];\n\n // List of the transit submodes that are included in the input params\n const queryTransitSubmodes = params.modes\n .filter(mode => TRANSIT_SUBMODES.includes(mode.mode))\n .map(mode => mode.mode);\n\n return (\n combinations(params.modes)\n .filter(combo => {\n if (combo.length === 0) return false;\n\n // All current qualifiers currently simplify to \"SHARED\"\n const simplifiedModes = Array.from(\n new Set(\n combo.map(c => (c.qualifier ? \"SHARED\" : SIMPLIFICATIONS[c.mode]))\n )\n );\n\n // Ensure that if we have one transit mode, then we include ALL transit modes\n if (simplifiedModes.includes(\"TRANSIT\")) {\n const flatModes = combo.map(m => m.mode);\n if (\n combo.reduce((prev, cur) => {\n if (queryTransitSubmodes.includes(cur.mode)) {\n return prev - 1;\n }\n return prev;\n }, queryTransitSubmodes.length) !== 0\n ) {\n return false;\n }\n }\n\n // OTP doesn't support multiple non-walk modes\n if (BANNED_TOGETHER.every(m => combo.find(c => c.mode === m)))\n return false;\n\n return !!VALID_COMBOS.find(\n vc =>\n simplifiedModes.every(m => vc.includes(m)) &&\n vc.every(m => simplifiedModes.includes(m))\n );\n })\n // create new filter that removes subTransit modes from appearing on their own\n // ONLY IF there's multiple of them!\n .map(combo => ({ ...params, modes: combo }))\n );\n}\n\n// eslint-disable-next-line import/prefer-default-export\nexport function generateOtp2Query(params: OTPQueryParams): any {\n const { to, from, modeSettings } = params;\n\n // This extracts the values from the mode settings to key value pairs\n const modeSettingValues = modeSettings.reduce((prev, cur) => {\n prev[cur.key] = cur.value;\n return prev;\n }, {}) as ModeSettingValues;\n\n const {\n walkReluctance,\n wheelchair,\n bikeReluctance,\n carReluctance,\n allowBikeRental\n } = modeSettingValues;\n\n return {\n query: print(PlanQuery),\n variables: {\n fromPlace: [from.lat, from.lon].join(\",\"),\n toPlace: [to.lat, to.lon].join(\",\"),\n modes: params.modes,\n allowBikeRental,\n walkReluctance,\n wheelchair,\n bikeReluctance,\n carReluctance\n }\n };\n}\n"],"file":"query-gen.js"}
package/esm/state.js ADDED
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"state.js"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=graphql.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"graphql.d.js"}
package/lib/index.d.ts CHANGED
@@ -4,11 +4,13 @@ import * as route from "./route";
4
4
  import * as storage from "./storage";
5
5
  import * as time from "./time";
6
6
  import * as ui from "./ui";
7
+ import * as queryGen from "./query-gen";
7
8
  declare const core: {
8
9
  itinerary: typeof itinerary;
9
10
  map: typeof map;
10
11
  profile: any;
11
12
  query: any;
13
+ queryGen: typeof queryGen;
12
14
  queryParams: any;
13
15
  route: typeof route;
14
16
  storage: typeof storage;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAI7B,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC;AAE3B,QAAA,MAAM,IAAI;;;;;;;;;;CAUT,CAAC;AAEF,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAI7B,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC;AAC3B,OAAO,KAAK,QAAQ,MAAM,aAAa,CAAC;AAExC,QAAA,MAAM,IAAI;;;;;;;;;;;CAWT,CAAC;AAEF,eAAe,IAAI,CAAC"}
package/lib/index.js CHANGED
@@ -23,6 +23,8 @@ var time = _interopRequireWildcard(require("./time"));
23
23
 
24
24
  var ui = _interopRequireWildcard(require("./ui"));
25
25
 
26
+ var queryGen = _interopRequireWildcard(require("./query-gen"));
27
+
26
28
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
29
 
28
30
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -32,6 +34,7 @@ const core = {
32
34
  map,
33
35
  profile,
34
36
  query,
37
+ queryGen,
35
38
  queryParams,
36
39
  route,
37
40
  storage,
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["core","itinerary","map","profile","query","queryParams","route","storage","time","ui"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,MAAMA,IAAI,GAAG;AACXC,EAAAA,SADW;AAEXC,EAAAA,GAFW;AAGXC,EAAAA,OAHW;AAIXC,EAAAA,KAJW;AAKXC,EAAAA,WALW;AAMXC,EAAAA,KANW;AAOXC,EAAAA,OAPW;AAQXC,EAAAA,IARW;AASXC,EAAAA;AATW,CAAb;eAYeT,I","sourcesContent":["import * as itinerary from \"./itinerary\";\nimport * as map from \"./map\";\nimport * as profile from \"./profile\";\nimport * as query from \"./query\";\nimport * as queryParams from \"./query-params\";\nimport * as route from \"./route\";\nimport * as storage from \"./storage\";\nimport * as time from \"./time\";\nimport * as ui from \"./ui\";\n\nconst core = {\n itinerary,\n map,\n profile,\n query,\n queryParams,\n route,\n storage,\n time,\n ui\n};\n\nexport default core;\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["core","itinerary","map","profile","query","queryGen","queryParams","route","storage","time","ui"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,MAAMA,IAAI,GAAG;AACXC,EAAAA,SADW;AAEXC,EAAAA,GAFW;AAGXC,EAAAA,OAHW;AAIXC,EAAAA,KAJW;AAKXC,EAAAA,QALW;AAMXC,EAAAA,WANW;AAOXC,EAAAA,KAPW;AAQXC,EAAAA,OARW;AASXC,EAAAA,IATW;AAUXC,EAAAA;AAVW,CAAb;eAaeV,I","sourcesContent":["import * as itinerary from \"./itinerary\";\nimport * as map from \"./map\";\nimport * as profile from \"./profile\";\nimport * as query from \"./query\";\nimport * as queryParams from \"./query-params\";\nimport * as route from \"./route\";\nimport * as storage from \"./storage\";\nimport * as time from \"./time\";\nimport * as ui from \"./ui\";\nimport * as queryGen from \"./query-gen\";\n\nconst core = {\n itinerary,\n map,\n profile,\n query,\n queryGen,\n queryParams,\n route,\n storage,\n time,\n ui\n};\n\nexport default core;\n"],"file":"index.js"}
@@ -0,0 +1,31 @@
1
+ import { ModeSetting, TransportMode } from "@opentripplanner/types";
2
+ import { LonLatOutput } from "@conveyal/lonlat";
3
+ declare type OTPQueryParams = {
4
+ to: LonLatOutput;
5
+ from: LonLatOutput;
6
+ modes: Array<TransportMode>;
7
+ modeSettings: ModeSetting[];
8
+ };
9
+ export declare const SIMPLIFICATIONS: {
10
+ AIRPLANE: string;
11
+ BICYCLE: string;
12
+ BUS: string;
13
+ CABLE_CAR: string;
14
+ CAR: string;
15
+ FERRY: string;
16
+ FLEX: string;
17
+ FUNICULAR: string;
18
+ GONDOLA: string;
19
+ RAIL: string;
20
+ SCOOTER: string;
21
+ SUBWAY: string;
22
+ TRAM: string;
23
+ TRANSIT: string;
24
+ WALK: string;
25
+ };
26
+ export declare const TRANSIT_SUBMODES: string[];
27
+ export declare const TRANSIT_SUBMODES_AND_TRANSIT: string[];
28
+ export declare function generateCombinations(params: OTPQueryParams): OTPQueryParams[];
29
+ export declare function generateOtp2Query(params: OTPQueryParams): any;
30
+ export {};
31
+ //# sourceMappingURL=query-gen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-gen.d.ts","sourceRoot":"","sources":["../src/query-gen.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,WAAW,EAEX,aAAa,EACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,aAAK,cAAc,GAAG;IACpB,EAAE,EAAE,YAAY,CAAC;IACjB,IAAI,EAAE,YAAY,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;IAC5B,YAAY,EAAE,WAAW,EAAE,CAAC;CAC7B,CAAC;AAmBF,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;CAgB3B,CAAC;AAEF,eAAO,MAAM,gBAAgB,UAE5B,CAAC;AACF,eAAO,MAAM,4BAA4B,UAExC,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,EAAE,CA2D7E;AAGD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc,GAAG,GAAG,CA8B7D"}
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.generateCombinations = generateCombinations;
7
+ exports.generateOtp2Query = generateOtp2Query;
8
+ exports.TRANSIT_SUBMODES_AND_TRANSIT = exports.TRANSIT_SUBMODES = exports.SIMPLIFICATIONS = void 0;
9
+
10
+ var _graphql = require("graphql");
11
+
12
+ /* eslint-disable @typescript-eslint/no-unused-vars */
13
+ var PlanQuery = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "PlanQuery" }, variableDefinitions: [{ kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "fromPlace" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "toPlace" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "modes" } }, type: { kind: "ListType", type: { kind: "NamedType", name: { kind: "Name", value: "TransportMode" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "time" } }, type: { kind: "NamedType", name: { kind: "Name", value: "String" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "date" } }, type: { kind: "NamedType", name: { kind: "Name", value: "String" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "wheelchair" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Boolean" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "bikeReluctance" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Float" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "carReluctance" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Float" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "walkReluctance" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Float" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "arriveBy" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Boolean" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "intermediatePlaces" } }, type: { kind: "ListType", type: { kind: "NamedType", name: { kind: "Name", value: "InputCoordinates" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "preferred" } }, type: { kind: "NamedType", name: { kind: "Name", value: "InputPreferred" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "unpreferred" } }, type: { kind: "NamedType", name: { kind: "Name", value: "InputUnpreferred" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "banned" } }, type: { kind: "NamedType", name: { kind: "Name", value: "InputBanned" } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "plan" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "fromPlace" }, value: { kind: "Variable", name: { kind: "Name", value: "fromPlace" } } }, { kind: "Argument", name: { kind: "Name", value: "toPlace" }, value: { kind: "Variable", name: { kind: "Name", value: "toPlace" } } }, { kind: "Argument", name: { kind: "Name", value: "transportModes" }, value: { kind: "Variable", name: { kind: "Name", value: "modes" } } }, { kind: "Argument", name: { kind: "Name", value: "locale" }, value: { kind: "StringValue", value: "en", block: false } }, { kind: "Argument", name: { kind: "Name", value: "time" }, value: { kind: "Variable", name: { kind: "Name", value: "time" } } }, { kind: "Argument", name: { kind: "Name", value: "date" }, value: { kind: "Variable", name: { kind: "Name", value: "date" } } }, { kind: "Argument", name: { kind: "Name", value: "wheelchair" }, value: { kind: "Variable", name: { kind: "Name", value: "wheelchair" } } }, { kind: "Argument", name: { kind: "Name", value: "bikeReluctance" }, value: { kind: "Variable", name: { kind: "Name", value: "bikeReluctance" } } }, { kind: "Argument", name: { kind: "Name", value: "carReluctance" }, value: { kind: "Variable", name: { kind: "Name", value: "carReluctance" } } }, { kind: "Argument", name: { kind: "Name", value: "walkReluctance" }, value: { kind: "Variable", name: { kind: "Name", value: "walkReluctance" } } }, { kind: "Argument", name: { kind: "Name", value: "arriveBy" }, value: { kind: "Variable", name: { kind: "Name", value: "arriveBy" } } }, { kind: "Argument", name: { kind: "Name", value: "intermediatePlaces" }, value: { kind: "Variable", name: { kind: "Name", value: "intermediatePlaces" } } }, { kind: "Argument", name: { kind: "Name", value: "preferred" }, value: { kind: "Variable", name: { kind: "Name", value: "preferred" } } }, { kind: "Argument", name: { kind: "Name", value: "unpreferred" }, value: { kind: "Variable", name: { kind: "Name", value: "unpreferred" } } }, { kind: "Argument", name: { kind: "Name", value: "banned" }, value: { kind: "Variable", name: { kind: "Name", value: "banned" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "itineraries" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "duration" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "endTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "startTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "waitingTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "walkTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "legs" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "distance" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "duration" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "endTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "mode" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "realTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "realtimeState" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "startTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "transitLeg" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "agency" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "timezone" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "url" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "legGeometry" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "length" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "points" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "intermediateStops" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "lat" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", alias: { kind: "Name", value: "stopCode" }, name: { kind: "Name", value: "code" }, arguments: [], directives: [] }, { kind: "Field", alias: { kind: "Name", value: "stopId" }, name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "locationType" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "route" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "shortName" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "color" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "textColor" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "type" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "from" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "lat" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "vertexType" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "stop" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "code" }, arguments: [], directives: [] }] } }] } }, { kind: "Field", name: { kind: "Name", value: "to" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "lat" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "vertexType" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "stop" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "code" }, arguments: [], directives: [] }] } }] } }, { kind: "Field", name: { kind: "Name", value: "steps" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "distance" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lat" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "elevationProfile" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "distance" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "elevation" }, arguments: [], directives: [] }] } }] } }] } }] } }] } }] } }], loc: { start: 0, end: 1587, source: { body: "query PlanQuery(\n\t$fromPlace: String!,\n\t$toPlace: String!,\n\t$modes: [TransportMode],\n\t$time: String,\n\t$date: String,\n\t$wheelchair: Boolean,\n\t$bikeReluctance: Float,\n\t$carReluctance: Float,\n\t$walkReluctance: Float,\n\t$arriveBy: Boolean,\n\t$intermediatePlaces: [InputCoordinates],\n\t$preferred: InputPreferred,\n\t$unpreferred: InputUnpreferred,\n\t$banned: InputBanned,\n) {\n\tplan(\n\t\tfromPlace: $fromPlace\n\t\ttoPlace: $toPlace\n\t\ttransportModes: $modes\n\t\tlocale: \"en\",\n\t\ttime: $time,\n\t\tdate: $date,\n\t\twheelchair: $wheelchair,\n\t\tbikeReluctance: $bikeReluctance,\n\t\tcarReluctance: $carReluctance,\n\t\twalkReluctance: $walkReluctance,\n\t\tarriveBy: $arriveBy,\n\t\tintermediatePlaces: $intermediatePlaces,\n\t\tpreferred: $preferred,\n\t\tunpreferred: $unpreferred,\n\t\tbanned: $banned,\n\t) {\n\t\titineraries {\n\t\t\tduration\n\t\t\tendTime\n\t\t\tstartTime\n\t\t\twaitingTime\n\t\t\twalkTime\n\t\t\tlegs {\n\t\t\t\tdistance\n\t\t\t\tduration\n\t\t\t\tendTime\n\t\t\t\tmode\n\t\t\t\trealTime\n\t\t\t\trealtimeState\t\n\t\t\t\tstartTime\n\t\t\t\ttransitLeg\n\t\t\t\tagency {\n\t\t\t\t\tname\n\t\t\t\t\tid\n\t\t\t\t\ttimezone\n\t\t\t\t\turl\n\t\t\t\t}\n\t\t\t\tlegGeometry {\n\t\t\t\t\tlength\n\t\t\t\t\tpoints\n\t\t\t\t}\n\t\t\t\tintermediateStops {\n\t\t\t\t\tlat\n\t\t\t\t\tlon\n\t\t\t\t\tname\n\t\t\t\t\tstopCode: code\n\t\t\t\t\tstopId: id\n\t\t\t\t\tlocationType\n\t\t\t\t}\n\t\t\t\troute {\n\t\t\t\t\tshortName\n\t\t\t\t\tcolor\n\t\t\t\t\ttextColor\n\t\t\t\t\tid\n\t\t\t\t\ttype\n\t\t\t\t}\n\t\t\t\tfrom {\n\t\t\t\t\tlat\n\t\t\t\t\tlon\n\t\t\t\t\tname\n\t\t\t\t\tvertexType\n\t\t\t\t\tstop {\n\t\t\t\t\t\tid\n\t\t\t\t\t\tcode\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tto {\n\t\t\t\t\tlat\n\t\t\t\t\tlon\n\t\t\t\t\tname\n\t\t\t\t\tvertexType\n\t\t\t\t\tstop {\n\t\t\t\t\t\tid\n\t\t\t\t\t\tcode\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tsteps {\n\t\t\t\t\tdistance\n\t\t\t\t\tlat\n\t\t\t\t\tlon\n\t\t\t\t\televationProfile {\n\t\t\t\t\t\tdistance\n\t\t\t\t\t\televation\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
14
+
15
+ /**
16
+ * Generates every possible mathematical subset of the input TransportModes.
17
+ * Uses code from:
18
+ * https://stackoverflow.com/questions/5752002/find-all-possible-subset-combos-in-an-array
19
+ * @param array Array of input transport modes
20
+ * @returns 2D array representing every possible subset of transport modes from input
21
+ */
22
+ function combinations(array) {
23
+ if (!array) return [];
24
+ return (// eslint-disable-next-line no-bitwise
25
+ new Array(1 << array.length).fill(null) // eslint-disable-next-line no-bitwise
26
+ .map((e1, i) => array.filter((e2, j) => i & 1 << j))
27
+ );
28
+ }
29
+
30
+ const SIMPLIFICATIONS = {
31
+ AIRPLANE: "TRANSIT",
32
+ BICYCLE: "PERSONAL",
33
+ BUS: "TRANSIT",
34
+ CABLE_CAR: "TRANSIT",
35
+ CAR: "CAR",
36
+ FERRY: "TRANSIT",
37
+ FLEX: "SHARED",
38
+ // TODO: this allows FLEX+WALK. Is this reasonable?
39
+ FUNICULAR: "TRANSIT",
40
+ GONDOLA: "TRANSIT",
41
+ RAIL: "TRANSIT",
42
+ SCOOTER: "PERSONAL",
43
+ SUBWAY: "TRANSIT",
44
+ TRAM: "TRANSIT",
45
+ TRANSIT: "TRANSIT",
46
+ WALK: "WALK"
47
+ };
48
+ exports.SIMPLIFICATIONS = SIMPLIFICATIONS;
49
+ const TRANSIT_SUBMODES = Object.keys(SIMPLIFICATIONS).filter(mode => SIMPLIFICATIONS[mode] === "TRANSIT" && mode !== "TRANSIT");
50
+ exports.TRANSIT_SUBMODES = TRANSIT_SUBMODES;
51
+ const TRANSIT_SUBMODES_AND_TRANSIT = Object.keys(SIMPLIFICATIONS).filter(mode => SIMPLIFICATIONS[mode] === "TRANSIT");
52
+ exports.TRANSIT_SUBMODES_AND_TRANSIT = TRANSIT_SUBMODES_AND_TRANSIT;
53
+
54
+ function generateCombinations(params) {
55
+ const VALID_COMBOS = [["WALK"], ["PERSONAL"], ["TRANSIT", "SHARED"], ["WALK", "SHARED"], ["TRANSIT"], ["TRANSIT", "PERSONAL"], ["TRANSIT", "CAR"]];
56
+ const BANNED_TOGETHER = ["SCOOTER", "BICYCLE"]; // List of the transit submodes that are included in the input params
57
+
58
+ const queryTransitSubmodes = params.modes.filter(mode => TRANSIT_SUBMODES.includes(mode.mode)).map(mode => mode.mode);
59
+ return combinations(params.modes).filter(combo => {
60
+ if (combo.length === 0) return false; // All current qualifiers currently simplify to "SHARED"
61
+
62
+ const simplifiedModes = Array.from(new Set(combo.map(c => c.qualifier ? "SHARED" : SIMPLIFICATIONS[c.mode]))); // Ensure that if we have one transit mode, then we include ALL transit modes
63
+
64
+ if (simplifiedModes.includes("TRANSIT")) {
65
+ const flatModes = combo.map(m => m.mode);
66
+
67
+ if (combo.reduce((prev, cur) => {
68
+ if (queryTransitSubmodes.includes(cur.mode)) {
69
+ return prev - 1;
70
+ }
71
+
72
+ return prev;
73
+ }, queryTransitSubmodes.length) !== 0) {
74
+ return false;
75
+ }
76
+ } // OTP doesn't support multiple non-walk modes
77
+
78
+
79
+ if (BANNED_TOGETHER.every(m => combo.find(c => c.mode === m))) return false;
80
+ return !!VALID_COMBOS.find(vc => simplifiedModes.every(m => vc.includes(m)) && vc.every(m => simplifiedModes.includes(m)));
81
+ }) // create new filter that removes subTransit modes from appearing on their own
82
+ // ONLY IF there's multiple of them!
83
+ .map(combo => ({ ...params,
84
+ modes: combo
85
+ }));
86
+ } // eslint-disable-next-line import/prefer-default-export
87
+
88
+
89
+ function generateOtp2Query(params) {
90
+ const {
91
+ to,
92
+ from,
93
+ modeSettings
94
+ } = params; // This extracts the values from the mode settings to key value pairs
95
+
96
+ const modeSettingValues = modeSettings.reduce((prev, cur) => {
97
+ prev[cur.key] = cur.value;
98
+ return prev;
99
+ }, {});
100
+ const {
101
+ walkReluctance,
102
+ wheelchair,
103
+ bikeReluctance,
104
+ carReluctance,
105
+ allowBikeRental
106
+ } = modeSettingValues;
107
+ return {
108
+ query: (0, _graphql.print)(PlanQuery),
109
+ variables: {
110
+ fromPlace: [from.lat, from.lon].join(","),
111
+ toPlace: [to.lat, to.lon].join(","),
112
+ modes: params.modes,
113
+ allowBikeRental,
114
+ walkReluctance,
115
+ wheelchair,
116
+ bikeReluctance,
117
+ carReluctance
118
+ }
119
+ };
120
+ }
121
+ //# sourceMappingURL=query-gen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/query-gen.ts"],"names":["combinations","array","Array","length","fill","map","e1","i","filter","e2","j","SIMPLIFICATIONS","AIRPLANE","BICYCLE","BUS","CABLE_CAR","CAR","FERRY","FLEX","FUNICULAR","GONDOLA","RAIL","SCOOTER","SUBWAY","TRAM","TRANSIT","WALK","TRANSIT_SUBMODES","Object","keys","mode","TRANSIT_SUBMODES_AND_TRANSIT","generateCombinations","params","VALID_COMBOS","BANNED_TOGETHER","queryTransitSubmodes","modes","includes","combo","simplifiedModes","from","Set","c","qualifier","flatModes","m","reduce","prev","cur","every","find","vc","generateOtp2Query","to","modeSettings","modeSettingValues","key","value","walkReluctance","wheelchair","bikeReluctance","carReluctance","allowBikeRental","query","PlanQuery","variables","fromPlace","lat","lon","join","toPlace"],"mappings":";;;;;;;;;AACA;;AADA;;;AAiBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,YAAT,CAAsBC,KAAtB,EAAiE;AAC/D,MAAI,CAACA,KAAL,EAAY,OAAO,EAAP;AACZ,SACE;AACA,QAAIC,KAAJ,CAAU,KAAKD,KAAK,CAACE,MAArB,EACGC,IADH,CACQ,IADR,EAEE;AAFF,KAGGC,GAHH,CAGO,CAACC,EAAD,EAAKC,CAAL,KAAWN,KAAK,CAACO,MAAN,CAAa,CAACC,EAAD,EAAKC,CAAL,KAAWH,CAAC,GAAI,KAAKG,CAAlC,CAHlB;AAFF;AAOD;;AACM,MAAMC,eAAe,GAAG;AAC7BC,EAAAA,QAAQ,EAAE,SADmB;AAE7BC,EAAAA,OAAO,EAAE,UAFoB;AAG7BC,EAAAA,GAAG,EAAE,SAHwB;AAI7BC,EAAAA,SAAS,EAAE,SAJkB;AAK7BC,EAAAA,GAAG,EAAE,KALwB;AAM7BC,EAAAA,KAAK,EAAE,SANsB;AAO7BC,EAAAA,IAAI,EAAE,QAPuB;AAOb;AAChBC,EAAAA,SAAS,EAAE,SARkB;AAS7BC,EAAAA,OAAO,EAAE,SAToB;AAU7BC,EAAAA,IAAI,EAAE,SAVuB;AAW7BC,EAAAA,OAAO,EAAE,UAXoB;AAY7BC,EAAAA,MAAM,EAAE,SAZqB;AAa7BC,EAAAA,IAAI,EAAE,SAbuB;AAc7BC,EAAAA,OAAO,EAAE,SAdoB;AAe7BC,EAAAA,IAAI,EAAE;AAfuB,CAAxB;;AAkBA,MAAMC,gBAAgB,GAAGC,MAAM,CAACC,IAAP,CAAYlB,eAAZ,EAA6BH,MAA7B,CAC9BsB,IAAI,IAAInB,eAAe,CAACmB,IAAD,CAAf,KAA0B,SAA1B,IAAuCA,IAAI,KAAK,SAD1B,CAAzB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AOV,IAAP;AACD,GAHyB,EAGvB,EAHuB,CAA1B;AAKA,QAAM;AACJW,IAAAA,cADI;AAEJC,IAAAA,UAFI;AAGJC,IAAAA,cAHI;AAIJC,IAAAA,aAJI;AAKJC,IAAAA;AALI,MAMFP,iBANJ;AAQA,SAAO;AACLQ,IAAAA,KAAK,EAAE,oBAAMC,SAAN,CADF;AAELC,IAAAA,SAAS,EAAE;AACTC,MAAAA,SAAS,EAAE,CAAC1B,IAAI,CAAC2B,GAAN,EAAW3B,IAAI,CAAC4B,GAAhB,EAAqBC,IAArB,CAA0B,GAA1B,CADF;AAETC,MAAAA,OAAO,EAAE,CAACjB,EAAE,CAACc,GAAJ,EAASd,EAAE,CAACe,GAAZ,EAAiBC,IAAjB,CAAsB,GAAtB,CAFA;AAGTjC,MAAAA,KAAK,EAAEJ,MAAM,CAACI,KAHL;AAIT0B,MAAAA,eAJS;AAKTJ,MAAAA,cALS;AAMTC,MAAAA,UANS;AAOTC,MAAAA,cAPS;AAQTC,MAAAA;AARS;AAFN,GAAP;AAaD","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { print } from \"graphql\";\nimport {\n ModeSetting,\n ModeSettingValues,\n TransportMode\n} from \"@opentripplanner/types\";\nimport { LonLatOutput } from \"@conveyal/lonlat\";\nimport PlanQuery from \"./planQuery.graphql\";\n\ntype OTPQueryParams = {\n to: LonLatOutput;\n from: LonLatOutput;\n modes: Array<TransportMode>;\n modeSettings: ModeSetting[];\n};\n\n/**\n * Generates every possible mathematical subset of the input TransportModes.\n * Uses code from:\n * https://stackoverflow.com/questions/5752002/find-all-possible-subset-combos-in-an-array\n * @param array Array of input transport modes\n * @returns 2D array representing every possible subset of transport modes from input\n */\nfunction combinations(array: TransportMode[]): TransportMode[][] {\n if (!array) return [];\n return (\n // eslint-disable-next-line no-bitwise\n new Array(1 << array.length)\n .fill(null)\n // eslint-disable-next-line no-bitwise\n .map((e1, i) => array.filter((e2, j) => i & (1 << j)))\n );\n}\nexport const SIMPLIFICATIONS = {\n AIRPLANE: \"TRANSIT\",\n BICYCLE: \"PERSONAL\",\n BUS: \"TRANSIT\",\n CABLE_CAR: \"TRANSIT\",\n CAR: \"CAR\",\n FERRY: \"TRANSIT\",\n FLEX: \"SHARED\", // TODO: this allows FLEX+WALK. Is this reasonable?\n FUNICULAR: \"TRANSIT\",\n GONDOLA: \"TRANSIT\",\n RAIL: \"TRANSIT\",\n SCOOTER: \"PERSONAL\",\n SUBWAY: \"TRANSIT\",\n TRAM: \"TRANSIT\",\n TRANSIT: \"TRANSIT\",\n WALK: \"WALK\"\n};\n\nexport const TRANSIT_SUBMODES = Object.keys(SIMPLIFICATIONS).filter(\n mode => SIMPLIFICATIONS[mode] === \"TRANSIT\" && mode !== \"TRANSIT\"\n);\nexport const TRANSIT_SUBMODES_AND_TRANSIT = Object.keys(SIMPLIFICATIONS).filter(\n mode => SIMPLIFICATIONS[mode] === \"TRANSIT\"\n);\n\nexport function generateCombinations(params: OTPQueryParams): OTPQueryParams[] {\n const VALID_COMBOS = [\n [\"WALK\"],\n [\"PERSONAL\"],\n [\"TRANSIT\", \"SHARED\"],\n [\"WALK\", \"SHARED\"],\n [\"TRANSIT\"],\n [\"TRANSIT\", \"PERSONAL\"],\n [\"TRANSIT\", \"CAR\"]\n ];\n\n const BANNED_TOGETHER = [\"SCOOTER\", \"BICYCLE\"];\n\n // List of the transit submodes that are included in the input params\n const queryTransitSubmodes = params.modes\n .filter(mode => TRANSIT_SUBMODES.includes(mode.mode))\n .map(mode => mode.mode);\n\n return (\n combinations(params.modes)\n .filter(combo => {\n if (combo.length === 0) return false;\n\n // All current qualifiers currently simplify to \"SHARED\"\n const simplifiedModes = Array.from(\n new Set(\n combo.map(c => (c.qualifier ? \"SHARED\" : SIMPLIFICATIONS[c.mode]))\n )\n );\n\n // Ensure that if we have one transit mode, then we include ALL transit modes\n if (simplifiedModes.includes(\"TRANSIT\")) {\n const flatModes = combo.map(m => m.mode);\n if (\n combo.reduce((prev, cur) => {\n if (queryTransitSubmodes.includes(cur.mode)) {\n return prev - 1;\n }\n return prev;\n }, queryTransitSubmodes.length) !== 0\n ) {\n return false;\n }\n }\n\n // OTP doesn't support multiple non-walk modes\n if (BANNED_TOGETHER.every(m => combo.find(c => c.mode === m)))\n return false;\n\n return !!VALID_COMBOS.find(\n vc =>\n simplifiedModes.every(m => vc.includes(m)) &&\n vc.every(m => simplifiedModes.includes(m))\n );\n })\n // create new filter that removes subTransit modes from appearing on their own\n // ONLY IF there's multiple of them!\n .map(combo => ({ ...params, modes: combo }))\n );\n}\n\n// eslint-disable-next-line import/prefer-default-export\nexport function generateOtp2Query(params: OTPQueryParams): any {\n const { to, from, modeSettings } = params;\n\n // This extracts the values from the mode settings to key value pairs\n const modeSettingValues = modeSettings.reduce((prev, cur) => {\n prev[cur.key] = cur.value;\n return prev;\n }, {}) as ModeSettingValues;\n\n const {\n walkReluctance,\n wheelchair,\n bikeReluctance,\n carReluctance,\n allowBikeRental\n } = modeSettingValues;\n\n return {\n query: print(PlanQuery),\n variables: {\n fromPlace: [from.lat, from.lon].join(\",\"),\n toPlace: [to.lat, to.lon].join(\",\"),\n modes: params.modes,\n allowBikeRental,\n walkReluctance,\n wheelchair,\n bikeReluctance,\n carReluctance\n }\n };\n}\n"],"file":"query-gen.js"}
package/lib/state.d.ts ADDED
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":""}
package/lib/state.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"state.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentripplanner/core-utils",
3
- "version": "9.0.0-alpha.1",
3
+ "version": "9.0.0-alpha.3",
4
4
  "description": "Core functionality that is shared among numerous UI components",
5
5
  "engines": {
6
6
  "node": ">=13"
@@ -12,6 +12,7 @@
12
12
  "license": "MIT",
13
13
  "private": false,
14
14
  "dependencies": {
15
+ "@conveyal/lonlat": "^1.4.1",
15
16
  "@mapbox/polyline": "^1.1.0",
16
17
  "@opentripplanner/geocoder": "^1.3.2",
17
18
  "@styled-icons/foundation": "^10.34.0",
@@ -20,6 +21,7 @@
20
21
  "chroma-js": "^2.4.2",
21
22
  "date-fns": "^2.28.0",
22
23
  "date-fns-tz": "^1.2.2",
24
+ "graphql-tag": "^2.12.6",
23
25
  "lodash.clonedeep": "^4.5.0",
24
26
  "lodash.isequal": "^4.5.0",
25
27
  "qs": "^6.9.1"
@@ -29,7 +31,8 @@
29
31
  "tsc": "tsc"
30
32
  },
31
33
  "devDependencies": {
34
+ "@opentripplanner/types": "4.1.0-alpha.4",
32
35
  "@types/chroma-js": "^2.1.4",
33
- "@opentripplanner/types": "^4.0.2"
36
+ "babel-plugin-graphql-tag": "^3.3.0"
34
37
  }
35
38
  }