@opentripplanner/core-utils 8.2.3 → 8.3.0

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.
@@ -1,4 +1,4 @@
1
- query PlanQuery(
1
+ query Plan(
2
2
  $fromPlace: String!
3
3
  $toPlace: String!
4
4
  $modes: [TransportMode]
@@ -16,161 +16,168 @@ query PlanQuery(
16
16
  $numItineraries: Int
17
17
  ) {
18
18
  plan(
19
- fromPlace: $fromPlace
20
- toPlace: $toPlace
21
- transportModes: $modes
22
- # Currently only supporting EN locale, used for times and text
23
- locale: "en"
24
- time: $time
25
- date: $date
26
- wheelchair: $wheelchair
19
+ arriveBy: $arriveBy
20
+ banned: $banned
27
21
  bikeReluctance: $bikeReluctance
28
22
  carReluctance: $carReluctance
29
- walkReluctance: $walkReluctance
30
- arriveBy: $arriveBy
23
+ date: $date
24
+ fromPlace: $fromPlace
31
25
  intermediatePlaces: $intermediatePlaces
26
+ # Currently only supporting EN locale, used for times and text
27
+ locale: "en"
28
+ numItineraries: $numItineraries
32
29
  preferred: $preferred
30
+ time: $time
31
+ toPlace: $toPlace
32
+ transportModes: $modes
33
33
  unpreferred: $unpreferred
34
- banned: $banned
35
- numItineraries: $numItineraries
34
+ walkReluctance: $walkReluctance
35
+ wheelchair: $wheelchair
36
36
  ) {
37
- routingErrors {
38
- code
39
- inputField
40
- description
41
- }
42
37
  itineraries {
38
+ accessibilityScore
43
39
  duration
44
40
  endTime
45
- startTime
46
- waitingTime
47
- walkTime
48
- accessibilityScore
49
- legs {
50
- pickupType
51
- dropoffType
52
- pickupBookingInfo {
53
- earliestBookingTime {
54
- daysPrior
55
- }
56
- }
57
- rentedBike
58
- interlineWithPreviousLeg
59
- departureDelay
60
- arrivalDelay
61
- distance
62
- duration
63
- endTime
64
- mode
65
- realTime
66
- realtimeState
67
- startTime
68
- transitLeg
41
+ legs {
69
42
  accessibilityScore
70
- trip {
71
- id
72
- gtfsId
73
- tripHeadsign
74
- }
75
43
  agency {
76
- name
77
- id
78
- timezone
79
- url
80
44
  alerts {
81
- alertHeaderText
82
45
  alertDescriptionText
46
+ alertHeaderText
83
47
  alertUrl
84
48
  effectiveStartDate
49
+ id
85
50
  }
51
+ id
52
+ name
53
+ timezone
54
+ url
86
55
  }
87
- legGeometry {
88
- length
89
- points
56
+ arrivalDelay
57
+ departureDelay
58
+ distance
59
+ dropoffType
60
+ duration
61
+ endTime
62
+ from {
63
+ lat
64
+ lon
65
+ name
66
+ rentalVehicle {
67
+ id
68
+ network
69
+ }
70
+ stop {
71
+ alerts {
72
+ alertDescriptionText
73
+ alertHeaderText
74
+ alertUrl
75
+ effectiveStartDate
76
+ id
77
+ }
78
+ code
79
+ gtfsId
80
+ id
81
+ }
82
+ vertexType
90
83
  }
84
+ interlineWithPreviousLeg
91
85
  intermediateStops {
92
86
  lat
87
+ locationType
93
88
  lon
94
89
  name
95
90
  stopCode: code
96
91
  stopId: id
97
- locationType
98
92
  }
93
+ legGeometry {
94
+ length
95
+ points
96
+ }
97
+ mode
98
+ pickupBookingInfo {
99
+ earliestBookingTime {
100
+ daysPrior
101
+ }
102
+ }
103
+ pickupType
104
+ realTime
105
+ realtimeState
106
+ rentedBike
99
107
  route {
100
- shortName
101
- longName
108
+ alerts {
109
+ alertDescriptionText
110
+ alertHeaderText
111
+ alertUrl
112
+ effectiveStartDate
113
+ id
114
+ }
102
115
  color
103
- textColor
104
116
  id
117
+ longName
118
+ shortName
119
+ textColor
105
120
  type
121
+ }
122
+ startTime
123
+ steps {
124
+ absoluteDirection
106
125
  alerts {
107
- alertHeaderText
108
126
  alertDescriptionText
127
+ alertHeaderText
109
128
  alertUrl
110
129
  effectiveStartDate
130
+ id
131
+ }
132
+ area
133
+ distance
134
+ elevationProfile {
135
+ distance
136
+ elevation
111
137
  }
112
- }
113
- from {
114
138
  lat
115
139
  lon
116
- name
117
- vertexType
118
- rentalVehicle {
119
- network
120
- }
121
- stop {
122
- id
123
- code
124
- gtfsId
125
- alerts {
126
- alertHeaderText
127
- alertDescriptionText
128
- alertUrl
129
- effectiveStartDate
130
- }
131
- }
140
+ relativeDirection
141
+ stayOn
142
+ streetName
132
143
  }
133
144
  to {
134
145
  lat
135
146
  lon
136
147
  name
137
- vertexType
138
148
  rentalVehicle {
149
+ id
139
150
  network
140
151
  }
141
152
  stop {
142
- id
143
- code
144
- gtfsId
145
153
  alerts {
146
- alertHeaderText
147
154
  alertDescriptionText
155
+ alertHeaderText
148
156
  alertUrl
149
157
  effectiveStartDate
158
+ id
150
159
  }
160
+ code
161
+ gtfsId
162
+ id
151
163
  }
164
+ vertexType
152
165
  }
153
- steps {
154
- distance
155
- lat
156
- lon
157
- relativeDirection
158
- absoluteDirection
159
- stayOn
160
- streetName
161
- area
162
- alerts {
163
- alertHeaderText
164
- alertDescriptionText
165
- alertUrl
166
- effectiveStartDate
167
- }
168
- elevationProfile {
169
- distance
170
- elevation
171
- }
166
+ transitLeg
167
+ trip {
168
+ gtfsId
169
+ id
170
+ tripHeadsign
172
171
  }
173
172
  }
173
+ startTime
174
+ waitingTime
175
+ walkTime
176
+ }
177
+ routingErrors {
178
+ code
179
+ description
180
+ inputField
174
181
  }
175
182
  }
176
183
  }
package/src/query-gen.ts CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  TransportMode
7
7
  } from "@opentripplanner/types";
8
8
 
9
- import PlanQuery from "./planQuery.graphql";
9
+ import DefaultPlanQuery from "./planQuery.graphql";
10
10
 
11
11
  type InputBanned = {
12
12
  routes?: string;
@@ -127,7 +127,7 @@ const VALID_COMBOS = [
127
127
  ["TRANSIT", "CAR"]
128
128
  ];
129
129
 
130
- const BANNED_TOGETHER = ["SCOOTER", "BICYCLE"];
130
+ const BANNED_TOGETHER = ["SCOOTER", "BICYCLE", "CAR"];
131
131
 
132
132
  export const TRANSIT_SUBMODES = Object.keys(SIMPLIFICATIONS).filter(
133
133
  mode => SIMPLIFICATIONS[mode] === "TRANSIT" && mode !== "TRANSIT"
@@ -168,7 +168,9 @@ function isCombinationValid(
168
168
  }
169
169
 
170
170
  // OTP doesn't support multiple non-walk modes
171
- if (BANNED_TOGETHER.every(m => combo.find(c => c.mode === m))) return false;
171
+ if (BANNED_TOGETHER.filter(m => combo.find(c => c.mode === m)).length > 1) {
172
+ return false;
173
+ }
172
174
 
173
175
  return !!VALID_COMBOS.find(
174
176
  vc =>
@@ -199,18 +201,27 @@ export function generateCombinations(params: OTPQueryParams): OTPQueryParams[] {
199
201
  .map(combo => ({ ...params, modes: combo }));
200
202
  }
201
203
 
202
- export function generateOtp2Query({
203
- arriveBy,
204
- banned,
205
- date,
206
- from,
207
- modes,
208
- modeSettings,
209
- numItineraries,
210
- preferred,
211
- time,
212
- to
213
- }: OTPQueryParams): GraphQLQuery {
204
+ /**
205
+ * Generates a query for OTP GraphQL API based on parameters.
206
+ * @param param0 OTP2 Parameters for the query
207
+ * @param planQuery Override the default query for OTP
208
+ * @returns A fully formed query+variables ready to be sent to GraphQL backend
209
+ */
210
+ export function generateOtp2Query(
211
+ {
212
+ arriveBy,
213
+ banned,
214
+ date,
215
+ from,
216
+ modes,
217
+ modeSettings,
218
+ numItineraries,
219
+ preferred,
220
+ time,
221
+ to
222
+ }: OTPQueryParams,
223
+ planQuery = DefaultPlanQuery
224
+ ): GraphQLQuery {
214
225
  // This extracts the values from the mode settings to key value pairs
215
226
  const modeSettingValues = modeSettings.reduce((prev, cur) => {
216
227
  if (cur.type === "SLIDER" && cur.inverseKey) {
@@ -228,7 +239,7 @@ export function generateOtp2Query({
228
239
  } = modeSettingValues;
229
240
 
230
241
  return {
231
- query: print(PlanQuery),
242
+ query: print(planQuery),
232
243
  variables: {
233
244
  arriveBy,
234
245
  banned,