@transportme/load-ptv-gtfs 1.4.32 → 1.4.34

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.
@@ -13,9 +13,11 @@ export default class RouteLoader {
13
13
  #routesReader
14
14
  #operators = {}
15
15
  #agencyFile
16
+ #routesFile
16
17
 
17
18
  #routeIDMap = {}
18
19
 
20
+
19
21
  /**
20
22
  * Creates a new Shape Loader.
21
23
  *
@@ -27,8 +29,8 @@ export default class RouteLoader {
27
29
  constructor(routesFile, agencyFile, mode, database) {
28
30
  this.#routes = this.getRoutesDB(database)
29
31
  this.#mode = mode
30
- this.#routesReader = this.createRouteReader(routesFile, mode)
31
- this.#agencyFile = agencyFile
32
+ this.#routesFile = routesFile
33
+ this.#agencyFile = agencyFile
32
34
  }
33
35
 
34
36
  getRoutesDB(db) {
@@ -111,6 +113,8 @@ export default class RouteLoader {
111
113
  async loadRoutes({ processRoute } = {}) {
112
114
  await this.loadAgencies()
113
115
 
116
+ this.#routesReader = this.createRouteReader(this.#routesFile, this.#mode)
117
+
114
118
  await this.#routesReader.open()
115
119
  while (this.#routesReader.available()) {
116
120
  try {
@@ -6,6 +6,8 @@ export default class ShapeLoader {
6
6
  #routes
7
7
  #shapeReader
8
8
 
9
+ #shapeFile
10
+
9
11
  #routeCache = {}
10
12
 
11
13
  /**
@@ -16,7 +18,7 @@ export default class ShapeLoader {
16
18
  */
17
19
  constructor(shapeFile, database) {
18
20
  this.#routes = this.getRoutesDB(database)
19
- this.#shapeReader = this.createShapeReader(shapeFile)
21
+ this.#shapeFile = shapeFile
20
22
  }
21
23
 
22
24
  getRoutesDB(db) {
@@ -83,6 +85,8 @@ export default class ShapeLoader {
83
85
  * @param {function} options.shapeIDMap A mapping of shape IDs to their trip IDs.
84
86
  */
85
87
  async loadShapes({ shapeIDMap }) {
88
+ this.#shapeReader = this.createShapeReader(this.#shapeFile)
89
+
86
90
  await this.#shapeReader.open()
87
91
 
88
92
  let shapesLoaded = 0
@@ -10,6 +10,10 @@ export default class StopsLoader {
10
10
  #mode
11
11
  #stopsReader
12
12
 
13
+ #stopsFile
14
+ #suburbs
15
+ #suburbHook
16
+
13
17
  #parentHolding = {}
14
18
 
15
19
  /**
@@ -25,7 +29,9 @@ export default class StopsLoader {
25
29
  constructor(stopsFile, suburbs, mode, database, suburbHook) {
26
30
  this.#stops = this.getStopsDB(database)
27
31
  this.#mode = mode
28
- this.#stopsReader = this.createStopReader(stopsFile, suburbs, suburbHook)
32
+ this.#stopsFile = stopsFile
33
+ this.#suburbs = suburbs
34
+ this.#suburbHook = suburbHook
29
35
  }
30
36
 
31
37
  getStopsDB(db) {
@@ -195,6 +201,7 @@ export default class StopsLoader {
195
201
  * @param {function} options.getMergeName Used to get a stop's merge name. Return null to use the default merge name.
196
202
  */
197
203
  async loadStops(options) {
204
+ this.#stopsReader = this.createStopReader(this.#stopsFile, this.#suburbs, this.#suburbHook)
198
205
  await this.#stopsReader.open()
199
206
  while (this.#stopsReader.available()) {
200
207
  try {
@@ -32,6 +32,11 @@ export default class TripLoader {
32
32
 
33
33
  #tripsToLoad = []
34
34
 
35
+ #tripsFile
36
+ #stopTimesFile
37
+ #calendarFile
38
+ #calendarDatesFile
39
+
35
40
  /**
36
41
  * Creates a new Trip Loader.
37
42
  *
@@ -50,9 +55,10 @@ export default class TripLoader {
50
55
 
51
56
  this.#mode = mode
52
57
 
53
- this.#stopTimesReader = this.createStopTimesReader(stopTimesFile, mode)
54
- this.#tripsReader = this.createTripReader(tripsFile, null, null, mode)
55
- this.#calendarReader = this.createCalendarReader(calendarFile, calendarDatesFile)
58
+ this.#tripsFile = tripsFile
59
+ this.#stopTimesFile = stopTimesFile
60
+ this.#calendarFile = calendarFile
61
+ this.#calendarDatesFile = calendarDatesFile
56
62
  }
57
63
 
58
64
  getRoutesDB(db) {
@@ -116,7 +122,12 @@ export default class TripLoader {
116
122
  if (this.#stopCache[stopGTFSID]) return this.#stopCache[stopGTFSID]
117
123
 
118
124
  let stop = await this.stops.findDocument({
119
- 'bays.stopGTFSID': stopGTFSID
125
+ bays: {
126
+ $elemMatch: {
127
+ stopGTFSID,
128
+ mode: this.#mode
129
+ }
130
+ }
120
131
  })
121
132
 
122
133
  this.#stopCache[stopGTFSID] = stop
@@ -131,6 +142,7 @@ export default class TripLoader {
131
142
  let stopData = await this.findMatchingStop(stop.stopID)
132
143
  if (!stopData) throw new Error(`Failed to match stop ${stop.stopID} in trip ${tripData.getTripID()}`)
133
144
  let bay = stopData.bays.find(bay => bay.stopGTFSID === stop.stopID && bay.mode === this.#mode)
145
+ if (!bay) throw new Error(`Missing bay for given stop ID ${stop.stopID} in trip ${tripData.getTripID()}`)
134
146
 
135
147
  let data = {
136
148
  stopName: bay.fullStopName,
@@ -230,6 +242,10 @@ export default class TripLoader {
230
242
  async loadTrips({ routeIDMap, processTrip, onWrite = () => {} }) {
231
243
  this.#routeIDMap = routeIDMap
232
244
 
245
+ this.#stopTimesReader = this.createStopTimesReader(this.#stopTimesFile, this.#mode)
246
+ this.#tripsReader = this.createTripReader(this.#tripsFile, null, null, this.#mode)
247
+ this.#calendarReader = this.createCalendarReader(this.#calendarFile, this.#calendarDatesFile)
248
+
233
249
  await this.loadCalendarData()
234
250
  await this.loadTripsData()
235
251
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transportme/load-ptv-gtfs",
3
- "version": "1.4.32",
3
+ "version": "1.4.34",
4
4
  "description": "",
5
5
  "main": "index.mjs",
6
6
  "scripts": {