gtfs 3.1.4 → 3.2.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 +269 -0
- package/@types/tests.ts +26 -0
- package/@types/tsconfig.json +17 -0
- package/CHANGELOG.md +12 -0
- package/README.md +54 -22
- package/docs/images/node-gtfs-logo.svg +18 -0
- package/lib/db.js +62 -13
- package/lib/export.js +1 -4
- package/lib/gtfs/agencies.js +7 -2
- package/lib/gtfs/attributions.js +7 -2
- package/lib/gtfs/calendar-dates.js +7 -2
- package/lib/gtfs/calendars.js +7 -2
- package/lib/gtfs/fare-attributes.js +7 -2
- package/lib/gtfs/fare-rules.js +7 -2
- package/lib/gtfs/feed-info.js +7 -2
- package/lib/gtfs/frequencies.js +7 -2
- package/lib/gtfs/levels.js +7 -2
- package/lib/gtfs/pathways.js +7 -2
- package/lib/gtfs/routes.js +7 -2
- package/lib/gtfs/shapes.js +16 -11
- package/lib/gtfs/stop-times.js +7 -2
- package/lib/gtfs/stops.js +11 -6
- package/lib/gtfs/transfers.js +7 -2
- package/lib/gtfs/translations.js +7 -2
- package/lib/gtfs/trips.js +7 -2
- package/lib/gtfs-ride/board-alights.js +7 -2
- package/lib/gtfs-ride/ride-feed-infos.js +7 -2
- package/lib/gtfs-ride/rider-trips.js +7 -2
- package/lib/gtfs-ride/riderships.js +7 -2
- package/lib/gtfs-ride/trip-capacities.js +7 -2
- package/lib/import.js +3 -3
- package/lib/non-standard/directions.js +7 -2
- package/lib/non-standard/stop-attributes.js +7 -2
- package/lib/non-standard/timetable-notes-references.js +3 -2
- package/lib/non-standard/timetable-notes.js +7 -2
- package/lib/non-standard/timetable-pages.js +7 -2
- package/lib/non-standard/timetable-stop-order.js +3 -2
- package/lib/non-standard/timetables.js +7 -2
- package/lib/utils.js +4 -1
- package/package.json +14 -10
- package/test/mocha/export-gtfs.js +11 -4
- package/test/mocha/get-agencies.js +9 -3
- package/test/mocha/get-attributions.js +9 -3
- package/test/mocha/get-board-alights.js +9 -3
- package/test/mocha/get-calendar-dates.js +9 -3
- package/test/mocha/get-calendars.js +9 -3
- package/test/mocha/get-db.js +62 -3
- package/test/mocha/get-directions.js +9 -3
- package/test/mocha/get-fare-attributes.js +9 -3
- package/test/mocha/get-fare-rules.js +9 -3
- package/test/mocha/get-feed-info.js +9 -3
- package/test/mocha/get-frequencies.js +9 -3
- package/test/mocha/get-levels.js +3 -3
- package/test/mocha/get-pathways.js +9 -3
- package/test/mocha/get-ride-feed-infos.js +9 -3
- package/test/mocha/get-rider-trips.js +9 -3
- package/test/mocha/get-riderships.js +9 -3
- package/test/mocha/get-routes.js +3 -3
- package/test/mocha/get-shapes-as-geojson.js +9 -3
- package/test/mocha/get-shapes.js +3 -3
- package/test/mocha/get-stop-attributes.js +9 -3
- package/test/mocha/get-stops-as-geojson.js +9 -3
- package/test/mocha/get-stops.js +3 -3
- package/test/mocha/get-stoptimes.js +9 -3
- package/test/mocha/get-timetable-pages.js +9 -3
- package/test/mocha/get-timetable-stop-orders.js +9 -3
- package/test/mocha/get-timetables.js +9 -3
- package/test/mocha/get-transfers.js +9 -3
- package/test/mocha/get-translations.js +9 -3
- package/test/mocha/get-trip-capacities.js +9 -3
- package/test/mocha/get-trips.js +3 -3
- package/test/mocha/import-gtfs.js +4 -4
- package/.prettierrc.js +0 -4
package/lib/gtfs/calendars.js
CHANGED
|
@@ -12,8 +12,13 @@ import calendars from '../../models/gtfs/calendar.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of calendars that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getCalendars(
|
|
16
|
-
|
|
15
|
+
export async function getCalendars(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(calendars.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
|
@@ -12,8 +12,13 @@ import fareAttributes from '../../models/gtfs/fare-attributes.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all fare attributes that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getFareAttributes(
|
|
16
|
-
|
|
15
|
+
export async function getFareAttributes(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(fareAttributes.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
package/lib/gtfs/fare-rules.js
CHANGED
|
@@ -12,8 +12,13 @@ import fareRules from '../../models/gtfs/fare-rules.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all fare rules that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getFareRules(
|
|
16
|
-
|
|
15
|
+
export async function getFareRules(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(fareRules.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
package/lib/gtfs/feed-info.js
CHANGED
|
@@ -12,8 +12,13 @@ import feedInfo from '../../models/gtfs/feed-info.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all feed info that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getFeedInfo(
|
|
16
|
-
|
|
15
|
+
export async function getFeedInfo(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(feedInfo.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
package/lib/gtfs/frequencies.js
CHANGED
|
@@ -12,8 +12,13 @@ import frequencies from '../../models/gtfs/frequencies.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all frequencies that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getFrequencies(
|
|
16
|
-
|
|
15
|
+
export async function getFrequencies(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(frequencies.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
package/lib/gtfs/levels.js
CHANGED
|
@@ -12,8 +12,13 @@ import levels from '../../models/gtfs/levels.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all levels that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getLevels(
|
|
16
|
-
|
|
15
|
+
export async function getLevels(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(levels.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
package/lib/gtfs/pathways.js
CHANGED
|
@@ -12,8 +12,13 @@ import pathways from '../../models/gtfs/pathways.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all pathways that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getPathways(
|
|
16
|
-
|
|
15
|
+
export async function getPathways(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(pathways.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
package/lib/gtfs/routes.js
CHANGED
|
@@ -26,8 +26,13 @@ function buildTripSubquery(query) {
|
|
|
26
26
|
* Returns an array of routes that match the query parameters. A `stop_id`
|
|
27
27
|
* query parameter may be passed to find all routes that contain that stop.
|
|
28
28
|
*/
|
|
29
|
-
export async function getRoutes(
|
|
30
|
-
|
|
29
|
+
export async function getRoutes(
|
|
30
|
+
query = {},
|
|
31
|
+
fields = [],
|
|
32
|
+
orderBy = [],
|
|
33
|
+
options = {}
|
|
34
|
+
) {
|
|
35
|
+
const db = options.db ?? (await getDb());
|
|
31
36
|
const tableName = sqlString.escapeId(routes.filenameBase);
|
|
32
37
|
const selectClause = formatSelectClause(fields);
|
|
33
38
|
let whereClause = '';
|
package/lib/gtfs/shapes.js
CHANGED
|
@@ -26,8 +26,13 @@ function buildTripSubquery(query) {
|
|
|
26
26
|
* query parameter may be passed to find all shapes for a trip. A
|
|
27
27
|
* `direction_id` query parameter may be passed to find all shapes for a direction.
|
|
28
28
|
*/
|
|
29
|
-
export async function getShapes(
|
|
30
|
-
|
|
29
|
+
export async function getShapes(
|
|
30
|
+
query = {},
|
|
31
|
+
fields = [],
|
|
32
|
+
orderBy = [],
|
|
33
|
+
options = {}
|
|
34
|
+
) {
|
|
35
|
+
const db = options.db ?? (await getDb());
|
|
31
36
|
const tableName = sqlString.escapeId(shapes.filenameBase);
|
|
32
37
|
const selectClause = formatSelectClause(fields);
|
|
33
38
|
let whereClause = '';
|
|
@@ -67,8 +72,8 @@ export async function getShapes(query = {}, fields = [], orderBy = []) {
|
|
|
67
72
|
* Returns geoJSON of the shapes that match the query parameters. A `route_id`
|
|
68
73
|
* query parameter may be passed to find all shapes for a route.
|
|
69
74
|
*/
|
|
70
|
-
export async function getShapesAsGeoJSON(query = {}) {
|
|
71
|
-
const agencies = await getAgencies();
|
|
75
|
+
export async function getShapesAsGeoJSON(query = {}, options = {}) {
|
|
76
|
+
const agencies = await getAgencies({}, [], [], options);
|
|
72
77
|
|
|
73
78
|
const routeQuery = {};
|
|
74
79
|
|
|
@@ -76,7 +81,7 @@ export async function getShapesAsGeoJSON(query = {}) {
|
|
|
76
81
|
routeQuery.route_id = query.route_id;
|
|
77
82
|
}
|
|
78
83
|
|
|
79
|
-
const routes = await getRoutes(routeQuery);
|
|
84
|
+
const routes = await getRoutes(routeQuery, [], [], options);
|
|
80
85
|
const features = [];
|
|
81
86
|
|
|
82
87
|
await Promise.all(
|
|
@@ -85,12 +90,12 @@ export async function getShapesAsGeoJSON(query = {}) {
|
|
|
85
90
|
route_id: route.route_id,
|
|
86
91
|
...omit(query, 'route_id'),
|
|
87
92
|
};
|
|
88
|
-
const shapes = await getShapes(
|
|
89
|
-
|
|
90
|
-
'shape_pt_sequence',
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
const shapes = await getShapes(
|
|
94
|
+
shapeQuery,
|
|
95
|
+
['shape_id', 'shape_pt_sequence', 'shape_pt_lon', 'shape_pt_lat'],
|
|
96
|
+
[],
|
|
97
|
+
options
|
|
98
|
+
);
|
|
94
99
|
|
|
95
100
|
const agency = agencies.find(
|
|
96
101
|
(agency) => agency.agency_id === route.agency_id
|
package/lib/gtfs/stop-times.js
CHANGED
|
@@ -12,8 +12,13 @@ import stopTimes from '../../models/gtfs/stop-times.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of stoptimes that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getStoptimes(
|
|
16
|
-
|
|
15
|
+
export async function getStoptimes(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(stopTimes.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
package/lib/gtfs/stops.js
CHANGED
|
@@ -30,8 +30,13 @@ function buildStoptimeSubquery(query) {
|
|
|
30
30
|
* query parameter may be passed to find all shapes for a trip. A
|
|
31
31
|
* `direction_id` query parameter may be passed to find all shapes for a direction.
|
|
32
32
|
*/
|
|
33
|
-
export async function getStops(
|
|
34
|
-
|
|
33
|
+
export async function getStops(
|
|
34
|
+
query = {},
|
|
35
|
+
fields = [],
|
|
36
|
+
orderBy = [],
|
|
37
|
+
options = {}
|
|
38
|
+
) {
|
|
39
|
+
const db = options.db ?? (await getDb());
|
|
35
40
|
const tableName = sqlString.escapeId(stops.filenameBase);
|
|
36
41
|
const selectClause = formatSelectClause(fields);
|
|
37
42
|
let whereClause = '';
|
|
@@ -71,12 +76,12 @@ export async function getStops(query = {}, fields = [], orderBy = []) {
|
|
|
71
76
|
* Returns geoJSON with stops for the `agencyKey` specified, optionally limited
|
|
72
77
|
* to the `stopIds` specified
|
|
73
78
|
*/
|
|
74
|
-
export async function getStopsAsGeoJSON(query = {}) {
|
|
75
|
-
const db = await getDb();
|
|
76
|
-
const stops = await getStops(query);
|
|
79
|
+
export async function getStopsAsGeoJSON(query = {}, options = {}) {
|
|
80
|
+
const db = options.db ?? (await getDb());
|
|
81
|
+
const stops = await getStops(query, [], [], options);
|
|
77
82
|
|
|
78
83
|
// Get all agencies for reference
|
|
79
|
-
const agencies = await getAgencies();
|
|
84
|
+
const agencies = await getAgencies({}, [], [], options);
|
|
80
85
|
|
|
81
86
|
const preparedStops = await Promise.all(
|
|
82
87
|
stops.map(async (stop) => {
|
package/lib/gtfs/transfers.js
CHANGED
|
@@ -12,8 +12,13 @@ import transfers from '../../models/gtfs/transfers.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all transfers that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getTransfers(
|
|
16
|
-
|
|
15
|
+
export async function getTransfers(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(transfers.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
package/lib/gtfs/translations.js
CHANGED
|
@@ -12,8 +12,13 @@ import translations from '../../models/gtfs/translations.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all translations that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getTranslations(
|
|
16
|
-
|
|
15
|
+
export async function getTranslations(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(translations.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
package/lib/gtfs/trips.js
CHANGED
|
@@ -12,8 +12,13 @@ import trips from '../../models/gtfs/trips.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all trips that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getTrips(
|
|
16
|
-
|
|
15
|
+
export async function getTrips(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(trips.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
|
@@ -12,8 +12,13 @@ import boardAlights from '../../models/gtfs-ride/board-alight.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all board-alights that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getBoardAlights(
|
|
16
|
-
|
|
15
|
+
export async function getBoardAlights(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(boardAlights.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
|
@@ -12,8 +12,13 @@ import rideFeedInfo from '../../models/gtfs-ride/ride-feed-info.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all ride-feed-info that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getRideFeedInfos(
|
|
16
|
-
|
|
15
|
+
export async function getRideFeedInfos(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(rideFeedInfo.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
|
@@ -12,8 +12,13 @@ import riderTrip from '../../models/gtfs-ride/rider-trip.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all rider trips that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getRiderTrips(
|
|
16
|
-
|
|
15
|
+
export async function getRiderTrips(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(riderTrip.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
|
@@ -12,8 +12,13 @@ import riderships from '../../models/gtfs-ride/ridership.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all riderships that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getRiderships(
|
|
16
|
-
|
|
15
|
+
export async function getRiderships(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(riderships.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
|
@@ -12,8 +12,13 @@ import tripCapacity from '../../models/gtfs-ride/trip-capacity.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all trip-capacities that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getTripCapacities(
|
|
16
|
-
|
|
15
|
+
export async function getTripCapacities(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(tripCapacity.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
package/lib/import.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createReadStream, existsSync, lstatSync } from 'node:fs';
|
|
|
3
3
|
import { readdir, rename, writeFile } from 'node:fs/promises';
|
|
4
4
|
import copy from 'recursive-copy';
|
|
5
5
|
import fetch from 'node-fetch';
|
|
6
|
-
import parse from 'csv-parse';
|
|
6
|
+
import { parse } from 'csv-parse';
|
|
7
7
|
import pluralize from 'pluralize';
|
|
8
8
|
import stripBomStream from 'strip-bom-stream';
|
|
9
9
|
import { dir } from 'tmp-promise';
|
|
@@ -38,9 +38,9 @@ const downloadFiles = async (task) => {
|
|
|
38
38
|
throw new Error('Couldn’t download files');
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const buffer = await response.
|
|
41
|
+
const buffer = await response.arrayBuffer();
|
|
42
42
|
|
|
43
|
-
await writeFile(task.path, buffer);
|
|
43
|
+
await writeFile(task.path, Buffer.from(buffer));
|
|
44
44
|
task.log('Download successful');
|
|
45
45
|
};
|
|
46
46
|
|
|
@@ -12,8 +12,13 @@ import directions from '../../models/non-standard/directions.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all directions that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getDirections(
|
|
16
|
-
|
|
15
|
+
export async function getDirections(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(directions.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
|
@@ -12,8 +12,13 @@ import stopAttributes from '../../models/non-standard/stop-attributes.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all stop attributes that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getStopAttributes(
|
|
16
|
-
|
|
15
|
+
export async function getStopAttributes(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(stopAttributes.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
|
@@ -15,9 +15,10 @@ import timetableNotesReferences from '../../models/non-standard/timetable-notes-
|
|
|
15
15
|
export async function getTimetableNotesReferences(
|
|
16
16
|
query = {},
|
|
17
17
|
fields = [],
|
|
18
|
-
orderBy = []
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
19
20
|
) {
|
|
20
|
-
const db = await getDb();
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
21
22
|
const tableName = sqlString.escapeId(timetableNotesReferences.filenameBase);
|
|
22
23
|
const selectClause = formatSelectClause(fields);
|
|
23
24
|
const whereClause = formatWhereClauses(query);
|
|
@@ -12,8 +12,13 @@ import timetableNotes from '../../models/non-standard/timetable-notes.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all timetable notes that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getTimetableNotes(
|
|
16
|
-
|
|
15
|
+
export async function getTimetableNotes(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(timetableNotes.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
|
@@ -12,8 +12,13 @@ import timetablePages from '../../models/non-standard/timetable-pages.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all timetable pages that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getTimetablePages(
|
|
16
|
-
|
|
15
|
+
export async function getTimetablePages(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(timetablePages.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
|
@@ -15,9 +15,10 @@ import timetableStopOrder from '../../models/non-standard/timetable-stop-order.j
|
|
|
15
15
|
export async function getTimetableStopOrders(
|
|
16
16
|
query = {},
|
|
17
17
|
fields = [],
|
|
18
|
-
orderBy = []
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
19
20
|
) {
|
|
20
|
-
const db = await getDb();
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
21
22
|
const tableName = sqlString.escapeId(timetableStopOrder.filenameBase);
|
|
22
23
|
const selectClause = formatSelectClause(fields);
|
|
23
24
|
const whereClause = formatWhereClauses(query);
|
|
@@ -12,8 +12,13 @@ import timetables from '../../models/non-standard/timetables.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all timetables that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getTimetables(
|
|
16
|
-
|
|
15
|
+
export async function getTimetables(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(timetables.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
package/lib/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gtfs",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Import GTFS transit data into SQLite and query routes, stops, times, fares and more",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"transit",
|
|
@@ -52,7 +52,8 @@
|
|
|
52
52
|
"Oskari Groenroos <oskari@groenroos.fi>",
|
|
53
53
|
"Devin Packer",
|
|
54
54
|
"Darius MARTIN",
|
|
55
|
-
"Mike Brocks"
|
|
55
|
+
"Mike Brocks",
|
|
56
|
+
"Matt Moran"
|
|
56
57
|
],
|
|
57
58
|
"type": "module",
|
|
58
59
|
"main": "index.js",
|
|
@@ -60,7 +61,9 @@
|
|
|
60
61
|
"gtfs-export": "bin/gtfs-export.js",
|
|
61
62
|
"gtfs-import": "bin/gtfs-import.js"
|
|
62
63
|
},
|
|
64
|
+
"types": "@types",
|
|
63
65
|
"scripts": {
|
|
66
|
+
"dtslint": "dtslint @types",
|
|
64
67
|
"lint": "eslint **/*.js",
|
|
65
68
|
"lint-fix": "eslint **/*.js --fix",
|
|
66
69
|
"test": "eslint **/*.js && NODE_ENV=test mocha ./test/mocha/**/*.js --timeout 2000"
|
|
@@ -68,12 +71,12 @@
|
|
|
68
71
|
"dependencies": {
|
|
69
72
|
"@turf/helpers": "^6.5.0",
|
|
70
73
|
"chalk": "^4.1.2",
|
|
71
|
-
"csv-parse": "^
|
|
72
|
-
"csv-stringify": "^
|
|
74
|
+
"csv-parse": "^5.0.3",
|
|
75
|
+
"csv-stringify": "^6.0.4",
|
|
73
76
|
"lodash-es": "^4.17.21",
|
|
74
|
-
"node-fetch": "^3.
|
|
77
|
+
"node-fetch": "^3.1.0",
|
|
75
78
|
"pluralize": "^8.0.0",
|
|
76
|
-
"pretty-error": "^
|
|
79
|
+
"pretty-error": "^4.0.0",
|
|
77
80
|
"promise-map-series": "^0.3.0",
|
|
78
81
|
"recursive-copy": "^2.0.13",
|
|
79
82
|
"sanitize-filename": "^1.6.3",
|
|
@@ -81,19 +84,20 @@
|
|
|
81
84
|
"sqlite3": "^5.0.2",
|
|
82
85
|
"sqlstring-sqlite": "^0.1.1",
|
|
83
86
|
"strip-bom-stream": "^5.0.0",
|
|
84
|
-
"tmp-promise": "^3.0.
|
|
87
|
+
"tmp-promise": "^3.0.3",
|
|
85
88
|
"untildify": "^4.0.0",
|
|
86
89
|
"unzipper": "^0.10.11",
|
|
87
90
|
"yargs": "^17.2.1"
|
|
88
91
|
},
|
|
89
92
|
"devDependencies": {
|
|
90
|
-
"
|
|
93
|
+
"dtslint": "^4.2.0",
|
|
94
|
+
"eslint": "^8.2.0",
|
|
91
95
|
"eslint-config-prettier": "^8.3.0",
|
|
92
96
|
"eslint-config-xo": "^0.39.0",
|
|
93
|
-
"husky": "^7.0.
|
|
97
|
+
"husky": "^7.0.4",
|
|
94
98
|
"mocha": "^9.1.3",
|
|
95
99
|
"prettier": "^2.4.1",
|
|
96
|
-
"pretty-quick": "^3.1.
|
|
100
|
+
"pretty-quick": "^3.1.2",
|
|
97
101
|
"should": "^13.2.3"
|
|
98
102
|
},
|
|
99
103
|
"engines": {
|
|
@@ -5,13 +5,19 @@ import path from 'node:path';
|
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { createReadStream, existsSync } from 'node:fs';
|
|
7
7
|
import { rm } from 'node:fs/promises';
|
|
8
|
-
import parse from 'csv-parse';
|
|
8
|
+
import { parse } from 'csv-parse';
|
|
9
9
|
import should from 'should';
|
|
10
10
|
|
|
11
|
-
import { openDb, closeDb } from '../../lib/db.js';
|
|
12
11
|
import { unzip, generateFolderName } from '../../lib/file-utils.js';
|
|
13
12
|
import config from '../test-config.js';
|
|
14
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
openDb,
|
|
15
|
+
getDb,
|
|
16
|
+
closeDb,
|
|
17
|
+
importGtfs,
|
|
18
|
+
exportGtfs,
|
|
19
|
+
getAgencies,
|
|
20
|
+
} from '../../index.js';
|
|
15
21
|
import models from '../../models/models.js';
|
|
16
22
|
|
|
17
23
|
describe('exportGtfs():', function () {
|
|
@@ -21,7 +27,8 @@ describe('exportGtfs():', function () {
|
|
|
21
27
|
});
|
|
22
28
|
|
|
23
29
|
after(async () => {
|
|
24
|
-
|
|
30
|
+
const db = getDb(config);
|
|
31
|
+
await closeDb(db);
|
|
25
32
|
});
|
|
26
33
|
|
|
27
34
|
this.timeout(10000);
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/* eslint-env mocha */
|
|
2
2
|
import should from 'should';
|
|
3
3
|
|
|
4
|
-
import { openDb, closeDb } from '../../lib/db.js';
|
|
5
4
|
import config from '../test-config.js';
|
|
6
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
openDb,
|
|
7
|
+
getDb,
|
|
8
|
+
closeDb,
|
|
9
|
+
importGtfs,
|
|
10
|
+
getAgencies,
|
|
11
|
+
} from '../../index.js';
|
|
7
12
|
|
|
8
13
|
describe('getAgencies():', () => {
|
|
9
14
|
before(async () => {
|
|
@@ -12,7 +17,8 @@ describe('getAgencies():', () => {
|
|
|
12
17
|
});
|
|
13
18
|
|
|
14
19
|
after(async () => {
|
|
15
|
-
|
|
20
|
+
const db = getDb(config);
|
|
21
|
+
await closeDb(db);
|
|
16
22
|
});
|
|
17
23
|
|
|
18
24
|
it('should return empty array if no agencies exist', async () => {
|