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.
- package/.eslintrc.json +14 -19
- package/.husky/pre-commit +4 -0
- package/.prettierrc.js +4 -0
- package/CHANGELOG.md +173 -0
- package/README.md +115 -126
- package/bin/gtfs-export.js +4 -5
- package/bin/gtfs-import.js +6 -7
- package/config-sample-full.json +2 -7
- package/lib/db.js +4 -2
- package/lib/export.js +26 -9
- package/lib/file-utils.js +26 -9
- package/lib/geojson-utils.js +51 -38
- package/lib/gtfs/agencies.js +8 -2
- package/lib/gtfs/attributions.js +8 -2
- package/lib/gtfs/calendar-dates.js +8 -2
- package/lib/gtfs/calendars.js +8 -2
- package/lib/gtfs/fare-attributes.js +8 -2
- package/lib/gtfs/fare-rules.js +8 -2
- package/lib/gtfs/feed-info.js +8 -2
- package/lib/gtfs/frequencies.js +8 -2
- package/lib/gtfs/levels.js +8 -2
- package/lib/gtfs/pathways.js +8 -2
- package/lib/gtfs/routes.js +15 -4
- package/lib/gtfs/shapes.js +49 -18
- package/lib/gtfs/stop-times.js +8 -2
- package/lib/gtfs/stops.js +45 -16
- package/lib/gtfs/transfers.js +8 -2
- package/lib/gtfs/translations.js +8 -2
- package/lib/gtfs/trips.js +8 -2
- package/lib/gtfs-ride/board-alights.js +8 -2
- package/lib/gtfs-ride/ride-feed-infos.js +8 -2
- package/lib/gtfs-ride/rider-trips.js +8 -2
- package/lib/gtfs-ride/riderships.js +8 -2
- package/lib/gtfs-ride/trip-capacities.js +8 -2
- package/lib/import.js +200 -125
- package/lib/log-utils.js +8 -4
- package/lib/non-standard/directions.js +8 -2
- package/lib/non-standard/stop-attributes.js +8 -2
- package/lib/non-standard/timetable-notes-references.js +13 -3
- package/lib/non-standard/timetable-notes.js +8 -2
- package/lib/non-standard/timetable-pages.js +8 -2
- package/lib/non-standard/timetable-stop-order.js +13 -3
- package/lib/non-standard/timetables.js +8 -2
- package/lib/utils.js +22 -11
- package/models/gtfs/agency.js +11 -11
- package/models/gtfs/attributions.js +14 -14
- package/models/gtfs/calendar-dates.js +7 -7
- package/models/gtfs/calendar.js +12 -12
- package/models/gtfs/fare-attributes.js +9 -9
- package/models/gtfs/fare-rules.js +8 -8
- package/models/gtfs/feed-info.js +12 -12
- package/models/gtfs/frequencies.js +10 -10
- package/models/gtfs/levels.js +5 -5
- package/models/gtfs/pathways.js +14 -14
- package/models/gtfs/routes.js +14 -14
- package/models/gtfs/shapes.js +8 -8
- package/models/gtfs/stop-times.js +17 -17
- package/models/gtfs/stops.js +17 -17
- package/models/gtfs/transfers.js +7 -7
- package/models/gtfs/translations.js +10 -10
- package/models/gtfs/trips.js +12 -12
- package/models/gtfs-ride/board-alight.js +24 -24
- package/models/gtfs-ride/ride-feed-info.js +8 -8
- package/models/gtfs-ride/rider-trip.js +21 -21
- package/models/gtfs-ride/ridership.js +23 -23
- package/models/gtfs-ride/trip-capacity.js +10 -10
- package/models/models.js +1 -1
- package/models/non-standard/directions.js +6 -6
- package/models/non-standard/stop-attributes.js +5 -5
- package/models/non-standard/timetable-notes-references.js +9 -9
- package/models/non-standard/timetable-notes.js +5 -5
- package/models/non-standard/timetable-pages.js +5 -5
- package/models/non-standard/timetable-stop-order.js +6 -6
- package/models/non-standard/timetables.js +27 -27
- package/package.json +29 -11
- package/test/mocha/export-gtfs.js +63 -40
- package/test/mocha/get-agencies.js +11 -11
- package/test/mocha/get-attributions.js +1 -1
- package/test/mocha/get-board-alights.js +1 -1
- package/test/mocha/get-calendar-dates.js +22 -21
- package/test/mocha/get-calendars.js +8 -8
- package/test/mocha/get-db.js +9 -2
- package/test/mocha/get-directions.js +1 -1
- package/test/mocha/get-fare-attributes.js +3 -3
- package/test/mocha/get-fare-rules.js +8 -10
- package/test/mocha/get-feed-info.js +1 -1
- package/test/mocha/get-frequencies.js +1 -1
- package/test/mocha/get-levels.js +1 -1
- package/test/mocha/get-pathways.js +1 -1
- package/test/mocha/get-rider-trips.js +1 -1
- package/test/mocha/get-riderships.js +1 -1
- package/test/mocha/get-routes.js +9 -13
- package/test/mocha/get-shapes-as-geojson.js +3 -3
- package/test/mocha/get-shapes.js +28 -36
- package/test/mocha/get-stop-attributes.js +1 -1
- package/test/mocha/get-stops-as-geojson.js +2 -2
- package/test/mocha/get-stops.js +59 -48
- package/test/mocha/get-stoptimes.js +9 -7
- package/test/mocha/get-timetable-pages.js +1 -1
- package/test/mocha/get-timetable-stop-orders.js +1 -1
- package/test/mocha/get-timetables.js +1 -1
- package/test/mocha/get-transfers.js +1 -1
- package/test/mocha/get-translations.js +1 -1
- package/test/mocha/get-trip-capacities.js +1 -1
- package/test/mocha/get-trips.js +3 -3
- package/test/mocha/import-gtfs.js +59 -42
- 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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
79
|
-
|
|
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
|
-
|
|
97
|
-
|
|
92
|
+
// GTFS has optional files
|
|
93
|
+
if (!existsSync(filePath)) {
|
|
94
|
+
countData[model.filenameBase] = 0;
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
98
97
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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(
|
|
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
|
}
|
package/test/test-config.js
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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;
|