gtfs 4.1.1 → 4.3.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 (56) hide show
  1. package/.github/workflows/nodejs.yml +3 -3
  2. package/CHANGELOG.md +19 -0
  3. package/README.md +64 -15
  4. package/lib/db.js +14 -15
  5. package/lib/file-utils.js +7 -9
  6. package/lib/gtfs/shapes.js +8 -0
  7. package/lib/gtfs/stops.js +7 -1
  8. package/lib/import.js +28 -8
  9. package/models/gtfs/agency.js +2 -5
  10. package/models/gtfs/areas.js +1 -0
  11. package/models/gtfs/attributions.js +6 -1
  12. package/models/gtfs/calendar-dates.js +3 -7
  13. package/models/gtfs/calendar.js +1 -0
  14. package/models/gtfs/fare-attributes.js +2 -0
  15. package/models/gtfs/fare-leg-rules.js +9 -0
  16. package/models/gtfs/fare-products.js +7 -0
  17. package/models/gtfs/fare-rules.js +5 -5
  18. package/models/gtfs/fare-transfer-rules.js +10 -0
  19. package/models/gtfs/feed-info.js +0 -5
  20. package/models/gtfs/frequencies.js +3 -6
  21. package/models/gtfs/levels.js +1 -0
  22. package/models/gtfs/pathways.js +3 -0
  23. package/models/gtfs/routes.js +3 -0
  24. package/models/gtfs/shapes.js +3 -6
  25. package/models/gtfs/stop-areas.js +2 -0
  26. package/models/gtfs/stop-times.js +4 -7
  27. package/models/gtfs/stops.js +3 -0
  28. package/models/gtfs/transfers.js +13 -9
  29. package/models/gtfs/translations.js +8 -5
  30. package/models/gtfs/trips.js +5 -0
  31. package/models/gtfs-plus/calendar-attributes.js +1 -0
  32. package/models/gtfs-plus/directions.js +3 -7
  33. package/models/gtfs-plus/route-attributes.js +1 -0
  34. package/models/gtfs-plus/stop-attributes.js +2 -6
  35. package/models/gtfs-realtime/service-alert-targets.js +0 -1
  36. package/models/gtfs-ride/board-alight.js +2 -0
  37. package/models/gtfs-ride/rider-trip.js +5 -0
  38. package/models/gtfs-ride/ridership.js +5 -0
  39. package/models/gtfs-ride/trip-capacity.js +2 -0
  40. package/models/non-standard/timetable-notes-references.js +5 -0
  41. package/models/non-standard/timetable-notes.js +1 -0
  42. package/models/non-standard/timetable-pages.js +1 -0
  43. package/models/non-standard/timetable-stop-order.js +3 -0
  44. package/models/non-standard/timetables.js +3 -0
  45. package/models/non-standard/trips-dated-vehicle-journey.js +1 -0
  46. package/models/ods/deadhead-times.js +4 -0
  47. package/models/ods/deadheads.js +8 -0
  48. package/models/ods/ops-locations.js +1 -0
  49. package/models/ods/run-events.js +4 -0
  50. package/package.json +7 -7
  51. package/test/mocha/advanced-query.js +7 -7
  52. package/test/mocha/export-gtfs.js +6 -1
  53. package/test/mocha/get-agencies.js +0 -2
  54. package/test/mocha/get-calendar-dates.js +0 -4
  55. package/test/mocha/import-gtfs.js +32 -5
  56. package/test/mocha/open-db.js +0 -1
@@ -8,6 +8,7 @@ const model = {
8
8
  type: 'varchar(255)',
9
9
  primary: true,
10
10
  required: true,
11
+ prefix: true,
11
12
  },
12
13
  {
13
14
  name: 'ops_location_code',
@@ -8,11 +8,13 @@ const model = {
8
8
  type: 'varchar(255)',
9
9
  primary: true,
10
10
  required: true,
11
+ prefix: true,
11
12
  },
12
13
  {
13
14
  name: 'piece_id',
14
15
  type: 'varchar(255)',
15
16
  required: true,
17
+ prefix: true,
16
18
  },
17
19
  {
18
20
  name: 'event_type',
@@ -47,6 +49,7 @@ const model = {
47
49
  {
48
50
  name: 'event_from_location_id',
49
51
  type: 'varchar(255)',
52
+ prefix: true,
50
53
  },
51
54
  {
52
55
  name: 'event_to_location_type',
@@ -58,6 +61,7 @@ const model = {
58
61
  {
59
62
  name: 'event_to_location_id',
60
63
  type: 'varchar(255)',
64
+ prefix: true,
61
65
  },
62
66
  ],
63
67
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtfs",
3
- "version": "4.1.1",
3
+ "version": "4.3.0",
4
4
  "description": "Import GTFS transit data into SQLite and query routes, stops, times, fares and more",
5
5
  "keywords": [
6
6
  "transit",
@@ -75,12 +75,13 @@
75
75
  "dependencies": {
76
76
  "@turf/helpers": "^6.5.0",
77
77
  "better-sqlite3": "^8.3.0",
78
- "csv-parse": "^5.3.6",
79
- "csv-stringify": "^6.3.0",
78
+ "csv-parse": "^5.3.8",
79
+ "csv-stringify": "^6.3.2",
80
80
  "gtfs-realtime-bindings": "^1.1.1",
81
81
  "lodash-es": "^4.17.21",
82
- "long": "^5.2.1",
82
+ "long": "^5.2.3",
83
83
  "node-fetch": "^3.3.1",
84
+ "node-stream-zip": "^1.15.0",
84
85
  "pluralize": "^8.0.0",
85
86
  "pretty-error": "^4.0.0",
86
87
  "promise-map-series": "^0.3.0",
@@ -90,19 +91,18 @@
90
91
  "strip-bom-stream": "^5.0.0",
91
92
  "tmp-promise": "^3.0.3",
92
93
  "untildify": "^4.0.0",
93
- "unzipper": "^0.10.11",
94
94
  "yargs": "^17.7.1",
95
95
  "yoctocolors": "^1.0.0"
96
96
  },
97
97
  "devDependencies": {
98
98
  "@types/better-sqlite3": "^7.6.4",
99
99
  "dtslint": "^4.2.1",
100
- "eslint": "^8.38.0",
100
+ "eslint": "^8.39.0",
101
101
  "eslint-config-prettier": "^8.8.0",
102
102
  "eslint-config-xo": "^0.43.1",
103
103
  "husky": "^8.0.3",
104
104
  "mocha": "^10.2.0",
105
- "prettier": "^2.8.7",
105
+ "prettier": "^2.8.8",
106
106
  "pretty-quick": "^3.1.3",
107
107
  "should": "^13.2.3"
108
108
  },
@@ -57,14 +57,14 @@ describe('advancedQuery():', () => {
57
57
  const results = advancedQuery('stop_times', advancedQueryOptions);
58
58
 
59
59
  const expectedResults = [
60
- { trip_id: '329', arrival_time: '9:09:00' },
61
- { trip_id: '329', arrival_time: '8:52:00' },
62
- { trip_id: '329', arrival_time: '8:44:00' },
63
- { trip_id: '329', arrival_time: '8:35:00' },
64
- { trip_id: '329', arrival_time: '8:27:00' },
65
- { trip_id: '329', arrival_time: '8:16:00' },
66
- { trip_id: '329', arrival_time: '8:03:00' },
67
60
  { trip_id: '329', arrival_time: '7:56:00' },
61
+ { trip_id: '329', arrival_time: '8:03:00' },
62
+ { trip_id: '329', arrival_time: '8:16:00' },
63
+ { trip_id: '329', arrival_time: '8:27:00' },
64
+ { trip_id: '329', arrival_time: '8:35:00' },
65
+ { trip_id: '329', arrival_time: '8:44:00' },
66
+ { trip_id: '329', arrival_time: '8:52:00' },
67
+ { trip_id: '329', arrival_time: '9:09:00' },
68
68
  ];
69
69
 
70
70
  should.exist(results);
@@ -8,7 +8,11 @@ import { rm } from 'node:fs/promises';
8
8
  import { parse } from 'csv-parse';
9
9
  import should from 'should';
10
10
 
11
- import { unzip, generateFolderName } from '../../lib/file-utils.js';
11
+ import {
12
+ unzip,
13
+ generateFolderName,
14
+ prepDirectory,
15
+ } from '../../lib/file-utils.js';
12
16
  import config from '../test-config.js';
13
17
  import {
14
18
  openDb,
@@ -45,6 +49,7 @@ describe('exportGtfs():', function () {
45
49
  );
46
50
 
47
51
  before(async () => {
52
+ await prepDirectory(temporaryDir);
48
53
  await unzip(config.agencies[0].path, temporaryDir);
49
54
 
50
55
  await Promise.all(
@@ -28,7 +28,6 @@ describe('getAgencies():', () => {
28
28
  const results = getAgencies();
29
29
 
30
30
  const expectedResult = {
31
- id: 1,
32
31
  agency_id: 'CT',
33
32
  agency_name: 'Caltrain',
34
33
  agency_url: 'http://www.caltrain.com',
@@ -54,7 +53,6 @@ describe('getAgencies():', () => {
54
53
  });
55
54
 
56
55
  const expectedResult = {
57
- id: 1,
58
56
  agency_id: 'CT',
59
57
  agency_name: 'Caltrain',
60
58
  agency_url: 'http://www.caltrain.com',
@@ -38,28 +38,24 @@ describe('getCalendarDates():', () => {
38
38
 
39
39
  const expectedResults = [
40
40
  {
41
- id: 2,
42
41
  service_id: 'CT-16APR-Caltrain-Weekday-01',
43
42
  date: 20161124,
44
43
  exception_type: 2,
45
44
  holiday_name: null,
46
45
  },
47
46
  {
48
- id: 4,
49
47
  service_id: 'CT-16APR-Caltrain-Weekday-01',
50
48
  date: 20160905,
51
49
  exception_type: 2,
52
50
  holiday_name: null,
53
51
  },
54
52
  {
55
- id: 6,
56
53
  service_id: 'CT-16APR-Caltrain-Weekday-01',
57
54
  date: 20160704,
58
55
  exception_type: 2,
59
56
  holiday_name: null,
60
57
  },
61
58
  {
62
- id: 8,
63
59
  service_id: 'CT-16APR-Caltrain-Weekday-01',
64
60
  date: 20160530,
65
61
  exception_type: 2,
@@ -7,9 +7,15 @@ import { fileURLToPath } from 'node:url';
7
7
  import { parse } from 'csv-parse';
8
8
  import should from 'should';
9
9
 
10
- import { unzip } from '../../lib/file-utils.js';
10
+ import { prepDirectory, unzip } from '../../lib/file-utils.js';
11
11
  import config from '../test-config.js';
12
- import { openDb, closeDb, importGtfs, getRoutes } from '../../index.js';
12
+ import {
13
+ openDb,
14
+ closeDb,
15
+ importGtfs,
16
+ getRoutes,
17
+ getStops,
18
+ } from '../../index.js';
13
19
  import models from '../../models/models.js';
14
20
 
15
21
  let db;
@@ -63,15 +69,35 @@ describe('importGtfs():', function () {
63
69
  routes.length.should.equal(4);
64
70
  });
65
71
 
66
- it("should throw an error when importing from local filesystem which doesn't exist", async () => {
67
- return importGtfs({
72
+ it("should throw an error when importing from local filesystem which doesn't exist", async () =>
73
+ importGtfs({
68
74
  ...config,
69
75
  agencies: [
70
76
  {
71
77
  path: '/does/not/exist',
72
78
  },
73
79
  ],
74
- }).should.be.rejected();
80
+ }).should.be.rejected());
81
+
82
+ it('should add a prefix to imported data if present in config', async () => {
83
+ const prefix = 'test-prefix';
84
+ await importGtfs({
85
+ ...config,
86
+ agencies: [
87
+ {
88
+ ...agenciesFixturesLocal[0],
89
+ prefix,
90
+ },
91
+ ],
92
+ });
93
+
94
+ const routes = getRoutes();
95
+ should.exist(routes);
96
+ routes[0].route_id.should.startWith(prefix);
97
+
98
+ const stops = getStops();
99
+ should.exist(stops);
100
+ stops[0].stop_id.should.startWith(prefix);
75
101
  });
76
102
  });
77
103
 
@@ -83,6 +109,7 @@ describe('importGtfs():', function () {
83
109
  );
84
110
 
85
111
  before(async () => {
112
+ await prepDirectory(temporaryDir);
86
113
  await unzip(agenciesFixturesLocal[0].path, temporaryDir);
87
114
 
88
115
  await Promise.all(
@@ -83,7 +83,6 @@ describe('openDb():', () => {
83
83
  );
84
84
 
85
85
  const expectedResult = {
86
- id: 1424,
87
86
  shape_id: 'cal_sf_tam',
88
87
  shape_pt_lat: 37.45375587083584,
89
88
  shape_pt_lon: -122.18063950538635,