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.
Files changed (89) hide show
  1. package/@types/index.d.ts +35 -60
  2. package/@types/tests.ts +18 -13
  3. package/CHANGELOG.md +10 -0
  4. package/README.md +227 -207
  5. package/lib/advancedQuery.js +8 -17
  6. package/lib/db.js +29 -59
  7. package/lib/export.js +16 -10
  8. package/lib/gtfs/agencies.js +8 -6
  9. package/lib/gtfs/areas.js +8 -11
  10. package/lib/gtfs/attributions.js +8 -6
  11. package/lib/gtfs/calendar-dates.js +8 -6
  12. package/lib/gtfs/calendars.js +8 -6
  13. package/lib/gtfs/fare-attributes.js +8 -6
  14. package/lib/gtfs/fare-leg-rules.js +8 -6
  15. package/lib/gtfs/fare-products.js +8 -6
  16. package/lib/gtfs/fare-rules.js +8 -6
  17. package/lib/gtfs/fare-transfer-rules.js +8 -6
  18. package/lib/gtfs/feed-info.js +8 -6
  19. package/lib/gtfs/frequencies.js +8 -6
  20. package/lib/gtfs/levels.js +8 -11
  21. package/lib/gtfs/pathways.js +8 -6
  22. package/lib/gtfs/routes.js +8 -11
  23. package/lib/gtfs/shapes.js +34 -39
  24. package/lib/gtfs/stop-areas.js +8 -6
  25. package/lib/gtfs/stop-times.js +8 -6
  26. package/lib/gtfs/stops.js +27 -33
  27. package/lib/gtfs/transfers.js +8 -6
  28. package/lib/gtfs/translations.js +8 -6
  29. package/lib/gtfs/trips.js +8 -11
  30. package/lib/gtfs-realtime/service-alerts.js +9 -7
  31. package/lib/gtfs-realtime/stop-times-updates.js +9 -7
  32. package/lib/gtfs-realtime/trip-updates.js +9 -7
  33. package/lib/gtfs-realtime/vehicle-positions.js +9 -7
  34. package/lib/gtfs-ride/board-alights.js +8 -6
  35. package/lib/gtfs-ride/ride-feed-infos.js +8 -6
  36. package/lib/gtfs-ride/rider-trips.js +8 -6
  37. package/lib/gtfs-ride/riderships.js +8 -6
  38. package/lib/gtfs-ride/trip-capacities.js +8 -6
  39. package/lib/gtfs.js +3 -9
  40. package/lib/import.js +195 -202
  41. package/lib/non-standard/directions.js +8 -6
  42. package/lib/non-standard/stop-attributes.js +8 -6
  43. package/lib/non-standard/timetable-notes-references.js +8 -6
  44. package/lib/non-standard/timetable-notes.js +8 -6
  45. package/lib/non-standard/timetable-pages.js +8 -6
  46. package/lib/non-standard/timetable-stop-order.js +8 -6
  47. package/lib/non-standard/timetables.js +8 -6
  48. package/lib/non-standard/trips-dated-vehicle-journey.js +9 -7
  49. package/package.json +2 -3
  50. package/test/mocha/advanced-query.js +9 -15
  51. package/test/mocha/export-gtfs.js +5 -6
  52. package/test/mocha/fare-transfer-rules.js +32 -0
  53. package/test/mocha/get-agencies.js +13 -19
  54. package/test/mocha/get-areas.js +27 -0
  55. package/test/mocha/get-attributions.js +7 -13
  56. package/test/mocha/get-board-alights.js +7 -13
  57. package/test/mocha/get-calendar-dates.js +11 -17
  58. package/test/mocha/get-calendars.js +11 -17
  59. package/test/mocha/get-directions.js +7 -13
  60. package/test/mocha/get-fare-attributes.js +9 -15
  61. package/test/mocha/get-fare-leg-rules.js +27 -0
  62. package/test/mocha/get-fare-products.js +27 -0
  63. package/test/mocha/get-fare-rules.js +9 -15
  64. package/test/mocha/get-feed-info.js +7 -13
  65. package/test/mocha/get-frequencies.js +7 -13
  66. package/test/mocha/get-levels.js +7 -7
  67. package/test/mocha/get-pathways.js +7 -13
  68. package/test/mocha/get-ride-feed-infos.js +7 -13
  69. package/test/mocha/get-rider-trips.js +7 -13
  70. package/test/mocha/get-riderships.js +7 -13
  71. package/test/mocha/get-routes.js +13 -13
  72. package/test/mocha/get-shapes-as-geojson.js +14 -15
  73. package/test/mocha/get-shapes.js +25 -25
  74. package/test/mocha/get-stop-attributes.js +7 -13
  75. package/test/mocha/get-stops-as-geojson.js +13 -19
  76. package/test/mocha/get-stops.js +19 -19
  77. package/test/mocha/get-stoptimes.js +11 -17
  78. package/test/mocha/get-timetable-pages.js +7 -13
  79. package/test/mocha/get-timetable-stop-orders.js +6 -7
  80. package/test/mocha/get-timetables.js +7 -13
  81. package/test/mocha/get-transfers.js +7 -13
  82. package/test/mocha/get-translations.js +7 -13
  83. package/test/mocha/get-trip-capacities.js +7 -13
  84. package/test/mocha/get-trips.js +9 -9
  85. package/test/mocha/import-gtfs.js +11 -11
  86. package/test/mocha/{get-db.js → open-db.js} +37 -29
  87. package/test/mocha/raw-query.js +34 -0
  88. package/test/mocha/exec-raw-query.js +0 -39
  89. 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, getDb, closeDb, importGtfs, getRoutes } from '../../index.js';
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(async () => {
34
- db = await openDb(config);
33
+ before(() => {
34
+ db = openDb(config);
35
35
  });
36
36
 
37
- after(async () => {
38
- const db = getDb(config);
39
- await closeDb(db);
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 = await getRoutes();
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 = await getRoutes();
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.get(
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, getDb, closeDb, importGtfs, getShapes } from '../../index.js';
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('getDb():', () => {
20
+ describe('openDb():', () => {
21
21
  before(async () => {
22
- await openDb(config);
22
+ openDb(config);
23
23
  await importGtfs(config);
24
24
  });
25
25
 
26
- after(async () => {
27
- const db = getDb(config);
28
- await closeDb(db);
26
+ after(() => {
27
+ const db = openDb(config);
28
+ closeDb(db);
29
29
 
30
30
  // Close db2 and then delete it
31
- const db2 = getDb(db2Config);
32
- await closeDb(db2);
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', async () => {
36
+ it('should allow raw db queries: calendar_dates', () => {
37
37
  const serviceIds = ['CT-16APR-Caltrain-Weekday-01'];
38
- const db = getDb();
39
- const results = await db.all(
40
- `SELECT * FROM calendar_dates WHERE exception_type = 1 AND service_id NOT IN (${serviceIds
41
- .map((serviceId) => `'${serviceId}'`)
42
- .join(', ')})`
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', async () => {
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 = getDb();
54
- const results = await db.all(
55
- '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 = ? ))',
56
- [startStopId, endStopId]
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 = await openDb(db2Config);
66
+ const db2 = openDb(db2Config);
64
67
  await importGtfs(db2Config);
65
68
 
66
- const db1 = getDb(config);
69
+ const db1 = openDb(config);
67
70
 
68
- db1.config.filename.should.equal(':memory:');
69
- db2.config.filename.should.equal('./tmpdb');
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 = await getShapes({
74
- shape_id: shapeId,
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 = await getShapes(
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
- });