gtfs 3.8.0 → 4.0.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.
- package/@types/index.d.ts +35 -60
- package/@types/tests.ts +18 -13
- package/CHANGELOG.md +10 -0
- package/README.md +227 -207
- package/lib/advancedQuery.js +8 -17
- package/lib/db.js +29 -59
- package/lib/export.js +16 -10
- package/lib/gtfs/agencies.js +8 -6
- package/lib/gtfs/areas.js +8 -11
- package/lib/gtfs/attributions.js +8 -6
- package/lib/gtfs/calendar-dates.js +8 -6
- package/lib/gtfs/calendars.js +8 -6
- package/lib/gtfs/fare-attributes.js +8 -6
- package/lib/gtfs/fare-leg-rules.js +8 -6
- package/lib/gtfs/fare-products.js +8 -6
- package/lib/gtfs/fare-rules.js +8 -6
- package/lib/gtfs/fare-transfer-rules.js +8 -6
- package/lib/gtfs/feed-info.js +8 -6
- package/lib/gtfs/frequencies.js +8 -6
- package/lib/gtfs/levels.js +8 -11
- package/lib/gtfs/pathways.js +8 -6
- package/lib/gtfs/routes.js +8 -11
- package/lib/gtfs/shapes.js +34 -39
- package/lib/gtfs/stop-areas.js +8 -6
- package/lib/gtfs/stop-times.js +8 -6
- package/lib/gtfs/stops.js +27 -33
- package/lib/gtfs/transfers.js +8 -6
- package/lib/gtfs/translations.js +8 -6
- package/lib/gtfs/trips.js +8 -11
- package/lib/gtfs-realtime/service-alerts.js +9 -7
- package/lib/gtfs-realtime/stop-times-updates.js +9 -7
- package/lib/gtfs-realtime/trip-updates.js +9 -7
- package/lib/gtfs-realtime/vehicle-positions.js +9 -7
- package/lib/gtfs-ride/board-alights.js +8 -6
- package/lib/gtfs-ride/ride-feed-infos.js +8 -6
- package/lib/gtfs-ride/rider-trips.js +8 -6
- package/lib/gtfs-ride/riderships.js +8 -6
- package/lib/gtfs-ride/trip-capacities.js +8 -6
- package/lib/gtfs.js +3 -9
- package/lib/import.js +195 -202
- package/lib/non-standard/directions.js +8 -6
- package/lib/non-standard/stop-attributes.js +8 -6
- package/lib/non-standard/timetable-notes-references.js +8 -6
- package/lib/non-standard/timetable-notes.js +8 -6
- package/lib/non-standard/timetable-pages.js +8 -6
- package/lib/non-standard/timetable-stop-order.js +8 -6
- package/lib/non-standard/timetables.js +8 -6
- package/lib/non-standard/trips-dated-vehicle-journey.js +9 -7
- package/package.json +2 -3
- package/test/mocha/advanced-query.js +9 -15
- package/test/mocha/export-gtfs.js +5 -6
- package/test/mocha/fare-transfer-rules.js +32 -0
- package/test/mocha/get-agencies.js +13 -19
- package/test/mocha/get-areas.js +27 -0
- package/test/mocha/get-attributions.js +7 -13
- package/test/mocha/get-board-alights.js +7 -13
- package/test/mocha/get-calendar-dates.js +11 -17
- package/test/mocha/get-calendars.js +11 -17
- package/test/mocha/get-directions.js +7 -13
- package/test/mocha/get-fare-attributes.js +9 -15
- package/test/mocha/get-fare-leg-rules.js +27 -0
- package/test/mocha/get-fare-products.js +27 -0
- package/test/mocha/get-fare-rules.js +9 -15
- package/test/mocha/get-feed-info.js +7 -13
- package/test/mocha/get-frequencies.js +7 -13
- package/test/mocha/get-levels.js +7 -7
- package/test/mocha/get-pathways.js +7 -13
- package/test/mocha/get-ride-feed-infos.js +7 -13
- package/test/mocha/get-rider-trips.js +7 -13
- package/test/mocha/get-riderships.js +7 -13
- package/test/mocha/get-routes.js +13 -13
- package/test/mocha/get-shapes-as-geojson.js +14 -15
- package/test/mocha/get-shapes.js +25 -25
- package/test/mocha/get-stop-attributes.js +7 -13
- package/test/mocha/get-stops-as-geojson.js +13 -19
- package/test/mocha/get-stops.js +19 -19
- package/test/mocha/get-stoptimes.js +11 -17
- package/test/mocha/get-timetable-pages.js +7 -13
- package/test/mocha/get-timetable-stop-orders.js +6 -7
- package/test/mocha/get-timetables.js +7 -13
- package/test/mocha/get-transfers.js +7 -13
- package/test/mocha/get-translations.js +7 -13
- package/test/mocha/get-trip-capacities.js +7 -13
- package/test/mocha/get-trips.js +9 -9
- package/test/mocha/import-gtfs.js +11 -11
- package/test/mocha/{get-db.js → open-db.js} +37 -29
- package/test/mocha/raw-query.js +34 -0
- package/test/mocha/exec-raw-query.js +0 -39
- package/test/mocha/run-raw-query.js +0 -54
|
@@ -9,7 +9,7 @@ import should from 'should';
|
|
|
9
9
|
|
|
10
10
|
import { unzip } from '../../lib/file-utils.js';
|
|
11
11
|
import config from '../test-config.js';
|
|
12
|
-
import { openDb,
|
|
12
|
+
import { openDb, closeDb, importGtfs, getRoutes } from '../../index.js';
|
|
13
13
|
import models from '../../models/models.js';
|
|
14
14
|
|
|
15
15
|
let db;
|
|
@@ -30,13 +30,13 @@ const agenciesFixturesLocal = [
|
|
|
30
30
|
];
|
|
31
31
|
|
|
32
32
|
describe('importGtfs():', function () {
|
|
33
|
-
before(
|
|
34
|
-
db =
|
|
33
|
+
before(() => {
|
|
34
|
+
db = openDb(config);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
after(
|
|
38
|
-
const db =
|
|
39
|
-
|
|
37
|
+
after(() => {
|
|
38
|
+
const db = openDb(config);
|
|
39
|
+
closeDb(db);
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
this.timeout(10000);
|
|
@@ -47,7 +47,7 @@ describe('importGtfs():', function () {
|
|
|
47
47
|
agencies: agenciesFixturesRemote,
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
const routes =
|
|
50
|
+
const routes = getRoutes();
|
|
51
51
|
should.exist(routes);
|
|
52
52
|
routes.length.should.equal(4);
|
|
53
53
|
});
|
|
@@ -58,7 +58,7 @@ describe('importGtfs():', function () {
|
|
|
58
58
|
agencies: agenciesFixturesLocal,
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
const routes =
|
|
61
|
+
const routes = getRoutes();
|
|
62
62
|
should.exist(routes);
|
|
63
63
|
routes.length.should.equal(4);
|
|
64
64
|
});
|
|
@@ -127,9 +127,9 @@ describe('importGtfs():', function () {
|
|
|
127
127
|
|
|
128
128
|
for (const model of models) {
|
|
129
129
|
it(`should import the same number of ${model.filenameBase}`, async () => {
|
|
130
|
-
const result = await db
|
|
131
|
-
`SELECT COUNT(*) FROM ${model.filenameBase};`
|
|
132
|
-
|
|
130
|
+
const result = await db
|
|
131
|
+
.prepare(`SELECT COUNT(*) FROM ${model.filenameBase};`)
|
|
132
|
+
.get();
|
|
133
133
|
result['COUNT(*)'].should.equal(countData[model.filenameBase]);
|
|
134
134
|
});
|
|
135
135
|
}
|
|
@@ -4,7 +4,7 @@ import should from 'should';
|
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
|
|
6
6
|
import config from '../test-config.js';
|
|
7
|
-
import { openDb,
|
|
7
|
+
import { openDb, closeDb, importGtfs, getShapes } from '../../index.js';
|
|
8
8
|
|
|
9
9
|
const db2Config = {
|
|
10
10
|
...config,
|
|
@@ -17,62 +17,70 @@ const db2Config = {
|
|
|
17
17
|
sqlitePath: './tmpdb',
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
describe('
|
|
20
|
+
describe('openDb():', () => {
|
|
21
21
|
before(async () => {
|
|
22
|
-
|
|
22
|
+
openDb(config);
|
|
23
23
|
await importGtfs(config);
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
after(
|
|
27
|
-
const db =
|
|
28
|
-
|
|
26
|
+
after(() => {
|
|
27
|
+
const db = openDb(config);
|
|
28
|
+
closeDb(db);
|
|
29
29
|
|
|
30
30
|
// Close db2 and then delete it
|
|
31
|
-
const db2 =
|
|
32
|
-
|
|
31
|
+
const db2 = openDb(db2Config);
|
|
32
|
+
closeDb(db2);
|
|
33
33
|
fs.unlinkSync(db2Config.sqlitePath);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
it('should allow raw db queries: calendar_dates',
|
|
36
|
+
it('should allow raw db queries: calendar_dates', () => {
|
|
37
37
|
const serviceIds = ['CT-16APR-Caltrain-Weekday-01'];
|
|
38
|
-
const db =
|
|
39
|
-
const results =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
const db = openDb();
|
|
39
|
+
const results = db
|
|
40
|
+
.prepare(
|
|
41
|
+
`SELECT * FROM calendar_dates WHERE exception_type = 1 AND service_id NOT IN (${serviceIds
|
|
42
|
+
.map((serviceId) => `'${serviceId}'`)
|
|
43
|
+
.join(', ')})`
|
|
44
|
+
)
|
|
45
|
+
.all();
|
|
44
46
|
|
|
45
47
|
should.exists(results);
|
|
46
48
|
results.should.have.length(4);
|
|
47
49
|
});
|
|
48
50
|
|
|
49
|
-
it('should allow raw db queries: trips',
|
|
51
|
+
it('should allow raw db queries: trips', () => {
|
|
50
52
|
// Find all trips between two stop ids
|
|
51
53
|
const startStopId = '70261';
|
|
52
54
|
const endStopId = '70131';
|
|
53
|
-
const db =
|
|
54
|
-
const results =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
const db = openDb();
|
|
56
|
+
const results = db
|
|
57
|
+
.prepare(
|
|
58
|
+
'SELECT * from trips where trips.trip_id IN (SELECT start_stop_times.trip_id FROM stop_times as start_stop_times WHERE stop_id = ? AND start_stop_times.stop_sequence < (SELECT end_stop_times.stop_sequence FROM stop_times as end_stop_times WHERE end_stop_times.stop_sequence > start_stop_times.stop_sequence AND end_stop_times.trip_id = start_stop_times.trip_id AND end_stop_times.stop_id = ? ))'
|
|
59
|
+
)
|
|
60
|
+
.all(startStopId, endStopId);
|
|
58
61
|
should.exists(results);
|
|
59
62
|
results.should.have.length(62);
|
|
60
63
|
});
|
|
61
64
|
|
|
62
65
|
it('should allow multiple db connections', async () => {
|
|
63
|
-
const db2 =
|
|
66
|
+
const db2 = openDb(db2Config);
|
|
64
67
|
await importGtfs(db2Config);
|
|
65
68
|
|
|
66
|
-
const db1 =
|
|
69
|
+
const db1 = openDb(config);
|
|
67
70
|
|
|
68
|
-
db1.
|
|
69
|
-
db2.
|
|
71
|
+
db1.name.should.equal(':memory:');
|
|
72
|
+
db2.name.should.equal('./tmpdb');
|
|
70
73
|
|
|
71
74
|
// Query db1 for shapes
|
|
72
75
|
const shapeId = 'cal_sf_tam';
|
|
73
|
-
const results1 =
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
const results1 = getShapes(
|
|
77
|
+
{
|
|
78
|
+
shape_id: shapeId,
|
|
79
|
+
},
|
|
80
|
+
[],
|
|
81
|
+
[],
|
|
82
|
+
{ db: db1 }
|
|
83
|
+
);
|
|
76
84
|
|
|
77
85
|
const expectedResult = {
|
|
78
86
|
id: 1424,
|
|
@@ -88,7 +96,7 @@ describe('getDb():', () => {
|
|
|
88
96
|
results1.should.containEql(expectedResult);
|
|
89
97
|
|
|
90
98
|
// Query db2 for shapes, none should exist
|
|
91
|
-
const results2 =
|
|
99
|
+
const results2 = getShapes(
|
|
92
100
|
{
|
|
93
101
|
shape_id: shapeId,
|
|
94
102
|
},
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
|
|
3
|
+
import should from 'should';
|
|
4
|
+
|
|
5
|
+
import config from '../test-config.js';
|
|
6
|
+
import { openDb, closeDb, importGtfs } from '../../index.js';
|
|
7
|
+
|
|
8
|
+
describe('Raw Query:', () => {
|
|
9
|
+
before(async () => {
|
|
10
|
+
openDb(config);
|
|
11
|
+
await importGtfs(config);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
after(() => {
|
|
15
|
+
const db = openDb(config);
|
|
16
|
+
closeDb(db);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should DELETE a trip', () => {
|
|
20
|
+
const db = openDb(config);
|
|
21
|
+
|
|
22
|
+
const results = db.prepare('SELECT count(*) FROM trips').get();
|
|
23
|
+
|
|
24
|
+
should.exists(results);
|
|
25
|
+
results['count(*)'].should.equal(218);
|
|
26
|
+
|
|
27
|
+
db.exec("DELETE FROM trips where trip_id = '329';");
|
|
28
|
+
|
|
29
|
+
const newResults = db.prepare('SELECT count(*) FROM trips').get();
|
|
30
|
+
|
|
31
|
+
should.exists(newResults);
|
|
32
|
+
newResults['count(*)'].should.equal(217);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
|
|
3
|
-
import should from 'should';
|
|
4
|
-
|
|
5
|
-
import config from '../test-config.js';
|
|
6
|
-
import {
|
|
7
|
-
openDb,
|
|
8
|
-
getDb,
|
|
9
|
-
closeDb,
|
|
10
|
-
importGtfs,
|
|
11
|
-
execRawQuery,
|
|
12
|
-
runRawQuery,
|
|
13
|
-
} from '../../index.js';
|
|
14
|
-
|
|
15
|
-
describe('execRawQuery():', () => {
|
|
16
|
-
before(async () => {
|
|
17
|
-
await openDb(config);
|
|
18
|
-
await importGtfs(config);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
after(async () => {
|
|
22
|
-
const db = getDb(config);
|
|
23
|
-
await closeDb(db);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('should DELETE a trip', async () => {
|
|
27
|
-
const results = await runRawQuery('SELECT count(*) FROM trips');
|
|
28
|
-
|
|
29
|
-
should.exists(results);
|
|
30
|
-
results[0]['count(*)'].should.equal(218);
|
|
31
|
-
|
|
32
|
-
await execRawQuery('DELETE FROM trips where trip_id = "329"');
|
|
33
|
-
|
|
34
|
-
const newResults = await runRawQuery('SELECT count(*) FROM trips');
|
|
35
|
-
|
|
36
|
-
should.exists(newResults);
|
|
37
|
-
newResults[0]['count(*)'].should.equal(217);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
|
|
3
|
-
import should from 'should';
|
|
4
|
-
|
|
5
|
-
import config from '../test-config.js';
|
|
6
|
-
import {
|
|
7
|
-
openDb,
|
|
8
|
-
getDb,
|
|
9
|
-
closeDb,
|
|
10
|
-
importGtfs,
|
|
11
|
-
runRawQuery,
|
|
12
|
-
} from '../../index.js';
|
|
13
|
-
|
|
14
|
-
describe('runRawQuery():', () => {
|
|
15
|
-
before(async () => {
|
|
16
|
-
await openDb(config);
|
|
17
|
-
await importGtfs(config);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
after(async () => {
|
|
21
|
-
const db = getDb(config);
|
|
22
|
-
await closeDb(db);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should return empty array if no trips', async () => {
|
|
26
|
-
const results = await runRawQuery(
|
|
27
|
-
'SELECT * FROM trips WHERE trip_id = "fake-trip-id"'
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
should.exists(results);
|
|
31
|
-
results.should.have.length(0);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should return expected results', async () => {
|
|
35
|
-
const results = await runRawQuery(
|
|
36
|
-
'SELECT "trip_id", "arrival_time" FROM stop_times WHERE trip_id = "329"'
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
const expectedResults = [
|
|
40
|
-
{ trip_id: '329', arrival_time: '9:09:00' },
|
|
41
|
-
{ trip_id: '329', arrival_time: '8:52:00' },
|
|
42
|
-
{ trip_id: '329', arrival_time: '8:44:00' },
|
|
43
|
-
{ trip_id: '329', arrival_time: '8:35:00' },
|
|
44
|
-
{ trip_id: '329', arrival_time: '8:27:00' },
|
|
45
|
-
{ trip_id: '329', arrival_time: '8:16:00' },
|
|
46
|
-
{ trip_id: '329', arrival_time: '8:03:00' },
|
|
47
|
-
{ trip_id: '329', arrival_time: '7:56:00' },
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
should.exist(results);
|
|
51
|
-
results.length.should.equal(8);
|
|
52
|
-
expectedResults.should.match(results);
|
|
53
|
-
});
|
|
54
|
-
});
|