gtfs 4.10.2 → 4.10.3
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 +5 -0
- package/CHANGELOG.md +11 -0
- package/README.md +27 -5
- package/lib/db.js +26 -0
- package/lib/gtfs.js +3 -1
- package/models/gtfs-realtime/vehicle-positions.js +31 -7
- package/package.json +2 -2
- package/test/mocha/delete-db.js +62 -0
package/@types/index.d.ts
CHANGED
|
@@ -160,6 +160,11 @@ export function openDb(config: DbConfig): Database.Database;
|
|
|
160
160
|
*/
|
|
161
161
|
export function closeDb(db?: Database.Database): void;
|
|
162
162
|
|
|
163
|
+
/**
|
|
164
|
+
* Deletes the specified database.
|
|
165
|
+
*/
|
|
166
|
+
export function deleteDb(db?: Database.Database): void;
|
|
167
|
+
|
|
163
168
|
/**
|
|
164
169
|
* Returns an array of agencies that match query parameters.
|
|
165
170
|
*/
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,17 @@ 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.10.3] - 2024-05-12
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Additional GTFS-RT vehiclePosition fields
|
|
13
|
+
- deleteDb method
|
|
14
|
+
|
|
15
|
+
### Updated
|
|
16
|
+
|
|
17
|
+
- Dependency updates
|
|
18
|
+
|
|
8
19
|
## [4.10.2] - 2024-04-02
|
|
9
20
|
|
|
10
21
|
### Added
|
package/README.md
CHANGED
|
@@ -636,6 +636,20 @@ const db = openDb(config);
|
|
|
636
636
|
closeDb(db);
|
|
637
637
|
```
|
|
638
638
|
|
|
639
|
+
### Deleting a Database
|
|
640
|
+
|
|
641
|
+
You can use `deleteDb` to delete a sqlite3 database from the filesystem.
|
|
642
|
+
|
|
643
|
+
```js
|
|
644
|
+
import { deleteDb, openDb } from 'gtfs';
|
|
645
|
+
const db = openDb(config);
|
|
646
|
+
|
|
647
|
+
// Do some stuff here
|
|
648
|
+
|
|
649
|
+
// Delete the database
|
|
650
|
+
deleteDb(db);
|
|
651
|
+
```
|
|
652
|
+
|
|
639
653
|
### Examples
|
|
640
654
|
|
|
641
655
|
For example, to get a list of all routes with just `route_id`, `route_short_name` and `route_color` sorted by `route_short_name`:
|
|
@@ -1338,11 +1352,13 @@ const timetableNotesReferences = getTimetableNotesReferences({
|
|
|
1338
1352
|
|
|
1339
1353
|
### GTFS-Realtime
|
|
1340
1354
|
|
|
1341
|
-
In order to use GTFS-Realtime query methods, you must first
|
|
1355
|
+
In order to use GTFS-Realtime query methods, you must first run the [GTFS-Realtime update script or function](#gtfsrealtime-update-script) to pull data into your database.
|
|
1342
1356
|
|
|
1343
1357
|
#### getServiceAlerts(query, fields, sortBy, options)
|
|
1344
1358
|
|
|
1345
|
-
Returns an array of GTFS Realtime service alerts that match query parameters. [
|
|
1359
|
+
Returns an array of GTFS Realtime service alerts that match query parameters. Note that this does not refresh the data from GTFS-Realtime feeds, it only fetches what is stored in the database. In order to fetch the latest service alerts from GTFS-Realtime feeds and store in your database, use the [GTFS-Realtime update script or function](#gtfsrealtime-update-script).
|
|
1360
|
+
|
|
1361
|
+
[More details on Service Alerts](https://gtfs.org/realtime/feed-entities/service-alerts/)
|
|
1346
1362
|
|
|
1347
1363
|
```js
|
|
1348
1364
|
import { getServiceAlerts } from 'gtfs';
|
|
@@ -1353,7 +1369,9 @@ const serviceAlerts = getServiceAlerts();
|
|
|
1353
1369
|
|
|
1354
1370
|
#### getTripUpdates(query, fields, sortBy, options)
|
|
1355
1371
|
|
|
1356
|
-
Returns an array of GTFS Realtime trip updates that match query parameters. [
|
|
1372
|
+
Returns an array of GTFS Realtime trip updates that match query parameters. Note that this does not refresh the data from GTFS-Realtime feeds, it only fetches what is stored in the database. In order to fetch the latest trip updates from GTFS-Realtime feeds and store in your database, use the [GTFS-Realtime update script or function](#gtfsrealtime-update-script).
|
|
1373
|
+
|
|
1374
|
+
[More details on Trip Updates](https://gtfs.org/realtime/feed-entities/trip-updates/)
|
|
1357
1375
|
|
|
1358
1376
|
```js
|
|
1359
1377
|
import { getTripUpdates } from 'gtfs';
|
|
@@ -1364,7 +1382,9 @@ const tripUpdates = getTripUpdates();
|
|
|
1364
1382
|
|
|
1365
1383
|
#### getStopTimeUpdates(query, fields, sortBy, options)
|
|
1366
1384
|
|
|
1367
|
-
Returns an array of GTFS Realtime stop time updates that match query parameters. [
|
|
1385
|
+
Returns an array of GTFS Realtime stop time updates that match query parameters. Note that this does not refresh the data from GTFS-Realtime feeds, it only fetches what is stored in the database. In order to fetch the latest stop time updates from GTFS-Realtime feeds and store in your database, use the [GTFS-Realtime update script or function](#gtfsrealtime-update-script).
|
|
1386
|
+
|
|
1387
|
+
[More details on Stop Time Updates](https://gtfs.org/realtime/feed-entities/trip-updates/#stoptimeupdate)
|
|
1368
1388
|
|
|
1369
1389
|
```js
|
|
1370
1390
|
import { getStopTimeUpdates } from 'gtfs';
|
|
@@ -1375,7 +1395,9 @@ const stopTimeUpdates = getStopTimeUpdates();
|
|
|
1375
1395
|
|
|
1376
1396
|
#### getVehiclePositions(query, fields, sortBy, options)
|
|
1377
1397
|
|
|
1378
|
-
Returns an array of GTFS Realtime vehicle positions that match query parameters. [
|
|
1398
|
+
Returns an array of GTFS Realtime vehicle positions that match query parameters. Note that this does not refresh the data from GTFS-Realtime feeds, it only fetches what is stored in the database. In order to fetch the latest vehicle positions from GTFS-Realtime feeds and store in your database, use the [GTFS-Realtime update script or function](#gtfsrealtime-update-script).
|
|
1399
|
+
|
|
1400
|
+
[More details on Vehicle Positions](https://gtfs.org/realtime/feed-entities/vehicle-positions/)
|
|
1379
1401
|
|
|
1380
1402
|
```js
|
|
1381
1403
|
import { getVehiclePositions } from 'gtfs';
|
package/lib/db.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
|
|
1
3
|
import Database from 'better-sqlite3';
|
|
2
4
|
import untildify from 'untildify';
|
|
3
5
|
|
|
@@ -64,3 +66,27 @@ export function closeDb(db) {
|
|
|
64
66
|
db.close();
|
|
65
67
|
delete dbs[db.name];
|
|
66
68
|
}
|
|
69
|
+
|
|
70
|
+
export function deleteDb(db) {
|
|
71
|
+
if (Object.keys(dbs).length === 0) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
'No database connection. Call `openDb(config)` before using any methods.',
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!db) {
|
|
78
|
+
if (Object.keys(dbs).length > 1) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
'Multiple database connections. Pass the db you want to delete as a parameter to `deleteDb`.',
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
db = dbs[Object.keys(dbs)[0]];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
db.close();
|
|
88
|
+
|
|
89
|
+
fs.unlinkSync(db.name);
|
|
90
|
+
|
|
91
|
+
delete dbs[db.name];
|
|
92
|
+
}
|
package/lib/gtfs.js
CHANGED
|
@@ -67,7 +67,7 @@ import { getRunEvents } from './ods/run-events.js';
|
|
|
67
67
|
import { getRunsPieces } from './ods/runs-pieces.js';
|
|
68
68
|
|
|
69
69
|
// Expose database connection
|
|
70
|
-
import { openDb, closeDb } from './db.js';
|
|
70
|
+
import { deleteDb, openDb, closeDb } from './db.js';
|
|
71
71
|
|
|
72
72
|
// Advanced Query
|
|
73
73
|
import { advancedQuery } from './advancedQuery.js';
|
|
@@ -238,6 +238,8 @@ const _openDb = openDb;
|
|
|
238
238
|
export { _openDb as openDb };
|
|
239
239
|
const _closeDb = closeDb;
|
|
240
240
|
export { _closeDb as closeDb };
|
|
241
|
+
const _deleteDb = deleteDb;
|
|
242
|
+
export { _deleteDb as deleteDb };
|
|
241
243
|
|
|
242
244
|
const _advancedQuery = advancedQuery;
|
|
243
245
|
export { _advancedQuery as advancedQuery };
|
|
@@ -66,13 +66,6 @@ const model = {
|
|
|
66
66
|
source: 'vehicle.trip.startTime',
|
|
67
67
|
default: null,
|
|
68
68
|
},
|
|
69
|
-
{
|
|
70
|
-
name: 'vehicle_id',
|
|
71
|
-
type: 'varchar(255)',
|
|
72
|
-
index: true,
|
|
73
|
-
source: 'vehicle.vehicle.id',
|
|
74
|
-
default: null,
|
|
75
|
-
},
|
|
76
69
|
{
|
|
77
70
|
name: 'congestion_level',
|
|
78
71
|
type: 'varchar(255)',
|
|
@@ -91,6 +84,37 @@ const model = {
|
|
|
91
84
|
source: 'vehicle.occupancyPercentage',
|
|
92
85
|
default: null,
|
|
93
86
|
},
|
|
87
|
+
{
|
|
88
|
+
name: 'vehicle_stop_status',
|
|
89
|
+
type: 'varchar(255)',
|
|
90
|
+
source: 'vehicle.vehicleStopStatus',
|
|
91
|
+
default: null,
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: 'vehicle_id',
|
|
95
|
+
type: 'varchar(255)',
|
|
96
|
+
index: true,
|
|
97
|
+
source: 'vehicle.vehicle.id',
|
|
98
|
+
default: null,
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: 'vehicle_label',
|
|
102
|
+
type: 'varchar(255)',
|
|
103
|
+
source: 'vehicle.vehicle.label',
|
|
104
|
+
default: null,
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: 'vehicle_license_plate',
|
|
108
|
+
type: 'varchar(255)',
|
|
109
|
+
source: 'vehicle.vehicle.licensePlate',
|
|
110
|
+
default: null,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: 'vehicle_wheelchair_accessible',
|
|
114
|
+
type: 'varchar(255)',
|
|
115
|
+
source: 'vehicle.vehicle.wheelchairAccessible',
|
|
116
|
+
default: null,
|
|
117
|
+
},
|
|
94
118
|
{
|
|
95
119
|
name: 'timestamp',
|
|
96
120
|
type: 'varchar(255)',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gtfs",
|
|
3
|
-
"version": "4.10.
|
|
3
|
+
"version": "4.10.3",
|
|
4
4
|
"description": "Import GTFS transit data into SQLite and query routes, stops, times, fares and more",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"transit",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"@turf/helpers": "^6.5.0",
|
|
80
|
-
"better-sqlite3": "^
|
|
80
|
+
"better-sqlite3": "^10.0.0",
|
|
81
81
|
"csv-parse": "^5.5.5",
|
|
82
82
|
"csv-stringify": "^6.4.6",
|
|
83
83
|
"gtfs-realtime-bindings": "^1.1.1",
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
|
|
5
|
+
import config from '../test-config.js';
|
|
6
|
+
import { deleteDb, openDb, importGtfs } from '../../index.js';
|
|
7
|
+
|
|
8
|
+
const db2Config = {
|
|
9
|
+
agencies: [
|
|
10
|
+
{
|
|
11
|
+
...config.agencies[0],
|
|
12
|
+
exclude: ['shapes'],
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
verbose: false,
|
|
16
|
+
sqlitePath: './tmpdb2',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const db3Config = {
|
|
20
|
+
agencies: [
|
|
21
|
+
{
|
|
22
|
+
...config.agencies[0],
|
|
23
|
+
exclude: ['shapes'],
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
verbose: false,
|
|
27
|
+
sqlitePath: './tmpdb3',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
describe('openDb():', () => {
|
|
31
|
+
before(async () => {});
|
|
32
|
+
|
|
33
|
+
after(() => {
|
|
34
|
+
// Delete extra databases
|
|
35
|
+
fs.rmSync(db2Config.sqlitePath, { force: true });
|
|
36
|
+
fs.rmSync(db3Config.sqlitePath, { force: true });
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should allow deleting a database', async () => {
|
|
40
|
+
const db2 = openDb(db2Config);
|
|
41
|
+
await importGtfs(db2Config);
|
|
42
|
+
|
|
43
|
+
const db3 = openDb(db3Config);
|
|
44
|
+
await importGtfs(db3Config);
|
|
45
|
+
|
|
46
|
+
db2.name.should.equal('./tmpdb2');
|
|
47
|
+
db3.name.should.equal('./tmpdb3');
|
|
48
|
+
|
|
49
|
+
fs.existsSync(db2Config.sqlitePath).should.equal(true);
|
|
50
|
+
fs.existsSync(db3Config.sqlitePath).should.equal(true);
|
|
51
|
+
|
|
52
|
+
deleteDb(db2);
|
|
53
|
+
|
|
54
|
+
fs.existsSync(db2Config.sqlitePath).should.equal(false);
|
|
55
|
+
fs.existsSync(db3Config.sqlitePath).should.equal(true);
|
|
56
|
+
|
|
57
|
+
deleteDb(db3);
|
|
58
|
+
|
|
59
|
+
fs.existsSync(db2Config.sqlitePath).should.equal(false);
|
|
60
|
+
fs.existsSync(db3Config.sqlitePath).should.equal(false);
|
|
61
|
+
});
|
|
62
|
+
});
|