gtfs 3.6.0 → 3.7.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 +16 -0
- package/README.md +38 -7
- package/config-sample-full.json +1 -0
- package/lib/db.js +1 -1
- package/lib/import.js +5 -4
- package/lib/utils.js +9 -1
- package/package.json +12 -11
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,22 @@ 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
|
+
## [3.7.0] - 2022-11-17
|
|
9
|
+
|
|
10
|
+
### Updated
|
|
11
|
+
|
|
12
|
+
- Dependency updates
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- Add ignoreDuplicates config option
|
|
17
|
+
|
|
18
|
+
## [3.6.1] - 2022-11-08
|
|
19
|
+
|
|
20
|
+
### Updated
|
|
21
|
+
|
|
22
|
+
- Support for querying null values as part of an array
|
|
23
|
+
|
|
8
24
|
## [3.6.0] - 2022-08-08
|
|
9
25
|
|
|
10
26
|
### Added
|
package/README.md
CHANGED
|
@@ -93,6 +93,10 @@ try {
|
|
|
93
93
|
<td><img src="https://github.com/BlinkTagInc/gtfs-tts/raw/main/docs/images/gtfs-tts-logo.svg" alt="GTFS-TTS" width="200"></td>
|
|
94
94
|
<td><a href="https://github.com/blinktaginc/gtfs-tts">GTFS-Text-to-Speech</a> app tests GTFS stop name pronunciation for text-to-speech. It uses `node-gtfs` for loading stop names from GTFS data.</td>
|
|
95
95
|
</tr>
|
|
96
|
+
<tr>
|
|
97
|
+
<td><img src="https://github.com/BlinkTagInc/transit-arrivals-widget/raw/master/docs/images/transit-arrivals-widget-logo.svg" alt="Transit Arrivals Widget" width="200"></td>
|
|
98
|
+
<td><a href="https://github.com/BlinkTagInc/transit-arrivals-widget">Transit Arrivals Widget</a> creates a realtime transit arrivals tool from GTFS and GTFS-RT data.</td>
|
|
99
|
+
</tr>
|
|
96
100
|
</table>
|
|
97
101
|
|
|
98
102
|
## Command-Line Usage
|
|
@@ -135,13 +139,14 @@ Copy `config-sample.json` to `config.json` and then add your projects configurat
|
|
|
135
139
|
|
|
136
140
|
cp config-sample.json config.json
|
|
137
141
|
|
|
138
|
-
| option
|
|
139
|
-
|
|
|
140
|
-
| [`agencies`](#agencies)
|
|
141
|
-
| [`csvOptions`](#csvOptions)
|
|
142
|
-
| [`exportPath`](#exportPath)
|
|
143
|
-
| [`
|
|
144
|
-
| [`
|
|
142
|
+
| option | type | description |
|
|
143
|
+
| --------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
144
|
+
| [`agencies`](#agencies) | array | An array of GTFS files to be imported. |
|
|
145
|
+
| [`csvOptions`](#csvOptions) | object | Options passed to `csv-parse` for parsing GTFS CSV files. Optional. |
|
|
146
|
+
| [`exportPath`](#exportPath) | string | A path to a directory to put exported GTFS files. Optional, defaults to `gtfs-export/<agency_name>`. |
|
|
147
|
+
| [`ignoreDuplicates`](#ignoreduplicates) | boolean | Whether or not to ignore unique constraints on ids when importing GTFS, such as `trip_id`, `calendar_id`. Optional, defaults to false. |
|
|
148
|
+
| [`sqlitePath`](#sqlitePath) | string | A path to an SQLite database. Optional, defaults to using an in-memory database. |
|
|
149
|
+
| [`verbose`](#verbose) | boolean | Whether or not to print output to the console. Optional, defaults to true. |
|
|
145
150
|
|
|
146
151
|
### agencies
|
|
147
152
|
|
|
@@ -270,6 +275,32 @@ See [full list of options](https://csv.js.org/parse/options/).
|
|
|
270
275
|
|
|
271
276
|
{String} A path to a directory to put exported GTFS files. If the directory does not exist, it will be created. Used when running `gtfs-export` script or `exportGtfs()`. Optional, defaults to `gtfs-export/<agency_name>` where `<agency_name>` is a sanitized, [snake-cased](https://en.wikipedia.org/wiki/Snake_case) version of the first `agency_name` in `agency.txt`.
|
|
272
277
|
|
|
278
|
+
```json
|
|
279
|
+
{
|
|
280
|
+
"agencies": [
|
|
281
|
+
{
|
|
282
|
+
"path": "/path/to/the/unzipped/gtfs/"
|
|
283
|
+
}
|
|
284
|
+
],
|
|
285
|
+
"exportPath": "~/path/to/export/gtfs"
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### ignoreDuplicates
|
|
290
|
+
|
|
291
|
+
{Boolean} If you don't want node-GTFS to throw an error when it encounters a duplicate id on GTFS import. If `true`, it will skip importing duplicate records where unique constraints are violated, such as`trip_id`, `stop_id`, `calendar_id`. Useful if importing GTFS from multiple sources into one SQlite database that share routes or stops. Defaults to `false`.
|
|
292
|
+
|
|
293
|
+
```json
|
|
294
|
+
{
|
|
295
|
+
"agencies": [
|
|
296
|
+
{
|
|
297
|
+
"path": "/path/to/the/unzipped/gtfs/"
|
|
298
|
+
}
|
|
299
|
+
],
|
|
300
|
+
"ignoreDuplicates": false
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
273
304
|
### sqlitePath
|
|
274
305
|
|
|
275
306
|
{String} A path to an SQLite database. Optional, defaults to using an in-memory database with a value of `:memory:`.
|
package/config-sample-full.json
CHANGED
package/lib/db.js
CHANGED
|
@@ -26,7 +26,7 @@ export async function setupDb(db) {
|
|
|
26
26
|
if (!db) {
|
|
27
27
|
if (Object.keys(dbs).length > 1) {
|
|
28
28
|
throw new Error(
|
|
29
|
-
'Multiple database connections. Pass the db you want to
|
|
29
|
+
'Multiple database connections. Pass the db you want to setup as a parameter to `setupDb`.'
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
32
|
|
package/lib/import.js
CHANGED
|
@@ -128,7 +128,7 @@ const cleanStaleRealtimeData = async (db, log) => {
|
|
|
128
128
|
(x) => x.filenameBase === 'service_alert_targets'
|
|
129
129
|
);
|
|
130
130
|
|
|
131
|
-
log(`Cleaning stale
|
|
131
|
+
log(`Cleaning stale GTFS-RT data..`);
|
|
132
132
|
await db.run(
|
|
133
133
|
`DELETE FROM ${vehiclePositionModel.filenameBase} WHERE isUpdated=0`
|
|
134
134
|
);
|
|
@@ -503,9 +503,9 @@ const importLines = async (task, lines, model, totalLineCount) => {
|
|
|
503
503
|
|
|
504
504
|
try {
|
|
505
505
|
await task.db.run(
|
|
506
|
-
`INSERT
|
|
507
|
-
|
|
508
|
-
)}) VALUES${placeholders.join(',')}`,
|
|
506
|
+
`INSERT ${task.ignoreDuplicates ? 'OR IGNORE' : ''} INTO ${
|
|
507
|
+
model.filenameBase
|
|
508
|
+
}(${fieldNames.join(', ')}) VALUES${placeholders.join(',')}`,
|
|
509
509
|
values
|
|
510
510
|
);
|
|
511
511
|
} catch (error) {
|
|
@@ -642,6 +642,7 @@ export async function importGtfs(initialConfig) {
|
|
|
642
642
|
downloadDir: path,
|
|
643
643
|
path: agency.path,
|
|
644
644
|
csvOptions: config.csvOptions || {},
|
|
645
|
+
ignoreDuplicates: config.ignoreDuplicates,
|
|
645
646
|
db,
|
|
646
647
|
log(message, overwrite) {
|
|
647
648
|
log(message, overwrite);
|
package/lib/utils.js
CHANGED
|
@@ -26,6 +26,7 @@ export function validateConfigForImport(config) {
|
|
|
26
26
|
export function setDefaultConfig(initialConfig) {
|
|
27
27
|
const defaults = {
|
|
28
28
|
sqlitePath: ':memory:',
|
|
29
|
+
ignoreDuplicates: false,
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
return {
|
|
@@ -81,9 +82,16 @@ export function formatJoinClause(joinObject) {
|
|
|
81
82
|
|
|
82
83
|
export function formatWhereClause(key, value) {
|
|
83
84
|
if (Array.isArray(value)) {
|
|
84
|
-
|
|
85
|
+
let whereClause = `${sqlString.escapeId(key)} IN (${value
|
|
86
|
+
.filter((v) => v !== null)
|
|
85
87
|
.map((v) => sqlString.escape(v))
|
|
86
88
|
.join(', ')})`;
|
|
89
|
+
|
|
90
|
+
if (value.includes(null)) {
|
|
91
|
+
whereClause = `(${whereClause} OR ${sqlString.escapeId(key)} IS NULL)`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return whereClause;
|
|
87
95
|
}
|
|
88
96
|
|
|
89
97
|
if (value === null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gtfs",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "Import GTFS transit data into SQLite and query routes, stops, times, fares and more",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"transit",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"Jean-François Vial <jeff@modulaweb.fr>",
|
|
36
36
|
"wdalrymple",
|
|
37
37
|
"Ivan Yulaev",
|
|
38
|
+
"Ivy Rose",
|
|
38
39
|
"Adam Pitchie",
|
|
39
40
|
"Daniel Demidov",
|
|
40
41
|
"gerlacdt",
|
|
@@ -72,34 +73,34 @@
|
|
|
72
73
|
},
|
|
73
74
|
"dependencies": {
|
|
74
75
|
"@turf/helpers": "^6.5.0",
|
|
75
|
-
"csv-parse": "^5.3.
|
|
76
|
-
"csv-stringify": "^6.2.
|
|
76
|
+
"csv-parse": "^5.3.2",
|
|
77
|
+
"csv-stringify": "^6.2.1",
|
|
77
78
|
"gtfs-realtime-bindings": "^0.0.6",
|
|
78
79
|
"lodash-es": "^4.17.21",
|
|
79
|
-
"long": "^5.2.
|
|
80
|
-
"node-fetch": "^3.
|
|
80
|
+
"long": "^5.2.1",
|
|
81
|
+
"node-fetch": "^3.3.0",
|
|
81
82
|
"pluralize": "^8.0.0",
|
|
82
83
|
"pretty-error": "^4.0.0",
|
|
83
84
|
"promise-map-series": "^0.3.0",
|
|
84
85
|
"recursive-copy": "^2.0.14",
|
|
85
86
|
"sanitize-filename": "^1.6.3",
|
|
86
87
|
"sqlite": "^4.1.2",
|
|
87
|
-
"sqlite3": "^5.
|
|
88
|
+
"sqlite3": "^5.1.2",
|
|
88
89
|
"sqlstring-sqlite": "^0.1.1",
|
|
89
90
|
"strip-bom-stream": "^5.0.0",
|
|
90
91
|
"tmp-promise": "^3.0.3",
|
|
91
92
|
"untildify": "^4.0.0",
|
|
92
93
|
"unzipper": "^0.10.11",
|
|
93
|
-
"yargs": "^17.
|
|
94
|
+
"yargs": "^17.6.2",
|
|
94
95
|
"yoctocolors": "^1.0.0"
|
|
95
96
|
},
|
|
96
97
|
"devDependencies": {
|
|
97
98
|
"dtslint": "^4.2.1",
|
|
98
|
-
"eslint": "^8.
|
|
99
|
+
"eslint": "^8.27.0",
|
|
99
100
|
"eslint-config-prettier": "^8.5.0",
|
|
100
|
-
"eslint-config-xo": "^0.
|
|
101
|
-
"husky": "^8.0.
|
|
102
|
-
"mocha": "^10.
|
|
101
|
+
"eslint-config-xo": "^0.43.1",
|
|
102
|
+
"husky": "^8.0.2",
|
|
103
|
+
"mocha": "^10.1.0",
|
|
103
104
|
"prettier": "^2.7.1",
|
|
104
105
|
"pretty-quick": "^3.1.3",
|
|
105
106
|
"should": "^13.2.3"
|