gtfs 3.6.1 → 3.8.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.
@@ -4,22 +4,22 @@ on: [push, pull_request]
4
4
 
5
5
  jobs:
6
6
  build:
7
-
8
7
  runs-on: ubuntu-latest
9
8
 
10
9
  strategy:
11
10
  matrix:
12
- node-version: [14.x, 16.x]
11
+ node-version: [14.x, 16.x, 18.x]
13
12
 
14
13
  steps:
15
- - uses: actions/checkout@v1
16
- - name: Use Node.js ${{ matrix.node-version }}
17
- uses: actions/setup-node@v1
18
- with:
19
- node-version: ${{ matrix.node-version }}
20
- - name: npm install and test
21
- run: |
22
- npm ci
23
- npm test
24
- env:
25
- CI: true
14
+ - uses: actions/checkout@v1
15
+ - name: Use Node.js ${{ matrix.node-version }}
16
+ uses: actions/setup-node@v1
17
+ with:
18
+ node-version: ${{ matrix.node-version }}
19
+ - name: npm install and test
20
+ run: |
21
+ npm install -g npm@9
22
+ npm ci
23
+ npm test
24
+ env:
25
+ CI: true
package/CHANGELOG.md CHANGED
@@ -5,6 +5,27 @@ 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.8.0] - 2022-12-22
9
+
10
+ ### Updated
11
+
12
+ - Dependency updates
13
+ - Add Node 18 tests
14
+
15
+ ### Changed
16
+
17
+ - Make transfer_type not required in transfers.txt
18
+
19
+ ## [3.7.0] - 2022-11-17
20
+
21
+ ### Updated
22
+
23
+ - Dependency updates
24
+
25
+ ### Added
26
+
27
+ - Add ignoreDuplicates config option
28
+
8
29
  ## [3.6.1] - 2022-11-08
9
30
 
10
31
  ### Updated
package/README.md CHANGED
@@ -139,13 +139,14 @@ Copy `config-sample.json` to `config.json` and then add your projects configurat
139
139
 
140
140
  cp config-sample.json config.json
141
141
 
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
- | [`sqlitePath`](#sqlitePath) | string | A path to an SQLite database. Optional, defaults to using an in-memory database. |
148
- | [`verbose`](#verbose) | boolean | Whether or not to print output to the console. Optional, defaults to true. |
142
+ | option | type | description |
143
+ | --------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------- |
144
+ | [`agencies`](#agencies) | array | An array of GTFS files to be imported, and which files to exclude. |
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. |
149
150
 
150
151
  ### agencies
151
152
 
@@ -274,6 +275,32 @@ See [full list of options](https://csv.js.org/parse/options/).
274
275
 
275
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`.
276
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
+
277
304
  ### sqlitePath
278
305
 
279
306
  {String} A path to an SQLite database. Optional, defaults to using an in-memory database with a value of `:memory:`.
@@ -12,6 +12,7 @@
12
12
  "csvOptions": {
13
13
  "skip_lines_with_error": true
14
14
  },
15
+ "ignoreDuplicates": false,
15
16
  "sqlitePath": "/tmp/gtfs",
16
17
  "exportPath": "~/path/to/export/gtfs"
17
18
  }
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 GRFS-RT data..`);
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 INTO ${model.filenameBase}(${fieldNames.join(
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 {
@@ -85,11 +86,11 @@ export function formatWhereClause(key, value) {
85
86
  .filter((v) => v !== null)
86
87
  .map((v) => sqlString.escape(v))
87
88
  .join(', ')})`;
88
-
89
+
89
90
  if (value.includes(null)) {
90
91
  whereClause = `(${whereClause} OR ${sqlString.escapeId(key)} IS NULL)`;
91
92
  }
92
-
93
+
93
94
  return whereClause;
94
95
  }
95
96
 
@@ -37,7 +37,8 @@ const model = {
37
37
  type: 'integer',
38
38
  min: 0,
39
39
  max: 5,
40
- required: true,
40
+ required: false,
41
+ default: 0
41
42
  },
42
43
  {
43
44
  name: 'min_transfer_time',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtfs",
3
- "version": "3.6.1",
3
+ "version": "3.8.0",
4
4
  "description": "Import GTFS transit data into SQLite and query routes, stops, times, fares and more",
5
5
  "keywords": [
6
6
  "transit",
@@ -55,7 +55,8 @@
55
55
  "Darius MARTIN",
56
56
  "Mike Brocks",
57
57
  "Matt Moran",
58
- "Daniel Sörlöv"
58
+ "Daniel Sörlöv",
59
+ "Ali Zarghami <alizarghami@gmail.com>"
59
60
  ],
60
61
  "type": "module",
61
62
  "main": "index.js",
@@ -73,19 +74,19 @@
73
74
  },
74
75
  "dependencies": {
75
76
  "@turf/helpers": "^6.5.0",
76
- "csv-parse": "^5.3.2",
77
- "csv-stringify": "^6.2.1",
77
+ "csv-parse": "^5.3.3",
78
+ "csv-stringify": "^6.2.3",
78
79
  "gtfs-realtime-bindings": "^0.0.6",
79
80
  "lodash-es": "^4.17.21",
80
81
  "long": "^5.2.1",
81
- "node-fetch": "^3.2.10",
82
+ "node-fetch": "^3.3.0",
82
83
  "pluralize": "^8.0.0",
83
84
  "pretty-error": "^4.0.0",
84
85
  "promise-map-series": "^0.3.0",
85
86
  "recursive-copy": "^2.0.14",
86
87
  "sanitize-filename": "^1.6.3",
87
88
  "sqlite": "^4.1.2",
88
- "sqlite3": "^5.1.2",
89
+ "sqlite3": "^5.1.4",
89
90
  "sqlstring-sqlite": "^0.1.1",
90
91
  "strip-bom-stream": "^5.0.0",
91
92
  "tmp-promise": "^3.0.3",
@@ -96,12 +97,12 @@
96
97
  },
97
98
  "devDependencies": {
98
99
  "dtslint": "^4.2.1",
99
- "eslint": "^8.27.0",
100
+ "eslint": "^8.30.0",
100
101
  "eslint-config-prettier": "^8.5.0",
101
102
  "eslint-config-xo": "^0.43.1",
102
103
  "husky": "^8.0.2",
103
- "mocha": "^10.1.0",
104
- "prettier": "^2.7.1",
104
+ "mocha": "^10.2.0",
105
+ "prettier": "^2.8.1",
105
106
  "pretty-quick": "^3.1.3",
106
107
  "should": "^13.2.3"
107
108
  },