@transportme/load-ptv-gtfs 1.4.34 → 1.4.35

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.
@@ -4,10 +4,12 @@ export default class GTFSCalendarDate {
4
4
 
5
5
  id
6
6
  date
7
+ rawDate
7
8
  type
8
9
 
9
10
  constructor({ id, date, type }) {
10
11
  this.id = id
12
+ this.rawDate = date
11
13
  this.date = dateUtils.parseDate(date)
12
14
  this.type = type
13
15
  }
@@ -6,6 +6,9 @@ export default class GTFSCalendarReader extends GTFSReader {
6
6
 
7
7
  #calendarDateFile
8
8
  #calendarDates = {}
9
+ #unprocessedCalendarDates = new Set()
10
+
11
+ #hasCalendar = true
9
12
 
10
13
  /**
11
14
  * Constructs a new GTFS Calendar reader.
@@ -19,14 +22,19 @@ export default class GTFSCalendarReader extends GTFSReader {
19
22
  }
20
23
 
21
24
  async open() {
22
- await super.open()
25
+ try {
26
+ await super.open()
27
+ } catch (e) { this.#hasCalendar = false }
23
28
 
24
29
  if (!this.#calendarDateFile) return
25
30
  let calendarDateReader = new GTFSCalendarDateReader(this.#calendarDateFile)
26
31
  await calendarDateReader.open()
27
32
  while (calendarDateReader.available()) {
28
33
  let calendarDate = await calendarDateReader.getNextEntity()
29
- if (!this.#calendarDates[calendarDate.id]) this.#calendarDates[calendarDate.id] = []
34
+ if (!this.#calendarDates[calendarDate.id]) {
35
+ this.#calendarDates[calendarDate.id] = []
36
+ this.#unprocessedCalendarDates.add(calendarDate.id)
37
+ }
30
38
  this.#calendarDates[calendarDate.id].push(calendarDate)
31
39
  }
32
40
  }
@@ -59,6 +67,30 @@ export default class GTFSCalendarReader extends GTFSReader {
59
67
  endDay: data.end_date
60
68
  }
61
69
 
70
+ this.#unprocessedCalendarDates.delete(data.service_id)
71
+
62
72
  return new GTFSCalendar(calendarData, this.#calendarDates[data.service_id])
63
73
  }
74
+
75
+ available() {
76
+ const underlyingAvailable = this.#hasCalendar ? super.available() : false
77
+ if (underlyingAvailable) return true
78
+ return this.#unprocessedCalendarDates.size > 0
79
+ }
80
+
81
+ getNextEntity() {
82
+ if (this.#hasCalendar && super.available()) return super.getNextEntity()
83
+ const calendarDate = Array.from(this.#unprocessedCalendarDates.values())[0]
84
+ const calendarData = this.#calendarDates[calendarDate]
85
+
86
+ const calendar = new GTFSCalendar({
87
+ id: calendarDate,
88
+ daysOfWeek: Array(7).fill(false),
89
+ startDay: calendarData[0].rawDate,
90
+ endDay: calendarData[0].rawDate
91
+ }, calendarData)
92
+
93
+ this.#unprocessedCalendarDates.delete(calendarDate)
94
+ return calendar
95
+ }
64
96
  }
@@ -31,7 +31,10 @@ export default class CSVLineReader {
31
31
  async open() {
32
32
  await new Promise((resolve, reject) => {
33
33
  lineReader.open(this.#file, async (err, reader) => {
34
- if (err) return reject(err)
34
+ if (err) {
35
+ err.stack = `${err.stack}\n${new Error().stack.split('\n').slice(1).join('\n')}`
36
+ return reject(err)
37
+ }
35
38
 
36
39
  this.#reader = reader
37
40
  this.#headers = (await this.#readNextLine()).split(',')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transportme/load-ptv-gtfs",
3
- "version": "1.4.34",
3
+ "version": "1.4.35",
4
4
  "description": "",
5
5
  "main": "index.mjs",
6
6
  "scripts": {