gtfs 3.1.0 → 3.1.4

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 (107) hide show
  1. package/.eslintrc.json +14 -19
  2. package/.husky/pre-commit +4 -0
  3. package/.prettierrc.js +4 -0
  4. package/CHANGELOG.md +173 -0
  5. package/README.md +115 -126
  6. package/bin/gtfs-export.js +4 -5
  7. package/bin/gtfs-import.js +6 -7
  8. package/config-sample-full.json +2 -7
  9. package/lib/db.js +4 -2
  10. package/lib/export.js +26 -9
  11. package/lib/file-utils.js +26 -9
  12. package/lib/geojson-utils.js +51 -38
  13. package/lib/gtfs/agencies.js +8 -2
  14. package/lib/gtfs/attributions.js +8 -2
  15. package/lib/gtfs/calendar-dates.js +8 -2
  16. package/lib/gtfs/calendars.js +8 -2
  17. package/lib/gtfs/fare-attributes.js +8 -2
  18. package/lib/gtfs/fare-rules.js +8 -2
  19. package/lib/gtfs/feed-info.js +8 -2
  20. package/lib/gtfs/frequencies.js +8 -2
  21. package/lib/gtfs/levels.js +8 -2
  22. package/lib/gtfs/pathways.js +8 -2
  23. package/lib/gtfs/routes.js +15 -4
  24. package/lib/gtfs/shapes.js +49 -18
  25. package/lib/gtfs/stop-times.js +8 -2
  26. package/lib/gtfs/stops.js +45 -16
  27. package/lib/gtfs/transfers.js +8 -2
  28. package/lib/gtfs/translations.js +8 -2
  29. package/lib/gtfs/trips.js +8 -2
  30. package/lib/gtfs-ride/board-alights.js +8 -2
  31. package/lib/gtfs-ride/ride-feed-infos.js +8 -2
  32. package/lib/gtfs-ride/rider-trips.js +8 -2
  33. package/lib/gtfs-ride/riderships.js +8 -2
  34. package/lib/gtfs-ride/trip-capacities.js +8 -2
  35. package/lib/import.js +200 -125
  36. package/lib/log-utils.js +8 -4
  37. package/lib/non-standard/directions.js +8 -2
  38. package/lib/non-standard/stop-attributes.js +8 -2
  39. package/lib/non-standard/timetable-notes-references.js +13 -3
  40. package/lib/non-standard/timetable-notes.js +8 -2
  41. package/lib/non-standard/timetable-pages.js +8 -2
  42. package/lib/non-standard/timetable-stop-order.js +13 -3
  43. package/lib/non-standard/timetables.js +8 -2
  44. package/lib/utils.js +22 -11
  45. package/models/gtfs/agency.js +11 -11
  46. package/models/gtfs/attributions.js +14 -14
  47. package/models/gtfs/calendar-dates.js +7 -7
  48. package/models/gtfs/calendar.js +12 -12
  49. package/models/gtfs/fare-attributes.js +9 -9
  50. package/models/gtfs/fare-rules.js +8 -8
  51. package/models/gtfs/feed-info.js +12 -12
  52. package/models/gtfs/frequencies.js +10 -10
  53. package/models/gtfs/levels.js +5 -5
  54. package/models/gtfs/pathways.js +14 -14
  55. package/models/gtfs/routes.js +14 -14
  56. package/models/gtfs/shapes.js +8 -8
  57. package/models/gtfs/stop-times.js +17 -17
  58. package/models/gtfs/stops.js +17 -17
  59. package/models/gtfs/transfers.js +7 -7
  60. package/models/gtfs/translations.js +10 -10
  61. package/models/gtfs/trips.js +12 -12
  62. package/models/gtfs-ride/board-alight.js +24 -24
  63. package/models/gtfs-ride/ride-feed-info.js +8 -8
  64. package/models/gtfs-ride/rider-trip.js +21 -21
  65. package/models/gtfs-ride/ridership.js +23 -23
  66. package/models/gtfs-ride/trip-capacity.js +10 -10
  67. package/models/models.js +1 -1
  68. package/models/non-standard/directions.js +6 -6
  69. package/models/non-standard/stop-attributes.js +5 -5
  70. package/models/non-standard/timetable-notes-references.js +9 -9
  71. package/models/non-standard/timetable-notes.js +5 -5
  72. package/models/non-standard/timetable-pages.js +5 -5
  73. package/models/non-standard/timetable-stop-order.js +6 -6
  74. package/models/non-standard/timetables.js +27 -27
  75. package/package.json +29 -11
  76. package/test/mocha/export-gtfs.js +63 -40
  77. package/test/mocha/get-agencies.js +11 -11
  78. package/test/mocha/get-attributions.js +1 -1
  79. package/test/mocha/get-board-alights.js +1 -1
  80. package/test/mocha/get-calendar-dates.js +22 -21
  81. package/test/mocha/get-calendars.js +8 -8
  82. package/test/mocha/get-db.js +9 -2
  83. package/test/mocha/get-directions.js +1 -1
  84. package/test/mocha/get-fare-attributes.js +3 -3
  85. package/test/mocha/get-fare-rules.js +8 -10
  86. package/test/mocha/get-feed-info.js +1 -1
  87. package/test/mocha/get-frequencies.js +1 -1
  88. package/test/mocha/get-levels.js +1 -1
  89. package/test/mocha/get-pathways.js +1 -1
  90. package/test/mocha/get-rider-trips.js +1 -1
  91. package/test/mocha/get-riderships.js +1 -1
  92. package/test/mocha/get-routes.js +9 -13
  93. package/test/mocha/get-shapes-as-geojson.js +3 -3
  94. package/test/mocha/get-shapes.js +28 -36
  95. package/test/mocha/get-stop-attributes.js +1 -1
  96. package/test/mocha/get-stops-as-geojson.js +2 -2
  97. package/test/mocha/get-stops.js +59 -48
  98. package/test/mocha/get-stoptimes.js +9 -7
  99. package/test/mocha/get-timetable-pages.js +1 -1
  100. package/test/mocha/get-timetable-stop-orders.js +1 -1
  101. package/test/mocha/get-timetables.js +1 -1
  102. package/test/mocha/get-transfers.js +1 -1
  103. package/test/mocha/get-translations.js +1 -1
  104. package/test/mocha/get-trip-capacities.js +1 -1
  105. package/test/mocha/get-trips.js +3 -3
  106. package/test/mocha/import-gtfs.js +59 -42
  107. package/test/test-config.js +9 -4
@@ -15,13 +15,20 @@ import models from '../../models/models.js';
15
15
 
16
16
  let db;
17
17
 
18
- const agenciesFixturesRemote = [{
19
- url: 'http://transitfeeds.com/p/caltrain/122/20160406/download'
20
- }];
21
-
22
- const agenciesFixturesLocal = [{
23
- path: path.join(path.dirname(fileURLToPath(import.meta.url)), '../fixture/caltrain_20160406.zip')
24
- }];
18
+ const agenciesFixturesRemote = [
19
+ {
20
+ url: 'http://transitfeeds.com/p/caltrain/122/20160406/download',
21
+ },
22
+ ];
23
+
24
+ const agenciesFixturesLocal = [
25
+ {
26
+ path: path.join(
27
+ path.dirname(fileURLToPath(import.meta.url)),
28
+ '../fixture/caltrain_20160406.zip'
29
+ ),
30
+ },
31
+ ];
25
32
 
26
33
  describe('importGtfs():', function () {
27
34
  before(async () => {
@@ -37,7 +44,7 @@ describe('importGtfs():', function () {
37
44
  it('should be able to download and import from HTTP', async () => {
38
45
  await importGtfs({
39
46
  ...config,
40
- agencies: agenciesFixturesRemote
47
+ agencies: agenciesFixturesRemote,
41
48
  });
42
49
 
43
50
  const routes = await getRoutes();
@@ -48,7 +55,7 @@ describe('importGtfs():', function () {
48
55
  it('should be able to download and import from local filesystem', async () => {
49
56
  await importGtfs({
50
57
  ...config,
51
- agencies: agenciesFixturesLocal
58
+ agencies: agenciesFixturesLocal,
52
59
  });
53
60
 
54
61
  const routes = await getRoutes();
@@ -56,63 +63,73 @@ describe('importGtfs():', function () {
56
63
  routes.length.should.equal(4);
57
64
  });
58
65
 
59
- it('should throw an error when importing from local filesystem which doesn\'t exist', async () => {
66
+ it("should throw an error when importing from local filesystem which doesn't exist", async () => {
60
67
  return importGtfs({
61
68
  ...config,
62
69
  agencies: [
63
70
  {
64
- path: '/does/not/exist'
65
- }
66
- ]
71
+ path: '/does/not/exist',
72
+ },
73
+ ],
67
74
  }).should.be.rejected();
68
75
  });
69
76
  });
70
77
 
71
78
  describe('Verify data imported into database', () => {
72
79
  const countData = {};
73
- const temporaryDir = path.join(path.dirname(fileURLToPath(import.meta.url)), '../fixture/tmp/');
80
+ const temporaryDir = path.join(
81
+ path.dirname(fileURLToPath(import.meta.url)),
82
+ '../fixture/tmp/'
83
+ );
74
84
 
75
85
  before(async () => {
76
86
  await unzip(agenciesFixturesLocal[0].path, temporaryDir);
77
87
 
78
- await Promise.all(models.map(model => {
79
- const filePath = path.join(temporaryDir, `${model.filenameBase}.txt`);
80
-
81
- // GTFS has optional files
82
- if (!existsSync(filePath)) {
83
- countData[model.filenameBase] = 0;
84
- return false;
85
- }
86
-
87
- const parser = parse({
88
- columns: true,
89
- relax: true,
90
- trim: true
91
- }, (error, data) => {
92
- if (error) {
93
- throw new Error(error);
94
- }
88
+ await Promise.all(
89
+ models.map((model) => {
90
+ const filePath = path.join(temporaryDir, `${model.filenameBase}.txt`);
95
91
 
96
- countData[model.filenameBase] = data.length;
97
- });
92
+ // GTFS has optional files
93
+ if (!existsSync(filePath)) {
94
+ countData[model.filenameBase] = 0;
95
+ return false;
96
+ }
98
97
 
99
- return createReadStream(filePath)
100
- .pipe(parser)
101
- .on('error', error => {
102
- countData[model.collection] = 0;
103
- throw new Error(error);
104
- });
105
- }));
98
+ const parser = parse(
99
+ {
100
+ columns: true,
101
+ relax: true,
102
+ trim: true,
103
+ },
104
+ (error, data) => {
105
+ if (error) {
106
+ throw new Error(error);
107
+ }
108
+
109
+ countData[model.filenameBase] = data.length;
110
+ }
111
+ );
112
+
113
+ return createReadStream(filePath)
114
+ .pipe(parser)
115
+ .on('error', (error) => {
116
+ countData[model.collection] = 0;
117
+ throw new Error(error);
118
+ });
119
+ })
120
+ );
106
121
 
107
122
  await importGtfs({
108
123
  ...config,
109
- agencies: agenciesFixturesLocal
124
+ agencies: agenciesFixturesLocal,
110
125
  });
111
126
  });
112
127
 
113
128
  for (const model of models) {
114
129
  it(`should import the same number of ${model.filenameBase}`, async () => {
115
- const result = await db.get(`SELECT COUNT(*) FROM ${model.filenameBase};`);
130
+ const result = await db.get(
131
+ `SELECT COUNT(*) FROM ${model.filenameBase};`
132
+ );
116
133
  result['COUNT(*)'].should.equal(countData[model.filenameBase]);
117
134
  });
118
135
  }
@@ -2,10 +2,15 @@ import path from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
3
 
4
4
  const config = {
5
- agencies: [{
6
- path: path.join(path.dirname(fileURLToPath(import.meta.url)), 'fixture/caltrain_20160406.zip')
7
- }],
8
- verbose: false
5
+ agencies: [
6
+ {
7
+ path: path.join(
8
+ path.dirname(fileURLToPath(import.meta.url)),
9
+ 'fixture/caltrain_20160406.zip'
10
+ ),
11
+ },
12
+ ],
13
+ verbose: false,
9
14
  };
10
15
 
11
16
  export default config;