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
@@ -2,7 +2,11 @@ import sqlString from 'sqlstring-sqlite';
2
2
 
3
3
  import { getDb } from '../db.js';
4
4
 
5
- import { formatOrderByClause, formatSelectClause, formatWhereClauses } from '../utils.js';
5
+ import {
6
+ formatOrderByClause,
7
+ formatSelectClause,
8
+ formatWhereClauses,
9
+ } from '../utils.js';
6
10
  import stopTimes from '../../models/gtfs/stop-times.js';
7
11
 
8
12
  /*
@@ -15,5 +19,7 @@ export async function getStoptimes(query = {}, fields = [], orderBy = []) {
15
19
  const whereClause = formatWhereClauses(query);
16
20
  const orderByClause = formatOrderByClause(orderBy);
17
21
 
18
- return db.all(`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`);
22
+ return db.all(
23
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
24
+ );
19
25
  }
package/lib/gtfs/stops.js CHANGED
@@ -3,7 +3,12 @@ import sqlString from 'sqlstring-sqlite';
3
3
 
4
4
  import { getDb } from '../db.js';
5
5
 
6
- import { formatOrderByClause, formatSelectClause, formatWhereClause, formatWhereClauses } from '../utils.js';
6
+ import {
7
+ formatOrderByClause,
8
+ formatSelectClause,
9
+ formatWhereClause,
10
+ formatWhereClauses,
11
+ } from '../utils.js';
7
12
  import { stopsToGeoJSON } from '../geojson-utils.js';
8
13
  import stops from '../../models/gtfs/stops.js';
9
14
  import { getAgencies } from './agencies.js';
@@ -14,7 +19,9 @@ function buildTripSubquery(query) {
14
19
  }
15
20
 
16
21
  function buildStoptimeSubquery(query) {
17
- return `SELECT DISTINCT stop_id FROM stop_times WHERE trip_id IN (${buildTripSubquery(query)})`;
22
+ return `SELECT DISTINCT stop_id FROM stop_times WHERE trip_id IN (${buildTripSubquery(
23
+ query
24
+ )})`;
18
25
  }
19
26
 
20
27
  /*
@@ -30,10 +37,22 @@ export async function getStops(query = {}, fields = [], orderBy = []) {
30
37
  let whereClause = '';
31
38
  const orderByClause = formatOrderByClause(orderBy);
32
39
 
33
- const stopQuery = omit(query, ['route_id', 'trip_id', 'service_id', 'direction_id']);
34
- const tripQuery = pick(query, ['route_id', 'trip_id', 'service_id', 'direction_id']);
35
-
36
- const whereClauses = Object.entries(stopQuery).map(([key, value]) => formatWhereClause(key, value));
40
+ const stopQuery = omit(query, [
41
+ 'route_id',
42
+ 'trip_id',
43
+ 'service_id',
44
+ 'direction_id',
45
+ ]);
46
+ const tripQuery = pick(query, [
47
+ 'route_id',
48
+ 'trip_id',
49
+ 'service_id',
50
+ 'direction_id',
51
+ ]);
52
+
53
+ const whereClauses = Object.entries(stopQuery).map(([key, value]) =>
54
+ formatWhereClause(key, value)
55
+ );
37
56
 
38
57
  if (Object.values(tripQuery).length > 0) {
39
58
  whereClauses.push(`stop_id IN (${buildStoptimeSubquery(tripQuery)})`);
@@ -43,7 +62,9 @@ export async function getStops(query = {}, fields = [], orderBy = []) {
43
62
  whereClause = `WHERE ${whereClauses.join(' AND ')}`;
44
63
  }
45
64
 
46
- return db.all(`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`);
65
+ return db.all(
66
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
67
+ );
47
68
  }
48
69
 
49
70
  /*
@@ -57,15 +78,23 @@ export async function getStopsAsGeoJSON(query = {}) {
57
78
  // Get all agencies for reference
58
79
  const agencies = await getAgencies();
59
80
 
60
- const preparedStops = await Promise.all(stops.map(async stop => {
61
- const routeSubquery = 'SELECT DISTINCT route_id FROM trips WHERE trip_id IN (SELECT DISTINCT trip_id FROM stop_times WHERE stop_id = ?)';
62
- const routes = await db.all(`SELECT * FROM routes WHERE route_id IN (${routeSubquery})`, [stop.stop_id]);
63
-
64
- stop.routes = orderBy(routes, route => Number.parseInt(route.route_short_name, 10));
65
- stop.agency_name = agencies[0].agency_name;
66
-
67
- return stop;
68
- }));
81
+ const preparedStops = await Promise.all(
82
+ stops.map(async (stop) => {
83
+ const routeSubquery =
84
+ 'SELECT DISTINCT route_id FROM trips WHERE trip_id IN (SELECT DISTINCT trip_id FROM stop_times WHERE stop_id = ?)';
85
+ const routes = await db.all(
86
+ `SELECT * FROM routes WHERE route_id IN (${routeSubquery})`,
87
+ [stop.stop_id]
88
+ );
89
+
90
+ stop.routes = orderBy(routes, (route) =>
91
+ Number.parseInt(route.route_short_name, 10)
92
+ );
93
+ stop.agency_name = agencies[0].agency_name;
94
+
95
+ return stop;
96
+ })
97
+ );
69
98
 
70
99
  return stopsToGeoJSON(preparedStops);
71
100
  }
@@ -2,7 +2,11 @@ import sqlString from 'sqlstring-sqlite';
2
2
 
3
3
  import { getDb } from '../db.js';
4
4
 
5
- import { formatOrderByClause, formatSelectClause, formatWhereClauses } from '../utils.js';
5
+ import {
6
+ formatOrderByClause,
7
+ formatSelectClause,
8
+ formatWhereClauses,
9
+ } from '../utils.js';
6
10
  import transfers from '../../models/gtfs/transfers.js';
7
11
 
8
12
  /*
@@ -15,5 +19,7 @@ export async function getTransfers(query = {}, fields = [], orderBy = []) {
15
19
  const whereClause = formatWhereClauses(query);
16
20
  const orderByClause = formatOrderByClause(orderBy);
17
21
 
18
- return db.all(`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`);
22
+ return db.all(
23
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
24
+ );
19
25
  }
@@ -2,7 +2,11 @@ import sqlString from 'sqlstring-sqlite';
2
2
 
3
3
  import { getDb } from '../db.js';
4
4
 
5
- import { formatOrderByClause, formatSelectClause, formatWhereClauses } from '../utils.js';
5
+ import {
6
+ formatOrderByClause,
7
+ formatSelectClause,
8
+ formatWhereClauses,
9
+ } from '../utils.js';
6
10
  import translations from '../../models/gtfs/translations.js';
7
11
 
8
12
  /*
@@ -15,5 +19,7 @@ export async function getTranslations(query = {}, fields = [], orderBy = []) {
15
19
  const whereClause = formatWhereClauses(query);
16
20
  const orderByClause = formatOrderByClause(orderBy);
17
21
 
18
- return db.all(`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`);
22
+ return db.all(
23
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
24
+ );
19
25
  }
package/lib/gtfs/trips.js CHANGED
@@ -2,7 +2,11 @@ import sqlString from 'sqlstring-sqlite';
2
2
 
3
3
  import { getDb } from '../db.js';
4
4
 
5
- import { formatOrderByClause, formatSelectClause, formatWhereClauses } from '../utils.js';
5
+ import {
6
+ formatOrderByClause,
7
+ formatSelectClause,
8
+ formatWhereClauses,
9
+ } from '../utils.js';
6
10
  import trips from '../../models/gtfs/trips.js';
7
11
 
8
12
  /*
@@ -15,5 +19,7 @@ export async function getTrips(query = {}, fields = [], orderBy = []) {
15
19
  const whereClause = formatWhereClauses(query);
16
20
  const orderByClause = formatOrderByClause(orderBy);
17
21
 
18
- return db.all(`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`);
22
+ return db.all(
23
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
24
+ );
19
25
  }
@@ -2,7 +2,11 @@ import sqlString from 'sqlstring-sqlite';
2
2
 
3
3
  import { getDb } from '../db.js';
4
4
 
5
- import { formatOrderByClause, formatSelectClause, formatWhereClauses } from '../utils.js';
5
+ import {
6
+ formatOrderByClause,
7
+ formatSelectClause,
8
+ formatWhereClauses,
9
+ } from '../utils.js';
6
10
  import boardAlights from '../../models/gtfs-ride/board-alight.js';
7
11
 
8
12
  /*
@@ -15,5 +19,7 @@ export async function getBoardAlights(query = {}, fields = [], orderBy = []) {
15
19
  const whereClause = formatWhereClauses(query);
16
20
  const orderByClause = formatOrderByClause(orderBy);
17
21
 
18
- return db.all(`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`);
22
+ return db.all(
23
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
24
+ );
19
25
  }
@@ -2,7 +2,11 @@ import sqlString from 'sqlstring-sqlite';
2
2
 
3
3
  import { getDb } from '../db.js';
4
4
 
5
- import { formatOrderByClause, formatSelectClause, formatWhereClauses } from '../utils.js';
5
+ import {
6
+ formatOrderByClause,
7
+ formatSelectClause,
8
+ formatWhereClauses,
9
+ } from '../utils.js';
6
10
  import rideFeedInfo from '../../models/gtfs-ride/ride-feed-info.js';
7
11
 
8
12
  /*
@@ -15,5 +19,7 @@ export async function getRideFeedInfos(query = {}, fields = [], orderBy = []) {
15
19
  const whereClause = formatWhereClauses(query);
16
20
  const orderByClause = formatOrderByClause(orderBy);
17
21
 
18
- return db.all(`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`);
22
+ return db.all(
23
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
24
+ );
19
25
  }
@@ -2,7 +2,11 @@ import sqlString from 'sqlstring-sqlite';
2
2
 
3
3
  import { getDb } from '../db.js';
4
4
 
5
- import { formatOrderByClause, formatSelectClause, formatWhereClauses } from '../utils.js';
5
+ import {
6
+ formatOrderByClause,
7
+ formatSelectClause,
8
+ formatWhereClauses,
9
+ } from '../utils.js';
6
10
  import riderTrip from '../../models/gtfs-ride/rider-trip.js';
7
11
 
8
12
  /*
@@ -15,5 +19,7 @@ export async function getRiderTrips(query = {}, fields = [], orderBy = []) {
15
19
  const whereClause = formatWhereClauses(query);
16
20
  const orderByClause = formatOrderByClause(orderBy);
17
21
 
18
- return db.all(`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`);
22
+ return db.all(
23
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
24
+ );
19
25
  }
@@ -2,7 +2,11 @@ import sqlString from 'sqlstring-sqlite';
2
2
 
3
3
  import { getDb } from '../db.js';
4
4
 
5
- import { formatOrderByClause, formatSelectClause, formatWhereClauses } from '../utils.js';
5
+ import {
6
+ formatOrderByClause,
7
+ formatSelectClause,
8
+ formatWhereClauses,
9
+ } from '../utils.js';
6
10
  import riderships from '../../models/gtfs-ride/ridership.js';
7
11
 
8
12
  /*
@@ -15,5 +19,7 @@ export async function getRiderships(query = {}, fields = [], orderBy = []) {
15
19
  const whereClause = formatWhereClauses(query);
16
20
  const orderByClause = formatOrderByClause(orderBy);
17
21
 
18
- return db.all(`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`);
22
+ return db.all(
23
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
24
+ );
19
25
  }
@@ -2,7 +2,11 @@ import sqlString from 'sqlstring-sqlite';
2
2
 
3
3
  import { getDb } from '../db.js';
4
4
 
5
- import { formatOrderByClause, formatSelectClause, formatWhereClauses } from '../utils.js';
5
+ import {
6
+ formatOrderByClause,
7
+ formatSelectClause,
8
+ formatWhereClauses,
9
+ } from '../utils.js';
6
10
  import tripCapacity from '../../models/gtfs-ride/trip-capacity.js';
7
11
 
8
12
  /*
@@ -15,5 +19,7 @@ export async function getTripCapacities(query = {}, fields = [], orderBy = []) {
15
19
  const whereClause = formatWhereClauses(query);
16
20
  const orderByClause = formatOrderByClause(orderBy);
17
21
 
18
- return db.all(`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`);
22
+ return db.all(
23
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
24
+ );
19
25
  }