gtfs 4.11.3 → 4.12.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/CHANGELOG.md +10 -0
- package/lib/gtfs/routes.js +23 -7
- package/lib/import.js +5 -5
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [4.12.0] - 2024-06-17
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Support for `service_id` in `getRoutes`
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- Use tempy for temporary directory creation
|
|
17
|
+
|
|
8
18
|
## [4.11.3] - 2024-06-13
|
|
9
19
|
|
|
10
20
|
### Fixed
|
package/lib/gtfs/routes.js
CHANGED
|
@@ -17,14 +17,30 @@ function buildStoptimeSubquery(query) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function buildTripSubquery(query) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
)
|
|
20
|
+
let whereClause = '';
|
|
21
|
+
const tripQuery = omit(query, ['stop_id']);
|
|
22
|
+
const stoptimeQuery = pick(query, ['stop_id']);
|
|
23
|
+
|
|
24
|
+
const whereClauses = Object.entries(tripQuery).map(([key, value]) =>
|
|
25
|
+
formatWhereClause(key, value),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
if (Object.values(stoptimeQuery).length > 0) {
|
|
29
|
+
whereClauses.push(`trip_id IN (${buildStoptimeSubquery(stoptimeQuery)})`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (whereClauses.length > 0) {
|
|
33
|
+
whereClause = `WHERE ${whereClauses.join(' AND ')}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return `SELECT DISTINCT route_id FROM trips ${whereClause}`;
|
|
23
37
|
}
|
|
24
38
|
|
|
25
39
|
/*
|
|
26
40
|
* Returns an array of routes that match the query parameters. A `stop_id`
|
|
27
41
|
* query parameter may be passed to find all routes that contain that stop.
|
|
42
|
+
* A `service_id` query parameter may be passed to limit routes to specific
|
|
43
|
+
* calendars.
|
|
28
44
|
*/
|
|
29
45
|
export function getRoutes(query = {}, fields = [], orderBy = [], options = {}) {
|
|
30
46
|
const db = options.db ?? openDb();
|
|
@@ -33,15 +49,15 @@ export function getRoutes(query = {}, fields = [], orderBy = [], options = {}) {
|
|
|
33
49
|
let whereClause = '';
|
|
34
50
|
const orderByClause = formatOrderByClause(orderBy);
|
|
35
51
|
|
|
36
|
-
const routeQuery = omit(query, ['stop_id']);
|
|
37
|
-
const
|
|
52
|
+
const routeQuery = omit(query, ['stop_id', 'service_id']);
|
|
53
|
+
const tripQuery = pick(query, ['stop_id', 'service_id']);
|
|
38
54
|
|
|
39
55
|
const whereClauses = Object.entries(routeQuery).map(([key, value]) =>
|
|
40
56
|
formatWhereClause(key, value),
|
|
41
57
|
);
|
|
42
58
|
|
|
43
|
-
if (Object.values(
|
|
44
|
-
whereClauses.push(`route_id IN (${buildTripSubquery(
|
|
59
|
+
if (Object.values(tripQuery).length > 0) {
|
|
60
|
+
whereClauses.push(`route_id IN (${buildTripSubquery(tripQuery)})`);
|
|
45
61
|
}
|
|
46
62
|
|
|
47
63
|
if (whereClauses.length > 0) {
|
package/lib/import.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { createReadStream, existsSync, lstatSync } from 'node:fs';
|
|
3
|
-
import { cp, readdir, rename, readFile, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { cp, readdir, rename, readFile, rm, writeFile } from 'node:fs/promises';
|
|
4
4
|
import fetch from 'node-fetch';
|
|
5
5
|
import { parse } from 'csv-parse';
|
|
6
6
|
import pluralize from 'pluralize';
|
|
7
7
|
import stripBomStream from 'strip-bom-stream';
|
|
8
|
-
import {
|
|
8
|
+
import { temporaryDirectory } from 'tempy';
|
|
9
9
|
import untildify from 'untildify';
|
|
10
10
|
import mapSeries from 'promise-map-series';
|
|
11
11
|
import GtfsRealtimeBindings from 'gtfs-realtime-bindings';
|
|
@@ -687,7 +687,7 @@ export async function importGtfs(initialConfig) {
|
|
|
687
687
|
createTables(db);
|
|
688
688
|
|
|
689
689
|
await mapSeries(config.agencies, async (agency) => {
|
|
690
|
-
const
|
|
690
|
+
const tempPath = temporaryDirectory();
|
|
691
691
|
|
|
692
692
|
const task = {
|
|
693
693
|
exclude: agency.exclude,
|
|
@@ -695,7 +695,7 @@ export async function importGtfs(initialConfig) {
|
|
|
695
695
|
headers: agency.headers || false,
|
|
696
696
|
realtime_headers: agency.realtimeHeaders || false,
|
|
697
697
|
realtime_urls: agency.realtimeUrls || false,
|
|
698
|
-
downloadDir:
|
|
698
|
+
downloadDir: tempPath,
|
|
699
699
|
downloadTimeout: config.downloadTimeout,
|
|
700
700
|
path: agency.path,
|
|
701
701
|
csvOptions: config.csvOptions || {},
|
|
@@ -719,7 +719,7 @@ export async function importGtfs(initialConfig) {
|
|
|
719
719
|
await updateRealtimeData(task);
|
|
720
720
|
}
|
|
721
721
|
|
|
722
|
-
|
|
722
|
+
await rm(tempPath, { recursive: true });
|
|
723
723
|
} catch (error) {
|
|
724
724
|
if (config.ignoreErrors) {
|
|
725
725
|
logError(error.message);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gtfs",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.12.0",
|
|
4
4
|
"description": "Import GTFS transit data into SQLite and query routes, stops, times, fares and more",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"transit",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"sanitize-filename": "^1.6.3",
|
|
92
92
|
"sqlstring-sqlite": "^0.1.1",
|
|
93
93
|
"strip-bom-stream": "^5.0.0",
|
|
94
|
-
"
|
|
94
|
+
"tempy": "^3.1.0",
|
|
95
95
|
"untildify": "^5.0.0",
|
|
96
96
|
"yargs": "^17.7.2",
|
|
97
97
|
"yoctocolors": "^2.0.2"
|